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"
24 #include "diagramdata.h"
26 #include "object_ops.h"
29 /* One could argue that the actual setting of the object's field
30 * should happen inside lib rather than app. I think that'd be overkill.
34 /* The highlighting must happen within a certain small area around the bbox.
35 * Highlighting sets the bbox to ... some more.
36 * Problem: The bbox is the same for all views, but highlighting size should
37 * depend on the zoom level. The renderer obviously can figure out to make
38 * it a few more pixels or something, but we need the bbox to also be
39 * enlarged by a bit. I guess the object_add_updates call must handle that,
40 * as it knows about the conversion.
43 static Color red
= { 1.0, 0.0, 0.0 };
46 highlight_object(DiaObject
*obj
, Color
*col
, Diagram
*dia
)
49 obj
->highlight_color
= col
;
51 obj
->highlight_color
= &red
;
53 object_add_updates(obj
, dia
);
57 highlight_object_off(DiaObject
*obj
, Diagram
*dia
)
59 if (obj
->highlight_color
!= NULL
) {
60 /* Must add updates first, so we get the border erased. */
61 object_add_updates(obj
, dia
);
62 obj
->highlight_color
= NULL
;
66 /** Resets all highlighting in this layer. Helper function for
70 highlight_reset_objects(GList
*objects
, Diagram
*dia
)
72 for (; objects
!= NULL
; objects
= g_list_next(objects
)) {
73 DiaObject
*object
= (DiaObject
*)objects
->data
;
74 highlight_object_off(object
, dia
);
75 if (IS_GROUP(object
)) {
76 highlight_reset_objects(group_objects(object
), dia
);
81 /* Currently does a brute-force run-through of all objects.
82 * If this is too slow, we could create a list of currently highlighted
83 * objects in the diagram and traverse that before killing it.
84 * Note that we're not assuming that all highlighted objects are in
88 highlight_reset_all(Diagram
*dia
) {
90 for (i
= 0; i
< dia
->data
->layers
->len
; i
++) {
91 highlight_reset_objects(((Layer
*)g_ptr_array_index(dia
->data
->layers
, i
))->objects
, dia
);