aseprite/src/ui/tooltips.h

93 lines
2.2 KiB
C
Raw Normal View History

// Aseprite UI Library
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
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"
#include "ui/popup_window.h"
#include "ui/timer.h"
2012-07-09 02:24:42 +00:00
#include "ui/window.h"
2008-02-10 18:49:12 +00:00
#include <map>
#include <memory>
namespace ui {
class TextBox;
class TipWindow;
class TooltipManager : public Widget {
public:
TooltipManager();
~TooltipManager();
void addTooltipFor(Widget* widget, const std::string& text, int arrowAlign = 0);
void removeTooltipFor(Widget* widget);
protected:
bool onProcessMessage(Message* msg) override;
void onInitTheme(InitThemeEvent& ev) override;
private:
void onTick();
struct TipInfo {
std::string text;
int arrowAlign;
TipInfo() { }
TipInfo(const std::string& text, int arrowAlign)
: text(text), arrowAlign(arrowAlign) {
}
};
typedef std::map<Widget*, TipInfo> Tips;
Tips m_tips; // All tips.
std::unique_ptr<TipWindow> m_tipWindow; // Frame to show tooltips.
std::unique_ptr<Timer> m_timer; // Timer to control the tooltip delay.
struct {
Widget* widget;
TipInfo tipInfo;
} m_target;
};
class TipWindow : public PopupWindow {
public:
TipWindow(const std::string& text = "");
Style* arrowStyle() { return m_arrowStyle; }
void setArrowStyle(Style* style) { m_arrowStyle = style; }
int arrowAlign() const { return m_arrowAlign; }
const gfx::Rect& target() const { return m_target; }
void setCloseOnKeyDown(bool state);
// Returns false there is no enough screen space to show the
// window.
bool pointAt(int arrowAlign, const gfx::Rect& target);
TextBox* textBox() const { return m_textBox; }
protected:
bool onProcessMessage(Message* msg) override;
void onPaint(PaintEvent& ev) override;
void onBuildTitleLabel() override;
private:
Style* m_arrowStyle;
int m_arrowAlign;
gfx::Rect m_target;
bool m_closeOnKeyDown;
TextBox* m_textBox;
};
} // namespace ui
2009-08-17 21:38:00 +00:00
#endif