mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-18 11:54:30 +01:00
Drop shadow support for TextureButton
This commit is contained in:
1 parent
82b266e358
commit
909b67743e
4 files changed
+29
-10
No files matched your search
+11
-2
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
#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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user