//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop

#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TFlyoutDemoForm *FlyoutDemoForm;
//---------------------------------------------------------------------------
__fastcall TFlyoutDemoForm::TFlyoutDemoForm(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFlyoutDemoForm::FormGesture(TObject *Sender, const TGestureEventInfo &EventInfo,
          bool &Handled)
{
	float DX, DY;

	if (EventInfo.GestureID == igiPan) {
		if (EventInfo.Flags.Contains(TInteractiveGestureFlag::gfBegin)
		  && (Sender == ToolbarPopup || EventInfo.Location.Y > (ClientHeight - 70))) {
			FGestureOrigin = EventInfo.Location;
			FGestureInProgress = true;
		}
	}

	if (FGestureInProgress && EventInfo.Flags.Contains(TInteractiveGestureFlag::gfEnd)) {
		FGestureInProgress = false;
		DX = EventInfo.Location.X - FGestureOrigin.X;
		DY = EventInfo.Location.Y - FGestureOrigin.Y;
		if (fabs(DY) > fabs(DX)) {
			ShowToolbar(DY < 0);
		}
	}
}
//---------------------------------------------------------------------------
void TFlyoutDemoForm::ShowToolbar(bool AShow)
{
  ToolbarPopup->Width = ClientWidth;
  ToolbarPopup->PlacementRectangle->Rect = TRect(0, ClientHeight-ToolbarPopup->Height, ClientWidth-1, ClientHeight-1);
  ToolbarPopupAnimation->StartValue = ToolbarPopup->Height;
  ToolbarPopupAnimation->StopValue = 0;

  ToolbarPopup->IsOpen = AShow;
}
//---------------------------------------------------------------------------
void __fastcall TFlyoutDemoForm::FormKeyDown(TObject *Sender, WORD &Key, System::WideChar &KeyChar,
          TShiftState Shift)
{
  if (Key == vkEscape) {
	  ShowToolbar(!ToolbarPopup->IsOpen);
  }
}
//---------------------------------------------------------------------------
void __fastcall TFlyoutDemoForm::ToolbarCloseButtonClick(TObject *Sender)
{
	Application->Terminate();
}
//---------------------------------------------------------------------------

void TFlyoutDemoForm::ShowExitFlyout(bool AShow)
{
  ExitFlyoutAnimation->StartValue = ClientWidth;
  ExitFlyoutAnimation->StopValue = Width/2 - ExitFlyout->Width/2;
  ExitFlyout->IsOpen = AShow;
}

void TFlyoutDemoForm::ShowCalendarFlyout(bool AShow)
{
  CalendarFlyoutAnimation->StartValue = ClientWidth;
  CalendarFlyoutAnimation->StopValue = Width/2 - CalendarFlyout->Width/2;
  CalendarFlyout->IsOpen = AShow;
}

void __fastcall TFlyoutDemoForm::CheckCalendarButtonClick(TObject *Sender)
{
  ShowCalendarFlyout(true);
}
//---------------------------------------------------------------------------

void __fastcall TFlyoutDemoForm::CalendarCloseButtonClick(TObject *Sender)
{
  ShowCalendarFlyout(false);
}
//---------------------------------------------------------------------------

void __fastcall TFlyoutDemoForm::CloseAppButtonClick(TObject *Sender)
{
  ShowExitFlyout(true);
}
//---------------------------------------------------------------------------

void __fastcall TFlyoutDemoForm::ReallyCloseButtonClick(TObject *Sender)
{
  Application->Terminate();
}
//---------------------------------------------------------------------------

