#****************************************************************************** # # * エセフルスクリーン # # -------------------------------------------------------------------------- # バージョン : 1.0.0 # 対 応 : RPGツクールVX : RGSS2 # 制 作 者 : CACAO # 配 布 元 : https://cacaosoft.mars.jp/ # -------------------------------------------------------------------------- # == 概 要 == # # :ウィンドウのサイズを変更する機能を追加します。 # ※ ゲーム解像度・800x600・フルサイズの順に変更を行います。 # # -------------------------------------------------------------------------- # == 注意事項 == # # ※ 設定によっては、「初期化ファイルの操作」スクリプトが必要です。 # # -------------------------------------------------------------------------- # == 使用方法 == # # ★ WLIB::SetGameWindowSize(width, height) # ウィンドウを中央に移動し、指定されたサイズに変更します。 # 引数が負数、もしくはデスクトップより大きい場合はフルサイズで表示されます。 # 処理が失敗すると false を返します。 # # #****************************************************************************** #============================================================================== # ◆ ユーザー設定 #============================================================================== module WND_SIZE #-------------------------------------------------------------------------- # ◇ サイズ変更キー #-------------------------------------------------------------------------- # 0 .. サイズ変更を行わない #-------------------------------------------------------------------------- INPUT_KEY = Input::F5 #-------------------------------------------------------------------------- # ◇ 初期サイズ #-------------------------------------------------------------------------- # 0 .. 初期サイズ変更を行わない。 # 1 .. 初期化ファイル (Game.ini) の設定を使用する。 # セクション : Window キー : WIDTH, HEIGHT # 2 .. データファイル (Game.rvdata) の設定を使用する。 # 内容は、クライアント領域の Rect オブジェクトです。 # 配列 .. [width, height] の値で変更する。 #-------------------------------------------------------------------------- INIT_SIZE = 0 end #/////////////////////////////////////////////////////////////////////////////# # # # 下記のスクリプトを変更する必要はありません。 # # # #/////////////////////////////////////////////////////////////////////////////# module WLIB #-------------------------------------------------------------------------- # ● 定数 #-------------------------------------------------------------------------- # SystemMetrics SM_CYCAPTION = 0x04 # タイトルバーの高さ SM_CXDLGFRAME = 0x07 # 枠の幅 SM_CYDLGFRAME = 0x08 # 枠の高さ # SetWindowPos SWP_NOSIZE = 0x01 # サイズ変更なし SWP_NOMOVE = 0x02 # 位置変更なし SWP_NOZORDER = 0x04 # 並び変更なし #-------------------------------------------------------------------------- # ● Win32API #-------------------------------------------------------------------------- @@FindWindow = Win32API.new('user32', 'FindWindow', 'pp', 'l') @@GetDesktopWindow = Win32API.new('user32', 'GetDesktopWindow', 'v', 'l') @@SetWindowPos = Win32API.new('user32', 'SetWindowPos', 'lliiiii', 'i') @@GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i') @@GetWindowRect = Win32API.new('user32', 'GetWindowRect', 'lp', 'i') @@GetWindowLong = Win32API.new('user32', 'GetWindowLong', 'li', 'l') @@GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i') @@SystemParametersInfo = Win32API.new('user32', 'SystemParametersInfo', 'iipi', 'i') #-------------------------------------------------------------------------- # ● ウィンドウの情報 #-------------------------------------------------------------------------- unless $! GAME_TITLE = NKF.nkf("-sxm0", load_data("Data/System.rvdata").game_title) GAME_HANDLE = @@FindWindow.call("RGSS Player", GAME_TITLE) end GAME_STYLE = @@GetWindowLong.call(GAME_HANDLE, -16) GAME_EXSTYLE = @@GetWindowLong.call(GAME_HANDLE, -20) HDSK = @@GetDesktopWindow.call module_function #-------------------------------------------------------------------------- # ● GetWindowRect #-------------------------------------------------------------------------- def GetWindowRect(hwnd) r = [0,0,0,0].pack('l4') if @@GetWindowRect.call(hwnd, r) != 0 result = Rect.new(*r.unpack('l4')) result.width -= result.x result.height -= result.y else result = nil end return result end #-------------------------------------------------------------------------- # ● GetClientRect #-------------------------------------------------------------------------- def GetClientRect(hwnd) r = [0,0,0,0].pack('l4') if @@GetClientRect.call(hwnd, r) != 0 result = Rect.new(*r.unpack('l4')) else result = nil end return result end #-------------------------------------------------------------------------- # ● GetSystemMetrics #-------------------------------------------------------------------------- def GetSystemMetrics(index) @@GetSystemMetrics.call(index) end #-------------------------------------------------------------------------- # ● SetWindowPos #-------------------------------------------------------------------------- def SetWindowPos(hwnd, x, y, width, height, z, flag) @@SetWindowPos.call(hwnd, z, x, y, width, height, flag) != 0 end #-------------------------------------------------------------------------- # ● ウィンドウのサイズを取得 #-------------------------------------------------------------------------- def GetGameWindowRect GetWindowRect(GAME_HANDLE) end #-------------------------------------------------------------------------- # ● ウィンドウのクライアントサイズを取得 #-------------------------------------------------------------------------- def GetGameClientRect GetClientRect(GAME_HANDLE) end #-------------------------------------------------------------------------- # ● デスクトップのサイズを取得 #-------------------------------------------------------------------------- def GetDesktopRect r = [0,0,0,0].pack('l4') if @@SystemParametersInfo.call(0x30, 0, r, 0) != 0 result = Rect.new(*r.unpack('l4')) result.width -= result.x result.height -= result.y else result = nil end return result end #-------------------------------------------------------------------------- # ● ウィンドウのフレームサイズを取得 #-------------------------------------------------------------------------- def GetFrameSize return [ GetSystemMetrics(SM_CYCAPTION), # タイトルバー GetSystemMetrics(SM_CXDLGFRAME), # 左右フレーム GetSystemMetrics(SM_CYDLGFRAME) # 上下フレーム ] end #-------------------------------------------------------------------------- # ● ウィンドウの位置を変更 #-------------------------------------------------------------------------- def MoveGameWindow(x, y) SetWindowPos(GAME_HANDLE, x, y, 0, 0, 0, SWP_NOSIZE|SWP_NOZORDER) end #-------------------------------------------------------------------------- # ● ウィンドウの位置を中央へ #-------------------------------------------------------------------------- def MoveGameWindowCenter dr = GetDesktopRect() wr = GetGameWindowRect() x = (dr.width - wr.width) / 2 y = (dr.height - wr.height) / 2 SetWindowPos(GAME_HANDLE, x, y, 0, 0, 0, SWP_NOSIZE|SWP_NOZORDER) end #-------------------------------------------------------------------------- # ● ウィンドウのサイズを変更 #-------------------------------------------------------------------------- def SetGameWindowSize(width, height) # 各領域の取得 dr = GetDesktopRect() # Rect デスクトップ wr = GetGameWindowRect() # Rect ウィンドウ cr = GetGameClientRect() # Rect クライアント return false unless dr && wr && cr # フレームサイズの取得 frame = GetFrameSize() ft = frame[0] + frame[2] # タイトルバーの縦幅 fl = frame[1] # 左フレームの横幅 fs = frame[1] * 2 # 左右フレームの横幅 fb = frame[2] # 下フレームの縦幅 if width < 0 || height < 0 || width >= dr.width || height >= dr.height w = dr.width + fs h = dr.height + ft + fb SetWindowPos(GAME_HANDLE, -fl, -ft, w, h, 0, SWP_NOZORDER) else w = width + fs h = height + ft + fb SetWindowPos(GAME_HANDLE, 0, 0, w, h, 0, SWP_NOMOVE|SWP_NOZORDER) MoveGameWindowCenter() end end end class Scene_Base #-------------------------------------------------------------------------- # ○ フレーム更新 #-------------------------------------------------------------------------- alias _cao_update_wndsize update def update _cao_update_wndsize if Input.trigger?(WND_SIZE::INPUT_KEY) case WLIB::GetGameClientRect().width when Graphics.width width, height = 800, 600 when 800 width, height = -1, -1 else width, height = Graphics.width, Graphics.height end unless WLIB::SetGameWindowSize(width, height) Sound.play_buzzer end end end end # 初期サイズの設定 case WND_SIZE::INIT_SIZE when 1 width = IniFile.read("Game", "Window", "WIDTH", Graphics.width).to_i height = IniFile.read("Game", "Window", "HEIGHT", Graphics.height).to_i WLIB::SetGameWindowSize(width, height) when 2 if FileTest.exist?("Game.rvdata") r = load_data("Game.rvdata") WLIB::SetGameWindowSize(r.width, r.height) end when Array WLIB::SetGameWindowSize(WND_SIZE::INIT_SIZE[0], WND_SIZE::INIT_SIZE[1]) end