Lephisto/src/gui_widget.h
Rtch90 fecd2866f5 [Add] Gui Tooltips.
[Clean] Cleaned up GUI::Screen.
2018-04-14 19:30:27 +01:00

70 lines
2.4 KiB
C++

#pragma once
#include "gui_events.h"
namespace Gui {
class Container;
class ToolTip;
class Widget {
public:
Widget(void);
virtual void Draw(void) = 0;
virtual ~Widget(void);
virtual void GetSizeRequested(float size[2]) = 0;
void GetPosition(float pos[2]) const { pos[0] = m_size.x; pos[1] = m_size.y; }
void GetAbsolutePosition(float pos[2]);
void SetPosition(float x, float y) { m_size.x = x; m_size.y = y; }
void GetSize(float size[2]) { size[0] = m_size.w; size[1] = m_size.h; }
void SetSize(float w, float h) { m_size.w = w; m_size.h = h; };
void SetShortcut(SDLKey key, SDLMod mod);
virtual void Show(void) { m_visible = true; }
virtual void Hide(void);
bool IsVisible(void) { return m_visible; }
Container* GetParent(void) const { return m_parent; }
void SetParent(Container* p) { m_parent = p; }
void SetToolTip(std::string s) { m_tooltip = s; }
const std::string& GetToolTip(void) const { return m_tooltip; }
/* Event handlers should return false to stop propagating event. */
virtual bool OnMouseDown(MouseButtonEvent* e) { return false; }
virtual bool OnMouseUp(MouseButtonEvent* e) { return false; }
virtual bool OnMouseMotion(MouseMotionEvent* e) { return true; }
virtual void OnActivate(void) { }
virtual void OnMouseEnter(void);
virtual void OnMouseLeave(void);
bool IsMouseOver(void) { return m_mouseOver; }
/* Only to be called by Screen::OnKeyDown. */
void OnPreShortcut(const SDL_keysym* sym);
enum EventMask {
EVENT_NONE = 0,
EVENT_KEYDOWN = 1<<0,
EVENT_KEYUP = 1<<1,
EVENT_MOUSEDOWN = 1<<2,
EVENT_MOUSEUP = 1<<3,
EVENT_MOUSEMOTION = 1<<4, /* Needed for OnMouseEnter, Leave, IsMOuseOver. */
EVENT_ALL = 0xffffffff
};
unsigned int GetEventMask(void) { return m_eventMask; }
protected:
unsigned int m_eventMask;
struct {
SDLKey sym;
SDLMod mod;
} m_shortcut;
virtual std::string GetOverrideTooltip(void) { return ""; }
void UpdateOverriddenTooltip(void);
private:
struct {
float x,y,w,h;
} m_size;
bool m_visible;
bool m_mouseOver;
Container* m_parent;
std::string m_tooltip;
sigc::signal<void> m_tooltipTimerSignal;
ToolTip* m_tooltipWidget;
void OnToolTip();
};
}