From 26fd0b6c2057bd73a65df380a6baa4ee2d67387c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 11 Aug 2011 23:45:00 +0200 Subject: Use layout stuff --- src/mainwindow.c | 36 ++++++++++++++++++++++++++++++++++ src/mainwindow.h | 1 + src/objects.c | 33 +++++++++++++++++++++++++++++-- src/objects.h | 3 +++ src/slide_render.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++- src/stylesheet.c | 16 +++++++++++++-- 6 files changed, 141 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mainwindow.c b/src/mainwindow.c index fe31ad4..7648f5a 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -145,6 +145,16 @@ void notify_slide_changed(struct presentation *p) } +void notify_slide_update(struct presentation *p) +{ + gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE); + + if ( p->slideshow != NULL ) { + notify_slideshow_slide_changed(p); + } +} + + static gint add_slide_sig(GtkWidget *widget, struct presentation *p) { struct slide *new; @@ -573,6 +583,32 @@ static void draw_editing_bits(cairo_t *cr, struct presentation *p, break; } + + if ( o->le != NULL ) { + + cairo_move_to(cr, o->le->margin_left, -p->border_offs_y); + cairo_line_to(cr, o->le->margin_left, + p->slide_height+p->border_offs_y); + + cairo_move_to(cr, p->slide_width-o->le->margin_right, + -p->border_offs_y); + cairo_line_to(cr, p->slide_width-o->le->margin_right, + p->slide_height+p->border_offs_y); + + cairo_move_to(cr, -p->border_offs_x, o->le->margin_top); + cairo_line_to(cr, p->slide_width+p->border_offs_x, + o->le->margin_top); + + cairo_move_to(cr, -p->border_offs_x, + p->slide_height-o->le->margin_bottom); + cairo_line_to(cr, p->slide_width+p->border_offs_x, + p->slide_height-o->le->margin_bottom); + + cairo_set_source_rgb(cr, 0.2, 0.2, 0.2); + cairo_set_line_width(cr, 1.0); + cairo_stroke(cr); + + } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 3c1f1c4..36cd289 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -30,5 +30,6 @@ extern int open_mainwindow(struct presentation *p); extern void notify_slide_changed(struct presentation *p); +extern void notify_slide_update(struct presentation *p); #endif /* MAINWINDOW_H */ diff --git a/src/objects.c b/src/objects.c index a97b769..9c8ed41 100644 --- a/src/objects.c +++ b/src/objects.c @@ -44,7 +44,7 @@ static struct object *new_object(enum objtype t, struct layout_element *le) new->type = t; new->empty = 1; new->parent = NULL; - new->le = NULL; + new->le = le; return new; } @@ -243,6 +243,7 @@ void notify_style_update(struct presentation *p, struct text_style *ts) for ( j=0; jslides[i]->num_objects; j++ ) { if ( s->objects[j]->type != TEXT ) continue; + if ( s->objects[j]->style != ts ) continue; s->object_seq++; if ( p->view_slide == s ) changed = 1; @@ -252,7 +253,35 @@ void notify_style_update(struct presentation *p, struct text_style *ts) } - if ( changed ) notify_slide_changed(p); + if ( changed ) notify_slide_update(p); +} + + +void notify_layout_update(struct presentation *p, struct layout_element *le) +{ + int i; + int changed = 0; + + for ( i=0; inum_slides; i++ ) { + + int j; + struct slide *s; + + s = p->slides[i]; + + for ( j=0; jslides[i]->num_objects; j++ ) { + + if ( s->objects[j]->le != le ) continue; + + s->object_seq++; + if ( p->view_slide == s ) changed = 1; + break; + + } + + } + + if ( changed ) notify_slide_update(p); } diff --git a/src/objects.h b/src/objects.h index 9ac58d0..ddbd2a8 100644 --- a/src/objects.h +++ b/src/objects.h @@ -71,6 +71,9 @@ extern void move_cursor_left(struct object *o); extern void move_cursor_right(struct object *o); extern void position_caret(struct object *o, double x, double y); +extern void notify_layout_update(struct presentation *p, + struct layout_element *ts); + extern void delete_object(struct object *o); diff --git a/src/slide_render.c b/src/slide_render.c index c4cd55c..6173dfe 100644 --- a/src/slide_render.c +++ b/src/slide_render.c @@ -38,18 +38,73 @@ static void render_text_object(cairo_t *cr, struct object *o) { int width, height; + double ebottom, eright, mw, mh; + double max_width, max_height; o->layout = pango_cairo_create_layout(cr); pango_layout_set_text(o->layout, o->text, -1); o->fontdesc = pango_font_description_from_string(o->style->font); pango_layout_set_font_description(o->layout, o->fontdesc); + eright = o->parent->slide_width - o->le->margin_right; + ebottom = o->parent->slide_height - o->le->margin_bottom; + mw = o->parent->slide_width; + mh = o->parent->slide_height; + + max_width = mw - o->le->margin_left - o->le->margin_right; + if ( o->le->use_max_width && (o->le->max_width < max_width) ) { + /* Use provided maximum value if given */ + max_width = o->le->max_width; + } + + max_height = mh - o->le->margin_top - o->le->margin_bottom; + + pango_layout_set_width(o->layout, max_width*PANGO_SCALE); + pango_layout_set_height(o->layout, max_height*PANGO_SCALE); + pango_layout_set_wrap(o->layout, PANGO_WRAP_WORD_CHAR); + + switch ( o->le->halign ) { + case J_LEFT : + pango_layout_set_alignment(o->layout, PANGO_ALIGN_LEFT); + break; + case J_RIGHT : + pango_layout_set_alignment(o->layout, PANGO_ALIGN_RIGHT); + break; + case J_CENTER : + pango_layout_set_alignment(o->layout, PANGO_ALIGN_CENTER); + break; + } + pango_cairo_update_layout(cr, o->layout); - pango_layout_get_size(o->layout, &width, &height); + pango_layout_get_size(o->layout, &width, &height); o->bb_width = width/PANGO_SCALE; o->bb_height = height/PANGO_SCALE; + switch ( o->le->halign ) { + case J_LEFT : + o->x = o->le->margin_left; + break; + case J_RIGHT : + o->x = eright - o->bb_width; + break; + case J_CENTER : + o->x = o->le->offset_x; + break; + } + + switch ( o->le->valign ) { + case V_TOP : + o->y = o->le->margin_top; + break; + case V_BOTTOM : + o->y = ebottom - o->bb_height; + break; + case V_CENTER : + o->y = mh/2.0 - o->bb_height/2.0 - o->le->offset_y; + break; + } + cairo_move_to(cr, o->x, o->y); cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); diff --git a/src/stylesheet.c b/src/stylesheet.c index 92a0b11..52cb556 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -33,6 +33,7 @@ #include "presentation.h" #include "stylesheet.h" +#include "objects.h" struct _stylesheetwindow @@ -174,6 +175,7 @@ static void margin_left_changed_sig(GtkSpinButton *spin, struct _stylesheetwindow *s) { s->cur_layout_element->margin_left = gtk_spin_button_get_value(spin); + notify_layout_update(s->p, s->cur_layout_element); } @@ -181,6 +183,7 @@ static void margin_right_changed_sig(GtkSpinButton *spin, struct _stylesheetwindow *s) { s->cur_layout_element->margin_right = gtk_spin_button_get_value(spin); + notify_layout_update(s->p, s->cur_layout_element); } @@ -188,6 +191,7 @@ static void margin_top_changed_sig(GtkSpinButton *spin, struct _stylesheetwindow *s) { s->cur_layout_element->margin_top = gtk_spin_button_get_value(spin); + notify_layout_update(s->p, s->cur_layout_element); } @@ -195,6 +199,7 @@ static void margin_bottom_changed_sig(GtkSpinButton *spin, struct _stylesheetwindow *s) { s->cur_layout_element->margin_bottom = gtk_spin_button_get_value(spin); + notify_layout_update(s->p, s->cur_layout_element); } @@ -202,6 +207,7 @@ static void offset_x_changed_sig(GtkSpinButton *spin, struct _stylesheetwindow *s) { s->cur_layout_element->offset_x = gtk_spin_button_get_value(spin); + notify_layout_update(s->p, s->cur_layout_element); } @@ -209,6 +215,7 @@ static void offset_y_changed_sig(GtkSpinButton *spin, struct _stylesheetwindow *s) { s->cur_layout_element->offset_y = gtk_spin_button_get_value(spin); + notify_layout_update(s->p, s->cur_layout_element); } @@ -216,6 +223,7 @@ static void halign_changed_sig(GtkComboBox *combo, struct _stylesheetwindow *s) { s->cur_layout_element->halign = gtk_combo_box_get_active(combo); + notify_layout_update(s->p, s->cur_layout_element); } @@ -223,6 +231,7 @@ static void valign_changed_sig(GtkComboBox *combo, struct _stylesheetwindow *s) { s->cur_layout_element->valign = gtk_combo_box_get_active(combo); + notify_layout_update(s->p, s->cur_layout_element); } @@ -230,6 +239,7 @@ static void max_changed_sig(GtkSpinButton *spin, struct _stylesheetwindow *s) { s->cur_layout_element->max_width = gtk_spin_button_get_value(spin); + notify_layout_update(s->p, s->cur_layout_element); } @@ -362,7 +372,8 @@ static void do_layout(struct _stylesheetwindow *s, GtkWidget *b) /* Up */ label = gtk_label_new("Upwards:"); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); - s->offset_y = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0); + s->offset_y = gtk_spin_button_new_with_range(-s->p->slide_height, + +s->p->slide_height, 1.0); gtk_table_attach_defaults(GTK_TABLE(table), s->offset_y, 1, 2, 0, 1); g_signal_connect(G_OBJECT(s->offset_y), "value-changed", G_CALLBACK(offset_y_changed_sig), s); @@ -370,7 +381,8 @@ static void do_layout(struct _stylesheetwindow *s, GtkWidget *b) /* Right */ label = gtk_label_new("Across:"); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); - s->offset_x = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0); + s->offset_x = gtk_spin_button_new_with_range(-s->p->slide_width, + +s->p->slide_width, 1.0); gtk_table_attach_defaults(GTK_TABLE(table), s->offset_x, 1, 2, 1, 2); g_signal_connect(G_OBJECT(s->offset_x), "value-changed", G_CALLBACK(offset_x_changed_sig), s); -- cgit v1.2.3