Class: Zif::UI::NinePanel Abstract
- Inherits:
-
CompoundSprite
- Object
- Sprite
- CompoundSprite
- Zif::UI::NinePanel
- Defined in:
- lib/zif/ui/nine_panel.rb
Overview
Subclass and override at least #resize_width and #resize_height to behave in a way which makes sense for your specific assets. Suggested to override #initialize and call super
before setting @corners @edges and @fill to reasonable defaults for the assets you are using.
A 9-slice panel/window
It is able to have multiple sprites because it inherits from CompoundSprite.
See below for subclassing examples such as ExampleApp::GlassPanel
Direct Known Subclasses
ExampleApp::GlassPanel, ExampleApp::MetalCutout, ExampleApp::MetalPanel
Constant Summary
Constants inherited from Sprite
Instance Attribute Summary collapse
-
#corners ⇒ Array<Zif::Sprite>
The corner slices in this order: [upper_left, upper_right, lower_left, lower_right].
-
#edges ⇒ Array<Zif::Sprite>
The edge slices in this order: [upper, right, lower, left].
-
#fill ⇒ Zif::Sprite
The center sprite.
Attributes inherited from CompoundSprite
Attributes inherited from 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 Clickable
#on_mouse_changed, #on_mouse_down, #on_mouse_up
Attributes included from Actions::Animatable
#animation_sequences, #cur_animation
Attributes included from Actions::Actionable
1. Public Interface collapse
-
#height ⇒ Integer
Height.
- #height=(new_height) ⇒ Object
-
#initialize(name = Zif.unique_name('nine_panel')) ⇒ NinePanel
constructor
Draw 4 corners, 4 edges (with optional transition), then fill the center.
-
#lower_left_corner ⇒ Zif::Sprite
The specified corner.
- #lower_left_corner=(new_corner) ⇒ Object
-
#lower_left_edge ⇒ Zif::Sprite
The specified edge.
- #lower_left_edge=(new_edge) ⇒ Object
-
#lower_right_corner ⇒ Zif::Sprite
The specified corner.
- #lower_right_corner=(new_corner) ⇒ Object
-
#lower_right_edge ⇒ Zif::Sprite
The specified edge.
- #lower_right_edge=(new_edge) ⇒ Object
-
#resize(width, height) ⇒ Object
A convenience for setting both width and height.
-
#resize_height(_height) ⇒ Object
In your subclass, please redefine this method so that it can be scaled properly.
-
#resize_width(_width) ⇒ Object
In your subclass, please redefine this method so that it can be scaled properly.
-
#upper_left_corner ⇒ Zif::Sprite
The specified corner.
- #upper_left_corner=(new_corner) ⇒ Object
-
#upper_left_edge ⇒ Zif::Sprite
The specified edge.
- #upper_left_edge=(new_edge) ⇒ Object
-
#upper_right_corner ⇒ Zif::Sprite
The specified corner.
- #upper_right_corner=(new_corner) ⇒ Object
-
#upper_right_edge ⇒ Zif::Sprite
The specified edge.
- #upper_right_edge=(new_edge) ⇒ Object
-
#width ⇒ Integer
Width.
-
#width=(new_width) ⇒ Object
This class has special getters and setters for
width
andheight
.
2. Private-ish methods collapse
-
#sprites ⇒ Array<Zif::Sprite>
private
This is an override to allow CompoundSprite to work with the three separate arrays.
Methods inherited from CompoundSprite
Methods inherited from 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 Clickable
Methods included from Actions::Animatable
#new_basic_animation, #new_tiled_animation, #register_animation_sequence, #run_animation_sequence, #stop_animating
Methods included from 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 Serializable
#exclude_from_serialize, #inspect, #serialize, #to_s
Methods included from Assignable
Constructor Details
#initialize(name = Zif.unique_name('nine_panel')) ⇒ NinePanel
Draw 4 corners, 4 edges (with optional transition), then fill the center
27 28 29 30 31 |
# File 'lib/zif/ui/nine_panel.rb', line 27 def initialize(name=Zif.unique_name('nine_panel')) super(name) @corners = Array.new(4) # ul, ur, ll, lr @edges = Array.new(4) # upper, right, lower, left end |
Instance Attribute Details
#corners ⇒ Array<Zif::Sprite>
Returns The corner slices in this order: [upper_left, upper_right, lower_left, lower_right].
14 15 16 |
# File 'lib/zif/ui/nine_panel.rb', line 14 def corners @corners end |
#edges ⇒ Array<Zif::Sprite>
Returns The edge slices in this order: [upper, right, lower, left].
16 17 18 |
# File 'lib/zif/ui/nine_panel.rb', line 16 def edges @edges end |
#fill ⇒ Zif::Sprite
Returns The center sprite.
18 19 20 |
# File 'lib/zif/ui/nine_panel.rb', line 18 def fill @fill end |
Instance Method Details
#height ⇒ Integer
Returns height.
75 76 77 |
# File 'lib/zif/ui/nine_panel.rb', line 75 def height @h end |
#height=(new_height) ⇒ Object
70 71 72 |
# File 'lib/zif/ui/nine_panel.rb', line 70 def height=(new_height) resize_height(new_height) end |
#lower_left_corner ⇒ Zif::Sprite
Returns The specified corner. Grabs the correct element from #corners.
99 100 101 102 |
# File 'lib/zif/ui/nine_panel.rb', line 99 %i[upper_left upper_right lower_right lower_left].each_with_index do |name, idx| define_method("#{name}_corner") { @corners[idx] } define_method("#{name}_corner=") { |new_corner| @corners[idx] = new_corner } end |
#lower_left_corner=(new_corner) ⇒ Object
99 100 101 102 |
# File 'lib/zif/ui/nine_panel.rb', line 99 %i[upper_left upper_right lower_right lower_left].each_with_index do |name, idx| define_method("#{name}_corner") { @corners[idx] } define_method("#{name}_corner=") { |new_corner| @corners[idx] = new_corner } end |
#lower_left_edge ⇒ Zif::Sprite
Returns The specified edge. Grabs the correct element from #edges.
121 122 123 124 |
# File 'lib/zif/ui/nine_panel.rb', line 121 %i[upper right lower left].each_with_index do |name, idx| define_method("#{name}_edge") { @edges[idx] } define_method("#{name}_edge=") { |new_edge| @edges[idx] = new_edge } end |
#lower_left_edge=(new_edge) ⇒ Object
121 122 123 124 |
# File 'lib/zif/ui/nine_panel.rb', line 121 %i[upper right lower left].each_with_index do |name, idx| define_method("#{name}_edge") { @edges[idx] } define_method("#{name}_edge=") { |new_edge| @edges[idx] = new_edge } end |
#lower_right_corner ⇒ Zif::Sprite
Returns The specified corner. Grabs the correct element from #corners.
99 100 101 102 |
# File 'lib/zif/ui/nine_panel.rb', line 99 %i[upper_left upper_right lower_right lower_left].each_with_index do |name, idx| define_method("#{name}_corner") { @corners[idx] } define_method("#{name}_corner=") { |new_corner| @corners[idx] = new_corner } end |
#lower_right_corner=(new_corner) ⇒ Object
99 100 101 102 |
# File 'lib/zif/ui/nine_panel.rb', line 99 %i[upper_left upper_right lower_right lower_left].each_with_index do |name, idx| define_method("#{name}_corner") { @corners[idx] } define_method("#{name}_corner=") { |new_corner| @corners[idx] = new_corner } end |
#lower_right_edge ⇒ Zif::Sprite
Returns The specified edge. Grabs the correct element from #edges.
121 122 123 124 |
# File 'lib/zif/ui/nine_panel.rb', line 121 %i[upper right lower left].each_with_index do |name, idx| define_method("#{name}_edge") { @edges[idx] } define_method("#{name}_edge=") { |new_edge| @edges[idx] = new_edge } end |
#lower_right_edge=(new_edge) ⇒ Object
121 122 123 124 |
# File 'lib/zif/ui/nine_panel.rb', line 121 %i[upper right lower left].each_with_index do |name, idx| define_method("#{name}_edge") { @edges[idx] } define_method("#{name}_edge=") { |new_edge| @edges[idx] = new_edge } end |
#resize(width, height) ⇒ Object
A convenience for setting both width and height.
36 37 38 39 40 |
# File 'lib/zif/ui/nine_panel.rb', line 36 def resize(width, height) resize_width(width) resize_height(height) view_actual_size! end |
#resize_height(_height) ⇒ Object
In your subclass, please redefine this method so that it can be scaled properly
50 51 52 |
# File 'lib/zif/ui/nine_panel.rb', line 50 def resize_height(_height) raise "#{self.class.name} is expected to define #resize_height, to properly set component sprite attributes" end |
#resize_width(_width) ⇒ Object
In your subclass, please redefine this method so that it can be scaled properly
44 45 46 |
# File 'lib/zif/ui/nine_panel.rb', line 44 def resize_width(_width) raise "#{self.class.name} is expected to define #resize_width, to properly set component sprite attributes" end |
#sprites ⇒ Array<Zif::Sprite>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This is an override to allow CompoundSprite to work with the three separate arrays
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/zif/ui/nine_panel.rb', line 132 def sprites unless @sprites_assigned @sprites.unshift( @fill, *@edges, *@corners ) @sprites.flatten! @sprites_assigned = true end @sprites end |
#upper_left_corner ⇒ Zif::Sprite
Returns The specified corner. Grabs the correct element from #corners.
99 100 101 102 |
# File 'lib/zif/ui/nine_panel.rb', line 99 %i[upper_left upper_right lower_right lower_left].each_with_index do |name, idx| define_method("#{name}_corner") { @corners[idx] } define_method("#{name}_corner=") { |new_corner| @corners[idx] = new_corner } end |
#upper_left_corner=(new_corner) ⇒ Object
99 100 101 102 |
# File 'lib/zif/ui/nine_panel.rb', line 99 %i[upper_left upper_right lower_right lower_left].each_with_index do |name, idx| define_method("#{name}_corner") { @corners[idx] } define_method("#{name}_corner=") { |new_corner| @corners[idx] = new_corner } end |
#upper_left_edge ⇒ Zif::Sprite
Returns The specified edge. Grabs the correct element from #edges.
121 122 123 124 |
# File 'lib/zif/ui/nine_panel.rb', line 121 %i[upper right lower left].each_with_index do |name, idx| define_method("#{name}_edge") { @edges[idx] } define_method("#{name}_edge=") { |new_edge| @edges[idx] = new_edge } end |
#upper_left_edge=(new_edge) ⇒ Object
121 122 123 124 |
# File 'lib/zif/ui/nine_panel.rb', line 121 %i[upper right lower left].each_with_index do |name, idx| define_method("#{name}_edge") { @edges[idx] } define_method("#{name}_edge=") { |new_edge| @edges[idx] = new_edge } end |
#upper_right_corner ⇒ Zif::Sprite
Returns The specified corner. Grabs the correct element from #corners.
99 100 101 102 |
# File 'lib/zif/ui/nine_panel.rb', line 99 %i[upper_left upper_right lower_right lower_left].each_with_index do |name, idx| define_method("#{name}_corner") { @corners[idx] } define_method("#{name}_corner=") { |new_corner| @corners[idx] = new_corner } end |
#upper_right_corner=(new_corner) ⇒ Object
99 100 101 102 |
# File 'lib/zif/ui/nine_panel.rb', line 99 %i[upper_left upper_right lower_right lower_left].each_with_index do |name, idx| define_method("#{name}_corner") { @corners[idx] } define_method("#{name}_corner=") { |new_corner| @corners[idx] = new_corner } end |
#upper_right_edge ⇒ Zif::Sprite
Returns The specified edge. Grabs the correct element from #edges.
121 122 123 124 |
# File 'lib/zif/ui/nine_panel.rb', line 121 %i[upper right lower left].each_with_index do |name, idx| define_method("#{name}_edge") { @edges[idx] } define_method("#{name}_edge=") { |new_edge| @edges[idx] = new_edge } end |
#upper_right_edge=(new_edge) ⇒ Object
121 122 123 124 |
# File 'lib/zif/ui/nine_panel.rb', line 121 %i[upper right lower left].each_with_index do |name, idx| define_method("#{name}_edge") { @edges[idx] } define_method("#{name}_edge=") { |new_edge| @edges[idx] = new_edge } end |
#width ⇒ Integer
Returns width.
64 65 66 |
# File 'lib/zif/ui/nine_panel.rb', line 64 def width @w end |
#width=(new_width) ⇒ Object
This class has special getters and setters for width
and height
. The reason is that it’s using #resize_width and #resize_height internally to support rescaling of the panel. This allows you to change the width and height using a Actions::Action as this is already an Actions::Actionable via CompoundSprite inheritance.
59 60 61 |
# File 'lib/zif/ui/nine_panel.rb', line 59 def width=(new_width) resize_width(new_width) end |