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
* 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);
COLOR32_TO_ARGB(color, a, r, g, b);
imlib_context_set_color(r, g, b, a);
imlib_context_set_blend(0);
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);
imlib_context_set_image(tim);
imlib_context_set_blend(0);
imlib_context_set_anti_alias(1);
imlib_blend_image_onto_image(tile, 0, 0, 0, sw, sh, 0, 0, tw, th);
imlib_context_set_anti_alias(0);

View File

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