CairoG2D/README.md
91 lines
4.7 KiB
Markdown
SandroBegashvil
2026-08-13 13:36:58 +04:00
# Cairo G2D — a 2D vector graphics engine in pure MQL5
Sandro Begashvili
2026-08-13 09:25:15 +00:00
Sandro Begashvili
2026-08-15 10:47:17 +00:00
Source code for the mql5.com article series **Creating a Cairo-Inspired Graphics Library for MetaTrader 5**.
Sandro Begashvili
2026-08-15 09:54:00 +00:00
SandroBegashvil
2026-08-13 13:36:58 +04:00
Part 1: https://www.mql5.com/en/articles/23818
Sandro Begashvili
2026-08-15 09:54:00 +00:00
Sandro Begashvili
2026-08-15 09:53:40 +00:00
Part 2: https://www.mql5.com/en/articles/23993
SandroBegashvil
2026-08-13 13:36:58 +04:00
SandroBegashvil
2026-08-19 19:58:01 +04:00
Part 3: https://www.mql5.com/en/articles/24165
SandroBegashvil
2026-08-24 15:25:24 +04:00
Part 4: https://www.mql5.com/en/articles/24259
SandroBegashvil
2026-08-31 17:55:20 +04:00
Part 5: https://www.mql5.com/en/articles/24315
Sandro Begashvili
2026-08-19 16:51:32 +00:00
A scanline rasteriser, path model and compositing pipeline written from scratch in MQL5, with no external libraries and no `CCanvas`. Everything it draws goes into one `OBJ_BITMAP_LABEL`, so a panel of a thousand shapes still costs the terminal exactly one chart object.
SandroBegashvil
2026-08-13 13:36:58 +04:00
---
## Which version do I want?
Sandro Begashvili
2026-08-19 16:51:32 +00:00
**Use the release that matches the article you are reading.** Each part of the series has its own release, frozen at the state the article explains — so if you are reading Part 1, the Part 1 release contains two header files and one demo, and nothing you have not read about yet.
SandroBegashvil
2026-08-13 13:36:58 +04:00
| Release | Article | What it adds |
|---|---|---|
Sandro Begashvili
2026-08-15 10:42:32 +00:00
| [`part-01`](https://forge.mql5.io/SandroBegashvil/CairoG2D/releases/tag/part-01) | [Part 1 — Why the Terminal Needs Its Own 2D Renderer](https://www.mql5.com/en/articles/23818) | `Color.mqh`, `Surface.mqh` — the ARGB type and the buffer-to-chart bridge |
| [`part-02`](https://forge.mql5.io/SandroBegashvil/CairoG2D/releases/tag/part-02) | [Part 2 — Points, Contours and the Path](https://www.mql5.com/en/articles/23993) | `Path.mqh` — points, contours, the path |
SandroBegashvil
2026-08-19 19:58:01 +04:00
| [`part-03`](https://forge.mql5.io/SandroBegashvil/CairoG2D/releases/tag/part-03) | [Part 3 — Edges and the First Filled Shape](https://www.mql5.com/en/articles/24165) | `Path.mqh` & `Raster.mqh` — the scanline fill |
SandroBegashvil
2026-08-24 15:25:24 +04:00
| [`part-04`](https://forge.mql5.io/SandroBegashvil/CairoG2D/releases/tag/part-04) | [Part 4 — Anti-Aliasing, Coverage and Compositing](https://www.mql5.com/en/articles/24259) | `Config.mqh` & `Raster.mqh` — coverage and compositing |
SandroBegashvil
2026-08-31 17:55:20 +04:00
| [`part-05`](https://forge.mql5.io/SandroBegashvil/CairoG2D/releases/tag/part-05) | [Part 5 — Fill Rules, Holes and Borders](https://www.mql5.com/en/articles/24315) | `Path.mqh` & `Raster.mqh` — fill rules and holes |
SandroBegashvil
2026-08-13 13:36:58 +04:00
Sandro Begashvili
2026-08-19 16:51:32 +00:00
Later parts are added to this table as they are published. The `main` branch is always the newest state, which will be ahead of every published article.
SandroBegashvil
2026-08-13 13:36:58 +04:00
---
## Installing
Sandro Begashvili
2026-08-19 16:51:32 +00:00
Download the release archive and extract it over your terminal's data folder (**File → Open Data Folder** in MetaTrader 5). The archive already has the right shape, so the files land where they belong:
SandroBegashvil
2026-08-13 13:36:58 +04:00
```text
MQL5/
├── Include/
│ └── CairoG2D/
│ ├── Color.mqh the ARGB color type
│ ├── Surface.mqh pixel buffer bound to one chart object
Sandro Begashvili
2026-08-15 09:53:40 +00:00
│ ├── Path.mqh points, contours, the path
Sandro Begashvili
2026-08-19 16:51:32 +00:00
│ ├── Raster.mqh the scanline fill
SandroBegashvil
2026-08-24 15:30:47 +04:00
│ ├── Config.mqh CairoAaSamples - the quality dial
SandroBegashvil
2026-08-13 13:36:58 +04:00
│ └── DemoTheme.mqh the demos' shared palette - NOT library code
└── Experts/
└── CairoG2D/
Sandro Begashvili
2026-08-15 09:53:40 +00:00
├── Article 01/
│ └── Demo01_FirstPixels.mq5
└── Article 02/
└── Demo02_PathViewer.mq5
SandroBegashvil
2026-08-13 13:36:58 +04:00
```
Sandro Begashvili
2026-08-19 16:51:32 +00:00
Then open the demo in MetaEditor, compile with **F7**, and drag it onto any chart. It needs no inputs, no indicators and no market data.
SandroBegashvil
2026-08-13 13:36:58 +04:00
The library headers are included the usual way:
```mql5
#include <CairoG2D/Color.mqh>
#include <CairoG2D/Surface.mqh>
```
Sandro Begashvili
2026-08-19 16:51:32 +00:00
`DemoTheme.mqh` is deliberately shipped alongside them but is **not** part of the engine. It holds the light palette and the chart setup that make every screenshot in the series look the same, and nothing in the renderer depends on it.
SandroBegashvil
2026-08-13 13:36:58 +04:00
---
## Scope
Sandro Begashvili
2026-08-19 16:51:32 +00:00
This is a software rasteriser aimed at **interface redraw** — panels that are repainted when something happens, not scenes animated at a high frame rate. It uses **straight (non-premultiplied) alpha from input to output**, which is what `COLOR_FORMAT_ARGB_NORMALIZE` expects.
SandroBegashvil
2026-08-13 13:36:58 +04:00
---
## Removing it
Sandro Begashvili
2026-08-19 16:51:32 +00:00
Each demo draws into a single chart object and deletes that object on `OnDeinit`, so removing the Expert Advisor leaves the chart exactly as it was found. Nothing is written outside the terminal's data folder.
SandroBegashvil
2026-08-13 13:36:58 +04:00
---
## Copyright and use
Copyright 2026, **Sandro Begashvili**
- mql5.com profile: https://www.mql5.com/en/users/sandrobegashvil
- Telegram: https://t.me/MrMQL5Developer
Sandro Begashvili
2026-08-19 16:51:32 +00:00
You are free to **use this code in your own projects and to extend it**, commercially or otherwise. The only thing asked in return is attribution: keep a mention of the author's mql5.com profile in the source you derive from it.
SandroBegashvil
2026-08-13 13:36:58 +04:00
Sandro Begashvili
2026-08-19 16:51:32 +00:00
If you build something with it, I would genuinely like to see it — the Telegram link above is the fastest way to reach me.