diff --git a/brush.c b/brush.c index a9d7ce16..54d0f323 100644 --- a/brush.c +++ b/brush.c @@ -123,7 +123,8 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) int position; byte * temp; - if (!(is_preview && Mouse_K)) // Si bouton enfoncé & preview > pas de dessin + if (is_preview==0 || Mouse_K==0) // pas de curseur si on est en preview et + // en train de cliquer switch (Paintbrush_shape) { case PAINTBRUSH_SHAPE_POINT : // !!! TOUJOURS EN PREVIEW !!! @@ -151,7 +152,7 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) end_counter_x=start_x_counter+width; end_counter_y=start_y_counter+height; - if (is_preview) + if (is_preview != 0) { if ( (width>0) && (height>0) ) Display_brush_color( @@ -165,7 +166,7 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) Brush_width ); - if (Main_magnifier_mode) + if (Main_magnifier_mode != 0) { Compute_clipped_dimensions_zoom(&start_x,&start_y,&width, &height @@ -196,9 +197,9 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) } else { - if ((Smear_mode) && (Shade_table==Shade_table_left)) + if ((Smear_mode != 0) && (Shade_table==Shade_table_left)) { - if (Smear_start) + if (Smear_start != 0) { if ((width>0) && (height>0)) { @@ -275,7 +276,7 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) start_y_counter=start_y-(y-Brush_offset_Y); end_counter_x=start_x_counter+width; end_counter_y=start_y_counter+height; - if (is_preview) + if (is_preview != 0) { if ( (width>0) && (height>0) ) Display_brush_mono(start_x-Main_offset_X, @@ -285,7 +286,7 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) Back_color,Fore_color, Brush_width); - if (Main_magnifier_mode) + if (Main_magnifier_mode != 0) { Compute_clipped_dimensions_zoom(&start_x,&start_y,&width,&height); start_x_counter=start_x-(x-Brush_offset_X); @@ -314,9 +315,9 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) } else { - if ((Smear_mode) && (Shade_table==Shade_table_left)) + if ((Smear_mode != 0) && (Shade_table==Shade_table_left)) { - if (Smear_start) + if (Smear_start != 0) { if ((width>0) && (height>0)) { @@ -377,7 +378,7 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) start_y_counter=start_y-(y-Paintbrush_offset_Y); end_counter_x=start_x_counter+width; end_counter_y=start_y_counter+height; - if (is_preview) + if (is_preview != 0) { temp=Brush; Brush=Paintbrush_sprite; @@ -390,7 +391,7 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) 0,Fore_color, MAX_PAINTBRUSH_SIZE); - if (Main_magnifier_mode) + if (Main_magnifier_mode != 0) { Compute_clipped_dimensions_zoom(&start_x,&start_y,&width,&height); start_x_counter=start_x-(x-Paintbrush_offset_X); @@ -419,9 +420,9 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) } else { - if ((Smear_mode) && (Shade_table==Shade_table_left)) + if ((Smear_mode != 0) && (Shade_table==Shade_table_left)) { - if (Smear_start) + if (Smear_start != 0) { if ((width>0) && (height>0)) { @@ -444,10 +445,13 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) { temp_color=Read_pixel_from_current_screen(x_pos,y_pos); position=(counter_y*Smear_brush_width)+counter_x; - if ( (Paintbrush_sprite[(MAX_PAINTBRUSH_SIZE*counter_y)+counter_x]) // Le pinceau sert de masque pour dire quels pixels on doit traiter dans le rectangle - && (counter_y=Smear_min_Y) && (counter_x>=Smear_min_X) ) - Display_pixel(x_pos,y_pos,Smear_brush[position]); + 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 + && (counter_y=Smear_min_Y) && (counter_x>=Smear_min_X) + // On clippe l'effet smear entre Smear_Min et Smear_Max + ) + Display_pixel(x_pos,y_pos,Smear_brush[position]); Smear_brush[position]=temp_color; } Update_part_of_screen(start_x, start_y, width, height); @@ -464,7 +468,7 @@ void Display_paintbrush(short x,short y,byte color,byte is_preview) for (y_pos=start_y,counter_y=start_y_counter;counter_yMAX_PAINTBRUSH_SIZE)?Brush_height:MAX_PAINTBRUSH_SIZE; Smear_brush=(byte *)malloc(((long)Smear_brush_height)*Smear_brush_width); - if (!Smear_brush) // On ne peut même pas allouer la brosse du smear! + 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; } @@ -690,7 +709,7 @@ void Capture_brush(short start_x,short start_y,short end_x,short end_y,short cle Copy_image_to_brush(start_x,start_y,Brush_width,Brush_height,Main_image_width); // On regarde s'il faut effacer quelque chose: - if (clear) + if (clear != 0) { for (y_pos=start_y;y_pos0) Pixel_in_brush(x_pos-1,y_pos,Back_color); @@ -955,7 +964,7 @@ void Nibble_brush(void) } else { - if (!state) + if (state == 0) { Pixel_in_brush(x_pos,y_pos,Back_color); state=1; @@ -984,7 +993,7 @@ void Nibble_brush(void) } else { - if (!state) + if (state == 0) { Pixel_in_brush(x_pos,y_pos,Back_color); state=1; @@ -1021,7 +1030,7 @@ void Capture_brush_with_lasso(int vertices, short * points,short clear) short start_y=Limit_bottom+1; short end_x=Limit_left-1; short end_y=Limit_top-1; - short temp; + unsigned short temp; short x_pos; short y_pos; word new_brush_width; @@ -1029,10 +1038,10 @@ void Capture_brush_with_lasso(int vertices, short * points,short clear) // On recherche les bornes de la brosse: - for (temp=0; tempend_x) @@ -1079,6 +1088,7 @@ void Capture_brush_with_lasso(int vertices, short * points,short clear) Error(0); Brush=(byte *)malloc(1*1); + if(Brush==NULL) Error(ERROR_MEMORY); new_brush_height=new_brush_width=1; *Brush=Fore_color; } @@ -1097,6 +1107,7 @@ void Capture_brush_with_lasso(int vertices, short * points,short clear) free(Brush); Brush=(byte *)malloc(1*1); + if(Brush==NULL) Error(ERROR_MEMORY); Brush_height=1; Brush_width=1; diff --git a/engine.h b/engine.h index b3547cc3..e3de8d0f 100644 --- a/engine.h +++ b/engine.h @@ -1,84 +1,94 @@ -/* Grafx2 - The Ultimate 256-color bitmap paint program - - Copyright 2007 Adrien Destugues - Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) - - Grafx2 is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; version 2 - of the License. - - Grafx2 is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Grafx2; if not, see -*/ - -////////////////////////////////////////////////////////////////////////////// -///@file engine.h -/// Utility functions for the menu and all windows. -////////////////////////////////////////////////////////////////////////////// - -void Main_handler (void); -void Draw_menu_button_frame(byte btn_number,byte pressed); -void Unselect_button (int btn_number); -void Select_button (int btn_number,byte click); -void Open_window (word width,word height, char * title); -void Close_window (void); - -void Open_popup (word x_pos, word y_pos, word width, word height); -void Close_popup (void); - -void Window_draw_normal_bouton(word x_pos,word y_pos,word width,word height, - char * title,byte undersc_letter,byte clickable); -void Window_select_normal_button(word x_pos,word y_pos,word width,word height); -void Window_unselect_normal_button(word x_pos,word y_pos,word width,word height); -void Window_draw_palette_bouton(word x_pos,word y_pos); - -void Compute_slider_cursor_height(T_Scroller_button * button); -void Window_draw_slider(T_Scroller_button * button); -void Window_draw_scroller_bouton(T_Scroller_button * button); - -void Window_input_content(T_Special_button * button, char * content); -void Window_clear_input_button(T_Special_button * button); -void Window_draw_input_bouton(word x_pos,word y_pos,word width_in_characters); - -T_Normal_button * Window_set_normal_button(word x_pos, word y_pos, - word width, word height, - char * title,byte undersc_letter, - byte clickable, word shortcut); -#define GGUI_set_normal_button(x_pos,y_pos,width,height,title,undersc_letter,clickable,shortcut,NAME) \ - const short NAME = Window_set_normal_button((x_pos),(y_pos),(width),(height),(title),(undersc_letter),(clickable),(shortcut))->Number; -T_Normal_button * Window_set_repeatable_button(word x_pos, word y_pos, - word width, word height, - char * title,byte undersc_letter, - byte clickable, word shortcut); - -T_Palette_button * Window_set_palette_button(word x_pos, word y_pos); -void Window_clear_tags(void); -void Tag_color_range(byte start,byte end); - -T_Scroller_button * Window_set_scroller_button(word x_pos, word y_pos, - word height, - word nb_elements, - word nb_elements_visible, - word initial_position); -T_Special_button * Window_set_special_button(word x_pos,word y_pos,word width,word height); -T_Special_button * Window_set_input_button(word x_pos,word y_pos,word width_in_characters); -T_Dropdown_button * Window_set_dropdown_button(word x_pos,word y_pos,word width,word height,word dropdown_width,const char *label,byte display_choice,byte display_centered,byte display_arrow,byte active_button); -void Window_dropdown_add_item(T_Dropdown_button * dropdown, word btn_number, const char *label); -void Window_dropdown_clear_items(T_Dropdown_button * dropdown); -T_List_button * Window_set_list_button(T_Special_button * entry_button, T_Scroller_button * scroller, Func_draw_list_item draw_list_item); -void Window_redraw_list(T_List_button * list); -byte Window_click_in_rectangle(short start_x,short start_y,short end_x,short end_y); -short Wait_click_in_palette(T_Palette_button * button); -void Get_color_behind_window(byte * color, byte * click); - -short Window_clicked_button(void); -int Button_under_mouse(void); -short Window_get_clicked_button(void); -void Remap_window_backgrounds(byte * conversion_table, int Min_Y, int Max_Y); -void Pixel_background(int x_pos, int y_pos, byte color); +/* Grafx2 - The Ultimate 256-color bitmap paint program + + Copyright 2007 Adrien Destugues + Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) + + Grafx2 is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; version 2 + of the License. + + Grafx2 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grafx2; if not, see +*/ + +////////////////////////////////////////////////////////////////////////////// +///@file engine.h +/// Utility functions for the menu and all windows. +////////////////////////////////////////////////////////////////////////////// + +#ifndef __ENGINE_H__ +#define __ENGINE_H__ + +#include "struct.h" + +void Main_handler (void); +void Draw_menu_button_frame(byte btn_number,byte pressed); +void Unselect_button (int btn_number); +void Select_button (int btn_number,byte click); +void Open_window (word width,word height, char * title); +void Close_window (void); + +void Open_popup (word x_pos, word y_pos, word width, word height); +void Close_popup (void); + +void Window_draw_normal_bouton(word x_pos,word y_pos,word width,word height, + char * title,byte undersc_letter,byte clickable); +void Window_select_normal_button(word x_pos,word y_pos,word width,word height); +void Window_unselect_normal_button(word x_pos,word y_pos,word width,word height); +void Window_draw_palette_bouton(word x_pos,word y_pos); + +void Compute_slider_cursor_height(T_Scroller_button * button); +void Window_draw_slider(T_Scroller_button * button); +void Window_draw_scroller_bouton(T_Scroller_button * button); + +void Window_input_content(T_Special_button * button, char * content); +void Window_clear_input_button(T_Special_button * button); +void Window_draw_input_bouton(word x_pos,word y_pos,word width_in_characters); + +T_Normal_button * Window_set_normal_button(word x_pos, word y_pos, + word width, word height, + char * title,byte undersc_letter, + byte clickable, word shortcut); +T_Normal_button * Window_set_repeatable_button(word x_pos, word y_pos, + word width, word height, + char * title,byte undersc_letter, + byte clickable, word shortcut); + +T_Palette_button * Window_set_palette_button(word x_pos, word y_pos); +void Window_clear_tags(void); +void Tag_color_range(byte start,byte end); + +T_Scroller_button * Window_set_scroller_button(word x_pos, word y_pos, + word height, word nb_elements, word nb_elements_visible, + word initial_position); +T_Special_button * Window_set_special_button(word x_pos,word y_pos,word width, + word height); +T_Special_button * Window_set_input_button(word x_pos,word y_pos, + word width_in_characters); +T_Dropdown_button * Window_set_dropdown_button(word x_pos,word y_pos,word width, + word height,word dropdown_width,const char *label,byte display_choice, + byte display_centered,byte display_arrow,byte active_button); +void Window_dropdown_add_item(T_Dropdown_button * dropdown, word btn_number, + const char *label); +void Window_dropdown_clear_items(T_Dropdown_button * dropdown); +T_List_button * Window_set_list_button(T_Special_button * entry_button, + T_Scroller_button * scroller, Func_draw_list_item draw_list_item); +void Window_redraw_list(T_List_button * list); +byte Window_click_in_rectangle(short start_x,short start_y,short end_x, + short end_y); +short Wait_click_in_palette(T_Palette_button * button); +void Get_color_behind_window(byte * color, byte * click); + +short Window_clicked_button(void); +int Button_under_mouse(void); +short Window_get_clicked_button(void); +void Remap_window_backgrounds(byte * conversion_table, int Min_Y, int Max_Y); +void Pixel_background(int x_pos, int y_pos, byte color); + +#endif diff --git a/filesel.h b/filesel.h index 1cbd2432..febe5e36 100644 --- a/filesel.h +++ b/filesel.h @@ -21,6 +21,10 @@ ///@file filesel.h /// Fileselector window, used for loading and saving images and brushes. ////////////////////////////////////////////////////////////////////////////// +#ifndef __FILESEL_H__ +#define __FILESEL_H__ + +#include "struct.h" byte Button_Load_or_Save(byte load, byte image); @@ -40,3 +44,5 @@ void Recount_files(T_Fileselector *list); T_Fileselector_item * Get_item_by_index(T_Fileselector *list, short index); short Find_file_in_fileselector(T_Fileselector *list, char * fname); + +#endif diff --git a/gfx2.cfg b/gfx2.cfg index eeea8c6a..5154c5a9 100644 Binary files a/gfx2.cfg and b/gfx2.cfg differ