src/window.c

changeset 154
4dff9cc488fe
parent 149
560772519ff9
equal deleted inserted replaced
153:4116e2bd501b 154:4dff9cc488fe
74 Sint32 w, h; 74 Sint32 w, h;
75 SDL_GetWindowSize(window->window, &w, &h); 75 SDL_GetWindowSize(window->window, &w, &h);
76 window->dimensions = asc_vec2u_new(w, h); 76 window->dimensions = asc_vec2u_new(w, h);
77 } 77 }
78 window->resized = true; // count initial sizing as resize 78 window->resized = true; // count initial sizing as resize
79
80 // default UI scale
81 window->ui_scale = 1.0f;
79 82
80 if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) { 83 if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) {
81 asc_scene_init(&window->ui, 84 asc_scene_init(&window->ui,
82 .type = ASC_CAMERA_ORTHO, 85 .type = ASC_CAMERA_ORTHO,
83 .ortho.rect = asc_recti_new(0, 0, window->dimensions.width, window->dimensions.height), 86 .ortho.rect = asc_recti_new(0, 0, window->dimensions.width, window->dimensions.height),
196 } 199 }
197 200
198 AscScene *asc_window_scene(unsigned int index) { 201 AscScene *asc_window_scene(unsigned int index) {
199 return &asc_active_window->scenes[index]; 202 return &asc_active_window->scenes[index];
200 } 203 }
204
205 asc_vec2u asc_window_display_resolution(void) {
206 const AscWindow *window = asc_active_window;
207 SDL_DisplayMode dm;
208 const int display = SDL_GetWindowDisplayIndex(window->window);
209 if (SDL_GetDesktopDisplayMode(display, &dm)) {
210 asc_error("Failed to get display mode for window %u on display %d: %s",
211 window->id, display, SDL_GetError());
212 }
213 return asc_vec2u_new(dm.w, dm.h);
214 }
215
216 void asc_ui_scale(float scale) {
217 asc_active_window->ui_scale = scale;
218 }
219
220 float asc_ui_get_scale(void) {
221 return asc_active_window->ui_scale;
222 }
223
224 void asc_ui_scale_auto(void) {
225 asc_vec2u res = asc_window_display_resolution();
226 // TODO: debug why this is wrong under GNOME or just throw GNOME away
227 if (res.width > 3000) {
228 asc_ui_scale(1.5f);
229 } else if (res.width > 2000) {
230 asc_ui_scale(1.2f);
231 } else {
232 return asc_ui_scale(1.f);
233 }
234 }

mercurial