void CEquationEditorWindow::ZoomDFS( float coef, std::shared_ptr<IBaseExprModel> node ) { for( auto child : node->GetChildren() ) { ZoomDFS( coef, child ); } CRect rect = node->GetRect(); int heightNew = ( int ) rect.GetHeight() * coef; int widthNew = ( int ) rect.GetWidth() * coef; rect.Set( rect.Left(), rect.Top(), rect.Left() + widthNew, rect.Top() + heightNew ); node->SetRect( rect ); std::wstring text = node->GetText(); if( text.length() > 0 ) { std::shared_ptr<CEditControlModel> eNode = std::dynamic_pointer_cast<CEditControlModel>(node); std::vector<int> symbolsWidthsNew; for( int i = 0; i < text.length(); i++ ) { int symbolWidth = GetSymbolWidth( text[i], heightNew ); symbolsWidthsNew.push_back( symbolWidth ); } eNode->UpdateSymbolsWidths( symbolsWidthsNew ); } }
void Msg(UINT nMessage, WPARAM wParam, LPARAM lParam) { if (nMessage == WM_SIZE) { if (!m_Val) return; CString* str = (CString*)Ctl()->GetState(_T("text")); if (!str) return; CRect rect; Ctl()->GetClientRect(rect); FmtTxtRect(rect, m_Val, str, (IGuiCtl*)Ctl()); } else if (nMessage == WM_PAINT) { if (!m_Val) return; CString* str = (CString*)Ctl()->GetState(_T("text")); if (!str) return; CRect rect; Ctl()->GetClientRect(rect); if (!FmtTxtRect(rect, m_Val, str, (IGuiCtl*)Ctl())) return; CGraph* mem_img = (CGraph*)lParam; if (!mem_img || mem_img->IsNull()) return; CSize scr_sz; Ctl()->GetScrollSize(scr_sz); rect.Left(-scr_sz.cx); rect.Top(-scr_sz.cy); CImgDrawer::Draw(*mem_img, m_imgClp, rect); } }
void CSystemControlModel::PlaceChildren() { CRect newRect; int currentTop = rect.Top() + 5; for (int i = 0; i < children.size(); ++i) { CRect oldRect = children[i]->GetRect(); newRect.Top() = currentTop; currentTop += oldRect.GetHeight() + 5; newRect.Bottom() = newRect.Top() + oldRect.GetHeight(); newRect.Left() = rect.Left() + 15; newRect.Right() = newRect.Left() + oldRect.GetWidth(); children[i]->SetRect(newRect); } updatePolygons(); }
void CEquationEditorWindow::DrawHighlightedRect( const CRect& controlRect, bool isSelected ) { HBRUSH highlightedHBrush = ::CreateSolidBrush( /*isSelected ? bkSelectedHighlightColorref :*/ bkUnselectedHightlightColorref ); HBRUSH oldBrush = static_cast< HBRUSH >(::SelectObject( hdc, highlightedHBrush )); ::Rectangle( hdc, controlRect.Left(), controlRect.Bottom(), controlRect.Right(), controlRect.Top() ); ::SelectObject( hdc, oldBrush ); ::DeleteObject( highlightedHBrush ); }
void CFracControlModel::PlaceChildren() { CRect newRect; int middle = (rect.Right() + rect.Left()) / 2; CRect oldRect = firstChild->GetRect( ); newRect.Top() = rect.Top(); newRect.Bottom() = rect.Top() + oldRect.GetHeight(); newRect.Left() = middle - oldRect.GetWidth() / 2; newRect.Right() = middle + oldRect.GetWidth() / 2; firstChild->SetRect( newRect ); oldRect = secondChild->GetRect( ); newRect.Bottom() = rect.Bottom(); newRect.Top() = rect.Bottom() - oldRect.GetHeight(); newRect.Left() = middle - oldRect.GetWidth() / 2; newRect.Right() = middle + oldRect.GetWidth() / 2; secondChild->SetRect( newRect ); updatePolygons(); }
void CEquationEditorWindow::DrawSelectedRect( const CRect& selectedRect ) { RECT rect; rect.bottom = selectedRect.Bottom(); rect.top = selectedRect.Top(); rect.left = selectedRect.Left(); rect.right = selectedRect.Right(); HBRUSH selectedHBrush = ::CreateSolidBrush( bkSelectedColorref ); ::FillRect( hdc, &rect, selectedHBrush ); ::DeleteObject( selectedHBrush ); }
void CEquationEditorWindow::DrawString( const std::wstring& text, const CRect& textRect, bool isSelected ) { RECT rect; rect.bottom = textRect.Bottom(); rect.top = textRect.Top(); rect.left = textRect.Left(); rect.right = textRect.Right(); HFONT font = getFont( textRect.GetHeight() ); HGDIOBJ oldObject = ::SelectObject( hdc, font ); if( isSelected ) { ::SetTextColor( hdc, symbolSelectedColorref ); ::SetBkColor( hdc, bkSelectedColorref ); } else { ::SetTextColor( hdc, symbolUnselectedColorref ); ::SetBkColor( hdc, bkUnselectedColorref ); } ::DrawText( hdc, text.c_str(), text.size(), &rect, DT_LEFT ); ::SelectObject( hdc, oldObject ); }
void FontRendererImpl::DrawText(fwWString text, const CRect& rect, const CRGBA& color, float fontSize, float fontScale, fwString fontRef) { // wait for a swap to complete FrpSeqAllocatorWaitForSwap(); m_mutex.lock(); // create or find a text format ComPtr<IDWriteTextFormat> textFormat; auto formatKey = std::make_pair(fontRef, fontSize); auto formatIter = m_textFormatCache.find(formatKey); if (formatIter != m_textFormatCache.end()) { textFormat = formatIter->second; } else { wchar_t fontRefWide[128]; mbstowcs(fontRefWide, fontRef.c_str(), _countof(fontRefWide)); m_dwFactory->CreateTextFormat(fontRefWide, nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, fontSize, L"en-us", textFormat.GetAddressOf()); m_textFormatCache[formatKey] = textFormat; } // create or find a cached text layout ComPtr<IDWriteTextLayout> textLayout; auto layoutKey = std::make_pair(textFormat.Get(), std::make_pair(color.AsARGB(), text)); auto layoutIter = m_textLayoutCache.find(layoutKey); if (layoutIter != m_textLayoutCache.end()) { textLayout = layoutIter->second; } else { m_dwFactory->CreateTextLayout(text.c_str(), text.length(), textFormat.Get(), rect.Width(), rect.Height(), textLayout.GetAddressOf()); m_textLayoutCache[layoutKey] = textLayout; // set effect DWRITE_TEXT_RANGE effectRange = { 0, UINT32_MAX }; ComPtr<CitizenDrawingEffect> effect = Make<CitizenDrawingEffect>(); effect->SetColor(color); textLayout->SetDrawingEffect((IUnknown*)effect.Get(), effectRange); } // draw auto drawingContext = new CitizenDrawingContext(); textLayout->Draw(drawingContext, m_textRenderer.Get(), rect.Left(), rect.Top()); auto numRuns = drawingContext->glyphRuns.size(); if (numRuns) { for (auto& run : drawingContext->glyphRuns) { m_queuedGlyphRuns.push_back(run); } } delete drawingContext; m_mutex.unlock(); }