1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
3 *
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.
8 *
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.
13 *
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.
17 */
18 #include <config.h>
19
20 #include "handle_ops.h"
21 #include "color.h"
22
23 /* This value is best left odd so that the handles are centered. */
24 #define HANDLE_SIZE 7
25
26 static const Color handle_color[NUM_HANDLE_TYPES<<1] =
27 {
28 { 0.0, 0.0, 0.5}, /* HANDLE_NON_MOVABLE */
29 { 0.0, 1.0, 0.0}, /* HANDLE_MAJOR_CONTROL */
30 { 1.0, 0.6, 0.0}, /* HANDLE_MINOR_CONTROL */
31 /* dim down the color if the handle is in a group of selected objects */
32 { 0.0, 0.0, 0.5}, /* HANDLE_NON_MOVABLE */
33 { 0.0, 0.7, 0.0}, /* HANDLE_MAJOR_CONTROL */
34 { 0.7, 0.4, 0.0}, /* HANDLE_MINOR_CONTROL */
35 };
36
37 static const Color handle_color_connected[NUM_HANDLE_TYPES<<1] =
38 {
39 { 0.0, 0.0, 0.5}, /* HANDLE_NON_MOVABLE */
40 { 1.0, 0.0, 0.0}, /* HANDLE_MAJOR_CONTROL */
41 { 1.0, 0.4, 0.0}, /* HANDLE_MINOR_CONTROL */
42 /* dim down the color if the handle is in a group of selected objects */
43 { 0.0, 0.0, 0.5}, /* HANDLE_NON_MOVABLE */
44 { 0.7, 0.0, 0.0}, /* HANDLE_MAJOR_CONTROL */
45 { 0.7, 0.3, 0.0}, /* HANDLE_MINOR_CONTROL */
46 };
47
48 void
handle_draw(Handle * handle,DDisplay * ddisp)49 handle_draw(Handle *handle, DDisplay *ddisp)
50 {
51 gboolean some_selected;
52 int x,y;
53 DiaRenderer *renderer = ddisp->renderer;
54 DiaInteractiveRendererInterface *irenderer =
55 DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp->renderer);
56 const Color *color;
57
58 ddisplay_transform_coords(ddisp, handle->pos.x, handle->pos.y, &x, &y);
59 /* change handle color to reflect different behaviour for multiple selected */
60 /* this code relies on the fact that only selected objects get their handles drawn */
61 some_selected = g_list_length (ddisp->diagram->data->selected) > 1;
62
63 if (handle->connected_to != NULL) {
64 color = &handle_color_connected[handle->type + (some_selected ? NUM_HANDLE_TYPES : 0)];
65 } else {
66 color = &handle_color[handle->type + (some_selected ? NUM_HANDLE_TYPES : 0)];
67 }
68
69 DIA_RENDERER_GET_CLASS(renderer)->set_linewidth(renderer, 0.0);
70 DIA_RENDERER_GET_CLASS(renderer)->set_linestyle(renderer, LINESTYLE_SOLID);
71 DIA_RENDERER_GET_CLASS(renderer)->set_linejoin(renderer, LINEJOIN_MITER);
72 DIA_RENDERER_GET_CLASS(renderer)->set_fillstyle(renderer, FILLSTYLE_SOLID);
73
74
75 irenderer->fill_pixel_rect(renderer,
76 x - HANDLE_SIZE/2 + 1,
77 y - HANDLE_SIZE/2 + 1,
78 HANDLE_SIZE-2, HANDLE_SIZE-2,
79 /* it does not change the color, but does not reflect taht in the signature */
80 (Color *)color);
81
82 irenderer->draw_pixel_rect(renderer,
83 x - HANDLE_SIZE/2,
84 y - HANDLE_SIZE/2,
85 HANDLE_SIZE-1, HANDLE_SIZE-1,
86 &color_black);
87
88
89
90 if (handle->connect_type != HANDLE_NONCONNECTABLE) {
91 irenderer->draw_pixel_line
92 (renderer,
93 x - HANDLE_SIZE/2, y - HANDLE_SIZE/2,
94 x + HANDLE_SIZE/2, y + HANDLE_SIZE/2,
95 &color_black);
96 irenderer->draw_pixel_line
97 (renderer,
98 x - HANDLE_SIZE/2, y + HANDLE_SIZE/2,
99 x + HANDLE_SIZE/2, y - HANDLE_SIZE/2,
100 &color_black);
101 }
102 }
103
104 void
handle_add_update(Handle * handle,Diagram * dia)105 handle_add_update(Handle *handle, Diagram *dia)
106 {
107 diagram_add_update_pixels(dia, &handle->pos,
108 HANDLE_SIZE, HANDLE_SIZE);
109 }
110
111 /* Call this after diagram_find_closest_handle() */
112 int
handle_is_clicked(DDisplay * ddisp,Handle * handle,Point * pos)113 handle_is_clicked(DDisplay *ddisp, Handle *handle, Point *pos)
114 {
115 real dx, dy;
116 int idx, idy;
117
118 if (handle==NULL)
119 return FALSE;
120
121 dx = ABS(handle->pos.x - pos->x);
122 dy = ABS(handle->pos.y - pos->y);
123
124 idx = ddisplay_transform_length(ddisp, dx);
125 idy = ddisplay_transform_length(ddisp, dy);
126
127 return (idx<(HANDLE_SIZE+1)/2) && (idy<(HANDLE_SIZE+1)/2);
128 }
129
130