aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/layout.c23
-rw-r--r--src/presentation.h23
-rw-r--r--src/render.c88
-rw-r--r--src/stylesheet.h48
-rw-r--r--tests/render_test.c45
5 files changed, 86 insertions, 141 deletions
diff --git a/src/layout.c b/src/layout.c
index c111e18..a257112 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -27,11 +27,22 @@
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
#include "presentation.h"
#include "layout.h"
+#include "stylesheet.h"
-void layout_frame(struct frame *fr, double w, double h)
+
+static void copy_lop_from_style(struct frame *fr, struct style *style)
+{
+ if ( style == NULL ) return; /* Not dictated by style sheet */
+
+ memcpy(&fr->lop, &style->lop, sizeof(struct layout_parameters));
+}
+
+
+static void layout_subframe(struct frame *fr, double w, double h)
{
int i;
@@ -47,6 +58,8 @@ void layout_frame(struct frame *fr, double w, double h)
if ( child == fr ) continue;
+ copy_lop_from_style(child, child->style);
+
child->offs_x = child->lop.margin_l + fr->lop.pad_l;
child->offs_y = child->lop.margin_t + fr->lop.pad_r;
child_w = w - (child->lop.margin_l + child->lop.margin_r);
@@ -54,8 +67,14 @@ void layout_frame(struct frame *fr, double w, double h)
child_w -= (fr->lop.pad_l + fr->lop.pad_r);
child_h -= (fr->lop.pad_t + fr->lop.pad_b);
- layout_frame(child, child_w, child_h);
+ layout_subframe(child, child_w, child_h);
}
}
+
+void layout_frame(struct frame *fr, double w, double h)
+{
+ copy_lop_from_style(fr, fr->style);
+ layout_subframe(fr, w, h);
+}
diff --git a/src/presentation.h b/src/presentation.h
index bda955a..64e6d79 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -53,23 +53,24 @@ struct slide
struct frame
{
- //struct frame_class *cl;
- PangoContext *pc;
+ PangoContext *pc; /* FIXME: Doesn't belong here */
- struct frame **rendering_order;
- int num_ro;
+ struct frame **rendering_order;
+ int num_ro;
- char *sc; /* Storycode */
+ char *sc; /* Storycode */
- struct layout_parameters lop;
+ struct layout_parameters lop;
+ struct style *style; /* Non-NULL if 'lop' came from SS */
/* Location relative to parent, calculated from alignment parameters */
- double offs_x;
- double offs_y;
- double w;
- double h;
+ double offs_x;
+ double offs_y;
+ double w;
+ double h;
- int empty;
+ /* True if this frame should be deleted on the next mouse click */
+ int empty;
};
diff --git a/src/render.c b/src/render.c
index 28365e8..e1915bf 100644
--- a/src/render.c
+++ b/src/render.c
@@ -30,77 +30,13 @@
#include <pango/pangocairo.h>
#include <assert.h>
#include <gdk/gdk.h>
+#include <string.h>
#include "storycode.h"
#include "stylesheet.h"
#include "presentation.h"
-static void render_bgblock(cairo_t *cr, struct bgblock *b)
-{
- GdkColor col1;
- GdkColor col2;
- cairo_pattern_t *patt = NULL;
- double cx, cy, r, r1, r2;
-
- cairo_rectangle(cr, b->min_x, b->min_y,
- b->max_x - b->min_x,
- b->max_y - b->min_y);
-
- switch ( b->type ) {
-
- case BGBLOCK_SOLID :
- gdk_color_parse(b->colour1, &col1);
- gdk_cairo_set_source_color(cr, &col1);
- /* FIXME: Honour alpha as well */
- cairo_fill(cr);
- break;
-
- case BGBLOCK_GRADIENT_CIRCULAR :
- cx = b->min_x + (b->max_x-b->min_x)/2.0;
- cy = b->min_y + (b->max_y-b->min_y)/2.0;
- r1 = (b->max_x-b->min_x)/2.0;
- r2 = (b->max_y-b->min_y)/2.0;
- r = r1 > r2 ? r1 : r2;
- patt = cairo_pattern_create_radial(cx, cy, r, cx, cy, 0.0);
- /* Fall-through */
-
- case BGBLOCK_GRADIENT_X :
- if ( patt == NULL ) {
- patt = cairo_pattern_create_linear(b->min_x, 0.0,
- b->max_y, 0.0);
- }
- /* Fall-through */
-
- case BGBLOCK_GRADIENT_Y :
- if ( patt == NULL ) {
- patt = cairo_pattern_create_linear(0.0, b->min_y,
- 0.0, b->max_y);
- }
-
- gdk_color_parse(b->colour1, &col1);
- gdk_color_parse(b->colour2, &col2);
- cairo_pattern_add_color_stop_rgba(patt, 0.0, col1.red/65535.0,
- col1.green/65535.0,
- col1.blue/65535.0,
- b->alpha1);
- cairo_pattern_add_color_stop_rgba(patt, 1.0, col2.red/65535.0,
- col2.green/65535.0,
- col2.blue/65535.0,
- b->alpha2);
- cairo_set_source(cr, patt);
- cairo_fill(cr);
- cairo_pattern_destroy(patt);
- break;
-
- case BGBLOCK_IMAGE :
- cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
- cairo_fill(cr);
-
- }
-}
-
-
/* Render Level 1 Storycode */
int render_sc(const char *sc, cairo_t *cr, double w, double h, PangoContext *pc)
{
@@ -139,6 +75,7 @@ int render_sc(const char *sc, cairo_t *cr, double w, double h, PangoContext *pc)
int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc)
{
int i;
+ int d = 0;
/* The rendering order is a list of children, but it also contains the
* current frame. In this way, it contains information about which
@@ -153,6 +90,15 @@ int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc)
/* Draw the frame itself (rectangle) */
cairo_rectangle(cr, 0.0, 0.0, fr->w, fr->h);
cairo_set_line_width(cr, 1.0);
+
+ if ( (fr->style != NULL)
+ && (strcmp(fr->style->name, "Default") == 0) )
+ {
+ cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
+ } else {
+ cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+ }
+ cairo_fill_preserve(cr);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
cairo_stroke(cr);
@@ -162,6 +108,8 @@ int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc)
h = fr->h - (fr->lop.pad_t + fr->lop.pad_b);
render_sc(fr->sc, cr, w, h, pc);
+ d = 1;
+
continue;
}
@@ -174,6 +122,11 @@ int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc)
}
+ if ( !d ) {
+ fprintf(stderr, "WARNING: Frame didn't appear on its own "
+ "rendering list?\n");
+ }
+
return 0;
}
@@ -183,7 +136,6 @@ cairo_surface_t *render_slide(struct slide *s, int w, int h)
cairo_surface_t *surf;
cairo_t *cr;
cairo_font_options_t *fopts;
- int i;
surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
@@ -196,10 +148,6 @@ cairo_surface_t *render_slide(struct slide *s, int w, int h)
cairo_font_options_set_antialias(fopts, CAIRO_ANTIALIAS_SUBPIXEL);
cairo_set_font_options(cr, fopts);
- for ( i=0; i<s->st->n_bgblocks; i++ ) {
- render_bgblock(cr, s->st->bgblocks[i]);
- }
-
render_frame(s->top, cr, NULL); /* FIXME: pc */
cairo_font_options_destroy(fopts);
diff --git a/src/stylesheet.h b/src/stylesheet.h
index b4dbf9f..f2f72b2 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -28,21 +28,15 @@
#endif
-struct frame_class
+struct frame;
+#include "layout.h"
+
+
+struct style
{
char *name;
- /* Margins of this frame from the parent */
- double margin_l;
- double margin_r;
- double margin_t;
- double margin_b;
-
- /* Padding between this frame and any children */
- double pad_l;
- double pad_r;
- double pad_t;
- double pad_b;
+ struct layout_parameters lop;
/* Storycode prologue (run through the interpreter before the
* main storycode for the frame */
@@ -50,36 +44,6 @@ struct frame_class
};
-enum bgblocktype
-{
- BGBLOCK_SOLID,
- BGBLOCK_GRADIENT_X,
- BGBLOCK_GRADIENT_Y,
- BGBLOCK_GRADIENT_CIRCULAR,
- BGBLOCK_IMAGE,
-};
-
-
-struct bgblock
-{
- enum bgblocktype type;
- double min_x;
- double max_x;
- double min_y;
- double max_y;
-
- char *colour1;
- double alpha1;
- char *colour2;
- double alpha2;
-
- struct image *image;
- GdkPixbuf *scaled_pb;
- int scaled_w;
- int scaled_h;
-};
-
-
struct slide_template
{
char *name;
diff --git a/tests/render_test.c b/tests/render_test.c
index 64b7583..126ad01 100644
--- a/tests/render_test.c
+++ b/tests/render_test.c
@@ -28,10 +28,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
+#include <string.h>
#include "../src/storycode.h"
#include "../src/render.h"
#include "../src/layout.h"
+#include "../src/stylesheet.h"
static gint mw_destroy(GtkWidget *w, void *p)
@@ -70,9 +72,34 @@ int main(int argc, char *argv[])
GtkWidget *drawingarea;
struct frame *fr;
struct frame *fr2;
+ struct style *sty1;
+ struct style *sty2;
gtk_init(&argc, &argv);
+ sty1 = calloc(1, sizeof(struct style));
+ sty1->lop.pad_l = 0.0;
+ sty1->lop.pad_r = 0.0;
+ sty1->lop.pad_t = 0.0;
+ sty1->lop.pad_b = 0.0;
+ sty1->lop.margin_l = 0.0;
+ sty1->lop.margin_r = 0.0;
+ sty1->lop.margin_t = 0.0;
+ sty1->lop.margin_b = 0.0;
+ sty1->name = strdup("Default");
+
+ sty2 = calloc(1, sizeof(struct style));
+ sty2->lop.pad_l = 10.0;
+ sty2->lop.pad_r = 10.0;
+ sty2->lop.pad_t = 10.0;
+ sty2->lop.pad_b = 10.0;
+ sty2->lop.margin_l = 10.0;
+ sty2->lop.margin_r = 10.0;
+ sty2->lop.margin_t = 10.0;
+ sty2->lop.margin_b = 10.0;
+ sty2->name = strdup("Text frame");
+
+
fr2 = calloc(1, sizeof(struct frame));
if ( fr2 == NULL ) return 1;
fr2->sc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.";
@@ -80,14 +107,7 @@ int main(int argc, char *argv[])
if ( fr2->rendering_order == NULL ) return 1;
fr2->rendering_order[0] = fr2;
fr2->num_ro = 1;
- fr2->lop.pad_l = 10.0;
- fr2->lop.pad_r = 10.0;
- fr2->lop.pad_t = 10.0;
- fr2->lop.pad_b = 10.0;
- fr2->lop.margin_l = 10.0;
- fr2->lop.margin_r = 10.0;
- fr2->lop.margin_t = 10.0;
- fr2->lop.margin_b = 10.0;
+ fr2->style = sty2;
fr = calloc(1, sizeof(struct frame));
if ( fr == NULL ) return 1;
@@ -96,14 +116,7 @@ int main(int argc, char *argv[])
if ( fr->rendering_order == NULL ) return 1;
fr->rendering_order[0] = fr; /* Render parent first */
fr->rendering_order[1] = fr2;
- fr->lop.margin_l = 0.0;
- fr->lop.margin_r = 0.0;
- fr->lop.margin_t = 0.0;
- fr->lop.margin_b = 0.0;
- fr->lop.pad_l = 10.0;
- fr->lop.pad_r = 10.0;
- fr->lop.pad_t = 10.0;
- fr->lop.pad_b = 10.0;
+ fr->style = sty1;
fr->num_ro = 2;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);