mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 19:15:14 -04:00
remove usage of Point2D
This commit is contained in:
parent
8f36382eb6
commit
9778e4534f
14
src/Camera.c
14
src/Camera.c
@ -12,7 +12,7 @@ struct _CameraData Camera;
|
|||||||
static struct PickedPos cameraClipPos;
|
static struct PickedPos cameraClipPos;
|
||||||
static Vec2 cam_rotOffset;
|
static Vec2 cam_rotOffset;
|
||||||
static bool cam_isForwardThird;
|
static bool cam_isForwardThird;
|
||||||
static Point2D cam_delta;
|
static int cam_deltaX, cam_deltaY;
|
||||||
|
|
||||||
static void Camera_AcquireFocus(void) {
|
static void Camera_AcquireFocus(void) {
|
||||||
Window_EnableRawMouse();
|
Window_EnableRawMouse();
|
||||||
@ -21,7 +21,7 @@ static void Camera_LoseFocus(void) {
|
|||||||
Window_DisableRawMouse();
|
Window_DisableRawMouse();
|
||||||
}
|
}
|
||||||
static void Camera_OnRawMouseMoved(int deltaX, int deltaY) {
|
static void Camera_OnRawMouseMoved(int deltaX, int deltaY) {
|
||||||
cam_delta.X += deltaX; cam_delta.Y += deltaY;
|
cam_deltaX += deltaX; cam_deltaY += deltaY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
@ -58,13 +58,13 @@ static Vec2 PerspectiveCamera_GetMouseDelta(double delta) {
|
|||||||
Vec2 v;
|
Vec2 v;
|
||||||
|
|
||||||
if (Camera.Smooth) {
|
if (Camera.Smooth) {
|
||||||
speedX += cam_delta.X * CAMERA_ADJUST;
|
speedX += cam_deltaX * CAMERA_ADJUST;
|
||||||
speedX *= CAMERA_SLIPPERY;
|
speedX *= CAMERA_SLIPPERY;
|
||||||
speedY += cam_delta.Y * CAMERA_ADJUST;
|
speedY += cam_deltaY * CAMERA_ADJUST;
|
||||||
speedY *= CAMERA_SLIPPERY;
|
speedY *= CAMERA_SLIPPERY;
|
||||||
} else {
|
} else {
|
||||||
speedX = (float)cam_delta.X;
|
speedX = (float)cam_deltaX;
|
||||||
speedY = (float)cam_delta.Y;
|
speedY = (float)cam_deltaY;
|
||||||
}
|
}
|
||||||
|
|
||||||
v.X = speedX * sensitivity; v.Y = speedY * sensitivity;
|
v.X = speedX * sensitivity; v.Y = speedY * sensitivity;
|
||||||
@ -101,7 +101,7 @@ static void PerspectiveCamera_UpdateMouse(double delta) {
|
|||||||
if (!s->handlesAllInput && Window_Focused) Window_UpdateRawMouse();
|
if (!s->handlesAllInput && Window_Focused) Window_UpdateRawMouse();
|
||||||
|
|
||||||
PerspectiveCamera_UpdateMouseRotation(delta);
|
PerspectiveCamera_UpdateMouseRotation(delta);
|
||||||
cam_delta.X = 0; cam_delta.Y = 0;
|
cam_deltaX = 0; cam_deltaY = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PerspectiveCamera_CalcViewBobbing(float t, float velTiltScale) {
|
static void PerspectiveCamera_CalcViewBobbing(float t, float velTiltScale) {
|
||||||
|
@ -89,7 +89,6 @@ typedef uint32_t ReturnCode;
|
|||||||
typedef uint64_t TimeMS;
|
typedef uint64_t TimeMS;
|
||||||
|
|
||||||
typedef struct Rect2D_ { int X, Y, Width, Height; } Rect2D;
|
typedef struct Rect2D_ { int X, Y, Width, Height; } Rect2D;
|
||||||
typedef struct Point2D_ { int X, Y; } Point2D;
|
|
||||||
typedef struct Size2D_ { int Width, Height; } Size2D;
|
typedef struct Size2D_ { int Width, Height; } Size2D;
|
||||||
typedef struct FontDesc_ { void* Handle; uint16_t Size, Style; } FontDesc;
|
typedef struct FontDesc_ { void* Handle; uint16_t Size, Style; } FontDesc;
|
||||||
typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec;
|
typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec;
|
||||||
|
78
src/Window.c
78
src/Window.c
@ -31,14 +31,14 @@ void Clipboard_RequestText(RequestClipboardCallback callback, void* obj) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Point2D cursorPrev;
|
static int cursorPrevX, cursorPrevY;
|
||||||
/* Gets the position of the cursor in screen coordinates. */
|
/* Gets the position of the cursor in screen coordinates. */
|
||||||
static Point2D Cursor_GetScreenPos(void);
|
static void Cursor_GetRawPos(int* x, int* y);
|
||||||
|
|
||||||
static void Window_CentreMousePosition(void) {
|
static void Window_CentreMousePosition(void) {
|
||||||
Cursor_SetPosition(Window_Width / 2, Window_Height / 2);
|
Cursor_SetPosition(Window_Width / 2, Window_Height / 2);
|
||||||
/* Fixes issues with large DPI displays on Windows >= 8.0. */
|
/* Fixes issues with large DPI displays on Windows >= 8.0. */
|
||||||
cursorPrev = Cursor_GetScreenPos();
|
Cursor_GetRawPos(&cursorPrevX, &cursorPrevY);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Window_RegrabMouse(void) {
|
static void Window_RegrabMouse(void) {
|
||||||
@ -52,8 +52,9 @@ static void Window_DefaultEnableRawMouse(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Window_DefaultUpdateRawMouse(void) {
|
static void Window_DefaultUpdateRawMouse(void) {
|
||||||
Point2D p = Cursor_GetScreenPos();
|
int x, y;
|
||||||
Event_RaiseMouseMove(&MouseEvents.RawMoved, p.X - cursorPrev.X, p.Y - cursorPrev.Y);
|
Cursor_GetRawPos(&x, &y);
|
||||||
|
Event_RaiseMouseMove(&MouseEvents.RawMoved, x - cursorPrevX, y - cursorPrevY);
|
||||||
Window_CentreMousePosition();
|
Window_CentreMousePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,12 +256,12 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||||||
dx = raw.data.mouse.lLastX;
|
dx = raw.data.mouse.lLastX;
|
||||||
dy = raw.data.mouse.lLastY;
|
dy = raw.data.mouse.lLastY;
|
||||||
} else if (raw.data.mouse.usFlags == MOUSE_MOVE_ABSOLUTE) {
|
} else if (raw.data.mouse.usFlags == MOUSE_MOVE_ABSOLUTE) {
|
||||||
static Point2D prevPos;
|
static int prevPosX, prevPosY;
|
||||||
dx = raw.data.mouse.lLastX - prevPos.X;
|
dx = raw.data.mouse.lLastX - prevPosX;
|
||||||
dy = raw.data.mouse.lLastY - prevPos.Y;
|
dy = raw.data.mouse.lLastY - prevPosY;
|
||||||
|
|
||||||
prevPos.X = raw.data.mouse.lLastX;
|
prevPosX = raw.data.mouse.lLastX;
|
||||||
prevPos.Y = raw.data.mouse.lLastY;
|
prevPosY = raw.data.mouse.lLastY;
|
||||||
} else { break; }
|
} else { break; }
|
||||||
|
|
||||||
if (rawMouseEnabled) Event_RaiseMouseMove(&MouseEvents.RawMoved, dx, dy);
|
if (rawMouseEnabled) Event_RaiseMouseMove(&MouseEvents.RawMoved, dx, dy);
|
||||||
@ -542,10 +543,12 @@ void Window_ProcessEvents(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Point2D Cursor_GetScreenPos(void) {
|
static void Cursor_GetRawPos(int* x, int* y) {
|
||||||
POINT point; GetCursorPos(&point);
|
POINT point;
|
||||||
Point2D p = { point.x, point.y }; return p;
|
GetCursorPos(&point);
|
||||||
|
*x = point.x; *y = point.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cursor_SetPosition(int x, int y) {
|
void Cursor_SetPosition(int x, int y) {
|
||||||
SetCursorPos(x + Window_X, y + Window_Y);
|
SetCursorPos(x + Window_X, y + Window_Y);
|
||||||
}
|
}
|
||||||
@ -1161,17 +1164,15 @@ void Window_ProcessEvents(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Point2D Cursor_GetScreenPos(void) {
|
static void Cursor_GetRawPos(int* x, int* y) {
|
||||||
Window rootW, childW;
|
Window rootW, childW;
|
||||||
Point2D root, child;
|
int childX, childY;
|
||||||
unsigned int mask;
|
unsigned int mask;
|
||||||
|
XQueryPointer(win_display, win_rootWin, &rootW, &childW, x, y, &childX, &childY, &mask);
|
||||||
XQueryPointer(win_display, win_rootWin, &rootW, &childW, &root.X, &root.Y, &child.X, &child.Y, &mask);
|
|
||||||
return root;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cursor_SetPosition(int x, int y) {
|
void Cursor_SetPosition(int x, int y) {
|
||||||
XWarpPointer(win_display, None, win_rootWin, 0,0, 0,0, x + Window_X, y + Window_Y);
|
XWarpPointer(win_display, None, win_handle, 0,0, 0,0, x, y);
|
||||||
XFlush(win_display); /* TODO: not sure if XFlush call is necessary */
|
XFlush(win_display); /* TODO: not sure if XFlush call is necessary */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1576,8 +1577,8 @@ static OSStatus Window_ProcessWindowEvent(EventRef inEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static OSStatus Window_ProcessMouseEvent(EventRef inEvent) {
|
static OSStatus Window_ProcessMouseEvent(EventRef inEvent) {
|
||||||
|
int mouseX, mouseY;
|
||||||
HIPoint pt;
|
HIPoint pt;
|
||||||
Point2D mousePos;
|
|
||||||
UInt32 kind;
|
UInt32 kind;
|
||||||
bool down;
|
bool down;
|
||||||
EventMouseButton button;
|
EventMouseButton button;
|
||||||
@ -1591,16 +1592,13 @@ static OSStatus Window_ProcessMouseEvent(EventRef inEvent) {
|
|||||||
Logger_Abort2(res, "Getting mouse position");
|
Logger_Abort2(res, "Getting mouse position");
|
||||||
}
|
}
|
||||||
|
|
||||||
mousePos.X = (int)pt.x; mousePos.Y = (int)pt.y;
|
mouseX = (int)pt.x; mouseY = (int)pt.y;
|
||||||
/* kEventParamMouseLocation is in screen coordinates */
|
/* kEventParamMouseLocation is in screen coordinates */
|
||||||
if (!win_fullscreen) {
|
if (!win_fullscreen) { mouseX -= Window_X; mouseY -= Window_Y; }
|
||||||
mousePos.X -= Window_X;
|
|
||||||
mousePos.Y -= Window_Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* mousePos.Y is < 0 if user clicks or moves when over titlebar */
|
/* mouseY is < 0 if user clicks or moves when over titlebar */
|
||||||
/* Don't intercept this, prevents clicking close/minimise/maximise from working */
|
/* Don't intercept this, prevents clicking close/minimise/maximise from working */
|
||||||
if (mousePos.Y < 0) return eventNotHandledErr;
|
if (mouseY < 0) return eventNotHandledErr;
|
||||||
|
|
||||||
kind = GetEventKind(inEvent);
|
kind = GetEventKind(inEvent);
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
@ -1630,7 +1628,7 @@ static OSStatus Window_ProcessMouseEvent(EventRef inEvent) {
|
|||||||
|
|
||||||
case kEventMouseMoved:
|
case kEventMouseMoved:
|
||||||
case kEventMouseDragged:
|
case kEventMouseDragged:
|
||||||
Mouse_SetPosition(mousePos.X, mousePos.Y);
|
Mouse_SetPosition(mouseX, mouseY);
|
||||||
return eventNotHandledErr;
|
return eventNotHandledErr;
|
||||||
}
|
}
|
||||||
return eventNotHandledErr;
|
return eventNotHandledErr;
|
||||||
@ -1912,15 +1910,12 @@ void Window_ProcessEvents(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Point2D Cursor_GetScreenPos(void) {
|
static void Cursor_GetRawPos(int* x, int* y) {
|
||||||
HIPoint point;
|
HIPoint point;
|
||||||
Point2D p;
|
|
||||||
/* NOTE: HIGetMousePosition is OSX 10.5 or later */
|
/* NOTE: HIGetMousePosition is OSX 10.5 or later */
|
||||||
/* TODO: Use GetGlobalMouse instead!!!! */
|
/* TODO: Use GetGlobalMouse instead!!!! */
|
||||||
HIGetMousePosition(kHICoordSpaceScreenPixel, NULL, &point);
|
HIGetMousePosition(kHICoordSpaceScreenPixel, NULL, &point);
|
||||||
|
*x = (int)point.x; *y = (int)point.y;
|
||||||
p.X = (int)point.x; p.Y = (int)point.y;
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cursor_SetPosition(int x, int y) {
|
void Cursor_SetPosition(int x, int y) {
|
||||||
@ -2273,14 +2268,9 @@ void Window_ProcessEvents(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Point2D Cursor_GetScreenPos(void) {
|
static void Cursor_GetRawPos(int* x, int* y) {
|
||||||
Point2D p;
|
SDL_GetMouseState(x, y);
|
||||||
SDL_GetGlobalMouseState(&p.X, &p.Y);
|
|
||||||
//SDL_GetMouseState(&p.X, &p.Y);
|
|
||||||
//p.X += Window_X; p.Y += Window_Y;
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cursor_SetPosition(int x, int y) {
|
void Cursor_SetPosition(int x, int y) {
|
||||||
SDL_WarpMouseInWindow(win_handle, x, y);
|
SDL_WarpMouseInWindow(win_handle, x, y);
|
||||||
}
|
}
|
||||||
@ -2737,8 +2727,8 @@ void Window_Close(void) {
|
|||||||
|
|
||||||
void Window_ProcessEvents(void) { }
|
void Window_ProcessEvents(void) { }
|
||||||
|
|
||||||
/* Not supported (or even used internally) */
|
/* Not needed because browser provides relative mouse and touch events */
|
||||||
Point2D Cursor_GetScreenPos(void) { Point2D p = { 0,0 }; return p; }
|
static void Cursor_GetRawPos(int* x, int* y) { *x = 0; *y = 0; }
|
||||||
/* Not allowed to move cursor from javascript */
|
/* Not allowed to move cursor from javascript */
|
||||||
void Cursor_SetPosition(int x, int y) { Mouse_X = x; Mouse_Y = y; }
|
void Cursor_SetPosition(int x, int y) { Mouse_X = x; Mouse_Y = y; }
|
||||||
|
|
||||||
@ -3046,9 +3036,7 @@ void Window_ProcessEvents(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* No actual cursor, so just fake one */
|
/* No actual cursor, so just fake one */
|
||||||
Point2D Cursor_GetScreenPos(void) {
|
static void Cursor_GetRawPos(int* x, int* y) { *x = 0; *y = 0; }
|
||||||
Point2D p; p.X = Mouse_X; p.Y = Mouse_Y; return p;
|
|
||||||
}
|
|
||||||
void Cursor_SetPosition(int x, int y) { Mouse_X = x; Mouse_Y = y; }
|
void Cursor_SetPosition(int x, int y) { Mouse_X = x; Mouse_Y = y; }
|
||||||
void Cursor_SetVisible(bool visible) { }
|
void Cursor_SetVisible(bool visible) { }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user