1 /* Dia -- an diagram creation/manipulation program
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.
20 #include "handle_ops.h"
23 /* This value is best left odd so that the handles are centered. */
26 static Color handle_color
[NUM_HANDLE_TYPES
] =
28 { 0.0, 0.0, 0.4}, /* HANDLE_NON_MOVABLE */
29 { 0.0, 1.0, 0.0}, /* HANDLE_MAJOR_CONTROL */
30 { 1.0, 0.4, 0.0}, /* HANDLE_MINOR_CONTROL */
33 static Color handle_color_connected
[NUM_HANDLE_TYPES
] =
35 { 0.0, 0.0, 0.4}, /* HANDLE_NON_MOVABLE */
36 { 1.0, 0.0, 0.0}, /* HANDLE_MAJOR_CONTROL */
37 { 1.0, 0.1, 0.0}, /* HANDLE_MINOR_CONTROL */
41 handle_draw(Handle
*handle
, DDisplay
*ddisp
)
44 DiaRenderer
*renderer
= ddisp
->renderer
;
45 DiaInteractiveRendererInterface
*irenderer
=
46 DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp
->renderer
);
49 ddisplay_transform_coords(ddisp
, handle
->pos
.x
, handle
->pos
.y
, &x
, &y
);
51 if (handle
->connected_to
!= NULL
) {
52 color
= &handle_color_connected
[handle
->type
];
54 color
= &handle_color
[handle
->type
];
57 DIA_RENDERER_GET_CLASS(renderer
)->set_linewidth(renderer
, 0.0);
58 DIA_RENDERER_GET_CLASS(renderer
)->set_linestyle(renderer
, LINESTYLE_SOLID
);
59 DIA_RENDERER_GET_CLASS(renderer
)->set_linejoin(renderer
, LINEJOIN_MITER
);
60 DIA_RENDERER_GET_CLASS(renderer
)->set_fillstyle(renderer
, FILLSTYLE_SOLID
);
63 irenderer
->fill_pixel_rect(renderer
,
64 x
- HANDLE_SIZE
/2 + 1,
65 y
- HANDLE_SIZE
/2 + 1,
66 HANDLE_SIZE
-2, HANDLE_SIZE
-2,
69 irenderer
->draw_pixel_rect(renderer
,
72 HANDLE_SIZE
-1, HANDLE_SIZE
-1,
77 if (handle
->connect_type
!= HANDLE_NONCONNECTABLE
) {
78 irenderer
->draw_pixel_line
80 x
- HANDLE_SIZE
/2, y
- HANDLE_SIZE
/2,
81 x
+ HANDLE_SIZE
/2, y
+ HANDLE_SIZE
/2,
83 irenderer
->draw_pixel_line
85 x
- HANDLE_SIZE
/2, y
+ HANDLE_SIZE
/2,
86 x
+ HANDLE_SIZE
/2, y
- HANDLE_SIZE
/2,
92 handle_add_update(Handle
*handle
, Diagram
*dia
)
94 diagram_add_update_pixels(dia
, &handle
->pos
,
95 HANDLE_SIZE
, HANDLE_SIZE
);
98 /* Call this after diagram_find_closest_handle() */
100 handle_is_clicked(DDisplay
*ddisp
, Handle
*handle
, Point
*pos
)
108 dx
= ABS(handle
->pos
.x
- pos
->x
);
109 dy
= ABS(handle
->pos
.y
- pos
->y
);
111 idx
= ddisplay_transform_length(ddisp
, dx
);
112 idy
= ddisplay_transform_length(ddisp
, dy
);
114 return (idx
<(HANDLE_SIZE
+1)/2) && (idy
<(HANDLE_SIZE
+1)/2);