This article extends a Cairo-style vector engine in MQL5 with anti-aliased clipping. We build rectangular and path-based clipping regions, combine their coverage in the rasterizer, and discuss the limitations of mask multiplication. We also implement path bounds and point containment for sizing masks and testing interface interactions.
A graphics engine needs more than the ability to draw shapes and fill them with colors. It must also control where those drawings are allowed to appear. Without this capability, graphical elements can extend beyond their intended boundaries, overlap neighboring components, and interfere with other parts of an interface. This becomes particularly important when developing complex applications such as trading dashboards, where panels, charts, buttons, and scrolling lists must remain visually separated.
Consider a list containing eight rows inside a panel that has enough space for only four. Without a way to restrict the drawing area, all eight rows will appear, with the remaining four spilling beyond the panel. A price line that extends past the right edge of its plot area will continue across the axis labels, while a long caption inside a narrow button may overlap the neighboring button. These problems cannot be solved by modifying the shape itself. The drawing operation must instead be restricted by a boundary belonging to another interface element.
This boundary is called a clip, and it is the main missing capability we address in this article. Along the way, we will also introduce two useful geometry operations: determining the bounding rectangle of a path and checking whether a given point is inside it.
The existing graphics library already provides the geometry and painting components required for these operations. As established in Part 8, the rendering model consists of two independent components: a mask describing how much of each pixel is covered by a shape, and a source determining the color to be applied there. The library can now fill outlines constructed from lines, polygons, Bézier curves, arcs, circles, and rounded rectangles, using either winding rule, with smooth edges and support for solid colors, linear gradients, and radial gradients.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: Creating a Cairo-Inspired Graphics Library for MetaTrader 5 (Part 9): Clipping, Bounds and Hit Testing.
A graphics engine needs more than the ability to draw shapes and fill them with colors. It must also control where those drawings are allowed to appear. Without this capability, graphical elements can extend beyond their intended boundaries, overlap neighboring components, and interfere with other parts of an interface. This becomes particularly important when developing complex applications such as trading dashboards, where panels, charts, buttons, and scrolling lists must remain visually separated.
Consider a list containing eight rows inside a panel that has enough space for only four. Without a way to restrict the drawing area, all eight rows will appear, with the remaining four spilling beyond the panel. A price line that extends past the right edge of its plot area will continue across the axis labels, while a long caption inside a narrow button may overlap the neighboring button. These problems cannot be solved by modifying the shape itself. The drawing operation must instead be restricted by a boundary belonging to another interface element.
This boundary is called a clip, and it is the main missing capability we address in this article. Along the way, we will also introduce two useful geometry operations: determining the bounding rectangle of a path and checking whether a given point is inside it.
The existing graphics library already provides the geometry and painting components required for these operations. As established in Part 8, the rendering model consists of two independent components: a mask describing how much of each pixel is covered by a shape, and a source determining the color to be applied there. The library can now fill outlines constructed from lines, polygons, Bézier curves, arcs, circles, and rounded rectangles, using either winding rule, with smooth edges and support for solid colors, linear gradients, and radial gradients.
Author: Sandro Begashvili