Module: CUIControl

Includes:
MINT
Included in:
LayoutAgent
Defined in:
lib/MINT-core/agent/cuicontrol.rb

Class Method Summary collapse

Methods included from MINT

#cache_coordinates, #cache_touched, #consume, #filter, #has_moved?, #restart_timeout, #start_one_time_tick, #start_timeout, #stop_timeout, #touch_changed?

Class Method Details

.add_to_cache(cio) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/MINT-core/agent/cuicontrol.rb', line 85

def CUIControl.add_to_cache(cio)
  if cio['highlightable'] and not @active_cios.index{|x|x.name==cio["name"]}
    c =  CIO.get(cio["name"])
    @active_cios << c
    puts "Added #{cio['name']} to CIO cache #{c.x}/#{c.y}"

  end
  return true
end

.clearHighlightedObject



7
8
9
10
# File 'lib/MINT-core/agent/cuicontrol.rb', line 7

def CUIControl.clearHighlighted
  @cached_highlighted = nil

end

.fill_active_cio_cache(result = nil) ⇒ Object



80
81
82
83
# File 'lib/MINT-core/agent/cuicontrol.rb', line 80

def CUIControl.fill_active_cio_cache(result=nil)
  @active_cios = CIO.all.select{ |e| e.is_in?(:displaying) and e.highlightable}
  puts "CIO cache initialized with #{@active_cios.inspect} elements"
end

.find_cio_from_coordinates(result) ⇒ Object



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
# File 'lib/MINT-core/agent/cuicontrol.rb', line 30

def CUIControl.find_cio_from_coordinates(result)
  # puts "mouse stopped #{result.inspect}"
  if result == nil or @active_cios.length ==0# we have not finished cui poition calculation, but we already received a mouse stopped event
    return true

  end
  x = result["x"]
  y = result["y"]

  highlighted_cio = retrieveHighlighted()

  if (highlighted_cio!=nil && highlighted_cio.x<=x && highlighted_cio.y<=y && highlighted_cio.x+highlighted_cio.width>=x && highlighted_cio.y+highlighted_cio.height>=y)
    #  puts "unchanged"
    return true
  else

    found = @active_cios.select{ |e|  e.x <=x && e.y<=y && e.x+e.width>=x && e.y+e.height>=y}

    #      puts "found #{found.inspect}"

    if (highlighted_cio)
      highlighted_cio.process_event("unhighlight")
      MINT::AIO.get(highlighted_cio.name).process_event("defocus")
      # old focus
      #      puts "unhighlight:"+highlighted_cio.name
      # @highlighted_cio.update(:state=>"calculated") # old focus
    end

    if (found.first)
      highlighted_cio = MINT::CIO.get(found.first.name)
      highlighted_cio.process_event("highlight")
      MINT::AIO.get(highlighted_cio.name).process_event("focus")
      #       puts "highlighted:"+highlighted_cio.name
    else
      #     puts "no highlight"
      return  true
    end
  end
  return true
end

.refresh_allObject



71
72
73
74
75
76
77
78
# File 'lib/MINT-core/agent/cuicontrol.rb', line 71

def CUIControl.refresh_all
  aics = AIO.all(:parent =>nil).map &:name
  aics.each do |name|
    cio = CIO.get(name)
    p "refrehsing #{cio.name}"
    cio.process_event :refresh
  end
end

.remove_from_cache(cio) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/MINT-core/agent/cuicontrol.rb', line 107

def CUIControl.remove_from_cache(cio)
  p "remove cache"
  if cio['highlightable']
    @active_cios.delete_if{|x| x.name == cio['name']}
    puts "Removed #{cio['name']} from CIO cache "
  end
  return true
end

.retrieveHighlightedObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/MINT-core/agent/cuicontrol.rb', line 11

def CUIControl.retrieveHighlighted
  if (@cached_highlighted)
    check = MINT::CIO.get(@cached_highlighted)
    if (check.is_in? "highlighted")
      return check
    end
  end

  new_highlighted =  MINT::CIO.first(:states=>/highlighted/)

  if new_highlighted
    @cached_highlighted= new_highlighted.name
  else
    @cached_highlighted = nil
  end

  return new_highlighted
end

.update_cache(cio) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/MINT-core/agent/cuicontrol.rb', line 95

def CUIControl.update_cache(cio)
  index = @active_cios.index{|x|x.name==cio["name"]}
  if index
    c =  CIO.get(cio["name"])
    @active_cios[index] = c
    puts "Updated#{cio['name']} to CIO cache #{c.x}/#{c.y} #{c.width}/#{c.height}"

  end
  return true
end