aboutsummaryrefslogtreecommitdiff
path: root/tests/render_test_sc1.c
blob: 417720b5a5cc42eb4f1225c7effdb2c51b034bf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * render_test_sc1.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 <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <string.h>
#include <assert.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)
{
	exit(0);
}

static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct frame *fr)
{
	PangoContext *pc;
	GtkAllocation allocation;
	gint w, h;

	w = gtk_widget_get_allocated_width(da);
	h = gtk_widget_get_allocated_height(da);

	/* Overall background */
	cairo_rectangle(cr, 0.0, 0.0, w, h);
	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);

	layout_frame(fr, allocation.width, allocation.height);
	render_frame(fr, cr, pc);

	return FALSE;
}


int main(int argc, char *argv[])
{
	GtkWidget *window;
	GtkWidget *drawingarea;
	struct frame *fr;
	struct style *sty;
	struct style *sty2;

	gtk_init(&argc, &argv);

	fr = sc_unpack("Lorem ipsum\\f{Donec ut libero} Wibble Wobble.");

	sty = calloc(1, sizeof(struct style));
	sty->lop.pad_l = 10.0;
	sty->lop.pad_r = 10.0;
	sty->lop.pad_t = 10.0;
	sty->lop.pad_b = 10.0;
	sty->lop.margin_l = 0.0;
	sty->lop.margin_r = 0.0;
	sty->lop.margin_t = 0.0;
	sty->lop.margin_b = 0.0;
	sty->name = strdup("Default");

	sty2 = calloc(1, sizeof(struct style));
	sty2->lop.pad_l = 0.0;
	sty2->lop.pad_r = 0.0;
	sty2->lop.pad_t = 0.0;
	sty2->lop.pad_b = 0.0;
	sty2->lop.margin_l = 20.0;
	sty2->lop.margin_r = 20.0;
	sty2->lop.margin_t = 20.0;
	sty2->lop.margin_b = 20.0;
	sty2->name = strdup("Default");

	fr->style = sty;
	fr->rendering_order[1]->style = sty2;

	assert(fr->rendering_order[0] == fr);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	drawingarea = gtk_drawing_area_new();
	gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(drawingarea));
	gtk_widget_set_size_request(GTK_WIDGET(drawingarea), 320, 200);

	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(mw_destroy),
	                 NULL);

	g_signal_connect(G_OBJECT(drawingarea), "draw",
			 G_CALLBACK(draw_sig), fr);

	gtk_widget_show_all(window);
	gtk_main();

	return 0;
}