diff --git a/desmume/src/agg2d.h b/desmume/src/agg2d.h index bcdc082f5..3bdea1c39 100644 --- a/desmume/src/agg2d.h +++ b/desmume/src/agg2d.h @@ -325,6 +325,8 @@ public: double m_masterAlpha; double m_antiAliasGamma; + const agg::int8u* m_font; + Color m_fillColor; Color m_lineColor; GradientArray m_fillGradient; @@ -407,6 +409,8 @@ public: void antiAliasGamma(double g); double antiAliasGamma() const; + void font(const agg::int8u* font) { m_font = font; } + void fillColor(Color c); void fillColor(unsigned r, unsigned g, unsigned b, unsigned a = 255); void noFill(); @@ -683,6 +687,36 @@ public: } } + + void renderText(double dstX, double dstY, const std::string& str) +{ + worldToScreen(dstX, dstY); + PixFormat pixF(m_rbuf); + //Rect r(imgX1, imgY1, imgX2, imgY2); + + typedef agg::glyph_raster_bin glyph_gen; + glyph_gen glyph(0); + + if(m_blendMode == BlendAlpha) + { + typedef agg::renderer_base ren_base; + agg::renderer_raster_htext_solid rt(m_renBasePre,glyph); + rt.color(m_lineColor); + glyph.font(m_font); + rt.render_text(dstX, dstY, str.c_str(), true); //flipy + } + else + { + typedef agg::renderer_base ren_base; + agg::renderer_raster_htext_solid rt(m_renBaseCompPre,glyph); + rt.color(m_lineColor); + glyph.font(m_font); + rt.render_text(dstX, dstY, str.c_str(), true); //flipy + } + + +} + AGG2D_IMAGE_TEMPLATE void blendImage(TIMAGE& img, double dstX, double dstY, unsigned alpha=255) { @@ -800,6 +834,8 @@ private: double m_masterAlpha; double m_antiAliasGamma; + const agg::int8u* m_font; + Color m_fillColor; Color m_lineColor; GradientArray m_fillGradient; diff --git a/desmume/src/agg2d.inl b/desmume/src/agg2d.inl index 866e521a6..02b1c77ea 100644 --- a/desmume/src/agg2d.inl +++ b/desmume/src/agg2d.inl @@ -70,6 +70,7 @@ AGG2D_TEMPLATE inline TAGG2D::Agg2D() : m_masterAlpha(1.0), m_antiAliasGamma(1.0), + m_font(agg::gse4x6), m_fillColor(255, 255, 255), m_lineColor(0, 0, 0), m_fillGradient(), @@ -146,6 +147,7 @@ AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::saveStateTo(State& st) st.m_masterAlpha = m_masterAlpha; st.m_antiAliasGamma = m_antiAliasGamma; + st.m_font = m_font; st.m_fillColor = m_fillColor; st.m_lineColor = m_lineColor; st.m_fillGradient = m_fillGradient; @@ -192,6 +194,7 @@ AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::restoreStateFrom(const State& st) m_masterAlpha = st.m_masterAlpha; m_antiAliasGamma = st.m_antiAliasGamma; + m_font = st.m_font; m_fillColor = st.m_fillColor; m_lineColor = st.m_lineColor; m_fillGradient = st.m_fillGradient; diff --git a/desmume/src/aggdraw.cpp b/desmume/src/aggdraw.cpp index d7d4e6abe..23a28b20d 100644 --- a/desmume/src/aggdraw.cpp +++ b/desmume/src/aggdraw.cpp @@ -63,6 +63,66 @@ #include "agg_span_allocator.h" + +typedef std::map TAgg_Font_Table; +static TAgg_Font_Table font_table; + +const agg::int8u* AggDrawTarget::lookupFont(const std::string& name) +{ + TAgg_Font_Table::iterator it(font_table.find(name)); + if(it == font_table.end()) return NULL; + else return it->second; +} + +static void Agg_init_fonts() +{ + struct font_type + { + const agg::int8u* font; + const char* name; + } + fonts[] = + { + { agg::gse4x6, "gse4x6" }, + { agg::gse4x8, "gse4x8" }, + { agg::gse5x7, "gse5x7" }, + { agg::gse5x9, "gse5x9" }, + { agg::gse6x9, "gse6x9" }, + { agg::gse6x12, "gse6x12" }, + { agg::gse7x11, "gse7x11" }, + { agg::gse7x11_bold, "gse7x11_bold" }, + { agg::gse7x15, "gse7x15" }, + { agg::gse7x15_bold, "gse7x15_bold" }, + { agg::gse8x16, "gse8x16" }, + { agg::gse8x16_bold, "gse8x16_bold" }, + { agg::mcs11_prop, "mcs11_prop" }, + { agg::mcs11_prop_condensed, "mcs11_prop_condensed" }, + { agg::mcs12_prop, "mcs12_prop" }, + { agg::mcs13_prop, "mcs13_prop" }, + { agg::mcs5x10_mono, "mcs5x10_mono" }, + { agg::mcs5x11_mono, "mcs5x11_mono" }, + { agg::mcs6x10_mono, "mcs6x10_mono" }, + { agg::mcs6x11_mono, "mcs6x11_mono" }, + { agg::mcs7x12_mono_high, "mcs7x12_mono_high" }, + { agg::mcs7x12_mono_low, "mcs7x12_mono_low" }, + { agg::verdana12, "verdana12" }, + { agg::verdana12_bold, "verdana12_bold" }, + { agg::verdana13, "verdana13" }, + { agg::verdana13_bold, "verdana13_bold" }, + { agg::verdana14, "verdana14" }, + { agg::verdana14_bold, "verdana14_bold" }, + { agg::verdana16, "verdana16" }, + { agg::verdana16_bold, "verdana16_bold" }, + { agg::verdana17, "verdana17" }, + { agg::verdana17_bold, "verdana17_bold" }, + { agg::verdana18, "verdana18" }, + { agg::verdana18_bold, "verdana18_bold" }, + }; + + for(int i=0;i > T_AGG_RGB555; @@ -84,6 +144,7 @@ static AggDrawTarget* targets[] = { void Agg_init() { + Agg_init_fonts(); aggDraw.target = targets[0]; } @@ -100,21 +161,21 @@ void AggDraw_Desmume::composite(void* dest) if(!agg_targetLua.empty) { T_AGG_RGBA::MyImage luaImage(agg_targetLua.buf()); - target.transformImage(luaImage, 0.5,0.5,256-0.5,384-0.5); + target.transformImage(luaImage, 0,0,256-1,384-1); } //if hud is nonempty, blend it if(!agg_targetHud.empty) { T_AGG_RGBA::MyImage hudImage(agg_targetHud.buf()); - target.transformImage(hudImage, 0.5,0.5,256-0.5,384-0.5); + target.transformImage(hudImage, 0,0,256-1,384-1); } } //temporary, just for testing the lib void AGGDraw() { - aggDraw.setTarget(AggTarget_Lua); + aggDraw.setTarget(AggTarget_Hud); aggDraw.target->clear(); @@ -123,6 +184,10 @@ void AGGDraw() { //aggDraw.target->noFill(); aggDraw.target->lineWidth(1.0); aggDraw.target->roundedRect(10,10,256-10,192-10,4); + + aggDraw.target->setFont("verdana18_bold"); + aggDraw.target->renderText(60,60, "testing testing testing"); + } diff --git a/desmume/src/aggdraw.h b/desmume/src/aggdraw.h index 1c6fd55a9..228d8214d 100644 --- a/desmume/src/aggdraw.h +++ b/desmume/src/aggdraw.h @@ -69,6 +69,10 @@ public: virtual void roundedRect(double x1, double y1, double x2, double y2,double rx_bottom, double ry_bottom,double rx_top, double ry_top) = 0; virtual void roundedRect(double x1, double y1, double x2, double y2, double r) = 0; virtual void roundedRect(double x1, double y1, double x2, double y2, double rx, double ry) = 0; + + static const agg::int8u* lookupFont(const std::string& name); + virtual void setFont(const std::string& name) = 0; + virtual void renderText(double dstX, double dstY, const std::string& str) = 0; }; @@ -84,7 +88,7 @@ public: { attach(buf,width,height,stride); - BASE::viewport(0, 0, width-1, height-1, 0.5, 0.5, width-0.5, height-0.5, TAGG2D::Anisotropic); + BASE::viewport(0, 0, width-1, height-1, 0, 0, width-1, height-1, TAGG2D::Anisotropic); } virtual void clear() { @@ -105,6 +109,9 @@ public: virtual void roundedRect(double x1, double y1, double x2, double y2,double rx_bottom, double ry_bottom,double rx_top,double ry_top) { dirty(); BASE::roundedRect(x1,y1,x2,y2,rx_bottom,ry_bottom,rx_top,ry_top); } virtual void roundedRect(double x1, double y1, double x2, double y2, double r) { dirty(); BASE::roundedRect(x1,y1,x2,y2,r); } virtual void roundedRect(double x1, double y1, double x2, double y2, double rx, double ry) { dirty(); BASE::roundedRect(x1,y1,x2,y2,rx,ry); } + + virtual void setFont(const std::string& name) { BASE::font(lookupFont(name)); } + virtual void renderText(double dstX, double dstY, const std::string& str) { dirty(); BASE::renderText(dstX, dstY, str); } }; class AggDraw