Class: ExampleApp::GlassPanel

Inherits:
Zif::UI::NinePanel show all
Defined in:
app/ui/panels/glass_panel.rb

Overview

The Kenney UI Space pack has transparent panels with optional cut corners. This is a normal nine slice where each corner has two options.

Constant Summary collapse

SPRITES_PATH =
'sprites/kenney-uipack-space/danhealy-modified'.freeze
CUT_CORNER =
"#{SPRITES_PATH}/glass_cut_corner.png".freeze
ROUND_CORNER =
"#{SPRITES_PATH}/glass_round_corner.png".freeze
WIDTH =
16

Constants inherited from Zif::Sprite

Zif::Sprite::BLENDMODE

Instance Attribute Summary collapse

Attributes inherited from Zif::UI::NinePanel

#corners, #edges, #fill

Attributes inherited from Zif::CompoundSprite

#labels, #sprites

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

#actions, #dirty

Instance Method Summary collapse

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

#draw_override, #source_rect

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

#absorb_click?, #clicked?

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

#assign

Constructor Details

#initialize(width, height, cut_corners = [false, false, false, false], name = Zif.unique_name('glass_panel')) ⇒ GlassPanel

Returns a new instance of GlassPanel.

[View source]

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/ui/panels/glass_panel.rb', line 12

def initialize(width, height, cut_corners=[false, false, false, false], name=Zif.unique_name('glass_panel'))
  super(name)

  self.upper_left_corner = Zif::Sprite.new.tap do |s|
    s.x = 0
    s.w = WIDTH
    s.h = WIDTH
  end

  self.upper_right_corner = Zif::Sprite.new.tap do |s|
    s.w = WIDTH
    s.h = WIDTH
    s.flip_horizontally = true
  end

  self.lower_right_corner = Zif::Sprite.new.tap do |s|
    s.y = 0
    s.w = WIDTH
    s.h = WIDTH
    s.flip_vertically = true
    s.flip_horizontally = true
  end

  self.lower_left_corner = Zif::Sprite.new.tap do |s|
    s.x = 0
    s.y = 0
    s.w = WIDTH
    s.h = WIDTH
    s.flip_vertically = true
  end

  self.upper_edge = Zif::Sprite.new.tap do |s|
    s.x = WIDTH
    s.h = WIDTH
    s.path = "#{SPRITES_PATH}/glass_side.png"
  end

  self.right_edge = Zif::Sprite.new.tap do |s|
    s.y = WIDTH
    s.w = WIDTH
    s.path = "#{SPRITES_PATH}/glass_side_right.png"
  end

  self.lower_edge = Zif::Sprite.new.tap do |s|
    s.x = WIDTH
    s.y = 0
    s.h = WIDTH
    s.path = "#{SPRITES_PATH}/glass_side.png"
    s.flip_vertically = true
  end

  self.left_edge = Zif::Sprite.new.tap do |s|
    s.x = 0
    s.y = WIDTH
    s.w = WIDTH
    s.path = "#{SPRITES_PATH}/glass_side_right.png"
    s.flip_horizontally = true
  end

  @fill = Zif::Sprite.new.tap do |s|
    s.x = WIDTH
    s.y = WIDTH
    s.path = "#{SPRITES_PATH}/glass_center.png"
  end

  resize(width, height)
  change_cuts(cut_corners)
end

Instance Attribute Details

#cutsObject

Returns the value of attribute cuts.


10
11
12
# File 'app/ui/panels/glass_panel.rb', line 10

def cuts
  @cuts
end

Instance Method Details

#change_cuts(cut_corners) ⇒ Object

[View source]

81
82
83
84
85
86
87
# File 'app/ui/panels/glass_panel.rb', line 81

def change_cuts(cut_corners)
  @cuts = cut_corners
  lower_left_corner.path  = cut_corners[0] ? CUT_CORNER : ROUND_CORNER
  lower_right_corner.path = cut_corners[1] ? CUT_CORNER : ROUND_CORNER
  upper_right_corner.path = cut_corners[2] ? CUT_CORNER : ROUND_CORNER
  upper_left_corner.path  = cut_corners[3] ? CUT_CORNER : ROUND_CORNER
end

#resize_height(height) ⇒ Object

[View source]

102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/ui/panels/glass_panel.rb', line 102

def resize_height(height)
  return if @h == height

  @h = height

  upper_left_corner.y  = @h - WIDTH
  upper_right_corner.y = @h - WIDTH
  upper_edge.y         = @h - WIDTH
  right_edge.h         = @h - 2 * WIDTH
  left_edge.h          = @h - 2 * WIDTH
  @fill.h = @h - 2 * WIDTH
end

#resize_width(width) ⇒ Object

[View source]

89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/ui/panels/glass_panel.rb', line 89

def resize_width(width)
  return if @w == width

  @w = width

  upper_right_corner.x = @w - WIDTH
  lower_right_corner.x = @w - WIDTH
  upper_edge.w         = @w - 2 * WIDTH
  right_edge.x         = @w - WIDTH
  lower_edge.w         = @w - 2 * WIDTH
  @fill.w = @w - 2 * WIDTH
end