mirror of
https://github.com/gnustep/libs-back.git
synced 2025-05-31 01:11:00 +00:00
Rewrote clipping code.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@13767 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9521318ad8
commit
394b4beaa2
1 changed files with 210 additions and 142 deletions
|
@ -105,13 +105,40 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface WIN32GState (WinOps)
|
@interface WIN32GState (WinOps)
|
||||||
- (void) setStyle: (HDC)hdc;
|
- (void) setStyle: (HDC)hDC;
|
||||||
|
- (void) restoreStyle: (HDC)hDC;
|
||||||
- (HDC) getHDC;
|
- (HDC) getHDC;
|
||||||
- (void) releaseHDC: (HDC)hdc;
|
- (void) releaseHDC: (HDC)hDC;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation WIN32GState
|
@implementation WIN32GState
|
||||||
|
|
||||||
|
- (id) deepen
|
||||||
|
{
|
||||||
|
[super deepen];
|
||||||
|
|
||||||
|
if (clipRegion)
|
||||||
|
{
|
||||||
|
HRGN newClipRegion;
|
||||||
|
|
||||||
|
newClipRegion = CreateRectRgn(0, 0, 1, 1);
|
||||||
|
CombineRgn(newClipRegion, clipRegion, NULL, RGN_COPY);
|
||||||
|
clipRegion = newClipRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
oldBrush = NULL;
|
||||||
|
oldPen = NULL;
|
||||||
|
oldClipRegion = NULL;
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
DeleteObject(clipRegion);
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) setWindow: (HWND)number
|
- (void) setWindow: (HWND)number
|
||||||
{
|
{
|
||||||
window = number;
|
window = number;
|
||||||
|
@ -137,7 +164,7 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
|
||||||
toPoint: (NSPoint)aPoint
|
toPoint: (NSPoint)aPoint
|
||||||
{
|
{
|
||||||
HDC otherDC;
|
HDC otherDC;
|
||||||
HDC hdc;
|
HDC hDC;
|
||||||
POINT p;
|
POINT p;
|
||||||
RECT rect;
|
RECT rect;
|
||||||
int h;
|
int h;
|
||||||
|
@ -153,9 +180,18 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
|
||||||
y1 = p.y - h;
|
y1 = p.y - h;
|
||||||
|
|
||||||
otherDC = [source getHDC];
|
otherDC = [source getHDC];
|
||||||
hdc = [self getHDC];
|
if (!otherDC)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hDC = [self getHDC];
|
||||||
|
if (!hDC)
|
||||||
|
{
|
||||||
|
[source releaseHDC: otherDC];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!BitBlt(hdc, p.x, y1, (rect.right - rect.left), h,
|
if (!BitBlt(hDC, p.x, y1, (rect.right - rect.left), h,
|
||||||
otherDC, rect.left, rect.top, SRCCOPY))
|
otherDC, rect.left, rect.top, SRCCOPY))
|
||||||
{
|
{
|
||||||
NSLog(@"Copy bitmap failed %d", GetLastError());
|
NSLog(@"Copy bitmap failed %d", GetLastError());
|
||||||
|
@ -164,7 +200,7 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
|
||||||
NSLog(@"Copy Bits to %d %d from %d %d size %d %d", p.x , y1,
|
NSLog(@"Copy Bits to %d %d from %d %d size %d %d", p.x , y1,
|
||||||
rect.left, rect.top, (rect.right - rect.left), h);
|
rect.left, rect.top, (rect.right - rect.left), h);
|
||||||
}
|
}
|
||||||
[self releaseHDC: hdc];
|
[self releaseHDC: hDC];
|
||||||
[source releaseHDC: otherDC];
|
[source releaseHDC: otherDC];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,9 +225,7 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
|
||||||
- (void) compositerect: (NSRect)aRect
|
- (void) compositerect: (NSRect)aRect
|
||||||
op: (NSCompositingOperation)op
|
op: (NSCompositingOperation)op
|
||||||
{
|
{
|
||||||
HDC hdc;
|
|
||||||
float gray;
|
float gray;
|
||||||
RECT rect = GSViewRectToWin(self, aRect);
|
|
||||||
|
|
||||||
[self DPScurrentgray: &gray];
|
[self DPScurrentgray: &gray];
|
||||||
if (fabs(gray - 0.667) < 0.005)
|
if (fabs(gray - 0.667) < 0.005)
|
||||||
|
@ -199,14 +233,25 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
|
||||||
else
|
else
|
||||||
[self DPSsetrgbcolor: 0.121 : 0.121 : 0];
|
[self DPSsetrgbcolor: 0.121 : 0.121 : 0];
|
||||||
|
|
||||||
hdc = [self getHDC];
|
|
||||||
switch (op)
|
switch (op)
|
||||||
{
|
{
|
||||||
case NSCompositeClear:
|
case NSCompositeClear:
|
||||||
break;
|
break;
|
||||||
case NSCompositeHighlight:
|
case NSCompositeHighlight:
|
||||||
InvertRect(hdc, &rect);
|
{
|
||||||
break;
|
HDC hDC;
|
||||||
|
RECT rect = GSViewRectToWin(self, aRect);
|
||||||
|
|
||||||
|
hDC = [self getHDC];
|
||||||
|
if (!hDC)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InvertRect(hDC, &rect);
|
||||||
|
[self releaseHDC: hDC];
|
||||||
|
break;
|
||||||
|
}
|
||||||
case NSCompositeCopy:
|
case NSCompositeCopy:
|
||||||
// FIXME
|
// FIXME
|
||||||
case NSCompositeSourceOver:
|
case NSCompositeSourceOver:
|
||||||
|
@ -225,12 +270,11 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
|
||||||
: NSWidth(aRect) : NSHeight(aRect)];
|
: NSWidth(aRect) : NSHeight(aRect)];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
[self releaseHDC: hdc];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
HBITMAP GSCreateBitmap(HDC hDC, int pixelsWide, int pixelsHigh,
|
||||||
int bitsPerSample, int samplesPerPixel,
|
int bitsPerSample, int samplesPerPixel,
|
||||||
int bitsPerPixel, int bytesPerRow,
|
int bitsPerPixel, int bytesPerRow,
|
||||||
BOOL isPlanar, BOOL hasAlpha,
|
BOOL isPlanar, BOOL hasAlpha,
|
||||||
|
@ -265,18 +309,26 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
while((bytesPerRow * 8) < (bitsPerPixel * pixelsWide))
|
while((bytesPerRow * 8) < (bitsPerPixel * pixelsWide))
|
||||||
bytesPerRow++;
|
bytesPerRow++;
|
||||||
|
|
||||||
if (!(GetDeviceCaps(hdc, RASTERCAPS) & RC_DI_BITMAP))
|
if (!(GetDeviceCaps(hDC, RASTERCAPS) & RC_DI_BITMAP))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hbitmap = CreateCompatibleBitmap(hdc, pixelsWide, pixelsHigh);
|
hbitmap = CreateCompatibleBitmap(hDC, pixelsWide, pixelsHigh);
|
||||||
if (!hbitmap)
|
if (!hbitmap)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmap = objc_malloc(sizeof(BITMAPINFOHEADER) + bitsPerPixel * sizeof(RGBQUAD));
|
if (bitsPerPixel > 8)
|
||||||
|
{
|
||||||
|
bitmap = objc_malloc(sizeof(BITMAPV4HEADER));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bitmap = objc_malloc(sizeof(BITMAPINFOHEADER) +
|
||||||
|
(1 << bitsPerPixel) * sizeof(RGBQUAD));
|
||||||
|
}
|
||||||
bmih = (BITMAPINFOHEADER*)bitmap;
|
bmih = (BITMAPINFOHEADER*)bitmap;
|
||||||
|
|
||||||
bmih->biSize = sizeof(BITMAPINFOHEADER);
|
bmih->biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
@ -286,8 +338,8 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
bmih->biBitCount = bitsPerPixel;
|
bmih->biBitCount = bitsPerPixel;
|
||||||
bmih->biCompression = BI_RGB;
|
bmih->biCompression = BI_RGB;
|
||||||
bmih->biSizeImage = 0;
|
bmih->biSizeImage = 0;
|
||||||
xres = GetDeviceCaps(hdc, HORZRES) / GetDeviceCaps(hdc, HORZSIZE);
|
xres = GetDeviceCaps(hDC, HORZRES) / GetDeviceCaps(hDC, HORZSIZE);
|
||||||
yres = GetDeviceCaps(hdc, VERTRES) / GetDeviceCaps(hdc, VERTSIZE);
|
yres = GetDeviceCaps(hDC, VERTRES) / GetDeviceCaps(hDC, VERTSIZE);
|
||||||
bmih->biXPelsPerMeter = xres;
|
bmih->biXPelsPerMeter = xres;
|
||||||
bmih->biYPelsPerMeter = yres;
|
bmih->biYPelsPerMeter = yres;
|
||||||
bmih->biClrUsed = 0;
|
bmih->biClrUsed = 0;
|
||||||
|
@ -329,7 +381,7 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
NSLog(@"Unsure how to handle images with %d bits", bitsPerPixel);
|
NSLog(@"Unsure how to handle images with %d bits", bitsPerPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetDIBits(hdc, hbitmap, 0, pixelsHigh, data[0],
|
if (!SetDIBits(hDC, hbitmap, 0, pixelsHigh, data[0],
|
||||||
bitmap, fuColorUse))
|
bitmap, fuColorUse))
|
||||||
{
|
{
|
||||||
objc_free(bitmap);
|
objc_free(bitmap);
|
||||||
|
@ -349,10 +401,10 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
: (const unsigned char *const [5]) data
|
: (const unsigned char *const [5]) data
|
||||||
{
|
{
|
||||||
NSAffineTransform *old_ctm = nil;
|
NSAffineTransform *old_ctm = nil;
|
||||||
HDC hdc;
|
HDC hDC;
|
||||||
HBITMAP hbitmap;
|
HBITMAP hbitmap;
|
||||||
HGDIOBJ old;
|
HGDIOBJ old;
|
||||||
HDC hdc2;
|
HDC hDC2;
|
||||||
POINT p;
|
POINT p;
|
||||||
int h;
|
int h;
|
||||||
int y1;
|
int y1;
|
||||||
|
@ -360,16 +412,17 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
NSLog(@"No window in DPSImage");
|
NSLog(@"No window in DPSImage");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdc = GetDC((HWND)window);
|
hDC = GetDC((HWND)window);
|
||||||
if (!hdc)
|
if (!hDC)
|
||||||
{
|
{
|
||||||
NSLog(@"No DC for window %d in DPSImage. Error %d",
|
NSLog(@"No DC for window %d in DPSImage. Error %d",
|
||||||
(int)window, GetLastError());
|
(int)window, GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
hbitmap = GSCreateBitmap(hdc, pixelsWide, pixelsHigh,
|
hbitmap = GSCreateBitmap(hDC, pixelsWide, pixelsHigh,
|
||||||
bitsPerSample, samplesPerPixel,
|
bitsPerSample, samplesPerPixel,
|
||||||
bitsPerPixel, bytesPerRow,
|
bitsPerPixel, bytesPerRow,
|
||||||
isPlanar, hasAlpha,
|
isPlanar, hasAlpha,
|
||||||
|
@ -379,23 +432,23 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
NSLog(@"Created bitmap failed %d", GetLastError());
|
NSLog(@"Created bitmap failed %d", GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
hdc2 = CreateCompatibleDC(hdc);
|
hDC2 = CreateCompatibleDC(hDC);
|
||||||
if (!hdc2)
|
if (!hDC2)
|
||||||
{
|
{
|
||||||
NSLog(@"No Compatible DC for window %d in DPSImage. Error %d",
|
NSLog(@"No Compatible DC for window %d in DPSImage. Error %d",
|
||||||
(int)window, GetLastError());
|
(int)window, GetLastError());
|
||||||
}
|
}
|
||||||
old = SelectObject(hdc2, hbitmap);
|
old = SelectObject(hDC2, hbitmap);
|
||||||
if (!old)
|
if (!old)
|
||||||
{
|
{
|
||||||
NSLog(@"SelectObject failed for window %d in DPSImage. Error %d",
|
NSLog(@"SelectObject failed for window %d in DPSImage. Error %d",
|
||||||
(int)window, GetLastError());
|
(int)window, GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
//SetMapMode(hdc2, GetMapMode(hdc));
|
//SetMapMode(hDC2, GetMapMode(hDC));
|
||||||
ReleaseDC((HWND)window, hdc);
|
ReleaseDC((HWND)window, hDC);
|
||||||
|
|
||||||
hdc = [self getHDC];
|
hDC = [self getHDC];
|
||||||
|
|
||||||
h = pixelsHigh;
|
h = pixelsHigh;
|
||||||
// Apply the additional transformation
|
// Apply the additional transformation
|
||||||
|
@ -416,18 +469,18 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
else
|
else
|
||||||
y1 = p.y - h;
|
y1 = p.y - h;
|
||||||
|
|
||||||
if (!BitBlt(hdc, p.x, y1, pixelsWide, pixelsHigh,
|
if (!BitBlt(hDC, p.x, y1, pixelsWide, pixelsHigh,
|
||||||
hdc2, 0, 0, SRCCOPY))
|
hDC2, 0, 0, SRCCOPY))
|
||||||
{
|
{
|
||||||
NSLog(@"Copy bitmap failed %d", GetLastError());
|
NSLog(@"Copy bitmap failed %d", GetLastError());
|
||||||
NSLog(@"DPSimage with %d %d %d %d to %d, %d", pixelsWide, pixelsHigh,
|
NSLog(@"DPSimage with %d %d %d %d to %d, %d", pixelsWide, pixelsHigh,
|
||||||
bytesPerRow, bitsPerPixel, p.x, y1);
|
bytesPerRow, bitsPerPixel, p.x, y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[self releaseHDC: hdc];
|
[self releaseHDC: hDC];
|
||||||
|
|
||||||
SelectObject(hdc2, old);
|
SelectObject(hDC2, old);
|
||||||
DeleteDC(hdc2);
|
DeleteDC(hDC2);
|
||||||
DeleteObject(hbitmap);
|
DeleteObject(hbitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,9 +491,13 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
- (void) _paintPath: (ctxt_object_t) drawType
|
- (void) _paintPath: (ctxt_object_t) drawType
|
||||||
{
|
{
|
||||||
unsigned count;
|
unsigned count;
|
||||||
HDC hdc;
|
HDC hDC;
|
||||||
|
|
||||||
hdc = [self getHDC];
|
hDC = [self getHDC];
|
||||||
|
if (!hDC)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
count = [path elementCount];
|
count = [path elementCount];
|
||||||
if (count)
|
if (count)
|
||||||
|
@ -450,7 +507,7 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
unsigned j, i = 0;
|
unsigned j, i = 0;
|
||||||
POINT p;
|
POINT p;
|
||||||
|
|
||||||
BeginPath(hdc);
|
BeginPath(hDC);
|
||||||
|
|
||||||
for(j = 0; j < count; j++)
|
for(j = 0; j < count; j++)
|
||||||
{
|
{
|
||||||
|
@ -459,12 +516,12 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
{
|
{
|
||||||
case NSMoveToBezierPathElement:
|
case NSMoveToBezierPathElement:
|
||||||
p = GSWindowPointToMS(self, points[0]);
|
p = GSWindowPointToMS(self, points[0]);
|
||||||
MoveToEx(hdc, p.x, p.y, NULL);
|
MoveToEx(hDC, p.x, p.y, NULL);
|
||||||
break;
|
break;
|
||||||
case NSLineToBezierPathElement:
|
case NSLineToBezierPathElement:
|
||||||
p = GSWindowPointToMS(self, points[0]);
|
p = GSWindowPointToMS(self, points[0]);
|
||||||
// FIXME This gives one pixel to few
|
// FIXME This gives one pixel to few
|
||||||
LineTo(hdc, p.x, p.y);
|
LineTo(hDC, p.x, p.y);
|
||||||
break;
|
break;
|
||||||
case NSCurveToBezierPathElement:
|
case NSCurveToBezierPathElement:
|
||||||
{
|
{
|
||||||
|
@ -474,59 +531,71 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
{
|
{
|
||||||
bp[i] = GSWindowPointToMS(self, points[i]);
|
bp[i] = GSWindowPointToMS(self, points[i]);
|
||||||
}
|
}
|
||||||
PolyBezierTo(hdc, bp, 3);
|
PolyBezierTo(hDC, bp, 3);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NSClosePathBezierPathElement:
|
case NSClosePathBezierPathElement:
|
||||||
CloseFigure(hdc);
|
CloseFigure(hDC);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EndPath(hdc);
|
EndPath(hDC);
|
||||||
|
|
||||||
// Now operate on the path
|
// Now operate on the path
|
||||||
switch (drawType)
|
switch (drawType)
|
||||||
{
|
{
|
||||||
case path_stroke:
|
case path_stroke:
|
||||||
StrokePath(hdc);
|
StrokePath(hDC);
|
||||||
break;
|
break;
|
||||||
case path_eofill:
|
case path_eofill:
|
||||||
SetPolyFillMode(hdc, ALTERNATE);
|
SetPolyFillMode(hDC, ALTERNATE);
|
||||||
FillPath(hdc);
|
FillPath(hDC);
|
||||||
break;
|
break;
|
||||||
case path_fill:
|
case path_fill:
|
||||||
SetPolyFillMode(hdc, WINDING);
|
SetPolyFillMode(hDC, WINDING);
|
||||||
FillPath(hdc);
|
FillPath(hDC);
|
||||||
break;
|
break;
|
||||||
case path_eoclip:
|
case path_eoclip:
|
||||||
{
|
{
|
||||||
HRGN region;
|
HRGN region;
|
||||||
|
|
||||||
SetPolyFillMode(hdc, ALTERNATE);
|
SetPolyFillMode(hDC, ALTERNATE);
|
||||||
region = PathToRegion(hdc);
|
region = PathToRegion(hDC);
|
||||||
// ExtSelectClipRgn(hdc, region, RGN_COPY);
|
if (clipRegion)
|
||||||
DeleteObject(clipRegion);
|
{
|
||||||
clipRegion = region;
|
CombineRgn(clipRegion, clipRegion, region, RGN_AND);
|
||||||
|
DeleteObject(region);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clipRegion = region;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case path_clip:
|
case path_clip:
|
||||||
{
|
{
|
||||||
HRGN region;
|
HRGN region;
|
||||||
|
|
||||||
SetPolyFillMode(hdc, WINDING);
|
SetPolyFillMode(hDC, WINDING);
|
||||||
region = PathToRegion(hdc);
|
region = PathToRegion(hDC);
|
||||||
// ExtSelectClipRgn(hdc, region, RGN_COPY);
|
if (clipRegion)
|
||||||
DeleteObject(clipRegion);
|
{
|
||||||
clipRegion = region;
|
CombineRgn(clipRegion, clipRegion, region, RGN_AND);
|
||||||
|
DeleteObject(region);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clipRegion = region;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[self releaseHDC: hdc];
|
[self releaseHDC: hDC];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* clip does not delete the current path, so we only clear the path if the
|
* clip does not delete the current path, so we only clear the path if the
|
||||||
|
@ -566,94 +635,81 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
|
|
||||||
- (void) DPSinitclip;
|
- (void) DPSinitclip;
|
||||||
{
|
{
|
||||||
HDC hdc;
|
if (clipRegion)
|
||||||
|
{
|
||||||
hdc = [self getHDC];
|
DeleteObject(clipRegion);
|
||||||
SelectClipRgn(hdc, NULL);
|
clipRegion = NULL;
|
||||||
DeleteObject(clipRegion);
|
}
|
||||||
clipRegion = NULL;
|
|
||||||
[self releaseHDC: hdc];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)DPSrectfill: (float)x : (float)y : (float)w : (float)h
|
- (void)DPSrectfill: (float)x : (float)y : (float)w : (float)h
|
||||||
{
|
{
|
||||||
HDC hdc;
|
HDC hDC;
|
||||||
HBRUSH brush;
|
HBRUSH brush;
|
||||||
RECT rect;
|
RECT rect;
|
||||||
|
|
||||||
|
hDC = [self getHDC];
|
||||||
|
if (!hDC)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
brush = GetCurrentObject(hDC, OBJ_BRUSH);
|
||||||
rect = GSViewRectToWin(self, NSMakeRect(x, y, w, h));
|
rect = GSViewRectToWin(self, NSMakeRect(x, y, w, h));
|
||||||
hdc = [self getHDC];
|
FillRect(hDC, &rect, brush);
|
||||||
brush = GetCurrentObject(hdc, OBJ_BRUSH);
|
[self releaseHDC: hDC];
|
||||||
FillRect(hdc, &rect, brush);
|
|
||||||
[self releaseHDC: hdc];
|
|
||||||
|
|
||||||
/*
|
|
||||||
NSPoint origin = [ctm pointInMatrixSpace: NSMakePoint(x, y)];
|
|
||||||
NSSize size = [ctm sizeInMatrixSpace: NSMakeSize(w, h)];
|
|
||||||
|
|
||||||
if (viewIsFlipped)
|
|
||||||
origin.y -= size.height;
|
|
||||||
ASSIGN(path, [NSBezierPath bezierPathWithRect:
|
|
||||||
NSMakeRect(origin.x, origin.y,
|
|
||||||
size.width, size.height)]);
|
|
||||||
//NSLog(@"Fill rect %@", NSStringFromRect(NSMakeRect(origin.x, origin.y,
|
|
||||||
// size.width, size.height)));
|
|
||||||
[self DPSfill];
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)DPSrectstroke: (float)x : (float)y : (float)w : (float)h
|
- (void)DPSrectstroke: (float)x : (float)y : (float)w : (float)h
|
||||||
{
|
{
|
||||||
NSPoint origin = [ctm pointInMatrixSpace: NSMakePoint(x, y)];
|
NSRect rect = NSMakeRect(x, y, w, h);
|
||||||
NSSize size = [ctm sizeInMatrixSpace: NSMakeSize(w, h)];
|
|
||||||
|
|
||||||
if (size.width > 0)
|
rect = [ctm rectInMatrixSpace: rect];
|
||||||
size.width--;
|
if (rect.size.width > 0)
|
||||||
if (size.height > 0)
|
rect.size.width--;
|
||||||
size.height--;
|
if (rect.size.height > 0)
|
||||||
if (viewIsFlipped)
|
rect.size.height--;
|
||||||
origin.y -= size.height;
|
rect.origin.y += 1;
|
||||||
else
|
|
||||||
origin.y += 1;
|
|
||||||
|
|
||||||
ASSIGN(path, [NSBezierPath bezierPathWithRect:
|
ASSIGN(path, [NSBezierPath bezierPathWithRect: rect]);
|
||||||
NSMakeRect(origin.x, origin.y,
|
//NSLog(@"Stroke rect %@", NSStringFromRect(rect));
|
||||||
size.width, size.height)]);
|
|
||||||
//NSLog(@"Stroke rect %@", NSStringFromRect(NSMakeRect(origin.x, origin.y,
|
|
||||||
// size.width, size.height)));
|
|
||||||
[self DPSstroke];
|
[self DPSstroke];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)DPSrectclip: (float)x : (float)y : (float)w : (float)h
|
- (void)DPSrectclip: (float)x : (float)y : (float)w : (float)h
|
||||||
{
|
{
|
||||||
NSPoint origin = [ctm pointInMatrixSpace: NSMakePoint(x, y)];
|
RECT rect;
|
||||||
NSSize size = [ctm sizeInMatrixSpace: NSMakeSize(w, h)];
|
HRGN region;
|
||||||
|
|
||||||
size.width++;
|
rect = GSViewRectToWin(self, NSMakeRect(x, y, w, h));
|
||||||
size.height++;
|
region = CreateRectRgnIndirect(&rect);
|
||||||
if (viewIsFlipped)
|
if (clipRegion)
|
||||||
origin.y -= size.height;
|
{
|
||||||
ASSIGN(path, [NSBezierPath bezierPathWithRect:
|
CombineRgn(clipRegion, clipRegion, region, RGN_AND);
|
||||||
NSMakeRect(origin.x, origin.y,
|
DeleteObject(region);
|
||||||
size.width, size.height)]);
|
}
|
||||||
//NSLog(@"Clip rect %@", NSStringFromRect(NSMakeRect(origin.x, origin.y,
|
else
|
||||||
// size.width, size.height)));
|
{
|
||||||
[self DPSclip];
|
clipRegion = region;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)DPSshow: (const char *)s
|
- (void)DPSshow: (const char *)s
|
||||||
{
|
{
|
||||||
NSPoint current = [path currentPoint];
|
NSPoint current = [path currentPoint];
|
||||||
POINT p;
|
POINT p;
|
||||||
HDC hdc;
|
HDC hDC;
|
||||||
//float ascent = [font ascender];
|
|
||||||
|
hDC = [self getHDC];
|
||||||
|
if (!hDC)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
p = GSWindowPointToMS(self, current);
|
p = GSWindowPointToMS(self, current);
|
||||||
hdc = [self getHDC];
|
|
||||||
[(WIN32FontInfo*)[font fontInfo] draw: s lenght: strlen(s)
|
[(WIN32FontInfo*)[font fontInfo] draw: s lenght: strlen(s)
|
||||||
onDC: hdc at: p];
|
onDC: hDC at: p];
|
||||||
//TextOut(hdc, p.x, p.y - ascent, s, strlen(s));
|
[self releaseHDC: hDC];
|
||||||
[self releaseHDC: hdc];
|
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -726,7 +782,7 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
|
|
||||||
@implementation WIN32GState (WinOps)
|
@implementation WIN32GState (WinOps)
|
||||||
|
|
||||||
- (void) setStyle: (HDC)hdc
|
- (void) setStyle: (HDC)hDC
|
||||||
{
|
{
|
||||||
HPEN pen;
|
HPEN pen;
|
||||||
HBRUSH brush;
|
HBRUSH brush;
|
||||||
|
@ -734,14 +790,14 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
int join;
|
int join;
|
||||||
int cap;
|
int cap;
|
||||||
DWORD penStyle;
|
DWORD penStyle;
|
||||||
SetBkMode(hdc, TRANSPARENT);
|
SetBkMode(hDC, TRANSPARENT);
|
||||||
/*
|
/*
|
||||||
br.lbStyle = BS_SOLID;
|
br.lbStyle = BS_SOLID;
|
||||||
br.lbColor = color;
|
br.lbColor = color;
|
||||||
brush = CreateBrushIndirect(&br);
|
brush = CreateBrushIndirect(&br);
|
||||||
*/
|
*/
|
||||||
brush = CreateSolidBrush(wfcolor);
|
brush = CreateSolidBrush(wfcolor);
|
||||||
oldBrush = SelectObject(hdc, brush);
|
oldBrush = SelectObject(hDC, brush);
|
||||||
|
|
||||||
switch (joinStyle)
|
switch (joinStyle)
|
||||||
{
|
{
|
||||||
|
@ -795,72 +851,84 @@ HBITMAP GSCreateBitmap(HDC hdc, int pixelsWide, int pixelsHigh,
|
||||||
&br,
|
&br,
|
||||||
0, NULL);
|
0, NULL);
|
||||||
|
|
||||||
oldPen = SelectObject(hdc, pen);
|
oldPen = SelectObject(hDC, pen);
|
||||||
|
|
||||||
SetMiterLimit(hdc, miterlimit, NULL);
|
SetMiterLimit(hDC, miterlimit, NULL);
|
||||||
|
|
||||||
SetTextColor(hdc, wfcolor);
|
SetTextColor(hDC, wfcolor);
|
||||||
SelectClipRgn(hdc, clipRegion);
|
|
||||||
|
oldClipRegion = CreateRectRgn(0, 0, 1, 1);
|
||||||
|
if (1 != GetClipRgn(hDC, oldClipRegion))
|
||||||
|
{
|
||||||
|
DeleteObject(oldClipRegion);
|
||||||
|
oldClipRegion = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectClipRgn(hDC, clipRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) restoreStyle: (HDC)hdc
|
- (void) restoreStyle: (HDC)hDC
|
||||||
{
|
{
|
||||||
HGDIOBJ old;
|
HGDIOBJ old;
|
||||||
|
|
||||||
old = SelectObject(hdc, oldBrush);
|
SelectClipRgn(hDC, oldClipRegion);
|
||||||
|
DeleteObject(oldClipRegion);
|
||||||
|
oldClipRegion = NULL;
|
||||||
|
|
||||||
|
old = SelectObject(hDC, oldBrush);
|
||||||
DeleteObject(old);
|
DeleteObject(old);
|
||||||
|
|
||||||
old = SelectObject(hdc, oldPen);
|
old = SelectObject(hDC, oldPen);
|
||||||
DeleteObject(old);
|
DeleteObject(old);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (HDC) getHDC
|
- (HDC) getHDC
|
||||||
{
|
{
|
||||||
WIN_INTERN *win;
|
WIN_INTERN *win;
|
||||||
HDC hdc;
|
HDC hDC;
|
||||||
|
|
||||||
if (NULL == window)
|
if (NULL == window)
|
||||||
{
|
{
|
||||||
NSLog(@"No window in getHDC");
|
//Log(@"No window in getHDC");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
win = (WIN_INTERN *)GetWindowLong((HWND)window, GWL_USERDATA);
|
win = (WIN_INTERN *)GetWindowLong((HWND)window, GWL_USERDATA);
|
||||||
if (win && win->useHDC)
|
if (win && win->useHDC)
|
||||||
{
|
{
|
||||||
hdc = win->hdc;
|
hDC = win->hdc;
|
||||||
//NSLog(@"getHDC found DC %d", hdc);
|
//NSLog(@"getHDC found DC %d", hDC);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hdc = GetDC((HWND)window);
|
hDC = GetDC((HWND)window);
|
||||||
//NSLog(@"getHDC using window DC %d", hdc);
|
//NSLog(@"getHDC using window DC %d", hDC);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hdc)
|
if (!hDC)
|
||||||
{
|
{
|
||||||
NSLog(@"No DC in getHDC");
|
//Log(@"No DC in getHDC");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self setStyle: hdc];
|
[self setStyle: hDC];
|
||||||
return hdc;
|
return hDC;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) releaseHDC: (HDC)hdc
|
- (void) releaseHDC: (HDC)hDC
|
||||||
{
|
{
|
||||||
WIN_INTERN *win;
|
WIN_INTERN *win;
|
||||||
|
|
||||||
if (NULL == window ||
|
if (NULL == window ||
|
||||||
NULL == hdc)
|
NULL == hDC)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self restoreStyle: hdc];
|
[self restoreStyle: hDC];
|
||||||
win = (WIN_INTERN *)GetWindowLong((HWND)window, GWL_USERDATA);
|
win = (WIN_INTERN *)GetWindowLong((HWND)window, GWL_USERDATA);
|
||||||
if (win && !win->useHDC)
|
if (win && !win->useHDC)
|
||||||
ReleaseDC((HWND)window, hdc);
|
ReleaseDC((HWND)window, hDC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue