94 lines
3.2 KiB
Markdown
94 lines
3.2 KiB
Markdown
# Cairo G2D — a 2D vector graphics engine in pure MQL5
|
|
|
|
Source code for the mql5.com article series **"Cairo-Style Graphics in MQL5"**.
|
|
Part 1: https://www.mql5.com/en/articles/23818
|
|
|
|
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.
|
|
|
|
---
|
|
|
|
## Which version do I want?
|
|
|
|
**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.
|
|
|
|
| Release | Article | What it adds |
|
|
|---|---|---|
|
|
| `part-01` | Part 1 — Why the Terminal Needs Its Own 2D Renderer | `Color.mqh`, `Surface.mqh` — the ARGB type and the buffer-to-chart bridge |
|
|
|
|
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.
|
|
|
|
---
|
|
|
|
## Installing
|
|
|
|
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:
|
|
|
|
```text
|
|
MQL5/
|
|
├── Include/
|
|
│ └── CairoG2D/
|
|
│ ├── Color.mqh the ARGB color type
|
|
│ ├── Surface.mqh pixel buffer bound to one chart object
|
|
│ └── DemoTheme.mqh the demos' shared palette - NOT library code
|
|
└── Experts/
|
|
└── CairoG2D/
|
|
└── Article 01/
|
|
└── Demo01_FirstPixels.mq5
|
|
```
|
|
|
|
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.
|
|
|
|
The library headers are included the usual way:
|
|
|
|
```mql5
|
|
#include <CairoG2D/Color.mqh>
|
|
#include <CairoG2D/Surface.mqh>
|
|
```
|
|
|
|
`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.
|
|
|
|
---
|
|
|
|
## Scope
|
|
|
|
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.
|
|
|
|
---
|
|
|
|
## Removing it
|
|
|
|
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.
|
|
|
|
---
|
|
|
|
## Copyright and use
|
|
|
|
Copyright 2026, **Sandro Begashvili**
|
|
|
|
- mql5.com profile: https://www.mql5.com/en/users/sandrobegashvil
|
|
- Telegram: https://t.me/MrMQL5Developer
|
|
|
|
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.
|
|
|
|
If you build something with it, I would genuinely like to see it — the Telegram
|
|
link above is the fastest way to reach me.
|