mirror of https://github.com/axmolengine/axmol.git
added critical section
This commit is contained in:
parent
f42afaa6bb
commit
afa052c5c7
|
@ -46,6 +46,7 @@ using namespace Windows::UI::Xaml;
|
|||
using namespace Windows::UI::Xaml::Controls;
|
||||
using namespace Windows::UI::Xaml::Input;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::UI::ViewManagement;
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -86,6 +87,7 @@ void EditBoxWinRT::OpenXamlEditBox(Platform::String^ strText)
|
|||
// must create XAML element on main UI thread
|
||||
m_dispatcher.Get()->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]()
|
||||
{
|
||||
critical_section::scoped_lock lock(m_criticalSection);
|
||||
auto item = findXamlElement(m_panel.Get(), "cocos2d_editbox");
|
||||
if (item != nullptr)
|
||||
{
|
||||
|
@ -122,6 +124,9 @@ void EditBoxWinRT::OpenXamlEditBox(Platform::String^ strText)
|
|||
|
||||
if (m_flyout)
|
||||
{
|
||||
auto inputPane = InputPane::GetForCurrentView();
|
||||
m_hideKeyboardToken = inputPane->Hiding += ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(this, &EditBoxWinRT::HideKeyboard);
|
||||
|
||||
m_closedToken = m_flyout->Closed += ref new EventHandler<Platform::Object^>(this, &EditBoxWinRT::Closed);
|
||||
m_flyout->ShowAt(m_panel.Get());
|
||||
}
|
||||
|
@ -145,6 +150,11 @@ void EditBoxWinRT::Cancel(Platform::Object^ sender, Windows::UI::Xaml::RoutedEve
|
|||
RemoveControls();
|
||||
}
|
||||
|
||||
void EditBoxWinRT::HideKeyboard(Windows::UI::ViewManagement::InputPane^ inputPane, Windows::UI::ViewManagement::InputPaneVisibilityEventArgs^ args)
|
||||
{
|
||||
RemoveControls();
|
||||
}
|
||||
|
||||
void EditBoxWinRT::RemoveControls()
|
||||
{
|
||||
if (m_dispatcher.Get() && m_panel.Get())
|
||||
|
@ -152,15 +162,32 @@ void EditBoxWinRT::RemoveControls()
|
|||
// run on main UI thread
|
||||
m_dispatcher.Get()->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]()
|
||||
{
|
||||
m_flyout->Closed -= m_closedToken;
|
||||
m_doneButton->Click -= m_doneToken;
|
||||
m_cancelButton->Click -= m_cancelToken;
|
||||
m_doneButton = nullptr;
|
||||
m_cancelButton = nullptr;
|
||||
critical_section::scoped_lock lock(m_criticalSection);
|
||||
|
||||
if (m_doneButton != nullptr)
|
||||
{
|
||||
m_doneButton->Click -= m_doneToken;
|
||||
m_doneButton = nullptr;
|
||||
}
|
||||
|
||||
if (m_cancelButton != nullptr)
|
||||
{
|
||||
m_cancelButton->Click -= m_cancelToken;
|
||||
m_cancelButton = nullptr;
|
||||
}
|
||||
|
||||
m_textBox = nullptr;
|
||||
m_passwordBox = nullptr;
|
||||
m_flyout->Hide();
|
||||
m_flyout = nullptr;
|
||||
|
||||
if (m_flyout != nullptr)
|
||||
{
|
||||
m_flyout->Closed -= m_closedToken;
|
||||
m_flyout->Hide();
|
||||
m_flyout = nullptr;
|
||||
}
|
||||
|
||||
auto inputPane = InputPane::GetForCurrentView();
|
||||
inputPane->Hiding -= m_hideKeyboardToken;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -177,12 +204,9 @@ void EditBoxWinRT::RemoveTextBox()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EditBoxWinRT::SetupTextBox()
|
||||
{
|
||||
RemoveTextBox();
|
||||
|
||||
m_textBox = ref new TextBox;
|
||||
m_textBox->Text = m_strText;
|
||||
m_textBox->Name = "cocos2d_editbox_textbox";
|
||||
|
@ -199,7 +223,6 @@ void EditBoxWinRT::SetupTextBox()
|
|||
void EditBoxWinRT::SetupPasswordBox()
|
||||
{
|
||||
RemoveTextBox();
|
||||
|
||||
m_passwordBox = ref new PasswordBox();
|
||||
m_passwordBox->Password = m_strText;
|
||||
m_passwordBox->MinWidth = 200;
|
||||
|
@ -253,16 +276,6 @@ void EditBoxWinRT::SetInputScope(TextBox^ box, EditBox::InputMode inputMode)
|
|||
box->InputScope = inputScope;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EditBoxWinRT::OnGotFocusPassword(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ args)
|
||||
{
|
||||
m_passwordBox->Password = m_strText;
|
||||
m_passwordBox->SelectAll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EditBoxWinRT::QueueText()
|
||||
{
|
||||
m_strText = m_inputFlag == EditBox::InputFlag::PASSWORD ? m_passwordBox->Password : m_textBox->Text;
|
||||
|
|
|
@ -58,9 +58,7 @@ namespace ui {
|
|||
void Done(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
void Cancel(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
void Closed(Platform::Object^ sender, Platform::Object^ e);
|
||||
|
||||
|
||||
void OnGotFocusPassword(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ args);
|
||||
void HideKeyboard(Windows::UI::ViewManagement::InputPane^ inputPane, Windows::UI::ViewManagement::InputPaneVisibilityEventArgs^ args);
|
||||
|
||||
Platform::Agile<Windows::UI::Core::CoreDispatcher> m_dispatcher;
|
||||
Platform::Agile<Windows::UI::Xaml::Controls::Panel> m_panel;
|
||||
|
@ -75,14 +73,15 @@ namespace ui {
|
|||
Windows::Foundation::EventRegistrationToken m_doneToken;
|
||||
Windows::Foundation::EventRegistrationToken m_cancelToken;
|
||||
Windows::Foundation::EventRegistrationToken m_closedToken;
|
||||
Windows::Foundation::EventRegistrationToken m_hideKeyboardToken;
|
||||
|
||||
Concurrency::critical_section m_criticalSection;
|
||||
|
||||
Platform::String^ m_strText;
|
||||
Platform::String^ m_strPlaceholder;
|
||||
EditBox::InputMode m_inputMode;
|
||||
EditBox::InputFlag m_inputFlag;
|
||||
int m_maxLength;
|
||||
|
||||
};
|
||||
|
||||
class CC_GUI_DLL UIEditBoxImplWinrt : public EditBoxImpl
|
||||
|
|
Loading…
Reference in New Issue