Skip to content

Commit

Permalink
enable hgih DPI awareness
Browse files Browse the repository at this point in the history
  • Loading branch information
crowplexus committed Jan 9, 2025
1 parent d1e82ea commit d7c4b8d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<!-- ____________________________ Window Settings ___________________________ -->

<!--These window settings apply to all targets-->
<window width="1280" height="720" fps="60" background="#000000" hardware="true" vsync="false" />
<window width="1280" height="720" fps="60" background="#000000" hardware="true" vsync="false" allow-high-dpi="true" />

<!--HTML5-specific-->
<window if="html5" resizable="true" />
Expand Down
76 changes: 29 additions & 47 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package;
import android.content.Context;
#end

import debug.FPSCounter;
import backend.FPSCounter;

import flixel.graphics.FlxGraphic;
import flixel.FlxGame;
Expand Down Expand Up @@ -35,20 +35,32 @@ import haxe.io.Path;

import backend.Highscore;

#if linux
// NATIVE API STUFF, YOU CAN IGNORE THIS AND SCROLL //
#if (linux && !debug)
@:cppInclude('./external/gamemode_client.h')
@:cppFileCode('#define GAMEMODE_AUTO')
#end
#if windows
@:buildXml('
<target id="haxe">
<lib name="wininet.lib" if="windows" />
<lib name="dwmapi.lib" if="windows" />
</target>
')
@:cppFileCode('
#define GAMEMODE_AUTO
#include <windows.h>
#include <winuser.h>
#pragma comment(lib, "Shell32.lib")
extern "C" HRESULT WINAPI SetCurrentProcessExplicitAppUserModelID(PCWSTR AppID);
')
#end

// // // // // // // // //
class Main extends Sprite
{
var game = {
width: 1280, // WINDOW width
height: 720, // WINDOW height
initialState: TitleState, // initial game state
zoom: -1.0, // game state bounds
framerate: 60, // default framerate
skipSplash: true, // if the default flixel splash screen should be skipped
startFullscreen: false // if the game should start at fullscreen mode
Expand All @@ -67,64 +79,36 @@ class Main extends Sprite
{
super();

#if windows
// DPI Scaling fix for windows
// this shouldn't be needed for other systems
// Credit to YoshiCrafter29 for finding this function
untyped __cpp__("SetProcessDPIAware();");
#end

// Credits to MAJigsaw77 (he's the og author for this code)
#if android
Sys.setCwd(Path.addTrailingSlash(Context.getExternalFilesDir()));
#elseif ios
Sys.setCwd(lime.system.System.applicationStorageDirectory);
#end

if (stage != null)
{
init();
}
else
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
#if VIDEOS_ALLOWED
hxvlc.util.Handle.init(#if (hxvlc >= "1.8.0") ['--no-lua'] #end);
#end
}

private function init(?E:Event):Void
{
if (hasEventListener(Event.ADDED_TO_STAGE))
{
removeEventListener(Event.ADDED_TO_STAGE, init);
}

setupGame();
}

private function setupGame():Void
{
var stageWidth:Int = Lib.current.stage.stageWidth;
var stageHeight:Int = Lib.current.stage.stageHeight;

if (game.zoom == -1.0)
{
var ratioX:Float = stageWidth / game.width;
var ratioY:Float = stageHeight / game.height;
game.zoom = Math.min(ratioX, ratioY);
game.width = Math.ceil(stageWidth / game.zoom);
game.height = Math.ceil(stageHeight / game.zoom);
}

#if LUA_ALLOWED
Mods.pushGlobalMods();
#end
Mods.loadTopMod();

FlxG.save.bind('funkin', CoolUtil.getSavePath());

Highscore.load();

#if LUA_ALLOWED Lua.set_callbacks_function(cpp.Callable.fromStaticFunction(psychlua.CallbackHandler.call)); #end
Controls.instance = new Controls();
ClientPrefs.loadDefaultKeys();
#if ACHIEVEMENTS_ALLOWED Achievements.load(); #end
addChild(new FlxGame(game.width, game.height, game.initialState, #if (flixel < "5.0.0") game.zoom, #end game.framerate, game.framerate, game.skipSplash, game.startFullscreen));
addChild(new FlxGame(game.width, game.height, game.initialState, game.framerate, game.framerate, game.skipSplash, game.startFullscreen));

#if !mobile
fpsVar = new FPSCounter(10, 3, 0xFFFFFF);
Expand Down Expand Up @@ -206,14 +190,12 @@ class Main extends Sprite
}

errMsg += "\nUncaught Error: " + e.error;
/*
* remove if you're modding and want the crash log message to contain the link
* please remember to actually modify the link for the github page to report the issues to.
*/
//
// remove if you're modding and want the crash log message to contain the link
// please remember to actually modify the link for the github page to report the issues to.
#if officialBuild
errMsg += "\nPlease report this error to the GitHub page: https://github.com/ShadowMario/FNF-PsychEngine\n\n> Crash Handler written by: sqirra-rng";
errMsg += "\nPlease report this error to the GitHub page: https://github.com/ShadowMario/FNF-PsychEngine";
#end
errMsg += "\n\n> Crash Handler written by: sqirra-rng";

if (!FileSystem.exists("./crash/"))
FileSystem.createDirectory("./crash/");
Expand Down

0 comments on commit d7c4b8d

Please sign in to comment.