コード例 #1
0
// Returns the bar position after scrolling for a number of pixels.
float WidgetSliderScroll::Scroll(float distance)
{
    float traversable_track_length = (track_length - bar_length);
    if (traversable_track_length <= 0)
        return GetBarPosition();

    return (GetBarPosition() * traversable_track_length + distance) / traversable_track_length;
}
コード例 #2
0
HRESULT ui::UIScrollBar::Initialize(graphics::D3DInteropHelper *pD3DInteropHelper) {
#ifdef DEBUG_UISCROLLBAR
  LOG_ENTER(SEVERITY_LEVEL_DEBUG);
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetTotalWidth() = " << GetTotalThick();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetTotalLength() = " << GetTotalLength();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetSlideAreaWidth() = " << GetSlideAreaThick();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetSlideAreaLength() = " << GetSlideAreaLength();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetSlideAreaMargin() = " << GetSlideAreaMargin();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetBarPosition() = " << GetBarPosition();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetBarLength() = " << GetBarLength();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetBarWidth() = " << GetBarThick();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetBarOffset() = " << GetBarOffset();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetArrowLength() = " << GetArrowLength();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetArrowWidth() = " << GetArrowThick();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetArrowMargin() = " << GetArrowMargin();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetArrow1Offset() = " << GetArrow1Offset();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetArrow2Offset() = " << GetArrow2Offset();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetSplitterMargin() = " << GetSplitterMargin();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetSplitterWidth() = " << GetSplitterThick();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetSplitterHeight() = " << GetSplitterHeight();
  LOG(SEVERITY_LEVEL_DEBUG) << L"GetSplitterOffset() = " << GetSplitterOffset();
#endif
  m_body->SetX(0.0f);
  m_body->SetY(0.0f);
  m_body->SetWidth(GetWidth());
  m_body->SetHeight(GetHeight());
  m_body->SetRadius(m_direction == SCROLLBAR_DIRECTION_HORIZONTAL ? GetHeight() / 2.0f : GetWidth() / 2.0f);
  m_body->SetColor(graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_HSBA, 0.0f, 0.0f, 0.2f, 1.0f),
                   graphics::color::COLOR_PATTERN_CONVEX);
  m_body->SetShadow(true);
  m_body->SetShadowColor(std::make_shared<graphics::color::SolidColor>(
      graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_HSBA, 190.0f, 1.0f, 1.0f, 1.0f)));
  m_body->Initialize(pD3DInteropHelper);

  if (m_direction == SCROLLBAR_DIRECTION_HORIZONTAL) {
    m_arrow1->SetX(GetArrow1Offset());
    m_arrow1->SetY(GetArrowMargin());
    m_arrow1->SetWidth(GetArrowLength());
    m_arrow1->SetHeight(GetArrowThick());
    m_arrow1->SetDirection(graphics::figure::TriangleFigure::TRIANGLE_DIRECTION_LEFT);
  } else {
    m_arrow1->SetX(GetArrowMargin());
    m_arrow1->SetY(GetArrow1Offset());
    m_arrow1->SetWidth(GetArrowThick());
    m_arrow1->SetHeight(GetArrowLength());
    m_arrow1->SetDirection(graphics::figure::TriangleFigure::TRIANGLE_DIRECTION_TOP);
  }
  m_arrow1->SetColor(graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_HSBA, 32.0f, 0.0f, 0.5f, 1.0f),
                     graphics::color::COLOR_PATTERN_CONVEX);
  m_arrow1->Initialize(pD3DInteropHelper);

  if (m_direction == SCROLLBAR_DIRECTION_HORIZONTAL) {
    m_arrow2->SetX(GetArrow2Offset());
    m_arrow2->SetY(GetArrowMargin());
    m_arrow2->SetWidth(GetArrowLength());
    m_arrow2->SetHeight(GetArrowThick());
    m_arrow2->SetDirection(graphics::figure::TriangleFigure::TRIANGLE_DIRECTION_RIGHT);
  } else {
    m_arrow2->SetX(GetArrowMargin());
    m_arrow2->SetY(GetArrow2Offset());
    m_arrow2->SetWidth(GetArrowThick());
    m_arrow2->SetHeight(GetArrowLength());
    m_arrow2->SetDirection(graphics::figure::TriangleFigure::TRIANGLE_DIRECTION_BOTTOM);
  }
  m_arrow2->SetColor(graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_HSBA, 32.0f, 0.0f, 0.5f, 1.0f),
                     graphics::color::COLOR_PATTERN_CONVEX);
  m_arrow2->Initialize(pD3DInteropHelper);

  if (m_direction == SCROLLBAR_DIRECTION_HORIZONTAL) {
    m_slideArea->SetX(GetSlideAreaOffset());
    m_slideArea->SetY(GetSlideAreaMargin());
    m_slideArea->SetWidth(GetSlideAreaLength());
    m_slideArea->SetHeight(GetSlideAreaThick());
  } else {
    m_slideArea->SetX(GetSlideAreaMargin());
    m_slideArea->SetY(GetSlideAreaOffset());
    m_slideArea->SetWidth(GetSlideAreaThick());
    m_slideArea->SetHeight(GetSlideAreaLength());
  }
  m_slideArea->SetColor(
      graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_HSBA, 190.0f, 1.0f, 0.3f, 1.0f),
      graphics::color::COLOR_PATTERN_CONVEX);
  m_slideArea->Initialize(pD3DInteropHelper);

  if (m_direction == SCROLLBAR_DIRECTION_HORIZONTAL) {
    m_bar->SetX(GetBarOffset());
    m_bar->SetY(GetSlideAreaMargin());
    m_bar->SetWidth(GetBarLength());
    m_bar->SetHeight(GetBarThick());
  } else {
    m_bar->SetX(GetSlideAreaMargin());
    m_bar->SetY(GetBarOffset());
    m_bar->SetWidth(GetBarThick());
    m_bar->SetHeight(GetBarLength());
  }
  m_bar->SetColor(graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_HSBA, 190.0f, 1.0f, 0.7f, 1.0f),
                  graphics::color::COLOR_PATTERN_CONVEX_METAL);
  m_bar->SetShadow(true);
  m_bar->SetShadowColor(std::make_shared<graphics::color::SolidColor>(
      graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_HSBA, 190.0f, 1.0f, 1.0f, 1.0f)));
  m_bar->Initialize(pD3DInteropHelper);

#ifdef DEBUG_UISCROLLBAR
  LOG_LEAVE(SEVERITY_LEVEL_DEBUG);
#endif
  return S_OK;
}