Frequently Asked Component Specific Questions
Options |
Display all FAQ items |
Displaying items 1 to 1 of 1, page 1 of 1
<< previous next >>
Initializing controls
The TMS GUIMotions control can also be used to display and paint controls that have the ability to draw to a canvas (ie. properly implement the PaintTo() method). To use controls, first references to the controls need to be added to the Images collection. Secondly, controls need to be set visible and positioned correct at the appropriate events. Here is a small tutorial which might help to setup similar projects.
Step 1: adding references to the controls to the collection. (Sample with chart control)
for I := 0 to 10 do begin with GUIMotions1.Images.Add do begin // 1) Create control with parent GUIMotions1 c := TAdvGDIPChartview.Create(GUIMotions1); // 2) Set the control visible to false c.Visible := false; // 3) Set the parent to GUIMotions1 c.Parent := GUIMotions1 // 4) Add some random data to your control // 5) Add control to image collection Control := c; end; end;
Step 2: making sure the control is displayed in the animation:
Add an event handler for GUIMotions.OnImageCustomDraw. This event can be called when the GUIMotions component is trying to create a texture. When no picture was set for the image from the collection to be rendered, GUIMotions will call this custom drawing event. In this event you need to draw the control on the canvas of the picture variable.
procedure TForm42.GUIMotions1ImageCustomDraw(Sender: TObject; Image: Integer; Picture: TBitmap); var c: TAdvGDIPChartView; begin c := TAdvGDIPChartView(GUIMotions1.Images[Image].Control); c.Width := GUIMotions1.PictureWidthZoomed; c.Height := GUIMotions1.PictureHeightZoomed; picture.Width := GUIMotions1.PictureWidthZoomed; picture.Height := GUIMotions1.PictureHeightZoomed; c.PaintTo(Picture.Canvas, 0, 0); Picture.Canvas.Pen.Color := clBlack; Picture.Canvas.Pen.Width := 2; Picture.Canvas.Brush.Style := bsClear; Picture.Canvas.Rectangle(0,0,Picture.Width,Picture.Height); end;
The control has 3 events that can be used to make the control visible. OnImageClick, OnImageDblClick, OnImageZoomed. In this case we are using the OnImageZoomed event.
procedure TForm42.GUIMotions1ImageZoomed(Sender: TObject; Image: Integer; ImageRectangle: TRect); var r: TRect; begin AdvChartPanesEditorDialogGDIP1.ChartView := TAdvGDIPChartview(GUIMotions1.Images[Image].Control); r := ImageRectangle; TAdvGDIPChartview(GUIMotions1.Images[Image].Control).SetBounds(r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top); TAdvGDIPChartview(GUIMotions1.Images[Image].Control).visible := true; end;
procedure TForm42.GUIMotions1ImageUnZoom(Sender: TObject; Image: Integer; ImageRectangle: TRect); var r: TRect; begin TAdvGDIPChartview(GUIMotions1.Images[Image].Control).visible := false; end;
Wherever you make changes to the control you need to force an update to pass the changes of the control to the image. The update will automatically call the OnImageCustomDraw event and will paint the latest updated control on the image.
GUIMotions1.Images[GUIMotions1.ImageSelected].Update;