Skip to content

Commit

Permalink
Application.setWindowSize, Application.setFullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
gecko0307 committed Mar 14, 2024
1 parent d120763 commit bb622e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
23 changes: 19 additions & 4 deletions src/dagon/core/application.d
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class Application: EventListener
{
uint width;
uint height;
bool fullscreen = false;
SDL_Window* window = null;
SDL_GLContext glcontext;
private EventManager _eventManager;
Expand Down Expand Up @@ -188,6 +189,7 @@ class Application: EventListener

width = winWidth;
height = winHeight;
this.fullscreen = fullscreen;

SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
Expand Down Expand Up @@ -222,9 +224,8 @@ class Application: EventListener
{
exitWithError("Error: failed to load OpenGL functions. Please, update graphics card driver and make sure it supports OpenGL 4.0");
}

if (fullscreen)
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);

setFullscreen(fullscreen);

_eventManager = New!EventManager(window, width, height);
super(_eventManager, null);
Expand Down Expand Up @@ -270,11 +271,25 @@ class Application: EventListener
SDL_Quit();
Delete(_eventManager);
}


void setWindowSize(uint w, uint h)
{
SDL_SetWindowSize(window, w, h);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}

void maximizeWindow()
{
SDL_MaximizeWindow(window);
}

void setFullscreen(bool mode)
{
if (mode)
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
else
SDL_SetWindowFullscreen(window, 0);
}

override void onUserEvent(int code)
{
Expand Down
8 changes: 4 additions & 4 deletions src/dagon/game/game.d
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ class Game: Application

void resize(int width, int height)
{
renderer.setViewport(0, 0, width, height);
postProcessingRenderer.setViewport(0, 0, width, height);
presentRenderer.setViewport(0, 0, width, height);
hudRenderer.setViewport(0, 0, width, height);
if (renderer) renderer.setViewport(0, 0, width, height);
if (postProcessingRenderer) postProcessingRenderer.setViewport(0, 0, width, height);
if (presentRenderer) presentRenderer.setViewport(0, 0, width, height);
if (hudRenderer) hudRenderer.setViewport(0, 0, width, height);
}

override void onResize(int width, int height)
Expand Down

0 comments on commit bb622e9

Please sign in to comment.