aboutsummaryrefslogtreecommitdiffstats
path: root/display.c
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-10 19:14:41 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-10 19:14:41 -0400
commitfad4734c206235ffcf52903e01f23d24f1e1e087 (patch)
treea3de6109710940239d177a88b9600d8fd05f36be /display.c
parentfde26a7c16c4662ede268bfd5cb1f61d6189dde2 (diff)
downloadrunes-fad4734c206235ffcf52903e01f23d24f1e1e087.tar.gz
runes-fad4734c206235ffcf52903e01f23d24f1e1e087.zip
split terminal processing out to a separate file
Diffstat (limited to 'display.c')
-rw-r--r--display.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/display.c b/display.c
index da15311..2766545 100644
--- a/display.c
+++ b/display.c
@@ -4,19 +4,16 @@
void runes_display_init(RunesTerm *t)
{
- cairo_font_extents_t extents;
-
cairo_select_font_face(t->cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(t->cr, 14.0);
cairo_set_source_rgb(t->cr, 0.0, 0.0, 1.0);
- cairo_font_extents(t->cr, &extents);
- cairo_move_to(t->cr, 0.0, extents.ascent);
+ runes_display_move_to(t, 0, 0);
runes_pty_backend_set_window_size(t);
}
-static void runes_display_get_font_dimensions(RunesTerm *t, double *fontx, double *fonty)
+static void runes_display_get_font_dimensions(RunesTerm *t, double *fontx, double *fonty, double *ascent)
{
cairo_font_extents_t extents;
@@ -24,34 +21,43 @@ static void runes_display_get_font_dimensions(RunesTerm *t, double *fontx, doubl
*fontx = extents.max_x_advance;
*fonty = extents.height;
+ *ascent = extents.ascent;
}
void runes_display_get_term_size(RunesTerm *t, int *row, int *col, int *xpixel, int *ypixel)
{
- double fontx, fonty;
+ double fontx, fonty, ascent;
runes_window_backend_get_size(t, xpixel, ypixel);
- runes_display_get_font_dimensions(t, &fontx, &fonty);
+ runes_display_get_font_dimensions(t, &fontx, &fonty, &ascent);
*row = (int)(*ypixel / fonty);
*col = (int)(*xpixel / fontx);
}
-void runes_display_glyph(RunesTerm *t, char *buf, size_t len)
+void runes_display_get_position(RunesTerm *t, int *row, int *col)
{
- if (len) {
- cairo_font_extents_t extents;
+ double x, y;
+ double fontx, fonty, ascent;
- cairo_font_extents(t->cr, &extents);
+ cairo_get_current_point(t->cr, &x, &y);
+ runes_display_get_font_dimensions(t, &fontx, &fonty, &ascent);
- char *nl;
+ *row = (y - ascent) / fonty;
+ *col = x / fontx;
+}
+
+void runes_display_move_to(RunesTerm *t, int row, int col)
+{
+ double fontx, fonty, ascent;
+
+ runes_display_get_font_dimensions(t, &fontx, &fonty, &ascent);
+
+ cairo_move_to(t->cr, col * fontx, row * fonty + ascent);
+}
+
+void runes_display_show_string(RunesTerm *t, char *buf, size_t len)
+{
+ if (len) {
buf[len] = '\0';
- while ((nl = strchr(buf, '\n'))) {
- double x, y;
- *nl = '\0';
- cairo_show_text(t->cr, buf);
- buf = nl + 1;
- cairo_get_current_point(t->cr, &x, &y);
- cairo_move_to(t->cr, 0.0, y + extents.height);
- }
cairo_show_text(t->cr, buf);
/* we have to flush manually because XNextEvent (which normally handles
* flushing) will most likely be called again before the keystroke is