Advertisement
Rafael_Sol_Maker

RAFAEL_SOL_MAKER's VX TOGGLE FULLSCREEN & RESOLUTION v1.0

Nov 17th, 2011
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.34 KB | None | 0 0
  1. #===============================================================================
  2. #         RAFAEL_SOL_MAKER's VX TOGGLE FULLSCREEN & RESOLUTION v1.0
  3. #-------------------------------------------------------------------------------
  4. # Description:  Puts the game in fullscreen or in a given resolution only by
  5. #               pressing a key, with automatic corrected scale considering
  6. #               window borders.
  7. #               Supports multiple screen sizes up to 640x480 and got some other
  8. #               adjustable properties. Similar to RPG Maker 2000/2003.
  9. #------------------------------------------------- ------------------------------
  10. # How to Use:   Press F5 to toggle the full screen mode;
  11. #               Press F6 to change the resolution, if it's in windowed mode.
  12. #               Extra settings can be found in the general configuration module.
  13. #-------------------------------------------------------------------------------
  14. # Special Thanks: Game_guy, OriginalWij, Mechacrash, Kylock
  15. #-------------------------------------------------------------------------------
  16. #===============================================================================
  17.  
  18. module PowerPackVX_General_Configs  
  19.      
  20.   # SCREEN OPTIONS
  21.   Default_Screen_Width  = 544 # Game screen width [max = 640] [default = 544]
  22.   Default_Screen_Height = 416 # Game screen height [max = 480] [default = 416]    
  23.   High_Res_Width  = 960       # Game screen width (adjustable resolution mode)
  24.   High_Res_Height = 720       # Game screen height (adjustable resolution mode)
  25.  
  26. end
  27.  
  28. class << Graphics
  29.   include PowerPackVX_General_Configs
  30.  
  31.   alias solmaker_update update unless $@
  32.   def Graphics.update
  33.     solmaker_update
  34.     if Input.trigger?(Input::F5)
  35.       toggle_fullscreen      
  36.     elsif Input.trigger? (Input::F6)      
  37.       if scaled? == false; scale_window(High_Res_Width, High_Res_Height)
  38.       else; scale_window(Default_Screen_Width , Default_Screen_Height); end      
  39.     end      
  40.   end
  41.  
  42.   def Graphics.fullscreen? # Property
  43.     screen_size = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
  44.     screen_width = screen_size.call(0);   screen_height = screen_size.call(1)    
  45.     detect_fullscreen = false
  46.     detect_fullscreen = true if screen_width == 640 and screen_height == 480
  47.     return detect_fullscreen
  48.   end
  49.  
  50.   def Graphics.toggle_fullscreen # Main function
  51.     keybd = Win32API.new 'user32.dll', 'keybd_event', ['i', 'i', 'l', 'l'], 'v'
  52.     keybd.call(0xA4, 0, 0, 0)
  53.     keybd.call(13, 0, 0, 0)
  54.     keybd.call(13, 0, 2, 0)
  55.     keybd.call(0xA4, 0, 2, 0)    
  56.   end  
  57.  
  58.   def Graphics.scaled? # Property
  59.     rect = [0, 0, 0, 0].pack('l4')      
  60.     find = Win32API.new('user32', 'FindWindowEx', ['l','l','p','p'], 'i')
  61.     window = find.call(0, 0, "RGSS Player", 0)      
  62.     Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(window, rect)
  63.     w, h = rect.unpack('l4') [2..3]
  64.     detect_scaled_window = false
  65.     detect_scaled_window = true if w != Default_Screen_Width and h != Default_Screen_Height
  66.     return detect_scaled_window
  67.   end  
  68.  
  69.   def Graphics.scale_window(w, h) # Main function
  70.     unless fullscreen?
  71.       size = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
  72.       move = Win32API.new('user32', 'MoveWindow', ['l','i','i','i','i','l'], 'l')
  73.       find = Win32API.new('user32', 'FindWindowEx', ['l','l','p','p'], 'i')
  74.       window = find.call(0, 0, "RGSS Player", 0)
  75.       window_w = size.call(0)
  76.       window_h = size.call(1)
  77.       detect_border
  78.       move.call(window, (window_w - w + @window_border_width) / 2,
  79.                         (window_h - h + @window_border_height) / 2,
  80.                         w + @window_border_width, h + @window_border_height, 1)
  81.     end
  82.   end
  83.  
  84.   def Graphics.detect_border # Auxiliary function
  85.       rect = [0, 0, 0, 0].pack('l4'); rect2 = [0, 0, 0, 0].pack('l4')      
  86.       find = Win32API.new('user32', 'FindWindowEx', ['l','l','p','p'], 'i')
  87.       window = find.call(0, 0, "RGSS Player", 0)      
  88.       Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(window, rect)
  89.       Win32API.new('user32', 'GetWindowRect', %w(l p), 'i').call(window, rect2)
  90.       w, h = rect.unpack('l4') [2..3]      
  91.       x, y, x2, y2 = rect2.unpack('l4') [0..3]
  92.       w2 = x2 - x; h2 = y2- y
  93.       @window_border_width = w2 - w
  94.       @window_border_height = h2 - h
  95.   end
  96.    
  97. end
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement