mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-11 16:45:48 -04:00
Eliminate Mouse_X/Y completely, start work on new keybinding changed event
This commit is contained in:
parent
e26e9887d2
commit
9e7d19bfd1
14
src/Event.c
14
src/Event.c
@ -143,13 +143,6 @@ void Event_RaiseBlock(struct Event_Block* handlers, IVec3 coords, BlockID oldBlo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event_RaiseMove(struct Event_PointerMove* handlers, int idx, int xDelta, int yDelta) {
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < handlers->Count; i++) {
|
|
||||||
handlers->Handlers[i](handlers->Objs[i], idx, xDelta, yDelta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Event_RaiseChat(struct Event_Chat* handlers, const cc_string* msg, int msgType) {
|
void Event_RaiseChat(struct Event_Chat* handlers, const cc_string* msg, int msgType) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < handlers->Count; i++) {
|
for (i = 0; i < handlers->Count; i++) {
|
||||||
@ -177,3 +170,10 @@ void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDel
|
|||||||
handlers->Handlers[i](handlers->Objs[i], xDelta, yDelta);
|
handlers->Handlers[i](handlers->Objs[i], xDelta, yDelta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Event_RaiseBind(struct Event_Bind* handlers, int binding, int pressed) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < handlers->Count; i++) {
|
||||||
|
handlers->Handlers[i](handlers->Objs[i], binding, pressed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
26
src/Event.h
26
src/Event.h
@ -39,12 +39,6 @@ struct Event_Block {
|
|||||||
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
|
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*Event_PointerMove_Callback)(void* obj, int idx, int xDelta, int yDelta);
|
|
||||||
struct Event_PointerMove {
|
|
||||||
Event_PointerMove_Callback Handlers[EVENT_MAX_CALLBACKS];
|
|
||||||
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void (*Event_Chat_Callback)(void* obj, const cc_string* msg, int msgType);
|
typedef void (*Event_Chat_Callback)(void* obj, const cc_string* msg, int msgType);
|
||||||
struct Event_Chat {
|
struct Event_Chat {
|
||||||
Event_Chat_Callback Handlers[EVENT_MAX_CALLBACKS];
|
Event_Chat_Callback Handlers[EVENT_MAX_CALLBACKS];
|
||||||
@ -69,6 +63,12 @@ struct Event_RawMove {
|
|||||||
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
|
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (*Event_Bind_Callback)(void* obj, int binding, int pressed);
|
||||||
|
struct Event_Bind {
|
||||||
|
Event_Bind_Callback Handlers[EVENT_MAX_CALLBACKS];
|
||||||
|
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
|
||||||
|
};
|
||||||
|
|
||||||
/* Registers a callback function for the given event. */
|
/* Registers a callback function for the given event. */
|
||||||
/* NOTE: Trying to register a callback twice or over EVENT_MAX_CALLBACKS callbacks will terminate the game. */
|
/* NOTE: Trying to register a callback twice or over EVENT_MAX_CALLBACKS callbacks will terminate the game. */
|
||||||
CC_API void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
CC_API void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
||||||
@ -90,8 +90,6 @@ void Event_RaiseEntry(struct Event_Entry* handlers, struct Stream* stream, const
|
|||||||
/* Calls all registered callbacks for an event which takes block change arguments. */
|
/* Calls all registered callbacks for an event which takes block change arguments. */
|
||||||
/* These are the coordinates/location of the change, block there before, block there now. */
|
/* These are the coordinates/location of the change, block there before, block there now. */
|
||||||
void Event_RaiseBlock(struct Event_Block* handlers, IVec3 coords, BlockID oldBlock, BlockID block);
|
void Event_RaiseBlock(struct Event_Block* handlers, IVec3 coords, BlockID oldBlock, BlockID block);
|
||||||
/* Calls all registered callbacks for an event which has pointer movement arguments. */
|
|
||||||
void Event_RaiseMove(struct Event_PointerMove* handlers, int idx, int xDelta, int yDelta);
|
|
||||||
/* Calls all registered callbacks for an event which has chat message type and contents. */
|
/* Calls all registered callbacks for an event which has chat message type and contents. */
|
||||||
/* See MsgType enum in Chat.h for what types of messages there are. */
|
/* See MsgType enum in Chat.h for what types of messages there are. */
|
||||||
void Event_RaiseChat(struct Event_Chat* handlers, const cc_string* msg, int msgType);
|
void Event_RaiseChat(struct Event_Chat* handlers, const cc_string* msg, int msgType);
|
||||||
@ -102,6 +100,8 @@ void Event_RaiseInput(struct Event_Input* handlers, int key, cc_bool repeating);
|
|||||||
void Event_RaiseString(struct Event_String* handlers, const cc_string* str);
|
void Event_RaiseString(struct Event_String* handlers, const cc_string* str);
|
||||||
/* Calls all registered callbacks for an event which has raw pointer movement arguments. */
|
/* Calls all registered callbacks for an event which has raw pointer movement arguments. */
|
||||||
void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDelta);
|
void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDelta);
|
||||||
|
/* Calls all registered callbacks for an event which has key binding arguments. */
|
||||||
|
void Event_RaiseBind(struct Event_Bind* handlers, int binding, int pressed);
|
||||||
|
|
||||||
void Event_UnregisterAll(void);
|
void Event_UnregisterAll(void);
|
||||||
/* NOTE: Event_UnregisterAll must be updated if events lists are changed */
|
/* NOTE: Event_UnregisterAll must be updated if events lists are changed */
|
||||||
@ -172,14 +172,14 @@ CC_VAR extern struct _InputEventsList {
|
|||||||
struct Event_Int Up; /* Key or button is released. Arg is a member of Key enumeration */
|
struct Event_Int Up; /* Key or button is released. Arg is a member of Key enumeration */
|
||||||
struct Event_Float Wheel; /* Mouse wheel is moved/scrolled (Arg is wheel delta) */
|
struct Event_Float Wheel; /* Mouse wheel is moved/scrolled (Arg is wheel delta) */
|
||||||
struct Event_String TextChanged; /* Text in the on-screen input keyboard changed (for Mobile) */
|
struct Event_String TextChanged; /* Text in the on-screen input keyboard changed (for Mobile) */
|
||||||
struct Event_Int BindChanged; /* Key binding changed. Arg is a member of KeyBind enumeration*/
|
struct Event_Bind BindChanged; /* Key binding changed. Arg is a member of KeyBind enumeration*/
|
||||||
} InputEvents;
|
} InputEvents;
|
||||||
|
|
||||||
CC_VAR extern struct _PointerEventsList {
|
CC_VAR extern struct _PointerEventsList {
|
||||||
struct Event_PointerMove Moved; /* Pointer position changed (Arg is delta from last position) */
|
struct Event_Int Moved; /* Pointer position changed (Arg is index) */
|
||||||
struct Event_Int Down; /* Left mouse or touch is pressed (Arg is index) */
|
struct Event_Int Down; /* Left mouse or touch is pressed (Arg is index) */
|
||||||
struct Event_Int Up; /* Left mouse or touch is released (Arg is index) */
|
struct Event_Int Up; /* Left mouse or touch is released (Arg is index) */
|
||||||
struct Event_RawMove RawMoved; /* Raw pointer position changed (Arg is delta) */
|
struct Event_RawMove RawMoved; /* Raw pointer position changed (Arg is delta) */
|
||||||
} PointerEvents;
|
} PointerEvents;
|
||||||
|
|
||||||
CC_VAR extern struct _NetEventsList {
|
CC_VAR extern struct _NetEventsList {
|
||||||
|
@ -265,7 +265,6 @@ void Input_Clear(void) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*----------------------------------------------------------Mouse----------------------------------------------------------*
|
*----------------------------------------------------------Mouse----------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
int Mouse_X, Mouse_Y;
|
|
||||||
struct Pointer Pointers[INPUT_MAX_POINTERS];
|
struct Pointer Pointers[INPUT_MAX_POINTERS];
|
||||||
cc_bool Input_RawMode;
|
cc_bool Input_RawMode;
|
||||||
|
|
||||||
@ -282,8 +281,6 @@ void Mouse_ScrollWheel(float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Pointer_SetPosition(int idx, int x, int y) {
|
void Pointer_SetPosition(int idx, int x, int y) {
|
||||||
int deltaX = x - Mouse_X, deltaY = y - Mouse_Y;
|
|
||||||
Mouse_X = x; Mouse_Y = y;
|
|
||||||
if (x == Pointers[idx].x && y == Pointers[idx].y) return;
|
if (x == Pointers[idx].x && y == Pointers[idx].y) return;
|
||||||
/* TODO: reset to -1, -1 when pointer is removed */
|
/* TODO: reset to -1, -1 when pointer is removed */
|
||||||
Pointers[idx].x = x; Pointers[idx].y = y;
|
Pointers[idx].x = x; Pointers[idx].y = y;
|
||||||
@ -291,7 +288,7 @@ void Pointer_SetPosition(int idx, int x, int y) {
|
|||||||
#ifdef CC_BUILD_TOUCH
|
#ifdef CC_BUILD_TOUCH
|
||||||
if (Input_TouchMode && !(touches[idx].type & TOUCH_TYPE_GUI)) return;
|
if (Input_TouchMode && !(touches[idx].type & TOUCH_TYPE_GUI)) return;
|
||||||
#endif
|
#endif
|
||||||
Event_RaiseMove(&PointerEvents.Moved, idx, deltaX, deltaY);
|
Event_RaiseInt(&PointerEvents.Moved, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -358,7 +355,7 @@ static void KeyBind_Save(void) {
|
|||||||
void KeyBind_Set(KeyBind binding, int key) {
|
void KeyBind_Set(KeyBind binding, int key) {
|
||||||
KeyBinds[binding] = key;
|
KeyBinds[binding] = key;
|
||||||
KeyBind_Save();
|
KeyBind_Save();
|
||||||
Event_RaiseInt(&InputEvents.BindChanged, binding);
|
Event_RaiseBind(&InputEvents.BindChanged, binding, KeyBind_IsPressed(binding));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialises and loads key bindings from options */
|
/* Initialises and loads key bindings from options */
|
||||||
@ -964,7 +961,7 @@ static void OnMouseWheel(void* obj, float delta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnPointerMove(void* obj, int idx, int xDelta, int yDelta) {
|
static void OnPointerMove(void* obj, int idx) {
|
||||||
struct Screen* s;
|
struct Screen* s;
|
||||||
int i, x = Pointers[idx].x, y = Pointers[idx].y;
|
int i, x = Pointers[idx].x, y = Pointers[idx].y;
|
||||||
|
|
||||||
|
@ -95,9 +95,6 @@ void Input_RemoveTouch(long id, int x, int y);
|
|||||||
|
|
||||||
/* Data for mouse and touch */
|
/* Data for mouse and touch */
|
||||||
extern struct Pointer { int x, y; } Pointers[INPUT_MAX_POINTERS];
|
extern struct Pointer { int x, y; } Pointers[INPUT_MAX_POINTERS];
|
||||||
/* (OBSOLETE) X and Y coordinates of the mouse. Use Mouse_SetPosition to change. */
|
|
||||||
extern int Mouse_X, Mouse_Y;
|
|
||||||
|
|
||||||
/* Raises InputEvents.Wheel with the given wheel delta. */
|
/* Raises InputEvents.Wheel with the given wheel delta. */
|
||||||
void Mouse_ScrollWheel(float delta);
|
void Mouse_ScrollWheel(float delta);
|
||||||
/* Sets X and Y position of the given pointer, always raising PointerEvents.Moved. */
|
/* Sets X and Y position of the given pointer, always raising PointerEvents.Moved. */
|
||||||
|
@ -147,7 +147,7 @@ static void LScreen_MouseUp(struct LScreen* s, int idx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LScreen_MouseMove(struct LScreen* s, int idx, int deltaX, int deltaY) {
|
static void LScreen_MouseMove(struct LScreen* s, int idx) {
|
||||||
struct LWidget* over = LScreen_WidgetAt(s, idx);
|
struct LWidget* over = LScreen_WidgetAt(s, idx);
|
||||||
struct LWidget* prev = s->hoveredWidget;
|
struct LWidget* prev = s->hoveredWidget;
|
||||||
cc_bool overSame = prev == over;
|
cc_bool overSame = prev == over;
|
||||||
|
@ -21,7 +21,7 @@ typedef void (*LWidget_Func)(struct LScreen* s, struct LWidget* w);
|
|||||||
void (*KeyPress)(struct LScreen* s, char c); \
|
void (*KeyPress)(struct LScreen* s, char c); \
|
||||||
void (*MouseDown)(struct LScreen* s, int idx); \
|
void (*MouseDown)(struct LScreen* s, int idx); \
|
||||||
void (*MouseUp)(struct LScreen* s, int idx); \
|
void (*MouseUp)(struct LScreen* s, int idx); \
|
||||||
void (*MouseMove)(struct LScreen* s, int idx, int deltaX, int deltaY); \
|
void (*MouseMove)(struct LScreen* s, int idx); \
|
||||||
void (*MouseWheel)(struct LScreen* s, float delta); \
|
void (*MouseWheel)(struct LScreen* s, float delta); \
|
||||||
void (*TextChanged)(struct LScreen* s, const cc_string* str); \
|
void (*TextChanged)(struct LScreen* s, const cc_string* str); \
|
||||||
LWidget_Func HoverWidget; /* Called when mouse is moved over a given widget. */ \
|
LWidget_Func HoverWidget; /* Called when mouse is moved over a given widget. */ \
|
||||||
|
@ -52,7 +52,7 @@ void Launcher_SetScreen(struct LScreen* screen) {
|
|||||||
screen->Layout(screen);
|
screen->Layout(screen);
|
||||||
/* for hovering over active button etc */
|
/* for hovering over active button etc */
|
||||||
for (i = 0; i < Pointers_Count; i++) {
|
for (i = 0; i < Pointers_Count; i++) {
|
||||||
screen->MouseMove(screen, i, 0, 0);
|
screen->MouseMove(screen, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
Launcher_Redraw();
|
Launcher_Redraw();
|
||||||
@ -219,9 +219,9 @@ static void OnPointerUp(void* obj, int idx) {
|
|||||||
activeScreen->MouseUp(activeScreen, idx);
|
activeScreen->MouseUp(activeScreen, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnPointerMove(void* obj, int idx, int deltaX, int deltaY) {
|
static void OnPointerMove(void* obj, int idx) {
|
||||||
if (!activeScreen) return;
|
if (!activeScreen) return;
|
||||||
activeScreen->MouseMove(activeScreen, idx, deltaX, deltaY);
|
activeScreen->MouseMove(activeScreen, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user