Compare commits

...

5 Commits

Author SHA1 Message Date
Kim Woelders de28c0a034 tooltips: Do vertical alignment of icons/text 2023-10-28 09:37:48 +02:00
Kim Woelders 3787b6e530 tooltips: Change some variable names 2023-10-28 09:37:48 +02:00
Kim Woelders f64ab61db2 tooltips: Shorten some function names 2023-10-28 08:46:38 +02:00
Kim Woelders ab6bf3484e tooltips: Fixup after recent rendering change
Render main tooltip window text etc. on own pixmap, not the cached one
associated with the ImageState image.
2023-10-27 08:28:22 +02:00
Kim Woelders 1510cf0477 eimage: Remove some redundant function calls 2023-10-27 08:28:22 +02:00
2 changed files with 115 additions and 97 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2004-2022 Kim Woelders * Copyright (C) 2004-2023 Kim Woelders
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -328,7 +328,6 @@ EImageFill(EImage * im, int x, int y, int w, int h, unsigned int color)
imlib_context_set_image(im); imlib_context_set_image(im);
COLOR32_TO_ARGB(color, a, r, g, b); COLOR32_TO_ARGB(color, a, r, g, b);
imlib_context_set_color(r, g, b, a); imlib_context_set_color(r, g, b, a);
imlib_context_set_blend(0);
imlib_image_fill_rectangle(x, y, w, h); imlib_image_fill_rectangle(x, y, w, h);
} }
@ -378,7 +377,6 @@ EImageTile(EImage * im, EImage * tile, int flags, int tw, int th,
{ {
tim = imlib_create_image(tw, th); tim = imlib_create_image(tw, th);
imlib_context_set_image(tim); imlib_context_set_image(tim);
imlib_context_set_blend(0);
imlib_context_set_anti_alias(1); imlib_context_set_anti_alias(1);
imlib_blend_image_onto_image(tile, 0, 0, 0, sw, sh, 0, 0, tw, th); imlib_blend_image_onto_image(tile, 0, 0, 0, sw, sh, 0, 0, tw, th);
imlib_context_set_anti_alias(0); imlib_context_set_anti_alias(0);

View File

@ -62,7 +62,7 @@ struct _tooltip {
TextClass *tclass; TextClass *tclass;
int dist; int dist;
EObj *win[5]; EObj *win[5];
PmapMask pmm4; EX_Pixmap pmap4;
ImageClass *tooltippic; ImageClass *tooltippic;
}; };
@ -70,7 +70,7 @@ struct _tooltip {
#define TTICL iclass[4] #define TTICL iclass[4]
static void static void
TooltipRealize(ToolTip * tt) _TtRealize(ToolTip * tt)
{ {
int i, wh; int i, wh;
EObj *eo; EObj *eo;
@ -89,9 +89,9 @@ TooltipRealize(ToolTip * tt)
} }
static ToolTip * static ToolTip *
TooltipCreate(const char *name, const char *ic0, const char *ic1, _TtCreate(const char *name, const char *ic0, const char *ic1,
const char *ic2, const char *ic3, const char *ic4, const char *ic2, const char *ic3, const char *ic4,
const char *tclass, int dist, const char *tooltippic) const char *tclass, int dist, const char *tooltippic)
{ {
ToolTip *tt; ToolTip *tt;
ImageClass *ic; ImageClass *ic;
@ -125,7 +125,7 @@ TooltipCreate(const char *name, const char *ic0, const char *ic1,
#if 0 /* Not used */ #if 0 /* Not used */
static void static void
TooltipDestroy(ToolTip * tt) _TtDestroy(ToolTip * tt)
{ {
if (!tt) if (!tt)
return; return;
@ -162,9 +162,8 @@ TooltipConfigLoad(FILE * fs)
{ {
case CONFIG_CLOSE: case CONFIG_CLOSE:
if (iclass[0] && tclass[0] && name[0]) if (iclass[0] && tclass[0] && name[0])
TooltipCreate(name, iclass, bubble1, bubble2, _TtCreate(name, iclass, bubble1, bubble2,
bubble3, bubble4, tclass, distance, bubble3, bubble4, tclass, distance, tooltiphelppic);
tooltiphelppic);
goto done; goto done;
case CONFIG_CLASSNAME: case CONFIG_CLASSNAME:
@ -211,7 +210,7 @@ TooltipConfigLoad(FILE * fs)
} }
static ImageClass * static ImageClass *
TooltipCreateIclass(const char *name, const char *file, int *pw, int *ph) _TtIcCreate(const char *name, const char *file, int *pw, int *ph)
{ {
ImageClass *ic; ImageClass *ic;
EImage *im; EImage *im;
@ -235,7 +234,7 @@ TooltipCreateIclass(const char *name, const char *file, int *pw, int *ph)
} }
static void static void
TooltipIclassPaste(ToolTip * tt, const char *ic_name, int x, int y, int *px) _TtIcPaste(ToolTip * tt, const char *ic_name, int x, int y, int *px)
{ {
ImageClass *ic; ImageClass *ic;
EImage *im; EImage *im;
@ -247,23 +246,26 @@ TooltipIclassPaste(ToolTip * tt, const char *ic_name, int x, int y, int *px)
return; return;
EImageGetSize(im, &w, &h); EImageGetSize(im, &w, &h);
EImageRenderOnDrawable(im, EobjGetWin(tt->TTWIN), tt->pmm4.pmap, EImageRenderOnDrawable(im, EobjGetWin(tt->TTWIN), tt->pmap4,
EIMAGE_BLEND, x, y, w, h); EIMAGE_BLEND, x, y, w, h);
*px = x + w; *px = x + w;
} }
typedef struct {
int h_icons, h_text, h_line;
} tt_hdim_t;
void void
TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y) TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
{ {
int i, w, h, ix, iy, iw, ih, dx, dy, xx, yy; int i, w, h, iw, ih, dx, dy, xx, yy;
int ww, hh, adx, ady, dist; int ww, hh, adx, ady, dist;
int headline_h, headline_w; int headline_h, headline_w;
int icons_width, labels_width, double_w; int icons_width, labels_width, double_w;
EImage *im; EImage *im;
int *heights = NULL; tt_hdim_t *heights = NULL;
EImageBorder *pad; EImageBorder *pad;
int cols[10];
int num, modifiers; int num, modifiers;
Action *aa; Action *aa;
const char *tts; const char *tts;
@ -274,7 +276,7 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
if (!tt->TTWIN) if (!tt->TTWIN)
{ {
TooltipRealize(tt); _TtRealize(tt);
if (!tt->TTWIN) if (!tt->TTWIN)
return; return;
} }
@ -284,19 +286,16 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
h = 0; h = 0;
if (ac) if (ac)
{ {
int cols[10];
num = ActionclassGetActionCount(ac); num = ActionclassGetActionCount(ac);
heights = EMALLOC(int, num); heights = ECALLOC(tt_hdim_t, num);
cols[0] = 0; cols[0] = 0;
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
int temp_w, temp_h, j; int temp_w, temp_h, j;
temp_w = 0;
temp_h = 0;
for (j = 1; j < 10; j++)
cols[j] = 0;
aa = ActionclassGetAction(ac, i); aa = ActionclassGetAction(ac, i);
if (!aa) if (!aa)
continue; continue;
@ -306,6 +305,11 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
continue; continue;
tts = _(tts); tts = _(tts);
temp_w = 0;
temp_h = 0;
for (j = 1; j < 10; j++)
cols[j] = 0;
TextSize(tt->tclass, 0, 0, STATE_NORMAL, tts, &temp_w, &temp_h); TextSize(tt->tclass, 0, 0, STATE_NORMAL, tts, &temp_w, &temp_h);
if (temp_w > labels_width) if (temp_w > labels_width)
labels_width = temp_w; labels_width = temp_w;
@ -317,34 +321,36 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
if (cols[0] < double_w) if (cols[0] < double_w)
cols[0] = double_w; cols[0] = double_w;
} }
heights[i].h_text = temp_h;
temp_h = 0;
if (ActionGetAnybutton(aa)) if (ActionGetAnybutton(aa))
{ {
TooltipCreateIclass("TOOLTIP_MOUSEBUTTON_ANY", _TtIcCreate("TOOLTIP_MOUSEBUTTON_ANY",
"pix/mouse_any.png", &cols[1], &temp_h); "pix/mouse_any.png", &cols[1], &temp_h);
} }
else else
switch (ActionGetButton(aa)) switch (ActionGetButton(aa))
{ {
case 1: case 1:
TooltipCreateIclass("TOOLTIP_MOUSEBUTTON_1", _TtIcCreate("TOOLTIP_MOUSEBUTTON_1",
"pix/mouse_1.png", &cols[1], &temp_h); "pix/mouse_1.png", &cols[1], &temp_h);
break; break;
case 2: case 2:
TooltipCreateIclass("TOOLTIP_MOUSEBUTTON_2", _TtIcCreate("TOOLTIP_MOUSEBUTTON_2",
"pix/mouse_2.png", &cols[1], &temp_h); "pix/mouse_2.png", &cols[1], &temp_h);
break; break;
case 3: case 3:
TooltipCreateIclass("TOOLTIP_MOUSEBUTTON_3", _TtIcCreate("TOOLTIP_MOUSEBUTTON_3",
"pix/mouse_3.png", &cols[1], &temp_h); "pix/mouse_3.png", &cols[1], &temp_h);
break; break;
case 4: case 4:
TooltipCreateIclass("TOOLTIP_MOUSEBUTTON_4", _TtIcCreate("TOOLTIP_MOUSEBUTTON_4",
"pix/mouse_4.png", &cols[1], &temp_h); "pix/mouse_4.png", &cols[1], &temp_h);
break; break;
case 5: case 5:
TooltipCreateIclass("TOOLTIP_MOUSEBUTTON_5", _TtIcCreate("TOOLTIP_MOUSEBUTTON_5",
"pix/mouse_5.png", &cols[1], &temp_h); "pix/mouse_5.png", &cols[1], &temp_h);
break; break;
case 0: case 0:
default: default:
@ -355,38 +361,40 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
if (modifiers) if (modifiers)
{ {
if (modifiers & ShiftMask) if (modifiers & ShiftMask)
TooltipCreateIclass("TOOLTIP_KEY_SHIFT", _TtIcCreate("TOOLTIP_KEY_SHIFT",
"pix/key_shift.png", "pix/key_shift.png", &cols[2], &temp_h);
&cols[2], &temp_h);
if (modifiers & LockMask) if (modifiers & LockMask)
TooltipCreateIclass("TOOLTIP_KEY_LOCK", _TtIcCreate("TOOLTIP_KEY_LOCK",
"pix/key_lock.png", &cols[3], &temp_h); "pix/key_lock.png", &cols[3], &temp_h);
if (modifiers & ControlMask) if (modifiers & ControlMask)
TooltipCreateIclass("TOOLTIP_KEY_CTRL", _TtIcCreate("TOOLTIP_KEY_CTRL",
"pix/key_ctrl.png", &cols[4], &temp_h); "pix/key_ctrl.png", &cols[4], &temp_h);
if (modifiers & Mod1Mask) if (modifiers & Mod1Mask)
TooltipCreateIclass("TOOLTIP_KEY_MOD1", _TtIcCreate("TOOLTIP_KEY_MOD1",
"pix/key_mod1.png", &cols[5], &temp_h); "pix/key_mod1.png", &cols[5], &temp_h);
if (modifiers & Mod2Mask) if (modifiers & Mod2Mask)
TooltipCreateIclass("TOOLTIP_KEY_MOD2", _TtIcCreate("TOOLTIP_KEY_MOD2",
"pix/key_mod2.png", &cols[6], &temp_h); "pix/key_mod2.png", &cols[6], &temp_h);
if (modifiers & Mod3Mask) if (modifiers & Mod3Mask)
TooltipCreateIclass("TOOLTIP_KEY_MOD3", _TtIcCreate("TOOLTIP_KEY_MOD3",
"pix/key_mod3.png", &cols[7], &temp_h); "pix/key_mod3.png", &cols[7], &temp_h);
if (modifiers & Mod4Mask) if (modifiers & Mod4Mask)
TooltipCreateIclass("TOOLTIP_KEY_MOD4", _TtIcCreate("TOOLTIP_KEY_MOD4",
"pix/key_mod4.png", &cols[8], &temp_h); "pix/key_mod4.png", &cols[8], &temp_h);
if (modifiers & Mod5Mask) if (modifiers & Mod5Mask)
TooltipCreateIclass("TOOLTIP_KEY_MOD5", _TtIcCreate("TOOLTIP_KEY_MOD5",
"pix/key_mod5.png", &cols[9], &temp_h); "pix/key_mod5.png", &cols[9], &temp_h);
} }
heights[i].h_icons = temp_h;
temp_w = cols[1] + cols[2] + cols[3] + cols[4] + temp_w = cols[1] + cols[2] + cols[3] + cols[4] +
cols[5] + cols[6] + cols[7] + cols[8] + cols[9]; cols[5] + cols[6] + cols[7] + cols[8] + cols[9];
if (temp_w > icons_width) if (temp_w > icons_width)
icons_width = temp_w; icons_width = temp_w;
heights[i] = temp_h;
temp_h = MAX(heights[i].h_text, heights[i].h_icons);
heights[i].h_line = temp_h;
h += temp_h; h += temp_h;
} }
icons_width += cols[0] + 2; icons_width += cols[0] + 2;
@ -551,12 +559,16 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
} }
else else
{ {
PmapMask pmm;
tt->pmap4 = EGetWindowBackgroundPixmap(EobjGetWin(eo));
ImageclassApplyCopy(tt->iclass[i], EobjGetWin(eo), ImageclassApplyCopy(tt->iclass[i], EobjGetWin(eo),
EobjGetW(eo), EobjGetH(eo), EobjGetW(eo), EobjGetH(eo),
0, 0, STATE_NORMAL, &tt->pmm4, 0, 0, STATE_NORMAL, &pmm, IC_FLAG_MAKE_MASK);
IC_FLAG_MAKE_MASK); EXCopyArea(pmm.pmap, tt->pmap4,
ESetWindowBackgroundPixmap(EobjGetWin(eo), tt->pmm4.pmap, 1); 0, 0, EobjGetW(eo), EobjGetH(eo), 0, 0);
EShapeSetMask(EobjGetWin(eo), 0, 0, tt->pmm4.mask); EShapeSetMask(EobjGetWin(eo), 0, 0, pmm.mask);
PmapMaskFree(&pmm);
} }
EobjShapeUpdate(eo, 0); EobjShapeUpdate(eo, 0);
EobjMap(eo, 0); EobjMap(eo, 0);
@ -564,30 +576,28 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
if (im) if (im)
{ {
ix = pad->left; xx = pad->left;
iy = (h - ih) / 2; yy = (h - ih) / 2;
EImageRenderOnDrawable(im, EobjGetWin(tt->TTWIN), tt->pmm4.pmap, EImageRenderOnDrawable(im, EobjGetWin(tt->TTWIN), tt->pmap4,
EIMAGE_BLEND, ix, iy, iw, ih); EIMAGE_BLEND, xx, yy, iw, ih);
EImageFree(im); EImageFree(im);
} }
xx = pad->left + iw;
/* draw the ordinary tooltip text */ /* draw the ordinary tooltip text */
TextDraw(tt->tclass, EobjGetWin(tt->TTWIN), tt->pmm4.pmap, 0, 0, xx = pad->left + iw;
TextDraw(tt->tclass, EobjGetWin(tt->TTWIN), tt->pmap4, 0, 0,
STATE_NORMAL, text, xx, pad->top, headline_w, headline_h, 512); STATE_NORMAL, text, xx, pad->top, headline_w, headline_h, 512);
/* draw the icons and labels, if any */ /* draw the icons and labels, if any */
if (ac) if (ac)
{ {
int ytxt, yico, htxt, hico;
num = ActionclassGetActionCount(ac); num = ActionclassGetActionCount(ac);
y = pad->top + headline_h; yy = pad->top + headline_h;
xx = pad->left + double_w;
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
x = xx + iw;
aa = ActionclassGetAction(ac, i); aa = ActionclassGetAction(ac, i);
if (!aa) if (!aa)
continue; continue;
@ -597,34 +607,45 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
continue; continue;
tts = _(tts); tts = _(tts);
xx = pad->left + iw;
ytxt = yico = yy;
htxt = heights[i].h_text;
hico = heights[i].h_icons;
if (hico > htxt)
ytxt += (hico - htxt) / 2;
else
yico += (htxt - hico) / 2;
if (ActionGetEvent(aa) == EVENT_DOUBLE_DOWN) if (ActionGetEvent(aa) == EVENT_DOUBLE_DOWN)
{ {
TextDraw(tt->tclass, EobjGetWin(tt->TTWIN), tt->pmm4.pmap, TextDraw(tt->tclass, EobjGetWin(tt->TTWIN), tt->pmap4,
0, 0, STATE_NORMAL, "2x", xx + iw - double_w, y, 0, 0, STATE_NORMAL, "2x",
double_w, heights[i], 0); xx, ytxt, double_w, htxt, 0);
} }
xx += double_w;
if (ActionGetAnybutton(aa)) if (ActionGetAnybutton(aa))
{ {
TooltipIclassPaste(tt, "TOOLTIP_MOUSEBUTTON_ANY", x, y, &x); _TtIcPaste(tt, "TOOLTIP_MOUSEBUTTON_ANY", xx, yico, &xx);
} }
else else
switch (ActionGetButton(aa)) switch (ActionGetButton(aa))
{ {
case 1: case 1:
TooltipIclassPaste(tt, "TOOLTIP_MOUSEBUTTON_1", x, y, &x); _TtIcPaste(tt, "TOOLTIP_MOUSEBUTTON_1", xx, yico, &xx);
break; break;
case 2: case 2:
TooltipIclassPaste(tt, "TOOLTIP_MOUSEBUTTON_2", x, y, &x); _TtIcPaste(tt, "TOOLTIP_MOUSEBUTTON_2", xx, yico, &xx);
break; break;
case 3: case 3:
TooltipIclassPaste(tt, "TOOLTIP_MOUSEBUTTON_3", x, y, &x); _TtIcPaste(tt, "TOOLTIP_MOUSEBUTTON_3", xx, yico, &xx);
break; break;
case 4: case 4:
TooltipIclassPaste(tt, "TOOLTIP_MOUSEBUTTON_4", x, y, &x); _TtIcPaste(tt, "TOOLTIP_MOUSEBUTTON_4", xx, yico, &xx);
break; break;
case 5: case 5:
TooltipIclassPaste(tt, "TOOLTIP_MOUSEBUTTON_5", x, y, &x); _TtIcPaste(tt, "TOOLTIP_MOUSEBUTTON_5", xx, yico, &xx);
break; break;
default: default:
break; break;
@ -634,34 +655,33 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y)
if (modifiers) if (modifiers)
{ {
if (modifiers & ShiftMask) if (modifiers & ShiftMask)
TooltipIclassPaste(tt, "TOOLTIP_KEY_SHIFT", x, y, &x); _TtIcPaste(tt, "TOOLTIP_KEY_SHIFT", xx, yico, &xx);
if (modifiers & LockMask) if (modifiers & LockMask)
TooltipIclassPaste(tt, "TOOLTIP_KEY_LOCK", x, y, &x); _TtIcPaste(tt, "TOOLTIP_KEY_LOCK", xx, yico, &xx);
if (modifiers & ControlMask) if (modifiers & ControlMask)
TooltipIclassPaste(tt, "TOOLTIP_KEY_CTRL", x, y, &x); _TtIcPaste(tt, "TOOLTIP_KEY_CTRL", xx, yico, &xx);
if (modifiers & Mod1Mask) if (modifiers & Mod1Mask)
TooltipIclassPaste(tt, "TOOLTIP_KEY_MOD1", x, y, &x); _TtIcPaste(tt, "TOOLTIP_KEY_MOD1", xx, yico, &xx);
if (modifiers & Mod2Mask) if (modifiers & Mod2Mask)
TooltipIclassPaste(tt, "TOOLTIP_KEY_MOD2", x, y, &x); _TtIcPaste(tt, "TOOLTIP_KEY_MOD2", xx, yico, &xx);
if (modifiers & Mod3Mask) if (modifiers & Mod3Mask)
TooltipIclassPaste(tt, "TOOLTIP_KEY_MOD3", x, y, &x); _TtIcPaste(tt, "TOOLTIP_KEY_MOD3", xx, yico, &xx);
if (modifiers & Mod4Mask) if (modifiers & Mod4Mask)
TooltipIclassPaste(tt, "TOOLTIP_KEY_MOD4", x, y, &x); _TtIcPaste(tt, "TOOLTIP_KEY_MOD4", xx, yico, &xx);
if (modifiers & Mod5Mask) if (modifiers & Mod5Mask)
TooltipIclassPaste(tt, "TOOLTIP_KEY_MOD5", x, y, &x); _TtIcPaste(tt, "TOOLTIP_KEY_MOD5", xx, yico, &xx);
} }
TextDraw(tt->tclass, EobjGetWin(tt->TTWIN), tt->pmm4.pmap, xx = pad->left + iw + icons_width;
0, 0, STATE_NORMAL, tts, pad->left + icons_width + iw, y, TextDraw(tt->tclass, EobjGetWin(tt->TTWIN), tt->pmap4,
labels_width, heights[i], 0); 0, 0, STATE_NORMAL, tts, xx, ytxt, labels_width, htxt, 0);
y += heights[i];
yy += heights[i].h_line;
} }
} }
EClearWindow(EobjGetWin(tt->TTWIN)); EClearWindow(EobjGetWin(tt->TTWIN));
PmapMaskFree(&tt->pmm4);
Efree(heights); Efree(heights);
} }
@ -722,7 +742,7 @@ TooltipsEnable(int enable)
static ToolTip *ttip = NULL; static ToolTip *ttip = NULL;
static int static int
ToolTipTimeout(void *data __UNUSED__) _TtTimeout(void *data __UNUSED__)
{ {
int x, y; int x, y;
unsigned int mask; unsigned int mask;
@ -803,7 +823,7 @@ TooltipsSetPending(int type, CB_GetAclass * func, void *data)
if (type && !Conf_tooltips.showroottooltip) if (type && !Conf_tooltips.showroottooltip)
return; return;
TIMER_ADD(tt_timer, Conf_tooltips.delay, ToolTipTimeout, NULL); TIMER_ADD(tt_timer, Conf_tooltips.delay, _TtTimeout, NULL);
} }
/* /*
@ -811,7 +831,7 @@ TooltipsSetPending(int type, CB_GetAclass * func, void *data)
*/ */
static void static void
TooltipsSighan(int sig, void *prm __UNUSED__) _TtsSighan(int sig, void *prm __UNUSED__)
{ {
switch (sig) switch (sig)
{ {
@ -901,7 +921,7 @@ extern const EModule ModTooltips;
const EModule ModTooltips = { const EModule ModTooltips = {
"tooltips", "tt", "tooltips", "tt",
TooltipsSighan, _TtsSighan,
{0, NULL}, {0, NULL},
MOD_ITEMS(TooltipsCfgItems) MOD_ITEMS(TooltipsCfgItems)
}; };