设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3121|回复: 5
打印 上一主题 下一主题

求汉化 位图显示功能增强[汉化中]

 关闭 [复制链接]

Lv2.观梦者

天仙

梦石
0
星屑
610
在线时间
184 小时
注册时间
2008-4-15
帖子
5023

贵宾

跳转到指定楼层
1
发表于 2008-11-22 14:15:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
http://f44.aaa.livedoor.jp/~ytomy/tkool/rpgtech/php/tech.php?tool=VX&cat=tech_xp/draw_function&tech=bitmap_extension

日语的,懒得用翻译引擎慢慢去猜他的意思

看截图效果很华丽,但是说明看不明白







自己接了{/gg}
需要 dll
http://rpg.blue/upload_program/d/snstar2006_trgssex_107794431.rar

  1. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  2. #_/    ◆ Bitmap 扩张 - KGC_BitmapExtension ◆ XP/VX ◆
  3. #_/    ◇ Last update : 2008/11/16 ◇
  4. #_/----------------------------------------------------------------------------
  5. #_/  Bitmap 类描画功能增强。
  6. #_/  XP/VX 通用脚本
  7. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

  8. =begin
  9. 增强 Bitmap 类的绘制,增摘了下列功能:

  10.      * 位图操作
  11.            o SRCCOPY, SRCPAINT, 等七种操作方式
  12.      * 特殊合成
  13.            o 加法
  14.            o 减法
  15.            o 乘法
  16.            o 高光
  17.      * 裁减
  18.            o 矩形
  19.            o 圆角矩形
  20.            o 椭圆(包含圆形)
  21.            o 星形
  22.            o 复合型
  23.      * 位图保存
  24.        ※ alpha 通道会被舍弃

  25. XP 和 VX通用

  26. ━━━━━ 使用方法 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  27. ──── Class - Bitmap ────────────────────────────
  28. rop_blt(x, y, src_bitmap, src_rect[, rop])
  29.   x, y       : 描画的 X, Y 座标
  30.   src_bitmap : 描画的 Bitmap
  31.   src_rect   : src_bitmap 传送范围
  32.   rop        : 位图操作
  33.                SRCCOPY, SRCPAINT, SRCAND, SRCINVERT, SRCERASE,
  34.                NOTSRCCOPY, NOTSRCERASE
  35.                (默认: SRCCOPY)

  36.   rop 就是指定位图描绘的方式。

  37. --------------------------------------------------------------------------------
  38. blend_blt(x, y, src_bitmap, src_rect[, blend_type])
  39.   x, y       : 描画的 X, Y 座标
  40.   src_bitmap : 描画的 Bitmap
  41.   src_rect   : src_bitmap 传送范围
  42.   blend_type : 合成方式
  43.                BLEND_NORMAL, BLEND_ADD, BLEND_SUB, BLEND_MUL, BLEND_HILIGHT
  44.                (默认 : BLEND_NORMAL)

  45. blend+type 就是指定描绘 src_bitmap 的合成方式。

  46. --------------------------------------------------------------------------------
  47. clip_blt(x, y, src_bitmap, src_rect, region)
  48.   x, y       : 描画的 X, Y 座标
  49.   src_bitmap : 描画的 Bitmap
  50.   src_rect   : src_bitmap 传送范围
  51.   region     : 执行裁剪的区域 (Region)

  52. region 指定裁剪并描绘 src_bitmap 的区域和形状。

  53. --------------------------------------------------------------------------------
  54. save(filename)
  55.   filename : 保存文件名

  56. 保存为 bitmap 格式。


  57. ━━━━━ 使用方法 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  58. Region

  59. 各种形状区域的超级类。

  60. --------------------------------------------------------------------------------
  61. RectRegion < Region

  62.     - 构造符 -
  63.   (x, y, width, height)
  64.   (rect)

  65.     - 公开成员 -
  66.   x, y, width, height : 矩形的位置和大小

  67. 矩形区域
  68. 指定一个矩形的绘制范围。

  69. --------------------------------------------------------------------------------
  70. RoundRectRegion < RectRegion

  71.     - 构造符 -
  72.   (x, y, width, height[, width_ellipse[, height_ellipse]])
  73.     width_ellipse  : 圆角宽度
  74.     height_ellipse : 圆角高度
  75.   (rect[, width_ellipse[, height_ellipse]])

  76.     - 公开成员 -
  77.   RectRegion 的公开成员
  78.   width_ellipse, height_ellipse : 圆角宽、高度

  79. 圆角矩形区域
  80. 指定一个圆角矩形的绘制范围。

  81. --------------------------------------------------------------------------------
  82. EllipticRegion < RectRegion

  83.     - 构造符 -
  84.   (x, y, width, height)
  85.   (rect)

  86.     - 公开成员 -
  87.   RectRegion 的公开成员

  88. 椭圆形区域
  89. 指定一个椭圆形的绘制范围。

  90. --------------------------------------------------------------------------------
  91. CircularRegion < EllipticRegion

  92.     - 构造符 -
  93.   (x, y, radius)
  94.     x, y   : 原心座標
  95.     radius : 半径

  96.     - 公开成员 -
  97.   x, y, radius : 原心与半径

  98. 圆形区域
  99. 指定一个圆形的绘制范围。

  100. --------------------------------------------------------------------------------
  101. PolygonRegion < Region

  102.     - 构造符 -
  103.   (point1, point2, ...)
  104.     point : [x, y] 形式的座标

  105.     - 公开成员 -
  106.   points    : [x, y] 形式的座標
  107.   fill_mode : 多边形充填形式
  108.                 ALTERNATE : 奇数番目の線分と偶数番目の線分の間の領域のみ
  109.                 WINDING   : すべて線分の間の領域
  110.               初始值为 WINDING

  111. 多边形区域
  112. 由指定座标所连结而成的多边行描绘范围。

  113. --------------------------------------------------------------------------------
  114. StarRegion < PolygonRegion

  115.     - 构造符 -
  116.   (x, y, width, height[, angle])
  117.   (region[, angle])
  118.     region : Rect, RectRegion, EllipticRegion, CircularRegion のいずれか
  119.     angle  : 開始角度 (省略時 : 0)

  120.     - 公开成员 -
  121.   fill_mode           : 与 PolygonRegion 一样
  122.   x, y, width, height : 基准矩形
  123.   angle               : 开始角度 (0 ~ 359)

  124. 星形区域
  125. 由与基准矩形内切的椭圆形形成的星形描绘范围。

  126. --------------------------------------------------------------------------------
  127. CombinedRegion < Region

  128. 複合リージョンです。
  129. リージョン r1, r2 に対する以下の二項演算によって生成されます。

  130.   r1 & r2 : r1 与 r2 之積 (共通部分)
  131.   r1 * r2 : r1 与 r2 之積
  132.   r1 | r2 : r1 与 r2 之和 (双方的总和)
  133.   r1 + r2 : r1 与 r2 之和
  134.   r1 ^ r2 : r1 与 r2 之排他的論理和 (片方のみに存在する領域をとる)
  135.   r1 - r2 : r1 与 r2 之差 (除去共通部分)

  136. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  137. =end

  138. $imported = {} if $imported == nil
  139. $imported["BitmapExtension"] = true

  140. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  141. #==============================================================================
  142. # □ TRGSSEx
  143. #------------------------------------------------------------------------------
  144. #   "TRGSSEx.dll" の機能を扱うモジュールです。
  145. #==============================================================================

  146. module TRGSSEx
  147.   # 合成タイプ
  148.   BLEND_NORMAL  = 0  # 通常
  149.   BLEND_ADD     = 1  # 加算
  150.   BLEND_SUB     = 2  # 減算
  151.   BLEND_MUL     = 3  # 乗算
  152.   BLEND_HILIGHT = 4  # 覆い焼き

  153.   # ラスタオペレーションコード
  154.   SRCCOPY     = 0x00CC0020  # dest = src
  155.   SRCPAINT    = 0x00EE0086  # dest = dest | src
  156.   SRCAND      = 0x008800C6  # dest = dest & src
  157.   SRCINVERT   = 0x00660046  # dest = dest ^ src
  158.   SRCERASE    = 0x00440328  # dest = dest & ~src
  159.   NOTSRCCOPY  = 0x00330008  # dest = ~src
  160.   NOTSRCERASE = 0x001100A6  # dest = ~(dest | src) = ~dest & ~src

  161.   DLL_NAME = 'TRGSSEx'
  162.   begin
  163.     NO_TRGSS_EX = false
  164.     @@_trgss_ex_version =
  165.       Win32API.new(DLL_NAME, 'DllGetVersion', 'v', 'l')
  166.     @@_trgss_ex_rop_blt =
  167.       Win32API.new(DLL_NAME, 'RopBlt', 'pllllplll', 'l')
  168.     @@_trgss_ex_clip_blt =
  169.       Win32API.new(DLL_NAME, 'ClipBlt', 'pllllplll', 'l')
  170.     @@_trgss_ex_blend_blt =
  171.       Win32API.new(DLL_NAME, 'BlendBlt', 'pllllplll', 'l')
  172.     @@_trgss_ex_save_to_bitmap =
  173.       Win32API.new(DLL_NAME, 'SaveToBitmapA', 'pp', 'l')
  174.   rescue
  175.     NO_TRGSS_EX = true
  176.   end

  177.   module_function
  178.   #--------------------------------------------------------------------------
  179.   # ○ バージョン取得
  180.   #     (<例> 1.23 → 123)
  181.   #--------------------------------------------------------------------------
  182.   def version
  183.     return -1 if NO_TRGSS_EX

  184.     return @@_trgss_ex_version.call
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # ○ BitBltRop
  188.   #--------------------------------------------------------------------------
  189.   def rop_blt(dest_info, dx, dy, dw, dh, src_info, sx, sy, rop)
  190.     return @@_trgss_ex_rop_blt.call(dest_info, dx, dy, dw, dh,
  191.       src_info, sx, sy, rop)
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # ○ ClipBlt
  195.   #--------------------------------------------------------------------------
  196.   def clip_blt(dest_info, dx, dy, dw, dh, src_info, sx, sy, hRgn)
  197.     return @@_trgss_ex_clip_blt.call(dest_info, dx, dy, dw, dh,
  198.       src_info, sx, sy, hRgn)
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # ○ BlendBlt
  202.   #--------------------------------------------------------------------------
  203.   def blend_blt(dest_info, dx, dy, dw, dh, src_info, sx, sy, blend)
  204.     return @@_trgss_ex_blend_blt.call(dest_info, dx, dy, dw, dh,
  205.       src_info, sx, sy, blend)
  206.   end
  207.   #--------------------------------------------------------------------------
  208.   # ○ SaveToBitmapA
  209.   #--------------------------------------------------------------------------
  210.   def save_to_bitmap(filename, info)
  211.     return @@_trgss_ex_save_to_bitmap.call(filename, info)
  212.   end
  213. end

  214. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  215. #==============================================================================
  216. # ■ Bitmap
  217. #==============================================================================

  218. class Bitmap
  219.   #--------------------------------------------------------------------------
  220.   # ○ ビットマップ情報 (object_id, width, height) の pack を取得
  221.   #--------------------------------------------------------------------------
  222.   def get_base_info
  223.     return [object_id, width, height].pack('l3')
  224.   end
  225.   #--------------------------------------------------------------------------
  226.   # ○ ラスタオペレーションを使用して描画
  227.   #     rop : ラスタオペレーションコード
  228.   #--------------------------------------------------------------------------
  229.   def rop_blt(x, y, src_bitmap, src_rect, rop = TRGSSEx::SRCCOPY)
  230.     return -1 if TRGSSEx::NO_TRGSS_EX

  231.     return TRGSSEx.rop_blt(get_base_info,
  232.       x, y, src_rect.width, src_rect.height,
  233.       src_bitmap.get_base_info, src_rect.x, src_rect.y, rop)
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   # ○ クリッピング描画
  237.   #     region : リージョン
  238.   #--------------------------------------------------------------------------
  239.   def clip_blt(x, y, src_bitmap, src_rect, region)
  240.     return -1 if TRGSSEx::NO_TRGSS_EX

  241.     hRgn = region.create_region_handle
  242.     return if hRgn == nil || hRgn == 0

  243.     result = TRGSSEx.clip_blt(get_base_info,
  244.       x, y, src_rect.width, src_rect.height,
  245.       src_bitmap.get_base_info, src_rect.x, src_rect.y, hRgn)
  246.     # 後始末
  247.     Region.delete_region_handles

  248.     return result
  249.   end
  250.   #--------------------------------------------------------------------------
  251.   # ○ ブレンド描画
  252.   #     blend : ブレンドタイプ
  253.   #--------------------------------------------------------------------------
  254.   def blend_blt(x, y, src_bitmap, src_rect, blend = TRGSSEx::BLEND_NORMAL)
  255.     return -1 if TRGSSEx::NO_TRGSS_EX

  256.     return TRGSSEx.blend_blt(get_base_info,
  257.       x, y, src_rect.width, src_rect.height,
  258.       src_bitmap.get_base_info, src_rect.x, src_rect.y, blend)
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # ○ 保存
  262.   #     filename : 保存先
  263.   #--------------------------------------------------------------------------
  264.   def save(filename)
  265.     return -1 if TRGSSEx::NO_TRGSS_EX

  266.     return TRGSSEx.save_to_bitmap(filename, get_base_info)
  267.   end
  268. end

  269. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  270. #==============================================================================
  271. # □ Region
  272. #------------------------------------------------------------------------------
  273. #   クリッピング用のリージョンを扱うクラスです。
  274. #==============================================================================

  275. class Region
  276.   #--------------------------------------------------------------------------
  277.   # ○ クラス変数
  278.   #--------------------------------------------------------------------------
  279.   @@handles = []  # 生成したリージョンハンドル
  280.   #--------------------------------------------------------------------------
  281.   # ○ Win32API
  282.   #--------------------------------------------------------------------------
  283.   @@_api_delete_object = Win32API.new('gdi32', 'DeleteObject', 'l', 'l')
  284.   #--------------------------------------------------------------------------
  285.   # ○ リージョンハンドル生成
  286.   #--------------------------------------------------------------------------
  287.   def create_region_handle
  288.     # 継承先で再定義
  289.     return 0
  290.   end
  291.   #--------------------------------------------------------------------------
  292.   # ○ AND (&)
  293.   #--------------------------------------------------------------------------
  294.   def &(obj)
  295.     return nil unless obj.is_a?(Region)
  296.     return CombinedRegion.new(CombinedRegion::RGN_AND, self, obj)
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # ○ AND (*)
  300.   #--------------------------------------------------------------------------
  301.   def *(obj)
  302.     return self.&(obj)
  303.   end
  304.   #--------------------------------------------------------------------------
  305.   # ○ OR (|)
  306.   #--------------------------------------------------------------------------
  307.   def |(obj)
  308.     return nil unless obj.is_a?(Region)
  309.     return CombinedRegion.new(CombinedRegion::RGN_OR, self, obj)
  310.   end
  311.   #--------------------------------------------------------------------------
  312.   # ○ OR (+)
  313.   #--------------------------------------------------------------------------
  314.   def +(obj)
  315.     return self.|(obj)
  316.   end
  317.   #--------------------------------------------------------------------------
  318.   # ○ XOR (^)
  319.   #--------------------------------------------------------------------------
  320.   def ^(obj)
  321.     return nil unless obj.is_a?(Region)
  322.     return CombinedRegion.new(CombinedRegion::RGN_XOR, self, obj)
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # ○ DIFF (-)
  326.   #--------------------------------------------------------------------------
  327.   def -(obj)
  328.     return nil unless obj.is_a?(Region)
  329.     return CombinedRegion.new(CombinedRegion::RGN_DIFF, self, obj)
  330.   end

  331.   #--------------------------------------------------------------------------
  332.   # ○ リージョンハンドル破棄
  333.   #--------------------------------------------------------------------------
  334.   def self.delete_region_handles
  335.     @@handles.uniq!
  336.     @@handles.each { |h| @@_api_delete_object.call(h) }
  337.     @@handles.clear
  338.   end
  339. end

  340. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  341. #==============================================================================
  342. # □ RectRegion
  343. #------------------------------------------------------------------------------
  344. #   矩形リージョンを扱うクラスです。
  345. #==============================================================================

  346. class RectRegion < Region
  347.   #--------------------------------------------------------------------------
  348.   # ○ 公開インスタンス変数
  349.   #--------------------------------------------------------------------------
  350.   attr_accessor :x               # X 座標
  351.   attr_accessor :y               # Y 座標
  352.   attr_accessor :width           # 幅
  353.   attr_accessor :height          # 高さ
  354.   #--------------------------------------------------------------------------
  355.   # ○ Win32API
  356.   #--------------------------------------------------------------------------
  357.   @@_api_create_rect_rgn = Win32API.new('gdi32',
  358.     'CreateRectRgn', 'llll', 'l')
  359.   @@_api_create_rect_rgn_indirect = Win32API.new('gdi32',
  360.     'CreateRectRgnIndirect', 'l', 'l')
  361.   #--------------------------------------------------------------------------
  362.   # ○ オブジェクト初期化
  363.   #--------------------------------------------------------------------------
  364.   def initialize(*args)
  365.     if args[0].is_a?(Rect)
  366.       rect = args[0]
  367.       @x = rect.x
  368.       @y = rect.y
  369.       @width  = rect.width
  370.       @height = rect.height
  371.     else
  372.       @x, @y, @width, @height = args
  373.     end
  374.   end
  375.   #--------------------------------------------------------------------------
  376.   # ○ リージョンハンドル生成
  377.   #--------------------------------------------------------------------------
  378.   def create_region_handle
  379.     hRgn = @@_api_create_rect_rgn.call(@x, @y, @x + @width, @y + @height)
  380.     @@handles << hRgn
  381.     return hRgn
  382.   end
  383. end

  384. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  385. #==============================================================================
  386. # □ RoundRectRegion
  387. #------------------------------------------------------------------------------
  388. #   角丸矩形リージョンを扱うクラスです。
  389. #==============================================================================

  390. class RoundRectRegion < RectRegion
  391.   #--------------------------------------------------------------------------
  392.   # ○ 公開インスタンス変数
  393.   #--------------------------------------------------------------------------
  394.   attr_accessor :width_ellipse   # 丸みの幅
  395.   attr_accessor :height_ellipse  # 丸みの高さ
  396.   #--------------------------------------------------------------------------
  397.   # ○ Win32API
  398.   #--------------------------------------------------------------------------
  399.   @@_api_create_round_rect_rgn = Win32API.new('gdi32',
  400.     'CreateRoundRectRgn', 'llllll', 'l')
  401.   #--------------------------------------------------------------------------
  402.   # ○ オブジェクト初期化
  403.   #--------------------------------------------------------------------------
  404.   def initialize(*args)
  405.     super
  406.     if args[0].is_a?(Rect)
  407.       @width_ellipse  = args[1]
  408.       @height_ellipse = args[2]
  409.     else
  410.       @width_ellipse  = args[4]
  411.       @height_ellipse = args[5]
  412.     end
  413.   end
  414.   #--------------------------------------------------------------------------
  415.   # ○ リージョンハンドル生成
  416.   #--------------------------------------------------------------------------
  417.   def create_region_handle
  418.     hRgn = @@_api_create_round_rect_rgn.call(@x, @y, @x + @width, @y + @height,
  419.       width_ellipse, height_ellipse)
  420.     @@handles << hRgn
  421.     return hRgn
  422.   end
  423. end

  424. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  425. #==============================================================================
  426. # □ EllipticRegion
  427. #------------------------------------------------------------------------------
  428. #   楕円形リージョンを扱うクラスです。
  429. #==============================================================================

  430. class EllipticRegion < RectRegion
  431.   #--------------------------------------------------------------------------
  432.   # ○ Win32API
  433.   #--------------------------------------------------------------------------
  434.   @@_api_create_elliptic_rgn = Win32API.new('gdi32',
  435.     'CreateEllipticRgn', 'llll', 'l')
  436.   @@_api_create_elliptic_rgn_indirect = Win32API.new('gdi32',
  437.     'CreateEllipticRgnIndirect', 'l', 'l')
  438.   #--------------------------------------------------------------------------
  439.   # ○ リージョンハンドル生成
  440.   #--------------------------------------------------------------------------
  441.   def create_region_handle
  442.     hRgn = @@_api_create_elliptic_rgn.call(@x, @y, @x + @width, @y + @height)
  443.     @@handles << hRgn
  444.     return hRgn
  445.   end
  446. end

  447. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  448. #==============================================================================
  449. # □ CircularRegion
  450. #------------------------------------------------------------------------------
  451. #   円形リージョンを扱うクラスです。
  452. #==============================================================================

  453. class CircularRegion < EllipticRegion
  454.   #--------------------------------------------------------------------------
  455.   # ○ 公開インスタンス変数
  456.   #--------------------------------------------------------------------------
  457.   attr_reader   :radius  # 半径
  458.   #--------------------------------------------------------------------------
  459.   # ○ オブジェクト初期化
  460.   #--------------------------------------------------------------------------
  461.   def initialize(x, y, r)
  462.     @cx = x
  463.     @cy = y
  464.     @radius = r
  465.     super(@cx - r, @cy - r, r * 2, r * 2)
  466.   end
  467.   #--------------------------------------------------------------------------
  468.   # ○ 中心 X 座標参照
  469.   #--------------------------------------------------------------------------
  470.   def x
  471.     return @cx
  472.   end
  473.   #--------------------------------------------------------------------------
  474.   # ○ 中心 Y 座標参照
  475.   #--------------------------------------------------------------------------
  476.   def y
  477.     return @cy
  478.   end
  479.   #--------------------------------------------------------------------------
  480.   # ○ 中心 X 座標変更
  481.   #--------------------------------------------------------------------------
  482.   def x=(value)
  483.     @cx = value
  484.     @x = @cx - radius
  485.   end
  486.   #--------------------------------------------------------------------------
  487.   # ○ 中心 Y 座標変更
  488.   #--------------------------------------------------------------------------
  489.   def y=(value)
  490.     @cy = value
  491.     @y = @cy - radius
  492.   end
  493.   #--------------------------------------------------------------------------
  494.   # ○ 半径変更
  495.   #--------------------------------------------------------------------------
  496.   def radius=(value)
  497.     @radius = value
  498.     @x = @cx - @radius
  499.     @y = @cy - @radius
  500.     @width = @height = @radius * 2
  501.   end
  502. end

  503. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  504. #==============================================================================
  505. # □ PolygonRegion
  506. #------------------------------------------------------------------------------
  507. #   多角形リージョンを扱うクラスです。
  508. #==============================================================================

  509. class PolygonRegion < Region
  510.   #--------------------------------------------------------------------------
  511.   # ○ 定数
  512.   #--------------------------------------------------------------------------
  513.   # 多角形充填形式
  514.   ALTERNATE = 1  # 交互モード
  515.   WINDING   = 2  # 螺旋モード
  516.   #--------------------------------------------------------------------------
  517.   # ○ 公開インスタンス変数
  518.   #--------------------------------------------------------------------------
  519.   attr_accessor :points     # 頂点座標 [x, y] の配列
  520.   attr_accessor :fill_mode  # 多角形充填形式
  521.   #--------------------------------------------------------------------------
  522.   # ○ Win32API
  523.   #--------------------------------------------------------------------------
  524.   @@_api_create_polygon_rgn = Win32API.new('gdi32',
  525.     'CreatePolygonRgn', 'pll', 'l')
  526.   @@_api_create_polypolygon_rgn = Win32API.new('gdi32',
  527.     'CreatePolyPolygonRgn', 'llll', 'l')
  528.   #--------------------------------------------------------------------------
  529.   # ○ オブジェクト初期化
  530.   #--------------------------------------------------------------------------
  531.   def initialize(*points)
  532.     @points = points  # [x, y] の配列
  533.     @fill_mode = WINDING
  534.   end
  535.   #--------------------------------------------------------------------------
  536.   # ○ リージョンハンドル生成
  537.   #--------------------------------------------------------------------------
  538.   def create_region_handle
  539.     pts = ""
  540.     points.each { |pt| pts += pt.pack("ll") }
  541.     hRgn = @@_api_create_polygon_rgn.call(pts, points.size, fill_mode)
  542.     @@handles << hRgn
  543.     return hRgn
  544.   end
  545. end

  546. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  547. #==============================================================================
  548. # □ StarRegion
  549. #------------------------------------------------------------------------------
  550. #   星型リージョンを扱うクラスです。
  551. #==============================================================================

  552. class StarRegion < PolygonRegion
  553.   #--------------------------------------------------------------------------
  554.   # ○ 定数
  555.   #--------------------------------------------------------------------------
  556.   POINT_NUM = 5               # 点数
  557.   PI_4      = 4.0 * Math::PI  # 4 * Pi
  558.   #--------------------------------------------------------------------------
  559.   # ○ 公開インスタンス変数
  560.   #--------------------------------------------------------------------------
  561.   attr_reader   :x               # X 座標
  562.   attr_reader   :y               # Y 座標
  563.   attr_reader   :width           # 幅
  564.   attr_reader   :height          # 高さ
  565.   attr_reader   :angle           # 開始角度 (0 ~ 359)
  566.   #--------------------------------------------------------------------------
  567.   # ○ オブジェクト初期化
  568.   #--------------------------------------------------------------------------
  569.   def initialize(*args)
  570.     super()
  571.     shape = args[0]
  572.     ang = args[1]
  573.     case shape
  574.     when CircularRegion
  575.       @x = shape.x - shape.radius
  576.       @y = shape.y - shape.radius
  577.       @width = @height = shape.radius * 2
  578.     when Rect, RectRegion, EllipticRegion
  579.       @x = shape.x
  580.       @y = shape.y
  581.       @width  = shape.width
  582.       @height = shape.height
  583.     when Integer
  584.       @x, @y, @width, @height = args
  585.       ang = args[4]
  586.     else
  587.       @x = @y = @width = @height = 0
  588.     end
  589.     @angle = (ang == nil ? 0 : ang) % 360
  590.     @points = create_star_points
  591.   end
  592.   #--------------------------------------------------------------------------
  593.   # ○ 星型座標を生成
  594.   #--------------------------------------------------------------------------
  595.   def create_star_points
  596.     dw = (width + 1) / 2
  597.     dh = (height + 1) / 2
  598.     dx = x + dw
  599.     dy = y + dh
  600.     base_angle = angle * Math::PI / 180.0
  601.     pts = []
  602.     POINT_NUM.times { |i|
  603.       ang = base_angle + PI_4 * i / POINT_NUM
  604.       pts << [dx + (Math.sin(ang) * dw).to_i,
  605.         dy - (Math.cos(ang) * dh).to_i]
  606.     }
  607.     return pts
  608.   end
  609.   #--------------------------------------------------------------------------
  610.   # ○ X 座標変更
  611.   #--------------------------------------------------------------------------
  612.   def x=(value)
  613.     @x = value
  614.     @points = create_star_points
  615.   end
  616.   #--------------------------------------------------------------------------
  617.   # ○ Y 座標変更
  618.   #--------------------------------------------------------------------------
  619.   def y=(value)
  620.     @y = value
  621.     @points = create_star_points
  622.   end
  623.   #--------------------------------------------------------------------------
  624.   # ○ 幅変更
  625.   #--------------------------------------------------------------------------
  626.   def width=(value)
  627.     @width = value
  628.     @points = create_star_points
  629.   end
  630.   #--------------------------------------------------------------------------
  631.   # ○ 高さ座標変更
  632.   #--------------------------------------------------------------------------
  633.   def height=(value)
  634.     @height = value
  635.     @points = create_star_points
  636.   end
  637.   #--------------------------------------------------------------------------
  638.   # ○ 開始角度変更
  639.   #--------------------------------------------------------------------------
  640.   def angle=(value)
  641.     @angle = value % 360
  642.     @points = create_star_points
  643.   end
  644. end

  645. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  646. #==============================================================================
  647. # □ CombinedRegion
  648. #------------------------------------------------------------------------------
  649. #   混合リージョンを扱うクラスです。
  650. #==============================================================================

  651. class CombinedRegion < Region
  652.   #--------------------------------------------------------------------------
  653.   # ○ 定数
  654.   #--------------------------------------------------------------------------
  655.   # 合成モード
  656.   RGN_AND  = 1
  657.   RGN_OR   = 2
  658.   RGN_XOR  = 3
  659.   RGN_DIFF = 4
  660.   RGN_COPY = 5
  661.   #--------------------------------------------------------------------------
  662.   # ○ Win32API
  663.   #--------------------------------------------------------------------------
  664.   @@_api_combine_rgn = Win32API.new('gdi32', 'CombineRgn', 'llll', 'l')
  665.   #--------------------------------------------------------------------------
  666.   # ○ オブジェクト初期化
  667.   #--------------------------------------------------------------------------
  668.   def initialize(mode, region1, region2)
  669.     @exp = CombinedRegionExp.new(mode, region1.clone, region2.clone)
  670.   end
  671.   #--------------------------------------------------------------------------
  672.   # ○ リージョンハンドル生成
  673.   #--------------------------------------------------------------------------
  674.   def create_region_handle
  675.     return combine_region(@exp.region1, @exp.region2, @exp.mode)
  676.   end
  677.   #--------------------------------------------------------------------------
  678.   # ○ リージョン合成
  679.   #     dest : 合成先
  680.   #     src  : 合成元
  681.   #     mode : 合成モード
  682.   #--------------------------------------------------------------------------
  683.   def combine_region(dest, src, mode)
  684.     hdest = dest.create_region_handle
  685.     hsrc  = src.create_region_handle
  686.     @@_api_combine_rgn.call(hdest, hdest, hsrc, mode)
  687.     return hdest
  688.   end
  689.   protected :combine_region
  690. end

  691. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

  692. #==============================================================================
  693. # □ Struct
  694. #==============================================================================

  695. # □ CombinedRegionExp 構造体
  696. CombinedRegionExp = Struct.new("CombinedRegionExp", :mode, :region1, :region2)
复制代码
VA脚本开工中...
偷窃脚本1.0 - 已完成

Lv1.梦旅人

敌敌畏

梦石
0
星屑
80
在线时间
52 小时
注册时间
2008-5-12
帖子
1748
2
发表于 2008-11-22 16:35:04 | 只看该作者
先毫不犹豫的抱下来,据说约束桑在holiday,你要等几天了
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
46
在线时间
10 小时
注册时间
2007-5-27
帖子
2558

第1届Title华丽大赛新人奖

3
发表于 2008-11-22 19:09:22 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复 支持 反对

使用道具 举报

Lv1.梦旅人

星辰创始

梦石
0
星屑
55
在线时间
154 小时
注册时间
2008-3-8
帖子
611
4
发表于 2008-11-22 20:09:40 | 只看该作者
前几天在QQ上问了下,好像KISS姐在研究这些东西
回复 支持 反对

使用道具 举报

Lv3.寻梦者 (暗夜天使)

名侦探小柯

梦石
0
星屑
3263
在线时间
3616 小时
注册时间
2006-9-6
帖子
37399

开拓者贵宾第3届短篇游戏大赛主流游戏组亚军第5届短篇游戏比赛亚军

5
发表于 2008-11-22 20:11:08 | 只看该作者
这效果真的很不错。
回复 支持 反对

使用道具 举报

Lv2.观梦者

天仙

梦石
0
星屑
610
在线时间
184 小时
注册时间
2008-4-15
帖子
5023

贵宾

6
 楼主| 发表于 2008-11-22 21:45:58 | 只看该作者
以下引用偶尔杀人越货于2008-11-22 8:35:04的发言:
先毫不犹豫的抱下来,据说约束桑在holiday,你要等几天了

那还是我来吧
VA脚本开工中...
偷窃脚本1.0 - 已完成
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-3 10:59

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表