dominus

Untitled

Nov 26th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.90 KB | None | 0 0
  1. diff --git a/cheat.cc b/cheat.cc
  2. index c542eb75..d0af000d 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, 0) && defined(MACOSX)
  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. diff --git a/exult.cc b/exult.cc
  18. index 4a9405d8..a40a6840 100644
  19. --- a/exult.cc
  20. +++ b/exult.cc
  21. @@ -2318,6 +2318,10 @@ void setup_video(bool fullscreen, int setup_video_type, int resx, int resy,
  22.     config->value("config/video/share_video_settings", share_settings, true);
  23.     const string vidStr((fullscreen || share_settings) ?
  24.                            "config/video" : "config/video/window");
  25. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  26. +   bool high_dpi;
  27. +   config->value("config/video/highdpi", high_dpi, true);
  28. + #endif
  29.     if (read_config) {
  30.  #ifdef DEBUG
  31.         cout << "Reading video menu adjustable configuration options" << endl;
  32. @@ -2360,6 +2364,12 @@ void setup_video(bool fullscreen, int setup_video_type, int resx, int resy,
  33.         config->value(vidStr + "/display/height", resy, resy * scaleval);
  34.         config->value(vidStr + "/game/width", gw, 320);
  35.         config->value(vidStr + "/game/height", gh, 200);
  36. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  37. +       if (high_dpi)
  38. +           SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0");
  39. +       else
  40. +           SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1");
  41. + #endif
  42.         config->value(vidStr + "/fill_mode", fmode_string, "Centre");
  43.         fillmode = Image_window::string_to_fillmode(fmode_string.c_str());
  44.         if (fillmode == 0)
  45. @@ -2389,6 +2399,10 @@ void setup_video(bool fullscreen, int setup_video_type, int resx, int resy,
  46.         config->set((vidStr + "/scale_method").c_str(), scalerName , false);
  47.         config->set((vidStr + "/fill_mode").c_str(), fmode_string, false);
  48.         config->set((vidStr + "/fill_scaler").c_str(), fillScalerName, false);
  49. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  50. +       config->set("config/video/highdpi", high_dpi ?
  51. +                   "yes" : "no", false);
  52. + #endif
  53.     }
  54.     if (video_init) {
  55.  #ifdef DEBUG
  56. diff --git a/gumps/VideoOptions_gump.cc b/gumps/VideoOptions_gump.cc
  57. index 7cfdca6f..7404e270 100644
  58. --- a/gumps/VideoOptions_gump.cc
  59. +++ b/gumps/VideoOptions_gump.cc
  60. @@ -136,6 +136,10 @@ void VideoOptions_gump::toggle(Gump_button *btn, int state) {
  61.         fill_mode = static_cast<Image_window::FillMode>((fill_mode&~1) | (has_ac ? 1 : 0));
  62.     } else if (btn == buttons[id_share_settings])
  63.         share_settings = state;
  64. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  65. +   else if (btn == buttons[id_high_dpi])
  66. +       highdpi = state;
  67. + #endif
  68.  
  69.     paint();
  70.  }
  71. @@ -336,6 +340,9 @@ void VideoOptions_gump::load_settings(bool Fullscreen) {
  72.     o_fill_scaler = fill_scaler;
  73.     o_fill_mode = fill_mode;
  74.     o_game_resolution = game_resolution;
  75. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  76. +   o_highdpi = highdpi;
  77. + #endif
  78.  }
  79.  
  80.  VideoOptions_gump::VideoOptions_gump() : Modal_gump(0, EXULT_FLX_VIDEOOPTIONS_SHP, SF_EXULT_FLX) {
  81. @@ -349,6 +356,16 @@ VideoOptions_gump::VideoOptions_gump() : Modal_gump(0, EXULT_FLX_VIDEOOPTIONS_SH
  82.     enabledtext[1] = "Enabled";
  83.     buttons[id_fullscreen] = new VideoTextToggle(this, enabledtext, colx[2], rowy[0], 74,
  84.             fullscreen, 2);
  85. +
  86. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  87. +   config->value("config/video/highdpi", highdpi, false);
  88. +   std::string *hdpi_text = new std::string[2];
  89. +   hdpi_text[0] = "Disabled";
  90. +   hdpi_text[1] = "Enabled";
  91. +   buttons[id_high_dpi] = new VideoTextToggle(this, hdpi_text, colx[2], rowy[2], 74,
  92. +           highdpi, 2);
  93. +#endif
  94. +          
  95.     config->value("config/video/share_video_settings", share_settings, false);
  96.     std::string *yesNO = new std::string[2];
  97.     yesNO[0] = "No";
  98. @@ -385,6 +402,12 @@ void VideoOptions_gump::save_settings() {
  99.         if (!Yesno_gump::ask("Scaled size less than 320x200.\nExult may be unusable.\nApply anyway?", "TINY_BLACK_FONT"))
  100.             return;
  101.     }
  102. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  103. +   if (highdpi != o_highdpi) {
  104. +       if (!Yesno_gump::ask("After toggling HighDPi you will need to restart Exult!\nApply anyway?", "TINY_BLACK_FONT"))
  105. +           return;
  106. +   }
  107. + #endif
  108.     gwin->resized(resx, resy, fullscreen != 0, gw, gh, scaling + 1, scaler, fill_mode,
  109.                   fill_scaler ? Image_window::bilinear : Image_window::point);
  110.     gclock->set_palette();
  111. @@ -411,6 +434,9 @@ void VideoOptions_gump::save_settings() {
  112.         config->set("config/video/share_video_settings", share_settings ? "yes" : "no", false);
  113.         setup_video(fullscreen != 0, SET_CONFIG, resx, resy, gw, gh, scaling + 1, scaler, fill_mode,
  114.                     fill_scaler ? Image_window::bilinear : Image_window::point);
  115. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  116. +       config->set("config/video/highdpi", highdpi ? "yes" : "no", false);
  117. +#endif
  118.         config->write_back();
  119.         o_resolution = resolution;
  120.         o_scaling = scaling;
  121. @@ -419,6 +445,9 @@ void VideoOptions_gump::save_settings() {
  122.         o_fill_mode = fill_mode;
  123.         o_fill_scaler = fill_scaler;
  124.         o_share_settings = share_settings;
  125. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  126. +       o_highdpi = highdpi;
  127. + #endif
  128.     }
  129.  }
  130.  
  131. @@ -433,6 +462,9 @@ void VideoOptions_gump::paint() {
  132.     font->paint_text(iwin->get_ib8(), "Full Screen:", x + colx[0], y + rowy[0] + 1);
  133.     if (fullscreen) font->paint_text(iwin->get_ib8(), "Display Mode:", x + colx[0], y + rowy[1] + 1);
  134.     else font->paint_text(iwin->get_ib8(), "Window Size:", x + colx[0], y + rowy[1] + 1);
  135. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  136. +   font->paint_text(iwin->get_ib8(), "HighDpi:", x + colx[0], y + rowy[2] + 1);
  137. + #endif
  138.     font->paint_text(iwin->get_ib8(), "Scaler:", x + colx[0], y + rowy[3] + 1);
  139.     if (buttons[id_scaling]) font->paint_text(iwin->get_ib8(), "Scaling:", x + colx[0], y + rowy[4] + 1);
  140.     font->paint_text(iwin->get_ib8(), "Game Area:", x + colx[0], y + rowy[6] + 1);
  141. diff --git a/gumps/VideoOptions_gump.h b/gumps/VideoOptions_gump.h
  142. index 87a19127..74004acc 100644
  143. --- a/gumps/VideoOptions_gump.h
  144. +++ b/gumps/VideoOptions_gump.h
  145. @@ -47,6 +47,10 @@ class VideoOptions_gump : public Modal_gump {
  146.     uint32 o_game_resolution;
  147.     int o_fill_scaler;
  148.     Image_window::FillMode o_fill_mode;
  149. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  150. +   bool highdpi;
  151. +   bool o_highdpi;
  152. +#endif
  153.  
  154.     static uint32 *resolutions;
  155.     static int num_resolutions;
  156. @@ -64,6 +68,9 @@ class VideoOptions_gump : public Modal_gump {
  157.         id_apply = id_first,
  158.         id_fullscreen,
  159.         id_share_settings,
  160. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  161. +       id_high_dpi,
  162. +#endif
  163.         id_resolution,  // id_resolution and all past it
  164.         id_scaler,      // are deleted by rebuild_buttons
  165.         id_scaling,
  166. diff --git a/imagewin/imagewin.cc b/imagewin/imagewin.cc
  167. index 0f6779fc..8759cf99 100644
  168. --- a/imagewin/imagewin.cc
  169. +++ b/imagewin/imagewin.cc
  170. @@ -102,6 +102,9 @@ int Image_window::desktop_depth = 0;
  171.  int Image_window::windowed_8 = 0;
  172.  int Image_window::windowed_16 = 0;
  173.  int Image_window::windowed_32 = 0;
  174. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  175. +float Image_window::nativescale = 1.0;
  176. +#endif
  177.  
  178.  const int Image_window::guard_band = 4;
  179.  
  180. @@ -691,6 +694,11 @@ bool Image_window::create_scale_surfaces(int w, int h, int bpp) {
  181.         h=dh;
  182.         Resolution res = { w, h, false, false, false};
  183.         p_resolutions[(w << 16) | h] = res;
  184. +       //getting new native scale when highdpi is active
  185. +       int sw;
  186. +       SDL_GetWindowSize(screen_window, &sw, 0);
  187. +       nativescale = dw / sw;
  188. +
  189.         //high resolution fullscreen needs this to make the whole screen available
  190.         SDL_RenderSetLogicalSize(screen_renderer, w, h);
  191.     } else
  192. diff --git a/imagewin/imagewin.h b/imagewin/imagewin.h
  193. index 8e018612..a422637a 100644
  194. --- a/imagewin/imagewin.h
  195. +++ b/imagewin/imagewin.h
  196. @@ -293,6 +293,9 @@ class Image_window {
  197.     static int windowed_8;
  198.     static int windowed_16;
  199.     static int windowed_32;
  200. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  201. +   static float nativescale;
  202. +#endif
  203.  
  204.  public:
  205.  #if SDL_VERSION_ATLEAST(2, 0, 0)
  206. @@ -334,6 +337,19 @@ class Image_window {
  207.             gy = (sy * inter_height) / (scale * get_display_height()) + get_start_y();
  208.         }
  209.     }
  210. +
  211. +#if SDL_VERSION_ATLEAST(2, 0, 0) && defined(MACOSX)
  212. +   void screen_to_game_hdpi(int sx, int sy, bool fast, int &gx, int &gy) {
  213. +       if (fast) {
  214. +           gx = (sx + get_start_x())* nativescale;
  215. +           gy = (sy + get_start_y())* nativescale;
  216. +       } else {
  217. +           gx = ((sx * inter_width) / (scale * get_display_width()) + get_start_x()) * nativescale;
  218. +           gy = ((sy * inter_height) / (scale * get_display_height()) + get_start_y()) * nativescale;
  219. +       }
  220. +   }
  221. + #endif
  222. +
  223.     void game_to_screen(int gx, int gy, bool fast, int &sx, int &sy) {
  224.         if (fast) {
  225.             sx = gx - get_start_x();
Add Comment
Please, Sign In to add comment