+ CreateLevelEditorGadgets();
+ CreateGameButtons();
+ CreateTapeButtons();
+ CreateToolButtons();
+ CreateScreenGadgets();
+
+ gadgets_initialized = TRUE;
+}
+
+void InitElementSmallImages()
+{
+ struct PropertyMapping *property_mapping = getImageListPropertyMapping();
+ int num_property_mappings = getImageListPropertyMappingSize();
+ int i;
+
+ /* initialize normal images from static configuration */
+ for (i=0; element_to_graphic[i].element > -1; i++)
+ CreateImageWithSmallImages(element_to_graphic[i].graphic);
+
+ /* initialize special images from static configuration */
+ for (i=0; element_to_special_graphic[i].element > -1; i++)
+ CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
+
+ /* initialize images from dynamic configuration */
+ for (i=0; i < num_property_mappings; i++)
+ if (property_mapping[i].artwork_index < MAX_NUM_ELEMENTS)
+ CreateImageWithSmallImages(property_mapping[i].artwork_index);
+}
+
+static int getFontBitmapID(int font_nr)
+{
+ int special = -1;
+
+ if (game_status == MAINMENU || game_status == TYPENAME)
+ special = GFX_SPECIAL_ARG_MAIN;
+ else if (game_status == CHOOSELEVEL)
+ special = GFX_SPECIAL_ARG_LEVELS;
+ else if (game_status == HALLOFFAME)
+ special = GFX_SPECIAL_ARG_SCORES;
+ else if (game_status == LEVELED)
+ special = GFX_SPECIAL_ARG_EDITOR;
+ else if (game_status == HELPSCREEN)
+ special = GFX_SPECIAL_ARG_INFO;
+ else if (game_status == SETUP)
+ special = GFX_SPECIAL_ARG_SETUP;
+ else if (game_status == PSEUDO_PREVIEW)
+ special = GFX_SPECIAL_ARG_PREVIEW;
+ else if (game_status == PLAYING || game_status == PSEUDO_DOOR)
+ special = GFX_SPECIAL_ARG_DOOR;
+
+ if (special != -1)
+ return font_info[font_nr].special_bitmap_id[special];
+ else
+ return font_nr;
+}
+
+void InitFontGraphicInfo()
+{
+ static struct FontBitmapInfo *font_bitmap_info = NULL;
+ struct PropertyMapping *property_mapping = getImageListPropertyMapping();
+ int num_property_mappings = getImageListPropertyMappingSize();
+ int num_font_bitmaps = NUM_FONTS;
+ int i, j;
+
+ if (graphic_info == NULL) /* still at startup phase */
+ {
+ InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
+
+ return;
+ }
+
+ /* ---------- initialize font graphic definitions ---------- */
+
+ /* always start with reliable default values (normal font graphics) */
+ for (i=0; i < NUM_FONTS; i++)
+ font_info[i].graphic = FONT_INITIAL_1;
+
+ /* initialize normal font/graphic mapping from static configuration */
+ for (i=0; font_to_graphic[i].font_nr > -1; i++)
+ {
+ int font_nr = font_to_graphic[i].font_nr;
+ int special = font_to_graphic[i].special;
+ int graphic = font_to_graphic[i].graphic;
+
+ if (special != -1)
+ continue;
+
+ font_info[font_nr].graphic = graphic;
+ }
+
+ /* always start with reliable default values (special font graphics) */
+ for (i=0; i < NUM_FONTS; i++)
+ {
+ for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
+ {
+ font_info[i].special_graphic[j] = font_info[i].graphic;
+ font_info[i].special_bitmap_id[j] = i;
+ }
+ }
+
+ /* initialize special font/graphic mapping from static configuration */
+ for (i=0; font_to_graphic[i].font_nr > -1; i++)
+ {
+ int font_nr = font_to_graphic[i].font_nr;
+ int special = font_to_graphic[i].special;
+ int graphic = font_to_graphic[i].graphic;
+
+ if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
+ {
+ font_info[font_nr].special_graphic[special] = graphic;
+ font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
+ num_font_bitmaps++;
+ }
+ }
+
+ /* initialize special element/graphic mapping from dynamic configuration */
+ for (i=0; i < num_property_mappings; i++)
+ {
+ int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
+ int special = property_mapping[i].ext3_index;
+ int graphic = property_mapping[i].artwork_index;
+
+ if (font_nr < 0)
+ continue;
+
+ if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
+ {
+ font_info[font_nr].special_graphic[special] = graphic;
+ font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
+ num_font_bitmaps++;
+ }
+ }
+
+ /* ---------- initialize font bitmap array ---------- */
+
+ if (font_bitmap_info != NULL)
+ free(font_bitmap_info);
+
+ font_bitmap_info =
+ checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
+
+ /* ---------- initialize font bitmap definitions ---------- */
+
+ for (i=0; i < NUM_FONTS; i++)
+ {
+ if (i < NUM_INITIAL_FONTS)
+ {
+ font_bitmap_info[i] = font_initial[i];
+ continue;
+ }
+
+ for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
+ {
+ int font_bitmap_id = font_info[i].special_bitmap_id[j];
+ int graphic = font_info[i].special_graphic[j];
+
+ /* copy font relevant information from graphics information */
+ font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
+ font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x;
+ font_bitmap_info[font_bitmap_id].src_y = graphic_info[graphic].src_y;
+ font_bitmap_info[font_bitmap_id].width = graphic_info[graphic].width;
+ font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
+ font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x;
+ font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y;
+ }
+ }
+
+ InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
+}
+
+void InitElementGraphicInfo()
+{
+ struct PropertyMapping *property_mapping = getImageListPropertyMapping();
+ int num_property_mappings = getImageListPropertyMappingSize();
+ int i, act, dir;
+
+ /* set values to -1 to identify later as "uninitialized" values */
+ for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ {
+ for (act=0; act<NUM_ACTIONS; act++)
+ {
+ element_info[i].graphic[act] = -1;
+
+ for (dir=0; dir<NUM_DIRECTIONS; dir++)
+ element_info[i].direction_graphic[act][dir] = -1;
+ }
+ }
+
+ /* initialize normal element/graphic mapping from static configuration */
+ for (i=0; element_to_graphic[i].element > -1; i++)
+ {
+ int element = element_to_graphic[i].element;
+ int action = element_to_graphic[i].action;
+ int direction = element_to_graphic[i].direction;
+ int graphic = element_to_graphic[i].graphic;
+
+ if (action < 0)
+ action = ACTION_DEFAULT;
+
+ if (direction > -1)
+ element_info[element].direction_graphic[action][direction] = graphic;
+ else
+ element_info[element].graphic[action] = graphic;
+ }
+
+ /* initialize normal element/graphic mapping from dynamic configuration */
+ for (i=0; i < num_property_mappings; i++)
+ {
+ int element = property_mapping[i].base_index;
+ int action = property_mapping[i].ext1_index;
+ int direction = property_mapping[i].ext2_index;
+ int special = property_mapping[i].ext3_index;
+ int graphic = property_mapping[i].artwork_index;
+
+ if (element >= MAX_NUM_ELEMENTS || special != -1)
+ continue;
+
+ if (action < 0)
+ action = ACTION_DEFAULT;
+
+ if (direction > -1)
+ element_info[element].direction_graphic[action][direction] = graphic;
+ else
+ element_info[element].graphic[action] = graphic;
+ }
+
+ /* now set all '-1' values to element specific default values */
+ for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ {
+ int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
+ int default_action_direction_graphic[NUM_DIRECTIONS];
+
+ if (default_action_graphic == -1)
+ default_action_graphic = IMG_CHAR_QUESTION;
+
+ for (dir=0; dir<NUM_DIRECTIONS; dir++)
+ {
+ default_action_direction_graphic[dir] =
+ element_info[i].direction_graphic[ACTION_DEFAULT][dir];
+
+ if (default_action_direction_graphic[dir] == -1)
+ default_action_direction_graphic[dir] = default_action_graphic;
+ }
+
+ for (act=0; act<NUM_ACTIONS; act++)
+ {
+ for (dir=0; dir<NUM_DIRECTIONS; dir++)
+ {
+ int default_direction_graphic = element_info[i].graphic[act];
+
+ /* no graphic for current action -- use default direction graphic */
+ if (default_direction_graphic == -1)
+ default_direction_graphic = default_action_direction_graphic[dir];
+
+ if (element_info[i].direction_graphic[act][dir] == -1)
+ element_info[i].direction_graphic[act][dir] =
+ default_direction_graphic;
+ }
+
+ /* no graphic for this specific action -- use default action graphic */
+ if (element_info[i].graphic[act] == -1)
+ element_info[i].graphic[act] = default_action_graphic;
+ }
+ }
+
+#if 0
+#if DEBUG
+ if (options.verbose)
+ {
+ for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ if (element_info[i].graphic[ACTION_DEFAULT] == IMG_CHAR_QUESTION &&
+ i != EL_CHAR_QUESTION)
+ Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
+ element_info[i].token_name, i);
+ }
+#endif
+#endif
+}
+
+void InitElementSpecialGraphicInfo()
+{
+ struct PropertyMapping *property_mapping = getImageListPropertyMapping();
+ int num_property_mappings = getImageListPropertyMappingSize();
+ int i, j;
+
+ /* always start with reliable default values */
+ for (i=0; i < MAX_NUM_ELEMENTS; i++)
+ for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
+ element_info[i].special_graphic[j] =
+ element_info[i].graphic[ACTION_DEFAULT];
+
+ /* initialize special element/graphic mapping from static configuration */
+ for (i=0; element_to_special_graphic[i].element > -1; i++)
+ {
+ int element = element_to_special_graphic[i].element;
+ int special = element_to_special_graphic[i].special;
+ int graphic = element_to_special_graphic[i].graphic;
+ boolean base_redefined = getImageListEntry(el2img(element))->redefined;
+ boolean special_redefined = getImageListEntry(graphic)->redefined;
+
+ if (base_redefined && !special_redefined)
+ continue;
+
+ element_info[element].special_graphic[special] = graphic;
+ }
+
+ /* initialize special element/graphic mapping from dynamic configuration */
+ for (i=0; i < num_property_mappings; i++)
+ {
+ int element = property_mapping[i].base_index;
+ int special = property_mapping[i].ext3_index;
+ int graphic = property_mapping[i].artwork_index;
+
+ if (element >= MAX_NUM_ELEMENTS)
+ continue;
+
+ if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
+ element_info[element].special_graphic[special] = graphic;
+ }
+}
+
+static void set_graphic_parameters(int graphic, char **parameter_raw)
+{
+ Bitmap *src_bitmap = getBitmapFromImageID(graphic);
+ int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX;
+ int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY;
+ int parameter[NUM_GFX_ARGS];
+ int i;
+
+ /* get integer values from string parameters */
+ for (i=0; i < NUM_GFX_ARGS; i++)
+ parameter[i] =
+ get_parameter_value(image_config_suffix[i].token, parameter_raw[i],
+ image_config_suffix[i].type);
+
+ graphic_info[graphic].bitmap = src_bitmap;
+
+ /* start with reliable default values */
+ graphic_info[graphic].src_x = 0;
+ graphic_info[graphic].src_y = 0;
+ graphic_info[graphic].width = TILEX;
+ graphic_info[graphic].height = TILEY;
+ graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
+ graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
+
+ /* optional x and y tile position of animation frame sequence */
+ if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
+ if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
+
+ /* optional x and y pixel position of animation frame sequence */
+ if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].src_x = parameter[GFX_ARG_X];
+ if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
+
+ /* optional width and height of each animation frame */
+ if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
+ if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
+
+ /* correct x or y offset dependant of vertical or horizontal frame order */
+ if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
+ {
+ if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET];
+ else
+ graphic_info[graphic].offset_y = graphic_info[graphic].height;
+ }
+ else /* frames are ordered horizontally */
+ {
+ if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET];
+ else
+ graphic_info[graphic].offset_x = graphic_info[graphic].width;
+ }
+
+ /* optionally, the x and y offset of frames can be specified directly */
+ if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
+ if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
+
+ /* automatically determine correct number of frames, if not defined */
+ if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
+ else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
+ graphic_info[graphic].anim_frames = num_xtiles;
+ else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
+ graphic_info[graphic].anim_frames = num_ytiles;
+ else
+ graphic_info[graphic].anim_frames = 1;
+
+ graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
+ if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
+ graphic_info[graphic].anim_delay = 1;
+
+ if (parameter[GFX_ARG_ANIM_MODE] != ANIM_NONE)
+ graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
+ else if (graphic_info[graphic].anim_frames > 1)
+ graphic_info[graphic].anim_mode = ANIM_LOOP;
+
+ /* automatically determine correct start frame, if not defined */
+ if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
+ graphic_info[graphic].anim_start_frame = 0;
+ else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
+ graphic_info[graphic].anim_start_frame =
+ graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
+ else
+ graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
+
+ /* animation synchronized with global frame counter, not move position */
+ graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
+
+ /* this is only used for toon animations */
+ graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
+ graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
+
+ /* this is only used for drawing font characters */
+ graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET];
+ graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET];
+}
+
+static void InitGraphicInfo()
+{
+ int fallback_graphic = IMG_CHAR_EXCLAM;
+ struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
+ Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
+ int num_images = getImageListSize();
+ int i;
+
+#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
+ static boolean clipmasks_initialized = FALSE;
+ Pixmap src_pixmap;
+ XGCValues clip_gc_values;
+ unsigned long clip_gc_valuemask;
+ GC copy_clipmask_gc = None;