#==============================================================================
# ** Graphics
#------------------------------------------------------------------------------
# * Library
#
# Graphics:
# ---------------------------------------------------------------------------
# Graphics.screenshot
# Graphics.snap_to_bitmap
# Graphics.width
# Graphics.height
# Graphics.resize
# Graphics.fullscreen
# Graphics.size
#==============================================================================
#==============================================================================
# ** Graphics
#==============================================================================
module Graphics
#--------------------------------------------------------------------------
# * Screenshot File Directory
#--------------------------------------------------------------------------
Screenshot_Dir = ''
#--------------------------------------------------------------------------
# * Screenshot (By Andreas21 & Cybersam)
#
# image_type : 0 - bmp, 1 - jpg, 2 - png
#--------------------------------------------------------------------------
def self.screenshot(filename = 'screenshot', image_type = 2)
# Adds File Extension
filename += image_type == 0 ? '.bmp' : image_type == 1 ? '.jpg' : '.png'
# Create True Filename
file_name = Screenshot_Dir + filename
# Make Screenshot
API::Screenshot.Screenshot(0, 0, self.width, self.height, file_name,
API.hwnd, image_type)
end
#--------------------------------------------------------------------------
# * Snap to Bitmap
#--------------------------------------------------------------------------
def self.snap_to_bitmap
# Take Screenshot
self.screenshot('snap_to_bitmap')
# Load Bitmap
bitmap = Bitmap.new('snap_to_bitmap')
# Delete Screenshot
File.delete('snap_to_bitmap.png')
# Return Bitmap
return bitmap
end
#--------------------------------------------------------------------------
# * Width
#--------------------------------------------------------------------------
def self.width
return @width == nil ? 640 : @width
end
#--------------------------------------------------------------------------
# * Height
#--------------------------------------------------------------------------
def self.height
return @height == nil ? 480 : @height
end
#--------------------------------------------------------------------------
# * Resize
#--------------------------------------------------------------------------
def self.resize(width = Default_Width, height = Default_Height,
fs = @fullscreen)
# Saves Width & Height
@width, @height = width, height
# Modify Transition Viewport
@transition_viewport.dispose
@transition_sprite.dispose
@transition_viewport = Viewport.new(0, 0, @width, @height)
@transition_viewport.z = 99999
@transition_sprite = Sprite.new(@transition_viewport)
# Set Resolution
self.set_resolution(fs)
end
#--------------------------------------------------------------------------
# * Set Resolution
#--------------------------------------------------------------------------
private
def self.set_resolution(fullscreen = !@fullscreen)
if fullscreen
API::User32.SetWindowLong.call(API.hwnd, API::User32::GWL_STYLE, API::User32::WS_VISIBLE|API::User32::WS_CLIPSIBLINGS)
API::User32.SetWindowPos.call(API.hwnd, HWND_TOPMOST, 0, 0, @width, @height, API::User32::SWP_SHOWWINDOW)
API::Display.Set_Res.call(@width, @height, 4)
else
w = @width + (2 * API::User32.GetSystemMetrics(API::User32::SM_CXFIXEDFRAME))
h = @height + (2 * API::User32.GetSystemMetrics(API::User32::SM_CYFIXEDFRAME)) +
API::User32.GetSystemMetrics(API::User32::SM_CYCAPTION)
x = (@default_size[0] - w) / 2
y = (@default_size[1] - h) / 2
API::User32.SetWindowLong(API.hwnd, API::User32::GWL_STYLE,
API::User32::WS_VISIBLE|API::User32::WS_CLIPSIBLINGS|API::User32::WS_CAPTION|API::User32::WS_SYSMENU|API::User32::WS_MINIMIZEBOX)
API::User32.SetWindowPos(API.hwnd, API::User32::HWND_TOP, x, y, w, h, API::User32::SWP_SHOWWINDOW)
self.update
API::Display.SetResolution(@default_size[0], @default_size[1], 0)
end
end
#--------------------------------------------------------------------------
# * Size
#--------------------------------------------------------------------------
private
def self.size
return API::User32.GetSystemMetrics(0), API::User32.GetSystemMetrics(1)
end
#--------------------------------------------------------------------------
# * Resized?
#--------------------------------------------------------------------------
private
def self.resized?
return @width > 640 || @height > 480
end
#--------------------------------------------------------------------------
# * Save Default Instances
#--------------------------------------------------------------------------
@default_size = self.size
@width = self.width
@height = self.height
@fullscreen = false
#--------------------------------------------------------------------------
# * Tranisition Viewport & Sprite
#--------------------------------------------------------------------------
@transition_viewport = Viewport.new(0, 0, @width, @height)
@transition_viewport.z = 99999
@transition_sprite = Sprite.new(@transition_viewport)
end
# Resize
Graphics.resize