//******************************************************************************* void CBCGPKnob::OnDrawTickMarkTextLabel(CBCGPGraphicsManager* pGM, const CBCGPTextFormat& tf, const CBCGPRect& rectText, const CString& strLabel, double dblVal, int nScale, const CBCGPBrush& br) { if (m_sizeIcon.cx == 0) { CBCGPCircularGaugeImpl::OnDrawTickMarkTextLabel(pGM, tf, rectText, strLabel, dblVal, nScale, br); return; } if (m_sizeIcon.cy == 0) { m_sizeIcon.cy = pGM->GetImageSize(m_Icons).cy; } CBCGPSize sizeIcon(m_sizeIcon.cx * m_sizeScaleRatio.cx, m_sizeIcon.cy * m_sizeScaleRatio.cy); double cx = 0.; double cy = 0.; double angle = 0.; if (ValueToAngle(dblVal, angle, nScale)) { cx = sizeIcon.cx * cos(bcg_deg2rad(angle)) / 2; } CBCGPPoint ptImage( rectText.left + max(0., .5 * (rectText.Width() - sizeIcon.cx)) + cx, rectText.top + max(0., .5 * (rectText.Height() - sizeIcon.cy)) + cy); pGM->DrawImage(m_Icons, ptImage, sizeIcon, 1., CBCGPImage::BCGP_IMAGE_INTERPOLATION_MODE_LINEAR, CBCGPRect(CBCGPPoint(m_sizeIcon.cx * m_nCurrLabelIndex, 0), m_sizeIcon)); }
RotationDlg::RotationDlg(QWidget *parent, int an) : Dialog(parent) , ui(new Ui::RotationDlg) , angle(an) { ui->setupUi(this); QSize size( getSizePx( QSize(100, 100), 5 ) ); // 100 = 1 inch int max = qMax( size.width(), size.height() ); QSize sizeIcon(max, max); ui->btnRot0->setIconSize( sizeIcon ); ui->btnRot90->setIconSize( sizeIcon ); ui->btnRot180->setIconSize( sizeIcon ); ui->btnRot270->setIconSize( sizeIcon ); setAttribute(Qt::WA_TranslucentBackground); setWindowFlags( windowFlags() | Qt::FramelessWindowHint ); switch( angle ) { case 0: default: ui->btnRot0->setFocus(); break; case 1: ui->btnRot90->setFocus(); break; case 2: ui->btnRot180->setFocus(); break; case 3: ui->btnRot270->setFocus(); break; } init(); }
//*************************************************************************************** void CBCGPRadialMenuObject::OnDraw(CBCGPGraphicsManager* pGM, const CBCGPRect& /*rectClip*/, DWORD dwFlags) { if (dwFlags == BCGP_DRAW_STATIC) { return; } m_nShadowDepth = pGM->IsSupported(BCGP_GRAPHICS_MANAGER_COLOR_OPACITY) ? GetShadowDepth() : 0; CBCGPRect rect = m_rect; if (rect.Width() < rect.Height()) { rect.top += (rect.Height() - rect.Width()) / 2; rect.bottom = rect.top + rect.Width(); } else if (rect.Height() < rect.Width()) { rect.left += (rect.Width() - rect.Height()) / 2; rect.right = rect.left + rect.Height(); } rect.DeflateRect(2., 2.); rect.right -= m_nShadowDepth; rect.bottom -= m_nShadowDepth; const double radius = rect.Width() / 2; const double radiusSmall = INTERNAL_PART * rect.Width() + 1.0; const CBCGPPoint center = rect.CenterPoint(); CBCGPSize sizeIcon((double)m_cxIcon, 16); if (!m_Icons.IsNull()) { sizeIcon.cy = pGM->GetImageSize(m_Icons).cy; } const int nItems = (int)m_arItems.GetSize(); if (IsDirty()) { int nCircleItems = m_bHasCenterButton ? nItems - 1 : nItems; double dblDeltaAngle = nCircleItems == 0 ? 0. : 360. / nCircleItems; double dblStartAngle = 90. - dblDeltaAngle / 2; for (int i = 0; i < nItems; i++) { CBCGPRadialMenuItem* pItem = m_arItems[i]; ASSERT_VALID(pItem); pItem->m_bIsCenter = i == nItems -1 && m_bHasCenterButton; pItem->m_Shape.Destroy(); pItem->m_Shape.Clear(); if (!pItem->m_bIsCenter) { double dblFinishAngle = dblStartAngle + dblDeltaAngle; const double dblStartAngleRad = bcg_deg2rad(dblStartAngle); const double dblFinishAngleRad = bcg_deg2rad(dblFinishAngle); const double dblMiddleAngleRad = bcg_deg2rad(dblStartAngle + dblDeltaAngle / 2); double angleStartCos = cos(dblStartAngleRad); double angleStartSin = sin(dblStartAngleRad); double angleFinishCos = cos(dblFinishAngleRad); double angleFinishSin = sin(dblFinishAngleRad); pItem->m_Shape.SetStart( CBCGPPoint(center.x + angleStartCos * radius, center.y - angleStartSin * radius)); pItem->m_Shape.AddArc( CBCGPPoint(center.x + angleFinishCos * radius, center.y - angleFinishSin * radius), CBCGPSize(radius, radius), dblStartAngle > dblFinishAngle, FALSE); pItem->m_Shape.AddLine( CBCGPPoint(center.x + angleFinishCos * radiusSmall, center.y - angleFinishSin * radiusSmall)); pItem->m_Shape.AddArc( CBCGPPoint(center.x + angleStartCos * radiusSmall, center.y - angleStartSin * radiusSmall), CBCGPSize(radiusSmall, radiusSmall), dblStartAngle < dblFinishAngle, FALSE); pItem->m_ptCenter = CBCGPPoint( center.x + cos(dblMiddleAngleRad) * 2 * radius / 3, center.y - sin(dblMiddleAngleRad) * 2 * radius / 3); dblStartAngle = dblFinishAngle; } else { pItem->m_Shape.SetStart(center); pItem->m_Shape.AddLine(center); pGM->CombineGeometry(pItem->m_Shape, pItem->m_Shape, CBCGPEllipseGeometry(CBCGPEllipse(center, radiusSmall, radiusSmall)), RGN_OR); pItem->m_ptCenter = center; } } } CBCGPEllipse ellipseInt(center, radiusSmall, radiusSmall); CBCGPRect rectShadow = rect; rectShadow.OffsetRect(m_nShadowDepth, m_nShadowDepth); if (!m_bHasCenterButton && m_pCtrl->GetSafeHwnd() != NULL && (m_pCtrl->GetExStyle() & WS_EX_LAYERED)) { if (m_nShadowDepth > 0) { CBCGPEllipseGeometry egShadow(rectShadow); CBCGPPoint centerShadow = center; centerShadow.x += m_nShadowDepth; centerShadow.y += m_nShadowDepth; CBCGPEllipse ellipseIntShadow(centerShadow, radiusSmall, radiusSmall); CBCGPEllipseGeometry egInternalShadow(ellipseIntShadow); CBCGPComplexGeometry shapeShadow; pGM->CombineGeometry(shapeShadow, egShadow, egInternalShadow, RGN_DIFF); pGM->FillGeometry(shapeShadow, m_brShadow); } CBCGPEllipseGeometry eg(rect); CBCGPEllipseGeometry egInternal(ellipseInt); CBCGPComplexGeometry shape; pGM->CombineGeometry(shape, eg, egInternal, RGN_DIFF); pGM->FillGeometry(shape, m_brFill); } else { if (m_nShadowDepth > 0) { pGM->FillEllipse(rectShadow, m_brShadow); } pGM->FillEllipse(rect, m_brFill); } pGM->DrawEllipse(rect, m_brBorder); if (!pGM->IsSupported(BCGP_GRAPHICS_MANAGER_COLOR_OPACITY)) { CBCGPRect rect1 = rect; rect1.DeflateRect(1, 1); pGM->DrawEllipse(rect1, m_brFill); } BOOL bIsCtrlDisabled = m_pCtrl->GetSafeHwnd() != NULL && !m_pCtrl->IsWindowEnabled(); for (int i = 0; i < nItems; i++) { CBCGPRadialMenuItem* pItem = m_arItems[i]; ASSERT_VALID(pItem); if (i == m_nHighlighted) { pGM->FillGeometry(pItem->m_Shape, m_nHighlighted == m_nPressed ? m_brPressed : m_brHighlighted.IsEmpty() ? m_brFill : m_brHighlighted); } pItem->OnDrawIcon(pGM, bIsCtrlDisabled, m_Icons, sizeIcon); pGM->DrawGeometry(pItem->m_Shape, m_brBorder); } pGM->DrawEllipse(ellipseInt, m_brBorder); if (!pGM->IsSupported(BCGP_GRAPHICS_MANAGER_ANTIALIAS)) { rect.InflateRect(1, 1); pGM->DrawEllipse(rect, m_brBorder); } if (m_pCtrl->GetSafeHwnd() != NULL && m_pCtrl->IsFocused() && !m_pCtrl->IsPopup()) { rect.InflateRect(1, 1); pGM->DrawEllipse(rect, m_brFocusedBorder); } }
void CButtonDialog::PositionControls() { CSize sizeBase = GetBaseUnits(); int nButtonHeight = (sizeBase.cy*14)/8; int nHeight = 0; int nSep,nLeftMargin,nRightMargin,nTopMargin,nBottomMargin; int nButtonAdj; int nWidth = 0; CRect rectText; // a) 5/8 screen Width // b) Caption // c) nLeftMargin ICON nSep TEXT nRightMargin // d) nLeftMargin Button1 nSep Button2 ... nRightMargin // client width is max(b,d, min(c,a)) CSize sizeIcon(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); nSep = sizeIcon.cx/2; nLeftMargin = nSep; nRightMargin = nSep; nTopMargin = nSep; nBottomMargin = nSep; CClientDC dc(this); CFont* pOldFont = dc.SelectObject(&m_font); nButtonAdj = dc.GetTextExtent(_T("XXX"),3).cx; // padding on buttons int nScreenWidth58 = dc.GetDeviceCaps(HORZRES)*5/8; int nCaptionWidth = dc.GetTextExtent(m_strCaption, m_strCaption. GetLength()).cx; CSize sizeText = dc.GetTextExtent(m_strText,m_strText.GetLength()); int nTextIconWidth = nLeftMargin+sizeIcon.cx+nSep+sizeText.cx+nRightMargin; int nButtons = (int)m_strArray.GetSize(); int nButtonsWidth = nLeftMargin+nRightMargin+(nButtons-1)*nSep; int i = 0; for (i=0;i<nButtons;i++) { nButtonsWidth += dc.GetTextExtent(m_strArray[i],m_strArray[i].GetLength()).cx+ nButtonAdj*2; } nWidth = min(nTextIconWidth,nScreenWidth58); nWidth = max(nWidth, nCaptionWidth); nWidth = max(nWidth, nButtonsWidth); m_staticIcon.SetWindowPos(NULL, nLeftMargin, nTopMargin, sizeIcon.cx, sizeIcon.cy, SWP_NOZORDER); if (sizeText.cx > nWidth-nLeftMargin-nRightMargin-sizeIcon.cx-nSep) { sizeText.cx = nWidth-nLeftMargin-nRightMargin-sizeIcon.cx-nSep; // int nTextWidth = nWidth-nLeftMargin-nRightMargin-sizeIcon.cx-nSep; // rectText.SetRect(0, 0, nTextWidth, 32767); rectText.SetRect(0, 0, sizeText.cx, 32767); /* Ask DrawText for the right cy */ sizeText.cy = dc.DrawText(m_strText, m_strText.GetLength(), &rectText, DT_CALCRECT | DT_WORDBREAK | DT_EXPANDTABS | DT_NOPREFIX); } m_staticText.SetWindowPos(NULL, nSep+sizeIcon.cx+nSep, nTopMargin, sizeText.cx, sizeText.cy, SWP_NOZORDER); sizeText.cy = max(sizeText.cy, sizeIcon.cy); // at least icon height nHeight = nTopMargin + sizeText.cy + nSep + nButtonHeight + nBottomMargin; CRect rect; rect.left = (nWidth - (nButtonsWidth - nLeftMargin - nRightMargin))/2; rect.top = nTopMargin + sizeText.cy + nSep; rect.bottom = rect.top + nButtonHeight; for (i=0;i<m_strArray.GetSize();i++) { rect.right = rect.left + dc.GetTextExtent(m_strArray[i],m_strArray[i].GetLength()).cx + 2*nButtonAdj; m_pButtons[i].MoveWindow(&rect); rect.left = rect.right + nSep; } rect.SetRect(0,0,nWidth,nHeight); CalcWindowRect(&rect); SetWindowPos(NULL, (dc.GetDeviceCaps(HORZRES)-rect.Width())/2, (dc.GetDeviceCaps(VERTRES)-rect.Height())/2, rect.Width(), rect.Height(), SWP_NOZORDER|SWP_NOACTIVATE); if(m_nCancel == -1) // no cancel button { // CMenu* pMenu = GetSystemMenu(FALSE); // if (pMenu != NULL) // pMenu->DeleteMenu(SC_CLOSE, MF_BYCOMMAND); } dc.SelectObject(pOldFont); }