diff --git a/buttons.c b/buttons.c index c9f75428..bcf9e1b4 100644 --- a/buttons.c +++ b/buttons.c @@ -51,6 +51,7 @@ #include "windows.h" #include "brush.h" #include "input.h" +#include "special.h" #if defined(__amigaos4__) || defined(__AROS__) || defined(__MORPHOS__) || defined(__amigaos__) #include @@ -5633,12 +5634,184 @@ 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) + { + int x,y; + int offset_x=0, offset_y=0; + //int brush_offset_x=0, brush_offset_y=0; + + // Determine draw offset (small brushes are stacked on corner of their preview) + if (Brush_container[index].WidthBRUSH_CONTAINER_PREVIEW_WIDTH) + brush_offset_x = (Paintbrush_width-BRUSH_CONTAINER_PREVIEW_WIDTH)/2; + if (Paintbrush_height>BRUSH_CONTAINER_PREVIEW_HEIGHT) + brush_offset_y = (Paintbrush_height-BRUSH_CONTAINER_PREVIEW_HEIGHT)/2; + + for (y=0; y>1; + Paintbrush_offset_Y=Paintbrush_height>>1; + } + else + { + // Recreate the brush pixels from its shape and dimensions + Set_paintbrush_size(Paintbrush_width,Paintbrush_height); + } + } + + Change_paintbrush_shape(shape); + return 1; +} + +void Button_Brush_container(void) +{ + short clicked_button; + short x_pos,y_pos; + byte index; + + Open_window(BRUSH_CONTAINER_COLUMNS*(BRUSH_CONTAINER_PREVIEW_WIDTH+8)+8, + BRUSH_CONTAINER_ROWS*(BRUSH_CONTAINER_PREVIEW_HEIGHT+8)+40, + "Brushes"); + + Window_set_normal_button( + (BRUSH_CONTAINER_COLUMNS*(BRUSH_CONTAINER_PREVIEW_WIDTH+8)-59)/2, + (BRUSH_CONTAINER_ROWS)*(BRUSH_CONTAINER_PREVIEW_HEIGHT+8)+18, + 67,14,"Cancel",0,1,KEY_ESC); // 1 + + index=0; + for (index=0; index < BRUSH_CONTAINER_ROWS*BRUSH_CONTAINER_COLUMNS; index++) + { + x_pos = (index % BRUSH_CONTAINER_COLUMNS)*(BRUSH_CONTAINER_PREVIEW_WIDTH+8)+7; + y_pos = (index / BRUSH_CONTAINER_COLUMNS)*(BRUSH_CONTAINER_PREVIEW_HEIGHT+8)+18; + Window_set_normal_button( + x_pos, + y_pos, + BRUSH_CONTAINER_PREVIEW_WIDTH+2, + BRUSH_CONTAINER_PREVIEW_HEIGHT+2, + "",0,1,SDLK_LAST); + Display_stored_brush_in_window(x_pos+1, y_pos+1, index); + } + Update_window_area(0,0,Window_width, Window_height); + + Display_cursor(); + + do + { + clicked_button=Window_clicked_button(); + //if (Is_shortcut(Key,0x100+BUTTON_HELP)) + // Window_help(BUTTON_PAINTBRUSHES, NULL); + + if (clicked_button == 1) + break; + + if (clicked_button>1) + { + index = clicked_button-2; + + if (Window_attribute1==RIGHT_SIDE) + { + // Store + + x_pos = (index % BRUSH_CONTAINER_COLUMNS)*(BRUSH_CONTAINER_PREVIEW_WIDTH+8)+7; + y_pos = (index / BRUSH_CONTAINER_COLUMNS)*(BRUSH_CONTAINER_PREVIEW_HEIGHT+8)+18; + + Store_brush(index); + Hide_cursor(); + Display_stored_brush_in_window(x_pos+1, y_pos+1, index); + Display_cursor(); + } + else + { + // Restore and exit + + if (Restore_brush(index)) + break; + } + } + } + while (1); + Close_window(); + + //Unselect_button(BUTTON_PAINTBRUSHES); + Display_cursor(); +} \ No newline at end of file diff --git a/buttons.h b/buttons.h index 4e109c83..8376dcc5 100644 --- a/buttons.h +++ b/buttons.h @@ -651,5 +651,7 @@ void Button_Smooth_menu(void); */ void Button_Smear_mode(void); +void Button_Brush_container(void); + #endif diff --git a/const.h b/const.h index 82b07cd8..9b3b1596 100644 --- a/const.h +++ b/const.h @@ -65,6 +65,11 @@ /// Character to display in menus for an ellipsis. #define ELLIPSIS_CHARACTER '…' +#define BRUSH_CONTAINER_PREVIEW_WIDTH 16 ///< Size for preview of a brush in Brush container +#define BRUSH_CONTAINER_PREVIEW_HEIGHT 16 ///< Size for preview of a brush in Brush container +#define BRUSH_CONTAINER_COLUMNS 4 ///< Number of columns in the Brush container +#define BRUSH_CONTAINER_ROWS 3 ///< Number of rows in the Brush container + /// /// We force the dynamic backup page allocation to leave a minimum of /// 256Kb of free memory, to allow the rest of the program to work safely. @@ -210,7 +215,8 @@ enum PAINTBRUSH_SHAPES PAINTBRUSH_SHAPE_MISC, ///< A raw monochrome bitmap, can't be resized. This must be the last of the preset paintbrush types. PAINTBRUSH_SHAPE_POINT, ///< Used to reduce the paintbrush to a single pixel, during operations like colorpicker. PAINTBRUSH_SHAPE_COLOR_BRUSH, ///< User's brush, in color mode - PAINTBRUSH_SHAPE_MONO_BRUSH ///< User's brush, in mono mode + PAINTBRUSH_SHAPE_MONO_BRUSH, ///< User's brush, in mono mode + PAINTBRUSH_SHAPE_MAX ///< Upper limit. }; /// Normal resting state for a menu button. diff --git a/global.h b/global.h index 4044ae73..92395130 100644 --- a/global.h +++ b/global.h @@ -830,6 +830,8 @@ GFX2_GLOBAL short Colorpicker_X; /// Position of the colorpicker tool, in image coordinates. GFX2_GLOBAL short Colorpicker_Y; +/// Brush container +GFX2_GLOBAL T_Brush_template Brush_container[BRUSH_CONTAINER_COLUMNS*BRUSH_CONTAINER_ROWS]; #ifdef GLOBAL_VARIABLES byte CURSOR_FOR_OPERATION[NB_OPERATIONS]= diff --git a/init.c b/init.c index c8f8bf4d..1aa4b496 100644 --- a/init.c +++ b/init.c @@ -1063,7 +1063,7 @@ void Init_buttons(void) 106,18, 16,16, BUTTON_SHAPE_RECTANGLE, - Button_Brush_FX,Button_Brush_FX, + Button_Brush_FX,Button_Brush_container, Do_nothing, FAMILY_INSTANT); @@ -2446,3 +2446,23 @@ void Init_sighandler(void) #endif } +void Init_brush_container(void) +{ + int i; + + for (i=0; i