#define ED_STICKYBUTTON_YPOS (ED_BUTTON_MINUS_YPOS + 66)
/* some positions in the editor control window */
-#define ED_BUTTON_ELEM_XPOS 6
-#define ED_BUTTON_ELEM_YPOS 30
-#define ED_BUTTON_ELEM_XSIZE 22
-#define ED_BUTTON_ELEM_YSIZE 22
-
-/* some values for text input and counter gadgets */
-#define ED_BUTTON_COUNT_YPOS 60
-#define ED_BUTTON_COUNT_XSIZE 20
-#define ED_BUTTON_COUNT_YSIZE 20
-#define ED_WIN_COUNT_XPOS (2 + ED_BUTTON_COUNT_XSIZE + 2)
-#define ED_WIN_COUNT_YPOS ED_BUTTON_COUNT_YPOS
-#define ED_WIN_COUNT_XSIZE 52
-#define ED_WIN_COUNT_YSIZE ED_BUTTON_COUNT_YSIZE
-#define ED_WIN_COUNT2_XPOS 27
-#define ED_WIN_COUNT2_YPOS 3
-#define ED_WIN_COUNT2_XSIZE 46
-#define ED_WIN_COUNT2_YSIZE ED_BUTTON_COUNT_YSIZE
-
-#define ED_BUTTON_MINUS_XPOS 2
-#define ED_BUTTON_MINUS_YPOS ED_BUTTON_COUNT_YPOS
-#define ED_BUTTON_MINUS_XSIZE ED_BUTTON_COUNT_XSIZE
-#define ED_BUTTON_MINUS_YSIZE ED_BUTTON_COUNT_YSIZE
-#define ED_BUTTON_PLUS_XPOS (ED_WIN_COUNT_XPOS + ED_WIN_COUNT_XSIZE + 2)
-#define ED_BUTTON_PLUS_YPOS ED_BUTTON_COUNT_YPOS
-#define ED_BUTTON_PLUS_XSIZE ED_BUTTON_COUNT_XSIZE
-#define ED_BUTTON_PLUS_YSIZE ED_BUTTON_COUNT_YSIZE
+#define ED_BUTTON_ELEM_XPOS 6
+#define ED_BUTTON_ELEM_YPOS 30
+#define ED_BUTTON_ELEM_XSIZE 22
+#define ED_BUTTON_ELEM_YSIZE 22
+
+/* some values for text input, selectbox and counter gadgets */
+#define ED_BUTTON_COUNT_YPOS 60
+#define ED_BUTTON_COUNT_XSIZE 20
+#define ED_BUTTON_COUNT_YSIZE 20
+#define ED_WIN_COUNT_XPOS (2 + ED_BUTTON_COUNT_XSIZE + 2)
+#define ED_WIN_COUNT_YPOS ED_BUTTON_COUNT_YPOS
+#define ED_WIN_COUNT_XSIZE 52
+#define ED_WIN_COUNT_YSIZE ED_BUTTON_COUNT_YSIZE
+#define ED_WIN_COUNT2_XPOS 27
+#define ED_WIN_COUNT2_YPOS 3
+#define ED_WIN_COUNT2_XSIZE 46
+#define ED_WIN_COUNT2_YSIZE ED_BUTTON_COUNT_YSIZE
+
+#define ED_BUTTON_MINUS_XPOS 2
+#define ED_BUTTON_MINUS_YPOS ED_BUTTON_COUNT_YPOS
+#define ED_BUTTON_MINUS_XSIZE ED_BUTTON_COUNT_XSIZE
+#define ED_BUTTON_MINUS_YSIZE ED_BUTTON_COUNT_YSIZE
+#define ED_BUTTON_PLUS_XPOS (ED_WIN_COUNT_XPOS + \
+ ED_WIN_COUNT_XSIZE + 2)
+#define ED_BUTTON_PLUS_YPOS ED_BUTTON_COUNT_YPOS
+#define ED_BUTTON_PLUS_XSIZE ED_BUTTON_COUNT_XSIZE
+#define ED_BUTTON_PLUS_YSIZE ED_BUTTON_COUNT_YSIZE
+
+#define ED_SELECTBOX_XPOS ED_WIN_COUNT_XPOS
+#define ED_SELECTBOX_YPOS (ED_WIN_COUNT_YPOS + 2 + \
+ ED_WIN_COUNT_YSIZE)
+#define ED_SELECTBOX_XSIZE ED_WIN_COUNT_XSIZE
+#define ED_SELECTBOX_YSIZE ED_WIN_COUNT_YSIZE
/* editor gadget identifiers */
#define GADGET_ID_LEVEL_NAME 60
#define GADGET_ID_LEVEL_AUTHOR 61
+/* selectbox identifiers */
+#define GADGET_ID_SELECTBOX_TEST 62
+
/* gadgets for scrolling of drawing area */
-#define GADGET_ID_SCROLL_UP 62
-#define GADGET_ID_SCROLL_DOWN 63
-#define GADGET_ID_SCROLL_LEFT 64
-#define GADGET_ID_SCROLL_RIGHT 65
-#define GADGET_ID_SCROLL_HORIZONTAL 66
-#define GADGET_ID_SCROLL_VERTICAL 67
+#define GADGET_ID_SCROLL_UP 63
+#define GADGET_ID_SCROLL_DOWN 64
+#define GADGET_ID_SCROLL_LEFT 65
+#define GADGET_ID_SCROLL_RIGHT 66
+#define GADGET_ID_SCROLL_HORIZONTAL 67
+#define GADGET_ID_SCROLL_VERTICAL 68
/* gadgets for scrolling element list */
-#define GADGET_ID_SCROLL_LIST_UP 68
-#define GADGET_ID_SCROLL_LIST_DOWN 69
-#define GADGET_ID_SCROLL_LIST_VERTICAL 70
+#define GADGET_ID_SCROLL_LIST_UP 69
+#define GADGET_ID_SCROLL_LIST_DOWN 70
+#define GADGET_ID_SCROLL_LIST_VERTICAL 71
/* buttons for level/element properties */
-#define GADGET_ID_RANDOM_PERCENTAGE 71
-#define GADGET_ID_RANDOM_QUANTITY 72
-#define GADGET_ID_RANDOM_RESTRICTED 73
-#define GADGET_ID_DOUBLE_SPEED 74
-#define GADGET_ID_GRAVITY 75
-#define GADGET_ID_STICK_ELEMENT 76
-#define GADGET_ID_EM_SLIPPERY_GEMS 77
-#define GADGET_ID_CUSTOM_INDESTRUCTIBLE 78
-#define GADGET_ID_CUSTOM_CAN_FALL 79
-#define GADGET_ID_CUSTOM_CAN_SMASH 80
-#define GADGET_ID_CUSTOM_PUSHABLE 81
-#define GADGET_ID_CUSTOM_SLIPPERY 82
+#define GADGET_ID_RANDOM_PERCENTAGE 72
+#define GADGET_ID_RANDOM_QUANTITY 73
+#define GADGET_ID_RANDOM_RESTRICTED 74
+#define GADGET_ID_DOUBLE_SPEED 75
+#define GADGET_ID_GRAVITY 76
+#define GADGET_ID_STICK_ELEMENT 77
+#define GADGET_ID_EM_SLIPPERY_GEMS 78
+#define GADGET_ID_CUSTOM_INDESTRUCTIBLE 79
+#define GADGET_ID_CUSTOM_CAN_FALL 80
+#define GADGET_ID_CUSTOM_CAN_SMASH 81
+#define GADGET_ID_CUSTOM_PUSHABLE 82
+#define GADGET_ID_CUSTOM_SLIPPERY 83
/* gadgets for buttons in element list */
-#define GADGET_ID_ELEMENTLIST_FIRST 83
+#define GADGET_ID_ELEMENTLIST_FIRST 84
#define GADGET_ID_ELEMENTLIST_LAST (GADGET_ID_ELEMENTLIST_FIRST + \
ED_NUM_ELEMENTLIST_BUTTONS - 1)
#define ED_TEXTINPUT_ID_LEVEL_FIRST ED_TEXTINPUT_ID_LEVEL_NAME
#define ED_TEXTINPUT_ID_LEVEL_LAST ED_TEXTINPUT_ID_LEVEL_AUTHOR
+/* values for selectbox gadgets */
+#define ED_SELECTBOX_ID_TEST 0
+
+#define ED_NUM_SELECTBOX 1
+
/* values for checkbutton gadgets */
#define ED_CHECKBUTTON_ID_DOUBLE_SPEED 0
#define ED_CHECKBUTTON_ID_GRAVITY 1
}
};
+static char *test_values[] =
+{
+ "test 1",
+ "test 2",
+ "dieser test-text ist viel zu lang fuer die selectbox",
+ "letzter text"
+};
+static int test_index = 0;
+
+static struct
+{
+ int x, y;
+ int gadget_id;
+ int size;
+ char **values;
+ int *index;
+ char *text, *infotext;
+} selectbox_info[ED_NUM_SELECTBOX] =
+{
+ {
+ ED_SETTINGS_XPOS, ED_COUNTER_YPOS(3),
+ GADGET_ID_SELECTBOX_TEST,
+ MAX_PLAYER_NAME_LEN,
+ test_values, &test_index,
+ "test:", "test-selectbox entry"
+ },
+};
+
static struct
{
int xpos, ypos;
static void HandleDrawingAreas(struct GadgetInfo *);
static void HandleCounterButtons(struct GadgetInfo *);
static void HandleTextInputGadgets(struct GadgetInfo *);
+static void HandleSelectboxGadgets(struct GadgetInfo *);
static void HandleRadiobuttons(struct GadgetInfo *);
static void HandleCheckbuttons(struct GadgetInfo *);
static void HandleControlButtons(struct GadgetInfo *);
}
}
+static void CreateSelectboxGadgets()
+{
+ int max_infotext_len = getMaxInfoTextLength();
+ int i;
+
+ for (i=0; i<ED_NUM_SELECTBOX; i++)
+ {
+ Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
+ int gd_x, gd_y;
+ struct GadgetInfo *gi;
+ unsigned long event_mask;
+ char infotext[MAX_OUTPUT_LINESIZE + 1];
+ int id = selectbox_info[i].gadget_id;
+
+ event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
+
+ gd_x = DOOR_GFX_PAGEX4 + ED_SELECTBOX_XPOS;
+ gd_y = DOOR_GFX_PAGEY1 + ED_SELECTBOX_YPOS;
+
+ sprintf(infotext, "Select %s", selectbox_info[i].infotext);
+ infotext[max_infotext_len] = '\0';
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_CUSTOM_TYPE_ID, i,
+ GDI_INFO_TEXT, infotext,
+ GDI_X, SX + selectbox_info[i].x,
+ GDI_Y, SY + selectbox_info[i].y,
+ GDI_TYPE, GD_TYPE_SELECTBOX,
+ GDI_SELECTBOX_VALUES, selectbox_info[i].values,
+ GDI_SELECTBOX_INDEX, selectbox_info[i].index,
+ GDI_TEXT_SIZE, selectbox_info[i].size,
+ GDI_TEXT_FONT, FONT_INPUT,
+ GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
+ GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
+ GDI_BORDER_SIZE, ED_BORDER_SIZE,
+ GDI_BORDER_SIZE_SELECTBUTTON, getFontHeight(FONT_INPUT),
+ GDI_TEXTINPUT_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
+ GDI_CALLBACK_ACTION, HandleSelectboxGadgets,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+}
+
static void CreateScrollbarGadgets()
{
int i;
CreateCounterButtons();
CreateDrawingAreas();
CreateTextInputGadgets();
+ CreateSelectboxGadgets();
CreateScrollbarGadgets();
CreateCheckbuttonGadgets();
}
MapGadget(level_editor_gadget[textinput_info[id].gadget_id]);
}
+static void MapSelectboxGadget(int id)
+{
+ MapGadget(level_editor_gadget[selectbox_info[id].gadget_id]);
+}
+
static void MapRadiobuttonGadget(int id)
{
MapGadget(level_editor_gadget[radiobutton_info[id].gadget_id]);
ModifyGadget(level_editor_gadget[checkbutton_info[i].gadget_id],
GDI_CHECKED, *checkbutton_info[i].value, GDI_END);
MapCheckbuttonGadget(i);
+
+ /* draw selectbox gadget */
+ i = ED_SELECTBOX_ID_TEST;
+ x = selectbox_info[i].x + xoffset_right2;
+ y = selectbox_info[i].y + yoffset_right2;
+
+ selectbox_info[i].index = &test_index;
+
+ DrawTextF(x, y, FONT_TEXT_1, selectbox_info[i].text);
+ ModifyGadget(level_editor_gadget[selectbox_info[i].gadget_id],
+ GDI_SELECTBOX_INDEX, *selectbox_info[i].index, GDI_END);
+ MapSelectboxGadget(i);
}
}
strcpy(textinput_info[gi->custom_type_id].value, gi->text.value);
}
+static void HandleSelectboxGadgets(struct GadgetInfo *gi)
+{
+ *selectbox_info[gi->custom_type_id].index = gi->selectbox.index;
+
+#if 1
+ printf("Selected text value: '%s'\n",
+ selectbox_info[gi->custom_type_id].values[gi->selectbox.index]);
+#endif
+}
+
static void HandleRadiobuttons(struct GadgetInfo *gi)
{
*radiobutton_info[gi->custom_type_id].value =
gd->x, gd->y, border, gi->height, gi->x, gi->y);
/* middle part of gadget */
- for (i=0; i<=gi->text.size; i++)
+ for (i=0; i <= gi->text.size; i++)
BlitBitmapOnBackground(gd->bitmap, drawto,
gd->x + border, gd->y, font_width, gi->height,
gi->x + border + i * font_width, gi->y);
/* right part of gadget */
BlitBitmapOnBackground(gd->bitmap, drawto,
- gd->x + gi->border.width -border, gd->y, border,
+ gd->x + gi->border.width - border, gd->y,border,
gi->height, gi->x + gi->width - border, gi->y);
/* gadget text value */
}
break;
+ case GD_TYPE_SELECTBOX:
+ {
+ int i;
+ char text[MAX_GADGET_TEXTSIZE + 1];
+ int font_type = gi->selectbox.font_type;
+ int font_width = getFontWidth(font_type);
+ int border = gi->border.size;
+ int button = gi->border.size_selectbutton;
+ int width_inner = gi->border.width - button - 2 * border;
+
+ strncpy(text, gi->selectbox.values[gi->selectbox.index],
+ MAX_GADGET_TEXTSIZE);
+ text[MAX_GADGET_TEXTSIZE] = '\0';
+
+ /* left part of gadget */
+ BlitBitmapOnBackground(gd->bitmap, drawto,
+ gd->x, gd->y, border, gi->height, gi->x, gi->y);
+
+ /* middle part of gadget */
+ for (i=0; i <= gi->selectbox.size; i++)
+ BlitBitmapOnBackground(gd->bitmap, drawto,
+ gd->x + border, gd->y, font_width, gi->height,
+ gi->x + border + i * font_width, gi->y);
+
+ /* button part of gadget */
+ BlitBitmapOnBackground(gd->bitmap, drawto,
+ gd->x + border + width_inner, gd->y,
+ button, gi->height,
+ gi->x + gi->width - border - button, gi->y);
+
+ /* right part of gadget */
+ BlitBitmapOnBackground(gd->bitmap, drawto,
+ gd->x + gi->border.width - border, gd->y,border,
+ gi->height, gi->x + gi->width - border, gi->y);
+
+ /* gadget text value */
+ DrawTextExt(drawto,
+ gi->x + border, gi->y + border, text,
+ font_type, FONT_MASKED);
+ }
+ break;
+
case GD_TYPE_SCROLLBAR_VERTICAL:
{
int i;
gi->text.size = max_textsize;
gi->text.value[max_textsize] = '\0';
+
+ /* same tag also used for selectbox definition */
+ gi->selectbox.size = gi->text.size;
}
break;
case GDI_TEXT_FONT:
gi->text.font_type = va_arg(ap, int);
+
+ /* same tag also used for selectbox definition */
+ gi->selectbox.font_type = gi->text.font_type;
+ break;
+
+ case GDI_SELECTBOX_VALUES:
+ gi->selectbox.values = va_arg(ap, const char **);
+ break;
+
+ case GDI_SELECTBOX_INDEX:
+ gi->selectbox.index = va_arg(ap, int);
break;
case GDI_DESIGN_UNPRESSED:
gi->border.size = va_arg(ap, int);
break;
+ case GDI_BORDER_SIZE_SELECTBUTTON:
+ gi->border.size_selectbutton = va_arg(ap, int);
+ break;
+
case GDI_TEXTINPUT_DESIGN_WIDTH:
gi->border.width = va_arg(ap, int);
break;
tag = va_arg(ap, int); /* read next tag */
}
- /* check if gadget complete */
+ /* check if gadget is complete */
if (gi->type != GD_TYPE_DRAWING_AREA &&
(!gi->design[GD_BUTTON_UNPRESSED].bitmap ||
!gi->design[GD_BUTTON_PRESSED].bitmap))
{
int font_width = getFontWidth(gi->text.font_type);
int font_height = getFontHeight(gi->text.font_type);
+ int border_size = gi->border.size;
+
+ gi->width = 2 * border_size + (gi->text.size + 1) * font_width;
+ gi->height = 2 * border_size + font_height;
+ }
+
+ if (gi->type & GD_TYPE_SELECTBOX)
+ {
+ int font_width = getFontWidth(gi->selectbox.font_type);
+ int font_height = getFontHeight(gi->selectbox.font_type);
+ int border_size = gi->border.size;
+ int button_size = gi->border.size_selectbutton;
- gi->width = 2 * gi->border.size + (gi->text.size + 1) * font_width;
- gi->height = 2 * gi->border.size + font_height;
+ gi->width = 2 * border_size + gi->text.size * font_width + button_size;
+ gi->height = 2 * border_size + font_height;
}
if (gi->type & GD_TYPE_TEXTINPUT_NUMERIC)
#define GD_TYPE_DRAWING_AREA (1 << 3)
#define GD_TYPE_TEXTINPUT_ALPHANUMERIC (1 << 4)
#define GD_TYPE_TEXTINPUT_NUMERIC (1 << 5)
-#define GD_TYPE_SCROLLBAR_VERTICAL (1 << 6)
-#define GD_TYPE_SCROLLBAR_HORIZONTAL (1 << 7)
+#define GD_TYPE_SELECTBOX (1 << 6)
+#define GD_TYPE_SCROLLBAR_VERTICAL (1 << 7)
+#define GD_TYPE_SCROLLBAR_HORIZONTAL (1 << 8)
#define GD_TYPE_BUTTON (GD_TYPE_NORMAL_BUTTON | \
GD_TYPE_CHECK_BUTTON | \
#define GDI_TEXT_VALUE 14
#define GDI_TEXT_SIZE 15
#define GDI_TEXT_FONT 16
-#define GDI_DESIGN_UNPRESSED 17
-#define GDI_DESIGN_PRESSED 18
-#define GDI_ALT_DESIGN_UNPRESSED 19
-#define GDI_ALT_DESIGN_PRESSED 20
-#define GDI_BORDER_SIZE 21
-#define GDI_TEXTINPUT_DESIGN_WIDTH 22
-#define GDI_DECORATION_DESIGN 23
-#define GDI_DECORATION_POSITION 24
-#define GDI_DECORATION_SIZE 25
-#define GDI_DECORATION_SHIFTING 26
-#define GDI_EVENT_MASK 27
-#define GDI_EVENT 28
-#define GDI_CALLBACK_INFO 29
-#define GDI_CALLBACK_ACTION 30
-#define GDI_AREA_SIZE 31
-#define GDI_ITEM_SIZE 32
-#define GDI_SCROLLBAR_ITEMS_MAX 33
-#define GDI_SCROLLBAR_ITEMS_VISIBLE 34
-#define GDI_SCROLLBAR_ITEM_POSITION 35
-#define GDI_INFO_TEXT 36
+#define GDI_SELECTBOX_VALUES 17
+#define GDI_SELECTBOX_INDEX 18
+#define GDI_DESIGN_UNPRESSED 19
+#define GDI_DESIGN_PRESSED 20
+#define GDI_ALT_DESIGN_UNPRESSED 21
+#define GDI_ALT_DESIGN_PRESSED 22
+#define GDI_BORDER_SIZE 23
+#define GDI_BORDER_SIZE_SELECTBUTTON 24
+#define GDI_TEXTINPUT_DESIGN_WIDTH 25
+#define GDI_DECORATION_DESIGN 26
+#define GDI_DECORATION_POSITION 27
+#define GDI_DECORATION_SIZE 28
+#define GDI_DECORATION_SHIFTING 29
+#define GDI_EVENT_MASK 30
+#define GDI_EVENT 31
+#define GDI_CALLBACK_INFO 32
+#define GDI_CALLBACK_ACTION 33
+#define GDI_AREA_SIZE 34
+#define GDI_ITEM_SIZE 35
+#define GDI_SCROLLBAR_ITEMS_MAX 36
+#define GDI_SCROLLBAR_ITEMS_VISIBLE 37
+#define GDI_SCROLLBAR_ITEM_POSITION 38
+#define GDI_INFO_TEXT 39
typedef void (*gadget_function)(void *);
struct GadgetBorder
{
int size; /* size of gadget border */
- int width; /* for text input gadgets */
+ int size_selectbutton; /* for selectbox gadgets */
+ int width; /* for selectbox/text input gadgets */
};
struct GadgetDesign
int font_type; /* font to use for text input */
};
+struct GadgetSelectbox
+{
+ const char **values; /* pointer to array of text strings */
+ int index; /* index of actual text string */
+ int size; /* maximal size of text strings */
+ int font_type; /* font to use for text input */
+};
+
struct GadgetScrollbar
{
int items_max; /* number of items to access */
gadget_function callback_action; /* function for gadget action */
struct GadgetDrawingArea drawing; /* fields for drawing area gadget */
struct GadgetTextInput text; /* fields for text input gadget */
+ struct GadgetSelectbox selectbox; /* fields for selectbox gadget */
struct GadgetScrollbar scrollbar; /* fields for scrollbar gadget */
struct GadgetInfo *next; /* next list entry */
};