mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 14:04:39 +02:00
eeshow/gui/over.c (overlay_draw): break down into more manageable parts
This commit is contained in:
parent
b7fc07b650
commit
e88fd0ac6c
@ -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,
|
static unsigned overlay_draw(struct overlay *over, cairo_t *cr,
|
||||||
unsigned x, unsigned y, int dx, int dy)
|
unsigned x, unsigned y, int dx, int dy)
|
||||||
{
|
{
|
||||||
const struct overlay_style *style = &over->style;
|
const struct overlay_style *style = &over->style;
|
||||||
const struct color *fg = &style->fg;
|
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 ink_w, ink_h; /* effectively used text area size */
|
||||||
unsigned w, h; /* box size */
|
unsigned w, h; /* box size */
|
||||||
int tx, ty; /* text start position */
|
int tx, ty; /* text start position */
|
||||||
double center;
|
|
||||||
|
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
@ -117,15 +163,7 @@ fprintf(stderr, "%d + %d %d + %d\n",
|
|||||||
tx = x - ink_rect.x / PANGO_SCALE + style->pad;
|
tx = x - ink_rect.x / PANGO_SCALE + style->pad;
|
||||||
ty = y - ink_rect.y / PANGO_SCALE + style->pad;
|
ty = y - ink_rect.y / PANGO_SCALE + style->pad;
|
||||||
|
|
||||||
center = style->width / 2.0;
|
background(over, cr, x, y, w, h);
|
||||||
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);
|
|
||||||
|
|
||||||
if (style->wmax) {
|
if (style->wmax) {
|
||||||
cairo_new_path(cr);
|
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);
|
cairo_reset_clip(cr);
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
|
|
||||||
if (over->hover || over->click) {
|
post_aoi(over, x, y, w, h);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user