Exemplo n.º 1
0
void HorizontalLayout::Draw(DrawingContext & drawingContext)
{
    UpdateLayout();
    POMDOG_ASSERT(!needToUpdateLayout);

    auto transform = GetTransform() * drawingContext.Top();

#if 0
    renderCommand.SetInvoker([transform, this](PrimitiveBatch& primitiveBatch) {
        const Color backgroundColor = {45, 45, 48, 225};
        const Color borderColor = {40, 40, 40, 255};
        const Color highlightColor = {106, 106, 106, 255};

        const auto width = static_cast<float>(GetWidth());
        const auto height = static_cast<float>(GetHeight());

        primitiveBatch.DrawRectangle(transform, Vector2::Zero, width, height, backgroundColor);

        primitiveBatch.DrawLine(transform, Vector2{0.0f, 0.0f}, Vector2{width, 0.0f}, borderColor, 1.0f);
        primitiveBatch.DrawLine(transform, Vector2{0.0f, 0.0f}, Vector2{0.0f, height}, borderColor, 1.0f);
        primitiveBatch.DrawLine(transform, Vector2{0.0f, height}, Vector2{width, height}, borderColor, 1.0f);
        primitiveBatch.DrawLine(transform, Vector2{width, 0.0f}, Vector2{width, height}, borderColor, 1.0f);
    });
    drawingContext.PushCommand(renderCommand);
#endif

    drawingContext.Push(transform);

    for (auto & child : children) {
        POMDOG_ASSERT(child);
        child->Draw(drawingContext);
    }

    drawingContext.Pop();
}
Exemplo n.º 2
0
void DisclosureTriangleButton::Draw(DrawingContext & drawingContext)
{
    auto transform = GetTransform() * drawingContext.Top();

    renderCommand.SetInvoker([this, transform](PrimitiveBatch& primitiveBatch) {
        Color thumbColor = isOn ? Color{27, 161, 226, 255} : Color{162, 160, 161, 255};

        const auto transformOffset = Vector2{transform(2, 0), transform(2, 1)};

        const auto triangleWidth = 6.0f;
        if (isOn) {
            primitiveBatch.DrawTriangle(
                transformOffset + Vector2{0.0f, 0.0f},
                transformOffset + Vector2{triangleWidth, triangleWidth},
                transformOffset + Vector2{triangleWidth, 0.0f},
                thumbColor);
        }
        else {
            const float squareRoot = 1.41421356f;
            primitiveBatch.DrawTriangle(
                transformOffset + Vector2{0.0f, 0.0f},
                transformOffset + Vector2{0.0f, triangleWidth * squareRoot},
                transformOffset + Vector2{triangleWidth / squareRoot, triangleWidth * 0.5f * squareRoot},
                thumbColor);
        }
    });
    drawingContext.PushCommand(renderCommand);
}
Exemplo n.º 3
0
void HorizontalLine::Draw(DrawingContext & drawingContext)
{
    auto transform = GetTransform() * drawingContext.Top();

    renderCommand.SetInvoker([this, transform](PolygonBatch & polygonBatch) {
        auto offset = Vector2{transform(2, 0), transform(2, 1)};
        auto start = offset + Vector2{0.0f, 0.0f};
        auto end = offset + Vector2{static_cast<float>(GetWidth()), 0.0f};
        polygonBatch.DrawLine(start, end, Color{92, 91, 90, 255}, 1.0f);
    });
    drawingContext.PushCommand(renderCommand);
}
Exemplo n.º 4
0
//-----------------------------------------------------------------------
void DebugNavigator::Draw(DrawingContext & drawingContext)
{
    constexpr float minFramerate = 10.0f;
    constexpr float maxFramerate = 60.0f;
    constexpr std::uint16_t maxHistories = 20;

    {
        if (clock->TotalGameTime() - duration > Duration(0.2))
        {
            auto frameRate = clock->FrameRate();
            frameRateString = StringFormat("%4.2f fps", frameRate);
            frameRates.push_back(MathHelper::Clamp(frameRate, minFramerate, maxFramerate));

            if (frameRates.size() > maxHistories)
            {
                frameRates.pop_front();
            }
            duration = clock->TotalGameTime();
        }
    }

    auto transform = Transform() * drawingContext.Top();
    {
        auto graphTransform = Matrix3x2::CreateTranslation(Vector2{0, 16}) * transform;

        constexpr std::uint16_t maxGraphHeight = 26;
        constexpr float graphMarginLeft = 1.0f;

        auto graghWidth = (static_cast<float>(Width()) / maxHistories);

        std::int32_t startPosition = graghWidth * (maxHistories - frameRates.size());
        std::int32_t graphX = startPosition;
        for (auto & frameRate: frameRates)
        {
            auto amount = ((frameRate - minFramerate) / (maxFramerate - minFramerate));
            auto graphHeight = MathHelper::Clamp<std::uint16_t>(maxGraphHeight * amount, 1, maxGraphHeight);

            drawingContext.DrawRectangle(graphTransform, Color::CornflowerBlue,
                Rectangle(graphX, maxGraphHeight - graphHeight, graghWidth - graphMarginLeft, graphHeight));
            graphX += graghWidth;
        }
    }

    drawingContext.DrawString(transform * Matrix3x2::CreateTranslation({0.5f, -2.5f}),
        Color::White, FontWeight::Bold, FontSize::Medium, frameRateString);
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------
void TextBlock::Draw(DrawingContext & drawingContext)
{
    auto transform = Transform() * drawingContext.Top();

    drawingContext.DrawString(transform, Color::White, FontWeight::Normal, FontSize::Medium, text);
}