MiniEngine/MiniEngine_Widget.h

88 lines
1.6 KiB
C
Raw Normal View History

2017-03-02 12:18:59 +08:00
#pragma once
#include "MiniEngine.h"
#include <functional>
2017-03-02 21:59:29 +08:00
#include <vector>
2017-03-02 12:18:59 +08:00
2017-03-02 13:13:05 +08:00
namespace MiniEngine
{
namespace Widget
{
class Brush : public Renderer
2017-03-02 12:18:59 +08:00
{
public:
2017-03-02 13:13:05 +08:00
void setArea(Rect Area);
void setFullArea(Rect FullArea);
2017-03-02 12:18:59 +08:00
2017-03-02 13:13:05 +08:00
int copy(Texture t, Rect src, Rect dst);
int copyTo(Texture t, Rect dst);
int copyTo(Texture t, Point lupoint);
int copyFill(Texture t,Rect src);
int copyFullFill(Texture t);
2017-03-02 21:00:53 +08:00
protected:
Brush(Renderer Rnd);
2017-03-02 12:18:59 +08:00
private:
2017-03-02 13:13:05 +08:00
Rect area,fullarea;
2017-03-02 21:00:53 +08:00
friend class Board;
2017-03-02 12:18:59 +08:00
};
class Drawable
{
public:
virtual void draw(Brush& brush)=0;
virtual ~Drawable()=default;
};
class Interactive
{
public:
2017-03-02 21:00:53 +08:00
virtual int handle(SDL_Event e,int& running,int& update)=0;
2017-03-02 12:18:59 +08:00
};
class ButtonBase : public Drawable, public Interactive
{
public:
ButtonBase();
2017-03-02 13:13:05 +08:00
void setTextureNormal(Texture Normal);
void setTextureMouseover(Texture Mouseover);
void setTextureClicked(Texture Clicked);
void setRect(Rect SensorArea);
2017-03-02 12:18:59 +08:00
virtual void draw(Brush& brush);
2017-03-02 21:00:53 +08:00
virtual int handle(SDL_Event e,int& running,int& update);
std::function<void()> onmouseover,onclicked,onrelease,onmouseout;
2017-03-02 12:18:59 +08:00
private:
int status;
2017-03-02 13:13:05 +08:00
Texture t1,t2,t3;
Rect rect;
2017-03-02 12:18:59 +08:00
};
2017-03-02 13:13:05 +08:00
2017-03-02 21:59:29 +08:00
class Board
{
public:
Board(Renderer Rnd,Rect Area);
Brush getBrush();
Rect getArea();
class _Control
{
public:
void add(Interactive* widget);
Interactive* at(int index);
int size();
bool remove(Interactive* widget);
private:
std::vector<Interactive*> vec;
}Control;
private:
Rect area;
Brush brush;
};
2017-03-02 13:13:05 +08:00
}/// End of namespace MiniEngine::Widget
}/// End of namespace MiniEngine