From cbcb7a6b8ff2b7101088935f79593fefd00b1980 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Wed, 1 Feb 2012 00:56:21 +0000 Subject: [PATCH] Issue 233: Added mouse panning. Default is 'space' for new users, others need pick a key in Help screen. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1901 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/const.h | 3 ++ src/engine.c | 12 ++++++- src/global.h | 3 +- src/helpfile.h | 1 + src/hotkeys.c | 11 +++++- src/hotkeys.h | 2 +- src/init.c | 13 +++++++- src/input.c | 16 +++++++-- src/input.h | 4 +++ src/operatio.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/operatio.h | 7 ++++ 11 files changed, 155 insertions(+), 7 deletions(-) diff --git a/src/const.h b/src/const.h index 2d42648f..adb9a730 100644 --- a/src/const.h +++ b/src/const.h @@ -518,6 +518,8 @@ enum SPECIAL_ACTIONS SPECIAL_FORMAT_CHECKER, SPECIAL_FORMAT_CHECKER_MENU, + SPECIAL_HOLD_PAN, + NB_SPECIAL_SHORTCUTS ///< Number of special shortcuts }; @@ -558,6 +560,7 @@ enum OPERATIONS OPERATION_DISTORT_BRUSH, ///< Distort brush OPERATION_GRAD_RECTANGLE, ///< Gradient-filled rectangle OPERATION_RMB_COLORPICK, ///< Colorpick on right mouse button + OPERATION_PAN_VIEW, ///< Pan view NB_OPERATIONS ///< Number of operations handled by the engine }; diff --git a/src/engine.c b/src/engine.c index bb36c851..2e7a527f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -734,7 +734,14 @@ void Main_handler(void) Button_Quit(); } - if (Key) + if (Pan_shortcut_pressed && Current_operation!=OPERATION_PAN_VIEW) + { + Hide_cursor(); + Start_operation_stack(OPERATION_PAN_VIEW); + Display_cursor(); + action++; + } + else if (Key) { effect_modified = 0; @@ -1341,6 +1348,9 @@ void Main_handler(void) Set_palette(Main_palette); action++; break; + case SPECIAL_HOLD_PAN: + // already handled by Pan_shortcut_pressed + break; } } } // End of special keys diff --git a/src/global.h b/src/global.h index a87d7796..86b9952f 100644 --- a/src/global.h +++ b/src/global.h @@ -900,7 +900,7 @@ GFX2_GLOBAL T_Brush_template Brush_container[BRUSH_CONTAINER_COLUMNS*BRUSH_CONTA CURSOR_SHAPE_TARGET , // Polyform CURSOR_SHAPE_TARGET , // Filled polygon CURSOR_SHAPE_TARGET , // Filled polyform - CURSOR_SHAPE_MULTIDIRECTIONAL , // Scroll (pan) + CURSOR_SHAPE_MULTIDIRECTIONAL , // Scroll image CURSOR_SHAPE_XOR_TARGET , // Gradient-filled circle CURSOR_SHAPE_XOR_TARGET , // Gradient-filled ellipse CURSOR_SHAPE_XOR_ROTATION , // Rotate brush @@ -908,6 +908,7 @@ GFX2_GLOBAL T_Brush_template Brush_container[BRUSH_CONTAINER_COLUMNS*BRUSH_CONTA CURSOR_SHAPE_TARGET , // Distort brush CURSOR_SHAPE_XOR_TARGET , // Gradient-filled rectangle CURSOR_SHAPE_COLORPICKER , // Colorpick on right mouse button + CURSOR_SHAPE_MULTIDIRECTIONAL , // Pan view }; #else /// ::Cursor_shape to use for each operation. diff --git a/src/helpfile.h b/src/helpfile.h index 15f29ee2..4648d000 100644 --- a/src/helpfile.h +++ b/src/helpfile.h @@ -122,6 +122,7 @@ static const T_Help_table helptable_help[] = HELP_LINK (" down slower: %s", SPECIAL_SCROLL_DOWN_SLOW) HELP_LINK (" left slower: %s", SPECIAL_SCROLL_LEFT_SLOW) HELP_LINK (" right slower: %s", SPECIAL_SCROLL_RIGHT_SLOW) + HELP_LINK ("Mouse pan: %s", SPECIAL_HOLD_PAN) HELP_TEXT ("Emulate mouse") HELP_LINK (" Up: %s", SPECIAL_MOUSE_UP) HELP_LINK (" Down: %s", SPECIAL_MOUSE_DOWN) diff --git a/src/hotkeys.c b/src/hotkeys.c index 8d81e7ed..2b36a6f9 100644 --- a/src/hotkeys.c +++ b/src/hotkeys.c @@ -163,7 +163,7 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = { "left mouse button. It's useful", "when you want ultra-high precision.", true, - SDLK_SPACE, // Space + SDLK_SPACE|MOD_CTRL, // Ctrl + Space 0}, {17, "Simulate right mouse click", @@ -1721,6 +1721,14 @@ T_Key_config ConfigKey[NB_SHORTCUTS] = { true, 0, // No shortcut 0}, + {208, + "Pan view", + "While this key is being held,", + "click and drag the mouse to", + "pan the view.", + true, + SDLK_SPACE, // Space + 0}, }; word Ordering[NB_SHORTCUTS]= @@ -1933,4 +1941,5 @@ word Ordering[NB_SHORTCUTS]= 0x100+BUTTON_ANIM_PREV_FRAME, 0x100+BUTTON_ANIM_NEXT_FRAME, 0x100+BUTTON_ANIM_PLAY, + SPECIAL_HOLD_PAN, }; diff --git a/src/hotkeys.h b/src/hotkeys.h index eac4325f..0e7d4e8e 100644 --- a/src/hotkeys.h +++ b/src/hotkeys.h @@ -33,7 +33,7 @@ #endif #include -#define NB_SHORTCUTS 208 ///< Number of actions that can have a key combination associated to it. +#define NB_SHORTCUTS 209 ///< Number of actions that can have a key combination associated to it. /*** Types definitions and structs ***/ diff --git a/src/init.c b/src/init.c index 01e14533..1bcfff55 100644 --- a/src/init.c +++ b/src/init.c @@ -1737,9 +1737,20 @@ void Init_operations(void) Centered_lines_12_7,0,FAST_MOUSE); Init_operation(OPERATION_CENTERED_LINES,0,7, Centered_lines_0_7,0,FAST_MOUSE); - Init_operation(OPERATION_RMB_COLORPICK,0,1, Rightclick_colorpick_0_1,0,FAST_MOUSE); + Init_operation(OPERATION_PAN_VIEW,0,0, + Pan_view_0_0,0,FAST_MOUSE); + Init_operation(OPERATION_PAN_VIEW,1,0, + Pan_view_12_0,0,FAST_MOUSE); + Init_operation(OPERATION_PAN_VIEW,2,0, + Pan_view_12_0,0,FAST_MOUSE); + Init_operation(OPERATION_PAN_VIEW,1,2, + Pan_view_12_2,0,FAST_MOUSE); + Init_operation(OPERATION_PAN_VIEW,2,2, + Pan_view_12_2,0,FAST_MOUSE); + Init_operation(OPERATION_PAN_VIEW,0,2, + Pan_view_0_2,0,FAST_MOUSE); } diff --git a/src/input.c b/src/input.c index d9e5273d..241dc964 100644 --- a/src/input.c +++ b/src/input.c @@ -85,6 +85,8 @@ word Input_new_mouse_Y; byte Input_new_mouse_K; byte Button_inverter=0; // State of the key that swaps mouse buttons. +byte Pan_shortcut_pressed; + // Joystick/pad configurations for the various console ports. // See the #else for the documentation of fields. // TODO: Make these user-settable somehow. @@ -443,7 +445,11 @@ int Handle_key_press(SDL_KeyboardEvent event) Directional_click=2; return Move_cursor_with_constraints(); } - + else if(Is_shortcut(Key,SPECIAL_HOLD_PAN)) + { + Pan_shortcut_pressed=1; + return 0; + } return 0; } @@ -507,7 +513,13 @@ int Release_control(int key_code, int modifier) return Move_cursor_with_constraints() || need_feedback; } } - + if((key_code && key_code == (Config_Key[SPECIAL_HOLD_PAN][0]&0x0FFF)) || (Config_Key[SPECIAL_HOLD_PAN][0]&modifier) || + (key_code && key_code == (Config_Key[SPECIAL_HOLD_PAN][1]&0x0FFF)) || (Config_Key[SPECIAL_HOLD_PAN][1]&modifier)) + { + Pan_shortcut_pressed=0; + need_feedback = 1; + } + // Other keys don't need to be released : they are handled as "events" and procesed only once. // These clicks are apart because they need to be continuous (ie move while key pressed) // We are relying on "hardware" keyrepeat to achieve that. diff --git a/src/input.h b/src/input.h index 74485db2..3a88dc1b 100644 --- a/src/input.h +++ b/src/input.h @@ -53,6 +53,10 @@ void Set_mouse_position(void); /// that will record and retrieve a real control ID. extern int Input_sticky_control; +/// +/// State of the shortcut for panning (SPECIAL_HOLD_PAN) : pressed or not. +extern byte Pan_shortcut_pressed; + /// Allows locking movement to X or Y axis: 0=normal, 1=lock on next move, 2=locked horizontally, 3=locked vertically. extern int Snap_axis; /// For the :Snap_axis mode, sets the origin's point (in image coordinates) diff --git a/src/operatio.c b/src/operatio.c index 558abec7..3566a261 100644 --- a/src/operatio.c +++ b/src/operatio.c @@ -70,6 +70,7 @@ void Start_operation_stack(word new_operation) case OPERATION_GRAB_BRUSH: case OPERATION_POLYBRUSH: case OPERATION_STRETCH_BRUSH: + case OPERATION_PAN_VIEW: Operation_before_interrupt=Current_operation; // On passe à l'operation demandée Current_operation=new_operation; @@ -4031,3 +4032,92 @@ void Centered_lines_0_7(void) Operation_push(Paintbrush_Y); } +///////////////////////////////////////////////////////////// OPERATION_PAN_VIEW + +void Pan_view_0_0(void) +// Opération : OPERATION_PAN_VIEW +// Click Souris: 0 +// Taille_Pile : 0 +// +// Souris effacée: Non +{ + if (Pan_shortcut_pressed) + { + Print_coordinates(); + } + else + { + // End of operation, return to previous + Hide_cursor(); + Start_operation_stack(Operation_before_interrupt); + Display_cursor(); + } +} + +void Pan_view_12_0(void) +// Opération : OPERATION_PAN_VIEW +// Click Souris: 1 ou 2 +// Taille_Pile : 0 +// +// Souris effacée: Non + +// First time the user clicks +{ + Init_start_operation(); + + Operation_push(Paintbrush_X); + Operation_push(Paintbrush_Y); +} + +void Pan_view_12_2(void) +// Opération : OPERATION_PAN_VIEW +// Click Souris: 1 ou 2 +// Taille_Pile : 2 +// +// Souris effacée: Non + +// While dragging view +{ + short start_x; + short start_y; + + Operation_pop(&start_y); + Operation_pop(&start_x); + + if (Paintbrush_X!=start_x || Paintbrush_Y!=start_y) + { + // User moved + if (Main_magnifier_mode) + Scroll_magnifier(start_x-Paintbrush_X,start_y-Paintbrush_Y); + else + Scroll_screen(start_x-Paintbrush_X,start_y-Paintbrush_Y); + } + // The "scroll" functions have actualized the Paintbrush_X and Y + + Operation_push(Paintbrush_X); + Operation_push(Paintbrush_Y); +} + +void Pan_view_0_2(void) +// Opération : OPERATION_PAN_VIEW +// Click Souris: 0 +// Taille_Pile : 2 +// +// Souris effacée: Non + +// When releasing after dragging +{ + short start_x; + short start_y; + + Operation_pop(&start_y); + Operation_pop(&start_x); + + if (!Pan_shortcut_pressed) + { + // End of operation, return to previous + Hide_cursor(); + Start_operation_stack(Operation_before_interrupt); + Display_cursor(); + } +} \ No newline at end of file diff --git a/src/operatio.h b/src/operatio.h index 62002a59..5905892c 100644 --- a/src/operatio.h +++ b/src/operatio.h @@ -230,3 +230,10 @@ void Centered_lines_0_7(void); byte Rightclick_colorpick(byte cursor_visible); void Rightclick_colorpick_2_1(void); void Rightclick_colorpick_0_1(void); + +/////////////////////////////////////////////////// OPERATION_PAN_VIEW + +void Pan_view_0_0(void); +void Pan_view_12_0(void); +void Pan_view_12_2(void); +void Pan_view_0_2(void);