diff options
author | chai <chaifix@163.com> | 2018-10-10 19:06:46 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-10-10 19:06:46 +0800 |
commit | d6263f17643654ccee4e304a048781be38a9e08d (patch) | |
tree | 01f025947444be9f6ecd9a082b19393b3e7e6b19 | |
parent | f435df9cdfcb6d1b2a4c916ae61d5af0762e171b (diff) |
*update
-rw-r--r-- | libjin/Graphics/Color.h | 6 | ||||
-rw-r--r-- | libjin/Graphics/Font.h | 7 | ||||
-rw-r--r-- | libjin/Graphics/Graphics.h | 1 | ||||
-rw-r--r-- | libjin/Graphics/TTF.cpp | 22 | ||||
-rw-r--r-- | libjin/Graphics/TTF.h | 12 | ||||
-rw-r--r-- | libjin/Graphics/TexFont.cpp | 25 | ||||
-rw-r--r-- | libjin/Graphics/TexFont.h | 16 | ||||
-rw-r--r-- | libjin/Math/Vector4.hpp | 1 |
8 files changed, 49 insertions, 41 deletions
diff --git a/libjin/Graphics/Color.h b/libjin/Graphics/Color.h index 6f9e887..3de49dc 100644 --- a/libjin/Graphics/Color.h +++ b/libjin/Graphics/Color.h @@ -76,12 +76,6 @@ namespace graphics Channel r, g, b, a; - //#if LIBJIN_BYTEORDER == LIBJIN_BIG_ENDIAN - // unsigned char r, g, b, a; - //#else - // unsigned char a, b, g, r; - //#endif - }; } // render diff --git a/libjin/Graphics/Font.h b/libjin/Graphics/Font.h index cdf2d54..6b8cc73 100644 --- a/libjin/Graphics/Font.h +++ b/libjin/Graphics/Font.h @@ -1,5 +1,6 @@ #ifndef __LIBJIN_FONT_H #define __LIBJIN_FONT_H +#include <vector> namespace jin { @@ -8,6 +9,8 @@ namespace graphics typedef unsigned int Codepoint; + typedef std::vector<Codepoint> Sentence; + struct Page; class Font @@ -17,8 +20,8 @@ namespace graphics virtual ~Font() {}; virtual void print(const Page* page, int x, int y) = 0; - virtual void print(const std::vector<Codepoint>& text, int x, int y, int lineheight, int spacing = 0) = 0; - virtual Page* typeset(const std::vector<Codepoint>& text, int lineheight, int spacing = 0) = 0; + virtual void print(const Sentence& text, int x, int y, int lineheight, int spacing = 0) = 0; + virtual Page* typeset(const Sentence& text, int lineheight, int spacing = 0) = 0; }; diff --git a/libjin/Graphics/Graphics.h b/libjin/Graphics/Graphics.h index a4bf98b..7c11122 100644 --- a/libjin/Graphics/Graphics.h +++ b/libjin/Graphics/Graphics.h @@ -5,7 +5,6 @@ #include "canvas.h" #include "color.h" -#include "FontData.h" #include "Font.h" #include "Shapes.h" #include "texture.h" diff --git a/libjin/Graphics/TTF.cpp b/libjin/Graphics/TTF.cpp index 5988296..6833610 100644 --- a/libjin/Graphics/TTF.cpp +++ b/libjin/Graphics/TTF.cpp @@ -234,14 +234,14 @@ namespace graphics return t; } - void TTF::print(const std::vector<Codepoint>& t, int x, int y, int lineheight, int spacing) + void TTF::print(const Sentence& t, int x, int y, int lineheight, int spacing) { Page* page = typeset(t, lineheight, spacing); print(page, x, y); delete page; } - Page* TTF::typeset(const std::vector<Codepoint>& text, int lineheight, int spacing) + Page* TTF::typeset(const Sentence& text, int lineheight, int spacing) { Page* page = new Page(); page->font = this; @@ -279,10 +279,10 @@ glyphvertices.push_back(vertex); } glyphinfolist[glyphinfolist.size() - 1].count += 4; TTFGlyph::Bbox& bbox = glyph->bbox; - glyphvertices_push(p.x, p.y, bbox.x, bbox.y); - glyphvertices_push(p.x, p.y + glyph->height, bbox.x, bbox.y + bbox.height); - glyphvertices_push(p.x + glyph->width, p.y + glyph->height, bbox.x + bbox.width, bbox.y + bbox.height); - glyphvertices_push(p.x + glyph->width, p.y, bbox.x + bbox.width, bbox.y); + glyphvertices_push(p.x, p.y, bbox.x, bbox.y); + glyphvertices_push(p.x, p.y + glyph->height, bbox.x, bbox.y + bbox.h); + glyphvertices_push(p.x + glyph->width, p.y + glyph->height, bbox.x + bbox.w, bbox.y + bbox.h); + glyphvertices_push(p.x + glyph->width, p.y, bbox.x + bbox.w, bbox.y); p.x += glyph->width + spacing; @@ -326,7 +326,7 @@ glyphvertices.push_back(vertex); return descent; } - int TTF::getTextWidth(const std::vector<Codepoint>& t, int spacing) + int TTF::getTextWidth(const Sentence& t, int spacing) { ttf->pushTTFsize(ttfsize); int res = 0; @@ -348,7 +348,7 @@ glyphvertices.push_back(vertex); return res; } - int TTF::getTextHeight(const std::vector<Codepoint>& t, int lineheight) + int TTF::getTextHeight(const Sentence& t, int lineheight) { ttf->pushTTFsize(ttfsize); int res = 0; @@ -368,7 +368,7 @@ glyphvertices.push_back(vertex); return res; } - void TTF::getTextBox(const std::vector<Codepoint>& text, int* w, int* h, int lineheight, int spacing) + void TTF::getTextBox(const Sentence& text, int* w, int* h, int lineheight, int spacing) { ttf->pushTTFsize(ttfsize); *w = 0; @@ -427,8 +427,8 @@ glyphvertices.push_back(vertex); glyph->atlas = atlas; glyph->bbox.x = cursor.x / (float)textureWidth; glyph->bbox.y = cursor.y / (float)textureHeight; - glyph->bbox.width = adw / (float)textureWidth; - glyph->bbox.height = descent / (float)textureHeight; + glyph->bbox.w = adw / (float)textureWidth; + glyph->bbox.h = descent / (float)textureHeight; glyph->width = adw; glyph->height = descent; glyphs.insert(std::pair<unsigned int, TTFGlyph*>(character, glyph)); diff --git a/libjin/Graphics/TTF.h b/libjin/Graphics/TTF.h index d2459ba..aa1ed31 100644 --- a/libjin/Graphics/TTF.h +++ b/libjin/Graphics/TTF.h @@ -52,8 +52,8 @@ namespace graphics public: static TTF* createTTF(TTFData* ttfData, unsigned int ttfSzie); - Page* typeset(const std::vector<Codepoint>& text, int lineheight, int spacing) override; - void print(const std::vector<Codepoint>& text, int x, int y, int lineheight, int spacing = 0) override; + Page* typeset(const Sentence& text, int lineheight, int spacing) override; + void print(const Sentence& text, int x, int y, int lineheight, int spacing = 0) override; void print(const Page* page, int x, int y) override ; #if defined(ttf_debug) void drawAtlas(); @@ -68,7 +68,7 @@ namespace graphics struct Bbox { float x, y; - float width, height; + float w, h; } bbox; /* glyph size in pixel */ unsigned int width, height; @@ -88,9 +88,9 @@ namespace graphics int getCharWidth(int c); int getCharHeight(int c); - int getTextWidth(const std::vector<Codepoint>& text, int spacing = 0); - int getTextHeight(const std::vector<Codepoint>& text, int lineheight); - void getTextBox(const std::vector<Codepoint>& text, int* w, int* h, int lineheight, int spacing = 0); + int getTextWidth(const Sentence& text, int spacing = 0); + int getTextHeight(const Sentence& text, int lineheight); + void getTextBox(const Sentence& text, int* w, int* h, int lineheight, int spacing = 0); int textureWidth; int textureHeight; diff --git a/libjin/Graphics/TexFont.cpp b/libjin/Graphics/TexFont.cpp index 4c6c66b..a000b1c 100644 --- a/libjin/Graphics/TexFont.cpp +++ b/libjin/Graphics/TexFont.cpp @@ -17,23 +17,24 @@ namespace graphics */ /* create texture font from tilemap */ - TexFont * TexFont::createTexFont(const Bitmap* bitmap, const std::vector<Codepoint>& codepoints, int cellw, int cellh, int l, int r, int t, int b) + TexFont * TexFont::createTexFont(const Bitmap* bitmap, const Sentence& codepoints, int cellw, int cellh, const math::Vector4<int>& spacing) { - + TexFont* tf = new TexFont(bitmap, codepoints, cellw, cellh, spacing); + return tf; } /* create texture font from seperated glyphs */ - TexFont* TexFont::createTexFont(const Bitmap* bitmap, const std::vector<Codepoint>& codepoints, Color mask, int cellh, int l, int r, int t, int b) + TexFont* TexFont::createTexFont(const Bitmap* bitmap, const Sentence& codepoints, Color mask, int cellh, const math::Vector4<int>& spacing) { - + TexFont* tf = new TexFont(bitmap, codepoints, mask, cellh, spacing); + return tf; } TexFont::~TexFont() { - } - Page* TexFont::typeset(const std::vector<Codepoint>& text, int lineheight, int spacing = 0) + Page* TexFont::typeset(const Sentence& text, int lineheight, int spacing = 0) { } @@ -43,14 +44,22 @@ namespace graphics } - void TexFont::print(const std::vector<Codepoint>& text, int x, int y, int linehgiht, int spacing = 0) + void TexFont::print(const Sentence& text, int x, int y, int linehgiht, int spacing) { } - TexFont::TexFont(const Bitmap* bitmap) + TexFont::TexFont(const Bitmap* bitmap, const Sentence& codepoints, int cellw, int cellh, const math::Vector4<int>& spacing) : Drawable(bitmap) { + int l, r, t, b; + + } + + TexFont::TexFont(const Bitmap* bitmap, const Sentence& codepoints, Color mask, int cellh, const math::Vector4<int>& spacing) + : Drawable(bitmap) + { + } } diff --git a/libjin/Graphics/TexFont.h b/libjin/Graphics/TexFont.h index fcc00b1..d830fc2 100644 --- a/libjin/Graphics/TexFont.h +++ b/libjin/Graphics/TexFont.h @@ -4,35 +4,37 @@ #include <map> #include <vector> +#include "Drawable.h" #include "Page.h" #include "Bitmap.h" #include "Font.h" -#include "Drawable.h" +#include "../Math/Vector4.hpp" namespace jin { namespace graphics { - + class TexFont : public Font , public Drawable { public: /* create texture font from tilemap */ - static TexFont * createTexFont(const Bitmap* bitmap, const std::vector<Codepoint>& codepoints, int cellw, int cellh, int l = 0, int r = 0, int t = 0, int b = 0); + static TexFont* createTexFont(const Bitmap* bitmap, const Sentence& codepoints, int cellw, int cellh, const math::Vector4<int>& spacing = math::Vector4<int>()); /* create texture font from seperated glyphs */ - static TexFont* createTexFont(const Bitmap* bitmap, const std::vector<Codepoint>& codepoints, Color mask, int cellh, int l = 0, int r = 0, int t = 0, int b = 0); + static TexFont* createTexFont(const Bitmap* bitmap, const Sentence& codepoints, Color mask, int cellh, const math::Vector4<int>& spacing = math::Vector4<int>()); ~TexFont(); - Page* typeset(const std::vector<Codepoint>& text, int lineheight, int spacing = 0) override ; + Page* typeset(const Sentence& text, int lineheight, int spacing = 0) override ; void print(const Page* page, int x, int y) override; - void print(const std::vector<Codepoint>& text, int x, int y, int linehgiht, int spacing = 0) override; + void print(const Sentence& text, int x, int y, int linehgiht, int spacing = 0) override; private: struct TexGlyph { unsigned short x, y, w, h;}; - TexFont(const Bitmap* bitmap); + TexFont(const Bitmap* bitmap, const Sentence& codepoints, int cellw, int cellh, const math::Vector4<int>& spacing); + TexFont(const Bitmap* bitmap, const Sentence& codepoints, Color mask, int cellh, const math::Vector4<int>& spacing); std::map<Codepoint, TexGlyph> glyphs; diff --git a/libjin/Math/Vector4.hpp b/libjin/Math/Vector4.hpp index c7dfaa8..da4110f 100644 --- a/libjin/Math/Vector4.hpp +++ b/libjin/Math/Vector4.hpp @@ -32,6 +32,7 @@ namespace math T &x = data[0], &y = data[1], &z = data[2], &t = data[3]; // xyzt T &w = data[2], &h = data[3]; // xywh T &r = data[0], &g = data[1], &b = data[2], &a = data[3]; // rgb + T &left = data[0], &right = data[1], &top = data[2], &bottom = data[3]; // lrtb private: T data[4]; |