Rafael_Sol_Maker

RSM's VX&ACE FULLSCREEN & SCALE v1.0

Jul 12th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.51 KB | None | 0 0
  1. #===============================================================================
  2. #                     RSM's VX&ACE FULLSCREEN & SCALE v1.0
  3. #               Compatible with RPG Maker VX and RPG Maker VX Ace
  4. #            (In RPG Maker XP, it works only thr fullscreen toggle!)
  5. #_______________________________________________________________________________
  6. #   Description  | Puts the game in fullscreen or in a given scale only by
  7. #                | pressing a key, with automatic corrected scale considering
  8. #                | window borders. Similar effect from RPG Maker 2000/2003.
  9. #                | Supports adjustable game window scale and custom keys to
  10. #                | toggle fullscreen and scaled screen mode.
  11. #________________|______________________________________________________________
  12. #     Usage      | Plug and Play! (But got some optional adjusts)
  13. #________________|______________________________________________________________
  14. # Specifications | Difficulty to Use:
  15. #                |  * (meh easy)
  16. #                | Scripting Difficulty:
  17. #                |  * * * ¾  (required advanced API knowledge)
  18. #                | Compatibility:
  19. #                |  * * * * (probably highly compatible)
  20. #                | New Methods:
  21. #                |  - Graphics.fullscreen?
  22. #                |  - Graphics.toggle_fullscreen
  23. #                |  - Graphics.scaled?
  24. #                | Overwritten Methods:
  25. #                |  - (none)
  26. #                | Aliased Methods:
  27. #                |  - Graphics.update
  28. #________________|______________________________________________________________
  29. # Special Thanks | Game_guy, OriginalWij, Mechacrash, Kylock
  30. #________________|______________________________________________________________
  31. #===============================================================================
  32.  
  33. #==============================================================================
  34. # ** Configurables
  35. #------------------------------------------------------------------------------
  36. module Configurables
  37.  
  38.   # SCREEN OPTIONS
  39.   # Game screen width (adjustable resolution mode)
  40.   Resized_Width  = (Graphics.width  * 2)
  41.   # Game screen height (adjustable resolution mode)
  42.   Resized_Height = (Graphics.height * 2)
  43.  
  44.   # KEY OPTIONS
  45.   # Key to toggle scaled screen mode
  46.     Resize_Key     = Input::F5
  47.   # Key to toggle fullscreen mode
  48.     Fullscreen_Key = Input::F6
  49. end
  50. #==============================================================================
  51. # ** Graphics
  52. #------------------------------------------------------------------------------
  53. class << Graphics
  54.   include Configurables
  55.   #--------------------------------------------------------------------------
  56.   # * Aliasing the graphics update to track the keys we want
  57.   #--------------------------------------------------------------------------
  58.   alias rsm_fullscreen_scale_update update
  59.   def Graphics.update
  60.     rsm_fullscreen_scale_update
  61.     toggle_fullscreen if Input.trigger?(Resize_Key)
  62.     if Input.trigger?(Fullscreen_Key)
  63.       scaled? ? __scale_window__(Graphics.width , Graphics.height)
  64.               : __scale_window__(Resized_Width, Resized_Height)
  65.     end
  66.   end
  67.   #--------------------------------------------------------------------------
  68.   # * use some clever API to find if we're on fullscreen resolution
  69.   #--------------------------------------------------------------------------
  70.   def Graphics.fullscreen?
  71.     screen_size = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
  72.     screen_width = screen_size.call(0);   screen_height = screen_size.call(1)
  73.     (screen_width == 640 && screen_height == 480)
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # * It will toggle de fullscreen mode on and off.
  77.   #--------------------------------------------------------------------------
  78.   def Graphics.toggle_fullscreen
  79.     keybd = Win32API.new 'user32.dll', 'keybd_event', ['i', 'i', 'l', 'l'], 'v'
  80.     keybd.call(0xA4, 0, 0, 0)
  81.     keybd.call(13, 0, 0, 0)
  82.     keybd.call(13, 0, 2, 0)
  83.     keybd.call(0xA4, 0, 2, 0)
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # * Check whether our graphics were previously scaled or not
  87.   #--------------------------------------------------------------------------
  88.   def Graphics.scaled?
  89.     rect = [0, 0, 0, 0].pack('l4')
  90.     find = Win32API.new('user32', 'FindWindowEx', ['l','l','p','p'], 'i')
  91.     window = find.call(0, 0, "RGSS Player", 0)
  92.     Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(window, rect)
  93.     width, height = rect.unpack('l4')[2..3]
  94.     (width != Graphics.width && height != Graphics.height)
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # * Internal use. Function to do the hard job of scaling the window
  98.   #--------------------------------------------------------------------------
  99.   def Graphics.__scale_window__(width, height)
  100.     unless fullscreen?
  101.       size = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
  102.       move = Win32API.new('user32', 'MoveWindow', ['l','i','i','i','i','l'], 'l')
  103.       find = Win32API.new('user32', 'FindWindowEx', ['l','l','p','p'], 'i')
  104.       window = find.call(0, 0, "RGSS Player", 0)
  105.       window_w = size.call(0)
  106.       window_h = size.call(1)
  107.       border = __border__
  108.       move.call(window, (window_w - width + border[0]) / 2,
  109.                         (window_h - height + border[1]) / 2,
  110.                         width + border[0], height + border[1], 1)
  111.     end
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   # * Internal use. Detect difference between user area and total window
  115.   #--------------------------------------------------------------------------
  116.   def Graphics.__border__
  117.       rect = [0, 0, 0, 0].pack('l4'); rect2 = [0, 0, 0, 0].pack('l4')
  118.       find = Win32API.new('user32', 'FindWindowEx', ['l','l','p','p'], 'i')
  119.       window = find.call(0, 0, "RGSS Player", 0)
  120.       Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(window, rect)
  121.       Win32API.new('user32', 'GetWindowRect', %w(l p), 'i').call(window, rect2)
  122.       width, height = rect.unpack('l4') [2..3]
  123.       x, y, x2, y2 = rect2.unpack('l4') [0..3]
  124.       w2 = x2 - x; h2 = y2- y
  125.       [w2 - width, h2 - height]
  126.   end
  127. end
  128. #-------------------------------------------------------------------------------
  129. # * THE END - That's all, folks!
  130. #-------------------------------------------------------------------------------
  131. #===============================================================================
Add Comment
Please, Sign In to add comment