Browse Source

Turbobadger Widget updates

JimMarlowe 8 years ago
parent
commit
3f922d8b64

+ 1 - 1
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" : {

+ 24 - 6
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<TBScrollBar>())
+    {
+        UIScrollBar* slider = new UIScrollBar(context_, false);
+        slider->SetWidget(widget);
+        WrapWidget(slider, widget);
+        return slider;
+    }
+
     if (widget->IsOfType<TBColorWidget>())
     {
         UIColorWidget* colorWidget = new UIColorWidget(context_, false);
@@ -734,6 +744,14 @@ UIWidget* UI::WrapWidget(tb::TBWidget* widget)
         return nwidget;
     }
 
+    if (widget->IsOfType<TBRadioButton>())
+    {
+        UIRadioButton* nwidget = new UIRadioButton(context_, false);
+        nwidget->SetWidget(widget);
+        WrapWidget(nwidget, widget);
+        return nwidget;
+    }
+
     if (widget->IsOfType<TBBarGraph>())
     {
         UIBargraph* nwidget = new UIBargraph(context_, false);
@@ -757,7 +775,7 @@ UIWidget* UI::WrapWidget(tb::TBWidget* widget)
         WrapWidget(nwidget, widget);
         return nwidget;
     }
-    
+
     if (widget->IsOfType<TBPromptWindow>())
     {
         UIPromptWindow* nwidget = new UIPromptWindow(context_, NULL, "", false);

+ 16 - 0
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"))

+ 4 - 0
Source/Atomic/UI/UIInlineSelect.h

@@ -39,6 +39,10 @@ public:
 
     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:

+ 56 - 0
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 <TurboBadger/tb_widgets.h>
+#include <TurboBadger/tb_widgets_common.h>
+
+#include <Atomic/IO/Log.h>
+
+#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<UI>()->WrapWidget(this, widget_);
+    }
+}
+
+UIRadioButton::~UIRadioButton()
+{
+}
+
+bool UIRadioButton::OnEvent(const tb::TBWidgetEvent &ev)
+{
+    return UIWidget::OnEvent(ev);
+}
+
+}

+ 48 - 0
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:
+
+};
+
+}

+ 101 - 0
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 <TurboBadger/tb_widgets.h>
+#include <TurboBadger/tb_widgets_common.h>
+
+#include <Atomic/IO/Log.h>
+
+#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<UI>()->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);
+}
+
+}

+ 53 - 0
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:
+
+};
+
+}

+ 18 - 0
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"))

+ 2 - 0
Source/Atomic/UI/UISlider.h

@@ -38,6 +38,8 @@ public:
     virtual ~UISlider();
 
     void SetLimits(double minimum, double maximum);
+    double GetMinValue() const;
+    double GetMaxValue() const;
 
 protected:
 

+ 12 - 3
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()) {
 

+ 9 - 0
Source/ThirdParty/TurboBadger/tb_inline_select.h

@@ -36,6 +36,12 @@ public:
     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 @@ protected:
     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);
 

+ 17 - 0
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);
 }