Advertisement
ForeverZer0

[XP][VX][VXA] Rpg.NET Wrapper

Jul 30th, 2014
1,867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 75.80 KB | None | 0 0
  1. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  2. # Rpg.NET Wrapper
  3. # Author: ForeverZer0
  4. # Version: 0.28A
  5. # Date: 7.30.2014
  6. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  7. #                             VERSION HISTORY
  8. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  9. # - Developer Release, no history until full public release.
  10. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  11. #
  12. # Introduction:
  13. #
  14. #   Rpg.NET is an API built using the .NET Framework for both improving
  15. #   performance and enhancing the RPG Maker series (XP, VX, and VXA). Contained
  16. #   within are various functions and classes that extend the ability of RPG
  17. #   Maker in areas such as graphics, audio, and Windows API interop. Included is
  18. #   a Ruby script that is the wrapper around the library, so it can be used as
  19. #   any other script within your game.
  20. #
  21. # Features:
  22. #
  23. #   A whole bunch, and growing. Will update this for full release.
  24. #
  25. # Instructions:
  26. #
  27. #   - Place Rpg.NET.dll in your game folder
  28. #   - If renaming, update RPGNET constant below
  29. #
  30. # Compatibility:
  31. #
  32. #   - RPG Maker XP, VX, and VXA
  33. #   - Rpg.NET Input Module is likely not compatible with other Input scripts
  34. #   - No know compatibility issues with other scripts.
  35. #
  36. # Credits/Thanks:
  37. #
  38. #   - ForeverZer0, for the script
  39. #
  40. # Authors Notes:
  41. #
  42. #   - This is NOT A FINAL RELEASE, and it is advised not to distribute with your
  43. #     game as such. It is not fully tested, not complete, so various bugs may
  44. #     yet be found.
  45. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  46.  
  47. #===============================================================================
  48. # ** RpgNET
  49. #-------------------------------------------------------------------------------
  50. # Module wrapper for Rpg.NET utility functions.
  51. #===============================================================================
  52.  
  53. # Relative name and path of the Rpg.NET library.
  54. RPGNET = 'Rpg.NET.dll'
  55.  
  56. module RpgNET
  57.   #-----------------------------------------------------------------------------
  58.   # * Constants
  59.   #-----------------------------------------------------------------------------
  60.   CopyGameWindow = Win32API.new(RPGNET, 'BmCopyGameWindow', 'ii', '')
  61.   GetWindowRect = Win32API.new(RPGNET, 'GetWindowRect', 'pi', '')
  62.   OpenFileDlg = Win32API.new(RPGNET, 'OpenFileDlg', 'p', 'p')
  63.   RgssEval = Win32API.new(RPGNET, 'RgssEval', 'p', '')
  64.   ShowScriptWindow = Win32API.new(RPGNET, 'ShowScriptWindow', '', '')
  65.   #-----------------------------------------------------------------------------
  66.   # * Initialize Rpg.NET Core
  67.   #-----------------------------------------------------------------------------
  68.   def self.initialize
  69.     version = 0
  70.     if RUBY_VERSION == '1.8.1'
  71.       version = defined?(Hangup) ? 1 : 2
  72.     elsif RUBY_VERSION == '1.9.2'
  73.       version = 4
  74.     end
  75.     Win32API.new(RPGNET, 'Initialize', 'i', '').call(version)
  76.   end
  77.   #-----------------------------------------------------------------------------
  78.   # * Open Script Window
  79.   #-----------------------------------------------------------------------------
  80.   def self.show_script_window
  81.     ShowScriptWindow.call
  82.   end
  83.   #-----------------------------------------------------------------------------
  84.   # * Send Message to Rpg.NET Core  
  85.   #     code : Code to evaluate within the RGSS scope and return
  86.   #
  87.   #                      ** INTERNAL USE ONLY ***
  88.   #-----------------------------------------------------------------------------
  89.   def self.send_message(code)
  90.     begin
  91.       result = eval(code)
  92.       unless result.is_a?(String)
  93.         result = result.to_s
  94.       end
  95.       RgssEval.call(result)
  96.     rescue
  97.       RgssEval.call('')
  98.     end
  99.   end  
  100.   #-----------------------------------------------------------------------------
  101.   # * Show Open File Dialog
  102.   #     filter : Filter to determine available files to open.
  103.   #-----------------------------------------------------------------------------
  104.   def self.open_file_dialog(filter = 'All Files|*.*')
  105.     return OpenFileDlg.call(filter)
  106.   end
  107.   #-----------------------------------------------------------------------------
  108.   # * Get Full Path to Local/RTP Resource
  109.   #     filename  : Filename to search for, without extension
  110.   #     subfolder : Relative subfolder where file is located
  111.   #-----------------------------------------------------------------------------
  112.   def self.get_full_path(filename, subfolder)
  113.     api = Win32API.new(RPGNET, 'GetFullPath', 'pp', 'p')
  114.     return api.call(filename, subfolder)
  115.   end
  116.   #-----------------------------------------------------------------------------
  117.   # * Show Console Output Window
  118.   #-----------------------------------------------------------------------------
  119.   def self.show_console
  120.     Win32API.new(RPGNET, 'ShowConsole', '', '').call
  121.   end
  122.   #-----------------------------------------------------------------------------
  123.   # * Hide Console Output Window
  124.   #-----------------------------------------------------------------------------
  125.   def self.hide_console
  126.     # TODO: Implement
  127.   end
  128.   #-----------------------------------------------------------------------------
  129.   # * Get RTP Path
  130.   #     index : Index of the RTP whose path to retrieve (XP Only)
  131.   #-----------------------------------------------------------------------------
  132.   def self.get_rtp_path(index = 0)
  133.     return Win32API.new(RPGNET, 'GetRtpPath', 'i', 'p').call(index)
  134.   end
  135.   #-----------------------------------------------------------------------------
  136.   # * Set Window Resolution
  137.   #     width  : Width of the new client area of the window to set
  138.   #     height : Height of the new client area of the window to set
  139.   #-----------------------------------------------------------------------------
  140.   def self.set_resolution(width, height)
  141.     Win32API.new(RPGNET, 'SetResolution', 'ii', '').call(width, height)
  142.   end
  143.   #-----------------------------------------------------------------------------
  144.   # * Set Window Icon
  145.   #     icon : Bitmap to use as window icon, or file to a image or *.ico file.
  146.   #            Bitmaps must be either 48x48, 128x128, or 256x256.
  147.   #-----------------------------------------------------------------------------
  148.   def self.set_window_icon(icon)
  149.     if icon.is_a?(String)
  150.       Win32API.new(RPGNET, 'SetIconFile', 'p', '').call(icon)
  151.     elsif icon.is_a?(Bitmap)
  152.       Win32API.new(RPGNET, 'SetIconBitmap', 'i', '').call(icon.__id__)
  153.     end
  154.   end
  155.   #-----------------------------------------------------------------------------
  156.   # * Get Window Rectangle
  157.   #     frame : Flag indiciating if window frame will be included in rectangle
  158.   #-----------------------------------------------------------------------------
  159.   def self.get_window_rect(frame = false)
  160.     rect = [0, 0, 0, 0].pack('l4')
  161.     GetWindowRect.call(rect, frame ? 1 : 0)
  162.     return Rect.new(*rect.unpack('l4'))
  163.   end
  164.   #-----------------------------------------------------------------------------
  165.   # * Get Screenshot
  166.   #     frame : Flag indiciating if window frame will be included in image.
  167.   #-----------------------------------------------------------------------------
  168.   def self.window_bitmap(frame = false)
  169.     rect = [0, 0, 0, 0].pack('l4')
  170.     GetWindowRect.call(rect, frame ? 1 : 0)
  171.     x, y, w, h = rect.unpack('l4')
  172.     bitmap = Bitmap.new(w, h)
  173.     CopyGameWindow.call(bitmap.__id__, frame ? 1 : 0)
  174.     return bitmap
  175.   end
  176.   #-----------------------------------------------------------------------------
  177.   # * Save Screenshot
  178.   #     filename : Path where image will be saved. (*.jpg, *.png, *.bmp, *.gif)
  179.   #     frame    : Flag indiciating if window frame will be included in image.
  180.   #-----------------------------------------------------------------------------
  181.   def self.screenshot(filename, frame = false)
  182.     screen = self.window_bitmap(frame)
  183.     screen.save(filename)
  184.     screen.dispose
  185.   end
  186. end
  187.  
  188. ################################################################################
  189. #              DO NOT REMOVE! REQUIRED FOR LIBRARY TO WORK!
  190. ################################################################################
  191.                           RpgNET.initialize
  192. ################################################################################
  193. #              DO NOT REMOVE! REQUIRED FOR LIBRARY TO WORK!
  194. ################################################################################
  195.  
  196. #===============================================================================
  197. # ** Bitmap
  198. #-------------------------------------------------------------------------------
  199. # The bitmap class. Bitmaps are expressions of so-called graphics.
  200. #===============================================================================
  201.  
  202. class Bitmap
  203.   #-----------------------------------------------------------------------------
  204.   # * Constants
  205.   #-----------------------------------------------------------------------------
  206.   Save = Win32API.new(RPGNET, 'BmSave', 'ip', '')
  207.   Filter = Win32API.new(RPGNET, 'BmFilter', 'iiiiii', '')
  208.   Load = Win32API.new(RPGNET, 'BmLoad', 'pp', '')
  209.   GetLoaded = Win32API.new(RPGNET, 'BmGetLoaded', 'i', '') # lol
  210.   DrawArc = Win32API.new(RPGNET, 'BmDrawArc', 'iiiiiiiii', '')
  211.   DrawBezier = Win32API.new(RPGNET, 'BmDrawBezier', 'iiiiiiiiii', '')
  212.   DrawBeziers = Win32API.new(RPGNET, 'BmDrawBezier', 'iip', '')
  213.   DrawClosedCurve = Win32API.new(RPGNET, 'BmDrawClosedCurve', 'iiipp', '')
  214.   DrawCurve = Win32API.new(RPGNET, 'BmDrawCurve', 'iiiipp', '')
  215.   DrawEllipse = Win32API.new(RPGNET, 'BmDrawEllipse', 'iiiiiii', '')
  216.   DrawLine = Win32API.new(RPGNET, 'BmDrawLine', 'iiiiiii', '')
  217.   DrawLines = Win32API.new(RPGNET, 'BmDrawLine', 'iiip', '')
  218.   DrawPolygon = Win32API.new(RPGNET, 'BmDrawPolygon', 'iiip', '')
  219.   DrawPie = Win32API.new(RPGNET, 'BmDrawPie', 'iiiiiiiii', '')
  220.   FillClosedCurve = Win32API.new(RPGNET, 'BmFillClosedCurve', 'iipp', '')
  221.   FillEllipse = Win32API.new(RPGNET, 'BmFillEllipse', 'iiiiii', '')
  222.   FillPie = Win32API.new(RPGNET, 'BmFillPie', 'iiiiiiii', '')
  223.   FillPolygon = Win32API.new(RPGNET, 'BmFillPolygon', 'iip', '')
  224.   FillGradientRect = Win32API.new(RPGNET, 'BmFillGradientRect', 'iiiiiiip', '')
  225.   FillGradientEllipse = Win32API.new(RPGNET, 'BmFillGradientEllipse', 'iiiiiiip', '')
  226.   FillGradientPolygon = Win32API.new(RPGNET, 'BmFillGradientPolygon', 'iiipp', '')
  227.   Invert = Win32API.new(RPGNET, 'BmInvert', 'ii', '')
  228.   Pixelate = Win32API.new(RPGNET, 'BmPixelate', 'iii', '')
  229.   ChangeRgba = Win32API.new(RPGNET, 'BmChangeRgba', 'iii', '')
  230.   GaussianBlur = Win32API.new(RPGNET, 'BmGaussianBlur', 'iip', '')
  231.   Blur = Win32API.new(RPGNET, 'BmBlur', 'iip', '')
  232.   Sharpen = Win32API.new(RPGNET, 'BmSharpen', 'iip', '')
  233.   Soften = Win32API.new(RPGNET, 'BmSoften', 'i', '')
  234.   EdgeDetect = Win32API.new(RPGNET, 'BmEdgeDetect', 'iii', '')
  235.   PosterEffect = Win32API.new(RPGNET, 'BmPosterEffect', 'i', '')
  236.   Sepia = Win32API.new(RPGNET, 'BmSepia', 'i', '')
  237.   HighPass = Win32API.new(RPGNET, 'BmHighPass', 'ii', '')
  238.   Grayscale = Win32API.new(RPGNET, 'BmGrayscale', 'ii', '')
  239.   Emboss = Win32API.new(RPGNET, 'BmEmboss', 'iii', '')
  240.   Tint = Win32API.new(RPGNET, 'BmTint', 'iiii', '')
  241.   ColorBalance = Win32API.new(RPGNET, 'BmColorBalance', 'iiii', '')
  242.   Bitonal = Win32API.new(RPGNET, 'BmBitonal', 'iiii', '')
  243.   Solarise = Win32API.new(RPGNET, 'BmSolarise', 'iiii', '')
  244.   MedianFilter = Win32API.new(RPGNET, 'BmMedianFilter', 'iiii', '')
  245.   DrawTextVertical = Win32API.new(RPGNET, 'BmDrawTextV', 'iiiiipipiiii', '')
  246.   DrawTextGradient = Win32API.new(RPGNET, 'BmDrawGradientText', 'iiiiipipiiiii', '')
  247.   DrawTextGradientV = Win32API.new(RPGNET, 'BmDrawGradientTextV', 'iiiiipipiiiiii', '')
  248.   ColorMask = Win32API.new(RPGNET, 'BmColorMask', 'iii', '')
  249.   Search = Win32API.new(RPGNET, 'BmSearch', 'iipp', '')
  250.   RotateFlip = Win32API.new(RPGNET, 'BmRotateFlip', 'ii', '')
  251.   #-----------------------------------------------------------------------------
  252.   # * Public Instance Variables
  253.   #-----------------------------------------------------------------------------
  254.   attr_reader :hue
  255.   attr_reader :saturation
  256.   attr_reader :contrast
  257.   attr_reader :brightness
  258.   attr_reader :gamma
  259.   attr_reader :red
  260.   attr_reader :green
  261.   attr_reader :blue
  262.   attr_reader :alpha
  263.   #-----------------------------------------------------------------------------
  264.   # * Object Initialization
  265.   #-----------------------------------------------------------------------------
  266.   alias effects_init initialize
  267.   def initialize(*args)
  268.     @hue = 0
  269.     @saturation = 100
  270.     @contrast = 100
  271.     @brightness = 100
  272.     @gamma = 100
  273.     @red = 0
  274.     @green = 0
  275.     @blue = 0
  276.     @alpha = 0
  277.     effects_init(*args)
  278.   end
  279.   #-----------------------------------------------------------------------------
  280.   # * Set Red Component Offset
  281.   #     value : Offset to apply to pixel component. (-255..255)
  282.   #-----------------------------------------------------------------------------
  283.   def red=(value)
  284.     if @red != value
  285.       @red = value
  286.       ChangeRgba.call(__id__, value, 2)
  287.     end
  288.   end
  289.   #-----------------------------------------------------------------------------
  290.   # * Set Green Component Offset
  291.   #     value : Offset to apply to pixel component. (-255..255)
  292.   #-----------------------------------------------------------------------------
  293.   def green=(value)
  294.     if @green != value
  295.       @green = value
  296.       ChangeRgba.call(__id__, value, 1)
  297.     end
  298.   end
  299.   #-----------------------------------------------------------------------------
  300.   # * Set Blue Component Offset
  301.   #     value : Offset to apply to pixel component. (-255..255)
  302.   #-----------------------------------------------------------------------------
  303.   def blue=(value)
  304.     if @blue != value
  305.       @blue = value
  306.       ChangeRgba.call(__id__, value, 0)
  307.     end
  308.   end
  309.   #-----------------------------------------------------------------------------
  310.   # * Set Alpha Component Offset
  311.   #     value : Offset to apply to pixel component. (-255..255)
  312.   #-----------------------------------------------------------------------------
  313.   def alpha=(value)
  314.     if @alpha != value
  315.       @alpha = value
  316.       ChangeRgba.call(__id__, value, 3)
  317.     end
  318.   end
  319.   #-----------------------------------------------------------------------------
  320.   # * Apply Multiple Filters (Destructive)
  321.   #     hue        : Set the hue level. (Clamped between 0 and 360)
  322.   #     saturation : Set the saturation level. (Clamped between 0 and 200)
  323.   #     brightness : Set the brightness level. (Clamped between 0 and 200)
  324.   #     contrast   : Set the contrast level. (Clamped between 1 and 400)
  325.   #     gamma      : Set the gamma level. (Clamped between 1 and 400)
  326.   #-----------------------------------------------------------------------------
  327.   def apply_filter!(hue, saturation, brightness, contrast, gamma)
  328.     @hue = [[0, hue].max, 360].min
  329.     @saturation = [[0, saturation].max, 200].min
  330.     @brightness = [[0, brightness].max, 200].min
  331.     @contrast = [[1, contrast].max, 400].min
  332.     @gamma = [[1, gamma].max, 400].min
  333.     Filter.call(__id__, @hue, @saturation, @brightness, @contrast, @gamma)
  334.   end
  335.   #-----------------------------------------------------------------------------
  336.   # * Apply Multiple Filters (Non-Destructive)
  337.   #     hue        : Set the hue level. (Clamped between 0 and 360)
  338.   #     saturation : Set the saturation level. (Clamped between 0 and 200)
  339.   #     brightness : Set the brightness level. (Clamped between 0 and 200)
  340.   #     contrast   : Set the contrast level. (Clamped between 1 and 400)
  341.   #     gamma      : Set the gamma level. (Clamped between 1 and 400)
  342.   #-----------------------------------------------------------------------------
  343.   def apply_filter(hue, saturation, brightness, contrast, gamma)
  344.     bitmap = self.clone
  345.     bitmap.apply_filter!(hue, saturation, brightness, contrast, gamma)
  346.     return bitmap
  347.   end
  348.   #-----------------------------------------------------------------------------
  349.   # * Apply Hue Filter (Destructive)
  350.   #     value : Set the hue level. (Clamped between 0 and 360)
  351.   #-----------------------------------------------------------------------------
  352.   def set_hue!(value)
  353.     @hue = [[0, value].max, 360].min
  354.     Filter.call(__id__, @hue, 100, 100, 100, 100)
  355.   end
  356.   #-----------------------------------------------------------------------------
  357.   # * Apply Hue Filter (Non-Destructive)
  358.   #     value : Set the hue level. (Clamped between 0 and 360)
  359.   #-----------------------------------------------------------------------------
  360.   def set_hue(value)
  361.     bitmap = self.clone
  362.     @hue = [[0, value].max, 360].min
  363.     Filter.call(bitmap._id__, @hue, 100, 100, 100, 100)
  364.     return bitmap
  365.   end
  366.   #-----------------------------------------------------------------------------
  367.   # * Apply Saturation Filter (Destructive)
  368.   #     value : Set the saturation level. (Clamped between 0 and 200)
  369.   #-----------------------------------------------------------------------------
  370.   def set_saturation!(value)
  371.     @saturation = [[0, value].max, 200].min
  372.     Filter.call(__id__, 0, @saturation, 100, 100, 100)
  373.   end
  374.   #-----------------------------------------------------------------------------
  375.   # * Apply Saturation Filter (Non-Destructive)
  376.   #     value : Set the saturation level. (Clamped between 0 and 200)
  377.   #-----------------------------------------------------------------------------
  378.   def set_saturation=(value)
  379.     bitmap = self.clone
  380.     @saturation = [[0, value].max, 200].min
  381.     Filter.call(bitmap.__id__, 0, @saturation, 100, 100, 100)
  382.     return bitmap
  383.   end
  384.   #-----------------------------------------------------------------------------
  385.   # * Apply Brightness Filter (Destructive)
  386.   #     value : Set the brightness level. (Clamped between 0 and 200)
  387.   #-----------------------------------------------------------------------------
  388.   def set_brightness!(value)
  389.     @brightness = [[0, value].max, 200].min
  390.     Filter.call(__id__, 0, 100, @brightness, 100, 100)
  391.   end
  392.   #-----------------------------------------------------------------------------
  393.   # * Apply Brightness Filter (Non-Destructive)
  394.   #     value : Set the brightness level. (Clamped between 0 and 200)
  395.   #-----------------------------------------------------------------------------
  396.   def set_brightness=(value)
  397.     bitmap = self.clone
  398.     @brightness = [[0, value].max, 200].min
  399.     Filter.call(bitmap.__id__, 0, 100, @brightness, 100, 100)
  400.     return bitmap
  401.   end
  402.   #-----------------------------------------------------------------------------
  403.   # * Apply Contrast Filter (Destructive)
  404.   #     value : Set the contrast level. (Clamped between 1 and 200)
  405.   #-----------------------------------------------------------------------------
  406.   def set_contrast!(value)
  407.     @contrast = [[1, value].max, 400].min
  408.     Filter.call(__id__, 0, 100, 100, @contrast, 100)
  409.   end
  410.   #-----------------------------------------------------------------------------
  411.   # * Apply Contrast Filter (Non-Destructive)
  412.   #     value : Set the contrast level. (Clamped between 1 and 200)
  413.   #-----------------------------------------------------------------------------
  414.   def set_contrast(value)
  415.     bitmap = self.clone
  416.     @contrast = [[1, value].max, 400].min
  417.     Filter.call(bitmap.__id__, 0, 100, 100, @contrast, 100)
  418.     return bitmap
  419.   end
  420.   #-----------------------------------------------------------------------------
  421.   # * Apply Gamma Filter (Destructive)
  422.   #     value : Set the gamma level. (Clamped between 1 and 400)
  423.   #-----------------------------------------------------------------------------
  424.   def set_gamma!(value)
  425.     @gamma = [[1, value].max, 400].min
  426.     Filter.call(__id__, 0, 100, 100, 100, @gamma)
  427.   end
  428.   #-----------------------------------------------------------------------------
  429.   # * Apply Gamma Filter (Non-Destructive)
  430.   #     value : Set the gamma level. (Clamped between 1 and 400)
  431.   #-----------------------------------------------------------------------------
  432.   def set_gamma(value)
  433.     bitmap = self.clone
  434.     @gamma = [[1, value].max, 400].min
  435.     Filter.call(bitmap.__id__, 0, 100, 100, 100, @gamma)
  436.     return bitmap
  437.   end
  438.   #-----------------------------------------------------------------------------
  439.   # * Save Bitmap  
  440.   #     filename : Path to file (*.jpg, *.png, *.bmp, *.gif)
  441.   #-----------------------------------------------------------------------------
  442.   def save(filename)
  443.     Save.call(__id__, filename)
  444.   end
  445.   #-----------------------------------------------------------------------------
  446.   # * Load an Image File
  447.   #     filename : Supported formats: PNG, JPG, PSD, BMP, GIF, EXIF, TIFF
  448.   #-----------------------------------------------------------------------------
  449.   def self.open(filename)
  450.     struct = [0, 0].pack('l2')  
  451.     Load.call(filename, struct)
  452.     size = struct.unpack('l2')
  453.     bitmap = Bitmap.new(size[0], size[1])
  454.     GetLoaded.call(bitmap.__id__)
  455.     return bitmap
  456.   end
  457.   #-----------------------------------------------------------------------------
  458.   # * Bitmap Contains Bitmap
  459.   #     other     : Child Bitmap to check for
  460.   #     tolerance : Amount of variance allowed in comparison (0.0 = Exact)
  461.   #-----------------------------------------------------------------------------
  462.   def include?(other, tolerance = 0.0)
  463.     rect = find(other, tolerance)
  464.     return rect.width != 0 && rect.height != 0
  465.   end
  466.   #-----------------------------------------------------------------------------
  467.   # * Find Rect of Child Bitmap
  468.   #     other     : Child Bitmap to check for
  469.   #     tolerance : Amount of variance allowed in comparison (0.0 = Exact)
  470.   #-----------------------------------------------------------------------------
  471.   def find(bitmap, tolerance = 0.0)
  472.     rect = [0, 0, 0, 0].pack('l4')
  473.     Search.call(bitmap.__id__, __id__, tolerance.to_s, rect)
  474.     rect = rect.unpack('l4')
  475.     return Rect.new(*rect)
  476.   end
  477.   #-----------------------------------------------------------------------------
  478.   # * Draw Text Vertical
  479.   #     x         : x-coordinate of text
  480.   #     y         : y-coordinate of text
  481.   #     width     : Width of area to draw. Text will be centered horizontally.
  482.   #     height    : Height of area to draw text.
  483.   #     text      : String to draw.
  484.   #     align     : Text justificatiion. 0 = Left, 1 = Center, 2 = Right
  485.   #     direction : Text direction. 0 = Left, 1 = Right
  486.   #-----------------------------------------------------------------------------
  487.   def draw_text_vertical(x, y, width, height, text, align = 0, direction = 0)
  488.     style = 0
  489.     style |= 1 if self.font.bold
  490.     style |= 2 if self.font.italic
  491.     DrawTextVertical.call(__id__, x, y, width, height, text, align,
  492.       self.font.name, self.font.color.to_i, self.font.size, style, direction)
  493.   end
  494.    
  495.  
  496.   def draw_gradient_text(x, y, width, height, text, align = 0)
  497.     if self.font.gradient.nil?
  498.       white = Color.new(255, 255, 255)
  499.       self.font.gradient = Gradient.new(self.font.color, white, 90)
  500.     end
  501.     style = 0
  502.     style |= 1 if self.font.bold
  503.     style |= 2 if self.font.italic
  504.     g = self.font.gradient
  505.     DrawTextGradient.call(__id__, x, y, width, height, text, align,
  506.       self.font.name, g.color1.to_i, g.color2.to_i, g.angle, self.font.size, style)
  507.   end
  508.    
  509.    
  510.   def draw_gradient_text_vertical(x, y, width, height, text, align = 0, direction = 0)
  511.     if self.font.gradient.nil?
  512.       white = Color.new(255, 255, 255)
  513.       self.font.gradient = Gradient.new(self.font.color, white, 90)
  514.     end
  515.     style = 0
  516.     style |= 1 if self.font.bold
  517.     style |= 2 if self.font.italic
  518.     g = self.font.gradient
  519.     DrawTextGradientV.call(__id__, x, y, width, height, text, align,
  520.       self.font.name, g.color1.to_i, g.color2.to_i, g.angle, self.font.size,
  521.       style, direction)
  522.   end
  523.   #-----------------------------------------------------------------------------
  524.   # * Draw Arc
  525.   #     color       : Color used to draw
  526.   #     thickness   : Thickness, in pixels, of the pen used to draw
  527.   #     x           : x-coordinate
  528.   #     y           : y-coordinate
  529.   #     width       : width of the shape
  530.   #     height      : height of the shape
  531.   #     start_angle : Angle in degrees measured clockwise from the x-axis to the
  532.   #                   starting point of the arc
  533.   #     sweep_angle : Angle in degrees measured clockwise from the startAngle
  534.   #                   parameter to ending point of the arc
  535.   #-----------------------------------------------------------------------------
  536.   def draw_arc(color, thickness, x, y, width, height, start_angle, sweep_angle)
  537.     DrawArc.call(__id__, color.to_i, thickness, x, y, width, height,
  538.       start_angle, sweep_angle)
  539.   end
  540.   #-----------------------------------------------------------------------------
  541.   # * Draw Bezier
  542.   #     color     : Color used to draw
  543.   #     x1        : first x-coordinate
  544.   #     y1        : first y-coordinate
  545.   #     x2        : second x-coordinate
  546.   #     y2        : second y-coordinate
  547.   #     x3        : third x-coordinate
  548.   #     y3        : third y-coordinate
  549.   #     x4        : fourth x-coordinate
  550.   #     y4        : fourth y-coordinate
  551.   #-----------------------------------------------------------------------------
  552.   def draw_bezier(x1, y1, x2, y2, x3, y3, x4, y4, color)
  553.     DrawBezier.call(__id__, color.to_i, x1, y1, x2, y2, x3, y3, x4, y4)
  554.   end
  555.   #-----------------------------------------------------------------------------
  556.   # * Draw Beziers
  557.   #     color  : Color used to draw
  558.   #     points : Points used to draw shape, variable number of arguments.
  559.   #              No. of points should be multiple of 3 + 1, such as 4, 7, or 10.
  560.   #-----------------------------------------------------------------------------
  561.   def draw_beziers(color, *points)
  562.     DrawBeziers.call(__id__, color.to_i, points.join(','))
  563.   end
  564.   #-----------------------------------------------------------------------------
  565.   # * Draws Closed Curve
  566.   #     color     : Color used to draw
  567.   #     thickness : Thickness, in pixels, of the pen used to draw
  568.   #     tension   : Specifies the tension of the curve
  569.   #     points    : Points used to draw shape, variable number of arguments.
  570.   #-----------------------------------------------------------------------------
  571.   def draw_closed_curve(color, thickness, tension, *points)
  572.     DrawClosedCurve(__id__, color.to_i, thickness, tension.to_s, points.join(','))
  573.   end
  574.   #-----------------------------------------------------------------------------
  575.   # * Draw Curve
  576.   #     color     : Color used to draw
  577.   #     thickness : Thickness, in pixels, of the pen used to draw
  578.   #     tension   : Specifies the tension of the curve
  579.   #     points    : Points used to draw shape, variable number of arguments.
  580.   #-----------------------------------------------------------------------------
  581.   def draw_curve(color, thickness, tension, *points)
  582.     points = points.join(',')
  583.     DrawCurve.call(__id__, color.to_i, thickness, tension.to_s, points)
  584.   end
  585.   #-----------------------------------------------------------------------------
  586.   # * Draw Ellipse
  587.   #     color     : Color used to draw
  588.   #     thickness : Thickness, in pixels, of the pen used to draw
  589.   #     x         : x-coordinate
  590.   #     y         : y-coordinate
  591.   #     width     : width of the shape
  592.   #     height    : height of the shape
  593.   #-----------------------------------------------------------------------------
  594.   def draw_ellipse(color, thickness, x, y, width, height)
  595.     DrawEllipse.call(__id__, color.to_i, thickness, x, y, width, height)
  596.   end
  597.   #-----------------------------------------------------------------------------
  598.   # * Draw Line
  599.   #     x1        : first x-coordinate
  600.   #     y1        : first y-coordinate
  601.   #     x2        : second x-coordinate
  602.   #     y2        : second y-coordinate
  603.   #     color     : Color used to draw
  604.   #     thickness : Thickness, in pixels, of the pen used to draw
  605.   #-----------------------------------------------------------------------------
  606.   def draw_line(x1, y1, x2, y2, color, thickness)
  607.     DrawLine.call(__id__, x1, y1, x2, y2, color.to_i, thickness)
  608.   end
  609.   #-----------------------------------------------------------------------------
  610.   # * Draw Lines
  611.   #     color     : Color used to draw
  612.   #     thickness : Thickness, in pixels, of the pen used to draw
  613.   #     points    : Points used to draw shape, variable number of arguments.
  614.   #-----------------------------------------------------------------------------
  615.   def draw_lines(color, thickness, *points)
  616.     DrawLines.call(__id__, color.to_i, thickness, points.join(','))
  617.   end
  618.   #-----------------------------------------------------------------------------
  619.   # * Draw Polygon
  620.   #     color     : Color used to draw
  621.   #     thickness : Thickness, in pixels, of the pen used to draw
  622.   #     points    : Points used to draw shape, variable number of arguments.
  623.   #-----------------------------------------------------------------------------
  624.   def draw_polygon(color, thickness, *points)
  625.     DrawPolygon.call(__id__, color.to_i, thickness, points.join(','))
  626.   end
  627.   #-----------------------------------------------------------------------------
  628.   # * Draw Pie
  629.   #     x           : x-coordinate
  630.   #     y           : y-coordinate
  631.   #     width       : width of the shape
  632.   #     height      : height of the shape
  633.   #     start_angle : Angle in degrees measured clockwise from the x-axis to the
  634.   #                   starting point of the arc
  635.   #     sweep_angle : Angle in degrees measured clockwise from the startAngle
  636.   #                   parameter to ending point of the arc
  637.   #     color       : Color used to draw
  638.   #     thickness   : Thickness, in pixels, of the pen used to draw
  639.   #-----------------------------------------------------------------------------
  640.   def draw_pie(x, y, width, height, start_angle, sweep_angle, color, thickness)
  641.     DrawPie.call(__id__, x, y, width, height, start_angle, sweep_angle,
  642.       color.to_i, thickness)
  643.   end
  644.   #-----------------------------------------------------------------------------
  645.   # * Fill Closed Curve
  646.   #     color   : Color used to draw
  647.   #     tension : Specifies the tension of the curve
  648.   #     points  : Points used to draw shape, variable number of arguments.
  649.   #-----------------------------------------------------------------------------
  650.   def fill_closed_curve(color, *points)
  651.     FillClosedCurve.call(__id__, color.to_i, tension.to_s, points.join(','))
  652.   end
  653.   #-----------------------------------------------------------------------------
  654.   # * Fill Ellipse
  655.   #     color     : Color used to draw
  656.   #     x         : x-coordinate
  657.   #     y         : y-coordinate
  658.   #     width     : width of the shape
  659.   #     height    : height of the shape
  660.   #-----------------------------------------------------------------------------
  661.   def fill_ellipse(x, y, width, height, color)
  662.     FillEllipse.call(__id__, color.to_i, x, y, width, height)
  663.   end
  664.   #-----------------------------------------------------------------------------
  665.   # * Fill Pie
  666.   #     color       : Color used to draw
  667.   #     x           : x-coordinate
  668.   #     y           : y-coordinate
  669.   #     width       : width of the shape
  670.   #     height      : height of the shape
  671.   #     start_angle : Angle in degrees measured clockwise from the x-axis to the
  672.   #                   starting point of the arc
  673.   #     sweep_angle : Angle in degrees measured clockwise from the startAngle
  674.   #                   parameter to ending point of the arc
  675.   #-----------------------------------------------------------------------------
  676.   def fill_pie(color, x, y, width, height, start_angle, sweep_angle)
  677.     FillPie.call(__id__, color.to_i, x, y, width, height, start_angle, sweep_angle)
  678.   end
  679.   #-----------------------------------------------------------------------------
  680.   # * Fill Polygon
  681.   #     color   : Color used to draw
  682.   #     points  : Points used to draw shape, variable number of arguments.
  683.   #-----------------------------------------------------------------------------
  684.   def fill_polygon(color, *points)  
  685.     FillPolygon.call(__id__, color.to_i, points.join(','))
  686.   end
  687.   #-----------------------------------------------------------------------------
  688.   # * Fill Rectangle Gradient
  689.   #     x      : x-coordinate
  690.   #     y      : y-coordinate
  691.   #     width  : width of the shape
  692.   #     height : height of the shape
  693.   #     color1 : Start color used to draw the gradient
  694.   #     color2 : End color used to draw the gradient
  695.   #     angle  : Angle at which the gradient will be drawn across the shape
  696.   #-----------------------------------------------------------------------------
  697.   def fill_gradient_rect(x, y, width, height, color1, color2, angle)
  698.     FillGradientRect.call(__id__, x, y, width, height, color1.to_i,
  699.       color2.to_i, angle.to_s)
  700.   end
  701.   #-----------------------------------------------------------------------------
  702.   # * Fill Ellipse Gradient
  703.   #     x      : x-coordinate
  704.   #     y      : y-coordinate
  705.   #     width  : width of the shape
  706.   #     height : height of the shape
  707.   #     color1 : Start color used to draw the gradient
  708.   #     color2 : End color used to draw the gradient
  709.   #     angle  : Angle at which the gradient will be drawn across the shape
  710.   #-----------------------------------------------------------------------------
  711.   def fill_gradient_ellipse(x, y, width, height, color1, color2, angle)
  712.     FillGradientEllipse.call(__id__, x, y, width, height, color1.to_i,
  713.       color2.to_i, angle.to_s)
  714.   end
  715.   #-----------------------------------------------------------------------------
  716.   # * Fill Polygon  Gradient
  717.   #     color1 : Start color used to draw the gradient
  718.   #     color2 : End color used to draw the gradient
  719.   #     angle  : Angle at which the gradient will be drawn across the shape
  720.   #     points : Points used to draw shape, variable number of arguments.
  721.   #-----------------------------------------------------------------------------
  722.   def fill_gradient_polygon(color1, color2, angle, *points)  
  723.     FillGradientPolygon.call(__id__, color1.to_i, color2.to_i,
  724.       angle.to_s, points.join(','))
  725.   end
  726.   #-----------------------------------------------------------------------------
  727.   # * Invert Colors (Destructive)
  728.   #     invert_alpha : Flag indiciating if the alpha component will be inverted
  729.   #-----------------------------------------------------------------------------
  730.   def invert!(invert_alpha = false)
  731.     Invert.call(__id__, invert_alpha ? 1 : 0)
  732.   end
  733.   #-----------------------------------------------------------------------------
  734.   # * Invert Colors (Non-Destructive)
  735.   #     invert_alpha : Flag indiciating if the alpha component will be inverted
  736.   #-----------------------------------------------------------------------------
  737.   def invert(invert_alpha = false)
  738.     bitmap = self.clone
  739.     Invert.call(bitmap.__id__, invert_alpha ? 1 : 0)
  740.     return bitmap
  741.   end
  742.   #-----------------------------------------------------------------------------
  743.   # * Pixelate (Destructive)
  744.   #     amount : New size of pixels in the bitmap
  745.   #     alpha  : Flag indicating if alpha will be averaged into pixel colors
  746.   #-----------------------------------------------------------------------------
  747.   def pixelate!(amount = 4, alpha = false)
  748.     amount = [[amount, 2].max, self.width / 2].min
  749.     Pixelate.call(__id__, amount, alpha ? 1 : 0)
  750.   end
  751.   #-----------------------------------------------------------------------------
  752.   # * Pixelate (Non-Destructive)
  753.   #     amount : New size of pixels in the bitmap
  754.   #     alpha  : Flag indicating if alpha will be averaged into pixel colors
  755.   #-----------------------------------------------------------------------------
  756.   def pixelate(amount = 4, alpha = false)
  757.     bitmap = self.clone
  758.     amount = [[amount, 2].max, self.width / 2].min
  759.     Pixelate.call(bitmap.__id__, amount, alpha ? 1 : 0)
  760.     return bitmap
  761.   end
  762.   #-----------------------------------------------------------------------------
  763.   # * Change Color Component (Destructive)
  764.   #     amount          : Amount to change color component (-255..255)
  765.   #     color_component : Component to change (B:0, G:1, R:2, A:3)
  766.   #-----------------------------------------------------------------------------
  767.   def change_rgba!(amount, color_component)
  768.     ChangeRgba.call(__id__, amount, color_component)
  769.   end
  770.   #-----------------------------------------------------------------------------
  771.   # * Change Color Component (Non-Destructive)
  772.   #     amount          : Amount to change color component (-255..255)
  773.   #     color_component : Component to change (B:0, G:1, R:2, A:3)
  774.   #-----------------------------------------------------------------------------
  775.   def change_rgba(amount, color_component)
  776.     bitmap = self.clone
  777.     ChangeRgba.call(bitmap.__id__, amount, color_component)
  778.     return bitmap
  779.   end
  780.   #-----------------------------------------------------------------------------
  781.   # * Gaussian Blur (Destructive)
  782.   #     kernel_size :
  783.   #     weight      :
  784.   #-----------------------------------------------------------------------------
  785.   def gaussian_blur!(kernel_size = 5, weight = 5.5)
  786.     GaussianBlur.call(__id__, kernel_size, weight.to_s)
  787.   end
  788.   #-----------------------------------------------------------------------------
  789.   # * Gaussian Blur (Non-Destructive)
  790.   #     kernel_size :
  791.   #     weight      :
  792.   #-----------------------------------------------------------------------------
  793.   def gaussian_blur(kernel_size = 5, weight = 5.5)
  794.     bitmap = self.clone
  795.     GaussianBlur.call(bitmap.__id__, kernel_size, weight.to_s)
  796.     return bitmap
  797.   end
  798.   #-----------------------------------------------------------------------------
  799.   # * Blur Effect (Destructive)
  800.   #     type   : Blur algorithm that will be used.
  801.   #              0 : Standard (3x3 matrix, 1.0 factor)
  802.   #              1 : 5x5 Matrix, 1.0 / 13.0 factor)
  803.   #              2 : Gaussian (3x3 matrix, 1.0 / 16.0 factor)
  804.   #              3 : Gaussian (5x5 matrix, 1.0 / 159.0 factor)
  805.   #              4 : Motion (9x9 matrix, 1.0 / 18.0 factor)
  806.   #              5 : Left to Right Motion (9x9 matrix, 1.0 / 9.0 factor)
  807.   #              6 : Right to Left Motion (9x9 matrix, 1.0 / 9.0 factor)
  808.   #              7 : Custom (5x5 matrix, custom factor)
  809.   #     factor : Factor level for custom type. Ignored for all others.
  810.   #-----------------------------------------------------------------------------
  811.   def blur!(type = 0, factor = 1.0)
  812.     Blur.call(__id__, type, factor.to_s)
  813.   end
  814.   #-----------------------------------------------------------------------------
  815.   # * Blur Effect (Non-Destructive)
  816.   #     type   : Blur algorithm that will be used.
  817.   #              0 : Standard (3x3 matrix, 1.0 factor)
  818.   #              1 : 5x5 Matrix, 1.0 / 13.0 factor)
  819.   #              2 : Gaussian (3x3 matrix, 1.0 / 16.0 factor)
  820.   #              3 : Gaussian (5x5 matrix, 1.0 / 159.0 factor)
  821.   #              4 : Motion (9x9 matrix, 1.0 / 18.0 factor)
  822.   #              5 : Left to Right Motion (9x9 matrix, 1.0 / 9.0 factor)
  823.   #              6 : Right to Left Motion (9x9 matrix, 1.0 / 9.0 factor)
  824.   #              7 : Custom (5x5 matrix, custom factor)
  825.   #     factor : Factor level for custom type. Ignored for all others.
  826.   #-----------------------------------------------------------------------------
  827.   def blur(type = 0, factor = 1.0)
  828.     bitmap = self.clone
  829.     Blur.call(__id__, type, factor.to_s)
  830.     return bitmap
  831.   end
  832.   #-----------------------------------------------------------------------------
  833.   # * Sharpen (Destructive)
  834.   #     type   : Sharpen algorithm that will be used.
  835.   #              0 : Standard (1.0 factor)
  836.   #              1 : Light (3x3 matrix)
  837.   #              2 : Ultra-Light (3x3 matrix, 0.3 factor)
  838.   #              3 : 5x5 matrix (Depending on source, sometimes softens)
  839.   #              4 : Intense
  840.   #              5 : Custom defined factor will be used
  841.   #     factor : Factor level for custom type. Ignored for all others.
  842.   #-----------------------------------------------------------------------------
  843.   def sharpen!(type = 0, factor = 1.0)
  844.     Sharpen.call(__id__, type, factor.to_s)
  845.   end
  846.   #-----------------------------------------------------------------------------
  847.   # * Sharpen (Non-Destructive)
  848.   #     type   : Sharpen algorithm that will be used.
  849.   #              0 : Standard (1.0 factor)
  850.   #              1 : Light (3x3 matrix)
  851.   #              2 : Ultra-Light (3x3 matrix, 0.3 factor)
  852.   #              3 : 5x5 matrix (Depending on source, sometimes softens)
  853.   #              4 : Intense
  854.   #              5 : Custom defined factor will be used
  855.   #     factor : Factor level for custom type. Ignored for all others.
  856.   #-----------------------------------------------------------------------------
  857.   def sharpen(type = 0, factor = 1.0)
  858.     bitmap = self.clone
  859.     Sharpen.call(bitmap.__id__, type, factor.to_s)
  860.     return bitmap
  861.   end
  862.   #-----------------------------------------------------------------------------
  863.   # * Soften (Destructive)
  864.   #-----------------------------------------------------------------------------
  865.   def soften!
  866.     Soften.call(__id__)
  867.   end
  868.   #-----------------------------------------------------------------------------
  869.   # * Soften (Non-Destructive)
  870.   #-----------------------------------------------------------------------------
  871.   def soften
  872.     bitmap = self.clone
  873.     Soften.call(bitmap.__id__)
  874.     return bitmap
  875.   end
  876.   #-----------------------------------------------------------------------------
  877.   # * Edge Detect (Destructive)
  878.   #     type      : Edge-detection algorithm that will be used.
  879.   #                 0 = Standard
  880.   #                 1 = 45 Degree
  881.   #                 2 = Horizontal
  882.   #                 3 = Vertical
  883.   #     grayscale : Flag indicating if result will be grayscaled
  884.   #-----------------------------------------------------------------------------
  885.   def edge_detect!(type = 0, grayscale = false)
  886.     EdgeDetect.call(__id__, type, grayscale ? 1 : 0)
  887.   end
  888.   #-----------------------------------------------------------------------------
  889.   # * Edge Detect (Non-Destructive)
  890.   #     type      : Edge-detection algorithm that will be used.
  891.   #                 0 = Standard
  892.   #                 1 = 45 Degree
  893.   #                 2 = Horizontal
  894.   #                 3 = Vertical
  895.   #     grayscale : Flag indicating if result will be grayscaled
  896.   #-----------------------------------------------------------------------------
  897.   def edge_detect(type = 0, grayscale = false)
  898.     bitmap = self.clone
  899.     EdgeDetect.call(bitmap.__id__, type, grayscale ? 1 : 0)
  900.     return bitmap
  901.   end
  902.   #-----------------------------------------------------------------------------
  903.   # * Poster Effect (Destructive)
  904.   #-----------------------------------------------------------------------------
  905.   def poster_effect!
  906.     PosterEffect.call(__id__)
  907.   end
  908.   #-----------------------------------------------------------------------------
  909.   # * Poster Effect (Non-Destructive)
  910.   #-----------------------------------------------------------------------------
  911.   def poster_effect
  912.     bitmap = self.clone
  913.     PosterEffect.call(bitmap.__id__)
  914.     return bitmap
  915.   end
  916.   #-----------------------------------------------------------------------------
  917.   # * High Pass Filter (Destructive)
  918.   #-----------------------------------------------------------------------------
  919.   def high_pass!(grayscale = false)
  920.     HighPass.call(__id__, grayscale ? 1 : 0)
  921.   end
  922.   #-----------------------------------------------------------------------------
  923.   # * High Pass Filter (Non-Destructive)
  924.   #-----------------------------------------------------------------------------
  925.   def high_pass(grayscale = false)
  926.     bitmap = self.clone
  927.     HighPass.call(bitmap.__id__, grayscale ? 1 : 0)
  928.     return bitmap
  929.   end
  930.   #-----------------------------------------------------------------------------
  931.   # * Color Mask
  932.   #     color     : Color to create mask for
  933.   #     tolerance : Amount of variance allowed in pixel comparison.
  934.   #-----------------------------------------------------------------------------
  935.   def color_mask(color, tolerance)
  936.     mask = self.clone
  937.     ColorMask.call(mask.__id__, color.to_i, tolerance)
  938.     return mask
  939.   end
  940.   #-----------------------------------------------------------------------------
  941.   # * Sepia Effect (Destructive)
  942.   #-----------------------------------------------------------------------------
  943.   def sepia!
  944.     Sepia.call(__id__)
  945.   end
  946.   #-----------------------------------------------------------------------------
  947.   # * Sepia Effect (Non-Destructive)
  948.   #-----------------------------------------------------------------------------
  949.   def sepia
  950.     bitmap = self.clone
  951.     Sepia.call(bitmap.__id__)
  952.     return bitmap
  953.   end
  954.   #-----------------------------------------------------------------------------
  955.   # * Grayscale Effect (Destructive)
  956.   #     remove_alpha : Flag indicating if alpha component will be removed
  957.   #-----------------------------------------------------------------------------
  958.   def grayscale!(remove_alpha = false)
  959.     Grayscale.call(__id__, remove_alpha ? 1 : 0)
  960.   end
  961.   #-----------------------------------------------------------------------------
  962.   # * Grayscale Effect (Non-Destructive)
  963.   #     remove_alpha : Flag indicating if alpha component will be removed
  964.   #-----------------------------------------------------------------------------
  965.   def grayscale(remove_alpha = false)
  966.     bitmap = self.clone
  967.     Grayscale.call(bitmap.__id__, remove_alpha ? 1 : 0)
  968.     return bitmap
  969.   end
  970.   #-----------------------------------------------------------------------------
  971.   # * Emboss Effect (Destructive)
  972.   #     type      : Emboss algorithm that will be used.
  973.   #                 0 : Standard
  974.   #                 1 : 45 Degree
  975.   #                 2 : Top-Left Bottom-Right
  976.   #                 3 : Intense
  977.   #     grayscale : Flag indicating if result will be grayscaled
  978.   #-----------------------------------------------------------------------------
  979.   def emboss!(type = 0, grayscale = false)
  980.     Emboss.call(__id__, type, grayscale ? 1 : 0)
  981.   end
  982.   #-----------------------------------------------------------------------------
  983.   # * Emboss Effect (Non-Destructive)
  984.   #     type      : Emboss algorithm that will be used.
  985.   #                 0 : Standard
  986.   #                 1 : 45 Degree
  987.   #                 2 : Top-Left Bottom-Right
  988.   #                 3 : Intense
  989.   #     grayscale : Flag indicating if result will be grayscaled
  990.   #-----------------------------------------------------------------------------
  991.   def emboss(type = 0, grayscale = false)
  992.     bitmap = self.clone
  993.     Emboss.call(bitmap.__id__, type, grayscale ? 1 : 0)
  994.     return bitmap
  995.   end
  996.   #-----------------------------------------------------------------------------
  997.   # * Tint Bitmap Colors (Destructive)
  998.   #     red_percent   : Percentage of red to increase. (0 - 100)
  999.   #     green_percent : Percentage of green to increase. (0 - 100)
  1000.   #     blue_percent  : Percentage of blue to increase. (0 - 100)
  1001.   #-----------------------------------------------------------------------------
  1002.   def tint!(red_percent, green_percent, blue_percent)
  1003.     Tint.call(__id__, red_percent, green_percent, blue_percent)
  1004.   end
  1005.   #-----------------------------------------------------------------------------
  1006.   # * Tint Bitmap Colors (Non-Destructive)
  1007.   #     red_percent   : Percentage of red to increase. (0 - 100)
  1008.   #     green_percent : Percentage of green to increase. (0 - 100)
  1009.   #     blue_percent  : Percentage of blue to increase. (0 - 100)
  1010.   #-----------------------------------------------------------------------------
  1011.   def tint(red_percent, green_percent, blue_percent)
  1012.     bitmap = self.clone
  1013.     Tint.call(bitmap.__id__, red_percent, green_percent, blue_percent)
  1014.     return bitmap
  1015.   end
  1016.   #-----------------------------------------------------------------------------
  1017.   # * Bitmap Color Balance (Destructive)
  1018.   #     red   : Red balance component (0 - 255)
  1019.   #     green : Green balance component (0 - 255)
  1020.   #     blue  : Blue balance component (0 - 255)
  1021.   #-----------------------------------------------------------------------------
  1022.   def color_balance!(red, green, blue)
  1023.     ColorBalance.call(__id__, red, green, blue)
  1024.   end
  1025.   #-----------------------------------------------------------------------------
  1026.   # * Bitmap Color Balance (Non-Destructive)
  1027.   #     red   : Red balance component (0 - 255)
  1028.   #     green : Green balance component (0 - 255)
  1029.   #     blue  : Blue balance component (0 - 255)
  1030.   #-----------------------------------------------------------------------------
  1031.   def color_balance(red, green, blue)
  1032.     bitmap = self.clone
  1033.     ColorBalance.call(bitmap.__id__, red, green, blue)
  1034.     return bitmap
  1035.   end
  1036.   #-----------------------------------------------------------------------------
  1037.   # * Bitonal Bitmap (Destructive)
  1038.   #     dark_color  : Color used for dark tones below the threshold
  1039.   #     light_color : Color used for light tones above the threshold
  1040.   #     threshold   : Threshold to determine light tones from dark tones
  1041.   #-----------------------------------------------------------------------------
  1042.   def bitonal!(dark_color, light_color, threshold)
  1043.     Bitonal.call(__id__, dark_color.to_i, light_color.to_i, threshold)
  1044.   end
  1045.   #-----------------------------------------------------------------------------
  1046.   # * Bitonal Bitmap (Non-Destructive)
  1047.   #     dark_color  : Color used for dark tones below the threshold
  1048.   #     light_color : Color used for light tones above the threshold
  1049.   #     threshold   : Threshold to determine light tones from dark tones
  1050.   #-----------------------------------------------------------------------------
  1051.   def bitonal(dark_color, light_color, threshold)
  1052.     bitmap = self.clone
  1053.     Bitonal.call(bitmap.__id__, dark_color.to_i, light_color.to_i, threshold)
  1054.     return bitmap
  1055.   end
  1056.   #-----------------------------------------------------------------------------
  1057.   # * Apply Solarise Effect (Destructive)
  1058.   #     red   : Red threshold value (0 - 255)
  1059.   #     green : Green threshold value (0 - 255)
  1060.   #     blue  : Blue threshold value (0 - 255)
  1061.   #-----------------------------------------------------------------------------
  1062.   def solarise!(red, green, blue)
  1063.     Solarise.call(__id__, red, green, blue)
  1064.   end
  1065.   #-----------------------------------------------------------------------------
  1066.   # * Apply Solarise Effect (Non-Destructive)
  1067.   #     red   : Red threshold value (0 - 255)
  1068.   #     green : Green threshold value (0 - 255)
  1069.   #     blue  : Blue threshold value (0 - 255)
  1070.   #-----------------------------------------------------------------------------
  1071.   def solarise(red, green, blue)
  1072.     bitmap = self.clone
  1073.     Solarise.call(bitmap.__id__, red, green, blue)
  1074.     return bitmap
  1075.   end
  1076.   #-----------------------------------------------------------------------------
  1077.   # * Median Filter Effect (Destructive)
  1078.   #     matrix_size : Size of the matrix used to calculate pixels
  1079.   #     bias        : Amount of bias to apply to the colors
  1080.   #     grayscale   : Flag indicating if result will be grayscaled
  1081.   #-----------------------------------------------------------------------------
  1082.   def median_filter!(matrix_size = 3, bias = 0, grayscale = false)
  1083.     MedianFilter.call(__id__, matrix_size, bias, grayscale ? 1 : 0)
  1084.   end
  1085.   #-----------------------------------------------------------------------------
  1086.   # * Median Filter Effect (Non-Destructive)
  1087.   #     matrix_size : Size of the matrix used to calculate pixels
  1088.   #     bias        : Amount of bias to apply to the colors
  1089.   #     grayscale   : Flag indicating if result will be grayscaled
  1090.   #-----------------------------------------------------------------------------
  1091.   def median_filter(matrix_size = 3, bias = 0, grayscale = false)
  1092.     bitmap = self.clone
  1093.     MedianFilter.call(bitmap.__id__, matrix_size, bias, grayscale ? 1 : 0)
  1094.     return bitmap
  1095.   end
  1096.   #-----------------------------------------------------------------------------
  1097.   # * Rotate and/or Flip Bitmap (Destructive)
  1098.   #     type : 0: Rotate180FlipXY or RotateNoneFlipNone
  1099.   #            1: Rotate270FlipXY or Rotate90FlipNone
  1100.   #            2: RotateNoneFlipXY or Rotate180FlipNone
  1101.   #            3: Rotate90FlipXY or Rotate270FlipNone
  1102.   #            4: Rotate180FlipY or RotateNoneFlipX
  1103.   #            5: Rotate90FlipX or Rotate270FlipY
  1104.   #            6: RotateNoneFlipY or Rotate180FlipX
  1105.   #            7: Rotate90FlipY or Rotate270FlipX
  1106.   #-----------------------------------------------------------------------------
  1107.   def rotate_flip!(type)
  1108.     RotateFlip.call(__id__, type)
  1109.   end
  1110.   #-----------------------------------------------------------------------------
  1111.   # * Rotate and/or Flip Bitmap (Non-Destructive)
  1112.   #     type : 0: Rotate180FlipXY or RotateNoneFlipNone
  1113.   #            1: Rotate270FlipXY or Rotate90FlipNone
  1114.   #            2: RotateNoneFlipXY or Rotate180FlipNone
  1115.   #            3: Rotate90FlipXY or Rotate270FlipNone
  1116.   #            4: Rotate180FlipY or RotateNoneFlipX
  1117.   #            5: Rotate90FlipX or Rotate270FlipY
  1118.   #            6: RotateNoneFlipY or Rotate180FlipX
  1119.   #            7: Rotate90FlipY or Rotate270FlipX
  1120.   #-----------------------------------------------------------------------------
  1121.   def rotate_flip(type)
  1122.     bitmap = self.clone
  1123.     RotateFlip.call(bitmap.__id__, type)
  1124.     return bitmap
  1125.   end
  1126. end
  1127.  
  1128. #===============================================================================
  1129. # ** Graphics
  1130. #-------------------------------------------------------------------------------
  1131. # The module that carries out graphics processing.
  1132. #===============================================================================
  1133.  
  1134. module Graphics
  1135.   #-----------------------------------------------------------------------------
  1136.   # * Width of window client area
  1137.   #-----------------------------------------------------------------------------
  1138.   def self.width
  1139.     return RpgNET.get_window_rect.width
  1140.   end
  1141.   #-----------------------------------------------------------------------------
  1142.   # * Height of window client area
  1143.   #-----------------------------------------------------------------------------
  1144.   def self.height
  1145.     return RpgNET.get_window_rect.height
  1146.   end
  1147. end
  1148.  
  1149. #===============================================================================
  1150. # ** Sprite
  1151. #-------------------------------------------------------------------------------
  1152. # Sprites are the basic concept used to display on the game screen.
  1153. #===============================================================================
  1154.  
  1155. class Sprite
  1156.   #-----------------------------------------------------------------------------
  1157.   # * Constants
  1158.   #-----------------------------------------------------------------------------
  1159.   CreateEffect = Win32API.new(RPGNET, 'CreateSpriteEffect', 'iiip', '')
  1160.   UpdateEffect = Win32API.new(RPGNET, 'UpdateSpriteEffect', 'ii', '')
  1161.   #-----------------------------------------------------------------------------
  1162.   # * Shrink
  1163.   #     frames : Number of frames effect will last
  1164.   #-----------------------------------------------------------------------------
  1165.   def shrink(frames = 20)
  1166.     return if @effect_frame != nil
  1167.     self.bitmap = self.bitmap.clone
  1168.     @effect_frame = frames
  1169.     CreateEffect.call(self.bitmap.__id__, 1, frames, '')
  1170.   end
  1171.   #-----------------------------------------------------------------------------
  1172.   # * Hue Rotation
  1173.   #     frames : Number of frames effect will last
  1174.   #     speed  : Amount of hue change each step
  1175.   #     fade   : Flag indicating if sprite will fade out
  1176.   #-----------------------------------------------------------------------------
  1177.   def hue_effect(frames = 60, speed = 8, fade = false)
  1178.     return if @effect_frame != nil
  1179.     self.bitmap = self.bitmap.clone
  1180.     @effect_frame = frames
  1181.     CreateEffect.call(self.bitmap.__id__, 2, frames, [speed, fade].join(','))
  1182.   end
  1183.   #-----------------------------------------------------------------------------
  1184.   # * Flatten
  1185.   #     frames     : Number of frames effect will last
  1186.   #     direction  : Direction of effect, 0:Up, 1:Down
  1187.   #-----------------------------------------------------------------------------
  1188.   def flatten(frames = 10, direction = 0)
  1189.     return if @effect_frame != nil
  1190.     self.bitmap = self.bitmap.clone
  1191.     @effect_frame = frames
  1192.     CreateEffect.call(self.bitmap.__id__, 3, frames, direction.to_s)
  1193.   end
  1194.   #-----------------------------------------------------------------------------
  1195.   # * Flatten
  1196.   #     frames     : Number of frames effect will last
  1197.   #     direction  : Direction of effect, 0:Horizontal, 1:Vertical
  1198.   #-----------------------------------------------------------------------------
  1199.   def squeeze(frames = 5, direction = 0)
  1200.     return if @effect_frame != nil
  1201.     self.bitmap = self.bitmap.clone
  1202.     @effect_frame = frames
  1203.     CreateEffect.call(self.bitmap.__id__, 4, frames, direction.to_s)
  1204.   end
  1205.   #-----------------------------------------------------------------------------
  1206.   # * Frame Update
  1207.   #-----------------------------------------------------------------------------
  1208.   alias rpgnet_update update
  1209.   def update
  1210.     rpgnet_update
  1211.     if @effect_frame != nil
  1212.       UpdateEffect.call(self.bitmap.__id__, @effect_frame)
  1213.       @effect_frame -= 1
  1214.       if @effect_frame < 0
  1215.         @effect_frame = nil
  1216.       end
  1217.     end
  1218.   end
  1219. end
  1220.  
  1221. #===============================================================================
  1222. # ** Color
  1223. #-------------------------------------------------------------------------------
  1224. # The RGBA color class. Each component is handled with a floating point value.
  1225. #===============================================================================
  1226.  
  1227. class Color
  1228.   #-----------------------------------------------------------------------------
  1229.   # * Integer value of Color
  1230.   #-----------------------------------------------------------------------------
  1231.   def to_i
  1232.     string = [red.to_i.chr, green.to_i.chr, blue.to_i.chr, alpha.to_i.chr].join
  1233.     return string.unpack('L').shift
  1234.   end
  1235. end
  1236.  
  1237. #===============================================================================
  1238. # ** Gradient
  1239. #-------------------------------------------------------------------------------
  1240. # Represents a gradient color
  1241. #===============================================================================
  1242. Gradient = Struct.new(:color1, :color2, :angle)
  1243.  
  1244. #===============================================================================
  1245. # ** Gradient
  1246. #-------------------------------------------------------------------------------
  1247. # The font class. Font is a property of the Bitmap class.
  1248. #===============================================================================
  1249. class Font
  1250.   attr_accessor :gradient
  1251. end
  1252.  
  1253. #===============================================================================
  1254. # ** RPG::AudioFile
  1255. #-------------------------------------------------------------------------------
  1256. # Data class for audio files. Common to all formats (BGM, BGS, ME, SE).
  1257. #===============================================================================
  1258.  
  1259. class RPG::AudioFile
  1260.   #-----------------------------------------------------------------------------
  1261.   # * Duration in Milliseconds
  1262.   #-----------------------------------------------------------------------------
  1263.   def milliseconds
  1264.     dir = File.dirname(@name)
  1265.     filename = File.basename(@name)
  1266.     path = RpgNET.get_full_path(filename, dir)
  1267.     return Audio::GetAudioDurationMs.call(path)
  1268.   end
  1269.   #-----------------------------------------------------------------------------
  1270.   # * Duration in Frames
  1271.   #     frame_rate : Frame rate to calculate number of frames for.
  1272.   #-----------------------------------------------------------------------------
  1273.   def frame_duration(frame_rate)
  1274.     return milliseconds / frame_rate
  1275.   end
  1276. end
  1277.  
  1278. #===============================================================================
  1279. # ** Vector
  1280. #-------------------------------------------------------------------------------
  1281. # This struct represents magnitude (length) and direction.
  1282. #===============================================================================
  1283. Vector = Struct.new(:x, :y, :z)
  1284.  
  1285. #===============================================================================
  1286. # ** ParticleGenerator
  1287. #-------------------------------------------------------------------------------
  1288. # This class acts as a wrapper around an Rpg.NET ParticleGenerator.
  1289. #===============================================================================
  1290.  
  1291. class ParticleGenerator < Sprite
  1292.   #-----------------------------------------------------------------------------
  1293.   # * Particle Types
  1294.   #-----------------------------------------------------------------------------
  1295.   FOUNTAIN  = 0x01
  1296.   FIREWORK  = 0x02
  1297.   EXPLOSION = 0x03
  1298.   #-----------------------------------------------------------------------------
  1299.   # * Constants
  1300.   #-----------------------------------------------------------------------------
  1301.   Initialize = Win32API.new(RPGNET, 'PgInitialize', 'ii', '')
  1302.   SetEnabled = Win32API.new(RPGNET, 'PgSetEnabled', 'ii', '')
  1303.   SetEnvironment = Win32API.new(RPGNET, 'PgSetEnvironment', 'ipp', '')
  1304.   SetSpeed = Win32API.new(RPGNET, 'PgSetSpeed', 'ii', '')
  1305.   SetParticles = Win32API.new(RPGNET, 'PgSetParticles', 'iii', '')
  1306.   SetColors = Win32API.new(RPGNET, 'PgSetColors', 'ip', '')
  1307.   GetRegenerate = Win32API.new(RPGNET, 'PgGetRegenerate', 'i', '')
  1308.   SetRegenerate = Win32API.new(RPGNET, 'PgSetRegenerate', 'ii', '')
  1309.   Dispose = Win32API.new(RPGNET, 'PgDispose', 'i', '')
  1310.   #-----------------------------------------------------------------------------
  1311.   # * Public Instance Variables
  1312.   #-----------------------------------------------------------------------------
  1313.   attr_reader :enabled
  1314.   attr_reader :gravity
  1315.   attr_reader :wind
  1316.   attr_reader :max_particles
  1317.   attr_reader :life_span
  1318.   attr_reader :type
  1319.   attr_reader :colors
  1320.   #-----------------------------------------------------------------------------
  1321.   # * Object Initialization
  1322.   #-----------------------------------------------------------------------------
  1323.   def initialize(viewport, width, height, type)
  1324.     super(viewport)
  1325.     self.bitmap = Bitmap.new(width, height)
  1326.     @id = self.bitmap.__id__
  1327.     @type = type
  1328.     @wind = Vector.new(0.002, 0.0, 0.0)
  1329.     @gravity = Vector.new(0.0, -0.02, 0.0)
  1330.     @speed = 20
  1331.     @life_span = 150
  1332.     @max_particles = 250
  1333.     Initialize.call(@id, @type)
  1334.   end
  1335.   #-----------------------------------------------------------------------------
  1336.   # * Width of the Particle Generator
  1337.   #-----------------------------------------------------------------------------
  1338.   def width
  1339.     return self.bitmap.width
  1340.   end
  1341.   #-----------------------------------------------------------------------------
  1342.   # * Height of the Particle Generator
  1343.   #-----------------------------------------------------------------------------
  1344.   def height
  1345.     return self.bitmap.height
  1346.   end
  1347.   #-----------------------------------------------------------------------------
  1348.   # * Start/Stop Particle Generation
  1349.   #     value : Flag indicating if generator is enabled or not
  1350.   #-----------------------------------------------------------------------------
  1351.   def enabled=(value)
  1352.     if @enabled != value
  1353.       @enabled = value
  1354.       SetEnabled.call(@id, @enabled ? 1 : 0)
  1355.     end
  1356.   end
  1357.   #-----------------------------------------------------------------------------
  1358.   # * Get Regenerate Flag
  1359.   #-----------------------------------------------------------------------------
  1360.   def regenerate
  1361.     return GetRegenerate.call(@id)
  1362.   end
  1363.   #-----------------------------------------------------------------------------
  1364.   # * Set Regenerate Flag
  1365.   #     value : Flag indicating if generator regenerates after executing
  1366.   #-----------------------------------------------------------------------------
  1367.   def regenerate=(value)
  1368.     SetRegenerate.call(@id, value ? 1 : 0)
  1369.   end
  1370.   #-----------------------------------------------------------------------------
  1371.   # * Set Particle Environment
  1372.   #     wind    : Vector representing wind factor
  1373.   #     gravity : Vector representing gravity factor
  1374.   #-----------------------------------------------------------------------------
  1375.   def set_environment(wind, gravity)
  1376.     if (@wind != wind) || (@gravity != gravity)
  1377.       @wind = wind
  1378.       @gravity = gravity
  1379.       wind = [@wind.x, @wind.y, @wind.z].join(',')
  1380.       gravity = [@gravity.x, @gravity.y, @gravity.z].join(',')
  1381.       SetEnvironment.call(@id, wind, gravity)
  1382.     end
  1383.   end
  1384.   #-----------------------------------------------------------------------------
  1385.   # * Set Particle Generator Speed
  1386.   #     value : Speed, in milliseconds, between updates
  1387.   #-----------------------------------------------------------------------------
  1388.   def speed=(value)
  1389.     if @speed != speed
  1390.       @speed = [speed, 4].max
  1391.       SetSpeed.call(@id, @speed)
  1392.     end
  1393.   end
  1394.   #-----------------------------------------------------------------------------
  1395.   # * Set Particle Settings
  1396.   #     max_particles : Maximum number of particles created at one time
  1397.   #     life_span     : Duration of time a particle will last
  1398.   #-----------------------------------------------------------------------------
  1399.   def set_particles(max_particles, life_span)
  1400.     if (@max_particles != max_particles) || (@life_span != life_span)
  1401.       @max_particles = [max_particles, 1].max
  1402.       @life_span = [life_span, 1].max
  1403.       SetParticles.call(@id, @max_particles, @life_span)
  1404.     end
  1405.   end
  1406.   #-----------------------------------------------------------------------------
  1407.   # * Dispose
  1408.   #-----------------------------------------------------------------------------
  1409.   alias base_dispose dispose
  1410.   def dispose
  1411.     Dispose.call(@id)
  1412.     base_dispose
  1413.   end
  1414.   #-----------------------------------------------------------------------------
  1415.   # * Set Color(s) used for Particles
  1416.   #     colors : One or more colors
  1417.   #-----------------------------------------------------------------------------
  1418.   def set_colors(*colors)
  1419.     if @colors != colors
  1420.       @colors = colors
  1421.       if @colors.size == 0
  1422.         @colors.push(Color.new(0, 0, 0, 0))
  1423.       end
  1424.       colors = @colors.collect {|c| c.to_i }
  1425.       SetColors.call(@id, colors.join(','))
  1426.     end
  1427.   end
  1428. end
  1429.  
  1430. #===============================================================================
  1431. # ** Input
  1432. #-------------------------------------------------------------------------------
  1433. # A module that handles input data from a gamepad or keyboard.
  1434. #===============================================================================
  1435.  
  1436. module Input
  1437.   #-----------------------------------------------------------------------------
  1438.   # * Virtual Keys
  1439.   #-----------------------------------------------------------------------------
  1440.     Key = { 'NONE' => 0, 'LBUTTON' => 1, 'RBUTTON' => 2, 'CANCEL' => 3,
  1441.         'MBUTTON' => 4, 'XBUTTON1' => 5, 'XBUTTON2' => 6, 'BACK' => 8, 'TAB' => 9,
  1442.         'LINEFEED' => 10, 'CLEAR' => 12, 'RETURN' => 13, 'ENTER' => 13,
  1443.     'SHIFTKEY' => 16, 'CONTROLKEY' => 17, 'MENU' => 18, 'PAUSE' => 19,
  1444.         'CAPITAL' => 20, 'CAPSLOCK' => 20, 'KANAMODE' => 21, 'HANGULMODE' => 21,
  1445.         'HANGUELMODE' => 21, 'JUNJAMODE' => 23, 'FINALMODE' => 24,'HANJAMODE' => 25,
  1446.         'KANJIMODE' => 25, 'ESCAPE' => 27, 'IMECONVERT' => 28,'IMENONCONVERT' => 29,
  1447.         'IMEACCEPT' => 30, 'IMEMODECHANGE' => 31, 'SPACE' => 32, 'PAGEUP' => 33,
  1448.         'PRIOR' => 33, 'PAGEDOWN' => 34, 'NEXT' => 34, 'END' => 35, 'HOME' => 36,
  1449.         'LEFT' => 37, 'UP' => 38, 'RIGHT' => 39, 'DOWN' => 40, 'SELECT' => 41,
  1450.         'PRINT' => 42, 'EXECUTE' => 43, 'SNAPSHOT' => 44, 'PRINTSCREEN' => 44,
  1451.         'INSERT' => 45, 'DELETE' => 46, 'HELP' => 47, 'D0' => 48, 'D1' => 49,
  1452.     'D2' => 50, 'D3' => 51, 'D4' => 52, 'D5' => 53, 'D6' => 54, 'D7' => 55,
  1453.         'D8' => 56, 'D9' => 57, 'A' => 65, 'B' => 66, 'C' => 67, 'D' => 68,
  1454.         'E' => 69, 'F' => 70, 'G' => 71, 'H' => 72, 'I' => 73, 'J' => 74, 'K' => 75,
  1455.         'L' => 76, 'M' => 77, 'N' => 78, 'O' => 79, 'P' => 80, 'Q' => 81, 'R' => 82,
  1456.         'S' => 83, 'T' => 84, 'U' => 85, 'V' => 86, 'W' => 87, 'X' => 88, 'Y' => 89,
  1457.         'Z' => 90, 'LWIN' => 91, 'RWIN' => 92, 'APPS' => 93, 'SLEEP' => 95,
  1458.         'NUMPAD0' => 96, 'NUMPAD1' => 97, 'NUMPAD2' => 98, 'NUMPAD3' => 99,
  1459.         'NUMPAD4' => 100, 'NUMPAD5' => 101, 'NUMPAD6' => 102, 'NUMPAD7' => 103,
  1460.         'NUMPAD8' => 104, 'NUMPAD9' => 105, 'MULTIPLY' => 106, 'ADD' => 107,
  1461.         'SEPARATOR' => 108, 'SUBTRACT' => 109, 'DECIMAL' => 110, 'DIVIDE' => 111,
  1462.         'F1' => 112, 'F2' => 113, 'F3' => 114, 'F4' => 115, 'F5' => 116,'F6' => 117,
  1463.         'F7' => 118, 'F8' => 119, 'F9' => 120, 'F10' => 121, 'F11' => 122,
  1464.         'F12' => 123, 'F13' => 124, 'F14' => 125, 'F15' => 126, 'F16' => 127,
  1465.     'F17' => 128, 'F18' => 129, 'F19' => 130, 'F20' => 131, 'F21' => 132,
  1466.         'F22' => 133, 'F23' => 134, 'F24' => 135, 'NUMLOCK' => 144, 'SCROLL' => 145,
  1467.         'LSHIFTKEY' => 160, 'RSHIFTKEY' => 161, 'LCONTROLKEY' => 162,
  1468.     'RCONTROLKEY' => 163, 'LMENU' => 164, 'RMENU' => 165, 'BROWSERBACK' => 166,
  1469.         'BROWSERFORWARD' => 167, 'BROWSERREFRESH' => 168, 'BROWSERSTOP' => 169,
  1470.         'BROWSERSEARCH' => 170, 'BROWSERFAVORITES' => 171, 'BROWSERHOME' => 172,
  1471.         'VOLUMEMUTE' => 173, 'VOLUMEDOWN' => 174, 'VOLUMEUP' => 175,
  1472.     'MEDIANEXTTRACK' => 176, 'MEDIAPREVIOUSTRACK' => 177, 'MEDIASTOP' => 178,
  1473.     'MEDIAPLAYPAUSE' => 179, 'LAUNCHMAIL' => 180, 'SELECTMEDIA' => 181,
  1474.         'LAUNCHAPPLICATION1' => 182, 'LAUNCHAPPLICATION2' => 183, 'OEM_1' => 186,
  1475.         'OEMSEMICOLON' => 186, 'OEMPLUS' => 187, 'OEMCOMMA' => 188,'OEMMINUS' => 189,
  1476.         'OEMPERIOD' => 190, 'SLASH' => 191, 'OEM2' => 191, 'OEM3' => 192,
  1477.     'OEMTILDE' => 192, 'LBRACKET' => 219, 'OEM4' => 219, 'OEM5' => 220,
  1478.         'OEMPIPE' => 220, 'RBRACKET' => 221, 'OEM6' => 221, 'OEM7' => 222,
  1479.         'OEMQUOTES' => 222, 'OEM8' => 223, 'BACKSLASH' => 226, 'OEM102' => 226,
  1480.         'PROCESSKEY' => 229, 'PACKET' => 231, 'ATTN' => 246, 'CRSEL' => 247,
  1481.         'EXSEL' => 248, 'ERASEEOF' => 249, 'PLAY' => 250, 'ZOOM' => 251,
  1482.     'NONAME' => 252, 'PA1' => 253, 'OEMCLEAR' => 254, 'KEYCODE' => 65535,
  1483.         'SHIFT' => 65536, 'CONTROL' => 131072,'ALT' => 262144, 'MODIFIERS' => -65536
  1484.     }
  1485.   #-----------------------------------------------------------------------------
  1486.   # * Key Configuration
  1487.   #-----------------------------------------------------------------------------
  1488.   UP = [Key['UP']]
  1489.   LEFT = [Key['LEFT']]
  1490.   DOWN = [Key['DOWN']]
  1491.   RIGHT = [Key['RIGHT']]
  1492.   A = [Key['SHIFT']]
  1493.   B = [Key['ESCAPE'], Key['NUMPAD0'], Key['X']]
  1494.   C = [Key['SPACE'], Key['ENTER'], Key['C']]
  1495.   X = [Key['A']]
  1496.   Y = [Key['S']]
  1497.   Z = [Key['D']]
  1498.   L = [Key['Q'], Key['PAGEDOWN']]
  1499.   R = [Key['W'], Key['PAGEUP']]
  1500.   F5 = [Key['F5']]
  1501.   F6 = [Key['F6']]
  1502.   F7 = [Key['F7']]
  1503.   F8 = [Key['F8']]
  1504.   F9 = [Key['F9']]
  1505.   SHIFT = [Key['SHIFT']]
  1506.   CTRL = [Key['CONTROL']]
  1507.   ALT = [Key['ALT']]
  1508.   LMOUSE = [Key['LBUTTON']]
  1509.   RMOUSE = [Key['RBUTTON']]
  1510.   MMOUSE = [Key['MBUTTON']]
  1511.   #-----------------------------------------------------------------------------
  1512.   # * Constants
  1513.   #-----------------------------------------------------------------------------
  1514.   Update = Win32API.new(RPGNET, 'InputUpdate', '', '')
  1515.   IsTriggered = Win32API.new(RPGNET, 'InputIsTriggered', 'i', 'i')
  1516.   IsPressed = Win32API.new(RPGNET, 'InputIsPressed', 'i', 'i')
  1517.   IsRepeated = Win32API.new(RPGNET, 'InputIsRepeated', 'i', 'i')
  1518.   IsReleased = Win32API.new(RPGNET, 'InputIsReleased', 'i', 'i')
  1519.   BeginCapture = Win32API.new(RPGNET, 'InputBeginCapture', '', '')
  1520.   EndCapture = Win32API.new(RPGNET, 'InputEndCapture', '', 'p')
  1521.   MousePosition = Win32API.new(RPGNET, 'InputMousePosition', 'p', '')
  1522.   IsDoubleClick = Win32API.new(RPGNET, 'InputIsDoubleClick', 'i', 'i')
  1523.   IsMouseMoving = Win32API.new(RPGNET, 'InputIsMouseMoved', '', 'i')
  1524.   IsWheelMoved = Win32API.new(RPGNET, 'InputIsWheelMoved', '', 'i')
  1525.   GetWheelDelta = Win32API.new(RPGNET, 'InputGetWheelDelta', '', 'i')
  1526.   #-----------------------------------------------------------------------------
  1527.   # * Frame Update
  1528.   #-----------------------------------------------------------------------------
  1529.   def self.update
  1530.     Update.call
  1531.   end
  1532.   #-----------------------------------------------------------------------------
  1533.   # * Key Triggered
  1534.   #     key : Key constant to test
  1535.   #-----------------------------------------------------------------------------
  1536.   def self.trigger?(key)
  1537.     return IsTriggered.call(key) if key.is_a?(Fixnum)
  1538.     return key.any? {|k| IsTriggered.call(k) != 0 }
  1539.   end
  1540.   #-----------------------------------------------------------------------------
  1541.   # * Key Pressed
  1542.   #     key : Key constant to test
  1543.   #-----------------------------------------------------------------------------
  1544.   def self.press?(key)
  1545.     return IsPressed.call(key) if key.is_a?(Fixnum)
  1546.     return key.any? {|k| IsPressed.call(k) != 0 }
  1547.   end
  1548.   #-----------------------------------------------------------------------------
  1549.   # * Key Repeated
  1550.   #     key : Key constant to test
  1551.   #-----------------------------------------------------------------------------
  1552.   def self.repeat?(key)
  1553.     return IsRepeated.call(key) if key.is_a?(Fixnum)
  1554.     return key.any? {|k| IsRepeated.call(k) != 0 }
  1555.   end
  1556.   #-----------------------------------------------------------------------------
  1557.   # * Key Released
  1558.   #     key : Key constant to test
  1559.   #-----------------------------------------------------------------------------
  1560.   def self.release?(key)
  1561.     return IsReleased.call(key) if key.is_a?(Fixnum)
  1562.     return key.any? {|k| IsReleased.call(k) != 0 }
  1563.   end
  1564.   #-----------------------------------------------------------------------------
  1565.   # * Mouse Double-Click
  1566.   #     key : Key constant to test
  1567.   #-----------------------------------------------------------------------------
  1568.   def self.dbl_click?(key)
  1569.     return IsDoubleClick.call(key) if key.is_a?(Fixnum)
  1570.     return key.any? {|k| IsDoubleClick.call(k) != 0 }
  1571.   end
  1572.   #-----------------------------------------------------------------------------
  1573.   # * Begin Key Logging
  1574.   #-----------------------------------------------------------------------------
  1575.   def self.begin_capture
  1576.     BeginCapture.call
  1577.   end
  1578.   #-----------------------------------------------------------------------------
  1579.   # * End Key Logging and Get String
  1580.   #-----------------------------------------------------------------------------
  1581.   def self.end_capture
  1582.     return EndCapture.call
  1583.   end
  1584.   #-----------------------------------------------------------------------------
  1585.   # * Current Mouse Position
  1586.   #-----------------------------------------------------------------------------
  1587.   def self.mouse_pos
  1588.     point = [0, 0].pack('ii')
  1589.     MousePosition.call(point)
  1590.     # Return mouse coordinates as two element array: [X, Y]
  1591.     return point.unpack('ii')
  1592.   end
  1593.   #-----------------------------------------------------------------------------
  1594.   # * Mouse is Moving
  1595.   #-----------------------------------------------------------------------------
  1596.   def self.mouse_moving?
  1597.     return IsMouseMoving.call != 0
  1598.   end
  1599.   #-----------------------------------------------------------------------------
  1600.   # * Mouse Wheel is Moving
  1601.   #-----------------------------------------------------------------------------
  1602.   def self.mouse_wheel?
  1603.     return IsWheelMoved.call != 0
  1604.   end
  1605.   #-----------------------------------------------------------------------------
  1606.   # * Mouse Wheel Amount
  1607.   #-----------------------------------------------------------------------------
  1608.   def self.wheel_delta
  1609.     return GetWheelDelta.call / 120
  1610.   end
  1611.   #-----------------------------------------------------------------------------
  1612.   # * Four Direction Check
  1613.   #-----------------------------------------------------------------------------
  1614.   def self.dir4
  1615.     return 2 if self.press?(DOWN)
  1616.     return 4 if self.press?(LEFT)
  1617.     return 6 if self.press?(RIGHT)
  1618.     return 8 if self.press?(UP)
  1619.     return 0
  1620.   end
  1621.   #-----------------------------------------------------------------------------
  1622.   # * Eight Direction Check
  1623.   #-----------------------------------------------------------------------------
  1624.   def self.dir8
  1625.     down = self.press?(DOWN)
  1626.     left = self.press?(LEFT)
  1627.     return 1 if down && left
  1628.     right = self.press?(RIGHT)
  1629.     return 3 if down && right
  1630.     up = self.press?(UP)
  1631.     return 7 if up && left
  1632.     return 9 if up && right
  1633.     return 2 if down
  1634.     return 4 if left
  1635.     return 6 if right
  1636.     return 8 if up
  1637.     return 0
  1638.   end
  1639. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement