CtrlCore: Extended SetSurface

git-svn-id: svn://ultimatepp.org/upp/trunk@1465 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-08-02 10:11:32 +00:00
commit c701b7ae38
9 changed files with 187 additions and 90 deletions

View file

@ -88,12 +88,18 @@ HBITMAP CreateBitMask(const RGBA *data, Size sz, Size tsz, Size csz, RGBA *ct)
return ::CreateBitmap(tsz.cx, tsz.cy, 1, 1, mask);
}
void SetSurface(HDC dc, int x, int y, int cx, int cy, const RGBA *pixels)
void SetSurface(HDC dc, const Rect& dest, const RGBA *pixels, Size srcsz, Point srcoff)
{
GuiLock __;
BitmapInfo32__ bi(cx, cy);
::SetDIBitsToDevice(dc, x, y, cx, cy, 0, 0, 0, cy, pixels,
bi, DIB_RGB_COLORS);
BitmapInfo32__ bi(srcsz.cx, srcsz.cy);
::SetDIBitsToDevice(dc, dest.left, dest.top, dest.GetWidth(), dest.GetHeight(),
srcoff.x, -srcoff.y - dest.Height() + srcsz.cy, 0, srcsz.cy, pixels, bi,
DIB_RGB_COLORS);
}
void SetSurface(HDC dc, int x, int y, int cx, int cy, const RGBA *pixels)
{
SetSurface(dc, RectC(x, y, cx, cy), pixels, Size(cx, cy), Point(0, 0));
}
void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels)
@ -101,6 +107,11 @@ void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels)
SetSurface(w.GetHandle(), x, y, cx, cy, pixels);
}
void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size psz, Point poff)
{
SetSurface(w.GetHandle(), dest, pixels, psz, poff);
}
class DrawSurface : NoCopy {
int x, y;
Size size;

View file

@ -1,83 +1,108 @@
#include "SystemDraw.h"
NAMESPACE_UPP
#define LTIMING(x)
void SystemDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color)
{
GuiLock __;
LTIMING("DrawImageOp");
bool tonative = !IsNative();
if(tonative) {
BeginNative();
Native(x, y);
Native(cx, cy);
}
Size sz = Size(cx, cy);
if((cx > 2000 || cy > 1500) && IsNull(color) && IsPrinter()) {
int yy = 0;
ImageRaster ir(img);
RescaleImage rm;
rm.Create(Size(cx, cy), ir, src);
while(yy < cy) {
int ccy = min(cy - yy, 16);
ImageBuffer ib(cx, ccy);
for(int q = 0; q < ccy; q++)
rm.Get(ib[q]);
DrawImageBandRLE(*this, x, y + yy, ib, 16);
yy += ccy;
}
}
else
if(src.GetSize() == sz)
img.PaintImage(*this, x, y, src, color);
else {
Image h = Rescale(img, Size(cx, cy), src);
h.PaintImage(*this, x, y, h.GetSize(), color);
}
if(tonative)
EndNative();
}
Draw& ImageDraw::Alpha()
{
if(!has_alpha) {
alpha.DrawRect(size, GrayColor(0));
has_alpha = true;
}
return alpha;
}
ImageBuffer::ImageBuffer(ImageDraw& iw)
{
Image m = iw;
Set(m);
}
void ImageAnyDrawSystem(Draw *(*f)(Size sz), Image (*e)(Draw *w));
static Draw *sCD(Size sz)
{
return new ImageDraw(sz);
}
static Image sED(Draw *w)
{
ImageDraw *ip = dynamic_cast<ImageDraw *>(w);
return ip ? (Image)(*ip) : Image();
}
void InstallSystemImage()
{
Image::Data::InitSystemImage(&Image::Data::SysInitImp, &Image::Data::SysReleaseImp,
&Image::Data::GetResCountImp, &Image::Data::PaintImp);
}
INITBLOCK {
ImageAnyDrawSystem(sCD, sED);
InstallSystemImage();
}
END_UPP_NAMESPACE
#include "SystemDraw.h"
NAMESPACE_UPP
#define LTIMING(x)
void SystemDraw::DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color)
{
GuiLock __;
LTIMING("DrawImageOp");
bool tonative = !IsNative();
if(tonative) {
BeginNative();
Native(x, y);
Native(cx, cy);
}
Size sz = Size(cx, cy);
if((cx > 2000 || cy > 1500) && IsNull(color) && IsPrinter()) {
int yy = 0;
ImageRaster ir(img);
RescaleImage rm;
rm.Create(Size(cx, cy), ir, src);
while(yy < cy) {
int ccy = min(cy - yy, 16);
ImageBuffer ib(cx, ccy);
for(int q = 0; q < ccy; q++)
rm.Get(ib[q]);
DrawImageBandRLE(*this, x, y + yy, ib, 16);
yy += ccy;
}
}
else
if(src.GetSize() == sz)
img.PaintImage(*this, x, y, src, color);
else {
Image h = Rescale(img, Size(cx, cy), src);
h.PaintImage(*this, x, y, h.GetSize(), color);
}
if(tonative)
EndNative();
}
Draw& ImageDraw::Alpha()
{
if(!has_alpha) {
alpha.DrawRect(size, GrayColor(0));
has_alpha = true;
}
return alpha;
}
ImageBuffer::ImageBuffer(ImageDraw& iw)
{
Image m = iw;
Set(m);
}
void ImageAnyDrawSystem(Draw *(*f)(Size sz), Image (*e)(Draw *w));
static Draw *sCD(Size sz)
{
return new ImageDraw(sz);
}
static Image sED(Draw *w)
{
ImageDraw *ip = dynamic_cast<ImageDraw *>(w);
return ip ? (Image)(*ip) : Image();
}
void InstallSystemImage()
{
Image::Data::InitSystemImage(&Image::Data::SysInitImp, &Image::Data::SysReleaseImp,
&Image::Data::GetResCountImp, &Image::Data::PaintImp);
}
INITBLOCK {
ImageAnyDrawSystem(sCD, sED);
InstallSystemImage();
}
void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels);
void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size psz, Point poff);
void SetSurface(Draw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff)
{
SystemDraw *sw = dynamic_cast<SystemDraw *>(&w);
if(sw && sw->IsGui() && IsWinNT())
SetSurface(*sw, dest, pixels, srcsz, poff);
else {
ImageBuffer ib(dest.GetWidth(), dest.GetHeight());
for(int i = 0; i < ib.GetHeight(); i++) {
int sl = poff.y + i;
if(i >= 0 && i < srcsz.cy)
Copy(ib[i], pixels + srcsz.cx * sl + poff.x,
minmax(srcsz.cx - poff.x, 0, min(dest.GetWidth(), srcsz.cx)));
}
w.DrawImage(dest.left, dest.top, ib);
}
}
void SetSurface(Draw& w, int x, int y, int cx, int cy, const RGBA *pixels)
{
SetSurface(w, RectC(x, y, cx, cy), pixels, Size(cx, cy), Point(0, 0));
}
END_UPP_NAMESPACE

View file

@ -104,6 +104,7 @@ typedef ImageDraw SystemImageDraw;
void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n,
Color color, uint64 pattern);
void SetSurface(SystemDraw& w, int x, int y, int cx, int cy, const RGBA *pixels);
void SetSurface(Draw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff);
void SetSurface(Draw& w, int x, int y, int cx, int cy, const RGBA *pixels);
END_UPP_NAMESPACE

View file

@ -35,7 +35,7 @@ void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font,
double cosa;
int d = 0;
if(angle)
Draw::SinCos(angle, sina, cosa); //TODO global sin tables!
Draw::SinCos(angle, sina, cosa);
for(int i = 0; i < n; i++) {
wchar chr = text[i];
GlyphInfo gi = GetGlyphInfo(font, chr);

View file

@ -0,0 +1,36 @@
topic "";
[2 $$0,0#00000000000000000000000000000000:Default]
[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class]
[l288;2 $$2,2#27521748481378242620020725143825:desc]
[0 $$3,0#96390100711032703541132217272105:end]
[H6;0 $$4,0#05600065144404261032431302351956:begin]
[i448;a25;kKO9;2 $$5,0#37138531426314131252341829483370:item]
[l288;a4;*@5;1 $$6,6#70004532496200323422659154056402:requirement]
[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param]
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
[b42;2 $$9,9#13035079074754324216151401829390:normal]
[{_}
[ {{10000@(113.42.0) [s0;%% [*@7;4 Font and Text Routines]]}}&]
[s4;H0; &]
[s5;:GetTextSize`(const wchar`*`,Font`,int`): [_^Size^ Size]_[* GetTextSize]([@(0.0.255) co
nst]_[_^wchar^ wchar]_`*[*@3 text], [_^Font^ Font]_[*@3 font], [@(0.0.255) int]_[*@3 n]_`=_`-
[@3 1])&]
[s5;:GetTextSize`(const WString`&`,Font`): [_^Size^ Size]_[* GetTextSize]([@(0.0.255) const
]_[_^WString^ WString][@(0.0.255) `&]_[*@3 text], [_^Font^ Font]_[*@3 font])&]
[s5;:GetTextSize`(const char`*`,byte`,Font`,int`): [_^Size^ Size]_[* GetTextSize]([@(0.0.255) c
onst]_[@(0.0.255) char]_`*[*@3 text], [_^byte^ byte]_[*@3 charset], [_^Font^ Font]_[*@3 font],
[@(0.0.255) int]_[*@3 n]_`=_`-[@3 1])&]
[s5;:GetTextSize`(const char`*`,Font`,int`): [_^Size^ Size]_[* GetTextSize]([@(0.0.255) con
st]_[@(0.0.255) char]_`*[*@3 text], [_^Font^ Font]_[*@3 font], [@(0.0.255) int]_[*@3 n]_`=_`-
[@3 1])&]
[s5;:GetTextSize`(const String`&`,Font`): [_^Size^ Size]_[* GetTextSize]([@(0.0.255) const]_
[_^String^ String][@(0.0.255) `&]_[*@3 text], [_^Font^ Font]_[*@3 font])&]
[s2;%% Computes the graphical size of [%-*@3 text] if drawn with [%-*@3 font],
using font metrics. Returned height is the height of font (ascent`+descent),
returned with is the total advance width of text. No overhangs
are considered. [%-*@3 n] is a number of characters; if negative
(default value), it is obtained using `[w`]strlen. Text can either
be unicode or in 8`-bit encoding; in that case either [%-*@3 charset]
is provided or it is assumed to be default charset.&]
[s3;%% &]
[s0; ]

View file

@ -0,0 +1,7 @@
TITLE("")
COMPRESSED
120,156,181,85,107,139,227,54,20,253,43,23,178,51,36,105,198,232,105,249,65,97,160,165,93,40,180,176,187,208,15,198,137,21,91,147,136,38,242,212,150,51,109,135,153,223,190,87,142,179,204,135,109,7,186,187,33,200,178,116,207,185,231,92,201,82,193,224,205,27,178,34,51,242,202,47,251,209,220,233,225,224,203,194,10,145,228,154,201,252,143,95,126,75,243,128,167,136,231,138,242,68,114,42,88,140,13,229,148,73,198,5,77,88,42,18,206,19,146,213,7,221,247,101,113,96,73,50,130,216,138,205,152,146,140,42,145,136,132,114,149,48,196,50,66,24,81,76,82,193,19,38,179,198,244,117,89,16,12,231,152,35,141,121,74,40,33,138,82,194,153,34,92,10,74,57,67,10,166,24,37,50,51,174,41,139,183,113,30,0,34,152,146,49,74,143,145,77,8,130,236,1,38,56,229,132,113,73,83,25,103,91,179,179,238,115,150,228,171,150,20,201,172,55,199,201,145,22,249,242,86,230,20,161,241,42,158,41,76,43,36,38,75,131,35,142,48,198,98,153,82,41,80,146,32,44,
235,204,159,131,237,204,209,56,63,49,88,74,25,205,183,84,229,40,225,249,249,57,162,130,156,43,165,80,11,37,168,155,81,28,67,31,138,202,148,164,50,161,9,225,74,48,169,208,250,189,238,244,113,114,178,21,44,159,124,36,171,100,22,211,24,43,74,18,212,47,83,36,32,104,2,159,88,72,137,127,158,100,126,2,7,92,0,165,171,116,134,69,226,146,168,148,40,161,164,64,39,140,198,20,11,73,130,127,92,134,204,181,221,81,31,202,226,113,243,4,5,60,62,210,176,75,110,231,184,32,145,96,17,89,64,209,147,252,234,10,138,229,173,202,5,252,212,58,15,218,53,240,193,252,229,225,93,59,120,235,76,95,150,79,79,215,101,209,139,252,45,201,33,244,100,158,253,108,124,8,122,111,255,49,213,188,110,93,239,225,161,222,235,174,90,86,171,64,83,173,44,54,139,12,138,205,58,4,173,33,180,229,166,88,194,11,104,57,47,110,231,36,34,17,186,94,192,72,131,33,155,245,72,181,62,51,150,155,106,137,250,56,120,4,149,171,64,24,18,172,71,181,129,16,167,238,
66,23,167,94,144,217,79,147,14,25,190,223,84,55,5,246,105,185,248,119,3,191,191,247,157,117,187,234,122,178,240,127,213,79,60,235,11,97,249,50,172,186,158,100,189,102,231,63,132,94,10,189,253,219,155,47,47,247,203,161,207,215,59,228,89,67,104,39,129,33,174,55,223,118,53,190,214,110,122,221,222,55,50,240,149,118,211,101,51,125,241,94,98,225,75,255,161,61,222,15,222,244,224,247,6,118,157,190,223,219,90,31,160,71,1,208,222,65,113,117,243,137,15,236,29,52,157,126,112,240,96,253,254,50,53,213,102,232,81,204,248,2,71,131,202,234,62,130,119,198,15,157,51,13,236,141,221,237,61,216,115,150,233,13,217,199,240,185,238,107,60,81,171,239,194,189,129,157,197,10,186,11,112,76,52,193,124,235,81,152,110,78,218,213,6,103,26,156,66,142,32,45,130,95,91,104,79,166,219,107,183,235,65,119,102,172,151,109,76,103,154,232,162,212,149,129,74,131,27,142,91,211,5,108,88,127,93,123,211,245,121,48,231,204,78,123,123,50,48,111,206,247,38,156,244,97,
48,40,200,142,226,219,173,215,54,200,58,155,173,138,135,170,236,125,119,48,46,58,159,144,181,118,96,80,50,178,111,13,12,206,214,109,131,101,236,112,183,64,82,221,108,145,198,56,28,67,116,30,198,252,94,7,80,111,46,168,73,233,229,115,10,73,239,187,246,132,70,154,145,102,148,129,87,242,112,196,1,223,134,44,23,169,19,38,10,43,203,195,202,134,14,158,207,229,71,196,61,117,248,

View file

@ -11,7 +11,7 @@ topic "";
[b42;2 $$9,9#13035079074754324216151401829390:normal]
[{_}%EN-US
[ {{10000@(113.42.0) [s0; [*@7;4 PaintRect]]}}&]
[s4;%- &]
[s4;H0;%- &]
[s1;:PaintRect`:`:class:%- [@(0.0.255) class]_[* PaintRect]_:_[@(0.0.255) private]_[*@3 Moveab
le]<[* PaintRect]>_&]
[s2; PaintRect is a simple helper class that combines Value and a

View file

@ -0,0 +1,9 @@
TITLE("")
COMPRESSED
120,156,213,88,109,111,219,54,16,254,43,68,211,6,182,33,123,36,37,89,178,181,13,1,210,46,45,182,110,65,210,245,139,32,91,180,69,59,66,100,201,147,104,39,78,210,254,246,29,41,217,150,95,99,39,195,128,6,129,20,146,119,199,123,238,30,222,81,113,41,122,251,22,107,248,4,63,243,211,126,207,7,108,18,9,207,13,13,195,118,24,53,157,219,223,255,106,57,82,159,128,190,110,17,221,54,117,98,208,38,60,136,78,168,73,117,131,216,180,101,216,186,110,227,118,63,98,89,230,185,17,181,109,165,68,53,122,66,45,147,18,203,176,13,155,232,150,77,65,151,98,76,177,69,77,98,232,54,53,219,1,207,250,158,139,65,92,135,61,90,77,189,133,9,198,22,33,88,167,22,214,77,131,16,157,130,9,106,81,130,205,54,143,3,207,253,216,116,164,130,33,65,153,77,112,189,9,214,12,3,131,117,169,102,232,68,199,84,55,73,203,108,182,123,124,24,198,219,32,153,207,66,178,112,59,20,124,84,32,98,134,83,59,51,29,2,170,77,173,121,98,193,182,134,9,155,
181,36,34,29,212,40,109,154,45,98,26,224,146,129,105,59,229,255,76,194,148,143,120,44,10,11,33,33,148,56,61,98,57,224,194,247,239,223,27,196,192,121,164,44,240,133,96,240,155,18,152,3,28,22,49,91,184,101,218,196,198,186,101,80,211,2,232,99,150,178,81,129,164,103,80,167,192,97,107,246,73,147,52,33,162,216,6,255,205,22,24,192,0,2,222,16,72,19,126,117,187,45,10,101,169,39,149,90,90,235,4,130,164,155,216,106,97,203,176,76,3,144,80,210,36,16,72,44,241,67,26,218,113,146,142,88,228,185,143,221,111,239,62,252,89,255,251,26,185,232,241,145,72,174,156,85,32,45,13,131,54,112,21,185,25,118,144,91,59,179,28,3,93,178,48,22,87,188,47,60,239,219,183,83,207,205,12,231,35,118,222,213,145,252,155,56,237,197,186,223,246,115,190,180,97,209,61,171,224,6,110,128,243,85,148,147,168,235,214,74,182,186,237,110,89,100,156,134,83,38,184,20,58,211,209,231,100,202,89,47,226,222,207,43,58,191,118,229,150,212,89,78,161,48,67,12,
101,225,104,28,113,116,195,163,49,79,243,221,144,184,97,2,245,147,81,47,140,121,134,190,178,104,194,17,139,3,144,78,249,128,167,60,238,115,36,18,16,227,232,125,152,141,35,54,147,195,113,154,76,195,128,35,255,205,52,204,38,44,2,11,177,128,108,251,111,80,50,0,205,190,96,241,48,226,13,244,73,109,237,190,171,215,74,32,22,110,55,164,159,122,17,163,121,124,127,171,16,106,87,47,212,243,140,204,67,140,46,39,189,40,236,163,207,92,220,36,1,250,35,204,182,198,217,92,139,179,26,248,149,247,41,187,243,79,125,13,220,204,4,82,139,48,58,79,162,36,93,188,130,187,36,13,252,170,18,89,207,204,52,9,131,101,98,188,138,219,237,72,147,29,36,159,94,89,210,63,45,114,115,231,105,171,201,149,118,97,173,219,145,219,119,148,19,219,53,83,169,217,237,40,183,58,72,189,138,149,48,190,245,186,254,47,221,107,53,249,133,223,139,93,146,99,6,41,46,201,94,202,177,18,86,48,59,72,189,10,225,76,204,32,25,82,216,133,17,246,170,221,77,199,11,70,
125,138,167,201,45,16,69,197,65,230,90,38,30,254,230,193,130,30,131,36,45,205,42,70,169,60,91,142,226,193,185,138,77,253,73,70,110,125,62,133,249,47,44,29,114,81,226,208,154,140,140,65,253,233,122,50,28,242,76,192,6,176,29,31,166,201,4,56,219,151,72,215,229,243,72,148,53,122,172,127,187,79,35,15,71,253,233,107,78,109,53,92,97,42,48,238,48,186,201,193,250,227,127,37,157,212,203,87,238,119,174,204,118,174,244,119,43,245,103,63,0,73,55,185,121,23,138,155,151,146,243,94,67,51,13,98,162,73,240,155,60,69,149,136,15,0,170,72,198,26,236,19,136,27,13,42,109,56,188,17,213,31,138,194,23,92,92,139,224,58,124,224,126,165,76,204,110,71,206,117,144,124,42,86,46,5,189,202,1,201,88,138,31,95,54,106,63,65,185,20,147,52,70,83,57,15,192,46,85,119,74,65,114,110,113,169,241,60,198,43,38,194,36,135,184,56,152,251,160,46,228,225,16,190,224,164,28,16,157,197,14,47,174,169,224,66,253,233,42,191,120,5,57,1,161,253,
14,208,3,79,19,13,133,2,101,55,201,36,2,234,112,217,238,199,19,73,35,232,228,183,156,143,17,203,198,242,146,144,74,39,138,51,50,219,176,63,43,219,207,153,253,154,13,238,247,100,119,37,167,10,124,17,136,227,243,171,158,135,230,118,125,81,158,164,135,125,233,251,0,225,0,167,225,230,35,161,46,76,85,178,135,134,44,20,242,53,171,30,232,244,53,23,5,74,191,146,223,83,230,195,83,191,186,179,55,44,181,86,185,185,188,110,20,203,157,185,185,237,157,35,240,170,5,38,176,152,149,239,123,235,68,8,100,125,60,42,29,96,81,101,114,142,43,31,60,131,74,9,237,194,164,22,59,185,161,237,120,166,155,120,182,30,155,169,172,146,71,148,14,176,182,153,30,237,8,92,175,77,211,174,91,229,139,66,50,175,47,242,198,191,51,68,235,9,127,69,244,206,35,206,82,217,87,118,70,72,73,64,67,41,60,189,226,35,248,88,88,117,214,175,163,108,210,203,160,20,201,115,215,103,81,148,201,211,151,95,73,25,148,25,150,193,135,73,156,160,4,218,166,60,146,177,
255,70,91,202,149,26,145,132,189,172,188,105,94,132,212,1,198,26,194,135,30,220,139,5,189,119,92,228,14,78,18,186,88,240,126,79,209,201,139,229,54,78,111,86,210,99,146,115,81,42,64,207,34,57,128,174,232,162,84,155,14,196,179,206,179,77,68,199,149,158,156,2,208,64,122,73,18,173,194,170,161,249,98,87,46,238,118,113,187,31,34,133,214,20,14,22,172,132,207,220,140,139,85,183,176,83,59,224,203,246,92,238,148,78,250,210,205,128,67,143,143,14,254,178,85,131,249,113,42,255,11,96,113,128,22,198,51,196,71,99,49,91,202,104,121,35,134,115,178,168,2,89,22,14,225,130,113,204,199,78,238,193,246,126,181,226,208,171,170,94,177,184,5,212,242,95,28,10,141,188,103,132,131,112,121,117,218,40,102,133,169,99,137,180,7,236,214,234,255,159,99,127,69,221,103,209,158,200,221,239,138,156,170,142,219,27,194,214,24,150,219,2,236,88,174,61,192,115,239,95,211,63,169,217,

View file

@ -6,3 +6,11 @@ TOPIC("Raster$en-us")
#include "Raster$en-us.tppi"
END_TOPIC
TOPIC("FontTextUtils$en-us")
#include "FontTextUtils$en-us.tppi"
END_TOPIC
TOPIC("PaintRect$en-us")
#include "PaintRect$en-us.tppi"
END_TOPIC