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
114
brush.c
114
brush.c
@ -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 -- //
|
||||
//
|
||||
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)
|
||||
new_brush_height=Main_image_height-start_y;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
Realloc_brush(new_brush_width, new_brush_height);
|
||||
|
||||
Copy_image_to_brush(start_x,start_y,Brush_width,Brush_height,Main_image_width);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
///
|
||||
/// 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
|
||||
|
||||
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)
|
||||
{
|
||||
if (Brush_container[index].Paintbrush_shape <= PAINTBRUSH_SHAPE_MISC)
|
||||
if (Brush_container[index].Paintbrush_shape < PAINTBRUSH_SHAPE_MAX)
|
||||
{
|
||||
int x,y;
|
||||
int offset_x=0, offset_y=0;
|
||||
@ -5655,13 +5655,18 @@ void Display_stored_brush_in_window(word x_pos,word y_pos,int index)
|
||||
|
||||
// Draw up to 16x16
|
||||
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++)
|
||||
Pixel_in_window(x_pos+x+offset_x,y_pos+y+offset_y,Brush_container[index].Thumbnail[y][x]?MC_Black:MC_Light);
|
||||
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)
|
||||
{
|
||||
for (x=0; x<Brush_container[index].Width && x<BRUSH_CONTAINER_PREVIEW_WIDTH; x++)
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
@ -5685,7 +5690,7 @@ void Store_brush(int index)
|
||||
Brush_container[index].Paintbrush_shape=Paintbrush_shape;
|
||||
Brush_container[index].Width=Paintbrush_width;
|
||||
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
|
||||
if (Paintbrush_width>BRUSH_CONTAINER_PREVIEW_WIDTH)
|
||||
brush_offset_x = (Paintbrush_width-BRUSH_CONTAINER_PREVIEW_WIDTH)/2;
|
||||
@ -5698,6 +5703,36 @@ void Store_brush(int index)
|
||||
// Re-init the rest
|
||||
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)
|
||||
@ -5738,8 +5773,21 @@ byte Restore_brush(int index)
|
||||
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);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user