void StyleHelper::drawPixmapWithScreenScaleFactor(QPainter* p, const QRect& rcOrign, const QPixmap& pix) { if (pix.isNull()) return; #ifdef Q_OS_MAC float factor = qt_mac_get_scalefactor(0); QRect rcTarget(rcOrign); rcTarget.setWidth(rcTarget.width() * factor); rcTarget.setHeight(rcTarget.height() * factor); QTransform transRect; transRect.scale(factor, factor); QPoint leftTop = transRect.map(rcOrign.topLeft()); rcTarget.moveTopLeft(leftTop); // float rFactor = 1 / factor; QTransform transPainter; transPainter.scale(rFactor, rFactor); // p->save(); p->setWorldTransform(transPainter); p->drawPixmap(rcTarget, pix); p->restore(); #else p->drawPixmap(rcOrign, pix); #endif }
CRect CNCaptureView::_GetPhotoRect( CRect rcClient, LPSIZE lpSize) { CRect rcTarget( 0, 0, 0, 0 ); if (m_pCalcRect) { rcTarget = m_pCalcRect->GetPhotoRect(rcClient, lpSize, 1.0f, FALSE, FALSE); } //CPoint ptOriginalLogical(0,0); //CPoint ptOriginalDevice(0,0); //DocToClient(&ptOriginalLogical); //ClientToDoc(&ptOriginalDevice); //FTLTRACE(TEXT("rcClient=[%d,%d]x[%d,%d], lpSize={%d,%d}, rcTarget=[%d,%d]x[%d,%d],{%d,%d}, DocToClient(0,0)=[%d,%d], ClientToDoc(0,0)=[%d,%d]\n"), // rcClient.left, rcClient.top, rcClient.right, rcClient.bottom, lpSize->cx, lpSize->cy, // rcTarget.left, rcTarget.top, rcTarget.right, rcTarget.bottom, // rcTarget.Width(), rcTarget.Height(), // ptOriginalLogical.x, ptOriginalLogical.y, ptOriginalDevice.x, ptOriginalDevice.y); return rcTarget; }
/*virtual*/ void CWndSpecAnnotations::OnPaint() { // when the waveform cover whole range 0..255, the amplitude is 128, // we need only half of the amplitude range to show float fMax = Settings.Runtime.m_fCH1Res * 4.0f; char* strMax = CUtils::FormatVoltage(fMax, 5); CRect rcTarget( 40, 40, 300, 222 ); if ( MainWnd.m_wndSpectrumMiniFD.IsVisible() ) rcTarget = MainWnd.m_wndSpectrumMiniFD.m_rcClient; if ( MainWnd.m_wndSpectrumGraph.IsVisible() ) rcTarget = MainWnd.m_wndSpectrumGraph.m_rcClient; if ( MainWnd.m_wndSpectrumMiniSG.IsVisible() ) rcTarget = MainWnd.m_wndSpectrumMiniSG.m_rcClient; char* strUnits = NULL; int x = 2; if ( !MainWnd.m_wndSpectrumMiniSG.IsVisible() ) { strUnits = strstr( strMax, " " ); if ( strUnits ) { *strUnits = 0; strUnits++; } BIOS::LCD::Bar(x, rcTarget.top, rcTarget.left-1, rcTarget.top+16, RGB565(000000)); x += BIOS::LCD::Print(x, rcTarget.top, RGB565(b0b0b0), RGB565(000000), strMax); x += 4; x += BIOS::LCD::Print(x, rcTarget.top, RGB565(808080), RGB565(000000), strUnits); } float fTime = Settings.Runtime.m_fTimeRes; if ( fTime == 0 ) return; // calculate time corresponding to single sample fTime /= 30.0f; //CGraphWnd::BlkX // calculate sampling frequency; float fSample = 1.0f / fTime; // nyquist fSample *= 0.5f; char* strFreq = CUtils::FormatFrequency(fSample); BIOS::LCD::Bar(rcTarget.left, rcTarget.bottom+2, rcTarget.right, rcTarget.bottom+18, RGB565(000000)); x = rcTarget.right - strlen(strFreq)*8; strUnits = strstr( strFreq, " " ); if ( strUnits ) { *strUnits = 0; strUnits++; } BIOS::LCD::Print(x-5*8, rcTarget.bottom + 2, RGB565(808080), RGB565(000000), "SPAN "); x += BIOS::LCD::Print(x, rcTarget.bottom + 2, RGB565(b0b0b0), RGB565(000000), strFreq); BIOS::LCD::Print(x, rcTarget.bottom + 2, RGB565(b0b0b0), RGB565(000000), " "); x += 4; x += BIOS::LCD::Print(x, rcTarget.bottom + 2, RGB565(808080), RGB565(000000), strUnits); fSample *= 0.2f; // 1/5 for single div strFreq = CUtils::FormatFrequency(fSample); x = rcTarget.left; x += BIOS::LCD::Print(x, rcTarget.bottom + 2, RGB565(808080), RGB565(000000), strFreq); x += BIOS::LCD::Draw(x, rcTarget.bottom + 2, RGB565(808080), RGB565(000000), CShapes::per_div); }
HRESULT CCUILayoutHorizontal::Layout(IUIFrame* pHostFrame) { DEBUG_ASSERT(pHostFrame) ; IF_RETURN(NULL == pHostFrame, E_INVALIDARG) ; CSize szContainer(0, 0) ; pHostFrame->GetSize(&szContainer) ; CRect rcPadding(0, 0, 0, 0) ; pHostFrame->GetPadding(&rcPadding) ; CRect rcExtPadding(0, 0, 0, 0) ; CComQIPtr<IUIFrameInternal> pFrameInternal = pHostFrame ; if (pFrameInternal) { pFrameInternal->GetExtPadding(&rcExtPadding) ; } CRect rcContainer(0, 0, 0, 0) ; rcContainer.left = rcPadding.left + rcExtPadding.left ; rcContainer.top = rcPadding.top + rcExtPadding.top ; rcContainer.right = szContainer.cx - rcPadding.right - rcExtPadding.right ; rcContainer.bottom = szContainer.cy - rcPadding.bottom - rcExtPadding.bottom ; INT nCurrentLayout = 0, nUsedSpace = 0 ; if (LAYOUT::ORIENTATION_NEAR == this->m_nOrientation) { nCurrentLayout = rcPadding.left + rcExtPadding.left ; } else if (LAYOUT::ORIENTATION_FAR == this->m_nOrientation) { nCurrentLayout = szContainer.cx - rcPadding.right - rcExtPadding.right ; } LONG lChildrenCount = 0 ; pHostFrame->GetChildrenCount(&lChildrenCount) ; for (INT i = 0; i < lChildrenCount; ++i) { CComPtr<IUIElement> pElement ; pHostFrame->GetChildByIndex(i, &pElement) ; CComQIPtr<IUIFrame> pFrameChild = pElement ; CComQIPtr<IUIFrameInternal> pFrameInternal = pElement ; IF_CONTINUE(NULL == pFrameChild || NULL == pFrameInternal) ; BOOL bHidden = FALSE ; pFrameChild->GetHidden(&bHidden) ; IF_CONTINUE(bHidden) ; BOOL bFloat = FALSE ; pFrameChild->GetFloat(&bFloat) ; IF_CONTINUE(bFloat) ; CRect rcChildMargin(0, 0, 0, 0) ; pFrameChild->GetMargin(&rcChildMargin) ; BOOL bChildHeightAsParent = FALSE ; pFrameChild->GetHeightAsParent(&bChildHeightAsParent) ; if (bChildHeightAsParent) { CSize szEstimateSize(0, 0) ; szEstimateSize.cx = -1 ; szEstimateSize.cy = rcContainer.Height() - rcChildMargin.top - rcChildMargin.bottom ; pFrameInternal->SetEstimateSize(szEstimateSize) ; } BOOL bChildWidthAsParent = FALSE ; pFrameChild->GetWidthAsParent(&bChildWidthAsParent) ; if (i == this->m_nFillItem -1 || -1 * lChildrenCount + i == this->m_nFillItem) { INT nFillSize = this->CalcFillSize(pHostFrame, rcContainer, nUsedSpace, i) ; CSize szEstimateSize(0, 0) ; szEstimateSize.cx = nFillSize - rcChildMargin.left - rcChildMargin.right ; szEstimateSize.cy = -1 ; pFrameInternal->SetEstimateSize(szEstimateSize) ; } else if (bChildWidthAsParent) { pFrameInternal->SetEstimateSize(CSize(0, -1)) ; } CRect rcTarget(0, 0, 0, 0) ; CSize szChildChild(0, 0) ; pFrameChild->GetSize(&szChildChild) ; nUsedSpace += szChildChild.cx + rcChildMargin.left + rcChildMargin.right ; INT nDrift = DRIFT::DRIFT_NEAR ; pFrameChild->GetDrift(&nDrift) ; if (LAYOUT::ORIENTATION_NEAR == this->m_nOrientation) { if (DRIFT::DRIFT_NEAR == nDrift) { rcTarget.top = rcContainer.top + rcChildMargin.top ; } else if (DRIFT::DRIFT_FAR == nDrift) { rcTarget.top = rcContainer.bottom - rcChildMargin.bottom - szChildChild.cy ; } else if (DRIFT::DRIFT_MIDDLE == nDrift) { rcTarget.top = (rcContainer.Height() - szChildChild.cy)/2 + rcContainer.top ; } rcTarget.left = nCurrentLayout + rcChildMargin.left ; rcTarget.right = rcTarget.left + szChildChild.cx ; rcTarget.bottom = rcTarget.top + szChildChild.cy ; nCurrentLayout += szChildChild.cx + rcChildMargin.left + rcChildMargin.right ; } else if (LAYOUT::ORIENTATION_FAR == this->m_nOrientation) { if (DRIFT::DRIFT_NEAR == nDrift) { rcTarget.top = rcContainer.top + rcChildMargin.top ; } else if (DRIFT::DRIFT_FAR == nDrift) { rcTarget.top = rcContainer.bottom - rcChildMargin.bottom - szChildChild.cy ; } else if (DRIFT::DRIFT_MIDDLE == nDrift) { rcTarget.top = (rcContainer.Height() - szChildChild.cy)/2 + rcContainer.top ; } rcTarget.right = nCurrentLayout - rcChildMargin.right ; rcTarget.left = rcTarget.right - szChildChild.cx ; rcTarget.bottom = rcTarget.top + szChildChild.cy ; nCurrentLayout -= szChildChild.cx + rcChildMargin.left + rcChildMargin.right ; } pFrameInternal->SetLayoutRect(rcTarget) ; } return S_OK ; }
BOOL CXTextGdiPlus::RefreashBufferDC(HDC hDCSrc) { ReleaseBufferDC(); m_dcBuffer = ::CreateCompatibleDC(hDCSrc); m_hBufferOldBmp = ::SelectObject(m_dcBuffer, (HGDIOBJ)Util::CreateDIBSection32(m_rcDst.Width(), m_rcDst.Height())); Gdiplus::Graphics graph(m_dcBuffer); graph.SetTextRenderingHint(m_Rendering); Gdiplus::FontFamily fontFamily(XLibST2W(m_strFontName)); Gdiplus::Font font(&fontFamily, m_nSize, m_FontStyle, Gdiplus::UnitPixel); Gdiplus::StringFormat stringformat; stringformat.SetAlignment(m_AlignmentH); stringformat.SetLineAlignment(m_AlignmentV == Gdiplus::StringAlignmentCenter ? Gdiplus::StringAlignmentNear : m_AlignmentV); stringformat.SetFormatFlags(m_FormatFlags); stringformat.SetTrimming(Gdiplus::StringTrimmingEllipsisWord); Gdiplus::SolidBrush brush(Gdiplus::Color(m_cAlpha, m_ColorR, m_ColorG, m_ColorB)); Gdiplus::RectF rfTargetRect(0, 0, m_rcDst.Width(), m_rcDst.Height()); CStringW strTextToDraw(XLibST2W(m_strText)); // When centering texts vertically, gdi+ will put the texts a litter higher, // so we'll handle vertically centering ourselves. if (m_AlignmentV == Gdiplus::StringAlignmentCenter) { Gdiplus::RectF rfBoundRect(0, 0, 0, 0); graph.MeasureString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &rfBoundRect); UINT nBufferWidth = rfTargetRect.Width, nBufferHeight = ceil(rfBoundRect.Height); UINT32 *pBufferBmp = NULL; HDC dcBuffer = ::CreateCompatibleDC(m_dcBuffer); HGDIOBJ hOldBmp = ::SelectObject(dcBuffer, (HGDIOBJ)Util::CreateDIBSection32(nBufferWidth, nBufferHeight, (BYTE **)&pBufferBmp)); Gdiplus::Graphics graBuffer(dcBuffer); graBuffer.SetTextRenderingHint(m_Rendering); graBuffer.DrawString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &brush); CRect rcStrictBound(0, 0, nBufferWidth, nBufferHeight); BOOL bTopFound = FALSE, bBottomFound = FALSE; for (UINT line = 0; line < nBufferHeight; line++) { for (UINT col = 0; col < nBufferWidth; col++) { // bottom bits. if (!bBottomFound && *(pBufferBmp + line * nBufferWidth + col) != 0) { bBottomFound = TRUE; rcStrictBound.bottom -= line; } // top bits. if (!bTopFound && *(pBufferBmp + (nBufferHeight - line - 1) * nBufferWidth + col) != 0) { bTopFound = TRUE; rcStrictBound.top += line; } if (bBottomFound && bTopFound) break; } if (bBottomFound && bTopFound) break; } CRect rcTarget(0, (m_rcDst.Height() - rcStrictBound.Height()) / 2, 0, 0); rcTarget.right = rcTarget.left + rcStrictBound.Width(); rcTarget.bottom = rcTarget.top + rcStrictBound.Height(); Util::BitBlt(dcBuffer, rcStrictBound, m_dcBuffer, rcTarget); ::DeleteObject(::SelectObject(dcBuffer, hOldBmp)); ::DeleteDC(dcBuffer); } else graph.DrawString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &brush); return TRUE; }