Skip to content

Commit

Permalink
improve japp_ratioFix 2 precision, apply to cgame too
Browse files Browse the repository at this point in the history
  • Loading branch information
Razish committed Sep 27, 2023
1 parent 935c2dc commit ae93787
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ void CG_ManualEntityRender(centity_t *cent);
void CG_MissileHitPlayer(int weapon, vector3 *origin, vector3 *dir, int entityNum, qboolean alt_fire);
void CG_MissileHitWall(int weapon, int clientNum, vector3 *origin, vector3 *dir, impactSound_t soundType, qboolean alt_fire, int charge);
void CG_MiscModelExplosion(vector3 *mins, vector3 *maxs, int size, material_t chunkType);
void CG_MouseEvent(int x, int y);
void CG_MouseEvent(int dx, int dy);
void CG_NextForcePower_f(void);
void CG_NextInventory_f(void);
void CG_NextWeapon_f(void);
Expand Down
14 changes: 10 additions & 4 deletions cgame/cg_newDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,15 @@ void CG_OwnerDraw(float x, float y, float w, float h, float text_x, float text_y
#endif
}

void CG_MouseEvent(int x, int y) {
cgDC.cursorx = cgs.cursorX = Q_clamp(0.0f, cgs.cursorX + x, SCREEN_WIDTH);
cgDC.cursory = cgs.cursorY = Q_clamp(0.0f, cgs.cursorY + y, SCREEN_HEIGHT);
void CG_MouseEvent(int dx, int dy) {
float dxScaled = dx;
float dyScaled = dy;
if (japp_ratioFix.integer & (1 << RATIOFIX_MOUSEINPUT)) {
dxScaled *= (SCREEN_WIDTH / (float)cgs.glconfig.vidWidth);
dyScaled *= (SCREEN_HEIGHT / (float)cgs.glconfig.vidHeight);
}
cgDC.cursorx = cgs.cursorX = Q_clamp(0.0f, cgs.cursorX + dxScaled, SCREEN_WIDTH);
cgDC.cursory = cgs.cursorY = Q_clamp(0.0f, cgs.cursorY + dyScaled, SCREEN_HEIGHT);

cursorType_e cursorType = Display_CursorType(cgs.cursorX, cgs.cursorY);
if (cursorType == CURSOR_NONE || cursorType == CURSOR_ARROW) {
Expand All @@ -748,7 +754,7 @@ void CG_MouseEvent(int x, int y) {
}

if (cgs.capturedItem) {
Display_MouseMove(cgs.capturedItem, x, y);
Display_MouseMove(cgs.capturedItem, dxScaled, dyScaled);
} else {
Display_MouseMove(NULL, cgs.cursorX, cgs.cursorY);
}
Expand Down
10 changes: 6 additions & 4 deletions ui/ui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7883,20 +7883,22 @@ void UI_KeyEvent(int key, qboolean down) {
}

void UI_MouseEvent(int dx, int dy) {
float dxScaled = dx;
float dyScaled = dy;
if (japp_ratioFix.integer & (1 << RATIOFIX_MOUSEINPUT)) {
// optional - the engine may have already scaled this
dx *= SCREEN_WIDTH / (float)uiInfo.uiDC.glconfig.vidWidth;
dy *= SCREEN_HEIGHT / (float)uiInfo.uiDC.glconfig.vidHeight;
dxScaled *= (SCREEN_WIDTH / (float)uiInfo.uiDC.glconfig.vidWidth);
dyScaled *= (SCREEN_HEIGHT / (float)uiInfo.uiDC.glconfig.vidHeight);
}

// update mouse screen position
uiInfo.uiDC.cursorx += dx;
uiInfo.uiDC.cursorx += dxScaled;
if (uiInfo.uiDC.cursorx < 0)
uiInfo.uiDC.cursorx = 0;
else if (uiInfo.uiDC.cursorx > SCREEN_WIDTH)
uiInfo.uiDC.cursorx = SCREEN_WIDTH;

uiInfo.uiDC.cursory += dy;
uiInfo.uiDC.cursory += dyScaled;
if (uiInfo.uiDC.cursory < 0)
uiInfo.uiDC.cursory = 0;
else if (uiInfo.uiDC.cursory > SCREEN_HEIGHT)
Expand Down

0 comments on commit ae93787

Please sign in to comment.