summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-20 23:56:16 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-20 23:56:16 -0300
commit3f9ef0eeb5631a72f45468bfd581d2d0aea81208 (patch)
tree7d2c1acb99185eaf8fcc48c935ad65c5eee7beb4 /gui
parenta591146bd867d5e3311d8831148dfe533778fec0 (diff)
downloadeeshow-3f9ef0eeb5631a72f45468bfd581d2d0aea81208.tar.gz
eeshow-3f9ef0eeb5631a72f45468bfd581d2d0aea81208.tar.bz2
eeshow-3f9ef0eeb5631a72f45468bfd581d2d0aea81208.zip
eeshow/gui/over.c (overlay_draw): break down into more manageable parts
Diffstat (limited to 'gui')
-rw-r--r--gui/over.c84
1 files changed, 51 insertions, 33 deletions
diff --git a/gui/over.c b/gui/over.c
index 1a1f511..3c54149 100644
--- a/gui/over.c
+++ b/gui/over.c
@@ -70,17 +70,63 @@ static void rrect(cairo_t *cr, double x, double y, double w, double h, int r)
}
+static void background(const struct overlay *over, cairo_t *cr,
+ unsigned x, unsigned y, unsigned w, unsigned h)
+{
+ const struct overlay_style *style = &over->style;
+ const struct color *bg = &style->bg;
+ const struct color *frame = &style->frame;
+ double center;
+
+ center = style->width / 2.0;
+ rrect(cr, x - center, y - center, w + style->width, h + style->width,
+ style->radius);
+
+ cairo_set_source_rgba(cr, bg->r, bg->g, bg->b, bg->alpha);
+ cairo_fill_preserve(cr);
+ cairo_set_source_rgba(cr, frame->r, frame->g, frame->b, frame->alpha);
+ cairo_set_line_width(cr, style->width);
+ cairo_stroke(cr);
+}
+
+
+static void post_aoi(struct overlay *over,
+ unsigned x, unsigned y, unsigned w, unsigned h)
+{
+ struct aoi aoi_cfg = {
+ .x = x,
+ .y = y,
+ .w = w,
+ .h = h,
+ .hover = over->hover,
+ .click = over->click,
+ .user = over->user,
+ };
+
+
+ if (!over->hover && !over->click)
+ return;
+
+ if (over->aoi) {
+ aoi_update(over->aoi, &aoi_cfg);
+ } else {
+ over->aoi = aoi_add(over->aois, &aoi_cfg);
+ if (over->related) {
+ assert(over->related->aoi);
+ aoi_set_related(over->aoi, over->related->aoi);
+ }
+ }
+}
+
+
static unsigned overlay_draw(struct overlay *over, cairo_t *cr,
unsigned x, unsigned y, int dx, int dy)
{
const struct overlay_style *style = &over->style;
const struct color *fg = &style->fg;
- const struct color *bg = &style->bg;
- const struct color *frame = &style->frame;
unsigned ink_w, ink_h; /* effectively used text area size */
unsigned w, h; /* box size */
int tx, ty; /* text start position */
- double center;
PangoLayout *layout;
PangoFontDescription *desc;
@@ -117,15 +163,7 @@ fprintf(stderr, "%d + %d %d + %d\n",
tx = x - ink_rect.x / PANGO_SCALE + style->pad;
ty = y - ink_rect.y / PANGO_SCALE + style->pad;
- center = style->width / 2.0;
- rrect(cr, x - center, y - center, w + style->width, h + style->width,
- style->radius);
-
- cairo_set_source_rgba(cr, bg->r, bg->g, bg->b, bg->alpha);
- cairo_fill_preserve(cr);
- cairo_set_source_rgba(cr, frame->r, frame->g, frame->b, frame->alpha);
- cairo_set_line_width(cr, style->width);
- cairo_stroke(cr);
+ background(over, cr, x, y, w, h);
if (style->wmax) {
cairo_new_path(cr);
@@ -156,27 +194,7 @@ fprintf(stderr, "%u(%d) %u %.60s\n", ty, ink_rect.y / PANGO_SCALE, ink_h, over->
cairo_reset_clip(cr);
g_object_unref(layout);
- if (over->hover || over->click) {
- struct aoi aoi_cfg = {
- .x = x,
- .y = y,
- .w = w,
- .h = h,
- .hover = over->hover,
- .click = over->click,
- .user = over->user,
- };
-
- if (over->aoi)
- aoi_update(over->aoi, &aoi_cfg);
- else {
- over->aoi = aoi_add(over->aois, &aoi_cfg);
- if (over->related) {
- assert(over->related->aoi);
- aoi_set_related(over->aoi, over->related->aoi);
- }
- }
- }
+ post_aoi(over, x, y, w, h);
return h;
}