diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-10 21:44:33 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-10 21:44:33 +0200 |
| commit | 2c2e0188f7dc29946483b83d088e4f35c3a9069c (patch) | |
| tree | 5f6c72677ea972bbaaafff06317526432bba611a /swt.c | |
| parent | c301a55b88a131f081a844552327c0ab85db017c (diff) | |
add font rendering
Diffstat (limited to 'swt.c')
| -rw-r--r-- | swt.c | 77 |
1 files changed, 61 insertions, 16 deletions
@@ -34,18 +34,15 @@ char *argv0; typedef struct { unsigned width; unsigned height; + int geometry_changed; struct { struct wl_surface *wl; struct xdg_surface *xdg; struct xdg_toplevel *toplevel; } surface; Canvas *canvas; - Font *font; + FontCache *fontcache; int mode; - struct { - int x; - int y; - } cursor; } Window; @@ -156,10 +153,31 @@ void wclipcopy() { void wdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) { fprintf(stderr, "DRAW CURSOR: cx: %i, cy: %i, ox: %i, oy: %i\n", cx, cy, ox, oy); - draw_rect(win.canvas, win.cursor.x * fontsize, win.cursor.y * fontsize, fontsize, fontsize, 0x0); - draw_rect(win.canvas, cx * fontsize, cy * fontsize, fontsize, fontsize, 0xffffffff); - win.cursor.x = cx; - win.cursor.y = cy; + + draw_rect( + win.canvas, + ox * win.fontcache->box.width, + oy * win.fontcache->box.height, + win.fontcache->box.width, + win.fontcache->box.height, + 0x0 + ); + draw_char( + win.canvas, + win.fontcache, + og.u, + ox * win.fontcache->box.width, + oy * win.fontcache->box.height + win.fontcache->fontsize, + 0xffffffff + ); + draw_rect( + win.canvas, + cx * win.fontcache->box.width, + cy * win.fontcache->box.height, + win.fontcache->box.width, + win.fontcache->box.height, + 0xffffffff + ); } @@ -167,9 +185,26 @@ void wdrawline(Line line, int x1, int y1, int x2) { int x; fprintf(stderr, "DRAW LINE: x1: %i, y1: %i, x2: %i\n"); - /*for (x = x1; x < x2; x++) { - fprintf(stderr, " line: %s\n", line[x]); - }*/ + draw_rect( + win.canvas, + x1 * win.fontcache->box.width, + y1 * win.fontcache->box.height, + (x2 - x1) * win.fontcache->box.width, + win.fontcache->box.height, + 0 + ); + + fprintf(stderr, " line: "); + for (x = x1; x < x2; x++) { + draw_char( + win.canvas, + win.fontcache, + line[x].u, + x * win.fontcache->box.width, + y1 * win.fontcache->box.height + win.fontcache->fontsize, + 0xffffffff + ); + } } @@ -262,14 +297,20 @@ commit_surface() void surface_configure(void *data, struct xdg_surface *surface, uint32_t serial) { + int first_canvas = win.canvas == 0; xdg_surface_ack_configure(surface, serial); - if (win.canvas != 0) { - free_drw(win.canvas); + if (win.geometry_changed || first_canvas) { + if (win.canvas != 0) { + free_drw(win.canvas); + } + win.canvas = create_drw(client.shm, win.width, win.height); + draw(); + win.geometry_changed = 0; } - win.canvas = create_drw(client.shm, win.width, win.height); - draw_frame(); + if (first_canvas) + draw_frame(); commit_surface(); } @@ -277,6 +318,9 @@ surface_configure(void *data, struct xdg_surface *surface, uint32_t serial) void toplevel_configure(void *data, struct xdg_toplevel *toplevel, int32_t width, int32_t height, struct wl_array *clients) { + if (width != win.width && height != win.height) + win.geometry_changed = 1; + if (width == 0 || height == 0) { win.width = 800; win.height = 600; @@ -471,6 +515,7 @@ pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axi void setup() { + win.fontcache = create_font_cache(fonts, sizeof(fonts) / sizeof(FontPath), fontsize); client.kb.repeat.timer = timerfd_create(CLOCK_MONOTONIC, 0); client.kb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); client.display = wl_display_connect(0); |