Ejemplo n.º 1
0
HRESULT ui::UIListBoxItem::__RecreateAllTextLayout(graphics::D3DInteropHelper *pD3DInteropHelper,
                                                   ID2D1RenderTarget *pRenderTarget) {
#ifdef DEBUG_UILISTBOXITEM
  LOG_ENTER(SEVERITY_LEVEL_DEBUG);
#endif
  CHK_WARN_HRESULT(__RecreateMainTextLayout(pD3DInteropHelper, pRenderTarget, m_mainText, m_mainTextLayout,
                                            m_mainTextMetrics, m_mainTextLayoutRect, m_mainTextNumberOfLines));
  CHK_WARN_HRESULT(__RecreateSubTextLayout(pD3DInteropHelper, pRenderTarget, m_subText1, m_subText1Layout,
                                           m_subText1Metrics, m_subText1LayoutRect));
  CHK_WARN_HRESULT(__RecreateSubTextLayout(pD3DInteropHelper, pRenderTarget, m_subText2, m_subText2Layout,
                                           m_subText2Metrics, m_subText2LayoutRect));
#ifdef DEBUG_UILISTBOXITEM
  LOG_LEAVE(SEVERITY_LEVEL_DEBUG);
#endif
  return S_OK;
}
Ejemplo n.º 2
0
HRESULT ui::UIListBox::Render(graphics::D3DInteropHelper *pD3DInteropHelper, ID2D1RenderTarget *pRenderTarget) {
#ifdef DEBUG_UILISTBOX
  LOG_ENTER(SEVERITY_LEVEL_DEBUG);
#endif
  m_rectFigure->Render(pD3DInteropHelper, pRenderTarget, 1.0f);

  FLOAT frameThick = static_cast<FLOAT>(m_colorSet->GetNumberOfColors());
  D2D1_RECT_F clipRect = D2D1::RectF(frameThick, frameThick, GetWidth() - frameThick, GetHeight() - frameThick);
  pRenderTarget->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);

  if (m_scrollDirection == SCROLL_DIRECTION_HORIZONTAL) {
    pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(-m_displayPositionOffset, 0.0f));

    FLOAT x = 0.0f;
    FLOAT y = m_marginBetweenItems;

    for (size_t i = 0; i < GetNumberOfElements(); ++i) {
      auto element = GetElement(i);
      auto listBoxItem = std::dynamic_pointer_cast<UIListBoxItem>(element);
      if (listBoxItem.get() != nullptr) {
        x += m_marginBetweenItems;
        pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(x, y));
        listBoxItem->Render(pD3DInteropHelper, pRenderTarget);
        x += listBoxItem->GetWidth();
        pD3DInteropHelper->PopMatrix(pRenderTarget);
      }
    }
    pD3DInteropHelper->PopMatrix(pRenderTarget);
  } else {
    pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(0.0f, -m_displayPositionOffset));

    FLOAT x = m_marginBetweenItems;
    FLOAT y = 0.0f;

    for (size_t i = 0; i < GetNumberOfElements(); ++i) {
      auto element = GetElement(i);
      auto listBoxItem = std::dynamic_pointer_cast<UIListBoxItem>(element);
      if (listBoxItem.get() != nullptr) {
        y += m_marginBetweenItems;
        pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(x, y));
        listBoxItem->Render(pD3DInteropHelper, pRenderTarget);
        y += listBoxItem->GetHeight();
        pD3DInteropHelper->PopMatrix(pRenderTarget);
      }
    }
    pD3DInteropHelper->PopMatrix(pRenderTarget);
  }

  pRenderTarget->PopAxisAlignedClip();

  pD3DInteropHelper->PushMatrix(pRenderTarget, D2D1::Matrix3x2F::Translation(m_scrollBar->GetX(), m_scrollBar->GetY()));
  CHK_WARN_HRESULT(m_scrollBar->Render(pD3DInteropHelper, pRenderTarget));
  pD3DInteropHelper->PopMatrix(pRenderTarget);

#ifdef DEBUG_UILISTBOX
  LOG_LEAVE(SEVERITY_LEVEL_DEBUG);
#endif
  return S_OK;
}
Ejemplo n.º 3
0
// 初期化
HRESULT ui::UIListBoxItem::Initialize(graphics::D3DInteropHelper *pD3DInteropHelper) {
#ifdef DEBUG_UILISTBOXITEM
  LOG_ENTER(SEVERITY_LEVEL_DEBUG);
#endif
  // ブラシセットの初期化
  m_textBrushSet->SetColorSet(m_textColorSet);
  // メインテキストの初期化
  CHK_WARN_HRESULT(__InitializeMainText(pD3DInteropHelper));
  // サブテキスト1の初期化
  CHK_WARN_HRESULT(__InitializeSubText(pD3DInteropHelper, m_subText1, m_subText1FontAttribute, m_subText1Format,
                                       m_subText1Layout, m_subText1Metrics, m_subText1LayoutRect));
  // サブテキスト2の初期化
  CHK_WARN_HRESULT(__InitializeSubText(pD3DInteropHelper, m_subText2, m_subText2FontAttribute, m_subText2Format,
                                       m_subText2Layout, m_subText2Metrics, m_subText2LayoutRect));
#ifdef DEBUG_UILISTBOXITEM
  LOG(SEVERITY_LEVEL_DEBUG) << L"m_mainTextLayout->GetMaxWidth() = " << m_mainTextLayout->GetMaxWidth();
  LOG(SEVERITY_LEVEL_DEBUG) << L"m_mainTextLayout->GetMaxHeight() = " << m_mainTextLayout->GetMaxHeight();
  LOG(SEVERITY_LEVEL_DEBUG) << L"m_subText1Layout->GetMaxWidth() = " << m_subText1Layout->GetMaxWidth();
  LOG(SEVERITY_LEVEL_DEBUG) << L"m_subText1Layout->GetMaxHeight() = " << m_subText1Layout->GetMaxHeight();
  LOG(SEVERITY_LEVEL_DEBUG) << L"m_subText2Layout->GetMaxWidth() = " << m_subText2Layout->GetMaxWidth();
  LOG(SEVERITY_LEVEL_DEBUG) << L"m_subText2Layout->GetMaxHeight() = " << m_subText2Layout->GetMaxHeight();
  LOG(SEVERITY_LEVEL_DEBUG) << L"m_mainTextMetrics = " << m_mainTextMetrics;
  LOG(SEVERITY_LEVEL_DEBUG) << L"m_subText1Metrics = " << m_subText1Metrics;
  LOG(SEVERITY_LEVEL_DEBUG) << L"m_subText2Metrics = " << m_subText2Metrics;
#endif

  __CalculateLayoutRect();

  // ボディ
  m_bodyBrushSet->SetColorSet(m_bodyColorSet);
  m_bodyRect->SetX(0.0f);
  m_bodyRect->SetY(0.0f);
  m_bodyRect->SetWidth(GetWidth());
  m_bodyRect->SetHeight(GetHeight());
  auto frameDecorator = std::make_shared<graphics::decorator::FrameDecorator>();
  m_bodyRect->Initialize(pD3DInteropHelper);

#ifdef DEBUG_UILISTBOXITEM
  LOG_LEAVE(SEVERITY_LEVEL_DEBUG);
#endif
  return S_OK;
}
HRESULT ui::UIRadioButtonGroup::CreateDeviceDependentResources(graphics::D3DInteropHelper *pD3DInteropHelper,
                                                               ID2D1RenderTarget *pRenderTarget) {
  CHK_WARN_HRESULT(UIContainer::CreateDeviceDependentResources(pD3DInteropHelper, pRenderTarget));
  FLOAT y = 0.0f;
  for (size_t i = 0; i < GetNumberOfElements(); ++i) {
    auto radioButton = std::dynamic_pointer_cast<UIRadioButton>(GetElement(i));
    UISize size = radioButton->GetPreferredSize();
#ifdef DEBUG_UIRADIOBUTTONGROUP
    LOG(SEVERITY_LEVEL_DEBUG) << L"preferred size = " << size;
#endif
    radioButton->SetBounds(0.0f, y, GetWidth(), size.height);
    y += radioButton->GetHeight() + MARGIN_BUTTONS;
  }
  ui::UIRectangle bounds = GetBounds();
  if (bounds.height < y) {
    bounds.height = y;
    SetBounds(bounds);
  }
  return S_OK;
}
Ejemplo n.º 5
0
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;
}