More updates...
authorThomas White <taw@bitwiz.org.uk>
Sun, 25 Sep 2011 21:01:35 +0000 (23:01 +0200)
committerThomas White <taw@bitwiz.org.uk>
Sun, 25 Sep 2011 21:01:35 +0000 (23:01 +0200)
src/loadsave.c
src/mainwindow.c
src/presentation.c
src/presentation.h
src/slide_render.c
src/stylesheet.c
src/stylesheet.h

index 27476a0..01c8a64 100644 (file)
@@ -63,6 +63,9 @@ int save_presentation(struct presentation *p, const char *filename)
        fprintf(fh, "# Colloquium presentation file\n");
        fprintf(fh, "version=0\n");
 
+       fprintf(fh, "width=%.2f\n", p->slide_width);
+       fprintf(fh, "height=%.2f\n", p->slide_height);
+
        write_stylesheet(p->ss, fh);
 
        for ( i=0; i<p->num_slides; i++ ) {
@@ -73,8 +76,6 @@ int save_presentation(struct presentation *p, const char *filename)
                s = p->slides[i];
 
                fprintf(fh, "++slide\n");
-               fprintf(fh, "width=%.2f\n", s->slide_width);
-               fprintf(fh, "height=%.2f\n", s->slide_height);
 
                for ( j=0; j<s->num_objects; j++ ) {
 
index 3446aed..4cbe7ef 100644 (file)
@@ -372,11 +372,34 @@ static gint set_tool_sig(GtkWidget *widget, GtkRadioAction *action,
 }
 
 
+static gint add_furniture(GtkWidget *widget, struct presentation *p)
+{
+       gchar *name;
+       struct style *sty;
+       struct object *n;
+
+       g_object_get(G_OBJECT(widget), "label", &name, NULL);
+       sty = find_style(p->ss, name);
+       g_free(name);
+       if ( sty == NULL ) return 0;
+
+       n = add_text_object(p->view_slide, 0.0, 0.0, sty);
+       p->editing_object = n;
+
+       gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
+
+       return 0;
+}
+
+
 static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
 {
        GError *error = NULL;
        GtkToolItem *titem;
        GtkWidget *toolbar;
+       GtkWidget *menu;
+       GtkWidget *item;
+       int i;
        GtkActionEntry entries[] = {
 
                { "FileAction", NULL, "_File", NULL, NULL, NULL },
@@ -466,8 +489,7 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
                                   gtk_ui_manager_get_accel_group(p->ui));
        gtk_ui_manager_ensure_update(p->ui);
 
-       toolbar = gtk_ui_manager_get_widget(p->ui,
-                                       "/ui/displaywindowtoolbar");
+       toolbar = gtk_ui_manager_get_widget(p->ui, "/displaywindowtoolbar");
        titem = gtk_separator_tool_item_new();
        gtk_toolbar_insert(GTK_TOOLBAR(toolbar), titem, -1);
 
@@ -476,6 +498,21 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
        gtk_container_add(GTK_CONTAINER(titem), p->tbox);
        gtk_toolbar_insert(GTK_TOOLBAR(toolbar), titem, -1);
 
+       /* Add the styles to the "Insert" menu */
+       menu = gtk_ui_manager_get_widget(p->ui, "/displaywindow/insert");
+       menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
+       item = gtk_separator_menu_item_new();
+       gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+       for ( i=1; i<p->ss->n_styles; i++ )
+       {
+               char *name;
+               name = p->ss->styles[i]->name;
+               item = gtk_menu_item_new_with_label(name);
+               gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+               g_signal_connect(G_OBJECT(item), "activate",
+                                G_CALLBACK(add_furniture), p);
+
+       }
        update_toolbar(p);
 }
 
@@ -487,6 +524,14 @@ static gint close_sig(GtkWidget *window, struct presentation *p)
 }
 
 
+static void redraw_object(struct object *o)
+{
+       if ( o == NULL ) return;
+       gdk_window_invalidate_rect(o->parent->parent->drawingarea->window,
+                                  NULL, FALSE);
+}
+
+
 static gboolean im_commit_sig(GtkIMContext *im, gchar *str,
                               struct presentation *p)
 {
@@ -495,8 +540,7 @@ static gboolean im_commit_sig(GtkIMContext *im, gchar *str,
 
        insert_text(p->editing_object, str);
 
-       /* FIXME: Invalidate only the necessary region */
-       gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
+       redraw_object(p->editing_object);
 
        return FALSE;
 }
@@ -520,14 +564,17 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
 
                case GDK_KEY_BackSpace :
                        handle_text_backspace(p->editing_object);
+                       redraw_object(p->editing_object);
                        break;
 
                case GDK_KEY_Left :
                        move_cursor_left(p->editing_object);
+                       redraw_object(p->editing_object);
                        break;
 
                case GDK_KEY_Right :
                        move_cursor_right(p->editing_object);
+                       redraw_object(p->editing_object);
                        break;
 
                }
@@ -545,14 +592,12 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
 
        case GDK_KEY_Escape :
                if ( p->slideshow != NULL ) end_slideshow(p);
+               redraw_object(p->editing_object);
                p->editing_object = NULL;
                break;
 
        }
 
-       /* FIXME: Invalidate only the necessary region */
-       gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
-
        return FALSE;
 }
 
@@ -601,8 +646,8 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
        }
        p->editing_object = NULL;
 
-       if ( (x>0.0) && (x<p->view_slide->slide_width)
-         && (y>0.0) && (y<p->view_slide->slide_height) )
+       if ( (x>0.0) && (x<p->slide_width)
+         && (y>0.0) && (y<p->slide_height) )
        {
                clicked = find_object_at_position(p->view_slide, x, y);
                switch ( p->tool ) {
@@ -630,10 +675,7 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
        }
 
        gtk_widget_grab_focus(GTK_WIDGET(da));
-
-       /* FIXME: Invalidate only the necessary region */
-       gdk_window_invalidate_rect(p->drawingarea->window, NULL, FALSE);
-
+       redraw_object(p->editing_object);
        return FALSE;
 }
 
index fc9aea4..c66507d 100644 (file)
@@ -52,9 +52,6 @@ struct slide *add_slide(struct presentation *p, int pos)
        p->completely_empty = 0;
        new->parent = p;
 
-       new->slide_width = p->slide_width;
-       new->slide_height = p->slide_height;
-
        new->render_cache_seq = 0;
        new->render_cache = NULL;
        render_slide(new);  /* Render nothing, just to make the surface exist */
index db53f07..a654978 100644 (file)
@@ -43,9 +43,6 @@ struct slide
        int              num_objects;
        struct object  **objects;
        int              object_seq;
-
-       double           slide_width;
-       double           slide_height;
 };
 
 
index 8c438d4..6ab2843 100644 (file)
@@ -42,10 +42,10 @@ static void calculate_size_from_style(struct object *o,
        double max_width, max_height;
        double ebottom, eright, mw, mh;
 
-       eright = o->parent->slide_width - o->style->margin_right;
-       ebottom = o->parent->slide_height - o->style->margin_bottom;
-       mw = o->parent->slide_width;
-       mh = o->parent->slide_height;
+       eright = o->parent->parent->slide_width - o->style->margin_right;
+       ebottom = o->parent->parent->slide_height - o->style->margin_bottom;
+       mw = o->parent->parent->slide_width;
+       mh = o->parent->parent->slide_height;
 
        *peright = eright;  *pebottom = ebottom;
        *pmw = mw;  *pmh = mh;
@@ -81,7 +81,8 @@ static void calculate_size_from_style(struct object *o,
 
 static void calculate_position_from_style(struct object *o,
                                           double eright, double ebottom,
-                                          double mw, double mh)
+                                          double mw, double mh,
+                                          double *pxo, double *pyo)
 {
        double xo, yo;
        PangoRectangle ink, logical;
@@ -101,8 +102,8 @@ static void calculate_position_from_style(struct object *o,
                break;
        }
 
-       if ( o->style->halign == J_CENTER ) {
-
+       if ( o->style->halign == J_CENTER )
+       {
                if ( o->x+xo < o->style->margin_left ) {
                        o->x = o->style->margin_left - xo;
                }
@@ -135,8 +136,7 @@ static void calculate_position_from_style(struct object *o,
                }
        }
 
-       o->x += xo;
-       o->y += yo;
+       *pxo = xo;  *pyo = yo;
 }
 
 
@@ -144,32 +144,39 @@ static void render_text_object(cairo_t *cr, struct object *o)
 {
        PangoRectangle ink, logical;
        double eright, ebottom, mw, mh;
+       double xo, yo;
+       int furniture = 0;
+
+       printf("%f, %f\n", o->x, o->y);
+
+       furniture = o->style != o->parent->parent->ss->styles[0];
 
        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);
 
-       if ( o->style != o->parent->parent->ss->styles[0] )
-       {
-               calculate_size_from_style(o, &eright, &ebottom, &mw, &mh);
-       }
+       calculate_size_from_style(o, &eright, &ebottom, &mw, &mh);
 
        pango_cairo_update_layout(cr, o->layout);
-
        pango_layout_get_extents(o->layout, &ink, &logical);
        o->bb_width = ink.width / PANGO_SCALE;
        o->bb_height = logical.height/PANGO_SCALE;
 
-       if ( o->style != o->parent->parent->ss->styles[0] )
-       {
-               calculate_position_from_style(o, eright, ebottom, mw, mh);
+       if ( furniture ) {
+               calculate_position_from_style(o, eright, ebottom,
+                                             mw, mh, &xo, &yo);
        }
 
+       printf("--- %f, %f\n", o->x, o->y);
        cairo_move_to(cr, o->x, o->y);
        cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
        pango_cairo_show_layout(cr, o->layout);
 
+       if ( furniture ) {
+               o->x += xo;
+               o->y += yo;
+       }
 }
 
 
@@ -200,11 +207,13 @@ int render_slide(struct slide *s)
        int i;
 
        surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
-                                         s->slide_width, s->slide_height);
+                                         s->parent->slide_width,
+                                         s->parent->slide_height);
 
        cr = cairo_create(surf);
 
-       cairo_rectangle(cr, 0.0, 0.0, s->slide_width, s->slide_height);
+       cairo_rectangle(cr, 0.0, 0.0,
+                       s->parent->slide_width, s->parent->slide_height);
        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
        cairo_fill(cr);
 
index b4cc11e..1e5b77b 100644 (file)
@@ -183,7 +183,22 @@ static void style_changed_sig(GtkComboBox *combo,
 
        n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
        s->cur_style = s->ss->styles[n];
-       /* FIXME: Handle default style */
+
+       if ( n == 0 ) {
+               gtk_widget_set_sensitive(s->offset_x, FALSE);
+               gtk_widget_set_sensitive(s->offset_y, FALSE);
+               gtk_widget_set_sensitive(s->use_max, FALSE);
+               gtk_widget_set_sensitive(s->max_width, FALSE);
+               gtk_widget_set_sensitive(s->halign, FALSE);
+               gtk_widget_set_sensitive(s->valign, FALSE);
+       } else {
+               gtk_widget_set_sensitive(s->offset_x, TRUE);
+               gtk_widget_set_sensitive(s->offset_y, TRUE);
+               gtk_widget_set_sensitive(s->use_max, TRUE);
+               gtk_widget_set_sensitive(s->max_width, TRUE);
+               gtk_widget_set_sensitive(s->halign, TRUE);
+               gtk_widget_set_sensitive(s->valign, TRUE);
+       }
 
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_left),
                                  s->cur_style->margin_left);
@@ -204,8 +219,9 @@ static void style_changed_sig(GtkComboBox *combo,
        gtk_combo_box_set_active(GTK_COMBO_BOX(s->valign),
                                 s->cur_style->valign);
 
-       gtk_widget_set_sensitive(s->max_width,
-                                s->cur_style->use_max_width);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(s->use_max),
+                                    s->cur_style->use_max_width);
+       gtk_widget_set_sensitive(s->max_width, s->cur_style->use_max_width);
 
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->max_width),
                                  s->cur_style->max_width);
@@ -233,7 +249,7 @@ static void do_layout(struct _stylesheetwindow *s, GtkWidget *b)
 
        box = gtk_hbox_new(FALSE, 5);
        gtk_box_pack_start(GTK_BOX(b), box, FALSE, FALSE, 5);
-       label = gtk_label_new("Element:");
+       label = gtk_label_new("Style:");
        gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
        gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
        combo = gtk_combo_box_new_text();
@@ -359,27 +375,22 @@ static void do_layout(struct _stylesheetwindow *s, GtkWidget *b)
                         G_CALLBACK(max_changed_sig), s);
 
        /* Font/colour stuff */
-       table = gtk_table_new(3, 2, FALSE);
-       gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 5);
-       gtk_table_set_row_spacings(GTK_TABLE(table), 5.0);
-       gtk_table_set_col_spacings(GTK_TABLE(table), 5.0);
-
        label = gtk_label_new("Font:");
        gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
-       gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
+       gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
        s->text_font = gtk_font_button_new_with_font("Sans 12");
        box = gtk_hbox_new(FALSE, 0);
-       gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 0, 1);
+       gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 3, 4);
        gtk_box_pack_start(GTK_BOX(box), s->text_font, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(s->text_font), "font-set",
                         G_CALLBACK(text_font_set_sig), s);
 
        label = gtk_label_new("Colour:");
        gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
-       gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
+       gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5);
        s->text_colour = gtk_color_button_new();
        box = gtk_hbox_new(FALSE, 0);
-       gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 1, 2);
+       gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 4, 5);
        gtk_box_pack_start(GTK_BOX(box), s->text_colour, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(s->text_colour), "color-set",
                         G_CALLBACK(text_colour_set_sig), s);
@@ -407,9 +418,12 @@ static struct style *new_style(StyleSheet *ss, const char *name)
        sty = malloc(sizeof(*sty));
        if ( sty == NULL ) return NULL;
 
+       sty->name = strdup(name);
+
        n = ss->n_styles;
        styles_new = realloc(ss->styles, (n+1)*sizeof(sty));
        if ( styles_new == NULL ) {
+               free(sty->name);
                free(sty);
                return NULL;
        }
@@ -452,6 +466,45 @@ static void default_stylesheet(StyleSheet *ss)
        sty->offset_x = 0.0;
        sty->offset_y = 0.0;  /* irrelevant */
 
+       sty = new_style(ss, "Slide credit");
+       sty->font = strdup("Sans 30");
+       sty->colour = strdup("#000000000000");  /* Black */
+       sty->alpha = 1.0;
+       sty->margin_left = 20.0;
+       sty->margin_right = 20.0;
+       sty->margin_top = 20.0;
+       sty->margin_bottom = 20.0;
+       sty->halign = J_CENTER;
+       sty->valign = V_CENTER;
+       sty->offset_x = +200.0;
+       sty->offset_y = -300.0;
+
+       sty = new_style(ss, "Slide date");
+       sty->font = strdup("Sans 30");
+       sty->colour = strdup("#000000000000");  /* Black */
+       sty->alpha = 1.0;
+       sty->margin_left = 20.0;
+       sty->margin_right = 20.0;
+       sty->margin_top = 20.0;
+       sty->margin_bottom = 20.0;
+       sty->halign = J_CENTER;
+       sty->valign = V_CENTER;
+       sty->offset_x = +200.0;
+       sty->offset_y = -300.0;
+
+       sty = new_style(ss, "Slide number");
+       sty->font = strdup("Sans 30");
+       sty->colour = strdup("#000000000000");  /* Black */
+       sty->alpha = 1.0;
+       sty->margin_left = 20.0;
+       sty->margin_right = 20.0;
+       sty->margin_top = 20.0;
+       sty->margin_bottom = 20.0;
+       sty->halign = J_CENTER;
+       sty->valign = V_CENTER;
+       sty->offset_x = +200.0;
+       sty->offset_y = -300.0;
+
        sty = new_style(ss, "Presentation title");
        sty->font = strdup("Sans 50");
        sty->colour = strdup("#000000000000");  /* Black */
@@ -477,6 +530,19 @@ static void default_stylesheet(StyleSheet *ss)
        sty->valign = V_CENTER;
        sty->offset_x = +200.0;
        sty->offset_y = -300.0;
+
+       sty = new_style(ss, "Presentation date");
+       sty->font = strdup("Sans 30");
+       sty->colour = strdup("#000000000000");  /* Black */
+       sty->alpha = 1.0;
+       sty->margin_left = 20.0;
+       sty->margin_right = 20.0;
+       sty->margin_top = 20.0;
+       sty->margin_bottom = 20.0;
+       sty->halign = J_CENTER;
+       sty->valign = V_CENTER;
+       sty->offset_x = +200.0;
+       sty->offset_y = -300.0;
 }
 
 
@@ -563,7 +629,7 @@ StylesheetWindow *open_stylesheet(struct presentation *p)
        text_box = gtk_vbox_new(FALSE, 0);
        gtk_container_set_border_width(GTK_CONTAINER(text_box), 12);
        gtk_notebook_append_page(GTK_NOTEBOOK(nb), text_box,
-                                gtk_label_new("Slide layout"));
+                                gtk_label_new("Styles"));
        do_layout(s, text_box);
 
        background_box = gtk_vbox_new(FALSE, 0);
@@ -580,3 +646,16 @@ StylesheetWindow *open_stylesheet(struct presentation *p)
 
        return s;
 }
+
+
+struct style *find_style(StyleSheet *ss, const char *name)
+{
+       int i;
+       for ( i=0; i<ss->n_styles; i++ ) {
+               if ( strcmp(ss->styles[i]->name, name) == 0 ) {
+                       return ss->styles[i];
+               }
+       }
+
+       return NULL;
+}
index 4b7f7fb..5b3bdb1 100644 (file)
@@ -85,4 +85,6 @@ extern StylesheetWindow *open_stylesheet(struct presentation *p);
 extern StyleSheet *new_stylesheet();
 extern StyleSheet *load_stylesheet(const char *filename);
 
+extern struct style *find_style(StyleSheet *ss, const char *name);
+
 #endif /* STYLESHEET_H */