Lephisto/src/gui_widget.h

53 lines
1.7 KiB
C++

#pragma once
#include "gui_events.h"
namespace Gui {
class Container;
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]) { pos[0] = m_size.x; pos[1] = m_size.y; }
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) { m_visible = false; }
bool IsVisible(void) { return m_visible; }
Container* GetParent(void) { return m_parent; }
void SetParent(Container* p) { m_parent = p; }
/* Event handlers should return false to stop propagating event. */
virtual bool OnMouseDown(MouseButtonEvent* e) { return false; }
virtual bool OnMouseUp(MouseButtonEvent* e) { return false; }
virtual void OnActivate(void) {}
/* 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_ALL = 0xffffffff
};
unsigned int GetEventMask(void) { return m_eventMask; }
protected:
unsigned int m_eventMask;
struct {
SDLKey sym;
SDLMod mod;
} m_shortcut;
private:
struct {
float x,y,w,h;
} m_size;
bool m_visible;
Container* m_parent;
};
}