diff options
author | Thomas White <taw@bitwiz.org.uk> | 2014-12-27 21:57:29 +0000 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2014-12-27 21:57:29 +0000 |
commit | a68d64edca4f67df49b9499272319cad93d38bbe (patch) | |
tree | e1f5084d006257713090bb7a2dc1f91976b91e7c | |
parent | fb69111748d9d4eba92024799421ee2573418d15 (diff) |
Draw from callbacks
-rw-r--r-- | src/narrative_window.c | 9 | ||||
-rw-r--r-- | src/render.c | 33 | ||||
-rw-r--r-- | src/sc_interp.c | 6 | ||||
-rw-r--r-- | src/shape.h | 3 | ||||
-rw-r--r-- | src/wrap.h | 6 |
5 files changed, 52 insertions, 5 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c index 50fc3e9..7a66f14 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -199,11 +199,14 @@ static cairo_surface_t *render_thumbnail(SCInterpreter *scin, SCBlock *bl, { struct presentation *p = vp; cairo_surface_t *surf; - - printf("thumbnail callback\n"); - show_sc_block(sc_interp_get_macro_real_block(scin), ""); + cairo_t *cr; surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 256, 256); + cr = cairo_create(surf); + cairo_set_source_rgb(cr, 0.0, 0.5, 0.0); + cairo_paint(cr); + cairo_destroy(cr); + return surf; } diff --git a/src/render.c b/src/render.c index e02c9ec..6a88116 100644 --- a/src/render.c +++ b/src/render.c @@ -59,6 +59,35 @@ static void render_glyph_box(cairo_t *cr, struct wrap_box *box) } +static void render_surface_box(cairo_t *cr, struct wrap_box *box) +{ + double ascd; + double x, y; + + cairo_save(cr); + + ascd = pango_units_to_double(box->ascent); + + x = 0.0; + y = -ascd; + cairo_user_to_device(cr, &x, &y); + + cairo_new_path(cr); + cairo_rectangle(cr, 0.0, -ascd, pango_units_to_double(box->width), + pango_units_to_double(box->height)); + + if ( box->surf == NULL ) { + cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 1.0); + fprintf(stderr, "Null surface box"); + } else { + cairo_identity_matrix(cr); + cairo_set_source_surface(cr, box->surf, x, y); + } + + cairo_fill(cr); + cairo_restore(cr); +} + static void render_image_box(cairo_t *cr, struct wrap_box *box, ImageStore *is, enum is_size isz) @@ -157,6 +186,10 @@ static void render_boxes(struct wrap_line *line, cairo_t *cr, ImageStore *is, render_image_box(cr, box, is, isz); break; + case WRAP_BOX_SURFACE: + render_surface_box(cr, box); + break; + case WRAP_BOX_NOTHING : break; diff --git a/src/sc_interp.c b/src/sc_interp.c index f628754..7d90b4f 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -184,8 +184,12 @@ static void do_callback(SCInterpreter *scin, SCBlock *bl, const char *name) } for ( i=0; i<cbl->n_callbacks; i++ ) { + cairo_surface_t *surf; if ( strcmp(cbl->names[i], name) != 0 ) continue; - cbl->funcs[i](scin, bl, cbl->vps[i]); + surf = cbl->funcs[i](scin, bl, cbl->vps[i]); + if ( surf == NULL ) return; + add_surface_box(sc_interp_get_frame(scin)->boxes, surf, + 256, 256); // FIXME: Box size return; } diff --git a/src/shape.h b/src/shape.h index 43356e0..e2a3e67 100644 --- a/src/shape.h +++ b/src/shape.h @@ -38,6 +38,9 @@ extern int split_words(struct wrap_line *boxes, PangoContext *pc, extern void add_image_box(struct wrap_line *line, const char *filename, int w, int h, int editable); +extern void add_surface_box(struct wrap_line *line, cairo_surface_t *surf, + double w, double h); + extern void reshape_box(struct wrap_box *box); #endif /* SHAPE_H */ @@ -38,7 +38,8 @@ enum wrap_box_type WRAP_BOX_NOTHING, WRAP_BOX_SENTINEL, WRAP_BOX_PANGO, - WRAP_BOX_IMAGE + WRAP_BOX_IMAGE, + WRAP_BOX_SURFACE }; @@ -81,6 +82,9 @@ struct wrap_box /* For type == WRAP_BOX_IMAGE */ char *filename; + + /* For type == WRAP_BOX_SURFACE */ + cairo_surface_t *surf; }; |