Brush container (Issue 135) now working with color brushes too.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1001 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
29ee887c78
commit
1ccdf24dfa
138
brush.c
138
brush.c
@ -124,7 +124,7 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview)
|
|||||||
byte * temp;
|
byte * temp;
|
||||||
|
|
||||||
if (is_preview==0 || Mouse_K==0) // pas de curseur si on est en preview et
|
if (is_preview==0 || Mouse_K==0) // pas de curseur si on est en preview et
|
||||||
// en train de cliquer
|
// en train de cliquer
|
||||||
switch (Paintbrush_shape)
|
switch (Paintbrush_shape)
|
||||||
{
|
{
|
||||||
case PAINTBRUSH_SHAPE_POINT : // !!! TOUJOURS EN PREVIEW !!!
|
case PAINTBRUSH_SHAPE_POINT : // !!! TOUJOURS EN PREVIEW !!!
|
||||||
@ -446,12 +446,12 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview)
|
|||||||
temp_color=Read_pixel_from_current_screen(x_pos,y_pos);
|
temp_color=Read_pixel_from_current_screen(x_pos,y_pos);
|
||||||
position=(counter_y*Smear_brush_width)+counter_x;
|
position=(counter_y*Smear_brush_width)+counter_x;
|
||||||
if ( (Paintbrush_sprite[(MAX_PAINTBRUSH_SIZE*counter_y)+counter_x] != 0)
|
if ( (Paintbrush_sprite[(MAX_PAINTBRUSH_SIZE*counter_y)+counter_x] != 0)
|
||||||
// Le pinceau sert de masque pour dire quels pixels on doit traiter dans le rectangle
|
// Le pinceau sert de masque pour dire quels pixels on doit traiter dans le rectangle
|
||||||
&& (counter_y<Smear_max_Y) && (counter_x<Smear_max_X)
|
&& (counter_y<Smear_max_Y) && (counter_x<Smear_max_X)
|
||||||
&& (counter_y>=Smear_min_Y) && (counter_x>=Smear_min_X)
|
&& (counter_y>=Smear_min_Y) && (counter_x>=Smear_min_X)
|
||||||
// On clippe l'effet smear entre Smear_Min et Smear_Max
|
// On clippe l'effet smear entre Smear_Min et Smear_Max
|
||||||
)
|
)
|
||||||
Display_pixel(x_pos,y_pos,Smear_brush[position]);
|
Display_pixel(x_pos,y_pos,Smear_brush[position]);
|
||||||
Smear_brush[position]=temp_color;
|
Smear_brush[position]=temp_color;
|
||||||
}
|
}
|
||||||
Update_part_of_screen(start_x, start_y, width, height);
|
Update_part_of_screen(start_x, start_y, width, height);
|
||||||
@ -477,6 +477,69 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Changes the Brush size, discarding its previous content.
|
||||||
|
/// @return 0 OK, 1 Failed
|
||||||
|
byte Realloc_brush(word new_brush_width, word new_brush_height)
|
||||||
|
{
|
||||||
|
byte return_code=0;
|
||||||
|
|
||||||
|
if ( (((long)Brush_height)*Brush_width) !=
|
||||||
|
(((long)new_brush_height)*new_brush_width) )
|
||||||
|
{
|
||||||
|
free(Brush);
|
||||||
|
Brush=(byte *)malloc(((long)new_brush_height)*new_brush_width);
|
||||||
|
if (Brush == NULL)
|
||||||
|
{
|
||||||
|
Error(0);
|
||||||
|
return_code=1;
|
||||||
|
|
||||||
|
Brush=(byte *)malloc(1*1);
|
||||||
|
if(Brush == NULL)
|
||||||
|
{
|
||||||
|
Error(ERROR_MEMORY);
|
||||||
|
exit(ERROR_MEMORY);
|
||||||
|
}
|
||||||
|
new_brush_height=new_brush_width=1;
|
||||||
|
*Brush=Fore_color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Brush_width=new_brush_width;
|
||||||
|
Brush_height=new_brush_height;
|
||||||
|
|
||||||
|
free(Smear_brush);
|
||||||
|
Smear_brush_width=(Brush_width>MAX_PAINTBRUSH_SIZE)?Brush_width:MAX_PAINTBRUSH_SIZE;
|
||||||
|
Smear_brush_height=(Brush_height>MAX_PAINTBRUSH_SIZE)?Brush_height:MAX_PAINTBRUSH_SIZE;
|
||||||
|
Smear_brush=(byte *)malloc(((long)Smear_brush_height)*Smear_brush_width);
|
||||||
|
|
||||||
|
if (Smear_brush == NULL) // Failed to allocate the smear brush
|
||||||
|
{
|
||||||
|
Error(0);
|
||||||
|
return_code=1;
|
||||||
|
|
||||||
|
free(Brush);
|
||||||
|
Brush=(byte *)malloc(1*1);
|
||||||
|
if(Brush == NULL)
|
||||||
|
{
|
||||||
|
Error(ERROR_MEMORY);
|
||||||
|
exit(ERROR_MEMORY);
|
||||||
|
}
|
||||||
|
Brush_height=1;
|
||||||
|
Brush_width=1;
|
||||||
|
|
||||||
|
Smear_brush=(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE);
|
||||||
|
if(Smear_brush == NULL)
|
||||||
|
{
|
||||||
|
Error(ERROR_MEMORY);
|
||||||
|
exit(ERROR_MEMORY);
|
||||||
|
}
|
||||||
|
Smear_brush_height=MAX_PAINTBRUSH_SIZE;
|
||||||
|
Smear_brush_width=MAX_PAINTBRUSH_SIZE;
|
||||||
|
}
|
||||||
|
return return_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- Effacer le pinceau -- //
|
// -- Effacer le pinceau -- //
|
||||||
//
|
//
|
||||||
void Hide_paintbrush(short x,short y)
|
void Hide_paintbrush(short x,short y)
|
||||||
@ -655,56 +718,7 @@ void Capture_brush(short start_x,short start_y,short end_x,short end_y,short cle
|
|||||||
if (start_y+new_brush_height>Main_image_height)
|
if (start_y+new_brush_height>Main_image_height)
|
||||||
new_brush_height=Main_image_height-start_y;
|
new_brush_height=Main_image_height-start_y;
|
||||||
|
|
||||||
if ( (((long)Brush_height)*Brush_width) !=
|
Realloc_brush(new_brush_width, new_brush_height);
|
||||||
(((long)new_brush_height)*new_brush_width) )
|
|
||||||
{
|
|
||||||
free(Brush);
|
|
||||||
Brush=(byte *)malloc(((long)new_brush_height)*new_brush_width);
|
|
||||||
if (Brush == NULL)
|
|
||||||
{
|
|
||||||
Error(0);
|
|
||||||
|
|
||||||
Brush=(byte *)malloc(1*1);
|
|
||||||
if(Brush == NULL)
|
|
||||||
{
|
|
||||||
Error(ERROR_MEMORY);
|
|
||||||
exit(ERROR_MEMORY);
|
|
||||||
}
|
|
||||||
new_brush_height=new_brush_width=1;
|
|
||||||
*Brush=Fore_color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Brush_width=new_brush_width;
|
|
||||||
Brush_height=new_brush_height;
|
|
||||||
|
|
||||||
free(Smear_brush);
|
|
||||||
Smear_brush_width=(Brush_width>MAX_PAINTBRUSH_SIZE)?Brush_width:MAX_PAINTBRUSH_SIZE;
|
|
||||||
Smear_brush_height=(Brush_height>MAX_PAINTBRUSH_SIZE)?Brush_height:MAX_PAINTBRUSH_SIZE;
|
|
||||||
Smear_brush=(byte *)malloc(((long)Smear_brush_height)*Smear_brush_width);
|
|
||||||
|
|
||||||
if (Smear_brush == NULL) // On ne peut même pas allouer la brosse du smear!
|
|
||||||
{
|
|
||||||
Error(0);
|
|
||||||
|
|
||||||
free(Brush);
|
|
||||||
Brush=(byte *)malloc(1*1);
|
|
||||||
if(Brush == NULL)
|
|
||||||
{
|
|
||||||
Error(ERROR_MEMORY);
|
|
||||||
exit(ERROR_MEMORY);
|
|
||||||
}
|
|
||||||
Brush_height=1;
|
|
||||||
Brush_width=1;
|
|
||||||
|
|
||||||
Smear_brush=(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE);
|
|
||||||
if(Smear_brush == NULL)
|
|
||||||
{
|
|
||||||
Error(ERROR_MEMORY);
|
|
||||||
exit(ERROR_MEMORY);
|
|
||||||
}
|
|
||||||
Smear_brush_height=MAX_PAINTBRUSH_SIZE;
|
|
||||||
Smear_brush_width=MAX_PAINTBRUSH_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Copy_image_to_brush(start_x,start_y,Brush_width,Brush_height,Main_image_width);
|
Copy_image_to_brush(start_x,start_y,Brush_width,Brush_height,Main_image_width);
|
||||||
|
|
||||||
@ -827,7 +841,7 @@ void Outline_brush(void)
|
|||||||
|
|
||||||
// On copie la brosse courante dans la nouvelle
|
// On copie la brosse courante dans la nouvelle
|
||||||
Copy_part_of_image_to_another(Brush, // source
|
Copy_part_of_image_to_another(Brush, // source
|
||||||
0, 0, Brush_width, Brush_height, Brush_width,
|
0, 0, Brush_width, Brush_height, Brush_width,
|
||||||
new_brush, // Destination
|
new_brush, // Destination
|
||||||
1, 1, width);
|
1, 1, width);
|
||||||
|
|
||||||
@ -858,8 +872,8 @@ void Outline_brush(void)
|
|||||||
}
|
}
|
||||||
else if (state == 0)
|
else if (state == 0)
|
||||||
{
|
{
|
||||||
Pixel_in_brush(x_pos-1,y_pos,Fore_color);
|
Pixel_in_brush(x_pos-1,y_pos,Fore_color);
|
||||||
state=1;
|
state=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Cas du dernier pixel à droite de la ligne
|
// Cas du dernier pixel à droite de la ligne
|
||||||
@ -1088,7 +1102,7 @@ void Capture_brush_with_lasso(int vertices, short * points,short clear)
|
|||||||
Error(0);
|
Error(0);
|
||||||
|
|
||||||
Brush=(byte *)malloc(1*1);
|
Brush=(byte *)malloc(1*1);
|
||||||
if(Brush==NULL) Error(ERROR_MEMORY);
|
if(Brush==NULL) Error(ERROR_MEMORY);
|
||||||
new_brush_height=new_brush_width=1;
|
new_brush_height=new_brush_width=1;
|
||||||
*Brush=Fore_color;
|
*Brush=Fore_color;
|
||||||
}
|
}
|
||||||
@ -1107,7 +1121,7 @@ void Capture_brush_with_lasso(int vertices, short * points,short clear)
|
|||||||
|
|
||||||
free(Brush);
|
free(Brush);
|
||||||
Brush=(byte *)malloc(1*1);
|
Brush=(byte *)malloc(1*1);
|
||||||
if(Brush==NULL) Error(ERROR_MEMORY);
|
if(Brush==NULL) Error(ERROR_MEMORY);
|
||||||
Brush_height=1;
|
Brush_height=1;
|
||||||
Brush_width=1;
|
Brush_width=1;
|
||||||
|
|
||||||
|
|||||||
8
brush.h
8
brush.h
@ -105,4 +105,12 @@ void Nibble_brush(void);
|
|||||||
*/
|
*/
|
||||||
void Capture_brush_with_lasso(int vertices, short * points,short clear);
|
void Capture_brush_with_lasso(int vertices, short * points,short clear);
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Changes the Brush size, discarding its previous content.
|
||||||
|
/// @return 0 OK, 1 Failed
|
||||||
|
byte Realloc_brush(word new_brush_width, word new_brush_height);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
64
buttons.c
64
buttons.c
@ -5636,7 +5636,7 @@ void Button_Text()
|
|||||||
|
|
||||||
void Display_stored_brush_in_window(word x_pos,word y_pos,int index)
|
void Display_stored_brush_in_window(word x_pos,word y_pos,int index)
|
||||||
{
|
{
|
||||||
if (Brush_container[index].Paintbrush_shape <= PAINTBRUSH_SHAPE_MISC)
|
if (Brush_container[index].Paintbrush_shape < PAINTBRUSH_SHAPE_MAX)
|
||||||
{
|
{
|
||||||
int x,y;
|
int x,y;
|
||||||
int offset_x=0, offset_y=0;
|
int offset_x=0, offset_y=0;
|
||||||
@ -5655,14 +5655,19 @@ void Display_stored_brush_in_window(word x_pos,word y_pos,int index)
|
|||||||
|
|
||||||
// Draw up to 16x16
|
// Draw up to 16x16
|
||||||
for (y=0; y<Brush_container[index].Height && y<BRUSH_CONTAINER_PREVIEW_HEIGHT; y++)
|
for (y=0; y<Brush_container[index].Height && y<BRUSH_CONTAINER_PREVIEW_HEIGHT; y++)
|
||||||
|
{
|
||||||
for (x=0; x<Brush_container[index].Width && x<BRUSH_CONTAINER_PREVIEW_WIDTH; x++)
|
for (x=0; x<Brush_container[index].Width && x<BRUSH_CONTAINER_PREVIEW_WIDTH; x++)
|
||||||
Pixel_in_window(x_pos+x+offset_x,y_pos+y+offset_y,Brush_container[index].Thumbnail[y][x]?MC_Black:MC_Light);
|
{
|
||||||
|
byte color;
|
||||||
|
if (Brush_container[index].Paintbrush_shape <= PAINTBRUSH_SHAPE_MISC)
|
||||||
|
color = Brush_container[index].Thumbnail[y][x]?MC_Black:MC_Light;
|
||||||
|
else
|
||||||
|
color = Brush_container[index].Thumbnail[y][x];
|
||||||
|
Pixel_in_window(x_pos+x+offset_x,y_pos+y+offset_y,color);
|
||||||
|
}
|
||||||
|
}
|
||||||
Update_window_area(x_pos,y_pos,BRUSH_CONTAINER_PREVIEW_WIDTH,BRUSH_CONTAINER_PREVIEW_HEIGHT);
|
Update_window_area(x_pos,y_pos,BRUSH_CONTAINER_PREVIEW_WIDTH,BRUSH_CONTAINER_PREVIEW_HEIGHT);
|
||||||
|
|
||||||
}
|
|
||||||
if (Brush_container[index].Paintbrush_shape == PAINTBRUSH_SHAPE_COLOR_BRUSH)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5685,7 +5690,7 @@ void Store_brush(int index)
|
|||||||
Brush_container[index].Paintbrush_shape=Paintbrush_shape;
|
Brush_container[index].Paintbrush_shape=Paintbrush_shape;
|
||||||
Brush_container[index].Width=Paintbrush_width;
|
Brush_container[index].Width=Paintbrush_width;
|
||||||
Brush_container[index].Height=Paintbrush_height;
|
Brush_container[index].Height=Paintbrush_height;
|
||||||
memcpy(Brush_container[index].Palette,Main_palette,sizeof(T_Palette));
|
//memcpy(Brush_container[index].Palette,Main_palette,sizeof(T_Palette));
|
||||||
// Preview: pick center for big mono brush
|
// Preview: pick center for big mono brush
|
||||||
if (Paintbrush_width>BRUSH_CONTAINER_PREVIEW_WIDTH)
|
if (Paintbrush_width>BRUSH_CONTAINER_PREVIEW_WIDTH)
|
||||||
brush_offset_x = (Paintbrush_width-BRUSH_CONTAINER_PREVIEW_WIDTH)/2;
|
brush_offset_x = (Paintbrush_width-BRUSH_CONTAINER_PREVIEW_WIDTH)/2;
|
||||||
@ -5698,6 +5703,36 @@ void Store_brush(int index)
|
|||||||
// Re-init the rest
|
// Re-init the rest
|
||||||
Brush_container[index].Transp_color=0;
|
Brush_container[index].Transp_color=0;
|
||||||
}
|
}
|
||||||
|
if (Paintbrush_shape == PAINTBRUSH_SHAPE_COLOR_BRUSH ||
|
||||||
|
Paintbrush_shape == PAINTBRUSH_SHAPE_MONO_BRUSH)
|
||||||
|
{
|
||||||
|
Brush_container[index].Brush=(byte *)malloc(Brush_width*Brush_height);
|
||||||
|
if (Brush_container[index].Brush)
|
||||||
|
{
|
||||||
|
Brush_container[index].Paintbrush_shape=Paintbrush_shape;
|
||||||
|
Brush_container[index].Width=Brush_width;
|
||||||
|
Brush_container[index].Height=Brush_height;
|
||||||
|
|
||||||
|
memcpy(Brush_container[index].Brush, Brush,Brush_height*Brush_width);
|
||||||
|
|
||||||
|
// Scale for preview
|
||||||
|
if (Brush_width>BRUSH_CONTAINER_PREVIEW_WIDTH ||
|
||||||
|
Brush_height>BRUSH_CONTAINER_PREVIEW_HEIGHT)
|
||||||
|
{
|
||||||
|
// Scale
|
||||||
|
Rescale(Brush, Brush_width, Brush_height, (byte *)(Brush_container[index].Thumbnail), BRUSH_CONTAINER_PREVIEW_WIDTH, BRUSH_CONTAINER_PREVIEW_HEIGHT, 0, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Direct copy
|
||||||
|
Copy_part_of_image_to_another(Brush, 0,0,Brush_width, Brush_height,Brush_width,(byte *)(Brush_container[index].Thumbnail),0,0,BRUSH_CONTAINER_PREVIEW_WIDTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Error(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte Restore_brush(int index)
|
byte Restore_brush(int index)
|
||||||
@ -5738,8 +5773,21 @@ byte Restore_brush(int index)
|
|||||||
Set_paintbrush_size(Paintbrush_width,Paintbrush_height);
|
Set_paintbrush_size(Paintbrush_width,Paintbrush_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Color brushes
|
||||||
|
if (shape == PAINTBRUSH_SHAPE_COLOR_BRUSH ||
|
||||||
|
shape == PAINTBRUSH_SHAPE_MONO_BRUSH)
|
||||||
|
{
|
||||||
|
Paintbrush_shape=shape;
|
||||||
|
Realloc_brush(Brush_container[index].Width,Brush_container[index].Height);
|
||||||
|
// Realloc sets Brush_width and Brush_height to new size.
|
||||||
|
memcpy(Brush, Brush_container[index].Brush, Brush_height*Brush_width);
|
||||||
|
|
||||||
|
Brush_offset_X=Brush_width>>1;
|
||||||
|
Brush_offset_Y=Brush_height>>1;
|
||||||
|
|
||||||
|
}
|
||||||
Change_paintbrush_shape(shape);
|
Change_paintbrush_shape(shape);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user