Mercurial > fife-parpg
changeset 589:d1df6cf5ff23
* Fixed a bug in RenderBackendSDL, the clip area was not properly set.
* Renamed the backquad and border commands of the FloatingTextRenderer.
* Added the TransparentArea commands to the InstanceRenderer.
Note: with addTransparentArea(instance, string, width, height, transparent, front) you can enable an area, that make all instances in this zone and with the same namespace transparent. The string is for the namespace, so you can set one or more namespaces to be transparent. Width and height specifies the size of the area. Transparent defines the intensity of transparency, 255 = invisible. The bool front, enable or disable the z check, so that only instances in front of the source instance could be transparent.
author | helios2000@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 13 Aug 2010 16:33:36 +0000 |
parents | a46368b3d8a0 |
children | 59c92d10d7bc |
files | demos/rio_de_hola/scripts/world.py engine/core/video/sdl/renderbackendsdl.cpp engine/core/view/renderers/floatingtextrenderer.cpp engine/core/view/renderers/floatingtextrenderer.h engine/core/view/renderers/floatingtextrenderer.i engine/core/view/renderers/instancerenderer.cpp engine/core/view/renderers/instancerenderer.h engine/core/view/renderers/instancerenderer.i |
diffstat | 8 files changed, 142 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/rio_de_hola/scripts/world.py Fri Aug 13 13:54:02 2010 +0000 +++ b/demos/rio_de_hola/scripts/world.py Fri Aug 13 16:33:36 2010 +0000 @@ -233,8 +233,8 @@ 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, 165) - renderer.setDefaultBorder(50, 255, 50) + renderer.setBackground(100, 255, 100, 165) + renderer.setBorder(50, 255, 50) renderer.setEnabled(True) # Activate the grid renderer on all layers
--- a/engine/core/video/sdl/renderbackendsdl.cpp Fri Aug 13 13:54:02 2010 +0000 +++ b/engine/core/video/sdl/renderbackendsdl.cpp Fri Aug 13 16:33:36 2010 +0000 @@ -120,6 +120,12 @@ } void RenderBackendSDL::startFrame() { + SDL_Rect rect; + rect.x = 0; + rect.y = 0; + rect.w = getWidth(); + rect.h = getHeight(); + SDL_SetClipRect(m_screen->getSurface(), &rect); SDL_FillRect(m_screen->getSurface(), 0, 0x00); }
--- a/engine/core/view/renderers/floatingtextrenderer.cpp Fri Aug 13 13:54:02 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.cpp Fri Aug 13 16:33:36 2010 +0000 @@ -128,7 +128,7 @@ m_font_color = true; } - void FloatingTextRenderer::setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba) { + void FloatingTextRenderer::setBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba) { m_backcolor.r = br; m_backcolor.g = bg; m_backcolor.b = bb; @@ -137,7 +137,7 @@ m_background = true; } - void FloatingTextRenderer::setDefaultBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba) { + void FloatingTextRenderer::setBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba) { m_backbordercolor.r = bbr; m_backbordercolor.g = bbg; m_backbordercolor.b = bbb; @@ -146,11 +146,11 @@ m_backborder = true; } - void FloatingTextRenderer::resetDefaultBackground() { + void FloatingTextRenderer::resetBackground() { m_background = false; } - void FloatingTextRenderer::resetDefaultBorder() { + void FloatingTextRenderer::resetBorder() { m_backborder = false; }
--- a/engine/core/view/renderers/floatingtextrenderer.h Fri Aug 13 13:54:02 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.h Fri Aug 13 16:33:36 2010 +0000 @@ -70,20 +70,20 @@ /** Set default background quad * r,g,b,a values for background */ - void setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba = 255); + void setBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba = 255); /** Set default border * r,g,b,a values for border */ - void setDefaultBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba = 255); + void setBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba = 255); /** Disable the default background */ - void resetDefaultBackground(); + void resetBackground(); /** Disable the default border */ - void resetDefaultBorder(); + void resetBorder(); /** returns instance used in given view */
--- a/engine/core/view/renderers/floatingtextrenderer.i Fri Aug 13 13:54:02 2010 +0000 +++ b/engine/core/view/renderers/floatingtextrenderer.i Fri Aug 13 16:33:36 2010 +0000 @@ -33,10 +33,10 @@ virtual ~FloatingTextRenderer(); void changeDefaultFont(AbstractFont* font); void setColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255); - void setDefaultBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba = 255); - void setDefaultBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba = 255); - void resetDefaultBackground(); - void resetDefaultBorder(); + void setBackground(Uint8 br, Uint8 bg, Uint8 bb, Uint8 ba = 255); + void setBorder(Uint8 bbr, Uint8 bbg, Uint8 bbb, Uint8 bba = 255); + void resetBackground(); + void resetBorder(); static FloatingTextRenderer* getInstance(IRendererContainer* cnt);
--- a/engine/core/view/renderers/instancerenderer.cpp Fri Aug 13 13:54:02 2010 +0000 +++ b/engine/core/view/renderers/instancerenderer.cpp Fri Aug 13 16:33:36 2010 +0000 @@ -72,6 +72,16 @@ curimg(NULL) { } + InstanceRenderer::AreaInfo::AreaInfo(): + instance(NULL), + groups(), + w(1), + h(1), + trans(0), + front(true), + z(0) { + } + InstanceRenderer::OutlineInfo::~OutlineInfo() { delete outline; } @@ -80,6 +90,9 @@ delete overlay; } + InstanceRenderer::AreaInfo::~AreaInfo() { + } + InstanceRenderer* InstanceRenderer::getInstance(IRendererContainer* cnt) { return dynamic_cast<InstanceRenderer*>(cnt->getRenderer("InstanceRenderer")); } @@ -87,14 +100,16 @@ InstanceRenderer::InstanceRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool): RendererBase(renderbackend, position), m_imagepool(imagepool), - m_animationpool(animpool) { + m_animationpool(animpool), + m_area_layer(false) { setEnabled(true); } InstanceRenderer::InstanceRenderer(const InstanceRenderer& old): RendererBase(old), m_imagepool(old.m_imagepool), - m_animationpool(old.m_animationpool) { + m_animationpool(old.m_animationpool), + m_area_layer(old.m_area_layer) { setEnabled(true); } @@ -115,12 +130,53 @@ const bool any_effects = !(m_instance_outlines.empty() && m_instance_colorings.empty()); - RenderList::iterator instance_it = instances.begin(); + m_area_layer = false; + if(!m_instance_areas.empty()) { + InstanceToAreas_t::iterator area_it = m_instance_areas.begin(); + for(;area_it != m_instance_areas.end(); area_it++) { + AreaInfo& info = area_it->second; + if(info.instance->getLocation().getLayer() == layer) { + if(info.front) { + DoublePoint3D instance_posv = cam->toVirtualScreenCoordinates(info.instance->getLocation().getMapCoordinates()); + info.z = instance_posv.z; + } + m_area_layer = true; + } + } + } + + RenderList::iterator instance_it = instances.begin(); for (;instance_it != instances.end(); ++instance_it) { FL_DBG(_log, "Iterating instances..."); Instance* instance = (*instance_it)->instance; RenderItem& vc = **instance_it; + if(m_area_layer) { + InstanceToAreas_t::iterator areas_it = m_instance_areas.begin(); + for(;areas_it != m_instance_areas.end(); areas_it++) { + AreaInfo& infoa = areas_it->second; + if(infoa.front) { + if(infoa.z >= vc.screenpoint.z) { + continue; + } + } + + std::string str_name = instance->getObject()->getNamespace(); + if(str_name.find(infoa.groups) != -1) { + ScreenPoint p; + Rect rec; + p = cam->toScreenCoordinates(infoa.instance->getLocation().getMapCoordinates()); + rec.x = p.x - infoa.w / 2; + rec.y = p.y - infoa.h / 2; + rec.w = infoa.w; + rec.h = infoa.h; + if(infoa.instance != instance && vc.dimensions.intersects(rec)) { + vc.transparency = 255 - infoa.trans; + } + } + } + } + FL_DBG(_log, LMsg("Instance layer coordinates = ") << instance->getLocationRef().getLayerCoordinates()); if (any_effects) { @@ -315,6 +371,29 @@ } } + void InstanceRenderer::addTransparentArea(Instance* instance, const std::string &groups, unsigned int w, unsigned int h, unsigned char trans, bool front) { + AreaInfo newinfo; + newinfo.instance = instance; + newinfo.groups = groups; + newinfo.w = w; + newinfo.h = h; + newinfo.trans = trans; + newinfo.front = front; + + + // attempts to insert the element into the area map + // will return false in the second value of the pair if the instance already exists + // in the map and the first value of the pair will then be an iterator to the + // existing data for the instance + std::pair<InstanceToAreas_t::iterator, bool> insertiter = m_instance_areas.insert(std::make_pair(instance, newinfo)); + + if (insertiter.second == false) { + // the insertion did not happen because the instance + // already exists in the map so lets just update its area info + AreaInfo& info = insertiter.first->second; + } + } + void InstanceRenderer::removeOutlined(Instance* instance) { m_instance_outlines.erase(instance); } @@ -323,6 +402,10 @@ m_instance_colorings.erase(instance); } + void InstanceRenderer::removeTransparentArea(Instance* instance) { + m_instance_areas.erase(instance); + } + void InstanceRenderer::removeAllOutlines() { m_instance_outlines.clear(); } @@ -331,9 +414,14 @@ m_instance_colorings.clear(); } + void InstanceRenderer::removeAllTransparentAreas() { + m_instance_areas.clear(); + } + void InstanceRenderer::reset() { removeAllOutlines(); removeAllColored(); + removeAllTransparentAreas(); } }
--- a/engine/core/view/renderers/instancerenderer.h Fri Aug 13 13:54:02 2010 +0000 +++ b/engine/core/view/renderers/instancerenderer.h Fri Aug 13 16:33:36 2010 +0000 @@ -23,6 +23,7 @@ #define FIFE_INSTANCERENDERER_H // Standard C++ library includes +#include <string> // 3rd party library includes @@ -64,6 +65,10 @@ /** Marks given instance to be colored with given parameters */ void addColored(Instance* instance, int r, int g, int b); + + /** Marks given instance to have an transparent area with given paramters + */ + void addTransparentArea(Instance* instance, const std::string &groups, unsigned int w, unsigned int h, unsigned char trans, bool front = true); /** Removes instance from outlining list */ @@ -72,6 +77,10 @@ /** Removes instance from coloring list */ void removeColored(Instance* instance); + + /** Removes instance form area list + */ + void removeTransparentArea(Instance* instance); /** Removes all outlines */ @@ -80,6 +89,10 @@ /** Removes all coloring */ void removeAllColored(); + + /** Removes all transparent areas + */ + void removeAllTransparentAreas(); /** Gets instance for interface access */ @@ -90,6 +103,7 @@ private: ImagePool* m_imagepool; AnimationPool* m_animationpool; + bool m_area_layer; // contains per-instance information for outline drawing class OutlineInfo { @@ -116,12 +130,25 @@ ColoringInfo(); ~ColoringInfo(); }; + class AreaInfo { + public: + Instance* instance; + std::string groups; + unsigned int w; + unsigned int h; + unsigned char trans; + bool front; + float z; + AreaInfo(); + ~AreaInfo(); + }; typedef std::map<Instance*, OutlineInfo> InstanceToOutlines_t; typedef std::map<Instance*, ColoringInfo> InstanceToColoring_t; - //typedef std::map<int, ColoringInfo> InstanceToColoring_t; + typedef std::map<Instance*, AreaInfo> InstanceToAreas_t; InstanceToOutlines_t m_instance_outlines; InstanceToColoring_t m_instance_colorings; + InstanceToAreas_t m_instance_areas; /** Binds new outline (if needed) to the instance's OutlineInfo */
--- a/engine/core/view/renderers/instancerenderer.i Fri Aug 13 13:54:02 2010 +0000 +++ b/engine/core/view/renderers/instancerenderer.i Fri Aug 13 16:33:36 2010 +0000 @@ -40,6 +40,9 @@ void addColored(Instance* instance, int r, int g, int b); void removeColored(Instance* instance); void removeAllColored(); + void addTransparentArea(Instance* instance, const std::string &groups, unsigned int w, unsigned int h, unsigned char trans, bool front = true); + void removeTransparentArea(Instance* instance); + void removeAllTransparentAreas(); static InstanceRenderer* getInstance(IRendererContainer* cnt); private: InstanceRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool);