HRESULT ui::UIScrollBar::Render(graphics::D3DInteropHelper *pD3DInteropHelper, ID2D1RenderTarget *pRenderTarget) { #ifdef DEBUG_UISCROLLBAR LOG_ENTER(SEVERITY_LEVEL_DEBUG) << L"propertyChanged = " << m_propertyChanged; #endif if (m_propertyChanged || IsPropertyChanged()) { CHK_FATAL_HRESULT(Initialize(pD3DInteropHelper)); CHK_FATAL_HRESULT(CreateDeviceDependentResources(pD3DInteropHelper, pRenderTarget)); m_propertyChanged = false; SetPropertyChanged(false); } if (m_barPositionChanged) { UpdateBarPosition(); m_barPositionChanged = false; } m_body->Render(pD3DInteropHelper, pRenderTarget, 1.0f); m_arrow1->Render(pD3DInteropHelper, pRenderTarget, 1.0f); m_arrow2->Render(pD3DInteropHelper, pRenderTarget, 1.0f); m_slideArea->Render(pD3DInteropHelper, pRenderTarget, 1.0f); m_bar->Render(pD3DInteropHelper, pRenderTarget, 1.0f); #ifdef DEBUG_UISCROLLBAR LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }
// メインテキストの初期化(テキストフォーマット、テキストレイアウト、テキストメトリックス) HRESULT ui::UIListBoxItem::__InitializeMainText(graphics::D3DInteropHelper *pD3DInteropHelper) { #ifdef DEBUG_UILISTBOXITEM LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif // text format m_mainTextFormat = nullptr; CHK_FATAL_HRESULT(pD3DInteropHelper->GetDWriteFactory()->CreateTextFormat( m_mainTextFontAttribute.fontFamilyName.c_str(), nullptr, m_mainTextFontAttribute.GetFontWeight(), m_mainTextFontAttribute.GetFontStyle(), m_mainTextFontAttribute.GetFontStretch(), m_mainTextFontAttribute.fontSize, L"", &m_mainTextFormat)); // text layout m_mainTextLayout = nullptr; CHK_FATAL_HRESULT(graphics::DirectWriteUtil::CreateTextLayoutWithTrimming( pD3DInteropHelper->GetDWriteFactory(), m_mainTextFormat, m_mainText.c_str(), m_preferredTextAreaSize.width, m_mainTextNumberOfLines, &m_mainTextLayout)); // metrics CHK_FATAL_HRESULT(m_mainTextLayout->GetMetrics(&m_mainTextMetrics)); #ifdef DEBUG_UILISTBOXITEM graphics::DirectWriteUtil::DumpMetrics(SEVERITY_LEVEL_DEBUG, L"m_mainTextLayout", m_mainTextLayout); #endif m_mainTextLayoutRect.width = m_textLayoutRect.width; m_mainTextLayoutRect.height = m_mainTextMetrics.height; #ifdef DEBUG_UILISTBOXITEM LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }
HRESULT graphics::brush::RadialGradientBrush::CreateDeviceDependentResource( ID2D1RenderTarget *pRenderTarget, const D2D1_RECT_F &rect, FLOAT opacity) { HRESULT hr = S_OK; CComPtr<ID2D1GradientStopCollection> gradientStopCollection; CHK_FATAL_HRESULT(pRenderTarget->CreateGradientStopCollection( &m_gradientStops.front(), static_cast<UINT>(m_gradientStops.size()), D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, &gradientStopCollection)); D2D1_POINT_2F center; D2D1_POINT_2F offset; FLOAT radiusX, radiusY; _CalculateParameters(rect, center, offset, radiusX, radiusY); m_brush = nullptr; CHK_FATAL_HRESULT( pRenderTarget->CreateRadialGradientBrush( D2D1::RadialGradientBrushProperties( D2D1::Point2F(0, 0), offset, radiusX, radiusY ), D2D1::BrushProperties(opacity, D2D1::Matrix3x2F::Translation(center.x, center.y)), gradientStopCollection, &m_brush )); m_deviceDependentResourceCreated = (m_brush != nullptr); return hr; }
HRESULT ui::UIListBox::CreateDeviceDependentResources(graphics::D3DInteropHelper *pD3DInteropHelper, ID2D1RenderTarget *pRenderTarget) { #ifdef DEBUG_UILISTBOX LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif CHK_FATAL_HRESULT(UIContainer::CreateDeviceDependentResources(pD3DInteropHelper, pRenderTarget)); CHK_FATAL_HRESULT(m_rectFigure->CreateDeviceDependentResources(pD3DInteropHelper, pRenderTarget)); CHK_FATAL_HRESULT(m_scrollBar->CreateDeviceDependentResources(pD3DInteropHelper, pRenderTarget)); #ifdef DEBUG_UILISTBOX LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }
HRESULT ui::UIListBoxItem::CreateDeviceDependentResources(graphics::D3DInteropHelper *pD3DInteropHelper, ID2D1RenderTarget *pRenderTarget) { #ifdef DEBUG_UILISTBOXITEM LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif CHK_FATAL_HRESULT(m_textBrushSet->CreateDeviceDependentResource(pRenderTarget, D2D1::RectF(), 1.0f)); CHK_FATAL_HRESULT(m_bodyRect->CreateDeviceDependentResources(pD3DInteropHelper, pRenderTarget)); #ifdef DEBUG_UILISTBOXITEM LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }
void graphics::DirectWriteUtil::GetLineMetrics(IN IDWriteTextLayout *pTextLayout, OUT std::vector<DWRITE_LINE_METRICS> &lineMetrics) { #ifdef DEBUG_DIRECTWRITEUTIL_ LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif DWRITE_TEXT_METRICS textMetrics; CHK_FATAL_HRESULT(pTextLayout->GetMetrics(&textMetrics)); lineMetrics.resize(textMetrics.lineCount); CHK_FATAL_HRESULT(pTextLayout->GetLineMetrics(lineMetrics.data(), textMetrics.lineCount, &textMetrics.lineCount)); #ifdef DEBUG_DIRECTWRITEUTIL_ LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif }
HRESULT ui::UIListBoxItem::__RecreateSubTextLayout(graphics::D3DInteropHelper *pD3DInteropHelper, ID2D1RenderTarget *pRenderTarget, const std::wstring &text, CComPtr<IDWriteTextLayout> &textLayout, DWRITE_TEXT_METRICS &textMetrics, UIRectangle &textRect) { #ifdef DEBUG_UILISTBOXITEM LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif UNREFERENCED_PARAMETER(pRenderTarget); CComPtr<IDWriteTextLayout> oldTextLayout = textLayout; textLayout = nullptr; CHK_FATAL_HRESULT(pD3DInteropHelper->GetDWriteFactory()->CreateTextLayout( text.c_str(), static_cast<UINT32>(text.length()), oldTextLayout, textRect.width, textRect.height, &textLayout)); CHK_FATAL_HRESULT(textLayout->GetMetrics(&textMetrics)); #ifdef DEBUG_UILISTBOXITEM LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }
void graphics::DirectWriteUtil::GetClusterMetrics(IN IDWriteTextLayout *pTextLayout, OUT std::vector<DWRITE_CLUSTER_METRICS> &clusterMetrics) { #ifdef DEBUG_DIRECTWRITEUTIL_ LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif UINT32 actualClusterCount = 0; HRESULT hr = pTextLayout->GetClusterMetrics(nullptr, 0, &actualClusterCount); if (hr != E_NOT_SUFFICIENT_BUFFER) { CHK_FATAL_HRESULT(hr); } clusterMetrics.resize(actualClusterCount); CHK_FATAL_HRESULT(pTextLayout->GetClusterMetrics(clusterMetrics.data(), actualClusterCount, &actualClusterCount)); #ifdef DEBUG_DIRECTWRITEUTIL_ LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif }
HRESULT ui::UIListBoxItem::__RecreateMainTextLayout(graphics::D3DInteropHelper *pD3DInteropHelper, ID2D1RenderTarget *pRenderTarget, const std::wstring &text, CComPtr<IDWriteTextLayout> &textLayout, DWRITE_TEXT_METRICS &textMetrics, UIRectangle &textRect, size_t numberOfLines) { #ifdef DEBUG_UILISTBOXITEM LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif UNREFERENCED_PARAMETER(pRenderTarget); CComPtr<IDWriteTextLayout> oldTextLayout = textLayout; textLayout = nullptr; CHK_FATAL_HRESULT(graphics::DirectWriteUtil::CreateTextLayoutWithTrimming( pD3DInteropHelper->GetDWriteFactory(), oldTextLayout, text.c_str(), textRect.width, numberOfLines, &textLayout)); CHK_FATAL_HRESULT(textLayout->GetMetrics(&textMetrics)); #ifdef DEBUG_UILISTBOXITEM LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }
// サブテキストの初期化(テキストフォーマット、テキストレイアウト、テキストメトリックス) HRESULT ui::UIListBoxItem::__InitializeSubText(graphics::D3DInteropHelper *pD3DInteropHelper, const std::wstring &text, const graphics::FontAttribute &fontAttribute, CComPtr<IDWriteTextFormat> &textFormat, CComPtr<IDWriteTextLayout> &textLayout, DWRITE_TEXT_METRICS &textMetrics, UIRectangle &textRect) { #ifdef DEBUG_UILISTBOXITEM LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif // text format textFormat = nullptr; CHK_FATAL_HRESULT(pD3DInteropHelper->GetDWriteFactory()->CreateTextFormat( fontAttribute.fontFamilyName.c_str(), nullptr, fontAttribute.GetFontWeight(), fontAttribute.GetFontStyle(), fontAttribute.GetFontStretch(), fontAttribute.fontSize, L"", &textFormat)); textRect.width = m_textLayoutRect.width; // text layout textLayout = nullptr; CHK_FATAL_HRESULT(pD3DInteropHelper->GetDWriteFactory()->CreateTextLayout( text.c_str(), static_cast<UINT>(text.size()), textFormat, m_preferredTextAreaSize.width, std::numeric_limits<FLOAT>::max(), &textLayout)); // trimming sign CComPtr<IDWriteInlineObject> inlineObject; CHK_FATAL_HRESULT(pD3DInteropHelper->GetDWriteFactory()->CreateEllipsisTrimmingSign(textLayout, &inlineObject)); DWRITE_TRIMMING trimming = {DWRITE_TRIMMING_GRANULARITY_CHARACTER, 0, 0}; textLayout->SetTrimming(&trimming, inlineObject); textLayout->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); // text metrics CHK_FATAL_HRESULT(textLayout->GetMetrics(&textMetrics)); #ifdef DEBUG_UILISTBOXITEM graphics::DirectWriteUtil::DumpMetrics(SEVERITY_LEVEL_DEBUG, L"m_subTextLayout", textLayout); LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }
void graphics::DirectWriteUtil::DumpMetrics(IN SEVERITY_LEVEL severityLevel, IN const std::wstring &layoutName, IN IDWriteTextLayout *pTextLayout) { #ifdef DEBUG_DIRECTWRITEUTIL_ LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif LOG(severityLevel) << layoutName << L"->GetMaxWidth() = " << pTextLayout->GetMaxWidth(); LOG(severityLevel) << layoutName << L"->GetMaxHeight() = " << pTextLayout->GetMaxHeight(); FLOAT minWidth = 0.0f; CHK_FATAL_HRESULT(pTextLayout->DetermineMinWidth(&minWidth)); LOG(severityLevel) << layoutName << L"->DetermineMinWidth() = " << minWidth; DWRITE_TEXT_METRICS textMetrics; CHK_FATAL_HRESULT(pTextLayout->GetMetrics(&textMetrics)); LOG(severityLevel) << layoutName << L"->GetMetrics() = " << textMetrics; DWRITE_OVERHANG_METRICS overhangMetrics; CHK_FATAL_HRESULT(pTextLayout->GetOverhangMetrics(&overhangMetrics)); LOG(severityLevel) << layoutName << L"->GetOverhangMetrics() = " << overhangMetrics; std::vector<DWRITE_LINE_METRICS> lineMetrics; graphics::DirectWriteUtil::GetLineMetrics(pTextLayout, lineMetrics); for (size_t i = 0; i < lineMetrics.size(); ++i) { LOG(severityLevel) << L"line[" << i << L"] " << lineMetrics.at(i); } std::vector<DWRITE_CLUSTER_METRICS> clusterMetrics; graphics::DirectWriteUtil::GetClusterMetrics(pTextLayout, clusterMetrics); for (size_t i = 0; i < clusterMetrics.size(); ++i) { LOG(severityLevel) << L"cluster[" << i << L"] " << clusterMetrics.at(i); } #ifdef DEBUG_DIRECTWRITEUTIL_ LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif }
HRESULT graphics::brush::BrushSet::CreateDeviceDependentResource( ID2D1RenderTarget *pRenderTarget, const D2D1_RECT_F &rect, FLOAT opacity ) { #ifdef DEBUG_BRUSHSET LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif HRESULT hr = S_OK; for (size_t i = 0; i < m_brushes.size(); ++i) { CHK_FATAL_HRESULT(m_brushes[i]->CreateDeviceDependentResource(pRenderTarget, rect, opacity)); #ifdef DEBUG_BRUSHSET LOG(SEVERITY_LEVEL_DEBUG) << L"raw brush[" << i << L"] = " << std::hex << m_brushes[i]->GetBrush() << std::dec; #endif } m_deviceDependentResourceCreated = SUCCEEDED(hr); #ifdef DEBUG_BRUSHSET LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return hr; }
HRESULT ui::UIListBox::Initialize(graphics::D3DInteropHelper *pD3DInteropHelper) { #ifdef DEBUG_UILISTBOX LOG_ENTER(SEVERITY_LEVEL_DEBUG); #endif assert(GetWidth() > 0.0f); assert(GetHeight() > 0.0f); ui::UIListBoxItem::LAYOUT_DIRECTION layoutDirection = ui::UIListBoxItem::LAYOUT_DIRECTION_VERTICAL; switch (m_scrollDirection) { case ui::UIListBox::SCROLL_DIRECTION_HORIZONTAL: layoutDirection = ui::UIListBoxItem::LAYOUT_DIRECTION_VERTICAL; m_itemHeight = GetHeight(); if (m_preferredTextAreaSize.height == 0.0f) { m_preferredTextAreaSize.height = GetHeight() - m_preferredBitmapSize.height - m_marginBetweenBitmapAndText; } if (m_preferredTextAreaSize.width == 0.0f) { m_preferredTextAreaSize.width = m_preferredBitmapSize.width * 3.0f; } m_itemWidth = m_preferredTextAreaSize.width; break; case ui::UIListBox::SCROLL_DIRECTION_VERTICAL: layoutDirection = ui::UIListBoxItem::LAYOUT_DIRECTION_HORIZONTAL; m_itemWidth = GetWidth(); if (m_preferredTextAreaSize.width == 0.0f) { m_preferredTextAreaSize.width = GetWidth() - m_preferredBitmapSize.width - m_marginBetweenBitmapAndText; } if (m_preferredTextAreaSize.height == 0.0f) { m_preferredTextAreaSize.height = m_preferredBitmapSize.height; } m_itemHeight = m_preferredTextAreaSize.height; break; } for (size_t i = 0; i < GetNumberOfElements(); ++i) { auto element = GetElement(i); auto listBoxItem = std::dynamic_pointer_cast<UIListBoxItem>(element); if (listBoxItem.get() != nullptr) { listBoxItem->SetLayoutDirection(layoutDirection); listBoxItem->SetPreferredBitmapSize(m_preferredBitmapSize); listBoxItem->SetPreferredTextAreaSize(m_preferredTextAreaSize); listBoxItem->SetBounds(0.0f, 0.0f, m_itemWidth, m_itemHeight); } } CHK_WARN_HRESULT(UIContainer::Initialize(pD3DInteropHelper)); auto frameDecorator = std::make_shared<graphics::decorator::FrameDecorator>(); frameDecorator->SetColorSet(m_colorSet); for (size_t i = 0; i < m_colorSet->GetNumberOfColors(); ++i) { frameDecorator->AddFrame(graphics::decorator::Frame(i)); } m_rectFigure->AddDecorator(frameDecorator); m_rectFigure->SetX(0.0f); m_rectFigure->SetY(0.0f); m_rectFigure->SetWidth(GetWidth()); m_rectFigure->SetHeight(GetHeight()); m_rectFigure->SetColor(graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_RGBA, 0x222222, 1.0f), graphics::color::COLOR_PATTERN_FLAT); CHK_WARN_HRESULT(m_rectFigure->Initialize(pD3DInteropHelper)); m_scrollBar->SetParentContainer(shared_from_this()); m_scrollBar->SetMinValue(0.0f); m_scrollBar->SetMaxValue(GetNumberOfElements() - 1.0f); m_scrollBar->SetPageSize(1.0f); if (m_scrollBar->GetCurrentValue() < m_scrollBar->GetMinValue() || m_scrollBar->GetCurrentValue() > m_scrollBar->GetMaxValue() - m_scrollBar->GetPageSize()) { m_scrollBar->SetCurrentValue(0.0f); } FLOAT frameThick = static_cast<FLOAT>(m_colorSet->GetNumberOfColors()); if (m_scrollDirection == ui::UIListBox::SCROLL_DIRECTION_HORIZONTAL) { m_scrollBar->SetDirection(ui::UIScrollBar::SCROLLBAR_DIRECTION_HORIZONTAL); m_scrollBar->SetBounds(frameThick + m_scrollBarMarginFromSide, GetHeight() - m_scrollBarThick - frameThick - m_scrollBarMarginFromSide, GetWidth() - (frameThick + m_scrollBarMarginFromSide) * 2, m_scrollBarThick); } else { m_scrollBar->SetDirection(ui::UIScrollBar::SCROLLBAR_DIRECTION_VERTICAL); m_scrollBar->SetBounds(GetWidth() - m_scrollBarThick - frameThick - m_scrollBarMarginFromSide, frameThick + m_scrollBarMarginFromSide, m_scrollBarThick, GetHeight() - (frameThick + m_scrollBarMarginFromSide) * 2); } m_scrollBar->AddPositionChangedCallback([&](FLOAT position) { NotifyScrollPositionChanged(position); }); CHK_FATAL_HRESULT(m_scrollBar->Initialize(pD3DInteropHelper)); #ifdef DEBUG_UILISTBOX LOG_LEAVE(SEVERITY_LEVEL_DEBUG); #endif return S_OK; }