Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
- # Rpg.NET Wrapper
- # Author: ForeverZer0
- # Version: 0.28A
- # Date: 7.30.2014
- #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
- # VERSION HISTORY
- #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
- # - Developer Release, no history until full public release.
- #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
- #
- # Introduction:
- #
- # Rpg.NET is an API built using the .NET Framework for both improving
- # performance and enhancing the RPG Maker series (XP, VX, and VXA). Contained
- # within are various functions and classes that extend the ability of RPG
- # Maker in areas such as graphics, audio, and Windows API interop. Included is
- # a Ruby script that is the wrapper around the library, so it can be used as
- # any other script within your game.
- #
- # Features:
- #
- # A whole bunch, and growing. Will update this for full release.
- #
- # Instructions:
- #
- # - Place Rpg.NET.dll in your game folder
- # - If renaming, update RPGNET constant below
- #
- # Compatibility:
- #
- # - RPG Maker XP, VX, and VXA
- # - Rpg.NET Input Module is likely not compatible with other Input scripts
- # - No know compatibility issues with other scripts.
- #
- # Credits/Thanks:
- #
- # - ForeverZer0, for the script
- #
- # Authors Notes:
- #
- # - This is NOT A FINAL RELEASE, and it is advised not to distribute with your
- # game as such. It is not fully tested, not complete, so various bugs may
- # yet be found.
- #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
- #===============================================================================
- # ** RpgNET
- #-------------------------------------------------------------------------------
- # Module wrapper for Rpg.NET utility functions.
- #===============================================================================
- # Relative name and path of the Rpg.NET library.
- RPGNET = 'Rpg.NET.dll'
- module RpgNET
- #-----------------------------------------------------------------------------
- # * Constants
- #-----------------------------------------------------------------------------
- CopyGameWindow = Win32API.new(RPGNET, 'BmCopyGameWindow', 'ii', '')
- GetWindowRect = Win32API.new(RPGNET, 'GetWindowRect', 'pi', '')
- OpenFileDlg = Win32API.new(RPGNET, 'OpenFileDlg', 'p', 'p')
- RgssEval = Win32API.new(RPGNET, 'RgssEval', 'p', '')
- ShowScriptWindow = Win32API.new(RPGNET, 'ShowScriptWindow', '', '')
- #-----------------------------------------------------------------------------
- # * Initialize Rpg.NET Core
- #-----------------------------------------------------------------------------
- def self.initialize
- version = 0
- if RUBY_VERSION == '1.8.1'
- version = defined?(Hangup) ? 1 : 2
- elsif RUBY_VERSION == '1.9.2'
- version = 4
- end
- Win32API.new(RPGNET, 'Initialize', 'i', '').call(version)
- end
- #-----------------------------------------------------------------------------
- # * Open Script Window
- #-----------------------------------------------------------------------------
- def self.show_script_window
- ShowScriptWindow.call
- end
- #-----------------------------------------------------------------------------
- # * Send Message to Rpg.NET Core
- # code : Code to evaluate within the RGSS scope and return
- #
- # ** INTERNAL USE ONLY ***
- #-----------------------------------------------------------------------------
- def self.send_message(code)
- begin
- result = eval(code)
- unless result.is_a?(String)
- result = result.to_s
- end
- RgssEval.call(result)
- rescue
- RgssEval.call('')
- end
- end
- #-----------------------------------------------------------------------------
- # * Show Open File Dialog
- # filter : Filter to determine available files to open.
- #-----------------------------------------------------------------------------
- def self.open_file_dialog(filter = 'All Files|*.*')
- return OpenFileDlg.call(filter)
- end
- #-----------------------------------------------------------------------------
- # * Get Full Path to Local/RTP Resource
- # filename : Filename to search for, without extension
- # subfolder : Relative subfolder where file is located
- #-----------------------------------------------------------------------------
- def self.get_full_path(filename, subfolder)
- api = Win32API.new(RPGNET, 'GetFullPath', 'pp', 'p')
- return api.call(filename, subfolder)
- end
- #-----------------------------------------------------------------------------
- # * Show Console Output Window
- #-----------------------------------------------------------------------------
- def self.show_console
- Win32API.new(RPGNET, 'ShowConsole', '', '').call
- end
- #-----------------------------------------------------------------------------
- # * Hide Console Output Window
- #-----------------------------------------------------------------------------
- def self.hide_console
- # TODO: Implement
- end
- #-----------------------------------------------------------------------------
- # * Get RTP Path
- # index : Index of the RTP whose path to retrieve (XP Only)
- #-----------------------------------------------------------------------------
- def self.get_rtp_path(index = 0)
- return Win32API.new(RPGNET, 'GetRtpPath', 'i', 'p').call(index)
- end
- #-----------------------------------------------------------------------------
- # * Set Window Resolution
- # width : Width of the new client area of the window to set
- # height : Height of the new client area of the window to set
- #-----------------------------------------------------------------------------
- def self.set_resolution(width, height)
- Win32API.new(RPGNET, 'SetResolution', 'ii', '').call(width, height)
- end
- #-----------------------------------------------------------------------------
- # * Set Window Icon
- # icon : Bitmap to use as window icon, or file to a image or *.ico file.
- # Bitmaps must be either 48x48, 128x128, or 256x256.
- #-----------------------------------------------------------------------------
- def self.set_window_icon(icon)
- if icon.is_a?(String)
- Win32API.new(RPGNET, 'SetIconFile', 'p', '').call(icon)
- elsif icon.is_a?(Bitmap)
- Win32API.new(RPGNET, 'SetIconBitmap', 'i', '').call(icon.__id__)
- end
- end
- #-----------------------------------------------------------------------------
- # * Get Window Rectangle
- # frame : Flag indiciating if window frame will be included in rectangle
- #-----------------------------------------------------------------------------
- def self.get_window_rect(frame = false)
- rect = [0, 0, 0, 0].pack('l4')
- GetWindowRect.call(rect, frame ? 1 : 0)
- return Rect.new(*rect.unpack('l4'))
- end
- #-----------------------------------------------------------------------------
- # * Get Screenshot
- # frame : Flag indiciating if window frame will be included in image.
- #-----------------------------------------------------------------------------
- def self.window_bitmap(frame = false)
- rect = [0, 0, 0, 0].pack('l4')
- GetWindowRect.call(rect, frame ? 1 : 0)
- x, y, w, h = rect.unpack('l4')
- bitmap = Bitmap.new(w, h)
- CopyGameWindow.call(bitmap.__id__, frame ? 1 : 0)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Save Screenshot
- # filename : Path where image will be saved. (*.jpg, *.png, *.bmp, *.gif)
- # frame : Flag indiciating if window frame will be included in image.
- #-----------------------------------------------------------------------------
- def self.screenshot(filename, frame = false)
- screen = self.window_bitmap(frame)
- screen.save(filename)
- screen.dispose
- end
- end
- ################################################################################
- # DO NOT REMOVE! REQUIRED FOR LIBRARY TO WORK!
- ################################################################################
- RpgNET.initialize
- ################################################################################
- # DO NOT REMOVE! REQUIRED FOR LIBRARY TO WORK!
- ################################################################################
- #===============================================================================
- # ** Bitmap
- #-------------------------------------------------------------------------------
- # The bitmap class. Bitmaps are expressions of so-called graphics.
- #===============================================================================
- class Bitmap
- #-----------------------------------------------------------------------------
- # * Constants
- #-----------------------------------------------------------------------------
- Save = Win32API.new(RPGNET, 'BmSave', 'ip', '')
- Filter = Win32API.new(RPGNET, 'BmFilter', 'iiiiii', '')
- Load = Win32API.new(RPGNET, 'BmLoad', 'pp', '')
- GetLoaded = Win32API.new(RPGNET, 'BmGetLoaded', 'i', '') # lol
- DrawArc = Win32API.new(RPGNET, 'BmDrawArc', 'iiiiiiiii', '')
- DrawBezier = Win32API.new(RPGNET, 'BmDrawBezier', 'iiiiiiiiii', '')
- DrawBeziers = Win32API.new(RPGNET, 'BmDrawBezier', 'iip', '')
- DrawClosedCurve = Win32API.new(RPGNET, 'BmDrawClosedCurve', 'iiipp', '')
- DrawCurve = Win32API.new(RPGNET, 'BmDrawCurve', 'iiiipp', '')
- DrawEllipse = Win32API.new(RPGNET, 'BmDrawEllipse', 'iiiiiii', '')
- DrawLine = Win32API.new(RPGNET, 'BmDrawLine', 'iiiiiii', '')
- DrawLines = Win32API.new(RPGNET, 'BmDrawLine', 'iiip', '')
- DrawPolygon = Win32API.new(RPGNET, 'BmDrawPolygon', 'iiip', '')
- DrawPie = Win32API.new(RPGNET, 'BmDrawPie', 'iiiiiiiii', '')
- FillClosedCurve = Win32API.new(RPGNET, 'BmFillClosedCurve', 'iipp', '')
- FillEllipse = Win32API.new(RPGNET, 'BmFillEllipse', 'iiiiii', '')
- FillPie = Win32API.new(RPGNET, 'BmFillPie', 'iiiiiiii', '')
- FillPolygon = Win32API.new(RPGNET, 'BmFillPolygon', 'iip', '')
- FillGradientRect = Win32API.new(RPGNET, 'BmFillGradientRect', 'iiiiiiip', '')
- FillGradientEllipse = Win32API.new(RPGNET, 'BmFillGradientEllipse', 'iiiiiiip', '')
- FillGradientPolygon = Win32API.new(RPGNET, 'BmFillGradientPolygon', 'iiipp', '')
- Invert = Win32API.new(RPGNET, 'BmInvert', 'ii', '')
- Pixelate = Win32API.new(RPGNET, 'BmPixelate', 'iii', '')
- ChangeRgba = Win32API.new(RPGNET, 'BmChangeRgba', 'iii', '')
- GaussianBlur = Win32API.new(RPGNET, 'BmGaussianBlur', 'iip', '')
- Blur = Win32API.new(RPGNET, 'BmBlur', 'iip', '')
- Sharpen = Win32API.new(RPGNET, 'BmSharpen', 'iip', '')
- Soften = Win32API.new(RPGNET, 'BmSoften', 'i', '')
- EdgeDetect = Win32API.new(RPGNET, 'BmEdgeDetect', 'iii', '')
- PosterEffect = Win32API.new(RPGNET, 'BmPosterEffect', 'i', '')
- Sepia = Win32API.new(RPGNET, 'BmSepia', 'i', '')
- HighPass = Win32API.new(RPGNET, 'BmHighPass', 'ii', '')
- Grayscale = Win32API.new(RPGNET, 'BmGrayscale', 'ii', '')
- Emboss = Win32API.new(RPGNET, 'BmEmboss', 'iii', '')
- Tint = Win32API.new(RPGNET, 'BmTint', 'iiii', '')
- ColorBalance = Win32API.new(RPGNET, 'BmColorBalance', 'iiii', '')
- Bitonal = Win32API.new(RPGNET, 'BmBitonal', 'iiii', '')
- Solarise = Win32API.new(RPGNET, 'BmSolarise', 'iiii', '')
- MedianFilter = Win32API.new(RPGNET, 'BmMedianFilter', 'iiii', '')
- DrawTextVertical = Win32API.new(RPGNET, 'BmDrawTextV', 'iiiiipipiiii', '')
- DrawTextGradient = Win32API.new(RPGNET, 'BmDrawGradientText', 'iiiiipipiiiii', '')
- DrawTextGradientV = Win32API.new(RPGNET, 'BmDrawGradientTextV', 'iiiiipipiiiiii', '')
- ColorMask = Win32API.new(RPGNET, 'BmColorMask', 'iii', '')
- Search = Win32API.new(RPGNET, 'BmSearch', 'iipp', '')
- RotateFlip = Win32API.new(RPGNET, 'BmRotateFlip', 'ii', '')
- #-----------------------------------------------------------------------------
- # * Public Instance Variables
- #-----------------------------------------------------------------------------
- attr_reader :hue
- attr_reader :saturation
- attr_reader :contrast
- attr_reader :brightness
- attr_reader :gamma
- attr_reader :red
- attr_reader :green
- attr_reader :blue
- attr_reader :alpha
- #-----------------------------------------------------------------------------
- # * Object Initialization
- #-----------------------------------------------------------------------------
- alias effects_init initialize
- def initialize(*args)
- @hue = 0
- @saturation = 100
- @contrast = 100
- @brightness = 100
- @gamma = 100
- @red = 0
- @green = 0
- @blue = 0
- @alpha = 0
- effects_init(*args)
- end
- #-----------------------------------------------------------------------------
- # * Set Red Component Offset
- # value : Offset to apply to pixel component. (-255..255)
- #-----------------------------------------------------------------------------
- def red=(value)
- if @red != value
- @red = value
- ChangeRgba.call(__id__, value, 2)
- end
- end
- #-----------------------------------------------------------------------------
- # * Set Green Component Offset
- # value : Offset to apply to pixel component. (-255..255)
- #-----------------------------------------------------------------------------
- def green=(value)
- if @green != value
- @green = value
- ChangeRgba.call(__id__, value, 1)
- end
- end
- #-----------------------------------------------------------------------------
- # * Set Blue Component Offset
- # value : Offset to apply to pixel component. (-255..255)
- #-----------------------------------------------------------------------------
- def blue=(value)
- if @blue != value
- @blue = value
- ChangeRgba.call(__id__, value, 0)
- end
- end
- #-----------------------------------------------------------------------------
- # * Set Alpha Component Offset
- # value : Offset to apply to pixel component. (-255..255)
- #-----------------------------------------------------------------------------
- def alpha=(value)
- if @alpha != value
- @alpha = value
- ChangeRgba.call(__id__, value, 3)
- end
- end
- #-----------------------------------------------------------------------------
- # * Apply Multiple Filters (Destructive)
- # hue : Set the hue level. (Clamped between 0 and 360)
- # saturation : Set the saturation level. (Clamped between 0 and 200)
- # brightness : Set the brightness level. (Clamped between 0 and 200)
- # contrast : Set the contrast level. (Clamped between 1 and 400)
- # gamma : Set the gamma level. (Clamped between 1 and 400)
- #-----------------------------------------------------------------------------
- def apply_filter!(hue, saturation, brightness, contrast, gamma)
- @hue = [[0, hue].max, 360].min
- @saturation = [[0, saturation].max, 200].min
- @brightness = [[0, brightness].max, 200].min
- @contrast = [[1, contrast].max, 400].min
- @gamma = [[1, gamma].max, 400].min
- Filter.call(__id__, @hue, @saturation, @brightness, @contrast, @gamma)
- end
- #-----------------------------------------------------------------------------
- # * Apply Multiple Filters (Non-Destructive)
- # hue : Set the hue level. (Clamped between 0 and 360)
- # saturation : Set the saturation level. (Clamped between 0 and 200)
- # brightness : Set the brightness level. (Clamped between 0 and 200)
- # contrast : Set the contrast level. (Clamped between 1 and 400)
- # gamma : Set the gamma level. (Clamped between 1 and 400)
- #-----------------------------------------------------------------------------
- def apply_filter(hue, saturation, brightness, contrast, gamma)
- bitmap = self.clone
- bitmap.apply_filter!(hue, saturation, brightness, contrast, gamma)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Apply Hue Filter (Destructive)
- # value : Set the hue level. (Clamped between 0 and 360)
- #-----------------------------------------------------------------------------
- def set_hue!(value)
- @hue = [[0, value].max, 360].min
- Filter.call(__id__, @hue, 100, 100, 100, 100)
- end
- #-----------------------------------------------------------------------------
- # * Apply Hue Filter (Non-Destructive)
- # value : Set the hue level. (Clamped between 0 and 360)
- #-----------------------------------------------------------------------------
- def set_hue(value)
- bitmap = self.clone
- @hue = [[0, value].max, 360].min
- Filter.call(bitmap._id__, @hue, 100, 100, 100, 100)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Apply Saturation Filter (Destructive)
- # value : Set the saturation level. (Clamped between 0 and 200)
- #-----------------------------------------------------------------------------
- def set_saturation!(value)
- @saturation = [[0, value].max, 200].min
- Filter.call(__id__, 0, @saturation, 100, 100, 100)
- end
- #-----------------------------------------------------------------------------
- # * Apply Saturation Filter (Non-Destructive)
- # value : Set the saturation level. (Clamped between 0 and 200)
- #-----------------------------------------------------------------------------
- def set_saturation=(value)
- bitmap = self.clone
- @saturation = [[0, value].max, 200].min
- Filter.call(bitmap.__id__, 0, @saturation, 100, 100, 100)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Apply Brightness Filter (Destructive)
- # value : Set the brightness level. (Clamped between 0 and 200)
- #-----------------------------------------------------------------------------
- def set_brightness!(value)
- @brightness = [[0, value].max, 200].min
- Filter.call(__id__, 0, 100, @brightness, 100, 100)
- end
- #-----------------------------------------------------------------------------
- # * Apply Brightness Filter (Non-Destructive)
- # value : Set the brightness level. (Clamped between 0 and 200)
- #-----------------------------------------------------------------------------
- def set_brightness=(value)
- bitmap = self.clone
- @brightness = [[0, value].max, 200].min
- Filter.call(bitmap.__id__, 0, 100, @brightness, 100, 100)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Apply Contrast Filter (Destructive)
- # value : Set the contrast level. (Clamped between 1 and 200)
- #-----------------------------------------------------------------------------
- def set_contrast!(value)
- @contrast = [[1, value].max, 400].min
- Filter.call(__id__, 0, 100, 100, @contrast, 100)
- end
- #-----------------------------------------------------------------------------
- # * Apply Contrast Filter (Non-Destructive)
- # value : Set the contrast level. (Clamped between 1 and 200)
- #-----------------------------------------------------------------------------
- def set_contrast(value)
- bitmap = self.clone
- @contrast = [[1, value].max, 400].min
- Filter.call(bitmap.__id__, 0, 100, 100, @contrast, 100)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Apply Gamma Filter (Destructive)
- # value : Set the gamma level. (Clamped between 1 and 400)
- #-----------------------------------------------------------------------------
- def set_gamma!(value)
- @gamma = [[1, value].max, 400].min
- Filter.call(__id__, 0, 100, 100, 100, @gamma)
- end
- #-----------------------------------------------------------------------------
- # * Apply Gamma Filter (Non-Destructive)
- # value : Set the gamma level. (Clamped between 1 and 400)
- #-----------------------------------------------------------------------------
- def set_gamma(value)
- bitmap = self.clone
- @gamma = [[1, value].max, 400].min
- Filter.call(bitmap.__id__, 0, 100, 100, 100, @gamma)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Save Bitmap
- # filename : Path to file (*.jpg, *.png, *.bmp, *.gif)
- #-----------------------------------------------------------------------------
- def save(filename)
- Save.call(__id__, filename)
- end
- #-----------------------------------------------------------------------------
- # * Load an Image File
- # filename : Supported formats: PNG, JPG, PSD, BMP, GIF, EXIF, TIFF
- #-----------------------------------------------------------------------------
- def self.open(filename)
- struct = [0, 0].pack('l2')
- Load.call(filename, struct)
- size = struct.unpack('l2')
- bitmap = Bitmap.new(size[0], size[1])
- GetLoaded.call(bitmap.__id__)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Bitmap Contains Bitmap
- # other : Child Bitmap to check for
- # tolerance : Amount of variance allowed in comparison (0.0 = Exact)
- #-----------------------------------------------------------------------------
- def include?(other, tolerance = 0.0)
- rect = find(other, tolerance)
- return rect.width != 0 && rect.height != 0
- end
- #-----------------------------------------------------------------------------
- # * Find Rect of Child Bitmap
- # other : Child Bitmap to check for
- # tolerance : Amount of variance allowed in comparison (0.0 = Exact)
- #-----------------------------------------------------------------------------
- def find(bitmap, tolerance = 0.0)
- rect = [0, 0, 0, 0].pack('l4')
- Search.call(bitmap.__id__, __id__, tolerance.to_s, rect)
- rect = rect.unpack('l4')
- return Rect.new(*rect)
- end
- #-----------------------------------------------------------------------------
- # * Draw Text Vertical
- # x : x-coordinate of text
- # y : y-coordinate of text
- # width : Width of area to draw. Text will be centered horizontally.
- # height : Height of area to draw text.
- # text : String to draw.
- # align : Text justificatiion. 0 = Left, 1 = Center, 2 = Right
- # direction : Text direction. 0 = Left, 1 = Right
- #-----------------------------------------------------------------------------
- def draw_text_vertical(x, y, width, height, text, align = 0, direction = 0)
- style = 0
- style |= 1 if self.font.bold
- style |= 2 if self.font.italic
- DrawTextVertical.call(__id__, x, y, width, height, text, align,
- self.font.name, self.font.color.to_i, self.font.size, style, direction)
- end
- def draw_gradient_text(x, y, width, height, text, align = 0)
- if self.font.gradient.nil?
- white = Color.new(255, 255, 255)
- self.font.gradient = Gradient.new(self.font.color, white, 90)
- end
- style = 0
- style |= 1 if self.font.bold
- style |= 2 if self.font.italic
- g = self.font.gradient
- DrawTextGradient.call(__id__, x, y, width, height, text, align,
- self.font.name, g.color1.to_i, g.color2.to_i, g.angle, self.font.size, style)
- end
- def draw_gradient_text_vertical(x, y, width, height, text, align = 0, direction = 0)
- if self.font.gradient.nil?
- white = Color.new(255, 255, 255)
- self.font.gradient = Gradient.new(self.font.color, white, 90)
- end
- style = 0
- style |= 1 if self.font.bold
- style |= 2 if self.font.italic
- g = self.font.gradient
- DrawTextGradientV.call(__id__, x, y, width, height, text, align,
- self.font.name, g.color1.to_i, g.color2.to_i, g.angle, self.font.size,
- style, direction)
- end
- #-----------------------------------------------------------------------------
- # * Draw Arc
- # color : Color used to draw
- # thickness : Thickness, in pixels, of the pen used to draw
- # x : x-coordinate
- # y : y-coordinate
- # width : width of the shape
- # height : height of the shape
- # start_angle : Angle in degrees measured clockwise from the x-axis to the
- # starting point of the arc
- # sweep_angle : Angle in degrees measured clockwise from the startAngle
- # parameter to ending point of the arc
- #-----------------------------------------------------------------------------
- def draw_arc(color, thickness, x, y, width, height, start_angle, sweep_angle)
- DrawArc.call(__id__, color.to_i, thickness, x, y, width, height,
- start_angle, sweep_angle)
- end
- #-----------------------------------------------------------------------------
- # * Draw Bezier
- # color : Color used to draw
- # x1 : first x-coordinate
- # y1 : first y-coordinate
- # x2 : second x-coordinate
- # y2 : second y-coordinate
- # x3 : third x-coordinate
- # y3 : third y-coordinate
- # x4 : fourth x-coordinate
- # y4 : fourth y-coordinate
- #-----------------------------------------------------------------------------
- def draw_bezier(x1, y1, x2, y2, x3, y3, x4, y4, color)
- DrawBezier.call(__id__, color.to_i, x1, y1, x2, y2, x3, y3, x4, y4)
- end
- #-----------------------------------------------------------------------------
- # * Draw Beziers
- # color : Color used to draw
- # points : Points used to draw shape, variable number of arguments.
- # No. of points should be multiple of 3 + 1, such as 4, 7, or 10.
- #-----------------------------------------------------------------------------
- def draw_beziers(color, *points)
- DrawBeziers.call(__id__, color.to_i, points.join(','))
- end
- #-----------------------------------------------------------------------------
- # * Draws Closed Curve
- # color : Color used to draw
- # thickness : Thickness, in pixels, of the pen used to draw
- # tension : Specifies the tension of the curve
- # points : Points used to draw shape, variable number of arguments.
- #-----------------------------------------------------------------------------
- def draw_closed_curve(color, thickness, tension, *points)
- DrawClosedCurve(__id__, color.to_i, thickness, tension.to_s, points.join(','))
- end
- #-----------------------------------------------------------------------------
- # * Draw Curve
- # color : Color used to draw
- # thickness : Thickness, in pixels, of the pen used to draw
- # tension : Specifies the tension of the curve
- # points : Points used to draw shape, variable number of arguments.
- #-----------------------------------------------------------------------------
- def draw_curve(color, thickness, tension, *points)
- points = points.join(',')
- DrawCurve.call(__id__, color.to_i, thickness, tension.to_s, points)
- end
- #-----------------------------------------------------------------------------
- # * Draw Ellipse
- # color : Color used to draw
- # thickness : Thickness, in pixels, of the pen used to draw
- # x : x-coordinate
- # y : y-coordinate
- # width : width of the shape
- # height : height of the shape
- #-----------------------------------------------------------------------------
- def draw_ellipse(color, thickness, x, y, width, height)
- DrawEllipse.call(__id__, color.to_i, thickness, x, y, width, height)
- end
- #-----------------------------------------------------------------------------
- # * Draw Line
- # x1 : first x-coordinate
- # y1 : first y-coordinate
- # x2 : second x-coordinate
- # y2 : second y-coordinate
- # color : Color used to draw
- # thickness : Thickness, in pixels, of the pen used to draw
- #-----------------------------------------------------------------------------
- def draw_line(x1, y1, x2, y2, color, thickness)
- DrawLine.call(__id__, x1, y1, x2, y2, color.to_i, thickness)
- end
- #-----------------------------------------------------------------------------
- # * Draw Lines
- # color : Color used to draw
- # thickness : Thickness, in pixels, of the pen used to draw
- # points : Points used to draw shape, variable number of arguments.
- #-----------------------------------------------------------------------------
- def draw_lines(color, thickness, *points)
- DrawLines.call(__id__, color.to_i, thickness, points.join(','))
- end
- #-----------------------------------------------------------------------------
- # * Draw Polygon
- # color : Color used to draw
- # thickness : Thickness, in pixels, of the pen used to draw
- # points : Points used to draw shape, variable number of arguments.
- #-----------------------------------------------------------------------------
- def draw_polygon(color, thickness, *points)
- DrawPolygon.call(__id__, color.to_i, thickness, points.join(','))
- end
- #-----------------------------------------------------------------------------
- # * Draw Pie
- # x : x-coordinate
- # y : y-coordinate
- # width : width of the shape
- # height : height of the shape
- # start_angle : Angle in degrees measured clockwise from the x-axis to the
- # starting point of the arc
- # sweep_angle : Angle in degrees measured clockwise from the startAngle
- # parameter to ending point of the arc
- # color : Color used to draw
- # thickness : Thickness, in pixels, of the pen used to draw
- #-----------------------------------------------------------------------------
- def draw_pie(x, y, width, height, start_angle, sweep_angle, color, thickness)
- DrawPie.call(__id__, x, y, width, height, start_angle, sweep_angle,
- color.to_i, thickness)
- end
- #-----------------------------------------------------------------------------
- # * Fill Closed Curve
- # color : Color used to draw
- # tension : Specifies the tension of the curve
- # points : Points used to draw shape, variable number of arguments.
- #-----------------------------------------------------------------------------
- def fill_closed_curve(color, *points)
- FillClosedCurve.call(__id__, color.to_i, tension.to_s, points.join(','))
- end
- #-----------------------------------------------------------------------------
- # * Fill Ellipse
- # color : Color used to draw
- # x : x-coordinate
- # y : y-coordinate
- # width : width of the shape
- # height : height of the shape
- #-----------------------------------------------------------------------------
- def fill_ellipse(x, y, width, height, color)
- FillEllipse.call(__id__, color.to_i, x, y, width, height)
- end
- #-----------------------------------------------------------------------------
- # * Fill Pie
- # color : Color used to draw
- # x : x-coordinate
- # y : y-coordinate
- # width : width of the shape
- # height : height of the shape
- # start_angle : Angle in degrees measured clockwise from the x-axis to the
- # starting point of the arc
- # sweep_angle : Angle in degrees measured clockwise from the startAngle
- # parameter to ending point of the arc
- #-----------------------------------------------------------------------------
- def fill_pie(color, x, y, width, height, start_angle, sweep_angle)
- FillPie.call(__id__, color.to_i, x, y, width, height, start_angle, sweep_angle)
- end
- #-----------------------------------------------------------------------------
- # * Fill Polygon
- # color : Color used to draw
- # points : Points used to draw shape, variable number of arguments.
- #-----------------------------------------------------------------------------
- def fill_polygon(color, *points)
- FillPolygon.call(__id__, color.to_i, points.join(','))
- end
- #-----------------------------------------------------------------------------
- # * Fill Rectangle Gradient
- # x : x-coordinate
- # y : y-coordinate
- # width : width of the shape
- # height : height of the shape
- # color1 : Start color used to draw the gradient
- # color2 : End color used to draw the gradient
- # angle : Angle at which the gradient will be drawn across the shape
- #-----------------------------------------------------------------------------
- def fill_gradient_rect(x, y, width, height, color1, color2, angle)
- FillGradientRect.call(__id__, x, y, width, height, color1.to_i,
- color2.to_i, angle.to_s)
- end
- #-----------------------------------------------------------------------------
- # * Fill Ellipse Gradient
- # x : x-coordinate
- # y : y-coordinate
- # width : width of the shape
- # height : height of the shape
- # color1 : Start color used to draw the gradient
- # color2 : End color used to draw the gradient
- # angle : Angle at which the gradient will be drawn across the shape
- #-----------------------------------------------------------------------------
- def fill_gradient_ellipse(x, y, width, height, color1, color2, angle)
- FillGradientEllipse.call(__id__, x, y, width, height, color1.to_i,
- color2.to_i, angle.to_s)
- end
- #-----------------------------------------------------------------------------
- # * Fill Polygon Gradient
- # color1 : Start color used to draw the gradient
- # color2 : End color used to draw the gradient
- # angle : Angle at which the gradient will be drawn across the shape
- # points : Points used to draw shape, variable number of arguments.
- #-----------------------------------------------------------------------------
- def fill_gradient_polygon(color1, color2, angle, *points)
- FillGradientPolygon.call(__id__, color1.to_i, color2.to_i,
- angle.to_s, points.join(','))
- end
- #-----------------------------------------------------------------------------
- # * Invert Colors (Destructive)
- # invert_alpha : Flag indiciating if the alpha component will be inverted
- #-----------------------------------------------------------------------------
- def invert!(invert_alpha = false)
- Invert.call(__id__, invert_alpha ? 1 : 0)
- end
- #-----------------------------------------------------------------------------
- # * Invert Colors (Non-Destructive)
- # invert_alpha : Flag indiciating if the alpha component will be inverted
- #-----------------------------------------------------------------------------
- def invert(invert_alpha = false)
- bitmap = self.clone
- Invert.call(bitmap.__id__, invert_alpha ? 1 : 0)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Pixelate (Destructive)
- # amount : New size of pixels in the bitmap
- # alpha : Flag indicating if alpha will be averaged into pixel colors
- #-----------------------------------------------------------------------------
- def pixelate!(amount = 4, alpha = false)
- amount = [[amount, 2].max, self.width / 2].min
- Pixelate.call(__id__, amount, alpha ? 1 : 0)
- end
- #-----------------------------------------------------------------------------
- # * Pixelate (Non-Destructive)
- # amount : New size of pixels in the bitmap
- # alpha : Flag indicating if alpha will be averaged into pixel colors
- #-----------------------------------------------------------------------------
- def pixelate(amount = 4, alpha = false)
- bitmap = self.clone
- amount = [[amount, 2].max, self.width / 2].min
- Pixelate.call(bitmap.__id__, amount, alpha ? 1 : 0)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Change Color Component (Destructive)
- # amount : Amount to change color component (-255..255)
- # color_component : Component to change (B:0, G:1, R:2, A:3)
- #-----------------------------------------------------------------------------
- def change_rgba!(amount, color_component)
- ChangeRgba.call(__id__, amount, color_component)
- end
- #-----------------------------------------------------------------------------
- # * Change Color Component (Non-Destructive)
- # amount : Amount to change color component (-255..255)
- # color_component : Component to change (B:0, G:1, R:2, A:3)
- #-----------------------------------------------------------------------------
- def change_rgba(amount, color_component)
- bitmap = self.clone
- ChangeRgba.call(bitmap.__id__, amount, color_component)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Gaussian Blur (Destructive)
- # kernel_size :
- # weight :
- #-----------------------------------------------------------------------------
- def gaussian_blur!(kernel_size = 5, weight = 5.5)
- GaussianBlur.call(__id__, kernel_size, weight.to_s)
- end
- #-----------------------------------------------------------------------------
- # * Gaussian Blur (Non-Destructive)
- # kernel_size :
- # weight :
- #-----------------------------------------------------------------------------
- def gaussian_blur(kernel_size = 5, weight = 5.5)
- bitmap = self.clone
- GaussianBlur.call(bitmap.__id__, kernel_size, weight.to_s)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Blur Effect (Destructive)
- # type : Blur algorithm that will be used.
- # 0 : Standard (3x3 matrix, 1.0 factor)
- # 1 : 5x5 Matrix, 1.0 / 13.0 factor)
- # 2 : Gaussian (3x3 matrix, 1.0 / 16.0 factor)
- # 3 : Gaussian (5x5 matrix, 1.0 / 159.0 factor)
- # 4 : Motion (9x9 matrix, 1.0 / 18.0 factor)
- # 5 : Left to Right Motion (9x9 matrix, 1.0 / 9.0 factor)
- # 6 : Right to Left Motion (9x9 matrix, 1.0 / 9.0 factor)
- # 7 : Custom (5x5 matrix, custom factor)
- # factor : Factor level for custom type. Ignored for all others.
- #-----------------------------------------------------------------------------
- def blur!(type = 0, factor = 1.0)
- Blur.call(__id__, type, factor.to_s)
- end
- #-----------------------------------------------------------------------------
- # * Blur Effect (Non-Destructive)
- # type : Blur algorithm that will be used.
- # 0 : Standard (3x3 matrix, 1.0 factor)
- # 1 : 5x5 Matrix, 1.0 / 13.0 factor)
- # 2 : Gaussian (3x3 matrix, 1.0 / 16.0 factor)
- # 3 : Gaussian (5x5 matrix, 1.0 / 159.0 factor)
- # 4 : Motion (9x9 matrix, 1.0 / 18.0 factor)
- # 5 : Left to Right Motion (9x9 matrix, 1.0 / 9.0 factor)
- # 6 : Right to Left Motion (9x9 matrix, 1.0 / 9.0 factor)
- # 7 : Custom (5x5 matrix, custom factor)
- # factor : Factor level for custom type. Ignored for all others.
- #-----------------------------------------------------------------------------
- def blur(type = 0, factor = 1.0)
- bitmap = self.clone
- Blur.call(__id__, type, factor.to_s)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Sharpen (Destructive)
- # type : Sharpen algorithm that will be used.
- # 0 : Standard (1.0 factor)
- # 1 : Light (3x3 matrix)
- # 2 : Ultra-Light (3x3 matrix, 0.3 factor)
- # 3 : 5x5 matrix (Depending on source, sometimes softens)
- # 4 : Intense
- # 5 : Custom defined factor will be used
- # factor : Factor level for custom type. Ignored for all others.
- #-----------------------------------------------------------------------------
- def sharpen!(type = 0, factor = 1.0)
- Sharpen.call(__id__, type, factor.to_s)
- end
- #-----------------------------------------------------------------------------
- # * Sharpen (Non-Destructive)
- # type : Sharpen algorithm that will be used.
- # 0 : Standard (1.0 factor)
- # 1 : Light (3x3 matrix)
- # 2 : Ultra-Light (3x3 matrix, 0.3 factor)
- # 3 : 5x5 matrix (Depending on source, sometimes softens)
- # 4 : Intense
- # 5 : Custom defined factor will be used
- # factor : Factor level for custom type. Ignored for all others.
- #-----------------------------------------------------------------------------
- def sharpen(type = 0, factor = 1.0)
- bitmap = self.clone
- Sharpen.call(bitmap.__id__, type, factor.to_s)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Soften (Destructive)
- #-----------------------------------------------------------------------------
- def soften!
- Soften.call(__id__)
- end
- #-----------------------------------------------------------------------------
- # * Soften (Non-Destructive)
- #-----------------------------------------------------------------------------
- def soften
- bitmap = self.clone
- Soften.call(bitmap.__id__)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Edge Detect (Destructive)
- # type : Edge-detection algorithm that will be used.
- # 0 = Standard
- # 1 = 45 Degree
- # 2 = Horizontal
- # 3 = Vertical
- # grayscale : Flag indicating if result will be grayscaled
- #-----------------------------------------------------------------------------
- def edge_detect!(type = 0, grayscale = false)
- EdgeDetect.call(__id__, type, grayscale ? 1 : 0)
- end
- #-----------------------------------------------------------------------------
- # * Edge Detect (Non-Destructive)
- # type : Edge-detection algorithm that will be used.
- # 0 = Standard
- # 1 = 45 Degree
- # 2 = Horizontal
- # 3 = Vertical
- # grayscale : Flag indicating if result will be grayscaled
- #-----------------------------------------------------------------------------
- def edge_detect(type = 0, grayscale = false)
- bitmap = self.clone
- EdgeDetect.call(bitmap.__id__, type, grayscale ? 1 : 0)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Poster Effect (Destructive)
- #-----------------------------------------------------------------------------
- def poster_effect!
- PosterEffect.call(__id__)
- end
- #-----------------------------------------------------------------------------
- # * Poster Effect (Non-Destructive)
- #-----------------------------------------------------------------------------
- def poster_effect
- bitmap = self.clone
- PosterEffect.call(bitmap.__id__)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * High Pass Filter (Destructive)
- #-----------------------------------------------------------------------------
- def high_pass!(grayscale = false)
- HighPass.call(__id__, grayscale ? 1 : 0)
- end
- #-----------------------------------------------------------------------------
- # * High Pass Filter (Non-Destructive)
- #-----------------------------------------------------------------------------
- def high_pass(grayscale = false)
- bitmap = self.clone
- HighPass.call(bitmap.__id__, grayscale ? 1 : 0)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Color Mask
- # color : Color to create mask for
- # tolerance : Amount of variance allowed in pixel comparison.
- #-----------------------------------------------------------------------------
- def color_mask(color, tolerance)
- mask = self.clone
- ColorMask.call(mask.__id__, color.to_i, tolerance)
- return mask
- end
- #-----------------------------------------------------------------------------
- # * Sepia Effect (Destructive)
- #-----------------------------------------------------------------------------
- def sepia!
- Sepia.call(__id__)
- end
- #-----------------------------------------------------------------------------
- # * Sepia Effect (Non-Destructive)
- #-----------------------------------------------------------------------------
- def sepia
- bitmap = self.clone
- Sepia.call(bitmap.__id__)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Grayscale Effect (Destructive)
- # remove_alpha : Flag indicating if alpha component will be removed
- #-----------------------------------------------------------------------------
- def grayscale!(remove_alpha = false)
- Grayscale.call(__id__, remove_alpha ? 1 : 0)
- end
- #-----------------------------------------------------------------------------
- # * Grayscale Effect (Non-Destructive)
- # remove_alpha : Flag indicating if alpha component will be removed
- #-----------------------------------------------------------------------------
- def grayscale(remove_alpha = false)
- bitmap = self.clone
- Grayscale.call(bitmap.__id__, remove_alpha ? 1 : 0)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Emboss Effect (Destructive)
- # type : Emboss algorithm that will be used.
- # 0 : Standard
- # 1 : 45 Degree
- # 2 : Top-Left Bottom-Right
- # 3 : Intense
- # grayscale : Flag indicating if result will be grayscaled
- #-----------------------------------------------------------------------------
- def emboss!(type = 0, grayscale = false)
- Emboss.call(__id__, type, grayscale ? 1 : 0)
- end
- #-----------------------------------------------------------------------------
- # * Emboss Effect (Non-Destructive)
- # type : Emboss algorithm that will be used.
- # 0 : Standard
- # 1 : 45 Degree
- # 2 : Top-Left Bottom-Right
- # 3 : Intense
- # grayscale : Flag indicating if result will be grayscaled
- #-----------------------------------------------------------------------------
- def emboss(type = 0, grayscale = false)
- bitmap = self.clone
- Emboss.call(bitmap.__id__, type, grayscale ? 1 : 0)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Tint Bitmap Colors (Destructive)
- # red_percent : Percentage of red to increase. (0 - 100)
- # green_percent : Percentage of green to increase. (0 - 100)
- # blue_percent : Percentage of blue to increase. (0 - 100)
- #-----------------------------------------------------------------------------
- def tint!(red_percent, green_percent, blue_percent)
- Tint.call(__id__, red_percent, green_percent, blue_percent)
- end
- #-----------------------------------------------------------------------------
- # * Tint Bitmap Colors (Non-Destructive)
- # red_percent : Percentage of red to increase. (0 - 100)
- # green_percent : Percentage of green to increase. (0 - 100)
- # blue_percent : Percentage of blue to increase. (0 - 100)
- #-----------------------------------------------------------------------------
- def tint(red_percent, green_percent, blue_percent)
- bitmap = self.clone
- Tint.call(bitmap.__id__, red_percent, green_percent, blue_percent)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Bitmap Color Balance (Destructive)
- # red : Red balance component (0 - 255)
- # green : Green balance component (0 - 255)
- # blue : Blue balance component (0 - 255)
- #-----------------------------------------------------------------------------
- def color_balance!(red, green, blue)
- ColorBalance.call(__id__, red, green, blue)
- end
- #-----------------------------------------------------------------------------
- # * Bitmap Color Balance (Non-Destructive)
- # red : Red balance component (0 - 255)
- # green : Green balance component (0 - 255)
- # blue : Blue balance component (0 - 255)
- #-----------------------------------------------------------------------------
- def color_balance(red, green, blue)
- bitmap = self.clone
- ColorBalance.call(bitmap.__id__, red, green, blue)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Bitonal Bitmap (Destructive)
- # dark_color : Color used for dark tones below the threshold
- # light_color : Color used for light tones above the threshold
- # threshold : Threshold to determine light tones from dark tones
- #-----------------------------------------------------------------------------
- def bitonal!(dark_color, light_color, threshold)
- Bitonal.call(__id__, dark_color.to_i, light_color.to_i, threshold)
- end
- #-----------------------------------------------------------------------------
- # * Bitonal Bitmap (Non-Destructive)
- # dark_color : Color used for dark tones below the threshold
- # light_color : Color used for light tones above the threshold
- # threshold : Threshold to determine light tones from dark tones
- #-----------------------------------------------------------------------------
- def bitonal(dark_color, light_color, threshold)
- bitmap = self.clone
- Bitonal.call(bitmap.__id__, dark_color.to_i, light_color.to_i, threshold)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Apply Solarise Effect (Destructive)
- # red : Red threshold value (0 - 255)
- # green : Green threshold value (0 - 255)
- # blue : Blue threshold value (0 - 255)
- #-----------------------------------------------------------------------------
- def solarise!(red, green, blue)
- Solarise.call(__id__, red, green, blue)
- end
- #-----------------------------------------------------------------------------
- # * Apply Solarise Effect (Non-Destructive)
- # red : Red threshold value (0 - 255)
- # green : Green threshold value (0 - 255)
- # blue : Blue threshold value (0 - 255)
- #-----------------------------------------------------------------------------
- def solarise(red, green, blue)
- bitmap = self.clone
- Solarise.call(bitmap.__id__, red, green, blue)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Median Filter Effect (Destructive)
- # matrix_size : Size of the matrix used to calculate pixels
- # bias : Amount of bias to apply to the colors
- # grayscale : Flag indicating if result will be grayscaled
- #-----------------------------------------------------------------------------
- def median_filter!(matrix_size = 3, bias = 0, grayscale = false)
- MedianFilter.call(__id__, matrix_size, bias, grayscale ? 1 : 0)
- end
- #-----------------------------------------------------------------------------
- # * Median Filter Effect (Non-Destructive)
- # matrix_size : Size of the matrix used to calculate pixels
- # bias : Amount of bias to apply to the colors
- # grayscale : Flag indicating if result will be grayscaled
- #-----------------------------------------------------------------------------
- def median_filter(matrix_size = 3, bias = 0, grayscale = false)
- bitmap = self.clone
- MedianFilter.call(bitmap.__id__, matrix_size, bias, grayscale ? 1 : 0)
- return bitmap
- end
- #-----------------------------------------------------------------------------
- # * Rotate and/or Flip Bitmap (Destructive)
- # type : 0: Rotate180FlipXY or RotateNoneFlipNone
- # 1: Rotate270FlipXY or Rotate90FlipNone
- # 2: RotateNoneFlipXY or Rotate180FlipNone
- # 3: Rotate90FlipXY or Rotate270FlipNone
- # 4: Rotate180FlipY or RotateNoneFlipX
- # 5: Rotate90FlipX or Rotate270FlipY
- # 6: RotateNoneFlipY or Rotate180FlipX
- # 7: Rotate90FlipY or Rotate270FlipX
- #-----------------------------------------------------------------------------
- def rotate_flip!(type)
- RotateFlip.call(__id__, type)
- end
- #-----------------------------------------------------------------------------
- # * Rotate and/or Flip Bitmap (Non-Destructive)
- # type : 0: Rotate180FlipXY or RotateNoneFlipNone
- # 1: Rotate270FlipXY or Rotate90FlipNone
- # 2: RotateNoneFlipXY or Rotate180FlipNone
- # 3: Rotate90FlipXY or Rotate270FlipNone
- # 4: Rotate180FlipY or RotateNoneFlipX
- # 5: Rotate90FlipX or Rotate270FlipY
- # 6: RotateNoneFlipY or Rotate180FlipX
- # 7: Rotate90FlipY or Rotate270FlipX
- #-----------------------------------------------------------------------------
- def rotate_flip(type)
- bitmap = self.clone
- RotateFlip.call(bitmap.__id__, type)
- return bitmap
- end
- end
- #===============================================================================
- # ** Graphics
- #-------------------------------------------------------------------------------
- # The module that carries out graphics processing.
- #===============================================================================
- module Graphics
- #-----------------------------------------------------------------------------
- # * Width of window client area
- #-----------------------------------------------------------------------------
- def self.width
- return RpgNET.get_window_rect.width
- end
- #-----------------------------------------------------------------------------
- # * Height of window client area
- #-----------------------------------------------------------------------------
- def self.height
- return RpgNET.get_window_rect.height
- end
- end
- #===============================================================================
- # ** Sprite
- #-------------------------------------------------------------------------------
- # Sprites are the basic concept used to display on the game screen.
- #===============================================================================
- class Sprite
- #-----------------------------------------------------------------------------
- # * Constants
- #-----------------------------------------------------------------------------
- CreateEffect = Win32API.new(RPGNET, 'CreateSpriteEffect', 'iiip', '')
- UpdateEffect = Win32API.new(RPGNET, 'UpdateSpriteEffect', 'ii', '')
- #-----------------------------------------------------------------------------
- # * Shrink
- # frames : Number of frames effect will last
- #-----------------------------------------------------------------------------
- def shrink(frames = 20)
- return if @effect_frame != nil
- self.bitmap = self.bitmap.clone
- @effect_frame = frames
- CreateEffect.call(self.bitmap.__id__, 1, frames, '')
- end
- #-----------------------------------------------------------------------------
- # * Hue Rotation
- # frames : Number of frames effect will last
- # speed : Amount of hue change each step
- # fade : Flag indicating if sprite will fade out
- #-----------------------------------------------------------------------------
- def hue_effect(frames = 60, speed = 8, fade = false)
- return if @effect_frame != nil
- self.bitmap = self.bitmap.clone
- @effect_frame = frames
- CreateEffect.call(self.bitmap.__id__, 2, frames, [speed, fade].join(','))
- end
- #-----------------------------------------------------------------------------
- # * Flatten
- # frames : Number of frames effect will last
- # direction : Direction of effect, 0:Up, 1:Down
- #-----------------------------------------------------------------------------
- def flatten(frames = 10, direction = 0)
- return if @effect_frame != nil
- self.bitmap = self.bitmap.clone
- @effect_frame = frames
- CreateEffect.call(self.bitmap.__id__, 3, frames, direction.to_s)
- end
- #-----------------------------------------------------------------------------
- # * Flatten
- # frames : Number of frames effect will last
- # direction : Direction of effect, 0:Horizontal, 1:Vertical
- #-----------------------------------------------------------------------------
- def squeeze(frames = 5, direction = 0)
- return if @effect_frame != nil
- self.bitmap = self.bitmap.clone
- @effect_frame = frames
- CreateEffect.call(self.bitmap.__id__, 4, frames, direction.to_s)
- end
- #-----------------------------------------------------------------------------
- # * Frame Update
- #-----------------------------------------------------------------------------
- alias rpgnet_update update
- def update
- rpgnet_update
- if @effect_frame != nil
- UpdateEffect.call(self.bitmap.__id__, @effect_frame)
- @effect_frame -= 1
- if @effect_frame < 0
- @effect_frame = nil
- end
- end
- end
- end
- #===============================================================================
- # ** Color
- #-------------------------------------------------------------------------------
- # The RGBA color class. Each component is handled with a floating point value.
- #===============================================================================
- class Color
- #-----------------------------------------------------------------------------
- # * Integer value of Color
- #-----------------------------------------------------------------------------
- def to_i
- string = [red.to_i.chr, green.to_i.chr, blue.to_i.chr, alpha.to_i.chr].join
- return string.unpack('L').shift
- end
- end
- #===============================================================================
- # ** Gradient
- #-------------------------------------------------------------------------------
- # Represents a gradient color
- #===============================================================================
- Gradient = Struct.new(:color1, :color2, :angle)
- #===============================================================================
- # ** Gradient
- #-------------------------------------------------------------------------------
- # The font class. Font is a property of the Bitmap class.
- #===============================================================================
- class Font
- attr_accessor :gradient
- end
- #===============================================================================
- # ** RPG::AudioFile
- #-------------------------------------------------------------------------------
- # Data class for audio files. Common to all formats (BGM, BGS, ME, SE).
- #===============================================================================
- class RPG::AudioFile
- #-----------------------------------------------------------------------------
- # * Duration in Milliseconds
- #-----------------------------------------------------------------------------
- def milliseconds
- dir = File.dirname(@name)
- filename = File.basename(@name)
- path = RpgNET.get_full_path(filename, dir)
- return Audio::GetAudioDurationMs.call(path)
- end
- #-----------------------------------------------------------------------------
- # * Duration in Frames
- # frame_rate : Frame rate to calculate number of frames for.
- #-----------------------------------------------------------------------------
- def frame_duration(frame_rate)
- return milliseconds / frame_rate
- end
- end
- #===============================================================================
- # ** Vector
- #-------------------------------------------------------------------------------
- # This struct represents magnitude (length) and direction.
- #===============================================================================
- Vector = Struct.new(:x, :y, :z)
- #===============================================================================
- # ** ParticleGenerator
- #-------------------------------------------------------------------------------
- # This class acts as a wrapper around an Rpg.NET ParticleGenerator.
- #===============================================================================
- class ParticleGenerator < Sprite
- #-----------------------------------------------------------------------------
- # * Particle Types
- #-----------------------------------------------------------------------------
- FOUNTAIN = 0x01
- FIREWORK = 0x02
- EXPLOSION = 0x03
- #-----------------------------------------------------------------------------
- # * Constants
- #-----------------------------------------------------------------------------
- Initialize = Win32API.new(RPGNET, 'PgInitialize', 'ii', '')
- SetEnabled = Win32API.new(RPGNET, 'PgSetEnabled', 'ii', '')
- SetEnvironment = Win32API.new(RPGNET, 'PgSetEnvironment', 'ipp', '')
- SetSpeed = Win32API.new(RPGNET, 'PgSetSpeed', 'ii', '')
- SetParticles = Win32API.new(RPGNET, 'PgSetParticles', 'iii', '')
- SetColors = Win32API.new(RPGNET, 'PgSetColors', 'ip', '')
- GetRegenerate = Win32API.new(RPGNET, 'PgGetRegenerate', 'i', '')
- SetRegenerate = Win32API.new(RPGNET, 'PgSetRegenerate', 'ii', '')
- Dispose = Win32API.new(RPGNET, 'PgDispose', 'i', '')
- #-----------------------------------------------------------------------------
- # * Public Instance Variables
- #-----------------------------------------------------------------------------
- attr_reader :enabled
- attr_reader :gravity
- attr_reader :wind
- attr_reader :max_particles
- attr_reader :life_span
- attr_reader :type
- attr_reader :colors
- #-----------------------------------------------------------------------------
- # * Object Initialization
- #-----------------------------------------------------------------------------
- def initialize(viewport, width, height, type)
- super(viewport)
- self.bitmap = Bitmap.new(width, height)
- @id = self.bitmap.__id__
- @type = type
- @wind = Vector.new(0.002, 0.0, 0.0)
- @gravity = Vector.new(0.0, -0.02, 0.0)
- @speed = 20
- @life_span = 150
- @max_particles = 250
- Initialize.call(@id, @type)
- end
- #-----------------------------------------------------------------------------
- # * Width of the Particle Generator
- #-----------------------------------------------------------------------------
- def width
- return self.bitmap.width
- end
- #-----------------------------------------------------------------------------
- # * Height of the Particle Generator
- #-----------------------------------------------------------------------------
- def height
- return self.bitmap.height
- end
- #-----------------------------------------------------------------------------
- # * Start/Stop Particle Generation
- # value : Flag indicating if generator is enabled or not
- #-----------------------------------------------------------------------------
- def enabled=(value)
- if @enabled != value
- @enabled = value
- SetEnabled.call(@id, @enabled ? 1 : 0)
- end
- end
- #-----------------------------------------------------------------------------
- # * Get Regenerate Flag
- #-----------------------------------------------------------------------------
- def regenerate
- return GetRegenerate.call(@id)
- end
- #-----------------------------------------------------------------------------
- # * Set Regenerate Flag
- # value : Flag indicating if generator regenerates after executing
- #-----------------------------------------------------------------------------
- def regenerate=(value)
- SetRegenerate.call(@id, value ? 1 : 0)
- end
- #-----------------------------------------------------------------------------
- # * Set Particle Environment
- # wind : Vector representing wind factor
- # gravity : Vector representing gravity factor
- #-----------------------------------------------------------------------------
- def set_environment(wind, gravity)
- if (@wind != wind) || (@gravity != gravity)
- @wind = wind
- @gravity = gravity
- wind = [@wind.x, @wind.y, @wind.z].join(',')
- gravity = [@gravity.x, @gravity.y, @gravity.z].join(',')
- SetEnvironment.call(@id, wind, gravity)
- end
- end
- #-----------------------------------------------------------------------------
- # * Set Particle Generator Speed
- # value : Speed, in milliseconds, between updates
- #-----------------------------------------------------------------------------
- def speed=(value)
- if @speed != speed
- @speed = [speed, 4].max
- SetSpeed.call(@id, @speed)
- end
- end
- #-----------------------------------------------------------------------------
- # * Set Particle Settings
- # max_particles : Maximum number of particles created at one time
- # life_span : Duration of time a particle will last
- #-----------------------------------------------------------------------------
- def set_particles(max_particles, life_span)
- if (@max_particles != max_particles) || (@life_span != life_span)
- @max_particles = [max_particles, 1].max
- @life_span = [life_span, 1].max
- SetParticles.call(@id, @max_particles, @life_span)
- end
- end
- #-----------------------------------------------------------------------------
- # * Dispose
- #-----------------------------------------------------------------------------
- alias base_dispose dispose
- def dispose
- Dispose.call(@id)
- base_dispose
- end
- #-----------------------------------------------------------------------------
- # * Set Color(s) used for Particles
- # colors : One or more colors
- #-----------------------------------------------------------------------------
- def set_colors(*colors)
- if @colors != colors
- @colors = colors
- if @colors.size == 0
- @colors.push(Color.new(0, 0, 0, 0))
- end
- colors = @colors.collect {|c| c.to_i }
- SetColors.call(@id, colors.join(','))
- end
- end
- end
- #===============================================================================
- # ** Input
- #-------------------------------------------------------------------------------
- # A module that handles input data from a gamepad or keyboard.
- #===============================================================================
- module Input
- #-----------------------------------------------------------------------------
- # * Virtual Keys
- #-----------------------------------------------------------------------------
- Key = { 'NONE' => 0, 'LBUTTON' => 1, 'RBUTTON' => 2, 'CANCEL' => 3,
- 'MBUTTON' => 4, 'XBUTTON1' => 5, 'XBUTTON2' => 6, 'BACK' => 8, 'TAB' => 9,
- 'LINEFEED' => 10, 'CLEAR' => 12, 'RETURN' => 13, 'ENTER' => 13,
- 'SHIFTKEY' => 16, 'CONTROLKEY' => 17, 'MENU' => 18, 'PAUSE' => 19,
- 'CAPITAL' => 20, 'CAPSLOCK' => 20, 'KANAMODE' => 21, 'HANGULMODE' => 21,
- 'HANGUELMODE' => 21, 'JUNJAMODE' => 23, 'FINALMODE' => 24,'HANJAMODE' => 25,
- 'KANJIMODE' => 25, 'ESCAPE' => 27, 'IMECONVERT' => 28,'IMENONCONVERT' => 29,
- 'IMEACCEPT' => 30, 'IMEMODECHANGE' => 31, 'SPACE' => 32, 'PAGEUP' => 33,
- 'PRIOR' => 33, 'PAGEDOWN' => 34, 'NEXT' => 34, 'END' => 35, 'HOME' => 36,
- 'LEFT' => 37, 'UP' => 38, 'RIGHT' => 39, 'DOWN' => 40, 'SELECT' => 41,
- 'PRINT' => 42, 'EXECUTE' => 43, 'SNAPSHOT' => 44, 'PRINTSCREEN' => 44,
- 'INSERT' => 45, 'DELETE' => 46, 'HELP' => 47, 'D0' => 48, 'D1' => 49,
- 'D2' => 50, 'D3' => 51, 'D4' => 52, 'D5' => 53, 'D6' => 54, 'D7' => 55,
- 'D8' => 56, 'D9' => 57, 'A' => 65, 'B' => 66, 'C' => 67, 'D' => 68,
- 'E' => 69, 'F' => 70, 'G' => 71, 'H' => 72, 'I' => 73, 'J' => 74, 'K' => 75,
- 'L' => 76, 'M' => 77, 'N' => 78, 'O' => 79, 'P' => 80, 'Q' => 81, 'R' => 82,
- 'S' => 83, 'T' => 84, 'U' => 85, 'V' => 86, 'W' => 87, 'X' => 88, 'Y' => 89,
- 'Z' => 90, 'LWIN' => 91, 'RWIN' => 92, 'APPS' => 93, 'SLEEP' => 95,
- 'NUMPAD0' => 96, 'NUMPAD1' => 97, 'NUMPAD2' => 98, 'NUMPAD3' => 99,
- 'NUMPAD4' => 100, 'NUMPAD5' => 101, 'NUMPAD6' => 102, 'NUMPAD7' => 103,
- 'NUMPAD8' => 104, 'NUMPAD9' => 105, 'MULTIPLY' => 106, 'ADD' => 107,
- 'SEPARATOR' => 108, 'SUBTRACT' => 109, 'DECIMAL' => 110, 'DIVIDE' => 111,
- 'F1' => 112, 'F2' => 113, 'F3' => 114, 'F4' => 115, 'F5' => 116,'F6' => 117,
- 'F7' => 118, 'F8' => 119, 'F9' => 120, 'F10' => 121, 'F11' => 122,
- 'F12' => 123, 'F13' => 124, 'F14' => 125, 'F15' => 126, 'F16' => 127,
- 'F17' => 128, 'F18' => 129, 'F19' => 130, 'F20' => 131, 'F21' => 132,
- 'F22' => 133, 'F23' => 134, 'F24' => 135, 'NUMLOCK' => 144, 'SCROLL' => 145,
- 'LSHIFTKEY' => 160, 'RSHIFTKEY' => 161, 'LCONTROLKEY' => 162,
- 'RCONTROLKEY' => 163, 'LMENU' => 164, 'RMENU' => 165, 'BROWSERBACK' => 166,
- 'BROWSERFORWARD' => 167, 'BROWSERREFRESH' => 168, 'BROWSERSTOP' => 169,
- 'BROWSERSEARCH' => 170, 'BROWSERFAVORITES' => 171, 'BROWSERHOME' => 172,
- 'VOLUMEMUTE' => 173, 'VOLUMEDOWN' => 174, 'VOLUMEUP' => 175,
- 'MEDIANEXTTRACK' => 176, 'MEDIAPREVIOUSTRACK' => 177, 'MEDIASTOP' => 178,
- 'MEDIAPLAYPAUSE' => 179, 'LAUNCHMAIL' => 180, 'SELECTMEDIA' => 181,
- 'LAUNCHAPPLICATION1' => 182, 'LAUNCHAPPLICATION2' => 183, 'OEM_1' => 186,
- 'OEMSEMICOLON' => 186, 'OEMPLUS' => 187, 'OEMCOMMA' => 188,'OEMMINUS' => 189,
- 'OEMPERIOD' => 190, 'SLASH' => 191, 'OEM2' => 191, 'OEM3' => 192,
- 'OEMTILDE' => 192, 'LBRACKET' => 219, 'OEM4' => 219, 'OEM5' => 220,
- 'OEMPIPE' => 220, 'RBRACKET' => 221, 'OEM6' => 221, 'OEM7' => 222,
- 'OEMQUOTES' => 222, 'OEM8' => 223, 'BACKSLASH' => 226, 'OEM102' => 226,
- 'PROCESSKEY' => 229, 'PACKET' => 231, 'ATTN' => 246, 'CRSEL' => 247,
- 'EXSEL' => 248, 'ERASEEOF' => 249, 'PLAY' => 250, 'ZOOM' => 251,
- 'NONAME' => 252, 'PA1' => 253, 'OEMCLEAR' => 254, 'KEYCODE' => 65535,
- 'SHIFT' => 65536, 'CONTROL' => 131072,'ALT' => 262144, 'MODIFIERS' => -65536
- }
- #-----------------------------------------------------------------------------
- # * Key Configuration
- #-----------------------------------------------------------------------------
- UP = [Key['UP']]
- LEFT = [Key['LEFT']]
- DOWN = [Key['DOWN']]
- RIGHT = [Key['RIGHT']]
- A = [Key['SHIFT']]
- B = [Key['ESCAPE'], Key['NUMPAD0'], Key['X']]
- C = [Key['SPACE'], Key['ENTER'], Key['C']]
- X = [Key['A']]
- Y = [Key['S']]
- Z = [Key['D']]
- L = [Key['Q'], Key['PAGEDOWN']]
- R = [Key['W'], Key['PAGEUP']]
- F5 = [Key['F5']]
- F6 = [Key['F6']]
- F7 = [Key['F7']]
- F8 = [Key['F8']]
- F9 = [Key['F9']]
- SHIFT = [Key['SHIFT']]
- CTRL = [Key['CONTROL']]
- ALT = [Key['ALT']]
- LMOUSE = [Key['LBUTTON']]
- RMOUSE = [Key['RBUTTON']]
- MMOUSE = [Key['MBUTTON']]
- #-----------------------------------------------------------------------------
- # * Constants
- #-----------------------------------------------------------------------------
- Update = Win32API.new(RPGNET, 'InputUpdate', '', '')
- IsTriggered = Win32API.new(RPGNET, 'InputIsTriggered', 'i', 'i')
- IsPressed = Win32API.new(RPGNET, 'InputIsPressed', 'i', 'i')
- IsRepeated = Win32API.new(RPGNET, 'InputIsRepeated', 'i', 'i')
- IsReleased = Win32API.new(RPGNET, 'InputIsReleased', 'i', 'i')
- BeginCapture = Win32API.new(RPGNET, 'InputBeginCapture', '', '')
- EndCapture = Win32API.new(RPGNET, 'InputEndCapture', '', 'p')
- MousePosition = Win32API.new(RPGNET, 'InputMousePosition', 'p', '')
- IsDoubleClick = Win32API.new(RPGNET, 'InputIsDoubleClick', 'i', 'i')
- IsMouseMoving = Win32API.new(RPGNET, 'InputIsMouseMoved', '', 'i')
- IsWheelMoved = Win32API.new(RPGNET, 'InputIsWheelMoved', '', 'i')
- GetWheelDelta = Win32API.new(RPGNET, 'InputGetWheelDelta', '', 'i')
- #-----------------------------------------------------------------------------
- # * Frame Update
- #-----------------------------------------------------------------------------
- def self.update
- Update.call
- end
- #-----------------------------------------------------------------------------
- # * Key Triggered
- # key : Key constant to test
- #-----------------------------------------------------------------------------
- def self.trigger?(key)
- return IsTriggered.call(key) if key.is_a?(Fixnum)
- return key.any? {|k| IsTriggered.call(k) != 0 }
- end
- #-----------------------------------------------------------------------------
- # * Key Pressed
- # key : Key constant to test
- #-----------------------------------------------------------------------------
- def self.press?(key)
- return IsPressed.call(key) if key.is_a?(Fixnum)
- return key.any? {|k| IsPressed.call(k) != 0 }
- end
- #-----------------------------------------------------------------------------
- # * Key Repeated
- # key : Key constant to test
- #-----------------------------------------------------------------------------
- def self.repeat?(key)
- return IsRepeated.call(key) if key.is_a?(Fixnum)
- return key.any? {|k| IsRepeated.call(k) != 0 }
- end
- #-----------------------------------------------------------------------------
- # * Key Released
- # key : Key constant to test
- #-----------------------------------------------------------------------------
- def self.release?(key)
- return IsReleased.call(key) if key.is_a?(Fixnum)
- return key.any? {|k| IsReleased.call(k) != 0 }
- end
- #-----------------------------------------------------------------------------
- # * Mouse Double-Click
- # key : Key constant to test
- #-----------------------------------------------------------------------------
- def self.dbl_click?(key)
- return IsDoubleClick.call(key) if key.is_a?(Fixnum)
- return key.any? {|k| IsDoubleClick.call(k) != 0 }
- end
- #-----------------------------------------------------------------------------
- # * Begin Key Logging
- #-----------------------------------------------------------------------------
- def self.begin_capture
- BeginCapture.call
- end
- #-----------------------------------------------------------------------------
- # * End Key Logging and Get String
- #-----------------------------------------------------------------------------
- def self.end_capture
- return EndCapture.call
- end
- #-----------------------------------------------------------------------------
- # * Current Mouse Position
- #-----------------------------------------------------------------------------
- def self.mouse_pos
- point = [0, 0].pack('ii')
- MousePosition.call(point)
- # Return mouse coordinates as two element array: [X, Y]
- return point.unpack('ii')
- end
- #-----------------------------------------------------------------------------
- # * Mouse is Moving
- #-----------------------------------------------------------------------------
- def self.mouse_moving?
- return IsMouseMoving.call != 0
- end
- #-----------------------------------------------------------------------------
- # * Mouse Wheel is Moving
- #-----------------------------------------------------------------------------
- def self.mouse_wheel?
- return IsWheelMoved.call != 0
- end
- #-----------------------------------------------------------------------------
- # * Mouse Wheel Amount
- #-----------------------------------------------------------------------------
- def self.wheel_delta
- return GetWheelDelta.call / 120
- end
- #-----------------------------------------------------------------------------
- # * Four Direction Check
- #-----------------------------------------------------------------------------
- def self.dir4
- return 2 if self.press?(DOWN)
- return 4 if self.press?(LEFT)
- return 6 if self.press?(RIGHT)
- return 8 if self.press?(UP)
- return 0
- end
- #-----------------------------------------------------------------------------
- # * Eight Direction Check
- #-----------------------------------------------------------------------------
- def self.dir8
- down = self.press?(DOWN)
- left = self.press?(LEFT)
- return 1 if down && left
- right = self.press?(RIGHT)
- return 3 if down && right
- up = self.press?(UP)
- return 7 if up && left
- return 9 if up && right
- return 2 if down
- return 4 if left
- return 6 if right
- return 8 if up
- return 0
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement