Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/cheat.cc b/cheat.cc
- index c542eb75..66a8d7c9 100644
- --- a/cheat.cc
- +++ b/cheat.cc
- @@ -842,7 +842,11 @@ void Cheat::cursor_teleport(void) const {
- int x, y;
- SDL_GetMouseState(&x, &y);
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + gwin->get_win()->screen_to_game_hdpi(x, y, gwin->get_fastmouse(), x, y);
- +#else
- gwin->get_win()->screen_to_game(x, y, gwin->get_fastmouse(), x, y);
- +#endif
- Tile_coord t(gwin->get_scrolltx() + x / c_tilesize,
- gwin->get_scrollty() + y / c_tilesize, 0);
- t.fixme();
- @@ -899,7 +903,11 @@ void Cheat::delete_object(void) {
- int x, y;
- SDL_GetMouseState(&x, &y);
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + gwin->get_win()->screen_to_game_hdpi(x, y, gwin->get_fastmouse(), x, y);
- +#else
- gwin->get_win()->screen_to_game(x, y, gwin->get_fastmouse(), x, y);
- +#endif
- Game_object *obj;
- Gump *gump = gwin->get_gump_man()->find_gump(x, y);
- diff --git a/exult.cc b/exult.cc
- index 4a9405d8..283e03f6 100644
- --- a/exult.cc
- +++ b/exult.cc
- @@ -1268,7 +1268,12 @@ static void Handle_events(
- gwin->main_actor_can_act_charmed()) {
- int x, y;// Check for 'stuck' Avatar.
- int ms = SDL_GetMouseState(&x, &y);
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + //mouse movement needs to be adjusted for HighDPI
- + gwin->get_win()->screen_to_game_hdpi(x, y, gwin->get_fastmouse(), x, y);
- +#else
- gwin->get_win()->screen_to_game(x, y, gwin->get_fastmouse(), x, y);
- +#endif
- if ((SDL_BUTTON(3) & ms) && !right_on_gump)
- gwin->start_actor(x, y,
- Mouse::mouse->avatar_speed);
- @@ -2086,7 +2091,12 @@ void Wizard_eye(
- int x, y;
- int ms = SDL_GetMouseState(&x, &y);
- int mx, my;
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + //mouse movement of the eye needs to adjust for HighDPI
- + gwin->get_win()->screen_to_game_hdpi(x, y, gwin->get_fastmouse(), mx, my);
- +#else
- gwin->get_win()->screen_to_game(x, y, gwin->get_fastmouse(), mx, my);
- +#endif
- if (SDL_BUTTON(3) & ms)
- Shift_wizards_eye(mx, my);
- gwin->set_all_dirty();
- @@ -2318,6 +2328,10 @@ void setup_video(bool fullscreen, int setup_video_type, int resx, int resy,
- config->value("config/video/share_video_settings", share_settings, true);
- const string vidStr((fullscreen || share_settings) ?
- "config/video" : "config/video/window");
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + bool high_dpi;
- + config->value("config/video/highdpi", high_dpi, true);
- +#endif
- if (read_config) {
- #ifdef DEBUG
- cout << "Reading video menu adjustable configuration options" << endl;
- @@ -2360,6 +2374,12 @@ void setup_video(bool fullscreen, int setup_video_type, int resx, int resy,
- config->value(vidStr + "/display/height", resy, resy * scaleval);
- config->value(vidStr + "/game/width", gw, 320);
- config->value(vidStr + "/game/height", gh, 200);
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + if (high_dpi)
- + SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0");
- + else
- + SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1");
- +#endif
- config->value(vidStr + "/fill_mode", fmode_string, "Centre");
- fillmode = Image_window::string_to_fillmode(fmode_string.c_str());
- if (fillmode == 0)
- @@ -2389,6 +2409,10 @@ void setup_video(bool fullscreen, int setup_video_type, int resx, int resy,
- config->set((vidStr + "/scale_method").c_str(), scalerName , false);
- config->set((vidStr + "/fill_mode").c_str(), fmode_string, false);
- config->set((vidStr + "/fill_scaler").c_str(), fillScalerName, false);
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + config->set("config/video/highdpi", high_dpi ?
- + "yes" : "no", false);
- +#endif
- }
- if (video_init) {
- #ifdef DEBUG
- diff --git a/gumps/VideoOptions_gump.cc b/gumps/VideoOptions_gump.cc
- index 7cfdca6f..cb49b14c 100644
- --- a/gumps/VideoOptions_gump.cc
- +++ b/gumps/VideoOptions_gump.cc
- @@ -136,6 +136,10 @@ void VideoOptions_gump::toggle(Gump_button *btn, int state) {
- fill_mode = static_cast<Image_window::FillMode>((fill_mode&~1) | (has_ac ? 1 : 0));
- } else if (btn == buttons[id_share_settings])
- share_settings = state;
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + else if (btn == buttons[id_high_dpi])
- + highdpi = state;
- + #endif
- paint();
- }
- @@ -336,6 +340,9 @@ void VideoOptions_gump::load_settings(bool Fullscreen) {
- o_fill_scaler = fill_scaler;
- o_fill_mode = fill_mode;
- o_game_resolution = game_resolution;
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + o_highdpi = highdpi;
- +#endif
- }
- VideoOptions_gump::VideoOptions_gump() : Modal_gump(0, EXULT_FLX_VIDEOOPTIONS_SHP, SF_EXULT_FLX) {
- @@ -349,6 +356,14 @@ VideoOptions_gump::VideoOptions_gump() : Modal_gump(0, EXULT_FLX_VIDEOOPTIONS_SH
- enabledtext[1] = "Enabled";
- buttons[id_fullscreen] = new VideoTextToggle(this, enabledtext, colx[2], rowy[0], 74,
- fullscreen, 2);
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + config->value("config/video/highdpi", highdpi, false);
- + std::string *hdpi_text = new std::string[2];
- + hdpi_text[0] = "Disabled";
- + hdpi_text[1] = "Enabled";
- + buttons[id_high_dpi] = new VideoTextToggle(this, hdpi_text, colx[2], rowy[2], 74,
- + highdpi, 2);
- +#endif
- config->value("config/video/share_video_settings", share_settings, false);
- std::string *yesNO = new std::string[2];
- yesNO[0] = "No";
- @@ -385,6 +400,12 @@ void VideoOptions_gump::save_settings() {
- if (!Yesno_gump::ask("Scaled size less than 320x200.\nExult may be unusable.\nApply anyway?", "TINY_BLACK_FONT"))
- return;
- }
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + if (highdpi != o_highdpi) {
- + if (!Yesno_gump::ask("After toggling HighDPI you will need to restart Exult!\nApply anyway?", "TINY_BLACK_FONT"))
- + return;
- + }
- +#endif
- gwin->resized(resx, resy, fullscreen != 0, gw, gh, scaling + 1, scaler, fill_mode,
- fill_scaler ? Image_window::bilinear : Image_window::point);
- gclock->set_palette();
- @@ -411,6 +432,9 @@ void VideoOptions_gump::save_settings() {
- config->set("config/video/share_video_settings", share_settings ? "yes" : "no", false);
- setup_video(fullscreen != 0, SET_CONFIG, resx, resy, gw, gh, scaling + 1, scaler, fill_mode,
- fill_scaler ? Image_window::bilinear : Image_window::point);
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + config->set("config/video/highdpi", highdpi ? "yes" : "no", false);
- +#endif
- config->write_back();
- o_resolution = resolution;
- o_scaling = scaling;
- @@ -419,6 +443,9 @@ void VideoOptions_gump::save_settings() {
- o_fill_mode = fill_mode;
- o_fill_scaler = fill_scaler;
- o_share_settings = share_settings;
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + o_highdpi = highdpi;
- +#endif
- }
- }
- @@ -433,6 +460,9 @@ void VideoOptions_gump::paint() {
- font->paint_text(iwin->get_ib8(), "Full Screen:", x + colx[0], y + rowy[0] + 1);
- if (fullscreen) font->paint_text(iwin->get_ib8(), "Display Mode:", x + colx[0], y + rowy[1] + 1);
- else font->paint_text(iwin->get_ib8(), "Window Size:", x + colx[0], y + rowy[1] + 1);
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + font->paint_text(iwin->get_ib8(), "HighDPI:", x + colx[0], y + rowy[2] + 1);
- +#endif
- font->paint_text(iwin->get_ib8(), "Scaler:", x + colx[0], y + rowy[3] + 1);
- if (buttons[id_scaling]) font->paint_text(iwin->get_ib8(), "Scaling:", x + colx[0], y + rowy[4] + 1);
- font->paint_text(iwin->get_ib8(), "Game Area:", x + colx[0], y + rowy[6] + 1);
- diff --git a/gumps/VideoOptions_gump.h b/gumps/VideoOptions_gump.h
- index 87a19127..e8af78ab 100644
- --- a/gumps/VideoOptions_gump.h
- +++ b/gumps/VideoOptions_gump.h
- @@ -47,6 +47,10 @@ class VideoOptions_gump : public Modal_gump {
- uint32 o_game_resolution;
- int o_fill_scaler;
- Image_window::FillMode o_fill_mode;
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + bool highdpi;
- + bool o_highdpi;
- +#endif
- static uint32 *resolutions;
- static int num_resolutions;
- @@ -64,6 +68,9 @@ class VideoOptions_gump : public Modal_gump {
- id_apply = id_first,
- id_fullscreen,
- id_share_settings,
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + id_high_dpi,
- +#endif
- id_resolution, // id_resolution and all past it
- id_scaler, // are deleted by rebuild_buttons
- id_scaling,
- diff --git a/imagewin/imagewin.cc b/imagewin/imagewin.cc
- index 0f6779fc..e971bf0c 100644
- --- a/imagewin/imagewin.cc
- +++ b/imagewin/imagewin.cc
- @@ -102,6 +102,10 @@ int Image_window::desktop_depth = 0;
- int Image_window::windowed_8 = 0;
- int Image_window::windowed_16 = 0;
- int Image_window::windowed_32 = 0;
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- +//When HighDPI is enabled we will end up with a different native scale factor, so we need to define the default
- +float Image_window::nativescale = 1.0;
- +#endif
- const int Image_window::guard_band = 4;
- @@ -654,7 +658,7 @@ bool Image_window::create_scale_surfaces(int w, int h, int bpp) {
- // Get best bpp
- flags = SDL_SWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0);
- -#if SDL_VERSION_ATLEAST(2, 0, 0) && defined (MACOSX)
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- flags |= SDL_WINDOW_ALLOW_HIGHDPI;
- #endif
- #ifdef __IPHONEOS__
- @@ -691,6 +695,10 @@ bool Image_window::create_scale_surfaces(int w, int h, int bpp) {
- h=dh;
- Resolution res = { w, h, false, false, false};
- p_resolutions[(w << 16) | h] = res;
- + //getting new native scale when highdpi is active
- + int sw;
- + SDL_GetWindowSize(screen_window, &sw, 0);
- + nativescale = dw / sw;
- //high resolution fullscreen needs this to make the whole screen available
- SDL_RenderSetLogicalSize(screen_renderer, w, h);
- } else
- diff --git a/imagewin/imagewin.h b/imagewin/imagewin.h
- index 8e018612..ee9ecd5d 100644
- --- a/imagewin/imagewin.h
- +++ b/imagewin/imagewin.h
- @@ -293,6 +293,9 @@ class Image_window {
- static int windowed_8;
- static int windowed_16;
- static int windowed_32;
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + static float nativescale;
- +#endif
- public:
- #if SDL_VERSION_ATLEAST(2, 0, 0)
- @@ -334,6 +337,17 @@ class Image_window {
- gy = (sy * inter_height) / (scale * get_display_height()) + get_start_y();
- }
- }
- +#if SDL_VERSION_ATLEAST(2, 0, 1)
- + void screen_to_game_hdpi(int sx, int sy, bool fast, int &gx, int &gy) {
- + if (fast) {
- + gx = (sx + get_start_x())* nativescale;
- + gy = (sy + get_start_y())* nativescale;
- + } else {
- + gx = ((sx * inter_width) / (scale * get_display_width()) + get_start_x()) * nativescale;
- + gy = ((sy * inter_height) / (scale * get_display_height()) + get_start_y()) * nativescale;
- + }
- + }
- +#endif
- void game_to_screen(int gx, int gy, bool fast, int &sx, int &sy) {
- if (fast) {
- sx = gx - get_start_x();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement