フォームにTGestureManagerコンポーネントを配置します。
フォームにTRectangleコンポーネントを配置します。
FillプロパティのKindプロパティを「bkGradient」にします。
グラデーションになりました。
必要なら、FillプロパティのGradientプロパティから編集を選択して、グラデーションの設定をします。
フォームのTouchプロパティのInteractiveGesturesのigRotateにチェックを入れます。
フォームにFLastAngleフィールドを追加します。
type
TForm1 = class(TForm)
private
FLastAngle: Single;
FLastAngleフィールドは、ジェスチャで回転する前の角度を持ちます。
フォームのOnGestuerイベントを追加します。
procedure TForm1.FormGesture(Sender: TObject;
const EventInfo: TGestureEventInfo; var Handled: Boolean);
var
Control: IControl;
Rectangle: TRectangle;
begin
if EventInfo.GestureID = igiRotate then
begin
Control := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location));
if Control is TRectangle then
begin
Rectangle := Control as TRectangle;
if TInteractiveGestureFlag.gfBegin in EventInfo.Flags then
begin
FLastAngle := Rectangle.RotationAngle;
end
else
begin
Rectangle.RotationAngle := FLastAngle - (EventInfo.Angle * 180) / Pi;
end;
end;
end;
end;
OnGestuerイベントはジェスチャが行われたときに発生します。
引数のEventInfoはイベントの情報を保持しています。
EventInfoのGestureIDからジェスチャを識別します。
if EventInfo.GestureID = igiRotate then
EventInfoのLocationからジェスチャの行われた位置を取得し、ObjectAtPointメソッドで該当する位置にあるコントロールを取得します。
Control := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location));
EventInfoのFlagsでジェスチャの状態を取得します。
ジェスチャが開始されたときは、現在の角度をFLastAngleフィールドに保持します。
if TInteractiveGestureFlag.gfBegin in EventInfo.Flags then
begin
FLastAngle := Rectangle.RotationAngle;
end
回転されたときは、Rectangleの角度を更新します。
Rectangle.RotationAngle := FLastAngle - (EventInfo.Angle * 180) / Pi;
このエントリーは「C++Builder XE5 – Rotation Interactive Gesture」を参考にしました。