Class: ExampleApp::MetalPanel
- Inherits:
-
Zif::UI::NinePanel
- Object
- Zif::Sprite
- Zif::CompoundSprite
- Zif::UI::NinePanel
- ExampleApp::MetalPanel
- Defined in:
- app/ui/panels/metal_panel.rb
Overview
The Kenney UI Space pack contains these metal panels which have a colorful tab in the upper left. This is a bit more complex than a normal nine-slice, since the top edge will actually have 3 parts So we are using NinePanelEdge for this, and regular sprites for the other 8 sections.
Constant Summary collapse
- SPRITES_PATH =
'sprites/kenney-uipack-space/danhealy-modified'.freeze
- VALID_COLORS =
%i[blue green red yellow].freeze
- BIG_CORNER =
32
- SMALL_CORNER =
16
- TRANSITION_WIDTH =
12
Constants inherited from Zif::Sprite
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#upper_edge_panel ⇒ Object
Returns the value of attribute upper_edge_panel.
Attributes inherited from Zif::UI::NinePanel
Attributes inherited from Zif::CompoundSprite
Attributes inherited from Zif::Sprite
#a, #angle, #b, #g, #h, #logical_x, #logical_y, #name, #path, #r, #render_target, #source_h, #source_w, #source_x, #source_y, #w, #x, #y, #z_index
Attributes included from Zif::Clickable
#on_mouse_changed, #on_mouse_down, #on_mouse_up
Attributes included from Zif::Actions::Animatable
#animation_sequences, #cur_animation
Attributes included from Zif::Actions::Actionable
Instance Method Summary collapse
- #change_color(color) ⇒ Object
-
#initialize(width, height, label = nil, color = :blue, name = Zif.unique_name('metal_panel')) ⇒ MetalPanel
constructor
A new instance of MetalPanel.
- #resize_height(height) ⇒ Object
- #resize_width(width) ⇒ Object
Methods inherited from Zif::UI::NinePanel
#height, #height=, #lower_left_corner, #lower_left_corner=, #lower_left_edge, #lower_left_edge=, #lower_right_corner, #lower_right_corner=, #lower_right_edge, #lower_right_edge=, #resize, #sprites, #upper_left_corner, #upper_left_corner=, #upper_left_edge, #upper_left_edge=, #upper_right_corner, #upper_right_corner=, #upper_right_edge, #upper_right_edge=, #width, #width=
Methods inherited from Zif::CompoundSprite
Methods inherited from Zif::Sprite
#blend, #blend=, #center, #center_x, #center_y, #clicked?, #color, #color=, #dup_and_assign, #exclude_from_serialize, #hide, #rect, rect_array_to_hash, rect_array_to_source_hash, #rect_hash, rect_hash_to_source_hash, #show, #source_as_rect_hash, #source_center, #source_is_set?, #source_rect, #source_rect_hash, #source_wh, #source_xy, #to_h, #view_actual_size!, #wh, #xy, #zoom_factor
Methods included from Zif::Clickable
Methods included from Zif::Actions::Animatable
#new_basic_animation, #new_tiled_animation, #register_animation_sequence, #run_animation_sequence, #stop_animating
Methods included from Zif::Actions::Actionable
#bounce_forever_around, #delayed_action, #fade_in, #fade_out, #fade_out_and_in_forever, #new_action, #perform_actions, #run_action, #running_actions?, #stop_action
Methods included from Zif::Serializable
#exclude_from_serialize, #inspect, #serialize, #to_s
Methods included from Zif::Assignable
Constructor Details
#initialize(width, height, label = nil, color = :blue, name = Zif.unique_name('metal_panel')) ⇒ MetalPanel
Returns a new instance of MetalPanel.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/ui/panels/metal_panel.rb', line 15 def initialize(width, height, label=nil, color=:blue, name=Zif.unique_name('metal_panel')) super(name) @upper_edge_panel = Zif::UI::NinePanelEdge.new @upper_edge_panel.left_edge_height = BIG_CORNER @upper_edge_panel.transition_height = BIG_CORNER @upper_edge_panel.transition_width = TRANSITION_WIDTH @upper_edge_panel.right_edge_path = "#{SPRITES_PATH}/metal_side.png" @upper_edge_panel.right_edge_height = SMALL_CORNER # Gotta define this first so we can set the color. self.upper_left_corner = Zif::Sprite.new.tap do |s| s.x = 0 s.w = BIG_CORNER s.h = BIG_CORNER end change_color(color) @upper_edge_panel.init_sprites self.right_edge = Zif::Sprite.new.tap do |s| s.y = SMALL_CORNER s.w = SMALL_CORNER s.path = "#{SPRITES_PATH}/metal_side_right.png" end self.lower_edge = Zif::Sprite.new.tap do |s| s.x = SMALL_CORNER s.y = 0 s.h = SMALL_CORNER s.path = "#{SPRITES_PATH}/metal_side.png" s.flip_vertically = true end self.left_edge = Zif::Sprite.new.tap do |s| s.x = 0 s.y = SMALL_CORNER s.w = SMALL_CORNER s.path = "#{SPRITES_PATH}/metal_side_right.png" s.flip_horizontally = true end self.upper_right_corner = Zif::Sprite.new.tap do |s| s.w = SMALL_CORNER s.h = SMALL_CORNER s.path = "#{SPRITES_PATH}/metal_corner.png" s.flip_horizontally = true end self.lower_right_corner = Zif::Sprite.new.tap do |s| s.y = 0 s.w = SMALL_CORNER s.h = SMALL_CORNER s.path = "#{SPRITES_PATH}/metal_corner.png" s.flip_horizontally = true s.flip_vertically = true end self.lower_left_corner = Zif::Sprite.new.tap do |s| s.x = 0 s.y = 0 s.w = SMALL_CORNER s.h = SMALL_CORNER s.path = "#{SPRITES_PATH}/metal_corner.png" s.flip_vertically = true end @fill = Zif::Sprite.new.tap do |s| s.x = SMALL_CORNER s.y = SMALL_CORNER s.path = "#{SPRITES_PATH}/metal_center.png" end if label @header = FutureLabel.new(label, size: -1, alignment: :left) @header.x = 10 @labels << @header end resize(width, height) self.upper_edge = @upper_edge_panel.sprites end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
6 7 8 |
# File 'app/ui/panels/metal_panel.rb', line 6 def header @header end |
#upper_edge_panel ⇒ Object
Returns the value of attribute upper_edge_panel.
6 7 8 |
# File 'app/ui/panels/metal_panel.rb', line 6 def upper_edge_panel @upper_edge_panel end |
Instance Method Details
#change_color(color) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'app/ui/panels/metal_panel.rb', line 99 def change_color(color) @color = VALID_COLORS.include?(color) ? color : :blue @upper_edge_panel.transition_path = "#{SPRITES_PATH}/metal_#{@color}_side_transition.png" @upper_edge_panel.left_edge_path = "#{SPRITES_PATH}/metal_#{@color}_side.png" upper_left_corner.path = "#{SPRITES_PATH}/metal_#{@color}_corner.png" @upper_edge_panel.update_paths end |
#resize_height(height) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/ui/panels/metal_panel.rb', line 126 def resize_height(height) return if @h == height @h = height @upper_edge_panel.reposition(BIG_CORNER, @h - BIG_CORNER) upper_right_corner.y = @h - SMALL_CORNER upper_left_corner.y = @h - BIG_CORNER left_edge.h = @h - 2 * SMALL_CORNER right_edge.h = @h - 2 * SMALL_CORNER @fill.h = @h - 2 * SMALL_CORNER @header.y = @h - 4 end |
#resize_width(width) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/ui/panels/metal_panel.rb', line 109 def resize_width(width) return if @w == width @w = width @upper_edge_panel.resize_width(@w - BIG_CORNER - SMALL_CORNER) @upper_edge_panel.reposition(BIG_CORNER, @h - BIG_CORNER) right_edge.x = BIG_CORNER + upper_edge_panel.width lower_edge.w = @w - 2 * SMALL_CORNER upper_right_corner.x = @w - SMALL_CORNER lower_right_corner.x = @w - SMALL_CORNER @fill.w = @w - 2 * SMALL_CORNER @header.truncate(@upper_edge_panel.left_edge.w + (upper_left_corner.w - @header.x)) end |