2017-03-02 12:19:13 +08:00
|
|
|
#include "MiniEngine_Widget.h"
|
|
|
|
using namespace MiniEngine;
|
|
|
|
|
2017-03-02 13:12:41 +08:00
|
|
|
namespace MiniEngine
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Widget
|
|
|
|
{
|
|
|
|
|
2017-03-02 12:19:13 +08:00
|
|
|
void Brush::setArea(Rect Area)
|
|
|
|
{
|
|
|
|
area=Area;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Brush::copy(Texture t,Rect src,Rect dst)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Brush::copyTo(Texture t,Rect dst)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int Brush::copyTo(Texture t,Point lupoint)
|
|
|
|
{
|
|
|
|
return copyTo(t,Rect(lupoint.x,lupoint.y,t.getw(),t.geth()));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 13:12:41 +08:00
|
|
|
Board::Board(Rect Area)
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
|
|
|
area=Area;
|
|
|
|
}
|
|
|
|
|
|
|
|
Brush Board::getBrush()
|
|
|
|
{
|
|
|
|
Brush b;
|
2017-03-02 13:12:41 +08:00
|
|
|
b.setArea(area);
|
2017-03-02 12:19:13 +08:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2017-03-02 13:12:41 +08:00
|
|
|
Rect Board::getArea()
|
|
|
|
{
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-02 12:19:13 +08:00
|
|
|
ButtonBase::ButtonBase()
|
|
|
|
{
|
|
|
|
status=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonBase::setTextureClicked(Texture Clicked)
|
|
|
|
{
|
|
|
|
t3=Clicked;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonBase::setTextureMouseover(Texture Mouseover)
|
|
|
|
{
|
|
|
|
t2=Mouseover;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonBase::setTextureNormal(Texture Normal)
|
|
|
|
{
|
|
|
|
t1=Normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonBase::setRect(Rect SensorArea)
|
|
|
|
{
|
|
|
|
rect=SensorArea;
|
|
|
|
}
|
|
|
|
|
2017-03-02 13:12:41 +08:00
|
|
|
void ButtonBase::draw(Brush& brush) /// virtual
|
2017-03-02 12:19:13 +08:00
|
|
|
{
|
|
|
|
switch(status)
|
|
|
|
{
|
|
|
|
case 0:
|
2017-03-02 13:12:41 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
break;
|
2017-03-02 12:19:13 +08:00
|
|
|
}
|
|
|
|
}
|
2017-03-02 13:12:41 +08:00
|
|
|
|
|
|
|
void ButtonBase::handle(SDL_Event e,int& running,int& update) /// virtual
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}/// End of namespace MiniEngine::Widget
|
|
|
|
|
|
|
|
}/// End of namespace MiniEngine::Widget
|