aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2015-10-12 22:53:02 +0200
committerThomas White <taw@bitwiz.org.uk>2015-10-12 22:53:02 +0200
commit4e204b3e02f78ca60d32d0c704abcb5499384157 (patch)
treec726ddb3c6b8b4b0ad68ffb1719356bebeb0e6c8
parenta8112c90cf0fdf44ceee5b54fed77468f5c15757 (diff)
Redraw on edit
-rw-r--r--src/render.c30
-rw-r--r--src/render.h3
-rw-r--r--src/sc_editor.c36
3 files changed, 56 insertions, 13 deletions
diff --git a/src/render.c b/src/render.c
index 45c825e..651a262 100644
--- a/src/render.c
+++ b/src/render.c
@@ -1,7 +1,7 @@
/*
* render.c
*
- * Copyright © 2013-2014 Thomas White <taw@bitwiz.org.uk>
+ * Copyright © 2013-2015 Thomas White <taw@bitwiz.org.uk>
*
* This file is part of Colloquium.
*
@@ -381,21 +381,17 @@ static int draw_frame(cairo_t *cr, struct frame *fr, ImageStore *is,
}
-static int recursive_wrap_and_draw(struct frame *fr, cairo_t *cr,
- ImageStore *is, enum is_size isz)
+int recursive_draw(struct frame *fr, cairo_t *cr,
+ ImageStore *is, enum is_size isz)
{
int i;
- /* Wrap boxes -> wrap lines */
- wrap_contents(fr);
-
- /* Actually draw the lines */
draw_frame(cr, fr, is, isz);
for ( i=0; i<fr->num_children; i++ ) {
cairo_save(cr);
cairo_translate(cr, fr->children[i]->x, fr->children[i]->y);
- recursive_wrap_and_draw(fr->children[i], cr, is, isz);
+ recursive_draw(fr->children[i], cr, is, isz);
cairo_restore(cr);
}
@@ -403,6 +399,21 @@ static int recursive_wrap_and_draw(struct frame *fr, cairo_t *cr,
}
+static int recursive_wrap(struct frame *fr, ImageStore *is, enum is_size isz)
+{
+ int i;
+
+ /* Wrap boxes -> wrap lines */
+ wrap_contents(fr);
+
+ for ( i=0; i<fr->num_children; i++ ) {
+ recursive_wrap(fr->children[i], is, isz);
+ }
+
+ return 0;
+}
+
+
static struct frame *render_sc_to_surface(SCBlock *scblocks, cairo_surface_t *surf,
cairo_t *cr, double log_w, double log_h,
SCBlock **stylesheets, SCCallbackList *cbl,
@@ -460,7 +471,8 @@ static struct frame *render_sc_to_surface(SCBlock *scblocks, cairo_surface_t *su
}
}
sc_interp_add_blocks(scin, scblocks);
- recursive_wrap_and_draw(top, cr, is, isz);
+ recursive_wrap(top, is, isz);
+ recursive_draw(top, cr, is, isz);
sc_interp_destroy(scin);
cairo_font_options_destroy(fopts);
diff --git a/src/render.h b/src/render.h
index 3938ca1..caab9ab 100644
--- a/src/render.h
+++ b/src/render.h
@@ -40,4 +40,7 @@ extern cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h,
extern int export_pdf(struct presentation *p, const char *filename);
+extern int recursive_draw(struct frame *fr, cairo_t *cr,
+ ImageStore *is, enum is_size isz);
+
#endif /* RENDER_H */
diff --git a/src/sc_editor.c b/src/sc_editor.c
index b9a0032..c8ef09a 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -43,6 +43,7 @@
#include "sc_interp.h"
#include "sc_editor.h"
#include "slideshow.h"
+#include "shape.h"
G_DEFINE_TYPE(SCEditor, sc_editor, GTK_TYPE_DRAWING_AREA);
@@ -559,6 +560,31 @@ void insert_scblock(SCBlock *scblock, SCEditor *e)
}
+/* The StoryCode for this box on this line in this frame has changed.
+ * Update the boxes from the StoryCode */
+static void update_local(SCEditor *e, struct frame *fr, int line, int bn)
+{
+ struct wrap_box *box = &fr->lines[line].boxes[bn];
+ cairo_t *cr;
+
+ /* Shape the box again */
+ shape_box(box);
+
+ /* Wrap the paragraph again */
+ wrap_contents(fr); /* FIXME: Only the current paragraph */
+
+ /* Render the lines again */
+ if ( e->surface != NULL ) {
+ cairo_surface_destroy(e->surface);
+ }
+ e->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, e->w, e->h);
+ cr = cairo_create(e->surface);
+ cairo_scale(cr, e->w/e->log_w, e->h/e->log_h);
+ recursive_draw(e->top, cr, e->is, ISZ_EDITOR);
+ cairo_destroy(cr);
+}
+
+
static void insert_text(char *t, SCEditor *e)
{
int sln, sbx, sps;
@@ -588,11 +614,13 @@ static void insert_text(char *t, SCEditor *e)
fr->empty = 0;
- full_rerender(e); /* FIXME: No need for full */
+ update_local(e, fr, sln, sbx);
- //fixup_cursor(e);
- //advance_cursor(e);
- //sc_editor_redraw(e);
+ /* ... by doing this properly */
+ fixup_cursor(e);
+ advance_cursor(e);
+
+ sc_editor_redraw(e);
}