手势编程[1] - 初识 TGestureManager

来源:互联网 发布:淘宝评价被系统删除 编辑:程序博客网 时间:2024/05/22 09:46

转自:http://www.cnblogs.com/del

Delphi 2010 最抢眼的新功能可能就是支持"触摸屏"了, 它包括一个 可触控的软键盘 和识别不同的触屏手势.

因为手势同时支持鼠标, 所以没有触摸屏的我也可以尝试一下其大多数的功能.



首次尝试的步骤:

1、加 TGestureManager 控件如窗体: GestureManager1;

2、设置窗体属性 Touch.GestureManager := GestureManager1; {下面程序是在设计时指定的属性}

3、添加窗体的 OnGesture 事件, 随便写点什么;

4、然后运行程序, 用鼠标随便在窗体上 "划" 几下... 第一个测试程序完成了!

测试代码:

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, GestureMgr;type  TForm1 = class(TForm)    GestureManager1: TGestureManager;    procedure FormCreate(Sender: TObject);    procedure FormGesture(Sender: TObject; const EventInfo: TGestureEventInfo;      var Handled: Boolean);  end;var  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin  Self.Touch.GestureManager := GestureManager1; {可在设计时指定}end;procedure TForm1.FormGesture(Sender: TObject;  const EventInfo: TGestureEventInfo; var Handled: Boolean);begin  ShowMessage(Sender.ClassName + '_Gesture');end;end.

现在程序可以 "感知手势" 了, 怎么 "识别手势" 呢? 

Delphi 把可以识别的手势分成了 3 类: 标准手势、自定义手势、交互手势(InteractiveGestures).

其中的交互手势用鼠标不好模拟, 可能只能用于触摸屏;

Delphi 预定义了 34 种标准手势, 并定义成 TStandardGesture 枚举类型:
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);

注意: 每个枚举项都对应了一个常数值(譬如: 枚举项 sgLeft 对应 sgiLeft, sgiLeft 是之前定义好的常数);

应记下常数的命名规律, 后面会经常用到它们, 以区别触发的是哪个手势, 譬如:

if EventInfo.GestureID = sgiLeft then ...

下面是从 docwiki.embarcadero.com/RADStudio/en/TStandardGesture_Enum 拷过来的标准手势的图示:

EnumSymbolsgLeftimage:64GestLeft.gifsgRightimage:64GestRight.gifsgUpimage:64GestUp.gifsgDownimage:64GestDown.gifsgUpLeftimage:64GestUpLeft.gifsgUpRightimage:64GestUpRight.gifsgDownLeftimage:64GestDownLeft.gifsgDownRightimage:64GestDownRight.gifsgLeftUpimage:64GestLeftUp.gifsgLeftDownimage:64GestLeftDown.gifsgRightUpimage:64GestRightUp.gifsgRightDownimage:64GestRightDown.gifsgUpDownimage:64GestUpDown.gifsgDownUpimage:64GestDownUp.gifsgLeftRightimage:64GestLeftRight.gifsgRightLeftimage:64GestRightLeft.gifsgUpLeftLongimage:64GestUpLeftLong.gifsgUpRightLongimage:64GestUpRightLong.gifsgDownLeftLongimage:64GestDownLeftLong.gifsgDownRightLongimage:64GestDownRightLong.gifsgScratchoutimage:64GestScratchOut.gifsgTriangleimage:64GestTriangle.gifsgSquareimage:64GestSquare.gifsgCheckimage:64GestCheck.gifsgCurlicueimage:64GestCurlicue.gifsgDoubleCurlicueimage:64GestDoubleCurlicue.gifsgCircleimage:64GestCircle.gifsgDoubleCircleimage:64GestDoubleCircle.gifsgSemiCircleLeftimage:64GestSemiCircleLeft.gifsgSemiCircleRightimage:64GestSemiCircleRight.gifsgChevronUpimage:64GestChevronUp.gifsgChevronDownimage:64GestChevronDown.gifsgChevronLeftimage:64GestChevronLeft.gifsgChevronRightimage:64GestChevronRight.gif

原创粉丝点击