59
60
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
|
# File 'ext/accessibility/highlighter/highlighter.c', line 59
static
VALUE
rb_highlighter_new(int argc, VALUE* argv, VALUE self)
{
if (!argc)
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1+)");
const CGRect bounds = flip(unwrap_rect(coerce_to_rect(argv[0])));
NSWindow* const window =
[[NSWindow alloc] initWithContentRect:NSRectFromCGRect(bounds)
styleMask:NSWindowStyleMaskBorderless
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:NSRectFromCGRect(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_main_queue(),
^(void) { [window close]; }
);
}
}
VALUE highlighter = wrap_window(window);
rb_ivar_set(highlighter, ivar_color, wrap_color(color));
return highlighter;
}
|