11package core ;
22
33import openfl .display .Screen ;
4- import lime .system .System ;
5- import haxe .ds .IntMap ;
4+ import haxe .ds .Map ;
65
7- // Define a proper type for screen resolution data
6+ // Define a type for screen resolution data
87typedef ScreenResolution = {
8+ index : Int ,
99 width : Float ,
1010 height : Float
1111}
1212
13- @:privateAccess
1413class ScreenInfo {
14+ public static function getScreenResolutions (getall : Bool ): Array <ScreenResolution > {
15+ var screenList : Array <ScreenResolution > = [];
1516
16- // Unified screen information retrieval
17- public static function getScreenResolutions (includeAll : Bool = true ): IntMap <ScreenResolution > {
18- var resolutions = new IntMap <ScreenResolution >();
19-
20- #if desktop
21- if (includeAll ) {
17+ if (getall == true ) {
18+ #if desktop
19+ // Attempt to handle multi-screen setups
2220 try {
23- final screens = Screen . screens ;
21+ var screens = Reflect . field ( Screen , " get_screens " ) ;
2422 if (screens != null ) {
25- for (screen in screens ) {
26- final id = getDisplayIndex (screen );
27- if (id != - 1 ) {
28- resolutions .set (id , getScreenResolution (screen ));
23+ var screenArray : Array <Screen > = cast screens ();
24+ for (screen in screenArray ) {
25+ @:privateAccess {
26+ screenList .insert (
27+ screen .__displayIndex ,
28+ {
29+ " index" : screen .__displayIndex ,
30+ " width" : screen .bounds .width ,
31+ " height" : screen .bounds .height
32+ }
33+ );
2934 }
3035 }
31- return resolutions ;
36+ return screenList ;
3237 }
33- } catch (e : Dynamic ) {
34- log (" Multi-screen detection failed, falling back to main screen" , Warn );
38+ } catch (e : Dynamic ) {
39+ // Handle platforms without multi-screen support
40+ trace (" Multi-screen support is not available. Falling back to primary screen." );
3541 }
42+ #end
3643 }
37- #end
3844
39- // Fallback to main screen
40- final mainScreen = Screen .mainScreen ;
41- if ( mainScreen != null ) {
42- resolutions . set ( 0 , getScreenResolution ( mainScreen ));
43- } else {
44- log ( " Failed to retrieve any screen information " , Error );
45- }
45+ // Fallback to primary screen resolution
46+ var primaryScreen = Screen .mainScreen ;
47+ screenList . push ( {
48+ " index " : 0 ,
49+ " width " : primaryScreen . bounds . width ,
50+ " height " : primaryScreen . bounds . height
51+ });
4652
47- return resolutions ;
53+ return screenList ;
4854 }
4955
50- // Helper to safely extract display index
51- private static function getDisplayIndex (screen : Screen ): Int {
52- try {
53- // Safer reflection-based approach
54- final dynamicScreen : Dynamic = screen ;
55- return (Reflect .hasField (dynamicScreen , " displayIndex" ))
56- ? dynamicScreen .displayIndex
57- : - 1 ;
58- } catch (e : Dynamic ) {
59- log (' Failed to get screen ID: ${e }' , Warn );
60- return - 1 ;
61- }
62- }
63-
64- // Unified resolution extraction
6556 private static function getScreenResolution (screen : Screen ): ScreenResolution {
66- return {
67- width : screen .bounds .width ,
68- height : screen .bounds .height
69- };
70- }
57+ var width : Float = screen .visibleBounds .width ;
58+ var height : Float = screen .visibleBounds .height ;
7159
72- // Logging utility
73- private static function log (message : String , level : LogLevel = Info ) {
74- #if debug
75- final prefix = switch (level ) {
76- case Error : " [ERROR]" ;
77- case Warn : " [WARN]" ;
78- case Info : " [INFO]" ;
60+ return {
61+ index : 0 ,
62+ width : width ,
63+ height : height
7964 };
80- trace (' $prefix $message ' );
81- #end
8265 }
83- }
84-
85- enum LogLevel {
86- Error ;
87- Warn ;
88- Info ;
8966}
0 commit comments