(svn r13049) -Codechange: make a class of the TooltipsWindow.

This commit is contained in:
rubidium 2008-05-11 17:44:38 +00:00
parent 1be2847668
commit 3ef0a1e3be

View File

@ -529,44 +529,55 @@ void HideFillingPercent(TextEffectID te_id)
if (te_id != INVALID_TE_ID) RemoveTextEffect(te_id); if (te_id != INVALID_TE_ID) RemoveTextEffect(te_id);
} }
struct tooltips_d {
StringID string_id;
byte paramcount;
uint64 params[5];
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d));
static const Widget _tooltips_widgets[] = { static const Widget _tooltips_widgets[] = {
{ WWT_PANEL, RESIZE_NONE, 14, 0, 199, 0, 31, 0x0, STR_NULL}, { WWT_PANEL, RESIZE_NONE, 14, 0, 199, 0, 31, 0x0, STR_NULL},
{ WIDGETS_END}, { WIDGETS_END},
}; };
struct TooltipsWindow : public Window
static void TooltipsWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { StringID string_id;
case WE_PAINT: byte paramcount;
GfxFillRect(0, 0, w->width - 1, w->height - 1, 0); uint64 params[5];
GfxFillRect(1, 1, w->width - 2, w->height - 2, 0x44);
for (uint arg = 0; arg < WP(w, tooltips_d).paramcount; arg++) { TooltipsWindow(int x, int y, int width, int height, const Widget *widget,
SetDParam(arg, WP(w, tooltips_d).params[arg]); StringID str, uint paramcount, const uint64 params[]) :
Window(x, y, width, height, NULL, WC_TOOLTIPS, widget)
{
this->string_id = str;
assert(sizeof(this->params[0]) == sizeof(params[0]));
memcpy(this->params, params, sizeof(this->params[0]) * paramcount);
this->paramcount = paramcount;
this->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip
this->widget[0].right = width;
this->widget[0].bottom = height;
FindWindowPlacementAndResize(width, height);
} }
DrawStringMultiCenter((w->width >> 1), (w->height >> 1) - 5, WP(w, tooltips_d).string_id, w->width - 2);
break;
case WE_MOUSELOOP: virtual void OnPaint()
{
GfxFillRect(0, 0, this->width - 1, this->height - 1, 0);
GfxFillRect(1, 1, this->width - 2, this->height - 2, 0x44);
for (uint arg = 0; arg < this->paramcount; arg++) {
SetDParam(arg, this->params[arg]);
}
DrawStringMultiCenter((this->width >> 1), (this->height >> 1) - 5, this->string_id, this->width - 2);
}
virtual void OnMouseLoop()
{
/* We can show tooltips while dragging tools. These are shown as long as /* We can show tooltips while dragging tools. These are shown as long as
* we are dragging the tool. Normal tooltips work with rmb */ * we are dragging the tool. Normal tooltips work with rmb */
if (WP(w, tooltips_d).paramcount == 0 ) { if (this->paramcount == 0 ) {
if (!_right_button_down) delete w; if (!_right_button_down) delete this;
} else { } else {
if (!_left_button_down) delete w; if (!_left_button_down) delete this;
}
break;
} }
} }
};
/** Shows a tooltip /** Shows a tooltip
* @param str String to be displayed * @param str String to be displayed
@ -600,16 +611,7 @@ void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[
if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5; if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5;
int x = Clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width); int x = Clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
Window *w = new Window(x, y, br.width, br.height, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets); new TooltipsWindow(x, y, br.width, br.height, _tooltips_widgets, str, paramcount, params);
WP(w, tooltips_d).string_id = str;
assert(sizeof(WP(w, tooltips_d).params[0]) == sizeof(params[0]));
memcpy(WP(w, tooltips_d).params, params, sizeof(WP(w, tooltips_d).params[0]) * paramcount);
WP(w, tooltips_d).paramcount = paramcount;
w->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip
w->widget[0].right = br.width;
w->widget[0].bottom = br.height;
} }