Experimental work on mouse locking with shift (issue 193). Consider unstable.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@921 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
c596b80b8d
commit
7fc318a856
21
input.c
21
input.c
@ -31,7 +31,14 @@
|
|||||||
void Handle_window_resize(SDL_ResizeEvent event);
|
void Handle_window_resize(SDL_ResizeEvent event);
|
||||||
void Handle_window_exit(SDL_QuitEvent event);
|
void Handle_window_exit(SDL_QuitEvent event);
|
||||||
|
|
||||||
|
// public Globals (available as extern)
|
||||||
|
|
||||||
int Input_sticky_control = 0;
|
int Input_sticky_control = 0;
|
||||||
|
int Snap_axis = 0;
|
||||||
|
int Snap_axis_origin_X;
|
||||||
|
int Snap_axis_origin_Y;
|
||||||
|
|
||||||
|
// --
|
||||||
|
|
||||||
byte Directional_up;
|
byte Directional_up;
|
||||||
byte Directional_up_right;
|
byte Directional_up_right;
|
||||||
@ -357,6 +364,14 @@ int Handle_key_press(SDL_KeyboardEvent event)
|
|||||||
|
|
||||||
int Release_control(int key_code, int modifier)
|
int Release_control(int key_code, int modifier)
|
||||||
{
|
{
|
||||||
|
int need_feedback = 0;
|
||||||
|
|
||||||
|
if (modifier == MOD_SHIFT)
|
||||||
|
{
|
||||||
|
// Disable "snap axis" mode
|
||||||
|
Snap_axis = 0;
|
||||||
|
need_feedback = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_UP][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_UP][0]&modifier) ||
|
if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_UP][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_UP][0]&modifier) ||
|
||||||
(key_code && key_code == (Config_Key[SPECIAL_MOUSE_UP][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_UP][1]&modifier))
|
(key_code && key_code == (Config_Key[SPECIAL_MOUSE_UP][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_UP][1]&modifier))
|
||||||
@ -385,7 +400,7 @@ int Release_control(int key_code, int modifier)
|
|||||||
{
|
{
|
||||||
Directional_click &= ~1;
|
Directional_click &= ~1;
|
||||||
Input_new_mouse_K &= ~1;
|
Input_new_mouse_K &= ~1;
|
||||||
return Move_cursor_with_constraints();
|
return Move_cursor_with_constraints() || need_feedback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((key_code && key_code == (Config_Key[SPECIAL_CLICK_RIGHT][0]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_RIGHT][0]&modifier) ||
|
if((key_code && key_code == (Config_Key[SPECIAL_CLICK_RIGHT][0]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_RIGHT][0]&modifier) ||
|
||||||
@ -395,14 +410,14 @@ int Release_control(int key_code, int modifier)
|
|||||||
{
|
{
|
||||||
Directional_click &= ~2;
|
Directional_click &= ~2;
|
||||||
Input_new_mouse_K &= ~2;
|
Input_new_mouse_K &= ~2;
|
||||||
return Move_cursor_with_constraints();
|
return Move_cursor_with_constraints() || need_feedback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other keys don't need to be released : they are handled as "events" and procesed only once.
|
// 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)
|
// These clicks are apart because they need to be continuous (ie move while key pressed)
|
||||||
// We are relying on "hardware" keyrepeat to achieve that.
|
// We are relying on "hardware" keyrepeat to achieve that.
|
||||||
return 0;
|
return need_feedback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
9
input.h
9
input.h
@ -46,4 +46,11 @@ void Set_mouse_position(void);
|
|||||||
/// is manipulating. The input system will reset it to zero
|
/// is manipulating. The input system will reset it to zero
|
||||||
/// when mouse button is released, but it's the engine
|
/// when mouse button is released, but it's the engine
|
||||||
/// that will record and retrieve a real control ID.
|
/// that will record and retrieve a real control ID.
|
||||||
extern int Input_sticky_control;
|
extern int Input_sticky_control;
|
||||||
|
|
||||||
|
/// 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)
|
||||||
|
extern int Snap_axis_origin_X;
|
||||||
|
/// For the :Snap_axis mode, sets the origin's point (in image coordinates)
|
||||||
|
extern int Snap_axis_origin_Y;
|
||||||
|
|||||||
41
windows.c
41
windows.c
@ -32,6 +32,7 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "sdlscreen.h"
|
#include "sdlscreen.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
// L'encapsulation tente une percée...ou un dernier combat.
|
// L'encapsulation tente une percée...ou un dernier combat.
|
||||||
|
|
||||||
@ -1275,6 +1276,46 @@ void Compute_paintbrush_coordinates(void)
|
|||||||
Paintbrush_X=(((Paintbrush_X+(Snap_width>>1)-Snap_offset_X)/Snap_width)*Snap_width)+Snap_offset_X;
|
Paintbrush_X=(((Paintbrush_X+(Snap_width>>1)-Snap_offset_X)/Snap_width)*Snap_width)+Snap_offset_X;
|
||||||
Paintbrush_Y=(((Paintbrush_Y+(Snap_height>>1)-Snap_offset_Y)/Snap_height)*Snap_height)+Snap_offset_Y;
|
Paintbrush_Y=(((Paintbrush_Y+(Snap_height>>1)-Snap_offset_Y)/Snap_height)*Snap_height)+Snap_offset_Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handling the snap axis mode, when shift is pressed.
|
||||||
|
switch (Current_operation)
|
||||||
|
{
|
||||||
|
// Operations that don't implement it
|
||||||
|
case OPERATION_LINE:
|
||||||
|
Snap_axis=0;
|
||||||
|
break;
|
||||||
|
// Operations that implement it
|
||||||
|
default:
|
||||||
|
if (Snap_axis==0 && (SDL_GetModState() & KMOD_SHIFT))
|
||||||
|
{
|
||||||
|
// Start "Snap axis" mode
|
||||||
|
Snap_axis=1;
|
||||||
|
Snap_axis_origin_X=Paintbrush_X;
|
||||||
|
Snap_axis_origin_Y=Paintbrush_Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Snap_axis==1)
|
||||||
|
{
|
||||||
|
// Cursor moved
|
||||||
|
if (Paintbrush_X != Snap_axis_origin_X || Paintbrush_Y != Snap_axis_origin_Y)
|
||||||
|
{
|
||||||
|
if ((Paintbrush_X-Snap_axis_origin_X)*(Paintbrush_X-Snap_axis_origin_X) >
|
||||||
|
(Paintbrush_Y-Snap_axis_origin_Y)*(Paintbrush_Y-Snap_axis_origin_Y))
|
||||||
|
// Displacement was bigger on X axis: lock Y
|
||||||
|
Snap_axis=2;
|
||||||
|
else
|
||||||
|
Snap_axis=3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Snap_axis==2)
|
||||||
|
{
|
||||||
|
Paintbrush_Y = Snap_axis_origin_Y;
|
||||||
|
}
|
||||||
|
else if (Snap_axis==3)
|
||||||
|
{
|
||||||
|
Paintbrush_X = Snap_axis_origin_X;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user