GrafX2 2.9.3227
The ultimate 256-color painting program
input.c File Reference
#include <string.h>
#include <limits.h>
#include "gfx2log.h"
#include "global.h"
#include "keyboard.h"
#include "screen.h"
#include "windows.h"
#include "errors.h"
#include "misc.h"
#include "osdep.h"
#include "buttons.h"
#include "input.h"
#include "loadsave.h"
+ Include dependency graph for input.c:

Macros

#define PAD_MAX_SPEED   3
 
#define D_JOYSTICK_UP   (1 << 0)
 
#define D_JOYSTICK_UP_RIGHT   (1 << 1)
 
#define D_JOYSTICK_RIGHT   (1 << 2)
 
#define D_JOYSTICK_DOWN_RIGHT   (1 << 3)
 
#define D_JOYSTICK_DOWN   (1 << 4)
 
#define D_JOYSTICK_DOWN_LEFT   (1 << 5)
 
#define D_JOYSTICK_LEFT   (1 << 6)
 
#define D_JOYSTICK_UP_LEFT   (1 << 7)
 
#define JOYSTICK_THRESHOLD   (10000)
 This is the sensitivity threshold for the directional pad of a cheap digital joypad on the PC. More...
 

Functions

static int Color_cycling (void)
 
int Has_shortcut (word function)
 Returns true if the function has any shortcut key. More...
 
int Is_shortcut (word key, word function)
 Returns true if the keycode has been set as a keyboard shortcut for the function. More...
 
int Move_cursor_with_constraints (int x, int y)
 Called each time there is a cursor move, either triggered by mouse or keyboard shortcuts. More...
 
int Handle_mouse_btn_change (void)
 
int Handle_special_key_press (void)
 check Keys that emulate mouse moves, etc. More...
 
int Release_control (int key_code, int modifier)
 
static int Cursor_displace (int step, long delta_x, long delta_y)
 Attempts to move the mouse cursor by the given deltas. More...
 
int Directional_acceleration (int msec)
 
static void Mouse_Emulation ()
 Emulate mouse move with Joystick or specific keys. More...
 
int Get_input (int sleep_time)
 This is the keyboard/mouse/joystick input polling function. More...
 
void Adjust_mouse_sensitivity (word fullscreen)
 Adjust mouse sensitivity (and actual mouse input mode) More...
 

Variables

int Input_sticky_control = 0
 This holds the ID of the GUI control that the mouse is manipulating. More...
 
int Snap_axis = 0
 Allows locking movement to X or Y axis: 0=normal, 1=lock on next move, 2=locked horizontally, 3=locked vertically. More...
 
int Snap_axis_origin_X
 For the :Snap_axis mode, sets the origin's point (in image coordinates) More...
 
int Snap_axis_origin_Y
 For the :Snap_axis mode, sets the origin's point (in image coordinates) More...
 
char * Drop_file_name = NULL
 This malloced string is set when a drag-and-drop event brings a file to Grafx2's window. More...
 
wordDrop_file_name_unicode = NULL
 
static byte Directional_click = 0
 
static byte Digital_joystick_state = 0
 
static byte Directional_emulated
 
word Input_new_mouse_X
 
word Input_new_mouse_Y
 
word Input_new_mouse_X_frac
 
word Input_new_mouse_Y_frac
 
byte Input_new_mouse_K
 
byte Button_inverter =0
 
long Directional_first_move
 
long Directional_last_move
 
int Mouse_moved
 Boolean, Set to true if any cursor movement occurs. More...
 
byte Pan_shortcut_pressed
 State of the shortcut for panning (SPECIAL_HOLD_PAN) : pressed or not. More...
 
short Joybutton_shift =-1
 A button that is marked as "modifier" will. More...
 
short Joybutton_control =-1
 Button number that serves as a "ctrl" modifier; -1 for none. More...
 
short Joybutton_alt =-1
 Button number that serves as a "alt" modifier; -1 for none. More...
 
short Joybutton_left_click =0
 Button number that serves as left click; -1 for none. More...
 
short Joybutton_right_click =1
 Button number that serves as right-click; -1 for none. More...
 

Macro Definition Documentation

◆ PAD_MAX_SPEED

#define PAD_MAX_SPEED   3

◆ D_JOYSTICK_UP

#define D_JOYSTICK_UP   (1 << 0)

◆ D_JOYSTICK_UP_RIGHT

#define D_JOYSTICK_UP_RIGHT   (1 << 1)

◆ D_JOYSTICK_RIGHT

#define D_JOYSTICK_RIGHT   (1 << 2)

◆ D_JOYSTICK_DOWN_RIGHT

#define D_JOYSTICK_DOWN_RIGHT   (1 << 3)

◆ D_JOYSTICK_DOWN

#define D_JOYSTICK_DOWN   (1 << 4)

◆ D_JOYSTICK_DOWN_LEFT

#define D_JOYSTICK_DOWN_LEFT   (1 << 5)

◆ D_JOYSTICK_LEFT

#define D_JOYSTICK_LEFT   (1 << 6)

◆ D_JOYSTICK_UP_LEFT

#define D_JOYSTICK_UP_LEFT   (1 << 7)

◆ JOYSTICK_THRESHOLD

#define JOYSTICK_THRESHOLD   (10000)

This is the sensitivity threshold for the directional pad of a cheap digital joypad on the PC.

It has been set through trial and error : If value is too large then the movement is randomly interrupted; if the value is too low the cursor will move by itself, controlled by parasits. YR 04/11/2010: I just observed a -8700 when joystick is idle.

Function Documentation

◆ Color_cycling()

◆ Has_shortcut()

int Has_shortcut ( word  function)

Returns true if the function has any shortcut key.

References Buttons_Pool, Config_Key, and KEY_NONE.

◆ Is_shortcut()

◆ Move_cursor_with_constraints()

int Move_cursor_with_constraints ( int  x,
int  y 
)

Called each time there is a cursor move, either triggered by mouse or keyboard shortcuts.

Parameters
xnew cursor X coordinate
ynew cursor Y coordinate
Returns
feedback

References Config, Current_operation, Hide_cursor, Input_new_mouse_X, Input_new_mouse_Y, T_Document::magnifier_mode, Main, Menu_Y, Mouse_K_unique, T_Config::Mouse_merge_movement, Mouse_moved, Mouse_X, Mouse_Y, Operation, Operation_in_magnifier, Operation_stack_size, Screen_height, Screen_width, T_Document::separator_position, Set_mouse_position(), and T_Document::X_zoom.

Referenced by Cursor_displace(), Get_input(), and Win32_WindowProc().

◆ Handle_mouse_btn_change()

◆ Handle_special_key_press()

◆ Release_control()

◆ Cursor_displace()

static int Cursor_displace ( int  step,
long  delta_x,
long  delta_y 
)
static

Attempts to move the mouse cursor by the given deltas.

Parameters
stepmove multiply factor
delta_x16.16 fixed point value
delta_y16.16 fixed point value
Returns
feedback

References Input_new_mouse_X, Input_new_mouse_X_frac, Input_new_mouse_Y, Input_new_mouse_Y_frac, T_Document::magnifier_factor, T_Document::magnifier_mode, Main, Move_cursor_with_constraints(), Screen_height, Screen_width, and T_Document::separator_position.

Referenced by Mouse_Emulation().

◆ Directional_acceleration()

int Directional_acceleration ( int  msec)

Referenced by Mouse_Emulation().

◆ Mouse_Emulation()

◆ Get_input()

int Get_input ( int  sleep_time)

This is the keyboard/mouse/joystick input polling function.

Returns 1 if a significant changed occurred, such as a mouse button pressed or depressed, or a new keypress was in the keyboard buffer. The latest input variables are held in Key, Key_ANSI, Key_UNICODE, Mouse_X, Mouse_Y, Mouse_K. Note that Key, Key_ANSI and Key_UNICODE are not persistent, they will be reset to 0 on subsequent calls to Get_input().

References Button_inverter, Color_cycling(), Compute_paintbrush_coordinates(), Config, Display_cursor(), Drop_file_name, Flush_update(), format, Get_Key_modifiers(), GFX2_DEBUG, GFX2_ERROR, GFX2_INFO, GFX2_Log(), GFX2_WARNING, GFX2_WINDOW_MAXIMIZED, GFX2_WINDOW_MINIMIZED, GFX2_WINDOW_STANDARD, Handle_mouse_btn_change(), Handle_special_key_press(), Input_new_mouse_K, Input_new_mouse_X, Input_new_mouse_Y, Key, Key_ANSI, KEY_MOUSEMIDDLE, KEY_MOUSEWHEELDOWN, KEY_MOUSEWHEELUP, Key_UNICODE, Mouse_Emulation(), Mouse_K, T_Config::Mouse_motion_debounce, Mouse_moved, Mouse_X, Mouse_Y, Move_cursor_with_constraints(), NULL, Pixel_height, Pixel_width, Quit_is_required, Release_control(), render_scale_x, render_scale_y, Resize_height, Resize_width, Update_rect(), user_feedback_required, T_Config::Window_pos_x, T_Config::Window_pos_y, Window_state, X11_display, and X11_window.

Referenced by Button_Anim_continuous_next(), Button_Anim_continuous_prev(), Button_Message_initial(), Button_Select_backcolor(), Button_Select_forecolor(), Curve_3_points_0_5(), Delay_with_active_mouse(), Dropdown_activate(), Get_color_behind_window(), GFX2_GetTextClipboard(), Load_ClipBoard_Image(), Main_handler(), Move_separator(), Move_window(), Readline_ex_unicode(), Redefine_control(), Tilemap_update(), Wait_click_in_palette(), Wait_click_in_shade_table(), Wait_end_of_click(), Window_clicked_button(), and Window_normal_button_onclick().

◆ Adjust_mouse_sensitivity()

void Adjust_mouse_sensitivity ( word  fullscreen)

Adjust mouse sensitivity (and actual mouse input mode)

Referenced by Init_mode_video().

Variable Documentation

◆ Input_sticky_control

int Input_sticky_control = 0

This holds the ID of the GUI control that the mouse is manipulating.

The input system will reset it to zero when mouse button is released, but it's the engine that will record and retrieve a real control ID.

Referenced by Button_Effects(), Button_Gradients(), Button_Palette(), Handle_mouse_btn_change(), Readline_ex_unicode(), Window_clicked_button(), and Window_get_clicked_button().

◆ Snap_axis

int Snap_axis = 0

Allows locking movement to X or Y axis: 0=normal, 1=lock on next move, 2=locked horizontally, 3=locked vertically.

Referenced by Compute_paintbrush_coordinates(), and Release_control().

◆ Snap_axis_origin_X

int Snap_axis_origin_X

For the :Snap_axis mode, sets the origin's point (in image coordinates)

Referenced by Compute_paintbrush_coordinates().

◆ Snap_axis_origin_Y

int Snap_axis_origin_Y

For the :Snap_axis mode, sets the origin's point (in image coordinates)

Referenced by Compute_paintbrush_coordinates().

◆ Drop_file_name

char* Drop_file_name = NULL

This malloced string is set when a drag-and-drop event brings a file to Grafx2's window.

Referenced by Get_input(), Main_handler(), and Win32_WindowProc().

◆ Drop_file_name_unicode

word* Drop_file_name_unicode = NULL

Referenced by Main_handler(), and Win32_WindowProc().

◆ Directional_click

byte Directional_click = 0
static

◆ Digital_joystick_state

byte Digital_joystick_state = 0
static

Referenced by Mouse_Emulation().

◆ Directional_emulated

byte Directional_emulated
static

◆ Input_new_mouse_X

word Input_new_mouse_X

◆ Input_new_mouse_Y

word Input_new_mouse_Y

◆ Input_new_mouse_X_frac

word Input_new_mouse_X_frac

Referenced by Cursor_displace().

◆ Input_new_mouse_Y_frac

word Input_new_mouse_Y_frac

Referenced by Cursor_displace().

◆ Input_new_mouse_K

◆ Button_inverter

byte Button_inverter =0

Referenced by Get_input(), and Release_control().

◆ Directional_first_move

long Directional_first_move

Referenced by Mouse_Emulation().

◆ Directional_last_move

long Directional_last_move

Referenced by Mouse_Emulation().

◆ Mouse_moved

int Mouse_moved

Boolean, Set to true if any cursor movement occurs.

Referenced by Get_input(), Handle_mouse_btn_change(), and Move_cursor_with_constraints().

◆ Pan_shortcut_pressed

byte Pan_shortcut_pressed

State of the shortcut for panning (SPECIAL_HOLD_PAN) : pressed or not.

Referenced by Handle_special_key_press(), Main_handler(), Pan_view_0_0(), Pan_view_0_2(), and Release_control().

◆ Joybutton_shift

short Joybutton_shift =-1

A button that is marked as "modifier" will.

Button number that serves as a "shift" modifier; -1 for none

◆ Joybutton_control

short Joybutton_control =-1

Button number that serves as a "ctrl" modifier; -1 for none.

◆ Joybutton_alt

short Joybutton_alt =-1

Button number that serves as a "alt" modifier; -1 for none.

◆ Joybutton_left_click

short Joybutton_left_click =0

Button number that serves as left click; -1 for none.

◆ Joybutton_right_click

short Joybutton_right_click =1

Button number that serves as right-click; -1 for none.