Programming C++Builder How to make a 'rubber banding' effect to the Graphics in CBuilder?
Notice: Undefined variable: relatedArticlesCount in /home/wwwroot/codeback.net/plugins/content/tags.php on line 149

How to make a 'rubber banding' effect in C++Builder?

This example describes the details of implementing the 'Rubber banding' effect in an graphics application that tracks mouse movements as the user draws a graphic at runtime. The example code in this section is taken from a sample application located in the Examples\Doc\GraphEx directory. The application draws lines and shapes on a window's canvas in response to clicks and drags: pressing a mouse button starts drawing, and releasing the button ends the drawing.

To start with, the example code shows how to draw on the surface of the main form. Later examples demonstrate drawing on a bitmap.

The following topics describe the example:

  1. Responding to the mouse.
  2. Adding a field to a form object to track mouse actions.
  3. Refining line drawing.

1. Responding to the mouse

Your application can respond to the mouse actions: mouse-button down, mouse moved, and mouse-button up. It can also respond to a click (a complete press-and-release, all in one place) that can be generated by some kinds of keystrokes (such as pressing Enter in a modal dialog box).
This section covers:

  1. What's in a mouse event.
  2. Responding to a mouse-down action.
  3. Responding to a mouse-up action.
  4. Responding to a mouse move.

2. Adding a field to a form object to track mouse actions

To track whether a mouse button was pressed, you must add an object field to the form object. When you add a component to a form, C++Builder adds a field that represents that component to the form object, so that you can refer to the component by the name of its field. You can also add your own fields to forms by editing the type declaration in the form unit's header file.

In the following example, the form needs to track whether the user has pressed a mouse button. To do that, it adds a Boolean field and sets its value when the user presses the mouse button.

To add a field to an object, edit the object's type definition, specifying the field identifier and type after the public directive at the bottom of the declaration.
C++Builder "Owns" any declarations before the public directive: that's where it puts the fields that represent controls and the methods that respond to events.

3. Refining line drawing

With fields in place to track various points, you can refine an application's line drawing.


Add comment


Security code
Refresh

Programming - C++Builder