105 renderer->addToCheck(outline);
109 if (renderer->needColorBinding()) {
110 renderer->addToCheck(overlay);
186 FL_WARN(
_log,
"No cellgrid assigned to layer, cannot draw instances");
203 std::multimap<float, RenderItem*> transparentInstances;
213 info.
z = instance_posv.
z;
220 RenderList::iterator instance_it = instances.begin();
221 for (;instance_it != instances.end(); ++instance_it) {
223 Instance* instance = (*instance_it)->instance;
238 std::list<std::string>::iterator group_it = infoa.
groups.begin();
239 for (;group_it != infoa.
groups.end(); ++group_it) {
240 if (str_name.find((*group_it)) != std::string::npos) {
244 rec.
x = p.
x - infoa.
w / 2;
245 rec.
y = p.
y - infoa.
h / 2;
262 transparentInstances.insert(std::pair<float, RenderItem*>(vertexZ, &vc));
266 uint8_t coloringColor[4] = { 0 };
267 Image* outlineImage = 0;
268 bool recoloring =
false;
274 coloringColor[0] = coloring_it->second.r;
275 coloringColor[1] = coloring_it->second.g;
276 coloringColor[2] = coloring_it->second.b;
277 coloringColor[3] = coloring_it->second.a;
287 outlineImage =
bindOutline(outline_it->second, vc, cam);
331 std::multimap<float, RenderItem*>::iterator it = transparentInstances.begin();
332 for( ; it != transparentInstances.end(); ++it) {
336 float vertexZ = it->first;
338 uint8_t coloringColor[4] = { 0 };
339 Image* outlineImage = 0;
340 bool recoloring =
false;
346 coloringColor[0] = coloring_it->second.r;
347 coloringColor[1] = coloring_it->second.g;
348 coloringColor[2] = coloring_it->second.b;
349 coloringColor[3] = coloring_it->second.a;
359 outlineImage =
bindOutline(outline_it->second, vc, cam);
393 info.
z = instance_posv.
z;
400 RenderList::iterator instance_it = instances.begin();
401 for (;instance_it != instances.end(); ++instance_it) {
403 Instance* instance = (*instance_it)->instance;
417 std::list<std::string>::iterator group_it = infoa.
groups.begin();
418 for(;group_it != infoa.
groups.end(); ++group_it) {
419 if(str_name.find((*group_it)) != std::string::npos) {
423 rec.
x = p.
x - infoa.
w / 2;
424 rec.
y = p.
y - infoa.
h / 2;
441 uint8_t coloringColor[4] = { 0 };
442 Image* outlineImage = 0;
443 bool recoloring =
false;
449 coloringColor[0] = coloring_it->second.r;
450 coloringColor[1] = coloring_it->second.g;
451 coloringColor[2] = coloring_it->second.b;
452 coloringColor[3] = coloring_it->second.a;
462 outlineImage =
bindOutline(outline_it->second, vc, cam);
478 std::list<std::string>::iterator unlit_it =
m_unlit_groups.begin();
480 if(lit_name.find(*unlit_it) != std::string::npos) {
525 if (animationOverlay && !animationColorOverlay) {
527 for (std::vector<ImagePtr>::iterator it = animationOverlay->begin(); it != animationOverlay->end(); ++it) {
531 for (std::vector<ImagePtr>::iterator it = animationOverlay->begin(); it != animationOverlay->end(); ++it) {
536 }
else if (animationOverlay && animationColorOverlay) {
537 std::vector<OverlayColors*>::iterator ovit = animationColorOverlay->begin();
538 std::vector<ImagePtr>::iterator it = animationOverlay->begin();
539 for (; it != animationOverlay->end(); ++it, ++ovit) {
549 std::map<Color, Color>::const_iterator cit = oc->
getColors().begin();
550 uint8_t factor[4] = { 0, 0, 0, cit->second.getAlpha() };
556 float alphaFactor1 =
static_cast<float>(coloringColor[3] / 255.0);
557 const std::map<Color, Color>& defaultColors = oc->
getColors();
558 for (std::map<Color, Color>::const_iterator c_it = defaultColors.begin(); c_it != defaultColors.end(); ++c_it) {
559 if (c_it->second.getAlpha() == 0) {
562 float alphaFactor2 =
static_cast<float>(c_it->second.getAlpha() / 255.0);
563 Color c(coloringColor[0]*(1.0-alphaFactor1) + (c_it->second.getR()*alphaFactor2)*alphaFactor1,
564 coloringColor[1]*(1.0-alphaFactor1) + (c_it->second.getG()*alphaFactor2)*alphaFactor1,
565 coloringColor[2]*(1.0-alphaFactor1) + (c_it->second.getB()*alphaFactor2)*alphaFactor1, 255);
569 factor[3] =
static_cast<uint8_t>(255 - factor[3]);
570 factor[3] = std::min(coloringColor[3], factor[3]);
588 std::map<Color, Color>::const_iterator color_it = oc->
getColors().begin();
589 uint8_t rgba[4] = { color_it->second.getR(), color_it->second.getG(), color_it->second.getB(),
static_cast<uint8_t>(255-color_it->second.getAlpha()) };
590 bool noOverlay = rgba[3] == 255;
593 float alphaFactor1 =
static_cast<float>(coloringColor[3] / 255.0);
594 float alphaFactor2 = 1.0-
static_cast<float>(rgba[3] / 255.0);
595 rgba[0] = coloringColor[0]*(1.0-alphaFactor1) + (rgba[0]*alphaFactor2)*alphaFactor1;
596 rgba[1] = coloringColor[1]*(1.0-alphaFactor1) + (rgba[1]*alphaFactor2)*alphaFactor1;
597 rgba[2] = coloringColor[2]*(1.0-alphaFactor1) + (rgba[2]*alphaFactor2)*alphaFactor1;
598 rgba[3] = std::min(coloringColor[3], rgba[3]);
618 if (colorOverlay->
getColors().size() > 1) {
622 std::map<Color, Color>::const_iterator it = colorOverlay->
getColors().begin();
623 uint8_t factor[4] = { 0, 0, 0, it->second.getAlpha() };
627 float alphaFactor1 =
static_cast<float>(coloringColor[3] / 255.0);
628 const std::map<Color, Color>& defaultColors = colorOverlay->
getColors();
629 for (std::map<Color, Color>::const_iterator c_it = defaultColors.begin(); c_it != defaultColors.end(); ++c_it) {
630 if (c_it->second.getAlpha() == 0) {
633 float alphaFactor2 =
static_cast<float>(c_it->second.getAlpha() / 255.0);
634 Color c(coloringColor[0]*(1.0-alphaFactor1) + (c_it->second.getR()*alphaFactor2)*alphaFactor1,
635 coloringColor[1]*(1.0-alphaFactor1) + (c_it->second.getG()*alphaFactor2)*alphaFactor1,
636 coloringColor[2]*(1.0-alphaFactor1) + (c_it->second.getB()*alphaFactor2)*alphaFactor1, 255);
640 factor[3] =
static_cast<uint8_t>(255 - factor[3]);
641 factor[3] = std::min(coloringColor[3], factor[3]);
646 if (!multiColorOverlay) {
659 std::map<Color, Color>::const_iterator color_it = colorOverlay->
getColors().begin();
660 uint8_t rgba[4] = { color_it->second.getR(), color_it->second.getG(), color_it->second.getB(),
static_cast<uint8_t>(255-color_it->second.getAlpha()) };
661 bool noOverlay = rgba[3] == 255;
664 float alphaFactor1 =
static_cast<float>(coloringColor[3] / 255.0);
665 float alphaFactor2 = 1.0-
static_cast<float>(rgba[3] / 255.0);
666 rgba[0] = coloringColor[0]*(1.0-alphaFactor1) + (rgba[0]*alphaFactor2)*alphaFactor1;
667 rgba[1] = coloringColor[1]*(1.0-alphaFactor1) + (rgba[1]*alphaFactor2)*alphaFactor1;
668 rgba[2] = coloringColor[2]*(1.0-alphaFactor1) + (rgba[2]*alphaFactor2)*alphaFactor1;
669 rgba[3] = std::min(coloringColor[3], rgba[3]);
689 inline bool aboveThreshold(int32_t threshold, int32_t alpha, int32_t prev_alpha) {
692 if (((alpha - threshold) >= 0 || (prev_alpha - threshold) >= 0) && (alpha != prev_alpha)) {
699 if((alpha == 0 || prev_alpha == 0) && (alpha != prev_alpha)) {
731 std::stringstream sts;
733 static_cast<uint32_t>(info.
g) <<
"," <<
static_cast<uint32_t>(info.
b) <<
"," << info.
width;
753 SDL_Surface* outline_surface = SDL_CreateRGBSurface(0,
761 for (int32_t x = 0; x < outline_surface->w; x ++) {
763 for (int32_t y = 0; y < outline_surface->h; y ++) {
767 for (int32_t yy = y; yy < y + info.
width; yy++) {
771 for (int32_t yy = y - info.
width; yy < y; yy++) {
780 for (int32_t y = 0; y < outline_surface->h; y ++) {
782 for (int32_t x = 0; x < outline_surface->w; x ++) {
786 for (int32_t xx = x; xx < x + info.
width; xx++) {
790 for (int32_t xx = x - info.
width; xx < x; xx++) {
826 std::stringstream sts;
830 std::vector<ImagePtr>::iterator it = animationOverlays->begin();
831 for (; it != animationOverlays->end(); ++it) {
834 if ((*it)->isSharedImage()) {
835 (*it)->forceLoadInternal();
837 sts << (*it)->getName() <<
",";
838 mw = std::max(mw, (*it)->getWidth());
839 mh = std::max(mh, (*it)->getHeight());
841 sts << static_cast<uint32_t>(info.
r) <<
"," <<
842 static_cast<uint32_t>(info.
g) <<
"," <<
static_cast<uint32_t>(info.
b) <<
"," << info.
width;
855 SDL_Surface* outline_surface = SDL_CreateRGBSurface(0, mw, mh, 32,
861 it = animationOverlays->begin();
862 for (; it != animationOverlays->end(); ++it) {
864 for (
uint32_t x = 0; x < (*it)->getWidth(); x++) {
866 for (
uint32_t y = 0; y < (*it)->getHeight(); y++) {
867 (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
871 int32_t tx = x + (mw/2 - (*it)->getWidth()/2);
872 int32_t ty = yy + (mh/2 - (*it)->getHeight()/2);
877 int32_t tx = x + (mw/2 - (*it)->getWidth()/2);
878 int32_t ty = yy + (mh/2 - (*it)->getHeight()/2);
888 for (
uint32_t y = 0; y < (*it)->getHeight(); y++) {
890 for (
uint32_t x = 0; x < (*it)->getWidth(); x++) {
891 (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
895 int32_t tx = xx + (mw/2 - (*it)->getWidth()/2);
896 int32_t ty = y + (mh/2 - (*it)->getHeight()/2);
901 int32_t tx = xx + (mw/2 - (*it)->getWidth()/2);
902 int32_t ty = y + (mh/2 - (*it)->getHeight()/2);
949 std::stringstream sts;
951 static_cast<uint32_t>(info.
g) <<
"," <<
static_cast<uint32_t>(info.
b) <<
"," << static_cast<uint32_t>(info.
a);
972 SDL_Surface* overlay_surface = SDL_CreateRGBSurface(0,
977 float alphaFactor =
static_cast<float>(info.
a/255.0);
978 for (int32_t x = 0; x < overlay_surface->w; x ++) {
979 for (int32_t y = 0; y < overlay_surface->h; y ++) {
982 Image::putPixel(overlay_surface, x, y, info.
r*(1.0-alphaFactor) + r*alphaFactor, info.
g*(1.0-alphaFactor) + g*alphaFactor, info.
b*(1.0-alphaFactor) + b*alphaFactor, a);
1010 std::map<Color, Color>::const_iterator it = colorMap.begin();
1015 std::stringstream sts;
1017 for (; it != colorMap.end(); ++it) {
1018 sts <<
"," <<
static_cast<uint32_t>(it->second.getR() | (it->second.getG() << 8) | (it->second.getB() << 16) | (it->second.getAlpha()<<24));
1030 if (!exist || !found) {
1038 SDL_Surface* overlay_surface = SDL_CreateRGBSurface(0,
1043 for (int32_t x = 0; x < overlay_surface->w; x++) {
1044 for (int32_t y = 0; y < overlay_surface->h; y++) {
1046 Color c(r, g, b, a);
1047 it = colorMap.find(c);
1048 if (it != colorMap.end()) {
1049 Image::putPixel(overlay_surface, x, y, it->second.getR(), it->second.getG(), it->second.getB(), it->second.getAlpha());
1072 return colorOverlay;
1081 newinfo.
width = width;
1082 newinfo.
dirty =
true;
1088 std::pair<InstanceToOutlines_t::iterator, bool> insertiter =
m_instance_outlines.insert(std::make_pair(instance, newinfo));
1090 if (insertiter.second ==
false) {
1095 if (info.
r != r || info.
g != g || info.
b != b || info.
width != width) {
1110 Effect& effect = iter.first->second;
1111 if ((effect &
OUTLINE) != OUTLINE) {
1124 newinfo.
dirty =
true;
1130 std::pair<InstanceToColoring_t::iterator, bool> insertiter =
m_instance_colorings.insert(std::make_pair(instance, newinfo));
1132 if (insertiter.second ==
false) {
1137 if (info.
r != r || info.
g != g || info.
b != b || info.
a != a) {
1150 Effect& effect = iter.first->second;
1151 if ((effect &
COLOR) != COLOR) {
1165 newinfo.
trans = trans;
1166 newinfo.
front = front;
1173 std::pair<InstanceToAreas_t::iterator, bool> insertiter =
m_instance_areas.insert(std::make_pair(instance, newinfo));
1175 if (insertiter.second ==
false) {
1178 AreaInfo& info = insertiter.first->second;
1189 Effect& effect = iter.first->second;
1190 if ((effect &
AREA) != AREA) {
1214 if (it->second ==
COLOR) {
1219 it->second -=
COLOR;
1228 if (it->second ==
AREA) {
1232 }
else if ((it->second &
AREA) ==
AREA) {
1263 if (it->second ==
COLOR) {
1267 it->second -=
COLOR;
1281 if (it->second ==
AREA) {
1284 }
else if ((it->second &
AREA) ==
AREA) {
1294 std::list<std::string>::const_iterator group_it = groups.begin();
1295 for(;group_it != groups.end(); ++group_it) {
1303 std::list<std::string>::const_iterator group_it = groups.begin();
1304 for(;group_it != groups.end(); ++group_it) {
1305 std::list<std::string>::iterator unlit_it =
m_unlit_groups.begin();
1307 if((*group_it).find(*unlit_it) != std::string::npos) {
1349 if (it->image.get()->getName() == image.
get()->
getName()) {
1354 entry.
image = image;
1391 if (it->image.get()->getName() == image.
get()->
getName()) {
#define FL_WARN(logger, msg)
ImagePtr getMultiColorOverlay(const RenderItem &vc, OverlayColors *colors=0)
Abstract interface for all the renderbackends.
static bool putPixel(SDL_Surface *surface, int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
virtual bool exists(const std::string &name)
Checks to see if an Image exists.
OverlayColors * getColorOverlay() const
Returns pointer to single ColorOverlay.
std::vector< RenderItem * > RenderList
virtual ResourceState getState()
uint32_t getTime() const
Get the time.
void addOutlined(Instance *instance, int32_t r, int32_t g, int32_t b, int32_t width, int32_t threshold=1)
Marks given instance to be outlined with given parameters.
Layer * getLayer() const
Gets the layer where this location is pointing to.
T h
Height of the rectangle.
void addDeleteListener(InstanceDeleteListener *listener)
Adds new instance delete listener.
Instance visual contains data that is needed to visualize the instance on screen. ...
InstanceToEffects_t m_assigned_instances
OutlineInfo(InstanceRenderer *r)
virtual const std::string & getName() const =0
The name of the renderbackend.
DoublePoint3D toVirtualScreenCoordinates(const ExactModelCoordinate &map_coords)
Transforms given point from map coordinates to virtual screen coordinates.
Image * bindColoring(ColoringInfo &info, RenderItem &vc, Camera *cam)
void removeInstance(Instance *instance)
Removes instance from all effects.
DoublePoint3D screenpoint
InstanceRenderer(RenderBackend *renderbackend, int32_t position)
constructor.
SDL_Surface * detachSurface()
Removes underlying SDL_Surface from the image (if exists) and returns this.
void getPixelRGBA(int32_t x, int32_t y, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
Interface to class owning the renderers Used to get correct subclass of renderer in scripting side (v...
static Logger _log(LM_AUDIO)
void setInterval(int32_t msec)
Set the interval in milliseconds.
std::list< std::string > m_unlit_groups
InstanceToOutlines_t m_instance_outlines
void start()
Start the timer.
virtual void onInstanceDeleted(Instance *instance)
RendererBase * clone()
Makes copy of this renderer.
void removeAllIgnoreLight()
Removes all groups(Namespaces)
void removeOutlined(Instance *instance)
Removes instance from outlining list.
virtual RendererBase * getRenderer(const std::string &renderername)=0
Returns renderer with given name.
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
void check()
Timer callback, tried to remove old effect images.
InstanceDeleteListener * m_delete_listener
static ImageManager * instance()
virtual ImagePtr getPtr(const std::string &name)
void addIgnoreLight(const std::list< std::string > &groups)
Add groups(Namespaces) into a list.
virtual uint32_t getLightingModel() const =0
Gets the current light model.
void removeDeleteListener(InstanceDeleteListener *listener)
Removes associated instance delete listener.
InstanceRendererDeleteListener(InstanceRenderer *r)
bool intersects(const RectType< T > &rect) const
Check whether two rectangles share some area.
bool m_need_bind_coloring
RenderBackend * m_renderbackend
bool aboveThreshold(int32_t threshold, int32_t alpha, int32_t prev_alpha)
virtual void changeRenderInfos(RenderDataType type, uint16_t elements, int32_t src, int32_t dst, bool light, bool stentest, uint8_t stenref, GLConstants stenop, GLConstants stenfunc, OverlayType otype=OVERLAY_TYPE_NONE)=0
Dirty helper function to change the render infos.
bool isVisible()
Is instance visible or not.
void changeColor(const Color &source, const Color &target)
InstanceRenderer * m_renderer
void removeIgnoreLight(const std::list< std::string > &groups)
Removes groups(Namespaces) from the list.
virtual void copySubimage(uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
Copies given image into this one with respect to given offsets.
uint32_t getHeight() const
InstanceToAreas_t m_instance_areas
void setVisible(bool visible)
Sets visibility value for object to be visualized.
Base class for all view renderers View renderer renders one aspect of the view shown on screen...
Object * getObject()
Gets object where this instance is instantiated from.
bool isValidImage(const ImagePtr &image)
void renderAlreadySorted(Camera *cam, Layer *layer, RenderList &instances)
virtual ~InstanceRenderer()
Destructor.
const std::string & getNamespace() const
virtual void setSurface(SDL_Surface *surface)=0
This frees the current suface and replaces it with the surface passed in the parameter (which can be ...
const std::map< Color, Color > & getColors()
void render(Camera *cam, Layer *layer, RenderList &instances)
This method is called by the view to ask renderer to draw its rendering aspect based on given paramet...
void addColored(Instance *instance, int32_t r, int32_t g, int32_t b, int32_t a=128)
Marks given instance to be colored with given parameters.
virtual void renderZ(const Rect &rect, float vertexZ, uint8_t alpha=255, uint8_t const *rgb=0)
virtual const std::string & getName()
virtual void setEnabled(bool enabled)
Enables renderer.
uint32_t getRemoveInterval() const
Gets the interval in seconds (default is 60).
void renderOverlay(RenderDataType type, RenderItem *item, uint8_t const *coloringColor, bool recoloring)
ImagePtr getColorOverlayImage()
std::vector< OverlayColors * > * getAnimationColorOverlay() const
Returns pointer to AnimationColorOverlay vector.
void renderUnsorted(Camera *cam, Layer *layer, RenderList &instances)
virtual ~InstanceRendererDeleteListener()
void removeTransparentArea(Instance *instance)
Removes instance form area list.
void removeAllTransparentAreas()
Removes all transparent areas.
virtual void free(const std::string &name)
Frees an Image from memory.
CellGrid * getCellGrid() const
Get the Cellgrid.
void addTransparentArea(Instance *instance, const std::list< std::string > &groups, uint32_t w, uint32_t h, uint8_t trans, bool front=true)
Marks given instance to have a transparent area with given parameters.
bool isSharedImage() const
Returns true if this image shares data with another one.
std::vector< ImagePtr > * getAnimationOverlay() const
Returns pointer to AnimationOverlay vector.
virtual void setState(const ResourceState &state)
virtual void render(const Rect &rect, uint8_t alpha=255, uint8_t const *rgb=0)=0
Renders itself to the current render target (main screen or attached destination image) at the rectan...
ScreenPoint toScreenCoordinates(const ExactModelCoordinate &map_coords)
Transforms given point from map coordinates to screen coordinates.
void stop()
Stop the timer.
T * getVisual() const
Gets used visualization.
virtual Image * createImage(IResourceLoader *loader=0)=0
virtual void forceLoadInternal()=0
Forces to load the image into internal memory of GPU.
void reset()
Removes all stuff.
ColoringInfo(InstanceRenderer *r)
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
void removeAllOutlines()
Removes all outlines.
T * get() const
allows direct access to underlying pointer
static InstanceRenderer * getInstance(IRendererContainer *cnt)
Gets instance for interface access.
bool isDepthBufferEnabled() const
void setRemoveInterval(uint32_t interval)
Sets the interval in seconds (default is 60).
std::list< std::string > groups
ImagesToCheck_t m_check_images
void removeAllColored()
Removes all coloring.
Image * bindMultiOutline(OutlineInfo &info, RenderItem &vc, Camera *cam)
void addToCheck(const ImagePtr &image)
Add properly old ImagePtr into a check list.
T w
Width of the rectangle.
void removeFromCheck(const ImagePtr &image)
An Instance is an "instantiation" of an Object at a Location.
void setCallback(const type_callback &callback)
Set the callback that will be called.
void removeColored(Instance *instance)
Removes instance from coloring list.
uint32_t getWidth() const
virtual ImagePtr add(Image *res)
Add an Image to the manager.
InstanceToColoring_t m_instance_colorings
InstanceRenderer * renderer
Image * bindOutline(OutlineInfo &info, RenderItem &vc, Camera *cam)
Binds new outline (if needed) to the instance's OutlineInfo.
Location getLocation() const
Gets current location of instance.