return gi;
}
-static void default_callback_function(void *ptr)
+static void default_callback_info(void *ptr)
+{
+ if (game_status == LEVELED)
+ HandleEditorGadgetInfoText(ptr);
+}
+
+static void default_callback_action(void *ptr)
{
return;
}
/* always start with reliable default values */
memset(new_gadget, 0, sizeof(struct GadgetInfo)); /* zero all fields */
- new_gadget->id = getNewGadgetID(); /* new gadget id */
- new_gadget->callback = default_callback_function; /* dummy function */
+ new_gadget->id = getNewGadgetID();
+ new_gadget->callback_info = default_callback_info;
+ new_gadget->callback_action = default_callback_action;
while (tag != GDI_END)
{
new_gadget->custom_id = va_arg(ap, int);
break;
+ case GDI_DESCRIPTION_TEXT:
+ new_gadget->description_text = va_arg(ap, char *);
+ break;
+
case GDI_X:
new_gadget->x = va_arg(ap, int);
break;
new_gadget->scrollbar.item_position = va_arg(ap, int);
break;
- case GDI_CALLBACK:
- new_gadget->callback = va_arg(ap, gadget_callback_function);
+ case GDI_CALLBACK_INFO:
+ new_gadget->callback_info = va_arg(ap, gadget_function);
+ break;
+
+ case GDI_CALLBACK_ACTION:
+ new_gadget->callback_action = va_arg(ap, gadget_function);
break;
default:
void HandleGadgets(int mx, int my, int button)
{
+ static struct GadgetInfo *last_info_gi = NULL;
static unsigned long pressed_delay = 0;
static int last_button = 0;
static int last_mx = 0, last_my = 0;
boolean gadget_released;
boolean gadget_released_inside;
boolean gadget_released_off_borders;
+ boolean changed_position = FALSE;
/* check if there are any gadgets defined */
if (gadget_list_first_entry == NULL)
DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
if (gi->event_mask & GD_EVENT_TEXT_LEAVING)
- gi->callback(gi);
+ gi->callback_action(gi);
last_gi = NULL;
}
if (button == 0 && last_gi && last_gi->type != GD_TYPE_TEXTINPUT)
last_gi = NULL;
- if (gi)
+ if (new_gi)
{
- gi->event.x = mx - gi->x;
- gi->event.y = my - gi->y;
+ int last_x = new_gi->event.x;
+ int last_y = new_gi->event.y;
- if (gi->type == GD_TYPE_DRAWING_AREA)
+ new_gi->event.x = mx - new_gi->x;
+ new_gi->event.y = my - new_gi->y;
+
+ if (new_gi->type == GD_TYPE_DRAWING_AREA)
{
- gi->event.x /= gi->drawing.item_xsize;
- gi->event.y /= gi->drawing.item_ysize;
+ new_gi->event.x /= new_gi->drawing.item_xsize;
+ new_gi->event.y /= new_gi->drawing.item_ysize;
+
+ if (last_x != new_gi->event.x || last_y != new_gi->event.y)
+ changed_position = TRUE;
}
}
+ /* handle gadget popup info text */
+ if (last_info_gi != new_gi ||
+ (new_gi && new_gi->type == GD_TYPE_DRAWING_AREA))
+ {
+ last_info_gi = new_gi;
+
+ if (new_gi != NULL)
+ new_gi->callback_info(new_gi);
+ else
+ default_callback_info(NULL);
+ }
+
if (gadget_pressed)
{
if (gi->type == GD_TYPE_RADIO_BUTTON)
struct GadgetScrollbar *gs = &gi->scrollbar;
int old_item_position = gs->item_position;
- boolean changed_position = FALSE;
+
+ changed_position = FALSE;
gs->item_position +=
gs->items_visible * (mpos < gpos + gi->scrollbar.position ? -1 : +1);
gi->event.off_borders = FALSE;
if (gi->event_mask & GD_EVENT_MOVING && changed_position)
- gi->callback(gi);
+ gi->callback_action(gi);
/* don't handle this scrollbar anymore while mouse button pressed */
last_gi = NULL;
DelayReached(&pressed_delay, GADGET_FRAME_DELAY);
if (gi->event_mask & GD_EVENT_PRESSED)
- gi->callback(gi);
+ gi->callback_action(gi);
}
if (gadget_pressed_repeated)
{
if (gi->event_mask & GD_EVENT_REPEATED &&
DelayReached(&pressed_delay, GADGET_FRAME_DELAY))
- gi->callback(gi);
+ gi->callback_action(gi);
}
if (gadget_moving)
{
- boolean changed_position = FALSE;
-
if (gi->type & GD_TYPE_BUTTON)
{
if (gadget_moving_inside && gi->state == GD_BUTTON_UNPRESSED)
DrawGadget(gi, DG_PRESSED, DG_DIRECT);
}
- if (gi->type == GD_TYPE_DRAWING_AREA)
- changed_position = TRUE;
-
gi->state = (gadget_moving_inside || gi->type & GD_TYPE_SCROLLBAR ?
GD_BUTTON_PRESSED : GD_BUTTON_UNPRESSED);
gi->event.type = GD_EVENT_MOVING;
if (gi->event_mask & GD_EVENT_MOVING && changed_position &&
(gadget_moving_inside || gi->event_mask & GD_EVENT_OFF_BORDERS))
- gi->callback(gi);
+ gi->callback_action(gi);
}
if (gadget_released_inside)
gi->event.type = GD_EVENT_RELEASED;
if (gi->event_mask & GD_EVENT_RELEASED)
- gi->callback(gi);
+ gi->callback_action(gi);
}
if (gadget_released_off_borders)
if (gi->event_mask & GD_EVENT_RELEASED &&
gi->event_mask & GD_EVENT_OFF_BORDERS)
- gi->callback(gi);
+ gi->callback_action(gi);
}
}
DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
if (gi->event_mask & GD_EVENT_TEXT_RETURN)
- gi->callback(gi);
+ gi->callback_action(gi);
last_gi = NULL;
}
/* values for properties window */
#define ED_PROPERTIES_XPOS (TILEX - MINI_TILEX/2)
+
/* values for counter gadgets */
#define ED_COUNT_VALUE_XOFFSET 5
#define ED_COUNT_VALUE_YOFFSET 3
#define UNDO_IMMEDIATE 0
#define UNDO_ACCUMULATE 1
+static char *control_infotext[ED_NUM_CTRL_BUTTONS] =
+{
+ "draw single items",
+ "draw connected items",
+ "draw lines",
+ "enter text elements",
+ "draw outline rectangles",
+ "draw filled boxes",
+ "wrap (rotate) level up",
+ "properties of drawing element",
+ "flood fill",
+ "wrap (rotate) level left",
+ "",
+ "wrap (rotate) level right",
+ "random element placement",
+ "grab brush",
+ "wrap (rotate) level down",
+ "pick drawing element from editing area",
+ "undo last operation",
+ "level properties",
+ "save level",
+ "clear level",
+ "test level",
+ "exit level editor",
+};
+
static struct
{
int x, y;
int xpos, ypos;
int x, y;
int gadget_id;
+ char *text;
} scrollbutton_info[ED_NUM_SCROLLBUTTONS] =
{
- { ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 0 * ED_SCROLLBUTTON_YSIZE,
- ED_SCROLL_UP_XPOS, ED_SCROLL_UP_YPOS, ED_CTRL_ID_SCROLL_UP },
- { ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 1 * ED_SCROLLBUTTON_YSIZE,
- ED_SCROLL_DOWN_XPOS, ED_SCROLL_DOWN_YPOS, ED_CTRL_ID_SCROLL_DOWN },
- { ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 2 * ED_SCROLLBUTTON_YSIZE,
- ED_SCROLL_LEFT_XPOS, ED_SCROLL_LEFT_YPOS, ED_CTRL_ID_SCROLL_LEFT },
- { ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 3 * ED_SCROLLBUTTON_YSIZE,
- ED_SCROLL_RIGHT_XPOS, ED_SCROLL_RIGHT_YPOS, ED_CTRL_ID_SCROLL_RIGHT }
+ {
+ ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 0 * ED_SCROLLBUTTON_YSIZE,
+ ED_SCROLL_UP_XPOS, ED_SCROLL_UP_YPOS, ED_CTRL_ID_SCROLL_UP,
+ "scroll level editing area up"
+ },
+ {
+ ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 1 * ED_SCROLLBUTTON_YSIZE,
+ ED_SCROLL_DOWN_XPOS, ED_SCROLL_DOWN_YPOS, ED_CTRL_ID_SCROLL_DOWN,
+ "scroll level editing area down"
+ },
+ {
+ ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 2 * ED_SCROLLBUTTON_YSIZE,
+ ED_SCROLL_LEFT_XPOS, ED_SCROLL_LEFT_YPOS, ED_CTRL_ID_SCROLL_LEFT,
+ "scroll level editing area left"
+ },
+ {
+ ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 3 * ED_SCROLLBUTTON_YSIZE,
+ ED_SCROLL_RIGHT_XPOS, ED_SCROLL_RIGHT_YPOS, ED_CTRL_ID_SCROLL_RIGHT,
+ "scroll level editing area right"
+ }
};
static struct
int width, height;
int type;
int gadget_id;
+ char *text;
} scrollbar_info[ED_NUM_SCROLLBARS] =
{
- { ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS,
+ {
+ ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS,
ED_SCROLL_VERTICAL_XPOS, ED_SCROLL_VERTICAL_YPOS,
ED_SCROLL_VERTICAL_XSIZE, ED_SCROLL_VERTICAL_YSIZE,
GD_TYPE_SCROLLBAR_VERTICAL,
- ED_CTRL_ID_SCROLL_VERTICAL },
- { ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS,
+ ED_CTRL_ID_SCROLL_VERTICAL,
+ "scroll level editing area vertically"
+ },
+ {
+ ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS,
ED_SCROLL_HORIZONTAL_XPOS, ED_SCROLL_HORIZONTAL_YPOS,
ED_SCROLL_HORIZONTAL_XSIZE, ED_SCROLL_HORIZONTAL_YSIZE,
GD_TYPE_SCROLLBAR_HORIZONTAL,
- ED_CTRL_ID_SCROLL_HORIZONTAL },
+ ED_CTRL_ID_SCROLL_HORIZONTAL,
+ "scroll level editing area horizontally"
+ },
};
static void HandleControlButtons(struct GadgetInfo *);
static void HandleCounterButtons(struct GadgetInfo *);
static void HandleDrawingAreas(struct GadgetInfo *);
+static void HandleDrawingAreaInfo(struct GadgetInfo *);
static void HandleTextInputGadgets(struct GadgetInfo *);
static struct GadgetInfo *level_editor_gadget[ED_NUM_GADGETS];
gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_DESCRIPTION_TEXT, control_infotext[i],
GDI_X, EX + gd_xoffset,
GDI_Y, EY + gd_yoffset,
GDI_WIDTH, width,
GDI_ALT_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y2,
GDI_ALT_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y2,
GDI_EVENT_MASK, event_mask,
- GDI_CALLBACK, HandleControlButtons,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
GDI_END);
if (gi == NULL)
gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_DESCRIPTION_TEXT, scrollbutton_info[i].text,
GDI_X, SX + scrollbutton_info[i].x,
GDI_Y, SY + scrollbutton_info[i].y,
GDI_WIDTH, ED_SCROLLBUTTON_XSIZE,
GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y,
GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y,
GDI_EVENT_MASK, event_mask,
- GDI_CALLBACK, HandleControlButtons,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
GDI_END);
if (gi == NULL)
GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y,
GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y,
GDI_EVENT_MASK, event_mask,
- GDI_CALLBACK, HandleCounterButtons,
+ GDI_CALLBACK_ACTION, HandleCounterButtons,
GDI_END);
if (gi == NULL)
gi = CreateGadget(GDI_CUSTOM_ID, id,
GDI_X, SX,
GDI_Y, SY,
-
- /*
- GDI_WIDTH, SXSIZE,
- GDI_HEIGHT, SYSIZE,
- */
-
GDI_TYPE, GD_TYPE_DRAWING_AREA,
GDI_AREA_SIZE, ED_FIELDX, ED_FIELDY,
GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
GDI_EVENT_MASK, event_mask,
- GDI_CALLBACK, HandleDrawingAreas,
+ GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
+ GDI_CALLBACK_ACTION, HandleDrawingAreas,
GDI_END);
if (gi == NULL)
GDI_TYPE, GD_TYPE_DRAWING_AREA,
GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
GDI_EVENT_MASK, event_mask,
- GDI_CALLBACK, HandleDrawingAreas,
+ GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
+ GDI_CALLBACK_ACTION, HandleDrawingAreas,
GDI_END);
if (gi == NULL)
GDI_TYPE, GD_TYPE_DRAWING_AREA,
GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
GDI_EVENT_MASK, event_mask,
- GDI_CALLBACK, HandleDrawingAreas,
+ GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
+ GDI_CALLBACK_ACTION, HandleDrawingAreas,
GDI_END);
if (gi == NULL)
GDI_DESIGN_PRESSED, gd_pixmap, gd_x, gd_y,
GDI_DESIGN_BORDER, 3,
GDI_EVENT_MASK, event_mask,
- GDI_CALLBACK, HandleTextInputGadgets,
+ GDI_CALLBACK_ACTION, HandleTextInputGadgets,
GDI_END);
if (gi == NULL)
gd_y2 = DOOR_GFX_PAGEY1 + scrollbar_info[i].ypos;
gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_DESCRIPTION_TEXT, scrollbar_info[i].text,
GDI_X, SX + scrollbar_info[i].x,
GDI_Y, SY + scrollbar_info[i].y,
GDI_WIDTH, scrollbar_info[i].width,
GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y2,
GDI_DESIGN_BORDER, 3,
GDI_EVENT_MASK, event_mask,
- GDI_CALLBACK, HandleControlButtons,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
GDI_END);
if (gi == NULL)
level_ypos = -1;
}
+void AdjustEditorScrollbar(int id)
+{
+ struct GadgetInfo *gi = level_editor_gadget[id];
+ struct GadgetScrollbar *gs = &gi->scrollbar;
+ int items_max, items_visible, item_position = gs->item_position;
+
+ if (id == ED_CTRL_ID_SCROLL_HORIZONTAL)
+ {
+ items_max = lev_fieldx + 2;
+ items_visible = ED_FIELDX;
+ }
+ else
+ {
+ items_max = lev_fieldy + 2;
+ items_visible = ED_FIELDY;
+ }
+
+ if (item_position > items_max - items_visible)
+ item_position = items_max - items_visible;
+
+ AdjustScrollbar(gi, items_max, item_position);
+}
+
static void PickDrawingElement(int button, int element)
{
if (button < 1 || button > 3)
{
ClearWindow();
UnmapLevelEditorWindowGadgets();
- MapMainDrawingArea();
AdjustLevelScrollPosition();
+ AdjustEditorScrollbar(ED_CTRL_ID_SCROLL_HORIZONTAL);
+ AdjustEditorScrollbar(ED_CTRL_ID_SCROLL_VERTICAL);
DrawMiniLevel(level_xpos, level_ypos);
+ MapMainDrawingArea();
}
static void DrawElementContentAreas()
break;
}
}
+
+/* values for ClearEditorGadgetInfoText() and HandleGadgetInfoText() */
+#define INFOTEXT_XPOS SX
+#define INFOTEXT_YPOS (SY + SYSIZE - MINI_TILEX + 2)
+#define INFOTEXT_XSIZE SXSIZE
+#define INFOTEXT_YSIZE MINI_TILEX
+#define MAX_INFOTEXT_LEN (SXSIZE / FONT2_XSIZE)
+
+void ClearEditorGadgetInfoText()
+{
+ XFillRectangle(display, drawto, gc,
+ INFOTEXT_XPOS, INFOTEXT_YPOS, INFOTEXT_XSIZE, INFOTEXT_YSIZE);
+ redraw_mask |= REDRAW_FIELD;
+}
+
+void HandleEditorGadgetInfoText(void *ptr)
+{
+ struct GadgetInfo *gi = (struct GadgetInfo *)ptr;
+ char infotext[MAX_INFOTEXT_LEN + 1];
+
+ ClearEditorGadgetInfoText();
+
+ if (gi == NULL || gi->description_text == NULL)
+ return;
+
+ strncpy(infotext, gi->description_text, MAX_INFOTEXT_LEN);
+ infotext[MAX_INFOTEXT_LEN] = '\0';
+
+ DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, FS_SMALL, FC_YELLOW);
+}
+
+static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
+{
+ int id = gi->custom_id;
+ int sx = gi->event.x;
+ int sy = gi->event.y;
+ int lx = sx + level_xpos;
+ int ly = sy + level_ypos;
+
+ ClearEditorGadgetInfoText();
+
+ if (id == ED_CTRL_ID_DRAWING_LEVEL)
+ {
+ if (IN_LEV_FIELD(lx, ly))
+ DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
+ "Level: %d, %d (Screen: %d, %d)", lx, ly, sx, sy);
+ }
+ else if (id == ED_CTRL_ID_AMOEBA_CONTENT)
+ DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
+ "Amoeba content");
+ else
+ DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
+ "Cruncher %d content: %d, %d", id - ED_CTRL_ID_ELEMCONT_0 + 1,
+ sx, sy);
+}