# HG changeset patch # User helios2000@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1280843832 0 # Node ID 5e04f634989474e452fde4b414825bea35bc38ef # Parent 1e69fd582c94c83155108189554a352a20e2a1df * Improved the floatingtextrenderer. You can now set a background speech quad. * Added a speech quad example to rio de hola. * Little fix to the editor stuff. diff -r 1e69fd582c94 -r 5e04f6349894 demos/rio_de_hola/scripts/world.py --- a/demos/rio_de_hola/scripts/world.py Mon Aug 02 10:26:21 2010 +0000 +++ b/demos/rio_de_hola/scripts/world.py Tue Aug 03 13:57:12 2010 +0000 @@ -233,6 +233,7 @@ textfont = self.engine.getGuiManager().createFont('fonts/rpgfont.png', 0, str(TDS.get("FIFE", "FontGlyphs"))); renderer.changeDefaultFont(textfont) renderer.activateAllLayers(self.map) + renderer.setDefaultBackground(100, 255, 100, 50, 255, 50) renderer.setEnabled(True) # Activate the grid renderer on all layers diff -r 1e69fd582c94 -r 5e04f6349894 engine/core/view/renderers/floatingtextrenderer.cpp --- a/engine/core/view/renderers/floatingtextrenderer.cpp Mon Aug 02 10:26:21 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.cpp Tue Aug 03 13:57:12 2010 +0000 @@ -47,6 +47,7 @@ FloatingTextRenderer::FloatingTextRenderer(RenderBackend* renderbackend, int position, AbstractFont* font): RendererBase(renderbackend, position), + m_renderbackend(renderbackend), m_font(font) { setEnabled(false); m_font_color = false; @@ -55,6 +56,7 @@ FloatingTextRenderer::FloatingTextRenderer(const FloatingTextRenderer& old): RendererBase(old), + m_renderbackend(old.m_renderbackend), m_font(old.m_font), m_font_color(old.m_font_color), m_color(old.m_color) { @@ -91,6 +93,20 @@ r.y = ir.y- img->getHeight(); /// make the text rect floating higher than the instance. r.w = img->getWidth(); r.h = img->getHeight(); + if(m_background) { + const int overdraw = 5; + Point p1 = Point(r.x-overdraw, r.y-overdraw); + Point p2 = Point(r.x+r.w+overdraw, r.y-overdraw); + Point p3 = Point(r.x+r.w+overdraw, r.y+r.h+overdraw); + Point p4 = Point(r.x-overdraw, r.y+r.h+overdraw); + + m_renderbackend->drawQuad(p1, p2, p3, p4, m_backcolor.r, m_backcolor.g, m_backcolor.b); + + m_renderbackend->drawLine(p1, p2, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); + m_renderbackend->drawLine(p2, p3, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); + m_renderbackend->drawLine(p3, p4, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); + m_renderbackend->drawLine(p4, p1, m_backbordercolor.r, m_backbordercolor.g, m_backbordercolor.b); + } img->render(r); } } @@ -106,6 +122,22 @@ m_color.b = b; } + void FloatingTextRenderer::setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 bbr, Uint8 bbg, Uint8 bbb) { + m_backcolor.r = br; + m_backcolor.g = bg; + m_backcolor.b = bb; + + m_backbordercolor.r = bbr; + m_backbordercolor.g = bbg; + m_backbordercolor.b = bbb; + + m_background = true; + } + + void FloatingTextRenderer::resetDefaultBackground() { + m_background = false; + } + FloatingTextRenderer* FloatingTextRenderer::getInstance(IRendererContainer* cnt) { return dynamic_cast(cnt->getRenderer("FloatingTextRenderer")); } diff -r 1e69fd582c94 -r 5e04f6349894 engine/core/view/renderers/floatingtextrenderer.h --- a/engine/core/view/renderers/floatingtextrenderer.h Mon Aug 02 10:26:21 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.h Tue Aug 03 13:57:12 2010 +0000 @@ -62,15 +62,32 @@ */ void changeDefaultFont(AbstractFont* font) { m_font = font; } + /** Changes default font color + * Only usefull for .ttf fonts + */ void setColor(Uint8 r, Uint8 g, Uint8 b); + + /** Set default background quad with border + * first r,g,b values for background, second for border color + */ + void setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 bbr, Uint8 bbg, Uint8 bbb); + + /** Disable the default background + */ + void resetDefaultBackground(); + /** returns instance used in given view */ static FloatingTextRenderer* getInstance(IRendererContainer* cnt); private: + RenderBackend* m_renderbackend; AbstractFont* m_font; bool m_font_color; SDL_Color m_color; + bool m_background; + SDL_Color m_backcolor; + SDL_Color m_backbordercolor; }; } diff -r 1e69fd582c94 -r 5e04f6349894 engine/core/view/renderers/floatingtextrenderer.i --- a/engine/core/view/renderers/floatingtextrenderer.i Mon Aug 02 10:26:21 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.i Tue Aug 03 13:57:12 2010 +0000 @@ -33,6 +33,8 @@ virtual ~FloatingTextRenderer(); void changeDefaultFont(AbstractFont* font); void setColor(Uint8 r, Uint8 g, Uint8 b); + void setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 bbr, Uint8 bbg, Uint8 bbb); + void resetDefaultBackground(); static FloatingTextRenderer* getInstance(IRendererContainer* cnt); diff -r 1e69fd582c94 -r 5e04f6349894 tools/editor/scripts/editor.py --- a/tools/editor/scripts/editor.py Mon Aug 02 10:26:21 2010 +0000 +++ b/tools/editor/scripts/editor.py Tue Aug 03 13:57:12 2010 +0000 @@ -284,19 +284,19 @@ toolbox.adaptLayout() def toggleBlocking(self, sender): - if self._mapview != None: + if self._mapview is not None: for cam in self._mapview.getMap().getCameras(): r = fife.BlockingInfoRenderer.getInstance(cam) r.setEnabled(not r.isEnabled()) def toggleGrid(self, sender): - if self._mapview != None: + if self._mapview is not None: for cam in self._mapview.getMap().getCameras(): r = fife.GridRenderer.getInstance(cam) r.setEnabled(not r.isEnabled()) def toggleCoordinates(self, sender): - if self._mapview != None: + if self._mapview is not None: for cam in self._mapview.getMap().getCameras(): r = fife.CoordinateRenderer.getInstance(cam) if not r.isEnabled(): diff -r 1e69fd582c94 -r 5e04f6349894 tools/editor/scripts/gui/mapeditor.py --- a/tools/editor/scripts/gui/mapeditor.py Mon Aug 02 10:26:21 2010 +0000 +++ b/tools/editor/scripts/gui/mapeditor.py Tue Aug 03 13:57:12 2010 +0000 @@ -595,8 +595,6 @@ blockrenderer.setEnabled(not blockrenderer.isEnabled()) elif keystr == 'c': - #coordinaterenderer = self._controller._camera.getRenderer('CoordinateRenderer') - #coordinaterenderer.setEnabled(not coordinaterenderer.isEnabled()) self._editor.toggleCoordinates("Toggle Coordinates") elif keystr == 'z': diff -r 1e69fd582c94 -r 5e04f6349894 tools/editor/scripts/mapcontroller.py --- a/tools/editor/scripts/mapcontroller.py Mon Aug 02 10:26:21 2010 +0000 +++ b/tools/editor/scripts/mapcontroller.py Tue Aug 03 13:57:12 2010 +0000 @@ -111,6 +111,7 @@ cellrenderer = fife.CellSelectionRenderer.getInstance(self._camera) cellrenderer.activateAllLayers(self._map) color = str(self._settings.get("Colors", "CellSelection", "255,0,0")) + cellrenderer.setColor(*[int(c) for c in color.split(',')]) cellrenderer.setEnabled(True) def getMap(self):