summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gfx/diff.c31
-rw-r--r--gfx/gfx.c95
-rw-r--r--gfx/gfx.h36
-rw-r--r--gfx/text.c29
-rw-r--r--gfx/text.h17
-rw-r--r--gui/common.h7
-rw-r--r--gui/gui.c2
-rw-r--r--gui/index.c18
-rw-r--r--gui/render.c63
-rw-r--r--kicad/dwg.c94
-rw-r--r--kicad/dwg.h21
-rw-r--r--kicad/lib-render.c171
-rw-r--r--kicad/lib.h9
-rw-r--r--kicad/pl-render.c16
-rw-r--r--kicad/pl.h5
-rw-r--r--kicad/sch-render.c41
-rw-r--r--kicad/sch.h11
-rw-r--r--main.c23
18 files changed, 378 insertions, 311 deletions
diff --git a/gfx/diff.c b/gfx/diff.c
index cf7c80e..24b2540 100644
--- a/gfx/diff.c
+++ b/gfx/diff.c
@@ -27,6 +27,7 @@
#include "kicad/sch.h"
#include "kicad/lib.h"
#include "gfx/record.h"
+#include "gfx/gfx.h"
#include "gfx/diff.h"
@@ -48,7 +49,7 @@
struct diff {
- void *cr_ctx;
+ struct gfx *gfx;
uint32_t *new_img;
int w, h, stride;
const char *output_name;
@@ -65,7 +66,7 @@ static void diff_line(void *ctx, int sx, int sy, int ex, int ey,
{
const struct diff *diff = ctx;
- cro_img_ops.line(diff->cr_ctx, sx, sy, ex, ey, color, layer);
+ gfx_line(diff->gfx, sx, sy, ex, ey, color, layer);
}
@@ -75,7 +76,7 @@ static void diff_poly(void *ctx,
{
const struct diff *diff = ctx;
- cro_img_ops.poly(diff->cr_ctx, points, x, y, color, fill_color, layer);
+ gfx_poly(diff->gfx, points, x, y, color, fill_color, layer);
}
@@ -84,7 +85,7 @@ static void diff_circ(void *ctx, int x, int y, int r,
{
const struct diff *diff = ctx;
- cro_img_ops.circ(diff->cr_ctx, x, y, r, color, fill_color, layer);
+ gfx_circ(diff->gfx, x, y, r, color, fill_color, layer);
}
@@ -93,8 +94,7 @@ static void diff_arc(void *ctx, int x, int y, int r, int sa, int ea,
{
const struct diff *diff = ctx;
- cro_img_ops.arc(diff->cr_ctx, x, y, r, sa, ea,
- color, fill_color, layer);
+ gfx_arc(diff->gfx, x, y, r, sa, ea, color, fill_color, layer);
}
@@ -103,8 +103,7 @@ static void diff_text(void *ctx, int x, int y, const char *s, unsigned size,
{
const struct diff *diff = ctx;
- cro_img_ops.text(diff->cr_ctx, x, y, s, size, align, rot,
- color, layer);
+ gfx_text(diff->gfx, x, y, s, size, align, rot, color, layer);
}
@@ -112,7 +111,7 @@ static unsigned diff_text_width(void *ctx, const char *s, unsigned size)
{
const struct diff *diff = ctx;
- return cro_img_ops.text_width(diff->cr_ctx, s, size);
+ return gfx_text_width(diff->gfx, s, size);
}
@@ -161,14 +160,14 @@ static void *diff_init(int argc, char *const *argv)
file_close(&sch_file);
optind = 0;
- gfx_init(&cro_img_ops, argc, argv);
- diff->cr_ctx = gfx_ctx;
- sch_render(new_sch.sheets);
- diff->new_img = cro_img_end(gfx_ctx,
+ diff->gfx = gfx_init(&cro_img_ops, argc, argv);
+ sch_render(new_sch.sheets, diff->gfx);
+ diff->new_img = cro_img_end(gfx_user(diff->gfx),
&diff->w, &diff->h, &diff->stride);
optind = 0;
- diff->cr_ctx = cro_img_ops.init(argc, argv);
+ diff->gfx = gfx_init(&cro_img_ops, argc, argv);
+ //diff->gfx = cro_img_ops.init(argc, argv);
return diff;
@@ -308,7 +307,7 @@ static void diff_end(void *ctx)
uint32_t *old_img;
int w, h, stride;
- old_img = cro_img_end(diff->cr_ctx, &w, &h, &stride);
+ old_img = cro_img_end(gfx_user(diff->gfx), &w, &h, &stride);
if (diff->w != w || diff->h != h)
fatal("%d x %d vs. %d x %d image\n", w, h, diff->w, diff->h);
@@ -316,7 +315,7 @@ static void diff_end(void *ctx)
show_areas(diff, old_img);
free_areas(&diff->areas);
- cro_img_write(diff->cr_ctx, diff->output_name);
+ cro_img_write(gfx_user(diff->gfx), diff->output_name);
}
diff --git a/gfx/gfx.c b/gfx/gfx.c
index 6236888..0324cfd 100644
--- a/gfx/gfx.c
+++ b/gfx/gfx.c
@@ -12,36 +12,40 @@
#include <stdbool.h>
+#include <stdlib.h>
+#include "misc/util.h"
#include "gfx/style.h"
#include "gfx/text.h"
#include "gfx/gfx.h"
-void *gfx_ctx;
+struct gfx {
+ const struct gfx_ops *ops;
+ void *user;
+};
-static const struct gfx_ops *gfx_ops;
-
-void gfx_line(int sx, int sy, int ex, int ey, int color, unsigned layer)
+void gfx_line(struct gfx *gfx,
+ int sx, int sy, int ex, int ey, int color, unsigned layer)
{
- if (gfx_ops->line) {
- gfx_ops->line(gfx_ctx, sx, sy, ex, ey, color, layer);
+ if (gfx->ops->line) {
+ gfx->ops->line(gfx->user, sx, sy, ex, ey, color, layer);
return;
}
int vx[] = { sx, ex };
int vy[] = { sy, ey };
- gfx_poly(2, vx, vy, color, COLOR_NONE, layer);
+ gfx_poly(gfx, 2, vx, vy, color, COLOR_NONE, layer);
}
-void gfx_rect(int sx, int sy, int ex, int ey,
+void gfx_rect(struct gfx *gfx, int sx, int sy, int ex, int ey,
int color, int fill_color, unsigned layer)
{
- if (gfx_ops->rect) {
- gfx_ops->rect(gfx_ctx, sx, sy, ex, ey,
+ if (gfx->ops->rect) {
+ gfx->ops->rect(gfx->user, sx, sy, ex, ey,
color, fill_color, layer);
return;
}
@@ -49,79 +53,94 @@ void gfx_rect(int sx, int sy, int ex, int ey,
int vx[] = { sx, ex, ex, sx, sx };
int vy[] = { sy, sy, ey, ey, sy };
- gfx_poly(5, vx, vy, color, fill_color, layer);
+ gfx_poly(gfx, 5, vx, vy, color, fill_color, layer);
}
-void gfx_poly(int points, const int x[points], const int y[points],
+void gfx_poly(struct gfx *gfx,
+ int points, const int x[points], const int y[points],
int color, int fill_color, unsigned layer)
{
- gfx_ops->poly(gfx_ctx, points, x, y, color, fill_color, layer);
+ gfx->ops->poly(gfx->user, points, x, y, color, fill_color, layer);
}
-void gfx_circ(int x, int y, int r, int color, int fill_color, unsigned layer)
+void gfx_circ(struct gfx *gfx,
+ int x, int y, int r, int color, int fill_color, unsigned layer)
{
- gfx_ops->circ(gfx_ctx, x, y, r, color, fill_color, layer);
+ gfx->ops->circ(gfx->user, x, y, r, color, fill_color, layer);
}
-void gfx_arc(int x, int y, int r, int sa, int ea,
+void gfx_arc(struct gfx *gfx, int x, int y, int r, int sa, int ea,
int color, int fill_color, unsigned layer)
{
- gfx_ops->arc(gfx_ctx, x, y, r, sa, ea, color, fill_color, layer);
+ gfx->ops->arc(gfx->user, x, y, r, sa, ea, color, fill_color, layer);
}
-void gfx_text(int x, int y, const char *s, unsigned size,
+void gfx_text(struct gfx *gfx, int x, int y, const char *s, unsigned size,
enum text_align align, int rot, unsigned color, unsigned layer)
{
- gfx_ops->text(gfx_ctx, x, y, s, size, align, rot, color, layer);
+ gfx->ops->text(gfx->user, x, y, s, size, align, rot, color, layer);
}
-void gfx_tag(const char *s,
+void gfx_tag(struct gfx *gfx, const char *s,
unsigned points, const int x[points], int const y[points])
{
- if (gfx_ops->tag)
- gfx_ops->tag(gfx_ctx, s, points, x, y);
+ if (gfx->ops->tag)
+ gfx->ops->tag(gfx->user, s, points, x, y);
}
-unsigned gfx_text_width(const char *s, unsigned size)
+unsigned gfx_text_width(struct gfx *gfx, const char *s, unsigned size)
{
- return gfx_ops->text_width(gfx_ctx, s, size);
+ return gfx->ops->text_width(gfx->user, s, size);
}
-void gfx_init(const struct gfx_ops *ops, int argc, char *const *argv)
+struct gfx *gfx_init(const struct gfx_ops *ops,
+ int argc, char *const *argv)
{
- gfx_ctx = ops->init(argc, argv);
- gfx_ops = ops;
+ struct gfx *new;
+
+ new = alloc_type(struct gfx);
+ new->user = ops->init(argc, argv);
+ new->ops = ops;
+ return new;
}
-void gfx_sheet_name(const char *name)
+void gfx_sheet_name(struct gfx *gfx, const char *name)
{
- if (gfx_ops->sheet_name)
- gfx_ops->sheet_name(gfx_ctx, name);
+ if (gfx->ops->sheet_name)
+ gfx->ops->sheet_name(gfx->user, name);
}
-void gfx_new_sheet(void)
+void gfx_new_sheet(struct gfx *gfx)
{
- if (gfx_ops->new_sheet)
- gfx_ops->new_sheet(gfx_ctx);
+ if (gfx->ops->new_sheet)
+ gfx->ops->new_sheet(gfx->user);
}
-bool gfx_multi_sheet(void)
+bool gfx_multi_sheet(struct gfx *gfx)
{
- return !!gfx_ops->new_sheet;
+ return !!gfx->ops->new_sheet;
}
-void gfx_end(void)
+
+void *gfx_user(struct gfx *gfx)
+{
+ return gfx->user;
+}
+
+
+void gfx_end(struct gfx *gfx)
{
- if (gfx_ops->end)
- gfx_ops->end(gfx_ctx);
+ if (gfx->ops->end)
+ gfx->ops->end(gfx->user);
+ free(gfx);
}
diff --git a/gfx/gfx.h b/gfx/gfx.h
index bdd5225..c31495b 100644
--- a/gfx/gfx.h
+++ b/gfx/gfx.h
@@ -19,6 +19,8 @@
#include "gfx/text.h"
+struct gfx;
+
struct gfx_ops {
const char *name;
void (*line)(void *ctx, int sx, int sy, int ex, int ey,
@@ -44,31 +46,33 @@ struct gfx_ops {
};
-extern void *gfx_ctx;
-
-
/* wrappers */
-void gfx_line(int sx, int sy, int ex, int ey, int color, unsigned layer);
-void gfx_rect(int sx, int sy, int ex, int ey,
+void gfx_line(struct gfx *gfx,
+ int sx, int sy, int ex, int ey, int color, unsigned layer);
+void gfx_rect(struct gfx *gfx, int sx, int sy, int ex, int ey,
int color, int fill_color, unsigned layer);
-void gfx_poly(int points, const int x[points], const int y[points],
+void gfx_poly(struct gfx *gfx,
+ int points, const int x[points], const int y[points],
int color, int fill_color, unsigned layer);
-void gfx_circ(int x, int y, int r, int color, int fill_color, unsigned layer);
-void gfx_arc(int x, int y, int r, int sa, int ea,
+void gfx_circ(struct gfx *gfx,
+ int x, int y, int r, int color, int fill_color, unsigned layer);
+void gfx_arc(struct gfx *gfx, int x, int y, int r, int sa, int ea,
int color, int fill_color, unsigned layer);
-void gfx_text(int x, int y, const char *s, unsigned size,
+void gfx_text(struct gfx *gfx, int x, int y, const char *s, unsigned size,
enum text_align align, int rot, unsigned color, unsigned layer);
-void gfx_tag(const char *s,
+void gfx_tag(struct gfx *gfx, const char *s,
unsigned points, const int x[points], int const y[points]);
-unsigned gfx_text_width(const char *s, unsigned size);
+unsigned gfx_text_width(struct gfx *gfx, const char *s, unsigned size);
/* inititalization and termination */
-void gfx_init(const struct gfx_ops *ops, int argc, char *const *argv);
-void gfx_sheet_name(const char *name);
-void gfx_new_sheet(void);
-bool gfx_multi_sheet(void);
-void gfx_end(void);
+struct gfx *gfx_init(const struct gfx_ops *ops,
+ int argc, char *const *argv);
+void gfx_sheet_name(struct gfx *gfx, const char *name);
+void gfx_new_sheet(struct gfx *gfx);
+bool gfx_multi_sheet(struct gfx *gfx);
+void *gfx_user(struct gfx *gfx); /* transitional kludge */
+void gfx_end(struct gfx *gfx);
#endif /* !GFX_GFX_H */
diff --git a/gfx/text.c b/gfx/text.c
index 1d6d38a..a081aef 100644
--- a/gfx/text.c
+++ b/gfx/text.c
@@ -93,7 +93,8 @@ static int align(int dim, enum text_align align)
}
-void text_fig(const struct text *txt, int color, unsigned layer)
+void text_fig(const struct text *txt, struct gfx *gfx,
+ int color, unsigned layer)
{
char *buf = stralloc(txt->s);
char *tmp = buf;
@@ -114,7 +115,8 @@ void text_fig(const struct text *txt, int color, unsigned layer)
if (!s)
break;
tmp = NULL;
- gfx_text(x, y, s, txt->size, txt->hor, txt->rot, color, layer);
+ gfx_text(gfx, x, y, s, txt->size, txt->hor, txt->rot, color,
+ layer);
x += rx(0, NEWLINE_SKIP * txt->size, txt->rot);
y += ry(0, NEWLINE_SKIP * txt->size, txt->rot);
}
@@ -122,10 +124,11 @@ void text_fig(const struct text *txt, int color, unsigned layer)
}
-void text_rel(const struct text *txt, enum text_align xr, enum text_align yr,
+void text_rel(const struct text *txt, struct gfx *gfx,
+ enum text_align xr, enum text_align yr,
int dx, int dy, int *res_x, int *res_y)
{
- int width = gfx_text_width(txt->s, txt->size);
+ int width = gfx_text_width(gfx, txt->s, txt->size);
dx -= align(width, txt->hor);
dy += align(txt->size, txt->vert);
@@ -138,28 +141,28 @@ void text_rel(const struct text *txt, enum text_align xr, enum text_align yr,
}
-void text_shift(struct text *txt, enum text_align xr, enum text_align yr,
- int dx, int dy)
+void text_shift(struct text *txt, struct gfx *gfx,
+ enum text_align xr, enum text_align yr, int dx, int dy)
{
- text_rel(txt, xr, yr, dx, dy, &txt->x, &txt->y);
+ text_rel(txt, gfx, xr, yr, dx, dy, &txt->x, &txt->y);
}
-int text_rel_x(const struct text *txt, enum text_align xr, enum text_align yr,
- int dx, int dy)
+int text_rel_x(const struct text *txt, struct gfx *gfx,
+ enum text_align xr, enum text_align yr, int dx, int dy)
{
int x;
- text_rel(txt, xr, yr, dx, dy, &x, NULL);
+ text_rel(txt, gfx, xr, yr, dx, dy, &x, NULL);
return x;
}
-int text_rel_y(const struct text *txt, enum text_align xr, enum text_align yr,
- int dx, int dy)
+int text_rel_y(const struct text *txt, struct gfx *gfx,
+ enum text_align xr, enum text_align yr, int dx, int dy)
{
int y;
- text_rel(txt, xr, yr, dx, dy, NULL, &y);
+ text_rel(txt, gfx, xr, yr, dx, dy, NULL, &y);
return y;
}
diff --git a/gfx/text.h b/gfx/text.h
index e6327fd..0564cb0 100644
--- a/gfx/text.h
+++ b/gfx/text.h
@@ -14,6 +14,8 @@
#ifndef GFX_TEXT_H
#define GFX_TEXT_H
+struct gfx; /* don't recurse */
+
/* use constants of FIG text sub_type */
@@ -45,15 +47,20 @@ void text_rot(struct text *txt, int deg);
void text_flip_x(struct text *txt);
enum text_align text_flip(enum text_align align);
-void text_fig(const struct text *txt, int color, unsigned layer);
+void text_fig(const struct text *txt, struct gfx *gfx,
+ int color, unsigned layer);
-void text_rel(const struct text *txt, enum text_align xr, enum text_align yr,
+void text_rel(const struct text *txt, struct gfx *gfx,
+ enum text_align xr, enum text_align yr,
int dx, int dy, int *res_x, int *res_y);
-void text_shift(struct text *txt, enum text_align xr, enum text_align yr,
+void text_shift(struct text *txt, struct gfx *gfx,
+ enum text_align xr, enum text_align yr,
int dx, int dy);
-int text_rel_x(const struct text *txt, enum text_align xr, enum text_align yr,
+int text_rel_x(const struct text *txt, struct gfx *gfx,
+ enum text_align xr, enum text_align yr,
int dx, int dy);
-int text_rel_y(const struct text *txt, enum text_align xr, enum text_align yr,
+int text_rel_y(const struct text *txt, struct gfx *gfx,
+ enum text_align xr, enum text_align yr,
int dx, int dy);
#endif /* !GFX_TEXT_H */
diff --git a/gui/common.h b/gui/common.h
index c823dd5..cf03953 100644
--- a/gui/common.h
+++ b/gui/common.h
@@ -18,6 +18,7 @@
#include <gtk/gtk.h>
#include "gfx/cro.h"
+#include "gfx/gfx.h"
#include "file/git-hist.h"
#include "kicad/lib.h"
#include "kicad/sch.h"
@@ -32,8 +33,8 @@ struct gui_sheet {
const struct sheet *sch;
struct gui_ctx *ctx; /* back link */
struct gui_hist *hist; /* back link */
- struct cro_ctx *gfx_ctx;
- struct cro_ctx *gfx_ctx_extra;
+ struct gfx *gfx;
+ struct gfx *gfx_extra;
int w, h; /* in eeschema coordinates */
int xmin, ymin;
@@ -44,7 +45,7 @@ struct gui_sheet {
struct aoi *aois; /* areas of interest; in schematics coord */
/* thumbnails, for index */
- struct cro_ctx *gfx_ctx_thumb; /* NULL if not yet rendered */
+ struct gfx *gfx_thumb; /* NULL if not yet rendered */
cairo_surface_t *thumb_surf; /* for caching */
unsigned thumb_w, thumb_h; /* size for which we cached */
struct overlay *thumb_over; /* thumb overlay */
diff --git a/gui/gui.c b/gui/gui.c
index 2b3e001..5587c4f 100644
--- a/gui/gui.c
+++ b/gui/gui.c
@@ -169,7 +169,7 @@ static struct gui_sheet *get_sheets(struct gui_ctx *ctx, struct gui_hist *hist,
new->sch = sheet;
new->ctx = ctx;
new->hist = hist;
- new->gfx_ctx_thumb = NULL;
+ new->gfx_thumb = NULL;
new->thumb_surf = NULL;
new->rendered = 0;
diff --git a/gui/index.c b/gui/index.c
index 2477cb7..8a6e4b5 100644
--- a/gui/index.c
+++ b/gui/index.c
@@ -266,13 +266,13 @@ static void index_render_sheet(const struct gui_ctx *ctx,
uint32_t *data;
int stride;
- if (!sheet->gfx_ctx_thumb) {
+ if (!sheet->gfx_thumb) {
char *argv[] = { "index", NULL };
- gfx_init(&cro_canvas_ops, 1, argv);
- sch_render(sheet->sch);
- cro_canvas_end(gfx_ctx, NULL, NULL, NULL, NULL);
- sheet->gfx_ctx_thumb = gfx_ctx;
+ sheet->gfx_thumb = gfx_init(&cro_canvas_ops, 1, argv);
+ sch_render(sheet->sch, sheet->gfx_thumb);
+ cro_canvas_end(gfx_user(sheet->gfx_thumb),
+ NULL, NULL, NULL, NULL);
}
if (ctx->old_hist && ctx->diff_mode == diff_delta) {
@@ -295,7 +295,7 @@ static void index_render_sheet(const struct gui_ctx *ctx,
sheet->thumb_surf = NULL;
}
- record_bbox((const struct record *) sheet->gfx_ctx_thumb,
+ record_bbox((const struct record *) gfx_user(sheet->gfx_thumb),
&xmin, &ymin, &w, &h);
if (!w || !h)
return;
@@ -306,13 +306,13 @@ static void index_render_sheet(const struct gui_ctx *ctx,
xo = -(xmin + w / 2) * f + thumb_w / 2;
yo = -(ymin + h / 2) * f + thumb_h / 2;
- data = cro_img(sheet->gfx_ctx_thumb, NULL, xo, yo, thumb_w, thumb_h, f,
- NULL, &stride);
+ data = cro_img(gfx_user(sheet->gfx_thumb), NULL,
+ xo, yo, thumb_w, thumb_h, f, NULL, &stride);
if (yellow)
paint_yellow(data, thumb_w, thumb_h, stride);
- sheet->thumb_surf = cro_img_surface(sheet->gfx_ctx_thumb);
+ sheet->thumb_surf = cro_img_surface(gfx_user(sheet->gfx_thumb));
sheet->thumb_w = thumb_w;
sheet->thumb_h = thumb_h;
sheet->thumb_yellow = yellow;
diff --git a/gui/render.c b/gui/render.c
index 9cf71e9..a5eb8e4 100644
--- a/gui/render.c
+++ b/gui/render.c
@@ -161,8 +161,9 @@ static void hack(const struct gui_ctx *ctx, cairo_t *cr,
areas = changed_sheets(ctx, xo, yo, f);
diff_to_canvas(cr, ctx->x, ctx->y, ctx->scale,
- old->gfx_ctx, show_extra ? old->gfx_ctx_extra : NULL,
- new->gfx_ctx, show_extra ? new->gfx_ctx_extra : NULL, areas);
+ gfx_user(old->gfx), show_extra ? gfx_user(old->gfx_extra) : NULL,
+ gfx_user(new->gfx), show_extra ? gfx_user(new->gfx_extra) : NULL,
+ areas);
free_areas(&areas);
}
@@ -184,15 +185,17 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
if (!ctx->old_hist || ctx->diff_mode == diff_new) {
highlight_glabel(ctx, sheet, cr, x, y, f);
if (show_extra)
- cro_canvas_draw(sheet->gfx_ctx_extra, cr, x, y, f);
- cro_canvas_draw(sheet->gfx_ctx, cr, x, y, f);
+ cro_canvas_draw(gfx_user(sheet->gfx_extra),
+ cr, x, y, f);
+ cro_canvas_draw(gfx_user(sheet->gfx), cr, x, y, f);
} else if (ctx->diff_mode == diff_old) {
sheet = find_corresponding_sheet(ctx->old_hist->sheets,
ctx->new_hist->sheets, ctx->curr_sheet);
highlight_glabel(ctx, sheet, cr, x, y, f);
if (show_extra)
- cro_canvas_draw(sheet->gfx_ctx_extra, cr, x, y, f);
- cro_canvas_draw(sheet->gfx_ctx, cr, x, y, f);
+ cro_canvas_draw(gfx_user(sheet->gfx_extra),
+ cr, x, y, f);
+ cro_canvas_draw(gfx_user(sheet->gfx), cr, x, y, f);
} else if (use_delta) {
struct area *areas = changed_sheets(ctx, x, y, f);
const struct area *area;
@@ -207,16 +210,16 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
/* @@@ fix geometry later */
if (show_extra) {
- cro_canvas_draw(ctx->delta_ab.gfx_ctx_extra, cr,
- x, y, f);
- cro_canvas_draw(ctx->delta_a.gfx_ctx_extra, cr,
- x, y, f);
- cro_canvas_draw(ctx->delta_b.gfx_ctx_extra, cr,
- x, y, f);
+ cro_canvas_draw(gfx_user(ctx->delta_ab.gfx_extra),
+ cr, x, y, f);
+ cro_canvas_draw(gfx_user(ctx->delta_a.gfx_extra),
+ cr, x, y, f);
+ cro_canvas_draw(gfx_user(ctx->delta_b.gfx_extra),
+ cr, x, y, f);
}
- cro_canvas_draw(ctx->delta_ab.gfx_ctx, cr, x, y, f);
- cro_canvas_draw(ctx->delta_a.gfx_ctx, cr, x, y, f);
- cro_canvas_draw(ctx->delta_b.gfx_ctx, cr, x, y, f);
+ cro_canvas_draw(gfx_user(ctx->delta_ab.gfx), cr, x, y, f);
+ cro_canvas_draw(gfx_user(ctx->delta_a.gfx), cr, x, y, f);
+ cro_canvas_draw(gfx_user(ctx->delta_b.gfx), cr, x, y, f);
} else {
hack(ctx, cr, x, y, f);
}
@@ -249,19 +252,17 @@ void render_sheet(struct gui_sheet *sheet)
{
char *argv[] = { "gui", NULL };
- gfx_init(&cro_canvas_ops, 1, argv);
+ sheet->gfx = gfx_init(&cro_canvas_ops, 1, argv);
if (sheet->hist && sheet->hist->pl) /* @@@ no pl_render for delta */
- pl_render(sheet->hist->pl, sheet->hist->sch_ctx.sheets,
- sheet->sch);
- sch_render(sheet->sch);
- cro_canvas_end(gfx_ctx,
+ pl_render(sheet->hist->pl, sheet->gfx,
+ sheet->hist->sch_ctx.sheets, sheet->sch);
+ sch_render(sheet->sch, sheet->gfx);
+ cro_canvas_end(gfx_user(sheet->gfx),
&sheet->w, &sheet->h, &sheet->xmin, &sheet->ymin);
- sheet->gfx_ctx = gfx_ctx;
- gfx_init(&cro_canvas_ops, 1, argv);
- sch_render_extra(sheet->sch);
- cro_canvas_end(gfx_ctx, NULL, NULL, NULL, NULL);
- sheet->gfx_ctx_extra = gfx_ctx;
+ sheet->gfx_extra = gfx_init(&cro_canvas_ops, 1, argv);
+ sch_render_extra(sheet->sch, sheet->gfx_extra);
+ cro_canvas_end(gfx_user(sheet->gfx_extra), NULL, NULL, NULL, NULL);
sheet->rendered = 1;
// gfx_end();
@@ -293,13 +294,13 @@ void render_delta(struct gui_ctx *ctx)
render_sheet(&ctx->delta_b);
render_sheet(&ctx->delta_ab);
- cro_color_override(ctx->delta_ab.gfx_ctx, COLOR_LIGHT_GREY);
- cro_color_override(ctx->delta_b.gfx_ctx, COLOR_RED);
- cro_color_override(ctx->delta_a.gfx_ctx, COLOR_GREEN2);
+ cro_color_override(gfx_user(ctx->delta_ab.gfx), COLOR_LIGHT_GREY);
+ cro_color_override(gfx_user(ctx->delta_b.gfx), COLOR_RED);
+ cro_color_override(gfx_user(ctx->delta_a.gfx), COLOR_GREEN2);
- cro_color_override(ctx->delta_ab.gfx_ctx_extra, COLOR_LIGHT_GREY);
- cro_color_override(ctx->delta_b.gfx_ctx_extra, COLOR_RED);
- cro_color_override(ctx->delta_a.gfx_ctx_extra, COLOR_GREEN2);
+ cro_color_override(gfx_user(ctx->delta_ab.gfx_extra), COLOR_LIGHT_GREY);
+ cro_color_override(gfx_user(ctx->delta_b.gfx_extra), COLOR_RED);
+ cro_color_override(gfx_user(ctx->delta_a.gfx_extra), COLOR_GREEN2);
// @@@ clean up when leaving sheet
#endif
diff --git a/kicad/dwg.c b/kicad/dwg.c
index 799c329..f925539 100644
--- a/kicad/dwg.c
+++ b/kicad/dwg.c
@@ -80,7 +80,7 @@ static enum box_type flip_box(enum box_type box)
}
-void dwg_label(int x, int y, const char *s, int dir, int dim,
+void dwg_label(struct gfx *gfx, int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape, struct dwg_bbox *bbox)
{
struct text txt = {
@@ -121,11 +121,11 @@ void dwg_label(int x, int y, const char *s, int dir, int dim,
txt.y -= dy * LABEL_OFFSET;
txt.x += dx * LABEL_OFFSET;
- text_fig(&txt, COLOR_LABEL, LAYER_LABEL);
+ text_fig(&txt, gfx, COLOR_LABEL, LAYER_LABEL);
}
-void dwg_glabel(int x, int y, const char *s, int dir, int dim,
+void dwg_glabel(struct gfx *gfx, int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape, struct dwg_bbox *bbox)
{
struct text txt = {
@@ -198,75 +198,75 @@ void dwg_glabel(int x, int y, const char *s, int dir, int dim,
switch (box) {
case box_simple:
n = 5;
- text_shift(&txt, txt.hor, text_mid, shift_flat, 0);
- text_rel(&txt, text_min, text_min,
+ text_shift(&txt, gfx, txt.hor, text_mid, shift_flat, 0);
+ text_rel(&txt, gfx, text_min, text_min,
-GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1);
- text_rel(&txt, text_max, text_min,
+ text_rel(&txt, gfx, text_max, text_min,
GLABEL_OFFSET, GLABEL_OFFSET, vx + 2, vy + 2);
- text_rel(&txt, text_max, text_max,
+ text_rel(&txt, gfx, text_max, text_max,
GLABEL_OFFSET, -GLABEL_OFFSET, vx + 3, vy + 3);
- text_rel(&txt, text_min, text_max,
+ text_rel(&txt, gfx, text_min, text_max,
-GLABEL_OFFSET, -GLABEL_OFFSET, vx + 4, vy + 4);
break;
case box_right:
- text_shift(&txt, txt.hor, text_mid,
+ text_shift(&txt, gfx, txt.hor, text_mid,
anchor_right ? shift_tip : shift_flat, 0);
- text_rel(&txt, text_min, text_min,
+ text_rel(&txt, gfx, text_min, text_min,
-GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1);
- text_rel(&txt, text_max, text_min,
+ text_rel(&txt, gfx, text_max, text_min,
GLABEL_OFFSET, GLABEL_OFFSET, vx + 2, vy + 2);
- text_rel(&txt, text_max, text_mid, GLABEL_OFFSET + half, 0,
+ text_rel(&txt, gfx, text_max, text_mid, GLABEL_OFFSET + half, 0,
vx + 3, vy + 3);
- text_rel(&txt, text_max, text_max,
+ text_rel(&txt, gfx, text_max, text_max,
GLABEL_OFFSET, -GLABEL_OFFSET, vx + 4, vy + 4);
- text_rel(&txt, text_min, text_max,
+ text_rel(&txt, gfx, text_min, text_max,
-GLABEL_OFFSET, -GLABEL_OFFSET, vx + 5, vy + 5);
break;
case box_left:
- text_shift(&txt, txt.hor, text_mid,
+ text_shift(&txt, gfx, txt.hor, text_mid,
anchor_right ? shift_flat : shift_tip, 0);
- text_rel(&txt, text_min, text_min,
+ text_rel(&txt, gfx, text_min, text_min,
-GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1);
- text_rel(&txt, text_max, text_min,
+ text_rel(&txt, gfx, text_max, text_min,
GLABEL_OFFSET, GLABEL_OFFSET, vx + 2, vy + 2);
- text_rel(&txt, text_max, text_max,
+ text_rel(&txt, gfx, text_max, text_max,
GLABEL_OFFSET, -GLABEL_OFFSET, vx + 3, vy + 3);
- text_rel(&txt, text_min, text_max,
+ text_rel(&txt, gfx, text_min, text_max,
-GLABEL_OFFSET, -GLABEL_OFFSET, vx + 4, vy + 4);
- text_rel(&txt, text_min, text_mid, -GLABEL_OFFSET- half, 0,
+ text_rel(&txt, gfx, text_min, text_mid, -GLABEL_OFFSET- half, 0,
vx + 5, vy + 5);
break;
case box_both:
n = 7;
- text_shift(&txt, txt.hor, text_mid, shift_tip, 0);
- text_rel(&txt, text_min, text_min,
+ text_shift(&txt, gfx, txt.hor, text_mid, shift_tip, 0);
+ text_rel(&txt, gfx, text_min, text_min,
-GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1);
- text_rel(&txt, text_max, text_min,
+ text_rel(&txt, gfx, text_max, text_min,
GLABEL_OFFSET, GLABEL_OFFSET, vx + 2, vy + 2);
- text_rel(&txt, text_max, text_mid, GLABEL_OFFSET + half, 0,
+ text_rel(&txt, gfx, text_max, text_mid, GLABEL_OFFSET + half, 0,
vx + 3, vy + 3);
- text_rel(&txt, text_max, text_max,
+ text_rel(&txt, gfx, text_max, text_max,
GLABEL_OFFSET, -GLABEL_OFFSET, vx + 4, vy + 4);
- text_rel(&txt, text_min, text_max,
+ text_rel(&txt, gfx, text_min, text_max,
-GLABEL_OFFSET, -GLABEL_OFFSET, vx + 5, vy + 5);
- text_rel(&txt, text_min, text_mid, -GLABEL_OFFSET- half, 0,
+ text_rel(&txt, gfx, text_min, text_mid, -GLABEL_OFFSET- half, 0,
vx + 6, vy + 6);
break;
default:
assert(0);
}
- text_fig(&txt, COLOR_GLABEL, LAYER_GLABEL);
+ text_fig(&txt, gfx, COLOR_GLABEL, LAYER_GLABEL);
vx[0] = vx[n - 1];
vy[0] = vy[n - 1];
- gfx_poly(n, vx, vy, COLOR_GLABEL, COLOR_NONE, LAYER_GLABEL);
+ gfx_poly(gfx, n, vx, vy, COLOR_GLABEL, COLOR_NONE, LAYER_GLABEL);
if (bbox)
bbox_from_poly(bbox, n, vx, vy);
if (asprintf(&tag, "G:%s", s)) {}
- gfx_tag(tag, n, vx, vy);
+ gfx_tag(gfx, tag, n, vx, vy);
}
@@ -325,7 +325,7 @@ static int make_box(enum box_type box, int h, int *vx, int *vy)
}
-void dwg_hlabel(int x, int y, const char *s, int dir, int dim,
+void dwg_hlabel(struct gfx *gfx, int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape, struct dwg_bbox *bbox)
{
struct text txt = {
@@ -396,15 +396,15 @@ void dwg_hlabel(int x, int y, const char *s, int dir, int dim,
txt.rot = rot % 180;
- text_fig(&txt, COLOR_HLABEL, LAYER_HLABEL);
- gfx_poly(n + 1, vx, vy, COLOR_HLABEL, COLOR_NONE, LAYER_HLABEL);
+ text_fig(&txt, gfx, COLOR_HLABEL, LAYER_HLABEL);
+ gfx_poly(gfx, n + 1, vx, vy, COLOR_HLABEL, COLOR_NONE, LAYER_HLABEL);
}
/* ----- Text -------------------------------------------------------------- */
-void dwg_text(int x, int y, const char *s, int dir, int dim,
+void dwg_text(struct gfx *gfx, int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape, struct dwg_bbox *bbox)
{
struct text txt = {
@@ -434,27 +434,27 @@ void dwg_text(int x, int y, const char *s, int dir, int dim,
assert(2 + 2 == 5);
}
- text_fig(&txt, COLOR_TEXT, LAYER_TEXT);
+ text_fig(&txt, gfx, COLOR_TEXT, LAYER_TEXT);
}
/* ----- Connections ------------------------------------------------------- */
-void dwg_junction(int x, int y)
+void dwg_junction(struct gfx *gfx, int x, int y)
{
- gfx_circ(x, y, JUNCTION_R, COLOR_NONE, COLOR_WIRE, LAYER_WIRES);
+ gfx_circ(gfx, x, y, JUNCTION_R, COLOR_NONE, COLOR_WIRE, LAYER_WIRES);
}
-void dwg_noconn(int x, int y)
+void dwg_noconn(struct gfx *gfx, int x, int y)
{
int vx[2] = { x - NOCONN_LEN, x + NOCONN_LEN };
int vy[2] = { y - NOCONN_LEN, y + NOCONN_LEN };
- gfx_poly(2, vx, vy, COLOR_NOCONN, COLOR_NONE, LAYER_NOCONN);
+ gfx_poly(gfx, 2, vx, vy, COLOR_NOCONN, COLOR_NONE, LAYER_NOCONN);
swap(vy[0], vy[1]);
- gfx_poly(2, vx, vy, COLOR_NOCONN, COLOR_NONE, LAYER_NOCONN);
+ gfx_poly(gfx, 2, vx, vy, COLOR_NOCONN, COLOR_NONE, LAYER_NOCONN);
}
@@ -469,33 +469,33 @@ void dwg_noconn(int x, int y)
* treat reversed lines as still equal.
*/
-void dwg_line(int sx, int sy, int ex, int ey)
+void dwg_line(struct gfx *gfx, int sx, int sy, int ex, int ey)
{
if (sx < ex || (sx == ex && sy < ey))
- gfx_line(sx, sy, ex, ey, COLOR_SHEET_DWG, LAYER_LINES);
+ gfx_line(gfx, sx, sy, ex, ey, COLOR_SHEET_DWG, LAYER_LINES);
else
- gfx_line(ex, ey, sx, sy, COLOR_SHEET_DWG, LAYER_LINES);
+ gfx_line(gfx, ex, ey, sx, sy, COLOR_SHEET_DWG, LAYER_LINES);
}
/* ----- Wires and busses -------------------------------------------------- */
-void dwg_wire(int sx, int sy, int ex, int ey)
+void dwg_wire(struct gfx *gfx, int sx, int sy, int ex, int ey)
{
int vx[] = { sx, ex };
int vy[] = { sy, ey };
// WIDTH_WIRE
- gfx_poly(2, vx, vy, COLOR_WIRE, COLOR_NONE, LAYER_WIRES);
+ gfx_poly(gfx, 2, vx, vy, COLOR_WIRE, COLOR_NONE, LAYER_WIRES);
}
-void dwg_bus(int sx, int sy, int ex, int ey)
+void dwg_bus(struct gfx *gfx, int sx, int sy, int ex, int ey)
{
int vx[] = { sx, ex };
int vy[] = { sy, ey };
// WIDTH_BUS
- gfx_poly(2, vx, vy, COLOR_BUS, COLOR_NONE, LAYER_BUSSES);
+ gfx_poly(gfx, 2, vx, vy, COLOR_BUS, COLOR_NONE, LAYER_BUSSES);
}
diff --git a/kicad/dwg.h b/kicad/dwg.h
index 2875b48..be1ac60 100644
--- a/kicad/dwg.h
+++ b/kicad/dwg.h
@@ -14,6 +14,9 @@
#ifndef KICAD_DWG_H
#define KICAD_DWG_H
+#include "gfx/gfx.h"
+
+
enum dwg_shape {
dwg_unspec, // UnSpc
dwg_in, // Input
@@ -28,21 +31,21 @@ struct dwg_bbox {
};
-void dwg_label(int x, int y, const char *s, int dir, int dim,
+void dwg_label(struct gfx *gfx, int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape, struct dwg_bbox *bbox);
-void dwg_hlabel(int x, int y, const char *s, int dir, int dim,
+void dwg_hlabel(struct gfx *gfx, int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape, struct dwg_bbox *bbox);
-void dwg_glabel(int x, int y, const char *s, int dir, int dim,
+void dwg_glabel(struct gfx *gfx, int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape, struct dwg_bbox *bbox);
-void dwg_text(int x, int y, const char *s, int dir, int dim,
+void dwg_text(struct gfx *gfx, int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape, struct dwg_bbox *bbox);
-void dwg_junction(int x, int y);
-void dwg_noconn(int x, int y);
+void dwg_junction(struct gfx *gfx, int x, int y);
+void dwg_noconn(struct gfx *gfx, int x, int y);
-void dwg_line(int sx, int sy, int ex, int ey);
+void dwg_line(struct gfx *gfx, int sx, int sy, int ex, int ey);
-void dwg_wire(int sx, int sy, int ex, int ey);
-void dwg_bus(int sx, int sy, int ex, int ey);
+void dwg_wire(struct gfx *gfx, int sx, int sy, int ex, int ey);
+void dwg_bus(struct gfx *gfx, int sx, int sy, int ex, int ey);
#endif /* !KICAD_DWG_H */
diff --git a/kicad/lib-render.c b/kicad/lib-render.c
index 7a08ea3..3e62bba 100644
--- a/kicad/lib-render.c
+++ b/kicad/lib-render.c
@@ -60,7 +60,8 @@ static void transform_poly_md(unsigned n, int *vx, int *vy, const int m[6],
/* ----- Polygons and rectangles ------------------------------------------- */
-static void draw_poly(const struct lib_poly *poly, const int m[6])
+static void draw_poly(const struct lib_poly *poly, struct gfx *gfx,
+ const int m[6])
{
int n = poly->points;
int x[n];
@@ -72,17 +73,17 @@ static void draw_poly(const struct lib_poly *poly, const int m[6])
y[i] = my(poly->x[i], poly->y[i], m);
}
- gfx_poly(n, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_poly(gfx, n, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
switch (poly->fill) {
case 'N':
break;
case 'F':
- gfx_poly(n, x, y, COLOR_NONE, COLOR_COMP_DWG,
+ gfx_poly(gfx, n, x, y, COLOR_NONE, COLOR_COMP_DWG,
LAYER_COMP_DWG_BG);
break;
case 'f':
- gfx_poly(n, x, y, COLOR_NONE, COLOR_COMP_DWG_BG,
+ gfx_poly(gfx, n, x, y, COLOR_NONE, COLOR_COMP_DWG_BG,
LAYER_COMP_DWG_BG);
break;
default:
@@ -91,24 +92,26 @@ static void draw_poly(const struct lib_poly *poly, const int m[6])
}
-static void draw_rect(const struct lib_rect *rect, const int m[6])
+static void draw_rect(const struct lib_rect *rect, struct gfx *gfx,
+ const int m[6])
{
int sx = mx(rect->sx, rect->sy, m);
int sy = my(rect->sx, rect->sy, m);
int ex = mx(rect->ex, rect->ey, m);
int ey = my(rect->ex, rect->ey, m);
- gfx_rect(sx, sy, ex, ey, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_rect(gfx, sx, sy, ex, ey,
+ COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
switch (rect->fill) {
case 'N':
break;
case 'F':
- gfx_rect(sx, sy, ex, ey, COLOR_NONE, COLOR_COMP_DWG,
+ gfx_rect(gfx, sx, sy, ex, ey, COLOR_NONE, COLOR_COMP_DWG,
LAYER_COMP_DWG_BG);
break;
case 'f':
- gfx_rect(sx, sy, ex, ey, COLOR_NONE, COLOR_COMP_DWG_BG,
+ gfx_rect(gfx, sx, sy, ex, ey, COLOR_NONE, COLOR_COMP_DWG_BG,
LAYER_COMP_DWG_BG);
break;
default:
@@ -120,24 +123,25 @@ static void draw_rect(const struct lib_rect *rect, const int m[6])
/* ----- Circles and arcs -------------------------------------------------- */
-static void draw_circ(const struct lib_circ *circ, const int m[6])
+static void draw_circ(const struct lib_circ *circ, struct gfx *gfx,
+ const int m[6])
{
int x = mx(circ->x, circ->y, m);
int y = my(circ->x, circ->y, m);
int r = circ->r;
- gfx_circ(x, y, r, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_circ(gfx, x, y, r, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
switch (circ->fill) {
case 'N':
break;
case 'F':
- gfx_circ(x, y, r, COLOR_NONE, COLOR_COMP_DWG,
- LAYER_COMP_DWG_BG);
+ gfx_circ(gfx, x, y, r,
+ COLOR_NONE, COLOR_COMP_DWG, LAYER_COMP_DWG_BG);
break;
case 'f':
- gfx_circ(x, y, r, COLOR_NONE, COLOR_COMP_DWG_BG,
- LAYER_COMP_DWG_BG);
+ gfx_circ(gfx, x, y, r,
+ COLOR_NONE, COLOR_COMP_DWG_BG, LAYER_COMP_DWG_BG);
break;
default:
BUG("invalid fill '%c'", circ->fill);
@@ -145,7 +149,7 @@ static void draw_circ(const struct lib_circ *circ, const int m[6])
}
-static void draw_arc(const struct lib_arc *arc, const int m[6])
+static void draw_arc(const struct lib_arc *arc, struct gfx *gfx, const int m[6])
{
int a = matrix_to_angle(m);
int x = mx(arc->x, arc->y, m);
@@ -175,18 +179,18 @@ static void draw_arc(const struct lib_arc *arc, const int m[6])
case 'N':
break;
case 'F':
- gfx_arc(x, y, arc->r, sa, ea,
+ gfx_arc(gfx, x, y, arc->r, sa, ea,
COLOR_COMP_DWG, COLOR_COMP_DWG, LAYER_COMP_DWG_BG);
break;
case 'f':
- gfx_arc(x, y, arc->r, sa, ea,
+ gfx_arc(gfx, x, y, arc->r, sa, ea,
COLOR_COMP_DWG_BG, COLOR_COMP_DWG_BG, LAYER_COMP_DWG_BG);
break;
default:
assert(0);
}
- gfx_arc(x, y, arc->r, sa, ea,
+ gfx_arc(gfx, x, y, arc->r, sa, ea,
COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
}
@@ -195,7 +199,8 @@ static void draw_arc(const struct lib_arc *arc, const int m[6])
static void draw_pin_name(const struct comp *comp, const struct lib_pin *pin,
- const int m[6], int dx, int dy, int rot, enum text_align hor)
+ struct gfx *gfx, const int m[6], int dx, int dy, int rot,
+ enum text_align hor)
{
int ox, oy, sx, sy;
@@ -244,12 +249,13 @@ static void draw_pin_name(const struct comp *comp, const struct lib_pin *pin,
break;
}
- text_fig(&txt, COLOR_PIN_NAME, LAYER_PIN_NAME);
+ text_fig(&txt, gfx, COLOR_PIN_NAME, LAYER_PIN_NAME);
}
static void draw_pin_num(const struct comp *comp, const struct lib_pin *pin,
- const int m[6], int dx, int dy, int rot, enum text_align hor)
+ struct gfx *gfx, const int m[6], int dx, int dy, int rot,
+ enum text_align hor)
{
int ox, oy, sx, sy;
@@ -303,15 +309,15 @@ static void draw_pin_num(const struct comp *comp, const struct lib_pin *pin,
break;
}
- text_fig(&txt, COLOR_PIN_NUMBER, LAYER_PIN_NUMBER);
+ text_fig(&txt, gfx, COLOR_PIN_NUMBER, LAYER_PIN_NUMBER);
}
/* ----- Pin shape --------------------------------------------------------- */
-static void draw_pin_line(const struct lib_pin *pin, enum pin_shape shape,
- int dx, int dy, const int m[6])
+static void draw_pin_line(const struct lib_pin *pin, struct gfx *gfx,
+ enum pin_shape shape, int dx, int dy, const int m[6])
{
int len = pin->length;
int x[4], y[4];
@@ -326,13 +332,13 @@ static void draw_pin_line(const struct lib_pin *pin, enum pin_shape shape,
y[1] = pin->y + dy * len;
transform_poly(2, x, y, m);
- gfx_poly(2, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_poly(gfx, 2, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
if (shape & pin_inverted) {
x[0] = pin->x + dx * (len + PIN_R);
y[0] = pin->y + dy * (len + PIN_R);
transform_poly(1, x, y, m);
- gfx_circ(x[0], y[0], PIN_R,
+ gfx_circ(gfx, x[0], y[0], PIN_R,
COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
}
@@ -349,7 +355,8 @@ static void draw_pin_line(const struct lib_pin *pin, enum pin_shape shape,
x[3] = x[0];
y[3] = y[0];
transform_poly(4, x, y, m);
- gfx_poly(4, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_poly(gfx, 4, x, y,
+ COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
}
/*
@@ -365,7 +372,8 @@ static void draw_pin_line(const struct lib_pin *pin, enum pin_shape shape,
x[2] = ex - dx * 2 * PIN_R;
y[2] = ey - dy * 2 * PIN_R;
transform_poly(3, x, y, m);
- gfx_poly(3, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_poly(gfx, 3, x, y,
+ COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
}
if (shape & pin_output_low) {
@@ -374,7 +382,8 @@ static void draw_pin_line(const struct lib_pin *pin, enum pin_shape shape,
x[1] = ex - dx * 2 * PIN_R;
y[1] = ey - dy * 2 * PIN_R;
transform_poly(2, x, y, m);
- gfx_poly(2, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_poly(gfx, 2, x, y,
+ COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
}
if (shape & pin_falling_edge) {
@@ -385,7 +394,8 @@ static void draw_pin_line(const struct lib_pin *pin, enum pin_shape shape,
x[2] = ex + dy * PIN_R;
y[2] = ey + dx * PIN_R;
transform_poly(3, x, y, m);
- gfx_poly(3, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_poly(gfx, 3, x, y,
+ COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
}
if (shape & pin_non_logic) {
@@ -394,9 +404,11 @@ static void draw_pin_line(const struct lib_pin *pin, enum pin_shape shape,
x[1] = ex + PIN_R;
y[1] = ey + PIN_R;
transform_poly(2, x, y, m);
- gfx_poly(2, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_poly(gfx, 2, x, y,
+ COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
swap(x[0], x[1]);
- gfx_poly(2, x, y, COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
+ gfx_poly(gfx, 2, x, y,
+ COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
}
}
@@ -404,8 +416,8 @@ static void draw_pin_line(const struct lib_pin *pin, enum pin_shape shape,
/* ----- Pin etype --------------------------------------------------------- */
-static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
- int dx, int dy, const int m[6])
+static void draw_pin_etype(const struct lib_pin *pin, struct gfx *gfx,
+ enum pin_shape shape, int dx, int dy, const int m[6])
{
int mx, my;
int x[6], y[6];
@@ -423,7 +435,8 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
x[2] = -PIN_EXTRA_R / 2;
y[2] = -PIN_EXTRA_R;
transform_poly_md(3, x, y, m, mx, my, dx, dy);
- gfx_poly(3, x, y, COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
+ gfx_poly(gfx, 3, x, y,
+ COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
break;
case 'O':
x[0] = PIN_EXTRA_R / 2;
@@ -433,7 +446,8 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
x[2] = PIN_EXTRA_R / 2;
y[2] = -PIN_EXTRA_R;
transform_poly_md(3, x, y, m, mx, my, dx, dy);
- gfx_poly(3, x, y, COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
+ gfx_poly(gfx, 3, x, y,
+ COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
break;
case 'B':
bidir:
@@ -448,7 +462,8 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
x[4] = x[0];
y[4] = y[0];
transform_poly_md(5, x, y, m, mx, my, dx, dy);
- gfx_poly(5, x, y, COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
+ gfx_poly(gfx, 5, x, y,
+ COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
break;
case 'T':
x[0] = 0;
@@ -464,7 +479,8 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
x[5] = 0;
y[5] = -PIN_EXTRA_R;
transform_poly_md(6, x, y, m, mx, my, dx, dy);
- gfx_poly(6, x, y, COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
+ gfx_poly(gfx, 6, x, y,
+ COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
break;
case 'P':
x[0] = mx - PIN_EXTRA_R;
@@ -472,7 +488,7 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
x[1] = mx + PIN_EXTRA_R;
y[1] = my + PIN_EXTRA_R;
transform_poly(2, x, y, m);
- gfx_rect(x[0], y[0], x[1], y[1],
+ gfx_rect(gfx, x[0], y[0], x[1], y[1],
COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
break;
case 'U':
@@ -488,7 +504,7 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
x[2] = off;
y[2] = -PIN_EXTRA_R;
transform_poly_md(3, x, y, m, mx, my, dx, dy);
- gfx_poly(3, x, y,
+ gfx_poly(gfx, 3, x, y,
COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
}
break;
@@ -504,7 +520,7 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
y[2] = -PIN_EXTRA_R;
transform_poly_md(3, x, y, m, mx, my,
dx, dy);
- gfx_poly(3, x, y,
+ gfx_poly(gfx, 3, x, y,
COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
}
break;
@@ -514,7 +530,8 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
x[1] = PIN_EXTRA_R;
y[1] = PIN_EXTRA_R;
transform_poly_md(2, x, y, m, mx, my, dx, dy);
- gfx_poly(2, x, y, COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
+ gfx_poly(gfx, 2, x, y,
+ COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
goto bidir;
case 'E':
x[0] = -PIN_EXTRA_R;
@@ -522,7 +539,8 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
x[1] = PIN_EXTRA_R;
y[1] = -PIN_EXTRA_R;
transform_poly_md(2, x, y, m, mx, my, dx, dy);
- gfx_poly(2, x, y, COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
+ gfx_poly(gfx, 2, x, y,
+ COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
goto bidir;
case 'N':
x[0] = -PIN_EXTRA_R;
@@ -530,9 +548,11 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
x[1] = PIN_EXTRA_R;
y[1] = PIN_EXTRA_R;
transform_poly_md(2, x, y, m, mx, my, dx, dy);
- gfx_poly(2, x, y, COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
+ gfx_poly(gfx, 2, x, y,
+ COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
swap(x[0], x[1]);
- gfx_poly(2, x, y, COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
+ gfx_poly(gfx, 2, x, y,
+ COLOR_PIN_EXTRA, COLOR_NONE, LAYER_PIN_EXTRA);
break;
default:
BUG("unrecognized etype '%c'", pin->etype);
@@ -544,7 +564,7 @@ static void draw_pin_etype(const struct lib_pin *pin, enum pin_shape shape,
static void draw_pin(const struct comp *comp, const struct lib_pin *pin,
- const int m[6])
+ struct gfx *gfx, const int m[6])
{
int dx = 0, dy = 0;
int rot;
@@ -579,13 +599,13 @@ static void draw_pin(const struct comp *comp, const struct lib_pin *pin,
BUG("invalid orientation '%c'", pin->orient);
}
- draw_pin_line(pin, shape, dx, dy, m);
+ draw_pin_line(pin, gfx, shape, dx, dy, m);
if (comp->show_pin_name)
- draw_pin_name(comp, pin, m, dx, dy, rot, hor);
+ draw_pin_name(comp, pin, gfx, m, dx, dy, rot, hor);
if (comp->show_pin_num)
- draw_pin_num(comp, pin, m, dx, dy, rot, hor);
+ draw_pin_num(comp, pin, gfx, m, dx, dy, rot, hor);
}
@@ -593,7 +613,7 @@ static void draw_pin(const struct comp *comp, const struct lib_pin *pin,
static void draw_pin_extra(const struct comp *comp, const struct lib_pin *pin,
- const int m[6])
+ struct gfx *gfx, const int m[6])
{
int dx = 0, dy = 0;
@@ -617,14 +637,15 @@ static void draw_pin_extra(const struct comp *comp, const struct lib_pin *pin,
BUG("invalid orientation '%c'", pin->orient);
}
- draw_pin_etype(pin, pin->etype, dx, dy, m);
+ draw_pin_etype(pin, gfx, pin->etype, dx, dy, m);
}
/* ----- Text -------------------------------------------------------------- */
-static void draw_text(const struct lib_text *text, const int m[6])
+static void draw_text(const struct lib_text *text, struct gfx *gfx,
+ const int m[6])
{
struct text txt = {
.s = text->s,
@@ -663,7 +684,7 @@ static void draw_text(const struct lib_text *text, const int m[6])
BUG("unknown rotation %d", txt.rot);
}
- text_fig(&txt, COLOR_COMP_DWG, WIDTH_COMP_DWG);
+ text_fig(&txt, gfx, COLOR_COMP_DWG, WIDTH_COMP_DWG);
}
@@ -697,26 +718,26 @@ bool lib_field_visible(const struct comp *comp, int n)
static void draw(const struct comp *comp, const struct lib_obj *obj,
- const int m[6])
+ struct gfx *gfx, const int m[6])
{
switch (obj->type) {
case lib_obj_poly:
- draw_poly(&obj->u.poly, m);
+ draw_poly(&obj->u.poly, gfx, m);
break;
case lib_obj_rect:
- draw_rect(&obj->u.rect, m);
+ draw_rect(&obj->u.rect, gfx, m);
break;
case lib_obj_circ:
- draw_circ(&obj->u.circ, m);
+ draw_circ(&obj->u.circ, gfx, m);
break;
case lib_obj_arc:
- draw_arc(&obj->u.arc, m);
+ draw_arc(&obj->u.arc, gfx, m);
break;
case lib_obj_text:
- draw_text(&obj->u.text, m);
+ draw_text(&obj->u.text, gfx, m);
break;
case lib_obj_pin:
- draw_pin(comp, &obj->u.pin, m);
+ draw_pin(comp, &obj->u.pin, gfx, m);
break;
default:
BUG("invalid object type %d", obj->type);
@@ -725,7 +746,7 @@ static void draw(const struct comp *comp, const struct lib_obj *obj,
static void draw_extra(const struct comp *comp, const struct lib_obj *obj,
- const int m[6])
+ struct gfx *gfx, const int m[6])
{
switch (obj->type) {
case lib_obj_poly:
@@ -735,7 +756,7 @@ static void draw_extra(const struct comp *comp, const struct lib_obj *obj,
case lib_obj_text:
break;
case lib_obj_pin:
- draw_pin_extra(comp, &obj->u.pin, m);
+ draw_pin_extra(comp, &obj->u.pin, gfx, m);
break;
default:
BUG("invalid object type %d", obj->type);
@@ -743,27 +764,27 @@ static void draw_extra(const struct comp *comp, const struct lib_obj *obj,
}
-static void missing_component(const int m[4])
+static void missing_component(struct gfx *gfx, const int m[4])
{
int sx = mx(0, 0, m);
int sy = my(0, 0, m);
int ex = mx(MISSING_WIDTH, MISSING_HEIGHT, m);
int ey = my(MISSING_WIDTH, MISSING_HEIGHT, m);
- gfx_rect(sx, sy, ex, ey, COLOR_MISSING_FG, COLOR_MISSING_BG,
+ gfx_rect(gfx, sx, sy, ex, ey, COLOR_MISSING_FG, COLOR_MISSING_BG,
LAYER_COMP_DWG);
}
-static void render_lib(const struct comp *comp, unsigned unit, unsigned convert,
- const int m[4],
+static void render_lib(const struct comp *comp, struct gfx *gfx,
+ unsigned unit, unsigned convert, const int m[4],
void (*draw_fn)(const struct comp *comp, const struct lib_obj *obj,
- const int m[4]))
+ struct gfx *gfx, const int m[4]))
{
const struct lib_obj *obj;
if (!comp) {
- missing_component(m);
+ missing_component(gfx, m);
return;
}
if (!unit)
@@ -773,20 +794,20 @@ static void render_lib(const struct comp *comp, unsigned unit, unsigned convert,
continue;
if (obj->convert && obj->convert != convert)
continue;
- draw_fn(comp, obj, m);
+ draw_fn(comp, obj, gfx, m);
}
}
-void lib_render(const struct comp *comp, unsigned unit, unsigned convert,
- const int m[4])
+void lib_render(const struct comp *comp, struct gfx *gfx,
+ unsigned unit, unsigned convert, const int m[4])
{
- render_lib(comp, unit, convert, m, draw);
+ render_lib(comp, gfx, unit, convert, m, draw);
}
-void lib_render_extra(const struct comp *comp, unsigned unit, unsigned convert,
- const int m[4])
+void lib_render_extra(const struct comp *comp, struct gfx *gfx,
+ unsigned unit, unsigned convert, const int m[4])
{
- render_lib(comp, unit, convert, m, draw_extra);
+ render_lib(comp, gfx, unit, convert, m, draw_extra);
}
diff --git a/kicad/lib.h b/kicad/lib.h
index 9056748..f146091 100644
--- a/kicad/lib.h
+++ b/kicad/lib.h
@@ -18,6 +18,7 @@
#include "file/file.h"
#include "gfx/text.h"
+#include "gfx/gfx.h"
enum pin_shape {
@@ -134,10 +135,10 @@ extern struct comp *comps;
const struct comp *lib_find(const struct lib *lib, const char *name);
bool lib_field_visible(const struct comp *comp, int n);
-void lib_render(const struct comp *comp, unsigned unit, unsigned convert,
- const int m[6]);
-void lib_render_extra(const struct comp *comp, unsigned unit, unsigned convert,
- const int m[4]);
+void lib_render(const struct comp *comp, struct gfx *gfx,
+ unsigned unit, unsigned convert, const int m[6]);
+void lib_render_extra(const struct comp *comp, struct gfx *gfx,
+ unsigned unit, unsigned convert, const int m[4]);
bool lib_parse_file(struct lib *lib, struct file *file);
bool lib_parse(struct lib *lib, const char *name, const struct file *related);
diff --git a/kicad/pl-render.c b/kicad/pl-render.c
index 386f719..961a51d 100644
--- a/kicad/pl-render.c
+++ b/kicad/pl-render.c
@@ -142,7 +142,7 @@ static char *increment(char *s, int inc, const char *range)
static void render_text(const struct pl_ctx *pl, const struct pl_obj *obj,
- int x, int y, int inc,
+ struct gfx *gfx, int x, int y, int inc,
const struct sheet *sheets, const struct sheet *sheet)
{
char *s = expand(pl, obj->s, sheets, sheet);
@@ -173,13 +173,13 @@ static void render_text(const struct pl_ctx *pl, const struct pl_obj *obj,
}
}
txt.s = s;
- text_fig(&txt, COLOR_COMP_DWG, LAYER_COMP_DWG);
+ text_fig(&txt, gfx, COLOR_COMP_DWG, LAYER_COMP_DWG);
free(s);
}
static void render_obj(const struct pl_ctx *pl, const struct pl_obj *obj,
- unsigned inc,
+ struct gfx *gfx, unsigned inc,
const struct sheet *sheets, const struct sheet *sheet)
{
int w = sheet->w;
@@ -207,19 +207,19 @@ static void render_obj(const struct pl_ctx *pl, const struct pl_obj *obj,
switch (obj->type) {
case pl_obj_rect:
- gfx_rect(x, y, ex, ey,
+ gfx_rect(gfx, x, y, ex, ey,
COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
break;
case pl_obj_line: {
int vx[] = { x, ex };
int vy[] = { y, ey };
- gfx_poly(2, vx, vy,
+ gfx_poly(gfx, 2, vx, vy,
COLOR_COMP_DWG, COLOR_NONE, LAYER_COMP_DWG);
}
break;
case pl_obj_text:
- render_text(pl, obj, x, y, inc, sheets, sheet);
+ render_text(pl, obj, gfx, x, y, inc, sheets, sheet);
break;
default:
break;
@@ -227,7 +227,7 @@ static void render_obj(const struct pl_ctx *pl, const struct pl_obj *obj,
}
-void pl_render(struct pl_ctx *pl, const struct sheet *sheets,
+void pl_render(struct pl_ctx *pl, struct gfx *gfx, const struct sheet *sheets,
const struct sheet *sheet)
{
const struct pl_obj *obj;
@@ -235,5 +235,5 @@ void pl_render(struct pl_ctx *pl, const struct sheet *sheets,
for (obj = pl->objs; obj; obj = obj->next)
for (i = 0; i != obj->repeat; i++)
- render_obj(pl, obj, i, sheets, sheet);
+ render_obj(pl, obj, gfx, i, sheets, sheet);
}
diff --git a/kicad/pl.h b/kicad/pl.h
index 7aee176..3f19347 100644
--- a/kicad/pl.h
+++ b/kicad/pl.h
@@ -14,6 +14,7 @@
#ifndef KICAD_PL_H
#define KICAD_PL_H
+#include "gfx/gfx.h"
#include "file/file.h"
#include "kicad/sch.h"
@@ -21,8 +22,8 @@
struct pl_ctx;
-void pl_render(struct pl_ctx *pl, const struct sheet *sheets,
- const struct sheet *sheet);
+void pl_render(struct pl_ctx *pl, struct gfx *gfx,
+ const struct sheet *sheets, const struct sheet *sheet);
struct pl_ctx *pl_parse(struct file *file);
void pl_free(struct pl_ctx *pl);
diff --git a/kicad/sch-render.c b/kicad/sch-render.c
index 265181e..49b5e64 100644
--- a/kicad/sch-render.c
+++ b/kicad/sch-render.c
@@ -27,7 +27,8 @@
/* ----- Rendering --------------------------------------------------------- */
-static void dump_field(const struct comp_field *field, const int m[6])
+static void dump_field(const struct comp_field *field, struct gfx *gfx,
+ const int m[6])
{
struct text txt = field->txt;
int dx, dy;
@@ -61,12 +62,12 @@ static void dump_field(const struct comp_field *field, const int m[6])
txt.vert = text_flip(txt.vert);
}
- text_fig(&txt, COLOR_FIELD, LAYER_FIELD);
+ text_fig(&txt, gfx, COLOR_FIELD, LAYER_FIELD);
}
static void do_hsheet_text(const struct sch_obj *obj,
- const struct sch_sheet *sheet)
+ const struct sch_sheet *sheet, struct gfx *gfx)
{
char *s;
@@ -105,8 +106,8 @@ static void do_hsheet_text(const struct sch_obj *obj,
file_txt.y += sheet->h + HSHEET_FIELD_OFFSET;
}
- text_fig(&sheet_txt, COLOR_HSHEET_SHEET, LAYER_HSHEET_FIELD);
- text_fig(&file_txt, COLOR_HSHEET_FILE, LAYER_HSHEET_FIELD);
+ text_fig(&sheet_txt, gfx, COLOR_HSHEET_SHEET, LAYER_HSHEET_FIELD);
+ text_fig(&file_txt, gfx, COLOR_HSHEET_FILE, LAYER_HSHEET_FIELD);
// free((void *) ctx->sheet);
// free((void *) ctx->file);
@@ -114,24 +115,24 @@ static void do_hsheet_text(const struct sch_obj *obj,
static void render_sheet(const struct sch_obj *obj,
- const struct sch_sheet *sheet)
+ const struct sch_sheet *sheet, struct gfx *gfx)
{
const struct sheet_field *field;
- gfx_rect(obj->x, obj->y, obj->x + sheet->w, obj->y + sheet->h,
+ gfx_rect(gfx, obj->x, obj->y, obj->x + sheet->w, obj->y + sheet->h,
COLOR_HSHEET_BOX, sheet->error ? COLOR_MISSING_BG : COLOR_NONE,
LAYER_HSHEET_BOX);
- do_hsheet_text(obj, sheet);
+ do_hsheet_text(obj, sheet, gfx);
for (field = sheet->fields; field; field = field->next)
- dwg_hlabel(field->x, field->y, field->s,
+ dwg_hlabel(gfx, field->x, field->y, field->s,
field->side, field->dim,
field->shape, NULL);
// free(field->s)
}
-void sch_render(const struct sheet *sheet)
+void sch_render(const struct sheet *sheet, struct gfx *gfx)
{
struct sch_obj *obj;
@@ -141,21 +142,23 @@ void sch_render(const struct sheet *sheet)
{
const struct sch_wire *wire = &obj->u.wire;
- wire->fn(obj->x, obj->y, wire->ex, wire->ey);
+ wire->fn(gfx, obj->x, obj->y,
+ wire->ex, wire->ey);
}
break;
case sch_obj_junction:
- dwg_junction(obj->x, obj->y);
+ dwg_junction(gfx, obj->x, obj->y);
break;
case sch_obj_noconn:
- dwg_noconn(obj->x, obj->y);
+ dwg_noconn(gfx, obj->x, obj->y);
break;
case sch_obj_glabel:
case sch_obj_text:
{
struct sch_text *text = &obj->u.text;
- text->fn(obj->x, obj->y, text->s, text->dir,
+ text->fn(gfx, obj->x, obj->y,
+ text->s, text->dir,
text->dim, text->shape, &text->bbox);
}
break;
@@ -164,15 +167,15 @@ void sch_render(const struct sheet *sheet)
const struct sch_comp *comp = &obj->u.comp;
const struct comp_field *field;
- lib_render(comp->comp, comp->unit,
+ lib_render(comp->comp, gfx, comp->unit,
comp->convert, comp->m);
for (field = comp->fields; field;
field = field->next)
- dump_field(field, comp->m);
+ dump_field(field, gfx, comp->m);
}
break;
case sch_obj_sheet:
- render_sheet(obj, &obj->u.sheet);
+ render_sheet(obj, &obj->u.sheet, gfx);
break;
default:
BUG("invalid object type \"%d\"", obj->type);
@@ -180,7 +183,7 @@ void sch_render(const struct sheet *sheet)
}
-void sch_render_extra(const struct sheet *sheet)
+void sch_render_extra(const struct sheet *sheet, struct gfx *gfx)
{
struct sch_obj *obj;
@@ -197,7 +200,7 @@ void sch_render_extra(const struct sheet *sheet)
{
const struct sch_comp *comp = &obj->u.comp;
- lib_render_extra(comp->comp, comp->unit,
+ lib_render_extra(comp->comp, gfx, comp->unit,
comp->convert, comp->m);
}
break;
diff --git a/kicad/sch.h b/kicad/sch.h
index 06d9684..48c2ee5 100644
--- a/kicad/sch.h
+++ b/kicad/sch.h
@@ -18,6 +18,7 @@
#include "kicad/dwg.h"
#include "gfx/text.h"
+#include "gfx/gfx.h"
#include "file/file.h"
#include "kicad/lib.h"
@@ -49,11 +50,13 @@ struct sch_obj {
union {
struct sch_wire {
- void (*fn)(int sx, int sy, int ex, int ey);
+ void (*fn)(struct gfx *gfx,
+ int sx, int sy, int ex, int ey);
int ex, ey;
} wire;
struct sch_text {
- void (*fn)(int x, int y, const char *s,
+ void (*fn)(struct gfx *gfx,
+ int x, int y, const char *s,
int dir, int dim, enum dwg_shape shape,
struct dwg_bbox *bbox);
const char *s;
@@ -131,8 +134,8 @@ struct sch_ctx {
void decode_alignment(struct text *txt, char hor, char vert);
-void sch_render(const struct sheet *sheet);
-void sch_render_extra(const struct sheet *sheet);
+void sch_render(const struct sheet *sheet, struct gfx *gfx);
+void sch_render_extra(const struct sheet *sheet, struct gfx *gfx);
bool sch_parse(struct sch_ctx *ctx, struct file *file, const struct lib *lib,
const struct sch_ctx *prev);
void sch_init(struct sch_ctx *ctx, bool recurse);
diff --git a/main.c b/main.c
index e0551d7..10f6e72 100644
--- a/main.c
+++ b/main.c
@@ -139,6 +139,7 @@ int main(int argc, char **argv)
int gfx_argc;
char **gfx_argv;
const struct gfx_ops **ops = ops_list;
+ struct gfx *gfx;
if (argc > 1 && !strcmp(argv[1], "gdb")) {
char **args;
@@ -289,30 +290,30 @@ found:
return 1;
file_close(&sch_file);
- gfx_init(*ops, gfx_argc, gfx_argv);
+ gfx = gfx_init(*ops, gfx_argc, gfx_argv);
if (recurse) {
const struct sheet *sheet;
- if (!gfx_multi_sheet())
+ if (!gfx_multi_sheet(gfx))
fatal("graphics backend only supports single sheet\n");
for (sheet = sch_ctx.sheets; sheet; sheet = sheet->next) {
- gfx_sheet_name(sheet->title);
- sch_render(sheet);
+ gfx_sheet_name(gfx, sheet->title);
+ sch_render(sheet, gfx);
if (extra)
- sch_render_extra(sheet);
+ sch_render_extra(sheet, gfx);
if (pl)
- pl_render(pl, sch_ctx.sheets, sheet);
+ pl_render(pl, gfx, sch_ctx.sheets, sheet);
if (sheet->next)
- gfx_new_sheet();
+ gfx_new_sheet(gfx);
}
} else {
- sch_render(sch_ctx.sheets);
+ sch_render(sch_ctx.sheets, gfx);
if (extra)
- sch_render_extra(sch_ctx.sheets);
+ sch_render_extra(sch_ctx.sheets, gfx);
if (pl)
- pl_render(pl, sch_ctx.sheets, sch_ctx.sheets);
+ pl_render(pl, gfx, sch_ctx.sheets, sch_ctx.sheets);
}
- gfx_end();
+ gfx_end(gfx);
sch_free(&sch_ctx);
lib_free(&lib);