Class: CyberarmEngine::BackgroundNineSlice
- Inherits:
-
Object
- Object
- CyberarmEngine::BackgroundNineSlice
- Includes:
- Common
- Defined in:
- lib/cyberarm_engine/background_nine_slice.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
- #cheight ⇒ Object
- #cwidth ⇒ Object
- #cx ⇒ Object
- #cy ⇒ Object
- #draw ⇒ Object
- #draw_stretched ⇒ Object
- #draw_tiled ⇒ Object
- #height_scale ⇒ Object
-
#initialize(image_path:, x: 0, y: 0, z: 0, width: 64, height: 64, mode: :tiled, left: 4, top: 4, right: 56, bottom: 56) ⇒ BackgroundNineSlice
constructor
A new instance of BackgroundNineSlice.
- #nine_slice ⇒ Object
- #width_scale ⇒ Object
Methods included from Common
#current_state, #darken, #draw_rect, #fill, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #show_cursor, #show_cursor=, #window
Constructor Details
#initialize(image_path:, x: 0, y: 0, z: 0, width: 64, height: 64, mode: :tiled, left: 4, top: 4, right: 56, bottom: 56) ⇒ BackgroundNineSlice
Returns a new instance of BackgroundNineSlice.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 6 def initialize(image_path:, x: 0, y: 0, z: 0, width: 64, height: 64, mode: :tiled, left: 4, top: 4, right: 56, bottom: 56) @image = get_image(image_path) @x = x @y = y @z = z @width = width @height = height @mode = mode @left = left @top = top @right = right @bottom = bottom nine_slice end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
4 5 6 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 4 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
4 5 6 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 4 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
4 5 6 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 4 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
4 5 6 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 4 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
4 5 6 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 4 def z @z end |
Instance Method Details
#cheight ⇒ Object
54 55 56 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 54 def cheight @cy - @height end |
#cwidth ⇒ Object
50 51 52 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 50 def cwidth @cx - @width end |
#cx ⇒ Object
42 43 44 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 42 def cx @x + @left end |
#cy ⇒ Object
46 47 48 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 46 def cy @y + @top end |
#draw ⇒ Object
66 67 68 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 66 def draw @mode == :tiled ? draw_tiled : draw_stretched end |
#draw_stretched ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 70 def draw_stretched @segment_top_left.draw(@x, @y, @z) @segment_top.draw(@x + @segment_top_left.width, @y, @z, width_scale) # SCALE X @segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z) @segment_right.draw((@x + @width) - @segment_right.width, @y + @top, @z, 1, height_scale) # SCALE Y @segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z) @segment_bottom.draw(@x + @segment_bottom_left.width, (@y + @height) - @segment_bottom.height, @z, width_scale) # SCALE X @segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z) @segment_left.draw(@x, @y + @top, @z, 1, height_scale) # SCALE Y @segment_middle.draw(@x + @segment_top_left.width, @y + @segment_top.height, @z, width_scale, height_scale) # SCALE X and SCALE Y end |
#draw_tiled ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 83 def draw_tiled @segment_top_left.draw(@x, @y, @z) Gosu.clip_to(@x + @segment_top_left.width, @y, @segment_top.width * width_scale, @segment_top.height) do width_scale.ceil.times do |i| @segment_top.draw(@x + @segment_top_left.width + (@segment_top.width * i), @y, @z) # SCALE X end end @segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z) Gosu.clip_to(@x + @width - @segment_top_right.width, @y + @top, @segment_right.width, @segment_right.height * height_scale) do height_scale.ceil.times do |i| @segment_right.draw((@x + @width) - @segment_right.width, @y + @top + (@segment_right.height * i), @z) # SCALE Y end end @segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z) Gosu.clip_to(@x + @segment_top_left.width, @y + @height - @segment_bottom.height, @segment_top.width * width_scale, @segment_bottom.height) do width_scale.ceil.times do |i| @segment_bottom.draw(@x + @segment_bottom_left.width + (@segment_bottom.width * i), (@y + @height) - @segment_bottom.height, @z) # SCALE X end end @segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z) Gosu.clip_to(@x, @y + @top, @segment_left.width, @segment_left.height * height_scale) do height_scale.ceil.times do |i| @segment_left.draw(@x, @y + @top + (@segment_left.height * i), @z) # SCALE Y end end Gosu.clip_to(@x + @segment_top_left.width, @y + @segment_top.height, @width - (@segment_left.width + @segment_right.width), @height - (@segment_top.height + @segment_bottom.height)) do height_scale.ceil.times do |y| width_scale.ceil.times do |x| @segment_middle.draw(@x + @segment_top_left.width + (@segment_middle.width * x), @y + @segment_top.height + (@segment_middle.height * y), @z) # SCALE X and SCALE Y end end end end |
#height_scale ⇒ Object
62 63 64 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 62 def height_scale height_scale = (@height - (@top + (@image.height - @bottom))).to_f / (@bottom - @top) end |
#nine_slice ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 26 def nine_slice @segment_top_left = Gosu.render(@left, @top) { @image.draw(0, 0, 0) } @segment_top_right = Gosu.render(@image.width - @right, @top) { @image.draw(-@right, 0, 0) } @segment_left = Gosu.render(@left, @bottom - @top) { @image.draw(0, -@top, 0) } @segment_right = Gosu.render(@image.width - @right, @bottom - @top) { @image.draw(-@right, -@top, 0) } @segment_bottom_left = Gosu.render(@left, @image.height - @bottom) { @image.draw(0, -@bottom, 0) } @segment_bottom_right = Gosu.render(@image.width - @right, @image.height - @bottom) { @image.draw(-@right, -@bottom, 0) } @segment_top = Gosu.render(@right - @left, @top) { @image.draw(-@left, 0, 0) } @segment_bottom = Gosu.render(@right - @left, @image.height - @bottom) { @image.draw(-@left, -@bottom, 0) } @segment_middle = Gosu.render(@right - @left, @bottom - @top) { @image.draw(-@left, -@top, 0) } end |
#width_scale ⇒ Object
58 59 60 |
# File 'lib/cyberarm_engine/background_nine_slice.rb', line 58 def width_scale width_scale = (@width - (@left + (@image.width - @right))).to_f / (@right - @left) end |