Skip to content

Commit 19a34fb

Browse files
committed
Add ability to change display windows is on and check display count
1 parent 60c84b3 commit 19a34fb

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

docs/modules/dome.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ Returns the generic name of the operating system or platform, where possible.
8080
#### `time: Number`
8181
Returns the integer number of seconds since the unix epoch (1st January 1970).
8282

83+
#### `displayCount: Number`
84+
Returns the integer number of displays on the system.
85+
8386
## Process
8487

8588
### Static Fields
@@ -144,6 +147,10 @@ Default is `false`.
144147

145148
This is the height of the window/viewport, in pixels.
146149

150+
#### `static display: Number`
151+
152+
This is the display window is rendered on. Default is `0` which is users primary/main display. When going out of bounds (less than `0` or more than number of displays) will automatically loop back around
153+
147154
#### `static integerScale: Boolean`
148155

149156
If set to true, the Canvas within the Window will be scaled by integer scaling factors only. This is useful for avoiding the "fat-pixel" look

src/modules/dome.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,33 @@ WINDOW_getHeight(WrenVM* vm) {
114114
wrenSetSlotDouble(vm, 0, height);
115115
}
116116

117+
internal void
118+
WINDOW_setDisplay(WrenVM* vm) {
119+
ENGINE* engine = (ENGINE*)wrenGetUserData(vm);
120+
ASSERT_SLOT_TYPE(vm, 1, NUM, "display");
121+
int32_t display = wrenGetSlotDouble(vm, 1);
122+
if(display < 0) {
123+
display = SDL_GetNumVideoDisplays() - 1;
124+
}
125+
DISPLAY = display;
126+
uint32_t flags = SDL_GetWindowFlags(engine->window);
127+
bool fullscreen = (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
128+
if(fullscreen) {
129+
SDL_SetWindowFullscreen(engine->window, SDL_WINDOW_SHOWN);
130+
}
131+
SDL_SetWindowPosition(engine->window, SDL_WINDOWPOS_CENTERED_DISPLAY(DISPLAY), SDL_WINDOWPOS_CENTERED_DISPLAY(DISPLAY));
132+
if(fullscreen) {
133+
SDL_SetWindowFullscreen(engine->window, SDL_WINDOW_FULLSCREEN_DESKTOP);
134+
}
135+
}
136+
137+
internal void
138+
WINDOW_getDisplay(WrenVM* vm) {
139+
ENGINE* engine = (ENGINE*)wrenGetUserData(vm);
140+
int display = SDL_GetWindowDisplayIndex(engine->window);
141+
wrenSetSlotDouble(vm, 0, display);
142+
}
143+
117144
internal void
118145
WINDOW_setTitle(WrenVM* vm) {
119146
ENGINE* engine = (ENGINE*)wrenGetUserData(vm);

src/modules/dome.wren

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ class Process {
115115

116116

117117
class Window {
118+
foreign static display=(value)
119+
foreign static display
118120
foreign static title=(value)
119121
foreign static title
120122
foreign static vsync=(value)

src/modules/platform.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ PLATFORM_getName(WrenVM* vm) {
99
wrenEnsureSlots(vm, 1);
1010
wrenSetSlotString(vm, 0, SDL_GetPlatform());
1111
}
12+
13+
internal void
14+
PLATFORM_getDisplayCount(WrenVM* vm) {
15+
int displays = SDL_GetNumVideoDisplays();
16+
wrenSetSlotDouble(vm, 0, displays);
17+
}

src/modules/platform.wren

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class Platform {
22
foreign static time
33
foreign static name
4+
foreign static displayCount
45
}

src/vm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ internal WrenVM* VM_create(ENGINE* engine) {
184184
MAP_addFunction(&engine->moduleMap, "dome", "static Log.print(_,_,_)", LOG_print);
185185
MAP_addFunction(&engine->moduleMap, "dome", "static Log.f_level=(_)", LOG_setLevel);
186186
MAP_addFunction(&engine->moduleMap, "dome", "static Log.level", LOG_getLevel);
187+
MAP_addFunction(&engine->moduleMap, "dome", "static Window.display=(_)", WINDOW_setDisplay);
188+
MAP_addFunction(&engine->moduleMap, "dome", "static Window.display", WINDOW_getDisplay);
187189
MAP_addFunction(&engine->moduleMap, "dome", "static Window.title=(_)", WINDOW_setTitle);
188190
MAP_addFunction(&engine->moduleMap, "dome", "static Window.title", WINDOW_getTitle);
189191
MAP_addFunction(&engine->moduleMap, "dome", "static Window.integerScale=(_)", WINDOW_setIntegerScale);
@@ -338,6 +340,7 @@ internal WrenVM* VM_create(ENGINE* engine) {
338340
// Platform
339341
MAP_addFunction(&engine->moduleMap, "platform", "static Platform.time", PLATFORM_getTime);
340342
MAP_addFunction(&engine->moduleMap, "platform", "static Platform.name", PLATFORM_getName);
343+
MAP_addFunction(&engine->moduleMap, "platform", "static Platform.displayCount", PLATFORM_getDisplayCount);
341344
MAP_lockModule(&engine->moduleMap, "platform");
342345

343346
// Plugin

0 commit comments

Comments
 (0)