55 lines
1.8 KiB
Ruby
55 lines
1.8 KiB
Ruby
#==============================================================================
|
|
# ■ Window Resize Toggle (F5) - Auto-Center + Taskbar Offset
|
|
#------------------------------------------------------------------------------
|
|
# Cycles through safe window sizes and auto-centers the window to ensure it
|
|
# stays fully visible within the monitor bounds. Nudges window upward to avoid
|
|
# overlapping the taskbar at the bottom.
|
|
#==============================================================================
|
|
|
|
module WindowScaler
|
|
# Define fixed window sizes [width, height]
|
|
SIZES = [
|
|
[544, 416], # 1.0x native
|
|
[816, 624], # 1.5x
|
|
[1088, 832], # 2.0x
|
|
[1360, 1040], # 2.5x
|
|
[1632, 1248], # 3.0x
|
|
[1856, 1392], # ~3.4x
|
|
]
|
|
|
|
TASKBAR_OFFSET = 20 # Move window upward to avoid taskbar
|
|
end
|
|
|
|
class << Graphics
|
|
alias resize_update update
|
|
def update
|
|
resize_update
|
|
WindowResize.update
|
|
end
|
|
end
|
|
|
|
module WindowResize
|
|
@index = 0
|
|
|
|
def self.update
|
|
if Input.trigger?(:F5)
|
|
@index = (@index + 1) % WindowScaler::SIZES.size
|
|
apply_size(*WindowScaler::SIZES[@index])
|
|
end
|
|
end
|
|
|
|
def self.apply_size(width, height)
|
|
# Get screen resolution
|
|
screen_width = Win32API.new('user32', 'GetSystemMetrics', ['I'], 'I').call(0)
|
|
screen_height = Win32API.new('user32', 'GetSystemMetrics', ['I'], 'I').call(1)
|
|
|
|
# Calculate centered position, nudged up by TASKBAR_OFFSET
|
|
x = [(screen_width - width) / 2, 0].max
|
|
y = [(screen_height - height) / 2 - WindowScaler::TASKBAR_OFFSET, 0].max
|
|
|
|
# Resize and move window
|
|
hwnd = Win32API.new('user32', 'FindWindowA', ['P', 'P'], 'L').call("RGSS Player", nil)
|
|
move_window = Win32API.new('user32', 'MoveWindow', %w(L L L L L L), 'L')
|
|
move_window.call(hwnd, x, y, width, height, 1)
|
|
end
|
|
end
|