GrafX2 2.9.3227
The ultimate 256-color painting program
readline.c File Reference

Text input GUI widget. More...

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "const.h"
#include "struct.h"
#include "global.h"
#include "misc.h"
#include "osdep.h"
#include "errors.h"
#include "screen.h"
#include "readline.h"
#include "windows.h"
#include "input.h"
#include "engine.h"
#include "unicode.h"
#include "keycodes.h"
+ Include dependency graph for readline.c:

Macros

#define VIRT_KEY_DEFAULT_ON   0
 
#define TEXT_COLOR   MC_Black
 
#define BACKGROUND_COLOR   MC_Light
 
#define CURSOR_COLOR   MC_Black
 
#define CURSOR_BACKGROUND_COLOR   MC_Dark
 

Functions

static void Remove_character (char *str, int position)
 remove a character from a string More...
 
static void Remove_character_unicode (word *str, int position)
 remove a character from a unicode string More...
 
static void Insert_character (char *str, char letter, int position)
 Insert a character in string at position. More...
 
static void Insert_character_unicode (word *str, word c, int position)
 Insert a character in unicode string at position. More...
 
static int Prepend_string (char *dest, const char *src, int max)
 Insert a string at the start of another. More...
 
static int Prepend_string_unicode (word *dest, const word *src, int max)
 Insert a unicode string at the start of another. More...
 
static int Valid_character (word c, enum INPUT_TYPE input_type)
 Check validy of character depending on input_type. More...
 
static void Cleanup_string (char *str, int input_type)
 remove invalid characters More...
 
static void Cleanup_string_unicode (word *str, int input_type)
 remove invalid characters More...
 
static void Display_whole_string (word x_pos, word y_pos, const char *str, byte position)
 Prints the string and the cursor on screen. More...
 
static void Display_whole_string_unicode (word x_pos, word y_pos, const word *str_unicode, byte position)
 Prints the unicode string and the cursor on screen. More...
 
void Init_virtual_keyboard (word y_pos, word keyboard_width, word keyboard_height)
 Initializes and displays the visual keyboard. More...
 
byte Readline (word x_pos, word y_pos, char *str, byte visible_size, enum INPUT_TYPE input_type)
 Lets the user input a line of text, exit by Esc or Return. More...
 
byte Readline_ex (word x_pos, word y_pos, char *str, byte visible_size, byte max_size, enum INPUT_TYPE input_type, byte decimal_places)
 Lets the user input a line of text, exit by Esc or Return. More...
 
byte Readline_ex_unicode (word x_pos, word y_pos, char *str, word *str_unicode, byte visible_size, byte max_size, enum INPUT_TYPE input_type, byte decimal_places)
 Lets the user input a line of text, exit by Esc or Return. More...
 
void Sprint_double (char *str, double value, byte decimal_places, byte min_positions)
 Converts a double to string. More...
 

Detailed Description

Text input GUI widget.

Macro Definition Documentation

◆ VIRT_KEY_DEFAULT_ON

#define VIRT_KEY_DEFAULT_ON   0

◆ TEXT_COLOR

#define TEXT_COLOR   MC_Black

◆ BACKGROUND_COLOR

#define BACKGROUND_COLOR   MC_Light

◆ CURSOR_COLOR

#define CURSOR_COLOR   MC_Black

◆ CURSOR_BACKGROUND_COLOR

#define CURSOR_BACKGROUND_COLOR   MC_Dark

Function Documentation

◆ Remove_character()

static void Remove_character ( char *  str,
int  position 
)
static

remove a character from a string

Referenced by Readline_ex_unicode().

◆ Remove_character_unicode()

static void Remove_character_unicode ( word str,
int  position 
)
static

remove a character from a unicode string

Referenced by Readline_ex_unicode().

◆ Insert_character()

static void Insert_character ( char *  str,
char  letter,
int  position 
)
static

Insert a character in string at position.

Referenced by Readline_ex_unicode().

◆ Insert_character_unicode()

static void Insert_character_unicode ( word str,
word  c,
int  position 
)
static

Insert a character in unicode string at position.

Referenced by Readline_ex_unicode().

◆ Prepend_string()

static int Prepend_string ( char *  dest,
const char *  src,
int  max 
)
static

Insert a string at the start of another.

Up to MAX characters only.

Returns
actual number of chars inserted

Referenced by Readline_ex_unicode().

◆ Prepend_string_unicode()

static int Prepend_string_unicode ( word dest,
const word src,
int  max 
)
static

Insert a unicode string at the start of another.

Up to MAX characters only.

Returns
actual number of chars inserted

References Unicode_strlen().

Referenced by Readline_ex_unicode().

◆ Valid_character()

static int Valid_character ( word  c,
enum INPUT_TYPE  input_type 
)
static

Check validy of character depending on input_type.

Returns
0 = Not allowed
1 = Allowed
2 = Allowed only once at start of string (for - sign in numbers)

References INPUT_TYPE_DECIMAL, INPUT_TYPE_FILENAME, INPUT_TYPE_HEXA, INPUT_TYPE_INTEGER, and INPUT_TYPE_STRING.

Referenced by Cleanup_string(), Cleanup_string_unicode(), and Readline_ex_unicode().

◆ Cleanup_string()

static void Cleanup_string ( char *  str,
int  input_type 
)
static

remove invalid characters

References Valid_character().

Referenced by Readline_ex_unicode().

◆ Cleanup_string_unicode()

static void Cleanup_string_unicode ( word str,
int  input_type 
)
static

remove invalid characters

References Valid_character().

Referenced by Readline_ex_unicode().

◆ Display_whole_string()

static void Display_whole_string ( word  x_pos,
word  y_pos,
const char *  str,
byte  position 
)
static

Prints the string and the cursor on screen.

Parameters
x_pos,y_posposition on screen
strthe string to display
positionthe cursor position

References BACKGROUND_COLOR, CURSOR_BACKGROUND_COLOR, CURSOR_COLOR, Menu_factor_X, Print_general(), and TEXT_COLOR.

Referenced by Readline_ex_unicode().

◆ Display_whole_string_unicode()

static void Display_whole_string_unicode ( word  x_pos,
word  y_pos,
const word str_unicode,
byte  position 
)
static

Prints the unicode string and the cursor on screen.

Parameters
x_pos,y_posposition on screen
str_unicodethe string to display
positionthe cursor position

References BACKGROUND_COLOR, CURSOR_BACKGROUND_COLOR, CURSOR_COLOR, Menu_factor_X, Print_general_unicode(), and TEXT_COLOR.

Referenced by Readline_ex_unicode().

◆ Init_virtual_keyboard()

void Init_virtual_keyboard ( word  y_pos,
word  keyboard_width,
word  keyboard_height 
)

◆ Readline()

byte Readline ( word  x_pos,
word  y_pos,
char *  str,
byte  visible_size,
enum INPUT_TYPE  input_type 
)

Lets the user input a line of text, exit by Esc or Return.

Parameters
x_posCoordinates of input, in window coordinates before scaling.
y_posCoordinates of input, in window coordinates before scaling.
strThe original string value (will be modified, unless user cancels.
visible_sizeNumber of characters visible and editable.
input_typeone of enum INPUT_TYPE
Returns
0 if user cancelled (esc), 1 if accepted (return)

References INPUT_TYPE_FILENAME, and Readline_ex().

Referenced by Button_Airbrush_menu(), Button_Anim_time(), Button_Colorize_menu(), Button_Grid_menu(), Button_Load_or_Save(), Button_Palette(), Button_Quick_shade_menu(), Button_Resolution(), Button_Settings(), Button_Smooth_menu(), Button_Text(), Button_Tiling_menu(), Button_Transform_menu(), Load_SCR(), Menu_shade(), and Requester_window().

◆ Readline_ex()

byte Readline_ex ( word  x_pos,
word  y_pos,
char *  str,
byte  visible_size,
byte  max_size,
enum INPUT_TYPE  input_type,
byte  decimal_places 
)

Lets the user input a line of text, exit by Esc or Return.

Parameters
x_posCoordinates of input, in window coordinates before scaling.
y_posCoordinates of input, in window coordinates before scaling.
strThe original string value (will be modified, unless user cancels.
visible_sizeNumber of characters visible.
max_sizeNumber of characters editable.
input_typeone of enum INPUT_TYPE
decimal_placesNumber of decimal places (used only with decimal type)
Returns
0 if user cancelled (esc), 1 if accepted (return)

References NULL, and Readline_ex_unicode().

Referenced by Button_Load_or_Save(), Button_Text(), and Readline().

◆ Readline_ex_unicode()

byte Readline_ex_unicode ( word  x_pos,
word  y_pos,
char *  str,
word unicode_str,
byte  visible_size,
byte  max_size,
enum INPUT_TYPE  input_type,
byte  decimal_places 
)

Lets the user input a line of text, exit by Esc or Return.

Parameters
x_pos,y_posCoordinates of input, in window coordinates before scaling.
strThe original string value. Will be modified, unless user cancels or unicode_str is not NULL.
unicode_strThe original unicode string value or NULL for ANSI editing. Will be modified if not NULL, unless user cancels.
visible_sizeNumber of characters visible.
max_sizeNumber of characters editable.
input_typeone of enum INPUT_TYPE
decimal_placesNumber of decimal places (used only with decimal type)
Returns
0 : user cancelled (esc)
1 : user accepted (return)

References BACKGROUND_COLOR, Cleanup_string(), Cleanup_string_unicode(), Close_popup(), Config, Display_cursor(), Display_whole_string(), Display_whole_string_unicode(), Flush_update(), Fround(), Get_input(), GFX2_GetTextClipboard(), GFX2_INFO, GFX2_Log(), GFX2_WARNING, Hide_cursor, Init_virtual_keyboard(), Input_sticky_control, INPUT_TYPE_DECIMAL, INPUT_TYPE_FILENAME, INPUT_TYPE_HEXA, INPUT_TYPE_INTEGER, INPUT_TYPE_STRING, Insert_character(), Insert_character_unicode(), Key, Key_ANSI, KEY_BACKSPACE, KEY_CAPSLOCK, KEY_CLEAR, KEY_DELETE, KEY_END, KEY_ESC, KEY_HOME, KEY_LEFT, KEY_NONE, KEY_RETURN, KEY_RIGHT, Key_UNICODE, Keyboard_click_allowed, label, LEFT_SIDE, LEFT_TRIANGLE_CHARACTER, MC_Black, MC_Light, Menu_factor_X, Menu_factor_Y, Mouse_K, Mouse_X, NULL, Pixel_height, Pixel_width, Prepend_string(), Prepend_string_unicode(), Print_in_window(), Print_in_window_limited(), Remove_character(), Remove_character_unicode(), RIGHT_SIDE, RIGHT_TRIANGLE_CHARACTER, Screen_FillRect(), SHORTCUT_PASTE, Sprint_double(), TEXT_COLOR, Unicode_char_strlcat(), Unicode_char_strlcpy(), Unicode_strlcpy(), Unicode_strlen(), Update_rect(), Update_window_area, T_Config::Use_virtual_keyboard, Valid_character(), VIRT_KEY_DEFAULT_ON, Wait_end_of_click(), Window_clicked_button(), Window_display_frame_in(), Window_height, Window_pos_X, Window_pos_Y, Window_set_normal_button(), and Window_width.

Referenced by Button_Load_or_Save(), and Readline_ex().

◆ Sprint_double()

void Sprint_double ( char *  str,
double  value,
byte  decimal_places,
byte  min_positions 
)

Converts a double to string.

Parameters
strTarget string, should be pre-allocated and at least 40 characters, to be safe.
valueThe number to convert
decimal_placesNumber of decimal places to keep. 15 seems the maximum.
min_positionsMinimum number of characters: Will pad spaces on the left to meet this minimum.

Referenced by Readline_ex_unicode().