From: Holger Schemel Date: Fri, 20 Sep 2024 19:58:29 +0000 (+0200) Subject: added using color picker gadget prototype in level editor X-Git-Tag: 4.4.0.0-test-4~210 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=5f016a5e6e17b933e0c494ef2c45b1aca6595e80;p=rocksndiamonds.git added using color picker gadget prototype in level editor --- diff --git a/src/conf_gfx.c b/src/conf_gfx.c index 2bc30921..43d3b8b1 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -8145,6 +8145,14 @@ struct ConfigInfo image_config[] = { "editor.input.textarea.active_xoffset", "-100" }, { "editor.input.textarea.border_size", "3" }, + { "editor.input.colorpicker", "RocksDoor.png" }, + { "editor.input.colorpicker.x", "324" }, + { "editor.input.colorpicker.y", "60" }, + { "editor.input.colorpicker.width", "52" }, + { "editor.input.colorpicker.height", "20" }, + { "editor.input.colorpicker.active_xoffset", "-100" }, + { "editor.input.colorpicker.border_size", "3" }, + { "editor.cascade_list", "RocksMore.png" }, { "editor.cascade_list.xpos", "9" }, { "editor.cascade_list.ypos", "8" }, diff --git a/src/editor.c b/src/editor.c index 13ce2702..5baac1e2 100644 --- a/src/editor.c +++ b/src/editor.c @@ -898,6 +898,10 @@ enum GADGET_ID_CHANGE_BY_DIRECT_ACT, GADGET_ID_CHANGE_BY_OTHER_ACT, + // color picker identifiers + + GADGET_ID_COLOR_PICKER, + NUM_STATIC_GADGET_IDS }; @@ -1415,6 +1419,17 @@ enum #define ED_DRAWING_ID_EDITOR_FIRST ED_DRAWING_ID_RANDOM_BACKGROUND #define ED_DRAWING_ID_EDITOR_LAST ED_DRAWING_ID_RANDOM_BACKGROUND +// values for color picker gadgets +enum +{ + ED_COLORPICKER_ID_PICK_COLOR, + + ED_NUM_COLORPICKERS +}; + +#define ED_COLORPICKER_ID_FIRST ED_COLORPICKER_ID_PICK_COLOR +#define ED_COLORPICKER_ID_LAST ED_COLORPICKER_ID_PICK_COLOR + // ---------------------------------------------------------------------------- // some internally used definitions @@ -5408,6 +5423,24 @@ static struct }, }; +static struct +{ + int gadget_type_id; + int x, y; + int gadget_id; + int *value; + char *infotext; +} colorpicker_info[ED_NUM_COLORPICKERS] = +{ + { + ED_COLORPICKER_ID_PICK_COLOR, + 8, 40, + GADGET_ID_COLOR_PICKER, + NULL, + "Select color" + }, +}; + // ---------------------------------------------------------------------------- // some internally used variables @@ -5479,6 +5512,7 @@ static void HandleRadiobuttons(struct GadgetInfo *); static void HandleCheckbuttons(struct GadgetInfo *); static void HandleControlButtons(struct GadgetInfo *); static void HandleDrawingAreaInfo(struct GadgetInfo *); +static void HandleColorPickerGadgets(struct GadgetInfo *); static void PrintEditorGadgetInfoText(struct GadgetInfo *); static boolean AskToCopyAndModifyLevelTemplate(void); static boolean getDrawModeHiRes(void); @@ -9428,6 +9462,49 @@ static void CreateRadiobuttonGadgets(void) } } +static void CreateColorPickerGadgets(void) +{ + int i; + + for (i = 0; i < ED_NUM_COLORPICKERS; i++) + { + struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_INPUT_COLORPICKER]; + int gd_x1 = gd->src_x; + int gd_y1 = gd->src_y; + int gd_x2 = gd->src_x + gd->active_xoffset; + int gd_y2 = gd->src_y + gd->active_yoffset; + struct GadgetInfo *gi; + unsigned int event_mask = GD_EVENT_COLOR_PICKER_LEAVING; + int id = colorpicker_info[i].gadget_id; + int type_id = colorpicker_info[i].gadget_type_id; + + if (type_id != i) + Fail("'colorpicker_info' structure corrupted at index %d -- please fix", i); + + gi = CreateGadget(GDI_CUSTOM_ID, id, + GDI_CUSTOM_TYPE_ID, type_id, + GDI_INFO_TEXT, colorpicker_info[i].infotext, + GDI_X, SX + ED_SETTINGS_X(colorpicker_info[i].x), + GDI_Y, SY + ED_SETTINGS_Y(colorpicker_info[i].y), + GDI_TYPE, GD_TYPE_COLOR_PICKER, + GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1, + GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2, + GDI_BORDER_SIZE, gd->border_size, gd->border_size, + GDI_DESIGN_WIDTH, gd->width, + GDI_DESIGN_HEIGHT, gd->height, + GDI_EVENT_MASK, event_mask, + GDI_CALLBACK_INFO, HandleEditorGadgetInfoText, + GDI_CALLBACK_ACTION, HandleColorPickerGadgets, + GDI_CALLBACK_ACTION_ALWAYS, TRUE, + GDI_END); + + if (gi == NULL) + Fail("cannot create gadget"); + + level_editor_gadget[id] = gi; + } +} + void CreateLevelEditorGadgets(void) { // force EDITOR font inside level editor @@ -9471,6 +9548,7 @@ void CreateLevelEditorGadgets(void) CreateGraphicbuttonGadgets(); CreateTextbuttonGadgets(); CreateDrawingAreas(); + CreateColorPickerGadgets(); ResetFontStatus(); } @@ -9810,6 +9888,13 @@ static void MapCheckbuttonGadget(int id) MapGadget(gi); } +static void MapColorPickerGadget(int id) +{ + struct GadgetInfo *gi = level_editor_gadget[colorpicker_info[id].gadget_id]; + + MapGadget(gi); +} + static void MapMainDrawingArea(void) { boolean no_horizontal_scrollbar = (lev_fieldx + 2 <= ed_fieldx); @@ -16898,7 +16983,7 @@ static void HandleGraphicbuttonGadgets(struct GadgetInfo *gi) else if (type_id >= ED_GRAPHICBUTTON_ID_PICK_FIRST || type_id <= ED_GRAPHICBUTTON_ID_PICK_LAST) { - Warn("color picker not implemented yet"); + MapColorPickerGadget(ED_COLORPICKER_ID_PICK_COLOR); } } @@ -17035,6 +17120,16 @@ static void HandleCheckbuttons(struct GadgetInfo *gi) level.changed = TRUE; } +static void HandleColorPickerGadgets(struct GadgetInfo *gi) +{ + int type_id = gi->custom_type_id; + + if (type_id == ED_COLORPICKER_ID_PICK_COLOR) + DrawLevelConfigWindow(); + + level.changed = TRUE; +} + static void HandleControlButtons(struct GadgetInfo *gi) { static int last_level_drawing_function = GADGET_ID_SINGLE_ITEMS;