button: allow for disabled buttons

This commit is contained in:
K. Lange 2018-11-24 14:10:49 +09:00
parent 6ddeeb27ce
commit 3dc166607d
1 changed files with 16 additions and 8 deletions

View File

@ -37,24 +37,28 @@ void ttk_button_draw(gfx_context_t * ctx, struct TTKButton * button) {
if (button->width == 0) {
return;
}
int hilight = button->hilight & 0xFF;
int disabled = button->hilight & 0x100;
/* Dark edge */
if (button->hilight < 3) {
if (hilight < 3) {
struct gradient_definition edge = {button->height, button->y, rgb(166,166,166), rgb(136,136,136)};
draw_rounded_rectangle_pattern(ctx, button->x, button->y, button->width, button->height, 4, gradient_pattern, &edge);
}
/* Sheen */
if (button->hilight < 2) {
if (hilight < 2) {
draw_rounded_rectangle(ctx, button->x + 1, button->y + 1, button->width - 2, button->height - 2, 3, rgb(238,238,238));
/* Button face - this should normally be a gradient */
if (button->hilight == 1) {
if (hilight == 1) {
struct gradient_definition face = {button->height-3, button->y + 2, rgb(240,240,240), rgb(230,230,230)};
draw_rounded_rectangle_pattern(ctx, button->x + 2, button->y + 2, button->width - 4, button->height - 3, 2, gradient_pattern, &face);
} else {
struct gradient_definition face = {button->height-3, button->y + 2, rgb(219,219,219), rgb(204,204,204)};
draw_rounded_rectangle_pattern(ctx, button->x + 2, button->y + 2, button->width - 4, button->height - 3, 2, gradient_pattern, &face);
}
} else if (button->hilight == 2) {
} else if (hilight == 2) {
struct gradient_definition face = {button->height-2, button->y + 1, rgb(180,180,180), rgb(160,160,160)};
draw_rounded_rectangle_pattern(ctx, button->x + 1, button->y + 1, button->width - 2, button->height - 2, 3, gradient_pattern, &face);
}
@ -64,12 +68,16 @@ void ttk_button_draw(gfx_context_t * ctx, struct TTKButton * button) {
int centered = (button->width - label_width) / 2;
int centered_y = (button->height - 16) / 2;
draw_sdf_string(ctx, button->x + centered + (button->hilight == 2), button->y + centered_y + (button->hilight == 2), button->title, 16, rgb(0,0,0), SDF_FONT_THIN);
draw_sdf_string(ctx, button->x + centered + (hilight == 2), button->y + centered_y + (hilight == 2), button->title, 16, disabled ? rgb(120,120,120) : rgb(0,0,0), SDF_FONT_THIN);
} else {
sprite_t * icon = icon_get_16(button->title+1);
int centered = button->x + (button->width - icon->width) / 2 + (button->hilight == 2);
int centered_y = button->y + (button->height - icon->height) / 2 + (button->hilight == 2);
draw_sprite(ctx, icon, centered, centered_y);
int centered = button->x + (button->width - icon->width) / 2 + (hilight == 2);
int centered_y = button->y + (button->height - icon->height) / 2 + (hilight == 2);
if (disabled) {
draw_sprite_alpha(ctx, icon, centered, centered_y, 0.5);
} else {
draw_sprite(ctx, icon, centered, centered_y);
}
}
}