ultimatepp/rainbow/Telpp/TelDraw.cpp
cxl c50daeece4 rainbow: Developing tel++
git-svn-id: svn://ultimatepp.org/upp/trunk@6624 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2013-12-01 16:12:14 +00:00

69 lines
1.1 KiB
C++

#include "Telpp.h"
NAMESPACE_UPP
void SystemDraw::Put16(int x)
{
result.Cat(LOBYTE(x));
result.Cat(HIBYTE(x));
}
void SystemDraw::Put(Point p)
{// TODO: Clamp?
Put16(p.x);
Put16(p.y);
}
void SystemDraw::Put(Size sz)
{
Put((Point)sz);
}
void SystemDraw::Put(const Rect& r)
{
Put(r.TopLeft());
Put(r.GetSize());
}
Index<int64> SystemDraw::img_index;
int SystemDraw::GetImageI(SystemDraw& w, const Image& img)
{
int id = img.GetSerialId();
int q = img_index.Find(id);
if(q < 0) { // TODO: Implement some sort of victim elimination
q = img_index.GetCount();
img_index.Add(id);
w.Put8(SETIMAGE);
w.Put16(q);
w.Put(img.GetSize());
const RGBA *end = ~img + img.GetLength();
for(const RGBA *s = ~img; s < end; s++) {
w.Put8(s->r);
w.Put8(s->g);
w.Put8(s->b);
w.Put8(s->a);
}
}
return q;
}
void SystemDraw::PutImage(Point p, const Image& img, const Rect& src)
{
int i = GetImageI(*this, img);
Put8(IMAGE);
Put16(i);
Put(p);
Put(src);
}
void SystemDraw::PutRect(const Rect& r, Color color)
{ // TODO: Support InvertColor
Put8(RECT);
Put(r);
Put8(color.GetR());
Put8(color.GetG());
Put8(color.GetB());
}
END_UPP_NAMESPACE