Support enabling windowed mode
This commit is contained in:
parent
323b264b41
commit
a8c89f84bd
5 changed files with 26 additions and 1 deletions
|
|
@ -72,6 +72,7 @@ extern "C" jlong Java_psemek_app_PsemekApplication_createNativeApp(JNIEnv * env,
|
|||
psemek::app::application::context context;
|
||||
context.show_cursor = [](bool){};
|
||||
context.vsync = [](bool){};
|
||||
context.windowed = [](bool){};
|
||||
auto app = factory->create(factory->options(), context).release();
|
||||
|
||||
return reinterpret_cast<jlong>(app);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ namespace psemek::app
|
|||
std::vector<std::string> args;
|
||||
std::function<void(bool)> show_cursor;
|
||||
std::function<void(bool)> vsync;
|
||||
std::function<void(bool)> windowed;
|
||||
};
|
||||
|
||||
struct factory
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace psemek::sdl2
|
|||
void swap();
|
||||
void show_cursor(bool show);
|
||||
void vsync(bool on);
|
||||
void windowed(bool on);
|
||||
|
||||
private:
|
||||
std::shared_ptr<void> sdl_init_;
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ int main(int argc, char ** argv) try
|
|||
context.args.push_back(argv[i]);
|
||||
context.show_cursor = [&](bool show){ window.show_cursor(show); };
|
||||
context.vsync = [&](bool on){ window.vsync(on); };
|
||||
context.windowed = [&](bool on){ window.windowed(on); };
|
||||
|
||||
auto application = factory->create(options, context);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace psemek::sdl2
|
|||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, options.multisampling);
|
||||
}
|
||||
|
||||
std::uint32_t flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED | SDL_WINDOW_BORDERLESS | SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
std::uint32_t flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;
|
||||
if (options.highdpi) flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
|
||||
SDL_DisplayMode display_mode;
|
||||
|
|
@ -85,6 +85,27 @@ namespace psemek::sdl2
|
|||
}
|
||||
}
|
||||
|
||||
void window::windowed(bool on)
|
||||
{
|
||||
SDL_DisplayMode display_mode;
|
||||
SDL_GetCurrentDisplayMode(0, &display_mode);
|
||||
|
||||
SDL_Rect display_usable_bounds;
|
||||
SDL_GetDisplayUsableBounds(0, &display_usable_bounds);
|
||||
|
||||
SDL_SetWindowFullscreen(window_, on ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
SDL_SetWindowBordered(window_, on ? SDL_TRUE : SDL_FALSE);
|
||||
SDL_RestoreWindow(window_);
|
||||
if (on)
|
||||
{
|
||||
int top_border, left_border, bottom_border, right_border;
|
||||
SDL_GetWindowBordersSize(window_, &top_border, &left_border, &bottom_border, &right_border);
|
||||
|
||||
SDL_SetWindowSize(window_, display_usable_bounds.w - left_border - right_border, display_usable_bounds.h - top_border - bottom_border);
|
||||
SDL_SetWindowPosition(window_, left_border, top_border);
|
||||
}
|
||||
}
|
||||
|
||||
window::~window()
|
||||
{
|
||||
if (gl_context_)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue