Class: WindowBlessing::Window

Inherits:
Object
  • Object
show all
Includes:
Evented, Tools, Drawing, Geometry, KeyboardFocus, ParentsAndChildren
Defined in:
lib/window_blessing/window.rb

Defined Under Namespace

Modules: Drawing, Geometry, KeyboardFocus, ParentsAndChildren

Instance Attribute Summary collapse

Attributes included from Drawing

#buffer, #redraw_areas

Attributes included from ParentsAndChildren

#children, #parent

Attributes included from Geometry

#area

Attributes included from KeyboardFocus

#focused, #focused_child

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Drawing

#add_redraw_area, #clear_redraw_areas, #draw, #draw_background, #draw_internal, #redraw, #redraw_requested?, #request_redraw, #request_redraw_internal

Methods included from ParentsAndChildren

#add_child, #each_child, #each_child_with_index, #parent_path, #path, #remove_child

Methods included from Geometry

#internal_area, #loc, #loc=, #move_onscreen, #pointer_inside?, #size, #size=

Methods included from KeyboardFocus

#blur, #blurred?, #focus, #focused?, #route_keyboard_event

Methods included from Evented

#event_manager, #handle_event, #on

Methods included from Tools

#buffer, #clone_value, #color, #fill_line, #gen_array2d, #gray_screen_color, #log, #overlapping_span, #overlay2d, #overlay_span, #range_length, #resize2d, #rgb_screen_color, #subarray2d, #window

Constructor Details

#initialize(area = rect(0,0,20,20)) ⇒ Window

Returns a new instance of Window.



26
27
28
29
30
31
32
33
# File 'lib/window_blessing/window.rb', line 26

def initialize(area=rect(0,0,20,20))
  @area = rect
  @children = []
  @bg = Buffer.default_bg
  @fg = Buffer.default_fg
  @buffer = Buffer.new area.size, :bg => @bg, :fg => @fg
  self.area = area
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



24
25
26
# File 'lib/window_blessing/window.rb', line 24

def name
  @name
end

Class Method Details

.attr_accessor_with_redraw(*symbols) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/window_blessing/window.rb', line 6

def Window.attr_accessor_with_redraw( *symbols )
  symbols.each do | symbol |
    class_eval <<ENDCODE
    def #{symbol}
      @#{symbol}
    end

    def #{symbol}=(value)
      old_value = @#{symbol}
      @#{symbol} = value
      request_redraw_internal if old_value != @#{symbol}
    end
ENDCODE
  end
end

Instance Method Details

#inspectObject



35
36
37
# File 'lib/window_blessing/window.rb', line 35

def inspect
  "<Window:#{name || object_id} area:#{area.to_s} children:#{children.length}>"
end

#route_pointer_event(event) ⇒ Object

event is in parent-space



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/window_blessing/window.rb', line 40

def route_pointer_event(event)
  focus
  event = event.clone
  event[:loc] -= area.loc

  @pointer_focused ||= children.reverse_each.find do |child|
    child.pointer_inside? event[:loc]
  end || :background

  if @pointer_focused == :background
    handle_event(event)
  else
    @pointer_focused.route_pointer_event event
  end

  @pointer_focused = nil if event[:type][1] == :button_up
end