|
|
1.1 ! root 1: #ifndef __CANVAS_HXX_ ! 2: #define __CANVAS_HXX_ ! 3: ! 4: //-------------------------------------------------------------------- ! 5: // File: Canvas.hxx ! 6: // ! 7: // Classes: ! 8: // CPoint - POINT with vector operations ! 9: // CCanvas - Base class for Device contexts ! 10: // CScreenCanvas - Device context for client area or display ! 11: // CPaintCanvas - Device context for WM_PAINT message handling ! 12: // ! 13: // History: 22-Jan-1993 Asmusf Created ! 14: // ! 15: // Copyright (c) 1993 Microsoft Corp. All Rights reserved ! 16: // ! 17: //-------------------------------------------------------------------- ! 18: ! 19: //========= CPoint ========================================== ! 20: ! 21: class CPoint: public tagPOINT ! 22: { ! 23: public: ! 24: CPoint() {x=0; y=0; }; ! 25: CPoint(COORD X, COORD Y) {x = X; y = Y; }; ! 26: CPoint(POINT pt) {x = pt.x; y=pt.y; }; ! 27: ! 28: CPoint operator +(CPoint &pt){ return CPoint(x+pt.x, y+pt.y); }; ! 29: CPoint operator -(CPoint &pt){ return CPoint(x-pt.x, y-pt.y); }; ! 30: CPoint operator *(int c) { return CPoint(x*c, y*c); }; ! 31: CPoint operator /(int c) { return CPoint(x/c, y/c); }; ! 32: }; ! 33: ! 34: //======== CCanvas ========================================== ! 35: // Base class: Any form of canvas ! 36: // Inline methods only for speed. ! 37: ! 38: class CCanvas ! 39: { ! 40: public: ! 41: CCanvas():_hdc(0) ! 42: { ! 43: } ! 44: ! 45: operator HDC() { return _hdc; } ! 46: ! 47: void TextAlign( WORD aligntype ) ! 48: { ! 49: SetTextAlign(_hdc, aligntype ); ! 50: } ! 51: ! 52: void Line ( COORD x1, COORD y1, COORD x2, COORD y2 ) ! 53: { ! 54: MoveToEx ( _hdc, x1, y1, NULL ); ! 55: LineTo ( _hdc, x2, y2 ); ! 56: } ! 57: ! 58: void Clear ( RECT& rect ) ! 59: { ! 60: // Trick: fast erase with Extended Text Out ! 61: ExtTextOut (_hdc, rect.left, rect.top, ETO_OPAQUE, &rect, TEXT(""), 0, NULL ); ! 62: } ! 63: ! 64: void Text ( int x, int y, LPTSTR buf, int cBuf ) ! 65: { ! 66: TextOut ( _hdc, x, y, buf, cBuf ); ! 67: } ! 68: ! 69: void Char ( int x, int y, TCHAR ch ) ! 70: { ! 71: TextOut ( _hdc, x, y,(LPTSTR) &ch, 1 ); ! 72: } ! 73: ! 74: void Scale(UINT iScale) ! 75: { ! 76: // Logical TWIPS ! 77: SetMapMode (_hdc, MM_ANISOTROPIC); ! 78: ! 79: SetWindowExtEx (_hdc, MulDiv(INCH1,iScale,100), MulDiv(INCH1,iScale,100), NULL); ! 80: SetViewportExtEx (_hdc, GetDeviceCaps (_hdc, LOGPIXELSX), ! 81: GetDeviceCaps (_hdc, LOGPIXELSY), NULL); ! 82: } ! 83: ! 84: void Scroll(int dx, int dy) ! 85: { ! 86: SetWindowOrgEx(_hdc, dx, dy, NULL ); ! 87: } ! 88: ! 89: void DPtoLP( LPPOINT lppt ) ! 90: { ! 91: ::DPtoLP(_hdc, lppt, 1); ! 92: }; ! 93: ! 94: void LPtoDP( LPPOINT lppt ) ! 95: { ! 96: ::LPtoDP(_hdc, lppt, 1); ! 97: }; ! 98: ! 99: protected: ! 100: void Init ( HDC hdc ) ! 101: { ! 102: _hdc = hdc; ! 103: TextAlign(TA_CENTER | TA_BASELINE ); ! 104: }; ! 105: ! 106: HDC _hdc; ! 107: }; ! 108: ! 109: //======== CScreenCanvas ==================================== ! 110: // Device Context ! 111: // Use for painting on client area other than WM_PAINT ! 112: ! 113: class CScreenCanvas: public CCanvas ! 114: { ! 115: public: ! 116: CScreenCanvas ( HWND hwnd ): _hwnd(hwnd) ! 117: { ! 118: Init (GetDC ( hwnd )); ! 119: } ! 120: ! 121: ~CScreenCanvas () ! 122: { ! 123: ReleaseDC ( _hwnd, _hdc ); ! 124: } ! 125: ! 126: protected: ! 127: ! 128: HWND _hwnd; ! 129: }; ! 130: ! 131: //======== CPaintCanvas ===================================== ! 132: // Use for painting after WM_PAINT ! 133: ! 134: class CPaintCanvas: public CCanvas ! 135: { ! 136: public: ! 137: CPaintCanvas ( HWND hwnd ): _hwnd(hwnd) ! 138: { ! 139: BeginPaint ( _hwnd, &_paint ); ! 140: Init ( _paint.hdc ); ! 141: } ! 142: ! 143: ~CPaintCanvas () ! 144: { ! 145: EndPaint(_hwnd, &_paint ); ! 146: } ! 147: ! 148: RECT GetRect() { return _paint.rcPaint; }; ! 149: protected: ! 150: ! 151: PAINTSTRUCT _paint; ! 152: HWND _hwnd; ! 153: }; ! 154: ! 155: #endif ! 156:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.