Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Multi-touch using the TTrackBar in C++Builder FireMonkey(iOS)
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include "uMain_touchbar_20170227.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
for (int i=0; i < 4; i++)
{
UnicodeString s = (std::to_string(i+1)).c_str();
trackBars[i] = static_cast<TTrackBar* >(this->FindComponent("TrackBar" + s ));
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormTouch(TObject *Sender, const TTouches Touches, const TTouchAction Action)
{
for (int i=0; i< Touches.Length; i++)
for (auto tb_: trackBars)
if ((Touches[i].Location.Y >= tb_->Position->Y) &&
(Touches[i].Location.Y <= (tb_->Position->Y + tb_->Height + 50)) &&
(Touches[i].Location.X >= tb_->Position->X) &&
(Touches[i].Location.X <= (tb_->Position->X + tb_->Width)) )
tb_->Value = Touches[i].Location.X - tb_->Position->X;
}
//---------------------------------------------------------------------------
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 480
ClientWidth = 640
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
OnTouch = FormTouch
DesignerMasterStyle = 2
object Label1: TLabel
Align = Top
Size.Width = 640.000000000000000000
Size.Height = 25.000000000000000000
Size.PlatformDefault = False
Text = 'Multi touch TrackBar'
end
object Layout1: TLayout
Align = Top
Position.Y = 25.000000000000000000
Size.Width = 640.000000000000000000
Size.Height = 352.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
object TrackBar1: TTrackBar
CanParentFocus = True
HitTest = False
Max = 350.000000000000000000
Orientation = Horizontal
Position.X = 10.000000000000000000
Position.Y = 10.000000000000000000
Size.Width = 350.000000000000000000
Size.Height = 36.000000000000000000
Size.PlatformDefault = False
TabOrder = 3
end
object TrackBar2: TTrackBar
CanParentFocus = True
HitTest = False
Max = 350.000000000000000000
Orientation = Horizontal
Position.X = 10.000000000000000000
Position.Y = 100.000000000000000000
Size.Width = 350.000000000000000000
Size.Height = 36.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
end
object TrackBar3: TTrackBar
CanParentFocus = True
HitTest = False
Max = 350.000000000000000000
Orientation = Horizontal
Position.X = 10.000000000000000000
Position.Y = 200.000000000000000000
Size.Width = 350.000000000000000000
Size.Height = 36.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
end
object TrackBar4: TTrackBar
CanParentFocus = True
HitTest = False
Max = 350.000000000000000000
Orientation = Horizontal
Position.X = 10.000000000000000000
Position.Y = 300.000000000000000000
Size.Width = 350.000000000000000000
Size.Height = 36.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
end
end
object ToolBar1: TToolBar
Align = Bottom
Position.Y = 436.000000000000000000
Size.Width = 640.000000000000000000
Size.Height = 44.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
object Label2: TLabel
Align = Center
Size.Width = 640.000000000000000000
Size.Height = 44.000000000000000000
Size.PlatformDefault = False
TextSettings.HorzAlign = Center
Text = 'C++Builder'
end
end
end
//---------------------------------------------------------------------------
#ifndef uMain_touchbar_20170227H
#define uMain_touchbar_20170227H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Layouts.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
#include <array>
#include <string>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE で管理されるコンポーネント
TLabel *Label1;
TLayout *Layout1;
TTrackBar *TrackBar1;
TTrackBar *TrackBar2;
TTrackBar *TrackBar3;
TTrackBar *TrackBar4;
TToolBar *ToolBar1;
TLabel *Label2;
void __fastcall FormTouch(TObject *Sender, const TTouches Touches, const TTouchAction Action);
private:
public:
std::array<TTrackBar* ,4> trackBars;
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment