ruby-miyako 2.1.0 → 2.1.1

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 (72) hide show
  1. data/README +275 -20
  2. data/extern.h +21 -1
  3. data/install_miyako.rb +5 -3
  4. data/lib/Miyako/API/audio.rb +11 -6
  5. data/lib/Miyako/API/basic_data.rb +0 -985
  6. data/lib/Miyako/API/bitmap.rb +19 -22
  7. data/lib/Miyako/API/choices.rb +203 -69
  8. data/lib/Miyako/API/collision.rb +451 -9
  9. data/lib/Miyako/API/color.rb +177 -0
  10. data/lib/Miyako/API/diagram.rb +18 -20
  11. data/lib/Miyako/API/fixedmap.rb +207 -73
  12. data/lib/Miyako/API/font.rb +111 -18
  13. data/lib/Miyako/API/i_yuki.rb +1201 -0
  14. data/lib/Miyako/API/input.rb +65 -0
  15. data/lib/Miyako/API/layout.rb +41 -29
  16. data/lib/Miyako/API/map.rb +202 -157
  17. data/lib/Miyako/API/map_event.rb +86 -19
  18. data/lib/Miyako/API/map_struct.rb +268 -0
  19. data/lib/Miyako/API/modules.rb +136 -37
  20. data/lib/Miyako/API/movie.rb +8 -8
  21. data/lib/Miyako/API/parts.rb +63 -20
  22. data/lib/Miyako/API/plane.rb +4 -4
  23. data/lib/Miyako/API/screen.rb +16 -8
  24. data/lib/Miyako/API/sprite.rb +290 -23
  25. data/lib/Miyako/API/sprite_animation.rb +23 -11
  26. data/lib/Miyako/API/sprite_list.rb +406 -183
  27. data/lib/Miyako/API/story.rb +4 -65
  28. data/lib/Miyako/API/struct_point.rb +157 -0
  29. data/lib/Miyako/API/struct_rect.rb +233 -0
  30. data/lib/Miyako/API/struct_segment.rb +641 -0
  31. data/lib/Miyako/API/struct_size.rb +158 -0
  32. data/lib/Miyako/API/struct_square.rb +253 -0
  33. data/lib/Miyako/API/textbox.rb +49 -35
  34. data/lib/Miyako/API/viewport.rb +5 -5
  35. data/lib/Miyako/API/wait_counter.rb +350 -0
  36. data/lib/Miyako/API/yuki.rb +95 -60
  37. data/lib/Miyako/EXT/raster_scroll.rb +30 -8
  38. data/lib/Miyako/EXT/slides.rb +6 -6
  39. data/lib/Miyako/miyako.rb +25 -11
  40. data/lib/miyako.rb +28 -0
  41. data/lib/miyako_require_only.rb +35 -0
  42. data/miyako_basicdata.c +201 -17
  43. data/miyako_collision.c +315 -6
  44. data/miyako_diagram.c +331 -0
  45. data/miyako_drawing.c +26 -7
  46. data/miyako_font.c +259 -129
  47. data/miyako_input_audio.c +24 -14
  48. data/miyako_layout.c +106 -8
  49. data/miyako_no_katana.c +398 -171
  50. data/miyako_sprite2.c +275 -38
  51. data/miyako_transform.c +113 -107
  52. data/miyako_utility.c +34 -48
  53. data/miyako_yuki.c +241 -0
  54. data/sample/Diagram_sample/diagram_sample_yuki2.rb +30 -30
  55. data/sample/Room3/blue.rb +19 -19
  56. data/sample/Room3/green.rb +9 -9
  57. data/sample/Room3/main.rb +12 -12
  58. data/sample/Room3/red.rb +12 -12
  59. data/sample/Room3/title.rb +15 -10
  60. data/sample/collision_test2.rb +2 -1
  61. data/sample/fixed_map_test/fixed_map_sample.rb +7 -6
  62. data/sample/map_test/main_scene.rb +12 -10
  63. data/sample/map_test/map_manager.rb +14 -13
  64. data/sample/rasterscroll.rb +5 -5
  65. data/sample/takahashi.rb +3 -3
  66. data/sample/textbox_sample.rb +7 -6
  67. data/sample/transform.rb +2 -1
  68. data/uninstall_miyako.rb +4 -1
  69. data/win/miyako_no_katana.so +0 -0
  70. metadata +15 -4
  71. data/lib/Miyako/EXT/miyako_cairo.rb +0 -62
  72. data/sample/cairo_sample.rb +0 -25
@@ -19,7 +19,7 @@ class Title
19
19
  @visible = false
20
20
 
21
21
  @title = Sprite.new(:file=>"image/mittsu_no_oheya.png", :type=>:ck)
22
-
22
+
23
23
  @exec = self.method(:view_in)
24
24
  end
25
25
 
@@ -52,7 +52,7 @@ class Title
52
52
  end
53
53
  return TitleCall
54
54
  end
55
-
55
+
56
56
  def update
57
57
  return nil if (Input.pushed_any?(:esc) || Input.quit?)
58
58
  return @exec.call
@@ -79,7 +79,7 @@ class TitleCall
79
79
  @man.center!.bottom!
80
80
  @alpha = 0.0
81
81
  @wait = WaitCounter.new(0.2)
82
- @exec = self.method(:view_in)
82
+ @exec = :view_in
83
83
  end
84
84
 
85
85
  def setup
@@ -92,19 +92,24 @@ class TitleCall
92
92
 
93
93
  def update
94
94
  return nil if (Input.pushed_any?(:esc) || Input.quit?)
95
- return @exec.call
95
+ case @exec
96
+ when :view_in
97
+ return view_in
98
+ when :exec_yuki
99
+ return exec_yuki
100
+ end
96
101
  end
97
-
102
+
98
103
  def final
99
104
  message_box.stop
100
105
  end
101
-
106
+
102
107
  def view_in
103
108
  if @wait.finish?
104
109
  if @alpha == 1.0
105
- @yuki.start_plot
106
- @exec = self.method(:exec_yuki)
110
+ @exec = :exec_yuki
107
111
  message_box.start
112
+ @yuki.start_plot
108
113
  return @now
109
114
  end
110
115
  @alpha += 0.15
@@ -119,7 +124,7 @@ class TitleCall
119
124
  @yuki.update
120
125
  return @yuki.result ? @yuki.result : @now
121
126
  end
122
-
127
+
123
128
  def plot
124
129
  yuki_plot do
125
130
  text("「レディ〜ス エ〜ン ジェントルメ〜ン!」").pause.cr
@@ -179,6 +184,6 @@ class TitleCall
179
184
 
180
185
  def render
181
186
  Bitmap.dec_alpha(@man, Screen, @alpha)
182
- message_box.render if @exec == self.method(:exec_yuki)
187
+ message_box.render if @exec == :exec_yuki
183
188
  end
184
189
  end
@@ -48,6 +48,7 @@ sprites = Array.new(Sprites){|n|
48
48
 
49
49
  # :collisioned => 当たり判定した?
50
50
  {
51
+ :name => "sprite_#{n}",
51
52
  :sprite => sprite,
52
53
  :collision => collision,
53
54
  :amount => get_amount_one
@@ -66,7 +67,7 @@ cautions = {
66
67
  collision_type = collision_list.next
67
68
 
68
69
  # 一気にレンダリング
69
- Screen.pre_render_array << sprites.map{|m| m[:sprite]}
70
+ sprites.each{|m| Screen.pre_render_array << [m[:name], m[:sprite]] }
70
71
 
71
72
  # 判定を切り替えるタイミングを決めるタイマー
72
73
  wait = WaitCounter.new(1.0)
@@ -30,7 +30,7 @@ class Monster
30
30
  def start
31
31
  @anim.start
32
32
  end
33
-
33
+
34
34
  def update(map, events, param)
35
35
  @anim.update_animation
36
36
  end
@@ -41,7 +41,7 @@ class Monster
41
41
 
42
42
  def finish
43
43
  end
44
-
44
+
45
45
  def dispose
46
46
  @anim.dispose
47
47
  @spr.dispose
@@ -103,11 +103,11 @@ class SlimeEvent
103
103
  def init(map, x, y)
104
104
  @slime = Slime.new(map, x, y)
105
105
  end
106
-
106
+
107
107
  def update(map, events, param)
108
108
  @slime.update(map, events, param)
109
109
  end
110
-
110
+
111
111
  def final
112
112
  @slime.finish
113
113
  end
@@ -115,7 +115,7 @@ class SlimeEvent
115
115
  def dispose
116
116
  @slime.dispose
117
117
  end
118
-
118
+
119
119
  def render
120
120
  @slime.render
121
121
  end
@@ -126,7 +126,8 @@ em.add(1, SlimeEvent)
126
126
 
127
127
  # main
128
128
  mp = MapChipFactory.load("./mapchip.csv")
129
- @fmap = FixedMap.new(mp, "./map.csv", em)
129
+ ms = MapStructFactory.load("./map.csv")
130
+ @fmap = FixedMap.new(mp, ms, em)
130
131
 
131
132
  Miyako.main_loop do
132
133
  break if Input.quit_or_escape?
@@ -20,14 +20,19 @@ class MainScene
20
20
  @map.move!(*@chr.margin)
21
21
  # マップの実座標を設定する
22
22
  @map.move!(*@chr.position)
23
-
23
+
24
24
  @parts = CommonParts.instance
25
25
  #Yukiの初期化
26
26
  @yuki = Yuki.new
27
27
  @yuki.select_textbox(@parts.box[:box])
28
28
  @yuki.select_commandbox(@parts.cbox[:box])
29
+ @yuki.vars[:command] = [
30
+ Yuki::Command.new("話す", "話す", "話す", true, nil, talk),
31
+ Yuki::Command.new("調べる", "調べる", "調べる", true, nil, check),
32
+ Yuki::Command.new("その他", "その他", "その他", false, nil, check)
33
+ ]
29
34
  end
30
-
35
+
31
36
  def setup
32
37
  @map.start
33
38
  @chr.start
@@ -56,8 +61,6 @@ class MainScene
56
61
  if event_flags.none?
57
62
  #標準のコマンドを表示
58
63
  @yuki.vars[:now] = @now
59
- @yuki.vars[:talk] = talk
60
- @yuki.vars[:check] = check
61
64
  @yuki.start_plot(command_plot)
62
65
  else
63
66
  #キャラの立ち位置が重なっているイベントを起動
@@ -93,7 +96,7 @@ class MainScene
93
96
  end
94
97
  }
95
98
  @executing_flags = @map.events[0].map{|e| e.executing? }
96
-
99
+
97
100
  #コマンド選択の結果、イベントが実行されたときは、結果として@nowを返す
98
101
  return @now unless @yuki.is_scene?(@yuki.result)
99
102
  return @yuki.result || @now
@@ -112,8 +115,7 @@ class MainScene
112
115
 
113
116
  def command_plot
114
117
  yuki_plot do
115
- command([Yuki::Command.new("話す", "話す", nil, vars[:talk]),
116
- Yuki::Command.new("調べる", "調べる", nil, vars[:check])], vars[:now])
118
+ command(vars[:command], vars[:now])
117
119
  call_plot(select_result) if is_scenario?(select_result)
118
120
  vars[:now]
119
121
  end
@@ -128,7 +130,7 @@ class MainScene
128
130
  clear
129
131
  end
130
132
  end
131
-
133
+
132
134
  #コマンドウィンドウの「話す」を選んだときの処理
133
135
  def talk
134
136
  yuki_plot do
@@ -139,13 +141,13 @@ class MainScene
139
141
  clear
140
142
  end
141
143
  end
142
-
144
+
143
145
  def final
144
146
  @parts.stop
145
147
  @map.stop
146
148
  @chr.stop
147
149
  end
148
-
150
+
149
151
  def dispose
150
152
  @map.dispose
151
153
  @chr.dispose
@@ -1,27 +1,28 @@
1
1
  # -*- encoding: utf-8 -*-
2
- #�}�b�v�Ǘ��N���X
2
+ #マップ管理クラス
3
3
  class MapManager
4
4
  extend Forwardable
5
5
 
6
6
  attr_reader :mapchip
7
-
7
+
8
8
  def initialize
9
9
  @moving = false
10
10
 
11
- #�}�b�v�`�b�v�C���X�^���X�̍쐬
11
+ #マップチップインスタンスの作成
12
12
  @mapchip = MapChipFactory.load("./mapchip.csv")
13
13
 
14
- #�C�x���g��o�^
14
+ #イベントを登録
15
15
  em = MapEventManager.new
16
16
  em.add(3, EventRouteMarker).
17
17
  add(7, EventRouteMarker2).
18
18
  add(8, EventTown).
19
19
  add(16, EventOasis)
20
20
 
21
- #�}�b�v�̍쐬
22
- @map = Map.new(@mapchip, "./map_layer.csv", em)
21
+ #マップの作成
22
+ @map_struct = MapStructFactory.load("./map_layer.csv")
23
+ @map = Map.new(@mapchip, @map_struct, em)
23
24
 
24
- #�C�̃}�b�v�`�b�v��g���A�j���[�V��������摜�ɒu������
25
+ #海のマップチップを波がアニメーションする画像に置き換え
25
26
  @sp = Sprite.new(:file=>"sea.png", :type=>:as)
26
27
  @sp.oh = @sp.w
27
28
  @ar = SpriteAnimation.new(:sprite=>@sp, :wait=>0.4)
@@ -32,21 +33,21 @@ class MapManager
32
33
  @map.move!(dx, dy)
33
34
  @map.events[0].each{|e| e.move!(dx, dy) }
34
35
  end
35
-
36
+
36
37
  def move_to!(x, y)
37
38
  @map.events[0].each{|e| e.move!(x-@map.pos.x, y-@map.pos.y) }
38
39
  @map.move_to!(x, y)
39
40
  end
40
-
41
+
41
42
  def start
42
43
  @ar.start
43
44
  end
44
-
45
+
45
46
  def update
46
47
  @ar.update_animation
47
48
  @map.events[0].each{|e| e.update(@map, @map.events, nil) }
48
49
  end
49
-
50
+
50
51
  def render
51
52
  @map.render
52
53
  end
@@ -62,13 +63,13 @@ class MapManager
62
63
  def stop
63
64
  @ar.stop
64
65
  end
65
-
66
+
66
67
  def dispose
67
68
  @map.dispose
68
69
  @ar.dispose
69
70
  @sp.dispose
70
71
  end
71
-
72
+
72
73
  def_delegators(:@map, :w, :h, :get_code, :get_code_real, :margin, :mapchips, :[])
73
74
  def_delegators(:@map, :collision?, :meet?, :cover?, :events)
74
75
  def_delegators(:@mapchip, :collision_table, :access_table)
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # ���X�^�X�N���[���T���v��
2
+ # ラスタスクロールサンプル
3
3
  # 2009.4.12 Cyross Makoto
4
4
 
5
5
  require 'Miyako/miyako'
@@ -7,9 +7,9 @@ require 'Miyako/EXT/raster_scroll'
7
7
 
8
8
  include Miyako
9
9
 
10
- #1�b��Ƀ��X�^�X�N���[���̃t�F�[�h�A�E�g��ݒ肷��
10
+ #1秒後にラスタスクロールのフェードアウトを設定する
11
11
  wait = WaitCounter.new(1.0).start
12
- # 0.05�b���ƂɁA2���C�����A8�s�N�Z���P�ʂ̃��X�^�X�N���[�����s��
12
+ # 0.05秒ごとに、2ラインずつ、8ピクセル単位のラスタスクロールを行う
13
13
  sprite = Sprite.new(:file => "Animation2/lex_body.png", :type => :ck).centering!
14
14
  rs = RasterScroll.new(sprite).start({:lines => 2, :size => 8, :wait=>WaitCounter.new(0.05)})
15
15
  fade = false
@@ -18,8 +18,8 @@ Miyako.main_loop do
18
18
  break if Input.quit_or_escape?
19
19
  rs.effecting? ? rs.update.render : sprite.render
20
20
  if fade == false && wait.finish?
21
- #1�b�ゲ�ƂɁA���X�^�X�N���[���̕����k�߂�
21
+ #1秒後ごとに、ラスタスクロールの幅を縮める
22
22
  rs.fade_out(1, WaitCounter.new(1.0))
23
23
  fade = true
24
24
  end
25
- end
25
+ end
data/sample/takahashi.rb CHANGED
@@ -32,9 +32,9 @@ shape2 = Shape.text(:font=>Font.serif, :align=>:right){|v|
32
32
  text("DEFG")
33
33
  }
34
34
 
35
- # 自動描画配列にshape1、shape2を組み込み
36
- Screen.auto_render_array << shape1
37
- Screen.auto_render_array << shape2
35
+ # オートレンダー(SpriteList)にshape1、shape2を組み込み
36
+ Screen.auto_render_array << [:shape1, shape1]
37
+ Screen.auto_render_array << [:shape2, shape2]
38
38
 
39
39
  Miyako.main_loop do
40
40
  break if Input.quit_or_escape?
@@ -38,15 +38,16 @@ box_bg.fill([128,0,64,128])
38
38
  @parts[:box].centering!
39
39
  @parts.centering!
40
40
 
41
- p @parts.broad_rect
42
-
43
41
  # 選択肢の作成
44
42
  list = [
45
- [Shape.text(:font=>font, :text=>"選択肢1"), nil, 1],
46
- [Shape.text(:font=>font, :text=>"選択肢2"), nil, 2],
47
- [Shape.text(:font=>font, :text=>"選択肢3"), nil, 3]
43
+ ["選択肢1", "選択肢1", "選択肢1", true, 1],
44
+ ["選択肢2", "選択肢2", "選択肢2", true, 2],
45
+ ["選択肢3", "選択肢3", "選択肢3", true, 3],
46
+ ["選択肢4", "選択肢4", "選択肢4", false, 4]
48
47
  ]
49
48
  @choices = @parts[:box].create_choices_chain(list)
49
+ #@choices[0][1].visible = false
50
+ #@choices[0][2].enable = false
50
51
 
51
52
  # カーソルのアニメーションの開始
52
53
  @parts[:box].start
@@ -183,7 +184,7 @@ Miyako.main_loop do
183
184
  # カーソルの移動
184
185
  @parts[:box].move_cursor(*Input.pushed_amount)
185
186
  # 1ボタンを押したとき、選択状態を解除する
186
- @parts[:box].finish_command if Input.pushed_any?(:btn1)
187
+ @parts[:box].finish_command if (Input.pushed_any?(:btn1) && @parts[:box].enable_choice?)
187
188
  process_textbox
188
189
  next
189
190
  end
data/sample/transform.rb CHANGED
@@ -29,7 +29,8 @@ yscale = 4.0 # 初期拡大率(y座標)4倍
29
29
  angle = 0.0 # 初期回転角度0度
30
30
 
31
31
  # 画面の中心に画像を表示指定(pre_render)
32
- Screen.pre_render_array << [Sprite.new(:file=>"Animation1/m1ku_back.jpg", :type=>:ac).centering!, @sprite]
32
+ Screen.pre_render_array << [:s1, Sprite.new(:file=>"Animation1/m1ku_back.jpg", :type=>:ac).centering!]
33
+ Screen.pre_render_array << [:s2, @sprite]
33
34
 
34
35
  # 画面の変形中心を設定
35
36
  Screen.center_x = Screen.w/2
data/uninstall_miyako.rb CHANGED
@@ -12,8 +12,11 @@ require 'fileutils'
12
12
  puts "Are you sure?(Y/else)"
13
13
  exit unless $stdin.gets.split(//)[0].upcase == 'Y'
14
14
 
15
- sitelibdir = Config::CONFIG["sitelibdir"] + "/Miyako"
15
+ baselibdir = Config::CONFIG["sitelibdir"]
16
+ sitelibdir = baselibdir + "/Miyako"
16
17
 
18
+ FileUtils.remove(baselibdir+"/miyako.rb")
19
+ FileUtils.remove(baselibdir+"/miyako_require_only.rb")
17
20
  FileUtils.remove_dir(sitelibdir, true)
18
21
 
19
22
  puts "uninstall completed."
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-miyako
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyross Makoto
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-09 00:00:00 +09:00
12
+ date: 2009-10-16 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -37,13 +37,16 @@ files:
37
37
  - ./lib/Miyako/API/bitmap.rb
38
38
  - ./lib/Miyako/API/choices.rb
39
39
  - ./lib/Miyako/API/collision.rb
40
+ - ./lib/Miyako/API/color.rb
40
41
  - ./lib/Miyako/API/diagram.rb
41
42
  - ./lib/Miyako/API/drawing.rb
42
43
  - ./lib/Miyako/API/exceptions.rb
43
44
  - ./lib/Miyako/API/fixedmap.rb
44
45
  - ./lib/Miyako/API/font.rb
46
+ - ./lib/Miyako/API/i_yuki.rb
45
47
  - ./lib/Miyako/API/input.rb
46
48
  - ./lib/Miyako/API/layout.rb
49
+ - ./lib/Miyako/API/map_struct.rb
47
50
  - ./lib/Miyako/API/map.rb
48
51
  - ./lib/Miyako/API/map_event.rb
49
52
  - ./lib/Miyako/API/modules.rb
@@ -57,15 +60,22 @@ files:
57
60
  - ./lib/Miyako/API/sprite_animation.rb
58
61
  - ./lib/Miyako/API/sprite_list.rb
59
62
  - ./lib/Miyako/API/story.rb
63
+ - ./lib/Miyako/API/struct_point.rb
64
+ - ./lib/Miyako/API/struct_size.rb
65
+ - ./lib/Miyako/API/struct_rect.rb
66
+ - ./lib/Miyako/API/struct_square.rb
67
+ - ./lib/Miyako/API/struct_segment.rb
60
68
  - ./lib/Miyako/API/textbox.rb
61
69
  - ./lib/Miyako/API/utility.rb
62
70
  - ./lib/Miyako/API/viewport.rb
71
+ - ./lib/Miyako/API/wait_counter.rb
63
72
  - ./lib/Miyako/API/yuki.rb
64
- - ./lib/Miyako/EXT/miyako_cairo.rb
65
73
  - ./lib/Miyako/EXT/raster_scroll.rb
66
74
  - ./lib/Miyako/EXT/slides.rb
67
75
  - ./lib/Miyako/miyako.rb
68
76
  - ./lib/Miyako/miyako_require_only.rb
77
+ - ./lib/miyako.rb
78
+ - ./lib/miyako_require_only.rb
69
79
  - ./logo/EGSR_logo.png
70
80
  - ./logo/EGSR_logo_bg.png
71
81
  - ./logo/EGSR_logo_fg.png
@@ -86,6 +96,8 @@ files:
86
96
  - ./miyako_sprite2.c
87
97
  - ./miyako_transform.c
88
98
  - ./miyako_utility.c
99
+ - ./miyako_yuki.c
100
+ - ./miyako_diagram.c
89
101
  - ./Rakefile
90
102
  - ./README
91
103
  - ./sample/Animation1/m1ku.rb
@@ -113,7 +125,6 @@ files:
113
125
  - ./sample/Animation2/song_title.png
114
126
  - ./sample/ball_action_sample.rb
115
127
  - ./sample/blit_rop.rb
116
- - ./sample/cairo_sample.rb
117
128
  - ./sample/circle_collision_test.rb
118
129
  - ./sample/collision_test.rb
119
130
  - ./sample/collision_test2.rb
@@ -1,62 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # Miyako Extension Cairo-Miyako interface
3
- =begin
4
- Miyako Extention Library v2.1
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
- =end
21
-
22
- begin
23
- loaded = false
24
- require 'cairo'
25
- rescue LoadError
26
- begin
27
- require 'rubygems'
28
- require 'cairo'
29
- loaded = true
30
- rescue LoadError
31
- raise Miyako::MiyakoError, "Sorry, Cairo-Miyako Interface has rcairo." unless loaded
32
- end
33
- end
34
-
35
- module Miyako
36
- #==MiyakoのSpriteクラスのインスタンスとCairoのImageSurfaceクラスのインスタンスとの相互変換モジュール
37
- #要rcairo1.8以降
38
- module MiyakoCairo
39
- #===SpriteインスタンスをCairoのImageSurfaceに変換
40
- #変換したCairo::ImageSurfaceインスタンスは、32ビット(Cairo::Format::ARGB32)の画像を持つ
41
- #_sprite_:: 変換元Spriteインスタンス
42
- #返却値:: 変換したCairo::ImageSurfaceインスタンス
43
- def MiyakoCairo.to_cairo_surface(sprite)
44
- return Cairo::ImageSurface.new(sprite.bitmap.pixels, Cairo::Format::ARGB32, sprite.w, sprite.h, sprite.w * 4)
45
- end
46
-
47
- #===CairoのImageSurfaceをSpriteインスタンスに変換
48
- #変換したSpriteインスタンスは、:acタイプ(但し元画像がCairo::Format::RGB24の時は:asタイプ)の画像を持つ
49
- #_surface_:: 変換元Cairo::ImageSurfaceインスタンス
50
- #返却値:: 変換したSpriteインスタンス
51
- def MiyakoCairo.to_sprite(surface)
52
- # エンディアン判別
53
- if [1].pack("V*") == [1].pack("L*") # リトルエンディアン?
54
- bitmap = SDL::Surface.new_from(surface.data, surface.width, surface.height, 32, surface.stride, 0xff0000, 0xff00, 0xff, 0xff000000)
55
- else # ビッグエンディアン
56
- bitmap = SDL::Surface.new_from(surface.data, surface.width, surface.height, 32, surface.stride, 0xff00, 0xff0000, 0xff000000, 0xff)
57
- end
58
- return Sprite.new(:bitmap => bitmap, :type => :as) if surface.format == Cairo::Format::RGB24
59
- return Sprite.new(:bitmap => bitmap, :type => :ac)
60
- end
61
- end
62
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- # MiyakoCairoサンプル
3
- # 2009.4.12 Cyross Makoto
4
-
5
- require 'Miyako/miyako'
6
- require 'Miyako/EXT/miyako_cairo'
7
-
8
- sprite = Miyako::Sprite.new(:file=>"Animation2/lex_body.png", :type=>:ck)
9
- sprite.bitmap.saveBMP("./sample.bmp")
10
-
11
- surface = Miyako::MiyakoCairo.to_cairo_surface(sprite)
12
- surface.write_to_png("./sample.png")
13
-
14
- surface = Cairo::ImageSurface.new(Cairo::Format::ARGB32, 320, 240)
15
- context = Cairo::Context.new(surface)
16
-
17
- context.set_source_rgb(1.0, 0.5, 0.8)
18
- context.fill{
19
- context.rectangle(50, 50, 150, 100)
20
- }
21
-
22
- surface.write_to_png("./sample2.png")
23
-
24
- sprite = Miyako::MiyakoCairo.to_sprite(surface)
25
- sprite.bitmap.saveBMP("./sample2.bmp")