Hello David,
in principle there are two reasonable approaches.
Approach 1:
1. In your GUI component add a new Image view. Arrange it to cover the area where you want the user to draw the figures.
2. Add to the component an object of the Graphics::Canvas class. You do this by drag&drop the corresponding class from the Browser view to Composer window as shown in the screen shot below. See also the documentation Create new embedded object.
3. In Inspector window configure the Canvas object's property FrameSize to a value corresponding to the size of the drawing area in pixel.
4. Assign the canvas object to the property Bitmap of the Image view (added in step 1 above). Accordingly, the Image view will show what evet the Canvas object stores actually. Canvas object can be seen as image pixel storage (a bitmap).
5. Add a new Simple Touch Handler and arrange it to cover the Image View (from step 1).
6. Add a new Slot method.
7. Connect the slot method to the property OnDrag of the Simple Touch Handler. Accordingly, every time the user touches and drags over the area, the Slot method is invoked.
8. Open the Slot method and implement following code:
var color clr = #FF0000FF;
// Draw a line segment between the latest and preceding position
Canvas.DrawLine( Image.Bounds.orect, SimpleTouchHandler.CurrentPos, SimpleTouchHandler.CurrentPos + SimpleTouchHandler.Offset, clr, clr, true );
// Trigger the associated views to update their aspect
notifyobservers Canvas;
9. Additionally you would need to override the inherited method Init.
10. Open the overriden method and implement following code:
// Clear the content of the Canvas bitmap. (Fill it with transparent color)
Canvas.FillRectangle( Image.Bounds.orect, Image.Bounds.orect, #00000000, #00000000, #00000000, #00000000, false );
So far the approach 1. When you implement it, you will see that it draws very thin line segments. I don't know whether it is what you expect.
Approach 2 works with vector graphic instead of drawing a bitmap. Following are steps for approach 2:
1. In your GUI component add a new Stroked Path view. Arrange it to cover the area where you want the user to draw the figures.
2. Modify the property Witdh of the Stroked Path view to the desired thickness of the path in pixel. Modify the property Color to the desired color value.
3. Add a new Path Data object.
4. Assign the Path data object to the propertxy Path of the Stroked Path view (from step 1).
5. Add a new Simple Touch Handler and arrange it to cover the Stroked Path View (from step 1).
6. Add two (2x) new Slot methods.
7. Connect the first slot method to the property OnPress and the second Slot method to the property OnDrag of the Simple Touch Handler. Accordingly, every time the user touches the area, the first method is invoked. When the user drags the finger, the second method is invoked.
8. Open the first slot method (associated to the property OnPress) and implement following code:
var point pos = SimpleTouchHandler.CurrentPos - StrokePath.Bounds.origin;
// Here you determine the max. number of segments the path may store
Path.InitSubPath( 0, 1000 );
Path.Begin( 0, pos.x, pos.y );
9. Now open and edit the second slot method (associated to the property OnDrag). Implement following code:
var point pos = SimpleTouchHandler.CurrentPos - StrokePath.Bounds.origin;
// Add a new segment to the path data object
Path.AddLine( 0, pos.x, pos.y );
That's all so far.
Does it help you?
Best regards
Paul Banach