Advertisement
dominus

Untitled

Nov 26th, 2018
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.40 KB | None | 0 0
  1. diff --git a/cheat.cc b/cheat.cc
  2. index c542eb75..66a8d7c9 100644
  3. --- a/cheat.cc
  4. +++ b/cheat.cc
  5. @@ -842,7 +842,11 @@ void Cheat::cursor_teleport(void) const {
  6.  
  7.     int x, y;
  8.     SDL_GetMouseState(&x, &y);
  9. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  10. +   gwin->get_win()->screen_to_game_hdpi(x, y, gwin->get_fastmouse(), x, y);
  11. +#else
  12.     gwin->get_win()->screen_to_game(x, y, gwin->get_fastmouse(), x, y);
  13. +#endif
  14.     Tile_coord t(gwin->get_scrolltx() + x / c_tilesize,
  15.                  gwin->get_scrollty() + y / c_tilesize, 0);
  16.     t.fixme();
  17. @@ -899,7 +903,11 @@ void Cheat::delete_object(void) {
  18.  
  19.     int x, y;
  20.     SDL_GetMouseState(&x, &y);
  21. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  22. +   gwin->get_win()->screen_to_game_hdpi(x, y, gwin->get_fastmouse(), x, y);
  23. +#else
  24.     gwin->get_win()->screen_to_game(x, y, gwin->get_fastmouse(), x, y);
  25. +#endif
  26.  
  27.     Game_object *obj;
  28.     Gump *gump = gwin->get_gump_man()->find_gump(x, y);
  29. diff --git a/exult.cc b/exult.cc
  30. index 4a9405d8..283e03f6 100644
  31. --- a/exult.cc
  32. +++ b/exult.cc
  33. @@ -1268,7 +1268,12 @@ static void Handle_events(
  34.                 gwin->main_actor_can_act_charmed()) {
  35.             int x, y;// Check for 'stuck' Avatar.
  36.             int ms = SDL_GetMouseState(&x, &y);
  37. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  38. +           //mouse movement needs to be adjusted for HighDPI
  39. +           gwin->get_win()->screen_to_game_hdpi(x, y, gwin->get_fastmouse(), x, y);
  40. +#else
  41.             gwin->get_win()->screen_to_game(x, y, gwin->get_fastmouse(), x, y);
  42. +#endif
  43.             if ((SDL_BUTTON(3) & ms) && !right_on_gump)
  44.                 gwin->start_actor(x, y,
  45.                                   Mouse::mouse->avatar_speed);
  46. @@ -2086,7 +2091,12 @@ void Wizard_eye(
  47.             int x, y;
  48.             int ms = SDL_GetMouseState(&x, &y);
  49.             int mx, my;
  50. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  51. +           //mouse movement of the eye needs to adjust for HighDPI
  52. +           gwin->get_win()->screen_to_game_hdpi(x, y, gwin->get_fastmouse(), mx, my);
  53. +#else
  54.             gwin->get_win()->screen_to_game(x, y, gwin->get_fastmouse(), mx, my);
  55. +#endif
  56.             if (SDL_BUTTON(3) & ms)
  57.                 Shift_wizards_eye(mx, my);
  58.             gwin->set_all_dirty();
  59. @@ -2318,6 +2328,10 @@ void setup_video(bool fullscreen, int setup_video_type, int resx, int resy,
  60.     config->value("config/video/share_video_settings", share_settings, true);
  61.     const string vidStr((fullscreen || share_settings) ?
  62.                            "config/video" : "config/video/window");
  63. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  64. +   bool high_dpi;
  65. +   config->value("config/video/highdpi", high_dpi, true);
  66. +#endif
  67.     if (read_config) {
  68.  #ifdef DEBUG
  69.         cout << "Reading video menu adjustable configuration options" << endl;
  70. @@ -2360,6 +2374,12 @@ void setup_video(bool fullscreen, int setup_video_type, int resx, int resy,
  71.         config->value(vidStr + "/display/height", resy, resy * scaleval);
  72.         config->value(vidStr + "/game/width", gw, 320);
  73.         config->value(vidStr + "/game/height", gh, 200);
  74. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  75. +       if (high_dpi)
  76. +           SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0");
  77. +       else
  78. +           SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1");
  79. +#endif
  80.         config->value(vidStr + "/fill_mode", fmode_string, "Centre");
  81.         fillmode = Image_window::string_to_fillmode(fmode_string.c_str());
  82.         if (fillmode == 0)
  83. @@ -2389,6 +2409,10 @@ void setup_video(bool fullscreen, int setup_video_type, int resx, int resy,
  84.         config->set((vidStr + "/scale_method").c_str(), scalerName , false);
  85.         config->set((vidStr + "/fill_mode").c_str(), fmode_string, false);
  86.         config->set((vidStr + "/fill_scaler").c_str(), fillScalerName, false);
  87. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  88. +       config->set("config/video/highdpi", high_dpi ?
  89. +                   "yes" : "no", false);
  90. +#endif
  91.     }
  92.     if (video_init) {
  93.  #ifdef DEBUG
  94. diff --git a/gumps/VideoOptions_gump.cc b/gumps/VideoOptions_gump.cc
  95. index 7cfdca6f..cb49b14c 100644
  96. --- a/gumps/VideoOptions_gump.cc
  97. +++ b/gumps/VideoOptions_gump.cc
  98. @@ -136,6 +136,10 @@ void VideoOptions_gump::toggle(Gump_button *btn, int state) {
  99.         fill_mode = static_cast<Image_window::FillMode>((fill_mode&~1) | (has_ac ? 1 : 0));
  100.     } else if (btn == buttons[id_share_settings])
  101.         share_settings = state;
  102. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  103. +   else if (btn == buttons[id_high_dpi])
  104. +       highdpi = state;
  105. + #endif
  106.  
  107.     paint();
  108.  }
  109. @@ -336,6 +340,9 @@ void VideoOptions_gump::load_settings(bool Fullscreen) {
  110.     o_fill_scaler = fill_scaler;
  111.     o_fill_mode = fill_mode;
  112.     o_game_resolution = game_resolution;
  113. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  114. +   o_highdpi = highdpi;
  115. +#endif
  116.  }
  117.  
  118.  VideoOptions_gump::VideoOptions_gump() : Modal_gump(0, EXULT_FLX_VIDEOOPTIONS_SHP, SF_EXULT_FLX) {
  119. @@ -349,6 +356,14 @@ VideoOptions_gump::VideoOptions_gump() : Modal_gump(0, EXULT_FLX_VIDEOOPTIONS_SH
  120.     enabledtext[1] = "Enabled";
  121.     buttons[id_fullscreen] = new VideoTextToggle(this, enabledtext, colx[2], rowy[0], 74,
  122.             fullscreen, 2);
  123. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  124. +   config->value("config/video/highdpi", highdpi, false);
  125. +   std::string *hdpi_text = new std::string[2];
  126. +   hdpi_text[0] = "Disabled";
  127. +   hdpi_text[1] = "Enabled";
  128. +   buttons[id_high_dpi] = new VideoTextToggle(this, hdpi_text, colx[2], rowy[2], 74,
  129. +           highdpi, 2);
  130. +#endif
  131.     config->value("config/video/share_video_settings", share_settings, false);
  132.     std::string *yesNO = new std::string[2];
  133.     yesNO[0] = "No";
  134. @@ -385,6 +400,12 @@ void VideoOptions_gump::save_settings() {
  135.         if (!Yesno_gump::ask("Scaled size less than 320x200.\nExult may be unusable.\nApply anyway?", "TINY_BLACK_FONT"))
  136.             return;
  137.     }
  138. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  139. +   if (highdpi != o_highdpi) {
  140. +       if (!Yesno_gump::ask("After toggling HighDPI you will need to restart Exult!\nApply anyway?", "TINY_BLACK_FONT"))
  141. +           return;
  142. +   }
  143. +#endif
  144.     gwin->resized(resx, resy, fullscreen != 0, gw, gh, scaling + 1, scaler, fill_mode,
  145.                   fill_scaler ? Image_window::bilinear : Image_window::point);
  146.     gclock->set_palette();
  147. @@ -411,6 +432,9 @@ void VideoOptions_gump::save_settings() {
  148.         config->set("config/video/share_video_settings", share_settings ? "yes" : "no", false);
  149.         setup_video(fullscreen != 0, SET_CONFIG, resx, resy, gw, gh, scaling + 1, scaler, fill_mode,
  150.                     fill_scaler ? Image_window::bilinear : Image_window::point);
  151. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  152. +       config->set("config/video/highdpi", highdpi ? "yes" : "no", false);
  153. +#endif
  154.         config->write_back();
  155.         o_resolution = resolution;
  156.         o_scaling = scaling;
  157. @@ -419,6 +443,9 @@ void VideoOptions_gump::save_settings() {
  158.         o_fill_mode = fill_mode;
  159.         o_fill_scaler = fill_scaler;
  160.         o_share_settings = share_settings;
  161. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  162. +       o_highdpi = highdpi;
  163. +#endif
  164.     }
  165.  }
  166.  
  167. @@ -433,6 +460,9 @@ void VideoOptions_gump::paint() {
  168.     font->paint_text(iwin->get_ib8(), "Full Screen:", x + colx[0], y + rowy[0] + 1);
  169.     if (fullscreen) font->paint_text(iwin->get_ib8(), "Display Mode:", x + colx[0], y + rowy[1] + 1);
  170.     else font->paint_text(iwin->get_ib8(), "Window Size:", x + colx[0], y + rowy[1] + 1);
  171. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  172. +   font->paint_text(iwin->get_ib8(), "HighDPI:", x + colx[0], y + rowy[2] + 1);
  173. +#endif
  174.     font->paint_text(iwin->get_ib8(), "Scaler:", x + colx[0], y + rowy[3] + 1);
  175.     if (buttons[id_scaling]) font->paint_text(iwin->get_ib8(), "Scaling:", x + colx[0], y + rowy[4] + 1);
  176.     font->paint_text(iwin->get_ib8(), "Game Area:", x + colx[0], y + rowy[6] + 1);
  177. diff --git a/gumps/VideoOptions_gump.h b/gumps/VideoOptions_gump.h
  178. index 87a19127..e8af78ab 100644
  179. --- a/gumps/VideoOptions_gump.h
  180. +++ b/gumps/VideoOptions_gump.h
  181. @@ -47,6 +47,10 @@ class VideoOptions_gump : public Modal_gump {
  182.     uint32 o_game_resolution;
  183.     int o_fill_scaler;
  184.     Image_window::FillMode o_fill_mode;
  185. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  186. +   bool highdpi;
  187. +   bool o_highdpi;
  188. +#endif
  189.  
  190.     static uint32 *resolutions;
  191.     static int num_resolutions;
  192. @@ -64,6 +68,9 @@ class VideoOptions_gump : public Modal_gump {
  193.         id_apply = id_first,
  194.         id_fullscreen,
  195.         id_share_settings,
  196. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  197. +       id_high_dpi,
  198. +#endif
  199.         id_resolution,  // id_resolution and all past it
  200.         id_scaler,      // are deleted by rebuild_buttons
  201.         id_scaling,
  202. diff --git a/imagewin/imagewin.cc b/imagewin/imagewin.cc
  203. index 0f6779fc..e971bf0c 100644
  204. --- a/imagewin/imagewin.cc
  205. +++ b/imagewin/imagewin.cc
  206. @@ -102,6 +102,10 @@ int Image_window::desktop_depth = 0;
  207.  int Image_window::windowed_8 = 0;
  208.  int Image_window::windowed_16 = 0;
  209.  int Image_window::windowed_32 = 0;
  210. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  211. +//When HighDPI is enabled we will end up with a different native scale factor, so we need to define the default
  212. +float Image_window::nativescale = 1.0;
  213. +#endif
  214.  
  215.  const int Image_window::guard_band = 4;
  216.  
  217. @@ -654,7 +658,7 @@ bool Image_window::create_scale_surfaces(int w, int h, int bpp) {
  218.  
  219.     // Get best bpp
  220.     flags = SDL_SWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0);
  221. -#if SDL_VERSION_ATLEAST(2, 0, 0) && defined (MACOSX)
  222. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  223.         flags |= SDL_WINDOW_ALLOW_HIGHDPI;
  224.  #endif
  225.  #ifdef __IPHONEOS__
  226. @@ -691,6 +695,10 @@ bool Image_window::create_scale_surfaces(int w, int h, int bpp) {
  227.         h=dh;
  228.         Resolution res = { w, h, false, false, false};
  229.         p_resolutions[(w << 16) | h] = res;
  230. +       //getting new native scale when highdpi is active
  231. +       int sw;
  232. +       SDL_GetWindowSize(screen_window, &sw, 0);
  233. +       nativescale = dw / sw;
  234.         //high resolution fullscreen needs this to make the whole screen available
  235.         SDL_RenderSetLogicalSize(screen_renderer, w, h);
  236.     } else
  237. diff --git a/imagewin/imagewin.h b/imagewin/imagewin.h
  238. index 8e018612..ee9ecd5d 100644
  239. --- a/imagewin/imagewin.h
  240. +++ b/imagewin/imagewin.h
  241. @@ -293,6 +293,9 @@ class Image_window {
  242.     static int windowed_8;
  243.     static int windowed_16;
  244.     static int windowed_32;
  245. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  246. +   static float nativescale;
  247. +#endif
  248.  
  249.  public:
  250.  #if SDL_VERSION_ATLEAST(2, 0, 0)
  251. @@ -334,6 +337,17 @@ class Image_window {
  252.             gy = (sy * inter_height) / (scale * get_display_height()) + get_start_y();
  253.         }
  254.     }
  255. +#if SDL_VERSION_ATLEAST(2, 0, 1)
  256. +   void screen_to_game_hdpi(int sx, int sy, bool fast, int &gx, int &gy) {
  257. +       if (fast) {
  258. +           gx = (sx + get_start_x())* nativescale;
  259. +           gy = (sy + get_start_y())* nativescale;
  260. +       } else {
  261. +           gx = ((sx * inter_width) / (scale * get_display_width()) + get_start_x()) * nativescale;
  262. +           gy = ((sy * inter_height) / (scale * get_display_height()) + get_start_y()) * nativescale;
  263. +       }
  264. +   }
  265. +#endif
  266.     void game_to_screen(int gx, int gy, bool fast, int &sx, int &sy) {
  267.         if (fast) {
  268.             sx = gx - get_start_x();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement