aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2012-08-12 14:54:45 +0200
committerThomas White <taw@bitwiz.org.uk>2012-08-12 14:54:45 +0200
commit3795b390e6923670d5510acc37315dc9e3668b09 (patch)
tree6cb236860acd89907516f645965435887bd006cd
parentf8d5a4d3c2eed0fde67371159a0ffc3c7d3849c3 (diff)
Basic structure for frames
-rw-r--r--Makefile.am9
-rw-r--r--src/colloquium.c2
-rw-r--r--src/layout.c59
-rw-r--r--src/layout.h44
-rw-r--r--src/presentation.h13
-rw-r--r--src/render.c27
-rw-r--r--src/render.h2
-rw-r--r--src/storycode.c17
-rw-r--r--tests/render_test.c33
9 files changed, 182 insertions, 24 deletions
diff --git a/Makefile.am b/Makefile.am
index aa364e6..30d789a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,11 +8,13 @@ AM_CFLAGS = -Wall
AM_CPPFLAGS = -DDATADIR=\""$(datadir)"\" -I$(top_builddir)/lib -I$(top_srcdir)/lib
LDADD = $(top_builddir)/lib/libgnu.a @IGNORE_UNUSED_LIBRARIES_CFLAGS@
-src_colloquium_SOURCES = src/colloquium.c src/storycode.c src/render.c
+src_colloquium_SOURCES = src/colloquium.c src/storycode.c src/render.c \
+ src/layout.c
INCLUDES = "-I$(top_srcdir)/data"
-EXTRA_DIST +=
+EXTRA_DIST += src/layout.h src/presentation.h src/render.h src/storycode.h \
+ src/stylesheet.h
colloquiumdir = $(datadir)/colloquium
colloquium_DATA = data/colloquium.ui
@@ -28,4 +30,5 @@ TESTS = tests/storycode_test tests/render_test
tests_storycode_test_SOURCES = tests/storycode_test.c src/storycode.c
-tests_render_test_SOURCES = tests/render_test.c src/storycode.c src/render.c
+tests_render_test_SOURCES = tests/render_test.c src/storycode.c src/render.c \
+ src/layout.c
diff --git a/src/colloquium.c b/src/colloquium.c
index 15836be..93d2c4e 100644
--- a/src/colloquium.c
+++ b/src/colloquium.c
@@ -43,7 +43,7 @@ static void show_help(const char *s)
int main(int argc, char *argv[])
{
int c;
- struct presentation *p;
+// struct presentation *p;
/* Long options */
const struct option longopts[] = {
diff --git a/src/layout.c b/src/layout.c
new file mode 100644
index 0000000..6bcb37c
--- /dev/null
+++ b/src/layout.c
@@ -0,0 +1,59 @@
+/*
+ * layout.c
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2012 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+
+#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)
+{
+ fr->w = w;
+ fr->h = h;
+
+ int i;
+
+ for ( i=0; i<fr->num_ro; i++ ) {
+
+ struct frame *child;
+ double child_w, child_h;
+
+ child = fr->rendering_order[i];
+
+ 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);
+ layout_frame(child, child_w, child_h);
+
+ }
+}
diff --git a/src/layout.h b/src/layout.h
new file mode 100644
index 0000000..9e76896
--- /dev/null
+++ b/src/layout.h
@@ -0,0 +1,44 @@
+/*
+ * layout.h
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2012 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef LAYOUT_H
+#define LAYOUT_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+struct layout_parameters
+{
+ double margin_l;
+ double margin_r;
+ double margin_t;
+ double margin_b;
+};
+
+
+/* Calculate layout for frame (and all its children) based on size */
+extern void layout_frame(struct frame *fr, double w, double h);
+
+
+#endif /* LAYOUT_H */
diff --git a/src/presentation.h b/src/presentation.h
index 8707151..50d3831 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -30,6 +30,9 @@
#include <cairo.h>
#include <pango/pango.h>
+struct frame;
+#include "layout.h"
+
struct slide
{
struct presentation *parent;
@@ -50,7 +53,7 @@ struct slide
struct frame
{
- struct frame_class *cl;
+ //struct frame_class *cl;
PangoContext *pc;
struct frame **rendering_order;
@@ -58,6 +61,14 @@ struct frame
char *sc; /* Storycode */
+ struct layout_parameters lop;
+
+ /* Location relative to parent, calculated from alignment parameters */
+ double x;
+ double y;
+ double w;
+ double h;
+
int empty;
};
diff --git a/src/render.c b/src/render.c
index 1e8a697..f05044e 100644
--- a/src/render.c
+++ b/src/render.c
@@ -108,6 +108,11 @@ 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);
@@ -115,6 +120,8 @@ int render_sc(const char *sc, cairo_t *cr, double w, double h, PangoContext *pc)
pango_cairo_update_layout(cr, layout);
pango_layout_set_width(layout, w*PANGO_SCALE);
pango_layout_set_height(layout, h*PANGO_SCALE);
+ pango_layout_set_justify(layout, 1);
+ pango_layout_set_ellipsize(layout, 1);
pango_layout_set_text(layout, sc, -1);
fontdesc = pango_font_description_from_string("Sans 12");
@@ -136,7 +143,7 @@ int render_sc(const char *sc, cairo_t *cr, double w, double h, PangoContext *pc)
}
-static int render_frame(struct frame *fr, cairo_t *cr, double w, double h)
+int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc)
{
int i;
@@ -146,24 +153,16 @@ static int render_frame(struct frame *fr, cairo_t *cr, double w, double h)
* children. */
for ( i=0; i<fr->num_ro; i++ ) {
- double nw, nh;
-
if ( fr->rendering_order[i] == fr ) {
- render_sc(fr->sc, cr, w, h, fr->pc);
+ render_sc(fr->sc, cr, fr->w, fr->h, pc);
continue;
}
/* Sort out the transformation for the margins */
- cairo_translate(cr, fr->rendering_order[i]->cl->margin_left,
- fr->rendering_order[i]->cl->margin_top);
-
- nw = w - fr->rendering_order[i]->cl->margin_left;
- nw -= fr->rendering_order[i]->cl->margin_right;
-
- nh = h - fr->rendering_order[i]->cl->margin_top;
- nh -= fr->rendering_order[i]->cl->margin_bottom;
+ cairo_translate(cr, fr->rendering_order[i]->x,
+ fr->rendering_order[i]->y);
- render_frame(fr->rendering_order[i], cr, nw, nh);
+ render_frame(fr->rendering_order[i], cr, pc);
}
@@ -193,7 +192,7 @@ cairo_surface_t *render_slide(struct slide *s, int w, int h)
render_bgblock(cr, s->st->bgblocks[i]);
}
- render_frame(s->top, cr, w, h);
+ render_frame(s->top, cr, NULL); /* FIXME: pc */
cairo_font_options_destroy(fopts);
cairo_destroy(cr);
diff --git a/src/render.h b/src/render.h
index d5054cd..2fbaa22 100644
--- a/src/render.h
+++ b/src/render.h
@@ -34,4 +34,6 @@ extern cairo_surface_t *render_slide(struct slide *s, int w, int h);
extern int render_sc(const char *sc, cairo_t *cr, double w, double h,
PangoContext *pc);
+extern int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc);
+
#endif /* RENDER_H */
diff --git a/src/storycode.c b/src/storycode.c
index f3c2e27..446d277 100644
--- a/src/storycode.c
+++ b/src/storycode.c
@@ -3,7 +3,7 @@
*
* Colloquium - A tiny presentation program
*
- * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
+ * Copyright (c) 2012 Thomas White <taw@bitwiz.org.uk>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,5 +26,20 @@
#endif
#include <assert.h>
+#include <stdlib.h>
#include "storycode.h"
+#include "presentation.h"
+
+
+struct frame *unpack_storycode(const char *sc)
+{
+ struct frame *fr;
+
+ fr = calloc(1, sizeof(struct frame));
+ if ( fr == NULL ) return NULL;
+
+
+
+ return fr;
+}
diff --git a/tests/render_test.c b/tests/render_test.c
index 9bed0e6..adaba8d 100644
--- a/tests/render_test.c
+++ b/tests/render_test.c
@@ -31,6 +31,7 @@
#include "../src/storycode.h"
#include "../src/render.h"
+#include "../src/layout.h"
static gint mw_destroy(GtkWidget *w, void *p)
@@ -38,7 +39,7 @@ static gint mw_destroy(GtkWidget *w, void *p)
exit(0);
}
-static gboolean draw_sig(GtkWidget *da, cairo_t *cr)
+static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct frame *fr)
{
PangoContext *pc;
GtkAllocation allocation;
@@ -49,14 +50,15 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr)
/* Overall background */
cairo_rectangle(cr, 0.0, 0.0, w, h);
- cairo_set_source_rgb(cr, 0.0, 1.0, 0.0);
+ cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
cairo_fill(cr);
pc = gtk_widget_get_pango_context(da);
gtk_widget_get_allocation(da, &allocation);
- render_sc("\\sf{m20.0}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.", cr, allocation.width, allocation.height, pc);
+ layout_frame(fr, allocation.width, allocation.height);
+ render_frame(fr, cr, pc);
return FALSE;
}
@@ -66,9 +68,32 @@ int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *drawingarea;
+ struct frame *fr;
+ struct frame *fr2;
gtk_init(&argc, &argv);
+ 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.";
+ fr2->rendering_order = calloc(1, sizeof(struct frame *));
+ if ( fr2->rendering_order == NULL ) return 1;
+ fr2->rendering_order[0] = fr2;
+ fr2->num_ro = 1;
+
+ fr = calloc(1, sizeof(struct frame));
+ if ( fr == NULL ) return 1;
+ fr->sc = "";
+ fr->rendering_order = calloc(2, sizeof(struct frame *));
+ 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->num_ro = 2;
+
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
drawingarea = gtk_drawing_area_new();
@@ -79,7 +104,7 @@ int main(int argc, char *argv[])
NULL);
g_signal_connect(G_OBJECT(drawingarea), "draw",
- G_CALLBACK(draw_sig), NULL);
+ G_CALLBACK(draw_sig), fr);
gtk_widget_show_all(window);
gtk_main();