[vte/vte-next: 62/114] Add private function to transform from xy to grid coordinates
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-next: 62/114] Add private function to transform from xy to grid coordinates
- Date: Mon, 30 May 2011 17:11:57 +0000 (UTC)
commit 90143ac22a1a59ccfa6fa67522de101f61974da3
Author: Christian Persch <chpe gnome org>
Date: Sat May 7 19:56:10 2011 +0200
Add private function to transform from xy to grid coordinates
... and from pixel size to grid size.
src/vte-private.h | 10 ++++++++
src/vte.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/src/vte-private.h b/src/vte-private.h
index d9c7b1c..87b0779 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -432,6 +432,16 @@ void _vte_terminal_handle_sequence(VteTerminal *terminal,
const char *match_s,
GQuark match,
GValueArray *params);
+gboolean _vte_terminal_xy_to_grid(VteTerminal *terminal,
+ long x,
+ long y,
+ long *col,
+ long *row);
+gboolean _vte_terminal_size_to_grid_size(VteTerminal *terminal,
+ long w,
+ long h,
+ long *cols,
+ long *rows);
G_END_DECLS
diff --git a/src/vte.c b/src/vte.c
index f251b56..9e722d1 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -5032,6 +5032,73 @@ vte_terminal_paste_cb(GtkClipboard *clipboard, const gchar *text, gpointer data)
}
}
+/**
+ * _vte_terminal_xy_to_grid:
+ * @x: the X coordinate
+ * @y: the Y coordinate
+ * @col: return location to store the column
+ * @row: return location to store the row
+ *
+ * Translates from widget coordinates to grid coordinates.
+ *
+ * If the coordinates are outside the grid, returns %FALSE.
+ */
+gboolean
+_vte_terminal_xy_to_grid(VteTerminal *terminal,
+ long x,
+ long y,
+ long *col,
+ long *row)
+{
+ VteTerminalPrivate *pvt = terminal->pvt;
+ long c, r;
+
+ /* FIXMEchpe: is this correct for RTL? */
+ c = (x - pvt->inner_border.left) / pvt->char_width;
+ r = (y - pvt->inner_border.top) / pvt->char_height;
+
+ if ((c < 0 || c >= pvt->column_count) ||
+ (r < 0 || r >= pvt->row_count))
+ return FALSE;
+
+ *col = c;
+ *row = r;
+ return TRUE;
+}
+
+/**
+ * _vte_terminal_size_to_grid_size
+ * @w: the width in px
+ * @h: the height in px
+ * @col: return location to store the column count
+ * @row: return location to store the row count
+ *
+ * Translates from widget size to grid size.
+ *
+ * If the given width or height are insufficient to show even
+ * one column or row (i.e due to padding), returns %FALSE.
+ */
+gboolean
+_vte_terminal_size_to_grid_size(VteTerminal *terminal,
+ long w,
+ long h,
+ long *cols,
+ long *rows)
+{
+ VteTerminalPrivate *pvt = terminal->pvt;
+ long n_cols, n_rows;
+
+ n_cols = (w - pvt->inner_border.left - pvt->inner_border.right) / pvt->char_width;
+ n_rows = (h - pvt->inner_border.top -pvt->inner_border.bottom) / pvt->char_height;
+
+ if (n_cols <= 0 || n_rows <= 0)
+ return FALSE;
+
+ *cols = n_cols;
+ *rows = n_rows;
+ return TRUE;
+}
+
static void
vte_terminal_get_mouse_tracking_info (VteTerminal *terminal,
int button,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]