[Update] Add ColorButton. Fix Frame,Board.

We have seperated the list in class Board to two.
New Button Class: ColorButton added.
This commit is contained in:
Kirigaya Kazuto 2017-04-07 16:00:40 +08:00
parent 4630a157dc
commit e5507cf505
2 changed files with 126 additions and 38 deletions

View File

@ -6,15 +6,16 @@ namespace MiniEngine
namespace Widget
{
Rect PosInfo::getRect(Rect SizeRect)
Rect PosInfo::getRect(Rect Area)
{
SizeRect.x*=x;
SizeRect.y*=y;
SizeRect.w*=w;
SizeRect.h*=h;
return SizeRect;
Area.x*=x;
Area.y*=y;
Area.w*=w;
Area.h*=h;
return Area;
}
void Brush::setArea(Rect Area)
{
area=Area;
@ -135,11 +136,13 @@ Frame::Frame(Renderer rnd,Rect Area) : brush(rnd)
void Frame::add(Board* p)
{
_lst.push_back(p);
p->_frame=this;
}
int Frame::remove(Board* p)
{
_lst.remove(p);
p->_frame=nullptr;
return 0;
}
@ -206,14 +209,29 @@ void Frame::needUpdate()
void Board::add(BoardBase* p)
void Board::add(Board* p)
{
_lst.push_back(p);
_blst.push_back(p);
p->_parent=this;
}
int Board::remove(BoardBase* p)
int Board::remove(Board* p)
{
_lst.remove(p);
_blst.remove(p);
p->_parent=nullptr;
return 0;
}
void Board::add(WidgetBase* p)
{
_wlst.push_back(p);
p->_parent=this;
}
int Board::remove(WidgetBase* p)
{
_wlst.remove(p);
p->_parent=nullptr;
return 0;
}
@ -225,34 +243,62 @@ PosInfo Board::getPosInfo()
void Board::draw(const Brush& b)
{
/// FIXME: Bug Found while trying to draw a Board in Board.
for(auto& p:_lst)
for(auto& p:_wlst)
{
p->draw(b);
}
Brush nb=b;
nb.setArea(info.getRect(nb.getArea()));
for(auto& p:_blst)
{
p->draw(nb);
}
}
bool Board::event(const EventBase& ev) /// virtual override
{
for(auto& p:_wlst)
{
if(p->event(ev)) return true;
}
for(auto& p:_blst)
{
if(p->event(ev)) return true;
}
return false;
}
bool ButtonBase::onClick()
ButtonBase::ButtonBase()
{
return false;
_status=0;
}
bool ButtonBase::onMouseOver()
void ButtonBase::onPressed()
{
return false;
}
bool ButtonBase::onMouseOut()
void ButtonBase::onClick()
{
return false;
}
void ButtonBase::onMouseOver()
{
}
void ButtonBase::onMouseOut()
{
}
bool ButtonBase::onMouseDown(const MouseButtonEvent& ev)
{
return false;
}
@ -280,9 +326,24 @@ std::string TextButton::getText()
void TextButton::draw(const Brush&)
{
/// FIXME: Unfinished TextButton::draw() due to Font loading in Frame.
printf("TextButton::draw()\n");
}
void ColorButton::draw(const Brush& b)
{
switch(_colorstatus)
{
case 0:/// Normal
/// How to fill rect with PosInfo and Brush...
break;
case 1:/// Active (MouseOver)
break;
case 2:/// Pressed Down (MouseUp)
break;
}
}
}/// End of namespace MiniEngine::Widget

View File

@ -15,7 +15,7 @@ class PosInfo
public:
double x,y;
double w,h;
Rect getRect(Rect SizeRect);
Rect getRect(Rect Area);
};
class PointInfo
@ -38,9 +38,9 @@ public:
int copyFill(Texture t,Rect src);
int copyFullFill(Texture t);
Rect getArea();
void setArea(Rect Area);
protected:
Brush(Renderer Rnd);
void setArea(Rect Area);
private:
Rect area;
friend class Frame;
@ -70,36 +70,49 @@ private:
Brush brush;
};
class Board : public BoardBase
{
public:
void add(BoardBase*);
int remove(BoardBase*);
virtual void draw(const Brush&);
virtual bool event(const EventBase& ev) override;
Frame* getFrame();
PosInfo getPosInfo();
private:
std::list<BoardBase*> _lst;
PosInfo info;
};
class WidgetBase : public BoardBase
{
public:
Board* getBoard();
protected:
PosInfo info;
private:
Board* _parent;
friend class Board;
};
class Board : public BoardBase
{
public:
void add(Board*);
void add(WidgetBase*);
int remove(Board*);
int remove(WidgetBase*);
virtual void draw(const Brush&);
virtual bool event(const EventBase& ev) override;
Board* getParent();
Frame* getFrame();
PosInfo getPosInfo();
private:
std::list<Board*> _blst;
std::list<WidgetBase*> _wlst;
PosInfo info;
Board* _parent;
Frame* _frame;
friend class Frame;
};
class ButtonBase : public WidgetBase
{
protected:
bool onClick();
bool onMouseOver();
bool onMouseOut();
ButtonBase();
void onPressed();
void onClick();
void onMouseOver();
void onMouseOut();
private:
/// Overrides
/// Overrides, called by EventHandler::event()
virtual bool onMouseDown(const MouseButtonEvent&) override;
virtual bool onMouseUp(const MouseButtonEvent&) override;
virtual bool onMouseMotion(const MouseMotionEvent&) override;
@ -118,6 +131,20 @@ private:
Texture _text;
};
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;
};
}/// End of namespace MiniEngine::Widget
}/// End of namespace MiniEngine