11 Clipping - inanevin/LinaVG GitHub Wiki

LinaVG supports clipping via global configuration values. You can use these:

lvgDrawer.SetClipPosX(BackendHandle posX, int threadID = 0);
lvgDrawer.SetClipPosY(BackendHandle posX, int threadID = 0);
lvgDrawer.SetClipSizeX(BackendHandle posX, int threadID = 0);
lvgDrawer.SetClipSizeY(BackendHandle posX, int threadID = 0);

Whatever LinaVG::DrawXXX command you execute, it will use the latest set clip properties. So when you receive DrawBuffers on your backend code, you will have access to individual clip information for each buffer to be rendered.

StyleOptions opts;
opts.isFilled = true;

const Vec2 min = Vec2(startPos.x - size.x / 2.0f, startPos.y - size.y / 2.0f);
const Vec2 max = Vec2(startPos.x + size.x / 2.0f, startPos.y + size.y / 2.0f);

if (clippingEnabled)
{
    lvgDrawer.SetClipPosX(static_cast<BackendHandle>(min.x));
    lvgDrawer.SetClipPosY(static_cast<BackendHandle>(min.y));
    lvgDrawer.SetClipSizeX(static_cast<BackendHandle>(size.x));
    lvgDrawer.SetClipSizeY(static_cast<BackendHandle>(size.y));
}

// Main rect.
opts.color = Vec4(0, 0, 0, 1);
lvgDrawer.DrawRect(min, max, opts, 0.0f, 1);

// Clipped rect.
opts.color = Vec4(0.8f, 0.1f, 0.2f, 1.0f);
lvgDrawer.DrawRect(Vec2(min.x - 100, min.y - 100), Vec2(min.x + 100, min.y + 100), opts, 0.0f, 2);

// Clipped circle.
lvgDrawer.DrawCircle(max, 75, opts, 36, 0.0f, 0.0f, 360.0f, 2);

TextOptions textOpts;
textOpts.font = m_defaultFont;
lvgDrawer.DrawTextNormal("This text is clipped by the black rectangle.", Vec2(min.x - 50, min.y + 250), textOpts, 0.0f, 2);

lvgDrawer.SetClipPosX(0);
lvgDrawer.SetClipPosY(0);
lvgDrawer.SetClipSizeX(0);
lvgDrawer.SetClipSizeY(0);

image

Here's the same drawing function without clipping:

image