diff --git a/base/colorutil.cpp b/base/colorutil.cpp index ff5bac7ece..ec9766296e 100644 --- a/base/colorutil.cpp +++ b/base/colorutil.cpp @@ -14,10 +14,19 @@ uint32_t blackAlpha(float alpha) { return (int)(alpha*255)<<24; } -uint32_t colorAlpha(uint32_t color, float alpha) { +uint32_t colorAlpha(uint32_t rgb, float alpha) { if (alpha < 0.0f) alpha = 0.0f; if (alpha > 1.0f) alpha = 1.0f; - return ((int)(alpha*255)<<24) | (color & 0xFFFFFF); + return ((int)(alpha*255)<<24) | (rgb & 0xFFFFFF); +} + +uint32_t alphaMul(uint32_t color, float alphaMul) { + uint32_t rgb = color & 0xFFFFFF; + uint32_t alpha = color >> 24; + alpha *= alphaMul; + if (alpha < 0.0f) alpha = 0.0f; + if (alpha > 255.0f) alpha = 255.0f; + return ((int)(alpha)<<24) | (rgb & 0xFFFFFF); } uint32_t rgba(float r, float g, float b, float alpha) { diff --git a/base/colorutil.h b/base/colorutil.h index 0dad43baf4..61d6f8b127 100644 --- a/base/colorutil.h +++ b/base/colorutil.h @@ -5,6 +5,7 @@ uint32_t whiteAlpha(float alpha); uint32_t blackAlpha(float alpha); uint32_t colorAlpha(uint32_t color, float alpha); +uint32_t alphaMul(uint32_t color, float alphaMul); uint32_t rgba(float r, float g, float b, float alpha); uint32_t rgba_clamp(float r, float g, float b, float alpha); uint32_t hsva(float h, float s, float v, float alpha); diff --git a/ui/ui.cpp b/ui/ui.cpp index 9f7698eebe..eb2c69c903 100644 --- a/ui/ui.cpp +++ b/ui/ui.cpp @@ -5,6 +5,7 @@ #include #include +#include "base/colorutil.h" #include "ui/ui.h" #include "ui/ui_context.h" #include "gfx/texture.h" @@ -234,7 +235,7 @@ int UIImageButton(int id, const LayoutManager &layout, float w, int image, int b return clicked; } -int UITextureButton(UIContext *ctx, int id, const LayoutManager &layout, float w, float h, Texture *texture, int button_align, uint32_t color) // uses current UI atlas for fetching images. +int UITextureButton(UIContext *ctx, int id, const LayoutManager &layout, float w, float h, Texture *texture, int button_align, uint32_t color, int drop_shadow) // uses current UI atlas for fetching images. { float x, y; layout.GetPos(&w, &h, &x, &y); @@ -273,12 +274,7 @@ int UITextureButton(UIContext *ctx, int id, const LayoutManager &layout, float w clicked = 1; } } - - // Render button - if (texture) { - texture->Bind(0); - float tw = texture->Width(); float th = texture->Height(); @@ -287,14 +283,27 @@ int UITextureButton(UIContext *ctx, int id, const LayoutManager &layout, float w float nw = h * tw / th; x += (w - nw) / 2.0f; w = nw; + } + + // Render button + const int dropsize = 10; + if (drop_shadow && texture) + { + ui_draw2d.DrawImage4Grid(drop_shadow, x - dropsize, y, x+w + dropsize, y+h+dropsize*1.5, + alphaMul(color,0.5f), 1.0f); + ui_draw2d.Flush(true); + } + + if (texture) { + texture->Bind(0); } else { ui_draw2d.DrawImage2GridH(theme.buttonImage, x, y, x + w, color); ui_draw2d.Flush(); Texture::Unbind(); } - ui_draw2d.DrawTexRect(x, y, x+w, y+h, 0, 0, 1, 1, color); + ui_draw2d.Flush(); ctx->RebindTexture(); diff --git a/ui/ui.h b/ui/ui.h index 22a566a6e9..13150f38ff 100644 --- a/ui/ui.h +++ b/ui/ui.h @@ -244,7 +244,7 @@ void UIReset(); // Returns 1 if clicked int UIButton(int id, const LayoutManager &layout, float w, float h, const char *text, int button_align); int UIImageButton(int id, const LayoutManager &layout, float w, int image_id, int button_align); // uses current UI atlas for fetching images. -int UITextureButton(UIContext *ctx, int id, const LayoutManager &layout, float w, float h, Texture *texture, int button_align, uint32_t color = 0xFFFFFFFF); // uses current UI atlas for fetching images. +int UITextureButton(UIContext *ctx, int id, const LayoutManager &layout, float w, float h, Texture *texture, int button_align, uint32_t color, int drop_shadow=0); // uses current UI atlas for fetching images. // Returns 1 if clicked, puts the value in *value (where it also gets the current state). int UICheckBox(int id, int x, int y, const char *text, int align, bool *value);