Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Is there a way to add TGestureManager manually (in code) ?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Feb 4, 2016 1:23 PM Last Post By: Roar Grønmo
Roar Grønmo

Posts: 14
Registered: 2/15/10
Is there a way to add TGestureManager manually (in code) ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 11:31 AM
There are many examples in the forrums on how to add Gestures with the IDE, but I can't find any good examples adding a TGestureManager (or using an existing one) in code (programmatically).

Where am I wrong ?

No gesturing events get caught in the manual rectangle... in the "IDE" rectangle, everything seems ok...

Example:
Headderfile

//---------------------------------------------------------------------------
 
#ifndef GestureTestUnitH
#define GestureTestUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Memo.hpp>
#include <FMX.Objects.hpp>
#include <FMX.ScrollBox.hpp>
#include <FMX.Types.hpp>
#include <FMX.Gestures.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TRectangle *Rectangle1;
	TMemo *Memo1;
	TGestureManager *GestureManager1;
 
	void __fastcall Rectangle1Gesture(TObject *Sender, const TGestureEventInfo &EventInfo,
		  bool &Handled);
private:	// User declarations
//	TGestureManager *manualgestmanager;
public:		// User declarations
 
	TRectangle *manualrect;
 
	__fastcall void mangestevent(TObject *Sender, const TGestureEventInfo &EventInfo,
		bool &Handled);
 
 
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


cpp-file
//---------------------------------------------------------------------------
 
#include <fmx.h>
#pragma hdrstop
 
#include "GestureTestUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
 
	manualrect = new TRectangle(Owner);
//	manualgestmanager = new TGestureManager(Owner);
 
	manualrect->OnGesture = &mangestevent;
 
	manualrect->Touch->GestureManager=GestureManager1;
 
	manualrect->Position->X=20;
	manualrect->Position->Y=300;
	manualrect->Height=100;
	manualrect->Width=200;
 
	manualrect->Visible=true;
 
	this->AddObject(manualrect);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Rectangle1Gesture(TObject *Sender, const TGestureEventInfo &EventInfo,
		  bool &Handled)
{
	String s;
 
	if(GestureToIdent(EventInfo.GestureID, s))
	{
		Memo1->Lines->Add("1:"+IntToStr(EventInfo.GestureID)+":"+s);
		Handled = true;
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::mangestevent(TObject *Sender, const TGestureEventInfo &EventInfo,
	bool &Handled)
{
	String s;
	if(GestureToIdent(EventInfo.GestureID, s))
	{
		Memo1->Lines->Add("2:"+IntToStr(EventInfo.GestureID)+":"+s);
		Handled = true;
	}
}
 


FMX-file

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 495
  ClientWidth = 309
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  DesignerMasterStyle = 3
  object Rectangle1: TRectangle
    Touch.GestureManager = GestureManager1
    OnGesture = Rectangle1Gesture
    Align = Top
    Margins.Left = 20.000000000000000000
    Margins.Top = 20.000000000000000000
    Margins.Right = 20.000000000000000000
    Margins.Bottom = 20.000000000000000000
    Position.X = 20.000000000000000000
    Position.Y = 20.000000000000000000
    Size.Width = 269.000000000000000000
    Size.Height = 117.000000000000000000
    Size.PlatformDefault = False
  end
  object Memo1: TMemo
    Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
    DataDetectorTypes = []
    Align = Bottom
    Margins.Left = 20.000000000000000000
    Margins.Top = 20.000000000000000000
    Margins.Right = 20.000000000000000000
    Margins.Bottom = 20.000000000000000000
    Position.X = 20.000000000000000000
    Position.Y = 328.000000000000000000
    Size.Width = 269.000000000000000000
    Size.Height = 147.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 1
    Viewport.Width = 261.000000000000000000
    Viewport.Height = 139.000000000000000000
  end
  object GestureManager1: TGestureManager
    Sensitivity = 100.000000000000000000
    Left = 256
    Top = 256
    GestureData = <
      item
        Control = Rectangle1
        Collection = <
          item
            GestureID = sgiUp
          end
          item
            GestureID = sgiDown
          end>
      end>
  end
end
Roar Grønmo

Posts: 14
Registered: 2/15/10
Re: Is there a way to add TGestureManager manually (in code) ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 12:33 PM   in response to: Roar Grønmo in response to: Roar Grønmo
Well, coffee helps somewhat.

Didn't quite realize that the "Gestures" types are set in level with TTouchManager (Didn't find them at once, since o looked in the TGestureManager object.

Here is the change i did in the code, so my manual gestures fires for up and down gestures:

__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
 
	manualrect = new TRectangle(Owner);
//	manualgestmanager = new TGestureManager(Owner);
 
	manualrect->OnGesture = &mangestevent;
 
	manualrect->Touch->GestureManager=GestureManager1;
 
//Added this line:
//-----
	manualrect->Touch->StandardGestures=manualrect->Touch->StandardGestures<<
		TStandardGesture::sgUp<<
		TStandardGesture::sgDown;
//----
	manualrect->Position->X=20;
	manualrect->Position->Y=300;
	manualrect->Height=100;
	manualrect->Width=200;
 
	manualrect->Visible=true;
 
	this->AddObject(manualrect);
}
 


Additional question: Is TGestureManger a "global class", in terms... I do only need one - 1 - GestureManager - object per applikcation ?

Since GestureManager1 above works both for the "IDE" Rectangle and the manual Rectangle ?

RG

Roar Grønmo

Posts: 14
Registered: 2/15/10
Re: Is there a way to add TGestureManager manually (in code) ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 1:19 PM   in response to: Roar Grønmo in response to: Roar Grønmo
Yepp, even more coffee helps...

It doesn't seem significant if I have one or more GestureManager objects defined.

Some small changes to the code:

(Adding (activating) before commented codelines, adding a manually added TGestureManager "manualgestmanager".

GestureTestUnit.h

//---------------------------------------------------------------------------
 
#ifndef GestureTestUnitH
#define GestureTestUnitH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Memo.hpp>
#include <FMX.Objects.hpp>
#include <FMX.ScrollBox.hpp>
#include <FMX.Types.hpp>
#include <FMX.Gestures.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TRectangle *Rectangle1;
	TMemo *Memo1;
	TGestureManager *GestureManager1;
 
	void __fastcall Rectangle1Gesture(TObject *Sender, const TGestureEventInfo &EventInfo,
		  bool &Handled);
private:	// User declarations
	TGestureManager *manualgestmanager;
public:		// User declarations
 
	TRectangle *manualrect;
 
	__fastcall void mangestevent(TObject *Sender, const TGestureEventInfo &EventInfo,
		bool &Handled);
 
 
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
 
 


GestureTestUnit.cpp


//---------------------------------------------------------------------------
 
#include <fmx.h>
#pragma hdrstop
 
#include "GestureTestUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
 
	manualrect = new TRectangle(Owner);
	manualgestmanager = new TGestureManager(Owner);
 
	manualrect->OnGesture = &mangestevent;
 
	//manualrect->Touch->GestureManager=GestureManager1;
	manualrect->Touch->GestureManager=manualgestmanager;
 
	manualrect->Touch->StandardGestures=manualrect->Touch->StandardGestures<<
		TStandardGesture::sgUp<<
		TStandardGesture::sgDown;
 
	manualrect->Position->X=20;
	manualrect->Position->Y=300;
	manualrect->Height=100;
	manualrect->Width=200;
 
	manualrect->Visible=true;
 
	this->AddObject(manualrect);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Rectangle1Gesture(TObject *Sender, const TGestureEventInfo &EventInfo,
		  bool &Handled)
{
	String s;
 
	if(GestureToIdent(EventInfo.GestureID, s))
	{
		Memo1->Lines->Add("1:"+IntToStr(EventInfo.GestureID)+":"+s);
		Handled = true;
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::mangestevent(TObject *Sender, const TGestureEventInfo &EventInfo,
	bool &Handled)
{
	String s;
	if(GestureToIdent(EventInfo.GestureID, s))
	{
		Memo1->Lines->Add("2:"+IntToStr(EventInfo.GestureID)+":"+s);
		Handled = true;
	}
}
 


GestureTestUnit.fmx:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 495
  ClientWidth = 309
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  DesignerMasterStyle = 3
  object Rectangle1: TRectangle
    Touch.GestureManager = GestureManager1
    OnGesture = Rectangle1Gesture
    Align = Top
    Margins.Left = 20.000000000000000000
    Margins.Top = 20.000000000000000000
    Margins.Right = 20.000000000000000000
    Margins.Bottom = 20.000000000000000000
    Position.X = 20.000000000000000000
    Position.Y = 20.000000000000000000
    Size.Width = 269.000000000000000000
    Size.Height = 117.000000000000000000
    Size.PlatformDefault = False
  end
  object Memo1: TMemo
    Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
    DataDetectorTypes = []
    Align = Bottom
    Margins.Left = 20.000000000000000000
    Margins.Top = 20.000000000000000000
    Margins.Right = 20.000000000000000000
    Margins.Bottom = 20.000000000000000000
    Position.X = 20.000000000000000000
    Position.Y = 328.000000000000000000
    Size.Width = 269.000000000000000000
    Size.Height = 147.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 1
    Viewport.Width = 261.000000000000000000
    Viewport.Height = 139.000000000000000000
  end
  object GestureManager1: TGestureManager
    Sensitivity = 100.000000000000000000
    Left = 256
    Top = 256
    GestureData = <
      item
        Control = Rectangle1
        Collection = <
          item
            GestureID = sgiUp
          end
          item
            GestureID = sgiDown
          end>
      end>
  end
end


I hope this was helpful for someone. Sometimes there are significantly simple solutions for complex problems !!
Roar Grønmo

Posts: 14
Registered: 2/15/10
Re: Is there a way to add TGestureManager manually (in code) ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 1:23 PM   in response to: Roar Grønmo in response to: Roar Grønmo
I asked a question,

and I wasn't patient enough...

...or didn't look closely enough.

But I hope it will help someone else too...
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02