Don't keep track of mouse wheel position because we only ever care about the delta anyways

This commit is contained in:
UnknownShadow200 2019-09-22 08:56:14 +10:00
parent d167b227da
commit cde36cc0f2
5 changed files with 28 additions and 33 deletions

View File

@ -125,7 +125,6 @@ void Key_Clear(void) {
/*########################################################################################################################* /*########################################################################################################################*
*----------------------------------------------------------Mouse----------------------------------------------------------* *----------------------------------------------------------Mouse----------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
float Mouse_Wheel;
int Mouse_X, Mouse_Y; int Mouse_X, Mouse_Y;
struct Pointer Pointers[INPUT_MAX_POINTERS]; struct Pointer Pointers[INPUT_MAX_POINTERS];
bool Input_RawMode, Input_TouchMode; bool Input_RawMode, Input_TouchMode;
@ -138,9 +137,7 @@ void Pointer_SetPressed(int idx, bool pressed) {
} }
} }
void Mouse_SetWheel(float wheel) { void Mouse_ScrollWheel(float delta) {
float delta = wheel - Mouse_Wheel;
Mouse_Wheel = wheel;
Event_RaiseFloat(&InputEvents.Wheel, delta); Event_RaiseFloat(&InputEvents.Wheel, delta);
} }

View File

@ -72,8 +72,6 @@ void Input_SetPressed(Key key, bool pressed);
void Key_Clear(void); void Key_Clear(void);
typedef int MouseButton; typedef int MouseButton;
/* Wheel position of the mouse. Use Mouse_SetWheel to change. */
extern float Mouse_Wheel;
/* Whether raw mouse/touch input is being listened for. */ /* Whether raw mouse/touch input is being listened for. */
extern bool Input_RawMode; extern bool Input_RawMode;
/* Whether touch input is being used. */ /* Whether touch input is being used. */
@ -98,8 +96,8 @@ extern int Mouse_X, Mouse_Y;
/* Raises PointerEvents.Up or PointerEvents.Down. */ /* Raises PointerEvents.Up or PointerEvents.Down. */
void Pointer_SetPressed(int idx, bool pressed); void Pointer_SetPressed(int idx, bool pressed);
/* Sets wheel position of the mouse, always raising InputEvents.Wheel. */ /* Raises InputEvents.Wheel with the given wheel delta. */
void Mouse_SetWheel(float wheel); 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. */
void Pointer_SetPosition(int idx, int x, int y); void Pointer_SetPosition(int idx, int x, int y);

View File

@ -1248,7 +1248,7 @@ static void Hex_Default(struct MenuInputDesc* d, String* value) {
PackedCol_ToHex(value, d->meta.h.Default); PackedCol_ToHex(value, d->meta.h.Default);
} }
const struct MenuInputVTABLE HexValidator_VTABLE = { const struct MenuInputVTABLE HexInput_VTABLE = {
Hex_Range, Hex_ValidChar, Hex_ValidString, Hex_ValidValue, Hex_Default Hex_Range, Hex_ValidChar, Hex_ValidString, Hex_ValidValue, Hex_Default
}; };
@ -1275,7 +1275,7 @@ static void Int_Default(struct MenuInputDesc* d, String* value) {
String_AppendInt(value, d->meta.i.Default); String_AppendInt(value, d->meta.i.Default);
} }
const struct MenuInputVTABLE IntValidator_VTABLE = { const struct MenuInputVTABLE IntInput_VTABLE = {
Int_Range, Int_ValidChar, Int_ValidString, Int_ValidValue, Int_Default Int_Range, Int_ValidChar, Int_ValidString, Int_ValidValue, Int_Default
}; };
@ -1284,7 +1284,7 @@ static void Seed_Range(struct MenuInputDesc* d, String* range) {
} }
static void Seed_NoDefault(struct MenuInputDesc* d, String* value) { } static void Seed_NoDefault(struct MenuInputDesc* d, String* value) { }
const struct MenuInputVTABLE SeedValidator_VTABLE = { const struct MenuInputVTABLE SeedInput_VTABLE = {
Seed_Range, Int_ValidChar, Int_ValidString, Int_ValidValue, Seed_NoDefault Seed_Range, Int_ValidChar, Int_ValidString, Int_ValidValue, Seed_NoDefault
}; };
@ -1311,7 +1311,7 @@ static void Float_Default(struct MenuInputDesc* d, String* value) {
String_AppendFloat(value, d->meta.f.Default, 3); String_AppendFloat(value, d->meta.f.Default, 3);
} }
const struct MenuInputVTABLE FloatValidator_VTABLE = { const struct MenuInputVTABLE FloatInput_VTABLE = {
Float_Range, Float_ValidChar, Float_ValidString, Float_ValidValue, Float_Default Float_Range, Float_ValidChar, Float_ValidString, Float_ValidValue, Float_Default
}; };
@ -1325,7 +1325,7 @@ static bool Path_ValidChar(struct MenuInputDesc* d, char c) {
} }
static bool Path_ValidString(struct MenuInputDesc* d, const String* s) { return true; } static bool Path_ValidString(struct MenuInputDesc* d, const String* s) { return true; }
const struct MenuInputVTABLE PathValidator_VTABLE = { const struct MenuInputVTABLE PathInput_VTABLE = {
Path_Range, Path_ValidChar, Path_ValidString, Path_ValidString, Seed_NoDefault Path_Range, Path_ValidChar, Path_ValidString, Path_ValidString, Seed_NoDefault
}; };
@ -1341,7 +1341,7 @@ static bool String_ValidString(struct MenuInputDesc* d, const String* s) {
return s->length <= STRING_SIZE; return s->length <= STRING_SIZE;
} }
const struct MenuInputVTABLE StringValidator_VTABLE = { const struct MenuInputVTABLE StringInput_VTABLE = {
String_Range, String_ValidChar, String_ValidString, String_ValidString, Seed_NoDefault String_Range, String_ValidChar, String_ValidString, String_ValidString, Seed_NoDefault
}; };

View File

@ -157,20 +157,20 @@ struct MenuInputDesc {
} meta; } meta;
}; };
extern const struct MenuInputVTABLE HexValidator_VTABLE; extern const struct MenuInputVTABLE HexInput_VTABLE;
extern const struct MenuInputVTABLE IntValidator_VTABLE; extern const struct MenuInputVTABLE IntInput_VTABLE;
extern const struct MenuInputVTABLE SeedValidator_VTABLE; extern const struct MenuInputVTABLE SeedInput_VTABLE;
extern const struct MenuInputVTABLE FloatValidator_VTABLE; extern const struct MenuInputVTABLE FloatInput_VTABLE;
extern const struct MenuInputVTABLE PathValidator_VTABLE; extern const struct MenuInputVTABLE PathInput_VTABLE;
extern const struct MenuInputVTABLE StringValidator_VTABLE; extern const struct MenuInputVTABLE StringInput_VTABLE;
#define MenuInput_Hex(v, def) v.VTABLE = &HexValidator_VTABLE; v.meta.h.Default = def; #define MenuInput_Hex(v, def) v.VTABLE = &HexInput_VTABLE; v.meta.h.Default = def;
#define MenuInput_Int(v, lo, hi, def) v.VTABLE = &IntValidator_VTABLE; v.meta.i.Min = lo; v.meta.i.Max = hi; v.meta.i.Default = def; #define MenuInput_Int(v, lo, hi, def) v.VTABLE = &IntInput_VTABLE; v.meta.i.Min = lo; v.meta.i.Max = hi; v.meta.i.Default = def;
#define MenuInput_Seed(v) v.VTABLE = &SeedValidator_VTABLE; v.meta.i.Min = Int32_MinValue; v.meta.i.Max = Int32_MaxValue; #define MenuInput_Seed(v) v.VTABLE = &SeedInput_VTABLE; v.meta.i.Min = Int32_MinValue; v.meta.i.Max = Int32_MaxValue;
#define MenuInput_Float(v, lo, hi, def) v.VTABLE = &FloatValidator_VTABLE; v.meta.f.Min = lo; v.meta.f.Max = hi; v.meta.f.Default = def; #define MenuInput_Float(v, lo, hi, def) v.VTABLE = &FloatInput_VTABLE; v.meta.f.Min = lo; v.meta.f.Max = hi; v.meta.f.Default = def;
#define MenuInput_Path(v) v.VTABLE = &PathValidator_VTABLE; #define MenuInput_Path(v) v.VTABLE = &PathInput_VTABLE;
#define MenuInput_Enum(v, names, count) v.VTABLE = NULL; v.meta.e.Names = names; v.meta.e.Count = count; #define MenuInput_Enum(v, names, count) v.VTABLE = NULL; v.meta.e.Names = names; v.meta.e.Count = count;
#define MenuInput_String(v) v.VTABLE = &StringValidator_VTABLE; #define MenuInput_String(v) v.VTABLE = &StringInput_VTABLE;
struct MenuInputWidget { struct MenuInputWidget {
struct InputWidget base; struct InputWidget base;

View File

@ -222,7 +222,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
wheelDelta = ((short)HIWORD(wParam)) / (float)WHEEL_DELTA; wheelDelta = ((short)HIWORD(wParam)) / (float)WHEEL_DELTA;
Mouse_SetWheel(Mouse_Wheel + wheelDelta); Mouse_ScrollWheel(wheelDelta);
return 0; return 0;
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
@ -1104,8 +1104,8 @@ void Window_ProcessEvents(void) {
if (e.xbutton.button == 1) Input_SetPressed(KEY_LMOUSE, true); if (e.xbutton.button == 1) Input_SetPressed(KEY_LMOUSE, true);
else if (e.xbutton.button == 2) Input_SetPressed(KEY_MMOUSE, true); else if (e.xbutton.button == 2) Input_SetPressed(KEY_MMOUSE, true);
else if (e.xbutton.button == 3) Input_SetPressed(KEY_RMOUSE, true); else if (e.xbutton.button == 3) Input_SetPressed(KEY_RMOUSE, true);
else if (e.xbutton.button == 4) Mouse_SetWheel(Mouse_Wheel + 1); else if (e.xbutton.button == 4) Mouse_ScrollWheel(+1);
else if (e.xbutton.button == 5) Mouse_SetWheel(Mouse_Wheel - 1); else if (e.xbutton.button == 5) Mouse_ScrollWheel(-1);
else if (e.xbutton.button == 6) Input_SetPressed(KEY_XBUTTON1, true); else if (e.xbutton.button == 6) Input_SetPressed(KEY_XBUTTON1, true);
else if (e.xbutton.button == 7) Input_SetPressed(KEY_XBUTTON2, true); else if (e.xbutton.button == 7) Input_SetPressed(KEY_XBUTTON2, true);
break; break;
@ -1931,7 +1931,7 @@ static OSStatus Window_ProcessMouseEvent(EventRef inEvent) {
res = GetEventParameter(inEvent, kEventParamMouseWheelDelta, typeSInt32, res = GetEventParameter(inEvent, kEventParamMouseWheelDelta, typeSInt32,
NULL, sizeof(SInt32), NULL, &delta); NULL, sizeof(SInt32), NULL, &delta);
if (res) Logger_Abort2(res, "Getting mouse wheel delta"); if (res) Logger_Abort2(res, "Getting mouse wheel delta");
Mouse_SetWheel(Mouse_Wheel + delta); Mouse_ScrollWheel(delta);
return 0; return 0;
case kEventMouseMoved: case kEventMouseMoved:
@ -2620,7 +2620,7 @@ void Window_ProcessEvents(void) {
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
Window_HandleMouseEvent(&e); break; Window_HandleMouseEvent(&e); break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
Mouse_SetWheel(Mouse_Wheel + e.wheel.y); Mouse_ScrollWheel(e.wheel.y);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
Pointer_SetPosition(0, e.motion.x, e.motion.y); Pointer_SetPosition(0, e.motion.x, e.motion.y);
@ -2767,7 +2767,7 @@ static void Window_CorrectFocus(void) {
static EM_BOOL Window_MouseWheel(int type, const EmscriptenWheelEvent* ev, void* data) { static EM_BOOL Window_MouseWheel(int type, const EmscriptenWheelEvent* ev, void* data) {
/* TODO: The scale factor isn't standardised.. is there a better way though? */ /* TODO: The scale factor isn't standardised.. is there a better way though? */
Mouse_SetWheel(Mouse_Wheel - Math_Sign(ev->deltaY)); Mouse_ScrollWheel(-Math_Sign(ev->deltaY));
Window_CorrectFocus(); Window_CorrectFocus();
return true; return true;
} }
@ -3813,7 +3813,7 @@ void Window_ProcessEvents(void) {
break; break;
case 22: /* NSScrollWheel */ case 22: /* NSScrollWheel */
Mouse_SetWheel(Mouse_Wheel + Send_CGFloat(ev, sel_registerName("deltaY"))); Mouse_ScrollWheel(Send_CGFloat(ev, sel_registerName("deltaY")));
break; break;
case 5: /* NSMouseMoved */ case 5: /* NSMouseMoved */