diff options
author | Thomas White <taw@bitwiz.org.uk> | 2013-01-27 20:36:57 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2013-01-27 20:36:57 +0100 |
commit | 09a240e765abbaa58365158acffaf26f1c7fee32 (patch) | |
tree | 95a77eb04d9bb78cb90e32057d3336efec1d97dc | |
parent | bdd8fab8bc3482c5629619ae3d89018c39e2a263 (diff) |
Add fractional units for frame width and height
-rw-r--r-- | src/frame.h | 10 | ||||
-rw-r--r-- | src/render.c | 25 | ||||
-rw-r--r-- | tests/render_test.c | 12 | ||||
-rw-r--r-- | tests/render_test_sc1.c | 12 |
4 files changed, 53 insertions, 6 deletions
diff --git a/src/frame.h b/src/frame.h index 8327f56..dbb7efe 100644 --- a/src/frame.h +++ b/src/frame.h @@ -45,6 +45,13 @@ typedef enum } Direction; +typedef enum +{ + UNITS_SLIDE, + UNITS_FRAC +} LengthUnits; + + struct layout_parameters { double margin_l; @@ -59,8 +66,11 @@ struct layout_parameters double x; double y; + double w; + LengthUnits w_units; double h; + LengthUnits h_units; }; diff --git a/src/render.c b/src/render.c index f879b99..f14d351 100644 --- a/src/render.c +++ b/src/render.c @@ -507,8 +507,29 @@ static int render_frame(struct frame *fr, cairo_t *cr) sizeof(struct layout_parameters)); } - ch->w = ch->lop.w; - ch->h = ch->lop.h; + switch ( ch->lop.w_units ) { + + case UNITS_SLIDE : + ch->w = ch->lop.w; + break; + + case UNITS_FRAC : + ch->w = fr->w * ch->lop.w; + break; + + } + + switch ( ch->lop.w_units ) { + + case UNITS_SLIDE : + ch->h = ch->lop.h; + break; + + case UNITS_FRAC : + ch->h = fr->h * ch->lop.h; + break; + + } render_frame(ch, cr); diff --git a/tests/render_test.c b/tests/render_test.c index 5fbb29d..dbc6b57 100644 --- a/tests/render_test.c +++ b/tests/render_test.c @@ -89,8 +89,10 @@ int main(int argc, char *argv[]) sty1->lop.margin_b = 0.0; sty1->lop.x = 0.0; sty1->lop.y = 0.0; - sty1->lop.w = 100.0; - sty1->lop.h = 100.0; + sty1->lop.w = 1.0; + sty1->lop.w_units = UNITS_FRAC; + sty1->lop.h = 1.0; + sty1->lop.h_units = UNITS_FRAC; sty1->name = strdup("Default"); sty2 = calloc(1, sizeof(struct style)); @@ -104,8 +106,10 @@ int main(int argc, char *argv[]) sty2->lop.margin_b = 5.0; sty2->lop.x = 0.0; sty2->lop.y = 0.0; - sty2->lop.w = 100.0; - sty2->lop.h = 100.0; + sty2->lop.w = 1.0; + sty2->lop.w_units = UNITS_FRAC; + sty2->lop.h = 1.0; + sty2->lop.h_units = UNITS_FRAC; sty2->name = strdup("Text frame"); fr2 = calloc(1, sizeof(struct frame)); diff --git a/tests/render_test_sc1.c b/tests/render_test_sc1.c index 36f0690..b24b33d 100644 --- a/tests/render_test_sc1.c +++ b/tests/render_test_sc1.c @@ -87,6 +87,14 @@ int main(int argc, char *argv[]) sty->lop.margin_r = 0.0; sty->lop.margin_t = 0.0; sty->lop.margin_b = 0.0; + sty->lop.x = 0.0; + sty->lop.y = 0.0; + sty->lop.w = 200.0; + sty->lop.h = 200.0; + sty->lop.w = 1.0; + sty->lop.w_units = UNITS_FRAC; + sty->lop.h = 1.0; + sty->lop.h_units = UNITS_FRAC; sty->name = strdup("Default"); sty2 = calloc(1, sizeof(struct style)); @@ -98,6 +106,10 @@ int main(int argc, char *argv[]) sty2->lop.margin_r = 20.0; sty2->lop.margin_t = 20.0; sty2->lop.margin_b = 20.0; + sty2->lop.w = 1.0; + sty2->lop.w_units = UNITS_FRAC; + sty2->lop.h = 1.0; + sty2->lop.h_units = UNITS_FRAC; sty2->name = strdup("Subframe1"); fr->style = sty; |