mirror of https://github.com/aseprite/aseprite.git
				
				
				
			Fixed problems with the brush-cursor drawing code.
This commit is contained in:
		
							parent
							
								
									8cc8d732e2
								
							
						
					
					
						commit
						dfae80457b
					
				|  | @ -1,3 +1,9 @@ | |||
| 2008-01-13  David A. Capello  <dacap@users.sourceforge.net> | ||||
| 
 | ||||
| 	* src/widgets/editor/cursor.c, src/widgets/editor/editor.c: Fixed | ||||
| 	a lot of bugs in the code that draws/cleans the brush-cursor in | ||||
| 	the editor. | ||||
| 
 | ||||
| 2008-01-06  David A. Capello  <dacap@users.sourceforge.net> | ||||
| 
 | ||||
| 	* src/jinete/jwidget.c (jwidget_free_deferred): Added. | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| # allegro-sprite-editor convolution matrices		-*- Shell-script -*- | ||||
| # Copyright (C) 2001-2005 by David A. Capello | ||||
| # Copyright (C) 2001-2005, 2008 by David A. Capello | ||||
| # | ||||
| # Loader in "plug-ins/action/convmatr.c". | ||||
| # | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| # Allegro Sprite Editor tips | ||||
| # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007  David A. Capello | ||||
| # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008  David A. Capello | ||||
| 
 | ||||
|  ********************************************************************** | ||||
| \palette ase.pcx | ||||
|  | @ -47,6 +47,8 @@ Right = go to next frame | |||
| 
 | ||||
| Up = go to last frame | ||||
| \done | ||||
| 
 | ||||
| Enter = play animation | ||||
|  ********************************************************************** | ||||
| You can add new animation frames pressing <Ctrl+Shift+N> or using | ||||
| "Frame/New" menu. | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| # Copyright (C) 2001-2005, 2007 by David A. Capello		-*-Makefile-*- | ||||
| # Copyright (C) 2001-2005, 2007, 2008 by David A. Capello		-*-Makefile-*- | ||||
| 
 | ||||
| .PHONY = _default | ||||
| _default: default | ||||
|  | @ -190,9 +190,13 @@ endif | |||
| 
 | ||||
| TESTS = $(addsuffix $(EXE),						\ | ||||
| 		$(basename						\ | ||||
| 			$(wildcard src/test/convmatr/*.c)		\ | ||||
| 			$(wildcard src/test/raster/*.c)			\ | ||||
| 			$(wildcard src/test/jinete/*.c))) | ||||
| 
 | ||||
| src/test/convmatr/%$(EXE): src/test/convmatr/%.c $(COMMON_OBJS) | ||||
| 	$(CC) $(CFLAGS) -o $@ $^ $(LFLAGS) $(LFLAGS_LAST) | ||||
| 
 | ||||
| src/test/raster/%$(EXE): src/test/raster/%.c $(COMMON_OBJS) | ||||
| 	$(CC) $(CFLAGS) -o $@ $^ $(LFLAGS) $(LFLAGS_LAST) | ||||
| 
 | ||||
|  |  | |||
|  | @ -545,6 +545,9 @@ bool jmanager_generate_messages(JWidget manager) | |||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /* generate redraw events */ | ||||
|   jwidget_flush_redraw(manager); | ||||
| 
 | ||||
|   return !jlist_empty(msg_queue); | ||||
| } | ||||
| 
 | ||||
|  | @ -552,9 +555,6 @@ void jmanager_dispatch_messages(JWidget manager) | |||
| { | ||||
|   JMessage msg; | ||||
|    | ||||
|   /* redraw dirty widgets */ | ||||
|   jwidget_flush_redraw(manager); | ||||
|    | ||||
|   /* add the "Queue Processing" message for the manager */ | ||||
|   msg = new_mouse_msg(JM_QUEUEPROCESSING); | ||||
|   jmessage_add_dest(msg, manager); | ||||
|  | @ -1122,13 +1122,14 @@ static void dispatch_messages(JWidget widget_manager) | |||
| 
 | ||||
|   link = jlist_first(msg_queue); | ||||
|   while (link != msg_queue->end) { | ||||
|     msg = link->data; | ||||
| 
 | ||||
| #ifdef LIMIT_DISPATCH_TIME | ||||
|     if (ji_clock-t > 250) | ||||
|       break; | ||||
| #endif | ||||
| 
 | ||||
|     /* the message to process */ | ||||
|     msg = link->data; | ||||
| 
 | ||||
|     /* go to next message */ | ||||
|     if (msg->any.used) { | ||||
|       link = link->next; | ||||
|  |  | |||
|  | @ -1409,6 +1409,10 @@ void jwidget_close_window(JWidget widget) | |||
|     jwindow_close(window, widget); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * Captures the mouse to send the future JM_BUTTONRELEASED messsage to | ||||
|  * the specified widget. | ||||
|  */ | ||||
| void jwidget_capture_mouse(JWidget widget) | ||||
| { | ||||
|   assert_valid_widget(widget); | ||||
|  | @ -1421,6 +1425,10 @@ void jwidget_capture_mouse(JWidget widget) | |||
|   } | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * Captures the mouse to send all the future mouse messsages to the | ||||
|  * specified widget. | ||||
|  */ | ||||
| void jwidget_hard_capture_mouse(JWidget widget) | ||||
| { | ||||
|   assert_valid_widget(widget); | ||||
|  | @ -1436,6 +1444,9 @@ void jwidget_hard_capture_mouse(JWidget widget) | |||
|   } | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * Releases the capture of the mouse events. | ||||
|  */ | ||||
| void jwidget_release_mouse(JWidget widget) | ||||
| { | ||||
|   assert_valid_widget(widget); | ||||
|  |  | |||
|  | @ -616,10 +616,15 @@ static void move_window(JWidget widget, JRect rect, bool use_blit) | |||
|   JRegion new_drawable_region; | ||||
|   JRegion manager_refresh_region; | ||||
|   JRegion window_refresh_region; | ||||
|   JRect old_pos = jrect_new_copy(widget->rc); | ||||
|   JRect man_pos = jwidget_get_rect(jwidget_get_manager(widget)); | ||||
|   JRect old_pos; | ||||
|   JRect man_pos; | ||||
|   JMessage msg; | ||||
| 
 | ||||
|   jmanager_dispatch_messages(ji_get_default_manager()); | ||||
| 
 | ||||
|   old_pos = jrect_new_copy(widget->rc); | ||||
|   man_pos = jwidget_get_rect(jwidget_get_manager(widget)); | ||||
|    | ||||
|   msg = jmessage_new(JM_WINMOVE); | ||||
|   jmessage_broadcast_to_children(msg, widget); | ||||
|   jmanager_enqueue_message(msg); | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /* ASE - Allegro Sprite Editor
 | ||||
|  * Copyright (C) 2001-2005, 2007  David A. Capello | ||||
|  * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008  David A. Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  |  | |||
|  | @ -56,7 +56,6 @@ | |||
| 
 | ||||
| #define REBUILD_LOCK		1 | ||||
| #define REBUILD_ROOT_MENU	2 | ||||
| #define REBUILD_SPRITE_LIST	4 | ||||
| #define REBUILD_RECENT_LIST	8 | ||||
| #define REBUILD_FULLREFRESH	16 | ||||
| 
 | ||||
|  | @ -78,6 +77,7 @@ static int try_depths[] = { 32, 24, 16, 15, 8 }; | |||
| /**************************************************************/ | ||||
| 
 | ||||
| static JWidget manager = NULL; | ||||
| static bool ji_screen_created = FALSE; | ||||
| 
 | ||||
| static volatile int next_idle_flags = 0; | ||||
| static JList icon_buttons; | ||||
|  | @ -258,8 +258,10 @@ void exit_module_gui(void) | |||
|   if (double_buffering) { | ||||
|     BITMAP *old_bmp = ji_screen; | ||||
|     ji_set_screen(screen); | ||||
|     if (old_bmp && old_bmp != screen) | ||||
| 
 | ||||
|     if (ji_screen_created) | ||||
|       destroy_bitmap(old_bmp); | ||||
|     ji_screen_created = FALSE; | ||||
|   } | ||||
| 
 | ||||
|   jlist_free(icon_buttons); | ||||
|  | @ -344,15 +346,9 @@ void gui_feedback(void) | |||
|       next_idle_flags ^= REBUILD_ROOT_MENU; | ||||
|       load_root_menu(); | ||||
| 
 | ||||
|       next_idle_flags |= REBUILD_SPRITE_LIST; | ||||
|       next_idle_flags |= REBUILD_RECENT_LIST; | ||||
|     } | ||||
| 
 | ||||
|     if (next_idle_flags & REBUILD_SPRITE_LIST) { | ||||
|       next_idle_flags ^= REBUILD_SPRITE_LIST; | ||||
|       app_realloc_sprite_list(); | ||||
|     } | ||||
| 
 | ||||
|     if (next_idle_flags & REBUILD_RECENT_LIST) { | ||||
|       next_idle_flags ^= REBUILD_RECENT_LIST; | ||||
|       app_realloc_recent_list(); | ||||
|  | @ -403,11 +399,14 @@ void gui_setup_screen(void) | |||
|     BITMAP *old_bmp = ji_screen; | ||||
|     ji_set_screen(create_bitmap(SCREEN_W / screen_scaling, | ||||
| 				SCREEN_H / screen_scaling)); | ||||
|     if (old_bmp && old_bmp != screen) | ||||
|     if (ji_screen_created) | ||||
|       destroy_bitmap(old_bmp); | ||||
| 
 | ||||
|     ji_screen_created = TRUE; | ||||
|   } | ||||
|   else { | ||||
|     ji_set_screen(screen); | ||||
|     ji_screen_created = FALSE; | ||||
|   } | ||||
| 
 | ||||
|   /* set the configuration */ | ||||
|  | @ -435,7 +434,7 @@ void reload_default_font(void) | |||
|     dirs_add_path(dirs, default_font); | ||||
| 
 | ||||
|   /* big font */ | ||||
| /*   if (JI_SCREEN_W > 320) */ | ||||
| /*   if (JI_SCREEN_W > 400) */ | ||||
| /*     dirs_cat_dirs(dirs, filename_in_datadir("fonts/default2.pcx")); */ | ||||
| /*   /\* tiny font *\/ */ | ||||
| /*   else */ | ||||
|  | @ -546,7 +545,7 @@ void rebuild_root_menu(void) | |||
| 
 | ||||
| void rebuild_sprite_list(void) | ||||
| { | ||||
|   next_idle_flags |= REBUILD_SPRITE_LIST; | ||||
|   app_realloc_sprite_list();       | ||||
| } | ||||
| 
 | ||||
| void rebuild_recent_list(void) | ||||
|  | @ -554,8 +553,6 @@ void rebuild_recent_list(void) | |||
|   next_idle_flags |= REBUILD_RECENT_LIST; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| 
 | ||||
| /**********************************************************************/ | ||||
| /* hook signals */ | ||||
| 
 | ||||
|  | @ -645,7 +642,6 @@ bool get_widgets(JWidget window, ...) | |||
|   return TRUE; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| /**********************************************************************/ | ||||
| /* Icon in buttons */ | ||||
| 
 | ||||
|  | @ -683,7 +679,6 @@ static bool button_with_icon_msg_proc(JWidget widget, JMessage msg) | |||
|   return FALSE; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| /**********************************************************************/ | ||||
| /* Button style (convert radio or check buttons and draw it like
 | ||||
|    normal buttons) */ | ||||
|  | @ -707,65 +702,6 @@ JWidget check_button_new(const char *text, int b1, int b2, int b3, int b4) | |||
|   return widget; | ||||
| } | ||||
| 
 | ||||
| #if 0 | ||||
| static int button_style_type(void) | ||||
| { | ||||
|   static int type = 0; | ||||
|   if (!type) | ||||
|     type = ji_register_widget_type(); | ||||
|   return type; | ||||
| } | ||||
| 
 | ||||
| static bool button_style_msg_proc(JWidget widget, JMessage msg) | ||||
| { | ||||
|   JHook hook = (JHook)jwidget_get_data(widget, button_style_type()); | ||||
| 
 | ||||
|   switch (msg->type) { | ||||
| 
 | ||||
|     case JM_DESTROY: | ||||
|       (*hook->msg_proc)(widget, msg); | ||||
|       jfree(hook); | ||||
|       break; | ||||
| 
 | ||||
|     case JM_REQSIZE: | ||||
|       return (*hook->msg_proc)(widget, msg); | ||||
|   } | ||||
| 
 | ||||
|   return FALSE; | ||||
| } | ||||
| 
 | ||||
| void change_to_button_style(JWidget widget, int b1, int b2, int b3, int b4) | ||||
| { | ||||
|   JWidget button = jbutton_new(NULL); | ||||
|   JHook hook = jwidget_get_hook(button, JI_BUTTON); | ||||
| 
 | ||||
|   /* setup button bevel */ | ||||
|   jbutton_set_bevel(button, b1, b2, b3, b4); | ||||
| 
 | ||||
|   /* steal JI_BUTTON hook */ | ||||
|   _jwidget_remove_hook(button, hook); | ||||
| 
 | ||||
|   /* put the JI_BUTTON hook data in the widget (to get it with
 | ||||
|      jwidget_get_data) */ | ||||
|   jwidget_add_hook(widget, JI_BUTTON, NULL, hook->data); | ||||
| 
 | ||||
|   /* put a cusomized hook to filter only some messages to the real
 | ||||
|      JI_BUTTON hook msg_proc */ | ||||
|   jwidget_add_hook(widget, button_style_type(), button_style_msg_proc, hook); | ||||
| 
 | ||||
|   /* setup widget geometry */ | ||||
|   widget->align = button->align; | ||||
|   widget->border_width = button->border_width; | ||||
|   widget->draw_method = button->draw_method; | ||||
| 
 | ||||
|   /* jwidget_set_border(widget, 2, 2, 2, 2); */ | ||||
| 
 | ||||
|   /* the data will be free after */ | ||||
|   jwidget_free(button); | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
|  | ||||
| /**********************************************************************/ | ||||
| /* manager event handler */ | ||||
| 
 | ||||
|  | @ -820,7 +756,7 @@ static bool manager_msg_proc(JWidget widget, JMessage msg) | |||
| 
 | ||||
|   return FALSE; | ||||
| } | ||||
|  | ||||
| 
 | ||||
| /**********************************************************************/ | ||||
| /* graphics */ | ||||
| 
 | ||||
|  |  | |||
|  | @ -291,7 +291,7 @@ int get_thickness_for_cursor(void) | |||
|   else | ||||
|     return brush->size; | ||||
| } | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* MARKER                                                  */ | ||||
| /***********************************************************/ | ||||
|  | @ -307,7 +307,7 @@ Tool ase_tool_marker = | |||
|   TOOL_FIRST2LAST | TOOL_UPDATE_BOX, | ||||
|   NULL | ||||
| }; | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* DOTS                                                    */ | ||||
| /***********************************************************/ | ||||
|  | @ -328,7 +328,7 @@ Tool ase_tool_dots = | |||
|   TOOL_ACCUMULATE_DIRTY | TOOL_OLD2LAST | TOOL_UPDATE_POINT, | ||||
|   tool_dots_put | ||||
| }; | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* PENCIL                                                  */ | ||||
| /***********************************************************/ | ||||
|  | @ -349,7 +349,7 @@ Tool ase_tool_pencil = | |||
|   TOOL_ACCUMULATE_DIRTY | TOOL_OLD2LAST | TOOL_UPDATE_TRACE, | ||||
|   tool_pencil_put | ||||
| }; | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* BRUSH                                                   */ | ||||
| /***********************************************************/ | ||||
|  | @ -365,7 +365,7 @@ Tool ase_tool_brush = | |||
|   TOOL_ACCUMULATE_DIRTY | TOOL_FOURCHAIN | TOOL_UPDATE_LAST4, | ||||
|   NULL | ||||
| }; | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* FLOODFILL                                               */ | ||||
| /***********************************************************/ | ||||
|  | @ -399,7 +399,7 @@ Tool ase_tool_floodfill = | |||
|   TOOL_ACCUMULATE_DIRTY | TOOL_OLD2LAST | TOOL_UPDATE_ALL, | ||||
|   tool_floodfill_put | ||||
| }; | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* SPRAY                                                   */ | ||||
| /***********************************************************/ | ||||
|  | @ -463,7 +463,7 @@ Tool ase_tool_line = | |||
|   TOOL_FIRST2LAST | TOOL_UPDATE_BOX | TOOL_EIGHT_ANGLES, | ||||
|   tool_line_put | ||||
| }; | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* RECTANGLE                                               */ | ||||
| /***********************************************************/ | ||||
|  | @ -542,7 +542,7 @@ Tool ase_tool_rectangle = | |||
|   TOOL_FIRST2LAST | TOOL_UPDATE_BOX | TOOL_ACCEPT_FILL, | ||||
|   tool_rectangle_put | ||||
| }; | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* ELLIPSE                                                 */ | ||||
| /***********************************************************/ | ||||
|  | @ -587,7 +587,7 @@ Tool ase_tool_ellipse = | |||
|   TOOL_FIRST2LAST | TOOL_UPDATE_BOX | TOOL_ACCEPT_FILL, | ||||
|   tool_ellipse_put | ||||
| }; | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* TOOL'S LIST                                             */ | ||||
| /***********************************************************/ | ||||
|  | @ -605,7 +605,7 @@ Tool *ase_tools_list[] = | |||
|   &ase_tool_ellipse, | ||||
|   NULL | ||||
| }; | ||||
|  | ||||
| 
 | ||||
| /***********************************************************/ | ||||
| /* TOOL CONTROL                                            */ | ||||
| /***********************************************************/ | ||||
|  | @ -642,7 +642,7 @@ static void marker_scroll_callback(int before_change) | |||
|     rect_data = NULL; | ||||
|   } | ||||
| } | ||||
|  | ||||
| 
 | ||||
| /* controls any tool to draw in the current sprite */ | ||||
| void control_tool(JWidget widget, Tool *tool, const char *_color) | ||||
| { | ||||
|  | @ -1304,7 +1304,7 @@ static void fourchain_line(int x1, int y1, int x2, int y2, void *data) | |||
|   else | ||||
|     dirty_line_brush(data, brush, x1, y1, x2, y2); | ||||
| } | ||||
|  | ||||
| 
 | ||||
| /**********************************************************************/ | ||||
| /* Opaque draw mode						      */ | ||||
| /**********************************************************************/ | ||||
|  | @ -1333,7 +1333,7 @@ static void my_image_hline1_opaque(int x1, int y, int x2, void *data) | |||
| { | ||||
|   memset(((ase_uint8 **)tool_image->line)[y]+x1, tool_color, x2-x1+1); | ||||
| } | ||||
|  | ||||
| 
 | ||||
| /**********************************************************************/ | ||||
| /* Glass draw mode						      */ | ||||
| /**********************************************************************/ | ||||
|  | @ -1390,7 +1390,7 @@ static void my_image_hline1_glass(int x1, int y, int x2, void *data) | |||
|     address++; | ||||
|   } | ||||
| } | ||||
|  | ||||
| 
 | ||||
| /**********************************************************************/ | ||||
| /* Semi draw mode						      */ | ||||
| /**********************************************************************/ | ||||
|  |  | |||
|  | @ -42,6 +42,10 @@ typedef struct Editor | |||
|   int cursor_editor_x; /* position in the editor (model) */ | ||||
|   int cursor_editor_y; | ||||
| 
 | ||||
|   int old_cursor_thick; | ||||
|   int old_cursor_screen_x; | ||||
|   int old_cursor_screen_y; | ||||
| 
 | ||||
|   /* for the mouse */ | ||||
|   unsigned lagged_mouseenter : 1; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /* ASE - Allegro Sprite Editor
 | ||||
|  * Copyright (C) 2001-2005, 2007  David A. Capello | ||||
|  * Copyright (C) 2001-2005, 2007, 2008  David A. Capello | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  | @ -20,6 +20,7 @@ | |||
| 
 | ||||
| #ifndef USE_PRECOMPILED_HEADER | ||||
| 
 | ||||
| #include <assert.h> | ||||
| #include <allegro.h> | ||||
| 
 | ||||
| #include "jinete/jbase.h" | ||||
|  | @ -68,7 +69,8 @@ static int cursor_negative; | |||
| 
 | ||||
| static int saved_pixel[MAX_SAVED]; | ||||
| static int saved_pixel_n; | ||||
| static JRegion limit_region; | ||||
| static JRegion clipping_region; | ||||
| static JRegion old_clipping_region; | ||||
| 
 | ||||
| static void generate_cursor_boundaries(void); | ||||
| static void for_each_pixel_of_brush(Editor *editor, int x, int y, int color, void (*pixel)(BITMAP *bmp, int x, int y, int color)); | ||||
|  | @ -80,7 +82,7 @@ static void savepixel(BITMAP *bmp, int x, int y, int color); | |||
| static void drawpixel(BITMAP *bmp, int x, int y, int color); | ||||
| static void cleanpixel(BITMAP *bmp, int x, int y, int color); | ||||
| 
 | ||||
| static int point_inside_region(int x, int y); | ||||
| static int point_inside_region(int x, int y, JRegion region); | ||||
| 
 | ||||
| /**
 | ||||
|  * Draws the brush cursor inside the specified editor. | ||||
|  | @ -99,8 +101,10 @@ void editor_draw_cursor(JWidget widget, int x, int y) | |||
|   Editor *editor = editor_data(widget); | ||||
|   int color; | ||||
| 
 | ||||
|   assert(editor->cursor_thick == 0); | ||||
| 
 | ||||
|   /* get drawable region */ | ||||
|   limit_region = jwidget_get_drawable_region(widget, JI_GDR_CUTTOPWINDOWS); | ||||
|   clipping_region = jwidget_get_drawable_region(widget, JI_GDR_CUTTOPWINDOWS); | ||||
| 
 | ||||
|   /* get cursor color */ | ||||
|   cursor_negative = is_cursor_mask(); | ||||
|  | @ -136,8 +140,10 @@ void editor_draw_cursor(JWidget widget, int x, int y) | |||
| 
 | ||||
|   /* save area and draw the cursor */ | ||||
|   acquire_bitmap(ji_screen); | ||||
|   ji_screen->clip = FALSE; | ||||
|   for_each_pixel_of_brush(editor, x, y, color, savepixel); | ||||
|   for_each_pixel_of_brush(editor, x, y, color, drawpixel); | ||||
|   ji_screen->clip = TRUE; | ||||
|   release_bitmap(ji_screen); | ||||
| 
 | ||||
|   /* cursor thickness */ | ||||
|  | @ -147,8 +153,8 @@ void editor_draw_cursor(JWidget widget, int x, int y) | |||
|   editor->cursor_editor_x = x; | ||||
|   editor->cursor_editor_y = y; | ||||
| 
 | ||||
|   jregion_free(limit_region); | ||||
|   limit_region = NULL; | ||||
|   /* save the clipping-region to know where to clean the pixels */ | ||||
|   old_clipping_region = clipping_region; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -169,20 +175,26 @@ void editor_clean_cursor(JWidget widget) | |||
|   Editor *editor = editor_data(widget); | ||||
|   int x, y; | ||||
| 
 | ||||
|   limit_region = jwidget_get_drawable_region(widget, JI_GDR_CUTTOPWINDOWS); | ||||
|   assert(editor->cursor_thick != 0); | ||||
| 
 | ||||
|   clipping_region = jwidget_get_drawable_region(widget, JI_GDR_CUTTOPWINDOWS); | ||||
| 
 | ||||
|   x = editor->cursor_editor_x; | ||||
|   y = editor->cursor_editor_y; | ||||
| 
 | ||||
|   /* restore points */ | ||||
|   acquire_bitmap(ji_screen); | ||||
|   ji_screen->clip = FALSE; | ||||
|   for_each_pixel_of_brush(editor, x, y, 0, cleanpixel); | ||||
|   ji_screen->clip = TRUE; | ||||
|   release_bitmap(ji_screen); | ||||
| 
 | ||||
|   editor->cursor_thick = 0; | ||||
| 
 | ||||
|   jregion_free(limit_region); | ||||
|   limit_region = NULL; | ||||
|   jregion_free(clipping_region); | ||||
|   jregion_free(old_clipping_region); | ||||
|   clipping_region = NULL; | ||||
|   old_clipping_region = NULL; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -320,13 +332,13 @@ static void editor_cursor_brush(Editor *editor, int x, int y, int color, void (* | |||
| 
 | ||||
| static void savepixel(BITMAP *bmp, int x, int y, int color) | ||||
| { | ||||
|   if (saved_pixel_n < MAX_SAVED && point_inside_region(x, y)) | ||||
|   if (saved_pixel_n < MAX_SAVED && point_inside_region(x, y, clipping_region)) | ||||
|     saved_pixel[saved_pixel_n++] = getpixel(bmp, x, y); | ||||
| } | ||||
| 
 | ||||
| static void drawpixel(BITMAP *bmp, int x, int y, int color) | ||||
| { | ||||
|   if (saved_pixel_n < MAX_SAVED && point_inside_region(x, y)) { | ||||
|   if (saved_pixel_n < MAX_SAVED && point_inside_region(x, y, clipping_region)) { | ||||
|     if (cursor_negative) { | ||||
|       int r, g, b, c = saved_pixel[saved_pixel_n++]; | ||||
| 
 | ||||
|  | @ -344,12 +356,16 @@ static void drawpixel(BITMAP *bmp, int x, int y, int color) | |||
| 
 | ||||
| static void cleanpixel(BITMAP *bmp, int x, int y, int color) | ||||
| { | ||||
|   if (saved_pixel_n < MAX_SAVED && point_inside_region(x, y)) | ||||
|   if (saved_pixel_n < MAX_SAVED) { | ||||
|     if (point_inside_region(x, y, clipping_region)) | ||||
|       putpixel(bmp, x, y, saved_pixel[saved_pixel_n++]); | ||||
|     else if (point_inside_region(x, y, old_clipping_region)) | ||||
|       saved_pixel[saved_pixel_n++]; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| static int point_inside_region(int x, int y) | ||||
| static int point_inside_region(int x, int y, JRegion region) | ||||
| { | ||||
|   struct jrect box; | ||||
|   return jregion_point_in(limit_region, x, y, &box); | ||||
|   return jregion_point_in(region, x, y, &box); | ||||
| } | ||||
|  |  | |||
|  | @ -23,6 +23,7 @@ | |||
| 
 | ||||
| #ifndef USE_PRECOMPILED_HEADER | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| #include <allegro.h> | ||||
| 
 | ||||
| #include "jinete/jdraw.h" | ||||
|  | @ -103,6 +104,9 @@ JWidget editor_new(void) | |||
|   editor->state = EDIT_STANDBY; | ||||
|   editor->mask_timer_id = jmanager_add_timer(widget, 100); | ||||
| 
 | ||||
|   editor->cursor_thick = 0; | ||||
|   editor->old_cursor_thick = 0; | ||||
| 
 | ||||
|   jwidget_add_hook(widget, editor_type(), editor_msg_proc, editor); | ||||
|   jwidget_focusrest(widget, TRUE); | ||||
| 
 | ||||
|  | @ -923,6 +927,7 @@ static bool editor_view_msg_proc(JWidget widget, JMessage msg) | |||
| 	jrect_free(pos); | ||||
|       } | ||||
|       return TRUE; | ||||
| 
 | ||||
|   } | ||||
|   return FALSE; | ||||
| } | ||||
|  | @ -951,7 +956,16 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
| 	jregion_free(editor->refresh_region); | ||||
|       break; | ||||
| 
 | ||||
|     case JM_DRAW: | ||||
|     case JM_DRAW: { | ||||
|       if (editor->old_cursor_thick == 0) { | ||||
| 	editor->old_cursor_thick = editor->cursor_thick; | ||||
| 	editor->old_cursor_screen_x = editor->cursor_screen_x; | ||||
| 	editor->old_cursor_screen_y = editor->cursor_screen_y; | ||||
|       } | ||||
| 
 | ||||
|       if (editor->cursor_thick != 0) | ||||
| 	editor_clean_cursor(widget); | ||||
| 
 | ||||
|       /* without sprite */ | ||||
|       if (!editor->sprite) { | ||||
| 	JWidget view = jwidget_get_view(widget); | ||||
|  | @ -1022,12 +1036,19 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
| 	  jmanager_stop_timer(editor->mask_timer_id); | ||||
| 	} | ||||
| 
 | ||||
| 	if (editor->cursor_thick && !msg->draw.count) { | ||||
| 	  editor_draw_cursor(widget, editor->cursor_screen_x, editor->cursor_screen_y); | ||||
| 	if (msg->draw.count == 0 | ||||
| 	    && editor->old_cursor_thick != 0) { | ||||
| 	  editor_draw_cursor(widget, | ||||
| 			     editor->old_cursor_screen_x, | ||||
| 			     editor->old_cursor_screen_y); | ||||
| 	} | ||||
|       } | ||||
|       return TRUE; | ||||
| 
 | ||||
|       if (msg->draw.count == 0) | ||||
| 	editor->old_cursor_thick = 0; | ||||
| 
 | ||||
|       return TRUE; | ||||
|     } | ||||
| 
 | ||||
|     case JM_TIMER: | ||||
|       if (msg->timer.timer_id == editor->mask_timer_id && | ||||
|  | @ -1043,50 +1064,14 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
| 	} | ||||
|       } | ||||
|       break; | ||||
| #if 0 | ||||
|     case JM_IDLE: | ||||
|       if (editor->sprite) | ||||
| 	editor_draw_mask_safe(widget); | ||||
| 
 | ||||
| /*       if (editor->sprite) { */ | ||||
| /* 	if (current_tool == &ase_tool_path) { */ | ||||
| /* 	  if (editor->cursor_thick) { */ | ||||
| /* 	    hide_drawing_cursor (widget); */ | ||||
| /* 	    jmouse_set_cursor(JI_CURSOR_NORMAL); */ | ||||
| /* 	  } */ | ||||
| /* 	} */ | ||||
| /* 	else { */ | ||||
| /* 	  if (!editor->cursor_thick) { */ | ||||
| /* 	    jmouse_set_cursor(JI_CURSOR_NULL); */ | ||||
| /* 	    show_drawing_cursor (widget); */ | ||||
| /* 	  } */ | ||||
| /* 	} */ | ||||
| /*       } */ | ||||
| 
 | ||||
|       /* Redraw cursor when the user changes the brush size. */ | ||||
|       if ((editor->cursor_thick) && | ||||
| 	  (editor->cursor_thick != get_thickness_for_cursor())) { | ||||
| 	editor_clean_cursor(widget); | ||||
| 	editor_draw_cursor(widget, editor->cursor_screen_x, editor->cursor_screen_y); | ||||
|       } | ||||
| 
 | ||||
| /*       if (editor->refresh_region) */ | ||||
| /* 	editor_refresh_region (widget); */ | ||||
|       break; | ||||
| #endif | ||||
| 
 | ||||
|     case JM_MOUSEENTER: | ||||
|       if (jmanager_get_capture() && | ||||
| 	  jmanager_get_capture() != widget) { | ||||
| 	editor->lagged_mouseenter = TRUE; | ||||
| 	break; | ||||
|       } | ||||
| 
 | ||||
|       if (editor->state == EDIT_MOVING_SCROLL) | ||||
| 	break; | ||||
| 
 | ||||
|       if (editor->sprite) | ||||
|       if (editor->sprite) { | ||||
| 	show_drawing_cursor(widget); | ||||
|       } | ||||
|       else { | ||||
| 	hide_drawing_cursor(widget); | ||||
| 	app_default_status_bar_message(); | ||||
|  | @ -1094,15 +1079,6 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
|       break; | ||||
| 
 | ||||
|     case JM_MOUSELEAVE: | ||||
|       editor->lagged_mouseenter = FALSE; | ||||
| 
 | ||||
|       if (jmanager_get_capture() && | ||||
| 	  jmanager_get_capture() != widget) | ||||
| 	break; | ||||
| 
 | ||||
| /*       if (!editor->sprite) */ | ||||
| /* 	break; */ | ||||
| 
 | ||||
|       if (editor->state == EDIT_MOVING_SCROLL) | ||||
| 	break; | ||||
| 
 | ||||
|  | @ -1116,12 +1092,6 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
|       if (!editor->sprite) | ||||
| 	break; | ||||
| 
 | ||||
|       /* lagged MOUSEENTER event */ | ||||
|       if (editor->lagged_mouseenter) { | ||||
| 	editor->lagged_mouseenter = FALSE; | ||||
| 	show_drawing_cursor(widget); | ||||
|       } | ||||
| 
 | ||||
|       /* move the scroll */ | ||||
|       if ((msg->mouse.left && has_only_shifts(msg, KB_SHIFT_FLAG)) || | ||||
| 	  (msg->mouse.middle && has_only_shifts(msg, 0))) { | ||||
|  | @ -1156,12 +1126,6 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
|       if (!editor->sprite) | ||||
| 	break; | ||||
| 
 | ||||
|       /* lagged MOUSEENTER event */ | ||||
|       if (editor->lagged_mouseenter) { | ||||
| 	editor->lagged_mouseenter = FALSE; | ||||
| 	show_drawing_cursor(widget); | ||||
|       } | ||||
| 
 | ||||
|       /* move the scroll */ | ||||
|       if (editor->state == EDIT_MOVING_SCROLL) { | ||||
| 	JWidget view = jwidget_get_view(widget); | ||||
|  | @ -1194,19 +1158,15 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
|       if (editor->cursor_thick) { | ||||
| 	int x, y; | ||||
| 
 | ||||
| 	/* Get the pixel position corresponding to the mouse
 | ||||
| 	   position.  */ | ||||
| /* 	screen_to_editor(widget, jmouse_x(0), jmouse_y(0), &x, &y); */ | ||||
| 	x = jmouse_x(0); | ||||
| 	y = jmouse_y(0); | ||||
| 	x = msg->mouse.x; | ||||
| 	y = msg->mouse.y; | ||||
| 
 | ||||
| 	/* Redraw it only when the mouse change to other pixel (not
 | ||||
| 	   when the mouse moves only).  */ | ||||
| /* 	if ((editor->cursor_x != x) || (editor->cursor_y != y)) { */ | ||||
| 	if ((editor->cursor_screen_x != x) || (editor->cursor_screen_y != y)) { | ||||
| 	  jmouse_hide(); | ||||
| 	  editor_clean_cursor(widget); | ||||
| 	  editor_draw_cursor(widget, jmouse_x(0), jmouse_y(0)); | ||||
| 	  editor_draw_cursor(widget, x, y); | ||||
| 	  jmouse_show(); | ||||
| 	} | ||||
|       } | ||||
|  | @ -1225,7 +1185,7 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
|       return TRUE; | ||||
|     } | ||||
| 
 | ||||
|     case JM_BUTTONRELEASED: { | ||||
|     case JM_BUTTONRELEASED: | ||||
|       if (!editor->sprite) | ||||
| 	break; | ||||
| 
 | ||||
|  | @ -1238,8 +1198,9 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
| 
 | ||||
|       editor->state = EDIT_STANDBY; | ||||
|       jwidget_release_mouse(widget); | ||||
| 
 | ||||
|       show_drawing_cursor(widget); | ||||
|       return TRUE; | ||||
|     } | ||||
| 
 | ||||
|     case JM_CHAR: | ||||
|       if (!editor_keys_toset_zoom(widget, msg->key.scancode) && | ||||
|  | @ -1326,6 +1287,7 @@ static bool editor_msg_proc(JWidget widget, JMessage msg) | |||
| 	} | ||||
|       } | ||||
|       break; | ||||
|        | ||||
|   } | ||||
| 
 | ||||
|   return FALSE; | ||||
|  |  | |||
|  | @ -67,6 +67,7 @@ int editor_keys_toset_zoom(JWidget widget, int scancode) | |||
| 
 | ||||
|     /* zoom */ | ||||
|     if (zoom >= 0) { | ||||
|       hide_drawing_cursor(widget); | ||||
|       screen_to_editor(widget, jmouse_x(0), jmouse_y(0), &x, &y); | ||||
| 
 | ||||
|       x = editor->offset_x - jrect_w(vp)/2 + ((1<<zoom)>>1) + (x << zoom); | ||||
|  | @ -84,6 +85,8 @@ int editor_keys_toset_zoom(JWidget widget, int scancode) | |||
| 
 | ||||
| 	jmouse_set_position((vp->x1+vp->x2)/2, (vp->y1+vp->y2)/2); | ||||
| 	jrect_free(vp); | ||||
| 
 | ||||
| 	show_drawing_cursor(widget); | ||||
| 	return TRUE; | ||||
|       } | ||||
|     } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue