Convert mask type to enum
[geda-pcb/pcjc2.git] / src / hid / common / extents.c
blobc9e34187e39b60149010b4dc2ec918cd19a290fe
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <math.h>
10 #include "global.h"
11 #include "data.h"
13 #include "hid.h"
14 #include "../hidint.h"
15 #include "hid/common/draw_helpers.h"
17 #ifdef HAVE_LIBDMALLOC
18 #include <dmalloc.h>
19 #endif
21 #ifndef MAXINT
22 #define MAXINT (((unsigned int)(~0))>>1)
23 #endif
25 static BoxType box;
27 typedef struct hid_gc_struct
29 int width;
30 } hid_gc_struct;
32 static int
33 extents_set_layer (const char *name, int group, int empty)
35 int idx = group;
36 if (idx >= 0 && idx < max_group)
38 idx = PCB->LayerGroups.Entries[idx][0];
40 if (idx >= 0 && idx < max_copper_layer + 2)
41 return 1;
42 if (idx < 0)
44 switch (SL_TYPE (idx))
46 case SL_INVISIBLE:
47 case SL_MASK:
48 case SL_ASSY:
49 return 0;
50 case SL_SILK:
51 case SL_PDRILL:
52 case SL_UDRILL:
53 return 1;
56 return 0;
59 static hidGC
60 extents_make_gc (void)
62 hidGC rv = (hidGC)malloc (sizeof (hid_gc_struct));
63 memset (rv, 0, sizeof (hid_gc_struct));
64 return rv;
67 static void
68 extents_destroy_gc (hidGC gc)
70 free (gc);
73 static void
74 extents_use_mask (enum mask_mode mode)
78 static void
79 extents_set_color (hidGC gc, const char *name)
83 static void
84 extents_set_line_cap (hidGC gc, EndCapStyle style)
88 static void
89 extents_set_line_width (hidGC gc, Coord width)
91 gc->width = width;
94 static void
95 extents_set_draw_xor (hidGC gc, int xor_)
99 #define PEX(x,w) if (box.X1 > (x)-(w)) box.X1 = (x)-(w); \
100 if (box.X2 < (x)+(w)) box.X2 = (x)+(w)
101 #define PEY(y,w) if (box.Y1 > (y)-(w)) box.Y1 = (y)-(w); \
102 if (box.Y2 < (y)+(w)) box.Y2 = (y)+(w)
104 static void
105 extents_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
107 PEX (x1, gc->width);
108 PEY (y1, gc->width);
109 PEX (x2, gc->width);
110 PEY (y2, gc->width);
113 static void
114 extents_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height,
115 Angle start_angle, Angle end_angle)
117 /* Naive but good enough. */
118 PEX (cx, width + gc->width);
119 PEY (cy, height + gc->width);
122 static void
123 extents_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
125 PEX (x1, gc->width);
126 PEY (y1, gc->width);
127 PEX (x2, gc->width);
128 PEY (y2, gc->width);
131 static void
132 extents_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
134 PEX (cx, radius);
135 PEY (cy, radius);
138 static void
139 extents_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
141 int i;
142 for (i = 0; i < n_coords; i++)
144 PEX (x[i], 0);
145 PEY (y[i], 0);
149 static void
150 extents_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
152 PEX (x1, 0);
153 PEY (y1, 0);
154 PEX (x2, 0);
155 PEY (y2, 0);
158 static HID extents_hid;
160 void
161 hid_extents_init (void)
163 static bool initialised = false;
165 if (initialised)
166 return;
168 memset (&extents_hid, 0, sizeof (HID));
170 common_draw_helpers_init (&extents_hid);
172 extents_hid.struct_size = sizeof (HID);
173 extents_hid.name = "extents-extents";
174 extents_hid.description = "used to calculate extents";
175 extents_hid.poly_before = 1;
177 extents_hid.set_layer = extents_set_layer;
178 extents_hid.make_gc = extents_make_gc;
179 extents_hid.destroy_gc = extents_destroy_gc;
180 extents_hid.use_mask = extents_use_mask;
181 extents_hid.set_color = extents_set_color;
182 extents_hid.set_line_cap = extents_set_line_cap;
183 extents_hid.set_line_width = extents_set_line_width;
184 extents_hid.set_draw_xor = extents_set_draw_xor;
185 extents_hid.draw_line = extents_draw_line;
186 extents_hid.draw_arc = extents_draw_arc;
187 extents_hid.draw_rect = extents_draw_rect;
188 extents_hid.fill_circle = extents_fill_circle;
189 extents_hid.fill_polygon = extents_fill_polygon;
190 extents_hid.fill_rect = extents_fill_rect;
192 initialised = true;
195 BoxType *
196 hid_get_extents (void *item)
198 BoxType region;
200 /* As this isn't a real "HID", we need to ensure we are initialised. */
201 hid_extents_init ();
203 box.X1 = MAXINT;
204 box.Y1 = MAXINT;
205 box.X2 = -MAXINT;
206 box.Y2 = -MAXINT;
208 region.X1 = -MAXINT;
209 region.Y1 = -MAXINT;
210 region.X2 = MAXINT;
211 region.Y2 = MAXINT;
212 hid_expose_callback (&extents_hid, &region, item);
214 return &box;