132 lines
3 KiB
C++
132 lines
3 KiB
C++
#pragma once
|
|
|
|
#include "DiscretePoint.h"
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
class MouseEvent;
|
|
class KeyboardEvent;
|
|
class PaintEvent;
|
|
|
|
class VisualLayer;
|
|
class Color;
|
|
|
|
class Widget
|
|
{
|
|
public:
|
|
struct BoundaryOffset
|
|
{
|
|
bool operator==(const BoundaryOffset& rhs) const
|
|
{
|
|
return (mLeft == rhs.mLeft)
|
|
&& (mRight == rhs.mRight)
|
|
&& (mTop == rhs.mTop)
|
|
&& (mBottom == rhs.mBottom);
|
|
}
|
|
bool operator!=(const BoundaryOffset& rhs) const
|
|
{
|
|
return !operator==(rhs);
|
|
}
|
|
|
|
unsigned mLeft = 0;
|
|
unsigned mRight = 0;
|
|
unsigned mTop = 0;
|
|
unsigned mBottom = 0;
|
|
};
|
|
|
|
struct BoundedSize
|
|
{
|
|
bool operator==(const BoundedSize& rhs) const
|
|
{
|
|
return (mWidth == rhs.mWidth)
|
|
&& (mMaxWidth == rhs.mMaxWidth)
|
|
&& (mMinWidth == rhs.mMinWidth)
|
|
&& (mHeight == rhs.mHeight)
|
|
&& (mMaxHeight == rhs.mMaxHeight)
|
|
&& (mMinHeight == rhs.mMinHeight);
|
|
}
|
|
bool operator!=(const BoundedSize& rhs) const
|
|
{
|
|
return !operator==(rhs);
|
|
}
|
|
|
|
unsigned mWidth = 0;
|
|
unsigned mMaxWidth = 0;
|
|
unsigned mMinWidth = 0;
|
|
unsigned mHeight = 0;
|
|
unsigned mMaxHeight = 0;
|
|
unsigned mMinHeight = 0;
|
|
};
|
|
|
|
public:
|
|
|
|
Widget();
|
|
|
|
virtual ~Widget();
|
|
|
|
static std::unique_ptr<Widget> Create();
|
|
|
|
virtual void addWidget(std::unique_ptr<Widget> widget);
|
|
|
|
BoundedSize getSize() const;
|
|
|
|
std::vector<VisualLayer*> getLayers() const;
|
|
|
|
DiscretePoint getLocation() const;
|
|
|
|
virtual void onPaintEvent(const PaintEvent* event);
|
|
|
|
virtual bool onMouseEvent(const MouseEvent* event);
|
|
|
|
virtual bool onKeyboardEvent(const KeyboardEvent* event);
|
|
|
|
bool contains(const DiscretePoint& loc) const;
|
|
|
|
void setBackgroundColor(std::unique_ptr<Color> color);
|
|
|
|
void setBounds(unsigned width, unsigned height);
|
|
|
|
void setSize(const BoundedSize& size);
|
|
|
|
void setMargin(unsigned margin);
|
|
|
|
void setMargin(const BoundaryOffset& margin);
|
|
|
|
void setPadding(unsigned padding);
|
|
|
|
void setPadding(const BoundaryOffset& padding);
|
|
|
|
void setLocation(const DiscretePoint& loc);
|
|
|
|
void setVisible(bool visible);
|
|
|
|
protected:
|
|
virtual bool onMyKeyboardEvent(const KeyboardEvent* event);
|
|
|
|
virtual void onMyMouseEvent(const MouseEvent* event);
|
|
|
|
virtual void addChildLayers(const PaintEvent* event);
|
|
|
|
virtual void addBackground(const PaintEvent* event);
|
|
|
|
void addMyLayers();
|
|
|
|
bool needsUpdate() const;
|
|
|
|
protected:
|
|
DiscretePoint mLocation;
|
|
BoundedSize mSize;
|
|
BoundaryOffset mPadding;
|
|
BoundaryOffset mMargin;
|
|
std::vector<std::unique_ptr<VisualLayer> > mMyLayers;
|
|
std::vector<VisualLayer*> mLayers;
|
|
std::vector<std::unique_ptr<Widget> > mChildren;
|
|
unsigned mBorderThickness{0};
|
|
std::unique_ptr<Color> mBackgroundColor;
|
|
std::unique_ptr<Color> mBorderColor;
|
|
bool mVisible{false};
|
|
bool mDirty{true};
|
|
};
|
|
|
|
using WidgetUPtr = std::unique_ptr<Widget>;
|