15 #include "../hidint.h"
16 #include "hid/common/draw_helpers.h"
18 #ifdef HAVE_LIBDMALLOC
24 typedef struct hid_gc_struct
30 extents_set_layer (const char *name
, int group
, int empty
)
33 if (idx
>= 0 && idx
< max_group
)
35 idx
= PCB
->LayerGroups
.Entries
[idx
][0];
37 if (idx
>= 0 && idx
< max_copper_layer
+ 2)
41 switch (SL_TYPE (idx
))
57 extents_make_gc (void)
59 hidGC rv
= (hidGC
)malloc (sizeof (hid_gc_struct
));
60 memset (rv
, 0, sizeof (hid_gc_struct
));
65 extents_destroy_gc (hidGC gc
)
71 extents_use_mask (enum mask_mode mode
)
76 extents_set_color (hidGC gc
, const char *name
)
81 extents_set_line_cap (hidGC gc
, EndCapStyle style
)
86 extents_set_line_width (hidGC gc
, Coord width
)
92 extents_set_draw_xor (hidGC gc
, int xor_
)
96 #define PEX(x,w) if (box.X1 > (x)-(w)) box.X1 = (x)-(w); \
97 if (box.X2 < (x)+(w)) box.X2 = (x)+(w)
98 #define PEY(y,w) if (box.Y1 > (y)-(w)) box.Y1 = (y)-(w); \
99 if (box.Y2 < (y)+(w)) box.Y2 = (y)+(w)
102 extents_draw_line (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
111 extents_draw_arc (hidGC gc
, Coord cx
, Coord cy
, Coord width
, Coord height
,
112 Angle start_angle
, Angle end_angle
)
114 /* Naive but good enough. */
115 PEX (cx
, width
+ gc
->width
);
116 PEY (cy
, height
+ gc
->width
);
120 extents_draw_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
129 extents_fill_circle (hidGC gc
, Coord cx
, Coord cy
, Coord radius
)
136 extents_fill_polygon (hidGC gc
, int n_coords
, Coord
*x
, Coord
*y
)
139 for (i
= 0; i
< n_coords
; i
++)
147 extents_fill_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
155 static HID extents_hid
;
156 static HID_DRAW extents_graphics
;
159 hid_extents_init (void)
161 static bool initialised
= false;
166 memset (&extents_hid
, 0, sizeof (HID
));
167 memset (&extents_graphics
, 0, sizeof (HID_DRAW
));
169 common_draw_helpers_init (&extents_graphics
);
171 extents_hid
.struct_size
= sizeof (HID
);
172 extents_hid
.name
= "extents-extents";
173 extents_hid
.description
= "used to calculate extents";
174 extents_hid
.poly_before
= 1;
176 extents_hid
.set_layer
= extents_set_layer
;
178 extents_hid
.graphics
= &extents_graphics
;
180 extents_graphics
.make_gc
= extents_make_gc
;
181 extents_graphics
.destroy_gc
= extents_destroy_gc
;
182 extents_graphics
.use_mask
= extents_use_mask
;
183 extents_graphics
.set_color
= extents_set_color
;
184 extents_graphics
.set_line_cap
= extents_set_line_cap
;
185 extents_graphics
.set_line_width
= extents_set_line_width
;
186 extents_graphics
.set_draw_xor
= extents_set_draw_xor
;
187 extents_graphics
.draw_line
= extents_draw_line
;
188 extents_graphics
.draw_arc
= extents_draw_arc
;
189 extents_graphics
.draw_rect
= extents_draw_rect
;
190 extents_graphics
.fill_circle
= extents_fill_circle
;
191 extents_graphics
.fill_polygon
= extents_fill_polygon
;
192 extents_graphics
.fill_rect
= extents_fill_rect
;
199 hid_get_extents (void *item
)
203 /* As this isn't a real "HID", we need to ensure we are initialised. */
208 box
.X2
= -COORD_MAX
- 1;
209 box
.Y2
= -COORD_MAX
- 1;
211 region
.X1
= -COORD_MAX
- 1;
212 region
.Y1
= -COORD_MAX
- 1;
213 region
.X2
= COORD_MAX
;
214 region
.Y2
= COORD_MAX
;
215 hid_expose_callback (&extents_hid
, ®ion
, item
);