Professional Documents
Culture Documents
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
#include "pch.h"
#include "1-InputEvents.xaml.h"
Scenario1::Scenario1()
{
InitializeComponent();
// gesture handlers
tapTarget->Tapped += ref new TappedEventHandler(this,
&Scenario1::target_Tapped);
tapTarget->DoubleTapped += ref new DoubleTappedEventHandler(this,
&Scenario1::target_DoubleTapped);
// A Holding event is sent whenever a finger or pen is pressed and held on top of
// an object.
// Once a small amount of time has elapsed, the event is sent with a HoldingState
// of the type HoldingState.Started, indicating that the held threshold has just
// been passed.
// When a finger has been lifted after a successful hold, a Holding event is sent
// with a HoldingState of Completed.
// If the user cancels the hold after it has been started, but before it completes,
// a Holding event is sent with a HoldingState of Canceled.
void Scenario1::target_Holding(Object^ sender, HoldingRoutedEventArgs^ e)
{
if (e->HoldingState == Windows::UI::Input::HoldingState::Started)
{
holdTarget->Background = ref new
SolidColorBrush(Windows::UI::Colors::DeepSkyBlue);
holdTargetText->Text = "Holding";
}
else if (e->HoldingState == Windows::UI::Input::HoldingState::Completed)
{
holdTarget->Background = ref new
SolidColorBrush(Windows::UI::Colors::LightGray);
holdTargetText->Text = "Held";
}
else
{
holdTarget->Background = ref new
SolidColorBrush(Windows::UI::Colors::LightGray);
holdTargetText->Text = "Hold Canceled";
}
}
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
#include "pch.h"
#include "3-DeviceCapabilities.xaml.h"
Scenario3::Scenario3()
{
InitializeComponent();
#include "pch.h"
#include "2-PointerPointProperties.xaml.h"
using namespace SDKTemplate;
Scenario2::Scenario2() : rootPage(SDKTemplate::MainPage::Current)
{
InitializeComponent();
// Determine if the point that entered the canvas is "in contact" with the
// screen (mouse button pressed, finger down, or pen down).
// This will be encountered if the user touches down in the app surface,
// drags their finger off of the app, and drags it back onto the app without
// lifting their finger.
if (currentPoint->IsInContact)
{
CreateOrUpdatePropertyPopUp(currentPoint);
}
}
// Create a popup if the pointer being moved is in contact with the screen
if (currentPoint->IsInContact)
{
CreateOrUpdatePropertyPopUp(currentPoint);
}
}
void Scenario2::CreateOrUpdatePropertyPopUp(Windows::UI::Input::PointerPoint^
currentPoint)
{
// Retrieve the properties that are common to all pointers
Platform::String^ pointerProperties = GetPointerProperties(currentPoint);
// Retrieve the properties that are specific to the device type associated
// with the current PointerPoint
Platform::String^ deviceSpecificProperties =
GetDeviceSpecificProperties(currentPoint);
Platform::String^
Scenario2::GetDeviceSpecificProperties(Windows::UI::Input::PointerPoint^
currentPoint)
{
Platform::String^ deviceSpecificProperties = "";
return deviceSpecificProperties;
}
return sb;
}
return sb;
}
return sb;
}
//
// Popup UI code below
//
void Scenario2::RenderPropertyPopUp(Platform::String^ pointerProperties,
Platform::String^ deviceSpecificProperties, Windows::UI::Input::PointerPoint^
currentPoint)
{
auto it = popups.find(currentPoint->PointerId);
if (it != popups.end())
{
auto tb = dynamic_cast<StackPanel^>(it->second);
TextBlock^ pointerText = dynamic_cast<TextBlock^>(tb->Children->GetAt(0));
pointerText->Text = pointerProperties;
TextBlock^ deviceSpecificText = dynamic_cast<TextBlock^>(tb->Children-
>GetAt(1));
deviceSpecificText->Text = deviceSpecificProperties;
}
else
{
StackPanel^ pointerPanel = ref new StackPanel();
TextBlock^ pointerText = ref new TextBlock();
pointerText->Text = pointerProperties;
pointerPanel->Children->Append(pointerText);
case Windows::Devices::Input::PointerDeviceType::Touch:
deviceSpecificText->Foreground = ref new
SolidColorBrush(Windows::UI::Colors::Green);
break;
case Windows::Devices::Input::PointerDeviceType::Pen:
deviceSpecificText->Foreground = ref new
SolidColorBrush(Windows::UI::Colors::Yellow);
break;
}
pointerPanel->Children->Append(deviceSpecificText);
popups[currentPoint->PointerId] = pointerPanel;
mainCanvas->Children->Append(popups[currentPoint->PointerId]);
}