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 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-03-02 13:12:41 +08:00
|
|
|
|
|
|
|
}/// End of namespace MiniEngine::Widget
|
|
|
|
|
|
|
|
}/// End of namespace MiniEngine::Widget
|