From 16a5fb52230df2b470e2519254518ff065be03b9 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 5 Oct 2024 11:54:33 +0200 Subject: [PATCH] improved opening/closing color picker gadget --- src/libgame/gadgets.c | 142 +++++++++++++++++++++++++----------------- src/libgame/gadgets.h | 3 + 2 files changed, 87 insertions(+), 58 deletions(-) diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 3dfd2d04..849f7b49 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -1158,66 +1158,84 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) int xsize = (width - 2 * border_x) / border_x + 1; int ysize = (height - 2 * border_y) / border_y + 1; - // top left part of gadget border - BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y, - border_x, border_y, x, y); - - // top middle part of gadget border - for (i = 0; i < xsize; i++) - BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y, - border_x, border_y, - x + border_x + i * border_x, y); - - // top right part of gadget border - BlitBitmapOnBackground(gd->bitmap, drawto, - gd->x + gi->border.width - border_x, gd->y, - border_x, border_y, - x + width - border_x, y); - - // left and right part of gadget border for each row - for (i = 0; i < ysize; i++) + if (pressed) { - BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y + border_y, - border_x, border_y, - x, y + border_y + i * border_y); - BlitBitmapOnBackground(gd->bitmap, drawto, - gd->x + gi->border.width - border_x, - gd->y + border_y, - border_x, border_y, - x + width - border_x, - y + border_y + i * border_y); - } - - // bottom left part of gadget border - BlitBitmapOnBackground(gd->bitmap, drawto, - gd->x, gd->y + gi->border.height - border_y, - border_x, border_y, - x, y + height - border_y); - - // bottom middle part of gadget border - for (i = 0; i < xsize; i++) - BlitBitmapOnBackground(gd->bitmap, drawto, - gd->x + border_x, - gd->y + gi->border.height - border_y, - border_x, border_y, - x + border_x + i * border_x, - y + height - border_y); - - // bottom right part of gadget border - BlitBitmapOnBackground(gd->bitmap, drawto, - gd->x + gi->border.width - border_x, - gd->y + gi->border.height - border_y, - border_x, border_y, - x + width - border_x, - y + height - border_y); - - ClearRectangleOnBackground(drawto, - x + border_x, - y + border_y, - width - 2 * border_x, - height - 2 * border_y); + if (!gi->colorpicker.open) + { + gi->colorpicker.open = TRUE; + + // save background under color picker + BlitBitmap(drawto, gfx.field_save_buffer, x, y, width, height, x, y); + } + + // top left part of gadget border + BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y, + border_x, border_y, x, y); + + // top middle part of gadget border + for (i = 0; i < xsize; i++) + BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y, + border_x, border_y, + x + border_x + i * border_x, y); + + // top right part of gadget border + BlitBitmapOnBackground(gd->bitmap, drawto, + gd->x + gi->border.width - border_x, gd->y, + border_x, border_y, + x + width - border_x, y); + + // left and right part of gadget border for each row + for (i = 0; i < ysize; i++) + { + BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y + border_y, + border_x, border_y, + x, y + border_y + i * border_y); + BlitBitmapOnBackground(gd->bitmap, drawto, + gd->x + gi->border.width - border_x, + gd->y + border_y, + border_x, border_y, + x + width - border_x, + y + border_y + i * border_y); + } + + // bottom left part of gadget border + BlitBitmapOnBackground(gd->bitmap, drawto, + gd->x, gd->y + gi->border.height - border_y, + border_x, border_y, + x, y + height - border_y); + + // bottom middle part of gadget border + for (i = 0; i < xsize; i++) + BlitBitmapOnBackground(gd->bitmap, drawto, + gd->x + border_x, + gd->y + gi->border.height - border_y, + border_x, border_y, + x + border_x + i * border_x, + y + height - border_y); + + // bottom right part of gadget border + BlitBitmapOnBackground(gd->bitmap, drawto, + gd->x + gi->border.width - border_x, + gd->y + gi->border.height - border_y, + border_x, border_y, + x + width - border_x, + y + height - border_y); + + ClearRectangleOnBackground(drawto, + x + border_x, + y + border_y, + width - 2 * border_x, + height - 2 * border_y); + + DrawColorPicker(gi); + } + else if (gi->colorpicker.open) + { + gi->colorpicker.open = FALSE; - DrawColorPicker(gi); + // restore background under color picker + BlitBitmap(gfx.field_save_buffer, drawto, x, y, width, height, x, y); + } } break; @@ -1927,6 +1945,9 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) }; cp_color_hsv = rgb_to_hsv(cp_color_rgb); + + // always start with closed color picker + gi->colorpicker.open = FALSE; } } @@ -2048,7 +2069,12 @@ static void MapGadgetExt(struct GadgetInfo *gi, boolean redraw) // when mapping color picker gadget, automatically activate it if (gi->type & GD_TYPE_COLOR_PICKER) + { + if (redraw) + DrawGadget(gi, DG_PRESSED, DG_BUFFERED); + last_gi = gi; + } } void MapGadget(struct GadgetInfo *gi) diff --git a/src/libgame/gadgets.h b/src/libgame/gadgets.h index c7e8d17e..9d616260 100644 --- a/src/libgame/gadgets.h +++ b/src/libgame/gadgets.h @@ -251,6 +251,9 @@ struct GadgetColorPicker int nr; // color slot (if using several colors) int type; // color type (RGB, C64, C64DTV, Atari) int value; // color value + + // runtime values + boolean open; // opening state of color picker }; struct GadgetInfo -- 2.34.1