[vte/vte-next] Add private function to transform from xy to grid coordinates



commit b4d35346971a64e7034adb17fe4c11de02d73423
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 66bc565..5dd85eb 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -5034,6 +5034,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]