mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Update minor
--HG-- branch : minor
This commit is contained in:
@@ -112,6 +112,7 @@ StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM>::Entry Graphics::alignM
|
||||
{ "left", Graphics::ALIGN_LEFT },
|
||||
{ "right", Graphics::ALIGN_RIGHT },
|
||||
{ "center", Graphics::ALIGN_CENTER },
|
||||
{ "justify", Graphics::ALIGN_JUSTIFY },
|
||||
};
|
||||
|
||||
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM> Graphics::alignModes(Graphics::alignModeEntries, sizeof(Graphics::alignModeEntries));
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
ALIGN_LEFT = 1,
|
||||
ALIGN_CENTER,
|
||||
ALIGN_RIGHT,
|
||||
ALIGN_JUSTIFY,
|
||||
ALIGN_MAX_ENUM
|
||||
};
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ float Font::getHeight() const
|
||||
return static_cast<float>(height);
|
||||
}
|
||||
|
||||
void Font::print(std::string text, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
||||
void Font::print(std::string text, float x, float y, float letter_spacing, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
||||
{
|
||||
float dx = 0.0f; // spacing counter for newline handling
|
||||
glPushMatrix();
|
||||
@@ -207,8 +207,8 @@ void Font::print(std::string text, float x, float y, float angle, float sx, floa
|
||||
bindTexture(glyph->texture);
|
||||
glCallList(glyph->list);
|
||||
glPopMatrix();
|
||||
glTranslatef(static_cast<GLfloat>(glyph->spacing), 0, 0);
|
||||
dx += glyph->spacing;
|
||||
glTranslatef(static_cast<GLfloat>(glyph->spacing + letter_spacing), 0, 0);
|
||||
dx += glyph->spacing + letter_spacing;
|
||||
}
|
||||
}
|
||||
catch(utf8::exception &e)
|
||||
@@ -234,36 +234,45 @@ void Font::print(char character, float x, float y)
|
||||
}
|
||||
}
|
||||
|
||||
int Font::getWidth(const std::string &line)
|
||||
int Font::getWidth(const std::string &str)
|
||||
{
|
||||
if (line.size() == 0) return 0;
|
||||
int temp = 0;
|
||||
if (str.size() == 0) return 0;
|
||||
|
||||
std::istringstream iss(str);
|
||||
std::string line;
|
||||
Glyph *g;
|
||||
int max_width = 0;
|
||||
|
||||
try
|
||||
while (getline(iss, line, '\n'))
|
||||
{
|
||||
utf8::iterator<std::string::const_iterator> i(line.begin(), line.begin(), line.end());
|
||||
utf8::iterator<std::string::const_iterator> end(line.end(), line.begin(), line.end());
|
||||
while (i != end)
|
||||
int width = 0;
|
||||
try
|
||||
{
|
||||
int c = *i++;
|
||||
g = glyphs[c];
|
||||
if (!g) g = addGlyph(c);
|
||||
temp += static_cast<int>(g->spacing * mSpacing);
|
||||
utf8::iterator<std::string::const_iterator> i(line.begin(), line.begin(), line.end());
|
||||
utf8::iterator<std::string::const_iterator> end(line.end(), line.begin(), line.end());
|
||||
while (i != end)
|
||||
{
|
||||
int c = *i++;
|
||||
g = glyphs[c];
|
||||
if (!g) g = addGlyph(c);
|
||||
width += static_cast<int>(g->spacing * mSpacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("%s", e.what());
|
||||
catch(utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("%s", e.what());
|
||||
}
|
||||
|
||||
if (width > max_width)
|
||||
max_width = width;
|
||||
}
|
||||
|
||||
return temp;
|
||||
return max_width;
|
||||
}
|
||||
|
||||
int Font::getWidth(const char *line)
|
||||
int Font::getWidth(const char *str)
|
||||
{
|
||||
return this->getWidth(std::string(line));
|
||||
return this->getWidth(std::string(str));
|
||||
}
|
||||
|
||||
int Font::getWidth(const char character)
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
* @param text A string.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param letter_spacing Additional spacing between letters.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx Scale along the x axis.
|
||||
* @param sy Scale along the y axis.
|
||||
@@ -68,7 +69,7 @@ public:
|
||||
* @param kx Shear along the x axis.
|
||||
* @param ky Shear along the y axis.
|
||||
**/
|
||||
void print(std::string text, float x, float y, float angle = 0.0f, float sx = 1.0f, float sy = 1.0f, float ox = 0.0f, float oy = 0.0f, float kx = 0.0f, float ky = 0.0f);
|
||||
void print(std::string text, float x, float y, float letter_spacing = 0.0f, float angle = 0.0f, float sx = 1.0f, float sy = 1.0f, float ox = 0.0f, float oy = 0.0f, float kx = 0.0f, float ky = 0.0f);
|
||||
|
||||
/**
|
||||
* Prints the character at the designated position.
|
||||
|
||||
@@ -113,7 +113,7 @@ bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int f
|
||||
if (isCreated())
|
||||
tempState = saveState();
|
||||
|
||||
// Unlad all volatile objects. These must be reloaded after
|
||||
// Unload all volatile objects. These must be reloaded after
|
||||
// the display mode change.
|
||||
Volatile::unloadAll();
|
||||
|
||||
@@ -402,7 +402,7 @@ Canvas *Graphics::newCanvas(int width, int height)
|
||||
Canvas *canvas = new Canvas(width, height);
|
||||
GLenum err = canvas->getStatus();
|
||||
|
||||
// everything ok, reaturn canvas (early out)
|
||||
// everything ok, return canvas (early out)
|
||||
if (err == GL_FRAMEBUFFER_COMPLETE)
|
||||
return canvas;
|
||||
|
||||
@@ -516,8 +516,6 @@ Font *Graphics::getFont()
|
||||
|
||||
void Graphics::setBlendMode(Graphics::BlendMode mode)
|
||||
{
|
||||
glAlphaFunc(GL_GEQUAL, 0);
|
||||
|
||||
if (GLEE_VERSION_1_4 || GLEE_ARB_imaging)
|
||||
{
|
||||
if (mode == BLEND_SUBTRACTIVE)
|
||||
@@ -686,7 +684,7 @@ void Graphics::print(const char *str, float x, float y , float angle, float sx,
|
||||
if (currentFont != 0)
|
||||
{
|
||||
std::string text(str);
|
||||
currentFont->print(text, x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
currentFont->print(text, x, y, 0.0, angle, sx, sy, ox, oy, kx, ky);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,6 +699,7 @@ void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode a
|
||||
|
||||
// now for the actual printing
|
||||
vector<string>::const_iterator line_iter, line_end = lines_to_draw.end();
|
||||
float letter_spacing = 0.0f;
|
||||
for (line_iter = lines_to_draw.begin(); line_iter != line_end; ++line_iter)
|
||||
{
|
||||
float width = static_cast<float>(currentFont->getWidth(*line_iter));
|
||||
@@ -712,6 +711,13 @@ void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode a
|
||||
case ALIGN_CENTER:
|
||||
currentFont->print(*line_iter, ceil(x + (wrap - width) / 2), ceil(y));
|
||||
break;
|
||||
case ALIGN_JUSTIFY:
|
||||
if (line_iter->length() > 1 && (line_iter+1) != line_end)
|
||||
letter_spacing = (wrap - width) / float(line_iter->length() - 1);
|
||||
else
|
||||
letter_spacing = 0.0f;
|
||||
currentFont->print(*line_iter, ceil(x), ceil(y), letter_spacing);
|
||||
break;
|
||||
case ALIGN_LEFT:
|
||||
default:
|
||||
currentFont->print(*line_iter, ceil(x), ceil(y));
|
||||
|
||||
@@ -211,7 +211,7 @@ public:
|
||||
int getModes(lua_State *L);
|
||||
|
||||
/**
|
||||
* Scissor defines a box such that everything outside that box is discared and not drawn.
|
||||
* Scissor defines a box such that everything outside that box is discarded and not drawn.
|
||||
* Scissoring is automatically enabled.
|
||||
* @param x The x-coordinate of the top-left corner.
|
||||
* @param y The y-coordinate of the top-left corner.
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* VertexBuffer is an abstraction over VBOs (Vertex Buffer Objecys), which
|
||||
* VertexBuffer is an abstraction over VBOs (Vertex Buffer Objects), which
|
||||
* falls back to regular vertex arrays if VBOs are not supported.
|
||||
*
|
||||
* This allows code to take advantage of VBOs where available, but still
|
||||
|
||||
@@ -249,7 +249,7 @@ int w_newQuad(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newFont1(lua_State *L)
|
||||
int w_newFont(lua_State *L)
|
||||
{
|
||||
Data *font_data = NULL;
|
||||
// Convert to File, if necessary.
|
||||
@@ -745,8 +745,9 @@ int w_setCanvas(lua_State *L)
|
||||
// discard stencil testing
|
||||
instance->discardStencil();
|
||||
|
||||
// called with nil or none -> reset to default buffer
|
||||
if (lua_isnoneornil(L,1))
|
||||
// called with none -> reset to default buffer
|
||||
// nil is an error, to help people with typoes
|
||||
if (lua_isnone(L,1))
|
||||
{
|
||||
Canvas::bindDefaultCanvas();
|
||||
return 0;
|
||||
@@ -911,7 +912,7 @@ int w_drawTest(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_print1(lua_State *L)
|
||||
int w_print(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
@@ -934,7 +935,7 @@ int w_print1(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_printf1(lua_State *L)
|
||||
int w_printf(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
@@ -1225,7 +1226,7 @@ static const luaL_Reg functions[] =
|
||||
|
||||
{ "newImage", w_newImage },
|
||||
{ "newQuad", w_newQuad },
|
||||
{ "newFont1", w_newFont1 },
|
||||
{ "newFont", w_newFont },
|
||||
{ "newImageFont", w_newImageFont },
|
||||
{ "newSpriteBatch", w_newSpriteBatch },
|
||||
{ "newParticleSystem", w_newParticleSystem },
|
||||
@@ -1270,8 +1271,8 @@ static const luaL_Reg functions[] =
|
||||
{ "drawq", w_drawq },
|
||||
{ "drawTest", w_drawTest },
|
||||
|
||||
{ "print1", w_print1 },
|
||||
{ "printf1", w_printf1 },
|
||||
{ "print", w_print },
|
||||
{ "printf", w_printf },
|
||||
|
||||
{ "setCaption", w_setCaption },
|
||||
{ "getCaption", w_getCaption },
|
||||
|
||||
@@ -58,7 +58,7 @@ int w_setMask(lua_State *L);
|
||||
int w_newImage(lua_State *L);
|
||||
int w_newQuad(lua_State *L);
|
||||
int w_newFrame(lua_State *L);
|
||||
int w_newFont1(lua_State *L);
|
||||
int w_newFont(lua_State *L);
|
||||
int w_newImageFont(lua_State *L);
|
||||
int w_newSpriteBatch(lua_State *L);
|
||||
int w_newParticleSystem(lua_State *L);
|
||||
@@ -95,8 +95,8 @@ int w_isSupported(lua_State *L);
|
||||
int w_draw(lua_State *L);
|
||||
int w_drawq(lua_State *L);
|
||||
int w_drawTest(lua_State *L);
|
||||
int w_print1(lua_State *L);
|
||||
int w_printf1(lua_State *L);
|
||||
int w_print(lua_State *L);
|
||||
int w_printf(lua_State *L);
|
||||
int w_point(lua_State *L);
|
||||
int w_line(lua_State *L);
|
||||
int w_triangle(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user