15 #include "../hidint.h"
16 #include "hid/common/draw_helpers.h"
18 #ifdef HAVE_LIBDMALLOC
24 typedef struct extents_gc_struct
26 struct hid_gc_struct hid_gc
; /* Parent */
32 extents_set_layer (const char *name
, int group
, int empty
)
35 if (idx
>= 0 && idx
< max_group
)
37 idx
= PCB
->LayerGroups
.Entries
[idx
][0];
39 if (idx
>= 0 && idx
< max_copper_layer
+ EXTRA_LAYERS
)
43 switch (SL_TYPE (idx
))
59 extents_make_gc (void)
61 hidGC gc
= (hidGC
)calloc (1, sizeof (struct extents_gc_struct
));
67 extents_destroy_gc (hidGC gc
)
73 extents_use_mask (enum mask_mode mode
)
78 extents_set_color (hidGC gc
, const char *name
)
83 extents_set_line_cap (hidGC gc
, EndCapStyle style
)
88 extents_set_line_width (hidGC gc
, Coord width
)
90 extentsGC extents_gc
= (extentsGC
)gc
;
92 extents_gc
->width
= width
;
96 extents_set_draw_xor (hidGC gc
, int xor_
)
100 #define PEX(x,w) if (box.X1 > (x)-(w)) box.X1 = (x)-(w); \
101 if (box.X2 < (x)+(w)) box.X2 = (x)+(w)
102 #define PEY(y,w) if (box.Y1 > (y)-(w)) box.Y1 = (y)-(w); \
103 if (box.Y2 < (y)+(w)) box.Y2 = (y)+(w)
106 extents_draw_line (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
108 extentsGC extents_gc
= (extentsGC
)gc
;
110 PEX (x1
, extents_gc
->width
);
111 PEY (y1
, extents_gc
->width
);
112 PEX (x2
, extents_gc
->width
);
113 PEY (y2
, extents_gc
->width
);
117 extents_draw_arc (hidGC gc
, Coord cx
, Coord cy
, Coord width
, Coord height
,
118 Angle start_angle
, Angle end_angle
)
120 extentsGC extents_gc
= (extentsGC
)gc
;
122 /* Naive but good enough. */
123 PEX (cx
, width
+ extents_gc
->width
);
124 PEY (cy
, height
+ extents_gc
->width
);
128 extents_draw_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
130 extentsGC extents_gc
= (extentsGC
)gc
;
132 PEX (x1
, extents_gc
->width
);
133 PEY (y1
, extents_gc
->width
);
134 PEX (x2
, extents_gc
->width
);
135 PEY (y2
, extents_gc
->width
);
139 extents_fill_circle (hidGC gc
, Coord cx
, Coord cy
, Coord radius
)
146 extents_fill_polygon (hidGC gc
, int n_coords
, Coord
*x
, Coord
*y
)
149 for (i
= 0; i
< n_coords
; i
++)
157 extents_fill_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
165 static HID extents_hid
;
166 static HID_DRAW extents_graphics
;
167 static HID_DRAW_CLASS extents_graphics_class
;
170 hid_extents_init (void)
172 static bool initialised
= false;
177 memset (&extents_hid
, 0, sizeof (HID
));
178 memset (&extents_graphics
, 0, sizeof (HID_DRAW
));
179 memset (&extents_graphics_class
, 0, sizeof (HID_DRAW_CLASS
));
181 extents_hid
.struct_size
= sizeof (HID
);
182 extents_hid
.name
= "extents-extents";
183 extents_hid
.description
= "used to calculate extents";
185 common_draw_helpers_class_init (&extents_graphics_class
);
187 extents_graphics_class
.set_layer
= extents_set_layer
;
188 extents_graphics_class
.make_gc
= extents_make_gc
;
189 extents_graphics_class
.destroy_gc
= extents_destroy_gc
;
190 extents_graphics_class
.use_mask
= extents_use_mask
;
191 extents_graphics_class
.set_color
= extents_set_color
;
192 extents_graphics_class
.set_line_cap
= extents_set_line_cap
;
193 extents_graphics_class
.set_line_width
= extents_set_line_width
;
194 extents_graphics_class
.set_draw_xor
= extents_set_draw_xor
;
195 extents_graphics_class
.draw_line
= extents_draw_line
;
196 extents_graphics_class
.draw_arc
= extents_draw_arc
;
197 extents_graphics_class
.draw_rect
= extents_draw_rect
;
198 extents_graphics_class
.fill_circle
= extents_fill_circle
;
199 extents_graphics_class
.fill_polygon
= extents_fill_polygon
;
200 extents_graphics_class
.fill_rect
= extents_fill_rect
;
202 extents_graphics
.klass
= &extents_graphics_class
;
203 extents_graphics
.poly_before
= true;
204 common_draw_helpers_init (&extents_graphics
);
211 hid_get_extents (void *item
)
215 /* As this isn't a real "HID", we need to ensure we are initialised. */
220 box
.X2
= -COORD_MAX
- 1;
221 box
.Y2
= -COORD_MAX
- 1;
223 region
.X1
= -COORD_MAX
- 1;
224 region
.Y1
= -COORD_MAX
- 1;
225 region
.X2
= COORD_MAX
;
226 region
.Y2
= COORD_MAX
;
227 hid_expose_callback (&extents_graphics
, ®ion
, item
);