From b3712ebdf148bd8d2d31e70734a4b7923f6038f8 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 6 Dec 2018 13:12:29 +0800 Subject: *remove create function --- src/libjin/graphics/fonts/je_texture_font.cpp | 148 ++++++++++++-------------- 1 file changed, 67 insertions(+), 81 deletions(-) (limited to 'src/libjin/graphics/fonts/je_texture_font.cpp') diff --git a/src/libjin/graphics/fonts/je_texture_font.cpp b/src/libjin/graphics/fonts/je_texture_font.cpp index 8facc34..9014509 100644 --- a/src/libjin/graphics/fonts/je_texture_font.cpp +++ b/src/libjin/graphics/fonts/je_texture_font.cpp @@ -17,28 +17,83 @@ namespace JinEngine namespace Fonts { - TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) + : Graphic(bitmap) + , Font(cellh) { - TextureFont* tf = new TextureFont(bitmap, codepoints, cellw, cellh); - return tf; + TextureGlyph glyph; + Vector2 count(bitmap->getWidth() / cellw, bitmap->getHeight() / cellh); + glyph.w = cellw; + glyph.h = cellh; + for (int y = 0; y < count.row; ++y) + { + glyph.y = y * cellh; + for (int x = 0; x < count.colum; ++x) + { + glyph.x = x * cellw; + if (x + y * count.colum >= codepoints.size()) + return; + glyphs.insert(std::pair(codepoints[x + y * count.colum], glyph)); + } + } } - TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, int cellw, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) + : Graphic(bitmap) + , Font(cellh) { - TextureFont* tf = new TextureFont(bitmap, *codepoints, cellw, cellh); - return tf; + TextureGlyph glyph; + glyph.h = cellh; + int w = bitmap->getWidth(); + int h = bitmap->getHeight(); + int i = 0; + for (int y = 0; y < h; y += cellh) + { + glyph.y = y; + bool newc = false; + for (int x = 0; x <= w; ++x) + { + if (x == w && newc) + { + glyph.w = x - glyph.x; + if (i >= codepoints.size()) + return; + glyphs.insert(std::pair(codepoints[i], glyph)); + ++i; + newc = false; + break; + } + Color c = bitmap->getPixels()[x + y * w]; + if (!newc && c != mask) + { + glyph.x = x; + newc = true; + } + else if (newc && c == mask) + { + glyph.w = x - glyph.x; + if (i >= codepoints.size()) + return; + glyphs.insert(std::pair(codepoints[i], glyph)); + if (codepoints[i] == 't') + { + int a = 10; + } + ++i; + newc = false; + } + } + } } - TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh) + : TextureFont(bitmap, *text, mask, cellh) { - TextureFont* tf = new TextureFont(bitmap, codepoints, mask, cellh); - return tf; } - TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, Color mask, int cellh) + TextureFont::TextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh) + : TextureFont(bitmap, *text, cellw, cellh) { - TextureFont* tf = new TextureFont(bitmap, *codepoints, mask, cellh); - return tf; } TextureFont::~TextureFont() @@ -248,75 +303,6 @@ namespace JinEngine delete page; } - TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh) - : Graphic(bitmap) - , Font(cellh) - { - TextureGlyph glyph; - Vector2 count(bitmap->getWidth() / cellw, bitmap->getHeight() / cellh); - glyph.w = cellw; - glyph.h = cellh; - for (int y = 0; y < count.row; ++y) - { - glyph.y = y * cellh; - for (int x = 0; x < count.colum; ++x) - { - glyph.x = x * cellw; - if (x + y * count.colum >= codepoints.size()) - return; - glyphs.insert(std::pair(codepoints[x + y * count.colum], glyph)); - } - } - } - - TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh) - : Graphic(bitmap) - , Font(cellh) - { - TextureGlyph glyph; - glyph.h = cellh; - int w = bitmap->getWidth(); - int h = bitmap->getHeight(); - int i = 0; - for (int y = 0; y < h; y += cellh) - { - glyph.y = y; - bool newc = false; - for (int x = 0; x <= w; ++x) - { - if (x == w && newc) - { - glyph.w = x - glyph.x; - if (i >= codepoints.size()) - return; - glyphs.insert(std::pair(codepoints[i], glyph)); - ++i; - newc = false; - break; - } - Color c = bitmap->getPixels()[x + y * w]; - if (!newc && c != mask) - { - glyph.x = x; - newc = true; - } - else if (newc && c == mask) - { - glyph.w = x - glyph.x; - if (i >= codepoints.size()) - return; - glyphs.insert(std::pair(codepoints[i], glyph)); - if (codepoints[i] == 't') - { - int a = 10; - } - ++i; - newc = false; - } - } - } - } - } } } \ No newline at end of file -- cgit v1.1-26-g67d0