Skip to content

Commit

Permalink
Adding fullscreen/windowed mode option
Browse files Browse the repository at this point in the history
  • Loading branch information
igorribeiroduarte committed Jun 9, 2016
1 parent b81ba32 commit 525ef0f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace ijengine {

namespace video {
Window * create_window(const string& title, int w, int h, double scale);
void set_full_screen(int mode);
}

namespace audio {
Expand Down
1 change: 1 addition & 0 deletions include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace ijengine {

virtual Window * create_window(const string& title, int w, int h,
double scale) = 0;
virtual void set_full_screen(int mode) = 0;

virtual void set_audio_dir(const string& dir_path) = 0;
virtual void play_audio_from_path(const string& title) = 0;
Expand Down
1 change: 1 addition & 0 deletions include/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace ijengine {
public:
virtual ~Video() = default;
virtual Window * create_window(const string& title, int w, int h) = 0;
virtual void set_full_screen(int mode) = 0;
};

}
Expand Down
17 changes: 17 additions & 0 deletions kernel/sdl2/sdl2kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,26 @@ SDL2Kernel::create_window(const string& title, int w, int h, double scale)
SDL_SetWindowTitle(window, title.c_str());
SDL_RenderSetScale(renderer, scale, scale);

m_window = window;

return new SDL2Window(window, renderer);
}

void
SDL2Kernel::set_full_screen(int mode)
{
int flag;

if(mode == 0)
flag = 0;
else if(mode == 1)
flag = SDL_WINDOW_FULLSCREEN;
else
flag = SDL_WINDOW_FULLSCREEN_DESKTOP;

SDL_SetWindowFullscreen(m_window, flag);
}

static KeyboardEvent::Modifier
key_modifier(Uint16 modifier)
{
Expand Down
4 changes: 4 additions & 0 deletions kernel/sdl2/sdl2kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class SDL2Kernel : public Kernel {

Window * create_window(const string& title, int w, int h, double scale);

void set_full_screen(int mode);

void set_audio_dir(const string& dir_path);
void play_audio_from_path(const string& title);
void stop_audio();
Expand Down Expand Up @@ -44,6 +46,8 @@ class SDL2Kernel : public Kernel {

void init_table();
void update_pending_events(unsigned now);

SDL_Window *m_window;
};

#endif
5 changes: 5 additions & 0 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ namespace ijengine
{
return kernel->create_window(title, w, h, scale);
}

void
set_full_screen(int mode){
return kernel->set_full_screen(mode);
}
}

namespace audio
Expand Down
5 changes: 5 additions & 0 deletions test/src/test_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ TestLevel::TestLevel(int r, int g, int b, const string& next_level, const string
{
RandomRect *rect = new RandomRect(r, g, b, 200, 200);

//0 for windowed mode
//1 for fullscreen mode
//2 for fullscreen-desktop mode
video::set_full_screen(0);

add_child(rect);
}

Expand Down

0 comments on commit 525ef0f

Please sign in to comment.