Allows exiting a textfield with a mouse click (but not using space). Introduce a new global var to do it, however...

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@952 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2009-07-24 15:22:18 +00:00
parent cdd8a3276c
commit bd9541cc04
4 changed files with 11 additions and 5 deletions

View File

@ -78,6 +78,7 @@ GFX2_GLOBAL T_Components Fav_menu_colors[4];
GFX2_GLOBAL word Mouse_X; ///< Current mouse cursor position. GFX2_GLOBAL word Mouse_X; ///< Current mouse cursor position.
GFX2_GLOBAL word Mouse_Y; ///< Current mouse cursor position. GFX2_GLOBAL word Mouse_Y; ///< Current mouse cursor position.
GFX2_GLOBAL byte Mouse_K; ///< Current mouse buttons state. Bitfield: 1 for RMB, 2 for LMB. GFX2_GLOBAL byte Mouse_K; ///< Current mouse buttons state. Bitfield: 1 for RMB, 2 for LMB.
GFX2_GLOBAL byte Keyboard_click_allowed; ///< Set to 0 when you edit a textfield so you can use space without exiting it
/// Helper macro to take only one button when both are pressed (LMB has priority) /// Helper macro to take only one button when both are pressed (LMB has priority)
#define Mouse_K_unique (Mouse_K==0?0:(Mouse_K&1?1:(Mouse_K&2?2:0))) #define Mouse_K_unique (Mouse_K==0?0:(Mouse_K&1?1:(Mouse_K&2?2:0)))

View File

@ -345,13 +345,13 @@ int Handle_key_press(SDL_KeyboardEvent event)
Directional_right=1; Directional_right=1;
return 0; return 0;
} }
else if(Is_shortcut(Key,SPECIAL_CLICK_LEFT)) else if(Is_shortcut(Key,SPECIAL_CLICK_LEFT) && Keyboard_click_allowed > 0)
{ {
Input_new_mouse_K=1; Input_new_mouse_K=1;
Directional_click=1; Directional_click=1;
return Move_cursor_with_constraints(); return Move_cursor_with_constraints();
} }
else if(Is_shortcut(Key,SPECIAL_CLICK_RIGHT)) else if(Is_shortcut(Key,SPECIAL_CLICK_RIGHT) && Keyboard_click_allowed > 0)
{ {
Input_new_mouse_K=2; Input_new_mouse_K=2;
Directional_click=2; Directional_click=2;

1
main.c
View File

@ -398,6 +398,7 @@ int Init_program(int argc,char * argv[])
Spare_magnifier_width=0; Spare_magnifier_width=0;
Spare_magnifier_offset_X=0; Spare_magnifier_offset_X=0;
Spare_magnifier_offset_Y=0; Spare_magnifier_offset_Y=0;
Keyboard_click_allowed = 0;
// SDL // SDL
if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0)

View File

@ -158,6 +158,9 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
else if (input_type==1) else if (input_type==1)
snprintf(str,10,"%d",atoi(str)); // On tasse la chaine à gauche snprintf(str,10,"%d",atoi(str)); // On tasse la chaine à gauche
Wait_end_of_click();
Keyboard_click_allowed = 0;
size=strlen(str); size=strlen(str);
position=(size<max_size)? size:size-1; position=(size<max_size)? size:size-1;
@ -176,14 +179,14 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
visible_size*(Menu_factor_X<<3),(Menu_factor_Y<<3)); visible_size*(Menu_factor_X<<3),(Menu_factor_Y<<3));
Flush_update(); Flush_update();
while ((input_key!=SDLK_RETURN) && (input_key!=KEY_ESC)) while ((input_key!=SDLK_RETURN) && (input_key!=KEY_ESC) && Mouse_K == 0)
{ {
Display_cursor(); Display_cursor();
do do
{ {
if(!Get_input()) SDL_Delay(20); if(!Get_input()) SDL_Delay(20);
input_key=Key_ANSI; input_key=Key_ANSI;
} while(input_key==0); } while(input_key==0 && Mouse_K == 0);
Hide_cursor(); Hide_cursor();
switch (input_key) switch (input_key)
{ {
@ -325,6 +328,7 @@ affichage:
Flush_update(); Flush_update();
} // End du "while" } // End du "while"
Keyboard_click_allowed = 1;
// Effacement de la chaîne // Effacement de la chaîne
Block(Window_pos_X+(x_pos*Menu_factor_X),Window_pos_Y+(y_pos*Menu_factor_Y), Block(Window_pos_X+(x_pos*Menu_factor_X),Window_pos_Y+(y_pos*Menu_factor_Y),
@ -346,5 +350,5 @@ affichage:
Update_rect(Window_pos_X+(x_pos*Menu_factor_X),Window_pos_Y+(y_pos*Menu_factor_Y), Update_rect(Window_pos_X+(x_pos*Menu_factor_X),Window_pos_Y+(y_pos*Menu_factor_Y),
visible_size*(Menu_factor_X<<3),(Menu_factor_Y<<3)); visible_size*(Menu_factor_X<<3),(Menu_factor_Y<<3));
return (input_key==SDLK_RETURN); return (input_key==SDLK_RETURN || Mouse_K != 0);
} }