Skip to content

Commit

Permalink
DPI scale from Blitz3D-NG
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Dec 2, 2023
1 parent 27ec797 commit 204bd15
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bbruntime/bbgraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,16 @@ int bbWindowed3D()
return (tc & gxRuntime::GFXMODECAPS_3D) ? 1 : 0;
}

float bbDPIScaleX() {
gx_runtime->calculateDPI();
return gx_runtime->scale_x;
}

float bbDPIScaleY() {
gx_runtime->calculateDPI();
return gx_runtime->scale_y;
}

int bbTotalVidMem()
{
return gx_graphics->getTotalVidmem();
Expand Down Expand Up @@ -1429,6 +1439,9 @@ void graphics_link(void (*rtSym)(const char* sym, void* pc))
rtSym("%AvailVidMem", bbAvailVidMem);
rtSym("%TotalVidMem", bbTotalVidMem);

rtSym("#DPIScaleX", bbDPIScaleX);
rtSym("#DPIScaleY", bbDPIScaleY);

rtSym("%GfxDriver3D%driver", bbGfxDriver3D);
rtSym("%CountGfxModes3D", bbCountGfxModes3D);
rtSym("%GfxMode3DExists%width%height%depth", bbGfxMode3DExists);
Expand Down
2 changes: 2 additions & 0 deletions bbruntime/bbgraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ int bbGraphicsHeight();
int bbGraphicsDepth();
int bbAvailVidMem();
int bbTotalVidMem();
float bbDPIScaleX();
float bbDPIScaleY();

//mode functions
void bbGraphics(int w, int h, int d, int mode);
Expand Down
9 changes: 9 additions & 0 deletions gxruntime/gxruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,15 @@ std::string gxRuntime::systemProperty(const std::string& p) {
return "";
}

void gxRuntime::calculateDPI() {
if ((this->scale_x == .0f) && (this->scale_y == .0f)) {
HDC hdc = GetDC(GetDesktopWindow());
this->scale_x = GetDeviceCaps(hdc, LOGPIXELSX) / 96.0f;
this->scale_y = GetDeviceCaps(hdc, LOGPIXELSY) / 96.0f;
ReleaseDC(GetDesktopWindow(), hdc);
}
}

void gxRuntime::enableDirectInput(bool enable) {
if(use_di = enable) {
acquireInput();
Expand Down
4 changes: 4 additions & 0 deletions gxruntime/gxruntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class gxRuntime {
gxGraphics* graphics;
gxFileSystem* fileSystem;

float scale_x = .0f, scale_y = .0f;

void flip(bool vwait);
void moveMouse(int x, int y);

Expand Down Expand Up @@ -142,6 +144,8 @@ class gxRuntime {
gxTimer* createTimer(int hertz);
void freeTimer(gxTimer* timer);

void calculateDPI();

void enableDirectInput(bool use);
int directInputEnabled() { return use_di; }

Expand Down

0 comments on commit 204bd15

Please # to comment.