Add support for filling / thindrawing raw polygons to the HID interface
[geda-pcb/gde.git] / src / hid / common / extents.c
blob60a71746dd79dac9eaa292c544e8aa90b90299f3
1 /* $Id$ */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <math.h>
12 #include "global.h"
13 #include "data.h"
15 #include "hid.h"
16 #include "../hidint.h"
17 #include "hid/common/draw_helpers.h"
19 #ifdef HAVE_LIBDMALLOC
20 #include <dmalloc.h>
21 #endif
23 RCSID ("$Id$");
25 #ifndef MAXINT
26 #define MAXINT (((unsigned int)(~0))>>1)
27 #endif
29 static BoxType box;
32 typedef struct hid_gc_struct
34 int width;
35 } hid_gc_struct;
37 static int
38 extents_set_layer (const char *name, int group, int empty)
40 int idx = group;
41 if (idx >= 0 && idx < max_layer)
43 idx = PCB->LayerGroups.Entries[idx][0];
45 if (idx >= 0 && idx < max_layer + 2)
46 return 1;
47 if (idx < 0)
49 switch (SL_TYPE (idx))
51 case SL_INVISIBLE:
52 case SL_MASK:
53 case SL_ASSY:
54 return 0;
55 case SL_SILK:
56 case SL_PDRILL:
57 case SL_UDRILL:
58 return 1;
61 return 0;
64 static hidGC
65 extents_make_gc (void)
67 hidGC rv = malloc (sizeof (hid_gc_struct));
68 memset (rv, 0, sizeof (hid_gc_struct));
69 return rv;
72 static void
73 extents_destroy_gc (hidGC gc)
75 free (gc);
78 static void
79 extents_use_mask (int use_it)
83 static void
84 extents_set_color (hidGC gc, const char *name)
88 static void
89 extents_set_line_cap (hidGC gc, EndCapStyle style)
93 static void
94 extents_set_line_width (hidGC gc, int width)
96 gc->width = width;
99 static void
100 extents_set_draw_xor (hidGC gc, int xor)
104 static void
105 extents_set_draw_faded (hidGC gc, int faded)
109 static void
110 extents_set_line_cap_angle (hidGC gc, int x1, int y1, int x2, int y2)
114 #define PEX(x,w) if (box.X1 > (x)-(w)) box.X1 = (x)-(w); \
115 if (box.X2 < (x)+(w)) box.X2 = (x)+(w)
116 #define PEY(y,w) if (box.Y1 > (y)-(w)) box.Y1 = (y)-(w); \
117 if (box.Y2 < (y)+(w)) box.Y2 = (y)+(w)
119 static void
120 extents_draw_line (hidGC gc, int x1, int y1, int x2, int y2)
122 PEX (x1, gc->width);
123 PEY (y1, gc->width);
124 PEX (x2, gc->width);
125 PEY (y2, gc->width);
128 static void
129 extents_draw_arc (hidGC gc, int cx, int cy, int width, int height,
130 int start_angle, int end_angle)
132 /* Naive but good enough. */
133 PEX (cx, width + gc->width);
134 PEY (cy, height + gc->width);
137 static void
138 extents_draw_rect (hidGC gc, int x1, int y1, int x2, int y2)
140 PEX (x1, gc->width);
141 PEY (y1, gc->width);
142 PEX (x2, gc->width);
143 PEY (y2, gc->width);
146 static void
147 extents_fill_circle (hidGC gc, int cx, int cy, int radius)
149 PEX (cx, radius);
150 PEY (cy, radius);
153 static void
154 extents_fill_polygon (hidGC gc, int n_coords, int *x, int *y)
156 int i;
157 for (i = 0; i < n_coords; i++)
159 PEX (x[i], 0);
160 PEY (y[i], 0);
164 static void
165 extents_fill_rect (hidGC gc, int x1, int y1, int x2, int y2)
167 PEX (x1, 0);
168 PEY (y1, 0);
169 PEX (x2, 0);
170 PEY (y2, 0);
173 static HID extents_hid = {
174 sizeof (HID),
175 "extents-extents",
176 "used to calculate extents",
177 0, /* gui */
178 0, /* printer */
179 0, /* exporter */
180 1, /* poly before */
181 0, /* poly after */
182 0, /* poly dicer */
184 0 /* extents_get_export_options */ ,
185 0 /* extents_do_export */ ,
186 0 /* extents_parse_arguments */ ,
188 0 /* extents_invalidate_wh */ ,
189 0 /* extents_invalidate_lr */ ,
190 0 /* extents_invalidate_all */ ,
191 extents_set_layer,
192 extents_make_gc,
193 extents_destroy_gc,
194 extents_use_mask,
195 extents_set_color,
196 extents_set_line_cap,
197 extents_set_line_width,
198 extents_set_draw_xor,
199 extents_set_draw_faded,
200 extents_set_line_cap_angle,
201 extents_draw_line,
202 extents_draw_arc,
203 extents_draw_rect,
204 extents_fill_circle,
205 extents_fill_polygon,
206 common_fill_pcb_polygon,
207 0 /* extents_thindraw_pcb_polygon */,
208 extents_fill_rect,
210 0 /* extents_calibrate */ ,
211 0 /* extents_shift_is_pressed */ ,
212 0 /* extents_control_is_pressed */ ,
213 0 /* extents_get_coords */ ,
214 0 /* extents_set_crosshair */ ,
215 0 /* extents_add_timer */ ,
216 0 /* extents_stop_timer */ ,
217 0 /* extents_watch_file */ ,
218 0 /* extents_unwatch_file */ ,
219 0 /* extents_add_block_hook */ ,
220 0 /* extents_stop_block_hook */ ,
222 0 /* extents_log */ ,
223 0 /* extents_logv */ ,
224 0 /* extents_confirm_dialog */ ,
225 0 /* extents_close_confirm_dialog */ ,
226 0 /* extents_report_dialog */ ,
227 0 /* extents_prompt_for */ ,
228 0 /* extents_attribute_dialog */ ,
229 0 /* extents_show_item */ ,
230 0 /* extents_beep */
233 BoxType *
234 hid_get_extents (void *item)
236 BoxType region;
238 box.X1 = MAXINT;
239 box.Y1 = MAXINT;
240 box.X2 = -MAXINT;
241 box.Y2 = -MAXINT;
243 region.X1 = -MAXINT;
244 region.Y1 = -MAXINT;
245 region.X2 = MAXINT;
246 region.Y2 = MAXINT;
247 hid_expose_callback (&extents_hid, &region, item);
249 return &box;