2013-08-09 00:01:20 +00:00
|
|
|
// Aseprite UI Library
|
2018-08-08 20:27:26 +00:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2010-09-27 22:18:17 +00:00
|
|
|
//
|
2014-03-29 23:08:05 +00:00
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
2010-09-27 22:18:17 +00:00
|
|
|
|
2012-06-18 01:49:58 +00:00
|
|
|
#ifndef UI_TOOLTIPS_H_INCLUDED
|
|
|
|
#define UI_TOOLTIPS_H_INCLUDED
|
2014-03-29 22:40:17 +00:00
|
|
|
#pragma once
|
2008-02-10 18:49:12 +00:00
|
|
|
|
2012-06-18 01:49:58 +00:00
|
|
|
#include "ui/base.h"
|
2014-04-13 22:35:15 +00:00
|
|
|
#include "ui/popup_window.h"
|
2015-08-28 17:45:56 +00:00
|
|
|
#include "ui/timer.h"
|
2012-07-09 02:24:42 +00:00
|
|
|
#include "ui/window.h"
|
2008-02-10 18:49:12 +00:00
|
|
|
|
2012-06-16 02:37:59 +00:00
|
|
|
#include <map>
|
2018-08-08 20:27:26 +00:00
|
|
|
#include <memory>
|
2012-06-16 02:37:59 +00:00
|
|
|
|
2012-06-18 01:02:54 +00:00
|
|
|
namespace ui {
|
2012-06-16 02:37:59 +00:00
|
|
|
|
2017-02-17 17:18:47 +00:00
|
|
|
class TextBox;
|
2012-06-16 02:37:59 +00:00
|
|
|
class TipWindow;
|
|
|
|
|
2015-12-10 19:50:16 +00:00
|
|
|
class TooltipManager : public Widget {
|
2012-06-16 02:37:59 +00:00
|
|
|
public:
|
|
|
|
TooltipManager();
|
|
|
|
~TooltipManager();
|
|
|
|
|
2014-04-20 22:53:27 +00:00
|
|
|
void addTooltipFor(Widget* widget, const std::string& text, int arrowAlign = 0);
|
2015-04-29 15:32:44 +00:00
|
|
|
void removeTooltipFor(Widget* widget);
|
2012-06-16 02:37:59 +00:00
|
|
|
|
|
|
|
protected:
|
2014-08-15 02:07:47 +00:00
|
|
|
bool onProcessMessage(Message* msg) override;
|
2017-08-15 13:39:06 +00:00
|
|
|
void onInitTheme(InitThemeEvent& ev) override;
|
2012-06-16 02:37:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void onTick();
|
|
|
|
|
|
|
|
struct TipInfo {
|
|
|
|
std::string text;
|
|
|
|
int arrowAlign;
|
|
|
|
|
|
|
|
TipInfo() { }
|
2014-04-20 22:53:27 +00:00
|
|
|
TipInfo(const std::string& text, int arrowAlign)
|
2012-06-16 02:37:59 +00:00
|
|
|
: text(text), arrowAlign(arrowAlign) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<Widget*, TipInfo> Tips;
|
|
|
|
Tips m_tips; // All tips.
|
2018-08-08 20:27:26 +00:00
|
|
|
std::unique_ptr<TipWindow> m_tipWindow; // Frame to show tooltips.
|
|
|
|
std::unique_ptr<Timer> m_timer; // Timer to control the tooltip delay.
|
2012-06-16 02:37:59 +00:00
|
|
|
struct {
|
|
|
|
Widget* widget;
|
|
|
|
TipInfo tipInfo;
|
|
|
|
} m_target;
|
|
|
|
};
|
|
|
|
|
2014-04-13 22:35:15 +00:00
|
|
|
class TipWindow : public PopupWindow {
|
2012-06-16 02:37:59 +00:00
|
|
|
public:
|
2015-12-10 19:50:16 +00:00
|
|
|
TipWindow(const std::string& text = "");
|
2012-06-16 02:37:59 +00:00
|
|
|
|
2017-02-17 17:18:47 +00:00
|
|
|
Style* arrowStyle() { return m_arrowStyle; }
|
|
|
|
void setArrowStyle(Style* style) { m_arrowStyle = style; }
|
|
|
|
|
2015-12-10 19:50:16 +00:00
|
|
|
int arrowAlign() const { return m_arrowAlign; }
|
|
|
|
const gfx::Rect& target() const { return m_target; }
|
2012-06-16 02:37:59 +00:00
|
|
|
|
2015-07-28 16:05:59 +00:00
|
|
|
void setCloseOnKeyDown(bool state);
|
|
|
|
|
2015-12-10 19:50:16 +00:00
|
|
|
// Returns false there is no enough screen space to show the
|
|
|
|
// window.
|
|
|
|
bool pointAt(int arrowAlign, const gfx::Rect& target);
|
2015-05-09 16:20:57 +00:00
|
|
|
|
2017-02-17 17:18:47 +00:00
|
|
|
TextBox* textBox() const { return m_textBox; }
|
|
|
|
|
2012-06-16 02:37:59 +00:00
|
|
|
protected:
|
2014-08-15 02:07:47 +00:00
|
|
|
bool onProcessMessage(Message* msg) override;
|
|
|
|
void onPaint(PaintEvent& ev) override;
|
2017-02-17 17:18:47 +00:00
|
|
|
void onBuildTitleLabel() override;
|
2012-06-16 02:37:59 +00:00
|
|
|
|
|
|
|
private:
|
2017-02-17 17:18:47 +00:00
|
|
|
Style* m_arrowStyle;
|
2012-06-16 02:37:59 +00:00
|
|
|
int m_arrowAlign;
|
2015-05-09 16:20:57 +00:00
|
|
|
gfx::Rect m_target;
|
2015-07-28 16:05:59 +00:00
|
|
|
bool m_closeOnKeyDown;
|
2017-02-17 17:18:47 +00:00
|
|
|
TextBox* m_textBox;
|
2012-06-16 02:37:59 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 01:02:54 +00:00
|
|
|
} // namespace ui
|
2008-02-29 19:29:49 +00:00
|
|
|
|
2009-08-17 21:38:00 +00:00
|
|
|
#endif
|