Enabling UML mainpoint
[dia.git] / app / handle_ops.c
blob57319ff2405f748c027c2cf5e90619b6d36a369d
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.
18 #include <config.h>
20 #include "handle_ops.h"
21 #include "color.h"
23 /* This value is best left odd so that the handles are centered. */
24 #define HANDLE_SIZE 7
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 */
40 void
41 handle_draw(Handle *handle, DDisplay *ddisp)
43 int x,y;
44 DiaRenderer *renderer = ddisp->renderer;
45 DiaInteractiveRendererInterface *irenderer =
46 DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp->renderer);
47 Color *color;
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];
53 } else {
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,
67 color);
69 irenderer->draw_pixel_rect(renderer,
70 x - HANDLE_SIZE/2,
71 y - HANDLE_SIZE/2,
72 HANDLE_SIZE-1, HANDLE_SIZE-1,
73 &color_black);
77 if (handle->connect_type != HANDLE_NONCONNECTABLE) {
78 irenderer->draw_pixel_line
79 (renderer,
80 x - HANDLE_SIZE/2, y - HANDLE_SIZE/2,
81 x + HANDLE_SIZE/2, y + HANDLE_SIZE/2,
82 &color_black);
83 irenderer->draw_pixel_line
84 (renderer,
85 x - HANDLE_SIZE/2, y + HANDLE_SIZE/2,
86 x + HANDLE_SIZE/2, y - HANDLE_SIZE/2,
87 &color_black);
91 void
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() */
99 int
100 handle_is_clicked(DDisplay *ddisp, Handle *handle, Point *pos)
102 real dx, dy;
103 int idx, idy;
105 if (handle==NULL)
106 return FALSE;
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);