diff options
author | Thomas White <taw@bitwiz.org.uk> | 2012-08-12 17:19:20 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2012-08-12 17:19:20 +0200 |
commit | 6d0e78aadcf111cfd82cc8762ebd43c10c7923ae (patch) | |
tree | 8d5863955735e94a54707440ff064d8509c925a1 /src | |
parent | 3795b390e6923670d5510acc37315dc9e3668b09 (diff) |
Clarify layout logic
Diffstat (limited to 'src')
-rw-r--r-- | src/layout.c | 18 | ||||
-rw-r--r-- | src/layout.h | 5 | ||||
-rw-r--r-- | src/presentation.h | 4 | ||||
-rw-r--r-- | src/render.c | 32 | ||||
-rw-r--r-- | src/stylesheet.h | 14 |
5 files changed, 47 insertions, 26 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 */ |