diff --git a/src/buttons.c b/src/buttons.c index 741546d5..90df77d7 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -70,6 +70,7 @@ #include "brush.h" #include "input.h" #include "special.h" +#include "tiles.h" #include "setup.h" #ifdef __VBCC__ @@ -210,7 +211,7 @@ void Button_Undo(void) { Hide_cursor(); Undo(); - + Tilemap_update(); Set_palette(Main_palette); Compute_optimal_menu_colors(Main_palette); @@ -225,7 +226,7 @@ void Button_Redo(void) { Hide_cursor(); Redo(); - + Tilemap_update(); Set_palette(Main_palette); Compute_optimal_menu_colors(Main_palette); @@ -1529,6 +1530,9 @@ void Button_Page(void) // On dégrossit le travail avec les infos des listes de pages Exchange_main_and_spare(); + // Tilemap info + Swap_tilemap(); + // On fait le reste du travail "à la main": #ifndef NOLAYERS SWAP_PBYTES(Main_visible_image.Image,Spare_visible_image.Image) @@ -1724,6 +1728,8 @@ void Button_Copy_page(void) Update_spare_buffers(Spare_image_width,Spare_image_height); Redraw_spare_image(); Spare_image_is_modified=1; + if (Spare_tilemap_mode) + Disable_spare_tilemap(); break; case 2: // Pixels only @@ -1733,6 +1739,8 @@ void Button_Copy_page(void) Update_spare_buffers(Spare_image_width,Spare_image_height); Redraw_spare_image(); Spare_image_is_modified=1; + if (Spare_tilemap_mode) + Disable_spare_tilemap(); break; case 3: // Palette only @@ -2185,7 +2193,8 @@ void Button_Resolution(void) || (chosen_height!=Main_image_height) ) { Resize_image(chosen_width,chosen_height); - End_of_modification(); + End_of_modification(); + Tilemap_update(); } if ((Video_mode[selected_mode].State & 3) == 3 || @@ -3275,6 +3284,7 @@ void Button_Load(void) Upload_infos_page_main(Main_backups->Pages); Load_picture(1); + Tilemap_update(); } @@ -3346,6 +3356,7 @@ void Button_Reload(void) Compute_limits(); Compute_paintbrush_coordinates(); } + Tilemap_update(); Redraw_layered_image(); End_of_modification(); Display_all_screen(); @@ -4494,7 +4505,7 @@ void Display_effect_states(void) Display_effect_state(C2+23,100, "Tiling" ,Tiling_mode); Display_effect_state(177+23,24, "8 bit" ,Constraint_mode); - Display_effect_state(177+23,43, "Tilemap",Tilemap_mode); + Display_effect_state(177+23,43, "Tilemap",Main_tilemap_mode); } @@ -4791,7 +4802,7 @@ void Button_Effects(void) case 15: // Tilemap Button_Tilemap_mode(); Hide_cursor(); - Display_effect_state(177+23,43, "Tilemap" ,Tilemap_mode); + Display_effect_state(177+23,43, "Tilemap" ,Main_tilemap_mode); Display_cursor(); break; } @@ -4803,7 +4814,7 @@ void Button_Effects(void) else Hide_cursor(); - if (!(Shade_mode||Quick_shade_mode||Colorize_mode||Smooth_mode||Tiling_mode||Smear_mode||Stencil_mode||Mask_mode||Sieve_mode||Snap_mode||Constraint_mode||Tilemap_mode)) + if (!(Shade_mode||Quick_shade_mode||Colorize_mode||Smooth_mode||Tiling_mode||Smear_mode||Stencil_mode||Mask_mode||Sieve_mode||Snap_mode||Constraint_mode||Main_tilemap_mode)) Unselect_button(BUTTON_EFFECTS); Display_cursor(); diff --git a/src/buttons_effects.c b/src/buttons_effects.c index 2bf09ba3..2212b455 100644 --- a/src/buttons_effects.c +++ b/src/buttons_effects.c @@ -42,6 +42,7 @@ #include "sdlscreen.h" #include "struct.h" #include "windows.h" +#include "tiles.h" //---------- Menu dans lequel on tagge des couleurs (genre Stencil) ---------- void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section, word close_shortcut) @@ -192,9 +193,8 @@ void Button_Constraint_menu(void) // Tilemap mode void Button_Tilemap_mode(void) { - Tilemap_mode=!Tilemap_mode; - if (Tilemap_mode) - Tilemap_create(); + Main_tilemap_mode=!Main_tilemap_mode; + Tilemap_update(); } void Button_Tilemap_menu(void) @@ -413,12 +413,25 @@ void Button_Grid_menu(void) if (clicked_button==2) // OK { + byte modified; + + modified = Snap_width!=chosen_X + || Snap_height!=chosen_Y + || Snap_offset_X!=dx_selected + || Snap_offset_Y!=dy_selected; + Snap_width=chosen_X; Snap_height=chosen_Y; Snap_offset_X=dx_selected; Snap_offset_Y=dy_selected; Snap_mode=snapgrid; Show_grid=showgrid; + + if (modified) + { + Tilemap_update(); + Disable_spare_tilemap(); + } } Close_window(); @@ -834,7 +847,7 @@ void Effects_off(void) Sieve_mode=0; Snap_mode=0; Constraint_mode=0; - Tilemap_mode=0; + Main_tilemap_mode=0; } diff --git a/src/global.h b/src/global.h index b8423bf9..91d910bd 100644 --- a/src/global.h +++ b/src/global.h @@ -348,13 +348,6 @@ GFX2_GLOBAL Uint32 Main_time_of_safety_backup; /// Letter prefix for the filenames of safety backups. a or b GFX2_GLOBAL byte Main_safety_backup_prefix; -/// Tilemap for the main screen -GFX2_GLOBAL T_Tile * Main_tilemap; - -GFX2_GLOBAL short Main_tilemap_width; -GFX2_GLOBAL short Main_tilemap_height; -GFX2_GLOBAL byte Main_tilemap_allow_flip; ///< 0:no, 1:horizontally, 2:vertically, 3:both - // -- Spare page data /// Palette of the spare page @@ -740,11 +733,11 @@ GFX2_GLOBAL byte Constraint_mode; // -- Tilemap mode -/// Tilemap mode -GFX2_GLOBAL byte Tilemap_mode; +/// Tilemap mode for main page +GFX2_GLOBAL byte Main_tilemap_mode; -/// Tilemap allows swapped tiles : 0:No 1:Horizontal 2:Vertical 3:Both -GFX2_GLOBAL byte Tilemap_allow_swap; +/// Tilemap mode for spare page +GFX2_GLOBAL byte Spare_tilemap_mode; // -- Magnifier data diff --git a/src/graph.c b/src/graph.c index 9a761c37..43886ce7 100644 --- a/src/graph.c +++ b/src/graph.c @@ -2747,7 +2747,7 @@ void Display_pixel(word x,word y,byte color) && (!((Mask_mode) && (Mask_table[Read_pixel_from_spare_screen(x,y)]))) ) { color=Effect_function(x,y,color); - if (Tilemap_mode) + if (Main_tilemap_mode) { Tilemap_draw(x,y, color); } diff --git a/src/tiles.c b/src/tiles.c index 0a3bd4c7..0c860b14 100644 --- a/src/tiles.c +++ b/src/tiles.c @@ -29,6 +29,26 @@ #include "misc.h" #include "tiles.h" +enum TILE_FLIPPED +{ + TILE_FLIPPED_NONE = 0, + TILE_FLIPPED_X = 1, + TILE_FLIPPED_Y = 2, + TILE_FLIPPED_XY = 3, // needs be TILE_FLIPPED_X|TILE_FLIPPED_Y +}; + +// globals +T_Tile * Main_tilemap; +short Main_tilemap_width; +short Main_tilemap_height; + +T_Tile * Spare_tilemap; +short Spare_tilemap_width; +short Spare_tilemap_height; + +T_Tilemap_settings Tilemap_settings = { 0, 0, 0, 0}; + +// /// Build the tile-area from the current picture void build_tile_area() @@ -253,7 +273,7 @@ int Tile_is_same_flipped_xy(int t1, int t2) } /// Create or update a tilemap based on current screen (layer)'s pixels. -void Tilemap_create(void) +void Tilemap_update(void) { int width; int height; @@ -262,8 +282,11 @@ void Tilemap_create(void) T_Tile * tile_ptr; int wait_window=0; - byte old_cursor; + byte old_cursor=0; + if (!Main_tilemap_mode) + return; + width=(Main_image_width-Snap_offset_X)/Snap_width; height=(Main_image_height-Snap_offset_Y)/Snap_height; @@ -275,15 +298,7 @@ void Tilemap_create(void) // Or the number of tiles seems unreasonable (one million) : This can // happen if you set grid 1x1 for example. - if (Main_tilemap) - { - // Recycle existing tilemap - free(Main_tilemap); - Main_tilemap=NULL; - } - Main_tilemap_width=0; - Main_tilemap_height=0; - Tilemap_mode=0; + Disable_main_tilemap(); return; } @@ -298,7 +313,7 @@ void Tilemap_create(void) Main_tilemap_width=width; Main_tilemap_height=height; - if (width*height > 1000 || 1) + if (width*height > 1000 || Tilemap_settings.Show_tile_count) { wait_window=1; Open_window(180,36,"Creating tileset"); @@ -347,69 +362,75 @@ void Tilemap_create(void) } // Try flipped-y comparison - - for (ref_tile=0; ref_tile