aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2018-01-04 15:36:33 +0100
committerThomas White <taw@bitwiz.org.uk>2018-01-04 15:36:33 +0100
commit921535b85a9f95df82bd88e714f1460f0b4ab7a8 (patch)
tree8832ece5f118f8d1e59fa5c4041c31fcec79f457 /src
parenta856b400d5cdddb1c3d7f7f4b9c078ab1dbfe1d0 (diff)
Slideshow: Handle letterboxing both ways
Diffstat (limited to 'src')
-rw-r--r--src/slideshow.c40
-rw-r--r--src/slideshow.h2
2 files changed, 24 insertions, 18 deletions
diff --git a/src/slideshow.c b/src/slideshow.c
index cbb41bd..9eae2dc 100644
--- a/src/slideshow.c
+++ b/src/slideshow.c
@@ -91,7 +91,6 @@ static gint ss_destroy_sig(GtkWidget *widget, SCSlideshow *ss)
static gboolean ss_draw_sig(GtkWidget *da, cairo_t *cr, SCSlideshow *ss)
{
- double xoff, yoff;
double width, height;
width = gtk_widget_get_allocated_width(GTK_WIDGET(da));
@@ -104,19 +103,10 @@ static gboolean ss_draw_sig(GtkWidget *da, cairo_t *cr, SCSlideshow *ss)
if ( !ss->blank ) {
- int h;
-
- /* FIXME: Assumes that monitor and slide sizes are such that
- * letterboxing at sides. This needn't be the case. */
- h = ss->slide_width * ss->p->slide_height / ss->p->slide_width;
-
- /* Get the overall size */
- xoff = (width - ss->slide_width)/2.0;
- yoff = (height - h)/2.0;
-
/* Draw the slide from the cache */
- cairo_rectangle(cr, xoff, yoff, ss->slide_width, h);
- cairo_set_source_surface(cr, ss->surface, xoff, yoff);
+ cairo_rectangle(cr, ss->xoff, ss->yoff,
+ ss->slide_width, ss->slide_height);
+ cairo_set_source_surface(cr, ss->surface, ss->xoff, ss->yoff);
cairo_fill(cr);
}
@@ -143,12 +133,26 @@ static gboolean ss_realize_sig(GtkWidget *w, SCSlideshow *ss)
static void ss_size_sig(GtkWidget *widget, GdkRectangle *rect, SCSlideshow *ss)
{
- int w;
+ const double sw = ss->p->slide_width;
+ const double sh = ss->p->slide_height;
+
+ if ( sw/sh > (double)rect->width/rect->height ) {
+ /* Slide is too wide. Letterboxing top/bottom */
+ ss->slide_width = rect->width;
+ ss->slide_height = rect->width * sh/sw;
+ } else {
+ /* Letterboxing at sides */
+ ss->slide_width = rect->height * sw/sh;
+ ss->slide_height = rect->height;
+ }
+
+ ss->xoff = (rect->width - ss->slide_width)/2.0;
+ ss->yoff = (rect->height - ss->slide_height)/2.0;
- w = rect->height * ss->p->slide_width/ss->p->slide_height;
- if ( w > rect->width ) w = rect->width;
- ss->slide_width = w;
- ss->slide_height = rect->height;
+ printf("screen %i %i\n", rect->width, rect->height);
+ printf("slide %f %f\n", sw, sh);
+ printf("rendering slide at %i %i\n", ss->slide_width, ss->slide_height);
+ printf("offset %i %i\n", ss->xoff, ss->yoff);
slideshow_rerender(ss);
}
diff --git a/src/slideshow.h b/src/slideshow.h
index 665134d..7ef0ea8 100644
--- a/src/slideshow.h
+++ b/src/slideshow.h
@@ -56,6 +56,8 @@ struct _scslideshow
int blank;
int slide_width;
int slide_height;
+ int xoff;
+ int yoff;
struct inhibit_sys *inhibit;
int linked;
cairo_surface_t *surface;