#define ED_SCROLL_HORIZONTAL_YSIZE ED_SCROLLBUTTON_YSIZE
/* control button identifiers */
+#define ED_CTRL_ID_NONE -1
+
#define ED_CTRL_ID_SINGLE_ITEMS 0
#define ED_CTRL_ID_CONNECTED_ITEMS 1
#define ED_CTRL_ID_LINE 2
#define ED_CTRL_ID_UNUSED1 10
#define ED_CTRL_ID_WRAP_RIGHT 11
#define ED_CTRL_ID_RANDOM_PLACEMENT 12
-#define ED_CTRL_ID_BRUSH 13
+#define ED_CTRL_ID_GRAB_BRUSH 13
#define ED_CTRL_ID_WRAP_DOWN 14
#define ED_CTRL_ID_PICK_ELEMENT 15
#define ED_CTRL_ID_UNDO 16
#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
+{
+ char shortcut;
+ char *text;
+} control_info[ED_NUM_CTRL_BUTTONS] =
+{
+ { 's', "draw single items" },
+ { 'd', "draw connected items" },
+ { 'l', "draw lines" },
+ { 't', "enter text elements" },
+ { 'r', "draw outline rectangles" },
+ { 'R', "draw filled rectangles" },
+ { '\0', "wrap (rotate) level up" },
+ { '?', "properties of drawing element" },
+ { 'f', "flood fill" },
+ { '\0', "wrap (rotate) level left" },
+ { '\0', "" },
+ { '\0', "wrap (rotate) level right" },
+ { '\0', "random element placement" },
+ { 'b', "grab brush" },
+ { '\0', "wrap (rotate) level down" },
+ { ',', "pick drawing element" },
+ { 'U', "undo last operation" },
+ { 'I', "level properties" },
+ { 'S', "save level" },
+ { 'C', "clear level" },
+ { 'T', "test level" },
+ { 'E', "exit level editor" }
};
static struct
},
};
-
/* forward declaration for internal use */
static void DrawDrawingWindow();
static void DrawPropertiesWindow();
id == ED_CTRL_ID_RECTANGLE ||
id == ED_CTRL_ID_FILLED_BOX ||
id == ED_CTRL_ID_FLOOD_FILL ||
- id == ED_CTRL_ID_BRUSH ||
+ id == ED_CTRL_ID_GRAB_BRUSH ||
id == ED_CTRL_ID_PICK_ELEMENT)
{
button_type = GD_TYPE_RADIO_BUTTON;
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_DESCRIPTION_TEXT, control_info[i].text,
GDI_X, EX + gd_xoffset,
GDI_Y, EY + gd_yoffset,
GDI_WIDTH, width,
if (!level_editor_gadgets_created)
CreateLevelEditorGadgets();
+ else
+ strcpy(level_editor_gadget[ED_CTRL_ID_LEVEL_NAME]->text.value, level.name);
MapControlButtons();
#define CB_BRUSH_TO_LEVEL 2
#define CB_DELETE_OLD_CURSOR 3
-static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, int mode)
+static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
+ int button, int mode)
{
static short brush_buffer[ED_FIELDX][ED_FIELDY];
static int brush_width, brush_height;
static int last_cursor_x = -1, last_cursor_y = -1;
static boolean delete_old_brush;
+ int new_element;
int x, y;
if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush)
return;
+ new_element = (button == 1 ? new_element1 :
+ button == 2 ? new_element2 :
+ button == 3 ? new_element3 : 0);
+
if (mode == CB_AREA_TO_BRUSH)
{
int from_lx, from_ly;
from_ly = from_y + level_ypos;
for (y=0; y<brush_height; y++)
+ {
for (x=0; x<brush_width; x++)
+ {
brush_buffer[x][y] = Feld[from_lx + x][from_ly + y];
+ if (button != 1)
+ DrawLineElement(from_x + x, from_y + y, new_element, TRUE);
+ }
+ }
+
+ if (button != 1)
+ CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
+
delete_old_brush = FALSE;
}
else if (mode == CB_BRUSH_TO_CURSOR || mode == CB_DELETE_OLD_CURSOR ||
int border_to_x = cursor_x, border_to_y = cursor_y;
if (mode != CB_DELETE_OLD_CURSOR && delete_old_brush)
- CopyBrushExt(0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
+ CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
if (!IN_LEV_FIELD(cursor_x + level_xpos, cursor_y + level_ypos))
{
int sy = cursor_from_y + y;
int lx = sx + level_xpos;
int ly = sy + level_ypos;
- int element = (mode == CB_DELETE_OLD_CURSOR ? -1 : brush_buffer[x][y]);
boolean change_level = (mode == CB_BRUSH_TO_LEVEL);
+ int element = (mode == CB_DELETE_OLD_CURSOR ? -1 :
+ mode == CB_BRUSH_TO_CURSOR || button == 1 ?
+ brush_buffer[x][y] : new_element);
if (IN_LEV_FIELD(lx, ly) &&
sx >=0 && sx < ED_FIELDX && sy >=0 && sy < ED_FIELDY)
if (mode != CB_DELETE_OLD_CURSOR)
DrawAreaBorder(border_from_x, border_from_y, border_to_x, border_to_y);
+ /*
if (mode == CB_BRUSH_TO_LEVEL)
CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
+ */
last_cursor_x = cursor_x;
last_cursor_y = cursor_y;
}
}
-static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y)
+static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y,
+ int button)
{
- CopyBrushExt(from_x, from_y, to_x, to_y, CB_AREA_TO_BRUSH);
+ CopyBrushExt(from_x, from_y, to_x, to_y, button, CB_AREA_TO_BRUSH);
}
-static void CopyBrushToLevel(int x, int y)
+static void CopyBrushToLevel(int x, int y, int button)
{
- CopyBrushExt(x, y, 0, 0, CB_BRUSH_TO_LEVEL);
+ CopyBrushExt(x, y, 0, 0, button, CB_BRUSH_TO_LEVEL);
}
static void CopyBrushToCursor(int x, int y)
{
- CopyBrushExt(x, y, 0, 0, CB_BRUSH_TO_CURSOR);
+ CopyBrushExt(x, y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
}
static void DeleteBrushFromCursor()
{
- CopyBrushExt(0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
+ CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
}
static void FloodFill(int from_x, int from_y, int fill_element)
int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
int x, y;
+ /* handle info callback for each invocation of action callback */
+ gi->callback_info(gi);
+
/*
if (edit_mode != ED_MODE_DRAWING)
return;
if (!button)
break;
- if (new_element != Feld[lx][ly])
+ if (draw_with_brush)
+ CopyBrushToLevel(sx, sy, button);
+ else if (new_element != Feld[lx][ly])
{
if (new_element == EL_SPIELFIGUR)
{
case ED_CTRL_ID_LINE:
case ED_CTRL_ID_RECTANGLE:
case ED_CTRL_ID_FILLED_BOX:
- case ED_CTRL_ID_BRUSH:
+ case ED_CTRL_ID_GRAB_BRUSH:
case ED_CTRL_ID_TEXT:
{
static int last_sx = -1;
draw_func = DrawRectangle;
else if (drawing_function == ED_CTRL_ID_FILLED_BOX)
draw_func = DrawFilledBox;
- else if (drawing_function == ED_CTRL_ID_BRUSH)
+ else if (drawing_function == ED_CTRL_ID_GRAB_BRUSH)
draw_func = SelectArea;
else /* (drawing_function == ED_CTRL_ID_TEXT) */
draw_func = SetTextCursor;
else if (button_release_event)
{
draw_func(start_sx, start_sy, sx, sy, new_element, TRUE);
- if (drawing_function == ED_CTRL_ID_BRUSH)
+ if (drawing_function == ED_CTRL_ID_GRAB_BRUSH)
{
- CopyAreaToBrush(start_sx, start_sy, sx, sy);
+ CopyAreaToBrush(start_sx, start_sy, sx, sy, button);
+ CopyBrushToCursor(sx, sy);
+ ClickOnGadget(level_editor_gadget[ED_CTRL_ID_SINGLE_ITEMS]);
draw_with_brush = TRUE;
}
else if (drawing_function == ED_CTRL_ID_TEXT)
case ED_CTRL_ID_RECTANGLE:
case ED_CTRL_ID_FILLED_BOX:
case ED_CTRL_ID_FLOOD_FILL:
- case ED_CTRL_ID_BRUSH:
+ case ED_CTRL_ID_GRAB_BRUSH:
case ED_CTRL_ID_PICK_ELEMENT:
last_drawing_function = drawing_function;
drawing_function = id;
+ draw_with_brush = FALSE;
break;
case ED_CTRL_ID_RANDOM_PLACEMENT:
void HandleLevelEditorKeyInput(KeySym key)
{
- if (edit_mode == ED_MODE_DRAWING && drawing_function == ED_CTRL_ID_TEXT)
+ if (edit_mode == ED_MODE_DRAWING)
{
char letter = getCharFromKeySym(key);
- if (letter)
- DrawLevelText(0, 0, letter, TEXT_WRITECHAR);
- else if (key == XK_Delete || key == XK_BackSpace)
- DrawLevelText(0, 0, 0, TEXT_BACKSPACE);
- else if (key == XK_Return)
- DrawLevelText(0, 0, 0, TEXT_NEWLINE);
+ if (drawing_function == ED_CTRL_ID_TEXT)
+ {
+ if (letter)
+ DrawLevelText(0, 0, letter, TEXT_WRITECHAR);
+ else if (key == XK_Delete || key == XK_BackSpace)
+ DrawLevelText(0, 0, 0, TEXT_BACKSPACE);
+ else if (key == XK_Return)
+ DrawLevelText(0, 0, 0, TEXT_NEWLINE);
+ }
+ else if (button_status == MB_RELEASED)
+ {
+ int i, id;
+
+ switch (key)
+ {
+ case XK_Left:
+ id = ED_CTRL_ID_SCROLL_LEFT;
+ break;
+ case XK_Right:
+ id = ED_CTRL_ID_SCROLL_RIGHT;
+ break;
+ case XK_Up:
+ id = ED_CTRL_ID_SCROLL_UP;
+ break;
+ case XK_Down:
+ id = ED_CTRL_ID_SCROLL_DOWN;
+ break;
+
+ default:
+ id = ED_CTRL_ID_NONE;
+ break;
+ }
+
+ if (id != ED_CTRL_ID_NONE)
+ ClickOnGadget(level_editor_gadget[id]);
+ else if (letter == '.')
+ ClickOnGadget(level_editor_gadget[ED_CTRL_ID_SINGLE_ITEMS]);
+ else
+ for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
+ if (letter && letter == control_info[i].shortcut)
+ ClickOnGadget(level_editor_gadget[i]);
+ }
}
}
switch (id)
{
case ED_CTRL_ID_LEVEL_NAME:
- strcpy(level.name, gi->text_value);
+ strcpy(level.name, gi->text.value);
break;
default:
{
struct GadgetInfo *gi = (struct GadgetInfo *)ptr;
char infotext[MAX_INFOTEXT_LEN + 1];
+ char shortcut[20];
ClearEditorGadgetInfoText();
strncpy(infotext, gi->description_text, MAX_INFOTEXT_LEN);
infotext[MAX_INFOTEXT_LEN] = '\0';
+ if (gi->custom_id < ED_NUM_CTRL_BUTTONS)
+ {
+ int key = control_info[gi->custom_id].shortcut;
+
+ if (key)
+ {
+ sprintf(shortcut, " ('%s%c')",
+ (key >= 'A' && key <= 'Z' ? "Shift-" : ""), key);
+
+ if (strlen(infotext) + strlen(shortcut) <= MAX_INFOTEXT_LEN)
+ strcat(infotext, shortcut);
+ }
+ }
+
DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, FS_SMALL, FC_YELLOW);
}
static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
{
+ static int start_lx, start_ly;
+ char *infotext;
int id = gi->custom_id;
int sx = gi->event.x;
int sy = gi->event.y;
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);
+ {
+ if (gi->state == GD_BUTTON_PRESSED)
+ {
+ if (gi->event.type == GD_EVENT_PRESSED)
+ {
+ start_lx = lx;
+ start_ly = ly;
+ }
+
+ switch (drawing_function)
+ {
+ case ED_CTRL_ID_SINGLE_ITEMS:
+ infotext = "Drawing single items";
+ break;
+ case ED_CTRL_ID_CONNECTED_ITEMS:
+ infotext = "Drawing connected items";
+ break;
+ case ED_CTRL_ID_LINE:
+ infotext = "Drawing line";
+ break;
+ case ED_CTRL_ID_TEXT:
+ infotext = "Setting text cursor";
+ break;
+ case ED_CTRL_ID_RECTANGLE:
+ infotext = "Drawing rectangle";
+ break;
+ case ED_CTRL_ID_FILLED_BOX:
+ infotext = "Drawing filled box";
+ break;
+ case ED_CTRL_ID_FLOOD_FILL:
+ infotext = "Flood fill";
+ break;
+ case ED_CTRL_ID_GRAB_BRUSH:
+ infotext = "Grabbing brush";
+ break;
+ case ED_CTRL_ID_PICK_ELEMENT:
+ infotext = "Picking element";
+ break;
+
+ default:
+ infotext = "Drawing position";
+ break;
+ }
+
+ DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
+ "%s: %d, %d", infotext,
+ ABS(lx - start_lx) + 1,
+ ABS(ly - start_ly) + 1);
+ }
+ else
+ DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
+ "Level position: %d, %d", lx, ly);
+ }
/* misuse this function to draw brush cursor, if needed */
if (edit_mode == ED_MODE_DRAWING && draw_with_brush)