cyross-ruby-miyako 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +977 -0
- data/Rakefile +7 -0
- data/img/cursor.png +0 -0
- data/img/cursors.png +0 -0
- data/img/dice.png +0 -0
- data/img/wait_cursor.png +0 -0
- data/img/win_base.png +0 -0
- data/img/window.png +0 -0
- data/install_miyako.rb +75 -0
- data/lib/Miyako/API/audio.rb +198 -0
- data/lib/Miyako/API/basic_data.rb +431 -0
- data/lib/Miyako/API/bitmap.rb +35 -0
- data/lib/Miyako/API/choices.rb +308 -0
- data/lib/Miyako/API/collision.rb +444 -0
- data/lib/Miyako/API/diagram.rb +573 -0
- data/lib/Miyako/API/drawing.rb +110 -0
- data/lib/Miyako/API/fixedmap.rb +315 -0
- data/lib/Miyako/API/font.rb +384 -0
- data/lib/Miyako/API/input.rb +440 -0
- data/lib/Miyako/API/layout.rb +451 -0
- data/lib/Miyako/API/map.rb +403 -0
- data/lib/Miyako/API/map_event.rb +198 -0
- data/lib/Miyako/API/modules.rb +109 -0
- data/lib/Miyako/API/movie.rb +151 -0
- data/lib/Miyako/API/parts.rb +154 -0
- data/lib/Miyako/API/plane.rb +131 -0
- data/lib/Miyako/API/screen.rb +257 -0
- data/lib/Miyako/API/shape.rb +362 -0
- data/lib/Miyako/API/sprite.rb +338 -0
- data/lib/Miyako/API/sprite_animation.rb +461 -0
- data/lib/Miyako/API/spriteunit.rb +113 -0
- data/lib/Miyako/API/story.rb +224 -0
- data/lib/Miyako/API/textbox.rb +496 -0
- data/lib/Miyako/API/viewport.rb +435 -0
- data/lib/Miyako/API/yuki.rb +779 -0
- data/lib/Miyako/EXT/miyako_cairo.rb +60 -0
- data/lib/Miyako/EXT/raster_scroll.rb +138 -0
- data/lib/Miyako/EXT/slides.rb +136 -0
- data/lib/Miyako/miyako.rb +172 -0
- data/miyako.png +0 -0
- data/miyako_banner.png +0 -0
- data/miyako_no_katana/extconf.rb +34 -0
- data/miyako_no_katana/miyako_no_katana.c +3301 -0
- data/sample/Animation1/m1ku.rb +89 -0
- data/sample/Animation1/m1ku_arm_0.png +0 -0
- data/sample/Animation1/m1ku_arm_1.png +0 -0
- data/sample/Animation1/m1ku_arm_2.png +0 -0
- data/sample/Animation1/m1ku_arm_3.png +0 -0
- data/sample/Animation1/m1ku_back.jpg +0 -0
- data/sample/Animation1/m1ku_body.png +0 -0
- data/sample/Animation1/m1ku_eye_0.png +0 -0
- data/sample/Animation1/m1ku_eye_1.png +0 -0
- data/sample/Animation1/m1ku_eye_2.png +0 -0
- data/sample/Animation1/m1ku_eye_3.png +0 -0
- data/sample/Animation1/m1ku_hair_front.png +0 -0
- data/sample/Animation1/m1ku_hair_rear.png +0 -0
- data/sample/Animation1/readme.txt +72 -0
- data/sample/Animation2/lex.rb +95 -0
- data/sample/Animation2/lex_back.png +0 -0
- data/sample/Animation2/lex_body.png +0 -0
- data/sample/Animation2/lex_roadroller.png +0 -0
- data/sample/Animation2/lex_wheel_0.png +0 -0
- data/sample/Animation2/lex_wheel_1.png +0 -0
- data/sample/Animation2/lex_wheel_2.png +0 -0
- data/sample/Animation2/readme.txt +72 -0
- data/sample/Animation2/song_title.png +0 -0
- data/sample/Diagram_sample/back.png +0 -0
- data/sample/Diagram_sample/chr01.png +0 -0
- data/sample/Diagram_sample/chr02.png +0 -0
- data/sample/Diagram_sample/cursor.png +0 -0
- data/sample/Diagram_sample/diagram_sample_yuki2.rb +283 -0
- data/sample/Diagram_sample/readme.txt +87 -0
- data/sample/Diagram_sample/wait_cursor.png +0 -0
- data/sample/Room3/blue.rb +250 -0
- data/sample/Room3/ending.rb +175 -0
- data/sample/Room3/green.rb +185 -0
- data/sample/Room3/image/akamatsu.png +0 -0
- data/sample/Room3/image/aoyama.png +0 -0
- data/sample/Room3/image/congra.png +0 -0
- data/sample/Room3/image/congratulation.png +0 -0
- data/sample/Room3/image/congratulation_bg.png +0 -0
- data/sample/Room3/image/cursor.png +0 -0
- data/sample/Room3/image/midori.png +0 -0
- data/sample/Room3/image/mittsu_no_oheya.png +0 -0
- data/sample/Room3/image/mittsu_no_oheya_logo.png +0 -0
- data/sample/Room3/image/room_blue.png +0 -0
- data/sample/Room3/image/room_green.png +0 -0
- data/sample/Room3/image/room_red.png +0 -0
- data/sample/Room3/image/start.png +0 -0
- data/sample/Room3/image/three_doors.png +0 -0
- data/sample/Room3/image/wait_cursor.png +0 -0
- data/sample/Room3/main.rb +102 -0
- data/sample/Room3/main_component.rb +58 -0
- data/sample/Room3/readme.txt +76 -0
- data/sample/Room3/red.rb +200 -0
- data/sample/Room3/room3.rb +26 -0
- data/sample/Room3/title.rb +171 -0
- data/sample/fixed_map_test/cursor.png +0 -0
- data/sample/fixed_map_test/fixed_map_sample.rb +149 -0
- data/sample/fixed_map_test/map.csv +19 -0
- data/sample/fixed_map_test/map_01.png +0 -0
- data/sample/fixed_map_test/map_sample.rb +121 -0
- data/sample/fixed_map_test/mapchip.csv +23 -0
- data/sample/fixed_map_test/monster.png +0 -0
- data/sample/fixed_map_test/readme.txt +72 -0
- data/sample/map_test/chara.rb +50 -0
- data/sample/map_test/chr1.png +0 -0
- data/sample/map_test/cursor.png +0 -0
- data/sample/map_test/main_parts.rb +48 -0
- data/sample/map_test/main_scene.rb +137 -0
- data/sample/map_test/map.png +0 -0
- data/sample/map_test/map2.png +0 -0
- data/sample/map_test/map_layer.csv +127 -0
- data/sample/map_test/map_manager.rb +92 -0
- data/sample/map_test/map_test.rb +23 -0
- data/sample/map_test/mapchip.csv +21 -0
- data/sample/map_test/oasis.rb +65 -0
- data/sample/map_test/readme.txt +87 -0
- data/sample/map_test/route.rb +144 -0
- data/sample/map_test/sea.png +0 -0
- data/sample/map_test/town.rb +68 -0
- data/sample/map_test/wait_cursor.png +0 -0
- data/sample/map_test/window.png +0 -0
- data/win/miyako_no_katana.so +0 -0
- metadata +194 -0
@@ -0,0 +1,362 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
--
|
4
|
+
Miyako v2.0
|
5
|
+
Copyright (C) 2007-2008 Cyross Makoto
|
6
|
+
|
7
|
+
This library is free software; you can redistribute it and/or
|
8
|
+
modify it under the terms of the GNU Lesser General Public
|
9
|
+
License as published by the Free Software Foundation; either
|
10
|
+
version 2.1 of the License, or (at your option) any later version.
|
11
|
+
|
12
|
+
This library is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public
|
18
|
+
License along with this library; if not, write to the Free Software
|
19
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
++
|
21
|
+
=end
|
22
|
+
|
23
|
+
module Miyako
|
24
|
+
@@modes = [:text, :txt_calc, :takahashi, :tk_calc]
|
25
|
+
|
26
|
+
#==テキストや図形を描画するクラス
|
27
|
+
#図形は、長方形・丸み付き長方形・円・楕円が描画可能
|
28
|
+
#文字列は、通常の文字列と高橋メソッド形式文字列が描画可能
|
29
|
+
class Shape
|
30
|
+
def init_parameter(parameter)
|
31
|
+
@text = parameter[:text]
|
32
|
+
@size = parameter[:size] ||= Size.new(100,100)
|
33
|
+
@color = parameter[:color] ||= Color[:white]
|
34
|
+
@font = parameter[:font] ||= Font.sans_serif
|
35
|
+
@ray = parameter[:ray] ||= 0
|
36
|
+
@edge = parameter[:edge] ||= nil
|
37
|
+
@align = parameter[:align] ||= :left
|
38
|
+
@lines = parameter[:lines] ||= 2
|
39
|
+
end
|
40
|
+
|
41
|
+
@@shape_executer = Shape.new
|
42
|
+
|
43
|
+
#===テキストを描画した画像を作成
|
44
|
+
#_param_:: 設定パラメータ。ハッシュ形式。
|
45
|
+
#(:font => 描画するフォントのインスタンス(デフォルトはFont.sans_serif),
|
46
|
+
#(:align => 複数行描画するときの文字列のアライン(:left,:center,:rightの三種。デフォルトは:left))
|
47
|
+
#_&block_:: 描画するテキスト(Yuki形式)
|
48
|
+
#返却値:: テキストを描画したスプライト
|
49
|
+
def Shape.text(param, &block)
|
50
|
+
raise MiyakoError, "Cannot find any text(:text parameter)!" unless (param[:text] || block)
|
51
|
+
@@shape_executer.create_text(param, block)
|
52
|
+
end
|
53
|
+
|
54
|
+
#===テキストを高橋メソッド形式で描画した画像を作成
|
55
|
+
#指定した大きさの矩形・行数で文字を描画する。
|
56
|
+
#指定した行数で描画を基準に文字サイズを算出する。
|
57
|
+
#但し、文字列が長すぎる時は、その文字数を基準に文字サイズを算出する。
|
58
|
+
#ブロックに渡した行数が指定数より多くなると文字列がはみ出るため、注意すること。
|
59
|
+
#_param_:: 設定パラメータ。ハッシュ形式。
|
60
|
+
#(:font => 描画するフォントのインスタンス(デフォルトはFont.sans_serif),
|
61
|
+
#(:align => 複数行描画するときの文字列のアライン(:left,:center,:rightの三種。デフォルトは:left),
|
62
|
+
#(:size => 描画するサイズ(ピクセル単位、Size構造体のインスタンス、デフォルトは[100,100]))
|
63
|
+
#(:lines => 描画する行数(デフォルトは2))
|
64
|
+
#_&block_:: 描画するテキスト(Yuki形式)
|
65
|
+
#返却値:: テキストを描画したスプライト
|
66
|
+
def Shape.takahashi(param, &block)
|
67
|
+
@@shape_executer.takahashi(param, block)
|
68
|
+
end
|
69
|
+
|
70
|
+
#===長方形を描画する(エッジ付きも可。そのとき、エッジは指定したサイズより内側に描画する)
|
71
|
+
#_param_:: 設定パラメータ。ハッシュ形式。
|
72
|
+
#(:size => 描画するサイズ(ピクセル単位、Size構造体のインスタンス、デフォルトは[100,100]),
|
73
|
+
#:color => 長方形の色[r,g,b(,a)]、デフォルトはColor[:white],
|
74
|
+
#:edge] => エッジを設定する。値は{:color=>色, :width=>幅}のハッシュを割り付ける)
|
75
|
+
#返却値:: 描画したスプライト
|
76
|
+
def Shape.box(param)
|
77
|
+
@@shape_executer.box(param)
|
78
|
+
end
|
79
|
+
|
80
|
+
#===丸み付き長方形を描画する(エッジ付きも可。そのとき、エッジは指定したサイズより内側に描画する)
|
81
|
+
#_param_:: 設定パラメータ。ハッシュ形式。
|
82
|
+
#(:size => 描画するサイズ(ピクセル単位、Size構造体のインスタンス、デフォルトは[100,100]),
|
83
|
+
#:ray => 丸みの半径の大きさ(ピクセル単位。デフォルトは0),
|
84
|
+
#:color => 長方形の色[r,g,b(,a)]、デフォルトはColor[:white],
|
85
|
+
#:edge => エッジを設定する。値は{:color=>色, :width=>幅}のハッシュを割り付ける)
|
86
|
+
#返却値:: 描画したスプライト
|
87
|
+
def Shape.roundbox(param)
|
88
|
+
@@shape_executer.roundbox(param)
|
89
|
+
end
|
90
|
+
|
91
|
+
#===円を描画する(エッジ付きも可。そのとき、エッジは指定したサイズより内側に描画する)
|
92
|
+
#_param_:: 設定パラメータ。ハッシュ形式。
|
93
|
+
#(:ray => 円の半径の大きさ(ピクセル単位。デフォルトは0),
|
94
|
+
#:color => 円の色[r,g,b(,a)]、デフォルトはColor[:white],
|
95
|
+
#:edge => エッジを設定する。値は{:color=>色, :width=>幅}のハッシュを割り付ける)
|
96
|
+
#返却値:: 描画したスプライト
|
97
|
+
def Shape.circle(param)
|
98
|
+
@@shape_executer.circle(param)
|
99
|
+
end
|
100
|
+
|
101
|
+
#===楕円を描画する(エッジ付きも可。そのとき、エッジは指定したサイズより内側に描画する)
|
102
|
+
#_param_:: 設定パラメータ。ハッシュ形式。
|
103
|
+
#(:size => 楕円の半径の横・縦の大きさ(ピクセル単位。デフォルトは0),
|
104
|
+
#:color => 円の色[r,g,b(,a)]、デフォルトはColor[:white],
|
105
|
+
#:edge => エッジを設定する。値は{:color=>色, :width=>幅}のハッシュを割り付ける)
|
106
|
+
#返却値:: 描画したスプライト
|
107
|
+
def Shape.ellipse(param)
|
108
|
+
@@shape_executer.ellipse(param)
|
109
|
+
end
|
110
|
+
|
111
|
+
def create_text(param, text_block) #:nodoc:
|
112
|
+
init_parameter(param)
|
113
|
+
text_block = lambda{ @text } if @text
|
114
|
+
org_size = @font.size
|
115
|
+
org_color = @font.color
|
116
|
+
@margins = []
|
117
|
+
area_size = calc(text_block)
|
118
|
+
@sprite = Sprite.new({:size => area_size, :type => :alpha_channel, :is_fill => true})
|
119
|
+
case @align
|
120
|
+
when :left
|
121
|
+
@margins = @margins.map{|v| 0 }
|
122
|
+
when :center
|
123
|
+
@margins = @margins.map{|v| (area_size.w - v) >> 1 }
|
124
|
+
when :right
|
125
|
+
@margins = @margins.map{|v| area_size.w - v }
|
126
|
+
end
|
127
|
+
@lines = @margins.length
|
128
|
+
@locate = Point.new(@margins.shift, 0)
|
129
|
+
text instance_eval(&text_block)
|
130
|
+
@font.size = org_size
|
131
|
+
@font.color = org_color
|
132
|
+
return @sprite
|
133
|
+
end
|
134
|
+
|
135
|
+
def takahashi(param, text_block) #:nodoc:
|
136
|
+
init_parameter(param)
|
137
|
+
org_size = @font.size
|
138
|
+
org_color = @font.color
|
139
|
+
# calc font size
|
140
|
+
@font.size = @size[1] / @lines
|
141
|
+
# calc font size incldue line_height
|
142
|
+
@font.size = @font.size * @font.size / @font.line_height
|
143
|
+
set_font_size_inner(text_block)
|
144
|
+
# over width?
|
145
|
+
if @img_size.w > @size[0]
|
146
|
+
@font.size = @font.size * @size[0] / @img_size.w
|
147
|
+
set_font_size_inner(text_block)
|
148
|
+
end
|
149
|
+
case @align
|
150
|
+
when :left
|
151
|
+
@margins = @margins.map{|v| 0 }
|
152
|
+
when :center
|
153
|
+
@margins = @margins.map{|v| (@size.w - v) / 2 }
|
154
|
+
when :right
|
155
|
+
@margins = @margins.map{|v| @size.w - v }
|
156
|
+
end
|
157
|
+
@sprite = Sprite.new({:size => @size, :type => :alpha_channel, :is_fill => true})
|
158
|
+
@locate = Point.new(@margins.shift, 0)
|
159
|
+
text instance_eval(&text_block)
|
160
|
+
@font.size = org_size
|
161
|
+
@font.color = org_color
|
162
|
+
return @sprite
|
163
|
+
end
|
164
|
+
|
165
|
+
def set_font_size_inner(text_block) #:nodoc:
|
166
|
+
@max_height = @font.line_height
|
167
|
+
@margins = []
|
168
|
+
tcalc(text_block)
|
169
|
+
end
|
170
|
+
|
171
|
+
def calc(block) #:nodoc:
|
172
|
+
@locate = Point.new(0, 0)
|
173
|
+
@img_size = Size.new(0, 0)
|
174
|
+
@max_height = @font.line_height
|
175
|
+
@calc_mode = true
|
176
|
+
text instance_eval(&block)
|
177
|
+
@calc_mode = false
|
178
|
+
if @locate.x != 0
|
179
|
+
@margins << @locate.x
|
180
|
+
@img_size.w = [@locate.x, @img_size.w].max
|
181
|
+
@img_size.h += @max_height
|
182
|
+
end
|
183
|
+
return @img_size
|
184
|
+
end
|
185
|
+
|
186
|
+
def tcalc(block) #:nodoc:
|
187
|
+
@locate = Point.new(0, 0)
|
188
|
+
@img_size = Size.new(0, 0)
|
189
|
+
@calc_mode = true
|
190
|
+
text instance_eval(&block)
|
191
|
+
@calc_mode = false
|
192
|
+
@margins << @locate.x if @locate.x != 0
|
193
|
+
end
|
194
|
+
|
195
|
+
#===Shape.textメソッドのブロック内で使用する、文字描画指示メソッド
|
196
|
+
#(例)Shape.text(){ text "abc" }
|
197
|
+
#(例)Shape.takahashi(:size=>[200,200]){ text "名前重要" }
|
198
|
+
#_text_:: 描画するテキスト
|
199
|
+
#返却値:: 自分自身
|
200
|
+
def text(txt)
|
201
|
+
return self if txt.eql?(self)
|
202
|
+
txt = txt.gsub(/[\n\r\t\f]/,"")
|
203
|
+
@font.draw_text(@sprite, txt, @locate.x, @locate.y) unless @calc_mode
|
204
|
+
@locate.x += @font.text_size(txt)[0]
|
205
|
+
return self
|
206
|
+
end
|
207
|
+
|
208
|
+
#===Shape.text/takahashiメソッドのブロック内で使用する、文字色指示メソッド
|
209
|
+
#ブロック内で指定した範囲でのみ色が変更される
|
210
|
+
#(例)Shape.text(){ text "abc"; cr; color(:red){"def"} }
|
211
|
+
#_color_:: 変更する色([r,g,b])もしくはColor[]メソッドの引数
|
212
|
+
#返却値:: 自分自身
|
213
|
+
def color(color, &block)
|
214
|
+
@font.color_during(Color.to_rgb(color)){ text instance_eval(&block) }
|
215
|
+
return self
|
216
|
+
end
|
217
|
+
|
218
|
+
#===Shape.textメソッドのブロック内で使用する、文字サイズ指示メソッド
|
219
|
+
#ブロック内で指定した範囲でのみサイズが変更される
|
220
|
+
#(例)Shape.text(){ text "abc"; cr; size(16){"def"} }
|
221
|
+
#_size_:: 変更するサイズ(整数)
|
222
|
+
#返却値:: 自分自身
|
223
|
+
def size(size, &block)
|
224
|
+
@font.size_during(size){
|
225
|
+
@max_height = [@max_height, @font.line_height].max
|
226
|
+
size_inner(@font.margin_height(:middle, @max_height)){ text instance_eval(&block) }
|
227
|
+
}
|
228
|
+
return self
|
229
|
+
end
|
230
|
+
|
231
|
+
def size_inner(margin, &block) #:nodoc:
|
232
|
+
@locate.y += margin
|
233
|
+
text instance_eval(&block)
|
234
|
+
@locate.y -= margin
|
235
|
+
end
|
236
|
+
|
237
|
+
#===Shape.textメソッドのブロック内で使用する、太文字指示メソッド
|
238
|
+
#ブロック内で指定した範囲でのみ太文字になる
|
239
|
+
#(使用すると文字の端が切れてしまう場合あり!)
|
240
|
+
#(例)Shape.text(){ text "abc"; cr; bold{"def"} }
|
241
|
+
#返却値:: 自分自身
|
242
|
+
def bold(&block)
|
243
|
+
@font.bold{ text instance_eval(&block) }
|
244
|
+
return self
|
245
|
+
end
|
246
|
+
|
247
|
+
#===Shape.textメソッドのブロック内で使用する、斜体指示メソッド
|
248
|
+
#ブロック内で指定した範囲でのみ斜体文字になる
|
249
|
+
#(使用すると文字の端が切れてしまう場合あり!)
|
250
|
+
#(例)Shape.text(){ text "abc"; cr; italic{"def"} }
|
251
|
+
#返却値:: 自分自身
|
252
|
+
def italic(&block)
|
253
|
+
@font.italic{ text instance_eval(&block) }
|
254
|
+
return self
|
255
|
+
end
|
256
|
+
|
257
|
+
#===Shape.textメソッドのブロック内で使用する、下線指示メソッド
|
258
|
+
#ブロック内で指定した範囲でのみ文字に下線が付く
|
259
|
+
#(例)Shape.text(){ text "abc"; cr; bold{"def"} }
|
260
|
+
#返却値:: 自分自身
|
261
|
+
def under_line(&block)
|
262
|
+
@font.under_line{ text instance_eval(&block) }
|
263
|
+
return self
|
264
|
+
end
|
265
|
+
|
266
|
+
#===Shape.text/takahashiメソッドのブロック内で使用する、改行指示メソッド
|
267
|
+
#(例)Shape.text(){ text "abc"; cr; bold{"def"} }
|
268
|
+
#返却値:: 自分自身
|
269
|
+
def cr
|
270
|
+
if @calc_mode
|
271
|
+
@margins << @locate.x
|
272
|
+
@img_size.w = [@locate.x, @img_size.w].max
|
273
|
+
@img_size.h += @max_height
|
274
|
+
@locate.x = 0
|
275
|
+
else
|
276
|
+
@locate.x = @margins.shift || 0
|
277
|
+
end
|
278
|
+
@locate.y += @max_height
|
279
|
+
return self
|
280
|
+
end
|
281
|
+
|
282
|
+
def box(param) #:nodoc:
|
283
|
+
init_parameter(param)
|
284
|
+
s = Sprite.new({:size => [w, h], :type => :alpha_channel, :is_fill => true})
|
285
|
+
w = @size[0]
|
286
|
+
h = @size[1]
|
287
|
+
if @edge
|
288
|
+
width = @edge[:width]
|
289
|
+
s.bitmap.fill_rect(0, 0, w-1, h-1, Color.to_rgb(@edge[:color]))
|
290
|
+
s.bitmap.fill_rect(width, width, w-width*2-1, h-width*2-1, Color.to_rgb(@color))
|
291
|
+
else
|
292
|
+
s.bitmap.fill_rect(0, 0, w-1, h-1, Color.to_rgb(@color))
|
293
|
+
end
|
294
|
+
return s
|
295
|
+
end
|
296
|
+
|
297
|
+
def roundbox_basic(s, x, y, w, h, r, c) #:nodoc:
|
298
|
+
color = Color.to_rgb(c)
|
299
|
+
s.bitmap.draw_aa_filled_circle(r+x, r+y, r, color)
|
300
|
+
s.bitmap.draw_aa_filled_circle(w-r-x-1, r+y, r, color)
|
301
|
+
s.bitmap.draw_aa_filled_circle(r+x, h-r-y-1, r, color)
|
302
|
+
s.bitmap.draw_aa_filled_circle(w-r-x-1, h-r-y-1, r, color)
|
303
|
+
s.bitmap.fill_rect(x, y+r, w-x*2, h-y*2-r*2, color)
|
304
|
+
s.bitmap.fill_rect(x+r, y, w-x*2-r*2, h-x*2, color)
|
305
|
+
end
|
306
|
+
|
307
|
+
def roundbox(param) #:nodoc:
|
308
|
+
init_parameter(param)
|
309
|
+
w = @size[0]
|
310
|
+
h = @size[1]
|
311
|
+
s = Sprite.new(@size, nil, nil)
|
312
|
+
s.fill([0, 0, 0, 0])
|
313
|
+
if @edge
|
314
|
+
roundbox_basic(s, 0, 0, w, h, @ray, Color.to_rgb(@edge[:color]))
|
315
|
+
roundbox_basic(s, @edge[:width], @edge[:width], w, h, @ray, Color.to_rgb(@color))
|
316
|
+
else
|
317
|
+
roundbox_basic(s, 0, 0, w, h, @ray, Color.to_rgb(@color))
|
318
|
+
end
|
319
|
+
return s
|
320
|
+
end
|
321
|
+
|
322
|
+
def circle(param) #:nodoc:
|
323
|
+
init_parameter(param)
|
324
|
+
s = Sprite.new({:size => [@ray*2+1, @ray*2+1], :type => :alpha_channel, :is_fill => true})
|
325
|
+
if @edge
|
326
|
+
et, ec = sp.get_param(:edge)[0..1]
|
327
|
+
s.bitmap.draw_aa_filled_circle(@ray, @ray, @ray, Color.to_rgb(@edge[:color]))
|
328
|
+
s.bitmap.draw_aa_filled_circle(@ray, @ray, @ray-@edge[:width], Color.to_rgb(@color))
|
329
|
+
else
|
330
|
+
s.bitmap.draw_aa_filled_circle(@ray, @ray, @ray, Color.to_rgb(@color))
|
331
|
+
end
|
332
|
+
return s
|
333
|
+
end
|
334
|
+
|
335
|
+
def ellipse(param) #:nodoc:
|
336
|
+
init_parameter(param)
|
337
|
+
w = @size[0]
|
338
|
+
w2 = w * 2 + 1
|
339
|
+
h = @size[1]
|
340
|
+
h2 = h * 2 + 1
|
341
|
+
s = Sprite.new({:size => [w2, h2], :type => :alpha_channel, :is_fill => true})
|
342
|
+
if @edge
|
343
|
+
s.bitmap.drawAAFilledEllipse(w, h, w, h, Color.to_rgb(@edge[:color]))
|
344
|
+
s.bitmap.drawAAFilledEllipse(w, h, w-@edge[:width], h-@edge[:width], Color.to_rgb(@color))
|
345
|
+
else
|
346
|
+
s.bitmap.drawAAFilledEllipse(w, h, w, h, Color.to_rgb(@color))
|
347
|
+
end
|
348
|
+
return s
|
349
|
+
end
|
350
|
+
|
351
|
+
private :roundbox_basic
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
class String
|
356
|
+
#===文字列から、その文字を描画したスプライトを作成する
|
357
|
+
#自分自身が持つ文字列をShape.textメソッドを使用して画像を作成する
|
358
|
+
#_data_:: 描画するフォント(Fontクラスのインスタンス)
|
359
|
+
def to_sprite(data)
|
360
|
+
return Miyako::Shape.text({:text => self, :font => data})
|
361
|
+
end
|
362
|
+
end
|
@@ -0,0 +1,338 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
--
|
4
|
+
Miyako v2.0
|
5
|
+
Copyright (C) 2007-2008 Cyross Makoto
|
6
|
+
|
7
|
+
This library is free software; you can redistribute it and/or
|
8
|
+
modify it under the terms of the GNU Lesser General Public
|
9
|
+
License as published by the Free Software Foundation; either
|
10
|
+
version 2.1 of the License, or (at your option) any later version.
|
11
|
+
|
12
|
+
This library is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public
|
18
|
+
License along with this library; if not, write to the Free Software
|
19
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
++
|
21
|
+
=end
|
22
|
+
|
23
|
+
# スプライト関連クラス群
|
24
|
+
module Miyako
|
25
|
+
#==スプライト管理クラス
|
26
|
+
class Sprite
|
27
|
+
include SpriteBase
|
28
|
+
include Animation
|
29
|
+
include Layout
|
30
|
+
include SingleEnumerable
|
31
|
+
extend Forwardable
|
32
|
+
|
33
|
+
attr_reader :tr_color #カラーキーが有向になっている場合のRGB値。[R,G,B]の配列(各要素は0~255の整数)
|
34
|
+
attr_reader :type #画像の透明度・透過タイプを取得する(詳細はSprite.newメソッドを参照)
|
35
|
+
|
36
|
+
@@abb = {:ck => :color_key, :as => :alpha_surface, :ac => :alpha_channel}
|
37
|
+
|
38
|
+
def setup #:nodoc:
|
39
|
+
@unit = SpriteUnitFactory.create
|
40
|
+
@aa = false
|
41
|
+
@tr_color = Color[:black]
|
42
|
+
@update = nil
|
43
|
+
@w = 0
|
44
|
+
@h = 0
|
45
|
+
@draw_list = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
private :setup
|
49
|
+
|
50
|
+
#===インスタンス生成
|
51
|
+
#スプライトをファイルや画像サイズから生成します。
|
52
|
+
#
|
53
|
+
#v1.5以前は、ファイルからスプライトを生成するときは、ファイル名で画像が共有されていましたが、
|
54
|
+
#v2.0では廃止されました。
|
55
|
+
#
|
56
|
+
#_param_:: 各種設定(ハッシュ引数。詳細は後述)
|
57
|
+
#返却値:: 生成したインスタンス
|
58
|
+
#
|
59
|
+
#<引数の内容>
|
60
|
+
#* 1.画像の元データ(括弧内は省略形)。以下の3種類のどれかを必ず指定する。
|
61
|
+
# * 画像ファイル(ファイル名)から生成。 (書式):filename(:file)=>画像ファイル名 (例):file=>"image.png"
|
62
|
+
# * 画像サイズ(2要素の整数の配列もしくはSize構造体)から生成。 (書式1):size=>2要素の配列((例):size=>[100,100]) (書式2):size=>Size構造体((例):size=>Size.new(100,100))
|
63
|
+
# * SDL::Surfaceクラスのインスタンスから生成。 (書式):bitmap(:bmp)=>SDL::Surfaceクラスのインスタンス((例):bmp=>@surface)
|
64
|
+
# * SpriteUnit構造体のインスタンスから生成(ビットマップ以外のUnitの値は引き継がれる。しかし、snapの親子関係は引き継がれない)。
|
65
|
+
# (書式):unit=>SpriteUnit構造体のインスタンス((例):unit=>@spr.to_unit)
|
66
|
+
#* 2.透過設定(括弧内は省略形)。以下の3種類のどれかを必ず指定する。
|
67
|
+
# * カラーキーによる透過は行わない方式(デフォルトの方式) (書式):type=>:alpha_surface(:as)
|
68
|
+
# * カラーキーの指定。 (書式):type=>:color_key(:ck) カラーキー指定の方法は以下のとおり
|
69
|
+
# * 透明色にするピクセルの位置(2要素の整数の配列、Point構造体) (書式1):point=>2要素の配列((例):type=>:ck, :point=>[20,20]) (書式2):point=>Point構造体((例):type=>:ck, :point=>Point.new(20,20))
|
70
|
+
# * 色を直接指定 (書式):tr_color=>色情報(Color.to_rgbメソッドで生成できるパラメータ)((例1):type=>:ck, :tr_color=>[255,0,255] # 紫色を透明色に (例2):type=>:ck, :tr_color=>:red # 赤色を透明色に)
|
71
|
+
# * デフォルト:画像の[0,0]の位置にあるピクセルの色
|
72
|
+
#* 3. αチャネル付き画像を使用(設定変更不可) (書式):type=>:alpha_channel(:ac)
|
73
|
+
def initialize(param)
|
74
|
+
raise MiyakoError, "Sprite parameter is not Hash!" unless param.kind_of?(Hash)
|
75
|
+
setup
|
76
|
+
init_layout
|
77
|
+
|
78
|
+
bitmap = nil
|
79
|
+
@tr_color = nil
|
80
|
+
|
81
|
+
param[:type] ||= :color_key
|
82
|
+
param[:type] = @@abb[param[:type]] if @@abb.has_key?(param[:type])
|
83
|
+
param[:point] ||= Point.new(0, 0)
|
84
|
+
param[:tr_color] ||= Color[:black]
|
85
|
+
param[:is_fill] ||= false
|
86
|
+
|
87
|
+
if param.has_key?(:bitmap) || param.has_key?(:bmp)
|
88
|
+
bitmap = param[:bitmap] || param[:bmp]
|
89
|
+
elsif param.has_key?(:size)
|
90
|
+
bitmap = Bitmap.create(*(param[:size].to_a))
|
91
|
+
param[:is_fill] = true
|
92
|
+
elsif param.has_key?(:filename) || param.has_key?(:file)
|
93
|
+
bitmap = Bitmap.load(param[:filename] || param[:file])
|
94
|
+
elsif param.has_key?(:unit)
|
95
|
+
bitmap = param[:unit].bitmap
|
96
|
+
else
|
97
|
+
raise MiyakoError, "Illegal Sprite parameter!"
|
98
|
+
end
|
99
|
+
|
100
|
+
case param[:type]
|
101
|
+
when :color_key
|
102
|
+
if param.has_key?(:point)
|
103
|
+
@tr_color = Color.to_rgb(bitmap.get_rgb(bitmap.getPixel(*(param[:point].to_a))))
|
104
|
+
else
|
105
|
+
@tr_color = Color.to_rgb(param[:tr_color])
|
106
|
+
end
|
107
|
+
# カラーキーのα値を0にしたビットマップを作成
|
108
|
+
tbitmap = bitmap.display_format
|
109
|
+
tunit = SpriteUnitFactory.create(:bitmap => tbitmap)
|
110
|
+
bitmap = Bitmap.create(bitmap.w, bitmap.h, SDL::HWSURFACE)
|
111
|
+
bitmap = bitmap.display_format_alpha
|
112
|
+
nunit = SpriteUnitFactory.create(:bitmap => bitmap)
|
113
|
+
Bitmap.ck_to_ac!(tunit, nunit, @tr_color)
|
114
|
+
self.bitmap = bitmap
|
115
|
+
@unit.bitmap.fill_rect(0,0,@unit.bitmap.w,@unit.bitmap.h,[0, 0, 0, 0]) if param[:is_fill]
|
116
|
+
tbitmap = nil
|
117
|
+
when :alpha_surface
|
118
|
+
# カラーキーのα値を0にしたビットマップを作成
|
119
|
+
tbitmap = bitmap.display_format
|
120
|
+
tunit = SpriteUnitFactory.create(:bitmap => tbitmap)
|
121
|
+
bitmap = Bitmap.create(bitmap.w, bitmap.h, SDL::HWSURFACE)
|
122
|
+
bitmap = bitmap.display_format_alpha
|
123
|
+
nunit = SpriteUnitFactory.create(:bitmap => bitmap)
|
124
|
+
Bitmap.normal_to_ac!(tunit, nunit)
|
125
|
+
self.bitmap = bitmap
|
126
|
+
@unit.bitmap.fill_rect(0,0,@unit.bitmap.w,@unit.bitmap.h,[0, 0, 0, 0]) if param[:is_fill]
|
127
|
+
tbitmap = nil
|
128
|
+
when :alpha_channel
|
129
|
+
self.bitmap = bitmap.display_format_alpha
|
130
|
+
@unit.bitmap.fill_rect(0,0,@unit.bitmap.w,@unit.bitmap.h,[0, 0, 0, 0]) if param[:is_fill]
|
131
|
+
when :movie
|
132
|
+
self.bitmap = bitmap.display_format
|
133
|
+
end
|
134
|
+
@type = param[:type]
|
135
|
+
|
136
|
+
if param.has_key?(:unit)
|
137
|
+
SpriteUnitFactory.apply(@unit, :ow=>param[:unit].ow, :oh=>param[:unit].oh,
|
138
|
+
:angle => param[:unit].angle,
|
139
|
+
:xscale => param[:unit].xscale, :yscale => param[:unit].yscale,
|
140
|
+
:cx => param[:unit].cx, :cy => param[:unit].cy)
|
141
|
+
self.move_to(param[:unit].x, param[:unit].y)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def_delegators(:@unit, :ox, :oy, :ow, :oh, :x, :y)
|
146
|
+
|
147
|
+
def update_layout_position #:nodoc:
|
148
|
+
@unit.move_to(*@layout.pos)
|
149
|
+
end
|
150
|
+
|
151
|
+
#===画像の幅を取得する
|
152
|
+
#返却値:: 画像の幅(ピクセル)
|
153
|
+
def w
|
154
|
+
return @unit.bitmap.w
|
155
|
+
end
|
156
|
+
|
157
|
+
#===画像の高さを取得する
|
158
|
+
#返却値:: 画像の高さ(ピクセル)
|
159
|
+
def h
|
160
|
+
return @unit.bitmap.h
|
161
|
+
end
|
162
|
+
|
163
|
+
def bitmap #:nodoc:
|
164
|
+
return @unit.bitmap
|
165
|
+
end
|
166
|
+
|
167
|
+
def bitmap=(bmp) #:nodoc:
|
168
|
+
@unit.bitmap = bmp
|
169
|
+
@unit.ow = @unit.bitmap.w
|
170
|
+
@unit.oh = @unit.bitmap.h
|
171
|
+
@w = @unit.bitmap.w
|
172
|
+
@h = @unit.bitmap.h
|
173
|
+
set_layout_size(@unit.ow, @unit.oh)
|
174
|
+
end
|
175
|
+
|
176
|
+
#===画像全体を指定の色で塗りつぶす
|
177
|
+
#_color_:: 塗りつぶす色。Color.to_rgbメソッドのパラメータでの指定が可能
|
178
|
+
#返却値:: 自分自身を返す
|
179
|
+
def fill(color)
|
180
|
+
@unit.bitmap.fill_rect(0,0,self.w,self.h,Color.to_rgb(color))
|
181
|
+
return self
|
182
|
+
end
|
183
|
+
|
184
|
+
#===画像の表示開始位置(X座標)を指定する
|
185
|
+
#oxを指定すると、表示の左上位置が変更される。
|
186
|
+
#_v_:: 表示開始位置。整数で指定
|
187
|
+
def ox=(v)
|
188
|
+
@unit.ox = v
|
189
|
+
end
|
190
|
+
|
191
|
+
#===画像の表示開始位置(Y座標)を指定する
|
192
|
+
#oyを指定すると、表示の左上位置が変更される。
|
193
|
+
#_v_:: 表示開始位置。整数で指定
|
194
|
+
def oy=(v)
|
195
|
+
@unit.oy = v
|
196
|
+
end
|
197
|
+
|
198
|
+
#===画像の表示幅を指定する
|
199
|
+
#owを指定すると、横方向の一部のみ表示される。
|
200
|
+
#_v_:: 表示幅。整数で指定
|
201
|
+
def ow=(v)
|
202
|
+
@unit.ow = v
|
203
|
+
set_layout_size(v, @unit.oh)
|
204
|
+
end
|
205
|
+
|
206
|
+
#===画像の表示高を指定する
|
207
|
+
#ohを指定すると、縦方向の一部のみ表示される。
|
208
|
+
#_v_:: 表示高。整数で指定
|
209
|
+
def oh=(v)
|
210
|
+
@unit.oh = v
|
211
|
+
set_layout_size(@unit.ow, v)
|
212
|
+
end
|
213
|
+
|
214
|
+
#===画像の回転角度を取得する
|
215
|
+
#値はラジアン。範囲は0<=angle<PI*2
|
216
|
+
#値が正の時は右回りに回転する。
|
217
|
+
#返却値:: 回転角度。ラジアン(実数)
|
218
|
+
def angle
|
219
|
+
return @unit.angle
|
220
|
+
end
|
221
|
+
|
222
|
+
#===画像の回転角度を設定する
|
223
|
+
#値はラジアン。範囲は0<=angle<PI*2
|
224
|
+
#値が正の時は右回りに回転する。
|
225
|
+
#_radian_:: 回転角度。ラジアン(実数)を指定
|
226
|
+
def angle=(radian)
|
227
|
+
raise MiyakoError, "Illegal radian! : #{radian}" if (radian < 0.0 || radian > Math::PI * 2)
|
228
|
+
@unit.angle = radian
|
229
|
+
end
|
230
|
+
|
231
|
+
#===画像の拡大縮小度を取得する
|
232
|
+
#x方向の拡大縮小度を取得する
|
233
|
+
#返却値:: 拡大縮小度。1.0で等倍。-1.0でミラー反転
|
234
|
+
def xscale
|
235
|
+
return @unit.xscale
|
236
|
+
end
|
237
|
+
|
238
|
+
#===画像の拡大縮小度を設定する
|
239
|
+
#x方向の拡大縮小度を設定する
|
240
|
+
#_scale_:: 拡大縮小度。1.0で等倍。-1.0でミラー反転
|
241
|
+
def xscale=(scale)
|
242
|
+
@unit.xscale = scale
|
243
|
+
end
|
244
|
+
|
245
|
+
#===画像の拡大縮小度を取得する
|
246
|
+
#y方向の拡大縮小度を取得する
|
247
|
+
#返却値:: 拡大縮小度。1.0で等倍。-1.0でミラー反転
|
248
|
+
def yscale
|
249
|
+
return @unit.yscale
|
250
|
+
end
|
251
|
+
|
252
|
+
#===画像の拡大縮小度を設定する
|
253
|
+
#y方向の拡大縮小度を設定する
|
254
|
+
#_scale_:: 拡大縮小度。1.0で等倍。-1.0でミラー反転
|
255
|
+
def yscale=(scale)
|
256
|
+
@unit.yscale = scale
|
257
|
+
end
|
258
|
+
|
259
|
+
#===画像の回転・拡大・縮小の中心座標を取得する
|
260
|
+
#x方向の中心座標を取得する
|
261
|
+
#返却値:: 中心座標。
|
262
|
+
def center_x
|
263
|
+
return @unit.cx
|
264
|
+
end
|
265
|
+
|
266
|
+
#===画像の回転・拡大・縮小の中心座標を取得する
|
267
|
+
#x方向の中心座標を取得する
|
268
|
+
#_pos_:: 中心座標
|
269
|
+
def center_x=(pos)
|
270
|
+
@unit.cx = pos
|
271
|
+
end
|
272
|
+
|
273
|
+
#===画像の回転・拡大・縮小の中心座標を取得する
|
274
|
+
#y方向の中心座標を取得する
|
275
|
+
#返却値:: 中心座標。
|
276
|
+
def center_y
|
277
|
+
return @unit.cy
|
278
|
+
end
|
279
|
+
|
280
|
+
#===画像の回転・拡大・縮小の中心座標を取得する
|
281
|
+
#y方向の中心座標を取得する
|
282
|
+
#_pos_:: 中心座標
|
283
|
+
def center_y=(pos)
|
284
|
+
@unit.cy = pos
|
285
|
+
end
|
286
|
+
|
287
|
+
#===画像の表示矩形を取得する
|
288
|
+
#画像が表示されているときの矩形を取得する。矩形は、[x,y,ow,oh]で取得する。
|
289
|
+
#返却値:: 生成された矩形
|
290
|
+
def rect
|
291
|
+
return Rect.new(@unit.x, @unit.y, @unit.ow, @unit.oh)
|
292
|
+
end
|
293
|
+
|
294
|
+
#===現在の画面の最大の大きさを矩形で取得する
|
295
|
+
#但し、Spriteの場合は最大の大きさ=スプライトの大きさなので、rectと同じ値が得られる
|
296
|
+
#返却値:: 画像の大きさ(Rect構造体のインスタンス)
|
297
|
+
def broad_rect
|
298
|
+
return self.rect
|
299
|
+
end
|
300
|
+
|
301
|
+
def update #:nodoc:
|
302
|
+
@update.call(self) if @update
|
303
|
+
yield self if block_given?
|
304
|
+
return self
|
305
|
+
end
|
306
|
+
|
307
|
+
def update=(u) #:nodoc:
|
308
|
+
@update = u
|
309
|
+
end
|
310
|
+
|
311
|
+
#===画像を解放する
|
312
|
+
#内部で使用しているデータをインスタンスから解放する
|
313
|
+
def dispose
|
314
|
+
layout_dispose
|
315
|
+
@unit.bitmap = nil
|
316
|
+
@unit = nil
|
317
|
+
end
|
318
|
+
|
319
|
+
#===インスタンスをSpriteUnit構造体に変換して取得する
|
320
|
+
#返却値:: SpriteUnit化したスプライト
|
321
|
+
def to_unit
|
322
|
+
return @unit.dup
|
323
|
+
end
|
324
|
+
|
325
|
+
#===インスタンスをスプライト化して返す
|
326
|
+
#インスタンスの複製を行う(画像インスタンスも複製)
|
327
|
+
#注意事項:
|
328
|
+
#1.複製のため、呼び出していくとメモリ使用量が著しく上がる
|
329
|
+
#2.レイアウト情報がリセットされる(snapの親子関係が解消される)
|
330
|
+
#返却値:: 自分自身を返す
|
331
|
+
def to_sprite
|
332
|
+
unit = @unit.dup
|
333
|
+
unit.bitmap = Bitmap.create(unit.bitmap.w, unit.bitmap.h)
|
334
|
+
Bitmap.blit_aa!(@unit, unit, 0, 0)
|
335
|
+
return Sprite.new(:unit=>unit, :type=>:ac)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|