From 3f922d8b646e66c0a2442add8389cd61b5c35973 Mon Sep 17 00:00:00 2001 From: JimMarlowe Date: Sun, 25 Jun 2017 09:47:29 -0700 Subject: [PATCH] Turbobadger Widget updates --- Script/Packages/Atomic/UI.json | 2 +- Source/Atomic/UI/UI.cpp | 30 ++++-- Source/Atomic/UI/UIInlineSelect.cpp | 16 +++ Source/Atomic/UI/UIInlineSelect.h | 4 + Source/Atomic/UI/UIRadioButton.cpp | 56 ++++++++++ Source/Atomic/UI/UIRadioButton.h | 48 +++++++++ Source/Atomic/UI/UIScrollBar.cpp | 101 ++++++++++++++++++ Source/Atomic/UI/UIScrollBar.h | 53 +++++++++ Source/Atomic/UI/UISlider.cpp | 18 ++++ Source/Atomic/UI/UISlider.h | 2 + .../TurboBadger/tb_inline_select.cpp | 15 ++- .../ThirdParty/TurboBadger/tb_inline_select.h | 9 ++ .../TurboBadger/tb_widgets_reader.cpp | 17 +++ 13 files changed, 361 insertions(+), 10 deletions(-) create mode 100644 Source/Atomic/UI/UIRadioButton.cpp create mode 100644 Source/Atomic/UI/UIRadioButton.h create mode 100644 Source/Atomic/UI/UIScrollBar.cpp create mode 100644 Source/Atomic/UI/UIScrollBar.h diff --git a/Script/Packages/Atomic/UI.json b/Script/Packages/Atomic/UI.json index f1d340d1a9..fd072ad56b 100755 --- a/Script/Packages/Atomic/UI.json +++ b/Script/Packages/Atomic/UI.json @@ -10,7 +10,7 @@ "UISkinImage", "UITabContainer", "UISceneView", "UIPreferredSize", "UIDragObject", "UIContainer", "UISection", "UIInlineSelect", "UITextureWidget", "UIColorWidget", "UIColorWheel", "UIScrollContainer", "UISeparator", "UIDimmer", "UISelectDropdown", "UISlider", "UIBargraph", - "UIPromptWindow", "UIFinderWindow", "UIPulldownMenu"], + "UIPromptWindow", "UIFinderWindow", "UIPulldownMenu", "UIRadioButton", "UIScrollBar"], "overloads" : { }, "typescript_decl" : { diff --git a/Source/Atomic/UI/UI.cpp b/Source/Atomic/UI/UI.cpp index 930dbacbb3..f572844ab7 100644 --- a/Source/Atomic/UI/UI.cpp +++ b/Source/Atomic/UI/UI.cpp @@ -93,6 +93,8 @@ using namespace tb; #include "UIFinderWindow.h" #include "UIPulldownMenu.h" #include "UIComponent.h" +#include "UIRadioButton.h" +#include "UIScrollBar.h" #include "SystemUI/SystemUI.h" #include "SystemUI/SystemUIEvents.h" @@ -150,12 +152,12 @@ UI::~UI() TBFile::SetReaderFunction(0); TBID::tbidRegisterCallback = 0; - + tb::TBWidgetsAnimationManager::Shutdown(); delete rootWidget_; widgetWrap_.Clear(); - + // leak //delete TBUIRenderer::renderer_; @@ -355,7 +357,7 @@ void UI::SetFocusedView(UIView* uiView) while (itr != uiViews_.End()) { if ((*itr)->GetAutoFocus()) - { + { SetFocusedView(*itr); return; } @@ -476,7 +478,7 @@ void UI::HandleUpdate(StringHash eventType, VariantMap& eventData) exitRequested_ = false; return; } - + tooltipHoverTime_ += eventData[Update::P_TIMESTEP].GetFloat(); if (tooltipHoverTime_ >= 0.5f) @@ -504,7 +506,7 @@ void UI::HandleUpdate(StringHash eventType, VariantMap& eventData) tooltip_->Show(mousePosition.x_ + 8, mousePosition.y_ + 8); } } - else + else { if (tooltip_) tooltip_->Close(); } @@ -619,6 +621,14 @@ UIWidget* UI::WrapWidget(tb::TBWidget* widget) return slider; } + if (widget->IsOfType()) + { + UIScrollBar* slider = new UIScrollBar(context_, false); + slider->SetWidget(widget); + WrapWidget(slider, widget); + return slider; + } + if (widget->IsOfType()) { UIColorWidget* colorWidget = new UIColorWidget(context_, false); @@ -734,6 +744,14 @@ UIWidget* UI::WrapWidget(tb::TBWidget* widget) return nwidget; } + if (widget->IsOfType()) + { + UIRadioButton* nwidget = new UIRadioButton(context_, false); + nwidget->SetWidget(widget); + WrapWidget(nwidget, widget); + return nwidget; + } + if (widget->IsOfType()) { UIBargraph* nwidget = new UIBargraph(context_, false); @@ -757,7 +775,7 @@ UIWidget* UI::WrapWidget(tb::TBWidget* widget) WrapWidget(nwidget, widget); return nwidget; } - + if (widget->IsOfType()) { UIPromptWindow* nwidget = new UIPromptWindow(context_, NULL, "", false); diff --git a/Source/Atomic/UI/UIInlineSelect.cpp b/Source/Atomic/UI/UIInlineSelect.cpp index 89e0601b7b..5395423f94 100644 --- a/Source/Atomic/UI/UIInlineSelect.cpp +++ b/Source/Atomic/UI/UIInlineSelect.cpp @@ -68,6 +68,22 @@ void UIInlineSelect::SetLimits(double minimum, double maximum) } +// set the inc, dec step size +void UIInlineSelect::SetStepSize(double step) +{ + if (!widget_) + return; + ((TBInlineSelect*) widget_)->SetStepSize(step); +} + +// get the inc, dec step size +double UIInlineSelect::GetStepSize() +{ + if (!widget_) + return 0.0; + return ((TBInlineSelect*) widget_)->GetStepSize(); +} + bool UIInlineSelect::OnEvent(const tb::TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CUSTOM && ev.ref_id == TBIDC("edit_complete")) diff --git a/Source/Atomic/UI/UIInlineSelect.h b/Source/Atomic/UI/UIInlineSelect.h index 347fbf28d8..1e74c85479 100644 --- a/Source/Atomic/UI/UIInlineSelect.h +++ b/Source/Atomic/UI/UIInlineSelect.h @@ -39,6 +39,10 @@ class ATOMIC_API UIInlineSelect : public UIWidget void SetLimits(double minimum, double maximum); + /// set and get the inc, dec step size + void SetStepSize(double step); + double GetStepSize(); + void SetEditFieldLayoutParams(UILayoutParams* params); protected: diff --git a/Source/Atomic/UI/UIRadioButton.cpp b/Source/Atomic/UI/UIRadioButton.cpp new file mode 100644 index 0000000000..1e4a480b00 --- /dev/null +++ b/Source/Atomic/UI/UIRadioButton.cpp @@ -0,0 +1,56 @@ +// +// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#include +#include + +#include + +#include "UIEvents.h" +#include "UI.h" +#include "UIRadioButton.h" + +using namespace tb; + +namespace Atomic +{ + +UIRadioButton::UIRadioButton(Context* context, bool createWidget) : UIWidget(context, false) +{ + if (createWidget) + { + widget_ = new TBRadioButton(); + widget_->SetDelegate(this); + GetSubsystem()->WrapWidget(this, widget_); + } +} + +UIRadioButton::~UIRadioButton() +{ +} + +bool UIRadioButton::OnEvent(const tb::TBWidgetEvent &ev) +{ + return UIWidget::OnEvent(ev); +} + +} diff --git a/Source/Atomic/UI/UIRadioButton.h b/Source/Atomic/UI/UIRadioButton.h new file mode 100644 index 0000000000..459a03dab3 --- /dev/null +++ b/Source/Atomic/UI/UIRadioButton.h @@ -0,0 +1,48 @@ +// +// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#pragma once + +#include "UIWidget.h" + +namespace Atomic +{ + + +class ATOMIC_API UIRadioButton : public UIWidget +{ + ATOMIC_OBJECT(UIRadioButton, UIWidget) + +public: + + UIRadioButton(Context* context, bool createWidget = true); + virtual ~UIRadioButton(); + +protected: + + virtual bool OnEvent(const tb::TBWidgetEvent &ev); + +private: + +}; + +} diff --git a/Source/Atomic/UI/UIScrollBar.cpp b/Source/Atomic/UI/UIScrollBar.cpp new file mode 100644 index 0000000000..670a6562ee --- /dev/null +++ b/Source/Atomic/UI/UIScrollBar.cpp @@ -0,0 +1,101 @@ +// +// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#include +#include + +#include + +#include "UIEvents.h" +#include "UI.h" +#include "UILayout.h" +#include "UIScrollBar.h" + +using namespace tb; + +namespace Atomic +{ + +UIScrollBar::UIScrollBar(Context* context, bool createWidget) : UIWidget(context, false) +{ + if (createWidget) + { + widget_ = new TBScrollBar(); + widget_->SetDelegate(this); + GetSubsystem()->WrapWidget(this, widget_); + } +} + +UIScrollBar::~UIScrollBar() +{ + +} + +void UIScrollBar::SetLimits(double minimum, double maximum, double visible) +{ + if (!widget_) + return; + ((TBScrollBar*) widget_)->SetLimits(minimum, maximum, visible); + +} + +double UIScrollBar::GetMinValue() const +{ + if (!widget_) + return 0.0; + + return ((TBScrollBar*) widget_)->GetMinValue(); + +} + +double UIScrollBar::GetMaxValue() const +{ + if (!widget_) + return 0.0; + + return ((TBScrollBar*) widget_)->GetMaxValue(); + +} + +double UIScrollBar::GetVisible() const +{ + if (!widget_) + return 0.0; + + return ((TBScrollBar*) widget_)->GetVisible(); + +} + +bool UIScrollBar::OnEvent(const tb::TBWidgetEvent &ev) +{ + if (ev.type == EVENT_TYPE_CUSTOM && ev.ref_id == TBIDC("edit_complete")) + { + VariantMap eventData; + eventData[UIWidgetEditComplete::P_WIDGET] = this; + SendEvent(E_UIWIDGETEDITCOMPLETE, eventData); + + return true; + } + return UIWidget::OnEvent(ev); +} + +} diff --git a/Source/Atomic/UI/UIScrollBar.h b/Source/Atomic/UI/UIScrollBar.h new file mode 100644 index 0000000000..534c932f6b --- /dev/null +++ b/Source/Atomic/UI/UIScrollBar.h @@ -0,0 +1,53 @@ +// +// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#pragma once + +#include "UIWidget.h" + +namespace Atomic +{ + + +class ATOMIC_API UIScrollBar : public UIWidget +{ + ATOMIC_OBJECT(UIScrollBar, UIWidget) + +public: + + UIScrollBar(Context* context, bool createWidget = true); + virtual ~UIScrollBar(); + + void SetLimits(double minimum, double maximum, double visible); + double GetMinValue() const; + double GetMaxValue() const; + double GetVisible() const; + +protected: + + virtual bool OnEvent(const tb::TBWidgetEvent &ev); + +private: + +}; + +} diff --git a/Source/Atomic/UI/UISlider.cpp b/Source/Atomic/UI/UISlider.cpp index 7ae6b2d1f4..975fa591f9 100644 --- a/Source/Atomic/UI/UISlider.cpp +++ b/Source/Atomic/UI/UISlider.cpp @@ -58,6 +58,24 @@ void UISlider::SetLimits(double minimum, double maximum) } +double UISlider::GetMinValue() const +{ + if (!widget_) + return 0.0; + + return ((UISlider*) widget_)->GetMinValue(); + +} + +double UISlider::GetMaxValue() const +{ + if (!widget_) + return 0.0; + + return ((UISlider*) widget_)->GetMaxValue(); + +} + bool UISlider::OnEvent(const tb::TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CUSTOM && ev.ref_id == TBIDC("edit_complete")) diff --git a/Source/Atomic/UI/UISlider.h b/Source/Atomic/UI/UISlider.h index cf50df256e..3641fdb5cb 100644 --- a/Source/Atomic/UI/UISlider.h +++ b/Source/Atomic/UI/UISlider.h @@ -38,6 +38,8 @@ class ATOMIC_API UISlider : public UIWidget virtual ~UISlider(); void SetLimits(double minimum, double maximum); + double GetMinValue() const; + double GetMaxValue() const; protected: diff --git a/Source/ThirdParty/TurboBadger/tb_inline_select.cpp b/Source/ThirdParty/TurboBadger/tb_inline_select.cpp index 1c942a90d9..79934b4691 100755 --- a/Source/ThirdParty/TurboBadger/tb_inline_select.cpp +++ b/Source/ThirdParty/TurboBadger/tb_inline_select.cpp @@ -20,6 +20,9 @@ TBInlineSelect::TBInlineSelect() , m_min(0) , m_max(100) , m_modified(false) +// ATOMIC BEGIN + , m_stepsize(1.0) +// ATOMIC END { SetSkinBg(TBIDC("TBInlineSelect")); AddChild(&m_layout); @@ -112,14 +115,18 @@ bool TBInlineSelect::OnEvent(const TBWidgetEvent &ev) { if (ev.special_key == TB_KEY_UP || ev.special_key == TB_KEY_DOWN) { - double dv = ev.special_key == TB_KEY_UP ? 1 : -1; +// ATOMIC BEGIN + double dv = ev.special_key == TB_KEY_UP ? m_stepsize : -m_stepsize; +// ATOMIC END SetValueDouble(GetValueDouble() + dv); return true; } } else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("dec")) { - SetValueDouble(GetValueDouble() - 1); +// ATOMIC BEGIN + SetValueDouble(GetValueDouble() - m_stepsize); +// ATOMIC END if (!ev.target->IsCaptured()) { InvokeModifiedEvent(); @@ -129,7 +136,9 @@ bool TBInlineSelect::OnEvent(const TBWidgetEvent &ev) } else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("inc")) { - SetValueDouble(GetValueDouble() + 1); +// ATOMIC BEGIN + SetValueDouble(GetValueDouble() + m_stepsize); +// ATOMIC END if (!ev.target->IsCaptured()) { diff --git a/Source/ThirdParty/TurboBadger/tb_inline_select.h b/Source/ThirdParty/TurboBadger/tb_inline_select.h index 9a166fc765..31979aaa4a 100755 --- a/Source/ThirdParty/TurboBadger/tb_inline_select.h +++ b/Source/ThirdParty/TurboBadger/tb_inline_select.h @@ -36,6 +36,12 @@ class TBInlineSelect : public TBWidget, private TBWidgetListener double GetMinValue() const { return m_min; } double GetMaxValue() const { return m_max; } + // ATOMIC BEGIN + /// set the increment, decrement step size for clicking the buttons + void SetStepSize(double value) { m_stepsize = value; } + double GetStepSize() const { return m_stepsize; } + // ATOMIC END + virtual void SetValueDouble(double value) { SetValueInternal(value, true); } virtual double GetValueDouble() { return m_value; } @@ -54,6 +60,9 @@ class TBInlineSelect : public TBWidget, private TBWidgetListener double m_value; double m_min, m_max; bool m_modified; + // ATOMIC BEGIN + double m_stepsize; + // ATOMIC END void SetValueInternal(double value, bool update_text); diff --git a/Source/ThirdParty/TurboBadger/tb_widgets_reader.cpp b/Source/ThirdParty/TurboBadger/tb_widgets_reader.cpp index 1155c0cdc8..acb50b3c76 100755 --- a/Source/ThirdParty/TurboBadger/tb_widgets_reader.cpp +++ b/Source/ThirdParty/TurboBadger/tb_widgets_reader.cpp @@ -159,6 +159,7 @@ void TBButton::OnInflate(const INFLATE_INFO &info) SetToggleMode(info.node->GetValueInt("toggle-mode", GetToggleMode()) ? true : false); // ATOMIC BEGIN SetURL(info.node->GetValueString("url", "")); + SetSqueezable(info.node->GetValueInt("squeezable", GetSqueezable()) ? true : false); // ATOMIC END TBWidget::OnInflate(info); } @@ -169,6 +170,11 @@ void TBInlineSelect::OnInflate(const INFLATE_INFO &info) int min = info.node->GetValueInt("min", GetMinValue()); int max = info.node->GetValueInt("max", GetMaxValue()); SetLimits(min, max); + +// ATOMIC BEGIN + double m_stepsize = (double)info.node->GetValueFloat("stepsize", (float)GetStepSize()); +// ATOMIC END + TBWidget::OnInflate(info); } @@ -318,6 +324,12 @@ void TBScrollBar::OnInflate(const INFLATE_INFO &info) const char *axis = info.node->GetValueString("axis", "x"); SetAxis(*axis == 'x' ? AXIS_X : AXIS_Y); SetGravity(*axis == 'x' ? WIDGET_GRAVITY_LEFT_RIGHT : WIDGET_GRAVITY_TOP_BOTTOM); +// ATOMIC BEGIN + double min = (double)info.node->GetValueFloat("min", (float)GetMinValue()); + double max = (double)info.node->GetValueFloat("max", (float)GetMaxValue()); + double thumb = (double)info.node->GetValueFloat("thumb", (float)GetVisible()); // use thumb, visible is already used. + SetLimits(min, max, thumb); +// ATOMIC END TBWidget::OnInflate(info); } @@ -387,6 +399,11 @@ void TBTextField::OnInflate(const INFLATE_INFO &info) else if (!strcmp(text_align, "center")) SetTextAlign(TB_TEXT_ALIGN_CENTER); else if (!strcmp(text_align, "right")) SetTextAlign(TB_TEXT_ALIGN_RIGHT); } + +//ATOMIC BEGIN + SetSqueezable(info.node->GetValueInt("squeezable", GetSqueezable()) ? true : false); +//ATOMIC END + TBWidget::OnInflate(info); }