17 #define USE_GRADIENTCOLOR_ASM 1 // Use _gradcolor.asm 18 #define USE_SCALECOLOR_ASM 0 // Use C++ fallback implementation 20 #define USE_GRADIENTCOLOR_ASM 0 // Use C++ fallback implementation 21 #define USE_SCALECOLOR_ASM 0 // Use C++ fallback implementation 33 return ::CreateFont( Points, 0,0,0, Weight, 0,0,0, Charset,
34 OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, Quality,
48 else height = -MulDiv( Points, GetDeviceCaps( hdc, LOGPIXELSY ),72 );
69 HDC hdc = GetDC( hWnd );
71 ReleaseDC( hWnd, hdc );
72 if (pLogFont) *pLogFont = lf;
81 if (MoveToEx( dc, 0,0, &xy ))
82 MoveToEx( dc, xy.x, xy.y, NULL );
90 HWND wnd = WindowFromDC( dc );
91 if (wnd && ReleaseDC( wnd, dc )) dc = (HDC)NULL;
99 return GetDC( GetDesktopWindow() );
104 ReleaseDC( GetDesktopWindow(), hDeskDC );
112 HDC hMemDC = CreateCompatibleDC( hdc );
113 if (cx && cy && hMemDC)
115 HBITMAP hBmp = CreateCompatibleBitmap( hdc, cx, cy );
116 HBITMAP oldBmp = SelectBitmap( hMemDC, hBmp );
117 if (pOldBmp) *pOldBmp = oldBmp;
128 HBITMAP memBmp = (HBITMAP) GetCurrentObject( hMemDC, OBJ_BITMAP );
131 oldBmp = SelectBitmap( hMemDC, oldBmp );
133 if (oldBmp != memBmp)
DPrint(
DP_WARNING,
_F(
"oldBmp != memBmp selected in hMemDC.\n") );
144 pLpi->x = GetDeviceCaps( hdc, LOGPIXELSX );
145 pLpi->y = GetDeviceCaps( hdc, LOGPIXELSY );
151 #if 1 // Revised to use the new CreateMemoryDC() and DeleteMemoryDC(). 157 if (!cx) cx =
SYSMET( CXSMICON );
158 if (!cy) cy =
SYSMET( CYSMICON );
159 if (!hbrBkg) hbrBkg =
SYSHBR( 3DFACE );
162 SetRect( &r, 0,0, cx,cy );
163 FillRect( mdc, &r, hbrBkg );
164 DrawIconEx( mdc, 0,0, hIcon, cx,cy, 0, NULL, DI_NORMAL );
169 #else // Original, plain Win32 170 HBITMAP WINAPI
CreateIconBitmap( HICON hIcon, HBRUSH hbrBkg, UINT cx, UINT cy )
172 if (!cx) cx =
SYSMET( CXSMICON );
173 if (!cy) cy =
SYSMET( CYSMICON );
176 HDC mdc = CreateCompatibleDC( hdc );
177 HBITMAP mbm = CreateCompatibleBitmap( hdc, cx, cy );
180 mbm = SelectBitmap( mdc, mbm );
181 SetRect( &r, 0,0, cx,cy );
182 FillRect( mdc, &r, hbrBkg );
183 DrawIconEx( mdc, 0,0, hIcon, cx,cy, 0, NULL, DI_NORMAL );
184 mbm = SelectBitmap( mdc, mbm );
195 BITMAP bim; ::GetObject( img,
sizeof(BITMAP), &bim );
196 RECT r = { 0,0, bim.bmWidth, bim.bmHeight };
198 HDC sdc = CreateCompatibleDC( NULL );
199 HBITMAP obs = (HBITMAP) SelectObject( sdc, img );
200 COLORREF ocs = SetBkColor( sdc, transp );
202 HDC mdc = CreateCompatibleDC( NULL );
203 HBITMAP mask = CreateBitmap( bim.bmWidth, bim.bmHeight, 1,1,NULL );
204 HBITMAP obd = (HBITMAP) SelectObject( mdc, mask );
206 BitBlt( mdc, 0,0, bim.bmWidth, bim.bmHeight, sdc, 0,0, SRCCOPY );
207 InvertRect( mdc, &r );
209 #if 0 // Superfluous cleaning up, since the DCs will be deleted 210 SelectObject( mdc, obd );
211 SetBkColor( sdc, ocs );
212 SelectObject( sdc, obs );
220 #pragma warning( disable: 4533 ) // initialization of 'r' is skipped by 'goto __cab_Exit' 230 SetLastError( ERROR_INVALID_FUNCTION );
235 HBITMAP obmMem, obmTmp, hbTmp;
236 UINT _cx = mu*cx, _cy = mu*cy;
239 RECT r =
MkRect( 0,0, _cx, _cy );
249 #ifndef HAVE_STRUCTURED_EH 250 ok = PaintBitmap( &ps );
252 __try { ok = PaintBitmap( &ps ); }
256 GetExceptionCode(), PaintBitmap );
266 if ( !ok ) DeleteBitmap( hbTmp );
270 hTmpDC = CreateCompatibleDC( hMemDC );
271 obmTmp = SelectBitmap( hTmpDC, hbTmp );
273 SetStretchBltMode( hMemDC, HALFTONE );
274 SetBrushOrgEx( hMemDC, 0,0, NULL );
275 StretchBlt( hMemDC, 0,0, cx, cy, hTmpDC, 0,0, _cx, _cy, SRCCOPY );
279 SelectBitmap( hTmpDC, obmTmp );
286 #pragma warning( default: 4533 ) 292 return hObj ? (DeleteObject( hObj ) ? NULL : hObj) : hObj;
323 case OBJ_BRUSH: DataSize =
sizeof(LOGBRUSH);
break;
324 case OBJ_FONT: DataSize =
sizeof(LOGFONT);
break;
325 case OBJ_PEN: DataSize =
sizeof(LOGPEN);
break;
326 case OBJ_EXTPEN: DataSize =
sizeof(EXTLOGPEN);
break;
327 case OBJ_BITMAP: DataSize =
sizeof(BITMAP);
break;
328 case OBJ_PAL: DataSize =
sizeof(
WORD);
break;
329 case OBJ_COLORSPACE: DataSize =
sizeof(LOGCOLORSPACE);
break;
331 DataSize =
sizeof(DIBSECTION);
332 ObjType = OBJ_BITMAP;
336 hObj = GetCurrentObject( hdc, ObjType );
337 if (hObj && DataSize) GetObject( hObj, DataSize, pObjData );
346 GetObject( hBmp,
sizeof(bm), &bm );
347 HDC mdc = CreateCompatibleDC( hdc );
348 HBITMAP hbm = SelectBitmap( mdc, hBmp );
351 hdc, x,y, bm.bmWidth, bm.bmHeight, mdc,0,0, hMask,0,0,
R4_MASKBLT 354 SelectBitmap( mdc, hbm );
362 HDC hdc,
int x,
int y,
int w,
int h, HBITMAP hBmp, COLORREF cTrans
366 GetObject( hBmp,
sizeof(bm), &bm );
367 if (!w) w = bm.bmWidth;
368 if (!h) h = bm.bmHeight;
369 HDC mdc = CreateCompatibleDC( hdc );
370 HBITMAP hbm = SelectBitmap( mdc, hBmp );
373 hdc, x,y, w,h, mdc, 0,0, bm.bmWidth, bm.bmHeight, cTrans
376 SelectBitmap( mdc, hbm );
383 void WINAPI
DrawBitmap( HDC hdc,
int x,
int y, HBITMAP hBmp )
386 GetObject( hBmp,
sizeof(bm), &bm );
387 HDC mdc = CreateCompatibleDC( hdc );
388 HBITMAP hbm = SelectBitmap( mdc, hBmp );
390 BitBlt( hdc, x, y, bm.bmWidth, bm.bmHeight, mdc, 0,0, SRCCOPY );
392 SelectBitmap( mdc, hbm );
399 HDC hdc,
int x,
int y,
int cx,
int cy,
400 HBITMAP hBmp,
int imx,
int imy,
int imw,
int imh,
406 BITMAP bm; GetObject( hBmp,
sizeof(bm), &bm );
407 if (!imw) imw = bm.bmWidth;
408 if (!imh) imh = bm.bmHeight;
412 HWND hWnd = WindowFromDC( hdc );
413 RECT r; GetClientRect( hWnd, &r );
414 if (!cx) cx = r.right;
415 if (!cy) cy = r.bottom;
420 HDC mdc = CreateCompatibleDC( hdc );
421 HBITMAP hbm = SelectBitmap( mdc, hBmp );
422 int sbmode = SetStretchBltMode( hdc, HALFTONE );
423 SetBrushOrgEx( hdc, 0, 0, NULL );
425 StretchBlt( hdc, x, y, cx, cy, mdc, imx, imy, imw, imh, rasterOp );
427 SetStretchBltMode( hdc, sbmode );
428 SelectBitmap( mdc, hbm );
444 GradientFill( hdc, vtx,2, &mesh,1, opt );
447 void WINAPI
DrawGradientRect( HDC hdc, PRECT pRc, COLORREF c1, COLORREF c2, UINT type )
452 GRADIENT_TRIANGLE mesh[2];
454 BYTE( (
WORD(GetRValue(c1)) + GetRValue(c2)) / 2),
455 BYTE( (
WORD(GetGValue(c1)) + GetGValue(c2)) / 2),
456 BYTE( (
WORD(GetBValue(c1)) + GetBValue(c2)) / 2)
465 GradientFill( hdc, vtx,4, mesh,2, GRADIENT_FILL_TRIANGLE );
473 GradientFill( hdc, vtx,2, &mesh,1, type );
480 pVtx->x = x; pVtx->y = y;
481 pVtx->Red = COLOR16( GetRValue( cr )) << 8;
482 pVtx->Green = COLOR16( GetGValue( cr )) << 8;
483 pVtx->Blue = COLOR16( GetBValue( cr )) << 8;
484 pVtx->Alpha = COLOR16( Alpha ) << 8;
487 void WINAPI
SetTriMesh( PGRADIENT_TRIANGLE pTri, UINT Vtx1, UINT Vtx2, UINT Vtx3 )
489 pTri->Vertex1 = Vtx1;
490 pTri->Vertex2 = Vtx2;
491 pTri->Vertex3 = Vtx3;
494 void WINAPI
SetRectMesh( PGRADIENT_RECT pRect, UINT TopLeft, UINT BotRight )
496 pRect->UpperLeft = TopLeft;
497 pRect->LowerRight = BotRight;
503 if (on) InvalidateRect( hwnd, NULL,
false );
506 void WINAPI
Line( HDC hdc,
int x1,
int y1,
int x2,
int y2 )
508 MoveToEx( hdc, x1, y1, NULL );
509 LineTo( hdc, x2, y2 );
513 POINT* Vtx,
int xOrg,
int yOrg,
int Radius,
double Orientation )
515 static const double angleStep = (2.0 * M_PI) / 3.0;
516 double& dir = Orientation;
521 Vtx[0].x = xOrg + int( Radius * cos( dir ));
522 Vtx[0].y = yOrg - int( Radius * sin( dir ));
523 Vtx[1].x = xOrg + int( Radius * cos( dir + angleStep ));
524 Vtx[1].y = yOrg - int( Radius * sin( dir + angleStep ));
525 Vtx[2].x = xOrg + int( Radius * cos( dir - angleStep ));
526 Vtx[2].y = yOrg - int( Radius * sin( dir - angleStep ));
530 HDC hdc,
int xOrg,
int yOrg,
int Radius,
double Orientation )
544 Polygon( hdc, pt, 3 );
553 return (lum > 255) ? 255 : (
BYTE) lum;
556 #if !USE_SCALECOLOR_ASM // In _gradcolor.asm 561 if (mul == div) result = color;
564 BYTE rr = _mulimClr( GetRValue( color ), mul, div );
565 BYTE gg = _mulimClr( GetGValue( color ), mul, div );
566 BYTE bb = _mulimClr( GetBValue( color ), mul, div );
567 result = RGB( rr,gg,bb );
573 #if !USE_GRADIENTCOLOR_ASM // C++ fallback implementation 580 BYTE r1 = GetRValue( c1 );
581 BYTE g1 = GetGValue( c1 );
582 BYTE b1 = GetBValue( c1 );
583 SHORT dr = SHORT(GetRValue( c2 )) - r1;
584 SHORT dg = SHORT(GetGValue( c2 )) - g1;
585 SHORT db = SHORT(GetBValue( c2 )) - b1;
587 WORD r =
WORD(r1) + ((dr * SHORT(Ix)) / N);
588 WORD g =
WORD(g1) + ((dg * SHORT(Ix)) / N);
589 WORD b =
WORD(b1) + ((db * SHORT(Ix)) / N);
598 static const float coef[3] = { 0.2126f, 0.7152f, 0.0722f };
601 coef[0] * GetRValue(rgb) +
602 coef[1] * GetGValue(rgb) +
603 coef[2] * GetBValue(rgb)
605 return RGB( luma,luma,luma );
613 MapWindowPoints( HWND_DESKTOP, hWnd, &pt, 1 );
614 return OffsetRgn( hRgn, pt.x, pt.y );
619 DWORD cbRgn = GetRegionData( hRgn, 0, NULL );
620 RGNDATA* pRgn = (RGNDATA*)
mem_Alloc( cbRgn );
623 GetRegionData( hRgn, cbRgn, pRgn );
624 if (ppRc) *ppRc = (RECT*) pRgn->Buffer;
634 #if _DEBUG // Dump region data to the debugger. 641 RECT r = pRgn->rdh.rcBound;
642 DPrint(
DP_INFO,
_F(
"%s: Bounds={%li,%li,%li,%li}, Count=%lu, Type=%lu\n"),
643 Title, r.left, r.top, r.right, r.bottom, pRgn->rdh.nCount, pRgn->rdh.iType
645 for(
DWORD ix = 0, N = pRgn->rdh.nCount; ix < N; ++ix )
649 ix, r.left, r.top, r.right, r.bottom );
662 int nPts = GetPath( hdc, NULL, NULL, 0 );
663 bool ok = (nPts > 1);
671 LPPOINT pPt = (LPPOINT)
mem_Alloc( nPts *
sizeof(POINT) + nPts );
672 LPBYTE pType = (LPBYTE)( pPt + nPts );
673 if ( ok = (pPt != NULL) )
675 int cPts = GetPath( hdc, pPt, pType, nPts );
679 RECT r = { LONG_MAX, LONG_MAX, 0,0 };
681 for(
int ix = 0; ix < cPts; ix++, ppt++ )
683 long x = ppt->x, y = ppt->y;
684 if (x < r.left) r.left = x;
685 if (x > r.right) r.right = x;
686 if (y < r.top) r.top = y;
687 if (y > r.bottom) r.bottom = y;
690 pData->nPoints = cPts;
692 pData->pType = pType;
696 DWORD err = GetLastError();
730 HRGN pathRgn = PathToRegion( hdc );
750 *pBounds = rgnData->rdh.rcBound;
761 for( UINT ix=0; ix < nPts; ix++, pt++ )
772 PRECT pr = (PRECT) prd->Buffer;
773 OffsetRect( &prd->rdh.rcBound, dx, dy );
774 for(
DWORD ix=0, N=prd->rdh.nCount; ix < N; ix++, pr++ )
776 OffsetRect( pr, dx, dy );
784 static const FIXED zero = {0,0}, one = {0,1};
785 pm->eM11 = pm->eM22 = one;
786 pm->eM12 = pm->eM21 = zero;
void SetIdentityMat2(MAT2 *pm)
void WINAPI SetTriMesh(PGRADIENT_TRIANGLE pTri, UINT Vtx1, UINT Vtx2, UINT Vtx3)
void WINAPI ReleaseDesktopDC(HDC hDeskDC)
void WINAPI FreeGdiPathData(PGdiPathData pData)
HGDIOBJ WINAPI GetCurrentObjectEx(HDC hdc, UINT ObjType, PVOID pObjData)
HGDIOBJ WINAPI DeleteObjectEx(HGDIOBJ hObj)
PVOID ctx
User's context, if any.
HDC WINAPI GetDesktopDC()
HDC WINAPI ReleaseWndDC(HDC dc)
RECT MkRect(LONG L, LONG T, LONG R, LONG B)
int WINAPI ScreenFontHeight(WORD Points)
HFONT WINAPI CreateFontEx(CSTR Typeface, int Points, int Weight, DWORD Charset, DWORD Quality)
void * mem_Alloc(size_t Bytes)
void WINAPI DrawBitmapEx(HDC hdc, int x, int y, int cx, int cy, HBITMAP hBmp, int imx, int imy, int imw, int imh, DWORD rasterOp)
#define GetCurrentFontEx(dc, plfont)
bool WINAPI GetGdiPathBounds(HDC hdc, PRECT pBounds)
bool WINAPI DrawTransparentBitmap(HDC hdc, int x, int y, int w, int h, HBITMAP hBmp, COLORREF cTrans)
void __cdecl DPrint(int Level, CSTR Fmt,...)
void WINAPI SetRedraw(HWND hwnd, bool on)
void OffsetPoints(POINT *Pts, UINT nPts, int dx, int dy)
void OffsetRgnData(PRGNDATA prd, int dx, int dy)
void WINAPI SetTriVertex(PTRIVERTEX pVtx, int x, int y, COLORREF cr, BYTE Alpha)
int WINAPI MapRegionToWindow(HRGN hRgn, HWND hWnd)
#define WM_SetRedraw(hwnd, on)
UINT mu
Scaling multiplier.
COLORREF WINAPI ScaleColorRef(COLORREF color, BYTE mul, BYTE div)
void WINAPI DrawGradientRect(HDC hdc, PRECT pRc, COLORREF c1, COLORREF c2, UINT opt)
RGNDATA *WINAPI FreeRegionData(RGNDATA *pRgn)
#define TRACE_IF(cond,...)
void WINAPI SetRectMesh(PGRADIENT_RECT pRect, UINT TopLeft, UINT BotRight)
void * mem_Free(void *pBlk)
void WINAPI GetScreenLPI(PPOINT pLpi)
COLORREF WINAPI GradientColor(COLORREF c1, COLORREF c2, WORD Ix, WORD Length)
HBITMAP WINAPI CreateMaskBitmap(HBITMAP img, COLORREF transp)
RGNDATA *WINAPI AllocAndGetRegionData(HRGN hRgn, RECT **ppRc)
bool(__stdcall * PFnPaintBitmap)(PAINTBMPSTRUCT *p)
CSTR SysErrorMsg(DWORD Err=0, TSTR Buf=NULL, UINT Length=0)
void WINAPI DrawBitmap(HDC hdc, int x, int y, HBITMAP hBmp)
HRGN WINAPI GetGdiPathRgnBounds(HDC hdc, OUT PRECT pBounds)
struct _gdiPathData * PGdiPathData
void WINAPI Line(HDC hdc, int x1, int y1, int x2, int y2)
bool __forceinline bool_cast(BOOL B52)
bool WINAPI GetGdiPathData(HDC hdc, OUT PGdiPathData pData)
HRGN WINAPI GetGdiPathRgn(HDC hdc, OUT RGNDATA **pRgnData, OPTOUT RECT **pRgnRects)
HDC WINAPI CreateMemoryDC(UINT cx, UINT cy, HBITMAP *pOldBmp)
Debug and error handling support.
RECT rcPaint
Upscaled drawing rect.
Common include; Added types, small "ubiquitous" utilities, et c.
void WINAPI GetIsoTriangleVertices(POINT *Vtx, int xOrg, int yOrg, int Radius, double Orientation)
POINT WINAPI WhereXY(HDC dc)
COLORREF WINAPI GrayScaleColor(COLORREF rgb)
HBITMAP WINAPI DeleteMemoryDC(HDC hMemDC, HBITMAP oldBmp)
HBITMAP WINAPI CreateIconBitmap(HICON hIcon, HBRUSH hbrBkg, UINT cx, UINT cy)
int WINAPI FontHeight(HDC hdc, int Points)
bool WINAPI DrawMaskedBitmap(HDC hdc, int x, int y, HBITMAP hBmp, HBITMAP hMask)
void WINAPI DrawIsoTriangle(HDC hdc, int xOrg, int yOrg, int Radius, double Orientation)
HBITMAP WINAPI CreateAntialiasedBitmap(UINT cx, UINT cy, UINT mu, PFnPaintBitmap PaintBitmap, PVOID Ctx)
RECT Bounds
Bounding rect for the whole path.
void WINAPI DumpRegionData(CSTR Title, HRGN hRgn)
HFONT WINAPI GetWndFont(HWND hWnd, LOGFONT *pLogFont)