mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
Treat left/right mouse as keys too, so hotkeys can be bound to them
This commit is contained in:
parent
d82b40bb0b
commit
9505a8c373
@ -559,9 +559,9 @@ static void Game_Render3D(double delta, float t) {
|
|||||||
Selections_Render(delta);
|
Selections_Render(delta);
|
||||||
Entities_RenderHoveredNames(delta);
|
Entities_RenderHoveredNames(delta);
|
||||||
|
|
||||||
left = InputHandler_IsMousePressed(MOUSE_LEFT);
|
left = KeyBind_IsPressed(KEYBIND_DELETE_BLOCK);
|
||||||
middle = KeyBind_IsPressed(KEYBIND_PICK_BLOCK);
|
middle = KeyBind_IsPressed(KEYBIND_PICK_BLOCK);
|
||||||
right = InputHandler_IsMousePressed(MOUSE_RIGHT);
|
right = KeyBind_IsPressed(KEYBIND_PLACE_BLOCK);
|
||||||
|
|
||||||
InputHandler_PickBlocks(true, left, middle, right);
|
InputHandler_PickBlocks(true, left, middle, right);
|
||||||
if (!Game_HideGui) HeldBlockRenderer_Render(delta);
|
if (!Game_HideGui) HeldBlockRenderer_Render(delta);
|
||||||
|
21
src/Input.c
21
src/Input.c
@ -42,7 +42,7 @@ const char* const Key_Names[KEY_COUNT] = {
|
|||||||
"KeypadAdd", "KeypadDecimal", "KeypadEnter",
|
"KeypadAdd", "KeypadDecimal", "KeypadEnter",
|
||||||
"Tilde", "Minus", "Plus", "BracketLeft", "BracketRight", "Slash",
|
"Tilde", "Minus", "Plus", "BracketLeft", "BracketRight", "Slash",
|
||||||
"Semicolon", "Quote", "Comma", "Period", "BackSlash",
|
"Semicolon", "Quote", "Comma", "Period", "BackSlash",
|
||||||
"XButton1", "XButton2", "MouseMid"
|
"XButton1", "XButton2", "LeftMouse", "RightMouse", "MiddleMouse"
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TODO: Should this only be shown in GUI? not saved to disc? */
|
/* TODO: Should this only be shown in GUI? not saved to disc? */
|
||||||
@ -64,7 +64,7 @@ const char* const Key_Names[KEY_COUNT] = {
|
|||||||
"5", "6", "7", "8", "9",
|
"5", "6", "7", "8", "9",
|
||||||
"GRAVE", "MINUS", "PLUS", "LBRACKET", "RBRACKET",
|
"GRAVE", "MINUS", "PLUS", "LBRACKET", "RBRACKET",
|
||||||
"SEMICOLON", "APOSTROPHE", "COMMA", "PERIOD", "SLASH", "BACKSLASH",
|
"SEMICOLON", "APOSTROPHE", "COMMA", "PERIOD", "SLASH", "BACKSLASH",
|
||||||
"XBUTTON1", "XBUTTON2", "MOUSEMID"
|
"XBUTTON1", "XBUTTON2", "MMOUSE"
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
void Key_SetPressed(Key key, bool pressed) {
|
void Key_SetPressed(Key key, bool pressed) {
|
||||||
@ -76,6 +76,10 @@ void Key_SetPressed(Key key, bool pressed) {
|
|||||||
} else if (wasPressed) {
|
} else if (wasPressed) {
|
||||||
Event_RaiseInt(&KeyEvents.Up, key);
|
Event_RaiseInt(&KeyEvents.Up, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* don't allow multiple left mouse down events */
|
||||||
|
if (key != KEY_LMOUSE || pressed == wasPressed) return;
|
||||||
|
Mouse_SetPressed(pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Key_Clear(void) {
|
void Key_Clear(void) {
|
||||||
@ -93,14 +97,11 @@ float Mouse_Wheel;
|
|||||||
int Mouse_X, Mouse_Y;
|
int Mouse_X, Mouse_Y;
|
||||||
bool Mouse_Pressed[MOUSE_COUNT];
|
bool Mouse_Pressed[MOUSE_COUNT];
|
||||||
|
|
||||||
void Mouse_SetPressed(MouseButton btn, bool pressed) {
|
void Mouse_SetPressed(bool pressed) {
|
||||||
if (Mouse_Pressed[btn] == pressed) return;
|
|
||||||
Mouse_Pressed[btn] = pressed;
|
|
||||||
|
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
Event_RaiseInt(&MouseEvents.Down, btn);
|
Event_RaiseInt(&MouseEvents.Down, MOUSE_LEFT);
|
||||||
} else {
|
} else {
|
||||||
Event_RaiseInt(&MouseEvents.Up, btn);
|
Event_RaiseInt(&MouseEvents.Up, MOUSE_LEFT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ const cc_uint8 KeyBind_Defaults[KEYBIND_COUNT] = {
|
|||||||
KEY_LSHIFT, 'X', 'Z', 'Q', 'E',
|
KEY_LSHIFT, 'X', 'Z', 'Q', 'E',
|
||||||
KEY_LALT, KEY_F3, KEY_F12, KEY_F11,
|
KEY_LALT, KEY_F3, KEY_F12, KEY_F11,
|
||||||
KEY_F5, KEY_F1, KEY_F7, 'C',
|
KEY_F5, KEY_F1, KEY_F7, 'C',
|
||||||
KEY_LCTRL, 0, KEY_MOUSEMID, 0,
|
KEY_LCTRL, KEY_LMOUSE, KEY_MMOUSE, KEY_RMOUSE,
|
||||||
KEY_F6, KEY_LALT, KEY_F8,
|
KEY_F6, KEY_LALT, KEY_F8,
|
||||||
'G', KEY_F10, 0
|
'G', KEY_F10, 0
|
||||||
};
|
};
|
||||||
@ -139,7 +140,7 @@ static const char* const keybindNames[KEYBIND_COUNT] = {
|
|||||||
"Speed", "NoClip", "Fly", "FlyUp", "FlyDown",
|
"Speed", "NoClip", "Fly", "FlyUp", "FlyDown",
|
||||||
"ExtInput", "HideFPS", "Screenshot", "Fullscreen",
|
"ExtInput", "HideFPS", "Screenshot", "Fullscreen",
|
||||||
"ThirdPerson", "HideGUI", "AxisLines", "ZoomScrolling",
|
"ThirdPerson", "HideGUI", "AxisLines", "ZoomScrolling",
|
||||||
"HalfSpeed", "MouseLeft", "PickBlock", "MouseRight",
|
"HalfSpeed", "DeleteBlock", "PickBlock", "PlaceBlock",
|
||||||
"AutoRotate", "HotbarSwitching", "SmoothCamera",
|
"AutoRotate", "HotbarSwitching", "SmoothCamera",
|
||||||
"DropBlock", "IDOverlay", "BreakableLiquids"
|
"DropBlock", "IDOverlay", "BreakableLiquids"
|
||||||
};
|
};
|
||||||
|
12
src/Input.h
12
src/Input.h
@ -39,7 +39,8 @@ enum Key_ {
|
|||||||
KEY_TILDE, KEY_MINUS, KEY_EQUALS, KEY_LBRACKET, KEY_RBRACKET, KEY_SLASH,
|
KEY_TILDE, KEY_MINUS, KEY_EQUALS, KEY_LBRACKET, KEY_RBRACKET, KEY_SLASH,
|
||||||
KEY_SEMICOLON, KEY_QUOTE, KEY_COMMA, KEY_PERIOD, KEY_BACKSLASH,
|
KEY_SEMICOLON, KEY_QUOTE, KEY_COMMA, KEY_PERIOD, KEY_BACKSLASH,
|
||||||
|
|
||||||
KEY_XBUTTON1, KEY_XBUTTON2, KEY_MOUSEMID, /* so these can be used for hotkeys */
|
/* NOTE: RMOUSE must be before MMOUSE for PlayerClick compatibility */
|
||||||
|
KEY_XBUTTON1, KEY_XBUTTON2, KEY_LMOUSE, KEY_RMOUSE, KEY_MMOUSE,
|
||||||
KEY_COUNT
|
KEY_COUNT
|
||||||
};
|
};
|
||||||
typedef int Key;
|
typedef int Key;
|
||||||
@ -81,11 +82,8 @@ extern float Mouse_Wheel;
|
|||||||
/* X and Y coordinates of the mouse. Use Mouse_SetPosition to change. */
|
/* X and Y coordinates of the mouse. Use Mouse_SetPosition to change. */
|
||||||
extern int Mouse_X, Mouse_Y;
|
extern int Mouse_X, Mouse_Y;
|
||||||
|
|
||||||
/* Pressed state of each mouse button. Use Mouse_SetPressed to change. */
|
/* Raises MouseEvents.Up or MouseEvents.Down. */
|
||||||
extern bool Mouse_Pressed[MOUSE_COUNT];
|
void Mouse_SetPressed(bool pressed);
|
||||||
/* Sets the pressed state of a mouse button. */
|
|
||||||
/* Raises MouseEvents.Up or MouseEvents.Down if state differs. */
|
|
||||||
void Mouse_SetPressed(MouseButton btn, bool pressed);
|
|
||||||
/* Sets wheel position of the mouse, always raising MouseEvents.Wheel. */
|
/* Sets wheel position of the mouse, always raising MouseEvents.Wheel. */
|
||||||
void Mouse_SetWheel(float wheel);
|
void Mouse_SetWheel(float wheel);
|
||||||
/* Sets X and Y position of the mouse, always raising MouseEvents.Moved. */
|
/* Sets X and Y position of the mouse, always raising MouseEvents.Moved. */
|
||||||
@ -100,7 +98,7 @@ enum KeyBind_ {
|
|||||||
KEYBIND_SPEED, KEYBIND_NOCLIP, KEYBIND_FLY, KEYBIND_FLY_UP, KEYBIND_FLY_DOWN,
|
KEYBIND_SPEED, KEYBIND_NOCLIP, KEYBIND_FLY, KEYBIND_FLY_UP, KEYBIND_FLY_DOWN,
|
||||||
KEYBIND_EXT_INPUT, KEYBIND_HIDE_FPS, KEYBIND_SCREENSHOT, KEYBIND_FULLSCREEN,
|
KEYBIND_EXT_INPUT, KEYBIND_HIDE_FPS, KEYBIND_SCREENSHOT, KEYBIND_FULLSCREEN,
|
||||||
KEYBIND_THIRD_PERSON, KEYBIND_HIDE_GUI, KEYBIND_AXIS_LINES, KEYBIND_ZOOM_SCROLL,
|
KEYBIND_THIRD_PERSON, KEYBIND_HIDE_GUI, KEYBIND_AXIS_LINES, KEYBIND_ZOOM_SCROLL,
|
||||||
KEYBIND_HALF_SPEED, KEYBIND_MOUSE_LEFT, KEYBIND_PICK_BLOCK, KEYBIND_MOUSE_RIGHT,
|
KEYBIND_HALF_SPEED, KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK,
|
||||||
KEYBIND_AUTOROTATE, KEYBIND_HOTBAR_SWITCH, KEYBIND_SMOOTH_CAMERA,
|
KEYBIND_AUTOROTATE, KEYBIND_HOTBAR_SWITCH, KEYBIND_SMOOTH_CAMERA,
|
||||||
KEYBIND_DROP_BLOCK, KEYBIND_IDOVERLAY, KEYBIND_BREAK_LIQUIDS,
|
KEYBIND_DROP_BLOCK, KEYBIND_IDOVERLAY, KEYBIND_BREAK_LIQUIDS,
|
||||||
KEYBIND_COUNT
|
KEYBIND_COUNT
|
||||||
|
@ -30,15 +30,6 @@ static float input_fovIndex = -1.0f;
|
|||||||
static bool suppressEscape;
|
static bool suppressEscape;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool InputHandler_IsMousePressed(MouseButton button) {
|
|
||||||
if (Mouse_Pressed[button]) return true;
|
|
||||||
|
|
||||||
/* Key --> mouse mappings */
|
|
||||||
if (button == MOUSE_LEFT && KeyBind_IsPressed(KEYBIND_MOUSE_LEFT)) return true;
|
|
||||||
if (button == MOUSE_RIGHT && KeyBind_IsPressed(KEYBIND_MOUSE_RIGHT)) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void InputHandler_ButtonStateUpdate(MouseButton button, bool pressed) {
|
static void InputHandler_ButtonStateUpdate(MouseButton button, bool pressed) {
|
||||||
struct Entity* p;
|
struct Entity* p;
|
||||||
/* defer getting the targeted entity, as it's a costly operation */
|
/* defer getting the targeted entity, as it's a costly operation */
|
||||||
@ -200,6 +191,10 @@ static bool InputHandler_HandleCoreKey(Key key) {
|
|||||||
} else {
|
} else {
|
||||||
InputHandler_CycleDistanceForwards(viewDists, count);
|
InputHandler_CycleDistanceForwards(viewDists, count);
|
||||||
}
|
}
|
||||||
|
} else if (key == KeyBinds[KEYBIND_DELETE_BLOCK]) {
|
||||||
|
InputHandler_PickBlocks(false, true, false, false);
|
||||||
|
} else if (key == KeyBinds[KEYBIND_PLACE_BLOCK]) {
|
||||||
|
InputHandler_PickBlocks(false, false, false, true);
|
||||||
} else if (key == KeyBinds[KEYBIND_PICK_BLOCK]) {
|
} else if (key == KeyBinds[KEYBIND_PICK_BLOCK]) {
|
||||||
InputHandler_PickBlocks(false, false, true, false);
|
InputHandler_PickBlocks(false, false, true, false);
|
||||||
} else if (key == KEY_F5 && Game_ClassicMode) {
|
} else if (key == KEY_F5 && Game_ClassicMode) {
|
||||||
@ -332,7 +327,7 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (left) {
|
if (left) {
|
||||||
/* always play delete animations, even if we aren't picking a block */
|
/* always play delete animations, even if we aren't deleting a block */
|
||||||
HeldBlockRenderer_ClickAnim(true);
|
HeldBlockRenderer_ClickAnim(true);
|
||||||
|
|
||||||
pos = Game_SelectedPos.BlockPos;
|
pos = Game_SelectedPos.BlockPos;
|
||||||
@ -408,8 +403,6 @@ static void InputHandler_MouseDown(void* obj, int btn) {
|
|||||||
input_lastClick = DateTime_CurrentUTC_MS(); return;
|
input_lastClick = DateTime_CurrentUTC_MS(); return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler_PickBlocks(false, btn == MOUSE_LEFT, false, btn == MOUSE_RIGHT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InputHandler_MouseUp(void* obj, int btn) {
|
static void InputHandler_MouseUp(void* obj, int btn) {
|
||||||
@ -420,23 +413,6 @@ static void InputHandler_MouseUp(void* obj, int btn) {
|
|||||||
s = Gui_Screens[i];
|
s = Gui_Screens[i];
|
||||||
if (s->VTABLE->HandlesMouseUp(s, Mouse_X, Mouse_Y, btn)) return;
|
if (s->VTABLE->HandlesMouseUp(s, Mouse_X, Mouse_Y, btn)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Server.SupportsPlayerClick && btn <= MOUSE_MIDDLE) {
|
|
||||||
input_pickingId = -1;
|
|
||||||
InputHandler_ButtonStateChanged(btn, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool InputHandler_SimulateMouse(Key key, bool pressed) {
|
|
||||||
Key left = KeyBinds[KEYBIND_MOUSE_LEFT];
|
|
||||||
Key right = KeyBinds[KEYBIND_MOUSE_RIGHT];
|
|
||||||
MouseButton btn;
|
|
||||||
if (!(key == left || key == right)) return false;
|
|
||||||
|
|
||||||
btn = key == left ? MOUSE_LEFT : MOUSE_RIGHT;
|
|
||||||
if (pressed) { InputHandler_MouseDown(NULL, btn); }
|
|
||||||
else { InputHandler_MouseUp(NULL, btn); }
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InputHandler_KeyDown(void* obj, int key, bool was) {
|
static void InputHandler_KeyDown(void* obj, int key, bool was) {
|
||||||
@ -445,7 +421,6 @@ static void InputHandler_KeyDown(void* obj, int key, bool was) {
|
|||||||
struct HotkeyData* hkey;
|
struct HotkeyData* hkey;
|
||||||
String text;
|
String text;
|
||||||
|
|
||||||
if (!was && InputHandler_SimulateMouse(key, true)) return;
|
|
||||||
#ifndef CC_BUILD_WEB
|
#ifndef CC_BUILD_WEB
|
||||||
if (key == KEY_ESCAPE && (s = Gui_GetClosable())) {
|
if (key == KEY_ESCAPE && (s = Gui_GetClosable())) {
|
||||||
/* Don't want holding down escape to go in and out of pause menu */
|
/* Don't want holding down escape to go in and out of pause menu */
|
||||||
@ -478,6 +453,11 @@ static void InputHandler_KeyDown(void* obj, int key, bool was) {
|
|||||||
PauseScreen_Show(); return;
|
PauseScreen_Show(); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Server.SupportsPlayerClick && key >= KEY_LMOUSE && key <= KEY_MMOUSE) {
|
||||||
|
input_pickingId = -1;
|
||||||
|
InputHandler_ButtonStateChanged(key - KEY_LMOUSE, true);
|
||||||
|
}
|
||||||
|
|
||||||
/* These should not be triggered multiple times when holding down */
|
/* These should not be triggered multiple times when holding down */
|
||||||
if (was) return;
|
if (was) return;
|
||||||
if (InputHandler_HandleCoreKey(key)) {
|
if (InputHandler_HandleCoreKey(key)) {
|
||||||
@ -501,9 +481,7 @@ static void InputHandler_KeyUp(void* obj, int key) {
|
|||||||
struct Screen* s;
|
struct Screen* s;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (InputHandler_SimulateMouse(key, false)) return;
|
|
||||||
if (key == KeyBinds[KEYBIND_ZOOM_SCROLL]) Game_SetFov(Game_DefaultFov);
|
if (key == KeyBinds[KEYBIND_ZOOM_SCROLL]) Game_SetFov(Game_DefaultFov);
|
||||||
|
|
||||||
#ifdef CC_BUILD_WEB
|
#ifdef CC_BUILD_WEB
|
||||||
/* When closing menus (which reacquires mouse focus) in key down, */
|
/* When closing menus (which reacquires mouse focus) in key down, */
|
||||||
/* this still leaves the cursor visible. But if this is instead */
|
/* this still leaves the cursor visible. But if this is instead */
|
||||||
@ -518,6 +496,11 @@ static void InputHandler_KeyUp(void* obj, int key) {
|
|||||||
s = Gui_Screens[i];
|
s = Gui_Screens[i];
|
||||||
if (s->VTABLE->HandlesKeyUp(s, key)) return;
|
if (s->VTABLE->HandlesKeyUp(s, key)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Server.SupportsPlayerClick && key >= KEY_LMOUSE && key <= KEY_MMOUSE) {
|
||||||
|
input_pickingId = -1;
|
||||||
|
InputHandler_ButtonStateChanged(key - KEY_LMOUSE, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InputHandler_KeyPress(void* obj, int keyChar) {
|
static void InputHandler_KeyPress(void* obj, int keyChar) {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
struct Screen;
|
struct Screen;
|
||||||
|
|
||||||
bool InputHandler_IsMousePressed(MouseButton button);
|
|
||||||
bool InputHandler_SetFOV(int fov);
|
bool InputHandler_SetFOV(int fov);
|
||||||
void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right);
|
void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right);
|
||||||
void InputHandler_Init(void);
|
void InputHandler_Init(void);
|
||||||
|
@ -122,7 +122,7 @@ static int Menu_DoMouseDown(void* screen, int x, int y, MouseButton btn) {
|
|||||||
if (!w || !Widget_Contains(w, x, y)) continue;
|
if (!w || !Widget_Contains(w, x, y)) continue;
|
||||||
if (w->disabled) return i;
|
if (w->disabled) return i;
|
||||||
|
|
||||||
if (w->MenuClick && btn == MOUSE_LEFT) {
|
if (w->MenuClick) {
|
||||||
w->MenuClick(s, w);
|
w->MenuClick(s, w);
|
||||||
} else {
|
} else {
|
||||||
Elem_HandlesMouseDown(w, x, y, btn);
|
Elem_HandlesMouseDown(w, x, y, btn);
|
||||||
@ -1753,13 +1753,13 @@ void OtherKeyBindingsScreen_Show(void) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void MouseKeyBindingsScreen_Init(struct KeyBindingsScreen* s) {
|
static void MouseKeyBindingsScreen_Init(struct KeyBindingsScreen* s) {
|
||||||
s->leftPage = Menu_SwitchKeysOther;
|
s->leftPage = Menu_SwitchKeysOther;
|
||||||
s->msgText = "&eRight click to remove the key binding";
|
s->msgText = "&ePress escape to reset the binding";
|
||||||
KeyBindingsScreen_InitWidgets(s, -40, 10, -1, 260, "Mouse key bindings");
|
KeyBindingsScreen_InitWidgets(s, -40, 10, -1, 260, "Mouse key bindings");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseKeyBindingsScreen_Show(void) {
|
void MouseKeyBindingsScreen_Show(void) {
|
||||||
static const cc_uint8 binds[3] = { KEYBIND_MOUSE_LEFT, KEYBIND_PICK_BLOCK, KEYBIND_MOUSE_RIGHT };
|
static const cc_uint8 binds[3] = { KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK };
|
||||||
static const char* descs[3] = { "Left", "Pick block", "Right" };
|
static const char* descs[3] = { "Delete block", "Pick block", "Place block" };
|
||||||
KeyBindingsScreen_Show(Array_Elems(binds), binds, descs, MouseKeyBindingsScreen_Init);
|
KeyBindingsScreen_Show(Array_Elems(binds), binds, descs, MouseKeyBindingsScreen_Init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ static bool InventoryScreen_MouseDown(void* screen, int x, int y, MouseButton bt
|
|||||||
if (table->scroll.draggingMouse || Elem_HandlesMouseDown(&hud->hotbar, x, y, btn)) return true;
|
if (table->scroll.draggingMouse || Elem_HandlesMouseDown(&hud->hotbar, x, y, btn)) return true;
|
||||||
handled = Elem_HandlesMouseDown(table, x, y, btn);
|
handled = Elem_HandlesMouseDown(table, x, y, btn);
|
||||||
|
|
||||||
if ((!handled || table->pendingClose) && btn == MOUSE_LEFT) {
|
if (!handled || table->pendingClose) {
|
||||||
hotbar = Key_IsControlPressed() || Key_IsShiftPressed();
|
hotbar = Key_IsControlPressed() || Key_IsShiftPressed();
|
||||||
if (!hotbar) Gui_Remove(screen);
|
if (!hotbar) Gui_Remove(screen);
|
||||||
}
|
}
|
||||||
@ -1091,7 +1091,7 @@ static bool HUDScreen_MouseDown(void* screen, int x, int y, MouseButton btn) {
|
|||||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||||
int height, chatY;
|
int height, chatY;
|
||||||
|
|
||||||
if (btn != MOUSE_LEFT || !s->grabsInput) return false;
|
if (!s->grabsInput) return false;
|
||||||
|
|
||||||
/* player clicks on name in tab list */
|
/* player clicks on name in tab list */
|
||||||
/* TODO: Move to PlayerListWidget */
|
/* TODO: Move to PlayerListWidget */
|
||||||
@ -1354,8 +1354,6 @@ static bool DisconnectScreen_MouseDown(void* screen, int x, int y, MouseButton b
|
|||||||
struct DisconnectScreen* s = (struct DisconnectScreen*)screen;
|
struct DisconnectScreen* s = (struct DisconnectScreen*)screen;
|
||||||
struct ButtonWidget* w = &s->reconnect;
|
struct ButtonWidget* w = &s->reconnect;
|
||||||
|
|
||||||
if (btn != MOUSE_LEFT) return true;
|
|
||||||
|
|
||||||
if (!w->disabled && Widget_Contains(w, x, y)) {
|
if (!w->disabled && Widget_Contains(w, x, y)) {
|
||||||
Gui_Remove((struct Screen*)s);
|
Gui_Remove((struct Screen*)s);
|
||||||
Gui_ShowDefault();
|
Gui_ShowDefault();
|
||||||
|
@ -244,7 +244,6 @@ static bool ScrollbarWidget_MouseDown(void* widget, int x, int y, MouseButton bt
|
|||||||
int posY, height;
|
int posY, height;
|
||||||
|
|
||||||
if (w->draggingMouse) return true;
|
if (w->draggingMouse) return true;
|
||||||
if (btn != MOUSE_LEFT) return false;
|
|
||||||
if (x < w->x || x >= w->x + w->width) return false;
|
if (x < w->x || x >= w->x + w->width) return false;
|
||||||
|
|
||||||
y -= w->y;
|
y -= w->y;
|
||||||
@ -441,7 +440,7 @@ static bool HotbarWidget_MouseDown(void* widget, int x, int y, MouseButton btn)
|
|||||||
int width, height;
|
int width, height;
|
||||||
int i, cellX, cellY;
|
int i, cellX, cellY;
|
||||||
|
|
||||||
if (btn != MOUSE_LEFT || !Widget_Contains(w, x, y)) return false;
|
if (!Widget_Contains(w, x, y)) return false;
|
||||||
|
|
||||||
width = (int)(w->elemSize + w->borderSize);
|
width = (int)(w->elemSize + w->borderSize);
|
||||||
height = Math_Ceil(w->barHeight);
|
height = Math_Ceil(w->barHeight);
|
||||||
@ -704,7 +703,6 @@ static void TableWidget_ScrollRelative(struct TableWidget* w, int delta) {
|
|||||||
static bool TableWidget_MouseDown(void* widget, int x, int y, MouseButton btn) {
|
static bool TableWidget_MouseDown(void* widget, int x, int y, MouseButton btn) {
|
||||||
struct TableWidget* w = (struct TableWidget*)widget;
|
struct TableWidget* w = (struct TableWidget*)widget;
|
||||||
w->pendingClose = false;
|
w->pendingClose = false;
|
||||||
if (btn != MOUSE_LEFT) return false;
|
|
||||||
|
|
||||||
if (Elem_HandlesMouseDown(&w->scroll, x, y, btn)) {
|
if (Elem_HandlesMouseDown(&w->scroll, x, y, btn)) {
|
||||||
return true;
|
return true;
|
||||||
@ -1191,9 +1189,7 @@ static bool InputWidget_MouseDown(void* widget, int x, int y, MouseButton button
|
|||||||
int cx, cy, offset = 0;
|
int cx, cy, offset = 0;
|
||||||
int charX, charWidth, charHeight;
|
int charX, charWidth, charHeight;
|
||||||
|
|
||||||
if (button != MOUSE_LEFT) return true;
|
|
||||||
x -= w->inputTex.X; y -= w->inputTex.Y;
|
x -= w->inputTex.X; y -= w->inputTex.Y;
|
||||||
|
|
||||||
DrawTextArgs_MakeEmpty(&args, w->font, true);
|
DrawTextArgs_MakeEmpty(&args, w->font, true);
|
||||||
charHeight = w->lineHeight;
|
charHeight = w->lineHeight;
|
||||||
String_InitArray(line, lineBuffer);
|
String_InitArray(line, lineBuffer);
|
||||||
|
58
src/Window.c
58
src/Window.c
@ -105,7 +105,7 @@ static void Window_AddTouch(long id, int x, int y) {
|
|||||||
touchesCount++;
|
touchesCount++;
|
||||||
|
|
||||||
Mouse_SetPosition(x, y);
|
Mouse_SetPosition(x, y);
|
||||||
Mouse_SetPressed(MOUSE_LEFT, true);
|
Key_SetPressed(KEY_LMOUSE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Window_UpdateTouch(long id, int x, int y) {
|
static void Window_UpdateTouch(long id, int x, int y) {
|
||||||
@ -136,7 +136,7 @@ static void Window_RemoveTouch(long id, int x, int y) {
|
|||||||
|
|
||||||
touchesCount--;
|
touchesCount--;
|
||||||
Mouse_SetPosition(x, y);
|
Mouse_SetPosition(x, y);
|
||||||
Mouse_SetPressed(MOUSE_LEFT, false);
|
Key_SetPressed(KEY_LMOUSE, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -266,9 +266,9 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||||||
|
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
/* Set before position change, in case mouse buttons changed when outside window */
|
/* Set before position change, in case mouse buttons changed when outside window */
|
||||||
Mouse_SetPressed(MOUSE_LEFT, (wParam & 0x01) != 0);
|
Key_SetPressed(KEY_LMOUSE, (wParam & 0x01) != 0);
|
||||||
Mouse_SetPressed(MOUSE_RIGHT, (wParam & 0x02) != 0);
|
Key_SetPressed(KEY_RMOUSE, (wParam & 0x02) != 0);
|
||||||
Key_SetPressed(KEY_MOUSEMID, (wParam & 0x10) != 0);
|
Key_SetPressed(KEY_MMOUSE, (wParam & 0x10) != 0);
|
||||||
/* TODO: do we need to set XBUTTON1/XBUTTON2 here */
|
/* TODO: do we need to set XBUTTON1/XBUTTON2 here */
|
||||||
Mouse_SetPosition(LOWORD(lParam), HIWORD(lParam));
|
Mouse_SetPosition(LOWORD(lParam), HIWORD(lParam));
|
||||||
break;
|
break;
|
||||||
@ -279,21 +279,21 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
Mouse_SetPressed(MOUSE_LEFT, true); break;
|
Key_SetPressed(KEY_LMOUSE, true); break;
|
||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
Key_SetPressed(KEY_MOUSEMID, true); break;
|
Key_SetPressed(KEY_MMOUSE, true); break;
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
Mouse_SetPressed(MOUSE_RIGHT, true); break;
|
Key_SetPressed(KEY_RMOUSE, true); break;
|
||||||
case WM_XBUTTONDOWN:
|
case WM_XBUTTONDOWN:
|
||||||
Key_SetPressed(HIWORD(wParam) == 1 ? KEY_XBUTTON1 : KEY_XBUTTON2, true);
|
Key_SetPressed(HIWORD(wParam) == 1 ? KEY_XBUTTON1 : KEY_XBUTTON2, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
Mouse_SetPressed(MOUSE_LEFT, false); break;
|
Key_SetPressed(KEY_LMOUSE, false); break;
|
||||||
case WM_MBUTTONUP:
|
case WM_MBUTTONUP:
|
||||||
Key_SetPressed(KEY_MOUSEMID, false); break;
|
Key_SetPressed(KEY_MMOUSE, false); break;
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
Mouse_SetPressed(MOUSE_RIGHT, false); break;
|
Key_SetPressed(KEY_RMOUSE, false); break;
|
||||||
case WM_XBUTTONUP:
|
case WM_XBUTTONUP:
|
||||||
Key_SetPressed(HIWORD(wParam) == 1 ? KEY_XBUTTON1 : KEY_XBUTTON2, false);
|
Key_SetPressed(HIWORD(wParam) == 1 ? KEY_XBUTTON1 : KEY_XBUTTON2, false);
|
||||||
break;
|
break;
|
||||||
@ -1096,9 +1096,9 @@ void Window_ProcessEvents(void) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
if (e.xbutton.button == 1) Mouse_SetPressed(MOUSE_LEFT, true);
|
if (e.xbutton.button == 1) Key_SetPressed(KEY_LMOUSE, true);
|
||||||
else if (e.xbutton.button == 2) Key_SetPressed(KEY_MOUSEMID, true);
|
else if (e.xbutton.button == 2) Key_SetPressed(KEY_MMOUSE, true);
|
||||||
else if (e.xbutton.button == 3) Mouse_SetPressed(MOUSE_RIGHT, true);
|
else if (e.xbutton.button == 3) Key_SetPressed(KEY_RMOUSE, true);
|
||||||
else if (e.xbutton.button == 4) Mouse_SetWheel(Mouse_Wheel + 1);
|
else if (e.xbutton.button == 4) Mouse_SetWheel(Mouse_Wheel + 1);
|
||||||
else if (e.xbutton.button == 5) Mouse_SetWheel(Mouse_Wheel - 1);
|
else if (e.xbutton.button == 5) Mouse_SetWheel(Mouse_Wheel - 1);
|
||||||
else if (e.xbutton.button == 6) Key_SetPressed(KEY_XBUTTON1, true);
|
else if (e.xbutton.button == 6) Key_SetPressed(KEY_XBUTTON1, true);
|
||||||
@ -1106,9 +1106,9 @@ void Window_ProcessEvents(void) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
if (e.xbutton.button == 1) Mouse_SetPressed(MOUSE_LEFT, false);
|
if (e.xbutton.button == 1) Key_SetPressed(KEY_LMOUSE, false);
|
||||||
else if (e.xbutton.button == 2) Key_SetPressed(KEY_MOUSEMID, false);
|
else if (e.xbutton.button == 2) Key_SetPressed(KEY_MMOUSE, false);
|
||||||
else if (e.xbutton.button == 3) Mouse_SetPressed(MOUSE_RIGHT, false);
|
else if (e.xbutton.button == 3) Key_SetPressed(KEY_RMOUSE, false);
|
||||||
else if (e.xbutton.button == 6) Key_SetPressed(KEY_XBUTTON1, false);
|
else if (e.xbutton.button == 6) Key_SetPressed(KEY_XBUTTON1, false);
|
||||||
else if (e.xbutton.button == 7) Key_SetPressed(KEY_XBUTTON2, false);
|
else if (e.xbutton.button == 7) Key_SetPressed(KEY_XBUTTON2, false);
|
||||||
break;
|
break;
|
||||||
@ -1657,11 +1657,11 @@ static OSStatus Window_ProcessMouseEvent(EventRef inEvent) {
|
|||||||
|
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case kEventMouseButtonPrimary:
|
case kEventMouseButtonPrimary:
|
||||||
Mouse_SetPressed(MOUSE_LEFT, down); break;
|
Key_SetPressed(KEY_LMOUSE, down); break;
|
||||||
case kEventMouseButtonSecondary:
|
case kEventMouseButtonSecondary:
|
||||||
Mouse_SetPressed(MOUSE_RIGHT, down); break;
|
Key_SetPressed(KEY_RMOUSE, down); break;
|
||||||
case kEventMouseButtonTertiary:
|
case kEventMouseButtonTertiary:
|
||||||
Key_SetPressed(KEY_MOUSEMID, down); break;
|
Key_SetPressed(KEY_MMOUSE, down); break;
|
||||||
}
|
}
|
||||||
return eventNotHandledErr;
|
return eventNotHandledErr;
|
||||||
|
|
||||||
@ -2224,11 +2224,11 @@ static void Window_HandleMouseEvent(const SDL_Event* e) {
|
|||||||
bool pressed = e->button.state == SDL_PRESSED;
|
bool pressed = e->button.state == SDL_PRESSED;
|
||||||
switch (e->button.button) {
|
switch (e->button.button) {
|
||||||
case SDL_BUTTON_LEFT:
|
case SDL_BUTTON_LEFT:
|
||||||
Mouse_SetPressed(MOUSE_LEFT, pressed); break;
|
Key_SetPressed(KEY_LMOUSE, pressed); break;
|
||||||
case SDL_BUTTON_MIDDLE:
|
case SDL_BUTTON_MIDDLE:
|
||||||
Key_SetPressed(KEY_MOUSEMID, pressed); break;
|
Key_SetPressed(KEY_MMOUSE, pressed); break;
|
||||||
case SDL_BUTTON_RIGHT:
|
case SDL_BUTTON_RIGHT:
|
||||||
Mouse_SetPressed(MOUSE_RIGHT, pressed); break;
|
Key_SetPressed(KEY_RMOUSE, pressed); break;
|
||||||
case SDL_BUTTON_X1:
|
case SDL_BUTTON_X1:
|
||||||
Key_SetPressed(KEY_XBUTTON1, pressed); break;
|
Key_SetPressed(KEY_XBUTTON1, pressed); break;
|
||||||
case SDL_BUTTON_X2:
|
case SDL_BUTTON_X2:
|
||||||
@ -2407,18 +2407,18 @@ static EM_BOOL Window_MouseButton(int type, const EmscriptenMouseEvent* ev, void
|
|||||||
Window_CorrectFocus();
|
Window_CorrectFocus();
|
||||||
|
|
||||||
switch (ev->button) {
|
switch (ev->button) {
|
||||||
case 0: Mouse_SetPressed(MOUSE_LEFT, down); break;
|
case 0: Key_SetPressed(KEY_LMOUSE, down); break;
|
||||||
case 1: Input_SetPressed(KEY_MOUSEMID, down); break;
|
case 1: Key_SetPressed(KEY_MMOUSE, down); break;
|
||||||
case 2: Mouse_SetPressed(MOUSE_RIGHT, down); break;
|
case 2: Key_SetPressed(KEY_RMOUSE, down); break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static EM_BOOL Window_MouseMove(int type, const EmscriptenMouseEvent* ev, void* data) {
|
static EM_BOOL Window_MouseMove(int type, const EmscriptenMouseEvent* ev, void* data) {
|
||||||
/* Set before position change, in case mouse buttons changed when outside window */
|
/* Set before position change, in case mouse buttons changed when outside window */
|
||||||
Mouse_SetPressed(MOUSE_LEFT, (ev->buttons & 0x01) != 0);
|
Key_SetPressed(KEY_LMOUSE, (ev->buttons & 0x01) != 0);
|
||||||
Mouse_SetPressed(MOUSE_RIGHT, (ev->buttons & 0x02) != 0);
|
Key_SetPressed(KEY_RMOUSE, (ev->buttons & 0x02) != 0);
|
||||||
Input_SetPressed(KEY_MOUSEMID, (ev->buttons & 0x04) != 0);
|
Key_SetPressed(KEY_MMOUSE, (ev->buttons & 0x04) != 0);
|
||||||
|
|
||||||
Mouse_SetPosition(ev->canvasX, ev->canvasY);
|
Mouse_SetPosition(ev->canvasX, ev->canvasY);
|
||||||
if (win_rawMouse) Event_RaiseMouseMove(&MouseEvents.RawMoved, ev->movementX, ev->movementY);
|
if (win_rawMouse) Event_RaiseMouseMove(&MouseEvents.RawMoved, ev->movementX, ev->movementY);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user