aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2012-08-12 17:19:20 +0200
committerThomas White <taw@bitwiz.org.uk>2012-08-12 17:19:20 +0200
commit6d0e78aadcf111cfd82cc8762ebd43c10c7923ae (patch)
tree8d5863955735e94a54707440ff064d8509c925a1
parent3795b390e6923670d5510acc37315dc9e3668b09 (diff)
Clarify layout logic
-rw-r--r--src/layout.c18
-rw-r--r--src/layout.h5
-rw-r--r--src/presentation.h4
-rw-r--r--src/render.c32
-rw-r--r--src/stylesheet.h14
-rw-r--r--tests/render_test.c20
6 files changed, 63 insertions, 30 deletions
diff --git a/src/layout.c b/src/layout.c
index 6bcb37c..c111e18 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -31,15 +31,13 @@
#include "presentation.h"
#include "layout.h"
-
-/* Calculate layout for frame (and all its children) based on size */
void layout_frame(struct frame *fr, double w, double h)
{
+ int i;
+
fr->w = w;
fr->h = h;
- int i;
-
for ( i=0; i<fr->num_ro; i++ ) {
struct frame *child;
@@ -49,11 +47,15 @@ void layout_frame(struct frame *fr, double w, double h)
if ( child == fr ) continue;
- child->x = fr->lop.margin_l;
- child->y = fr->lop.margin_t;
- child_w = w - (fr->lop.margin_l + fr->lop.margin_r);
- child_h = h - (fr->lop.margin_t + fr->lop.margin_b);
+ 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);
+ child_h = h - (child->lop.margin_t + child->lop.margin_b);
+ 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);
}
}
+
diff --git a/src/layout.h b/src/layout.h
index 9e76896..e389d67 100644
--- a/src/layout.h
+++ b/src/layout.h
@@ -34,6 +34,11 @@ struct layout_parameters
double margin_r;
double margin_t;
double margin_b;
+
+ double pad_l;
+ double pad_r;
+ double pad_t;
+ double pad_b;
};
diff --git a/src/presentation.h b/src/presentation.h
index 50d3831..bda955a 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -64,8 +64,8 @@ struct frame
struct layout_parameters lop;
/* Location relative to parent, calculated from alignment parameters */
- double x;
- double y;
+ double offs_x;
+ double offs_y;
double w;
double h;
diff --git a/src/render.c b/src/render.c
index f05044e..28365e8 100644
--- a/src/render.c
+++ b/src/render.c
@@ -108,18 +108,13 @@ int render_sc(const char *sc, cairo_t *cr, double w, double h, PangoContext *pc)
PangoFontDescription *fontdesc;
GdkColor col;
- cairo_rectangle(cr, 0.0, 0.0, w, h);
- cairo_set_line_width(cr, 0.1);
- cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
- cairo_stroke(cr);
-
/* FIXME: Check for Level 1 markup e.g. image */
layout = pango_layout_new(pc);
-
- pango_cairo_update_layout(cr, layout);
pango_layout_set_width(layout, w*PANGO_SCALE);
pango_layout_set_height(layout, h*PANGO_SCALE);
+
+ pango_cairo_update_layout(cr, layout);
pango_layout_set_justify(layout, 1);
pango_layout_set_ellipsize(layout, 1);
@@ -128,8 +123,6 @@ int render_sc(const char *sc, cairo_t *cr, double w, double h, PangoContext *pc)
pango_layout_set_font_description(layout, fontdesc);
- cairo_move_to(cr, 0.0, 0.0);
-
/* FIXME: Honour alpha as well */
gdk_color_parse("#000000", &col);
gdk_cairo_set_source_color(cr, &col);
@@ -154,13 +147,28 @@ int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc)
for ( i=0; i<fr->num_ro; i++ ) {
if ( fr->rendering_order[i] == fr ) {
- render_sc(fr->sc, cr, fr->w, fr->h, pc);
+
+ double w, h;
+
+ /* Draw the frame itself (rectangle) */
+ cairo_rectangle(cr, 0.0, 0.0, fr->w, fr->h);
+ cairo_set_line_width(cr, 1.0);
+ cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
+ cairo_stroke(cr);
+
+ /* Set up padding, and then draw the contents */
+ cairo_move_to(cr, fr->lop.pad_l, fr->lop.pad_t);
+ w = fr->w - (fr->lop.pad_l + fr->lop.pad_r);
+ h = fr->h - (fr->lop.pad_t + fr->lop.pad_b);
+ render_sc(fr->sc, cr, w, h, pc);
+
continue;
+
}
/* Sort out the transformation for the margins */
- cairo_translate(cr, fr->rendering_order[i]->x,
- fr->rendering_order[i]->y);
+ cairo_translate(cr, fr->rendering_order[i]->offs_x,
+ fr->rendering_order[i]->offs_y);
render_frame(fr->rendering_order[i], cr, pc);
diff --git a/src/stylesheet.h b/src/stylesheet.h
index 44230fb..b4dbf9f 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -33,10 +33,16 @@ struct frame_class
char *name;
/* Margins of this frame from the parent */
- double margin_left;
- double margin_right;
- double margin_top;
- double margin_bottom;
+ 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;
/* Storycode prologue (run through the interpreter before the
* main storycode for the frame */
diff --git a/tests/render_test.c b/tests/render_test.c
index adaba8d..64b7583 100644
--- a/tests/render_test.c
+++ b/tests/render_test.c
@@ -80,6 +80,14 @@ 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;
fr = calloc(1, sizeof(struct frame));
if ( fr == NULL ) return 1;
@@ -88,10 +96,14 @@ 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 = 10.0;
- fr->lop.margin_r = 10.0;
- fr->lop.margin_t = 10.0;
- fr->lop.margin_b = 10.0;
+ 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->num_ro = 2;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);