+ /* draw radiobutton gadgets */
+ for (i=ED_RADIOBUTTON_ID_LEVEL_FIRST; i<=ED_RADIOBUTTON_ID_LEVEL_LAST; i++)
+ MapRadiobuttonGadget(i);
+
+ /* draw text input gadgets */
+ for (i=ED_TEXTINPUT_ID_LEVEL_FIRST; i<=ED_TEXTINPUT_ID_LEVEL_LAST; i++)
+ MapTextInputGadget(i);
+
+ /* draw drawing area */
+ MapDrawingArea(ED_DRAWING_ID_RANDOM_BACKGROUND);
+}
+
+static void DrawCustomContentArea()
+{
+ int id = ED_DRAWING_ID_CUSTOM_CONTENT;
+ struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
+ int x1 = right_gadget_border[GADGET_ID_CUSTOM_DEADLINESS];
+ int x2 = right_gadget_border[GADGET_ID_CUSTOM_CONSISTENCY];
+ int x3 = right_gadget_border[GADGET_ID_CUSTOM_EXPLODE_IMPACT];
+ int xoffset = ED_DRAWINGAREA_TEXT_DISTANCE;
+
+ /* add distance for potential left text (without drawing area border) */
+ x2 += getTextWidthForGadget(drawingarea_info[id].text_left);
+
+ ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
+
+ MapDrawingArea(ED_DRAWING_ID_CUSTOM_CONTENT);
+}
+
+static void DrawCustomChangeContentArea()
+{
+ int id = ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT;
+ struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
+ int x1 = right_gadget_border[GADGET_ID_CHANGE_USE_CONTENT];
+ int x2 = right_gadget_border[GADGET_ID_CHANGE_POWER];
+ int x3 = right_gadget_border[GADGET_ID_CHANGE_ONLY_COMPLETE];
+ int xoffset = ED_DRAWINGAREA_TEXT_DISTANCE;
+
+ ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
+
+ MapDrawingArea(id);
+}
+
+static void DrawElementContentAreas()
+{
+ int x = SX + ED_AREA_YAMYAM_CONTENT_XPOS(3) + 4 * MINI_TILEX;
+ int y = SY + ED_AREA_YAMYAM_CONTENT_YPOS(0) + ED_BORDER_AREA_YSIZE;
+ int i;
+
+ /* display counter to choose number of element content areas */
+ MapCounterButtons(ED_COUNTER_ID_ELEMENT_CONTENT);
+
+ for (i=0; i < MAX_ELEMENT_CONTENTS; i++)
+ {
+ int id = ED_DRAWING_ID_ELEMENT_CONTENT_0 + i;
+ int font_height = getFontHeight(FONT_TEXT_1);
+
+ if (i < level.num_yamyam_contents)
+ MapDrawingArea(id);
+ else
+ {
+ UnmapDrawingArea(id);
+
+ /* delete content areas in case of reducing number of them */
+ DrawBackground(SX + drawingarea_info[id].x - MINI_TILEX / 2,
+ SY + drawingarea_info[id].y - MINI_TILEY / 2,
+ 4 * MINI_TILEX,
+ 4 * MINI_TILEX + ED_GADGET_TEXT_DISTANCE + font_height);
+ }
+ }
+
+ DrawText(x, y + 0 * MINI_TILEY, "content", FONT_TEXT_1);
+ DrawText(x, y + 1 * MINI_TILEY, "when", FONT_TEXT_1);
+ DrawText(x, y + 2 * MINI_TILEY, "smashed", FONT_TEXT_1);
+}
+
+static void DrawEnvelopeTextArea(int envelope_nr)
+{
+ int id = ED_TEXTAREA_ID_ENVELOPE_INFO;
+ struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
+
+ UnmapGadget(gi);
+ DrawBackground(gi->x, gi->y, gi->width, gi->height);
+
+ if (envelope_nr != -1)
+ textarea_info[id].value = level.envelope_text[envelope_nr];
+
+ ModifyGadget(gi, GDI_AREA_SIZE,
+ *counterbutton_info[ED_COUNTER_ID_ENVELOPE_XSIZE].value,
+ *counterbutton_info[ED_COUNTER_ID_ENVELOPE_YSIZE].value,
+ GDI_END);
+
+ MapTextAreaGadget(ED_TEXTAREA_ID_ENVELOPE_INFO);
+}
+
+char *getElementDescriptionFilename(int element)
+{
+ char *docs_dir = options.docs_directory;
+ char *elements_subdir = "elements";
+ static char *filename = NULL;
+ char basename[MAX_FILENAME_LEN];
+
+ if (filename != NULL)
+ free(filename);
+
+ /* 1st try: look for element description file for exactly this element */
+ sprintf(basename, "%s.txt", element_info[element].token_name);
+ filename = getPath3(docs_dir, elements_subdir, basename);
+ if (fileExists(filename))
+ return filename;
+
+ free(filename);
+
+ /* 2nd try: look for element description file for this element's class */
+ sprintf(basename, "%s.txt", element_info[element].class_name);
+ filename = getPath3(docs_dir, elements_subdir, basename);
+ if (fileExists(filename))
+ return filename;
+
+ return NULL;
+}
+
+#if 1
+static boolean PrintInfoText(char *text, int font_nr, int start_line)
+{
+ int font_height = getFontHeight(font_nr);
+ int pad_x = ED_SETTINGS_XPOS(0);
+ int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
+ int sx = SX + pad_x;
+ int sy = SY + pad_y;
+ int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
+
+ if (start_line >= max_lines_per_screen)
+ return FALSE;
+
+ DrawText(sx, sy + start_line * font_height, text, font_nr);
+
+ return TRUE;
+}
+
+#if 1
+
+static int PrintElementDescriptionFromFile(char *filename, int start_line)
+{
+ int font_nr = FONT_TEXT_2;
+ int font_width = getFontWidth(font_nr);
+ int font_height = getFontHeight(font_nr);
+ int pad_x = ED_SETTINGS_XPOS(0);
+ int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
+ int sx = SX + pad_x;
+ int sy = SY + pad_y;
+ int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
+ int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
+ int current_line = start_line;
+ char line[MAX_LINE_LEN];
+ char buffer[max_chars_per_line + 1];
+ int buffer_len;
+ FILE *file;
+
+ if (current_line >= max_lines_per_screen)
+ return 0;
+
+ if (filename == NULL)
+ return 0;
+
+ if (!(file = fopen(filename, MODE_READ)))
+ return 0;
+
+ buffer[0] = '\0';
+ buffer_len = 0;
+
+ while(!feof(file) && current_line < max_lines_per_screen)
+ {
+ char *line_ptr;
+ boolean last_line_was_empty = TRUE;
+
+ /* read next line of input file */
+ if (!fgets(line, MAX_LINE_LEN, file))
+ break;
+
+ /* skip comments (lines directly beginning with '#') */
+ if (line[0] == '#')
+ continue;
+
+ /* cut trailing newline from input line */
+ for (line_ptr = line; *line_ptr; line_ptr++)
+ {
+ if (*line_ptr == '\n' || *line_ptr == '\r')
+ {
+ *line_ptr = '\0';
+ break;
+ }
+ }
+
+ if (strlen(line) == 0) /* special case: force empty line */
+ strcpy(line, "\n");
+
+ line_ptr = line;
+
+ while (*line_ptr && current_line < max_lines_per_screen)
+ {
+ boolean buffer_filled = RenderLineToBuffer(&line_ptr,
+ buffer, &buffer_len,
+ last_line_was_empty,
+ max_chars_per_line);
+ if (buffer_filled)
+ {
+ DrawText(sx, sy + current_line * font_height, buffer, font_nr);
+ current_line++;
+
+ last_line_was_empty = (buffer_len == 0);
+
+ buffer[0] = '\0';
+ buffer_len = 0;
+ }
+ }
+ }
+
+ fclose(file);
+
+ if (buffer_len > 0 && current_line < max_lines_per_screen)
+ {
+ DrawText(sx, sy + current_line * font_height, buffer, font_nr);
+ current_line++;
+ }
+
+ return (current_line - start_line);
+}
+
+#else
+
+static int PrintElementDescriptionFromFile(char *filename, int start_line)
+{
+ int font_nr = FONT_TEXT_2;
+ int font_width = getFontWidth(font_nr);
+ int font_height = getFontHeight(font_nr);
+ int pad_x = ED_SETTINGS_XPOS(0);
+ int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
+ int sx = SX + pad_x;
+ int sy = SY + pad_y;
+ int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
+ int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
+ int current_line = start_line;
+ char line[MAX_LINE_LEN];
+ char buffer[max_chars_per_line + 1];
+ int buffer_len;
+ FILE *file;
+
+ if (filename == NULL)
+ return 0;
+
+ if (!(file = fopen(filename, MODE_READ)))
+ return 0;
+
+ buffer[0] = '\0';
+ buffer_len = 0;
+
+ while(!feof(file))
+ {
+ char *line_ptr, *word_ptr;
+ boolean last_line_was_empty = TRUE;
+
+ /* read next line of input file */
+ if (!fgets(line, MAX_LINE_LEN, file))
+ break;
+
+ /* skip comments (lines directly beginning with '#') */
+ if (line[0] == '#')
+ continue;