aboutsummaryrefslogtreecommitdiff
path: root/libstorycode
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2019-12-06 22:30:03 +0100
committerThomas White <taw@bitwiz.me.uk>2019-12-06 22:30:03 +0100
commitbbc6b6deaaa4a467c9f66e4200d769648f231450 (patch)
treeb3caf9b61a5d8aa0a69f6e9c760e643c313382a5 /libstorycode
parent510479e6bb291a28d7a8d896933e7ac23fe4c141 (diff)
Draw only visible narrative objects
Diffstat (limited to 'libstorycode')
-rw-r--r--libstorycode/gtk/gtknarrativeview.c3
-rw-r--r--libstorycode/narrative_render_cairo.c25
-rw-r--r--libstorycode/narrative_render_cairo.h2
3 files changed, 19 insertions, 11 deletions
diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c
index 57521a4..e13e106 100644
--- a/libstorycode/gtk/gtknarrativeview.c
+++ b/libstorycode/gtk/gtknarrativeview.c
@@ -609,7 +609,8 @@ static gboolean gtknv_draw_sig(GtkWidget *da, cairo_t *cr, GtkNarrativeView *e)
cairo_fill(cr);
/* Contents */
- narrative_render_cairo(e->n, cr, narrative_get_stylesheet(e->n));
+ narrative_render_cairo(e->n, cr, narrative_get_stylesheet(e->n),
+ e->scroll_pos, e->scroll_pos+e->visible_height);
/* Editing overlay */
cairo_translate(cr, e->n->space_l, e->n->space_t);
diff --git a/libstorycode/narrative_render_cairo.c b/libstorycode/narrative_render_cairo.c
index ebd14f9..0e65878 100644
--- a/libstorycode/narrative_render_cairo.c
+++ b/libstorycode/narrative_render_cairo.c
@@ -456,12 +456,10 @@ static void draw_text(struct narrative_item *item, cairo_t *cr)
cairo_save(cr);
cairo_translate(cr, item->space_l, item->space_t);
- //if ( (hpos + cur_h > min_y) && (hpos < max_y) ) {
- cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
- pango_cairo_update_layout(cr, item->layout);
- pango_cairo_show_layout(cr, item->layout);
- cairo_fill(cr);
- //} /* else paragraph is not visible */
+ cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
+ pango_cairo_update_layout(cr, item->layout);
+ pango_cairo_show_layout(cr, item->layout);
+ cairo_fill(cr);
cairo_restore(cr);
}
@@ -495,9 +493,11 @@ int narrative_render_item_cairo(Narrative*n, cairo_t *cr, int i)
/* NB You must first call narrative_wrap() */
-int narrative_render_cairo(Narrative *n, cairo_t *cr, Stylesheet *stylesheet)
+int narrative_render_cairo(Narrative *n, cairo_t *cr, Stylesheet *stylesheet,
+ double min_y, double max_y)
{
int i, r;
+ double hpos = 0.0;
enum gradient bg;
struct colour bgcol;
struct colour bgcol2;
@@ -539,8 +539,15 @@ int narrative_render_cairo(Narrative *n, cairo_t *cr, Stylesheet *stylesheet)
cairo_translate(cr, n->space_l, n->space_t);
for ( i=0; i<n->n_items; i++ ) {
- narrative_render_item_cairo(n, cr, i);
- cairo_translate(cr, 0.0, narrative_item_get_height(n, i));
+
+ double cur_h = narrative_item_get_height(n, i);
+
+ if ( (hpos + cur_h > min_y) && (hpos < max_y) ) {
+ narrative_render_item_cairo(n, cr, i);
+ } /* else paragraph is not visible */
+
+ cairo_translate(cr, 0.0, cur_h);
+ hpos += cur_h;
}
cairo_restore(cr);
diff --git a/libstorycode/narrative_render_cairo.h b/libstorycode/narrative_render_cairo.h
index bfd2a05..5234357 100644
--- a/libstorycode/narrative_render_cairo.h
+++ b/libstorycode/narrative_render_cairo.h
@@ -51,6 +51,6 @@ extern size_t narrative_pos_trail_to_offset(Narrative *n, int i, int offs, int t
extern int narrative_render_item_cairo(Narrative*n, cairo_t *cr, int i);
extern int narrative_render_cairo(Narrative *n, cairo_t *cr,
- Stylesheet *stylesheet);
+ Stylesheet *stylesheet, double min_y, double max_y);
#endif /* NARRATIVE_RENDER_CAIRO_H */