I have recently modified a fork of the vmulti project https://github.com/djpnewton/vmulti locally to work in Windows 10 with VS2019 Community, and have made some improvements to it including adding tip and barrel pressure to the HID report for the pen, as well as support for up to 4 joysticks, so that I can pass through mouse/keyboard/touch/pen/joystick events to another system over TCP/IP via a server that I have already written in C++.
I am writing a UI for it now and will either use Win32 C++ with Xaml Islands or will use UWP, both will consume a Xaml UserControl from a separate UWP dll project.
I want to use UWP InkCanvas with pen/touch/mouse to only collect strokes, I do not want strokes displayed on the screen at all if possible.
Right now my code looks like this:
MainScreen::MainScreen()
{
InitializeComponent();
this->inkCanvas1->InkPresenter->InputDeviceTypes = Windows::UI::Core::CoreInputDeviceTypes::Mouse | Windows::UI::Core::CoreInputDeviceTypes::Pen | Windows::UI::Core::CoreInputDeviceTypes::Touch;
this->inkCanvas1->InkPresenter->StrokeInput->InkPresenter->InputProcessingConfiguration->Mode = Windows::UI::Input::Inking::InkInputProcessingMode::Erasing;
this->inkCanvas1->InkPresenter->InputProcessingConfiguration->Mode = Windows::UI::Input::Inking::InkInputProcessingMode::Erasing;
this->inkCanvas1->InkPresenter->StrokeInput->StrokeStarted += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Input::Inking::InkStrokeInput^, Windows::UI::Core::PointerEventArgs^>(this, &VMulti_UI_Xaml::MainScreen::OnStrokeStarted);
this->inkCanvas1->InkPresenter->StrokeInput->StrokeContinued += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Input::Inking::InkStrokeInput^, Windows::UI::Core::PointerEventArgs^>(this, &VMulti_UI_Xaml::MainScreen::OnStrokeContinued);
this->inkCanvas1->InkPresenter->StrokeInput->StrokeEnded += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Input::Inking::InkStrokeInput^, Windows::UI::Core::PointerEventArgs^>(this, &VMulti_UI_Xaml::MainScreen::OnStrokeEnded);
this->inkCanvas1->Opacity = 0.002;
Windows::UI::Input::Inking::InkDrawingAttributes^ drawingAttributes = inkCanvas1->InkPresenter->CopyDefaultDrawingAttributes();
drawingAttributes->DrawAsHighlighter = true;
Windows::UI::Color color1 = Windows::UI::Color();
color1.R = 0;
color1.G = 0;
color1.B = 0;
color1.A = 0;
drawingAttributes->Color = color1;
Windows::Foundation::Size size1 = drawingAttributes->Size;
size1.Width = 0.0;
size1.Height = 0.0;
drawingAttributes->Size = size1;
inkCanvas1->InkPresenter->UpdateDefaultDrawingAttributes(drawingAttributes);
}
void VMulti_UI_Xaml::MainScreen::OnStrokeStarted(Windows::UI::Input::Inking::InkStrokeInput^ sender, Windows::UI::Core::PointerEventArgs^ args)
{
std::wcout << "Stroke Started: " << args->CurrentPoint->Position.X << "," << args->CurrentPoint->Position.Y << std::endl;
args->Handled = true;
inkCanvas1->InkPresenter->StrokeContainer->Clear();
}
void VMulti_UI_Xaml::MainScreen::OnStrokeContinued(Windows::UI::Input::Inking::InkStrokeInput^ sender, Windows::UI::Core::PointerEventArgs^ args)
{
std::wcout << "Stroke Continued: " << args->CurrentPoint->Position.X << "," << args->CurrentPoint->Position.Y << std::endl;
args->Handled = true;
inkCanvas1->InkPresenter->StrokeContainer->Clear();
}
void VMulti_UI_Xaml::MainScreen::OnStrokeEnded(Windows::UI::Input::Inking::InkStrokeInput^ sender, Windows::UI::Core::PointerEventArgs^ args)
{
std::wcout << "Stroke Ended: " << args->CurrentPoint->Position.X << "," << args->CurrentPoint->Position.Y << std::endl;
args->Handled = true;
inkCanvas1->InkPresenter->StrokeContainer->Clear();
}
This is almost good enough, but the current stroke you're drawing still displays. I want that gone too. Settings Handled to true on stroke events for the StrokeInput doesn't do anything to keep strokes from being drawn. Clearing strokes on each event clears everything but the current stroke you're drawing, which I want gone too. Displaying the Opacity for the InkCanvas to anything below 0.002 seems to make events somehow not fire.
So I would like to know, how can I get rid of all drawn strokes including the one being currently drawn on an InkCanvas? I am only passing through the capture events, I do not want to draw on the screen.
Found it, like as is the case sometimes with .NET things, you can't just make certain calls after InitializeComponent(), you have to wait until Loaded, the updated code below will hide the current ink.
Updated Code:
MainScreen::MainScreen()
{
InitializeComponent();
this->inkCanvas1->InkPresenter->InputDeviceTypes = Windows::UI::Core::CoreInputDeviceTypes::Mouse | Windows::UI::Core::CoreInputDeviceTypes::Pen | Windows::UI::Core::CoreInputDeviceTypes::Touch;
this->inkCanvas1->InkPresenter->StrokeInput->InkPresenter->InputProcessingConfiguration->Mode = Windows::UI::Input::Inking::InkInputProcessingMode::Erasing;
this->inkCanvas1->InkPresenter->InputProcessingConfiguration->Mode = Windows::UI::Input::Inking::InkInputProcessingMode::Erasing;
this->inkCanvas1->InkPresenter->StrokeInput->StrokeStarted += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Input::Inking::InkStrokeInput^, Windows::UI::Core::PointerEventArgs^>(this, &VMulti_UI_Xaml::MainScreen::OnStrokeStarted);
this->inkCanvas1->InkPresenter->StrokeInput->StrokeContinued += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Input::Inking::InkStrokeInput^, Windows::UI::Core::PointerEventArgs^>(this, &VMulti_UI_Xaml::MainScreen::OnStrokeContinued);
this->inkCanvas1->InkPresenter->StrokeInput->StrokeEnded += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Input::Inking::InkStrokeInput^, Windows::UI::Core::PointerEventArgs^>(this, &VMulti_UI_Xaml::MainScreen::OnStrokeEnded);
this->inkCanvas1->Opacity = 0.002;
this->Loaded += ref new Windows::UI::Xaml::RoutedEventHandler(this, &VMulti_UI_Xaml::MainScreen::OnLoaded);
}
void VMulti_UI_Xaml::MainScreen::OnLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Windows::UI::Input::Inking::InkDrawingAttributes^ drawingAttributes = inkCanvas1->InkPresenter->CopyDefaultDrawingAttributes();
drawingAttributes->DrawAsHighlighter = true;
Windows::UI::Color color1 = Windows::UI::Color();
color1.R = 0;
color1.G = 0;
color1.B = 0;
color1.A = 0;
drawingAttributes->Color = color1;
Windows::Foundation::Size size1 = drawingAttributes->Size;
size1.Width = 0.001;
size1.Height = 0.001;
drawingAttributes->Size = size1;
inkCanvas1->InkPresenter->UpdateDefaultDrawingAttributes(drawingAttributes);
inkCanvas1->InkPresenter->InputConfiguration->IsEraserInputEnabled = true;
}