Advertisement
dominus

Untitled

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