diff options
Diffstat (limited to 'src/entry.c')
-rw-r--r-- | src/entry.c | 79 |
1 files changed, 8 insertions, 71 deletions
diff --git a/src/entry.c b/src/entry.c index 845df0a..eb58695 100644 --- a/src/entry.c +++ b/src/entry.c @@ -1,7 +1,5 @@ #include <cairo/cairo.h> #include <glib.h> -#include <pango/pangocairo.h> -#include <pango/pango.h> #include <wchar.h> #include "entry.h" #include "log.h" @@ -11,6 +9,7 @@ void entry_init(struct entry *entry, uint32_t width, uint32_t height, uint32_t s { entry->image.width = width; entry->image.height = height; + entry->image.scale = scale; width /= scale; height /= scale; @@ -79,67 +78,19 @@ void entry_init(struct entry *entry, uint32_t width, uint32_t height, uint32_t s height -= 2 * entry->padding; cairo_rectangle(cr, 0, 0, width, height); cairo_clip(cr); - - /* Setup Pango. */ - log_debug("Creating Pango context.\n"); - PangoContext *context = pango_cairo_create_context(cr); - - log_debug("Creating Pango font description.\n"); - PangoFontDescription *font_description = - pango_font_description_from_string(entry->font_name); - pango_font_description_set_size( - font_description, - entry->font_size * PANGO_SCALE); - pango_context_set_font_description(context, font_description); - pango_font_description_free(font_description); - - entry->pango.prompt_layout = pango_layout_new(context); - log_debug("Setting Pango text.\n"); - pango_layout_set_text(entry->pango.prompt_layout, "run: ", -1); - int prompt_width; - int prompt_height; - log_debug("Get Pango pixel size.\n"); - pango_layout_get_pixel_size(entry->pango.prompt_layout, &prompt_width, &prompt_height); - log_debug("First Pango draw.\n"); - pango_cairo_update_layout(cr, entry->pango.prompt_layout); - - /* Draw the prompt now, as this only needs to be done once */ - color = entry->foreground_color; - cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - pango_cairo_show_layout(cr, entry->pango.prompt_layout); - - /* Move and clip so we don't draw over the prompt */ - cairo_translate(cr, prompt_width, 0); - width -= prompt_width; - cairo_rectangle(cr, 0, 0, width, height); - cairo_clip(cr); - - log_debug("Creating Pango layout.\n"); - entry->pango.entry_layout = pango_layout_new(context); - pango_layout_set_text(entry->pango.entry_layout, "", -1); - - for (size_t i = 0; i < 5; i++) { - PangoLayout *layout = pango_layout_new(context); - pango_layout_set_text(layout, "", -1); - entry->pango.result_layouts[i] = layout; - } - - entry->pango.context = context; entry->cairo.surface = surface; entry->cairo.cr = cr; + /* Setup the backend. */ + entry_backend_init(entry, width, height, scale); + entry->image.buffer = cairo_image_surface_get_data(surface); } void entry_destroy(struct entry *entry) { - for (size_t i = 0; i < 5; i++) { - g_object_unref(entry->pango.result_layouts[i]); - } - g_object_unref(entry->pango.entry_layout); - g_object_unref(entry->pango.prompt_layout); - g_object_unref(entry->pango.context); + entry_backend_destroy(entry); cairo_destroy(entry->cairo.cr); cairo_surface_destroy(entry->cairo.surface); } @@ -160,27 +111,13 @@ void entry_update(struct entry *entry) color = entry->foreground_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - pango_layout_set_text(entry->pango.entry_layout, entry->input_mb, -1); - pango_cairo_update_layout(cr, entry->pango.entry_layout); - pango_cairo_show_layout(cr, entry->pango.entry_layout); - - for (size_t i = 0; i < 5; i++) { - cairo_translate(cr, 0, 50); - PangoLayout *layout = entry->pango.result_layouts[i]; - const char *str; - if (i < entry->results.count) { - str = entry->results.buf[i]; - } else { - str = ""; - } - pango_layout_set_text(layout, str, -1); - pango_cairo_update_layout(cr, layout); - pango_cairo_show_layout(cr, layout); - } + entry_backend_update(entry); + cairo_restore(cr); } void entry_set_scale(struct entry *entry, uint32_t scale) { + entry->image.scale = scale; cairo_surface_set_device_scale(entry->cairo.surface, scale, scale); } |