From 7548690c51de3edc284e90c5105af8c304f09e0d Mon Sep 17 00:00:00 2001 From: elasota Date: Sun, 16 Feb 2020 21:57:02 -0500 Subject: [PATCH] Fix up radio buttons, more editbox functionality. All blocking issues with UI should now be fixed. --- GpApp/GpApp.vcxproj | 1 + GpApp/HighScores.cpp | 3 ++ PortabilityLayer/PLCheckboxWidget.cpp | 38 +++++++++++++++++++++++ PortabilityLayer/PLCheckboxWidget.h | 3 ++ PortabilityLayer/PLCore.cpp | 4 +-- PortabilityLayer/PLDialogs.cpp | 8 ++++- PortabilityLayer/PLEditboxWidget.cpp | 25 +++++++++++++-- PortabilityLayer/PLEditboxWidget.h | 2 ++ PortabilityLayer/PLHacks.cpp | 5 +++ PortabilityLayer/PLHacks.h | 1 + PortabilityLayer/PLRadioButtonWidget.cpp | 38 +++++++++++++++++++++++ PortabilityLayer/PLRadioButtonWidget.h | 3 ++ PortabilityLayer/PortabilityLayer.vcxproj | 3 ++ Release.props | 12 +++++++ 14 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 Release.props diff --git a/GpApp/GpApp.vcxproj b/GpApp/GpApp.vcxproj index e06751d..d16900d 100644 --- a/GpApp/GpApp.vcxproj +++ b/GpApp/GpApp.vcxproj @@ -83,6 +83,7 @@ + diff --git a/GpApp/HighScores.cpp b/GpApp/HighScores.cpp index 97297ef..c720e58 100644 --- a/GpApp/HighScores.cpp +++ b/GpApp/HighScores.cpp @@ -397,6 +397,9 @@ Boolean TestHighScore (void) break; } } + + if (IsHighScoreForceTop()) + placing = 0; if (placing != -1) { diff --git a/PortabilityLayer/PLCheckboxWidget.cpp b/PortabilityLayer/PLCheckboxWidget.cpp index 2499db3..9c2442b 100644 --- a/PortabilityLayer/PLCheckboxWidget.cpp +++ b/PortabilityLayer/PLCheckboxWidget.cpp @@ -1,6 +1,7 @@ #include "PLCheckboxWidget.h" #include "PLStandardColors.h" #include "FontFamily.h" +#include "PLTimeTaggedVOSEvent.h" #include @@ -9,6 +10,7 @@ namespace PortabilityLayer CheckboxWidget::CheckboxWidget(const WidgetBasicState &state) : WidgetSpec(state) , m_text(state.m_text) + , m_haveMouseDown(false) { } @@ -69,4 +71,40 @@ namespace PortabilityLayer if (m_window) DrawControl(&m_window->m_surface); } + + WidgetHandleState_t CheckboxWidget::ProcessEvent(const TimeTaggedVOSEvent &evt) + { + if (m_haveMouseDown) + { + if (evt.IsLMouseUpEvent()) + { + m_haveMouseDown = false; + + const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent); + if (m_rect.Contains(pt)) + return WidgetHandleStates::kActivated; + else + return WidgetHandleStates::kIgnored; + } + + return WidgetHandleStates::kCaptured; + } + else + { + if (evt.IsLMouseDownEvent()) + { + const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent); + + if (m_rect.Contains(pt)) + { + m_haveMouseDown = true; + return WidgetHandleStates::kCaptured; + } + else + return WidgetHandleStates::kIgnored; + } + } + + return WidgetHandleStates::kIgnored; + } } diff --git a/PortabilityLayer/PLCheckboxWidget.h b/PortabilityLayer/PLCheckboxWidget.h index e0d8ad9..3038cb6 100644 --- a/PortabilityLayer/PLCheckboxWidget.h +++ b/PortabilityLayer/PLCheckboxWidget.h @@ -19,7 +19,10 @@ namespace PortabilityLayer void OnStateChanged() override; + WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt); + private: PascalStr<255> m_text; + bool m_haveMouseDown; }; } diff --git a/PortabilityLayer/PLCore.cpp b/PortabilityLayer/PLCore.cpp index 4cf7db4..7f6e4a2 100644 --- a/PortabilityLayer/PLCore.cpp +++ b/PortabilityLayer/PLCore.cpp @@ -810,12 +810,12 @@ void Window::DrawControls() } bool Window::IsHandlingTickEvents() -{ +{ return m_numTickReceivingWidgets > 0; } void Window::OnTick() -{ +{ if (m_numTickReceivingWidgets == 0) return; diff --git a/PortabilityLayer/PLDialogs.cpp b/PortabilityLayer/PLDialogs.cpp index 67193f4..de1c93a 100644 --- a/PortabilityLayer/PLDialogs.cpp +++ b/PortabilityLayer/PLDialogs.cpp @@ -1,5 +1,9 @@ #include "PLDialogs.h" + +#include "DialogManager.h" +#include "PLArrayView.h" #include "PLPasStr.h" +#include "PLEditboxWidget.h" DialogTextSubstitutions::DialogTextSubstitutions() @@ -78,7 +82,9 @@ void SetDialogItemText(THandle handle, const PLPasStr &str) void SelectDialogItemText(Dialog *dialog, int item, int firstSelChar, int lastSelCharExclusive) { - PL_NotYetImplemented_TODO("TextBox_Critical"); + PortabilityLayer::EditboxWidget *widget = static_cast(dialog->GetItems()[item - 1].GetWidget()); + widget->GetWindow()->FocusWidget(widget); + widget->SetSelection(firstSelChar, lastSelCharExclusive); } ModalFilterUPP NewModalFilterUPP(ModalFilterUPP func) diff --git a/PortabilityLayer/PLEditboxWidget.cpp b/PortabilityLayer/PLEditboxWidget.cpp index 0aae72c..f8ebaf9 100644 --- a/PortabilityLayer/PLEditboxWidget.cpp +++ b/PortabilityLayer/PLEditboxWidget.cpp @@ -166,6 +166,9 @@ namespace PortabilityLayer { if (evt.m_vosEvent.m_eventType == GpVOSEventTypes::kKeyboardInput) { + if (!m_hasFocus) + return WidgetHandleStates::kIgnored; + const GpKeyboardInputEvent &keyEvent = evt.m_vosEvent.m_event.m_keyboardInputEvent; if (keyEvent.m_eventType == GpKeyboardInputEventTypes::kAutoChar || keyEvent.m_eventType == GpKeyboardInputEventTypes::kDownChar) @@ -191,8 +194,6 @@ namespace PortabilityLayer { if (ch >= 0x20 && ch <= 0x7e) HandleCharacter(ch, keyEvent.m_repeatCount); - else if (ch == '\b') - HandleBackspace(keyEvent.m_repeatCount); return WidgetHandleStates::kDigested; } @@ -206,7 +207,7 @@ namespace PortabilityLayer { if (keyEvent.m_key.m_specialKey == GpKeySpecials::kBackspace) { - + HandleBackspace(keyEvent.m_repeatCount); return WidgetHandleStates::kDigested; } else if (keyEvent.m_key.m_specialKey == GpKeySpecials::kDelete) @@ -234,6 +235,24 @@ namespace PortabilityLayer return true; } + void EditboxWidget::SetSelection(size_t startChar, size_t endChar) + { + if (startChar > m_length) + startChar = m_length; + + if (endChar < startChar) + endChar = startChar; + + if (endChar > m_length) + endChar = m_length; + + m_selStartChar = startChar; + m_selEndChar = endChar; + + m_caratTimer = 0; + Redraw(); + } + void EditboxWidget::OnTick() { if (m_hasFocus) diff --git a/PortabilityLayer/PLEditboxWidget.h b/PortabilityLayer/PLEditboxWidget.h index c4e3e10..3a2cb3c 100644 --- a/PortabilityLayer/PLEditboxWidget.h +++ b/PortabilityLayer/PLEditboxWidget.h @@ -24,6 +24,8 @@ namespace PortabilityLayer bool HandlesTickEvents() const; + void SetSelection(size_t startChar, size_t endChar); + private: static const unsigned int kCaratBlinkRate = 20; diff --git a/PortabilityLayer/PLHacks.cpp b/PortabilityLayer/PLHacks.cpp index cf51230..3ae7ad3 100644 --- a/PortabilityLayer/PLHacks.cpp +++ b/PortabilityLayer/PLHacks.cpp @@ -19,3 +19,8 @@ bool IsRoomEditorDisabled() { return true; } + +bool IsHighScoreForceTop() +{ + return false; +} diff --git a/PortabilityLayer/PLHacks.h b/PortabilityLayer/PLHacks.h index 915700e..9b582d8 100644 --- a/PortabilityLayer/PLHacks.h +++ b/PortabilityLayer/PLHacks.h @@ -4,3 +4,4 @@ bool IsMacPlusGraphicBanned(); bool IsMacPlusSoundBanned(); bool IsHighScoreDisabled(); bool IsRoomEditorDisabled(); +bool IsHighScoreForceTop(); diff --git a/PortabilityLayer/PLRadioButtonWidget.cpp b/PortabilityLayer/PLRadioButtonWidget.cpp index e980c5c..a346392 100644 --- a/PortabilityLayer/PLRadioButtonWidget.cpp +++ b/PortabilityLayer/PLRadioButtonWidget.cpp @@ -1,6 +1,7 @@ #include "PLRadioButtonWidget.h" #include "PLStandardColors.h" #include "FontFamily.h" +#include "PLTimeTaggedVOSEvent.h" #include @@ -9,6 +10,7 @@ namespace PortabilityLayer RadioButtonWidget::RadioButtonWidget(const WidgetBasicState &state) : WidgetSpec(state) , m_text(state.m_text) + , m_haveMouseDown(false) { } @@ -68,4 +70,40 @@ namespace PortabilityLayer if (m_window) DrawControl(&m_window->m_surface); } + + WidgetHandleState_t RadioButtonWidget::ProcessEvent(const TimeTaggedVOSEvent &evt) + { + if (m_haveMouseDown) + { + if (evt.IsLMouseUpEvent()) + { + m_haveMouseDown = false; + + const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent); + if (m_rect.Contains(pt)) + return WidgetHandleStates::kActivated; + else + return WidgetHandleStates::kIgnored; + } + + return WidgetHandleStates::kCaptured; + } + else + { + if (evt.IsLMouseDownEvent()) + { + const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent); + + if (m_rect.Contains(pt)) + { + m_haveMouseDown = true; + return WidgetHandleStates::kCaptured; + } + else + return WidgetHandleStates::kIgnored; + } + } + + return WidgetHandleStates::kIgnored; + } } diff --git a/PortabilityLayer/PLRadioButtonWidget.h b/PortabilityLayer/PLRadioButtonWidget.h index 7840cbd..dc26f5b 100644 --- a/PortabilityLayer/PLRadioButtonWidget.h +++ b/PortabilityLayer/PLRadioButtonWidget.h @@ -19,7 +19,10 @@ namespace PortabilityLayer void OnStateChanged() override; + WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt); + private: PascalStr<255> m_text; + bool m_haveMouseDown; }; } diff --git a/PortabilityLayer/PortabilityLayer.vcxproj b/PortabilityLayer/PortabilityLayer.vcxproj index ee14890..475c36c 100644 --- a/PortabilityLayer/PortabilityLayer.vcxproj +++ b/PortabilityLayer/PortabilityLayer.vcxproj @@ -64,6 +64,7 @@ + @@ -73,6 +74,7 @@ + @@ -91,6 +93,7 @@ + diff --git a/Release.props b/Release.props new file mode 100644 index 0000000..73a3061 --- /dev/null +++ b/Release.props @@ -0,0 +1,12 @@ + + + + + + + + NDEBUG;%(PreprocessorDefinitions) + + + + \ No newline at end of file