Brushes are now saved in gfx2.cfg. Fix a severe bug in gfx2.cfg format: in Settings screen, the button 'Reload' was readign the file incorrectly, which caused (for example) the keyboard shortcut to 'Scroll Up' to disappear.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1481 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2010-05-18 00:07:06 +00:00
parent 3c391bc3af
commit a84a9b7e66
13 changed files with 278 additions and 260 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -2726,9 +2726,9 @@ void Button_Unselect_fill(void)
/// Checks if the current brush is identical to a preset one.
byte Same_paintbrush(byte index)
{
if (Paintbrush_shape!=Gfx->Paintbrush_type[index] ||
Paintbrush_width!=Gfx->Preset_paintbrush_width[index] ||
Paintbrush_height!=Gfx->Preset_paintbrush_height[index])
if (Paintbrush_shape!=Paintbrush[index].Shape ||
Paintbrush_width!=Paintbrush[index].Width ||
Paintbrush_height!=Paintbrush[index].Height)
return 0;
if (Paintbrush_shape==PAINTBRUSH_SHAPE_MISC)
@ -2737,7 +2737,7 @@ byte Same_paintbrush(byte index)
int x,y;
for(y=0;y<Paintbrush_height;y++)
for(x=0;x<Paintbrush_width;x++)
if(Paintbrush_sprite[(y*MAX_PAINTBRUSH_SIZE)+x]!=Gfx->Paintbrush_sprite[index][y][x])
if(Paintbrush_sprite[(y*MAX_PAINTBRUSH_SIZE)+x]!=Paintbrush[index].Sprite[y][x])
return 0;
}
return 1;
@ -5028,15 +5028,15 @@ void Store_brush(int index)
void Select_paintbrush(int index)
{
int x_pos,y_pos;
Paintbrush_shape=Gfx->Paintbrush_type[index];
Paintbrush_width=Gfx->Preset_paintbrush_width[index];
Paintbrush_height=Gfx->Preset_paintbrush_height[index];
Paintbrush_offset_X=Gfx->Preset_paintbrush_offset_X[index];
Paintbrush_offset_Y=Gfx->Preset_paintbrush_offset_Y[index];
Paintbrush_shape=Paintbrush[index].Shape;
Paintbrush_width=Paintbrush[index].Width;
Paintbrush_height=Paintbrush[index].Height;
Paintbrush_offset_X=Paintbrush[index].Offset_X;
Paintbrush_offset_Y=Paintbrush[index].Offset_Y;
for (y_pos=0; y_pos<Paintbrush_height; y_pos++)
for (x_pos=0; x_pos<Paintbrush_width; x_pos++)
Paintbrush_sprite[(y_pos*MAX_PAINTBRUSH_SIZE)+x_pos]=Gfx->Paintbrush_sprite[index][y_pos][x_pos];
Change_paintbrush_shape(Gfx->Paintbrush_type[index]);
Paintbrush_sprite[(y_pos*MAX_PAINTBRUSH_SIZE)+x_pos]=Paintbrush[index].Sprite[y_pos][x_pos];
Change_paintbrush_shape(Paintbrush[index].Shape);
}
/// Store the current brush in paintbrush slot, if possible.
@ -5047,15 +5047,15 @@ byte Store_paintbrush(int index)
{
int x_pos,y_pos;
Gfx->Paintbrush_type[index]=Paintbrush_shape;
Gfx->Preset_paintbrush_width[index]=Paintbrush_width;
Gfx->Preset_paintbrush_height[index]=Paintbrush_height;
Gfx->Preset_paintbrush_offset_X[index]=Paintbrush_offset_X;
Gfx->Preset_paintbrush_offset_Y[index]=Paintbrush_offset_Y;
Paintbrush[index].Shape=Paintbrush_shape;
Paintbrush[index].Width=Paintbrush_width;
Paintbrush[index].Height=Paintbrush_height;
Paintbrush[index].Offset_X=Paintbrush_offset_X;
Paintbrush[index].Offset_Y=Paintbrush_offset_Y;
for (y_pos=0; y_pos<Paintbrush_height; y_pos++)
for (x_pos=0; x_pos<Paintbrush_width; x_pos++)
Gfx->Paintbrush_sprite[index][y_pos][x_pos]=Paintbrush_sprite[(y_pos*MAX_PAINTBRUSH_SIZE)+x_pos];
Paintbrush[index].Sprite[y_pos][x_pos]=Paintbrush_sprite[(y_pos*MAX_PAINTBRUSH_SIZE)+x_pos];
return 0;
}
@ -5068,15 +5068,15 @@ byte Store_paintbrush(int index)
// Color brush transformed into a real mono paintbrush
int x_pos,y_pos;
Gfx->Paintbrush_type[index]=PAINTBRUSH_SHAPE_MISC;
Gfx->Preset_paintbrush_width[index]=Brush_width;
Gfx->Preset_paintbrush_height[index]=Brush_height;
Gfx->Preset_paintbrush_offset_X[index]=Brush_offset_X;
Gfx->Preset_paintbrush_offset_Y[index]=Brush_offset_Y;
Paintbrush[index].Shape=PAINTBRUSH_SHAPE_MISC;
Paintbrush[index].Width=Brush_width;
Paintbrush[index].Height=Brush_height;
Paintbrush[index].Offset_X=Brush_offset_X;
Paintbrush[index].Offset_Y=Brush_offset_Y;
for (y_pos=0; y_pos<Brush_height; y_pos++)
for (x_pos=0; x_pos<Brush_width; x_pos++)
Gfx->Paintbrush_sprite[index][y_pos][x_pos]=Brush[(y_pos*Brush_width)+x_pos]!=Back_color;
Paintbrush[index].Sprite[y_pos][x_pos]=Brush[(y_pos*Brush_width)+x_pos]!=Back_color;
return 0;
}

View File

@ -243,7 +243,8 @@ enum CHUNKS_CFG
CHUNK_SMOOTH = 6, ///< Smooth effect settings
CHUNK_EXCLUDE_COLORS = 7, ///< List of excluded colors
CHUNK_QUICK_SHADE = 8, ///< QShade effect settings
CHUNK_GRID = 9,
CHUNK_GRID = 9, ///< Grid settings
CHUNK_BRUSH =10, ///< Paintbrushes
CHUNK_MAX
};

View File

@ -823,6 +823,9 @@ GFX2_GLOBAL byte * Menu_font;
/// Pointer to the current active skin.
GFX2_GLOBAL T_Gui_skin * Gfx;
/// Pointer to the current active skin.
GFX2_GLOBAL T_Paintbrush Paintbrush[NB_PAINTBRUSH_SPRITES];
// -- Help data
/// Index of the ::Help_section shown by the Help screen.

View File

@ -250,7 +250,6 @@ void Center_GUI_cursor(T_Gui_skin *gfx, byte *cursor_buffer, int cursor_number)
byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
{
int index;
int i,j;
int cursor_x=0,cursor_y=0;
byte color;
@ -459,6 +458,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
cursor_y+=MENU_SPRITE_HEIGHT;
// Paintbrushes
/*
for (i=0; i<NB_PAINTBRUSH_SPRITES; i++)
{
// Each line holds 12
@ -474,11 +474,12 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
if (GUI_seek_right(gui, &cursor_x, cursor_y, neutral_color, "brush icon"))
return 1;
}
if (Read_GUI_block(gfx, gui, cursor_x, cursor_y, gfx->Paintbrush_sprite[i], PAINTBRUSH_WIDTH, PAINTBRUSH_HEIGHT, "brush icon",2))
if (Read_GUI_block(gfx, gui, cursor_x, cursor_y, Paintbrush[i].Sprite, PAINTBRUSH_WIDTH, PAINTBRUSH_HEIGHT, "brush icon",2))
return 1;
cursor_x+=PAINTBRUSH_WIDTH;
}
cursor_y+=PAINTBRUSH_HEIGHT;
*/
// Drive sprites
for (i=0; i<NB_ICON_SPRITES; i++)
@ -604,204 +605,7 @@ byte Parse_skin(SDL_Surface * gui, T_Gui_skin *gfx)
cursor_x+=6;
}
cursor_y+=8;
gfx->Preset_paintbrush_width [ 0]= 1;
gfx->Preset_paintbrush_height[ 0]= 1;
gfx->Paintbrush_type [ 0]=PAINTBRUSH_SHAPE_SQUARE;
gfx->Preset_paintbrush_width [ 1]= 2;
gfx->Preset_paintbrush_height[ 1]= 2;
gfx->Paintbrush_type [ 1]=PAINTBRUSH_SHAPE_SQUARE;
gfx->Preset_paintbrush_width [ 2]= 3;
gfx->Preset_paintbrush_height[ 2]= 3;
gfx->Paintbrush_type [ 2]=PAINTBRUSH_SHAPE_SQUARE;
gfx->Preset_paintbrush_width [ 3]= 4;
gfx->Preset_paintbrush_height[ 3]= 4;
gfx->Paintbrush_type [ 3]=PAINTBRUSH_SHAPE_SQUARE;
gfx->Preset_paintbrush_width [ 4]= 5;
gfx->Preset_paintbrush_height[ 4]= 5;
gfx->Paintbrush_type [ 4]=PAINTBRUSH_SHAPE_SQUARE;
gfx->Preset_paintbrush_width [ 5]= 7;
gfx->Preset_paintbrush_height[ 5]= 7;
gfx->Paintbrush_type [ 5]=PAINTBRUSH_SHAPE_SQUARE;
gfx->Preset_paintbrush_width [ 6]= 8;
gfx->Preset_paintbrush_height[ 6]= 8;
gfx->Paintbrush_type [ 6]=PAINTBRUSH_SHAPE_SQUARE;
gfx->Preset_paintbrush_width [ 7]=12;
gfx->Preset_paintbrush_height[ 7]=12;
gfx->Paintbrush_type [ 7]=PAINTBRUSH_SHAPE_SQUARE;
gfx->Preset_paintbrush_width [ 8]=16;
gfx->Preset_paintbrush_height[ 8]=16;
gfx->Paintbrush_type [ 8]=PAINTBRUSH_SHAPE_SQUARE;
gfx->Preset_paintbrush_width [ 9]=16;
gfx->Preset_paintbrush_height[ 9]=16;
gfx->Paintbrush_type [ 9]=PAINTBRUSH_SHAPE_SIEVE_SQUARE;
gfx->Preset_paintbrush_width [10]=15;
gfx->Preset_paintbrush_height[10]=15;
gfx->Paintbrush_type [10]=PAINTBRUSH_SHAPE_DIAMOND;
gfx->Preset_paintbrush_width [11]= 5;
gfx->Preset_paintbrush_height[11]= 5;
gfx->Paintbrush_type [11]=PAINTBRUSH_SHAPE_DIAMOND;
gfx->Preset_paintbrush_width [12]= 3;
gfx->Preset_paintbrush_height[12]= 3;
gfx->Paintbrush_type [12]=PAINTBRUSH_SHAPE_ROUND;
gfx->Preset_paintbrush_width [13]= 4;
gfx->Preset_paintbrush_height[13]= 4;
gfx->Paintbrush_type [13]=PAINTBRUSH_SHAPE_ROUND;
gfx->Preset_paintbrush_width [14]= 5;
gfx->Preset_paintbrush_height[14]= 5;
gfx->Paintbrush_type [14]=PAINTBRUSH_SHAPE_ROUND;
gfx->Preset_paintbrush_width [15]= 6;
gfx->Preset_paintbrush_height[15]= 6;
gfx->Paintbrush_type [15]=PAINTBRUSH_SHAPE_ROUND;
gfx->Preset_paintbrush_width [16]= 8;
gfx->Preset_paintbrush_height[16]= 8;
gfx->Paintbrush_type [16]=PAINTBRUSH_SHAPE_ROUND;
gfx->Preset_paintbrush_width [17]=10;
gfx->Preset_paintbrush_height[17]=10;
gfx->Paintbrush_type [17]=PAINTBRUSH_SHAPE_ROUND;
gfx->Preset_paintbrush_width [18]=12;
gfx->Preset_paintbrush_height[18]=12;
gfx->Paintbrush_type [18]=PAINTBRUSH_SHAPE_ROUND;
gfx->Preset_paintbrush_width [19]=14;
gfx->Preset_paintbrush_height[19]=14;
gfx->Paintbrush_type [19]=PAINTBRUSH_SHAPE_ROUND;
gfx->Preset_paintbrush_width [20]=16;
gfx->Preset_paintbrush_height[20]=16;
gfx->Paintbrush_type [20]=PAINTBRUSH_SHAPE_ROUND;
gfx->Preset_paintbrush_width [21]=15;
gfx->Preset_paintbrush_height[21]=15;
gfx->Paintbrush_type [21]=PAINTBRUSH_SHAPE_SIEVE_ROUND;
gfx->Preset_paintbrush_width [22]=11;
gfx->Preset_paintbrush_height[22]=11;
gfx->Paintbrush_type [22]=PAINTBRUSH_SHAPE_SIEVE_ROUND;
gfx->Preset_paintbrush_width [23]= 5;
gfx->Preset_paintbrush_height[23]= 5;
gfx->Paintbrush_type [23]=PAINTBRUSH_SHAPE_SIEVE_ROUND;
gfx->Preset_paintbrush_width [24]= 2;
gfx->Preset_paintbrush_height[24]= 1;
gfx->Paintbrush_type [24]=PAINTBRUSH_SHAPE_HORIZONTAL_BAR;
gfx->Preset_paintbrush_width [25]= 3;
gfx->Preset_paintbrush_height[25]= 1;
gfx->Paintbrush_type [25]=PAINTBRUSH_SHAPE_HORIZONTAL_BAR;
gfx->Preset_paintbrush_width [26]= 4;
gfx->Preset_paintbrush_height[26]= 1;
gfx->Paintbrush_type [26]=PAINTBRUSH_SHAPE_HORIZONTAL_BAR;
gfx->Preset_paintbrush_width [27]= 8;
gfx->Preset_paintbrush_height[27]= 1;
gfx->Paintbrush_type [27]=PAINTBRUSH_SHAPE_HORIZONTAL_BAR;
gfx->Preset_paintbrush_width [28]= 1;
gfx->Preset_paintbrush_height[28]= 2;
gfx->Paintbrush_type [28]=PAINTBRUSH_SHAPE_VERTICAL_BAR;
gfx->Preset_paintbrush_width [29]= 1;
gfx->Preset_paintbrush_height[29]= 3;
gfx->Paintbrush_type [29]=PAINTBRUSH_SHAPE_VERTICAL_BAR;
gfx->Preset_paintbrush_width [30]= 1;
gfx->Preset_paintbrush_height[30]= 4;
gfx->Paintbrush_type [30]=PAINTBRUSH_SHAPE_VERTICAL_BAR;
gfx->Preset_paintbrush_width [31]= 1;
gfx->Preset_paintbrush_height[31]= 8;
gfx->Paintbrush_type [31]=PAINTBRUSH_SHAPE_VERTICAL_BAR;
gfx->Preset_paintbrush_width [32]= 3;
gfx->Preset_paintbrush_height[32]= 3;
gfx->Paintbrush_type [32]=PAINTBRUSH_SHAPE_CROSS;
gfx->Preset_paintbrush_width [33]= 5;
gfx->Preset_paintbrush_height[33]= 5;
gfx->Paintbrush_type [33]=PAINTBRUSH_SHAPE_CROSS;
gfx->Preset_paintbrush_width [34]= 5;
gfx->Preset_paintbrush_height[34]= 5;
gfx->Paintbrush_type [34]=PAINTBRUSH_SHAPE_PLUS;
gfx->Preset_paintbrush_width [35]=15;
gfx->Preset_paintbrush_height[35]=15;
gfx->Paintbrush_type [35]=PAINTBRUSH_SHAPE_PLUS;
gfx->Preset_paintbrush_width [36]= 2;
gfx->Preset_paintbrush_height[36]= 2;
gfx->Paintbrush_type [36]=PAINTBRUSH_SHAPE_SLASH;
gfx->Preset_paintbrush_width [37]= 4;
gfx->Preset_paintbrush_height[37]= 4;
gfx->Paintbrush_type [37]=PAINTBRUSH_SHAPE_SLASH;
gfx->Preset_paintbrush_width [38]= 8;
gfx->Preset_paintbrush_height[38]= 8;
gfx->Paintbrush_type [38]=PAINTBRUSH_SHAPE_SLASH;
gfx->Preset_paintbrush_width [39]= 2;
gfx->Preset_paintbrush_height[39]= 2;
gfx->Paintbrush_type [39]=PAINTBRUSH_SHAPE_ANTISLASH;
gfx->Preset_paintbrush_width [40]= 4;
gfx->Preset_paintbrush_height[40]= 4;
gfx->Paintbrush_type [40]=PAINTBRUSH_SHAPE_ANTISLASH;
gfx->Preset_paintbrush_width [41]= 8;
gfx->Preset_paintbrush_height[41]= 8;
gfx->Paintbrush_type [41]=PAINTBRUSH_SHAPE_ANTISLASH;
gfx->Preset_paintbrush_width [42]= 4;
gfx->Preset_paintbrush_height[42]= 4;
gfx->Paintbrush_type [42]=PAINTBRUSH_SHAPE_RANDOM;
gfx->Preset_paintbrush_width [43]= 8;
gfx->Preset_paintbrush_height[43]= 8;
gfx->Paintbrush_type [43]=PAINTBRUSH_SHAPE_RANDOM;
gfx->Preset_paintbrush_width [44]=13;
gfx->Preset_paintbrush_height[44]=13;
gfx->Paintbrush_type [44]=PAINTBRUSH_SHAPE_RANDOM;
gfx->Preset_paintbrush_width [45]= 3;
gfx->Preset_paintbrush_height[45]= 3;
gfx->Paintbrush_type [45]=PAINTBRUSH_SHAPE_MISC;
gfx->Preset_paintbrush_width [46]= 3;
gfx->Preset_paintbrush_height[46]= 3;
gfx->Paintbrush_type [46]=PAINTBRUSH_SHAPE_MISC;
gfx->Preset_paintbrush_width [47]= 7;
gfx->Preset_paintbrush_height[47]= 7;
gfx->Paintbrush_type [47]=PAINTBRUSH_SHAPE_MISC;
for (index=0;index<NB_PAINTBRUSH_SPRITES;index++)
{
gfx->Preset_paintbrush_offset_X[index]=(gfx->Preset_paintbrush_width [index]>>1);
gfx->Preset_paintbrush_offset_Y[index]=(gfx->Preset_paintbrush_height[index]>>1);
}
return 0;
}
@ -2240,6 +2044,53 @@ int Load_CFG(int reload_all)
goto Erreur_lecture_config;
}
break;
case CHUNK_BRUSH:
if (reload_all)
{
int index;
for (index=0; index<NB_PAINTBRUSH_SPRITES; index++)
{
int i;
byte current_byte=0;
word width,height;
if (!Read_byte(Handle, &Paintbrush[index].Shape))
goto Erreur_lecture_config;
if (!Read_word_le(Handle, &width))
goto Erreur_lecture_config;
if (!Read_word_le(Handle, &height))
goto Erreur_lecture_config;
Paintbrush[index].Width=width;
Paintbrush[index].Height=height;
if (!Read_word_le(Handle, &Paintbrush[index].Offset_X))
goto Erreur_lecture_config;
if (!Read_word_le(Handle, &Paintbrush[index].Offset_Y))
goto Erreur_lecture_config;
// Decode binary
for (i=0;i<width*height;i++)
{
if ((i&7) == 0)
{
// Read one byte
if (!Read_byte(Handle, &current_byte))
goto Erreur_lecture_config;
}
Paintbrush[index].Sprite[i/width][i%width] =
((current_byte & (0x80 >> (i&7))) != 0);
}
}
}
else
{
if (fseek(Handle,Chunk.Size,SEEK_CUR)==-1)
goto Erreur_lecture_config;
}
break;
default: // Chunk inconnu
goto Erreur_lecture_config;
}
@ -2292,7 +2143,7 @@ int Save_CFG(void)
// Enregistrement des touches
Chunk.Number=CHUNK_KEYS;
Chunk.Size=NB_SHORTCUTS*sizeof(cfg_shortcut_info);
Chunk.Size=NB_SHORTCUTS*6;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
@ -2334,7 +2185,7 @@ int Save_CFG(void)
// Sauvegarde de l'état de chaque mode vidéo
Chunk.Number=CHUNK_VIDEO_MODES;
Chunk.Size=modes_to_save * sizeof(cfg_video_mode);
Chunk.Size=modes_to_save * 5;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
@ -2359,7 +2210,7 @@ int Save_CFG(void)
// Ecriture des données du Shade (précédées du shade en cours)
Chunk.Number=CHUNK_SHADE;
Chunk.Size=sizeof(Shade_list)+sizeof(Shade_current);
Chunk.Size=8209;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
goto Erreur_sauvegarde_config;
@ -2379,7 +2230,7 @@ int Save_CFG(void)
// Sauvegarde des informations du Masque
Chunk.Number=CHUNK_MASK;
Chunk.Size=sizeof(Mask_table);
Chunk.Size=256;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
goto Erreur_sauvegarde_config;
@ -2388,7 +2239,7 @@ int Save_CFG(void)
// Sauvegarde des informations du Stencil
Chunk.Number=CHUNK_STENCIL;
Chunk.Size=sizeof(Stencil);
Chunk.Size=256;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
goto Erreur_sauvegarde_config;
@ -2397,7 +2248,7 @@ int Save_CFG(void)
// Sauvegarde des informations des dégradés
Chunk.Number=CHUNK_GRADIENTS;
Chunk.Size=sizeof(Gradient_array)+1;
Chunk.Size=241;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
goto Erreur_sauvegarde_config;
@ -2415,7 +2266,7 @@ int Save_CFG(void)
// Sauvegarde de la matrice du Smooth
Chunk.Number=CHUNK_SMOOTH;
Chunk.Size=sizeof(Smooth_matrix);
Chunk.Size=9;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
goto Erreur_sauvegarde_config;
@ -2426,7 +2277,7 @@ int Save_CFG(void)
// Sauvegarde des couleurs à exclure
Chunk.Number=CHUNK_EXCLUDE_COLORS;
Chunk.Size=sizeof(Exclude_color);
Chunk.Size=256;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
goto Erreur_sauvegarde_config;
@ -2435,7 +2286,7 @@ int Save_CFG(void)
// Sauvegarde des informations du Quick-shade
Chunk.Number=CHUNK_QUICK_SHADE;
Chunk.Size=sizeof(Quick_shade_step)+sizeof(Quick_shade_loop);
Chunk.Size=2;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
goto Erreur_sauvegarde_config;
@ -2459,7 +2310,70 @@ int Save_CFG(void)
if (!Write_word_le(Handle, Snap_offset_Y))
goto Erreur_sauvegarde_config;
// Save brush data
{
long total_size=0;
int index;
// Compute size: normal paintbrushes
for (index=0; index<NB_PAINTBRUSH_SPRITES; index++)
{
total_size+=9+(Paintbrush[index].Width*Paintbrush[index].Height+7)/8;
}
/*
// Compute size: brush container
for (index=0; index<BRUSH_CONTAINER_COLUMNS*BRUSH_CONTAINER_ROWS; index++)
{
}
*/
Chunk.Number=CHUNK_BRUSH;
Chunk.Size=total_size;
if (!Write_byte(Handle, Chunk.Number) ||
!Write_word_le(Handle, Chunk.Size) )
goto Erreur_sauvegarde_config;
for (index=0; index<NB_PAINTBRUSH_SPRITES; index++)
{
int i;
byte current_byte=0;
word width,height;
width=Paintbrush[index].Width;
height=Paintbrush[index].Height;
if (!Write_byte(Handle, Paintbrush[index].Shape))
goto Erreur_sauvegarde_config;
if (!Write_word_le(Handle, width))
goto Erreur_sauvegarde_config;
if (!Write_word_le(Handle, height))
goto Erreur_sauvegarde_config;
if (!Write_word_le(Handle, Paintbrush[index].Offset_X))
goto Erreur_sauvegarde_config;
if (!Write_word_le(Handle, Paintbrush[index].Offset_Y))
goto Erreur_sauvegarde_config;
// Encode in binary
for (i=0;i<width*height;i++)
{
if (Paintbrush[index].Sprite[i/width][i%width])
current_byte |= 0x80 >> (i&7);
if ((i&7) == 7)
{
// Write one byte
if (!Write_byte(Handle, current_byte))
goto Erreur_sauvegarde_config;
current_byte=0;
}
}
// Remainder
if ((i&7) != 0)
{
// Write one byte
if (!Write_byte(Handle, current_byte))
goto Erreur_sauvegarde_config;
}
}
}
if (fclose(Handle))
return ERROR_SAVING_CFG;
@ -2686,3 +2600,93 @@ void Compute_menu_offsets(void)
Menu_Y = Screen_height - Menu_height * Menu_factor_Y;
}
void Init_paintbrush(int index, int width, int height, byte shape, const char * bitmap)
{
if (bitmap!=NULL)
{
int i;
Paintbrush[index].Shape=shape;
Paintbrush[index].Width=width;
Paintbrush[index].Height=height;
Paintbrush[index].Offset_X=width>>1;
Paintbrush[index].Offset_Y=height>>1;
// Decode pixels
for (i=0;i<width*height;i++)
{
Paintbrush[index].Sprite[i/width][i%width] =
((bitmap[i/8] & (0x80 >> (i&7))) != 0);
}
}
else
{
Paintbrush_shape=shape;
Set_paintbrush_size(width, height);
Store_paintbrush(index);
}
}
void Init_paintbrushes(void)
{
int index;
Init_paintbrush( 0, 1, 1,PAINTBRUSH_SHAPE_SQUARE, NULL);
Init_paintbrush( 1, 2, 2,PAINTBRUSH_SHAPE_SQUARE, NULL);
Init_paintbrush( 2, 3, 3,PAINTBRUSH_SHAPE_SQUARE, NULL);
Init_paintbrush( 3, 4, 4,PAINTBRUSH_SHAPE_SQUARE, NULL);
Init_paintbrush( 4, 5, 5,PAINTBRUSH_SHAPE_SQUARE, NULL);
Init_paintbrush( 5, 7, 7,PAINTBRUSH_SHAPE_SQUARE, NULL);
Init_paintbrush( 6, 8, 8,PAINTBRUSH_SHAPE_SQUARE, NULL);
Init_paintbrush( 7,12,12,PAINTBRUSH_SHAPE_SQUARE, NULL);
Init_paintbrush( 8,16,16,PAINTBRUSH_SHAPE_SQUARE, NULL);
Init_paintbrush( 9,16,16,PAINTBRUSH_SHAPE_SIEVE_SQUARE, NULL);
Init_paintbrush(10,15,15,PAINTBRUSH_SHAPE_DIAMOND, NULL);
Init_paintbrush(11, 5, 5,PAINTBRUSH_SHAPE_DIAMOND, NULL);
Init_paintbrush(12, 3, 3,PAINTBRUSH_SHAPE_ROUND, NULL);
Init_paintbrush(13, 4, 4,PAINTBRUSH_SHAPE_ROUND, NULL);
Init_paintbrush(14, 5, 5,PAINTBRUSH_SHAPE_ROUND, NULL);
Init_paintbrush(15, 6, 6,PAINTBRUSH_SHAPE_ROUND, NULL);
Init_paintbrush(16, 8, 8,PAINTBRUSH_SHAPE_ROUND, NULL);
Init_paintbrush(17,10,10,PAINTBRUSH_SHAPE_ROUND, NULL);
Init_paintbrush(18,12,12,PAINTBRUSH_SHAPE_ROUND, NULL);
Init_paintbrush(19,14,14,PAINTBRUSH_SHAPE_ROUND, NULL);
Init_paintbrush(20,16,16,PAINTBRUSH_SHAPE_ROUND, NULL);
Init_paintbrush(21,15,15,PAINTBRUSH_SHAPE_SIEVE_ROUND, NULL);
Init_paintbrush(22,11,11,PAINTBRUSH_SHAPE_SIEVE_ROUND, NULL);
Init_paintbrush(23, 5, 5,PAINTBRUSH_SHAPE_SIEVE_ROUND, NULL);
Init_paintbrush(24, 2, 1,PAINTBRUSH_SHAPE_HORIZONTAL_BAR, NULL);
Init_paintbrush(25, 3, 1,PAINTBRUSH_SHAPE_HORIZONTAL_BAR, NULL);
Init_paintbrush(26, 4, 1,PAINTBRUSH_SHAPE_HORIZONTAL_BAR, NULL);
Init_paintbrush(27, 8, 1,PAINTBRUSH_SHAPE_HORIZONTAL_BAR, NULL);
Init_paintbrush(28, 1, 2,PAINTBRUSH_SHAPE_VERTICAL_BAR, NULL);
Init_paintbrush(29, 1, 3,PAINTBRUSH_SHAPE_VERTICAL_BAR, NULL);
Init_paintbrush(30, 1, 4,PAINTBRUSH_SHAPE_VERTICAL_BAR, NULL);
Init_paintbrush(31, 1, 8,PAINTBRUSH_SHAPE_VERTICAL_BAR, NULL);
Init_paintbrush(32, 3, 3,PAINTBRUSH_SHAPE_CROSS, NULL);
Init_paintbrush(33, 5, 5,PAINTBRUSH_SHAPE_CROSS, NULL);
Init_paintbrush(34, 5, 5,PAINTBRUSH_SHAPE_PLUS, NULL);
Init_paintbrush(35,15,15,PAINTBRUSH_SHAPE_PLUS, NULL);
Init_paintbrush(36, 2, 2,PAINTBRUSH_SHAPE_SLASH, NULL);
Init_paintbrush(37, 4, 4,PAINTBRUSH_SHAPE_SLASH, NULL);
Init_paintbrush(38, 8, 8,PAINTBRUSH_SHAPE_SLASH, NULL);
Init_paintbrush(39, 2, 2,PAINTBRUSH_SHAPE_ANTISLASH, NULL);
Init_paintbrush(40, 4, 4,PAINTBRUSH_SHAPE_ANTISLASH, NULL);
Init_paintbrush(41, 8, 8,PAINTBRUSH_SHAPE_ANTISLASH, NULL);
Init_paintbrush(42, 4, 4,PAINTBRUSH_SHAPE_RANDOM, "\x20\x81");
Init_paintbrush(43, 8, 8,PAINTBRUSH_SHAPE_RANDOM, "\x44\x00\x11\x00\x88\x01\x40\x08");
Init_paintbrush(44,13,13,PAINTBRUSH_SHAPE_RANDOM, "\x08\x00\x08\x90\x00\x10\x42\x10\x02\x06\x02\x02\x04\x02\x08\x42\x10\x44\x00\x00\x44\x00");
Init_paintbrush(45, 3, 3,PAINTBRUSH_SHAPE_MISC, "\x7f\x00");
Init_paintbrush(46, 3, 3,PAINTBRUSH_SHAPE_MISC, "\xdd\x80");
Init_paintbrush(47, 7, 7,PAINTBRUSH_SHAPE_MISC, "\x06\x30\x82\x04\x10\x20\x00");
for (index=0;index<NB_PAINTBRUSH_SPRITES;index++)
{
Paintbrush[index].Offset_X=(Paintbrush[index].Width>>1);
Paintbrush[index].Offset_Y=(Paintbrush[index].Height>>1);
}
}

View File

@ -34,6 +34,7 @@ int Save_CFG(void);
void Set_all_video_modes(void);
void Set_config_defaults(void);
void Init_sighandler(void);
void Init_paintbrushes(void);
extern char Gui_loading_error_message[512];

View File

@ -574,7 +574,6 @@ int Init_program(int argc,char * argv[])
// Données sur le pinceau:
Paintbrush_X=0;
Paintbrush_Y=0;
Paintbrush_shape=PAINTBRUSH_SHAPE_ROUND;
Paintbrush_hidden=0;
// On initialise tout ce qui concerne les opérations et les effets
@ -634,6 +633,18 @@ int Init_program(int argc,char * argv[])
Windows_open=0;
// Paintbrush
if (!(Paintbrush_sprite=(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE))) Error(ERROR_MEMORY);
// Load preset paintbrushes (uses Paintbrush_ variables)
Init_paintbrushes();
// Set a valid paintbrush afterwards
*Paintbrush_sprite=1;
Paintbrush_width=1;
Paintbrush_height=1;
Paintbrush_shape=PAINTBRUSH_SHAPE_ROUND;
// Charger la configuration des touches
Set_config_defaults();
@ -701,11 +712,6 @@ int Init_program(int argc,char * argv[])
if (!(Brush =(byte *)malloc( 1* 1))) Error(ERROR_MEMORY);
if (!(Smear_brush =(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE))) Error(ERROR_MEMORY);
// Pinceau
if (!(Paintbrush_sprite=(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE))) Error(ERROR_MEMORY);
*Paintbrush_sprite=1;
Paintbrush_width=1;
Paintbrush_height=1;
starting_videomode=Current_resolution;
Horizontal_line_buffer=NULL;

View File

@ -400,21 +400,6 @@ typedef struct
/// Graphic resources for the mouse cursor.
byte Cursor_sprite[NB_CURSOR_SPRITES][CURSOR_SPRITE_HEIGHT][CURSOR_SPRITE_WIDTH];
// Preset paintbrushes
/// Graphic resources for the preset paintbrushes.
byte Paintbrush_sprite [NB_PAINTBRUSH_SPRITES][PAINTBRUSH_HEIGHT][PAINTBRUSH_WIDTH];
/// Width of the preset paintbrushes.
word Preset_paintbrush_width[NB_PAINTBRUSH_SPRITES];
/// Height of the preset paintbrushes.
word Preset_paintbrush_height[NB_PAINTBRUSH_SPRITES];
/// Type of the preset paintbrush: index in enum PAINTBRUSH_SHAPES
byte Paintbrush_type[NB_PAINTBRUSH_SPRITES];
/// Brush handle for the preset brushes. Generally ::Preset_paintbrush_width[]/2
word Preset_paintbrush_offset_X[NB_PAINTBRUSH_SPRITES];
/// Brush handle for the preset brushes. Generally ::Preset_paintbrush_height[]/2
word Preset_paintbrush_offset_Y[NB_PAINTBRUSH_SPRITES];
// Sieve patterns
/// Preset sieve patterns, stored as binary (one word per line)
@ -465,6 +450,24 @@ typedef struct
} T_Gui_skin;
typedef struct {
// Preset paintbrushes
/// Graphic resources for the preset paintbrushes.
byte Sprite[PAINTBRUSH_HEIGHT][PAINTBRUSH_WIDTH];
/// Width of the preset paintbrushes.
word Width;
/// Height of the preset paintbrushes.
word Height;
/// Type of the preset paintbrush: index in enum PAINTBRUSH_SHAPES
byte Shape;
/// Brush handle for the preset brushes. Generally ::Width[]/2
word Offset_X;
/// Brush handle for the preset brushes. Generally ::Height[]/2
word Offset_Y;
} T_Paintbrush;
// A menubar.
typedef struct {
word Width;

View File

@ -1286,19 +1286,19 @@ void Display_paintbrush_in_window(word x,word y,int number)
if (y_size<1)
y_size=1;
origin_x = (x + 8)*Menu_factor_X - (Gfx->Preset_paintbrush_offset_X[number])*x_size+Window_pos_X;
origin_y = (y + 8)*Menu_factor_Y - (Gfx->Preset_paintbrush_offset_Y[number])*y_size+Window_pos_Y;
origin_x = (x + 8)*Menu_factor_X - (Paintbrush[number].Offset_X)*x_size+Window_pos_X;
origin_y = (y + 8)*Menu_factor_Y - (Paintbrush[number].Offset_Y)*y_size+Window_pos_Y;
for (window_y_pos=0,y_pos=0; y_pos<Gfx->Preset_paintbrush_height[number]; window_y_pos++,y_pos++)
for (window_x_pos=0,x_pos=0; x_pos<Gfx->Preset_paintbrush_width[number]; window_x_pos++,x_pos++)
if (Gfx->Paintbrush_sprite[number][y_pos][x_pos])
for (window_y_pos=0,y_pos=0; y_pos<Paintbrush[number].Height; window_y_pos++,y_pos++)
for (window_x_pos=0,x_pos=0; x_pos<Paintbrush[number].Width; window_x_pos++,x_pos++)
if (Paintbrush[number].Sprite[y_pos][x_pos])
Block(origin_x+window_x_pos*x_size,origin_y+window_y_pos*y_size,x_size,y_size,MC_Black);
// On n'utilise pas Pixel_in_window() car on ne dessine pas
// forcément avec la même taille de pixel.
Update_rect( ToWinX(origin_x), ToWinY(origin_y),
ToWinL(Gfx->Preset_paintbrush_width[number]),
ToWinH(Gfx->Preset_paintbrush_height[number])
ToWinL(Paintbrush[number].Width),
ToWinH(Paintbrush[number].Height)
);
}