Add GuiImage:setBlendMode
Signed-off-by: Thomas Rohloff <v10lator@myway.de>
This commit is contained in:
parent
e61d10c828
commit
37550b59d4
|
@ -41,10 +41,15 @@ public:
|
||||||
|
|
||||||
void setTexture(GuiTextureData *tex);
|
void setTexture(GuiTextureData *tex);
|
||||||
|
|
||||||
|
int setBlendMode(SDL_BlendMode blendMode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GuiTextureData *texture = nullptr;
|
GuiTextureData *texture = nullptr;
|
||||||
bool freeTextureData = false;
|
bool freeTextureData = false;
|
||||||
|
|
||||||
// Color of the rect that's drawn if the picture has no texture.
|
// Color of the rect that's drawn if the picture has no texture.
|
||||||
SDL_Color color = {0, 0, 0, 0};
|
SDL_Color color = {0, 0, 0, 0};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SDL_BlendMode blendMode;
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,11 +47,24 @@ void GuiImage::draw(Renderer *renderer) {
|
||||||
if (texture) {
|
if (texture) {
|
||||||
texture->draw(renderer, rect, getAngle());
|
texture->draw(renderer, rect, getAngle());
|
||||||
} else {
|
} else {
|
||||||
|
// copy the texture to the rendering context
|
||||||
|
SDL_BlendMode mode;
|
||||||
|
SDL_GetRenderDrawBlendMode(renderer->getRenderer(), &mode);
|
||||||
|
|
||||||
|
// adjust blend mode
|
||||||
|
if(blendMode != mode){
|
||||||
|
SDL_SetRenderDrawBlendMode(renderer->getRenderer(), blendMode);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer->getRenderer(), color.r, color.g, color.b, color.a);
|
SDL_SetRenderDrawColor(renderer->getRenderer(), color.r, color.g, color.b, color.a);
|
||||||
SDL_RenderFillRect(renderer->getRenderer(), &rect);
|
SDL_RenderFillRect(renderer->getRenderer(), &rect);
|
||||||
if(getAngle() != 0.0f){
|
if(getAngle() != 0.0f){
|
||||||
LG_Log("Drawing a rotated rect is not supported yet");
|
LG_Log("Drawing a rotated rect is not supported yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(blendMode != mode){
|
||||||
|
SDL_SetRenderDrawBlendMode(renderer->getRenderer(), mode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,3 +77,8 @@ void GuiImage::setTexture(GuiTextureData *tex) {
|
||||||
this->setSize(tex->getWidth(), tex->getHeight());
|
this->setSize(tex->getWidth(), tex->getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GuiImage::setBlendMode(SDL_BlendMode blendMode) {
|
||||||
|
this->blendMode = blendMode;
|
||||||
|
return this->texture ? this->texture->setBlendMode(blendMode) : 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue