lookingGlass: Draw a red border around target actor

This commit is contained in:
Colin Walters 2009-08-04 09:48:15 -04:00
parent 3429abff40
commit 902956ca0d
3 changed files with 50 additions and 0 deletions

View File

@ -230,6 +230,14 @@ LookingGlass.prototype = {
let displayText = new Clutter.Text({ color: MATRIX_GREEN, let displayText = new Clutter.Text({ color: MATRIX_GREEN,
font_name: MATRIX_FONT, text: '' }); font_name: MATRIX_FONT, text: '' });
eventHandler.append(displayText, Big.BoxPackFlags.EXPAND); eventHandler.append(displayText, Big.BoxPackFlags.EXPAND);
let borderPaintTarget = null;
let borderPaintId = null;
eventHandler.connect('destroy', Lang.bind(this, function() {
if (borderPaintTarget != null)
borderPaintTarget.disconnect(borderPaintId);
}));
eventHandler.connect('button-press-event', Lang.bind(this, function (actor, event) { eventHandler.connect('button-press-event', Lang.bind(this, function (actor, event) {
let global = Shell.Global.get(); let global = Shell.Global.get();
Clutter.ungrab_pointer(eventHandler); Clutter.ungrab_pointer(eventHandler);
@ -246,6 +254,7 @@ LookingGlass.prototype = {
global.stage.set_key_focus(this._entry); global.stage.set_key_focus(this._entry);
return true; return true;
})); }));
eventHandler.connect('motion-event', Lang.bind(this, function (actor, event) { eventHandler.connect('motion-event', Lang.bind(this, function (actor, event) {
let global = Shell.Global.get(); let global = Shell.Global.get();
let [stageX, stageY] = event.get_coords(); let [stageX, stageY] = event.get_coords();
@ -253,6 +262,10 @@ LookingGlass.prototype = {
stageX, stageX,
stageY); stageY);
displayText.text = '<inspect x: ' + stageX + ' y: ' + stageY + '> ' + target; displayText.text = '<inspect x: ' + stageX + ' y: ' + stageY + '> ' + target;
if (borderPaintTarget != null)
borderPaintTarget.disconnect(borderPaintId);
borderPaintTarget = target;
borderPaintId = Shell.add_hook_paint_red_border(target);
return true; return true;
})); }));
Clutter.grab_pointer(eventHandler); Clutter.grab_pointer(eventHandler);

View File

@ -178,3 +178,38 @@ shell_draw_glow (ClutterCairoTexture *texture,
cairo_pattern_destroy (gradient); cairo_pattern_destroy (gradient);
cairo_destroy (cr); cairo_destroy (cr);
} }
static void
hook_paint_red_border (ClutterActor *actor,
gpointer user_data)
{
CoglColor color;
ClutterGeometry geom;
float width = 2;
float x2;
float y2;
cogl_color_set_from_4ub (&color, 0xff, 0, 0, 0xc4);
cogl_set_source_color (&color);
clutter_actor_get_allocation_geometry (actor, &geom);
x2 = geom.x + geom.width;
y2 = geom.y + geom.height;
/** clockwise order **/
cogl_rectangle (geom.x, geom.y,
x2, geom.y + width);
cogl_rectangle (x2 - width, geom.y + width,
x2, y2);
cogl_rectangle (x2 - width, y2,
geom.x, y2 - width);
cogl_rectangle (geom.x + width, y2 - width,
geom.x, geom.y + width);
}
guint
shell_add_hook_paint_red_border (ClutterActor *actor)
{
return g_signal_connect_after (G_OBJECT (actor), "paint",
G_CALLBACK (hook_paint_red_border), NULL);
}

View File

@ -23,6 +23,8 @@ void shell_draw_glow (ClutterCairoTexture *texture,
double green, double green,
double alpha); double alpha);
guint shell_add_hook_paint_red_border (ClutterActor *actor);
G_END_DECLS G_END_DECLS
#endif /* __SHELL_GLOBAL_H__ */ #endif /* __SHELL_GLOBAL_H__ */