mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Revamped and streamlined retina / high-DPI support (resolves issue #1122).
With the highdpi window flag enabled on a retina-capable display and OS, content should now appear to the user at the same size and in the same positions as with the flag disabled. As a result, mouse and touch coordinates, Texture and graphics dimensions, and the graphics coordinate system now use pixel density-scaled units instead of pixels. Raw pixel units should generally only be used for things such as shader algorithms which execute per-pixel and rely on accurate pixel dimensions. love.window.fromPixels and friends typically don’t need to be used anymore. Images, Canvases, and Fonts can have an optional explicit ‘pixel density’ set when creating them. This allows for easily loading high pixel density content which displays at the same size as regular or low pixel density content. API changes: - Added Texture:getPixelWidth/getPixelHeight/getPixelDimensions and Texture:getPixelDensity. Texture:getWidth/getHeight return the pixel density-scaled width and height (as it will appear on the screen when drawn) rather than the number of pixels on each texture dimension. - Added love.graphics.getPixelWidth/getPixelHeight/getPixelDimensions. - Added optional ‘pixeldensity’ field to the settings table parameter of love.graphics.newImage. It defaults to 1, or if the file the Image was loaded from has “@2x”, “@3x”, etc. at the end of its name, it uses that number as the pixel density scale by default. - love.graphics.newCanvas now takes a table as its third parameter, with fields “format”, “msaa”, and “pixeldensity”. pixeldensity defaults to the main screen’s pixel density. The width and height parameters specify the visual size that the Canvas will be drawn at / can be drawn to (pixel density-scaled units). - love.graphics.newVideo accepts a table as its second parameter, with optional fields “audio” and “pixeldensity”. pixeldensity defaults to 1. - love.graphics.newFont variants have an optional pixeldensity parameter at the end of the argument list. For TrueType fonts this defaults to the current pixel density scale of the screen, and for BMFonts and ImageFonts this defaults to 1. - Added Font:getPixelDensity. - Renamed love.window.getPixelScale to love.window.getPixelDensity. --HG-- branch : minor
This commit is contained in:
@@ -54,17 +54,19 @@ public:
|
||||
|
||||
static love::Type type;
|
||||
|
||||
enum FlagType
|
||||
enum SettingType
|
||||
{
|
||||
FLAG_TYPE_MIPMAPS,
|
||||
FLAG_TYPE_LINEAR,
|
||||
FLAG_TYPE_MAX_ENUM
|
||||
SETTING_MIPMAPS,
|
||||
SETTING_LINEAR,
|
||||
SETTING_PIXELDENSITY,
|
||||
SETTING_MAX_ENUM
|
||||
};
|
||||
|
||||
struct Flags
|
||||
struct Settings
|
||||
{
|
||||
bool mipmaps = false;
|
||||
bool linear = false;
|
||||
float pixeldensity = 1.0f;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -75,14 +77,14 @@ public:
|
||||
* array is a mipmap level. If more than the base level is present, all
|
||||
* mip levels must be present.
|
||||
**/
|
||||
Image(const std::vector<love::image::ImageData *> &data, const Flags &flags);
|
||||
Image(const std::vector<love::image::ImageData *> &data, const Settings &settings);
|
||||
|
||||
/**
|
||||
* Creates a new Image with compressed image data.
|
||||
*
|
||||
* @param cdata The compressed data from which to load the image.
|
||||
**/
|
||||
Image(const std::vector<love::image::CompressedImageData *> &cdata, const Flags &flags);
|
||||
Image(const std::vector<love::image::CompressedImageData *> &cdata, const Settings &settings);
|
||||
|
||||
virtual ~Image();
|
||||
|
||||
@@ -112,7 +114,7 @@ public:
|
||||
**/
|
||||
bool refresh(int xoffset, int yoffset, int w, int h);
|
||||
|
||||
const Flags &getFlags() const;
|
||||
const Settings &getFlags() const;
|
||||
|
||||
static void setDefaultMipmapSharpness(float sharpness);
|
||||
static float getDefaultMipmapSharpness();
|
||||
@@ -122,8 +124,8 @@ public:
|
||||
static bool isFormatSupported(PixelFormat pixelformat);
|
||||
static bool hasSRGBSupport();
|
||||
|
||||
static bool getConstant(const char *in, FlagType &out);
|
||||
static bool getConstant(FlagType in, const char *&out);
|
||||
static bool getConstant(const char *in, SettingType &out);
|
||||
static bool getConstant(SettingType in, const char *&out);
|
||||
|
||||
static int imageCount;
|
||||
|
||||
@@ -154,8 +156,8 @@ private:
|
||||
// Whether this Image is using a compressed texture.
|
||||
bool compressed;
|
||||
|
||||
// The flags used to initialize this Image.
|
||||
Flags flags;
|
||||
// The settings used to initialize this Image.
|
||||
Settings settings;
|
||||
|
||||
bool sRGB;
|
||||
|
||||
@@ -170,8 +172,8 @@ private:
|
||||
static FilterMode defaultMipmapFilter;
|
||||
static float defaultMipmapSharpness;
|
||||
|
||||
static StringMap<FlagType, FLAG_TYPE_MAX_ENUM>::Entry flagNameEntries[];
|
||||
static StringMap<FlagType, FLAG_TYPE_MAX_ENUM> flagNames;
|
||||
static StringMap<SettingType, SETTING_MAX_ENUM>::Entry settingTypeEntries[];
|
||||
static StringMap<SettingType, SETTING_MAX_ENUM> settingTypes;
|
||||
|
||||
}; // Image
|
||||
|
||||
|
||||
Reference in New Issue
Block a user