mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Added Text objects via love.graphics.newText(font [, textstring]). Reworked the internal code of Font objects to use fewer individual textures and less VRAM per object, and to be compatible with OpenGL ES. Slightly improved the performance of love.graphics.print and love.graphics.printf.
Text objects are Drawable objects that represent text on the screen. They decouple text drawing from text parsing and vertex uploading, in a similar manner to SpriteBatches. They also optionally allow efficient batching of text from the same Font in different relative coordinate transformations, without having many draw calls. Text objects currently have the following methods: Text:set(textstring) -- replaces any existing text in the object with the new string. Text:setf(textstring, wraplimit, alignmode) -- replaces any existing text with formatted text using the new string. Text:getFont() -- gets the Font object used for this Text object. Text:getWidth() -- gets the width in pixels of the most recently added text in the Text object. Text:getHeight() -- gets the height in pixels of the most recently added text in the Text object. Text:add(textstring, x, y, angle, sx, sy, ox, oy, kx, ky) -- adds a new string to the text object using the specified relative coordinate transformation, without replacing existing text. This behaves much like SpriteBatch:add. Text:addf(textstring, wraplimit, alignmode, x, y, angle, sx, sy, ox, oy, kx, ky) -- adds a new formatted string to the text object using the specified relative coordinate transformation. Text:clear() -- clears all text from the object. --HG-- branch : minor
This commit is contained in:
@@ -177,28 +177,6 @@ void Matrix::shear(float kx, float ky)
|
||||
this->operator *=(t);
|
||||
}
|
||||
|
||||
// | x |
|
||||
// | y |
|
||||
// | 0 |
|
||||
// | 1 |
|
||||
// | e0 e4 e8 e12 |
|
||||
// | e1 e5 e9 e13 |
|
||||
// | e2 e6 e10 e14 |
|
||||
// | e3 e7 e11 e15 |
|
||||
|
||||
void Matrix::transform(Vertex *dst, const Vertex *src, int size) const
|
||||
{
|
||||
for (int i = 0; i<size; i++)
|
||||
{
|
||||
// Store in temp variables in case src = dst
|
||||
float x = (e[0]*src[i].x) + (e[4]*src[i].y) + (0) + (e[12]);
|
||||
float y = (e[1]*src[i].x) + (e[5]*src[i].y) + (0) + (e[13]);
|
||||
|
||||
dst[i].x = x;
|
||||
dst[i].y = y;
|
||||
}
|
||||
}
|
||||
|
||||
Matrix Matrix::ortho(float left, float right, float bottom, float top)
|
||||
{
|
||||
Matrix m;
|
||||
|
||||
+25
-1
@@ -153,7 +153,8 @@ public:
|
||||
* @param src The source vertices.
|
||||
* @param size The number of vertices.
|
||||
**/
|
||||
void transform(Vertex *dst, const Vertex *src, int size) const;
|
||||
template <typename V>
|
||||
void transform(V *dst, const V *src, int size) const;
|
||||
|
||||
/**
|
||||
* Creates a new orthographic projection matrix with depth in the range of
|
||||
@@ -173,6 +174,29 @@ private:
|
||||
|
||||
}; // Matrix
|
||||
|
||||
// | x |
|
||||
// | y |
|
||||
// | 0 |
|
||||
// | 1 |
|
||||
// | e0 e4 e8 e12 |
|
||||
// | e1 e5 e9 e13 |
|
||||
// | e2 e6 e10 e14 |
|
||||
// | e3 e7 e11 e15 |
|
||||
|
||||
template <typename V>
|
||||
void Matrix::transform(V *dst, const V *src, int size) const
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
// Store in temp variables in case src = dst
|
||||
float x = (e[0]*src[i].x) + (e[4]*src[i].y) + (0) + (e[12]);
|
||||
float y = (e[1]*src[i].x) + (e[5]*src[i].y) + (0) + (e[13]);
|
||||
|
||||
dst[i].x = x;
|
||||
dst[i].y = y;
|
||||
}
|
||||
}
|
||||
|
||||
} //love
|
||||
|
||||
#endif// LOVE_MATRIX_H
|
||||
|
||||
+4
-4
@@ -216,15 +216,15 @@ inline float Vector::normalize(float length)
|
||||
**/
|
||||
|
||||
inline Vector::Vector()
|
||||
: x(0.0f)
|
||||
, y(0.0f)
|
||||
{
|
||||
x = 1;
|
||||
y = 1;
|
||||
}
|
||||
|
||||
inline Vector::Vector(float x, float y)
|
||||
: x(x)
|
||||
, y(y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
inline Vector Vector::operator + (const Vector &v) const
|
||||
|
||||
@@ -652,6 +652,7 @@ StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[] =
|
||||
{"Canvas", GRAPHICS_CANVAS_ID},
|
||||
{"Shader", GRAPHICS_SHADER_ID},
|
||||
{"Mesh", GRAPHICS_MESH_ID},
|
||||
{"Text", GRAPHICS_TEXT_ID},
|
||||
|
||||
// Image
|
||||
{"ImageData", IMAGE_IMAGE_DATA_ID},
|
||||
|
||||
@@ -55,6 +55,7 @@ enum Type
|
||||
GRAPHICS_CANVAS_ID,
|
||||
GRAPHICS_SHADER_ID,
|
||||
GRAPHICS_MESH_ID,
|
||||
GRAPHICS_TEXT_ID,
|
||||
|
||||
// Image
|
||||
IMAGE_IMAGE_DATA_ID,
|
||||
@@ -141,6 +142,7 @@ const bits GRAPHICS_SPRITE_BATCH_T = (bits(1) << GRAPHICS_SPRITE_BATCH_ID) | GRA
|
||||
const bits GRAPHICS_CANVAS_T = (bits(1) << GRAPHICS_CANVAS_ID) | GRAPHICS_TEXTURE_T;
|
||||
const bits GRAPHICS_SHADER_T = (bits(1) << GRAPHICS_SHADER_ID) | OBJECT_T;
|
||||
const bits GRAPHICS_MESH_T = (bits(1) << GRAPHICS_MESH_ID) | GRAPHICS_DRAWABLE_T;
|
||||
const bits GRAPHICS_TEXT_T = (bits(1) << GRAPHICS_TEXT_ID) | GRAPHICS_DRAWABLE_T;
|
||||
|
||||
// Image.
|
||||
const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T;
|
||||
|
||||
Reference in New Issue
Block a user