Class: Accessibility::Highlighter
- Defined in:
- lib/accessibility/highlighter/macruby.rb,
ext/accessibility/highlighter/highlighter.c
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.
Options for setting up a highlighter are document in #initialize.
Class Method Summary collapse
Instance Method Summary collapse
-
#color ⇒ NSColor
(also: #colour)
Returns the color for the highlighter.
-
#frame ⇒ CGRect
Return the rectangle on screen which the highlighter is occupying.
-
#initialize(bounds, opts = {}) ⇒ Highlighter
constructor
A new instance of Highlighter.
-
#stop ⇒ self
Tell the highlighter to stop displaying.
-
#visible? ⇒ Boolean
Return whether or not the highlighter is currently drawn on screen.
Constructor Details
#initialize(bounds, opts = {}) ⇒ Highlighter
Returns a new instance of Highlighter.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/accessibility/highlighter/macruby.rb', line 25 def initialize bounds, opts = {} color = opts[:colour] || opts[:color] || NSColor.magentaColor bounds = bounds.to_rect 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 color setIgnoresMouseEvents true setFrame bounds, display: false makeKeyAndOrderFront NSApp if opts.has_key? :timeout Dispatch::Queue.concurrent.after opts[:timeout] do self.stop end end end |
Class Method Details
.new(*args) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'ext/accessibility/highlighter/highlighter.c', line 61
static
VALUE
rb_highlighter_new(int argc, VALUE* argv, VALUE self)
{
if (!argc)
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1+)");
CGRect bounds = unwrap_rect(coerce_to_rect(argv[0]));
bounds = flip(bounds); // we assume the rect is in the other co-ordinate system
NSWindow* window =
[[NSWindow alloc] initWithContentRect:bounds
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:true];
NSColor* color = [NSColor magentaColor];
if (argc > 1) {
VALUE rb_color = rb_hash_lookup(argv[1], color_key);
if (rb_color == Qnil)
rb_color = rb_hash_lookup(argv[1], colour_key);
if (rb_color != Qnil)
color = unwrap_color(rb_color);
}
[window setOpaque:false];
[window setAlphaValue:0.20];
[window setLevel:NSStatusWindowLevel];
[window setBackgroundColor:color];
[window setIgnoresMouseEvents:true];
[window setFrame:bounds display:false];
[window makeKeyAndOrderFront:NSApp];
[window setReleasedWhenClosed:false];
if (argc > 1) {
VALUE rb_timeout = rb_hash_lookup(argv[1], timeout_key);
if (rb_timeout != Qnil) {
dispatch_time_t timeout = dispatch_time(
DISPATCH_TIME_NOW,
NUM2LL(rb_timeout) * NSEC_PER_SEC
);
dispatch_after(
timeout,
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^(void) { [window close]; }
);
}
}
VALUE highlighter = wrap_window(window);
rb_ivar_set(highlighter, ivar_color, wrap_color(color));
return highlighter;
}
|
Instance Method Details
#color ⇒ NSColor Also known as: colour
Returns the color for the highlighter
62 63 64 |
# File 'lib/accessibility/highlighter/macruby.rb', line 62 def color backgroundColor end |
#frame ⇒ CGRect
Return the rectangle on screen which the highlighter is occupying
77 78 79 |
# File 'lib/accessibility/highlighter/macruby.rb', line 77 def frame super end |
#stop ⇒ self
Tell the highlighter to stop displaying.
54 55 56 |
# File 'lib/accessibility/highlighter/macruby.rb', line 54 def stop close end |
#visible? ⇒ Boolean
Return whether or not the highlighter is currently drawn on screen
69 70 71 |
# File 'lib/accessibility/highlighter/macruby.rb', line 69 def visible? super end |