Class: ExampleApp::MetalCutout
- Inherits:
-
Zif::UI::NinePanel
- Object
- Zif::Sprite
- Zif::CompoundSprite
- Zif::UI::NinePanel
- ExampleApp::MetalCutout
- Defined in:
- app/ui/panels/metal_cutout.rb
Overview
The Kenney UI Space pack included this inset cutout, desgned to partition the metal panel. This is a nine-slice where the left/right/bottom edges are just fill and don’t need to be defined.
Constant Summary collapse
- SPRITES_PATH =
'sprites/kenney-uipack-space/danhealy-modified'.freeze
- TOP_WIDTH =
7
- BOTTOM_WIDTH =
6
Constants inherited from Zif::Sprite
Instance Attribute Summary
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
-
#initialize(width, height, name = Zif.unique_name('metal_cutout')) ⇒ MetalCutout
constructor
A new instance of MetalCutout.
- #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, name = Zif.unique_name('metal_cutout')) ⇒ MetalCutout
Returns a new instance of MetalCutout.
9 10 11 12 13 14 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 |
# File 'app/ui/panels/metal_cutout.rb', line 9 def initialize(width, height, name=Zif.unique_name('metal_cutout')) super(name) self.upper_left_corner = Zif::Sprite.new.tap do |s| s.x = 0 s.w = TOP_WIDTH s.h = TOP_WIDTH s.path = "#{SPRITES_PATH}/plate_top_corner.png" end self.upper_right_corner = Zif::Sprite.new.tap do |s| s.w = TOP_WIDTH s.h = TOP_WIDTH s.path = "#{SPRITES_PATH}/plate_top_corner.png" s.flip_horizontally = true end self.lower_right_corner = Zif::Sprite.new.tap do |s| s.y = 0 s.w = BOTTOM_WIDTH s.h = BOTTOM_WIDTH s.path = "#{SPRITES_PATH}/plate_bottom_corner.png" s.flip_horizontally = true end self.lower_left_corner = Zif::Sprite.new.tap do |s| s.x = 0 s.y = 0 s.w = BOTTOM_WIDTH s.h = BOTTOM_WIDTH s.path = "#{SPRITES_PATH}/plate_bottom_corner.png" end self.upper_edge = Zif::Sprite.new.tap do |s| s.x = TOP_WIDTH s.h = TOP_WIDTH s.path = "#{SPRITES_PATH}/plate_top_edge.png" end # Need to create the bottom edge so that we don't overlap the corners self.lower_edge = Zif::Sprite.new.tap do |s| s.x = BOTTOM_WIDTH s.y = 0 s.h = BOTTOM_WIDTH s.path = "#{SPRITES_PATH}/plate_center.png" end # No left/right edge, just fill @fill = Zif::Sprite.new.tap do |s| s.x = 0 s.y = BOTTOM_WIDTH s.path = "#{SPRITES_PATH}/plate_center.png" end resize(width, height) end |
Instance Method Details
#resize_height(height) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'app/ui/panels/metal_cutout.rb', line 78 def resize_height(height) return if @h == height @h = height upper_left_corner.y = @h - TOP_WIDTH upper_right_corner.y = @h - TOP_WIDTH upper_edge.y = @h - TOP_WIDTH @fill.h = @h - BOTTOM_WIDTH - TOP_WIDTH end |
#resize_width(width) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/ui/panels/metal_cutout.rb', line 66 def resize_width(width) return if @w == width @w = width upper_right_corner.x = @w - TOP_WIDTH lower_right_corner.x = @w - BOTTOM_WIDTH upper_edge.w = @w - 2 * TOP_WIDTH lower_edge.w = @w - 2 * BOTTOM_WIDTH @fill.w = @w end |