Class: Accessibility::Highlighter

Inherits:
NSWindow
  • Object
show all
Defined in:
lib/accessibility/highlighter.rb

Overview

A screen highlighter for debugging. When you initialize a highligter object it will highlight the given bounds on the screen.

Highligter objects can have their colour configured at initialization, and can also have a timeout to automatically stop displaying.

Examples:


h = Accessibility::Highlighter.new(CGRectMake(100,100,100,100))
# when you are done...
h.stop

Instance Method Summary collapse

Constructor Details

#initialize(bounds, opts = {}) ⇒ Highlighter

Returns a new instance of Highlighter.

Options Hash (opts):

  • :timeout (Number)
  • :colour (NSColor) — default: NSColor.magentaColor


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/accessibility/highlighter.rb', line 23

def initialize bounds, opts = {}
  colour = opts[:colour] || opts[:color] || NSColor.magentaColor

  bounds.flip! # we assume the rect is in the other co-ordinate system

  initWithContentRect bounds,
           styleMask: NSBorderlessWindowMask,
             backing: NSBackingStoreBuffered,
               defer: true
  setOpaque false
  setAlphaValue 0.20
  setLevel NSStatusWindowLevel
  setBackgroundColor colour
  setIgnoresMouseEvents true
  setFrame bounds, display: false
  makeKeyAndOrderFront NSApp

  if opts.has_key? :timeout
    Dispatch::Queue.new(queue_id).after opts[:timeout] do
      self.stop
    end
  end
end

Instance Method Details

#stopself

Tell the highlighter to stop displaying.



51
52
53
# File 'lib/accessibility/highlighter.rb', line 51

def stop
  close
end