Support for hexa text input (internal)
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1522 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
d5a772f5ae
commit
7a46da32d5
@ -1080,7 +1080,7 @@ void Button_Settings(void)
|
||||
str[0]='\0';
|
||||
if (! (old_mouse_k & RIGHT_SIDE))
|
||||
Num2str(value,str,item.Digits+1);
|
||||
if (Readline(panel->Pos_X+3+176, panel->Pos_Y+num*SETTING_HEIGHT+(SETTING_HEIGHT-6)/2,str,item.Digits+1,1))
|
||||
if (Readline(panel->Pos_X+3+176, panel->Pos_Y+num*SETTING_HEIGHT+(SETTING_HEIGHT-6)/2,str,item.Digits+1,INPUT_TYPE_INTEGER))
|
||||
{
|
||||
value=atoi(str);
|
||||
if (value<item.Min_value)
|
||||
@ -2006,7 +2006,7 @@ void Button_Resolution(void)
|
||||
|
||||
case 3 : // Largeur
|
||||
Num2str(chosen_width,str,4);
|
||||
Readline(62,37,str,4,1);
|
||||
Readline(62,37,str,4,INPUT_TYPE_INTEGER);
|
||||
chosen_width=atoi(str);
|
||||
// On corrige les dimensions
|
||||
if (chosen_width==0)
|
||||
@ -2020,7 +2020,7 @@ void Button_Resolution(void)
|
||||
|
||||
case 4 : // Height
|
||||
Num2str(chosen_height,str,4);
|
||||
Readline(166,37,str,4,1);
|
||||
Readline(166,37,str,4,INPUT_TYPE_INTEGER);
|
||||
chosen_height=atoi(str);
|
||||
// On corrige les dimensions
|
||||
if (chosen_height==0)
|
||||
@ -4203,7 +4203,7 @@ void Button_Airbrush_menu(void)
|
||||
|
||||
case 11 : // Size
|
||||
Num2str(Airbrush_size,str,3);
|
||||
Readline(188,25,str,3,1);
|
||||
Readline(188,25,str,3,INPUT_TYPE_INTEGER);
|
||||
Airbrush_size=atoi(str);
|
||||
// On corrige les dimensions
|
||||
if (Airbrush_size>256)
|
||||
@ -4223,7 +4223,7 @@ void Button_Airbrush_menu(void)
|
||||
|
||||
case 12 : // Delay
|
||||
Num2str(Airbrush_delay,str,2);
|
||||
Readline(196,39,str,2,1);
|
||||
Readline(196,39,str,2,INPUT_TYPE_INTEGER);
|
||||
Airbrush_delay=atoi(str);
|
||||
// On corrige le delai
|
||||
if (Airbrush_delay>99)
|
||||
@ -4237,7 +4237,7 @@ void Button_Airbrush_menu(void)
|
||||
|
||||
case 13 : // Mono-Flow
|
||||
Num2str(Airbrush_mono_flow,str,2);
|
||||
Readline(113,24,str,2,1);
|
||||
Readline(113,24,str,2,INPUT_TYPE_INTEGER);
|
||||
Airbrush_mono_flow=atoi(str);
|
||||
// On corrige le flux
|
||||
if (!Airbrush_mono_flow)
|
||||
@ -4251,7 +4251,7 @@ void Button_Airbrush_menu(void)
|
||||
|
||||
case 14 : // Init
|
||||
Num2str(spray_init,str,2);
|
||||
Readline(113,40,str,2,1);
|
||||
Readline(113,40,str,2,INPUT_TYPE_INTEGER);
|
||||
spray_init=atoi(str);
|
||||
// On corrige la valeur
|
||||
if (spray_init>=50)
|
||||
@ -4834,7 +4834,7 @@ void Button_Text()
|
||||
switch(clicked_button)
|
||||
{
|
||||
case 1: // Texte saisi
|
||||
Readline_ex(50,20,str,29,250,0,0);
|
||||
Readline_ex(50,20,str,29,250,INPUT_TYPE_STRING,0);
|
||||
preview_is_needed=1;
|
||||
break;
|
||||
|
||||
@ -4874,7 +4874,7 @@ void Button_Text()
|
||||
break;
|
||||
|
||||
case 7: // Taille du texte (nombre)
|
||||
Readline(222,45,size_buffer,3,1);
|
||||
Readline(222,45,size_buffer,3,INPUT_TYPE_INTEGER);
|
||||
font_size=atoi(size_buffer);
|
||||
// On corrige les dimensions
|
||||
if (font_size < 1)
|
||||
|
||||
@ -279,7 +279,7 @@ void Button_Grid_menu(void)
|
||||
{
|
||||
case 3 :
|
||||
Num2str(chosen_X,str,2);
|
||||
Readline(39,26,str,2,1);
|
||||
Readline(39,26,str,2,INPUT_TYPE_INTEGER);
|
||||
chosen_X=atoi(str);
|
||||
// On corrige les dimensions
|
||||
if ((!chosen_X) || (chosen_X>80))
|
||||
@ -301,7 +301,7 @@ void Button_Grid_menu(void)
|
||||
break;
|
||||
case 4 :
|
||||
Num2str(chosen_Y,str,2);
|
||||
Readline(39,47,str,2,1);
|
||||
Readline(39,47,str,2,INPUT_TYPE_INTEGER);
|
||||
chosen_Y=atoi(str);
|
||||
// On corrige les dimensions
|
||||
if ((!chosen_Y) || (chosen_Y>80))
|
||||
@ -323,7 +323,7 @@ void Button_Grid_menu(void)
|
||||
break;
|
||||
case 5 :
|
||||
Num2str(dx_selected,str,2);
|
||||
Readline(97,26,str,2,1);
|
||||
Readline(97,26,str,2,INPUT_TYPE_INTEGER);
|
||||
dx_selected=atoi(str);
|
||||
// On corrige les dimensions
|
||||
if (dx_selected>79)
|
||||
@ -338,7 +338,7 @@ void Button_Grid_menu(void)
|
||||
break;
|
||||
case 6 :
|
||||
Num2str(dy_selected,str,2);
|
||||
Readline(97,47,str,2,1);
|
||||
Readline(97,47,str,2,INPUT_TYPE_INTEGER);
|
||||
dy_selected=atoi(str);
|
||||
// On corrige les dimensions
|
||||
if (dy_selected>79)
|
||||
@ -479,7 +479,7 @@ void Button_Smooth_menu(void)
|
||||
Num2str(chosen_matrix[x][y],str,2);
|
||||
Readline(matrix_input[x][y]->Pos_X+2,
|
||||
matrix_input[x][y]->Pos_Y+2,
|
||||
str,2,1);
|
||||
str,2,INPUT_TYPE_INTEGER);
|
||||
chosen_matrix[x][y]=atoi(str);
|
||||
Display_cursor();
|
||||
}
|
||||
@ -639,7 +639,7 @@ void Button_Colorize_menu(void)
|
||||
{
|
||||
case 1: // Zone de saisie de l'opacité
|
||||
Num2str(chosen_opacity,str,3);
|
||||
Readline(89,23,str,3,1);
|
||||
Readline(89,23,str,3,INPUT_TYPE_INTEGER);
|
||||
chosen_opacity=atoi(str);
|
||||
// On corrige le pourcentage
|
||||
if (chosen_opacity>100)
|
||||
@ -732,7 +732,7 @@ void Button_Tiling_menu(void)
|
||||
if (clicked_button==3) // Zone de saisie du décalage X
|
||||
{
|
||||
Num2str(chosen_offset_x,str,4);
|
||||
Readline(93,23,str,4,1);
|
||||
Readline(93,23,str,4,INPUT_TYPE_INTEGER);
|
||||
chosen_offset_x=atoi(str);
|
||||
// On corrige le décalage en X
|
||||
if (chosen_offset_x>=Brush_width)
|
||||
@ -747,7 +747,7 @@ void Button_Tiling_menu(void)
|
||||
if (clicked_button==4) // Zone de saisie du décalage Y
|
||||
{
|
||||
Num2str(chosen_offset_y,str,4);
|
||||
Readline(93,37,str,4,1);
|
||||
Readline(93,37,str,4,INPUT_TYPE_INTEGER);
|
||||
chosen_offset_y=atoi(str);
|
||||
// On corrige le décalage en Y
|
||||
if (chosen_offset_y>=Brush_height)
|
||||
|
||||
@ -675,7 +675,7 @@ int L_InputBox(lua_State* L)
|
||||
case CONTROL_INPUT:
|
||||
|
||||
Sprint_double(str,current_value[setting],decimal_places[setting],0);
|
||||
Readline_ex(12+max_label_length*8+23, 22+setting*17,str,7,40,3,decimal_places[setting]);
|
||||
Readline_ex(12+max_label_length*8+23, 22+setting*17,str,7,40,INPUT_TYPE_DECIMAL,decimal_places[setting]);
|
||||
current_value[setting]=atof(str);
|
||||
|
||||
if (current_value[setting] < min_value[setting])
|
||||
|
||||
@ -1368,7 +1368,7 @@ byte Button_Load_or_Save(byte load, T_IO_Context *context)
|
||||
case 7 : // Saisie d'un commentaire pour la sauvegarde
|
||||
if ( (!load) && (Get_fileformat(Main_format)->Comment) )
|
||||
{
|
||||
Readline(45,70,context->Comment,32,0);
|
||||
Readline(45,70,context->Comment,32,INPUT_TYPE_STRING);
|
||||
Display_cursor();
|
||||
}
|
||||
break;
|
||||
@ -1377,7 +1377,7 @@ byte Button_Load_or_Save(byte load, T_IO_Context *context)
|
||||
// Save the filename
|
||||
strcpy(save_filename, Selector_filename);
|
||||
|
||||
if (Readline(82,48,Selector_filename,27,2))
|
||||
if (Readline(82,48,Selector_filename,27,INPUT_TYPE_FILENAME))
|
||||
{
|
||||
// On regarde s'il faut rajouter une extension. C'est-à-dire s'il
|
||||
// n'y a pas de '.' dans le nom du fichier.
|
||||
@ -1499,7 +1499,7 @@ byte Button_Load_or_Save(byte load, T_IO_Context *context)
|
||||
strcpy(bookmark_label, Config.Bookmark_label[clicked_button-10]);
|
||||
if (bookmark_label[7]==ELLIPSIS_CHARACTER)
|
||||
bookmark_label[7]='\0';
|
||||
if (Readline_ex(bookmark_dropdown[clicked_button-10]->Pos_X+3+10,bookmark_dropdown[clicked_button-10]->Pos_Y+2,bookmark_label,8,8,0,0))
|
||||
if (Readline_ex(bookmark_dropdown[clicked_button-10]->Pos_X+3+10,bookmark_dropdown[clicked_button-10]->Pos_Y+2,bookmark_label,8,8,INPUT_TYPE_STRING,0))
|
||||
strcpy(Config.Bookmark_label[clicked_button-10],bookmark_label);
|
||||
Display_bookmark(bookmark_dropdown[clicked_button-10],clicked_button-10);
|
||||
Display_cursor();
|
||||
|
||||
@ -149,13 +149,17 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
|
||||
// Si on a commencé à editer par un clic-droit, on vide la chaine.
|
||||
if (Mouse_K==RIGHT_SIDE)
|
||||
str[0]='\0';
|
||||
else if (input_type==1 && str[0]!='\0')
|
||||
else if (input_type==INPUT_TYPE_INTEGER && str[0]!='\0')
|
||||
snprintf(str,10,"%d",atoi(str)); // On tasse la chaine à gauche
|
||||
else if (input_type==3)
|
||||
else if (input_type==INPUT_TYPE_DECIMAL)
|
||||
{
|
||||
// Nothing. The caller should have used Sprint_double, with min_positions
|
||||
// at zero, so there's no spaces on the left and no useless 0s on the right.
|
||||
}
|
||||
else if (input_type==INPUT_TYPE_HEXA)
|
||||
{
|
||||
// Nothing. The caller should have initialized a valid hexa number.
|
||||
}
|
||||
|
||||
Wait_end_of_click();
|
||||
Keyboard_click_allowed = 0;
|
||||
@ -285,15 +289,15 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
|
||||
is_authorized=0; // On commence par supposer qu'elle est interdite
|
||||
switch(input_type)
|
||||
{
|
||||
case 0 : // N'importe quelle chaîne:
|
||||
case INPUT_TYPE_STRING :
|
||||
if (input_key>=' ' && input_key<= 255)
|
||||
is_authorized=1;
|
||||
break;
|
||||
case 1 : // Nombre
|
||||
case INPUT_TYPE_INTEGER :
|
||||
if ( (input_key>='0') && (input_key<='9') )
|
||||
is_authorized=1;
|
||||
break;
|
||||
case 3: // Decimal number
|
||||
case INPUT_TYPE_DECIMAL:
|
||||
if ( (input_key>='0') && (input_key<='9') )
|
||||
is_authorized=1;
|
||||
else if (input_key=='-' && position==0 && str[0]!='-')
|
||||
@ -301,10 +305,18 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
|
||||
else if (input_key=='.')
|
||||
is_authorized=1;
|
||||
break;
|
||||
default : // Nom de fichier
|
||||
case INPUT_TYPE_FILENAME:
|
||||
// On regarde si la touche est autorisée
|
||||
if ( Valid_character(input_key))
|
||||
is_authorized=1;
|
||||
case INPUT_TYPE_HEXA:
|
||||
if ( (input_key>='0') && (input_key<='9') )
|
||||
is_authorized=1;
|
||||
else if ( (input_key>='A') && (input_key<='F') )
|
||||
is_authorized=1;
|
||||
else if ( (input_key>='a') && (input_key<='f') )
|
||||
is_authorized=1;
|
||||
break;
|
||||
} // End du "switch(input_type)"
|
||||
|
||||
// Si la touche était autorisée...
|
||||
@ -350,7 +362,7 @@ affichage:
|
||||
Block(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),BACKGROUND_COLOR);
|
||||
// On raffiche la chaine correctement
|
||||
if (input_type==1)
|
||||
if (input_type==INPUT_TYPE_INTEGER)
|
||||
{
|
||||
if (str[0]=='\0')
|
||||
{
|
||||
@ -359,7 +371,7 @@ affichage:
|
||||
}
|
||||
Print_in_window(x_pos+((max_size-size)<<3),y_pos,str,TEXT_COLOR,BACKGROUND_COLOR);
|
||||
}
|
||||
else if (input_type==3)
|
||||
else if (input_type==INPUT_TYPE_DECIMAL)
|
||||
{
|
||||
double value;
|
||||
// Discard extra digits
|
||||
|
||||
@ -24,13 +24,22 @@
|
||||
/// Text input functions.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum INPUT_TYPE
|
||||
{
|
||||
INPUT_TYPE_STRING=0, ///< Any string
|
||||
INPUT_TYPE_INTEGER=1, ///< Decimal integer
|
||||
INPUT_TYPE_FILENAME=2,///< Filename
|
||||
INPUT_TYPE_DECIMAL=3, ///< Decimal value
|
||||
INPUT_TYPE_HEXA=4, ///< Hexadecimal integer
|
||||
};
|
||||
|
||||
///
|
||||
/// Lets the user input a line of text, exit by Esc or Return.
|
||||
/// @param x_pos Coordinates of input, in window coordinates before scaling.
|
||||
/// @param y_pos Coordinates of input, in window coordinates before scaling.
|
||||
/// @param str The original string value (will be modified, unless user cancels.
|
||||
/// @param visible_size Number of characters visible and editable.
|
||||
/// @param input_type 0=string, 1=number, 2=filename (255 editable characters)
|
||||
/// @param input_type one of enum ::INPUT_TYPE
|
||||
/// @return 0 if user cancelled (esc), 1 if accepted (return)
|
||||
byte Readline(word x_pos,word y_pos,char * str,byte visible_size,byte input_type);
|
||||
|
||||
@ -41,7 +50,7 @@ byte Readline(word x_pos,word y_pos,char * str,byte visible_size,byte input_type
|
||||
/// @param str The original string value (will be modified, unless user cancels.
|
||||
/// @param visible_size Number of characters visible.
|
||||
/// @param max_size Number of characters editable.
|
||||
/// @param input_type 0=string, 1=integer, 2=filename (255 editable characters) 3=decimal
|
||||
/// @param input_type one of enum ::INPUT_TYPE
|
||||
/// @param decimal_places Number of decimal places (used only with decimal type)
|
||||
/// @return 0 if user cancelled (esc), 1 if accepted (return)
|
||||
byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_size, byte input_type, byte decimal_places);
|
||||
|
||||
@ -837,7 +837,7 @@ int Menu_shade(void)
|
||||
|
||||
case 15 : // Saisie du pas
|
||||
Num2str(Shade_list[Shade_current].Step,str,3);
|
||||
Readline(276,176,str,3,1);
|
||||
Readline(276,176,str,3,INPUT_TYPE_INTEGER);
|
||||
temp=atoi(str);
|
||||
// On corrige le pas
|
||||
if (!temp)
|
||||
@ -1089,7 +1089,7 @@ void Button_Quick_shade_menu(void)
|
||||
|
||||
case 4 : // Saisie du pas
|
||||
Num2str(Quick_shade_step,str,3);
|
||||
Readline(42,21,str,3,1);
|
||||
Readline(42,21,str,3,INPUT_TYPE_INTEGER);
|
||||
temp=atoi(str);
|
||||
// On corrige le pas
|
||||
if (!temp)
|
||||
|
||||
@ -273,7 +273,7 @@ void Button_Transform_menu(void)
|
||||
input_button[clicked_button-10]->Pos_Y+2,
|
||||
buffer,
|
||||
4,
|
||||
1))
|
||||
INPUT_TYPE_INTEGER))
|
||||
{
|
||||
// Accept entered value
|
||||
*(input_value[clicked_button-10])=atoi(buffer);
|
||||
|
||||
@ -1074,7 +1074,7 @@ int Requester_window(char* message, int initial_value)
|
||||
{
|
||||
clicked_button = Window_clicked_button();
|
||||
if (clicked_button == 1)
|
||||
Readline(11, 39, str, 4, 1);
|
||||
Readline(11, 39, str, 4, INPUT_TYPE_INTEGER);
|
||||
if (Key == SDLK_ESCAPE) clicked_button = 2;
|
||||
}
|
||||
while (clicked_button <= 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user