+ counterbutton_info[ED_COUNTER_ID_ELEM_SCORE].value =
+ elements_with_counter[i].value;
+
+ DrawTextF(x, y, font_color, elements_with_counter[i].text);
+
+
+ /*
+ ModifyEditorCounter(ED_COUNTER_ID_ELEM_SCORE, *gadget_elem_score_value);
+ */
+
+
+ ModifyEditorCounter(ED_COUNTER_ID_ELEM_SCORE,
+ *counterbutton_info[ED_COUNTER_ID_ELEM_SCORE].value);
+
+ MapCounterButtons(ED_COUNTER_ID_ELEM_SCORE);
+ break;
+ }
+ }
+
+ if (HAS_CONTENT(properties_element))
+ {
+ /* draw stickybutton gadget */
+ i = ED_CHECKBUTTON_ID_STICK_ELEMENT;
+ x = checkbutton_info[i].x + xoffset_right2;
+ y = checkbutton_info[i].y + yoffset_right2;
+
+ DrawTextF(x, y, font_color, checkbutton_info[i].text);
+ ModifyGadget(level_editor_gadget[checkbutton_info[i].gadget_id],
+ GDI_CHECKED, *checkbutton_info[i].value, GDI_END);
+ MapCheckbuttonGadget(i);
+
+ if (IS_AMOEBOID(properties_element))
+ DrawAmoebaContentArea();
+ else
+ DrawElementContentAreas();
+ }
+}
+
+static void swap_numbers(int *i1, int *i2)
+{
+ int help = *i1;
+
+ *i1 = *i2;
+ *i2 = help;
+}
+
+static void swap_number_pairs(int *x1, int *y1, int *x2, int *y2)
+{
+ int help_x = *x1;
+ int help_y = *y1;
+
+ *x1 = *x2;
+ *x2 = help_x;
+
+ *y1 = *y2;
+ *y2 = help_y;
+}
+
+static void DrawLineElement(int sx, int sy, int element, boolean change_level)
+{
+ int lx = sx + level_xpos;
+ int ly = sy + level_ypos;
+
+ DrawMiniElement(sx, sy, (element < 0 ? Feld[lx][ly] : element));
+
+ if (change_level)
+ Feld[lx][ly] = element;
+}
+
+static void DrawLine(int from_x, int from_y, int to_x, int to_y,
+ int element, boolean change_level)
+{
+ if (from_y == to_y) /* horizontal line */
+ {
+ int x;
+ int y = from_y;
+
+ if (from_x > to_x)
+ swap_numbers(&from_x, &to_x);
+
+ for (x=from_x; x<=to_x; x++)
+ DrawLineElement(x, y, element, change_level);
+ }
+ else if (from_x == to_x) /* vertical line */
+ {
+ int x = from_x;
+ int y;
+
+ if (from_y > to_y)
+ swap_numbers(&from_y, &to_y);
+
+ for (y=from_y; y<=to_y; y++)
+ DrawLineElement(x, y, element, change_level);
+ }
+ else /* diagonal line */
+ {
+ int len_x = ABS(to_x - from_x);
+ int len_y = ABS(to_y - from_y);
+ int x, y;
+
+ if (len_y < len_x) /* a < 1 */
+ {
+ float a = (float)len_y / (float)len_x;
+
+ if (from_x > to_x)
+ swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
+
+ for (x=0; x<=len_x; x++)
+ {
+ y = (int)(a * x + 0.5) * (to_y < from_y ? -1 : +1);
+ DrawLineElement(from_x + x, from_y + y, element, change_level);
+ }
+ }
+ else /* a >= 1 */
+ {
+ float a = (float)len_x / (float)len_y;
+
+ if (from_y > to_y)
+ swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
+
+ for (y=0; y<=len_y; y++)
+ {
+ x = (int)(a * y + 0.5) * (to_x < from_x ? -1 : +1);
+ DrawLineElement(from_x + x, from_y + y, element, change_level);
+ }
+ }
+ }
+}
+
+static void DrawRectangle(int from_x, int from_y, int to_x, int to_y,
+ int element, boolean change_level)
+{
+ DrawLine(from_x, from_y, from_x, to_y, element, change_level);
+ DrawLine(from_x, to_y, to_x, to_y, element, change_level);
+ DrawLine(to_x, to_y, to_x, from_y, element, change_level);
+ DrawLine(to_x, from_y, from_x, from_y, element, change_level);
+}
+
+static void DrawFilledBox(int from_x, int from_y, int to_x, int to_y,
+ int element, boolean change_level)
+{
+ int y;
+
+ if (from_y > to_y)
+ swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
+
+ for (y=from_y; y<=to_y; y++)
+ DrawLine(from_x, y, to_x, y, element, change_level);
+}
+
+static void DrawArcExt(int from_x, int from_y, int to_x2, int to_y2,
+ int element, boolean change_level)
+{
+ int to_x = to_x2 - (to_x2 > from_x ? +1 : -1);
+ int to_y = to_y2 - (to_y2 > from_y ? +1 : -1);
+ int len_x = ABS(to_x - from_x);
+ int len_y = ABS(to_y - from_y);
+ int radius, x, y;
+
+ radius = (int)(sqrt((float)(len_x * len_x + len_y * len_y)) + 0.5);
+
+ /* not optimal (some points get drawn twice) but simple,
+ and fast enough for the few points we are drawing */
+
+ for (x=0; x<=radius; x++)
+ {
+ int sx, sy, lx, ly;
+
+ y = (int)(sqrt((float)(radius * radius - x * x)) + 0.5);
+
+ sx = from_x + x * (from_x < to_x2 ? +1 : -1);
+ sy = from_y + y * (from_y < to_y2 ? +1 : -1);
+ lx = sx + level_xpos;
+ ly = sy + level_ypos;
+
+ if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
+ DrawLineElement(sx, sy, element, change_level);
+ }
+
+ for (y=0; y<=radius; y++)
+ {
+ int sx, sy, lx, ly;
+
+ x = (int)(sqrt((float)(radius * radius - y * y)) + 0.5);
+
+ sx = from_x + x * (from_x < to_x2 ? +1 : -1);
+ sy = from_y + y * (from_y < to_y2 ? +1 : -1);
+ lx = sx + level_xpos;
+ ly = sy + level_ypos;
+
+ if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
+ DrawLineElement(sx, sy, element, change_level);
+ }
+}
+
+static void DrawArc(int from_x, int from_y, int to_x, int to_y,
+ int element, boolean change_level)
+{
+ int to_x2 = to_x + (to_x < from_x ? -1 : +1);
+ int to_y2 = to_y + (to_y > from_y ? +1 : -1);
+
+ DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
+}
+
+#define DRAW_CIRCLES_BUTTON_AVAILABLE 0
+#if DRAW_CIRCLES_BUTTON_AVAILABLE
+static void DrawCircle(int from_x, int from_y, int to_x, int to_y,
+ int element, boolean change_level)
+{
+ int to_x2 = to_x + (to_x < from_x ? -1 : +1);
+ int to_y2 = to_y + (to_y > from_y ? +1 : -1);
+ int mirror_to_x2 = from_x - (to_x2 - from_x);
+ int mirror_to_y2 = from_y - (to_y2 - from_y);
+
+ DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
+ DrawArcExt(from_x, from_y, mirror_to_x2, to_y2, element, change_level);
+ DrawArcExt(from_x, from_y, to_x2, mirror_to_y2, element, change_level);
+ DrawArcExt(from_x, from_y, mirror_to_x2, mirror_to_y2, element,change_level);
+}
+#endif
+
+static void DrawAreaBorder(int from_x, int from_y, int to_x, int to_y)
+{
+ int from_sx, from_sy;
+ int to_sx, to_sy;
+
+ if (from_x > to_x)
+ swap_numbers(&from_x, &to_x);
+
+ if (from_y > to_y)
+ swap_numbers(&from_y, &to_y);
+
+ from_sx = SX + from_x * MINI_TILEX;
+ from_sy = SY + from_y * MINI_TILEY;
+ to_sx = SX + to_x * MINI_TILEX + MINI_TILEX - 1;
+ to_sy = SY + to_y * MINI_TILEY + MINI_TILEY - 1;
+
+ XSetForeground(display, gc, WhitePixel(display, screen));
+
+ XDrawLine(display, drawto, gc, from_sx, from_sy, to_sx, from_sy);
+ XDrawLine(display, drawto, gc, to_sx, from_sy, to_sx, to_sy);
+ XDrawLine(display, drawto, gc, to_sx, to_sy, from_sx, to_sy);
+ XDrawLine(display, drawto, gc, from_sx, to_sy, from_sx, from_sy);
+
+ XSetForeground(display, gc, BlackPixel(display, screen));
+
+ if (from_x == to_x && from_y == to_y)
+ MarkTileDirty(from_x/2, from_y/2);
+ else
+ redraw_mask |= REDRAW_FIELD;
+}
+
+static void SelectArea(int from_x, int from_y, int to_x, int to_y,
+ int element, boolean change_level)
+{
+ if (element == -1 || change_level)
+ DrawRectangle(from_x, from_y, to_x, to_y, -1, FALSE);
+ else
+ DrawAreaBorder(from_x, from_y, to_x, to_y);
+}
+
+/* values for CopyBrushExt() */
+#define CB_AREA_TO_BRUSH 0
+#define CB_BRUSH_TO_CURSOR 1
+#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 button, int mode)
+{
+ static short brush_buffer[MAX_ED_FIELDX][MAX_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 = BUTTON_ELEMENT(button);
+ int x, y;
+
+ if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush)
+ return;
+
+ if (mode == CB_AREA_TO_BRUSH)
+ {
+ int from_lx, from_ly;
+
+ if (from_x > to_x)
+ swap_numbers(&from_x, &to_x);
+
+ if (from_y > to_y)
+ swap_numbers(&from_y, &to_y);
+
+ brush_width = to_x - from_x + 1;
+ brush_height = to_y - from_y + 1;
+
+ from_lx = from_x + level_xpos;
+ 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 ||
+ mode == CB_BRUSH_TO_LEVEL)
+ {
+ int cursor_x = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_x : from_x);
+ int cursor_y = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_y : from_y);
+ int cursor_from_x = cursor_x - brush_width / 2;
+ int cursor_from_y = cursor_y - brush_height / 2;
+ int border_from_x = cursor_x, border_from_y = cursor_y;
+ 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, 0, CB_DELETE_OLD_CURSOR);
+
+ if (!IN_ED_FIELD(cursor_x, cursor_y) ||
+ !IN_LEV_FIELD(cursor_x + level_xpos, cursor_y + level_ypos))
+ {
+ delete_old_brush = FALSE;
+ return;
+ }
+
+ for (y=0; y<brush_height; y++)
+ {
+ for (x=0; x<brush_width; x++)
+ {
+ int sx = cursor_from_x + x;
+ int sy = cursor_from_y + y;
+ int lx = sx + level_xpos;
+ int ly = sy + level_ypos;
+ 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_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))