Add ArrowAlign to TipWindow so the tip is pointing to some widget.

This commit is contained in:
David Capello 2011-02-15 09:02:51 -03:00
parent f96d1f7fa3
commit cb2eb74ff0
8 changed files with 123 additions and 23 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -113,7 +113,8 @@ void CelPropertiesCommand::onExecute(Context* context)
if (layer->is_background()) {
slider_opacity->setEnabled(false);
jwidget_add_tooltip_text(slider_opacity, "The `Background' layer is opaque,\n"
"you can't change its opacity.");
"you can't change its opacity.",
JI_LEFT);
}
}
else {

View File

@ -24,12 +24,13 @@ struct TipData
Frame* window; // Frame where is the tooltip
std::string text;
int timer_id;
int arrowAlign;
};
static int tip_type();
static bool tip_hook(JWidget widget, JMessage msg);
void jwidget_add_tooltip_text(JWidget widget, const char *text)
void jwidget_add_tooltip_text(JWidget widget, const char *text, int arrowAlign)
{
TipData* tip = reinterpret_cast<TipData*>(jwidget_get_data(widget, tip_type()));
@ -42,6 +43,7 @@ void jwidget_add_tooltip_text(JWidget widget, const char *text)
tip->window = NULL;
tip->text = text;
tip->timer_id = -1;
tip->arrowAlign = arrowAlign;
jwidget_add_hook(widget, tip_type(), tip_hook, tip);
}
@ -98,25 +100,60 @@ static bool tip_hook(JWidget widget, JMessage msg)
case JM_TIMER:
if (msg->timer.timer_id == tip->timer_id) {
if (!tip->window) {
Frame* window = new TipWindow(tip->text.c_str(), true);
/* int x = tip->widget->rc->x1; */
/* int y = tip->widget->rc->y2; */
TipWindow* window = new TipWindow(tip->text.c_str(), true);
gfx::Rect bounds = tip->widget->getBounds();
int x = jmouse_x(0)+12*jguiscale();
int y = jmouse_y(0)+12*jguiscale();
int w, h;
tip->window = window;
window->setArrowAlign(tip->arrowAlign);
window->remap_window();
w = jrect_w(window->rc);
h = jrect_h(window->rc);
if (x+w > JI_SCREEN_W) {
x = jmouse_x(0) - w - 4*jguiscale();
y = jmouse_y(0);
switch (tip->arrowAlign) {
case JI_TOP | JI_LEFT:
x = bounds.x + bounds.w;
y = bounds.y + bounds.h;
break;
case JI_TOP | JI_RIGHT:
x = bounds.x - w;
y = bounds.y + bounds.h;
break;
case JI_BOTTOM | JI_LEFT:
x = bounds.x + bounds.w;
y = bounds.y - h;
break;
case JI_BOTTOM | JI_RIGHT:
x = bounds.x - w;
y = bounds.y - h;
break;
case JI_TOP:
x = bounds.x + bounds.w/2 - w/2;
y = bounds.y + bounds.h;
break;
case JI_BOTTOM:
x = bounds.x + bounds.w/2 - w/2;
y = bounds.y - h;
break;
case JI_LEFT:
x = bounds.x + bounds.w;
y = bounds.y + bounds.h/2 - h/2;
break;
case JI_RIGHT:
x = bounds.x - w;
y = bounds.y + bounds.h/2 - h/2;
break;
}
// if (x+w > JI_SCREEN_W) {
// x = jmouse_x(0) - w - 4*jguiscale();
// y = jmouse_y(0);
// }
window->position_window(MID(0, x, JI_SCREEN_W-w),
MID(0, y, JI_SCREEN_H-h));
window->open_window();
@ -140,6 +177,7 @@ TipWindow::TipWindow(const char *text, bool close_on_buttonpressed)
m_close_on_buttonpressed = close_on_buttonpressed;
m_hot_region = NULL;
m_filtering = false;
m_arrowAlign = 0;
set_sizeable(false);
set_moveable(false);
@ -186,6 +224,16 @@ void TipWindow::set_hotregion(JRegion region)
m_hot_region = region;
}
int TipWindow::getArrowAlign() const
{
return m_arrowAlign;
}
void TipWindow::setArrowAlign(int arrowAlign)
{
m_arrowAlign = arrowAlign;
}
bool TipWindow::onProcessMessage(JMessage msg)
{
switch (msg->type) {
@ -201,10 +249,10 @@ bool TipWindow::onProcessMessage(JMessage msg)
case JM_SIGNAL:
if (msg->signal.num == JI_SIGNAL_INIT_THEME) {
this->border_width.l = 4 * jguiscale();
this->border_width.t = 4 * jguiscale();
this->border_width.r = 4 * jguiscale();
this->border_width.b = 5 * jguiscale();
this->border_width.l = 6 * jguiscale();
this->border_width.t = 6 * jguiscale();
this->border_width.r = 6 * jguiscale();
this->border_width.b = 7 * jguiscale();
// Setup the background color.
setBgColor(makecol(255, 255, 200));

View File

@ -12,22 +12,27 @@
class TipWindow : public Frame
{
bool m_close_on_buttonpressed;
JRegion m_hot_region;
bool m_filtering;
public:
TipWindow(const char *text, bool close_on_buttonpressed = false);
~TipWindow();
void set_hotregion(JRegion region);
int getArrowAlign() const;
void setArrowAlign(int arrowAlign);
protected:
bool onProcessMessage(JMessage msg);
void onPreferredSize(PreferredSizeEvent& ev);
void onPaint(PaintEvent& ev);
private:
bool m_close_on_buttonpressed;
JRegion m_hot_region;
bool m_filtering;
int m_arrowAlign;
};
void jwidget_add_tooltip_text(Widget* widget, const char *text);
void jwidget_add_tooltip_text(Widget* widget, const char* text, int arrowAlign = 0);
#endif

View File

@ -1482,13 +1482,58 @@ void SkinTheme::paintTooltip(PaintEvent& ev)
{
TipWindow* widget = static_cast<TipWindow*>(ev.getSource());
Graphics* g = ev.getGraphics();
gfx::Rect pos = widget->getClientBounds();
gfx::Rect rc = widget->getClientBounds();
int bg = makecol(255, 255, 125);
draw_bounds_nw(g, pos, PART_TOOLTIP_NW, bg);
pos.shrink(widget->getBorder());
int nw = PART_TOOLTIP_NW;
int n = PART_TOOLTIP_N;
int ne = PART_TOOLTIP_NE;
int e = PART_TOOLTIP_E;
int se = PART_TOOLTIP_SE;
int s = PART_TOOLTIP_S;
int sw = PART_TOOLTIP_SW;
int w = PART_TOOLTIP_W;
g->drawString(widget->getText(), ji_color_foreground(), bg, pos, widget->getAlign());
switch (widget->getArrowAlign()) {
case JI_TOP | JI_LEFT: nw = PART_TOOLTIP_ARROW_NW; break;
case JI_TOP | JI_RIGHT: ne = PART_TOOLTIP_ARROW_NE; break;
case JI_BOTTOM | JI_LEFT: sw = PART_TOOLTIP_ARROW_SW; break;
case JI_BOTTOM | JI_RIGHT: se = PART_TOOLTIP_ARROW_SE; break;
}
draw_bounds_template(g, rc, nw, n, ne, e, se, s, sw, w);
// Draw arrow in sides
BITMAP* arrow = NULL;
switch (widget->getArrowAlign()) {
case JI_TOP:
arrow = m_part[PART_TOOLTIP_ARROW_N];
g->drawAlphaBitmap(arrow, rc.x+rc.w/2-arrow->w/2, rc.y);
break;
case JI_BOTTOM:
arrow = m_part[PART_TOOLTIP_ARROW_S];
g->drawAlphaBitmap(arrow, rc.x+rc.w/2-arrow->w/2, rc.y+rc.h-arrow->h);
break;
case JI_LEFT:
arrow = m_part[PART_TOOLTIP_ARROW_W];
g->drawAlphaBitmap(arrow, rc.x, rc.y+rc.h/2-arrow->h/2);
break;
case JI_RIGHT:
arrow = m_part[PART_TOOLTIP_ARROW_E];
g->drawAlphaBitmap(arrow, rc.x+rc.w-arrow->w, rc.y+rc.h/2-arrow->h/2);
break;
}
// Fill background
g->fillRect(bg, gfx::Rect(rc).shrink(gfx::Border(m_part[w]->w,
m_part[n]->h,
m_part[e]->w,
m_part[s]->h)));
rc.shrink(widget->getBorder());
g->drawString(widget->getText(), ji_color_foreground(), bg, rc, widget->getAlign());
}
int SkinTheme::get_bg_color(JWidget widget)

View File

@ -102,7 +102,7 @@ Frame* colorselector_new()
colorselector->selected_model = &models[0];
/* palette */
jwidget_add_tooltip_text(pal, "Use SHIFT or CTRL to select ranges");
jwidget_add_tooltip_text(pal, "Use SHIFT or CTRL to select ranges", JI_TOP);
/* data for a better layout */
grid1->child_spacing = 0;

View File

@ -489,6 +489,7 @@ void ToolBar::openTipWindow(int group_index, Tool* tool)
}
m_tipWindow = new TipWindow(tooltip.c_str(), true);
m_tipWindow->setArrowAlign(JI_TOP | JI_RIGHT);
m_tipWindow->remap_window();
Rect toolrc = getToolGroupBounds(group_index);

View File

@ -333,7 +333,7 @@ static Widget* convert_xmlelement_to_widget(TiXmlElement* elem, Widget* root)
widget->setName(name);
if (tooltip != NULL)
jwidget_add_tooltip_text(widget, tooltip);
jwidget_add_tooltip_text(widget, tooltip, JI_LEFT);
if (selected)
widget->setSelected(selected);