C++ whiteboard
-
2012년 8월 8일 수요일 오전 1:52
How do you create a whiteboard application using C++.
모든 응답
-
2012년 8월 9일 목요일 오전 11:48중재자
Hello,
Do you want to write an app like draw with mouse?
If so, we can use a Canvas and use PointerMoved event and PointerPressed event to add mouse points to a line and add this line to canvas' children. There is the xaml file<Canvas x:Name="Scenario1OutputRoot" Background="White" Height="300" Width="500" PointerMoved="Scenario1OutputRoot_PointerMoved" PointerPressed="Scenario1OutputRoot_PointerPressed" PointerReleased="Scenario1OutputRoot_PointerReleased"/>
Here the cpp file
// MainPage.xaml.h const int SUPPORTEDCONTACTS = 5; const double STROKETHICKNESS = 5; public ref class MainPage sealed { private: int numActiveContacts; Platform::Collections::Map<int, Windows::Foundation::Point>^ contacts; // ManiPage.xaml.cpp double Distance(Point currentContact, Point previousContact) { return std::sqrt(std::pow(currentContact.X - previousContact.X, 2) + std::pow(currentContact.Y - previousContact.Y, 2)); } void Drawpath::MainPage::Scenario1OutputRoot_PointerMoved(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) { Windows::UI::Input::PointerPoint^ pt = e->GetCurrentPoint(Scenario1OutputRoot); int ptrId = pt->PointerId; if (contacts->HasKey(ptrId) ) { Point currentContact = pt->Position; Point previousContact = contacts->Lookup(ptrId); if (Distance(currentContact, previousContact) > 4) { Windows::UI::Xaml::Shapes::Line^ l = ref new Windows::UI::Xaml::Shapes::Line(); l->X1 = previousContact.X; l->Y1 = previousContact.Y; l->X2 = currentContact.X; l->Y2 = currentContact.Y; l->StrokeThickness = STROKETHICKNESS; l->Stroke = ref new SolidColorBrush(Windows::UI::Colors::Red); l->StrokeEndLineCap = PenLineCap::Round; contacts->Insert(ptrId,currentContact); Scenario1OutputRoot->Children->Append(l); } } e->Handled = true; } void Drawpath::MainPage::Scenario1OutputRoot_PointerPressed(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) { if (numActiveContacts >= SUPPORTEDCONTACTS) { // cannot support more contacts return; } Windows::UI::Input::PointerPoint^ pt = e->GetCurrentPoint(Scenario1OutputRoot); contacts->Insert(pt->PointerId, pt->Position); e->Handled= true; ++numActiveContacts; } void Drawpath::MainPage::Scenario1OutputRoot_PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) { int ptrId = e->GetCurrentPoint((FrameworkElement^)sender)->PointerId; if (contacts->HasKey(ptrId)) { contacts->Remove(ptrId); --numActiveContacts; } e->Handled = true; }
Best regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us
- 답변으로 표시됨 Jesse JiangMicrosoft Contingent Staff, Moderator 2012년 8월 13일 월요일 오전 8:35

