Module: Miyako::Drawing

Defined in:
lib/Miyako/API/drawing.rb

Overview

線形描画モジュール

Class Method Summary collapse

Class Method Details

.circle(sprite, point, r, color, fill = false, aa = false) ⇒ Object

画像内に円を描画する

引数spriteにto_unitもしくはbitmapメソッドが定義されていない場合は例外が発生する。

sprite

描画対象のスプライト(to_unitもしくはbitmapメソッドを持つインスタンス)

point

中心の位置。2要素の整数の配列、もしくはPoint構造体を使用可能

r

円の半径。整数を使用可能。

color

描画色。Color.to_rgbメソッドのパラメータでの指定が可能

fill

描画の属性。falseで縁のみ描画、trueで内部も塗りつぶす。デフォルトはfalse

aa

アンチエイリアスの指定。trueでオン。デフォルトはfalse

返却値

自分自身を返す

Raises:



107
108
109
110
111
112
113
114
115
# File 'lib/Miyako/API/drawing.rb', line 107

def Drawing.circle(sprite, point, r, color, fill = false, aa = false)
  color = Color.to_rgb(color)
  methods = sprite.methods
  raise MiyakoError, 
        "this method needs sprite have to_method or bitmap method!" if !methods.include?(:to_unit) && !methods.include?(:bitmap)
  bitmap = sprite.methods.include?(:to_unit) ? sprite.to_unit.bitmap : sprite.bitmap
  bitmap.draw_circle(*point.to_a[0..1], r, color, fill, aa, color[3]==255 ? nil : color[3])
  return self
end

.ellipse(sprite, point, rx, ry, color, fill = false, aa = false) ⇒ Object

画像内に楕円を描画する

引数spriteにto_unitもしくはbitmapメソッドが定義されていない場合は例外が発生する。

sprite

描画対象のスプライト(to_unitもしくはbitmapメソッドを持つインスタンス)

point

楕円の中心位置。2要素の整数の配列かPoint構造体を使用

rx

x方向半径。1以上の整数

ry

y方向半径。1以上の整数

color

描画色。Color.to_rgbメソッドのパラメータでの指定が可能

fill

描画の属性。falseで縁のみ描画、trueで内部も塗りつぶす。デフォルトはfalse

aa

アンチエイリアスの指定。trueでオン。デフォルトはfalse

返却値

自分自身を返す

Raises:



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/Miyako/API/drawing.rb', line 127

def Drawing.ellipse(sprite, point, rx, ry, color, fill = false, aa = false)
  color = Color.to_rgb(color)
  methods = sprite.methods
  raise MiyakoError, 
        "this method needs sprite have to_method or bitmap method!" if !methods.include?(:to_unit) && !methods.include?(:bitmap)
  bitmap = sprite.methods.include?(:to_unit) ? sprite.to_unit.bitmap : sprite.bitmap
  bitmap.draw_ellipse(
    point[0], point[1], rx, ry,
    color, fill, aa, color[3]==255 ? nil : color[3]
  )
end

.fill(sprite, color) ⇒ Object

画像全体を指定の色で塗りつぶす

引数spriteにto_unitもしくはbitmapメソッドが定義されていない場合は例外が発生する。

sprite

描画対象のスプライト(to_unitもしくはbitmapメソッドを持つインスタンス)

color

塗りつぶす色。Color.to_rgbメソッドのパラメータでの指定が可能

返却値

自分自身を返す

Raises:



32
33
34
35
36
37
38
39
40
# File 'lib/Miyako/API/drawing.rb', line 32

def Drawing.fill(sprite, color)
  color = Color.to_rgb(color)
  methods = sprite.methods
  raise MiyakoError, 
        "this method needs sprite have to_method or bitmap method!" if !methods.include?(:to_unit) && !methods.include?(:bitmap)
  bitmap = methods.include?(:to_unit) ? sprite.to_unit.bitmap : methods.include?(:bitmap) ? sprite.bitmap : sprite
  bitmap.draw_rect(0,0, bitmap.w, bitmap.h, color, true, color[3]==255 ? nil : color[3])
  return self
end

.line(sprite, rect, color, aa = false) ⇒ Object

画像内に直線を引く

引数spriteにto_unitもしくはbitmapメソッドが定義されていない場合は例外が発生する。

sprite

描画対象のスプライト(to_unitもしくはbitmapメソッドを持つインスタンス)

rect

描画する矩形。画像の左上をとする。4要素の整数の配列かRect構造体を使用

color

描画色。Color.to_rgbメソッドのパラメータでの指定が可能

aa

アンチエイリアスの指定。trueでオン。デフォルトはfalse

返却値

自分自身を返す

Raises:



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/Miyako/API/drawing.rb', line 65

def Drawing.line(sprite, rect, color, aa = false)
  color = Color.to_rgb(color)
  methods = sprite.methods
  raise MiyakoError, 
        "this method needs sprite have to_method or bitmap method!" if !methods.include?(:to_unit) && !methods.include?(:bitmap)
  bitmap = sprite.methods.include?(:to_unit) ? sprite.to_unit.bitmap : sprite.bitmap
  bitmap.draw_line(
    rect[0], rect[1], rect[0]+rect[2]-1, rect[1]+rect[3]-1,
    color, aa, color[3]==255 ? nil : color[3]
  )
  return self
end

.polygon(sprite, points, color, fill = false, aa = false) ⇒ Object

画像内に多角形を描画する

多角形を描画するとき、頂点のリストは、で示した配列のリスト(配列)を渡す。 引数spriteにto_unitもしくはbitmapメソッドが定義されていない場合は例外が発生する。

sprite

描画対象のスプライト(to_unitもしくはbitmapメソッドを持つインスタンス)

points

座標の配列。2要素の整数の配列かPoint構造体を使用

color

描画色。Color.to_rgbメソッドのパラメータでの指定が可能

fill

描画の属性。falseで縁のみ描画、trueで内部も塗りつぶす。デフォルトはfalse

aa

アンチエイリアスの指定。trueでオン。デフォルトはfalse

返却値

自分自身を返す



148
149
# File 'lib/Miyako/API/drawing.rb', line 148

def Drawing.polygon(sprite, points, color, fill = false, aa = false)
end

.pset(sprite, point, color) ⇒ Object

画像内に点を描画する

引数spriteにto_unitもしくはbitmapメソッドが定義されていない場合は例外が発生する。

sprite

描画対象のスプライト(to_unitもしくはbitmapメソッドを持つインスタンス)

rect

描画する矩形。画像の左上をとする。4要素の整数の配列かRect構造体を使用

color

描画色。Color.to_rgbメソッドのパラメータでの指定が可能

aa

アンチエイリアスの指定。trueでオン。デフォルトはfalse

返却値

自分自身を返す

Raises:



49
50
51
52
53
54
55
56
# File 'lib/Miyako/API/drawing.rb', line 49

def Drawing.pset(sprite, point, color)
  methods = sprite.methods
  raise MiyakoError, 
        "this method needs sprite have to_method or bitmap method!" if !methods.include?(:to_unit) && !methods.include?(:bitmap)
  bitmap = sprite.methods.include?(:to_unit) ? sprite.to_unit.bitmap : sprite.bitmap
  bitmap[point[0], point[1]] = Color.to_rgb(color)
  return self
end

.rect(sprite, rect, color, fill = false) ⇒ Object

画像内に矩形を描画する

引数spriteにto_unitもしくはbitmapメソッドが定義されていない場合は例外が発生する。

sprite

描画対象のスプライト(to_unitもしくはbitmapメソッドを持つインスタンス)

rect

描画する矩形。画像の左上をとする。4要素の整数の配列かRect構造体を使用

color

描画色。Color.to_rgbメソッドのパラメータでの指定が可能

fill

描画の属性。falseで縁のみ描画、trueで内部も塗りつぶす。デフォルトはfalse

返却値

自分自身を返す

Raises:



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/Miyako/API/drawing.rb', line 85

def Drawing.rect(sprite, rect, color, fill = false)
  color = Color.to_rgb(color)
  methods = sprite.methods
  raise MiyakoError, 
        "this method needs sprite have to_method or bitmap method!" if !methods.include?(:to_unit) && !methods.include?(:bitmap)
  bitmap = sprite.methods.include?(:to_unit) ? sprite.to_unit.bitmap : sprite.bitmap
  bitmap.draw_rect(
    rect[0], rect[1], rect[2]-1, rect[3]-1,
    color, fill, color[3]==255 ? nil : color[3]
  )
  return self
end