Advertisement
Gabz

Σ Fullscreen

Sep 26th, 2014
13,943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 22.43 KB | None | 0 0
  1. #=============================================================================
  2. # Σ Fullscreen
  3. #-----------------------------------------------------------------------------
  4. # @author  : Gabriel "Gab!" Teles
  5. # @date    : 2014-09-27
  6. # @version : 0.9.2
  7. #-----------------------------------------------------------------------------
  8. # TODO:
  9. #   - Transições por imagens
  10. #-----------------------------------------------------------------------------
  11. # Créditos:
  12. #   Scripter Desconhecido no Pastebin (http://pastebin.com/sM2MNJZj)
  13. #   Esrever : Map viewport/scroll fix
  14. #   Zeus81  : FPS Display
  15. #-----------------------------------------------------------------------------
  16. # Permite utilizar fullscreen real (sem redimensionamento de tela), e alterar
  17. # o limite da função Graphics.resize_screen para a resolução máxima do monitor
  18. # ou um valor próximo.
  19. #=============================================================================
  20.  
  21. # Módulo Graphics
  22. class << Graphics
  23.   # API
  24.   User32   = DL.dlopen('user32')
  25.   Kernel32 = DL.dlopen('kernel32')
  26.   GetActiveWindow  = DL::CFunc.new(  User32['GetActiveWindow' ], DL::TYPE_LONG)
  27.   GetSystemMetrics = DL::CFunc.new(  User32['GetSystemMetrics'], DL::TYPE_LONG)
  28.   GetWindowRect    = DL::CFunc.new(  User32['GetWindowRect'   ], DL::TYPE_LONG)
  29.   SetWindowLong    = DL::CFunc.new(  User32['SetWindowLong'   ], DL::TYPE_LONG)
  30.   SetWindowPos     = DL::CFunc.new(  User32['SetWindowPos'    ], DL::TYPE_LONG)
  31.   GetModuleHandle  = DL::CFunc.new(Kernel32['GetModuleHandle' ], DL::TYPE_LONG)  
  32.  
  33.   # DLL sendo utilizada
  34.   _DLLName = DL::CPtr.malloc(140)
  35.   s = DL::CFunc.new(Kernel32['GetPrivateProfileString'], DL::TYPE_LONG).call([
  36.     DL::CPtr["Game"].to_i,
  37.     DL::CPtr["Library"].to_i,
  38.     0,
  39.     _DLLName.to_i,
  40.     140,
  41.     DL::CPtr["./Game.ini"].to_i
  42.   ])
  43.  
  44.   @@DLLName = File.basename(_DLLName.to_s(s))
  45.  
  46.   # Verifica se é uma RGSS3xx.dll
  47.   if @@DLLName.match(/^RGSS3(\d{2})\.dll$/)
  48.     @@DLLVersion = $1.to_i
  49.    
  50.     # Verifica se a versão é 0 ou 1.
  51.     if @@DLLVersion.between?(0, 1)
  52.       # Flag de fullscreen
  53.       @@inFullscreen = false
  54.      
  55.       # Instância da DLL. *Necessariamente* a RGSS300.dll ou RGSS301.dll, visto
  56.       # que o trabalho com memória a seguir é específico.
  57.      
  58.       @@DLLHandle   = GetModuleHandle.call([DL::CPtr[@@DLLName].to_i])
  59.      
  60.       # Instância da janela de jogo
  61.       @@hWnd       = GetActiveWindow.call([])
  62.      
  63.       # Tamanho da tela
  64.       @@screenSize = [
  65.         GetSystemMetrics.call([0]),
  66.         GetSystemMetrics.call([1])
  67.       ]
  68.      
  69.       # Calcula o próximo tamanho divisível por 32 para fazer a limitação
  70.       width, height = @@screenSize
  71.       width  += (32 - (width  % 32)) unless (width  % 32).zero?
  72.       height += (32 - (height % 32)) unless (height % 32).zero?
  73.       puts "Limitando para: #{width}x#{height}" if $TEST
  74.      
  75.       #-----------------------------------------------------------------------
  76.       # Bruxaria de scripter desconhecido. Remove a limitação de tamanho para
  77.       # o método Graphics.resize_screen (640x480)
  78.       #
  79.       # Base retirada de: http://pastebin.com/sM2MNJZj
  80.       #
  81.       # Adaptações para a RGSS300.dll e início do mapeamento dos endereços
  82.       # utilizados por Gab!
  83.       #-----------------------------------------------------------------------
  84.      
  85.       # Número para string
  86.       wh = ->(w, h, off = 0){
  87.         [w + off, h + off].pack('l2').scan(/..../)
  88.       }
  89.      
  90.       # Altera um valor na memória relativa à DLL
  91.       mod = ->(adr, val){
  92.         adr += @@OFF if @@DLLVersion.zero?
  93.         DL::CPtr.new(@@DLLHandle + adr)[0, val.size] = val
  94.       }
  95.      
  96.       # Valores úteis
  97.       wt,  ht  = width.divmod(32), height.divmod(32)
  98.       w,   h   = wh.(width, height)
  99.       ww,  hh  = wh.(width, height, 32)
  100.       www, hhh = wh.(wt.first, ht.first, 1)
  101.       zero     = [0].pack('l')
  102.          
  103.       # Faz as alterações na memória
  104.      
  105.       # Graphics
  106.       @@OFF = 0
  107.       mod.(0x195F, "\x90"*5) # ???
  108.       mod.(0x19A4,   h     ) # ???
  109.       mod.(0x19A9,   w     ) # ???
  110.       mod.(0x1A56,   h     ) # ???
  111.       mod.(0x1A5B,   w     ) # ???
  112.       mod.(0x20F6,   w     ) # Max width  (?)
  113.       mod.(0x20FF,   w     ) # Max width  (?)
  114.       mod.(0x2106,   h     ) # Max height (?)
  115.       mod.(0x210F,   h     ) # Max height (?)
  116.      
  117.       # Plane (?) Class
  118.       @@OFF   = -0xC0
  119.       Graphics::PlaneSpeedUp = true
  120.         # Setando para false não é necessário reescrever classe Plane. No
  121.         # entanto, o mapa fica MUITO lento.
  122.       mod.(0x1C5E3,  Graphics::PlaneSpeedUp ? zero : h) # Max height
  123.       mod.(0x1C5E8,  Graphics::PlaneSpeedUp ? zero : w) # Max width
  124.      
  125.       # ???
  126.       @@OFF = 0x20
  127.       mod.(0x1F477,  h     ) # ???
  128.       mod.(0x1F47C,  w     ) # ???
  129.      
  130.       # Tilemap Class
  131.       @@OFF = 0x1E0
  132.       mod.(0x211FF,  hh    ) # Tilemap render height
  133.       mod.(0x21204,  ww    ) # Tilemap render width
  134.       mod.(0x21D7D,  hhh[0]) # Tilemap max tiles on screen height
  135.       mod.(0x21E01,  www[0]) # Tilemap max tiles on screen width
  136.      
  137.       # ???
  138.       @@OFF = 0x140
  139.       mod.(0x10DEA8, h     ) # ???
  140.       mod.(0x10DEAD, w     ) # ???    
  141.       mod.(0x10DEDF, h     ) # ???
  142.       mod.(0x10DEE3, w     ) # ???
  143.       mod.(0x10DF14, h     ) # ???
  144.       mod.(0x10DF18, w     ) # ???
  145.       mod.(0x10DF48, h     ) # ???
  146.       mod.(0x10DF4C, w     ) # ???
  147.       mod.(0x10E6A7, w     ) # ???
  148.       mod.(0x10E6C3, h     ) # ???
  149.       mod.(0x10EEA9, w     ) # ???
  150.       mod.(0x10EEB9, h     ) # ???
  151.      
  152.       #-------------------------------------------------------------------------
  153.       # Fim da bruxaria
  154.       #-------------------------------------------------------------------------
  155.      
  156.       # Sprite de transição de tela
  157.       @@TransitionSprite = Sprite.new
  158.       @@TransitionSprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  159.       @@TransitionSprite.bitmap.fill_rect(@@TransitionSprite.bitmap.rect, Color.new(0, 0, 0))
  160.       @@TransitionSprite.opacity = 0
  161.       @@TransitionSprite.z = 0x7FFFFFFF
  162.      
  163.       # Bitmap da tela no momento do Graphics.freeze
  164.       @@FrozenBitmap = Bitmap.new(Graphics.width, Graphics.height)
  165.       @@FrozenBitmap.fill_rect(@@FrozenBitmap.rect, Color.new(0, 0, 0))
  166.      
  167.       # Realiza a transição de tela
  168.       # Nota: Não é possível realizar transição de tela com imagens
  169.       alias oldFullscreenResTransition transition
  170.       def transition(time, image='', vague=40)
  171.         @@TransitionSprite.bitmap.dispose
  172.         @@TransitionSprite.dispose
  173.         @@TransitionSprite = Sprite.new
  174.         @@TransitionSprite.bitmap = @@FrozenBitmap
  175.         @@TransitionSprite.opacity = 255
  176.         @@TransitionSprite.z = 0x7FFFFFFF
  177.      
  178.         oldFullscreenResTransition(0)
  179.        
  180.         dec = (255.0 / time)
  181.         time.times {
  182.           @@TransitionSprite.opacity -= dec
  183.           Graphics.update
  184.         }
  185.       end
  186.      
  187.       # Fadein
  188.       def fadein(time)
  189.         @@FrozenBitmap = Bitmap.new(Graphics.width, Graphics.height)
  190.         @@FrozenBitmap.fill_rect(@@FrozenBitmap.rect, Color.new(0, 0, 0))
  191.        
  192.         transition(time)
  193.       end
  194.      
  195.       # Fadeout
  196.       def fadeout(time)
  197.         inc = (255.0 / time)
  198.         time.times {
  199.           @@TransitionSprite.opacity += inc
  200.           Graphics.update
  201.         }
  202.       end
  203.      
  204.       # Armazena a imagem da tela
  205.       alias oldFullscreenResFreeze freeze
  206.       def freeze(*a, &b)
  207.         oldFullscreenResFreeze(*a, &b)
  208.         @@FrozenBitmap = Graphics.snap_to_bitmap
  209.       end
  210.      
  211.       # Realiza o redimensionamento de tela
  212.       alias gabFullscreenOldResizeScreen resize_screen
  213.       def resize_screen(*a, &b)
  214.         # Redimensiona normalmente
  215.         gabFullscreenOldResizeScreen(*a, &b)
  216.         # Redimensiona o sprite de transição
  217.         @@TransitionSprite.bitmap.dispose
  218.         @@TransitionSprite.bitmap = Bitmap.new(*Graphics.size)
  219.         @@TransitionSprite.bitmap.fill_rect(@@TransitionSprite.bitmap.rect, Color.new(0, 0, 0))
  220.        
  221.         if Graphics::PlaneSpeedUp
  222.           # Manda o sinal de atualização para todas as instâncias da classe Plane
  223.           ObjectSpace.each_object(Plane){|plane|
  224.             plane.send(:recreateBitmap)
  225.           }
  226.         end
  227.       end
  228.      
  229.       # Altera para fullscreen
  230.       def fullscreen
  231.         # Retorna se já estiver em fullscreen
  232.         return if @@inFullscreen
  233.         # Tamanho antes do fullscreen
  234.         rect = DL::CPtr.malloc(16)
  235.         rect[0, 16] = 0.chr * 16
  236.         GetWindowRect.call([@@hWnd, rect])
  237.         @@windowSize = rect[0, 16].unpack("l*")
  238.         @@windowSize[2] -= @@windowSize[0]
  239.         @@windowSize[3] -= @@windowSize[1]
  240.         @@windowResolution = Graphics.size
  241.         # Muda o tamanho da tela
  242.         Graphics.resize_screen(*@@screenSize)
  243.         # Remover bordas da janela
  244.         SetWindowLong.call([@@hWnd, -16, 0x14000000])
  245.         # Coloca a janela acima de todas as outras
  246.         SetWindowPos.call([@@hWnd, -1, 0, 0, *@@screenSize, 0])
  247.         # Modifica a flag de fullscreen
  248.         @@inFullscreen = true
  249.         # Espera alguns frames para terminar o processamento
  250.         Graphics.wait(5)
  251.       end
  252.      
  253.       # Altera para modo janela
  254.       def windowed
  255.         # Retorna se não estiver em fullscreen
  256.         return unless @@inFullscreen
  257.         # Muda o tamanho da tela
  258.         Graphics.resize_screen(*@@windowResolution)
  259.         # Recoloca bordas da janela
  260.         SetWindowLong.call([@@hWnd, -16, 0x14CA0000])
  261.         # Coloca a janela na posição x,y,z comum e ajusta seu tamanho
  262.         SetWindowPos.call([@@hWnd, 0, *@@windowSize, 0])
  263.         # Modifica a flag de fullscreen
  264.         @@inFullscreen = false
  265.         # Espera alguns frames para terminar o processamento
  266.         Graphics.wait(5)
  267.       end
  268.      
  269.       # Tamanho da tela
  270.       def size
  271.         [self.width, self.height]
  272.       end
  273.      
  274.       # Verifica se a janela está no modo fullscreen
  275.       def fullscreen?
  276.         return @@inFullscreen
  277.       end
  278.      
  279.       # Verifica se a janela está no modo janela
  280.       def windowed?
  281.         return !@@inFullscreen
  282.       end
  283.      
  284.       # Alterna entre os modos fullscreen e janela
  285.       def toggleFullscreen
  286.         @@inFullscreen ? self.windowed : self.fullscreen
  287.       end
  288.     end
  289.   end
  290. end
  291.  
  292. if Graphics::PlaneSpeedUp
  293.   # Remove a classe Plane Anterior
  294.   Object.send(:remove_const, :Plane)
  295.   # Redefinição da classe Plane
  296.   class Plane
  297.     attr_reader :viewport
  298.     attr_reader :bitmap
  299.     attr_reader :ox
  300.     attr_reader :oy
  301.     attr_reader :opacity
  302.     attr_reader :blend_type
  303.     attr_reader :color
  304.     attr_reader :tone
  305.     attr_reader :visible
  306.     attr_reader :zoom_x
  307.     attr_reader :zoom_y
  308.     attr_reader :z
  309.    
  310.     # Inicialização do objeto
  311.     def initialize(viewport = nil)
  312.       # É necessário verificar se um viewport foi enviado. Desse modo, ao mudar a
  313.       # resolução da tela, deve-se mudar também a rect do viewport para que o
  314.       # Plane que ocupava a tela toda continue
  315.       @defaultViewport = !viewport.is_a?(Viewport)
  316.       @viewport = @defaultViewport ? Viewport.new(0, 0, *Graphics.size) : viewport
  317.      
  318.       @sprite        = Sprite.new(@viewport)
  319.       @bitmap        = nil
  320.       @ox            = @sprite.ox         # 0
  321.       @oy            = @sprite.oy         # 0
  322.       @opacity       = @sprite.opacity    # 255
  323.       @blend_type    = @sprite.blend_type # 0
  324.       @color         = @sprite.color      # Color.new(0, 0, 0, 0)
  325.       @tone          = @sprite.tone       # Tone.new(0, 0, 0, 0)
  326.       @visible       = @sprite.visible    # true
  327.       @z             = @sprite.z          # 0
  328.       @zoom_x        = @sprite.zoom_x     # 1.0
  329.       @zoom_y        = @sprite.zoom_y     # 1.0
  330.     end
  331.    
  332.     def bitmap=(bitmap)
  333.       return unless bitmap.is_a?(Bitmap)
  334.       @bitmap = bitmap
  335.       self.recreateBitmap(true)
  336.     end
  337.    
  338.     def ox=(value)
  339.       @ox = value
  340.       return unless @bitmap
  341.       @sprite.ox = (value % @bitmap.width)
  342.     end
  343.    
  344.     def oy=(value)
  345.       @oy = value
  346.       return unless @bitmap
  347.       @sprite.oy = (value % @bitmap.height)
  348.     end
  349.    
  350.     def opacity=(value)
  351.       @sprite.opacity = value
  352.       @opacity = @sprite.opacity
  353.     end
  354.    
  355.     def blend_type=(value)
  356.       @sprite.blend_type = value
  357.       @blend_type = @sprite.blend_type
  358.     end
  359.    
  360.     def color=(value)
  361.       @sprite.color = value
  362.       @color = @sprite.color
  363.     end
  364.    
  365.     def tone=(value)
  366.       @sprite.tone = value
  367.       @tone = @sprite.tone
  368.     end
  369.    
  370.     def viewport=(value)
  371.       @defaultViewport &= (value == @sprite.viewport)
  372.       @sprite.viewport = value
  373.       @viewport = @sprite.viewport
  374.     end
  375.    
  376.     def visible=(value)
  377.       @sprite.visible = value
  378.       @visible = sprite.visible
  379.     end
  380.    
  381.     def z=(value)
  382.       @sprite.z = value
  383.       @z = @sprite.z
  384.     end
  385.    
  386.     def zoom_x=(value)
  387.       @sprite.zoom_x = value
  388.       @zoom_x = @sprite.zoom_x
  389.       self.recreateBitmap
  390.     end
  391.    
  392.     def zoom_y=(value)
  393.       @sprite.zoom_y = value
  394.       @zoom_y = @sprite.zoom_y
  395.       self.recreateBitmap
  396.     end
  397.    
  398.     def disposed?
  399.       return @sprite.disposed?
  400.     end
  401.    
  402.     def dispose
  403.       @sprite.dispose
  404.     end
  405.    
  406.     protected
  407.    
  408.     def recreateBitmap(forceRefresh = false)
  409.       cw, ch      = Graphics.width * (2.0/@zoom_x), Graphics.height * (2.0/@zoom_y)
  410.       needRefresh = true
  411.      
  412.       if @defaultViewport
  413.         @viewport.rect.width, @viewport.rect.height = *Graphics.size
  414.       end
  415.      
  416.       if @sprite.bitmap.nil? or @sprite.bitmap.disposed?
  417.         newBitmap = Bitmap.new(cw, ch)
  418.       else
  419.         if (cw == @sprite.bitmap.width) and (ch == @sprite.bitmap.height) and (!forceRefresh)
  420.           return
  421.         end
  422.        
  423.         newBitmap = Bitmap.new(cw, ch)
  424.         if (cw < @sprite.bitmap.width) and (ch < @sprite.bitmap.height)
  425.           newBitmap.blt(0, 0, @sprite.bitmap, @sprite.bitmap.rect)
  426.           @sprite.bitmap.dispose
  427.           needRefresh = false
  428.         end
  429.       end
  430.      
  431.       @sprite.bitmap = newBitmap
  432.       self.refreshBitmap if needRefresh or forceRefresh
  433.     end
  434.    
  435.     def refreshBitmap
  436.       # Limpa o bitmap
  437.       b = @sprite.bitmap
  438.       b.clear
  439.      
  440.       return if @bitmap.nil?
  441.      
  442.       # Quantia de espaços para blt
  443.       tx = (b.width  / @bitmap.width.to_f )
  444.       ty = (b.height / @bitmap.height.to_f)
  445.      
  446.       b.blt(0, 0, @bitmap, @bitmap.rect)
  447.      
  448.       return if tx + ty == 2
  449.      
  450.       # Preenche 1 linha
  451.       basePow = @bitmap.width
  452.       baseRct = Rect.new(0, 0, @bitmap.width, @bitmap.height)
  453.      
  454.       Math.log2(tx).floor.times{
  455.         b.blt(basePow, 0, b, baseRct)
  456.         baseRct.width += basePow
  457.         basePow *= 2
  458.       }
  459.      
  460.       # Último bitmap da linha
  461.       baseRct.width = (b.width - baseRct.width)
  462.       b.blt(basePow, 0, b, baseRct)
  463.      
  464.       # Preenche o restante das linhas
  465.       basePow = @bitmap.height
  466.       baseRct = Rect.new(0, 0, b.width, @bitmap.height)
  467.      
  468.       Math.log2(ty).floor.times{
  469.         b.blt(0, basePow, b, baseRct)
  470.         baseRct.height += basePow
  471.         basePow *= 2
  472.       }
  473.      
  474.       # Última linha
  475.       baseRct.height = b.height - baseRct.height
  476.       b.blt(basePow, 0, b, baseRct)
  477.     end
  478.   end
  479. end
  480.  
  481. class Game_Map
  482.   # Número de tiles horizontais na tela
  483.   def screen_tile_x
  484.     (Graphics.width / 32.0).ceil
  485.   end
  486.  
  487.   # Número de tiles verticais na tela
  488.   def screen_tile_y
  489.     (Graphics.height / 32.0).ceil
  490.   end
  491. end
  492.  
  493. # Contador de FPS para o modo Fullscreen
  494. if $TEST
  495.   # FPS Display // Zeus81
  496.   # http://forums.rpgmakerweb.com/index.php?/topic/3738-fps-display-isnt-very-accurate/#entry40350
  497.   module Graphics
  498.     @fps, @fps_tmp = 0, []
  499.    
  500.     class << self
  501.       attr_reader :fps
  502.      
  503.       alias fps_update update unless method_defined?(:fps_update)
  504.       def update
  505.         t = Time.now
  506.         fps_update
  507.         @fps_tmp[frame_count % frame_rate] = Time.now != t
  508.         @fps = 0
  509.         frame_rate.times {|i| @fps += 1 if @fps_tmp[i]}
  510.         fps_sprite.src_rect.y = @fps * 16
  511.       end
  512.      
  513.       def fps_sprite
  514.         if !@fps_sprite or @fps_sprite.disposed?
  515.           @fps_sprite = Sprite.new
  516.           @fps_sprite.z = 0x7FFFFFFF
  517.           @fps_sprite.bitmap = Bitmap.new(24, 16*120)
  518.           @fps_sprite.bitmap.font.name = "Arial"
  519.           @fps_sprite.bitmap.font.size = 16
  520.           @fps_sprite.bitmap.font.color.set(255, 255, 255)
  521.           @fps_sprite.bitmap.fill_rect(@fps_sprite.bitmap.rect, Color.new(0, 0, 0, 127))
  522.           120.times {|i|
  523.             @fps_sprite.bitmap.draw_text(0, i*16, 24, 16, "% 3d"%i, 1)
  524.           }
  525.           @fps_sprite.src_rect.height = 16
  526.         end
  527.         return @fps_sprite
  528.       end      
  529.     end
  530.   end
  531. end
  532.  
  533. #==============================================================================
  534. # ▼ Viewports/Map Fix for Modified RGSS300.dll File
  535. #   Origin of Code: Yanfly Engine Ace - Ace Core Engine v1.06
  536. # -- Last Updated: 2011.12.26
  537. # -- Level: Easy, Normal
  538. # -- Requires: n/a
  539. #==============================================================================
  540.  
  541. #==============================================================================
  542. # ■ Game_Map
  543. #==============================================================================
  544.  
  545. class Game_Map
  546.  
  547.   #--------------------------------------------------------------------------
  548.   # overwrite method: scroll_down
  549.   #--------------------------------------------------------------------------
  550.   def scroll_down(distance)
  551.     if loop_vertical?
  552.       @display_y += distance
  553.       @display_y %= @map.height * 256
  554.       @parallax_y += distance
  555.     else
  556.       last_y = @display_y
  557.       dh = Graphics.height > height * 32 ? height : screen_tile_y
  558.       @display_y = [@display_y + distance, height - dh].min
  559.       @parallax_y += @display_y - last_y
  560.     end
  561.   end
  562.  
  563.   #--------------------------------------------------------------------------
  564.   # overwrite method: scroll_right
  565.   #--------------------------------------------------------------------------
  566.   def scroll_right(distance)
  567.     if loop_horizontal?
  568.       @display_x += distance
  569.       @display_x %= @map.width * 256
  570.       @parallax_x += distance
  571.     else
  572.       last_x = @display_x
  573.       dw = Graphics.width > width * 32 ? width : screen_tile_x
  574.       @display_x = [@display_x + distance, width - dw].min
  575.       @parallax_x += @display_x - last_x
  576.     end
  577.   end
  578.  
  579. end # Game_Map
  580.  
  581. #==============================================================================
  582. # ■ Spriteset_Map
  583. #==============================================================================
  584.  
  585. class Spriteset_Map
  586.  
  587.   #--------------------------------------------------------------------------
  588.   # overwrite method: create_viewports
  589.   #--------------------------------------------------------------------------
  590.   def create_viewports
  591.     if Graphics.width > $game_map.width * 32 && !$game_map.loop_horizontal?
  592.       dx = (Graphics.width - $game_map.width * 32) / 2
  593.     else
  594.       dx = 0
  595.     end
  596.     dw = [Graphics.width, $game_map.width * 32].min
  597.     dw = Graphics.width if $game_map.loop_horizontal?
  598.     if Graphics.height > $game_map.height * 32 && !$game_map.loop_vertical?
  599.       dy = (Graphics.height - $game_map.height * 32) / 2
  600.     else
  601.       dy = 0
  602.     end
  603.     dh = [Graphics.height, $game_map.height * 32].min
  604.     dh = Graphics.height if $game_map.loop_vertical?
  605.     @viewport1 = Viewport.new(dx, dy, dw, dh)
  606.     @viewport2 = Viewport.new(dx, dy, dw, dh)
  607.     @viewport3 = Viewport.new(dx, dy, dw, dh)
  608.     @viewport2.z = 50
  609.     @viewport3.z = 100
  610.   end
  611.  
  612.   #--------------------------------------------------------------------------
  613.   # new method: update_viewport_sizes
  614.   #--------------------------------------------------------------------------
  615.   def update_viewport_sizes
  616.     if Graphics.width > $game_map.width * 32 && !$game_map.loop_horizontal?
  617.       dx = (Graphics.width - $game_map.width * 32) / 2
  618.     else
  619.       dx = 0
  620.     end
  621.     dw = [Graphics.width, $game_map.width * 32].min
  622.     dw = Graphics.width if $game_map.loop_horizontal?
  623.     if Graphics.height > $game_map.height * 32 && !$game_map.loop_vertical?
  624.       dy = (Graphics.height - $game_map.height * 32) / 2
  625.     else
  626.       dy = 0
  627.     end
  628.     dh = [Graphics.height, $game_map.height * 32].min
  629.     dh = Graphics.height if $game_map.loop_vertical?
  630.     rect = Rect.new(dx, dy, dw, dh)
  631.     for viewport in [@viewport1, @viewport2, @viewport3]
  632.       viewport.rect = rect
  633.     end
  634.   end
  635.  
  636. end # Spriteset_Map
  637.  
  638. #==============================================================================
  639. # ■ Scene_Map
  640. #==============================================================================
  641.  
  642. class Scene_Map < Scene_Base
  643.  
  644.   #--------------------------------------------------------------------------
  645.   # alias method: post_transfer
  646.   #--------------------------------------------------------------------------
  647.   alias scene_map_post_transfer_ace post_transfer
  648.   def post_transfer
  649.     @spriteset.update_viewport_sizes
  650.     scene_map_post_transfer_ace
  651.   end
  652.  
  653. end # Scene_Map
  654.  
  655. #==============================================================================
  656. # ■ Game_Event
  657. #==============================================================================
  658.  
  659. class Game_Event < Game_Character
  660.  
  661.   #--------------------------------------------------------------------------
  662.   # overwrite method: near_the_screen?
  663.   #--------------------------------------------------------------------------
  664.   def near_the_screen?(dx = nil, dy = nil)
  665.     dx = [Graphics.width, $game_map.width * 256].min/32 - 5 if dx.nil?
  666.     dy = [Graphics.height, $game_map.height * 256].min/32 - 5 if dy.nil?
  667.     ax = $game_map.adjust_x(@real_x) - Graphics.width / 2 / 32
  668.     ay = $game_map.adjust_y(@real_y) - Graphics.height / 2 / 32
  669.     ax >= -dx && ax <= dx && ay >= -dy && ay <= dy
  670.   end
  671.  
  672. end # Game_Event
  673.  
  674. # Chama o método que realiza a mudança de tamanho
  675. # Graphics.fullscreen
  676. Graphics.resize_screen(1632, 832)
  677.  
  678. __END__
  679. # TESTES
  680. # Graphics.windowed
  681. x = Bitmap.new(50, 50)
  682. x.gradient_fill_rect(0,  0, 50, 25, Color.new(255, 0, 0), Color.new(0, 255, 0))
  683. x.gradient_fill_rect(0, 25, 50, 25, Color.new(0, 255, 0), Color.new(0, 0, 255))
  684. y = Plane.new
  685. y.bitmap = x
  686. y.zoom_x = 3
  687. y.zoom_y = 3
  688. #Graphics.fullscreen
  689. #Graphics.windowed
  690. loop do
  691.   Graphics.update
  692.   y.ox += 1
  693.   y.oy += 1
  694. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement