Displayable tile grid (Issue 171)

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1007 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-08-26 23:42:55 +00:00
parent 7bfdb28936
commit d6bf9413bf
22 changed files with 169 additions and 15 deletions

View File

@ -3613,6 +3613,13 @@ void Button_Grid_menu(void)
Display_cursor();
}
void Button_Show_grid(void)
{
Show_grid = !Show_grid;
Hide_cursor();
Display_all_screen();
Display_cursor();
}
// ----------------------- Modifications de brosse ---------------------------

View File

@ -353,6 +353,11 @@ void Button_Snap_mode(void);
*/
void Button_Grid_menu(void);
/*!
Callback to toggle the grid visible in the magnified view.
*/
void Button_Show_grid(void);
// Mode trame (Sieve)
/*!

View File

@ -33,7 +33,7 @@
#define BETA1 98 ///< Version number for gfx2.cfg (3/4)
#define BETA2 0 ///< Version number for gfx2.cfg (4/4)
#define MAX_VIDEO_MODES 100 ///< Maximum number of video modes Grafx2 can propose.
#define NB_SHORTCUTS 158 ///< Number of actions that can have a key combination associated to it.
#define NB_SHORTCUTS 159 ///< Number of actions that can have a key combination associated to it.
#define NB_ZOOM_FACTORS 12 ///< Number of zoom levels available in the magnifier.
#define MENU_WIDTH 254 ///< Width of the menu (not counting the palette)
#define MENU_HEIGHT 44 ///< Height of the menu.
@ -406,6 +406,7 @@ enum SPECIAL_ACTIONS
SPECIAL_ZOOM_16,
SPECIAL_ZOOM_18,
SPECIAL_ZOOM_20,
SPECIAL_SHOW_GRID,
NB_SPECIAL_SHORTCUTS ///< Number of special shortcuts
};

View File

@ -825,6 +825,10 @@ void Main_handler(void)
Button_Grid_menu();
Key=0;
break;
case SPECIAL_SHOW_GRID :
Button_Show_grid();
Key=0;
break;
case SPECIAL_SIEVE_MODE :
Button_Sieve_mode();
Key=0;

View File

@ -328,5 +328,16 @@
; want to use. | 8x8 utilisée dans les menus.
; Default : (empty to let the program choose)
Font_file =
; This determines the color value for the grid. Each pixel of
; the grid will be displayed by XOR-ing the original color with
; the value of this setting.
; For example, if you always paint 16-color images, you can set it
; to 16 so the color of the grid are 16 for 0, 17 for 1, etc.
; Then you can set colors 16-31 as lighter/darker variants
; of your original palette, resulting in a pretty grid !
;
; Valid values are 1 to 255.
Grid_XOR_color = 255; (Default 255)
; end of configuration

View File

@ -138,7 +138,7 @@ GFX2_GLOBAL byte Cursor_in_menu;
/// Boolean, means the cursor was hovering over a menu GUI element.
GFX2_GLOBAL byte Cursor_in_menu_previous;
/// Storage for the graphics under the mouse cursor. Used by ::Hide_cursor and ::Display_cursor
GFX2_GLOBAL byte CURSOR_BACKGROUND[CURSOR_SPRITE_HEIGHT][CURSOR_SPRITE_WIDTH];
GFX2_GLOBAL byte Cursor_background[CURSOR_SPRITE_HEIGHT][CURSOR_SPRITE_WIDTH];
// -- Paintbrush data
@ -645,6 +645,8 @@ GFX2_GLOBAL byte Stencil[256];
/// Boolean, true when the Grid mode is active.
GFX2_GLOBAL byte Snap_mode;
/// Boolean, true when the Grid is displayed in zoomed view.
GFX2_GLOBAL byte Show_grid;
/// Width of the grid in Grid mode.
GFX2_GLOBAL word Snap_width;
/// Height of the grid in Grid mode.

55
graph.c
View File

@ -107,6 +107,7 @@ void Update_part_of_screen(short x, short y, short width, short height)
if(effective_Y + effective_h > Menu_Y)
effective_h = Menu_Y - effective_Y;
/*
SDL_Rect r;
r.x=effective_X;
@ -136,7 +137,7 @@ void Update_part_of_screen(short x, short y, short width, short height)
}
else
effective_X += Main_separator_position + SEPARATOR_WIDTH*Menu_factor_X;
diff = effective_X+effective_w-Screen_width;
diff = effective_X+effective_w-Min(Screen_width, Main_X_zoom+(Main_image_width-Main_magnifier_offset_X)*Main_magnifier_factor);
if (diff>0)
{
effective_w -=diff;
@ -153,7 +154,7 @@ void Update_part_of_screen(short x, short y, short width, short height)
return;
effective_Y = 0;
}
diff = effective_Y+effective_h-Menu_Y;
diff = effective_Y+effective_h-Min(Menu_Y, (Main_image_height-Main_magnifier_offset_Y)*Main_magnifier_factor);
if (diff>0)
{
effective_h -=diff;
@ -161,6 +162,7 @@ void Update_part_of_screen(short x, short y, short width, short height)
return;
}
// Très utile pour le debug :)
/*SDL_Rect r;
r.x=effective_X;
@ -169,6 +171,7 @@ void Update_part_of_screen(short x, short y, short width, short height)
r.w=effective_w;
SDL_FillRect(Screen_SDL,&r,3);*/
Redraw_grid(effective_X,effective_Y,effective_w,effective_h);
Update_rect(effective_X,effective_Y,effective_w,effective_h);
}
}
@ -999,6 +1002,16 @@ void Fill_general(byte fill_color)
// par l'utilisation de "Display_pixel()", et que les autres... eh bein
// on n'y a jamais touché à l'écran les autres: ils sont donc corrects.
if(Main_magnifier_mode)
{
short w,h;
w=Min(Screen_width-Main_X_zoom, (Main_image_width-Main_magnifier_offset_X)*Main_magnifier_factor);
h=Min(Menu_Y, (Main_image_height-Main_magnifier_offset_Y)*Main_magnifier_factor);
Redraw_grid(Main_X_zoom,0,w,h);
}
Update_rect(0,0,0,0);
End_of_modification();
}
@ -2803,3 +2816,41 @@ byte Effect_smooth(word x,word y,__attribute__((unused)) byte color)
Read_pixel_from_current_screen(x,y); // C'est bien l'écran courant et pas
// l'écran feedback car il s'agit de ne
} // pas modifier l'écran courant.
void Horizontal_grid_line(word x_pos,word y_pos,word width)
{
int x;
for (x=!(x_pos&1);x<width;x+=2)
Pixel(x_pos+x, y_pos, *((y_pos-1)*Pixel_height*VIDEO_LINE_WIDTH+x_pos*Pixel_width+Screen_pixels+x*Pixel_width)^Config.Grid_XOR_color);
}
void Vertical_grid_line(word x_pos,word y_pos,word height)
{
int y;
for (y=!(y_pos&1);y<height;y+=2)
Pixel(x_pos, y_pos+y, *(Screen_pixels+(x_pos*Pixel_width-1)+(y_pos*Pixel_height+y*Pixel_height)*VIDEO_LINE_WIDTH)^Config.Grid_XOR_color);
}
// Tile Grid
void Redraw_grid(short x, short y, unsigned short w, unsigned short h)
{
int row, col;
if (!Show_grid)
return;
row=y+((Snap_height*1000-(y-0)/Main_magnifier_factor-Main_magnifier_offset_Y+Snap_offset_Y-1)%Snap_height)*Main_magnifier_factor+Main_magnifier_factor-1;
while (row < y+h)
{
Horizontal_grid_line(x, row, w);
row+= Snap_height*Main_magnifier_factor;
}
col=x+((Snap_width*1000-(x-Main_X_zoom)/Main_magnifier_factor-Main_magnifier_offset_X+Snap_offset_X-1)%Snap_width)*Main_magnifier_factor+Main_magnifier_factor-1;
while (col < x+w)
{
Vertical_grid_line(col, y, h);
col+= Snap_width*Main_magnifier_factor;
}
}

View File

@ -108,3 +108,5 @@ void Remap_picture(void);
extern Func_pixel Pixel_figure;
void Update_part_of_screen(short x, short y, short width, short height);
void Redraw_grid(short x, short y, unsigned short w, unsigned short h);

View File

@ -170,6 +170,7 @@ static const T_Help_table helptable_help[] =
HELP_LINK ("Mask menu: %s", SPECIAL_MASK_MENU)
HELP_LINK ("Grid mode: %s", SPECIAL_GRID_MODE)
HELP_LINK ("Grid menu: %s", SPECIAL_GRID_MENU)
HELP_LINK ("Grid view: %s", SPECIAL_SHOW_GRID)
HELP_LINK ("Sieve mode: %s", SPECIAL_SIEVE_MODE)
HELP_LINK ("Sieve menu: %s", SPECIAL_SIEVE_MENU)
HELP_LINK ("Invert Sieve: %s", SPECIAL_INVERT_SIEVE)
@ -1485,7 +1486,7 @@ static const T_Help_table helptable_effects[] =
HELP_BOLD ("LEFT CLICK")
HELP_LINK ("(Key: %s)", SPECIAL_GRID_MODE)
HELP_TEXT ("")
HELP_TEXT ("Switches the Grid mode.")
HELP_TEXT ("Switches the Snap-to-grid mode.")
HELP_TEXT ("")
HELP_BOLD ("RIGHT CLICK")
HELP_LINK ("(Key: %s)", SPECIAL_GRID_MENU)
@ -1498,6 +1499,8 @@ static const T_Help_table helptable_effects[] =
HELP_TEXT ("- dX,dY: Offsets of the grid.")
HELP_TEXT ("")
HELP_TEXT ("")
HELP_LINK ("Show/Hide grid : ", SPECIAL_SHOW_GRID)
HELP_TEXT ("")
HELP_TITLE("SIEVE")
HELP_TEXT (" This effect allows you, by defining a")
HELP_TEXT ("pattern, to draw only on particular points")

View File

@ -1286,6 +1286,14 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = {
true,
0,
0},
{158,
"Show/Hide Grid",
"Turns on or off the visible grid in ",
"the magnified view. Grid cells match",
"the size ",
true,
SDLK_g|MOD_SHIFT|MOD_ALT, // Shift + Alt + G,
0},
};
word Ordering[NB_SHORTCUTS]=
@ -1448,4 +1456,5 @@ word Ordering[NB_SHORTCUTS]=
SPECIAL_ZOOM_16, /**< Sets zoom factor to 16:1 */
SPECIAL_ZOOM_18, /**< Sets zoom factor to 18:1 */
SPECIAL_ZOOM_20, /**< Sets zoom factor to 20:1 */
SPECIAL_SHOW_GRID,
};

View File

@ -366,6 +366,8 @@ void Display_part_of_screen_scaled_double(
y++;
if(y==height)
{
Redraw_grid(Main_X_zoom,0,
width*Main_magnifier_factor,height);
Update_rect(Main_X_zoom,0,
width*Main_magnifier_factor,height);
return;
@ -447,6 +449,8 @@ void Display_brush_mono_zoom_double(word x_pos, word y_pos,
// On vérifie qu'on est pas à la ligne finale
if(y == end_y_pos*ZOOMY)
{
Redraw_grid( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
Update_rect( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
return;
@ -483,6 +487,8 @@ void Clear_brush_scaled_double(word x_pos,word y_pos,word x_offset,word y_offset
y++;
if(y==end_y_pos)
{
Redraw_grid(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
Update_rect(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
return;

View File

@ -383,6 +383,8 @@ void Display_part_of_screen_scaled_quad(
y++;
if(y==height/**ZOOMY*/)
{
Redraw_grid(Main_X_zoom,0,
width*Main_magnifier_factor,height);
Update_rect(Main_X_zoom,0,
width*Main_magnifier_factor,height);
return;
@ -481,6 +483,8 @@ void Display_brush_mono_zoom_quad(word x_pos, word y_pos,
// On vérifie qu'on est pas à la ligne finale
if(y == end_y_pos*ZOOMY)
{
Redraw_grid( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
Update_rect( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
return;
@ -518,6 +522,8 @@ void Clear_brush_scaled_quad(word x_pos,word y_pos,word x_offset,word y_offset,w
y++;
if(y==end_y_pos)
{
Redraw_grid(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
Update_rect(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
return;

View File

@ -324,6 +324,8 @@ void Display_part_of_screen_scaled_simple(
y++;
if(y==height)
{
Redraw_grid(Main_X_zoom,0,
width*Main_magnifier_factor,height);
Update_rect(Main_X_zoom,0,
width*Main_magnifier_factor,height);
return;
@ -421,6 +423,8 @@ void Display_brush_mono_zoom_simple(word x_pos, word y_pos,
// On vérifie qu'on est pas à la ligne finale
if(y == end_y_pos)
{
Redraw_grid( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
Update_rect( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
return;
@ -456,6 +460,8 @@ void Clear_brush_scaled_simple(word x_pos,word y_pos,word x_offset,word y_offset
y++;
if(y==end_y_pos)
{
Redraw_grid(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
Update_rect(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
return;
@ -466,5 +472,3 @@ void Clear_brush_scaled_simple(word x_pos,word y_pos,word x_offset,word y_offset
src+= image_width;
}
}

View File

@ -325,6 +325,8 @@ void Display_part_of_screen_scaled_tall(
y++;
if(y==height*ZOOMY)
{
Redraw_grid(Main_X_zoom,0,
width*Main_magnifier_factor,height);
Update_rect(Main_X_zoom,0,
width*Main_magnifier_factor,height);
return;
@ -406,6 +408,8 @@ void Display_brush_mono_zoom_tall(word x_pos, word y_pos,
// On vérifie qu'on est pas à la ligne finale
if(y == end_y_pos*ZOOMY)
{
Redraw_grid( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
Update_rect( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
return;
@ -441,6 +445,8 @@ void Clear_brush_scaled_tall(word x_pos,word y_pos,word x_offset,word y_offset,w
y++;
if(y==end_y_pos)
{
Redraw_grid(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
Update_rect(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
return;

View File

@ -375,6 +375,8 @@ void Display_part_of_screen_scaled_tall2(
y++;
if(y==height/**ZOOMY*/)
{
Redraw_grid(Main_X_zoom,0,
width*Main_magnifier_factor,height);
Update_rect(Main_X_zoom,0,
width*Main_magnifier_factor,height);
return;
@ -473,6 +475,8 @@ void Display_brush_mono_zoom_tall2(word x_pos, word y_pos,
// On vérifie qu'on est pas à la ligne finale
if(y == end_y_pos*ZOOMY)
{
Redraw_grid( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
Update_rect( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
return;
@ -510,6 +514,8 @@ void Clear_brush_scaled_tall2(word x_pos,word y_pos,word x_offset,word y_offset,
y++;
if(y==end_y_pos)
{
Redraw_grid(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
Update_rect(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
return;

View File

@ -373,6 +373,8 @@ void Display_part_of_screen_scaled_triple(
y++;
if(y==height/**ZOOMY*/)
{
Redraw_grid(Main_X_zoom,0,
width*Main_magnifier_factor,height);
Update_rect(Main_X_zoom,0,
width*Main_magnifier_factor,height);
return;
@ -469,6 +471,8 @@ void Display_brush_mono_zoom_triple(word x_pos, word y_pos,
// On vérifie qu'on est pas à la ligne finale
if(y == end_y_pos*ZOOMY)
{
Redraw_grid( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
Update_rect( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
return;
@ -506,6 +510,8 @@ void Clear_brush_scaled_triple(word x_pos,word y_pos,word x_offset,word y_offset
y++;
if(y==end_y_pos)
{
Redraw_grid(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
Update_rect(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
return;

View File

@ -359,6 +359,8 @@ void Display_part_of_screen_scaled_wide(
y++;
if(y==height)
{
Redraw_grid(Main_X_zoom,0,
width*Main_magnifier_factor,height);
Update_rect(Main_X_zoom,0,
width*Main_magnifier_factor,height);
return;
@ -457,6 +459,8 @@ void Display_brush_mono_zoom_wide(word x_pos, word y_pos,
// On vérifie qu'on est pas à la ligne finale
if(y == end_y_pos*ZOOMY)
{
Redraw_grid( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
Update_rect( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
return;
@ -492,6 +496,8 @@ void Clear_brush_scaled_wide(word x_pos,word y_pos,word x_offset,word y_offset,w
y++;
if(y==end_y_pos)
{
Redraw_grid(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
Update_rect(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
return;

View File

@ -369,6 +369,8 @@ void Display_part_of_screen_scaled_wide2(
y++;
if(y==height/**ZOOMY*/)
{
Redraw_grid(Main_X_zoom,0,
width*Main_magnifier_factor,height);
Update_rect(Main_X_zoom,0,
width*Main_magnifier_factor,height);
return;
@ -463,6 +465,8 @@ void Display_brush_mono_zoom_wide2(word x_pos, word y_pos,
// On vérifie qu'on est pas à la ligne finale
if(y == end_y_pos*ZOOMY)
{
Redraw_grid( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
Update_rect( x_pos, y_pos,
width * Main_magnifier_factor, end_y_pos - y_pos );
return;
@ -500,6 +504,8 @@ void Clear_brush_scaled_wide2(word x_pos,word y_pos,word x_offset,word y_offset,
y++;
if(y==end_y_pos)
{
Redraw_grid(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
Update_rect(x_pos,y_pos,
width*Main_magnifier_factor,end_y_pos-y_pos);
return;

View File

@ -826,6 +826,14 @@ int Load_INI(T_Config * conf)
else
conf->Font_file = strdup("font_Classic.png");
conf->Grid_XOR_color=255;
// Optional, XOR color for grid overlay (>2.0)
if (!Load_INI_get_values (file,buffer,"Grid_XOR_color",1,values))
{
if ((values[0]>0) || (values[0]<=255))
conf->Grid_XOR_color=values[0];
}
fclose(file);
free(filename);

View File

@ -644,6 +644,10 @@ int Save_INI(T_Config * conf)
if ((return_code=Save_INI_set_strings (Ancien_fichier,Nouveau_fichier,buffer,"Font_file",conf->Font_file)))
goto Erreur_Retour;
values[0]=(conf->Grid_XOR_color);
if ((return_code=Save_INI_set_values (Ancien_fichier,Nouveau_fichier,buffer,"Grid_XOR_color",1,values,0)))
goto Erreur_Retour;
Save_INI_flush(Ancien_fichier,Nouveau_fichier,buffer);

View File

@ -308,6 +308,7 @@ typedef struct
int Window_pos_y; ///< Last window y position (9999 if unsupportd/irrelevant for the platform)
word Double_click_speed; ///< Maximum delay for double-click, in ms.
word Double_key_speed; ///< Maximum delay for double-keypress, in ms.
byte Grid_XOR_color; ///< XOR value to apply for grid color.
} T_Config;
// Structures utilisées pour les descriptions de pages et de liste de pages.

View File

@ -1663,7 +1663,7 @@ void Display_cursor(void)
{
if( x_pos < 0 ) continue;
color=Gfx->Cursor_sprite[temp][counter_y][counter_x];
CURSOR_BACKGROUND[counter_y][counter_x]=Read_pixel(x_pos,y_pos);
Cursor_background[counter_y][counter_x]=Read_pixel(x_pos,y_pos);
if (color!=MC_Trans)
Pixel(x_pos,y_pos,color);
}
@ -1733,8 +1733,8 @@ void Display_cursor(void)
if(x_pos<0) continue;
if(x_pos>=Screen_width) break;
color=Gfx->Cursor_sprite[temp][counter_y][counter_x];
// On sauvegarde dans CURSOR_BACKGROUND pour restaurer plus tard
CURSOR_BACKGROUND[counter_y][counter_x]=Read_pixel(x_pos,y_pos);
// On sauvegarde dans Cursor_background pour restaurer plus tard
Cursor_background[counter_y][counter_x]=Read_pixel(x_pos,y_pos);
if (color!=MC_Trans)
Pixel(x_pos,y_pos,color);
}
@ -1762,8 +1762,8 @@ void Display_cursor(void)
if(x_pos<0) continue;
if(x_pos>=Screen_width) break;
color=Gfx->Cursor_sprite[shape][counter_y][counter_x];
// On sauvegarde dans CURSOR_BACKGROUND pour restaurer plus tard
CURSOR_BACKGROUND[counter_y][counter_x]=Read_pixel(x_pos,y_pos);
// On sauvegarde dans Cursor_background pour restaurer plus tard
Cursor_background[counter_y][counter_x]=Read_pixel(x_pos,y_pos);
if (color!=MC_Trans)
Pixel(x_pos,y_pos,color);
}
@ -1966,7 +1966,7 @@ void Hide_cursor(void)
{
if(x_pos < 0) continue;
else if (x_pos>=Screen_width) break;
Pixel(x_pos,y_pos,CURSOR_BACKGROUND[counter_y][counter_x]);
Pixel(x_pos,y_pos,Cursor_background[counter_y][counter_x]);
}
}
@ -2035,7 +2035,7 @@ void Hide_cursor(void)
{
if(x_pos<0) continue;
if(x_pos>=Screen_width) break;
Pixel(x_pos,y_pos,CURSOR_BACKGROUND[counter_y][counter_x]);
Pixel(x_pos,y_pos,Cursor_background[counter_y][counter_x]);
}
}
Update_rect(Max(start_x,0),Max(start_y,0),counter_x,counter_y);
@ -2063,7 +2063,7 @@ void Hide_cursor(void)
{
if(x_pos<0) continue;
if(x_pos>=Screen_width) break;
Pixel(x_pos,y_pos,CURSOR_BACKGROUND[counter_y][counter_x]);
Pixel(x_pos,y_pos,Cursor_background[counter_y][counter_x]);
}
}
Update_rect(Max(start_x,0),Max(start_y,0),counter_x,counter_y);