소스 검색

Exposing a few properties that are great for tweening on UIWidget.

Jay Sistar 9 년 전
부모
커밋
0b05db3aca
4개의 변경된 파일357개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 0
      Source/Atomic/UI/UIFontDescription.cpp
  2. 2 0
      Source/Atomic/UI/UIFontDescription.h
  3. 309 0
      Source/Atomic/UI/UIWidget.cpp
  4. 41 1
      Source/Atomic/UI/UIWidget.h

+ 5 - 0
Source/Atomic/UI/UIFontDescription.cpp

@@ -43,6 +43,11 @@ UIFontDescription::~UIFontDescription()
 
 }
 
+int UIFontDescription::GetSize()
+{
+    return desc_.GetSize();
+}
+
 void UIFontDescription::SetId(const String& id)
 {
     desc_.SetID(TBIDC(id.CString()));

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

@@ -36,6 +36,8 @@ public:
     UIFontDescription(Context* context);
     virtual ~UIFontDescription();
 
+    int GetSize();
+
     void SetId(const String& id);
     void SetSize(int size);
 

+ 309 - 0
Source/Atomic/UI/UIWidget.cpp

@@ -427,6 +427,315 @@ void UIWidget::SetFontDescription(UIFontDescription* fd)
 
 }
 
+void UIWidget::SetFontId(const String& fontId)
+{
+    if (!widget_)
+        return;
+
+    tb::TBFontDescription fd(widget_->GetFontDescription());
+    fd.SetID(fontId.CString());
+    widget_->SetFontDescription(fd);
+}
+
+void UIWidget::SetFontId(tb::uint32 fontId)
+{
+    if (!widget_)
+        return;
+
+    tb::TBFontDescription fd(widget_->GetFontDescription());
+    fd.SetID(fontId);
+    widget_->SetFontDescription(fd);
+}
+
+
+void UIWidget::SetFontSize(int size)
+{
+    if (!widget_)
+        return;
+
+    tb::TBFontDescription fd(widget_->GetFontDescription());
+    fd.SetSize(size);
+    widget_->SetFontDescription(fd);
+}
+
+int UIWidget::GetFontSize()
+{
+    if (!widget_)
+        return 0;
+
+    tb::TBFontDescription fd(widget_->GetFontDescription());
+    return fd.GetSize();
+}
+
+void UIWidget::SetLayoutWidth(int width)
+{
+    if (!widget_)
+        return;
+
+    tb::LayoutParams lp;
+
+    const tb::LayoutParams *oldLp(widget_->GetLayoutParams());
+    if (oldLp)
+        lp = *oldLp;
+
+    lp.SetWidth(width);
+    widget_->SetLayoutParams(lp);
+}
+
+int UIWidget::GetLayoutWidth()
+{
+    if (!widget_)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    const tb::LayoutParams *lp(widget_->GetLayoutParams());
+    if (!lp)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    return lp->pref_w;
+}
+
+void UIWidget::SetLayoutHeight(int height)
+{
+    if (!widget_)
+        return;
+
+    tb::LayoutParams lp;
+
+    const tb::LayoutParams *oldLp(widget_->GetLayoutParams());
+    if (oldLp)
+        lp = *oldLp;
+
+    lp.SetHeight(height);
+    widget_->SetLayoutParams(lp);
+}
+
+int UIWidget::GetLayoutHeight()
+{
+    if (!widget_)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    const tb::LayoutParams *lp(widget_->GetLayoutParams());
+    if (!lp)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    return lp->pref_h;
+}
+
+void UIWidget::SetLayoutPrefWidth(int width)
+{
+    if (!widget_)
+        return;
+
+    tb::LayoutParams lp;
+
+    const tb::LayoutParams *oldLp(widget_->GetLayoutParams());
+    if (oldLp)
+        lp = *oldLp;
+
+    lp.pref_w = width;
+    widget_->SetLayoutParams(lp);
+}
+
+int UIWidget::GetLayoutPrefWidth()
+{
+    if (!widget_)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    const tb::LayoutParams *lp(widget_->GetLayoutParams());
+    if (!lp)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    return lp->pref_w;
+}
+
+void UIWidget::SetLayoutPrefHeight(int height)
+{
+    if (!widget_)
+        return;
+
+    tb::LayoutParams lp;
+
+    const tb::LayoutParams *oldLp(widget_->GetLayoutParams());
+    if (oldLp)
+        lp = *oldLp;
+
+    lp.pref_h = height;
+    widget_->SetLayoutParams(lp);
+}
+
+int UIWidget::GetLayoutPrefHeight()
+{
+    if (!widget_)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    const tb::LayoutParams *lp(widget_->GetLayoutParams());
+    if (!lp)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    return lp->pref_h;
+}
+
+void UIWidget::SetLayoutMinWidth(int width)
+{
+    if (!widget_)
+        return;
+
+    tb::LayoutParams lp;
+
+    const tb::LayoutParams *oldLp(widget_->GetLayoutParams());
+    if (oldLp)
+        lp = *oldLp;
+
+    lp.min_w = width;
+    widget_->SetLayoutParams(lp);
+}
+
+int UIWidget::GetLayoutMinWidth()
+{
+    if (!widget_)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    const tb::LayoutParams *lp(widget_->GetLayoutParams());
+    if (!lp)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    return lp->min_w;
+}
+
+void UIWidget::SetLayoutMinHeight(int height)
+{
+    if (!widget_)
+        return;
+
+    tb::LayoutParams lp;
+
+    const tb::LayoutParams *oldLp(widget_->GetLayoutParams());
+    if (oldLp)
+        lp = *oldLp;
+
+    lp.min_h = height;
+    widget_->SetLayoutParams(lp);
+}
+
+int UIWidget::GetLayoutMinHeight()
+{
+    if (!widget_)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    const tb::LayoutParams *lp(widget_->GetLayoutParams());
+    if (!lp)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    return lp->min_h;
+}
+
+void UIWidget::SetLayoutMaxWidth(int width)
+{
+    if (!widget_)
+        return;
+
+    tb::LayoutParams lp;
+
+    const tb::LayoutParams *oldLp(widget_->GetLayoutParams());
+    if (oldLp)
+        lp = *oldLp;
+
+    lp.max_w = width;
+    widget_->SetLayoutParams(lp);
+}
+
+int UIWidget::GetLayoutMaxWidth()
+{
+    if (!widget_)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    const tb::LayoutParams *lp(widget_->GetLayoutParams());
+    if (!lp)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    return lp->max_w;
+}
+
+void UIWidget::SetLayoutMaxHeight(int height)
+{
+    if (!widget_)
+        return;
+
+    tb::LayoutParams lp;
+
+    const tb::LayoutParams *oldLp(widget_->GetLayoutParams());
+    if (oldLp)
+        lp = *oldLp;
+
+    lp.max_h = height;
+    widget_->SetLayoutParams(lp);
+}
+
+int UIWidget::GetLayoutMaxHeight()
+{
+    if (!widget_)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    const tb::LayoutParams *lp(widget_->GetLayoutParams());
+    if (!lp)
+        return tb::LayoutParams::UNSPECIFIED;
+
+    return lp->max_h;
+}
+
+void UIWidget::SetOpacity(float opacity)
+{
+    if (!widget_)
+        return;
+
+    widget_->SetOpacity(opacity);
+}
+
+float UIWidget::GetOpacity()
+{
+    if (!widget_)
+        return -0.0f;
+
+    return widget_->GetOpacity();
+}
+
+void UIWidget::SetAutoOpacity(float autoOpacity)
+{
+    if (!widget_)
+        return;
+
+    if (autoOpacity == 0.0f)
+    {
+        widget_->SetOpacity(autoOpacity);
+        widget_->SetVisibilility(tb::WIDGET_VISIBILITY_INVISIBLE);
+    }
+    else
+    {
+        widget_->SetVisibilility(tb::WIDGET_VISIBILITY_VISIBLE);
+        widget_->SetOpacity(autoOpacity);
+    }
+}
+
+float UIWidget::GetAutoOpacity()
+{
+    if (!widget_)
+        return -0.0f;
+
+    float autoOpacity(widget_->GetOpacity());
+
+    if (autoOpacity == 0.0f)
+    {
+        if (widget_->GetVisibility() == tb::WIDGET_VISIBILITY_VISIBLE)
+            return 0.0001f; // Don't say that it's completly invisible.
+    }
+    else
+    {
+        if (widget_->GetVisibility() != tb::WIDGET_VISIBILITY_VISIBLE)
+            return 0.0f; // Say it's invisible.
+    }
+    return autoOpacity;
+}
+
 void UIWidget::DeleteAllChildren()
 {
     if (!widget_)

+ 41 - 1
Source/Atomic/UI/UIWidget.h

@@ -164,7 +164,7 @@ class UIWidget : public Object, public tb::TBWidgetDelegate
 
     public:
 
-        UIWidget(Context* context, bool createWidget = true);
+    UIWidget(Context* context, bool createWidget = true);
     virtual ~UIWidget();
 
     bool Load(const String& filename);
@@ -273,6 +273,46 @@ class UIWidget : public Object, public tb::TBWidgetDelegate
     void Enable();
     void Disable();
 
+    // Font Description
+    void SetFontId(const String& fontId);
+    void SetFontId(tb::uint32 fontId);
+    void SetFontSize(int size);
+    int GetFontSize();
+
+    // Rect
+    void SetX(int x) { IntRect r(GetRect()); r.right_ = x + r.Width(); r.left_ = x; SetRect(r); }
+    int GetX() { return GetRect().left_; }
+    void SetY(int y) { IntRect r(GetRect()); r.bottom_ = y + r.Height(); r.top_ = y; SetRect(r); }
+    int GetY() { return GetRect().top_; }
+    void SetWidth(int width) { IntRect r(GetRect()); r.right_ = r.left_ + width; SetRect(r); }
+    int GetWidth() { return GetRect().Width(); }
+    void SetHeight(int height) { IntRect r(GetRect()); r.bottom_ = r.top_ + height; SetRect(r); }
+    int GetHeight() { return GetRect().Height(); }
+
+    // Layout Params
+    void SetLayoutWidth(int width);
+    int GetLayoutWidth();
+    void SetLayoutHeight(int height);
+    int GetLayoutHeight();
+    void SetLayoutPrefWidth(int width);
+    int GetLayoutPrefWidth();
+    void SetLayoutPrefHeight(int height);
+    int GetLayoutPrefHeight();
+    void SetLayoutMinWidth(int width);
+    int GetLayoutMinWidth();
+    void SetLayoutMinHeight(int height);
+    int GetLayoutMinHeight();
+    void SetLayoutMaxWidth(int width);
+    int GetLayoutMaxWidth();
+    void SetLayoutMaxHeight(int height);
+    int GetLayoutMaxHeight();
+
+    // Opacity and AutoOpacity (AutoOpacity sets visibility as well based on opacity being 0.0 or non-0.0).
+    void SetOpacity(float opacity);
+    float GetOpacity();
+    void SetAutoOpacity(float autoOpacity);
+    float GetAutoOpacity();
+
 protected:
 
     void ConvertEvent(UIWidget* handler, UIWidget* target, const tb::TBWidgetEvent &ev, VariantMap& data);