Discussing the article: "MQL5 Trading Tools (Part 36): Adding Shape and Annotation Tools with In-Place Label Editing to the Canvas Drawing Layer"
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: MQL5 Trading Tools (Part 36): Adding Shape and Annotation Tools with In-Place Label Editing to the Canvas Drawing Layer.
We add eight shape tools and nine annotation tools to the canvas and implement a full in-place label-editing system. The article walks through geometry, AA rendering, shared word-wrap and supersampled text helpers, and the caret-driven state machine for typing, navigation, and selection. This yields a complete, consistent annotation toolkit with editable labels that plugs into the prior interaction pipeline.
The new tools fall into two categories (shapes and annotations) and share a third architectural layer: in-place text editing. Shapes are filled regions defined by two or three anchor points, with a translucent fill rendered using signed-distance anti-aliasing. This makes the edges look clean even on rotated geometry. Annotations are markers that carry user text. A Note pins a rectangle to an anchor with a connector line. A Callout extends a tail from the rectangle to point at something. A Comment tucks a rounded badge against a click point. An Arrow draws a directional indicator with a filled triangular head. The text editing layer is the most demanding piece. We need a word-wrap that finds the right break point per visual line through binary search prefix measurement. There is a blinking caret driven by a timer. Mouse-click coordinates are translated into character positions. Windows virtual-key capture enables typing. Arrow-key navigation respects visual lines after wrap. Shift-arrow extends selection. A chart keyboard control override ensures typing does not trigger MetaTrader 5's own navigation. We did much of this on the AI series, so we will just refer to it, since the same logic is used here.
To avoid rewriting the inheritance chain, we add two layers. "CFibonacciTools" becomes the base for "CShapeTools", and "CShapeTools" becomes the base for "CAnnotationTools". "CAnnotationTools" then becomes the parent of the tool registry and the drawing engine. Each layer adds draw routines, hit testers, and shared helpers. These include supersampled rounded-rectangle fills, dual-pass black/white alpha extraction for text, point-in-polygon tests for filled silhouettes, two-pass separable box blurs for drop shadows, and shared word-wrap and text-rendering utilities. All this is inspired by the default MQL5 web chart analysis tools, which we went an extra mile to extend. Have a look below at a visualization of our objectives.
Author: Allan Munene Mutiiria