Per schedule-touch screen programming ongesture

Source: Internet
Author: User

The most eye-catching new feature of Delphi 2010 may be the support for "Touch Screen", which includes a touch-able soft keyboard and recognition of different touch screen gestures.

Because gestures support the mouse at the same time, I can try most of the functions without a touch screen.

Steps for the first attempt:

1. Add the tgesturemanager control, such as the form: gesturemanager1;

2. Set the form attribute touch. gesturemanager: = gesturemanager1; {The following program is the attribute specified during design}

3. Add the ongesture event of the form and write anything at will;

4. Run the program and drag a few times on the form with the mouse... The first test program is completed!

5. Add the panle1 oncreate event of the form, and write: Touch. standardgestures: = [sgleft, sgright];

 

6. Add and associate tgesturemanager to the form, and add tactionlist;

7. Associate action with action:

8. write code for action.

Now the program can "perceive gestures". How can it "recognize gestures?

Delphi divides recognizable gestures into three categories: Standard gestures, custom gestures, and interactive gestures (interactivegestures ).

The interactive gestures are difficult to simulate with the mouse, and may only be used for touch screens;

Delphi predefines 34 standard gestures and defines them as tstandardgesture enumeration types:

TStandardGesture = (  sgLeft            = sgiLeft,  sgRight           = sgiRight,  sgUp              = sgiUp,  sgDown            = sgiDown,  sgUpLeft          = sgiUpLeft,  sgUpRight         = sgiUpRight,  sgDownLeft        = sgiDownLeft,  sgDownRight       = sgiDownRight,  sgLeftUp          = sgiLeftUp,  sgLeftDown        = sgiLeftDown,  sgRightUp         = sgiRightUp,  sgRightDown       = sgiRightDown,  sgUpDown          = sgiUpDown,  sgDownUp          = sgiDownUp,  sgLeftRight       = sgiLeftRight,  sgRightLeft       = sgiRightLeft,  sgUpLeftLong      = sgiUpLeftLong,  sgUpRightLong     = sgiUpRightLong,  sgDownLeftLong    = sgiDownLeftLong,  sgDownRightLong   = sgiDownRightLong,  sgScratchout      = sgiScratchout,  sgTriangle        = sgiTriangle,  sgSquare          = sgiSquare,  sgCheck           = sgiCheck,  sgCurlicue        = sgiCurlicue,  sgDoubleCurlicue  = sgiDoubleCurlicue,  sgCircle          = sgiCircle,  sgDoubleCircle    = sgiDoubleCircle,  sgSemiCircleLeft  = sgiSemiCircleLeft,  sgSemiCircleRight = sgiSemiCircleRight,  sgChevronUp       = sgiChevronUp,  sgChevronDown     = sgiChevronDown,  sgChevronLeft     = sgiChevronLeft,  sgChevronRight    = sgiChevronRight);
 

Note: Each enumeration item corresponds to a constant value (for example, sgleft of the enumeration item corresponds to sgileft, and sgileft is a previously defined constant );

Note the naming rules of constants, which will be frequently used later to differentiate which gesture is triggered, for example:

if EventInfo.GestureID = sgiLeft then ...
 

The following figure shows the standard gesture copied from docwiki.embarcadero.com/radstudio/en/tstandardgesture_enum:

Enum Symbol
Sgleft
Sgright
Sgup
Sgdown
Sgupleft
Sgupright
Sgdownleft
Sgdownright
Sgleftup
Sgleftdown
Sgrightup
Sgrightdown
Sgupdown
Sgdownup
Sgleftright
Sgrightleft
Sgupleftlong
Sguprightlong
Sgdownleftlong
Sgdownrightlong
Sgscratchout
Sgtriangle
Sgsquare
Sgcheck
Sgcurlicue
Sgdoublecurlicue
Sgcircle
Sgdoublecircle
Sgsemicircleleft
Sgsemicircleright
Sgchevronup
Sgchevrondown
Sgchevronleft
Sgchevronright

 

Const eventinfo: tgestureeventinfo in the ongesture event; the parameter is mainly used to identify gesture information;

Eventinfo. gestureid was used before, and eventinfo. location provided the starting coordinate of the gesture action. The test code is as follows:

procedure TForm1.FormGesture(Sender: TObject;  const EventInfo: TGestureEventInfo; var Handled: Boolean);begin  ShowMessage(Format('X:%d; Y:%d' , [EventInfo.Location.X, EventInfo.Location.Y]));end;
 

Eventinfo is a structure with more information. If there is no touch screen, other functions may not be used.

The ongesture event also has a VaR parameter handled: Boolean;

The value of handled is false. Generally, we can write a handled: = true;

If handled is set to false, the touch action continues to search for the upper-layer control.

First, you should know that many controls including forms now have the gesturemanager attribute and ongesture event...

For example, if you set a gesture on the Panel and its form, you can see the role of the handled parameter.

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, gesturemgr, stdctrls, extctrls, actnlist;

Type
Tform1 = Class (tform)
Gstrmngr1: tgesturemanager;
Pnl1: tpanel;
Actlst1: tactionlist;
Act1: taction;
Act2: taction;
Procedure formcreate (Sender: tobject );
Procedure formgesture (Sender: tobject; const eventinfo: tgestureeventinfo;
VaR handled: Boolean );
Procedure act1execute (Sender: tobject );
Procedure act2execute (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

Procedure tform1.act1execute (Sender: tobject );
Begin
Showmessage ('left ');
End;

Procedure tform1.act2execute (Sender: tobject );
Begin
Showmessage ('right ');
End;

Procedure tform1.formcreate (Sender: tobject );
Begin
Self. Touch. gesturemanager: = gstrmngr1;
End;

Procedure tform1.formgesture (Sender: tobject;
Const eventinfo: tgestureeventinfo; var handled: Boolean );
Begin
Showmessage (sender. classname + '_ gesture ');
// Case eventinfo. gestureid
// Sgileft: showmessage ('left ');
// Sgiright: showmessage ('right ');
// End;

End;

End.

Const eventinfo: tgestureeventinfo in the ongesture event; the parameter is mainly used to identify gesture information;

Eventinfo. gestureid was used before, and eventinfo. location provided the starting coordinate of the gesture action. The test code is as follows:

  procedure TForm1.FormGesture(Sender: TObject;  const EventInfo: TGestureEventInfo; var Handled: Boolean);begin  ShowMessage(Format('X:%d; Y:%d', [EventInfo.Location.X, EventInfo.Location.Y]));end;
 

Eventinfo is a structure with more information. If there is no touch screen, other functions may not be used.

The ongesture event also has a VaR parameter handled: Boolean;

The value of handled is false. Generally, we can write a handled: = true;

If handled is set to false, the touch action continues to search for the upper-layer control.

First, you should know that many controls including forms now have the gesturemanager attribute and ongesture event...

For example, if you set a gesture on the Panel and its form, you can see the role of the handled parameter.

After adding tgesturemanager, double-click its icon to edit the custom gesture;

In the edit box, sensitivity is used to adjust the sensitivity of the gesture response. After unidirectional is checked, the reverse gesture can also be recognized.

One or more gestures can be saved as a DGF file.

You can click the small button next to touch-> gestures in the control property to view, select, or edit the gesture.

The tgesturelistview, tgesturepreview, and tgesturerecorder controls in the same group as tgesturemanager can be used to design gesture editing at the same runtime as those at Delphi design. (officially: these controls are also used for gesture editing ).

The IDS of custom gestures are-1,-2,-3... It can be used for identification in the ongesture event. Of course, it can also be directly assigned an action.

Download Demo: temp code

Demo effect:

Program code:

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, gesturemgr, stdctrls, extctrls, actnlist;

Type
Tform1 = Class (tform)
Gstrmngr1: tgesturemanager;
Pnl1: tpanel;
Actlst1: tactionlist;
Act1: taction;
Act2: taction;
Procedure formcreate (Sender: tobject );
Procedure formgesture (Sender: tobject; const eventinfo: tgestureeventinfo;
VaR handled: Boolean );
Procedure act1execute (Sender: tobject );
Procedure act2execute (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

Procedure tform1.act1execute (Sender: tobject );
Begin
Showmessage ('left ');
End;

Procedure tform1.act2execute (Sender: tobject );
Begin
Showmessage ('right ');
End;

Procedure tform1.formcreate (Sender: tobject );
Begin
Self. Touch. gesturemanager: = gstrmngr1;
End;

Procedure tform1.formgesture (Sender: tobject;
Const eventinfo: tgestureeventinfo; var handled: Boolean );
Begin
Showmessage (sender. classname + '_ gesture ');
// Case eventinfo. gestureid
// Sgileft: showmessage ('left ');
// Sgiright: showmessage ('right ');
// End;

End;

End.

Form code:

Object form1: tform1
Left = 0
Top = 0
Caption = #24858 #20154 #31508 #35760 '-http://www.foolcode.com'
Clientheight = 1, 238
Clientwidth = 387
Color = clbtnface
Font. charset = default_charset
Font. Color = clwindowtext
Font. Height =-11
Font. Name = 'tahoma'
Font. Style = []
Oldcreateorder = false
Touch. gesturemanager = gstrmngr1
Oncreate = formcreate
Ongesture = formgesture
Pixelsperinch = 96
Textheight = 13
Object pnl1: tpanel
Left = 1, 183
Top = 0
Width = 204
Height = 238
Align = alright
Taborder = 0
Touch. gesturemanager = gstrmngr1
End
Object gstrmngr1: tgesturemanager
Left = 1, 192
Top = 40
Gesturedata = <
Item
Control = owner
Collection = <
Item
Gestureid = sgileft
End>
End
Item
Control = pnl1
Collection = <
Item
Action = act1
Gestureid = sgileft
End
Item
Action = Act2
Gestureid = sgiright
End>
End>
End
Object actlst1: tactionlist
Left = 1, 192
Top = 96
Object act1: taction
Caption = 'act1 ′
Onexecute = act1execute
End
Object Act2: taction
Caption = 'act2 ′
Onexecute = act2execute
End
End
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.