Class: Rubygoo::CheckBox

Inherits:
Widget
  • Object
show all
Defined in:
lib/rubygoo/check_box.rb

Constant Summary

Constants inherited from Widget

Widget::DEFAULT_PARAMS

Instance Attribute Summary collapse

Attributes inherited from Widget

#app, #container, #enabled, #focus_priority, #focussed, #h, #parent, #w, #x, #x_pad, #y, #y_pad

Instance Method Summary collapse

Methods inherited from Widget

#contains?, #enabled?, #focus, #focussed?, #get_color, #key_released, #mouse_down, #mouse_motion, #on_focus, #on_unfocus, #removed, #theme_property, #unfocus, #update, #update_rect

Constructor Details

#initialize(opts = {}) ⇒ CheckBox

Returns a new instance of CheckBox.



5
6
7
# File 'lib/rubygoo/check_box.rb', line 5

def initialize(opts={})
  super opts
end

Instance Attribute Details

#checkedObject

Returns the value of attribute checked.



3
4
5
# File 'lib/rubygoo/check_box.rb', line 3

def checked
  @checked
end

Instance Method Details

#addedObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/rubygoo/check_box.rb', line 9

def added()
  @checked = false
  @color = theme_property :color
  @bg_color = theme_property :bg_color
  @border_color = theme_property :border_color
  @focus_color = theme_property :focus_color
  @checked_color = theme_property :checked_color

  @rect = Rect.new [@x-@x_pad,@y-@y_pad,@w+2*@x_pad,@h+2*@y_pad]
end

#checkObject



32
33
34
35
# File 'lib/rubygoo/check_box.rb', line 32

def check()
  @checked = true
  fire :checked
end

#checked?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rubygoo/check_box.rb', line 20

def checked?()
  @checked
end

#draw(screen) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rubygoo/check_box.rb', line 55

def draw(screen)
  if @focussed
    screen.fill @focus_color, @rect
  elsif @bg_color
    screen.fill @bg_color, @rect
  end

  if @checked
    screen.fill @checked_color, @rect.inflate(-@x_pad,-@y_pad)
  end

  if @border_color
    x1 = @rect[0]
    y1 = @rect[1]
    x2 = @rect[2] + x1
    y2 = @rect[3] + y1
    screen.draw_box x1, y1, x2, y2, @border_color
  end
end

#key_pressed(event) ⇒ Object

called when a key press is sent to us



48
49
50
51
52
53
# File 'lib/rubygoo/check_box.rb', line 48

def key_pressed(event)
  case event.data[:key]
  when K_SPACE
    toggle
  end
end

#mouse_up(event) ⇒ Object

called when there is a mouse click



43
44
45
# File 'lib/rubygoo/check_box.rb', line 43

def mouse_up(event)
  toggle
end

#toggleObject



24
25
26
27
28
29
30
# File 'lib/rubygoo/check_box.rb', line 24

def toggle()
  if checked?
    uncheck
  else
    check
  end
end

#uncheckObject



37
38
39
40
# File 'lib/rubygoo/check_box.rb', line 37

def uncheck()
  @checked = false
  fire :checked
end