zoukankan      html  css  js  c++  java
  • Delphi 2010 新增功能之: 手势编程[1] 初识 TGestureManager


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

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

    首次尝试的步骤:

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

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

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

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

    测试代码:

    unit Unit1;
    
    interface
    
    uses
      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 拷过来的标准手势的图示:

    Enum Symbol
    sgLeft image:64GestLeft.gif
    sgRight image:64GestRight.gif
    sgUp image:64GestUp.gif
    sgDown image:64GestDown.gif
    sgUpLeft image:64GestUpLeft.gif
    sgUpRight image:64GestUpRight.gif
    sgDownLeft image:64GestDownLeft.gif
    sgDownRight image:64GestDownRight.gif
    sgLeftUp image:64GestLeftUp.gif
    sgLeftDown image:64GestLeftDown.gif
    sgRightUp image:64GestRightUp.gif
    sgRightDown image:64GestRightDown.gif
    sgUpDown image:64GestUpDown.gif
    sgDownUp image:64GestDownUp.gif
    sgLeftRight image:64GestLeftRight.gif
    sgRightLeft image:64GestRightLeft.gif
    sgUpLeftLong image:64GestUpLeftLong.gif
    sgUpRightLong image:64GestUpRightLong.gif
    sgDownLeftLong image:64GestDownLeftLong.gif
    sgDownRightLong image:64GestDownRightLong.gif
    sgScratchout image:64GestScratchOut.gif
    sgTriangle image:64GestTriangle.gif
    sgSquare image:64GestSquare.gif
    sgCheck image:64GestCheck.gif
    sgCurlicue image:64GestCurlicue.gif
    sgDoubleCurlicue image:64GestDoubleCurlicue.gif
    sgCircle image:64GestCircle.gif
    sgDoubleCircle image:64GestDoubleCircle.gif
    sgSemiCircleLeft image:64GestSemiCircleLeft.gif
    sgSemiCircleRight image:64GestSemiCircleRight.gif
    sgChevronUp image:64GestChevronUp.gif
    sgChevronDown image:64GestChevronDown.gif
    sgChevronLeft image:64GestChevronLeft.gif
    sgChevronRight image:64GestChevronRight.gif


  • 相关阅读:
    Oracle 按一行里某个字段里的值分割成多行进行展示
    Property or method "openPageOffice" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by
    SpringBoot 项目启动 Failed to convert value of type 'java.lang.String' to required type 'cn.com.goldenwater.dcproj.dao.TacPageOfficePblmListDao';
    Maven 设置阿里镜像
    JS 日期格式化,留作参考
    JS 过滤数组里对象的某个属性
    原生JS实现简单富文本编辑器2
    Chrome控制台使用详解
    android权限(permission)大全
    不借助第三方网站四步实现手机网站转安卓APP
  • 原文地址:https://www.cnblogs.com/del/p/1587265.html
Copyright © 2011-2022 走看看