BOOL DrawMeter(HDC hdc, RECT rect) { static HFONT font; // Plain vanilla font static LOGFONT lf = {0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, ""}; // Draw nice etched edge DrawEdge(hdc, &rect , EDGE_SUNKEN, BF_ADJUST | BF_RECT); // Select font if (font == NULL) { lf.lfHeight = 16; font = CreateFontIndirect(&lf); } // Calculate dimensions int width = rect.right - rect.left; // Move the origin SetViewportOrgEx(hdc, 2, 2, NULL); SelectObject(hdc, font); SetTextAlign(hdc, TA_CENTER); // Draw the meter scale static int as[] = {-40, -20, -14, -10, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3}; for (int i = 0; i < LENGTH(as); i++) { static char s[16]; sprintf(s, "%d", abs(as[i])); float x = pow(10.0, (as[i] + 20.0) / 20.0) / 10.0; x /= pow(10.0, 23.0 / 20.0) / 10.0; x *= (width - 22); x += 10; TextOut(hdc, x, 0, s, strlen(s)); } MoveToEx(hdc, 3, 20, NULL); LineTo(hdc, 8, 20); MoveToEx(hdc, width - 8, 20, NULL); LineTo(hdc, width - 3, 20); MoveToEx(hdc, width - 6, 18, NULL); LineTo(hdc, width - 6, 23); static int at[] = {-10, -5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; for (int i = 0; i < LENGTH(at); i++) { float x = pow(10.0, at[i] / 10.0) / 10.0; x /= pow(10.0, 23.0 / 20.0) / 10.0; x *= (width - 22); x += 10; MoveToEx(hdc, x, 16, NULL); LineTo(hdc, x, 24); } for (int i = 1; i < 26; i += 2) { float x = pow(10.0, (i / 20.0)) / 10.0; x /= pow(10.0, 23.0 / 20.0) / 10.0; x *= (width - 22); x += 10; MoveToEx(hdc, x, 18, NULL); LineTo(hdc, x, 24); } for (int i = 17; i < 48; i += 2) { float x = pow(10.0, (i / 40.0)) / 10.0; x /= pow(10.0, 23.0 / 20.0) / 10.0; x *= (width - 22); x += 10; MoveToEx(hdc, x, 20, NULL); LineTo(hdc, x, 24); } return TRUE; }
void track_bar_impl::draw_thumb (HDC dc, const RECT * rc) const { if (get_theme_handle()) { DrawThemeBackground(get_theme_handle(), dc, get_orientation() ? TKP_THUMBVERT : TKP_THUMB, get_enabled() ? (get_tracking() ? TUS_PRESSED : (get_hot() ? TUS_HOT : TUS_NORMAL)) : TUS_DISABLED, rc, 0); } else { HPEN pn_highlight = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DHIGHLIGHT)); HPEN pn_light = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DLIGHT)); HPEN pn_dkshadow = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW)); HPEN pn_shadow = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW)); HPEN pn_old = SelectPen(dc, pn_highlight); MoveToEx(dc, rc->left, rc->top, 0); LineTo(dc, rc->right-1, rc->top); SelectPen(dc, pn_dkshadow); LineTo(dc, rc->right-1, rc->bottom-1); SelectPen(dc, pn_highlight); MoveToEx(dc, rc->left, rc->top, 0); LineTo(dc, rc->left, rc->bottom-1); SelectPen(dc, pn_dkshadow); LineTo(dc, rc->right, rc->bottom-1); SelectPen(dc, pn_light); MoveToEx(dc, rc->left+1, rc->top+1, 0); LineTo(dc, rc->right-2, rc->top+1); MoveToEx(dc, rc->left+1, rc->top+1, 0); LineTo(dc, rc->left+1, rc->bottom-2); SelectPen(dc, pn_shadow); LineTo(dc, rc->right-1, rc->bottom-2); MoveToEx(dc, rc->right-2, rc->top+1, 0); LineTo(dc, rc->right-2, rc->bottom-2); SelectPen(dc, pn_old); DeleteObject(pn_light); DeleteObject(pn_highlight); DeleteObject(pn_shadow); DeleteObject(pn_dkshadow); RECT rc_fill = *rc; rc_fill.top+=2; rc_fill.left+=2; rc_fill.right-=2; rc_fill.bottom-=2; HBRUSH br = GetSysColorBrush(COLOR_BTNFACE); FillRect(dc, &rc_fill, br); if (!get_enabled()) { COLORREF cr_btnhighlight = GetSysColor(COLOR_BTNHIGHLIGHT); int x, y; for (x=rc_fill.left; x<rc_fill.right; x++) for (y=rc_fill.top; y<rc_fill.bottom; y++) if ((x+y)%2) SetPixel(dc, x, y, cr_btnhighlight); //i dont have anything better than SetPixel } } }
void DockingCont::drawCaptionItem(DRAWITEMSTRUCT *pDrawItemStruct) { HBRUSH bgbrush = NULL; HFONT hOldFont = NULL; RECT rc = pDrawItemStruct->rcItem; HDC hDc = pDrawItemStruct->hDC; HPEN hPen = ::CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_BTNSHADOW)); BITMAP bmp = {0}; HBITMAP hBmpCur = NULL; HBITMAP hBmpOld = NULL; HBITMAP hBmpNew = NULL; UINT length = lstrlen(_pszCaption); INT nSavedDC = ::SaveDC(hDc); // begin with paint ::SetBkMode(hDc, TRANSPARENT); if (_isActive == TRUE) { bgbrush = ::CreateSolidBrush(::GetSysColor(COLOR_ACTIVECAPTION)); ::SetTextColor(hDc, ::GetSysColor(COLOR_CAPTIONTEXT)); } else { bgbrush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE)); } // set text and/or caption grid if (_isTopCaption == TRUE) { if (_isActive == TRUE) { // fill background ::FillRect(hDc, &rc, bgbrush); rc.right -= 1; rc.bottom -= 1; } else { // fill background rc.right -= 1; rc.bottom -= 1; ::FillRect(hDc, &rc, bgbrush); // draw grid lines HPEN hOldPen = (HPEN)::SelectObject(hDc, hPen); MoveToEx(hDc, rc.left , rc.top , NULL); LineTo (hDc, rc.right, rc.top ); LineTo (hDc, rc.right, rc.bottom ); LineTo (hDc, rc.left , rc.bottom ); LineTo (hDc, rc.left , rc.top); } // draw text rc.left += 2; rc.top += 1; rc.right -= 16; hOldFont = (HFONT)::SelectObject(hDc, _hFont); ::DrawText(hDc, _pszCaption, length, &rc, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); // calculate text size and if its trankated... SIZE size = {0}; GetTextExtentPoint32(hDc, _pszCaption, length, &size); _bCaptionTT = (((rc.right - rc.left) < size.cx) ? TRUE : FALSE); ::SelectObject(hDc, hOldFont); } else { // create local font for vertical draw HFONT hFont; if (_isActive == TRUE) { // fill background ::FillRect(hDc, &rc, bgbrush); rc.right -= 1; rc.bottom -= 1; } else { // fill background rc.right -= 1; rc.bottom -= 1; ::FillRect(hDc, &rc, bgbrush); // draw grid lines HPEN hOldPen = (HPEN)::SelectObject(hDc, hPen); MoveToEx(hDc, rc.left , rc.top , NULL); LineTo (hDc, rc.right, rc.top ); LineTo (hDc, rc.right, rc.bottom ); LineTo (hDc, rc.left , rc.bottom ); LineTo (hDc, rc.left , rc.top); } // draw text rc.left += 1; rc.top += HIGH_CAPTION; // to make ellipsis working rc.right = rc.bottom - rc.top; rc.bottom += 14; hFont = ::CreateFont(12, 0, 90 * 10, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, TEXT("MS Shell Dlg")); hOldFont = (HFONT)::SelectObject(hDc, hFont); ::DrawText(hDc, _pszCaption, length, &rc, DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX); // calculate text size and if its trankated... SIZE size = {0}; GetTextExtentPoint32(hDc, _pszCaption, length, &size); _bCaptionTT = (((rc.bottom - rc.top) < size.cy) ? TRUE : FALSE); ::SelectObject(hDc, hOldFont); ::DeleteObject(hFont); } ::DeleteObject(hPen); ::DeleteObject(bgbrush); // draw button HDC dcMem = ::CreateCompatibleDC(NULL); // select correct bitmap if ((_isMouseOver == TRUE) && (_isMouseDown == TRUE)) hBmpCur = ::LoadBitmap(_hInst, MAKEINTRESOURCE(IDB_CLOSE_DOWN)); else hBmpCur = ::LoadBitmap(_hInst, MAKEINTRESOURCE(IDB_CLOSE_UP)); // blit bitmap into the destination ::GetObject(hBmpCur, sizeof(bmp), &bmp); hBmpOld = (HBITMAP)::SelectObject(dcMem, hBmpCur); hBmpNew = ::CreateCompatibleBitmap(dcMem, bmp.bmWidth, bmp.bmHeight); rc = pDrawItemStruct->rcItem; ::SelectObject(hDc, hBmpNew); if (_isTopCaption == TRUE) ::BitBlt(hDc, rc.right-bmp.bmWidth-CLOSEBTN_POS_LEFT, CLOSEBTN_POS_TOP, bmp.bmWidth, bmp.bmHeight, dcMem, 0, 0, SRCCOPY); else ::BitBlt(hDc, CLOSEBTN_POS_LEFT, CLOSEBTN_POS_LEFT, bmp.bmWidth, bmp.bmHeight, dcMem, 0, 0, SRCCOPY); ::SelectObject(dcMem, hBmpOld); ::DeleteObject(hBmpCur); ::DeleteObject(hBmpNew); ::DeleteDC(dcMem); ::RestoreDC(hDc, nSavedDC); }
BOOL CWinMenu::DrawMenuItems(HDC hDC, LPRECT pRect) { if ( hDC == NULL || pRect == NULL ) return FALSE; BOOL bFirst = m_bFirstDraw; m_bFirstDraw = FALSE; CText text; long x = pRect->left + 4; long y = pRect->top + 4; long w = pRect->right - pRect->left - 8; long bx = x; long by = y; // Set colors COLORREF rgbMenu, rgbMenuText, rgbSel, rgbSelText; if ( m_bSystemColors ) { rgbMenu = GetSysColor( COLOR_MENU ); rgbMenuText = GetSysColor( COLOR_MENUTEXT ); rgbSel = GetSysColor( COLOR_HIGHLIGHT ); rgbSelText = GetSysColor( COLOR_HIGHLIGHTTEXT ); } // end if else { rgbMenu = m_rgbMenu; rgbMenuText = m_rgbMenuText; rgbSel = m_rgbSel; rgbSelText = m_rgbSelText; } // end else COLORREF rgbLightPen = ScaleColor( rgbMenu, 100 ); COLORREF rgbDarkPen = ScaleColor( rgbMenu, -150 ); COLORREF rgbBck = rgbMenu; COLORREF rgbBckLt = ScaleColor( rgbBck, 40 ); COLORREF rgbBckDk = ScaleColor( rgbBck, -40 ); COLORREF rgbSelLt = ScaleColor( rgbSel, 80 ); COLORREF rgbSelDk = ScaleColor( rgbSel, -120 ); COLORREF rgbSelTextLt = ScaleColor( rgbSelText, 80 ); COLORREF rgbSelTextDk = ScaleColor( rgbSelText, -150 ); COLORREF rgbBumpLt = ScaleColor( rgbBck, 120 ); COLORREF rgbBumpDk = ScaleColor( rgbBck, -120 ); COLORREF rgbText = rgbMenuText; COLORREF rgbTextLt = ScaleColor( rgbBck, 100 ); COLORREF rgbTextDk = ScaleColor( rgbBck, -100 ); if ( GetColorAvg( rgbSel ) > 128 ) { COLORREF swap = rgbSelTextLt; rgbSelTextLt = rgbSelTextDk; rgbSelTextDk = swap; } // end if // What font does the user want for menu's? NONCLIENTMETRICS info; info.cbSize = sizeof(info); SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( info ), &info, 0 ); // Check for empty menu if ( m_mitems.Size() == 0 ) { COLORREF rgbEmptyLt = ScaleColor( rgbBck, 120 ); COLORREF rgbEmptyDk = ScaleColor( rgbBck, -120 ); if ( GetColorAvg( rgbBck ) < 128 ) { COLORREF swap = rgbEmptyLt; rgbEmptyLt = rgbEmptyDk; rgbEmptyDk = swap; } // end if RECT t; CopyRect( &t, pRect ); text.SetWeight( FW_BOLD ); text.SetFont( &info.lfMenuFont ); text.SetFlags( DT_SINGLELINE | DT_CENTER | DT_VCENTER ); // Make text look recessed OffsetRect( &t, -1, -1 ); text.SetColor( rgbEmptyDk ); text.DrawText( hDC, EMPTY_STR, &t ); OffsetRect( &t, 1, 1 ); text.SetColor( rgbEmptyLt ); text.DrawText( hDC, EMPTY_STR, &t ); } // end if // This kinda bites, but we need to know how far to offset the text BOOL islots = 0; LPMITEMINFO pmi = NULL; while( islots < 2 && ( pmi = (LPMITEMINFO)m_mitems.GetNext( pmi ) ) != NULL ) { // Do we need both icon slots? if ( pmi->icon != NULL && pmi->b != NULL ) islots = 2; // Do we have one islot already? else if ( islots < 1 ) { if ( pmi->icon != NULL ) islots = 1; else if ( pmi->b != NULL && m_hCheck == NULL && m_hUncheck == NULL ) islots = 1; } // end else if } // end while // The icon size long iconsize = m_th - 4; // Draw each item pmi = NULL; while( ( pmi = (LPMITEMINFO)m_mitems.GetNext( pmi ) ) != NULL && x < pRect->right && y < pRect->bottom ) { // Set base coords bx = x; by = y; if ( *pmi->name != NULL ) { POINT pt; GetCursorPos( &pt ); ScreenToClient( &pt ); // Is this item being selected? BOOL bSelected = FALSE; RECT hl; hl.left = pRect->left + 3; hl.right = pRect->right - 4; hl.top = by; hl.bottom = by + m_th; // if ( pt.x > hl.left && pt.x < hl.right && // pt.y > hl.top && pt.y < hl.bottom ) // Add for toolbar if ( pmi->toolbar != NULL && pmi->toolbar->GetNumButtons() ) hl.left += pmi->toolbar->GetWidth(); if ( pmi == m_itemover ) { bSelected = TRUE; // HPEN whitepen = CreatePen( PS_SOLID, 1, RGB( 255, 255, 255 ) ); // HPEN dkgraypen = CreatePen( PS_SOLID, 1, RGB( 50, 50, 50 ) ); HPEN whitepen = CreatePen( PS_SOLID, 1, rgbLightPen ); HPEN dkgraypen = CreatePen( PS_SOLID, 1, rgbDarkPen ); HPEN oldpen = (HPEN)SelectObject( hDC, whitepen ); // Draw white line MoveToEx( hDC, hl.right, hl.top, NULL ); LineTo( hDC, hl.right, hl.bottom ); LineTo( hDC, hl.left, hl.bottom ); // Draw dark gray line SelectObject( hDC, dkgraypen ); MoveToEx( hDC, hl.right, hl.top, NULL ); LineTo( hDC, hl.left, hl.top ); LineTo( hDC, hl.left, hl.bottom ); SelectObject( hDC, oldpen ); DeleteObject( whitepen ); DeleteObject( dkgraypen ); // InflateRect( &hl, -1, -1 ); hl.left += 1; hl.top += 1; // GradientFill( hDC, &hl, RGB( 170, 170, 190 ), RGB( 110, 110, 110 ) ); CGrDC::VertGradientFill( hDC, &hl, rgbSelLt, rgbSelDk ); /* HBRUSH brush = CreateSolidBrush( RGB( 120, 120, 120 ) ); FillRect( hDC, &hl, brush ); DeleteObject( brush ); */ } // end if // Draw toolbar if ( pmi->toolbar != NULL && pmi->toolbar->GetNumButtons() ) { pmi->toolbar->SetHeight( m_th ); RECT tbar; SetRect( &tbar, bx, by, bx + pmi->toolbar->GetWidth(), by + pmi->toolbar->GetHeight() ); if ( bFirst ) pmi->toolbar->CreateToolTips( GetSafeHwnd(), &tbar ); pmi->toolbar->SetMessageTarget( GetSafeHwnd(), WM_MENUCMD ); pmi->toolbar->Draw( GetSafeHwnd(), hDC, &tbar ); bx += pmi->toolbar->GetWidth(); } // end if RECT t; // Calc text box t.left = bx + 4; t.left += islots * iconsize; t.right = pRect->right; t.top = by; t.bottom = by + m_th; // Draw Check if ( pmi->b != NULL ) { RECT icon; SetRect( &icon, bx + 2, by + 2, bx + 2 + iconsize, by + 2 + iconsize ); if ( *pmi->b != FALSE ) { if ( bSelected && m_hHotCheck != NULL ) CGrDC::DrawIcon( hDC, &icon, m_hHotCheck ); // DrawIconEx( hDC, bx + 2, by + 2, m_hHotCheck, iconsize, iconsize, 0, 0, DI_NORMAL ); else if ( m_hCheck != NULL ) CGrDC::DrawIcon( hDC, &icon, m_hCheck ); // DrawIconEx( hDC, bx + 2, by + 2, m_hCheck, iconsize, iconsize, 0, 0, DI_NORMAL ); } // end if else { if ( bSelected && m_hHotUncheck != NULL ) CGrDC::DrawIcon( hDC, &icon, m_hHotUncheck ); // DrawIconEx( hDC, bx + 2, by + 2, m_hHotUncheck, iconsize, iconsize, 0, 0, DI_NORMAL ); else if ( m_hUncheck != NULL ) CGrDC::DrawIcon( hDC, &icon, m_hUncheck ); // DrawIconEx( hDC, bx + 2, by + 2, m_hUncheck, iconsize, iconsize, 0, 0, DI_NORMAL ); } // end else } // end if // Draw icon if ( pmi->icon != NULL ) { long xoff = 2; xoff += iconsize * ( islots - 1 ) + 1; // DrawIconEx( hDC, x + xoff, y + 2, pmi->icon, // 16, 16, 0, 0, DI_NORMAL ); DrawIconEx( hDC, bx + xoff, by + 2, pmi->icon, iconsize, iconsize, 0, 0, DI_NORMAL ); } // end if // Setup the text object text.SetFlags( DT_SINGLELINE | DT_VCENTER ); if ( bSelected ) { text.SetWeight( FW_BOLD ); text.SetFont( &info.lfMenuFont ); // Make text look recessed OffsetRect( &t, -1, -1 ); // text.SetColor( RGB( 0, 0, 0 ) ); text.SetColor( rgbSelTextDk ); text.DrawText( hDC, pmi->name, &t ); OffsetRect( &t, 1, 1 ); text.SetColor( rgbSelTextLt ); } // end if else { // text.SetItalic( FALSE ); text.SetWeight( FW_BOLD ); text.SetFont( &info.lfMenuFont ); // text.SetFont( TFONTSIZE, TFONTTYPE ); // text.SetColor( RGB( 0, 50, 128 ) ); text.SetColor( rgbText ); } // end else // else text.SetColor( rgbText ); // text.SetColor( RGB( 0, 50, 128 ) ); text.DrawText( hDC, pmi->name, &t ); // Draw sub menu indicator if ( pmi->submenu != NULL ) { // Do we have a tick mark icon? if ( m_hTick != NULL ) { RECT ic; SetRect( &ic, t.right - 18, t.top + 5, t.right - 8, t.bottom - 7 ); // Colorize tick icon HICON hMono = NULL; if ( !pmi->submenu->IsEmpty() ) hMono = CGrDC::CreateMonoChromeIcon( m_hTick, GetSysColor( COLOR_ACTIVECAPTION ) ); else hMono = CGrDC::CreateMonoChromeIcon( m_hTick, GetSysColor( COLOR_INACTIVECAPTION ) ); // hMono = CGrDC::CreateMonoChromeIcon( m_hTick, rgbSel ); // else hMono = CGrDC::CreateMonoChromeIcon( m_hTick, rgbBck ); // Draw the icon if ( hMono != NULL ) { CGrDC::DrawIcon( hDC, &ic, hMono ); DestroyIcon( hMono ); } // end if } // end if else { HPEN whitepen = CreatePen( PS_SOLID, 1, rgbLightPen ); HPEN dkgraypen = CreatePen( PS_SOLID, 1, ScaleColor( rgbBck, -10 ) ); HPEN blackpen = CreatePen( PS_SOLID, 1, ScaleColor( rgbBck, -40 ) ); HPEN oldpen = (HPEN)SelectObject( hDC, whitepen ); HBRUSH mbrush; if ( !pmi->submenu->IsEmpty() ) mbrush = CreateSolidBrush( rgbBck ); else mbrush = CreateSolidBrush( ScaleColor( rgbBck, -80 ) ); HBRUSH oldbrush = (HBRUSH)SelectObject( hDC, mbrush ); POINT pts[ 3 ]; pts[ 0 ].x = t.right - 14; pts[ 0 ].y = t.top + 5; pts[ 1 ].x = t.right - 14; pts[ 1 ].y = t.bottom - 7; pts[ 2 ].x = t.right - 8; pts[ 2 ].y = t.top + ( ( t.bottom - t.top ) / 2 ); // Draw the shape Polygon( hDC, pts, sizeof( pts ) / sizeof( POINT ) ); // Draw border MoveToEx( hDC, pts[ 0 ].x, pts[ 0 ].y, NULL ); LineTo( hDC, pts[ 1 ].x, pts[ 1 ].y ); SelectObject( hDC, blackpen ); LineTo( hDC, pts[ 2 ].x, pts[ 2 ].y ); SelectObject( hDC, dkgraypen ); LineTo( hDC, pts[ 0 ].x, pts[ 0 ].y ); // Release drawing objects SelectObject( hDC, oldpen ); DeleteObject( whitepen ); DeleteObject( dkgraypen ); DeleteObject( blackpen ); SelectObject( hDC, oldbrush ); DeleteObject( mbrush ); } // end if } // end if // Next menu item position y += m_th; } // end if else // separator { // HPEN whitepen = CreatePen( PS_SOLID, 1, RGB( 255, 255, 255 ) ); // HPEN dkgraypen = CreatePen( PS_SOLID, 1, RGB( 50, 50, 50 ) ); HPEN whitepen = CreatePen( PS_SOLID, 1, rgbBumpLt ); HPEN dkgraypen = CreatePen( PS_SOLID, 1, rgbBumpDk ); HPEN oldpen = (HPEN)SelectObject( hDC, whitepen ); // Draw white line MoveToEx( hDC, bx + 2, by + 2, NULL ); LineTo( hDC, ( pRect->right - pRect->left ) - 2, by + 2 ); // Draw dark gray line SelectObject( hDC, dkgraypen ); MoveToEx( hDC, bx + 2, by + 3, NULL ); LineTo( hDC, ( pRect->right - pRect->left ) - 2, by + 3 ); SelectObject( hDC, oldpen ); DeleteObject( whitepen ); DeleteObject( dkgraypen ); y += 6; } // end else } // end while return TRUE; }
static void PaintPreviewWnd(CTextureProp *pDlg, HWND hWnd, HDC hDC) { CMoDWordArray rgbData; CMoWordArray rgb4444Data; TextureData *pTexture; FMConvertRequest cRequest; FormatMgr formatMgr; DRESULT dResult; DWORD x, y, *pInLine, r, g, b, a, outYCoord, iMipmap; S3TC_Compressor compressor; HPEN hPen, hOldPen; int oldROP; BPPIdent bppIdent; char oldText[256]; TextureMipData *pMip; if(!pDlg || !pDlg->m_pPreviewTexture) return; pTexture = pDlg->m_pPreviewTexture; if(!rgbData.SetSize(pTexture->m_Header.m_BaseWidth * pTexture->m_Header.m_BaseHeight)) return; GetWindowText(hWnd, oldText, sizeof(oldText)); outYCoord = 0; for(iMipmap=0; iMipmap < pTexture->m_Header.m_nMipmaps; iMipmap++) { pMip = &pTexture->m_Mips[iMipmap]; // Get us into PValue format. SetWindowText(hWnd, "Converting..."); dtx_SetupDTXFormat(pTexture, cRequest.m_pSrcFormat); cRequest.m_pSrc = pMip->m_Data; cRequest.m_SrcPitch = pMip->m_Pitch; cRequest.m_pDestFormat->InitPValueFormat(); cRequest.m_pDest = (BYTE*)rgbData.GetArray(); cRequest.m_DestPitch = pMip->m_Width * sizeof(DWORD); cRequest.m_Width = pMip->m_Width; cRequest.m_Height = pMip->m_Height; if( pTexture->m_Header.GetBPPIdent() == BPP_32P ) { DtxSection* pSection = dtx_FindSection(pTexture, "PALLETE32"); if( pSection ) { cRequest.m_pSrcPalette = (RPaletteColor*)pSection->m_Data; } } dResult = formatMgr.ConvertPixels(&cRequest); if(dResult != LT_OK) { SetWindowText(hWnd, oldText); return; } // Store this in the stack so it doesn't crash if they change it in the other thread. bppIdent = pDlg->m_BPPIdent; // Possibly compress. if(IsBPPCompressed(bppIdent) && bppIdent != pTexture->m_Header.GetBPPIdent()) { compressor.m_Format = bppIdent; compressor.m_Width = pMip->m_Width; compressor.m_Height = pMip->m_Height; compressor.m_pData = rgbData.GetArray(); compressor.m_Pitch = pMip->m_Width * sizeof(DWORD); compressor.m_DataFormat.InitPValueFormat(); SetWindowText(hWnd, "Compressing..."); dResult = compressor.CompressUsingLibrary(); if(dResult == LT_OK) { // Now decompress into the PValue format. cRequest.m_pSrcFormat->Init(bppIdent, 0, 0, 0, 0); cRequest.m_pSrc = (BYTE*)compressor.m_pOutData; cRequest.m_pDestFormat->InitPValueFormat(); cRequest.m_pDest = (BYTE*)rgbData.GetArray(); cRequest.m_DestPitch = pMip->m_Width * sizeof(DWORD); cRequest.m_Width = pMip->m_Width; cRequest.m_Height = pMip->m_Height; SetWindowText(hWnd, "Decompressing..."); dResult = formatMgr.ConvertPixels(&cRequest); delete compressor.m_pOutData; } } SetWindowText(hWnd, "Drawing..."); hPen = CreatePen(PS_SOLID, 1, RGB(255,255,255)); hOldPen = (HPEN)SelectObject(hDC, hPen); pInLine = rgbData.GetArray(); for(y=0; y < pMip->m_Height; y++) { oldROP = SetROP2(hDC, R2_XORPEN); MoveToEx(hDC, 0, outYCoord+1, NULL); LineTo(hDC, pMip->m_Width*2, outYCoord+1); SetROP2(hDC, oldROP); for(x=0; x < pMip->m_Width; x++) { PValue_Get(pInLine[x], a, r, g, b); SetPixel(hDC, x, outYCoord, RGB(r, g, b)); SetPixel(hDC, x+pMip->m_Width, outYCoord, RGB(a, a, a)); } pInLine += pMip->m_Width; ++outYCoord; } SelectObject(hDC, hOldPen); DeleteObject(hPen); } SetWindowText(hWnd, oldText); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HMETAFILE hmf; static int cxClient, cyClient; HBRUSH hBrush; HDC hdc, hdcMeta; int x, y; PAINTSTRUCT ps; switch (message) { case WM_CREATE: hdcMeta = CreateMetaFile(NULL); hBrush = CreateSolidBrush(RGB(0, 0, 255)); Rectangle(hdcMeta, 0, 0, 100, 100); MoveToEx(hdcMeta, 0, 0, NULL); LineTo(hdcMeta, 100, 100); MoveToEx(hdcMeta, 0, 100, NULL); LineTo(hdcMeta, 100, 0); SelectObject(hdcMeta, hBrush); Ellipse(hdcMeta, 20, 20, 80, 80); hmf = CloseMetaFile(hdcMeta); DeleteObject(hBrush); return 0; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); SetMapMode(hdc, MM_ANISOTROPIC); SetWindowExtEx(hdc, 1000, 1000, NULL); SetViewportExtEx(hdc, cxClient, cyClient, NULL); for (x = 0; x < 10; x++) for (y = 0; y < 10; y++) { SetWindowOrgEx(hdc, -100 * x, -100 * y, NULL); PlayMetaFile(hdc, hmf); } EndPaint(hwnd, &ps); return 0; case WM_DESTROY: DeleteMetaFile(hmf); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
// ³ static void near PaintTheLine( HDC hDC, RECT * rct, WORD wIndex, PCLIPVAR pAtext, PCLIPVAR pAsizes, HPEN hWhitePen, HPEN hGrayPen, BOOL bTree, PCLIPVAR pAJustify, WORD wPressed, BOOL bHeader, WORD nStyle, WORD wFocus, BOOL bFocused, PCLIPVAR pTextColor, PCLIPVAR pBkColor, WORD wRowPos, WORD nHeightCtrl, LONG nClrLine, BOOL bFooter, BOOL bSelect, PCLIPVAR pFont, BOOL bDrawFocusRect ) { RECT box, wholebox, rctadj; int iMaxRight = rct->right; WORD wLen = _VARRAYLEN( pAtext ); HPEN hOldPen, hPen; CLV_WORD lJustify; BITMAP bmp; WORD wRow, wCol; LONG lColor ; //, lBkColor = GetBkColor( hDC ); HBRUSH hBrush; LONG lTextColorOld = -1 ; // CeSoTech LONG lBkColorOld = -1 ; // CeSoTech PCLIPVAR pEvalOld ; HFONT hFont ; // CeSoTech WORD wAlign ;// CeSoTech // CeSoTech LONG nClrLineC = ( nStyle == 2 || nStyle == 6 || nStyle == 8 || nStyle == 10 ) ? GetSysColor( COLOR_BTNSHADOW ) : 0 ; // CeSoTech if ( nClrLine >= 0 ) // Desde Clipper manda color especifico linea nClrLineC = nClrLine ; if ( ! bDrawHeaders ) bHeader = FALSE ; if ( bFooter ) bHeader = TRUE ; //-> Para que lo pinte con similar aspecto //CeSoTech // Si es un estilo sin separadores horizontales, pintar uno mas arriba //CeSoTech para que que bien completa el area !!! if ( ! (bHeader) && (nStyle == 0 || nStyle == 5 || nStyle == 6 || nStyle == 9 || nStyle == 10) ) rct->top-- ; wholebox.top = rct->top+1; wholebox.left = rct->left; wholebox.bottom = rct->bottom; wholebox.right = rct->right; rct->right = 0; box.top = rct->top ; box.bottom = rct->bottom - 1; if( !wIndex | wIndex > wLen ) wIndex = 1; while( wIndex <= wLen ) { rct->left = rct->right; rct->right = ( wIndex == wLen ? iMaxRight : rct->left + GetInt( pAsizes, wIndex ) ); // CeSoTech // Cuando estoy estoy en la ultima celda, NO pintar hasta // el final si no existe ajuste de ultima columna. if ( ( wIndex == wLen ) && ( ! bAdjLastCol ) ) { rct->right = rct->left + GetInt( pAsizes, wIndex ) +(bHeader ? 1: 0) ; if ( !bAdjBrowse ) wholebox.right = rct->right ; // Tambien ajusto el borde focus } // CeSoTech // _cAt( pAtext, wIndex, 0xFFFF, ++_tos ); if( wFocus > 0 && wIndex != wFocus ) { _tos--; if( rct->right >= iMaxRight ) { wIndex = wLen + 1; // ya no pintamos m s } else ++wIndex; continue; } if( bTree || (GetInt( pAsizes, wIndex ) > 0) ) //Si NO es columna oculta (x Freeze) { //(Es lo mismo no hacer esto, // pero es para evitar hacer trabajar // al codigo sin sentido !!! ) if( (_tos->wType & NUMERIC) && bTree ) { if( _tos->pPointer1 ) { FillRect( hDC, rct, hBrush = CreateSolidBrush( GetPixel( hDC, rct->left, rct->top ) ) ); DrawMasked( hDC, (int) _tos->pPointer1, rct->top, rct->left ); DeleteObject( hBrush ); } } else // Si es Numerico Bmp no Tree, o , es Character !!!! { if ( pBkColor ) // Bloque de Color Fondo Celda { _PutSym( _SymEval ); _xPushM( pBkColor ); _PutLN( wRowPos ); _PutLN( wIndex ); _PutLN( bFooter ? 2 : ( bHeader ? 1 : ( bSelect ? 3 : 0 ) ) ); _xEval( 3 ) ; if ( _parinfo( -1 ) == NUMERIC ) lBkColorOld = SetBkColor( hDC, _parnl( - 1 ) ) ; } if( pTextColor ) // Bloque de Color Texto Celda { _PutSym( _SymEval ); _xPushM( pTextColor ); _PutLN( wRowPos ); _PutLN( wIndex ); _PutLN( bFooter ? 2 : ( bHeader ? 1 : ( bSelect ? 3 : 0 ) ) ); _xEval( 3 ) ; if ( _parinfo( -1 ) == NUMERIC ) lTextColorOld = SetTextColor( hDC, _parnl( - 1 ) ) ; } hFont = 0 ; if( pFont ) // Bloque de Font Celda { _PutSym( _SymEval ); _xPushM( pFont ); _PutLN( wRowPos ); _PutLN( wIndex ); _PutLN( bFooter ? 2 : ( bHeader ? 1 : ( bSelect ? 3 : 0 ) ) ); _xEval( 3 ) ; if ( _parinfo( -1 ) == NUMERIC ) hFont = _parnl( - 1 ) ; } /////// CeSoTech /////// if (!bHeader) rct->top ++; if( _tos->wType & NUMERIC ) // Es un BitMap { FW_DrawBitmapCenter( hDC, (int) _tos->pPointer1, rct, nStyle ); } else // Es una Cadena { wAlign = HA_LEFT | VA_CENTER ; // por defecto if( pAJustify && ( wIndex <= _VARRAYLEN( pAJustify ) ) ) { _cAt( pAJustify, wIndex, 0xFFFF, ( PCLIPVAR ) &lJustify ); wAlign = lJustify.wWord ; // tiene alineacio de usuario } FW_DrawText( hDC, rct, ( _tos->wType & CHARACTER ) ? _VSTR( _tos ): "", wAlign, _tos->w2, hFont, bHeader ) ; } /////// CeSoTech restauracion de colores ////// if ( lTextColorOld >= 0 ) { SetTextColor( hDC, lTextColorOld ) ; lTextColorOld = -1 ; } if ( lBkColorOld >= 0 ) { SetBkColor( hDC, lBkColorOld ) ; lBkColorOld = -1 ; } /// CeSoTech /// // Si hay modalidad ajustar el Browse y no hay ajuste de ultima // columna, deber‚ pintar hasta el final hasta cubrir toda // el area, hasta llegar a la derecha del control. (Col.Ficticia) if ( bAdjBrowse && wIndex == wLen && !bAdjLastCol && rct->right <= iMaxRight ) { rctadj.top = rct->top; rctadj.left = rct->right ; rctadj.bottom = rct->bottom; rctadj.right = wholebox.right ; if ( nStyle == 3 ) rctadj.top--; if ( wFocus == 0 ) // Si No es CellStyle (Pinto hasta final) ExtTextOut( hDC, 0, rct->top, ETO_OPAQUE, &rctadj, "", 0, 0 ); if ( bHeader ) // Pinto Bordes Header Falso { rctadj.right = wholebox.right - 2 ; rctadj.bottom = rctadj.bottom - 2 ; WndDrawBox( hDC, &rctadj, hWhitePen, hGrayPen ); rctadj.bottom++ ; rctadj.right++ ; WndDrawBox( hDC, &rctadj, hWhitePen, GetStockObject( BLACK_PEN ) ); if ( bFooter ) // Si es Footer (Linea Negra de Arriba Foot) { hPen = GetStockObject( BLACK_PEN ); hOldPen = SelectObject( hDC, hPen ); MoveTo( hDC, rctadj.left-1, rctadj.top-1 ); LineTo( hDC, rctadj.right+1, rctadj.top-1 ); SelectObject( hDC, hOldPen ); } } } /// CeSoTech Fin /// if (!bHeader) rct->top --; } box.left = rct->left; box.right = ( wIndex < wLen && rct->right <= iMaxRight ? rct->right - 1 : iMaxRight - 1 ); // CeSoTech // El Borde derecho de Box de la ultima columna, // no estirarlo cuando no exista ajuste de ultima columna // PERO cuando nLineStyle (nStyle) es 7/8 (Lineas Horiz) // queda anti-estetico cortar los renglones, cuando no hay // ajuste ult.col. y hay ajuste de browse. Por ello // se verificara que para cortar el borde no se de esta // condicion. if ( ( wIndex == wLen ) && ( ! bAdjLastCol ) ) { if (! (!bHeader && (nStyle==7 || nStyle==8) && !bAdjLastCol && bAdjBrowse) ) box.right = rct->left + GetInt( pAsizes, wIndex ) - 1 ; } // CeSoTech // if( ! bTree ) { if( wPressed && ( wIndex == wPressed ) ) { WndDrawBox( hDC, &box, hGrayPen, hWhitePen ); } else if(!bHeader) { switch( nStyle ) { case 0: break; case 1: // hOldPen = SelectObject( hDC, GetStockObject( BLACK_PEN ) ); hPen = CreatePen(PS_SOLID, 0, nClrLineC ); hOldPen = SelectObject( hDC, hPen); MoveTo( hDC, box.left, box.bottom+1 ); LineTo( hDC, box.left, box.top ); LineTo( hDC, box.right+1, box.top ); LineTo( hDC, box.right+1, box.bottom+1 ); LineTo( hDC, box.left, box.bottom+1 ); SelectObject( hDC, hOldPen ); DeleteObject( hPen); break; case 2: hPen = CreatePen(PS_SOLID, 0, nClrLineC ); hOldPen = SelectObject( hDC, hPen); MoveTo( hDC, box.left, box.bottom+1 ); LineTo( hDC, box.left, box.top ); LineTo( hDC, box.right+1, box.top ); LineTo( hDC, box.right+1, box.bottom+1 ); LineTo( hDC, box.left, box.bottom+1 ); SelectObject( hDC, hOldPen ); DeleteObject( hPen); break; case 3: WndDrawBox( hDC, &box, hWhitePen, hGrayPen ); break; case 4: box.bottom ++; box.right ++; FrameDot( hDC, &box ); box.bottom --; box.right --; break; case 7: case 8: hPen = CreatePen(PS_SOLID, 0, nClrLineC ); hOldPen = SelectObject( hDC, hPen); MoveTo( hDC, box.left, box.top ); LineTo( hDC, box.right+1, box.top ); MoveTo( hDC, box.right+1, box.bottom+1 ); LineTo( hDC, box.left, box.bottom+1 ); SelectObject( hDC, hOldPen ); DeleteObject( hPen); break; case 5: case 6: case 9: case 10: hPen = CreatePen(PS_SOLID, 0, nClrLineC); hOldPen = SelectObject( hDC, hPen); if (box.left>1) { MoveTo( hDC, box.left, box.bottom+1 ); LineTo( hDC, box.left, box.top ); } MoveTo( hDC, box.right+1, box.top ); if ( bDrawFooters && nStyle >= 9 ) { LineTo( hDC, box.right+1, nHeightCtrl - (wFooterHeight+1) ) ; } else { LineTo( hDC, box.right+1, nStyle < 9 ? box.bottom+1 : nHeightCtrl ); } SelectObject( hDC, hOldPen ); DeleteObject( hPen); break; } } else // Box para Headers !!! { box.left ++; // CeSoTech if ( bFooter ) // Linea negra sobre el Footer { hPen = GetStockObject( BLACK_PEN ); hOldPen = SelectObject( hDC, hPen ); MoveTo( hDC, box.left-1, box.top-1 ); LineTo( hDC, box.right+1, box.top-1 ); SelectObject( hDC, hOldPen ); } box.right-- ; box.bottom-- ; WndDrawBox( hDC, &box, hWhitePen, hGrayPen ); box.bottom++ ; box.right++ ; WndDrawBox( hDC, &box, hWhitePen, GetStockObject( BLACK_PEN ) ); box.left --; } } else { if( ! ( _tos->wType & NUMERIC ) ) { box.left -= 1; //6; } } // CeSoTech if( bFocused && wFocus > 0 && wIndex == wFocus ) if( bDrawFocusRect && bFocused && wFocus > 0 && wIndex == wFocus && nStyle != 3) { rct->left++; rct->top++; DrawFocusRect( hDC, rct ); rct->left--; rct->top--; } } _tos--; if( rct->right >= iMaxRight ) { wIndex = wLen + 1; // ya no pintamos m s } else ++wIndex; } if (bDrawFocusRect && !bTree && bFocused && wFocus==0 && nStyle!=3) // CeSoTech DrawFocusRect( hDC, &wholebox ); }
////////////////////////////////////////////////////////// // TMapDC // ------ // draw a Thing void TMapDC::DrawMapThing (int editmode, SHORT tnum) { assert_tnum (tnum); Thing HUGE *pThing = &Things[tnum]; SHORT xpos = pThing->xpos; SHORT ypos = pThing->ypos; SHORT scrRadius; SHORT mapRadius; // Select the radius if (editmode == OBJ_THINGS) mapRadius = GetKodObjectRadius(Things[tnum].type); else mapRadius = OBJSIZE; // Calc. bouding rectangle SHORT x0 = xpos - mapRadius; SHORT y0 = ypos + mapRadius; SHORT x1 = xpos + mapRadius; SHORT y1 = ypos - mapRadius; #ifndef WINDOWS_CLIPPING if ( ! IS_VISIBLE_MAP_RECT(x0,y0,x1,y1) ) return; #endif // Convert map coords. to screen coords. scrRadius = (SHORT)(mapRadius * MUL_SCALE); #ifndef WINDOWS_SCALING xpos = SCREENX(xpos); ypos = SCREENY(ypos); x0 = SCREENX(x0); y0 = SCREENY(y0); x1 = SCREENX(x1); y1 = SCREENY(y1); #endif // Draw bouding circle of the thing if (editmode == OBJ_THINGS) { SetPenColor16 (GetKodObjectColor (Things[tnum].type)); // If radius is small, draw a rectangle instead of an ellipse if ( scrRadius > 4 ) { Ellipse (x0, y0, x1+1, y1+1); } else if ( scrRadius > 1 ) { TPoint points[5], *pp = points ; pp->x = xpos; pp->y = y0; pp++; pp->x = x1; pp->y = ypos; pp++; pp->x = xpos; pp->y = y1; pp++; pp->x = x0; pp->y = ypos; pp++; pp->x = xpos; pp->y = y0; Polyline (points, 5); } } // Set pen color to default (LIGHTGRAY) else SetPenColor16 (LIGHTGRAY); // Draw the cross MoveTo (xpos, y0) ; LineTo (xpos, y1) ; MoveTo (x0, ypos) ; LineTo (x1, ypos) ; }
static void horizontal( DRAWITEMSTRUCT FAR * draw, int row ) { MoveToEx( draw->hDC,draw->rcItem.left + 1, row, NULL ); LineTo( draw->hDC, draw->rcItem.right - 1, row ); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int iCount; static POINT pt[MAX_POINTS * 2]; HDC hdc; PAINTSTRUCT ps; int i, j; TCHAR szBuffer[256]; POINT screen, client; LRESULT hit; switch (message) { case WM_LBUTTONDOWN: iCount = 0; InvalidateRect(hwnd, NULL, TRUE); return 0; case WM_MOUSEMOVE: if (wParam & MK_LBUTTON && iCount< MAX_POINTS) { pt[iCount].x = LOWORD(lParam); pt[iCount++].y = HIWORD(lParam); hdc = GetDC(hwnd); SetPixel(hdc, LOWORD(lParam), HIWORD(lParam), 0); ReleaseDC(hwnd, hdc); } return 0; case WM_LBUTTONUP: InvalidateRect(hwnd, NULL, FALSE); return 0; case WM_NCHITTEST: return (LRESULT) HTNOWHERE; case WM_NCRBUTTONDOWN: screen.x = client.x = LOWORD(lParam); screen.y = client.y = HIWORD(lParam); ScreenToClient(hwnd, &client); wsprintf(szBuffer, TEXT("Screen: (%d,%d) Client(%d,%d)"), screen.x, screen.y, client.x, client.y); //MessageBox(NULL, szBuffer, TEXT("ScreenToClient"), MB_OK); hdc = GetDC(hwnd); TextOut(hdc, 0, 0, szBuffer, lstrlen(szBuffer)); ReleaseDC(hwnd, hdc); return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); SetCursor(LoadCursor(NULL, IDC_WAIT)); ShowCursor(TRUE); for (i = 0; i < iCount - 1; i++) { for( j = i; j < iCount; j++) { MoveToEx(hdc, pt[i].x, pt[i].y, NULL); LineTo(hdc, pt[j].x, pt[j].y); } } ShowCursor(FALSE); SetCursor(LoadCursor(NULL, IDC_ARROW)); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } //return DefWindowProc(hwnd, message, wParam, lParam); if( DwmDefWindowProc(hwnd, message, wParam, lParam, &hit) ) { return hit; } else { return DefWindowProc(hwnd, message, wParam, lParam); } }
static BOOL CALLBACK SkinEdit_ExtBkDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { SKINDESCRIPTION *psd = (SKINDESCRIPTION *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); if(psd) { ID_EXTBK_FIRST = psd->firstItem; ID_EXTBK_LAST = psd->lastItem; StatusItems = psd->StatusItems; } switch (msg) { case WM_INITDIALOG: psd = (SKINDESCRIPTION *)malloc(sizeof(SKINDESCRIPTION)); ZeroMemory(psd, sizeof(SKINDESCRIPTION)); CopyMemory(psd, (void *)lParam, sizeof(SKINDESCRIPTION)); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)psd); if(psd) { ID_EXTBK_FIRST = psd->firstItem; ID_EXTBK_LAST = psd->lastItem; StatusItems = psd->StatusItems; } TranslateDialogDefault(hwndDlg); FillItemList(hwndDlg); SendMessage(hwndDlg, WM_USER + 101, 0, 0); psd->hMenuItems = CreatePopupMenu(); AppendMenu(psd->hMenuItems, MF_STRING | MF_DISABLED, (UINT_PTR)0, _T("Copy from")); AppendMenuA(psd->hMenuItems, MF_SEPARATOR, (UINT_PTR)0, NULL); { int i; for(i = ID_EXTBK_FIRST; i <= ID_EXTBK_LAST; i++) { int iOff = StatusItems[i - ID_EXTBK_FIRST].szName[0] == '{' ? 3 : 0; if(iOff) AppendMenuA(psd->hMenuItems, MF_SEPARATOR, (UINT_PTR)0, NULL); AppendMenuA(psd->hMenuItems, MF_STRING, (UINT_PTR)i, &StatusItems[i - ID_EXTBK_FIRST].szName[iOff]); } } return TRUE; case WM_USER + 101: { SendDlgItemMessage(hwndDlg, IDC_MRGN_LEFT_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_MRGN_TOP_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_MRGN_RIGHT_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_MRGN_BOTTOM_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_ALPHASPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_ALPHASPIN2, UDM_SETRANGE, 0, MAKELONG(100, 0)); return 0; } case WM_DRAWITEM: { DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *) lParam; int iItem = dis->itemData; TStatusItem *item = 0; SetBkMode(dis->hDC, TRANSPARENT); FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_WINDOW)); if(iItem >= ID_EXTBK_FIRST && iItem <= ID_EXTBK_LAST) item = &StatusItems[iItem - ID_EXTBK_FIRST]; if (dis->itemState & ODS_SELECTED && iItem != ID_EXTBKSEPARATOR) { FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT)); SetTextColor(dis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); } else { FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_WINDOW)); if(item && item->IGNORED) SetTextColor(dis->hDC, RGB(255, 0, 0)); else if(item && item->dwFlags & S_ITEM_IMAGE_ONLY) SetTextColor(dis->hDC, RGB(0, 0, 255)); else SetTextColor(dis->hDC, GetSysColor(COLOR_WINDOWTEXT)); } if(iItem == ID_EXTBKSEPARATOR) { HPEN hPen, hPenOld; POINT pt; hPen = CreatePen(PS_SOLID, 2, GetSysColor(COLOR_WINDOWTEXT)); hPenOld = (HPEN)SelectObject(dis->hDC, hPen); MoveToEx(dis->hDC, dis->rcItem.left, (dis->rcItem.top + dis->rcItem.bottom) / 2, &pt); LineTo(dis->hDC, dis->rcItem.right, (dis->rcItem.top + dis->rcItem.bottom) / 2); SelectObject(dis->hDC, hPenOld); DeleteObject((HGDIOBJ)hPen); } else if(dis->itemID >= 0 && item) { char *szName = item->szName[0] == '{' ? &item->szName[3] : item->szName; TextOutA(dis->hDC, dis->rcItem.left, dis->rcItem.top, szName, lstrlenA(szName)); } return TRUE; } case WM_CONTEXTMENU: { POINT pt; RECT rc; HWND hwndList = GetDlgItem(hwndDlg, IDC_ITEMS); GetCursorPos(&pt); GetWindowRect(hwndList, &rc); if(PtInRect(&rc, pt)) { int iSelection = (int)TrackPopupMenu(psd->hMenuItems, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL); if(iSelection >= ID_EXTBK_FIRST && iSelection <= ID_EXTBK_LAST) { iSelection -= ID_EXTBK_FIRST; for(int i = ID_EXTBK_FIRST; i <= ID_EXTBK_LAST; i++) { if(SendMessage(hwndList, LB_GETSEL, i - ID_EXTBK_FIRST, 0) > 0) { int iIndex = SendMessage(hwndList, LB_GETITEMDATA, i - ID_EXTBK_FIRST, 0); iIndex -= ID_EXTBK_FIRST; if(iIndex >= 0) { StatusItems[iIndex].ALPHA = StatusItems[iSelection].ALPHA; StatusItems[iIndex].COLOR = StatusItems[iSelection].COLOR; StatusItems[iIndex].COLOR2 = StatusItems[iSelection].COLOR2; StatusItems[iIndex].ALPHA2 = StatusItems[iSelection].ALPHA2; StatusItems[iIndex].CORNER = StatusItems[iSelection].CORNER; StatusItems[iIndex].GRADIENT = StatusItems[iSelection].GRADIENT; StatusItems[iIndex].IGNORED = StatusItems[iSelection].IGNORED; StatusItems[iIndex].imageItem = StatusItems[iSelection].imageItem; StatusItems[iIndex].MARGIN_BOTTOM = StatusItems[iSelection].MARGIN_BOTTOM; StatusItems[iIndex].MARGIN_LEFT = StatusItems[iSelection].MARGIN_LEFT; StatusItems[iIndex].MARGIN_RIGHT = StatusItems[iSelection].MARGIN_RIGHT; StatusItems[iIndex].MARGIN_TOP = StatusItems[iSelection].MARGIN_TOP; StatusItems[iIndex].TEXTCOLOR = StatusItems[iSelection].TEXTCOLOR; StatusItems[iIndex].dwFlags = StatusItems[iSelection].dwFlags; } } } OnListItemsChange(hwndDlg); } } break; } case WM_COMMAND: // this will check if the user changed some actual statusitems values // if yes the flag bChanged will be set to TRUE SetChangedStatusItemFlag(wParam, hwndDlg); switch(LOWORD(wParam)) { case IDC_ITEMS: if (HIWORD(wParam) != LBN_SELCHANGE) return FALSE; { int iItem = SendDlgItemMessage(hwndDlg, IDC_ITEMS, LB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_ITEMS, LB_GETCURSEL, 0, 0), 0); if(iItem == ID_EXTBKSEPARATOR) return FALSE; } OnListItemsChange(hwndDlg); if(psd->pfnClcOptionsChanged) psd->pfnClcOptionsChanged(); break; case IDC_SKIP_UNDERLAY: case IDC_SKIP_IMAGE: case IDC_GRADIENT: case IDC_CORNER: case IDC_IGNORE: ReActiveCombo(hwndDlg); break; } if ((LOWORD(wParam) == IDC_ALPHA || LOWORD(wParam) == IDC_ALPHA2 || LOWORD(wParam) == IDC_MRGN_LEFT || LOWORD(wParam) == IDC_MRGN_BOTTOM || LOWORD(wParam) == IDC_MRGN_TOP || LOWORD(wParam) == IDC_MRGN_RIGHT) && (HIWORD(wParam) != EN_CHANGE || (HWND) lParam != GetFocus())) return 0; SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case WM_NOTIFY: switch (((LPNMHDR) lParam)->idFrom) { case 0: switch (((LPNMHDR) lParam)->code) { case PSN_APPLY: // save user made changes SaveLatestChanges(hwndDlg); // save struct to DB if(psd->pfnSaveCompleteStruct) psd->pfnSaveCompleteStruct(); if(psd->pfnClcOptionsChanged) psd->pfnClcOptionsChanged(); if(psd->hwndCLUI) { SendMessage(psd->hwndCLUI, WM_SIZE, 0, 0); PostMessage(psd->hwndCLUI, WM_USER+100, 0, 0); // CLUIINTM_REDRAW } break; } } break; case WM_DESTROY: DestroyMenu(psd->hMenuItems); break; case WM_NCDESTROY: free(psd); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)0); break; } return FALSE; }
void shape_def::update(float delta_time, character_ptr instance) { // XXX optimize this. static bool first = true; if(first) { first = false; auto vgraph = std::dynamic_pointer_cast<KRE::Vector::Context>(instance->get_render_object()); auto& mat = instance->get_matrix_transform(); auto vmat = vgraph->createMatrix(); vmat->init(mat.scale_x.to_double()/20.0, mat.rotate_skew1.to_double(), mat.rotate_skew0.to_double(), mat.scale_y.to_double()/20.0, mat.translate_x - bounds_.x1()/20.0, mat.translate_y - bounds_.y1()/20.0); //vmat->scale(1.0f/20.0, 1.0f/20.0); vgraph->setMatrix(vmat); auto path = vgraph->NewPath(); for(auto& sr : shape_records_) { switch(sr->get_type()) { case ShapeRecordTypes::MOVE: { //std::cerr << "Bounds: " << bounds_ << " : " << (bounds_/20.0) << "\n"; path->MoveTo(sr->get_delta().delta_x, sr->get_delta().delta_y); //auto p = vmat->transformPoint(sr->get_delta().delta_x, sr->get_delta().delta_y); //std::cerr << "POINT: " << p << "\n"; //ASSERT_LOG(false, ""); break; } case ShapeRecordTypes::LINE: path->LineTo(sr->get_delta().delta_x, sr->get_delta().delta_y); break; case ShapeRecordTypes::CURVE: { auto cr = std::dynamic_pointer_cast<curve_edge_record>(sr); ASSERT_LOG(cr != nullptr, "Type was curve. cast was null."); path->QuadraticCurveTo(cr->control().delta_x, cr->control().delta_y, cr->anchor().delta_x+cr->control().delta_x, cr->anchor().delta_y+cr->control().delta_y, true); break; } case ShapeRecordTypes::STYLE_CHANGE: { /*auto scr = std::dynamic_pointer_cast<style_change_record>(sr); if(scr->has_linestyle_change()) { auto ls = get_line_style(scr->get_line_style()); // XXX if ls->end_cap_style != ls->start_cap_style we need to split the line. // or something. switch(ls->end_cap_style) { case line_style::CAP_STYLE_NONE: vgraph->SetLineCap(KRE::Vector::LineCap::LINE_CAP_BUTT); break; case line_style::CAP_STYLE_SQUARE: vgraph->SetLineCap(KRE::Vector::LineCap::LINE_CAP_SQUARE); break; case line_style::CAP_STYLE_ROUND: vgraph->SetLineCap(KRE::Vector::LineCap::LINE_CAP_ROUND); break; default: break; } vgraph->SetLineWidth(static_cast<double>(ls->width) / instance->get_player()->get_twips()); switch(ls->join_style) { case line_style::JOIN_STYLE_BEVEL: vgraph->SetLineJoin(KRE::Vector::LineJoin::LINE_JOIN_BEVEL); break; case line_style::JOIN_STYLE_MITER: vgraph->SetLineJoin(KRE::Vector::LineJoin::LINE_JOIN_MITER); vgraph->SetMiterLimit(ls->miter_limit_factor); break; case line_style::JOIN_STYLE_ROUND: vgraph->SetLineJoin(KRE::Vector::LineJoin::LINE_JOIN_ROUND); break; } if(ls->has_fill_flag) { // apply fill change } vgraph->SetSourceColor(ls->color.r, ls->color.g, ls->color.b, ls->color.a); } break;*/ } default: break; } } vgraph->AddPath(path); vgraph->Stroke(true); vgraph->Fill(); } }
void Enermy::Draw(HDC& hdc) { HPEN pen =::CreatePen(0,0,color); HPEN oldPen = (HPEN)SelectObject(hdc,pen); Arc(hdc,point.x-DISTANCE,point.y-DISTANCE, point.x+DISTANCE,point.y+DISTANCE, point.x+DISTANCE,point.y, point.x-DISTANCE,point.y);//半圆型的头 int const LEGLENTH = (DISTANCE)/(LEGCOUNTS); //根据祯数来绘制身体和“腿部” if(frame%2 == 0) { MoveToEx(hdc,point.x-DISTANCE,point.y,NULL);//矩形的身子 LineTo(hdc,point.x-DISTANCE,point.y +DISTANCE - LEGLENTH); //point.y+10-2 MoveToEx(hdc,point.x+DISTANCE,point.y,NULL); LineTo(hdc,point.x+DISTANCE,point.y +DISTANCE - LEGLENTH); for(int i = 0;i<LEGCOUNTS;i++)//从左往右绘制“腿部” { Arc(hdc,point.x-DISTANCE+i*2*LEGLENTH,point.y+DISTANCE-2*LEGLENTH, point.x-DISTANCE+(i+1)*2*LEGLENTH,point.y+DISTANCE, point.x-DISTANCE+i*2*LEGLENTH,point.y+DISTANCE-LEGLENTH, point.x-DISTANCE+(i+1)*2*LEGLENTH,point.y+DISTANCE-LEGLENTH ); } } else{ MoveToEx(hdc,point.x-DISTANCE,point.y,NULL);//绘制身体 LineTo(hdc,point.x-DISTANCE,point.y +DISTANCE); MoveToEx(hdc,point.x+DISTANCE,point.y,NULL); LineTo(hdc,point.x+DISTANCE,point.y +DISTANCE); //从左往右绘制“腿部” MoveToEx(hdc,point.x-DISTANCE,point.y+DISTANCE,NULL); LineTo(hdc,point.x-DISTANCE+LEGLENTH,point.y+DISTANCE-LEGLENTH); for(int i = 0;i<LEGCOUNTS-1;i++) { Arc(hdc,point.x-DISTANCE+(1+i*2)*LEGLENTH,point.y+DISTANCE-2*LEGLENTH, point.x-DISTANCE+(3+i*2)*LEGLENTH,point.y+DISTANCE, point.x-DISTANCE+(1+i*2)*LEGLENTH,point.y+DISTANCE-LEGLENTH, point.x-DISTANCE+(3+i*2)*LEGLENTH,point.y+DISTANCE-LEGLENTH ); } MoveToEx(hdc,point.x+DISTANCE,point.y+DISTANCE,NULL); LineTo(hdc,point.x+DISTANCE-LEGLENTH,point.y+DISTANCE-LEGLENTH); } //根据方向绘制眼睛 int R = DISTANCE/5; //眼睛的半径 switch(tw) { case UP: Ellipse(hdc,point.x-2*R,point.y-2*R, point.x,point.y); Ellipse(hdc,point.x,point.y-2*R, point.x+2*R,point.y); break; case DOWN: Ellipse(hdc,point.x-2*R,point.y,point.x,point.y+2*R); Ellipse(hdc,point.x,point.y,point.x+2*R,point.y+2*R); break; case LEFT: Ellipse(hdc,point.x-3*R,point.y-R, point.x-R,point.y +R); Ellipse(hdc,point.x-R,point.y-R, point.x+R,point.y +R); break; case RIGHT: Ellipse(hdc,point.x-R,point.y-R, point.x+R,point.y +R); Ellipse(hdc,point.x+R,point.y-R, point.x+3*R,point.y+R); break; } frame++; //准备绘制下一祯 SelectObject(hdc,oldPen); DeleteObject(pen); return; }
void PacMan::Draw( HDC& memDC) { if(frame%2 ==0)//第4祯动画与第2祯动画 { int x1=0,x2=0,y1=0,y2=0; int offsetX = DISTANCE/2+D_OFFSET;//弧弦交点 int offsetY = DISTANCE/2+D_OFFSET;//弧弦交点 switch(tw) //优弧 { case UP: x1 = point.x - offsetX; x2 = point.x + offsetX; y2 = y1 = point.y-offsetY; break; case DOWN: x1 = point.x + offsetX; x2 = point.x - offsetX; y2 = y1 = point.y+offsetY; break; case LEFT: x2 = x1 = point.x-offsetX; y1 = point.y + offsetY; y2 = point.y - offsetY; break; case RIGHT: x2 = x1 =point.x + offsetX; y1 = point.y - offsetY; y2 = point.y + offsetY; break; } Arc(memDC,point.x-DISTANCE,point.y-DISTANCE, point.x+DISTANCE,point.y+DISTANCE, x1,y1, x2,y2); MoveToEx(memDC,x1,y1,NULL); LineTo(memDC,point.x,point.y); LineTo(memDC,x2,y2); } else if(frame%3 ==0) //圆形 { Ellipse(memDC,point.x-DISTANCE,point.y-DISTANCE, point.x+DISTANCE,point.y+DISTANCE); } else { int x1=0,x2=0,y1=0,y2=0; switch(tw) //半圆形 { case UP: x1 = point.x - DISTANCE; x2 = point.x + DISTANCE; y2 = y1 = point.y; break; case DOWN: x1 = point.x + DISTANCE; x2 = point.x - DISTANCE; y2 = y1 = point.y; break; case LEFT: x2 = x1 = point.x; y1 = point.y + DISTANCE; y2 = point.y - DISTANCE; break; case RIGHT: x2 = x1 =point.x ; y1 = point.y - DISTANCE; y2 = point.y + DISTANCE; break; } Arc(memDC,point.x-DISTANCE,point.y-DISTANCE, point.x+DISTANCE,point.y+DISTANCE, x1,y1, x2,y2); MoveToEx(memDC,x1,y1,NULL); LineTo(memDC,point.x,point.y); LineTo(memDC,x2,y2); } frame++;//绘制下一祯 }
LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam) { static struct { int idStockFont ; TCHAR * szStockFont ; } stockfont [] = { OEM_FIXED_FONT, "OEM_FIXED_FONT", ANSI_FIXED_FONT, "ANSI_FIXED_FONT", ANSI_VAR_FONT, "ANSI_VAR_FONT", SYSTEM_FONT, "SYSTEM_FONT", DEVICE_DEFAULT_FONT,"DEVICE_DEFAULT_FONT", SYSTEM_FIXED_FONT, "SYSTEM_FIXED_FONT", DEFAULT_GUI_FONT, "DEFAULT_GUI_FONT" } ; static int iFont, cFonts = sizeof stockfont / sizeof stockfont[0] ; HDC hdc ; int i, x, y, cxGrid, cyGrid ; PAINTSTRUCT ps ; TCHAR szFaceName [LF_FACESIZE], szBuffer [LF_FACESIZE + 64] ; TEXTMETRIC tm ; switch (message) { case WM_CREATE: SetScrollRange (hwnd, SB_VERT, 0, cFonts - 1, TRUE) ; return 0 ; case WM_DISPLAYCHANGE: InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; case WM_VSCROLL: switch (LOWORD (wParam)) { case SB_TOP: iFont = 0 ; break ; case SB_BOTTOM: iFont = cFonts - 1 ; break ; case SB_LINEUP: case SB_PAGEUP: iFont -= 1 ; break ; case SB_LINEDOWN: case SB_PAGEDOWN: iFont += 1 ; break ; case SB_THUMBPOSITION:iFont = HIWORD (wParam) ; break ; } iFont = max (0, min (cFonts - 1, iFont)) ; SetScrollPos (hwnd, SB_VERT, iFont, TRUE) ; InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; case WM_KEYDOWN: switch (wParam) { case VK_HOME: SendMessage (hwnd, WM_VSCROLL, SB_TOP, 0) ; break ; case VK_END: SendMessage (hwnd, WM_VSCROLL, SB_BOTTOM, 0) ; break ; case VK_PRIOR: case VK_LEFT: case VK_UP: SendMessage (hwnd, WM_VSCROLL, SB_LINEUP, 0) ; break ; case VK_NEXT: case VK_RIGHT: case VK_DOWN: SendMessage (hwnd, WM_VSCROLL, SB_PAGEDOWN, 0) ; break ; } return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; SelectObject (hdc, GetStockObject (stockfont[iFont].idStockFont)) ; GetTextFace (hdc, LF_FACESIZE, szFaceName) ; GetTextMetrics (hdc, &tm) ; cxGrid = max (3 * tm.tmAveCharWidth, 2 * tm.tmMaxCharWidth) ; cyGrid = tm.tmHeight + 3 ; TextOut (hdc, 0, 0, szBuffer, wsprintf ( szBuffer, TEXT (" %s: Face Name = %s, CharSet = %i"), stockfont[iFont].szStockFont, szFaceName, tm.tmCharSet)) ; SetTextAlign (hdc, TA_TOP | TA_CENTER) ; // vertical and horizontal lines for (i = 0 ; i < 17 ; i++) { MoveToEx (hdc, (i + 2) * cxGrid, 2 * cyGrid, NULL) ; LineTo (hdc, (i + 2) * cxGrid, 19 * cyGrid) ; MoveToEx (hdc, cxGrid, (i + 3) * cyGrid, NULL) ; LineTo (hdc, 18 * cxGrid, (i + 3) * cyGrid) ; } // vertical and horizontal headings for (i = 0 ; i < 16 ; i++) { TextOut (hdc, (2 * i + 5) * cxGrid / 2, 2 * cyGrid + 2, szBuffer, wsprintf (szBuffer, TEXT ("%X-"), i)) ; TextOut (hdc, 3 * cxGrid / 2, (i + 3) * cyGrid + 2, szBuffer, wsprintf (szBuffer, TEXT ("-%X"), i)) ; } // characters for (y = 0 ; y < 16 ; y++) for (x = 0 ; x < 16 ; x++) { TextOut (hdc, (2 * x + 5) * cxGrid / 2, (y + 3) * cyGrid + 2, szBuffer, wsprintf (szBuffer, TEXT ("%c"), 16 * x + y)) ; } EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
static void vertical( DRAWITEMSTRUCT FAR * draw, int column ) { MoveToEx( draw->hDC, column, draw->rcItem.top + 1, NULL ); LineTo( draw->hDC, column, draw->rcItem.bottom - 1 ); }
LRESULT CALLBACK WndProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { HDC hdc; LPDCB lpDCB = &cc.dcb; static int cxClient,cyClient; PAINTSTRUCT ps; static int iVertPos = 0; SCROLLINFO si; char buffer[128] = {0}; DWORD bytesRead; DWORD bytesWritten; //OVERLAPPED ov = {0,0,0}; std::fstream ifs; OPENFILENAME ofn; static TCHAR szFilter[] = TEXT ("All Files (*.*)\0*.*\0\0") ; static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH] ; char packet[1024]; char packet2[2]; if (cxClient && cyClient) { /*text_area.left = 0; text_area.top = 0; text_area.right = cxClient; text_area.bottom = cyClient; areaset = true;*/ topright.left = cxClient - cxClient/3 + 1; topright.top = 1; topright.right = cxClient; topright.bottom = cyClient - cyClient/3 - 1; topleft.left = 1; topleft.top = 1; topleft.right = cxClient - cxClient/3 - 1; topleft.bottom = cyClient - cyClient/3 - 1; } switch (Message) { case WM_CREATE: ov.Offset = 0; ov.OffsetHigh = 0; ov.Pointer = 0; ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); global.hSem = (HANDLE*)malloc(sizeof(HANDLE)); *global.hSem = CreateSemaphore(NULL, 0, 1, NULL); //global.hSem = &semm; global.ofs.open("file.txt"); global.ofs.close(); break; case WM_COMMAND: switch (LOWORD (wParam)) { case IDM_COM1: cc.dwSize = sizeof(COMMCONFIG); cc.wVersion = 0x100; if (!CommConfigDialog (lpszCommName1, hwnd, &cc)) break; else { comset = true; curCom = 1; } break; case IDM_COM2: cc.dwSize = sizeof(COMMCONFIG); cc.wVersion = 0x100; if (!CommConfigDialog (lpszCommName2, hwnd, &cc)) break; else { comset = true; curCom = 2; } break; case IDM_COM3: cc.dwSize = sizeof(COMMCONFIG); cc.wVersion = 0x100; if (!CommConfigDialog (lpszCommName3, hwnd, &cc)) break; else { comset = true; curCom = 3; } break; case IDM_COM4: cc.dwSize = sizeof(COMMCONFIG); cc.wVersion = 0x100; if (!CommConfigDialog (lpszCommName4, hwnd, &cc)) { break; }else { comset = true; curCom = 4; } break; case IDM_Connect: //WaitForSingleObject(ov.hEvent, INFINITE); //MessageBox(hwnd, TEXT(""), TEXT(""), MB_OK); if (comset) { if (curCom == 1) { if ((hComm = CreateFile (lpszCommName1, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)) == INVALID_HANDLE_VALUE) { MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK); return FALSE; } } else if (curCom == 2) { if ((hComm = CreateFile (lpszCommName2, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL, NULL)) == INVALID_HANDLE_VALUE) { MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK); return FALSE; } } else if (curCom == 3) { if ((hComm = CreateFile (lpszCommName3, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL, NULL)) == INVALID_HANDLE_VALUE) { MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK); return FALSE; } } else if (curCom == 4) { if ((hComm = CreateFile (lpszCommName4, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)) == INVALID_HANDLE_VALUE) { MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK); return FALSE; } } lpDCB = &cc.dcb; if (!SetCommState(hComm, lpDCB)) { MessageBox (NULL, TEXT("Error setting COM state"), TEXT(""), MB_OK); return false; } COMMTIMEOUTS timeouts; timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.ReadTotalTimeoutConstant = 0; timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 0; if (!SetCommTimeouts(hComm, &timeouts)) { MessageBox (NULL, TEXT("Error setting COM timeouts"), TEXT(""), MB_OK); return false; } if (hComm) { global.hComm = &hComm; //global.ov = ov; //opThrd = CreateThread(NULL, 0, OutputThread, (LPVOID)hwnd, 0, &opThrdID ); recvThread = CreateThread(NULL, 0, receiverThread, &global, NULL, &opThrdID); MessageBox(NULL, TEXT("connected"), TEXT(""), MB_OK); } else { MessageBox(NULL, TEXT("Please select a COM port."), TEXT(""), MB_OK); } } else { MessageBox(NULL, TEXT("Please select a COM port."), TEXT(""), MB_OK); } break; case IDM_Disconnect: //kills the reading thread and closes the com port if they are active if (KillReader == false && hComm) { KillReader = true; CloseHandle(hComm); MessageBox(NULL, TEXT("disconnected"), TEXT(""), MB_OK); } break; case IDM_OpenFile: ofn.lStructSize = sizeof (OPENFILENAME) ; ofn.hwndOwner = hwnd ; ofn.hInstance = NULL ; ofn.lpstrFilter = szFilter ; ofn.lpstrCustomFilter = NULL ; ofn.nMaxCustFilter = 0 ; ofn.nFilterIndex = 0 ; ofn.lpstrFile = NULL ; // Set in Open and Close functions ofn.nMaxFile = MAX_PATH ; ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions ofn.nMaxFileTitle = MAX_PATH ; ofn.lpstrInitialDir = NULL ; ofn.lpstrTitle = NULL ; ofn.Flags = 0 ; // Set in Open and Close functions ofn.nFileOffset = 0 ; ofn.nFileExtension = 0 ; ofn.lpstrDefExt = TEXT ("txt") ; ofn.lCustData = 0L ; ofn.lpfnHook = NULL ; ofn.lpTemplateName = NULL ; ofn.hwndOwner = hwnd ; ofn.lpstrFile = szFileName ; ofn.lpstrFileTitle = szTitleName ; ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ; if (GetOpenFileName(&ofn)) { std::wstring wfilename(szFileName); std::string filename; for(int i = 0; i < wfilename.size(); i++) { filename += wfilename[i]; } ifs = OpenFile(filename); readFile(ifs); DWORD threadID; DWORD exitStatus; if (sendThread == 0 || (GetExitCodeThread(sendThread, &exitStatus) && exitStatus != STILL_ACTIVE)) { sendThread = CreateThread(NULL, 0, sendBufferThread, &global, NULL, &threadID); } } } break; case WM_CHAR: // Process keystroke break; case WM_LBUTTONDOWN: break; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); si.cbSize = sizeof(si); si.fMask = SIF_ALL; si.nMin = 0; si.nMax = cyClient; si.nPos = 0; si.nPage = 50; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); break; case WM_VSCROLL: si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); iVertPos = si.nPos; switch(LOWORD(wParam)){ case SB_LINEUP: si.nPos -= 10; break; case SB_LINEDOWN: si.nPos += 10; break; case SB_PAGEUP: si.nPos -= si.nPage; break; case SB_PAGEDOWN: si.nPos += si.nPage; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; default: break; } si.fMask = SIF_POS; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); GetScrollInfo(hwnd, SB_VERT, &si); //if there was change in the vertical scroll bar, make adjustments to redraw if (si.nPos != iVertPos){ //InvalidateRect(hwnd, &text_area, TRUE); } break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); MoveToEx(hdc, cxClient - cxClient/3, 0, NULL); LineTo(hdc, cxClient - cxClient/3, cyClient); MoveToEx(hdc, 0, cyClient - cyClient/3, NULL); LineTo(hdc, cxClient, cyClient - cyClient/3); DisplayStatistics(topright, stats, hdc); DisplayReceivedFileData(topleft, lines, hdc); ReleaseDC(hwnd, hdc); break; case WM_DESTROY: // Terminate program if (hComm) { //CloseHandle(hComm); } PostQuitMessage (0); break; default: return DefWindowProc (hwnd, Message, wParam, lParam); } return 0; }
void Draw2DCorSys(HWND hWnd,HDC hdc,P_2D_COORSYS p2DCoorSys) { HPEN m_COOR_Pen,mOldPen1,m_Grid_Pen,mOldPen2; RECT mOPAixsRect,mHelpRect; HFONT mTextFont1,mTextFont2,mOldFont; int iFontSize; TCHAR chHelpString[200]; // if((p2DCoorSys == NULL) || (hWnd == NULL) || (hdc == NULL)) return; m_COOR_Pen = CreatePen(PS_SOLID,2,RGB(0,0,0)); mOldPen1 = (HPEN)SelectObject(hdc,m_COOR_Pen); //draw X axis MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - p2DCoorSys->shX_MinusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen); //draw arrow MoveToEx(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio - 5, p2DCoorSys->shOP_YinScreen - 5); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio - 5, p2DCoorSys->shOP_YinScreen + 5); //draw Y aixs MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen + p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); //draw arrow MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - 5,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio + 5); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + 5,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio + 5); //display "+x" iFontSize = 40; mTextFont1 = CreateFont(iFontSize,0,0,0,FW_BOLD, 0/*非斜体*/,0/*不带下划线*/,0,GB2312_CHARSET/*字符集*/,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,(LPCSTR)"Arial"); mOldFont = (HFONT)SelectObject(hdc,mTextFont1); SetTextColor(hdc,RGB(0,0,255)); mOPAixsRect.left = p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio + 5; mOPAixsRect.right = mOPAixsRect.left + 40; mOPAixsRect.top = p2DCoorSys->shOP_YinScreen - 20; mOPAixsRect.bottom = p2DCoorSys->shOP_YinScreen +20; DrawText(hdc,"+x",2,&mOPAixsRect,DT_LEFT | DT_VCENTER); //display "+y" mOPAixsRect.left = p2DCoorSys->shOP_XinScreen - 20; mOPAixsRect.right = mOPAixsRect.left + 40; mOPAixsRect.bottom = p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio +30; mOPAixsRect.top = mOPAixsRect.bottom - 40; DrawText(hdc,"+y",2,&mOPAixsRect,DT_LEFT | DT_VCENTER); //display help information. iFontSize = 15; mTextFont2 = CreateFont(iFontSize,0,0,0,FW_BOLD, 0/*非斜体*/,0/*不带下划线*/,0,GB2312_CHARSET/*字符集*/,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,(LPCSTR)"Arial"); mOldFont = (HFONT)SelectObject(hdc,mTextFont2); SetTextColor(hdc,RGB(255,0,0)); mHelpRect.left = mTextRect.left; mHelpRect.top = mTextRect.top; mHelpRect.bottom = mHelpRect.top + 20; mHelpRect.right = mHelpRect.left + 300; sprintf(chHelpString,"X_OP:%d Y_OP:%d\0",p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen); DrawText(hdc,chHelpString,strlen(chHelpString),&mHelpRect,DT_LEFT|DT_VCENTER); mHelpRect.top = mHelpRect.bottom; mHelpRect.bottom = mHelpRect.top + 20; sprintf(chHelpString,"Pixel Scale Ratio: 1:%d\0",p2DCoorSys->shPixelMapRatio); DrawText(hdc,chHelpString,strlen(chHelpString),&mHelpRect,DT_LEFT|DT_VCENTER); mHelpRect.top = mHelpRect.bottom; mHelpRect.bottom = mHelpRect.top + 20; sprintf(chHelpString,"Mouse_X:%d Mouse_Y:%d\0",p2DCoorSys->shMouseXPos,p2DCoorSys->shMouseYPos); DrawText(hdc,chHelpString,strlen(chHelpString),&mHelpRect,DT_LEFT|DT_VCENTER); //draw grid. if(p2DCoorSys->bShowGrid) { int iTmp; m_Grid_Pen = CreatePen(PS_SOLID,1,RGB(255,0,0)); mOldPen2 = (HPEN)SelectObject(hdc,m_Grid_Pen); for(iTmp = 1; iTmp <= p2DCoorSys->shX_PlusAxisValue; iTmp++) { MoveToEx(hdc,p2DCoorSys->shOP_XinScreen + iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen + p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen + iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); } for(iTmp = 1; iTmp <= p2DCoorSys->shX_PlusAxisValue; iTmp++) { MoveToEx(hdc,p2DCoorSys->shOP_XinScreen - iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen + p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen - iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); } for(iTmp = 1; iTmp <= p2DCoorSys->shY_PlusAxisValue; iTmp++) { MoveToEx(hdc,p2DCoorSys->shOP_XinScreen, p2DCoorSys->shOP_YinScreen - iTmp * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen - iTmp * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen, p2DCoorSys->shOP_YinScreen - iTmp * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen - iTmp * p2DCoorSys->shPixelMapRatio); } for(iTmp = 1; iTmp <= p2DCoorSys->shY_MinusAxisValue; iTmp++) { MoveToEx(hdc,p2DCoorSys->shOP_XinScreen, p2DCoorSys->shOP_YinScreen + iTmp * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen + iTmp * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen, p2DCoorSys->shOP_YinScreen + iTmp * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen + iTmp * p2DCoorSys->shPixelMapRatio); } } SelectObject(hdc,mOldPen1); SelectObject(hdc,mOldPen2); DeleteObject(m_COOR_Pen); DeleteObject(m_Grid_Pen); SelectObject(hdc,mOldFont); DeleteObject(mOldFont); return; }
void PaintLine(HDC hdc, const RectI& rect) { MoveToEx(hdc, rect.x, rect.y, NULL); LineTo(hdc, rect.x + rect.dx, rect.y + rect.dy); }
void CALLBACK PaintPageGraphic(LPWIZARD pWiz, HDC hdc, LPRECT prTarget, HPALETTE hpal) { static HFONT hFont = AfsAppLib_CreateFont(IDS_GRAPHIC_FONT); static HPEN hPenWhite = CreatePen(PS_SOLID, 1, clrWHITE); static HPEN hPenHighlight = CreatePen(PS_SOLID, 1, clrHIGHLIGHT); static HPEN hPenShadow = CreatePen(PS_SOLID, 1, clrSHADOW); static HPEN hPenBlack = CreatePen(PS_SOLID, 1, clrBLACK); static HPEN hPenBarIntLeft = CreatePen(PS_SOLID, 1, clrBAR_INT_LEFT); static HPEN hPenBarIntRight = CreatePen(PS_SOLID, 1, clrBAR_INT_RIGHT); static HPEN hPenArrowInterior = CreatePen(PS_SOLID, 1, clrARROW_INTERIOR); // First find out where we'll be drawing things. RECT rArea; rArea.top = prTarget->bottom - cyAREA - cyBOTTOM_MARGIN; rArea.bottom = prTarget->bottom - cyBOTTOM_MARGIN; rArea.left = prTarget->left + cxLEFT_MARGIN; rArea.right = prTarget->right - cxRIGHT_MARGIN; // Draw the "Current Step:" text HGDIOBJ hFontOld = SelectObject(hdc, hFont); COLORREF clrTextOld = SetTextColor (hdc, clrTEXT_CURRENT); SetBkMode (hdc, TRANSPARENT); TCHAR szText[cchRESOURCE]; GetResString(IDS_CURRENT_STEP, szText); RECT rText = rArea; DWORD dwFlags = DT_CENTER | DT_TOP | DT_SINGLELINE; DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags | DT_CALCRECT, NULL); rText.right = rArea.right; DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL); // Draw the progress bar; it should look like this: // wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww // (w=white, b=black... // whhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhb // h=highlight, s=shadow... // whllllllllllllllllrrrrrrrrrrrrrrrsb // l=left/int, r=right/int) // whllllllllllllllllrrrrrrrrrrrrrrrsb // l=left/int, r=right/int) // whssssssssssssssssssssssssssssssssb // h=highlight, s=shadow... // wbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb // h=highlight, s=shadow... // Oh--we'll need to know where the pointer's point should go. We'll // make that be where the leftmost dot of the pointer's tip, and the // rightmost dot that's colored "l". One state 0, we want the pointer // to be all the way to the left--and on state {g_nNumStates-1}, we want // it all the way to the right RECT rBar = rArea; rBar.top = rText.bottom + cyBELOW_CURRENT; rBar.bottom = rBar.top + 6; RECT rBarInterior = rBar; InflateRect (&rBarInterior, -2, -2); int nStepSize = (rBarInterior.right - rBarInterior.left) / (g_nNumStates-1); int xCurPos = rBarInterior.left + (g_pWiz->GetState() * nStepSize); if (!g_pWiz->GetState()) xCurPos = rBarInterior.left-1; // don't draw *any* green else if (g_pWiz->GetState() == (int)(g_nNumStates-1)) xCurPos = rBarInterior.right-1; // don't draw *any* red // Draw that bar! HGDIOBJ hPenOld = SelectObject (hdc, hPenWhite); MoveToEx (hdc, rBar.left, rBar.bottom-1, 0); LineTo (hdc, rBar.left, rBar.top); LineTo (hdc, rBar.right, rBar.top); MoveToEx (hdc, rBar.left, rBar.bottom, 0); SelectObject (hdc, hPenHighlight); MoveToEx (hdc, rBar.left+1, rBar.bottom-2, 0); LineTo (hdc, rBar.left+1, rBar.top+1); LineTo (hdc, rBar.right-1, rBar.top+1); SelectObject (hdc, hPenShadow); MoveToEx (hdc, rBar.left+2, rBar.bottom-2, 0); LineTo (hdc, rBar.right-2, rBar.bottom-2); LineTo (hdc, rBar.right-2, rBar.top+1); SelectObject (hdc, hPenBlack); MoveToEx (hdc, rBar.left+1, rBar.bottom-1, 0); LineTo (hdc, rBar.right-1, rBar.bottom-1); LineTo (hdc, rBar.right-1, rBar.top); if (xCurPos >= rBarInterior.left) { SelectObject (hdc, hPenBarIntLeft); MoveToEx (hdc, rBarInterior.left, rBarInterior.top, 0); LineTo (hdc, xCurPos+1, rBarInterior.top); MoveToEx (hdc, rBarInterior.left, rBarInterior.top+1, 0); LineTo (hdc, xCurPos+1, rBarInterior.top+1); } if (xCurPos < rBarInterior.right-1) { SelectObject (hdc, hPenBarIntRight); MoveToEx (hdc, xCurPos+1, rBarInterior.top, 0); LineTo (hdc, rBarInterior.right, rBarInterior.top); MoveToEx (hdc, xCurPos+1, rBarInterior.top+1, 0); LineTo (hdc, rBarInterior.right, rBarInterior.top+1); } SelectObject (hdc, hPenOld); // Draw the arrow underneath it; it should look like this: // wb // whsb // whassb // whaaassb // whaaaaassb // wssssssssssb // Remember that the topmost "w" is where xCurPos is. RECT rArrow; rArrow.top = rBar.bottom +1; rArrow.bottom = rArrow.top +6; rArrow.left = xCurPos -5; rArrow.right = xCurPos +7; hPenOld = SelectObject (hdc, hPenWhite); MoveToEx (hdc, rArrow.left, rArrow.bottom-1, 0); LineTo (hdc, xCurPos+1, rArrow.top-1); SelectObject (hdc, hPenHighlight); MoveToEx (hdc, rArrow.left+2, rArrow.bottom-2, 0); LineTo (hdc, xCurPos+1, rArrow.top); SelectObject (hdc, hPenShadow); MoveToEx (hdc, rArrow.left+1, rArrow.bottom-1, 0); LineTo (hdc, rArrow.right-1, rArrow.bottom-1); MoveToEx (hdc, xCurPos+1, rArrow.top+1, 0); LineTo (hdc, rArrow.right, rArrow.bottom); MoveToEx (hdc, xCurPos+1, rArrow.top+2, 0); LineTo (hdc, rArrow.right-1, rArrow.bottom); SelectObject (hdc, hPenBlack); MoveToEx (hdc, xCurPos+1, rArrow.top, 0); LineTo (hdc, rArrow.right, rArrow.bottom); // wb // whsb // whassb // whaaassb // whaaaaassb // wssssssssssb SelectObject (hdc, hPenArrowInterior); MoveToEx (hdc, xCurPos, rArrow.top+2, 0); LineTo (hdc, xCurPos+1, rArrow.top+2); MoveToEx (hdc, xCurPos-1, rArrow.top+3, 0); LineTo (hdc, xCurPos+2, rArrow.top+3); MoveToEx (hdc, xCurPos-2, rArrow.top+4, 0); LineTo (hdc, xCurPos+3, rArrow.top+4); SelectObject (hdc, hPenOld); // Draw the description text SetTextColor (hdc, clrTEXT_STEP); GetResString(g_StateDesc[g_pWiz->GetState()], szText); rText = rArea; rText.top = rArrow.bottom + cyBELOW_ARROW; dwFlags = DT_CENTER | DT_TOP | DT_WORDBREAK; DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL); SetTextColor (hdc, clrTextOld); SelectObject (hdc, hFontOld); }
void CWinMenu::OnPaint() { CPaintDC dc(this); // device context for painting RECT rect; HDC hDC = dc.GetSafeHdc(); GetClientRect( &rect ); // Where will we draw? HDC hDraw = hDC; if ( m_offscreen.Create( hDC, &rect ) ) hDraw = m_offscreen.GetSafeHdc(); // Fill in menu window COLORREF rgbBck = m_rgbMenu; if ( m_bSystemColors ) rgbBck = GetSysColor( COLOR_MENU ); COLORREF rgbBckLt = ScaleColor( rgbBck, 40 ); COLORREF rgbBckDk = ScaleColor( rgbBck, -40 ); // CGrDC::GradientFill( hDraw, &rect, RGB( 255, 0, 0 ), RGB( 0, 255, 0 ), // RGB( 255, 0, 255 ), RGB( 0, 255, 255 ) ); if ( m_bck.GetSafeHdc() == NULL || RW( rect ) != m_bck.GetWidth() || RH( rect ) != m_bck.GetHeight() ) { // Create the background m_bck.Create( NULL, &rect ); if ( m_dwShading == 0 ) CGrDC::FillSolidRect( hDraw, &rect, rgbBck ); else if ( m_dwShading == 1 ) CGrDC::VertGradientFill( hDraw, &rect, rgbBckLt, rgbBckDk ); else if ( m_dwShading == 3 ) { CGrDC::VertGradientFill( m_bck, m_bck, CGrDC::ScaleColor( GetSysColor( COLOR_3DFACE ), 50 ), CGrDC::ScaleColor( GetSysColor( COLOR_3DFACE ), -50 ) ); m_bck.Aluminize( 2 ); } // end else if else if ( m_dwShading == 4 ) { CGrDC::VertGradientFill( m_bck, m_bck, CGrDC::ScaleColor( GetSysColor( COLOR_3DFACE ), 50 ), CGrDC::ScaleColor( GetSysColor( COLOR_3DFACE ), -50 ) ); m_bck.Texturize( 5 ); } // end else if else { // Gradient fill COLORREF rgbCorner = m_rgbSel; if ( m_bSystemColors ) rgbCorner = GetSysColor( COLOR_ACTIVECAPTION ); CGrDC::GradientFill( m_bck, &rect, rgbBckLt, rgbBckDk, rgbBckLt, rgbCorner ); } // end else RECT brect; CopyRect( &brect, m_bck ); HPEN whitepen = CreatePen( PS_SOLID, 3, ScaleColor( rgbBck, 120 ) ); HPEN dkgraypen = CreatePen( PS_SOLID, 3, ScaleColor( rgbBck, -120 ) ); HPEN oldpen = (HPEN)SelectObject( m_bck, whitepen ); // Draw white line MoveToEx( m_bck, brect.right, brect.top, NULL ); LineTo( m_bck, brect.left, brect.top ); LineTo( m_bck, brect.left, brect.bottom ); // Draw dark gray line SelectObject( m_bck, dkgraypen ); MoveToEx( m_bck, brect.left, brect.bottom, NULL ); LineTo( m_bck, brect.right, brect.bottom ); LineTo( m_bck, brect.right, brect.top ); SelectObject( m_bck, oldpen ); DeleteObject( whitepen ); DeleteObject( dkgraypen ); } // end if // Draw background m_bck.Draw( hDraw, &rect ); // Draw the menu items DrawMenuItems( hDraw, &rect ); // Copy from offscreen if ( m_offscreen.GetSafeHdc() ) m_offscreen.Draw( hDC, &rect ); }
static LRESULT WINAPI submenuWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { const int itemheight = 12, lcol=12, rcol=12, mcol=10; switch (uMsg) { case WM_CREATE: m_trackingMenus.Add(hwnd); SetWindowLongPtr(hwnd,GWLP_USERDATA,lParam); if (m_trackingPar && !(m_trackingFlags&TPM_NONOTIFY)) SendMessage(m_trackingPar,WM_INITMENUPOPUP,(WPARAM)lParam,0); { HDC hdc = GetDC(hwnd); HMENU__ *menu = (HMENU__*)lParam; int ht = menu->items.GetSize()*itemheight, wid=100,wid2=0; int xpos=m_trackingPt.x; int ypos=m_trackingPt.y; int x; for (x=0; x < menu->items.GetSize(); x++) { MENUITEMINFO *inf = menu->items.Get(x); if (inf->fType == MFT_STRING && inf->dwTypeData) { RECT r={0,}; const char *pt2 = strstr(inf->dwTypeData,"\t"); DrawText(hdc,inf->dwTypeData,pt2 ? pt2-inf->dwTypeData : -1,&r,DT_CALCRECT|DT_SINGLELINE); if (r.right > wid) wid=r.right; if (pt2) { r.right=r.left; DrawText(hdc,pt2+1,-1,&r,DT_CALCRECT|DT_SINGLELINE); if (r.right > wid2) wid2=r.right; } } } wid+=lcol+rcol + (wid2?wid2+mcol:0); ReleaseDC(hwnd,hdc); RECT tr={xpos,ypos,xpos+wid,ypos+ht},vp; SWELL_GetViewPort(&vp,&tr,true); if (tr.bottom > vp.bottom) { tr.top += vp.bottom-tr.bottom; tr.bottom=vp.bottom; } if (tr.right > vp.right) { tr.left += vp.right-tr.right; tr.right=vp.right; } if (tr.left < vp.left) { tr.right += vp.left-tr.left; tr.left=vp.left; } if (tr.top < vp.top) { tr.bottom += vp.top-tr.top; tr.top=vp.top; } SetWindowPos(hwnd,NULL,tr.left,tr.top,tr.right-tr.left,tr.bottom-tr.top,SWP_NOZORDER); } SetWindowLong(hwnd,GWL_STYLE,GetWindowLong(hwnd,GWL_STYLE)&~WS_CAPTION); ShowWindow(hwnd,SW_SHOW); SetFocus(hwnd); SetTimer(hwnd,1,250,NULL); break; case WM_PAINT: { PAINTSTRUCT ps; if (BeginPaint(hwnd,&ps)) { RECT cr; GetClientRect(hwnd,&cr); HBRUSH br=CreateSolidBrush(GetSysColor(COLOR_3DFACE)); HPEN pen=CreatePen(PS_SOLID,0,GetSysColor(COLOR_3DSHADOW)); HGDIOBJ oldbr = SelectObject(ps.hdc,br); HGDIOBJ oldpen = SelectObject(ps.hdc,pen); Rectangle(ps.hdc,cr.left,cr.top,cr.right-1,cr.bottom-1); SetBkMode(ps.hdc,TRANSPARENT); int cols[2]={ GetSysColor(COLOR_BTNTEXT),GetSysColor(COLOR_3DHILIGHT)}; HMENU__ *menu = (HMENU__*)GetWindowLongPtr(hwnd,GWLP_USERDATA); int x; for (x=0; x < menu->items.GetSize(); x++) { MENUITEMINFO *inf = menu->items.Get(x); RECT r={lcol,x*itemheight,cr.right,(x+1)*itemheight}; bool dis = !!(inf->fState & MF_GRAYED); SetTextColor(ps.hdc,cols[dis]); if (inf->fType == MFT_STRING && inf->dwTypeData) { const char *pt2 = strstr(inf->dwTypeData,"\t"); DrawText(ps.hdc,inf->dwTypeData,pt2 ? pt2-inf->dwTypeData : -1,&r,DT_VCENTER|DT_SINGLELINE); if (pt2) { RECT tr=r; tr.right-=rcol; DrawText(ps.hdc,pt2+1,-1,&tr,DT_VCENTER|DT_SINGLELINE|DT_RIGHT); } } else { MoveToEx(ps.hdc,r.left - lcol/2,(r.top+r.bottom)/2,NULL); LineTo(ps.hdc,r.right - rcol*3/2,(r.top+r.bottom)/2); } if (inf->hSubMenu) { RECT r2=r; r2.left = r2.right - rcol; DrawText(ps.hdc,">",-1,&r2,DT_VCENTER|DT_RIGHT|DT_SINGLELINE); } if (inf->fState&MF_CHECKED) { RECT r2=r; r2.left = 0; r2.right=lcol; DrawText(ps.hdc,"X",-1,&r2,DT_VCENTER|DT_CENTER|DT_SINGLELINE); } } SelectObject(ps.hdc,oldbr); SelectObject(ps.hdc,oldpen); DeleteObject(br); DeleteObject(pen); EndPaint(hwnd,&ps); } } break; case WM_TIMER: if (wParam==1) { HWND GetFocusIncludeMenus(); HWND h = GetFocusIncludeMenus(); if (h!=hwnd) { int a = h ? m_trackingMenus.Find(h) : -1; if (a<0 || a < m_trackingMenus.Find(hwnd)) DestroyWindow(hwnd); } } break; case WM_DESTROY: { int a = m_trackingMenus.Find(hwnd); m_trackingMenus.Delete(a); if (m_trackingMenus.Get(a)) DestroyWindow(m_trackingMenus.Get(a)); RemoveProp(hwnd,"SWELL_MenuOwner"); } break; case WM_LBUTTONUP: case WM_RBUTTONUP: { RECT r; GetClientRect(hwnd,&r); if (GET_X_LPARAM(lParam)>=r.left && GET_X_LPARAM(lParam)<r.right) { int which = GET_Y_LPARAM(lParam)/itemheight; HMENU__ *menu = (HMENU__*)GetWindowLongPtr(hwnd,GWLP_USERDATA); MENUITEMINFO *inf = menu->items.Get(which); if (inf) { if (inf->fState&MF_GRAYED){ } else if (inf->hSubMenu) { int a = m_trackingMenus.Find(hwnd); HWND next = m_trackingMenus.Get(a+1); if (next) DestroyWindow(next); m_trackingPt.x=r.right; m_trackingPt.y=r.top + which*itemheight; ClientToScreen(hwnd,&m_trackingPt); HWND hh; submenuWndProc(hh=new HWND__(NULL,0,NULL,"menu",false,submenuWndProc,NULL),WM_CREATE,0,(LPARAM)inf->hSubMenu); SetProp(hh,"SWELL_MenuOwner",GetProp(hh,"SWELL_MenuOwner")); } else if (inf->wID) m_trackingRet = inf->wID; } else DestroyWindow(hwnd); } else DestroyWindow(hwnd); } break; } return DefWindowProc(hwnd,uMsg,wParam,lParam); }
void CFrameHolder::PaintFrame2k(HWND hWnd, HDC hdc, RECT &cr) { //RECT cr; //GetWindowRect(hWnd, &cr); //OffsetRect(&cr, -cr.left, -cr.top); //TODO: Обработка XP HPEN hOldPen = (HPEN)SelectObject(hdc, (HPEN)GetStockObject(BLACK_PEN)); HBRUSH hOldBr = (HBRUSH)SelectObject(hdc, (HBRUSH)GetStockObject(BLACK_BRUSH)); HPEN hPenHilight = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT)); HPEN hPenLight = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DLIGHT)); HPEN hPenShadow = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW)); HPEN hPenDkShadow = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW)); HPEN hPenFace = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DFACE)); //TODO: разобраться с шириной рамки, активной/неактивной HPEN hPenBorder = CreatePen(PS_SOLID, 1, GetSysColor(mb_NcActive ? COLOR_ACTIVEBORDER : COLOR_INACTIVEBORDER)); //TODO: градиент HBRUSH hBrCaption = GetSysColorBrush(mb_NcActive ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION); // int nCaptionY = GetSystemMetrics(SM_CYCAPTION); SelectObject(hdc, hPenLight); MoveToEx(hdc, cr.left, cr.bottom-1, NULL); LineTo(hdc, cr.left, 0); LineTo(hdc, cr.right-1, 0); SelectObject(hdc, hPenHilight); MoveToEx(hdc, cr.left+1, cr.bottom-2, NULL); LineTo(hdc, cr.left+1, 1); LineTo(hdc, cr.right-2, 1); SelectObject(hdc, hPenDkShadow); MoveToEx(hdc, cr.left, cr.bottom-1, NULL); LineTo(hdc, cr.right-1, cr.bottom-1); LineTo(hdc, cr.right-1, -1); SelectObject(hdc, hPenShadow); MoveToEx(hdc, cr.left+1, cr.bottom-2, NULL); LineTo(hdc, cr.right-2, cr.bottom-2); LineTo(hdc, cr.right-2, 0); // рамка. обычно это 1 пиксел цвета кнопки SelectObject(hdc, hPenBorder); //TODO: но может быть и более одного пиксела Rectangle(hdc, cr.left+2, cr.top+2, cr.right-2, cr.bottom-2); //TODO: Заливка заголовка через GradientFill SelectObject(hdc, hPenFace); SelectObject(hdc, hBrCaption); Rectangle(hdc, cr.left+3, cr.top+3, cr.right-3, cr.top+nCaptionY+4); //что осталось SelectObject(hdc, hPenFace); //Rectangle(hdc, cr.left+3, cr.top+3+nCaptionY, cr.right-3, cr.bottom-3); MoveToEx(hdc, cr.left+3, cr.top+3+nCaptionY, 0); LineTo(hdc, cr.left+3, cr.bottom-3); LineTo(hdc, cr.right-3, cr.bottom-3); LineTo(hdc, cr.right-3, cr.top+3+nCaptionY); SelectObject(hdc, hOldPen); SelectObject(hdc, hOldBr); DeleteObject(hPenHilight); DeleteObject(hPenLight); DeleteObject(hPenShadow); DeleteObject(hPenDkShadow); DeleteObject(hPenFace); DeleteObject(hPenBorder); cr.left += 4; cr.right -= 4; cr.bottom -= 4; cr.top += 4+nCaptionY; }
void CCodeView::OnPaint(wxPaintEvent& event) { // -------------------------------------------------------------------- // General settings // ------------------------- wxPaintDC dc(this); wxRect rc = GetClientRect(); dc.SetFont(DebuggerFont); wxCoord w,h; dc.GetTextExtent("0WJyq", &w, &h); if (h > m_rowHeight) m_rowHeight = h; dc.GetTextExtent("W", &w, &h); int charWidth = w; struct branch { int src, dst, srcAddr; }; branch branches[256]; int numBranches = 0; // TODO: Add any drawing code here... int width = rc.width; int numRows = (rc.height / m_rowHeight) / 2 + 2; // ------------ // -------------------------------------------------------------------- // Colors and brushes // ------------------------- dc.SetBackgroundMode(wxTRANSPARENT); // the text background const wxColour bgColor = *wxWHITE; wxPen nullPen(bgColor); wxPen currentPen(*wxBLACK_PEN); wxPen selPen(*wxGREY_PEN); nullPen.SetStyle(wxTRANSPARENT); currentPen.SetStyle(wxSOLID); wxBrush currentBrush(*wxLIGHT_GREY_BRUSH); wxBrush pcBrush(*wxGREEN_BRUSH); wxBrush bpBrush(*wxRED_BRUSH); wxBrush bgBrush(bgColor); wxBrush nullBrush(bgColor); nullBrush.SetStyle(wxTRANSPARENT); dc.SetPen(nullPen); dc.SetBrush(bgBrush); dc.DrawRectangle(0, 0, 16, rc.height); dc.DrawRectangle(0, 0, rc.width, 5); // ------------ // -------------------------------------------------------------------- // Walk through all visible rows // ------------------------- for (int i = -numRows; i <= numRows; i++) { unsigned int address = m_curAddress + i * m_align; int rowY1 = rc.height / 2 + m_rowHeight * i - m_rowHeight / 2; int rowY2 = rc.height / 2 + m_rowHeight * i + m_rowHeight / 2; wxString temp = wxString::Format("%08x", address); u32 col = m_debugger->GetColor(address); wxBrush rowBrush(wxColour(col >> 16, col >> 8, col)); dc.SetBrush(nullBrush); dc.SetPen(nullPen); dc.DrawRectangle(0, rowY1, 16, rowY2 - rowY1 + 2); if (m_selecting && (address == m_selection)) dc.SetPen(selPen); else dc.SetPen(i == 0 ? currentPen : nullPen); if (address == m_debugger->GetPC()) dc.SetBrush(pcBrush); else dc.SetBrush(rowBrush); dc.DrawRectangle(16, rowY1, width, rowY2 - rowY1 + 1); dc.SetBrush(currentBrush); if (!m_plain) { dc.SetTextForeground("#600000"); // the address text is dark red dc.DrawText(temp, 17, rowY1); dc.SetTextForeground(*wxBLACK); } // If running if (m_debugger->IsAlive()) { char dis[256]; m_debugger->Disassemble(address, dis, 256); char* dis2 = strchr(dis, '\t'); char desc[256] = ""; // If we have a code if (dis2) { *dis2 = 0; dis2++; // look for hex strings to decode branches const char* mojs = strstr(dis2, "0x8"); if (mojs) { for (int k = 0; k < 8; k++) { bool found = false; for (int j = 0; j < 22; j++) { if (mojs[k + 2] == "0123456789ABCDEFabcdef"[j]) found = true; } if (!found) { mojs = nullptr; break; } } } if (mojs) { int offs; sscanf(mojs + 2, "%08x", &offs); branches[numBranches].src = rowY1 + m_rowHeight / 2; branches[numBranches].srcAddr = address / m_align; branches[numBranches++].dst = (int)(rowY1 + ((s64)(u32)offs - (s64)(u32)address) * m_rowHeight / m_align + m_rowHeight / 2); sprintf(desc, "-->%s", m_debugger->GetDescription(offs).c_str()); dc.SetTextForeground(wxTheColourDatabase->Find("PURPLE")); // the -> arrow illustrations are purple } else { dc.SetTextForeground(*wxBLACK); } dc.DrawText(StrToWxStr(dis2), 17 + 17*charWidth, rowY1); // ------------ } // Show blr as its' own color if (strcmp(dis, "blr")) dc.SetTextForeground(wxTheColourDatabase->Find("DARK GREEN")); else dc.SetTextForeground(wxTheColourDatabase->Find("VIOLET")); dc.DrawText(StrToWxStr(dis), 17 + (m_plain ? 1*charWidth : 9*charWidth), rowY1); if (desc[0] == 0) { strcpy(desc, m_debugger->GetDescription(address).c_str()); } if (!m_plain) { dc.SetTextForeground(*wxBLUE); //char temp[256]; //UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE); if (strlen(desc)) { dc.DrawText(StrToWxStr(desc), 17 + 35 * charWidth, rowY1); } } // Show red breakpoint dot if (m_debugger->IsBreakpoint(address)) { dc.SetBrush(bpBrush); dc.DrawRectangle(2, rowY1 + 1, 11, 11); } } } // end of for // ------------ // -------------------------------------------------------------------- // Colors and brushes // ------------------------- dc.SetPen(currentPen); for (int i = 0; i < numBranches; i++) { int x = 17 + 49 * charWidth + (branches[i].srcAddr % 9) * 8; MoveTo(x-2, branches[i].src); if (branches[i].dst < rc.height + 400 && branches[i].dst > -400) { LineTo(dc, x+2, branches[i].src); LineTo(dc, x+2, branches[i].dst); LineTo(dc, x-4, branches[i].dst); MoveTo(x, branches[i].dst - 4); LineTo(dc, x-4, branches[i].dst); LineTo(dc, x+1, branches[i].dst+5); } //else //{ // This can be re-enabled when there is a scrollbar or // something on the codeview (the lines are too long) //LineTo(dc, x+4, branches[i].src); //MoveTo(x+2, branches[i].dst-4); //LineTo(dc, x+6, branches[i].dst); //LineTo(dc, x+1, branches[i].dst+5); //} //LineTo(dc, x, branches[i].dst+4); //LineTo(dc, x-2, branches[i].dst); } // ------------ }
LRESULT CALLBACK ChildWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (message) { case WM_CREATE : SetWindowLong (hwnd, 0, 0) ; // on/off flag return 0 ; case WM_KEYDOWN: // Send most key presses to the parent window if (wParam != VK_RETURN && wParam != VK_SPACE) { SendMessage (GetParent (hwnd), message, wParam, lParam) ; return 0 ; } // For Return and Space, fall through to toggle the square case WM_LBUTTONDOWN : SetWindowLong (hwnd, 0, 1 ^ GetWindowLong (hwnd, 0)) ; SetFocus (hwnd) ; InvalidateRect (hwnd, NULL, FALSE) ; return 0 ; // For focus messages, invalidate the window for repaint case WM_SETFOCUS: idFocus = GetWindowLong (hwnd, GWL_ID) ; // Fall through case WM_KILLFOCUS: InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; case WM_PAINT : hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; Rectangle (hdc, 0, 0, rect.right, rect.bottom) ; // Draw the "x" mark if (GetWindowLong (hwnd, 0)) { MoveToEx (hdc, 0, 0, NULL) ; LineTo (hdc, rect.right, rect.bottom) ; MoveToEx (hdc, 0, rect.bottom, NULL) ; LineTo (hdc, rect.right, 0) ; } // Draw the "focus" rectangle if (hwnd == GetFocus ()) { rect.left += rect.right / 10 ; rect.right -= rect.left ; rect.top += rect.bottom / 10 ; rect.bottom -= rect.top ; SelectObject (hdc, GetStockObject (NULL_BRUSH)) ; SelectObject (hdc, CreatePen (PS_DASH, 0, 0)) ; Rectangle (hdc, rect.left, rect.top, rect.right, rect.bottom) ; DeleteObject (SelectObject (hdc, GetStockObject (BLACK_PEN))) ; } EndPaint (hwnd, &ps) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
LOCAL void Slider_Paint (HWND hWindow, HDC hDC, LPRECT lpRect, BOOL fHighlight) /***********************************************************************/ { BOOL bHasFocus, bSelected, bDown; DWORD dwStyle; RECT rSrcArea, rDstArea; POINT ptDst; UINT id; PDIB pdibSrc, pdibDst; HDC hWinGDC; LPHSLIDERINFO lpInfo; if (! (lpInfo = (LPHSLIDERINFO)GetWindowLong (hWindow, GWL_DATAPTR) ) ) return; rSrcArea = *lpRect; rDstArea = *lpRect; MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rDstArea, 2 ); LPSCENE lpScene = CScene::GetScene (GetParent (hWindow) ); if (! lpScene) return; if ( !lpScene->GetDIBs( &pdibSrc, &pdibDst, &hWinGDC ) ) return; if ( !pdibSrc || !pdibDst || !hWinGDC ) return; bSelected = GetWindowWord (hWindow, GWW_STATE); dwStyle = GetWindowStyle(hWindow); bHasFocus = (GetFocus () == hWindow); bDown = ( bSelected || (lpInfo->bTrack && lpInfo->bInRect && bHasFocus) ); // Repair the dirty bitmap with the clean bitmap if ( pdibSrc->GetCompression() == BI_RLE8 || pdibDst->GetCompression() == BI_RLE8) { // compressed DIBs must use GDI copying (lose transparency ability) pdibSrc->DCBlt( hWinGDC, rDstArea.left, rDstArea.top, rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top, rDstArea.left, rDstArea.top, rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top ); } else { pdibSrc->DibBlt( pdibDst, rDstArea.left, rDstArea.top, rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top, rDstArea.left, rDstArea.top, rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top, NO /*bTransparent*/ ); } // Draw the slider background RECT rSlider = lpInfo->rSlider; RECT rInner = lpInfo->rSlider; rInner.top = lpInfo->iCenter - (lpInfo->iTrackWidth / 2); rInner.bottom = lpInfo->iCenter + (lpInfo->iTrackWidth / 2); MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rSlider, 2); MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rInner, 2); // Turn off tick painting because using background bitmap #ifdef UNUSED HBRUSH hBrush = CreateSolidBrush (lpInfo->rgbBackgnd); HBRUSH hBrush2 = (HBRUSH)GetStockObject (BLACK_BRUSH); FillRect (hWinGDC, & rSlider, hBrush); FillRect (hWinGDC, & rInner, hBrush2); DeleteObject (hBrush); #endif RECT rClient; GetClientRect (hWindow, & rClient); MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rClient, 2 ); // Turn off tick painting because using background bitmap #ifdef UNUSED // Draw a chiselled border RECT rBorder = rClient; InflateRect (& rBorder, 1, 1); int cxButton = rBorder.right - rBorder.left; int cyButton = rBorder.bottom - rBorder.top; HPEN hLitePen = CreatePen (PS_SOLID, 1, RGB (255, 255, 255)); HPEN hDarkPen = CreatePen (PS_SOLID, 1, RGB (128, 128, 128)); HPEN hOldPen = (HPEN)SelectObject (hWinGDC, hLitePen); MoveToEx (hWinGDC, rBorder.left, rBorder.bottom - 1, NULL); LineTo (hWinGDC, rBorder.left, rBorder.top); LineTo (hWinGDC, rBorder.right - 1, rBorder.top); MoveToEx (hWinGDC, rBorder.left + 1, rBorder.bottom - 2, NULL); LineTo (hWinGDC, rBorder.left + 1, rBorder.top + 1); LineTo (hWinGDC, rBorder.right - 2, rBorder.top + 1); SelectObject (hWinGDC, hDarkPen); MoveToEx (hWinGDC, rBorder.right - 1, rBorder.top, NULL); LineTo (hWinGDC, rBorder.right - 1, rBorder.bottom - 1); LineTo (hWinGDC, rBorder.left, rBorder.bottom - 1); MoveToEx (hWinGDC, rBorder.right - 2, rBorder.top + 1, NULL); LineTo (hWinGDC, rBorder.right - 2, rBorder.bottom - 2); LineTo (hWinGDC, rBorder.left + 1, rBorder.bottom - 2); SelectObject (hWinGDC, hOldPen); DeleteObject (hLitePen); DeleteObject (hDarkPen); // If tick-marks are wanted if (lpInfo->iTicks) { int pw = 2; // pen width HPEN hTickPen = CreatePen (PS_SOLID, pw, lpInfo->rgbBackgnd); hOldPen = (HPEN)SelectObject (hWinGDC, hTickPen); int iBmpWidth = lpInfo->rBitmap.right - lpInfo->rBitmap.left; int wx = rClient.right - rClient.left - iBmpWidth; int dx = wx / lpInfo->iTicks; wx = wx - (dx * lpInfo->iTicks) - pw; int x = rClient.left + (iBmpWidth + wx + pw) / 2; // wx is now the excess int y1 = rClient.top + 2; int y2 = y1 + 10; for (int idx = 0; idx <= lpInfo->iTicks ; idx++) { MoveToEx (hWinGDC, x, y1, NULL); LineTo (hWinGDC, x, y2); x += dx; } SelectObject (hWinGDC, hOldPen); DeleteObject (hTickPen); } #endif rSrcArea = lpInfo->rBitmap; rDstArea = lpInfo->rBitmap; MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rDstArea, 2 ); // Get the control ID to load the bitmap resource if (! (id = GetWindowWord (hWindow, GWW_ICONID) ) ) id = GET_WINDOW_ID (hWindow); if (pdibSrc = CDib::LoadDibFromResource (GetWindowInstance (hWindow), MAKEINTRESOURCE(id), GetApp()->m_hPal, (dwStyle & BS_MASK) != 0 )) { // Load the resource if ( pdibSrc->GetCompression() == BI_RLE8 || pdibDst->GetCompression() == BI_RLE8 ) { // compressed DIBs must use GDI copying (lose transparency ability) pdibSrc->DCBlt( hWinGDC, rDstArea.left, rDstArea.top, rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top, rSrcArea.left, rSrcArea.top, rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top ); } else { RGBTRIPLE rgb; LPRGBTRIPLE lpRGB = NULL; if (dwStyle & BS_MASK) { STRING szColor; GetWindowText(hWindow, szColor, sizeof(szColor)); AsciiRGB( szColor, &rgb ); lpRGB = &rgb; } if (dwStyle & BS_HIGHLIGHT) { // Get the transparency color BYTE bTrans = *pdibSrc->GetXY(0, 0); // Get the color to replace LPTR lpColor = pdibSrc->GetXY(1, 0); BYTE bColor = *lpColor; *lpColor = bTrans; // Get the hightlight color LPTR lpHighlight = pdibSrc->GetXY(2, 0); BYTE bHighlight = *lpHighlight; *lpHighlight = bTrans; // Replace the pixels in the DIB if (bDown && (bColor != bHighlight)) { HPTR hp = pdibSrc->GetPtr(); DWORD dwSize = pdibSrc->GetSizeImage(); while ( dwSize-- ) { if (*hp == bColor) *hp = bHighlight; ++hp; } } } // Set slider position if needed if (lpInfo->Position) { int iBmpWidth = lpInfo->rBitmap.right - lpInfo->rBitmap.left; int iWidth = rClient.right - rClient.left - iBmpWidth; int x = (int)(((long)(lpInfo->Position - lpInfo->Min) * iWidth) / (lpInfo->Max - lpInfo->Min)); rDstArea.left += x; if (rDstArea.left < rClient.left) rDstArea.left = rClient.left; else if (rDstArea.left + iBmpWidth > rClient.right) rDstArea.left = rClient.right - iBmpWidth; rDstArea.right = rDstArea.left + iBmpWidth; } pdibSrc->DibBlt( pdibDst, rDstArea.left, rDstArea.top, rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top, rSrcArea.left, rSrcArea.top, rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top, (dwStyle & BS_TRANSPARENT) != 0 /*bTransparent*/, lpRGB ); } delete pdibSrc; } ptDst.x = rSrcArea.left; ptDst.y = rSrcArea.top; if (lpScene) lpScene->Paint( hDC, &rClient, &ptDst ); }
void Path::DoSimplify(int off, int N, double treshhold) { // non-dichotomic method: grow an interval of points approximated by a curve, until you reach the treshhold, and repeat if (N <= 1) { return; } int curP = 0; fitting_tables data; data.Xk = data.Yk = data.Qk = NULL; data.tk = data.lk = NULL; data.fk = NULL; data.totLen = 0; data.nbPt = data.maxPt = data.inPt = 0; Geom::Point const moveToPt = pts[off].p; MoveTo(moveToPt); Geom::Point endToPt = moveToPt; while (curP < N - 1) { int lastP = curP + 1; int M = 2; // remettre a zero data.inPt = data.nbPt = 0; PathDescrCubicTo res(Geom::Point(0, 0), Geom::Point(0, 0), Geom::Point(0, 0)); bool contains_forced = false; int step = 64; while ( step > 0 ) { int forced_pt = -1; int worstP = -1; do { if (pts[off + lastP].isMoveTo == polyline_forced) { contains_forced = true; } forced_pt = lastP; lastP += step; M += step; } while (lastP < N && ExtendFit(off + curP, M, data, (contains_forced) ? 0.05 * treshhold : treshhold, res, worstP) ); if (lastP >= N) { lastP -= step; M -= step; } else { // le dernier a echoue lastP -= step; M -= step; if ( contains_forced ) { lastP = forced_pt; M = lastP - curP + 1; } AttemptSimplify(off + curP, M, treshhold, res, worstP); // ca passe forcement } step /= 2; } endToPt = pts[off + lastP].p; if (M <= 2) { LineTo(endToPt); } else { CubicTo(endToPt, res.start, res.end); } curP = lastP; } if (Geom::LInfty(endToPt - moveToPt) < 0.00001) { Close(); } g_free(data.Xk); g_free(data.Yk); g_free(data.Qk); g_free(data.tk); g_free(data.lk); g_free(data.fk); }
/* ================ rvPropertyGrid::HandleDrawItem Handle the draw item message ================ */ int rvPropertyGrid::HandleDrawItem ( WPARAM wParam, LPARAM lParam ) { DRAWITEMSTRUCT* dis = (DRAWITEMSTRUCT*) lParam; rvPropertyGridItem* item = (rvPropertyGridItem*) dis->itemData; RECT rTemp; HBRUSH brush; if ( !item ) { return 0; } rTemp = dis->rcItem; if ( mStyle & PGS_HEADERS ) { brush = GetSysColorBrush ( COLOR_SCROLLBAR ); rTemp.right = rTemp.left + 10; FillRect ( dis->hDC, &rTemp, brush ); rTemp.left = rTemp.right; rTemp.right = dis->rcItem.right; } if ( item->mType == PGIT_HEADER ) { brush = GetSysColorBrush ( COLOR_SCROLLBAR ); } else if ( dis->itemState & ODS_SELECTED ) { brush = GetSysColorBrush ( COLOR_HIGHLIGHT ); } else { brush = GetSysColorBrush ( COLOR_WINDOW ); } FillRect ( dis->hDC, &rTemp, brush ); HPEN pen = CreatePen ( PS_SOLID, 1, GetSysColor ( COLOR_SCROLLBAR ) ); HPEN oldpen = (HPEN)SelectObject ( dis->hDC, pen ); MoveToEx ( dis->hDC, dis->rcItem.left, dis->rcItem.top, NULL ); LineTo ( dis->hDC, dis->rcItem.right, dis->rcItem.top ); MoveToEx ( dis->hDC, dis->rcItem.left, dis->rcItem.bottom, NULL ); LineTo ( dis->hDC, dis->rcItem.right, dis->rcItem.bottom); if ( item->mType != PGIT_HEADER ) { MoveToEx ( dis->hDC, dis->rcItem.left + mSplitter, dis->rcItem.top, NULL ); LineTo ( dis->hDC, dis->rcItem.left + mSplitter, dis->rcItem.bottom ); } SelectObject ( dis->hDC, oldpen ); DeleteObject ( pen ); int colorIndex = ( (dis->itemState & ODS_SELECTED ) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT ); SetTextColor ( dis->hDC, GetSysColor ( colorIndex ) ); SetBkMode ( dis->hDC, TRANSPARENT ); SetBkColor ( dis->hDC, GetSysColor ( COLOR_3DFACE ) ); RECT rText; rText = rTemp; rText.right = rText.left + mSplitter; rText.left += 2; DrawText ( dis->hDC, item->mName, item->mName.Length(), &rText, DT_LEFT|DT_VCENTER|DT_SINGLELINE ); rText.left = dis->rcItem.left + mSplitter + 2; rText.right = dis->rcItem.right; DrawText ( dis->hDC, item->mValue, item->mValue.Length(), &rText, DT_LEFT|DT_VCENTER|DT_SINGLELINE ); return 0; }
void EmfPaintEngine::drawPath ( const QPainterPath & path ) { setClipping(); int points = path.elementCount(); POINT *pts = new POINT[points]; BYTE *types = new BYTE[points]; POINT *bzs = new POINT[3]; int bez = 0; BeginPath(metaDC); QMatrix m = painter()->worldMatrix(); for (int i = 0; i < points; i++){ QPainterPath::Element el = path.elementAt(i); QPointF p = m.map(QPointF(el.x, el.y)); int x = qRound(p.x()); int y = qRound(p.y()); pts[i].x = x; pts[i].y = y; switch(el.type){ case QPainterPath::MoveToElement: types[i] = PT_MOVETO; #ifndef Q_WS_WIN MoveToEx (metaDC, x, y, 0); #endif break; case QPainterPath::LineToElement: types[i] = PT_LINETO; #ifndef Q_WS_WIN LineTo(metaDC, x, y); #endif break; case QPainterPath::CurveToElement: types[i] = PT_BEZIERTO; #ifndef Q_WS_WIN bzs[bez] = pts[i]; bez++; #endif break; case QPainterPath::CurveToDataElement: types[i] = PT_BEZIERTO; #ifndef Q_WS_WIN bzs[bez] = pts[i]; if (bez == 2){ PolyBezierTo(metaDC, bzs, 3); bez = 0; } else bez++; #endif break; } } HPEN wpen = convertPen(painter()->pen()); SelectObject(metaDC, wpen); #ifdef Q_WS_WIN PolyDraw(metaDC, pts, types, points); #else StrokePath(metaDC); #endif HBRUSH wbrush = convertBrush(painter()->brush()); SelectObject(metaDC, wbrush); EndPath(metaDC); if(QPoint(pts[0].x, pts[0].y) == QPoint(pts[points - 1].x, pts[points - 1].y)) StrokeAndFillPath(metaDC); else { FillPath(metaDC); #ifdef Q_WS_WIN PolyDraw(metaDC, pts, types, points); #else StrokePath(metaDC); #endif } resetClipping(); DeleteObject(wbrush); DeleteObject(wpen); delete [] pts; delete [] types; }
BOOL DrawSpectrum(HDC hdc, RECT rect) { static HBITMAP bitmap; static HDC hbdc; // Draw nice etched edge DrawEdge(hdc, &rect , EDGE_SUNKEN, BF_ADJUST | BF_RECT); // Calculate bitmap dimensions int width = rect.right - rect.left; int height = rect.bottom - rect.top; // Create DC if (hbdc == NULL) { hbdc = CreateCompatibleDC(hdc); bitmap = CreateCompatibleBitmap(hdc, width, height); SelectObject(hbdc, bitmap); SelectObject(hbdc, GetStockObject(DC_PEN)); } // Erase background RECT brct = {0, 0, width, height}; FillRect(hbdc, &brct, GetStockObject(BLACK_BRUSH)); // Dark green graticule SetDCPenColor(hbdc, RGB(0, 128, 0)); // Draw graticule for (int i = 4; i < width; i += 5) { MoveToEx(hbdc, i, 0, NULL); LineTo(hbdc, i, height); } for (int i = 4; i < height; i += 5) { MoveToEx(hbdc, 0, i, NULL); LineTo(hbdc, width, i); } // Don't attempt the trace until there's a buffer if (spectrum.data == NULL) { // Copy the bitmap BitBlt(hdc, rect.left, rect.top, width, height, hbdc, 0, 0, SRCCOPY); return TRUE; } // Move the origin SetViewportOrgEx(hbdc, 0, height - 1, NULL); // Yellow pen for frequency trace SetDCPenColor(hbdc, RGB(255, 255, 0)); float xscale = (float)log(spectrum.length) / width; int xf = round(log(spectrum.f) / xscale); MoveToEx(hbdc, xf, 0, NULL); LineTo(hbdc, xf, -height); // Green pen for spectrum trace SetDCPenColor(hbdc, RGB(0, 255, 0)); static float max; if (max < 1.0) max = 1.0; // Calculate the scaling float yscale = (float)height / max; max = 0.0; // Draw the spectrum MoveToEx(hbdc, 0, 0, NULL); // Create trace int last = 1; for (int x = 0; x < width; x++) { float value = 0.0; int index = (int)round(pow(M_E, x * xscale)); for (int i = last; i <= index; i++) { // Don't show DC component if (i > 0 && i < spectrum.length) { if (value < spectrum.data[i]) value = spectrum.data[i]; } } // Update last index last = index + 1; if (max < value) max = value; int y = -round(value * yscale); LineTo(hbdc, x, y); } // Move the origin back SetViewportOrgEx(hbdc, 0, 0, NULL); // Copy the bitmap BitBlt(hdc, rect.left, rect.top, width, height, hbdc, 0, 0, SRCCOPY); return TRUE; }