Class: Accessibility::Highlighter

Inherits:
Object
  • Object
show all
Defined in:
ext/accessibility/highlighter/highlighter.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args) ⇒ Object



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: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: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_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

#colorObject Also known as: colour



120
121
122
123
124
125
# File 'ext/accessibility/highlighter/highlighter.c', line 120

static
VALUE
rb_highlighter_color(VALUE self)
{
  return wrap_color([unwrap_window(self) backgroundColor]);
}

#frameObject



127
128
129
130
131
132
# File 'ext/accessibility/highlighter/highlighter.c', line 127

static
VALUE
rb_highlighter_frame(VALUE self)
{
    return wrap_rect(NSRectToCGRect([unwrap_window(self) frame]));
}

#stopObject



112
113
114
115
116
117
118
# File 'ext/accessibility/highlighter/highlighter.c', line 112

static
VALUE
rb_highlighter_stop(VALUE self)
{
  [unwrap_window(self) close];
  return self;
}

#visible?Boolean

Returns:

  • (Boolean)


134
135
136
137
138
139
# File 'ext/accessibility/highlighter/highlighter.c', line 134

static
VALUE
rb_highlighter_is_visible(VALUE self)
{
  return ([unwrap_window(self) isVisible] ? Qtrue : Qfalse);
}