Made the tooltips 'work' again.

Added a bit hacky code for 1.6, which needs to be cleanup later. Doing
it properly is a bit too intrusive for 1.6.
This commit is contained in:
Mark de Wever 2009-03-01 09:40:47 +00:00
parent 5adea4af72
commit d39a649b21
2 changed files with 33 additions and 3 deletions

View file

@ -104,6 +104,7 @@ twindow::twindow(CVideo& video,
, top_level_(false)
, restorer_()
, tooltip_()
, tooltip_restorer_()
, help_popup_()
, automatic_placement_(automatic_placement)
, horizontal_placement_(horizontal_placement)
@ -294,6 +295,10 @@ void twindow::draw()
populate_dirty_list(*this, call_stack);
}
if(tooltip_.is_visible() && tooltip_.get_dirty()) {
dirty_list_.push_back(std::vector<twidget*>(1, &tooltip_));
}
if(dirty_list_.empty()) {
if(preferences::use_colour_cursors() || sunset_) {
surface frame_buffer = get_video_surface();
@ -642,8 +647,13 @@ void twindow::do_show_tooltip(const tpoint& location, const t_string& tooltip)
tooltip_.set_label(tooltip);
const tpoint size = tooltip_.get_best_size();
SDL_Rect tooltip_rect = {0, 0, size.x, size.y};
SDL_Rect tooltip_rect = {
(settings::screen_width - size.x) / 2
, settings::screen_height - size.y
, size.x
, size.y
};
#if 0
// Find the best position to place the widget
if(widget_rect.y - size.y > 0) {
// put above
@ -660,12 +670,24 @@ void twindow::do_show_tooltip(const tpoint& location, const t_string& tooltip)
// shift left, no test
tooltip_rect.x = client_rect.w - size.x;
}
#endif
tooltip_.set_size(
tpoint(tooltip_rect.x, tooltip_rect.y),
tpoint(tooltip_rect.w, tooltip_rect.h));
tooltip_.set_visible(twidget::VISIBLE);
tooltip_restorer_= get_surface_portion(video_.getSurface(), tooltip_rect);
}
void twindow::do_remove_tooltip()
{
SDL_Rect rect = tooltip_.get_rect();
SDL_BlitSurface(tooltip_restorer_, 0, video_.getSurface(), &rect);
update_rect(tooltip_.get_rect());
tooltip_.set_visible(twidget::HIDDEN);
}
void twindow::do_show_help_popup(const tpoint& location, const t_string& help_popup)

View file

@ -325,6 +325,14 @@ private:
/** Widget for the tooltip. */
ttooltip tooltip_;
/**
* Restorer for the tooltip area.
*
* @todo the current way of showing a tooltip is a kind of hack which
* should be polished post 1.6.
*/
surface tooltip_restorer_;
/** Widget for the help popup FIXME should be thelp_popup. */
ttooltip help_popup_;
@ -421,8 +429,8 @@ private:
void do_show_tooltip(const tpoint& location, const t_string& tooltip);
/** Inherited from tevent_handler. */
void do_remove_tooltip();
void do_remove_tooltip() { tooltip_.set_visible(twidget::HIDDEN); }
/** Inherited from tevent_handler. */
void do_show_help_popup(const tpoint& location, const t_string& help_popup);