MQL5 Article · Preview

Creating a Cairo-Inspired Graphics Library for MetaTrader 5 (Part 2): Points, Contours and the Path

Creating a Cairo-Inspired Graphics Library for MetaTrader 5 (Part 2): Points, Contours and the Path

Introduction

Part 1 introduced Cairo's separation between what to draw and where it goes, then implemented the two supporting files: a color type Color.mqh and a surface that binds a pixel buffer to a single chart object Surface.mqh. We finished by writing pixels directly in nested loops and drawing a triangle and a circle with separate functions.

That demonstration exposed two limitations:

  • the edges formed staircases because each pixel was either inside or outside, with no intermediate coverage;
  • the approach does not scale because every new shape requires its own rendering function, loops, bounds, and edge handling.

This part addresses the second limitation by introducing a common representation for shape geometry. In Part 3, a single fill routine will use that representation without needing shape-specific rendering code. In this part, we implement Path.mqh. By the end, the library can describe geometry but cannot yet fill it.

This separation is deliberate. Filling is introduced in Part 3, after the geometry it consumes has been defined.

Here is the state of the library when we are done today:

MQL5
Color.mqh      Part 1    the ARGB color type, uint 0xAARRGGBB
Surface.mqh    Part 1    a pixel buffer bound to one chart object
Path.mqh       Part 2    points, contours, MoveTo / LineTo / Close   <- today

Continue reading on MQL5.com

The full article with complete source code is published on MQL5.com.

Read the full article