mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-22 22:02:34 -06:00
Developint SystemDraw
git-svn-id: svn://ultimatepp.org/upp/trunk@1364 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
782abba616
commit
fd73adeb60
7 changed files with 111 additions and 81 deletions
|
|
@ -903,10 +903,9 @@ DrawingToPdfFnType GetDrawingToPdfFn();
|
|||
#include "DrawX11.h"
|
||||
#endif
|
||||
|
||||
#include "BackDraw.h"
|
||||
#include "SystemDraw.h"
|
||||
|
||||
#include "Display.h"
|
||||
#include "ImageDraw.h"
|
||||
#include "Debug.h"
|
||||
#include "Cham.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -45,25 +45,24 @@ file
|
|||
Debug.h,
|
||||
Debug.cpp,
|
||||
SystemDraw readonly separator,
|
||||
SystemDraw.cpp,
|
||||
DrawWin32.h,
|
||||
DrawWin32.cpp,
|
||||
DrawOpWin32.cpp,
|
||||
DrawTextWin32.cpp,
|
||||
ImageWin32.cpp,
|
||||
MetaFile.cpp,
|
||||
DrawX11.h,
|
||||
DrawX11.cpp,
|
||||
DrawOpX11.cpp,
|
||||
DrawTextX11.cpp,
|
||||
BackDraw.h,
|
||||
ImageX11.cpp,
|
||||
SystemDraw.h,
|
||||
BackDraw.cpp,
|
||||
SystemDraw.cpp,
|
||||
Image readonly separator,
|
||||
Image.h,
|
||||
ImageDraw.h,
|
||||
Image.cpp,
|
||||
ImageBlit.cpp,
|
||||
ImageWin32.cpp,
|
||||
ImageX11.cpp,
|
||||
Raster.h,
|
||||
RasterFormat.cpp,
|
||||
RasterWrite.cpp,
|
||||
|
|
|
|||
|
|
@ -245,9 +245,7 @@ static const char *sFontReplacements[] = {
|
|||
"PMingLiU",
|
||||
};
|
||||
|
||||
//!!! Add ascent replacement cache!!!
|
||||
|
||||
struct FontMetricsReplacement {
|
||||
struct sFontMetricsReplacement {
|
||||
Font src;
|
||||
Font dst;
|
||||
Font mdst;
|
||||
|
|
@ -270,7 +268,7 @@ bool Replace(Font fnt, int chr, Font& rfnt)
|
|||
int a = fnt.GetAscent();
|
||||
int d = fnt.GetDescent();
|
||||
if(f.GetAscent() > a || f.GetDescent() > d) {
|
||||
static FontMetricsReplacement cache[256];
|
||||
static sFontMetricsReplacement cache[256];
|
||||
int q = CombineHash(fnt, f) & 255;
|
||||
if(cache[q].src != fnt || cache[q].dst != f) {
|
||||
cache[q].src = fnt;
|
||||
|
|
|
|||
|
|
@ -128,16 +128,15 @@ private:
|
|||
|
||||
void Retain() { AtomicInc(refcount); }
|
||||
void Release() { if(AtomicDec(refcount) == 0) delete this; }
|
||||
|
||||
struct SystemData;
|
||||
|
||||
void *system_buffer[6];
|
||||
SystemData& Sys() const;
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
LPCSTR cursor_cheat;
|
||||
HBITMAP hbmp;
|
||||
HBITMAP hmask;
|
||||
HBITMAP himg;
|
||||
RGBA *section;
|
||||
|
||||
void CreateHBMP(HDC dc, const RGBA *data);
|
||||
int GetResCount() const { return !!hbmp + !!hmask + !!himg; }
|
||||
int GetResCount() const;
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_X11
|
||||
|
|
@ -146,6 +145,7 @@ private:
|
|||
XPicture picture8;
|
||||
int GetResCount() const { return !!picture; }
|
||||
#endif
|
||||
|
||||
|
||||
ImageBuffer buffer;
|
||||
bool paintonly;
|
||||
|
|
@ -179,8 +179,8 @@ private:
|
|||
|
||||
#ifdef PLATFORM_WIN32
|
||||
#ifndef PLATFORM_WINCE
|
||||
void SetCursorCheat(LPCSTR id) { data->cursor_cheat = id; }
|
||||
LPCSTR GetCursorCheat() const { return data ? data->cursor_cheat : NULL; }
|
||||
void SetCursorCheat(LPCSTR id);
|
||||
LPCSTR GetCursorCheat() const;
|
||||
friend Image Win32IconCursor(LPCSTR id, int iconsize, bool cursor);
|
||||
friend HICON IconWin32(const Image& img, bool cursor);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
class ImageDraw : public SystemDraw {
|
||||
Size size;
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
struct Section {
|
||||
HDC dc;
|
||||
HBITMAP hbmp, hbmpOld;
|
||||
RGBA *pixels;
|
||||
|
||||
void Init(int cx, int cy);
|
||||
~Section();
|
||||
};
|
||||
|
||||
Section rgb;
|
||||
Section a;
|
||||
SystemDraw alpha;
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_X11
|
||||
SystemDraw alpha;
|
||||
#endif
|
||||
|
||||
bool has_alpha;
|
||||
|
||||
void Init();
|
||||
Image Get(bool pm) const;
|
||||
|
||||
public:
|
||||
Draw& Alpha();
|
||||
|
||||
operator Image() const;
|
||||
|
||||
Image GetStraight() const;
|
||||
|
||||
ImageDraw(Size sz);
|
||||
ImageDraw(int cx, int cy);
|
||||
~ImageDraw();
|
||||
};
|
||||
|
|
@ -14,6 +14,14 @@ bool ImageFallBack
|
|||
// = true
|
||||
;
|
||||
|
||||
struct Image::Data::SystemData {
|
||||
LPCSTR cursor_cheat;
|
||||
HBITMAP hbmp;
|
||||
HBITMAP hmask;
|
||||
HBITMAP himg;
|
||||
RGBA *section;
|
||||
};
|
||||
|
||||
class BitmapInfo32__ {
|
||||
Buffer<byte> data;
|
||||
|
||||
|
|
@ -149,28 +157,30 @@ DrawSurface::~DrawSurface()
|
|||
|
||||
void Image::Data::SysInit()
|
||||
{
|
||||
hbmp = hmask = himg = NULL;
|
||||
cursor_cheat = NULL;
|
||||
SystemData& sd = Sys();
|
||||
sd.hbmp = sd.hmask = sd.himg = NULL;
|
||||
sd.cursor_cheat = NULL;
|
||||
}
|
||||
|
||||
void Image::Data::SysRelease()
|
||||
{
|
||||
if(hbmp) {
|
||||
SystemData& sd = Sys();
|
||||
if(sd.hbmp) {
|
||||
DrawLock __;
|
||||
DeleteObject(hbmp);
|
||||
DeleteObject(sd.hbmp);
|
||||
ResCount -= !paintonly;
|
||||
}
|
||||
if(hmask) {
|
||||
if(sd.hmask) {
|
||||
DrawLock __;
|
||||
DeleteObject(hmask);
|
||||
DeleteObject(sd.hmask);
|
||||
ResCount -= !paintonly;
|
||||
}
|
||||
if(himg) {
|
||||
if(sd.himg) {
|
||||
DrawLock __;
|
||||
DeleteObject(himg);
|
||||
DeleteObject(sd.himg);
|
||||
ResCount -= !paintonly;
|
||||
}
|
||||
himg = hbmp = hmask = NULL;
|
||||
sd.himg = sd.hbmp = sd.hmask = NULL;
|
||||
}
|
||||
|
||||
#ifndef PLATFORM_WINCE
|
||||
|
|
@ -193,9 +203,32 @@ static tAlphaBlend fnAlphaBlend()
|
|||
}
|
||||
#endif
|
||||
|
||||
void Image::SetCursorCheat(LPCSTR id)
|
||||
{
|
||||
data->Sys().cursor_cheat = id;
|
||||
}
|
||||
|
||||
LPCSTR Image::GetCursorCheat() const
|
||||
{
|
||||
return data ? data->Sys().cursor_cheat : NULL;
|
||||
}
|
||||
|
||||
Image::Data::SystemData& Image::Data::Sys() const
|
||||
{
|
||||
ASSERT(sizeof(system_buffer) >= sizeof(SystemData));
|
||||
return *(SystemData *)system_buffer;
|
||||
}
|
||||
|
||||
int Image::Data::GetResCount() const
|
||||
{
|
||||
SystemData& sd = Sys();
|
||||
return !!sd.hbmp + !!sd.hmask + !!sd.himg;
|
||||
}
|
||||
|
||||
void Image::Data::CreateHBMP(HDC dc, const RGBA *data)
|
||||
{
|
||||
DrawLock __;
|
||||
SystemData& sd = Sys();
|
||||
Size sz = buffer.GetSize();
|
||||
BitmapInfo32__ bi(sz.cx, sz.cy);
|
||||
HDC dcMem = ::CreateCompatibleDC(dc);
|
||||
|
|
@ -204,8 +237,8 @@ void Image::Data::CreateHBMP(HDC dc, const RGBA *data)
|
|||
HDC hbmpOld = (HDC) ::SelectObject(dcMem, hbmp32);
|
||||
memcpy(pixels, data, buffer.GetLength() * sizeof(RGBA));
|
||||
HDC dcMem2 = ::CreateCompatibleDC(dc);
|
||||
hbmp = ::CreateCompatibleBitmap(dc, sz.cx, sz.cy);
|
||||
HBITMAP o2 = (HBITMAP)::SelectObject(dcMem2, hbmp);
|
||||
sd.hbmp = ::CreateCompatibleBitmap(dc, sz.cx, sz.cy);
|
||||
HBITMAP o2 = (HBITMAP)::SelectObject(dcMem2, sd.hbmp);
|
||||
::BitBlt(dcMem2, 0, 0, sz.cx, sz.cy, dcMem, 0, 0, SRCCOPY);
|
||||
::SelectObject(dcMem2, o2);
|
||||
::DeleteDC(dcMem2);
|
||||
|
|
@ -218,6 +251,7 @@ void Image::Data::CreateHBMP(HDC dc, const RGBA *data)
|
|||
void Image::Data::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c)
|
||||
{
|
||||
DrawLock __;
|
||||
SystemData& sd = Sys();
|
||||
ASSERT(!paintonly || IsNull(c));
|
||||
int max = IsWinNT() ? 250 : 100;
|
||||
while(ResCount > max) {
|
||||
|
|
@ -247,13 +281,13 @@ void Image::Data::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c)
|
|||
Unlink();
|
||||
LinkAfter(ResData);
|
||||
if(GetKind() == IMAGE_OPAQUE) {
|
||||
if(!hbmp) {
|
||||
if(!sd.hbmp) {
|
||||
LTIMING("Image Opaque create");
|
||||
CreateHBMP(dc, buffer);
|
||||
}
|
||||
LTIMING("Image Opaque blit");
|
||||
HDC dcMem = ::CreateCompatibleDC(dc);
|
||||
HBITMAP o = (HBITMAP)::SelectObject(dcMem, hbmp);
|
||||
HBITMAP o = (HBITMAP)::SelectObject(dcMem, sd.hbmp);
|
||||
::BitBlt(dc, x, y, ssz.cx, ssz.cy, dcMem, sr.left, sr.top, SRCCOPY);
|
||||
::SelectObject(dcMem, o);
|
||||
::DeleteDC(dcMem);
|
||||
|
|
@ -262,22 +296,22 @@ void Image::Data::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c)
|
|||
}
|
||||
if(GetKind() == IMAGE_MASK/* || GetKind() == IMAGE_OPAQUE*/) {
|
||||
HDC dcMem = ::CreateCompatibleDC(dc);
|
||||
if(!hmask) {
|
||||
if(!sd.hmask) {
|
||||
LTIMING("Image Mask create");
|
||||
Buffer<RGBA> bmp(len);
|
||||
hmask = CreateBitMask(buffer, sz, sz, sz, bmp);
|
||||
sd.hmask = CreateBitMask(buffer, sz, sz, sz, bmp);
|
||||
ResCount++;
|
||||
if(!hbmp)
|
||||
if(!sd.hbmp)
|
||||
CreateHBMP(dc, bmp);
|
||||
}
|
||||
LTIMING("Image Mask blt");
|
||||
HBITMAP o = (HBITMAP)::SelectObject(dcMem, ::CreateCompatibleBitmap(dc, sz.cx, sz.cy));
|
||||
::BitBlt(dcMem, 0, 0, ssz.cx, ssz.cy, dc, x, y, SRCCOPY);
|
||||
HDC dcMem2 = ::CreateCompatibleDC(dc);
|
||||
::SelectObject(dcMem2, hmask);
|
||||
::SelectObject(dcMem2, sd.hmask);
|
||||
::BitBlt(dcMem, 0, 0, ssz.cx, ssz.cy, dcMem2, sr.left, sr.top, SRCAND);
|
||||
if(IsNull(c)) {
|
||||
::SelectObject(dcMem2, hbmp);
|
||||
::SelectObject(dcMem2, sd.hbmp);
|
||||
::BitBlt(dcMem, 0, 0, ssz.cx, ssz.cy, dcMem2, sr.left, sr.top, SRCPAINT);
|
||||
}
|
||||
else {
|
||||
|
|
@ -294,13 +328,12 @@ void Image::Data::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c)
|
|||
}
|
||||
#ifndef PLATFORM_WINCE
|
||||
if(fnAlphaBlend() && IsNull(c) && !ImageFallBack) {
|
||||
if(!himg) {
|
||||
if(!sd.himg) {
|
||||
LTIMING("Image Alpha create");
|
||||
BitmapInfo32__ bi(sz.cx, sz.cy);
|
||||
himg = CreateDIBSection(ScreenHDC(), bi, DIB_RGB_COLORS,
|
||||
(void **)§ion, NULL, 0);
|
||||
sd.himg = CreateDIBSection(ScreenHDC(), bi, DIB_RGB_COLORS, (void **)&sd.section, NULL, 0);
|
||||
ResCount++;
|
||||
memcpy(section, ~buffer, buffer.GetLength() * sizeof(RGBA));
|
||||
memcpy(sd.section, ~buffer, buffer.GetLength() * sizeof(RGBA));
|
||||
}
|
||||
LTIMING("Image Alpha blit");
|
||||
BLENDFUNCTION bf;
|
||||
|
|
@ -309,7 +342,7 @@ void Image::Data::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c)
|
|||
bf.SourceConstantAlpha = 255;
|
||||
bf.AlphaFormat = AC_SRC_ALPHA;
|
||||
HDC dcMem = ::CreateCompatibleDC(dc);
|
||||
::SelectObject(dcMem, himg);
|
||||
::SelectObject(dcMem, sd.himg);
|
||||
fnAlphaBlend()(dc, x, y, ssz.cx, ssz.cy, dcMem, sr.left, sr.top, ssz.cx, ssz.cy, bf);
|
||||
::DeleteDC(dcMem);
|
||||
PaintOnlyShrink();
|
||||
|
|
|
|||
|
|
@ -37,3 +37,42 @@ public:
|
|||
void Create(Draw& w, int cx, int cy) { Create(*(SystemDraw*)&w, cx, cy); }
|
||||
void Create(Draw& w, Size sz) { Create(*(SystemDraw*)&w, sz.cx, sz.cy); }*/
|
||||
};
|
||||
|
||||
class ImageDraw : public SystemDraw {
|
||||
Size size;
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
struct Section {
|
||||
HDC dc;
|
||||
HBITMAP hbmp, hbmpOld;
|
||||
RGBA *pixels;
|
||||
|
||||
void Init(int cx, int cy);
|
||||
~Section();
|
||||
};
|
||||
|
||||
Section rgb;
|
||||
Section a;
|
||||
SystemDraw alpha;
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_X11
|
||||
SystemDraw alpha;
|
||||
#endif
|
||||
|
||||
bool has_alpha;
|
||||
|
||||
void Init();
|
||||
Image Get(bool pm) const;
|
||||
|
||||
public:
|
||||
Draw& Alpha();
|
||||
|
||||
operator Image() const;
|
||||
|
||||
Image GetStraight() const;
|
||||
|
||||
ImageDraw(Size sz);
|
||||
ImageDraw(int cx, int cy);
|
||||
~ImageDraw();
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue