2017-03-02 12:18:59 +08:00
|
|
|
#pragma once
|
|
|
|
#include "MiniEngine.h"
|
2017-04-06 12:32:07 +08:00
|
|
|
#include "MiniEngine_Event.h"
|
2017-04-06 21:53:53 +08:00
|
|
|
#include <string>
|
|
|
|
#include <list>
|
2017-03-02 12:18:59 +08:00
|
|
|
|
2017-03-02 13:13:05 +08:00
|
|
|
namespace MiniEngine
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Widget
|
|
|
|
{
|
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
class PosInfo
|
2017-03-02 12:18:59 +08:00
|
|
|
{
|
|
|
|
public:
|
2017-04-06 21:53:53 +08:00
|
|
|
double x,y;
|
|
|
|
double w,h;
|
2017-04-07 16:00:40 +08:00
|
|
|
Rect getRect(Rect Area);
|
2017-04-06 21:53:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PointInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
double x,y;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Forward Declaration
|
|
|
|
class Frame;
|
|
|
|
class Board;
|
2017-03-02 12:18:59 +08:00
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
class Brush : public Renderer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int copy(Texture t, Rect src, PosInfo dst);
|
|
|
|
int copyTo(Texture t, PosInfo dst);
|
|
|
|
int copyTo(Texture t, PointInfo lupoint);
|
2017-03-02 13:13:05 +08:00
|
|
|
int copyFill(Texture t,Rect src);
|
|
|
|
int copyFullFill(Texture t);
|
2017-04-06 21:53:53 +08:00
|
|
|
Rect getArea();
|
2017-04-07 16:00:40 +08:00
|
|
|
void setArea(Rect Area);
|
2017-03-02 21:00:53 +08:00
|
|
|
protected:
|
|
|
|
Brush(Renderer Rnd);
|
2017-04-06 21:53:53 +08:00
|
|
|
private:
|
|
|
|
Rect area;
|
|
|
|
friend class Frame;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BoardBase : public EventHandlerBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void draw(const Brush&)=0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Frame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Frame(Renderer,Rect);
|
|
|
|
void run();
|
|
|
|
void stop();
|
|
|
|
void needUpdate();
|
|
|
|
void add(Board*);
|
|
|
|
int remove(Board*);
|
|
|
|
private:
|
|
|
|
bool running;
|
|
|
|
bool update;
|
|
|
|
SDL_Event e;
|
|
|
|
std::list<Board*> _lst;
|
|
|
|
Brush brush;
|
|
|
|
};
|
|
|
|
|
2017-04-07 16:00:40 +08:00
|
|
|
class WidgetBase : public BoardBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Board* getBoard();
|
|
|
|
PosInfo info;
|
|
|
|
private:
|
|
|
|
Board* _parent;
|
|
|
|
friend class Board;
|
|
|
|
};
|
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
class Board : public BoardBase
|
|
|
|
{
|
|
|
|
public:
|
2017-04-07 16:00:40 +08:00
|
|
|
void add(Board*);
|
|
|
|
void add(WidgetBase*);
|
|
|
|
int remove(Board*);
|
|
|
|
int remove(WidgetBase*);
|
2017-04-06 21:53:53 +08:00
|
|
|
virtual void draw(const Brush&);
|
|
|
|
virtual bool event(const EventBase& ev) override;
|
2017-04-07 16:00:40 +08:00
|
|
|
Board* getParent();
|
2017-04-06 21:53:53 +08:00
|
|
|
Frame* getFrame();
|
|
|
|
PosInfo getPosInfo();
|
2017-03-02 12:18:59 +08:00
|
|
|
private:
|
2017-04-07 16:00:40 +08:00
|
|
|
std::list<Board*> _blst;
|
|
|
|
std::list<WidgetBase*> _wlst;
|
2017-04-06 21:53:53 +08:00
|
|
|
PosInfo info;
|
2017-04-07 16:00:40 +08:00
|
|
|
Board* _parent;
|
|
|
|
Frame* _frame;
|
|
|
|
friend class Frame;
|
2017-03-02 12:18:59 +08:00
|
|
|
};
|
|
|
|
|
2017-04-07 16:00:40 +08:00
|
|
|
|
2017-03-02 12:18:59 +08:00
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
class ButtonBase : public WidgetBase
|
2017-03-02 12:18:59 +08:00
|
|
|
{
|
2017-04-06 12:32:07 +08:00
|
|
|
protected:
|
2017-04-07 16:00:40 +08:00
|
|
|
ButtonBase();
|
|
|
|
void onPressed();
|
|
|
|
void onClick();
|
|
|
|
void onMouseOver();
|
|
|
|
void onMouseOut();
|
2017-04-06 21:53:53 +08:00
|
|
|
private:
|
2017-04-07 16:00:40 +08:00
|
|
|
/// Overrides, called by EventHandler::event()
|
2017-04-06 21:53:53 +08:00
|
|
|
virtual bool onMouseDown(const MouseButtonEvent&) override;
|
|
|
|
virtual bool onMouseUp(const MouseButtonEvent&) override;
|
|
|
|
virtual bool onMouseMotion(const MouseMotionEvent&) override;
|
|
|
|
|
|
|
|
int _status;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TextButton : public ButtonBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void setText(std::string Text);
|
|
|
|
std::string getText();
|
|
|
|
virtual void draw(const Brush&) override;
|
2017-03-02 21:59:29 +08:00
|
|
|
private:
|
2017-04-06 21:53:53 +08:00
|
|
|
std::string _word;
|
|
|
|
Texture _text;
|
2017-03-02 21:59:29 +08:00
|
|
|
};
|
|
|
|
|
2017-04-07 16:00:40 +08:00
|
|
|
class ColorButton : public ButtonBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RGBA normal,active,clicked;
|
|
|
|
virtual void draw(const Brush&) override;
|
|
|
|
protected:
|
|
|
|
void onPressed();
|
|
|
|
void onClick();
|
|
|
|
void onMouseOver();
|
|
|
|
void onMouseOut();
|
|
|
|
private:
|
|
|
|
int _colorstatus;
|
|
|
|
};
|
|
|
|
|
2017-04-23 22:00:59 +08:00
|
|
|
class ProcessBarBase : public WidgetBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int currentVal,maxVal;
|
|
|
|
ProcessBarBase();
|
|
|
|
virtual void draw(const Brush&) override;
|
|
|
|
};
|
|
|
|
|
2017-03-02 13:13:05 +08:00
|
|
|
}/// End of namespace MiniEngine::Widget
|
|
|
|
|
|
|
|
}/// End of namespace MiniEngine
|