summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-30 00:16:07 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-30 00:16:07 (GMT)
commitda054390b0b924be7e42da258524d86358491c55 (patch)
tree947f5701258a457b0a573f2a09b324cc82fe5f44 /gfx
parentdcf32638d8d05c7cd45ed41128c41e73ec6aa5b4 (diff)
downloadeeshow-da054390b0b924be7e42da258524d86358491c55.zip
eeshow-da054390b0b924be7e42da258524d86358491c55.tar.gz
eeshow-da054390b0b924be7e42da258524d86358491c55.tar.bz2
gfx/: add "extra" flags to gfx API, and preserve them in record.c (WIP)
This is in preparation of generalizing the "extra" system.
Diffstat (limited to 'gfx')
-rw-r--r--gfx/cro.c5
-rw-r--r--gfx/gfx.c15
-rw-r--r--gfx/gfx.h9
-rw-r--r--gfx/record.c11
-rw-r--r--gfx/record.h3
5 files changed, 42 insertions, 1 deletions
diff --git a/gfx/cro.c b/gfx/cro.c
index 637d3fb..fe2bd69 100644
--- a/gfx/cro.c
+++ b/gfx/cro.c
@@ -1160,6 +1160,7 @@ const struct gfx_ops cro_png_ops = {
.circ = record_circ,
.arc = record_arc,
.text = record_text,
+ .set_extra = record_set_extra,
.text_width = cr_text_width,
.init = cr_png_init,
.args = cr_args,
@@ -1178,6 +1179,7 @@ const struct gfx_ops cro_pdf_ops = {
.circ = record_circ,
.arc = record_arc,
.text = record_text,
+ .set_extra = record_set_extra,
.text_width = cr_text_width,
.init = cr_pdf_init,
.args = cr_pdf_args,
@@ -1198,6 +1200,7 @@ const struct gfx_ops cro_ps_ops = {
.circ = record_circ,
.arc = record_arc,
.text = record_text,
+ .set_extra = record_set_extra,
.text_width = cr_text_width,
.init = cr_ps_init,
.args = cr_ps_args,
@@ -1217,6 +1220,7 @@ const struct gfx_ops cro_eps_ops = {
.circ = record_circ,
.arc = record_arc,
.text = record_text,
+ .set_extra = record_set_extra,
.text_width = cr_text_width,
.init = cr_ps_init,
.args = cr_ps_args,
@@ -1235,6 +1239,7 @@ const struct gfx_ops cro_svg_ops = {
.circ = record_circ,
.arc = record_arc,
.text = record_text,
+ .set_extra = record_set_extra,
.text_width = cr_text_width,
.init = cr_svg_init,
.args = cr_ps_args,
diff --git a/gfx/gfx.c b/gfx/gfx.c
index e49160c..bc1a318 100644
--- a/gfx/gfx.c
+++ b/gfx/gfx.c
@@ -24,10 +24,11 @@
struct gfx {
const struct gfx_ops *ops;
void *user;
+ enum gfx_extra extra;
};
-/* ----- Wrappers for graphis primitives ----------------------------------- */
+/* ----- Wrappers for graphics primitives ---------------------------------- */
void gfx_line(struct gfx *gfx,
@@ -107,6 +108,17 @@ unsigned gfx_text_width(struct gfx *gfx, const char *s, unsigned size,
}
+enum gfx_extra gfx_set_extra(struct gfx *gfx, enum gfx_extra extra)
+{
+ enum gfx_extra old = gfx->extra;
+
+ if (gfx->ops->set_extra)
+ gfx->ops->set_extra(gfx->user, extra);
+ gfx->extra = extra;
+ return old;
+}
+
+
/* ----- Initialization ---------------------------------------------------- */
@@ -117,6 +129,7 @@ struct gfx *gfx_init(const struct gfx_ops *ops)
new = alloc_type(struct gfx);
new->user = ops->init();
new->ops = ops;
+ new->extra = 0;
return new;
}
diff --git a/gfx/gfx.h b/gfx/gfx.h
index 2930f5f..5aa1e82 100644
--- a/gfx/gfx.h
+++ b/gfx/gfx.h
@@ -19,6 +19,11 @@
#include "gfx/text.h"
+enum gfx_extra {
+ gfx_pin_type = 1 << 1,
+ gfx_footprint = 1 << 2,
+};
+
struct gfx;
struct gfx_ops {
@@ -45,6 +50,8 @@ struct gfx_ops {
unsigned (*text_width)(void *ctx, const char *s, unsigned size,
enum text_style style);
+ void (*set_extra)(void *ctx, enum gfx_extra extra);
+
void *(*init)(void);
bool (*args)(void *ctx, int argc, char *const *argv, const char *opts);
void (*sheet_name)(void *ctx, const char *name);
@@ -74,6 +81,8 @@ void gfx_tag(struct gfx *gfx, const char *s,
unsigned gfx_text_width(struct gfx *gfx, const char *s, unsigned size,
enum text_style style);
+enum gfx_extra gfx_set_extra(struct gfx *gfx, enum gfx_extra extra);
+
/* inititalization and termination */
struct gfx *gfx_init(const struct gfx_ops *ops);
diff --git a/gfx/record.c b/gfx/record.c
index 7bf09c1..1cad6ff 100644
--- a/gfx/record.c
+++ b/gfx/record.c
@@ -33,6 +33,8 @@ struct record_obj {
ro_text,
} type;
+ enum gfx_extra extra;
+
int x, y;
int color, fill_color;
union {
@@ -114,6 +116,7 @@ static struct record_obj *new_obj(struct record *rec, enum ro_type type,
this_layer:
new_obj = alloc_type(struct record_obj);
new_obj->type = type;
+ new_obj->extra = rec->extra;
new_obj->color = color;
new_obj->fill_color = fill_color;
new_obj->next = NULL;
@@ -253,6 +256,14 @@ void record_text(void *ctx, int x, int y, const char *s, unsigned size,
}
+void record_set_extra(void *ctx, enum gfx_extra extra)
+{
+ struct record *rec = ctx;
+
+ rec->extra = extra;
+}
+
+
/* ----- Initialization and cleanup ---------------------------------------- */
diff --git a/gfx/record.h b/gfx/record.h
index b492ed7..1fefc68 100644
--- a/gfx/record.h
+++ b/gfx/record.h
@@ -30,6 +30,7 @@ struct record_layer {
struct record {
const struct gfx_ops *ops;
void *user;
+ enum gfx_extra extra;
int xmin, xmax;
int ymin, ymax;
struct record_layer *layers;
@@ -51,6 +52,8 @@ void record_text(void *ctx, int x, int y, const char *s, unsigned size,
enum text_align align, int rot, enum text_style style,
unsigned color, unsigned layer);
+void record_set_extra(void *ctx, enum gfx_extra extra);
+
void record_init(struct record *rec, const struct gfx_ops *ops, void *user);
void record_wipe(struct record *rec);
void record_replay(const struct record *rec);