#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ #_/ ◆ Bitmap Extension - KGC_BitmapExtension ◆ XP/VX ◆ #_/ ◇ Last Update: 11/22/2008 #_/ ◆ Written by TOMY #_/ ◆ Translation by Mr. Anonymous #_/ ◆ KGC Site: #_/ ◆ http://ytomy.sakura.ne.jp/ #_/ ◆ Translator's Blog: #_/ ◆ http://mraprojects.wordpress.com #_/---------------------------------------------------------------------------- #_/ This script adds additional drawing functions to the Bitmap class. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ =begin ==== Methods =================================== ──── Class - Bitmap ──────────────────────────── rop_blt(x, y, src_bitmap, src_rect[, rop]) x, y : Draw at X, Y coordinates src_bitmap : Draw Bitmap src_rect : src_bitmap transfer range rop : Raster Operation Code SRCCOPY, SRCPAINT, SRCAND, SRCINVERT, SRCERASE, NOTSRCCOPY, NOTSRCERASE (Default : SRCCOPY) Raster src_bitmap then draw bitmap. -------------------------------------------------------------------------------- blend_blt(x, y, src_bitmap, src_rect[, blend_type]) x, y : Draw at X, Y Coordiates src_bitmap : Draw Bitmap src_rect : src_bitmap transfer range blend_type : Blending type BLEND_NORMAL, BLEND_ADD, BLEND_SUB, BLEND_MUL, BLEND_HILIGHT (Default : BLEND_NORMAL) Change src_bitmap blending type then draw bitmap. -------------------------------------------------------------------------------- clip_blt(x, y, src_bitmap, src_rect, region) x, y : Draw at X, Y Coordinates src_bitmap : Drawn Bitmap src_rect : src_bitmap transfer range region : Create cropping region Crop src_bitmap by region then draw bitmap. -------------------------------------------------------------------------------- save(filename) filename : Filename output Save bitmap output to given filename. When saved, the alpha channel is removed. ==== Classes =================================== Region This is the superclass of various regions. -------------------------------------------------------------------------------- RectRegion < Region - Constructors - (x, y, width, height) (rect) - Public Members - x, y, width, height : Rectangle Size This is a rectangular region. It draws a rectangle itself within the specified range. -------------------------------------------------------------------------------- RoundRectRegion < RectRegion - Constructors - (x, y, width, height[, width_ellipse[, height_ellipse]]) width_ellipse : Rounded corner width height_ellipse : Rounded corner height (rect[, width_ellipse[, height_ellipse]]) - Public Members - Public members of RectRegion width_ellipse, height_ellipse : rounded corner Rounded corner is a rectangular region. Drawing is rounded to the angle range of the specified rectangle. -------------------------------------------------------------------------------- EllipticRegion < RectRegion - Constructors - (x, y, width, height) (rect) - Public Members - Public members of the RectRegion This is an elliptical region. The drawing range of an ellipse is specified inside a rectangle. (Note: That may not be entirely correct.) -------------------------------------------------------------------------------- CircularRegion < EllipticRegion - Constructors - (x, y, radius) x, y : Coordinates radius : Radius - Public Members - x, y, radius : Center of the radius This is a circular region. Draws a circle with a specified range of radius. -------------------------------------------------------------------------------- PolygonRegion < Region - Constructors - (point1, point2, ...) point : [x, y] Shape coordinates - Public Members - points : [x, y] Coordinates in listed format fill_mode : Fill polygon shape ALTERNATE : 奇数番目の線分と偶数番目の線分の間の領域のみ Only the area between the odd segments lines and the second lines even(???) WINDING : Between all segments of the region The default is WINDING This is a polygonal region. The polygon connects to the coordinates lists draws between the range. -------------------------------------------------------------------------------- StarRegion < PolygonRegion - Constructors - (x, y, width, height[, angle]) (region[, angle]) region : Rect, RectRegion, EllipticRegion, CircularRegion のいずれか angle : Starting angle (Default : 0) - Public Members - fill_mode : Fill PolygonRegion x, y, width, height : Rectangle base angle : Rotation angle (0 ~ 359) This is a star-shaped region. The star is inscribed to the range of an ellipse and a base rectagle which becomes its drawing range.(???) Rotation is clockwise. -------------------------------------------------------------------------------- PieRegion < Region - Constructors - (region, start_angle, sweep_angle) region : Base CircularRegion start_angle : Starting angle sweep_angle : Drawing angle (-360 ~ 360) - Public Members - x, y, radius : Radius of the center start_angle : Starting angle sweep_angle : Drawing angle (-360 ~ 360) This is a sectorial region.(???) The drawing angle ends at the range of drawing from the starting base angle. The starting angle is 0. It can also be specified as a negative number to begin on the right side (clockwise). -------------------------------------------------------------------------------- CombinedRegion < Region This is a complex region. Region r1, r2 are generated by operations for the following two paragraphs... r1 & r2 r1 * r2 Product of r1 and r2 (A common of r1 and r2 part is taken). r1 | r2 r1 + r2 Sum of r1 and r2 (R1 and the entire r2 are taken). r1 ^ r2 Exclusive (OR) r1 and r2 (The area that exists only in one is taken). r1 - r2 Difference between r1 and r2 (The area where r2 overlaps r1 is removed). #-------------------------------------------------------------------------- =end $imported = {} if $imported == nil $imported["BitmapExtension"] = true ##-------------------------------------------------------------------------- #============================================================================== # □ TRGSSEx #------------------------------------------------------------------------------ # "TRGSSEx.dll" の機能を扱うモジュールです。 #============================================================================== module TRGSSEx # 合成タイプ BLEND_NORMAL = 0 # 通常 BLEND_ADD = 1 # 加算 BLEND_SUB = 2 # 減算 BLEND_MUL = 3 # 乗算 BLEND_HILIGHT = 4 # 覆い焼き # ラスタオペレーションコード SRCCOPY = 0x00CC0020 # dest = src SRCPAINT = 0x00EE0086 # dest = dest | src SRCAND = 0x008800C6 # dest = dest & src SRCINVERT = 0x00660046 # dest = dest ^ src SRCERASE = 0x00440328 # dest = dest & ~src NOTSRCCOPY = 0x00330008 # dest = ~src NOTSRCERASE = 0x001100A6 # dest = ~(dest | src) = ~dest & ~src DLL_NAME = 'TRGSSEx' begin NO_TRGSS_EX = false @@_trgss_ex_version = Win32API.new(DLL_NAME, 'DllGetVersion', 'v', 'l') @@_trgss_ex_rop_blt = Win32API.new(DLL_NAME, 'RopBlt', 'pllllplll', 'l') @@_trgss_ex_clip_blt = Win32API.new(DLL_NAME, 'ClipBlt', 'pllllplll', 'l') @@_trgss_ex_blend_blt = Win32API.new(DLL_NAME, 'BlendBlt', 'pllllplll', 'l') @@_trgss_ex_save_to_bitmap = Win32API.new(DLL_NAME, 'SaveToBitmapA', 'pp', 'l') rescue NO_TRGSS_EX = true end module_function #-------------------------------------------------------------------------- # ○ バージョン取得 # (<例> 1.23 → 123) #-------------------------------------------------------------------------- def version return -1 if NO_TRGSS_EX return @@_trgss_ex_version.call end #-------------------------------------------------------------------------- # ○ BitBltRop #-------------------------------------------------------------------------- def rop_blt(dest_info, dx, dy, dw, dh, src_info, sx, sy, rop) return @@_trgss_ex_rop_blt.call(dest_info, dx, dy, dw, dh, src_info, sx, sy, rop) end #-------------------------------------------------------------------------- # ○ ClipBlt #-------------------------------------------------------------------------- def clip_blt(dest_info, dx, dy, dw, dh, src_info, sx, sy, hRgn) return @@_trgss_ex_clip_blt.call(dest_info, dx, dy, dw, dh, src_info, sx, sy, hRgn) end #-------------------------------------------------------------------------- # ○ BlendBlt #-------------------------------------------------------------------------- def blend_blt(dest_info, dx, dy, dw, dh, src_info, sx, sy, blend) return @@_trgss_ex_blend_blt.call(dest_info, dx, dy, dw, dh, src_info, sx, sy, blend) end #-------------------------------------------------------------------------- # ○ SaveToBitmapA #-------------------------------------------------------------------------- def save_to_bitmap(filename, info) return @@_trgss_ex_save_to_bitmap.call(filename, info) end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # ■ Bitmap #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ○ ビットマップ情報 (object_id, width, height) の pack を取得 #-------------------------------------------------------------------------- def get_base_info return [object_id, width, height].pack('l3') end #-------------------------------------------------------------------------- # ○ ラスタオペレーションを使用して描画 # rop : ラスタオペレーションコード #-------------------------------------------------------------------------- def rop_blt(x, y, src_bitmap, src_rect, rop = TRGSSEx::SRCCOPY) return -1 if TRGSSEx::NO_TRGSS_EX return TRGSSEx.rop_blt(get_base_info, x, y, src_rect.width, src_rect.height, src_bitmap.get_base_info, src_rect.x, src_rect.y, rop) end #-------------------------------------------------------------------------- # ○ クリッピング描画 # region : リージョン #-------------------------------------------------------------------------- def clip_blt(x, y, src_bitmap, src_rect, region) return -1 if TRGSSEx::NO_TRGSS_EX hRgn = region.create_region_handle return if hRgn == nil || hRgn == 0 result = TRGSSEx.clip_blt(get_base_info, x, y, src_rect.width, src_rect.height, src_bitmap.get_base_info, src_rect.x, src_rect.y, hRgn) # 後始末 Region.delete_region_handles return result end #-------------------------------------------------------------------------- # ○ ブレンド描画 # blend : ブレンドタイプ #-------------------------------------------------------------------------- def blend_blt(x, y, src_bitmap, src_rect, blend = TRGSSEx::BLEND_NORMAL) return -1 if TRGSSEx::NO_TRGSS_EX return TRGSSEx.blend_blt(get_base_info, x, y, src_rect.width, src_rect.height, src_bitmap.get_base_info, src_rect.x, src_rect.y, blend) end #-------------------------------------------------------------------------- # ○ 保存 # filename : 保存先 #-------------------------------------------------------------------------- def save(filename) return -1 if TRGSSEx::NO_TRGSS_EX return TRGSSEx.save_to_bitmap(filename, get_base_info) end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ Region #------------------------------------------------------------------------------ # クリッピング用のリージョンを扱うクラスです。 #============================================================================== class Region #-------------------------------------------------------------------------- # ○ クラス変数 #-------------------------------------------------------------------------- @@handles = [] # 生成したリージョンハンドル #-------------------------------------------------------------------------- # ○ Win32API #-------------------------------------------------------------------------- @@_api_delete_object = Win32API.new('gdi32', 'DeleteObject', 'l', 'l') #-------------------------------------------------------------------------- # ○ リージョンハンドル生成 #-------------------------------------------------------------------------- def create_region_handle # 継承先で再定義 return 0 end #-------------------------------------------------------------------------- # ○ AND (&) #-------------------------------------------------------------------------- def &(obj) return nil unless obj.is_a?(Region) return CombinedRegion.new(CombinedRegion::RGN_AND, self, obj) end #-------------------------------------------------------------------------- # ○ AND (*) #-------------------------------------------------------------------------- def *(obj) return self.&(obj) end #-------------------------------------------------------------------------- # ○ OR (|) #-------------------------------------------------------------------------- def |(obj) return nil unless obj.is_a?(Region) return CombinedRegion.new(CombinedRegion::RGN_OR, self, obj) end #-------------------------------------------------------------------------- # ○ OR (+) #-------------------------------------------------------------------------- def +(obj) return self.|(obj) end #-------------------------------------------------------------------------- # ○ XOR (^) #-------------------------------------------------------------------------- def ^(obj) return nil unless obj.is_a?(Region) return CombinedRegion.new(CombinedRegion::RGN_XOR, self, obj) end #-------------------------------------------------------------------------- # ○ DIFF (-) #-------------------------------------------------------------------------- def -(obj) return nil unless obj.is_a?(Region) return CombinedRegion.new(CombinedRegion::RGN_DIFF, self, obj) end #-------------------------------------------------------------------------- # ○ リージョンハンドル破棄 #-------------------------------------------------------------------------- def self.delete_region_handles @@handles.uniq! @@handles.each { |h| @@_api_delete_object.call(h) } @@handles.clear end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ RectRegion #------------------------------------------------------------------------------ # 矩形リージョンを扱うクラスです。 #============================================================================== class RectRegion < Region #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :x # X 座標 attr_accessor :y # Y 座標 attr_accessor :width # 幅 attr_accessor :height # 高さ #-------------------------------------------------------------------------- # ○ Win32API #-------------------------------------------------------------------------- @@_api_create_rect_rgn = Win32API.new('gdi32', 'CreateRectRgn', 'llll', 'l') @@_api_create_rect_rgn_indirect = Win32API.new('gdi32', 'CreateRectRgnIndirect', 'l', 'l') #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(*args) if args[0].is_a?(Rect) rect = args[0] @x = rect.x @y = rect.y @width = rect.width @height = rect.height else @x, @y, @width, @height = args end end #-------------------------------------------------------------------------- # ○ リージョンハンドル生成 #-------------------------------------------------------------------------- def create_region_handle hRgn = @@_api_create_rect_rgn.call(@x, @y, @x + @width, @y + @height) @@handles << hRgn return hRgn end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ RoundRectRegion #------------------------------------------------------------------------------ # 角丸矩形リージョンを扱うクラスです。 #============================================================================== class RoundRectRegion < RectRegion #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :width_ellipse # 丸みの幅 attr_accessor :height_ellipse # 丸みの高さ #-------------------------------------------------------------------------- # ○ Win32API #-------------------------------------------------------------------------- @@_api_create_round_rect_rgn = Win32API.new('gdi32', 'CreateRoundRectRgn', 'llllll', 'l') #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(*args) super if args[0].is_a?(Rect) @width_ellipse = args[1] @height_ellipse = args[2] else @width_ellipse = args[4] @height_ellipse = args[5] end end #-------------------------------------------------------------------------- # ○ リージョンハンドル生成 #-------------------------------------------------------------------------- def create_region_handle hRgn = @@_api_create_round_rect_rgn.call(@x, @y, @x + @width, @y + @height, width_ellipse, height_ellipse) @@handles << hRgn return hRgn end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ EllipticRegion #------------------------------------------------------------------------------ # 楕円形リージョンを扱うクラスです。 #============================================================================== class EllipticRegion < RectRegion #-------------------------------------------------------------------------- # ○ Win32API #-------------------------------------------------------------------------- @@_api_create_elliptic_rgn = Win32API.new('gdi32', 'CreateEllipticRgn', 'llll', 'l') @@_api_create_elliptic_rgn_indirect = Win32API.new('gdi32', 'CreateEllipticRgnIndirect', 'l', 'l') #-------------------------------------------------------------------------- # ○ リージョンハンドル生成 #-------------------------------------------------------------------------- def create_region_handle hRgn = @@_api_create_elliptic_rgn.call(@x, @y, @x + @width, @y + @height) @@handles << hRgn return hRgn end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ CircularRegion #------------------------------------------------------------------------------ # 円形リージョンを扱うクラスです。 #============================================================================== class CircularRegion < EllipticRegion #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :radius # 半径 #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(x, y, r) @cx = x @cy = y self.radius = r super(@cx - r, @cy - r, r * 2, r * 2) end #-------------------------------------------------------------------------- # ○ 中心 X 座標参照 #-------------------------------------------------------------------------- def x return @cx end #-------------------------------------------------------------------------- # ○ 中心 Y 座標参照 #-------------------------------------------------------------------------- def y return @cy end #-------------------------------------------------------------------------- # ○ 中心 X 座標変更 #-------------------------------------------------------------------------- def x=(value) @cx = value @x = @cx - @radius end #-------------------------------------------------------------------------- # ○ 中心 Y 座標変更 #-------------------------------------------------------------------------- def y=(value) @cy = value @y = @cy - @radius end #-------------------------------------------------------------------------- # ○ 半径変更 #-------------------------------------------------------------------------- def radius=(value) @radius = value @x = @cx - @radius @y = @cy - @radius @width = @height = @radius * 2 end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ PolygonRegion #------------------------------------------------------------------------------ # 多角形リージョンを扱うクラスです。 #============================================================================== class PolygonRegion < Region #-------------------------------------------------------------------------- # ○ 定数 #-------------------------------------------------------------------------- # 多角形充填形式 ALTERNATE = 1 # 交互モード WINDING = 2 # 螺旋モード #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :points # 頂点座標 [x, y] の配列 attr_accessor :fill_mode # 多角形充填形式 #-------------------------------------------------------------------------- # ○ Win32API #-------------------------------------------------------------------------- @@_api_create_polygon_rgn = Win32API.new('gdi32', 'CreatePolygonRgn', 'pll', 'l') @@_api_create_polypolygon_rgn = Win32API.new('gdi32', 'CreatePolyPolygonRgn', 'llll', 'l') #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(*points) @points = points # [x, y] の配列 @fill_mode = WINDING end #-------------------------------------------------------------------------- # ○ リージョンハンドル生成 #-------------------------------------------------------------------------- def create_region_handle pts = "" points.each { |pt| pts += pt.pack("ll") } hRgn = @@_api_create_polygon_rgn.call(pts, points.size, fill_mode) @@handles << hRgn return hRgn end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ StarRegion #------------------------------------------------------------------------------ # 星型リージョンを扱うクラスです。 #============================================================================== class StarRegion < PolygonRegion #-------------------------------------------------------------------------- # ○ 定数 #-------------------------------------------------------------------------- POINT_NUM = 5 # 点数 PI_4 = 4.0 * Math::PI # 4 * Pi #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :x # X 座標 attr_reader :y # Y 座標 attr_reader :width # 幅 attr_reader :height # 高さ attr_reader :angle # 回転角度 (0 ~ 359) #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(*args) super() shape = args[0] ang = args[1] case shape when CircularRegion @x = shape.x - shape.radius @y = shape.y - shape.radius @width = @height = shape.radius * 2 when Rect, RectRegion, EllipticRegion @x = shape.x @y = shape.y @width = shape.width @height = shape.height when Integer @x, @y, @width, @height = args ang = args[4] else @x = @y = @width = @height = 0 end @angle = (ang == nil ? 0 : ang % 360) @__init = true @points = create_star_points end #-------------------------------------------------------------------------- # ○ 星型座標を生成 #-------------------------------------------------------------------------- def create_star_points return unless @__init dw = (width + 1) / 2 dh = (height + 1) / 2 dx = x + dw dy = y + dh base_angle = angle * Math::PI / 180.0 pts = [] POINT_NUM.times { |i| ang = base_angle + PI_4 * i / POINT_NUM pts << [dx + (Math.sin(ang) * dw).to_i, dy - (Math.cos(ang) * dh).to_i] } return pts end #-------------------------------------------------------------------------- # ○ X 座標変更 #-------------------------------------------------------------------------- def x=(value) @x = value @points = create_star_points end #-------------------------------------------------------------------------- # ○ Y 座標変更 #-------------------------------------------------------------------------- def y=(value) @y = value @points = create_star_points end #-------------------------------------------------------------------------- # ○ 幅変更 #-------------------------------------------------------------------------- def width=(value) @width = value @points = create_star_points end #-------------------------------------------------------------------------- # ○ 高さ座標変更 #-------------------------------------------------------------------------- def height=(value) @height = value @points = create_star_points end #-------------------------------------------------------------------------- # ○ 開始角度変更 #-------------------------------------------------------------------------- def angle=(value) @angle = value % 360 @points = create_star_points end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ PieRegion #------------------------------------------------------------------------------ # 扇形リージョンを扱うクラスです。 #============================================================================== class PieRegion < Region #-------------------------------------------------------------------------- # ○ 定数 #-------------------------------------------------------------------------- HALF_PI = Math::PI / 2.0 # PI / 2 #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :begin_angle # 開始角度 [degree] attr_reader :sweep_angle # 描画角度 (0 ~ 359) #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(*args) super() shape = args[0] ang1, ang2 = args[1..2] case shape when CircularRegion @cx = shape.x @cy = shape.y self.radius = shape.radius else @cx = @cy = @x = @y = @radius = 0 end self.start_angle = (ang1 == nil ? 0 : ang1) self.sweep_angle = (ang2 == nil ? 0 : ang2) @__init = true create_pie_region end #-------------------------------------------------------------------------- # ○ 扇形リージョンを生成 #-------------------------------------------------------------------------- def create_pie_region return unless @__init # 座標・範囲調整 st_deg = @start_angle += (@sweep_angle < 0 ? @sweep_angle : 0) st_deg %= 360 ed_deg = st_deg + @sweep_angle.abs diff = st_deg % 90 r = @radius * 3 / 2 s = st_deg / 90 e = ed_deg / 90 # リージョン作成 @region = nil (s..e).each { |i| break if i * 90 >= ed_deg if diff > 0 st_rad = (i * 90 + diff) * Math::PI / 180.0 diff = 0 else st_rad = i * HALF_PI end if (i + 1) * 90 > ed_deg ed_rad = ed_deg * Math::PI / 180.0 else ed_rad = (i + 1) * HALF_PI end pt1 = [@cx, @cy] pt2 = [ @cx + Integer(Math.cos(st_rad) * r), @cy + Integer(Math.sin(st_rad) * r) ] pt3 = [ @cx + Integer(Math.cos(ed_rad) * r), @cy + Integer(Math.sin(ed_rad) * r) ] rgn = PolygonRegion.new(pt1, pt2, pt3) if @region == nil @region = rgn else @region |= rgn end } @region &= CircularRegion.new(@cx, @cy, @radius) return @region end #-------------------------------------------------------------------------- # ○ 中心 X 座標参照 #-------------------------------------------------------------------------- def x return @cx end #-------------------------------------------------------------------------- # ○ 中心 Y 座標参照 #-------------------------------------------------------------------------- def y return @cy end #-------------------------------------------------------------------------- # ○ 中心 X 座標変更 #-------------------------------------------------------------------------- def x=(value) @cx = value @x = @cx - @radius create_pie_region end #-------------------------------------------------------------------------- # ○ 中心 Y 座標変更 #-------------------------------------------------------------------------- def y=(value) @cy = value @y = @cy - @radius create_pie_region end #-------------------------------------------------------------------------- # ○ 半径変更 #-------------------------------------------------------------------------- def radius=(value) @radius = value @x = @cx - @radius @y = @cy - @radius create_pie_region end #-------------------------------------------------------------------------- # ○ 開始角度変更 #-------------------------------------------------------------------------- def start_angle=(value) @start_angle = value create_pie_region end #-------------------------------------------------------------------------- # ○ 描画角度変更 #-------------------------------------------------------------------------- def sweep_angle=(value) @sweep_angle = [[value, -360].max, 360].min create_pie_region end #-------------------------------------------------------------------------- # ○ リージョンハンドル生成 #-------------------------------------------------------------------------- def create_region_handle return @region.create_region_handle end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ CombinedRegion #------------------------------------------------------------------------------ # 混合リージョンを扱うクラスです。 #============================================================================== class CombinedRegion < Region #-------------------------------------------------------------------------- # ○ 定数 #-------------------------------------------------------------------------- # 合成モード RGN_AND = 1 RGN_OR = 2 RGN_XOR = 3 RGN_DIFF = 4 RGN_COPY = 5 #-------------------------------------------------------------------------- # ○ Win32API #-------------------------------------------------------------------------- @@_api_combine_rgn = Win32API.new('gdi32', 'CombineRgn', 'llll', 'l') #-------------------------------------------------------------------------- # ○ オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(mode, region1, region2) @exp = CombinedRegionExp.new(mode, region1.clone, region2.clone) end #-------------------------------------------------------------------------- # ○ リージョンハンドル生成 #-------------------------------------------------------------------------- def create_region_handle return combine_region(@exp.region1, @exp.region2, @exp.mode) end #-------------------------------------------------------------------------- # ○ リージョン合成 # dest : 合成先 # src : 合成元 # mode : 合成モード #-------------------------------------------------------------------------- def combine_region(dest, src, mode) hdest = dest.create_region_handle hsrc = src.create_region_handle @@_api_combine_rgn.call(hdest, hdest, hsrc, mode) return hdest end protected :combine_region end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ Struct #============================================================================== # □ CombinedRegionExp 構造体 CombinedRegionExp = Struct.new("CombinedRegionExp", :mode, :region1, :region2)