diff options
Diffstat (limited to 'src/ui/window.c')
-rw-r--r-- | src/ui/window.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index 4f59ef1a..315c4243 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -36,7 +36,7 @@ static float initialUiScale_ = 1.0f; | |||
36 | static float initialUiScale_ = 1.1f; | 36 | static float initialUiScale_ = 1.1f; |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | iDefineTypeConstruction(Window) | 39 | iDefineTypeConstructionArgs(Window, (iRect rect), rect) |
40 | 40 | ||
41 | static iBool handleRootCommands_(iWidget *root, const char *cmd) { | 41 | static iBool handleRootCommands_(iWidget *root, const char *cmd) { |
42 | iUnused(root); | 42 | iUnused(root); |
@@ -354,8 +354,16 @@ static float pixelRatio_Window_(const iWindow *d) { | |||
354 | return (float) dx / (float) x; | 354 | return (float) dx / (float) x; |
355 | } | 355 | } |
356 | 356 | ||
357 | void init_Window(iWindow *d) { | 357 | static void drawBlank_Window_(iWindow *d) { |
358 | const iColor bg = get_Color(gray25_ColorId); | ||
359 | SDL_SetRenderDrawColor(d->render, bg.r, bg.g, bg.b, 255); | ||
360 | SDL_RenderClear(d->render); | ||
361 | SDL_RenderPresent(d->render); | ||
362 | } | ||
363 | |||
364 | void init_Window(iWindow *d, iRect rect) { | ||
358 | theWindow_ = d; | 365 | theWindow_ = d; |
366 | d->isBlank = iTrue; | ||
359 | uint32_t flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; | 367 | uint32_t flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; |
360 | #if defined (iPlatformApple) | 368 | #if defined (iPlatformApple) |
361 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); | 369 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); |
@@ -363,17 +371,22 @@ void init_Window(iWindow *d) { | |||
363 | flags |= SDL_WINDOW_OPENGL; | 371 | flags |= SDL_WINDOW_OPENGL; |
364 | #endif | 372 | #endif |
365 | SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"); | 373 | SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"); |
366 | if (SDL_CreateWindowAndRenderer(800, 500, flags, &d->win, &d->render)) { | 374 | if (SDL_CreateWindowAndRenderer( |
375 | width_Rect(rect), height_Rect(rect), flags, &d->win, &d->render)) { | ||
367 | fprintf(stderr, "Error when creating window: %s\n", SDL_GetError()); | 376 | fprintf(stderr, "Error when creating window: %s\n", SDL_GetError()); |
368 | exit(-2); | 377 | exit(-2); |
369 | } | 378 | } |
379 | if (left_Rect(rect) >= 0) { | ||
380 | SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); | ||
381 | } | ||
370 | SDL_SetWindowMinimumSize(d->win, 640, 400); | 382 | SDL_SetWindowMinimumSize(d->win, 640, 400); |
371 | SDL_SetWindowTitle(d->win, "Lagrange"); | 383 | SDL_SetWindowTitle(d->win, "Lagrange"); |
372 | /* Some info. */ { | 384 | /* Some info. */ { |
373 | SDL_RendererInfo info; | 385 | SDL_RendererInfo info; |
374 | SDL_GetRendererInfo(d->render, &info); | 386 | SDL_GetRendererInfo(d->render, &info); |
375 | printf("[window] renderer: %s\n", info.name); | 387 | printf("[window] renderer: %s\n", info.name); |
376 | } | 388 | } |
389 | drawBlank_Window_(d); | ||
377 | d->uiScale = initialUiScale_; | 390 | d->uiScale = initialUiScale_; |
378 | d->pixelRatio = pixelRatio_Window_(d); | 391 | d->pixelRatio = pixelRatio_Window_(d); |
379 | setPixelRatio_Metrics(d->pixelRatio * d->uiScale); | 392 | setPixelRatio_Metrics(d->pixelRatio * d->uiScale); |
@@ -447,6 +460,11 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { | |||
447 | } | 460 | } |
448 | default: { | 461 | default: { |
449 | SDL_Event event = *ev; | 462 | SDL_Event event = *ev; |
463 | if (event.type == SDL_USEREVENT && isCommand_UserEvent(ev, "window.unblank")) { | ||
464 | d->isBlank = iFalse; | ||
465 | postRefresh_App(); | ||
466 | return iTrue; | ||
467 | } | ||
450 | /* Map mouse pointer coordinate to our coordinate system. */ | 468 | /* Map mouse pointer coordinate to our coordinate system. */ |
451 | if (event.type == SDL_MOUSEMOTION) { | 469 | if (event.type == SDL_MOUSEMOTION) { |
452 | const iInt2 pos = coord_Window(d, event.motion.x, event.motion.y); | 470 | const iInt2 pos = coord_Window(d, event.motion.x, event.motion.y); |
@@ -479,6 +497,10 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { | |||
479 | 497 | ||
480 | void draw_Window(iWindow *d) { | 498 | void draw_Window(iWindow *d) { |
481 | /* Clear the window. */ | 499 | /* Clear the window. */ |
500 | if (d->isBlank) { | ||
501 | drawBlank_Window_(d); | ||
502 | return; | ||
503 | } | ||
482 | SDL_SetRenderDrawColor(d->render, 0, 0, 0, 255); | 504 | SDL_SetRenderDrawColor(d->render, 0, 0, 0, 255); |
483 | SDL_RenderClear(d->render); | 505 | SDL_RenderClear(d->render); |
484 | /* Draw widgets. */ | 506 | /* Draw widgets. */ |