Tricky_Fat_Cat

GM2_DisplayManager

Oct 16th, 2019
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///--------------------------------------------------------///
  2. ///                     Create event                       ///
  3. ///--------------------------------------------------------///
  4.  
  5. /// @description ResolutionInitializer
  6.  
  7. // User events
  8. #macro UpdateResolution event_user(0);
  9.  
  10. // Parameters
  11. global.IdealWidth = 480;
  12. global.IdealHeight = 0;
  13. resolutionZoom = 1;
  14. resolutionZoomMax = 1;
  15. interfaceZoom = 2;
  16.  
  17. // Sequence
  18. aspectRatio = display_get_width() / display_get_height();
  19.  
  20. //global.IdealWidth = round(global.IdealHeight * aspectRatio);
  21. global.IdealHeight =round(global.IdealWidth/aspectRatio);
  22. global.IdealWidth = round(global.IdealWidth);
  23. global.IdealHeight = round(global.IdealHeight);
  24.  
  25. if (display_get_width() mod global.IdealWidth != 0)
  26. {
  27.     var d = round(display_get_width() / global.IdealWidth);
  28.     global.IdealWidth = display_get_width() / d;
  29. }
  30.  
  31. if (display_get_height() mod global.IdealHeight != 0)
  32. {
  33.     var d = round(display_get_height() / global.IdealHeight);
  34.     global.IdealHeight = display_get_height() / d;
  35. }
  36.  
  37. // Check for odd numbers
  38. if (global.IdealWidth & 1)
  39. {
  40.     global.IdealWidth++;
  41. }
  42. if (global.IdealHeight & 1)
  43. {
  44.     global.IdealHeight++;
  45. }
  46.  
  47. //resolutionZoomMax = floor(display_get_width() / global.IdealWidth);
  48. resolutionZoomMax = floor(display_get_height() / global.IdealHeight);
  49.  
  50. //Setup all the view ports so I don't have to.
  51. globalvar PlayerCamera;
  52. PlayerCamera = camera_create_view(0, 0, global.IdealWidth, global.IdealHeight, 0, noone, 0, 0, 0, 0);
  53. camera_set_view_size(PlayerCamera, global.IdealWidth, global.IdealHeight);
  54.  
  55. for (var i = 1; i <= room_last; i++)
  56. {
  57.     if (room_exists(i))
  58.     {
  59.         room_set_view_enabled(i, true);
  60.         room_set_viewport(i, 0, true, 0, 0, global.IdealWidth, global.IdealHeight);
  61.         room_set_camera(i, 0, PlayerCamera);
  62.     }
  63. }
  64.  
  65. resolutionZoom = max(resolutionZoomMax - 1, 1);
  66.  
  67. UpdateResolution;
  68.  
  69. ///--------------------------------------------------------///
  70. ///                     Step event                         ///
  71. ///--------------------------------------------------------///
  72.  
  73. /// @description ResolutionDebugController
  74.  
  75. if (keyboard_check_pressed(ord("Z")) || gamepad_button_check_pressed(global.ActiveGamepad, gp_stickl))
  76. {
  77.     resolutionZoom++;
  78.     if (resolutionZoom > resolutionZoomMax)
  79.     {
  80.         resolutionZoom = 1;
  81.     }
  82.    
  83.     UpdateResolution;
  84. }
  85.  
  86. ///--------------------------------------------------------///
  87. ///                     Alarm 0                            ///
  88. ///--------------------------------------------------------///
  89.  
  90. /// @description CenterWindow
  91.  
  92. window_center();
  93.  
  94. ///--------------------------------------------------------///
  95. ///                     User event 0                       ///
  96. ///--------------------------------------------------------///
  97.  
  98. /// @description RresolutionController
  99.  
  100. global.CurrentWidth = global.IdealWidth * resolutionZoom;
  101. global.CurrentHeight = global.IdealHeight * resolutionZoom;
  102. surface_resize(application_surface, global.CurrentWidth, global.CurrentHeight);
  103. window_set_size(global.CurrentWidth, global.CurrentHeight);
  104. display_set_gui_size(global.IdealWidth * interfaceZoom, global.IdealHeight * interfaceZoom);
  105. alarm[0] = 1;
Advertisement
Add Comment
Please, Sign In to add comment