linewidth is now working for PS_SOLID
[dia.git] / app / highlight.c
blob3cd7ba56b79d271eaa68e04d9de87839a8bc1b61
1 /* Dia -- an diagram creation/manipulation program -*- c -*-
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include "highlight.h"
21 #include "glib.h"
23 #include "diagram.h"
24 #include "diagramdata.h"
25 #include "object.h"
26 #include "object_ops.h"
28 /* One could argue that the actual setting of the object's field
29 * should happen inside lib rather than app. I think that'd be overkill.
30 * -Lars
33 /* The highlighting must happen within a certain small area around the bbox.
34 * Highlighting sets the bbox to ... some more.
35 * Problem: The bbox is the same for all views, but highlighting size should
36 * depend on the zoom level. The renderer obviously can figure out to make
37 * it a few more pixels or something, but we need the bbox to also be
38 * enlarged by a bit. I guess the object_add_updates call must handle that,
39 * as it knows about the conversion.
42 static Color red = { 1.0, 0.0, 0.0 };
44 void
45 highlight_object(DiaObject *obj, Color *col, Diagram *dia)
47 if (col)
48 obj->highlight_color = col;
49 else
50 obj->highlight_color = &red;
52 object_add_updates(obj, dia);
55 void
56 highlight_object_off(DiaObject *obj, Diagram *dia)
58 if (obj->highlight_color != NULL) {
59 /* Must add updates first, so we get the border erased. */
60 object_add_updates(obj, dia);
61 obj->highlight_color = NULL;
65 /** Resets all highlighting in this layer. Helper function for
66 * highlight_reset_all
68 static void
69 highlight_reset_layer(Layer *layer, Diagram *dia)
71 GList *objects;
73 for (objects = layer->objects; objects != NULL;
74 objects = g_list_next(objects)) {
75 DiaObject *object = (DiaObject*)objects->data;
76 highlight_object_off(object, dia);
80 /* Currently does a brute-force run-through of all objects.
81 * If this is too slow, we could create a list of currently highlighted
82 * objects in the diagram and traverse that before killing it.
83 * Note that we're not assuming that all highlighted objects are in
84 * the active layer.
86 void
87 highlight_reset_all(Diagram *dia) {
88 int i;
89 for (i = 0; i < dia->data->layers->len; i++) {
90 highlight_reset_layer((Layer*)g_ptr_array_index(dia->data->layers, i), dia);