From de33cd794955254a166d932e91de0b72d9dc20fd Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 19 Sep 2012 03:02:05 +0300 Subject: Dont resize minimap window if map name very big. Also show map name in minimap tooltip. --- src/gui/minimap.cpp | 26 +++++++++++++++++++++----- src/gui/minimap.h | 6 ++++++ 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index d928e6f8c..5ed18f84e 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -30,6 +30,7 @@ #include "gui/setup.h" #include "gui/viewport.h" +#include "gui/textpopup.h" #include "resources/image.h" #include "resources/imagehelper.h" @@ -50,7 +51,8 @@ Minimap::Minimap(): mHeightProportion(0.5), mCustomMapImage(false), mMapOriginX(0), - mMapOriginY(0) + mMapOriginY(0), + mTextPopup(new TextPopup) { setWindowName("Minimap"); mShow = config.getValueBool(getWindowName() + "Show", true); @@ -82,6 +84,8 @@ Minimap::~Minimap() mMapImage->decRef(); mMapImage = nullptr; } + delete mTextPopup; + mTextPopup = nullptr; } void Minimap::setMap(const Map *const map) @@ -164,13 +168,12 @@ void Minimap::setMap(const Map *const map) { const int offsetX = 2 * getPadding(); const int offsetY = getTitleBarHeight() + getPadding(); - const int titleWidth = getFont()->getWidth(getCaption()) + 15; const int mapWidth = mMapImage->mBounds.w < 100 ? mMapImage->mBounds.w + offsetX : 100; const int mapHeight = mMapImage->mBounds.h < 100 ? mMapImage->mBounds.h + offsetY : 100; - setMinWidth(mapWidth > titleWidth ? mapWidth : titleWidth); + setMinWidth(mapWidth); setMinHeight(mapHeight); mWidthProportion = static_cast( @@ -178,8 +181,7 @@ void Minimap::setMap(const Map *const map) mHeightProportion = static_cast( mMapImage->mBounds.h) / static_cast(map->getHeight()); - setMaxWidth(mMapImage->mBounds.w > titleWidth ? - mMapImage->mBounds.w + offsetX : titleWidth); + setMaxWidth(mMapImage->mBounds.w + offsetX); setMaxHeight(mMapImage->mBounds.h + offsetY); setDefaultSize(getX(), getY(), getWidth(), getHeight()); @@ -419,6 +421,20 @@ void Minimap::mouseReleased(gcn::MouseEvent &event) } } +void Minimap::mouseMoved(gcn::MouseEvent &event) +{ + Window::mouseMoved(event); + const int x = event.getX(); + const int y = event.getY(); + mTextPopup->show(x + getX(), y + getY(), mCaption); +} + +void Minimap::mouseExited(gcn::MouseEvent &event) +{ + Window::mouseExited(event); + mTextPopup->hide(); +} + void Minimap::screenToMap(int &x, int &y) { const gcn::Rectangle a = getChildrenArea(); diff --git a/src/gui/minimap.h b/src/gui/minimap.h index 7a6f865f8..ee5a63f6a 100644 --- a/src/gui/minimap.h +++ b/src/gui/minimap.h @@ -27,6 +27,7 @@ class Image; class Map; +class TextPopup; /** * Minimap window. Shows a minimap image and the name of the current map. @@ -58,8 +59,12 @@ class Minimap : public Window */ void draw(gcn::Graphics *graphics); + void mouseMoved(gcn::MouseEvent &event); + void mouseReleased(gcn::MouseEvent &event); + void mouseExited(gcn::MouseEvent &event); + void screenToMap(int &x, int &y); private: @@ -70,6 +75,7 @@ class Minimap : public Window bool mCustomMapImage; int mMapOriginX; int mMapOriginY; + TextPopup *mTextPopup; }; extern Minimap *minimap; -- cgit v1.2.3-60-g2f50