Class: Dialog
Defined Under Namespace
Classes: Label
Instance Attribute Summary
Attributes inherited from Scene
Instance Method Summary collapse
- #activated ⇒ Object
- #addButton(*args, **kwargs, &block) ⇒ Object
- #addElement(sprite) ⇒ Object
- #addLabel(label, rgb: [255], alpha: nil, fontSize: 24, align: CENTER, &block) ⇒ Object
- #addSpace(height = 0) ⇒ Object
- #close ⇒ Object
- #deactivated ⇒ Object
- #draw ⇒ Object
- #elements ⇒ Object
- #group(flow = :horizontal, space: nil, &block) ⇒ Object
-
#initialize(background: 0, alpha: 100, z: 1000, &block) ⇒ Dialog
constructor
A new instance of Dialog.
- #resized(w, h) ⇒ Object
- #sprites ⇒ Object
Methods inherited from Scene
#active?, #add, #emitParticle, #focusChanged, #mouseDragged, #mouseMoved, #mousePressed, #mouseReleased, #particle, #pause, #remove, #resume, #transition, #update
Constructor Details
#initialize(background: 0, alpha: 100, z: 1000, &block) ⇒ Dialog
Returns a new instance of Dialog.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 10 def initialize(background: 0, alpha: 100, z: 1000, &block) @background, @alpha = background, 0 @elements = [] super .z = z group :vertical, &block if block animate 0.2 do |t| @alpha = alpha * t end end |
Instance Method Details
#activated ⇒ Object
94 95 96 97 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 94 def activated() super parent.pause end |
#addButton(*args, **kwargs, &block) ⇒ Object
59 60 61 62 63 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 59 def addButton(*args, **kwargs, &block) addElement Button.new(*args, **kwargs).tap {|b| b.clicked &block } end |
#addElement(sprite) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 34 def addElement(sprite) (@group || @elements).push sprite sprite.z = .z addSprite sprite if active? updateLayout sprite end |
#addLabel(label, rgb: [255], alpha: nil, fontSize: 24, align: CENTER, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 42 def addLabel(label, rgb: [255], alpha: nil, fontSize: 24, align: CENTER, &block) bounds = textFont.textBounds label, 0, 0, fontSize addElement Label.new(0, 0, width - MARGIN * 2, bounds.h).tap {|sp| sp.label = label sp.draw do r, g, b, a = skin.translucentBackgroundColor fill r, g, b, alpha || (a * 3) rect 0, -MARGIN / 2, sp.w, sp.h + MARGIN textAlign align, CENTER textSize fontSize fill *rgb text sp.label, 0, 0, sp.w, sp.h end sp.mouseClicked &block } end |
#addSpace(height = 0) ⇒ Object
65 66 67 68 69 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 65 def addSpace(height = 0) addElement Sprite.new(0, 0, 1, height).tap {|sp| sp.draw {} } end |
#close ⇒ Object
71 72 73 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 71 def close() delay {parent.remove self} end |
#deactivated ⇒ Object
99 100 101 102 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 99 def deactivated() parent.resume super end |
#draw ⇒ Object
84 85 86 87 88 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 84 def draw() sprite super sprite *elements end |
#elements ⇒ Object
79 80 81 82 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 79 def elements() f = -> es {es.map {|e| ((e in {elements:})) ? f[elements] : e}} f.call(@elements).flatten end |
#group(flow = :horizontal, space: nil, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 21 def group(flow = :horizontal, space: nil, &block) old, @group = @group, [] block.call self ensure (old || @elements).push({ elements: @group, flow: flow, space: space || MARGIN }) @group = old updateLayout end |
#resized(w, h) ⇒ Object
90 91 92 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 90 def resized(w, h) updateLayout end |
#sprites ⇒ Object
75 76 77 |
# File 'lib/rubysketch/solitaire/common/dialog.rb', line 75 def sprites() super + [, *elements] end |