[gedit/wip/printing-enhancements: 1/4] print-preview: simplify get_page_at_coords()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/printing-enhancements: 1/4] print-preview: simplify get_page_at_coords()
- Date: Sun, 28 Jun 2015 08:33:07 +0000 (UTC)
commit e5386792edd85f31c443ebaf66e00167420604f2
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Jun 28 09:16:32 2015 +0200
print-preview: simplify get_page_at_coords()
'r' and 'c' actually meant 'row' and 'col'… In the context of math, r
and c can represent many things, like a radius and center, or rotation.
Since 'r' is the row, the code can be simplified since there is now at
most one row. Also avoid redundant "+1" and "-1".
A later commit will take into account selected pages for printing (like
print only pages 1, 5 and 7). And another later commit can fix the FIXME
comment.
gedit/gedit-print-preview.c | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/gedit/gedit-print-preview.c b/gedit/gedit-print-preview.c
index 2709745..b41761f 100644
--- a/gedit/gedit-print-preview.c
+++ b/gedit/gedit-print-preview.c
@@ -486,38 +486,44 @@ get_first_page_displayed (GeditPrintPreview *preview)
return preview->cur_page - (preview->cur_page % preview->n_columns);
}
-/* returns the page number (starting from 0) or -1 if no page */
+/* Returns the page number (starting from 0) or -1 if no page. */
static gint
get_page_at_coords (GeditPrintPreview *preview,
gint x,
gint y)
{
GtkAdjustment *hadj, *vadj;
- gint r, c, pg;
+ gint col, page;
if (preview->tile_height <= 0 || preview->tile_width <= 0)
+ {
return -1;
+ }
get_adjustments (preview, &hadj, &vadj);
x += gtk_adjustment_get_value (hadj);
y += gtk_adjustment_get_value (vadj);
- r = 1 + y / (preview->tile_height);
- c = 1 + x / (preview->tile_width);
+ col = x / preview->tile_width;
- if (c > preview->n_columns)
+ if (col >= preview->n_columns ||
+ y > preview->tile_height)
+ {
return -1;
+ }
- pg = get_first_page_displayed (preview) - 1;
- pg += (r - 1) * preview->n_columns + c;
+ page = get_first_page_displayed (preview) + col;
- if (pg >= preview->n_pages)
+ if (page >= preview->n_pages)
+ {
return -1;
+ }
- /* FIXME: we could try to be picky and check
- * if we actually are inside the page */
- return pg;
+ /* FIXME: we could try to be picky and check if we actually are inside
+ * the page (i.e. not in the padding or shadow).
+ */
+ return page;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]