svg text alignment
[dia.git] / app / handle_ops.c
blobf68c69aed0145f41e64d3f786f9bd45041da4e9d
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 Renderer *renderer = ddisp->renderer;
45 Color *color;
47 ddisplay_transform_coords(ddisp, handle->pos.x, handle->pos.y, &x, &y);
49 if (handle->connected_to != NULL) {
50 color = &handle_color_connected[handle->type];
51 } else {
52 color = &handle_color[handle->type];
55 (renderer->ops->set_linewidth)(renderer, 0.0);
56 (renderer->ops->set_linestyle)(renderer, LINESTYLE_SOLID);
57 (renderer->ops->set_linejoin)(renderer, LINEJOIN_MITER);
58 (renderer->ops->set_fillstyle)(renderer, FILLSTYLE_SOLID);
61 (renderer->interactive_ops->fill_pixel_rect)(renderer,
62 x - HANDLE_SIZE/2 + 1,
63 y - HANDLE_SIZE/2 + 1,
64 HANDLE_SIZE-2, HANDLE_SIZE-2,
65 color);
67 (renderer->interactive_ops->draw_pixel_rect)(renderer,
68 x - HANDLE_SIZE/2,
69 y - HANDLE_SIZE/2,
70 HANDLE_SIZE-1, HANDLE_SIZE-1,
71 &color_black);
75 if (handle->connect_type != HANDLE_NONCONNECTABLE) {
76 (renderer->interactive_ops->draw_pixel_line)
77 (renderer,
78 x - HANDLE_SIZE/2, y - HANDLE_SIZE/2,
79 x + HANDLE_SIZE/2, y + HANDLE_SIZE/2,
80 &color_black);
81 (renderer->interactive_ops->draw_pixel_line)
82 (renderer,
83 x - HANDLE_SIZE/2, y + HANDLE_SIZE/2,
84 x + HANDLE_SIZE/2, y - HANDLE_SIZE/2,
85 &color_black);
89 void
90 handle_add_update(Handle *handle, Diagram *dia)
92 diagram_add_update_pixels(dia, &handle->pos,
93 HANDLE_SIZE, HANDLE_SIZE);
96 /* Call this after diagram_find_closest_handle() */
97 int
98 handle_is_clicked(DDisplay *ddisp, Handle *handle, Point *pos)
100 real dx, dy;
101 int idx, idy;
103 if (handle==NULL)
104 return FALSE;
106 dx = ABS(handle->pos.x - pos->x);
107 dy = ABS(handle->pos.y - pos->y);
109 idx = ddisplay_transform_length(ddisp, dx);
110 idy = ddisplay_transform_length(ddisp, dy);
112 return (idx<(HANDLE_SIZE+1)/2) && (idy<(HANDLE_SIZE+1)/2);