summaryrefslogtreecommitdiff
path: root/gui/index.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-24 02:41:32 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-24 02:41:32 -0300
commit2989ad7ff3a8cf315c2acc5749651ede43cc0119 (patch)
tree1a2c0eecdcaa9b9e3bd5f45895f45d05d464ad4c /gui/index.c
parent558cf8608ba5f5226dafa4b4ebe7ab8c2ebd3117 (diff)
downloadeeshow-2989ad7ff3a8cf315c2acc5749651ede43cc0119.tar.gz
eeshow-2989ad7ff3a8cf315c2acc5749651ede43cc0119.tar.bz2
eeshow-2989ad7ff3a8cf315c2acc5749651ede43cc0119.zip
gui/index.c (best_ratio): fix algorithm; use size, not aspect; add margin
Diffstat (limited to 'gui/index.c')
-rw-r--r--gui/index.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/gui/index.c b/gui/index.c
index 3218f0f..570d085 100644
--- a/gui/index.c
+++ b/gui/index.c
@@ -28,6 +28,7 @@
#define SHEET_ASPECT 1.4146 /* width / height */
#define SHEET_PAD 3
#define SHEET_GAP 12 /* not counting the padding ! */
+#define INDEX_MARGIN 10 /* margin on each side */
static unsigned thumb_rows, thumb_cols;
@@ -138,15 +139,14 @@ static bool thumb_hover(void *user, bool on, int dx, int dy)
static void best_ratio(const struct gui_ctx *ctx)
{
GtkAllocation alloc;
- float screen_aspect, aspect;
const struct gui_sheet *sheet;
unsigned n = 0;
unsigned r, c;
- float ratio, best_ratio = 0;
+ float size, best_size = 0;
+ int aw, ah; /* available size */
int w, h;
gtk_widget_get_allocation(ctx->da, &alloc);
- screen_aspect = (float) alloc.width / alloc.height;
for (sheet = sheets(ctx); sheet; sheet = sheet->next)
n++;
@@ -154,20 +154,24 @@ static void best_ratio(const struct gui_ctx *ctx)
for (r = 1; r <= n; r++) {
c = (n + r - 1) / r;
- w = (alloc.width - (c - 1) * SHEET_GAP) / c;
- h = (alloc.height - (r - 1) * SHEET_GAP) / r;
+ aw = alloc.width - (c - 1) * SHEET_GAP - 2 * INDEX_MARGIN;
+ ah = alloc.height - (r - 1) * SHEET_GAP - 2 * INDEX_MARGIN;
+ if (aw < 0 || ah < 0)
+ continue;
+ w = aw / c;
+ h = ah / r;
if (w > SHEET_MAX_W)
w = SHEET_MAX_W;
- if (h * SHEET_ASPECT > thumb_w)
+ if (h * SHEET_ASPECT > w)
h = w / SHEET_ASPECT;
if (w / SHEET_ASPECT > h)
w = h * SHEET_ASPECT;
- aspect = ((c - 1) * SHEET_GAP + c * w) /
- ((r - 1) * SHEET_GAP + r * h);
- ratio = aspect > screen_aspect ?
- screen_aspect / aspect : aspect / screen_aspect;
- if (ratio > best_ratio) {
- best_ratio = ratio;
+ if (!w || !h)
+ continue;
+ size = ((c - 1) * (w + SHEET_GAP) + w) *
+ ((r - 1) * (h + SHEET_GAP) + h);
+ if (size > best_size) {
+ best_size = size;
thumb_cols = c;
thumb_rows = r;
thumb_w = w;