2017-03-02 12:19:13 +08:00
|
|
|
#include "MiniEngine_Widget.h"
|
2017-04-25 12:10:06 +08:00
|
|
|
#include <algorithm>
|
2017-03-02 12:19:13 +08:00
|
|
|
|
2017-03-02 13:12:41 +08:00
|
|
|
namespace MiniEngine
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Widget
|
|
|
|
{
|
|
|
|
|
2017-04-07 16:00:40 +08:00
|
|
|
Rect PosInfo::getRect(Rect Area)
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-25 10:22:21 +08:00
|
|
|
Rect NewArea;
|
|
|
|
NewArea.x=Area.x+Area.w*x;
|
|
|
|
NewArea.y=Area.y+Area.h*y;
|
|
|
|
NewArea.w=Area.w*w;
|
|
|
|
NewArea.h=Area.h*h;
|
|
|
|
return NewArea;
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
|
|
|
|
2017-04-07 16:00:40 +08:00
|
|
|
|
2017-03-02 12:19:13 +08:00
|
|
|
void Brush::setArea(Rect Area)
|
|
|
|
{
|
|
|
|
area=Area;
|
|
|
|
}
|
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
Rect Brush::getArea()
|
|
|
|
{
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Brush::copy(Texture t,Rect src,PosInfo dst_posinfo)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-04-06 21:53:53 +08:00
|
|
|
Rect dst=dst_posinfo.getRect(area);
|
2017-03-02 12:19:13 +08:00
|
|
|
dst.x+=area.x;
|
|
|
|
dst.y+=area.y;
|
2017-03-02 13:12:41 +08:00
|
|
|
|
|
|
|
if(dst.x>area.x+area.w||dst.y>area.y+area.h)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-03-02 13:12:41 +08:00
|
|
|
/// Not Printed.
|
|
|
|
return 1;
|
2017-03-02 12:19:13 +08:00
|
|
|
}
|
2017-03-02 13:12:41 +08:00
|
|
|
|
|
|
|
if(dst.x+dst.w>area.x+area.w)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-03-02 13:12:41 +08:00
|
|
|
/// Some parts will not be printed.
|
|
|
|
src.w=src.w*(area.w-dst.x+area.x)/dst.w;
|
|
|
|
|
|
|
|
dst.w=area.w-(dst.x-area.x);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dst.y+dst.h>area.y+area.h)
|
|
|
|
{
|
|
|
|
/// Some parts will not be printed
|
|
|
|
src.h=src.h*(area.h-dst.y+area.y)/dst.h;
|
|
|
|
|
|
|
|
dst.h=area.h-(dst.y-area.y);
|
2017-03-02 12:19:13 +08:00
|
|
|
}
|
2017-03-02 13:12:41 +08:00
|
|
|
|
2017-03-02 12:19:13 +08:00
|
|
|
return Renderer::copy(t,src,dst);
|
|
|
|
}
|
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
int Brush::copyTo(Texture t,PosInfo dst_posinfo)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-04-06 21:53:53 +08:00
|
|
|
Rect dst=dst_posinfo.getRect(area);
|
2017-03-02 12:19:13 +08:00
|
|
|
dst.x+=area.x;
|
|
|
|
dst.y+=area.y;
|
|
|
|
|
2017-03-02 13:12:41 +08:00
|
|
|
if(dst.x>area.x+area.w||dst.y>area.y+area.h)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-03-02 13:12:41 +08:00
|
|
|
/// Not Printed.
|
|
|
|
return 1;
|
2017-03-02 12:19:13 +08:00
|
|
|
}
|
2017-03-02 13:12:41 +08:00
|
|
|
|
|
|
|
if(dst.x+dst.w>area.x+area.w||dst.y+dst.h>area.y+area.h)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-03-02 13:12:41 +08:00
|
|
|
/// Some parts will not be printed.
|
2017-03-02 12:19:13 +08:00
|
|
|
Rect src=t.getSize();
|
|
|
|
src.x=src.y=0;
|
2017-03-02 13:12:41 +08:00
|
|
|
|
|
|
|
if(dst.x+dst.w>area.x+area.w)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-03-02 13:12:41 +08:00
|
|
|
src.w=src.w*(area.w-dst.x+area.x)/dst.w;
|
|
|
|
|
|
|
|
dst.w=area.w-(dst.x-area.x);
|
2017-03-02 12:19:13 +08:00
|
|
|
}
|
2017-03-02 13:12:41 +08:00
|
|
|
|
|
|
|
if(dst.y+dst.h>area.y+area.h)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-03-02 13:12:41 +08:00
|
|
|
src.h=src.h*(area.h-dst.y+area.y)/dst.h;
|
|
|
|
|
|
|
|
dst.h=area.h-(dst.y-area.y);
|
2017-03-02 12:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Renderer::copy(t,src,dst);
|
|
|
|
}
|
2017-03-02 13:12:41 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return Renderer::copyTo(t,dst);
|
|
|
|
}
|
2017-03-02 12:19:13 +08:00
|
|
|
}
|
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
int Brush::copyTo(Texture t,PointInfo lupoint)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-04-06 21:53:53 +08:00
|
|
|
PosInfo pos;
|
|
|
|
pos.x=lupoint.x;
|
|
|
|
pos.y=lupoint.y;
|
|
|
|
pos.w=(double)t.getw()/area.w;
|
|
|
|
pos.h=(double)t.geth()/area.h;
|
|
|
|
return copyTo(t,pos);
|
2017-03-02 12:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Brush::copyFill(Texture t,Rect src)
|
|
|
|
{
|
|
|
|
Rect dst=area;
|
|
|
|
return Renderer::copy(t,src,dst);
|
|
|
|
}
|
|
|
|
|
2017-03-02 13:12:41 +08:00
|
|
|
int Brush::copyFullFill(Texture t)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
|
|
|
Rect dst=area;
|
|
|
|
return Renderer::copyTo(t,dst);
|
|
|
|
}
|
|
|
|
|
2017-03-02 21:00:53 +08:00
|
|
|
Brush::Brush(Renderer Rnd) : Renderer(Rnd)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
2017-03-02 21:00:53 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-24 10:32:00 +08:00
|
|
|
int Brush::fillRect(PosInfo info)
|
|
|
|
{
|
|
|
|
return Renderer::fillRect(info.getRect(area));
|
|
|
|
}
|
|
|
|
|
2017-03-02 21:00:53 +08:00
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
SDL_Event _WidgetEventBase::getRealEvent()
|
|
|
|
{
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _PositionEvent::updatePos(int X,int Y,Rect Area)
|
|
|
|
{
|
|
|
|
printf("PositionEvent::updatePos(%d,%d,Rect:%d %d %d %d)\n",X,Y,Area.x,Area.y,Area.w,Area.h);
|
|
|
|
x=(double)(X-Area.x)/Area.w;
|
|
|
|
y=(double)(Y-Area.y)/Area.h;
|
|
|
|
printf("Position: %.2f %.2f\n",x,y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MouseButtonEvent::update(const MiniEngine::EventSystem::MouseButtonEvent& ev,Rect Area)
|
|
|
|
{
|
|
|
|
updatePos(ev.x,ev.y,Area);
|
|
|
|
button=ev.button;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MouseMotionEvent::update(const MiniEngine::EventSystem::MouseMotionEvent& ev,Rect Area)
|
|
|
|
{
|
|
|
|
updatePos(ev.x,ev.y,Area);
|
|
|
|
}
|
2017-03-02 13:12:41 +08:00
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
void KeyEvent::update(const MiniEngine::EventSystem::KeyEvent& ev)
|
|
|
|
{
|
|
|
|
key=ev.key;
|
|
|
|
}
|
2017-04-06 21:53:53 +08:00
|
|
|
|
|
|
|
Frame::Frame(Renderer rnd,Rect Area) : brush(rnd)
|
|
|
|
{
|
|
|
|
brush.setArea(Area);
|
|
|
|
update=running=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Frame::add(Board* p)
|
|
|
|
{
|
|
|
|
_lst.push_back(p);
|
2017-04-25 12:10:06 +08:00
|
|
|
p->setFrame(this);
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Frame::remove(Board* p)
|
|
|
|
{
|
|
|
|
_lst.remove(p);
|
2017-04-25 12:10:06 +08:00
|
|
|
p->setFrame(nullptr);
|
2017-04-06 21:53:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Frame::run()
|
|
|
|
{
|
|
|
|
while(running)
|
|
|
|
{
|
|
|
|
while(!update&&SDL_WaitEvent(&e))
|
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
MiniEngine::EventSystem::EventBase x(e);
|
2017-04-06 21:53:53 +08:00
|
|
|
bool dealed=false;
|
|
|
|
if(!_lst.empty())
|
|
|
|
{
|
|
|
|
for(auto iter=_lst.rbegin();iter!=_lst.rend();++iter)
|
|
|
|
{
|
|
|
|
if((dealed=(*iter)->event(x))) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// If Message Not Solved, Try to Solve it here. (Maybe System Message)
|
|
|
|
if(!dealed)
|
|
|
|
{
|
|
|
|
switch(e.type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT:
|
|
|
|
stop();
|
|
|
|
needUpdate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
brush.clear();
|
|
|
|
|
|
|
|
if(!_lst.empty())
|
|
|
|
{
|
|
|
|
for(auto iter=_lst.rbegin();iter!=_lst.rend();++iter)
|
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
(*iter)->_realrect=(*iter)->info.getRect(brush.getArea());
|
|
|
|
(*iter)->draw(brush);
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
brush.update();
|
|
|
|
|
|
|
|
update=false;
|
|
|
|
|
|
|
|
printf("Looped\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Frame::stop()
|
|
|
|
{
|
|
|
|
running=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Frame::needUpdate()
|
|
|
|
{
|
|
|
|
update=true;
|
|
|
|
}
|
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
//private virtual override
|
|
|
|
bool BoardBase::onMouseDown(const MiniEngine::EventSystem::MouseButtonEvent& ev)
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
MouseButtonEvent e;
|
|
|
|
e.update(ev,_realrect);
|
|
|
|
return onMouseDown(e);
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
2017-04-25 12:10:06 +08:00
|
|
|
//private virtual override
|
|
|
|
bool BoardBase::onMouseUp(const MiniEngine::EventSystem::MouseButtonEvent& ev)
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
MouseButtonEvent e;
|
|
|
|
e.update(ev,_realrect);
|
|
|
|
return onMouseUp(e);
|
2017-04-07 16:00:40 +08:00
|
|
|
}
|
2017-04-25 12:10:06 +08:00
|
|
|
//private virtual override
|
|
|
|
bool BoardBase::onMouseMotion(const MiniEngine::EventSystem::MouseMotionEvent& ev)
|
|
|
|
{
|
|
|
|
MouseMotionEvent e;
|
|
|
|
e.update(ev,_realrect);
|
|
|
|
return onMouseMotion(e);
|
|
|
|
}
|
|
|
|
//private virtual override
|
|
|
|
bool BoardBase::onKeyDown(const MiniEngine::EventSystem::KeyEvent& ev)
|
|
|
|
{
|
|
|
|
KeyEvent e;
|
|
|
|
e.update(ev);
|
|
|
|
return onKeyDown(e);
|
|
|
|
}
|
|
|
|
//private virtual override
|
|
|
|
bool BoardBase::onKeyUp(const MiniEngine::EventSystem::KeyEvent& ev)
|
|
|
|
{
|
|
|
|
KeyEvent e;
|
|
|
|
e.update(ev);
|
|
|
|
return onKeyUp(e);
|
|
|
|
}
|
|
|
|
//protected virtual
|
|
|
|
bool BoardBase::onMouseDown(const MouseButtonEvent& ev)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//protected virtual
|
|
|
|
bool BoardBase::onMouseUp(const MouseButtonEvent& ev)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//protected virtual
|
|
|
|
bool BoardBase::onMouseMotion(const MouseMotionEvent& ev)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//protected virtual
|
|
|
|
bool BoardBase::onKeyDown(const KeyEvent& ev)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//protected virtual
|
|
|
|
bool BoardBase::onKeyUp(const KeyEvent& ev)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Frame* BoardBase::getFrame()
|
|
|
|
{
|
|
|
|
return _frame;
|
|
|
|
}
|
|
|
|
BoardBase* BoardBase::getParent()
|
2017-04-07 16:00:40 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
return _parent;
|
|
|
|
}
|
|
|
|
//virtual
|
|
|
|
void BoardBase::setFrame(Frame* pFrame)
|
|
|
|
{
|
|
|
|
_frame=pFrame;
|
|
|
|
}
|
|
|
|
//virtual
|
|
|
|
void BoardBase::setParent(BoardBase* pBoardBase)
|
|
|
|
{
|
|
|
|
_parent=pBoardBase;
|
2017-04-07 16:00:40 +08:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
Board::Board()
|
2017-04-07 16:00:40 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
setParent(nullptr);
|
|
|
|
setFrame(nullptr);
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
void Board::add(BoardBase* p)
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
_lst.push_back(p);
|
|
|
|
p->setParent(this);
|
|
|
|
p->setFrame(getFrame());
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
bool Board::remove(BoardBase* p)
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
if(std::find(_lst.begin(),_lst.end(),p)!=_lst.end())
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
_lst.remove(p);
|
|
|
|
p->setParent(nullptr);
|
|
|
|
p->setFrame(nullptr);
|
|
|
|
return true;
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
2017-04-25 12:10:06 +08:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-07 16:00:40 +08:00
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
void Board::draw(Brush& b)
|
|
|
|
{
|
2017-04-07 16:00:40 +08:00
|
|
|
Brush nb=b;
|
2017-04-25 12:10:06 +08:00
|
|
|
nb.setArea(_realrect);
|
|
|
|
for(auto& p:_lst)
|
2017-04-07 16:00:40 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
p->_realrect=p->info.getRect(_realrect);
|
2017-04-07 16:00:40 +08:00
|
|
|
p->draw(nb);
|
|
|
|
}
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
bool Board::event(const MiniEngine::EventSystem::EventBase& ev) /// virtual override
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
for(auto& p:_lst)
|
2017-04-07 16:00:40 +08:00
|
|
|
{
|
|
|
|
if(p->event(ev)) return true;
|
|
|
|
}
|
2017-04-25 12:10:06 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//virtual override
|
|
|
|
void Board::setFrame(Frame* pFrame)
|
|
|
|
{
|
|
|
|
_frame=pFrame;
|
|
|
|
for(auto& p:_lst)
|
2017-04-07 16:00:40 +08:00
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
p->setFrame(pFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//virtual override
|
|
|
|
void Board::setParent(BoardBase* pBoardBase)
|
|
|
|
{
|
|
|
|
_parent=pBoardBase;
|
|
|
|
for(auto& p:_lst)
|
|
|
|
{
|
|
|
|
p->setParent(pBoardBase);
|
2017-04-07 16:00:40 +08:00
|
|
|
}
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
|
|
|
|
2017-04-07 16:00:40 +08:00
|
|
|
ButtonBase::ButtonBase()
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-07 16:00:40 +08:00
|
|
|
_status=0;
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
void ButtonBase::onRelease()
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-07 16:00:40 +08:00
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
|
|
|
|
2017-04-07 16:00:40 +08:00
|
|
|
void ButtonBase::onClick()
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-07 16:00:40 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonBase::onMouseOver()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonBase::onMouseOut()
|
|
|
|
{
|
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
}
|
2017-04-25 12:10:06 +08:00
|
|
|
//private override
|
2017-04-06 21:53:53 +08:00
|
|
|
bool ButtonBase::onMouseDown(const MouseButtonEvent& ev)
|
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
if(_status==1&&ev.x>0&&ev.y>0&&ev.x<1&&ev.y<1)
|
|
|
|
{
|
|
|
|
_status=2;
|
|
|
|
onClick();
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-06 21:53:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-25 12:10:06 +08:00
|
|
|
//private override
|
2017-04-06 21:53:53 +08:00
|
|
|
bool ButtonBase::onMouseUp(const MouseButtonEvent& ev)
|
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
if(_status==2&&ev.x>0&&ev.y>0&&ev.x<1&&ev.y<1)
|
|
|
|
{
|
|
|
|
_status=1;
|
|
|
|
onRelease();
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-06 21:53:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-25 12:10:06 +08:00
|
|
|
//private override
|
2017-04-06 21:53:53 +08:00
|
|
|
bool ButtonBase::onMouseMotion(const MouseMotionEvent& ev)
|
|
|
|
{
|
2017-04-25 12:10:06 +08:00
|
|
|
if(_status==0&&ev.x>0&&ev.y>0&&ev.x<1&&ev.y<1)
|
|
|
|
{
|
|
|
|
_status=1;
|
|
|
|
onMouseOver();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(_status==1&&!(ev.x>0&&ev.y>0&&ev.x<1&&ev.y<1))
|
|
|
|
{
|
|
|
|
_status=0;
|
|
|
|
onMouseOut();
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-06 21:53:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextButton::setText(std::string Text)
|
|
|
|
{
|
|
|
|
if(Text==_word) return;
|
|
|
|
_word=Text;
|
|
|
|
/// TODO: How to Render...
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TextButton::getText()
|
|
|
|
{
|
|
|
|
return _word;
|
|
|
|
}
|
|
|
|
|
2017-04-24 10:32:00 +08:00
|
|
|
void TextButton::draw(Brush&)
|
2017-04-06 21:53:53 +08:00
|
|
|
{
|
2017-04-07 16:00:40 +08:00
|
|
|
/// FIXME: Unfinished TextButton::draw() due to Font loading in Frame.
|
2017-04-06 21:53:53 +08:00
|
|
|
printf("TextButton::draw()\n");
|
|
|
|
}
|
|
|
|
|
2017-04-25 12:10:06 +08:00
|
|
|
void ColorButton::onRelease()
|
|
|
|
{
|
|
|
|
getFrame()->needUpdate();
|
|
|
|
}
|
|
|
|
void ColorButton::onClick()
|
|
|
|
{
|
|
|
|
getFrame()->needUpdate();
|
|
|
|
}
|
|
|
|
void ColorButton::onMouseOver()
|
|
|
|
{
|
|
|
|
getFrame()->needUpdate();
|
|
|
|
}
|
|
|
|
void ColorButton::onMouseOut()
|
|
|
|
{
|
|
|
|
getFrame()->needUpdate();
|
|
|
|
}
|
2017-04-24 10:32:00 +08:00
|
|
|
void ColorButton::draw(Brush& b)
|
2017-04-07 16:00:40 +08:00
|
|
|
{
|
2017-04-24 10:32:00 +08:00
|
|
|
RGBA td=b.getColor();
|
2017-04-25 12:10:06 +08:00
|
|
|
switch(_status)
|
2017-04-07 16:00:40 +08:00
|
|
|
{
|
|
|
|
case 0:/// Normal
|
2017-04-24 10:32:00 +08:00
|
|
|
b.setColor(normal);
|
|
|
|
b.fillRect(info);
|
2017-04-07 16:00:40 +08:00
|
|
|
break;
|
|
|
|
case 1:/// Active (MouseOver)
|
2017-04-24 10:32:00 +08:00
|
|
|
b.setColor(active);
|
|
|
|
b.fillRect(info);
|
2017-04-07 16:00:40 +08:00
|
|
|
break;
|
|
|
|
case 2:/// Pressed Down (MouseUp)
|
2017-04-25 12:10:06 +08:00
|
|
|
b.setColor(clicked);
|
2017-04-24 10:32:00 +08:00
|
|
|
b.fillRect(info);
|
2017-04-07 16:00:40 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-04-24 10:32:00 +08:00
|
|
|
b.setColor(td);
|
2017-04-07 16:00:40 +08:00
|
|
|
}
|
|
|
|
|
2017-04-06 21:53:53 +08:00
|
|
|
|
2017-03-02 13:12:41 +08:00
|
|
|
}/// End of namespace MiniEngine::Widget
|
|
|
|
|
|
|
|
}/// End of namespace MiniEngine::Widget
|