cyross-ruby-miyako-mswin32 2.0.5

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.
Files changed (145) hide show
  1. data/README +929 -0
  2. data/img/cursor.png +0 -0
  3. data/img/cursors.png +0 -0
  4. data/img/dice.png +0 -0
  5. data/img/wait_cursor.png +0 -0
  6. data/img/win_base.png +0 -0
  7. data/img/window.png +0 -0
  8. data/install_miyako.rb +61 -0
  9. data/lib/Miyako/API/audio.rb +198 -0
  10. data/lib/Miyako/API/basic_data.rb +573 -0
  11. data/lib/Miyako/API/bitmap.rb +507 -0
  12. data/lib/Miyako/API/choices.rb +475 -0
  13. data/lib/Miyako/API/collision.rb +460 -0
  14. data/lib/Miyako/API/diagram.rb +561 -0
  15. data/lib/Miyako/API/drawing.rb +151 -0
  16. data/lib/Miyako/API/fixedmap.rb +428 -0
  17. data/lib/Miyako/API/font.rb +403 -0
  18. data/lib/Miyako/API/input.rb +447 -0
  19. data/lib/Miyako/API/layout.rb +433 -0
  20. data/lib/Miyako/API/map.rb +529 -0
  21. data/lib/Miyako/API/map_event.rb +198 -0
  22. data/lib/Miyako/API/modules.rb +109 -0
  23. data/lib/Miyako/API/movie.rb +154 -0
  24. data/lib/Miyako/API/parts.rb +189 -0
  25. data/lib/Miyako/API/plane.rb +166 -0
  26. data/lib/Miyako/API/screen.rb +325 -0
  27. data/lib/Miyako/API/shape.rb +443 -0
  28. data/lib/Miyako/API/sprite.rb +752 -0
  29. data/lib/Miyako/API/sprite_animation.rb +481 -0
  30. data/lib/Miyako/API/spriteunit.rb +147 -0
  31. data/lib/Miyako/API/story.rb +300 -0
  32. data/lib/Miyako/API/textbox.rb +725 -0
  33. data/lib/Miyako/API/utility.rb +388 -0
  34. data/lib/Miyako/API/viewport.rb +140 -0
  35. data/lib/Miyako/API/yuki.rb +996 -0
  36. data/lib/Miyako/EXT/miyako_cairo.rb +62 -0
  37. data/lib/Miyako/EXT/raster_scroll.rb +138 -0
  38. data/lib/Miyako/EXT/slides.rb +157 -0
  39. data/lib/Miyako/miyako.rb +171 -0
  40. data/lib/Miyako/miyako_no_katana.so +0 -0
  41. data/logo/EGSR_logo.png +0 -0
  42. data/logo/EGSR_logo_bg.png +0 -0
  43. data/logo/EGSR_logo_fg.png +0 -0
  44. data/logo/EGSR_title_banner.png +0 -0
  45. data/logo/EGSR_title_logo.png +0 -0
  46. data/logo/miyako.png +0 -0
  47. data/logo/miyako_banner.png +0 -0
  48. data/logo/space.png +0 -0
  49. data/sample/Animation1/m1ku.rb +68 -0
  50. data/sample/Animation1/m1ku_arm_0.png +0 -0
  51. data/sample/Animation1/m1ku_arm_1.png +0 -0
  52. data/sample/Animation1/m1ku_arm_2.png +0 -0
  53. data/sample/Animation1/m1ku_arm_3.png +0 -0
  54. data/sample/Animation1/m1ku_back.jpg +0 -0
  55. data/sample/Animation1/m1ku_body.png +0 -0
  56. data/sample/Animation1/m1ku_eye_0.png +0 -0
  57. data/sample/Animation1/m1ku_eye_1.png +0 -0
  58. data/sample/Animation1/m1ku_eye_2.png +0 -0
  59. data/sample/Animation1/m1ku_eye_3.png +0 -0
  60. data/sample/Animation1/m1ku_hair_front.png +0 -0
  61. data/sample/Animation1/m1ku_hair_rear.png +0 -0
  62. data/sample/Animation1/readme.txt +72 -0
  63. data/sample/Animation2/lex.rb +96 -0
  64. data/sample/Animation2/lex_back.png +0 -0
  65. data/sample/Animation2/lex_body.png +0 -0
  66. data/sample/Animation2/lex_roadroller.png +0 -0
  67. data/sample/Animation2/lex_wheel_0.png +0 -0
  68. data/sample/Animation2/lex_wheel_1.png +0 -0
  69. data/sample/Animation2/lex_wheel_2.png +0 -0
  70. data/sample/Animation2/readme.txt +72 -0
  71. data/sample/Animation2/song_title.png +0 -0
  72. data/sample/Diagram_sample/back.png +0 -0
  73. data/sample/Diagram_sample/chr01.png +0 -0
  74. data/sample/Diagram_sample/chr02.png +0 -0
  75. data/sample/Diagram_sample/cursor.png +0 -0
  76. data/sample/Diagram_sample/diagram_sample_yuki2.rb +387 -0
  77. data/sample/Diagram_sample/readme.txt +90 -0
  78. data/sample/Diagram_sample/wait_cursor.png +0 -0
  79. data/sample/Room3/blue.rb +297 -0
  80. data/sample/Room3/ending.rb +180 -0
  81. data/sample/Room3/green.rb +220 -0
  82. data/sample/Room3/image/akamatsu.png +0 -0
  83. data/sample/Room3/image/aoyama.png +0 -0
  84. data/sample/Room3/image/congra.png +0 -0
  85. data/sample/Room3/image/congratulation.png +0 -0
  86. data/sample/Room3/image/congratulation_bg.png +0 -0
  87. data/sample/Room3/image/cursor.png +0 -0
  88. data/sample/Room3/image/midori.png +0 -0
  89. data/sample/Room3/image/mittsu_no_oheya.png +0 -0
  90. data/sample/Room3/image/mittsu_no_oheya_logo.png +0 -0
  91. data/sample/Room3/image/room_blue.png +0 -0
  92. data/sample/Room3/image/room_green.png +0 -0
  93. data/sample/Room3/image/room_red.png +0 -0
  94. data/sample/Room3/image/start.png +0 -0
  95. data/sample/Room3/image/three_doors.png +0 -0
  96. data/sample/Room3/image/wait_cursor.png +0 -0
  97. data/sample/Room3/main.rb +120 -0
  98. data/sample/Room3/main_component.rb +59 -0
  99. data/sample/Room3/readme.txt +76 -0
  100. data/sample/Room3/red.rb +227 -0
  101. data/sample/Room3/room3.rb +27 -0
  102. data/sample/Room3/title.rb +184 -0
  103. data/sample/ball_action_sample.rb +204 -0
  104. data/sample/blit_rop.rb +70 -0
  105. data/sample/cairo_sample.rb +25 -0
  106. data/sample/circle_collision_test.rb +62 -0
  107. data/sample/collision_test.rb +33 -0
  108. data/sample/collision_test2.rb +104 -0
  109. data/sample/fixed_map_test/cursor.png +0 -0
  110. data/sample/fixed_map_test/fixed_map_sample.rb +140 -0
  111. data/sample/fixed_map_test/map.csv +19 -0
  112. data/sample/fixed_map_test/map_01.png +0 -0
  113. data/sample/fixed_map_test/mapchip.csv +23 -0
  114. data/sample/fixed_map_test/monster.png +0 -0
  115. data/sample/fixed_map_test/readme.txt +72 -0
  116. data/sample/map_test/chara.rb +58 -0
  117. data/sample/map_test/chr1.png +0 -0
  118. data/sample/map_test/cursor.png +0 -0
  119. data/sample/map_test/main_parts.rb +69 -0
  120. data/sample/map_test/main_scene.rb +153 -0
  121. data/sample/map_test/map.png +0 -0
  122. data/sample/map_test/map2.png +0 -0
  123. data/sample/map_test/map_layer.csv +127 -0
  124. data/sample/map_test/map_manager.rb +75 -0
  125. data/sample/map_test/map_test.rb +23 -0
  126. data/sample/map_test/mapchip.csv +21 -0
  127. data/sample/map_test/oasis.rb +71 -0
  128. data/sample/map_test/readme.txt +89 -0
  129. data/sample/map_test/route.rb +157 -0
  130. data/sample/map_test/sea.png +0 -0
  131. data/sample/map_test/town.rb +74 -0
  132. data/sample/map_test/wait_cursor.png +0 -0
  133. data/sample/map_test/window.png +0 -0
  134. data/sample/polygon_test.rb +35 -0
  135. data/sample/rasterscroll.rb +25 -0
  136. data/sample/takahashi.rb +42 -0
  137. data/sample/text.png +0 -0
  138. data/sample/textbox_sample.rb +190 -0
  139. data/sample/transform.rb +54 -0
  140. data/sample/utility_test.rb +73 -0
  141. data/sample/utility_test2.rb +61 -0
  142. data/sample/utility_test3.rb +64 -0
  143. data/sample/utility_test4.rb +73 -0
  144. data/uninstall_miyako.rb +19 -0
  145. metadata +196 -0
@@ -0,0 +1,388 @@
1
+ # -*- encoding: utf-8 -*-
2
+ =begin
3
+ --
4
+ Miyako v2.0
5
+ Copyright (C) 2007-2009 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
+ #==ユーティリティモジュール
25
+ module Utility
26
+ def Utility.get_step_array_f(v1, v2, amount, skip_even = false) #:nodoc:
27
+ steps = []
28
+ amount = amount.abs
29
+ val = v1
30
+ if v1 < v2
31
+ loop do
32
+ val = val + amount
33
+ break if (skip_even && (v2-val).abs < Float::EPSILON)
34
+ break if val > v2
35
+ steps << val
36
+ end
37
+ else
38
+ loop do
39
+ val = val - amount
40
+ break if (skip_even && (v2-val).abs < Float::EPSILON)
41
+ break if val < v2
42
+ steps << val
43
+ end
44
+ end
45
+ return steps
46
+ end
47
+
48
+ def Utility.product_liner_inner_f(x1, y1, x2, y2, amount) #:nodoc:
49
+ array = nil
50
+ step_x = get_step_array_f(x1, x2, amount)
51
+ step_y = get_step_array_f(y1, y2, amount)
52
+ dx = x2 - x1
53
+ dy = y2 - y1
54
+ a = dx < Float::EPSILON ? dy.to_f : dy.to_f / dx.to_f
55
+ b = y1.to_f - a * x1.to_f
56
+ array = [[x1,y1] , [x2,y2]] + step_x.map{|x| [x, (a * x.to_f + b).to_i]}
57
+ array += step_y.map{|y| [((y.to_f - b) / a).to_i, y]} if (a.abs >= Float::EPSILON)
58
+ return array.uniq
59
+ end
60
+
61
+ #===矩形内の対角線の座標リストを実数で取得する
62
+ # (互換性維持のために残している)
63
+ # 矩形内の対角線の座標リストを取得する
64
+ # 引数には、Rect(x,y,w,h)形式のインスタンスを渡す
65
+ # 幅・高さはマイナスの値の設定が可能。
66
+ # 幅・高さのどちらかの値が0(Float::EPSILON未満)の場合は[]が返る
67
+ # 刻みの値は1以上の整数を渡す。0(Float::EPSILON未満)以下の場合は例外が発生する。
68
+ # 結果は[x,y]の配列となるが、正確さを優先したため、必ず刻みの値の間隔で並んでいない
69
+ #(刻みの値より小さい)ことがある
70
+ #_rect_:: 矩形情報
71
+ #_amount_:: 配列を作成する座標の刻み。デフォルトは1.0
72
+ #返却値:: 矩形左上位置[x,y]の配列(指定の矩形に掛かる位置の組み合わせ)
73
+ def Utility.product_liner_f(rect, amount = 1.0)
74
+ raise MiyakoError, "Illegal amount! #{amount}" if amount < Float::EPSILON
75
+ return [] if rect[2] < Float::EPSILON || rect[3] < Float::EPSILON
76
+ x1 = rect[0]
77
+ y1 = rect[1]
78
+ x2 = x1 + rect[2] - 1
79
+ y2 = y1 + rect[3] - 1
80
+ return product_liner_inner_f(x1, y1, x2, y2, amount)
81
+ end
82
+
83
+ #===矩形内の対角線の座標リストを実数で取得する
84
+ # (互換性維持のために残している)
85
+ # 矩形内の対角線の座標リストを取得する
86
+ # 引数には、Rect(x,y,w,h)形式のインスタンスを渡す
87
+ # 幅・高さはマイナスの値の設定が可能。
88
+ # 幅・高さのどちらかの値が0(Float::EPSILON未満)の場合は[]が返る
89
+ # 刻みの値は1以上の整数を渡す。0(Float::EPSILON未満)以下の場合は例外が発生する。
90
+ # 結果は[x,y]の配列となるが、正確さを優先したため、必ず刻みの値の間隔で並んでいない
91
+ #(刻みの値より小さい)ことがある
92
+ #_rect_:: 矩形情報
93
+ #_amount_:: 配列を作成する座標の刻み。デフォルトは1
94
+ #返却値:: 矩形左上位置[x,y]の配列(指定の矩形に掛かる位置の組み合わせ)
95
+ def Utility.product_liner_by_square_f(square, amount = 1.0)
96
+ raise MiyakoError, "Illegal amount! #{amount}" if amount < Float::EPSILON
97
+ return [] if (square[2] - square[0]) < Float::EPSILON || (square[3] - square[1]) < Float::EPSILON
98
+ return product_liner_inner_f(*square, amount)
99
+ end
100
+
101
+ def Utility.product_liner_inner(x1, y1, x2, y2, amount) #:nodoc:
102
+ array = nil
103
+ step_x = []
104
+ step_y = []
105
+ dx = x2 - x1
106
+ dy = y2 - y1
107
+ a = 0.0
108
+ if [x1, y1, x2, y2, amount].all?{|v| v.methods.include?(:step)}
109
+ step_x = x1 < x2 ? x1.step(x2, amount).to_a : x1.step(x2, -amount).to_a
110
+ step_y = y1 < y2 ? y1.step(y2, amount).to_a : y1.step(y2, -amount).to_a
111
+ a = dx == 0 ? dy.to_f : dy.to_f / dx.to_f
112
+ else
113
+ step_x = get_step_array_f(x1, x2, amount)
114
+ step_y = get_step_array_f(y1, y2, amount)
115
+ a = dx < Float::EPSILON ? dy.to_f : dy.to_f / dx.to_f
116
+ end
117
+ b = y1.to_f - a * x1.to_f
118
+ array = [[x1,y1] , [x2,y2]] + step_x.map{|x| [x, (a * x.to_f + b).to_i]}
119
+ array += step_y.map{|y| [((y.to_f - b) / a).to_i, y]} if (a.abs >= Float::EPSILON)
120
+ return array.uniq
121
+ end
122
+
123
+ #===矩形内の対角線の座標リストを取得する
124
+ # 矩形内の対角線の座標リストを取得する
125
+ # 引数には、Rect(x,y,w,h)形式のインスタンスを渡す
126
+ # 幅・高さはマイナスの値の設定が可能。
127
+ # 幅・高さのどちらかの値が0の場合は[]が返る
128
+ # 刻みの値は1以上の整数を渡す。0以下の場合は例外が発生する。
129
+ # 結果は[x,y]の配列となるが、正確さを優先したため、必ず刻みの値の間隔で並んでいない
130
+ #(刻みの値より小さいことがある)ことがある
131
+ #_rect_:: 矩形情報
132
+ #_amount_:: 配列を作成する座標の刻み。デフォルトは1
133
+ #返却値:: 矩形左上位置[x,y]の配列(指定の矩形に掛かる位置の組み合わせ)
134
+ def Utility.product_liner(rect, amount = 1)
135
+ raise MiyakoError, "Illegal amount! #{amount}" if amount <= 0
136
+ return [] if rect[2] == 0 || rect[3] == 0
137
+ x1 = rect[0]
138
+ y1 = rect[1]
139
+ x2 = x1 + rect[2] - 1
140
+ y2 = y1 + rect[3] - 1
141
+ return product_liner_inner(x1, y1, x2, y2, amount)
142
+ end
143
+
144
+ #===矩形内の対角線の座標リストを取得する
145
+ # 矩形内の対角線の座標リストを取得する
146
+ # 引数には、Rect(x,y,w,h)形式のインスタンスを渡す
147
+ # 幅・高さはマイナスの値の設定が可能。
148
+ # 幅・高さのどちらかの値が0の場合は[]が返る
149
+ # 刻みの値は1以上の整数を渡す。0以下の場合は例外が発生する。
150
+ # 結果は[x,y]の配列となるが、正確さを優先したため、必ず刻みの値の間隔で並んでいない
151
+ #(刻みの値より小さいことがある)ことがある
152
+ #_rect_:: 矩形情報
153
+ #_amount_:: 配列を作成する座標の刻み。デフォルトは1
154
+ #返却値:: 矩形左上位置[x,y]の配列(指定の矩形に掛かる位置の組み合わせ)
155
+ def Utility.product_liner_by_square(square, amount = 1)
156
+ raise MiyakoError, "Illegal amount! #{amount}" if amount <= 0
157
+ return [] if (square[2] - square[0]) == 0 || (square[3] - square[1]) == 0
158
+ return product_liner_inner(*square, amount)
159
+ end
160
+
161
+ def Utility.product_inner(x1, y1, x2, y2, size) #:nodoc:
162
+ x_array = ((x1 / size[0])..(x2 / size[0])).to_a.map{|e| e * size[0]}
163
+ y_array = ((y1 / size[1])..(y2 / size[1])).to_a.map{|e| e * size[1]}
164
+ return x_array.product(y_array)
165
+ end
166
+
167
+ #===指定の矩形が格子状のどこに重なっているかを返す
168
+ # position(Point([x,y])形式)を基準として、矩形rect(Rect([x,y,w,h])形式)が、格子状の並べた矩形
169
+ # (基準を[0,0]とした、大きさ[size,size]の矩形をタイル状に並べた物)にある場合、
170
+ #どの格子状の矩形が重なっているかを、矩形の左上座標の配列として渡す(x座標とy座標の組み合わせ)。
171
+ #
172
+ #_position_:: 基準位置
173
+ #_rect_:: 矩形情報
174
+ #返却値:: 矩形左上位置の配列(指定の矩形に掛かる位置の組み合わせ)
175
+ def Utility.product_position(position, rect, size)
176
+ return product_inner(
177
+ position[0] + rect[0],
178
+ position[1] + rect[1],
179
+ position[0] + rect[0] + rect[2] - 1,
180
+ position[1] + rect[1] + rect[3] - 1,
181
+ size
182
+ )
183
+ end
184
+
185
+ #===指定の矩形が格子状のどこに重なっているかを返す
186
+ # 矩形square(Square([x1,y1,x2,y2])形式)が、格子状の並べた矩形
187
+ # (基準を[0,0]とした、大きさ[size,size]の矩形をタイル状に並べた物)にある場合、
188
+ #どの格子状の矩形が重なっているかを、矩形の左上座標の配列として渡す(x座標とy座標の組み合わせ)。
189
+ #_square_:: 矩形情報
190
+ #返却値:: 矩形左上位置の配列(指定の矩形に掛かる位置の組み合わせ)
191
+ def Utility.product_position_by_square(square, size)
192
+ return product_inner(*square.to_a, size)
193
+ end
194
+
195
+ def Utility.product_inner_f(x1, y1, x2, y2, size, skip_even = false) #:nodoc:
196
+ sz = size[0].to_f
197
+ min = (x1.to_f/sz).floor.to_f * sz
198
+ x_array = [min] + get_step_array_f(min, x2.to_f, sz, skip_even)
199
+ sz = size[1].to_f
200
+ min = (y1.to_f/sz).floor.to_f * sz
201
+ y_array = [min] + get_step_array_f(min, y2.to_f, sz, skip_even)
202
+ return x_array.uniq.product(y_array.uniq)
203
+ end
204
+
205
+ #===指定の矩形が格子状のどこに重なっているかを返す(実数で指定)
206
+ #position(Point([x,y])形式)を基準として、矩形rect(Rect([x,y,w,h])形式)が、格子状の並べた矩形
207
+ #(基準を[0.0,0.0]とした、大きさ[size,size]の矩形をタイル状に並べた物)にある場合、
208
+ #どの格子状の矩形が重なっているかを、矩形の左上座標の配列として渡す(x座標とy座標の組み合わせ)。
209
+ #
210
+ #_position_:: 基準位置
211
+ #_rect_:: 矩形情報
212
+ #返却値:: 矩形左上位置の配列(指定の矩形に掛かる位置の組み合わせ)
213
+ def Utility.product_position_f(position, rect, size)
214
+ return product_inner_f(
215
+ position[0] + rect[0],
216
+ position[1] + rect[1],
217
+ position[0] + rect[0] + rect[2],
218
+ position[1] + rect[1] + rect[3],
219
+ size,
220
+ true
221
+ )
222
+ end
223
+
224
+ #===指定の矩形が格子状のどこに重なっているかを返す(実数で指定)
225
+ # 矩形square(Square([x1,y1,x2,y2])形式)が、格子状の並べた矩形
226
+ # (基準を[0.0,0.0]とした、大きさ[size,size]の矩形をタイル状に並べた物)にある場合、
227
+ #どの格子状の矩形が重なっているかを、矩形の左上座標の配列として渡す(x座標とy座標の組み合わせ)。
228
+ #_square_:: 矩形情報
229
+ #返却値:: 矩形左上位置の配列(指定の矩形に掛かる位置の組み合わせ)
230
+ def Utility.product_position_by_square_f(square, size)
231
+ return product_inner_f(*square.to_a, size)
232
+ end
233
+
234
+ #===小線分を移動させたとき、大線分が範囲内かどうかを判別する
235
+ # 移動後の小線分が大線分の範囲内にあるかどうかをtrue/falseで取得する
236
+ #_mini_segment_:: 小線分の範囲。[min,max]で構成された2要素の配列
237
+ #_big_segment_:: 大線分の範囲。[min,max]で構成された2要素の配列
238
+ #_d_:: mini_segmentの移動量
239
+ #_flag_:: 大線分の端いっぱいも範囲外に含めるときはtrueを設定する。デフォルトはfalse
240
+ #返却値:: 範囲内のときはtrue、範囲外の時はfalseを返す
241
+ def Utility.in_bounds?(mini_segment, big_segment, d, flag = false)
242
+ nx = mini_segment[0] + d
243
+ nx2 = mini_segment[1] + d
244
+ nx, nx2 = nx2, nx if nx > nx2
245
+ return flag ? (nx >= big_segment[0] && nx2 <= big_segment[1]) : (nx > big_segment[0] && (nx2 - 1) < big_segment[1])
246
+ end
247
+
248
+ #===小線分を移動させたとき、大線分が範囲内かどうかを判別して、その状態によって値を整数で返す
249
+ # 移動後の小線分の範囲が大線分の範囲内のときは0、
250
+ # マイナス方向で範囲外に出るときは-1、
251
+ # プラス方向で出るときは1を返す
252
+ #_mini_segment_:: 小線分の範囲。[min,max]で構成された2要素の配列
253
+ #_big_segment_:: 大線分の範囲。[min,max]で構成された2要素の配列
254
+ #_d_:: mini_segmentの移動量
255
+ #_flag_:: 大線分の端いっぱいも範囲外に含めるときはtrueを設定する。デフォルトはfalse
256
+ #返却値:: 判別の結果
257
+ def Utility.in_bounds_ex?(mini_segment, big_segment, d, flag = false)
258
+ nx = mini_segment[0] + d
259
+ nx2 = mini_segment[1] + d - 1
260
+ nx, nx2 = nx2, nx if nx > nx2
261
+ return -1 if (nx < big_segment[0]) || (flag && (nx == big_segment[0]))
262
+ return (nx2 > big_segment[1]) || (flag && (nx2 == big_segment[1])) ? 1 : 0
263
+ end
264
+
265
+ #===移動先が表示範囲内かどうかを判別して、その状態によって値を整数で返す
266
+ # 移動後の小線分の範囲が大線分の範囲内のときは0、
267
+ # マイナス方向で範囲外に出るときは1、
268
+ # プラス方向で出るときは-1を返す
269
+ #_mini_segment_:: 小線分の範囲。[min,max]で構成された2要素の配列
270
+ #_big_segment_:: 大線分の範囲。[min,max]で構成された2要素の配列
271
+ #_d_:: mini_segmentの移動量
272
+ #_flag_:: 大線分の端いっぱいも範囲外に含めるときはtrueを設定する。デフォルトはfalse
273
+ #返却値:: 判別の結果
274
+ def Utility.in_bounds_rev?(mini_segment, big_segment, d, flag = false)
275
+ nx = mini_segment[0] + d
276
+ nx2 = mini_segment[1] + d - 1
277
+ nx, nx2 = nx2, nx if nx > nx2
278
+ return 1 if (nx < big_segment[0]) || (flag && (nx == big_segment[0]))
279
+ return (nx2 > big_segment[1]) || (flag && (nx2 == big_segment[1])) ? -1 : 0
280
+ end
281
+
282
+ #===移動先が表示範囲内かどうかを判別して、その状態によって値を整数で返す
283
+ # 移動量が0のときは0、
284
+ # 移動後の小線分の範囲が大線分の範囲内のときは1、
285
+ # 範囲外に出るときは-1を返す
286
+ #_mini_segment_:: 小線分の範囲。[min,max]で構成された2要素の配列
287
+ #_big_segment_:: 大線分の範囲。[min,max]で構成された2要素の配列
288
+ #_d_:: mini_segmentの移動量
289
+ #_flag_:: 大線分の端いっぱいも範囲外に含めるときはtrueを設定する。デフォルトはfalse
290
+ #返却値:: 判別の結果
291
+ def Utility.in_bounds_rev_ex?(mini_segment, big_segment, d, flag = false)
292
+ return 0 if d == 0
293
+ dir = (d <=> 0)
294
+ nx = mini_segment[0] + d
295
+ nx2 = mini_segment[1] + d - 1
296
+ nx, nx2 = nx2, nx if nx > nx2
297
+ return -dir if (nx < big_segment[0]) || (flag && (nx == big_segment[0]))
298
+ return (nx2 > big_segment[1]) || (flag && (nx2 == big_segment[1])) ? -dir : dir
299
+ end
300
+
301
+ #===小線分を移動させたとき、大線分が範囲内かどうかを判別する
302
+ # 移動後の小線分が大線分の範囲内にあるかどうかをtrue/falseで取得する
303
+ #_mini_pos_:: 小線分の開始点の位置
304
+ #_mini_size_:: 小線分の幅。0以上の整数
305
+ #_big_pos_:: 大線分の開始点の位置
306
+ #_big_size_:: 大線分の幅。1以上の整数
307
+ #_d_:: mini_segmentの移動量
308
+ #_flag_:: 大線分の端いっぱいも範囲外に含めるときはtrueを設定する。デフォルトはfalse
309
+ #返却値:: 範囲内のときはtrue、範囲外の時はfalseを返す
310
+ def Utility.in_bounds_by_size?(pos1, size1, pos2, size2, d, flag = false)
311
+ raise MiyakoError, "illegal size1! #{size1}" if size1 < 0
312
+ raise MiyakoError, "illegal size2! #{size2}" if size2 <= 0
313
+ raise MiyakoError, "size1 is more than size2! #{size1}, #{size2}" if size1 > size2
314
+ min_x1 = pos1 + d
315
+ min_x2 = pos1 + size1 + d
316
+ min_x1, min_x2 = min_x2, min_x1 if min_x1 > min_x2
317
+ return flag ? (min_x1 >= pos2 && min_x2 <= pos2+size2) : (minx_x1 > pos2 && min_x2 < pos2+size2)
318
+ end
319
+
320
+ #===小線分を移動させたとき、大線分が範囲内かどうかを判別して、その状態によって値を整数で返す
321
+ # 移動後の小線分の範囲が大線分の範囲内のときは0、
322
+ # マイナス方向で範囲外に出るときは-1、
323
+ # プラス方向で出るときは1を返す
324
+ #_mini_pos_:: 小線分の開始点の位置
325
+ #_mini_size_:: 小線分の幅。0以上の整数
326
+ #_big_pos_:: 大線分の開始点の位置
327
+ #_big_size_:: 大線分の幅。1以上の整数
328
+ #_d_:: mini_segmentの移動量
329
+ #_flag_:: 大線分の端いっぱいも範囲外に含めるときはtrueを設定する。デフォルトはfalse
330
+ #返却値:: 判別の結果
331
+ def Utility.in_bounds_ex_by_size?(pos1, size1, pos2, size2, d, flag = false)
332
+ raise MiyakoError, "illegal size1! #{size1}" if size1 < 0
333
+ raise MiyakoError, "illegal size2! #{size2}" if size2 <= 0
334
+ raise MiyakoError, "size1 is more than size2! #{size1}, #{size2}" if size1 > size2
335
+ min_x1 = pos1 + d
336
+ min_x2 = pos1 + size1 + d
337
+ min_x1, min_x2 = min_x2, min_x1 if min_x1 > min_x2
338
+ return -1 if (min_x1 < pos2) || (flag && (min_x1 == pos2))
339
+ return (min_x2 > pos2+size2) || (flag && (min_x2 == pos2+size2)) ? 1 : 0
340
+ end
341
+
342
+ #===移動先が表示範囲内かどうかを判別して、その状態によって値を整数で返す
343
+ # 移動後の小線分の範囲が大線分の範囲内のときは0、
344
+ # マイナス方向で範囲外に出るときは1、
345
+ # プラス方向で出るときは-1を返す
346
+ #_mini_pos_:: 小線分の開始点の位置
347
+ #_mini_size_:: 小線分の幅。0以上の整数
348
+ #_big_pos_:: 大線分の開始点の位置
349
+ #_big_size_:: 大線分の幅。1以上の整数
350
+ #_d_:: mini_segmentの移動量
351
+ #_flag_:: 大線分の端いっぱいも範囲外に含めるときはtrueを設定する。デフォルトはfalse
352
+ #返却値:: 判別の結果
353
+ def Utility.in_bounds_rev_by_size?(pos1, size1, pos2, size2, d, flag = false)
354
+ raise MiyakoError, "illegal size1! #{size1}" if size1 < 0
355
+ raise MiyakoError, "illegal size2! #{size2}" if size2 <= 0
356
+ raise MiyakoError, "size1 is more than size2! #{size1}, #{size2}" if size1 > size2
357
+ min_x1 = pos1 + d
358
+ min_x2 = pos1 + size1 + d
359
+ min_x1, min_x2 = min_x2, min_x1 if min_x1 > min_x2
360
+ return 1 if (min_x1 < pos2) || (flag && (min_x1 == pos2))
361
+ return (min_x2 > pos2+size2) || (flag && (min_x2 == pos2+size2)) ? -1 : 0
362
+ end
363
+
364
+ #===移動先が表示範囲内かどうかを判別して、その状態によって値を整数で返す
365
+ # 移動量が0のときは0、
366
+ # 移動後の小線分の範囲が大線分の範囲内のときは1、
367
+ # 範囲外に出るときは-1を返す
368
+ #_mini_pos_:: 小線分の開始点の位置
369
+ #_mini_size_:: 小線分の幅。0以上の整数
370
+ #_big_pos_:: 大線分の開始点の位置
371
+ #_big_size_:: 大線分の幅。1以上の整数
372
+ #_d_:: mini_segmentの移動量
373
+ #_flag_:: 大線分の端いっぱいも範囲外に含めるときはtrueを設定する。デフォルトはfalse
374
+ #返却値:: 判別の結果
375
+ def Utility.in_bounds_rev_ex_by_size?(pos1, size1, pos2, size2, d, flag = false)
376
+ return 0 if d == 0
377
+ raise MiyakoError, "illegal size1! #{size1}" if size1 < 0
378
+ raise MiyakoError, "illegal size2! #{size2}" if size2 <= 0
379
+ raise MiyakoError, "size1 is more than size2! #{size1}, #{size2}" if size1 > size2
380
+ dir = (d <=> 0)
381
+ min_x1 = pos1 + d
382
+ min_x2 = pos1 + size1 + d
383
+ min_x1, min_x2 = min_x2, min_x1 if min_x1 > min_x2
384
+ return -dir if (min_x1 < pos2) || (flag && (min_x1 == pos2))
385
+ return (min_x2 > pos2+size2) || (flag && (min_x2 == pos2+size2)) ? -dir : dir
386
+ end
387
+ end
388
+ end
@@ -0,0 +1,140 @@
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
+ #==ビューポートクラス
25
+ # 描画時の表示範囲を変更する
26
+ # 画面全体を基準(640x480の画面のときは(0,0)-(639,479)の範囲)として、範囲を設定する
27
+ # 範囲の設定はいつでも行えるが、描画にはrenderメソッドを呼び出した時の値が反映される
28
+ class Viewport
29
+ attr_accessor :visible #レンダリングの可否(true->描画 false->非描画)
30
+
31
+ #===ビューポートのインスタンスを生成する
32
+ #_x_:: ビューポートの左上位置(x座標)
33
+ #_y_:: ビューポートの左上位置(y座標)
34
+ #_w_:: ビューポートの幅(共に1以上、0以下のときはエラーが出る)
35
+ #_h_:: ビューポートの高さ(共に1以上、0以下のときはエラーが出る)
36
+ def initialize(x, y, w, h)
37
+ raise MiyakoError, "Illegal size! w:#{w} h:#{h}" if (w <= 0 || h <= 0)
38
+ @rect = Rect.new(x, y, w, h)
39
+ @sq = Rect.new(x, y, x+w-1, y+h-1)
40
+ @visible = true
41
+ end
42
+
43
+ #===ビューポートの内容を画面に反映する
44
+ # ブロックが渡ってきたときは、範囲を変更して指定することが出来る(この変更は、本メソッドを呼ぶ時だけ有効)
45
+ # ブロックの引数は、|Rect構造体|が渡される。
46
+ #_block_:: 呼び出し時にブロック付き呼び出しが行われたときのブロック本体。
47
+ #呼び先に渡すことが出来る。ブロックがなければnilが入る
48
+ def render(&block)
49
+ return unless @visible
50
+ if block_given?
51
+ rect = @rect.dup
52
+ yield rect
53
+ Screen.bitmap.set_clip_rect(*rect)
54
+ else
55
+ Screen.bitmap.set_clip_rect(*@rect)
56
+ end
57
+ end
58
+
59
+ #===ビューポートの左上位置を変更する
60
+ # 移動量を指定して、位置を変更する
61
+ # ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す
62
+ #_dx_:: 移動量(x方向)
63
+ #_dy_:: 移動量(y方向)
64
+ #返却値:: 自分自身を返す
65
+ def move(dx,dy)
66
+ orect = rect.to_a[0..1]
67
+ osq = sq.to_a[0..1]
68
+ @rect.move(dx,dy)
69
+ @sq.move(dx, dy)
70
+ if block_given?
71
+ unless yield(self)
72
+ @rect.move_to(*orect)
73
+ @sq.move_to(*osq)
74
+ end
75
+ end
76
+ return self
77
+ end
78
+
79
+ #===ビューポートの左上位置を変更する
80
+ # 移動先を指定して、位置を変更する
81
+ # ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す
82
+ #_x_:: 移動先位置(x方向)
83
+ #_y_:: 移動先位置(y方向)
84
+ #返却値:: 自分自身を返す
85
+ def move_to(x,y)
86
+ orect = rect.to_a[0..1]
87
+ osq = sq.to_a[0..1]
88
+ @rect.move_to(x,y)
89
+ @sq.move_to(x, y)
90
+ if block_given?
91
+ unless yield(self)
92
+ @rect.move_to(*orect)
93
+ @sq.move_to(*osq)
94
+ end
95
+ end
96
+ end
97
+
98
+ #===ビューポートの大きさを変更する
99
+ # 変化量を指定して変更する
100
+ #_dw_:: 幅
101
+ #_dh_:: 高さ
102
+ #返却値:: 自分自身を返す
103
+ def resize(dw,dh)
104
+ raise MiyakoError, "Illegal size! w:#{w} h:#{h}" if ((@rect.w + dw) <= 0 || (@rect.h + dh) <= 0)
105
+ @rect.resize(dw, dh)
106
+ @sq.resize(dw, dh)
107
+ return self
108
+ end
109
+
110
+ #===ビューポートの大きさを変更する
111
+ # 幅と高さを指定して変更する
112
+ #_w_:: 幅
113
+ #_h_:: 高さ
114
+ #返却値:: 自分自身を返す
115
+ def resize_to(w,h)
116
+ raise MiyakoError, "Illegal size! w:#{w} h:#{h}" if (w <= 0 || h <= 0)
117
+ @rect.resize_to(w,h)
118
+ @sq.resize_to(w, h)
119
+ return self
120
+ end
121
+
122
+ #===インスタンスを解放する
123
+ def dispose
124
+ @rect = nil
125
+ @sq = nil
126
+ end
127
+
128
+ #===ビューポートのインスタンスを取得する
129
+ #返却値:: ビューポートの矩形(Rect構造体インスタンス)の複製
130
+ def viewport
131
+ return @rect.dup
132
+ end
133
+
134
+ #===ビューポートのインスタンスを「左、右、上、下」の形式で取得する
135
+ #返却値:: ビューポートの矩形(Square構造体インスタンス)の複製
136
+ def square
137
+ return @sq.dup
138
+ end
139
+ end
140
+ end