Antize

Fullscreen++ v2.2

Aug 12th, 2015
1,461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. # Fullscreen++ v2.2 for VX and VXace by Zeus81
  2. # Free for non commercial and commercial use
  3. # Licence : http://creativecommons.org/licenses/by-sa/3.0/
  4. # Contact : zeusex81@gmail.com
  5. # (fr) Manuel d'utilisation : http://pastebin.com/raw.php?i=1TQfMnVJ
  6. # (en) User Guide : http://pastebin.com/raw.php?i=EgnWt9ur
  7.  
  8. $imported ||= {}
  9. $imported[:Zeus_Fullscreen] = __FILE__
  10.  
  11. class << Graphics
  12. Disable_VX_Fullscreen = false
  13.  
  14. CreateWindowEx = Win32API.new('user32' , 'CreateWindowEx' , 'ippiiiiiiiii', 'i')
  15. GetClientRect = Win32API.new('user32' , 'GetClientRect' , 'ip' , 'i')
  16. GetDC = Win32API.new('user32' , 'GetDC' , 'i' , 'i')
  17. GetSystemMetrics = Win32API.new('user32' , 'GetSystemMetrics' , 'i' , 'i')
  18. GetWindowRect = Win32API.new('user32' , 'GetWindowRect' , 'ip' , 'i')
  19. FillRect = Win32API.new('user32' , 'FillRect' , 'ipi' , 'i')
  20. FindWindow = Win32API.new('user32' , 'FindWindow' , 'pp' , 'i')
  21. ReleaseDC = Win32API.new('user32' , 'ReleaseDC' , 'ii' , 'i')
  22. SendInput = Win32API.new('user32' , 'SendInput' , 'ipi' , 'i')
  23. SetWindowLong = Win32API.new('user32' , 'SetWindowLong' , 'iii' , 'i')
  24. SetWindowPos = Win32API.new('user32' , 'SetWindowPos' , 'iiiiiii' , 'i')
  25. ShowWindow = Win32API.new('user32' , 'ShowWindow' , 'ii' , 'i')
  26. SystemParametersInfo = Win32API.new('user32' , 'SystemParametersInfo' , 'iipi' , 'i')
  27. UpdateWindow = Win32API.new('user32' , 'UpdateWindow' , 'i' , 'i')
  28. GetPrivateProfileString = Win32API.new('kernel32', 'GetPrivateProfileString' , 'ppppip' , 'i')
  29. WritePrivateProfileString = Win32API.new('kernel32', 'WritePrivateProfileString', 'pppp' , 'i')
  30. CreateSolidBrush = Win32API.new('gdi32' , 'CreateSolidBrush' , 'i' , 'i')
  31. DeleteObject = Win32API.new('gdi32' , 'DeleteObject' , 'i' , 'i')
  32.  
  33. unless method_defined?(:zeus_fullscreen_update)
  34. HWND = FindWindow.call('RGSS Player', 0)
  35. BackHWND = CreateWindowEx.call(0x08000008, 'Static', '', 0x80000000, 0, 0, 0, 0, 0, 0, 0, 0)
  36. alias zeus_fullscreen_resize_screen resize_screen
  37. alias zeus_fullscreen_update update
  38. end
  39. private
  40. def initialize_fullscreen_rects
  41. @borders_size ||= borders_size
  42. @fullscreen_rect ||= screen_rect
  43. @workarea_rect ||= workarea_rect
  44. end
  45. def borders_size
  46. GetWindowRect.call(HWND, wrect = [0, 0, 0, 0].pack('l4'))
  47. GetClientRect.call(HWND, crect = [0, 0, 0, 0].pack('l4'))
  48. wrect, crect = wrect.unpack('l4'), crect.unpack('l4')
  49. Rect.new(0, 0, wrect[2]-wrect[0]-crect[2], wrect[3]-wrect[1]-crect[3])
  50. end
  51. def screen_rect
  52. Rect.new(0, 0, GetSystemMetrics.call(0), GetSystemMetrics.call(1))
  53. end
  54. def workarea_rect
  55. SystemParametersInfo.call(0x30, 0, rect = [0, 0, 0, 0].pack('l4'), 0)
  56. rect = rect.unpack('l4')
  57. Rect.new(rect[0], rect[1], rect[2]-rect[0], rect[3]-rect[1])
  58. end
  59. def hide_borders() SetWindowLong.call(HWND, -16, 0x14000000) end
  60. def show_borders() SetWindowLong.call(HWND, -16, 0x14CA0000) end
  61. def hide_back() ShowWindow.call(BackHWND, 0) end
  62. def show_back
  63. ShowWindow.call(BackHWND, 3)
  64. UpdateWindow.call(BackHWND)
  65. dc = GetDC.call(BackHWND)
  66. rect = [0, 0, @fullscreen_rect.width, @fullscreen_rect.height].pack('l4')
  67. brush = CreateSolidBrush.call(0)
  68. FillRect.call(dc, rect, brush)
  69. ReleaseDC.call(BackHWND, dc)
  70. DeleteObject.call(brush)
  71. end
  72. def resize_window(w, h)
  73. if @fullscreen
  74. x, y, z = (@fullscreen_rect.width-w)/2, (@fullscreen_rect.height-h)/2, -1
  75. else
  76. w += @borders_size.width
  77. h += @borders_size.height
  78. x = @workarea_rect.x + (@workarea_rect.width - w) / 2
  79. y = @workarea_rect.y + (@workarea_rect.height - h) / 2
  80. z = -2
  81. end
  82. SetWindowPos.call(HWND, z, x, y, w, h, 0)
  83. end
  84. def release_alt
  85. inputs = [1,18,2, 1,164,2, 1,165,2].pack('LSx2Lx16'*3)
  86. SendInput.call(3, inputs, 28)
  87. end
  88. public
  89. def load_fullscreen_settings
  90. buffer = [].pack('x256')
  91. section = 'Fullscreen++'
  92. filename = './Game.ini'
  93. get_option = Proc.new do |key, default_value|
  94. l = GetPrivateProfileString.call(section, key, default_value, buffer, buffer.size, filename)
  95. buffer[0, l]
  96. end
  97. @fullscreen = get_option.call('Fullscreen' , '0') == '1'
  98. @fullscreen_ratio = get_option.call('FullscreenRatio', '0').to_i
  99. @windowed_ratio = get_option.call('WindowedRatio' , '1').to_i
  100. toggle_vx_fullscreen if Disable_VX_Fullscreen and vx_fullscreen?
  101. fullscreen? ? fullscreen_mode : windowed_mode
  102. end
  103. def save_fullscreen_settings
  104. section = 'Fullscreen++'
  105. filename = './Game.ini'
  106. set_option = Proc.new do |key, value|
  107. WritePrivateProfileString.call(section, key, value.to_s, filename)
  108. end
  109. set_option.call('Fullscreen' , @fullscreen ? '1' : '0')
  110. set_option.call('FullscreenRatio', @fullscreen_ratio)
  111. set_option.call('WindowedRatio' , @windowed_ratio)
  112. end
  113. def fullscreen?
  114. @fullscreen or vx_fullscreen?
  115. end
  116. def vx_fullscreen?
  117. rect = screen_rect
  118. rect.width == 640 and rect.height == 480
  119. end
  120. def toggle_fullscreen
  121. fullscreen? ? windowed_mode : fullscreen_mode
  122. end
  123. def toggle_vx_fullscreen
  124. windowed_mode if @fullscreen and !vx_fullscreen?
  125. inputs = [1,18,0, 1,13,0, 1,13,2, 1,18,2].pack('LSx2Lx16'*4)
  126. SendInput.call(4, inputs, 28)
  127. zeus_fullscreen_update
  128. self.ratio += 0 # refresh window size
  129. end
  130. def vx_fullscreen_mode
  131. return if vx_fullscreen?
  132. toggle_vx_fullscreen
  133. end
  134. def fullscreen_mode
  135. return if vx_fullscreen?
  136. initialize_fullscreen_rects
  137. show_back
  138. hide_borders
  139. @fullscreen = true
  140. self.ratio += 0 # refresh window size
  141. end
  142. def windowed_mode
  143. toggle_vx_fullscreen if vx_fullscreen?
  144. initialize_fullscreen_rects
  145. hide_back
  146. show_borders
  147. @fullscreen = false
  148. self.ratio += 0 # refresh window size
  149. end
  150. def toggle_ratio
  151. return if vx_fullscreen?
  152. self.ratio += 1
  153. end
  154. def ratio
  155. return 1 if vx_fullscreen?
  156. @fullscreen ? @fullscreen_ratio : @windowed_ratio
  157. end
  158. def ratio=(r)
  159. return if vx_fullscreen?
  160. initialize_fullscreen_rects
  161. r = 0 if r < 0
  162. if @fullscreen
  163. @fullscreen_ratio = r
  164. w_max, h_max = @fullscreen_rect.width, @fullscreen_rect.height
  165. else
  166. @windowed_ratio = r
  167. w_max = @workarea_rect.width - @borders_size.width
  168. h_max = @workarea_rect.height - @borders_size.height
  169. end
  170. if r == 0
  171. w, h = w_max, w_max * height / width
  172. h, w = h_max, h_max * width / height if h > h_max
  173. else
  174. w, h = width * r, height * r
  175. return self.ratio = 0 if w > w_max or h > h_max
  176. end
  177. resize_window(w, h)
  178. save_fullscreen_settings
  179. end
  180. def update
  181. release_alt if Disable_VX_Fullscreen and Input.trigger?(Input::ALT)
  182. zeus_fullscreen_update
  183. toggle_fullscreen if Input.trigger?(Input::F5)
  184. toggle_ratio if Input.trigger?(Input::F6)
  185. end
  186. def resize_screen(width, height)
  187. zeus_fullscreen_resize_screen(width, height)
  188. self.ratio += 0 # refresh window size
  189. end
  190. end
  191. Graphics.load_fullscreen_settings
Add Comment
Please, Sign In to add comment