From dc0092500ad8b6a3c9c35aef63eda9ad1cb2a2cb Mon Sep 17 00:00:00 2001 From: Peter Clifton Date: Wed, 21 Nov 2012 20:26:36 +0000 Subject: [PATCH] Move HID drawing API prototypes into a separate header file Due to the mess of places we define various things in and the order we pull in headers, we cannot easily create APIs in hid.h which rely on being passed PCB data-structures. --- src/crosshair.c | 1 + src/draw.c | 1 + src/hid.h | 63 +------------------------------------------ src/hid/common/draw_helpers.c | 1 + src/hid/common/extents.c | 1 + src/hid/common/hidnogui.c | 1 + src/hid/gcode/gcode.c | 1 + src/hid/gerber/gerber.c | 1 + src/hid/gtk/gui.h | 1 + src/hid/lesstif/main.c | 1 + src/hid/nelma/nelma.c | 1 + src/hid/png/png.c | 1 + src/hid/ps/eps.c | 1 + src/hid/ps/ps.c | 1 + src/hid_draw.h | 61 +++++++++++++++++++++++++++++++++++++++++ src/print.c | 1 + 16 files changed, 76 insertions(+), 62 deletions(-) create mode 100644 src/hid_draw.h diff --git a/src/crosshair.c b/src/crosshair.c index 65a94fb0a4..1079c5fb47 100644 --- a/src/crosshair.c +++ b/src/crosshair.c @@ -36,6 +36,7 @@ #include #include "global.h" +#include "hid_draw.h" #include "crosshair.h" #include "data.h" diff --git a/src/draw.c b/src/draw.c index e4d59f580c..32aacd5dff 100644 --- a/src/draw.c +++ b/src/draw.c @@ -33,6 +33,7 @@ #endif #include "global.h" +#include "hid_draw.h" /*#include "clip.h"*/ #include "compat.h" diff --git a/src/hid.h b/src/hid.h index e2d0ab8b9c..003b6a47e5 100644 --- a/src/hid.h +++ b/src/hid.h @@ -232,69 +232,8 @@ typedef enum int (*throw_drc_dialog) (void); } HID_DRC_GUI; - enum mask_mode { - HID_MASK_OFF = 0, /* Flush the buffer and return to non-mask operation. */ - HID_MASK_BEFORE = 1, /* Polygons being drawn before clears. */ - HID_MASK_CLEAR = 2, /* Clearances being drawn. */ - HID_MASK_AFTER = 3, /* Polygons being drawn after clears. */ - }; - -/* Low level drawing API */ - typedef struct - { - /* Drawing Functions. Coordinates and distances are ALWAYS in PCB's - default coordinates (1 nm at the time this comment was written). - Angles are always in degrees, with 0 being "right" (positive X) - and 90 being "up" (positive Y). */ - - /* Make an empty graphics context. */ - hidGC (*make_gc) (void); - void (*destroy_gc) (hidGC gc_); - void (*use_mask) (enum mask_mode mode); - - /* Set a color. Names can be like "red" or "#rrggbb" or special - names like "erase". *Always* use the "erase" color for removing - ink (like polygon reliefs or thermals), as you cannot rely on - knowing the background color or special needs of the HID. Always - use the "drill" color to draw holes. You may assume this is - cheap enough to call inside the redraw callback, but not cheap - enough to call for each item drawn. */ - void (*set_color) (hidGC gc, const char *name); - - /* Set the line style. While calling this is cheap, calling it with - different values each time may be expensive, so grouping items by - line style is helpful. */ - void (*set_line_cap) (hidGC gc, EndCapStyle style); - void (*set_line_width) (hidGC gc, Coord width); - void (*set_draw_xor) (hidGC gc, int xor_); - - /* Blends 20% or so color with 80% background. Only used for - assembly drawings so far. */ - void (*set_draw_faded) (hidGC gc, int faded); - - /* The usual drawing functions. "draw" means to use segments of the - given width, whereas "fill" means to fill to a zero-width - outline. */ - void (*draw_line) (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); - void (*draw_arc) (hidGC gc, Coord cx, Coord cy, Coord xradius, Coord yradius, Angle start_angle, Angle delta_angle); - void (*draw_rect) (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); - void (*fill_circle) (hidGC gc, Coord cx, Coord cy, Coord radius); - void (*fill_polygon) (hidGC gc, int n_coords_, Coord *x, Coord *y); - void (*fill_rect) (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); - - /* The following APIs render using PCB data-structures, not immediate parameters */ - - void (*fill_pcb_polygon) (hidGC gc, PolygonType *poly, const BoxType *clip_box); - void (*thindraw_pcb_polygon) (hidGC gc, PolygonType *poly, const BoxType *clip_box); - void (*fill_pcb_pad) (hidGC gc, PadType *pad, bool clip, bool mask); - void (*thindraw_pcb_pad) (hidGC gc, PadType *pad, bool clip, bool mask); - void (*fill_pcb_pv) (hidGC fg_gc, hidGC bg_gc, PinType *pv, bool drawHole, bool mask); - void (*thindraw_pcb_pv) (hidGC fg_gc, hidGC bg_gc, PinType *pv, bool drawHole, bool mask); - - } HID_DRAW; - - typedef struct hid_st HID; + typedef struct hid_draw_st HID_DRAW; /* This is the main HID structure. */ struct hid_st diff --git a/src/hid/common/draw_helpers.c b/src/hid/common/draw_helpers.c index 6c6320a70b..c1de57bf58 100644 --- a/src/hid/common/draw_helpers.c +++ b/src/hid/common/draw_helpers.c @@ -1,5 +1,6 @@ #include "global.h" #include "hid.h" +#include "hid_draw.h" #include "polygon.h" static void diff --git a/src/hid/common/extents.c b/src/hid/common/extents.c index a5b662eb3f..665d206a86 100644 --- a/src/hid/common/extents.c +++ b/src/hid/common/extents.c @@ -11,6 +11,7 @@ #include "data.h" #include "hid.h" +#include "hid_draw.h" #include "../hidint.h" #include "hid/common/draw_helpers.h" diff --git a/src/hid/common/hidnogui.c b/src/hid/common/hidnogui.c index d6d9afedb4..bab0bff3bc 100644 --- a/src/hid/common/hidnogui.c +++ b/src/hid/common/hidnogui.c @@ -9,6 +9,7 @@ #include "global.h" #include "hid.h" +#include "hid_draw.h" #ifdef HAVE_LIBDMALLOC #include diff --git a/src/hid/gcode/gcode.c b/src/hid/gcode/gcode.c index a66599230d..26530a5596 100644 --- a/src/hid/gcode/gcode.c +++ b/src/hid/gcode/gcode.c @@ -53,6 +53,7 @@ #include "rats.h" #include "hid.h" +#include "hid_draw.h" #include "../hidint.h" #include #include "hid/common/hidnogui.h" diff --git a/src/hid/gerber/gerber.c b/src/hid/gerber/gerber.c index ccb7faa1ac..b9830e64c0 100644 --- a/src/hid/gerber/gerber.c +++ b/src/hid/gerber/gerber.c @@ -27,6 +27,7 @@ #include "pcb-printf.h" #include "hid.h" +#include "hid_draw.h" #include "../hidint.h" #include "hid/common/hidnogui.h" #include "hid/common/draw_helpers.h" diff --git a/src/hid/gtk/gui.h b/src/hid/gtk/gui.h index af719fd6d1..2bbd2de517 100644 --- a/src/hid/gtk/gui.h +++ b/src/hid/gtk/gui.h @@ -27,6 +27,7 @@ #include "global.h" #include "hid.h" +#include "hid_draw.h" #include "hid/common/hid_resource.h" #include "data.h" diff --git a/src/hid/lesstif/main.c b/src/hid/lesstif/main.c index ea793b84d0..3e2fa01b1d 100644 --- a/src/hid/lesstif/main.c +++ b/src/hid/lesstif/main.c @@ -25,6 +25,7 @@ #include "error.h" #include "hid.h" +#include "hid_draw.h" #include "../hidint.h" #include "hid/common/hidnogui.h" #include "hid/common/draw_helpers.h" diff --git a/src/hid/nelma/nelma.c b/src/hid/nelma/nelma.c index a7310b752f..7151f828d2 100644 --- a/src/hid/nelma/nelma.c +++ b/src/hid/nelma/nelma.c @@ -70,6 +70,7 @@ #include "rats.h" #include "hid.h" +#include "hid_draw.h" #include "../hidint.h" #include "hid/common/hidnogui.h" #include "hid/common/draw_helpers.h" diff --git a/src/hid/png/png.c b/src/hid/png/png.c index d14f53ce1c..2b277407e8 100644 --- a/src/hid/png/png.c +++ b/src/hid/png/png.c @@ -41,6 +41,7 @@ #include "misc.h" #include "hid.h" +#include "hid_draw.h" #include "../hidint.h" #include "hid/common/hidnogui.h" #include "hid/common/draw_helpers.h" diff --git a/src/hid/ps/eps.c b/src/hid/ps/eps.c index a2b4f4552b..144549170a 100644 --- a/src/hid/ps/eps.c +++ b/src/hid/ps/eps.c @@ -14,6 +14,7 @@ #include "pcb-printf.h" #include "hid.h" +#include "hid_draw.h" #include "../hidint.h" #include "hid/common/hidnogui.h" #include "hid/common/draw_helpers.h" diff --git a/src/hid/ps/ps.c b/src/hid/ps/ps.c index f40c66de2b..597ff6d603 100644 --- a/src/hid/ps/ps.c +++ b/src/hid/ps/ps.c @@ -17,6 +17,7 @@ #include "pcb-printf.h" #include "hid.h" +#include "hid_draw.h" #include "../hidint.h" #include "hid/common/hidnogui.h" #include "hid/common/draw_helpers.h" diff --git a/src/hid_draw.h b/src/hid_draw.h new file mode 100644 index 0000000000..28fc50f460 --- /dev/null +++ b/src/hid_draw.h @@ -0,0 +1,61 @@ +enum mask_mode { + HID_MASK_OFF = 0, /* Flush the buffer and return to non-mask operation. */ + HID_MASK_BEFORE = 1, /* Polygons being drawn before clears. */ + HID_MASK_CLEAR = 2, /* Clearances being drawn. */ + HID_MASK_AFTER = 3, /* Polygons being drawn after clears. */ +}; + +/* Low level drawing API */ + +struct hid_draw_st +{ + /* Drawing Functions. Coordinates and distances are ALWAYS in PCB's + default coordinates (1 nm at the time this comment was written). + Angles are always in degrees, with 0 being "right" (positive X) + and 90 being "up" (positive Y). */ + + /* Make an empty graphics context. */ + hidGC (*make_gc) (void); + void (*destroy_gc) (hidGC gc); + void (*use_mask) (enum mask_mode mode); + + /* Set a color. Names can be like "red" or "#rrggbb" or special + names like "erase". *Always* use the "erase" color for removing + ink (like polygon reliefs or thermals), as you cannot rely on + knowing the background color or special needs of the HID. Always + use the "drill" color to draw holes. You may assume this is + cheap enough to call inside the redraw callback, but not cheap + enough to call for each item drawn. */ + void (*set_color) (hidGC gc, const char *name); + + /* Set the line style. While calling this is cheap, calling it with + different values each time may be expensive, so grouping items by + line style is helpful. */ + void (*set_line_cap) (hidGC gc, EndCapStyle style); + void (*set_line_width) (hidGC gc, Coord width); + void (*set_draw_xor) (hidGC gc, int xor_); + + /* Blends 20% or so color with 80% background. Only used for + assembly drawings so far. */ + void (*set_draw_faded) (hidGC gc, int faded); + + /* The usual drawing functions. "draw" means to use segments of the + given width, whereas "fill" means to fill to a zero-width + outline. */ + void (*draw_line) (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); + void (*draw_arc) (hidGC gc, Coord cx, Coord cy, Coord xradius, Coord yradius, Angle start_angle, Angle delta_angle); + void (*draw_rect) (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); + void (*fill_circle) (hidGC gc, Coord cx, Coord cy, Coord radius); + void (*fill_polygon) (hidGC gc, int n_coords, Coord *x, Coord *y); + void (*fill_rect) (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); + + /* The following APIs render using PCB data-structures, not immediate parameters */ + + void (*fill_pcb_polygon) (hidGC gc, PolygonType *poly, const BoxType *clip_box); + void (*thindraw_pcb_polygon) (hidGC gc, PolygonType *poly, const BoxType *clip_box); + void (*fill_pcb_pad) (hidGC gc, PadType *pad, bool clip, bool mask); + void (*thindraw_pcb_pad) (hidGC gc, PadType *pad, bool clip, bool mask); + void (*fill_pcb_pv) (hidGC fg_gc, hidGC bg_gc, PinType *pv, bool drawHole, bool mask); + void (*thindraw_pcb_pv) (hidGC fg_gc, hidGC bg_gc, PinType *pv, bool drawHole, bool mask); + +}; diff --git a/src/print.c b/src/print.c index 27e1c98895..fc6f9ff3c4 100644 --- a/src/print.c +++ b/src/print.c @@ -38,6 +38,7 @@ #endif #include "global.h" +#include "hid_draw.h" #include #ifdef HAVE_UNISTD_H -- 2.11.4.GIT