diff options
author | Thomas White <taw@bitwiz.org.uk> | 2014-10-20 21:38:01 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2014-10-20 21:38:01 +0200 |
commit | 3c49a20ead8e15d5bf48a39a66b72c5b2ccef966 (patch) | |
tree | 23144585f8924f41e6798756b12d0a24e4417d95 | |
parent | 9c94f68c4982b09d94f689c6bbf7e28a2074577b (diff) |
Size and rendering stuff
-rw-r--r-- | src/render.c | 60 | ||||
-rw-r--r-- | src/render.h | 9 | ||||
-rw-r--r-- | src/sc_editor.c | 105 | ||||
-rw-r--r-- | src/sc_editor.h | 2 | ||||
-rw-r--r-- | src/slide_window.c | 2 | ||||
-rw-r--r-- | src/slideshow.c | 6 |
6 files changed, 88 insertions, 96 deletions
diff --git a/src/render.c b/src/render.c index 8028ad7..364b7bd 100644 --- a/src/render.c +++ b/src/render.c @@ -343,20 +343,18 @@ static int recursive_wrap_and_draw(struct frame *fr, cairo_t *cr, } -static void render_slide_to_surface(struct slide *s, cairo_surface_t *surf, - cairo_t *cr, enum is_size isz, - double scale, - ImageStore *is, int slide_number) +static void render_sc_to_surface(SCBlock *scblocks, cairo_surface_t *surf, + cairo_t *cr, double log_w, double log_h, + struct frame *top, SCBlock *stylesheet, + ImageStore *is, enum is_size isz, + int slide_number) { PangoFontMap *fontmap; PangoContext *pc; SCInterpreter *scin; char snum[64]; - cairo_scale(cr, scale, scale); - - cairo_rectangle(cr, 0.0, 0.0, - s->parent->slide_width, s->parent->slide_height); + cairo_rectangle(cr, 0.0, 0.0, log_w, log_h); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_fill(cr); @@ -372,7 +370,7 @@ static void render_slide_to_surface(struct slide *s, cairo_surface_t *surf, pc = pango_font_map_create_context(fontmap); pango_cairo_update_context(cr, pc); - scin = sc_interp_new(pc, s->top); + scin = sc_interp_new(pc, top); if ( scin == NULL ) { fprintf(stderr, "Failed to set up interpreter.\n"); return; @@ -382,10 +380,10 @@ static void render_slide_to_surface(struct slide *s, cairo_surface_t *surf, add_macro(scin, "slidenumber", snum); /* "The rendering pipeline" */ - sc_interp_run_stylesheet(scin, s->parent->stylesheet); - renew_frame(s->top); - sc_interp_add_blocks(scin, s->scblocks); - recursive_wrap_and_draw(s->top, cr, is, isz); + if ( stylesheet != NULL ) sc_interp_run_stylesheet(scin, stylesheet); + renew_frame(top); + sc_interp_add_blocks(scin, scblocks); + recursive_wrap_and_draw(top, cr, is, isz); sc_interp_destroy(scin); cairo_font_options_destroy(fopts); @@ -396,32 +394,27 @@ static void render_slide_to_surface(struct slide *s, cairo_surface_t *surf, /** * render_slide: * @s: A slide. - * @w: Width of the bitmap to produce - * @ww: Width of the slide in Cairo units - * @hh: Height of the slide in Cairo units + * @w: Width of bitmap to output + * @h: Height of bitmap to produce + * @ww: Logical width of the rendering area + * @hh: Logical height of the rendering area * * Render the entire slide. */ -cairo_surface_t *render_slide(struct slide *s, int w, int h, - double ww, double hh, - ImageStore *is, enum is_size isz, - int slide_number) +cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h, + double log_w, double log_h, struct frame *top, + SCBlock *stylesheet, + ImageStore *is, enum is_size isz, + int slide_number) { cairo_surface_t *surf; cairo_t *cr; - double scale; - - scale = w/ww; - - s->top->x = 0.0; - s->top->y = 0.0; - s->top->w = ww; - s->top->h = hh; surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); cr = cairo_create(surf); - render_slide_to_surface(s, surf, cr, isz, scale, is, - slide_number); + cairo_scale(cr, w/log_w, h/log_h); + render_sc_to_surface(scblocks, surf, cr, log_w, log_h, top, stylesheet, + is, isz,slide_number); cairo_destroy(cr); return surf; } @@ -455,6 +448,8 @@ int export_pdf(struct presentation *p, const char *filename) cairo_save(cr); + cairo_scale(cr, scale, scale); + cairo_rectangle(cr, 0.0, 0.0, p->slide_width, p->slide_height); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_fill(cr); @@ -464,8 +459,9 @@ int export_pdf(struct presentation *p, const char *filename) s->top->w = w; s->top->h = w*r; - render_slide_to_surface(s, surf, cr, ISZ_SLIDESHOW, scale, - p->is, i); + render_sc_to_surface(s->scblocks, surf, cr, p->slide_width, + p->slide_height, s->top, p->stylesheet, + p->is, ISZ_SLIDESHOW, i); cairo_restore(cr); diff --git a/src/render.h b/src/render.h index 4e1d86a..5354deb 100644 --- a/src/render.h +++ b/src/render.h @@ -30,9 +30,12 @@ #include "presentation.h" #include "imagestore.h" -extern cairo_surface_t *render_slide(struct slide *s, int w, int h, - double ww, double hh, ImageStore *is, - enum is_size isz, int slide_number); +extern cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h, + double log_w, double log_h, struct frame *top, + SCBlock *stylesheet, + ImageStore *is, enum is_size isz, + int slide_number); + extern int export_pdf(struct presentation *p, const char *filename); #endif /* RENDER_H */ diff --git a/src/sc_editor.c b/src/sc_editor.c index 69a9cf7..8573259 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -78,16 +78,17 @@ struct _sceditor GtkIMContext *im_context; int w; /* Surface size in pixels */ int h; - double ww; /* Size of surface in "SC units" */ - double hh; - struct presentation *p; + double log_w; /* Size of surface in "SC units" */ + double log_h; + SCBlock *scblocks; cairo_surface_t *surface; + struct frame top; + SCBlock *stylesheet; + ImageStore *is; /* Pointers to the frame currently being edited */ struct frame *selection; - struct slide *cur_slide; - PangoContext *pc; /* Location of the cursor */ @@ -125,19 +126,17 @@ struct _sceditor }; -/* Update a slide, once it's been edited in some way. */ -static void rerender_slide(SCEditor *e) +/* Update the view, once it's been edited in some way. */ +static void rerender(SCEditor *e) { - struct slide *s = e->cur_slide; - int n = slide_number(e->p, s); - if ( e->surface != NULL ) { cairo_surface_destroy(e->surface); } - e->surface = render_slide(s, e->w, e->h, - e->p->slide_width, e->p->slide_height, - e->p->is, ISZ_EDITOR, n); + /* FIXME: Slide number, if appropriate */ + e->surface = render_sc(e->scblocks, e->w, e->h, e->log_w, e->log_h, + &e->top, e->stylesheet, e->is, ISZ_EDITOR, + 0); } @@ -461,11 +460,11 @@ static gboolean draw_sig(GtkWidget *da, cairo_t *cr, /* Overall background */ cairo_rectangle(cr, 0.0, 0.0, width, height); - if ( slideshow_linked(e->p->slideshow) ) { - cairo_set_source_rgb(cr, 1.0, 0.3, 0.2); - } else { +// if ( slideshow_linked(e->p->slideshow) ) { +// cairo_set_source_rgb(cr, 1.0, 0.3, 0.2); +// } else { cairo_set_source_rgb(cr, 0.9, 0.9, 0.9); - } +// } FIXME cairo_fill(cr); /* Get the overall size */ @@ -561,7 +560,7 @@ static void insert_text(char *t, SCEditor *e) fr->empty = 0; - rerender_slide(e); + rerender(e); fixup_cursor(e); advance_cursor(e); @@ -606,7 +605,7 @@ static void do_backspace(struct frame *fr, SCEditor *e) // scbl = sc_block_next(scbl); // } while ( (scbl != fbox->scblock) && (scbl != NULL) ); - rerender_slide(e); + rerender(e); fixup_cursor(e); redraw_editor(e); } @@ -615,17 +614,7 @@ static void do_backspace(struct frame *fr, SCEditor *e) static gboolean im_commit_sig(GtkIMContext *im, gchar *str, SCEditor *e) { - if ( e->selection == NULL ) { - if ( str[0] == 'b' ) { - check_toggle_blank(e->p->slideshow); - } else { - printf("IM keypress: %s\n", str); - } - return FALSE; - } - insert_text(str, e); - return FALSE; } @@ -827,7 +816,7 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, if ( within_frame(e->selection, x, y) ) { clicked = e->selection; } else { - clicked = find_frame_at_position(e->cur_slide->top, x, y); + clicked = find_frame_at_position(&e->top, x, y); } /* If the user clicked the currently selected frame, position cursor @@ -870,7 +859,7 @@ static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event, } - } else if ( (clicked == NULL) || (clicked == e->cur_slide->top) ) { + } else if ( (clicked == NULL) || (clicked == &e->top) ) { /* Clicked no object. Deselect old object and set up for * (maybe) creating a new one. */ @@ -953,7 +942,7 @@ static struct frame *create_frame(SCEditor *e, double x, double y, struct frame *parent; struct frame *fr; - parent = e->cur_slide->top; + parent = &e->top; if ( w < 0.0 ) { x += w; @@ -968,7 +957,7 @@ static struct frame *create_frame(SCEditor *e, double x, double y, fr = add_subframe(parent); /* Add to SC */ - fr->scblocks = sc_block_append_end(e->cur_slide->scblocks, + fr->scblocks = sc_block_append_end(e->scblocks, "f", NULL, NULL); sc_block_set_frame(fr->scblocks, fr); sc_block_append_inside(fr->scblocks, NULL, NULL, strdup("")); @@ -1009,7 +998,7 @@ static void do_resize(SCEditor *e, double x, double y, double w, double h) fr->h = h; update_geom(fr); - rerender_slide(e); + rerender(e); redraw_editor(e); } @@ -1041,7 +1030,7 @@ static gboolean button_release_sig(GtkWidget *da, GdkEventButton *event, fr = create_frame(e, e->start_corner_x, e->start_corner_y, e->drag_corner_x - e->start_corner_x, e->drag_corner_y - e->start_corner_y); - rerender_slide(e); + rerender(e); e->selection = fr; break; @@ -1091,7 +1080,6 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, break; case GDK_KEY_Escape : - if ( e->p->slideshow != NULL ) end_slideshow(e->p->slideshow); e->selection = NULL; redraw_editor(e); claim = 1; @@ -1142,19 +1130,6 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, } break; - case GDK_KEY_B : - case GDK_KEY_b : - if ( e->p->slideshow != NULL ) { - //if ( p->prefs->b_splits ) { - toggle_slideshow_link(e->p->slideshow); - //} else { - // p->ss_blank = 1-p->ss_blank; - // redraw_slideshow(p); - //} - } - claim = 1; - break; - } if ( claim ) return TRUE; @@ -1362,8 +1337,8 @@ static void dnd_receive(GtkWidget *widget, GdkDragContext *drag_context, fr->is_image = 1; fr->empty = 0; sc_block_append_inside(fr->scblocks, "image", opts, ""); - show_hierarchy(e->cur_slide->top, ""); - rerender_slide(e); + show_hierarchy(&e->top, ""); + rerender(e); e->selection = fr; redraw_editor(e); free(filename); @@ -1408,7 +1383,7 @@ static gint realise_sig(GtkWidget *da, SCEditor *e) /* FIXME: Can do this "properly" by setting up a separate font map */ e->pc = gtk_widget_get_pango_context(e->drawingarea); - rerender_slide(e); + rerender(e); return FALSE; } @@ -1432,8 +1407,15 @@ void sc_editor_set_size(SCEditor *e, int w, int h) } +void sc_editor_set_logical_size(SCEditor *e, double w, double h) +{ + e->log_w = w; + e->log_h = h; +} + + /* FIXME: GObjectify this */ -SCEditor *sc_editor_new(struct presentation *p) +SCEditor *sc_editor_new(SCBlock *scblocks) { SCEditor *sceditor; GtkTargetEntry targets[1]; @@ -1441,14 +1423,23 @@ SCEditor *sc_editor_new(struct presentation *p) sceditor = calloc(1, sizeof(SCEditor)); if ( sceditor == NULL ) return NULL; - sceditor->p = p; + sceditor->scblocks = scblocks; sceditor->drawingarea = gtk_drawing_area_new(); - sceditor->cur_slide = p->slides[0]; /* FIXME */ sceditor->surface = NULL; sceditor->w = 100; sceditor->h = 100; - - rerender_slide(sceditor); + sceditor->log_w = 100; + sceditor->log_h = 100; + sceditor->is = imagestore_new(); + + sceditor->top.children = NULL; + sceditor->top.num_children = 0; + sceditor->top.max_children = 0; + sceditor->top.lines = NULL; + sceditor->top.n_lines = 0; + sceditor->top.max_lines = 0; + + rerender(sceditor); gtk_widget_set_size_request(GTK_WIDGET(sceditor->drawingarea), sceditor->w, sceditor->h); diff --git a/src/sc_editor.h b/src/sc_editor.h index 664d6e8..694ad5b 100644 --- a/src/sc_editor.h +++ b/src/sc_editor.h @@ -35,7 +35,7 @@ typedef struct _sceditor SCEditor; extern void sc_editor_set_slide(SCEditor *e, struct slide *s); extern GtkWidget *sc_editor_get_widget(SCEditor *e); -extern SCEditor *sc_editor_new(struct presentation *p); +extern SCEditor *sc_editor_new(SCBlock *scblocks); extern void sc_editor_set_size(SCEditor *e, int w, int h); #endif /* SC_EDITOR_H */ diff --git a/src/slide_window.c b/src/slide_window.c index 0ca5f8f..380ed2e 100644 --- a/src/slide_window.c +++ b/src/slide_window.c @@ -601,7 +601,7 @@ SlideWindow *slide_window_open(struct presentation *p, GApplication *app) vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(window), vbox); - sw->sceditor = sc_editor_new(p); + sw->sceditor = sc_editor_new(sw->cur_slide->scblocks); scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, diff --git a/src/slideshow.c b/src/slideshow.c index bd26d03..5f4e93e 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -72,11 +72,13 @@ void slideshow_rerender(SlideShow *ss) int n; n = slide_number(ss->p, ss->cur_slide); - ss->surface = render_slide(ss->cur_slide, + ss->surface = render_sc(ss->cur_slide->scblocks, ss->slide_width, ss->slide_height, ss->p->slide_width, ss->p->slide_height, + ss->cur_slide->top, + ss->p->stylesheet, ss->p->is, ISZ_SLIDESHOW, n); } @@ -174,7 +176,7 @@ void toggle_slideshow_link(SlideShow *ss) if ( ss->linked ) { change_proj_slide(ss, ss->p->cur_edit_slide); } - redraw_editor(ss->p); + //redraw_editor(ss->p); FIXME } |