Browse Source

Applied UI patch from primitivewaste.

Lasse Öörni 13 years ago
parent
commit
26f23adb14
5 changed files with 40 additions and 6 deletions
  1. 21 2
      Engine/UI/BorderImage.cpp
  2. 6 0
      Engine/UI/BorderImage.h
  3. 1 0
      Engine/UI/UIElement.cpp
  4. 2 0
      Engine/UI/UIElement.h
  5. 10 4
      Engine/UI/Window.cpp

+ 21 - 2
Engine/UI/BorderImage.cpp

@@ -31,6 +31,18 @@
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
+static const char* blendModes[] =
+{
+    "Replace",
+    "Add",
+    "Multiply",
+    "Alpha",
+    "AddAlpha",
+    "PreMultiply",
+    "InvDestAlpha",
+    0
+};
+
 OBJECTTYPESTATIC(BorderImage);
 OBJECTTYPESTATIC(BorderImage);
 
 
 BorderImage::BorderImage(Context* context) :
 BorderImage::BorderImage(Context* context) :
@@ -38,7 +50,8 @@ BorderImage::BorderImage(Context* context) :
     imageRect_(IntRect::ZERO),
     imageRect_(IntRect::ZERO),
     border_(IntRect::ZERO),
     border_(IntRect::ZERO),
     hoverOffset_(IntVector2::ZERO),
     hoverOffset_(IntVector2::ZERO),
-    tiled_(false)
+    tiled_(false),
+    blendMode_(0)
 {
 {
 }
 }
 
 
@@ -55,6 +68,7 @@ void BorderImage::RegisterObject(Context* context)
     REF_ACCESSOR_ATTRIBUTE(BorderImage, VAR_INTRECT, "Border", GetBorder, SetBorder, IntRect, IntRect::ZERO, AM_FILE);
     REF_ACCESSOR_ATTRIBUTE(BorderImage, VAR_INTRECT, "Border", GetBorder, SetBorder, IntRect, IntRect::ZERO, AM_FILE);
     REF_ACCESSOR_ATTRIBUTE(BorderImage, VAR_INTVECTOR2, "Hover Image Offset", GetHoverOffset, SetHoverOffset, IntVector2, IntVector2::ZERO, AM_FILE);
     REF_ACCESSOR_ATTRIBUTE(BorderImage, VAR_INTVECTOR2, "Hover Image Offset", GetHoverOffset, SetHoverOffset, IntVector2, IntVector2::ZERO, AM_FILE);
     ACCESSOR_ATTRIBUTE(BorderImage, VAR_BOOL, "Tiled", IsTiled, SetTiled, bool, true, AM_FILE);
     ACCESSOR_ATTRIBUTE(BorderImage, VAR_BOOL, "Tiled", IsTiled, SetTiled, bool, true, AM_FILE);
+    ENUM_ACCESSOR_ATTRIBUTE(BorderImage, "Blend Mode", GetBlendMode, SetBlendMode, unsigned, blendModes, 0, AM_FILE);
     COPY_BASE_ATTRIBUTES(BorderImage, UIElement);
     COPY_BASE_ATTRIBUTES(BorderImage, UIElement);
 }
 }
 
 
@@ -116,6 +130,11 @@ void BorderImage::SetTiled(bool enable)
     tiled_ = enable;
     tiled_ = enable;
 }
 }
 
 
+void BorderImage::SetBlendMode(unsigned mode)
+{
+    blendMode_ = mode;
+}
+
 void BorderImage::GetBatches(PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, const IntRect& currentScissor, const IntVector2& offset)
 void BorderImage::GetBatches(PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, const IntRect& currentScissor, const IntVector2& offset)
 {
 {
     bool allOpaque = true;
     bool allOpaque = true;
@@ -123,7 +142,7 @@ void BorderImage::GetBatches(PODVector<UIBatch>& batches, PODVector<UIQuad>& qua
         color_[C_BOTTOMLEFT].a_ < 1.0f || color_[C_BOTTOMRIGHT].a_ < 1.0f)
         color_[C_BOTTOMLEFT].a_ < 1.0f || color_[C_BOTTOMRIGHT].a_ < 1.0f)
         allOpaque = false;
         allOpaque = false;
         
         
-    UIBatch batch(allOpaque ? BLEND_REPLACE : BLEND_ALPHA, currentScissor, texture_, &quads);
+    UIBatch batch(blendMode_ == BLEND_REPLACE && !allOpaque ? BLEND_ALPHA : static_cast<BlendMode>(blendMode_), currentScissor, texture_, &quads);
     
     
     // Calculate size of the inner rect, and texture dimensions of the inner rect
     // Calculate size of the inner rect, and texture dimensions of the inner rect
     const IntVector2& size = GetSize();
     const IntVector2& size = GetSize();

+ 6 - 0
Engine/UI/BorderImage.h

@@ -62,6 +62,10 @@ public:
     void SetTiled(bool enable);
     void SetTiled(bool enable);
     /// Return whether is tiled.
     /// Return whether is tiled.
     bool IsTiled() const { return tiled_; }
     bool IsTiled() const { return tiled_; }
+    /// Set blend mode.
+    void SetBlendMode(unsigned mode);
+    /// Return blend mode.
+    unsigned GetBlendMode() const { return blendMode_; }
     
     
     /// Return texture.
     /// Return texture.
     Texture* GetTexture() const { return texture_; }
     Texture* GetTexture() const { return texture_; }
@@ -91,6 +95,8 @@ protected:
     IntVector2 hoverOffset_;
     IntVector2 hoverOffset_;
     /// Tiled flag.
     /// Tiled flag.
     bool tiled_;
     bool tiled_;
+    /// Blend mode flag.
+    unsigned blendMode_;
 };
 };
 
 
 }
 }

+ 1 - 0
Engine/UI/UIElement.cpp

@@ -167,6 +167,7 @@ void UIElement::RegisterObject(Context* context)
     REF_ACCESSOR_ATTRIBUTE(UIElement, VAR_INTRECT, "Clip Border", GetClipBorder, SetClipBorder, IntRect, IntRect::ZERO, AM_FILE);
     REF_ACCESSOR_ATTRIBUTE(UIElement, VAR_INTRECT, "Clip Border", GetClipBorder, SetClipBorder, IntRect, IntRect::ZERO, AM_FILE);
     ACCESSOR_ATTRIBUTE(UIElement, VAR_INT, "Priority", GetPriority, SetPriority, int, 0, AM_FILE);
     ACCESSOR_ATTRIBUTE(UIElement, VAR_INT, "Priority", GetPriority, SetPriority, int, 0, AM_FILE);
     ACCESSOR_ATTRIBUTE(UIElement, VAR_FLOAT, "Opacity", GetOpacity, SetOpacity, float, 1.0f, AM_FILE);
     ACCESSOR_ATTRIBUTE(UIElement, VAR_FLOAT, "Opacity", GetOpacity, SetOpacity, float, 1.0f, AM_FILE);
+    REF_ACCESSOR_ATTRIBUTE(UIElement, VAR_COLOR, "Color", GetColorAttr, SetColor, Color, Color::WHITE, AM_FILE);
     ATTRIBUTE(UIElement, VAR_COLOR, "Top Left Color", color_[0], Color::WHITE, AM_FILE);
     ATTRIBUTE(UIElement, VAR_COLOR, "Top Left Color", color_[0], Color::WHITE, AM_FILE);
     ATTRIBUTE(UIElement, VAR_COLOR, "Top Right Color", color_[1], Color::WHITE, AM_FILE);
     ATTRIBUTE(UIElement, VAR_COLOR, "Top Right Color", color_[1], Color::WHITE, AM_FILE);
     ATTRIBUTE(UIElement, VAR_COLOR, "Bottom Left Color", color_[2], Color::WHITE, AM_FILE);
     ATTRIBUTE(UIElement, VAR_COLOR, "Bottom Left Color", color_[2], Color::WHITE, AM_FILE);

+ 2 - 0
Engine/UI/UIElement.h

@@ -389,6 +389,8 @@ public:
     /// Get UI rendering batches with a specified offset. Also recurses to child elements.
     /// Get UI rendering batches with a specified offset. Also recurses to child elements.
     void GetBatchesWithOffset(IntVector2& offset, PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, IntRect
     void GetBatchesWithOffset(IntVector2& offset, PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, IntRect
         currentScissor);
         currentScissor);
+    /// Get color attribute. Uses just the top-left color.
+    const Color& GetColorAttr() const { return color_[0]; }
     
     
 protected:
 protected:
     /// Mark screen position as needing an update.
     /// Mark screen position as needing an update.

+ 10 - 4
Engine/UI/Window.cpp

@@ -94,6 +94,11 @@ void Window::OnDragMove(const IntVector2& position, const IntVector2& screenPosi
         return;
         return;
     
     
     IntVector2 delta = screenPosition - dragBeginCursor_;
     IntVector2 delta = screenPosition - dragBeginCursor_;
+
+    const IntVector2& position_ = GetPosition();
+    const IntVector2& size_ = GetSize();
+    const IntVector2& minSize_ = GetMinSize();
+    const IntVector2& maxSize_ = GetMaxSize();
     
     
     switch (dragMode_)
     switch (dragMode_)
     {
     {
@@ -102,12 +107,13 @@ void Window::OnDragMove(const IntVector2& position, const IntVector2& screenPosi
         break;
         break;
         
         
     case DRAG_RESIZE_TOPLEFT:
     case DRAG_RESIZE_TOPLEFT:
-        SetPosition(dragBeginPosition_ + delta);
+        SetPosition(Clamp(dragBeginPosition_.x_ + delta.x_, position_.x_ - (maxSize_.x_ - size_.x_), position_.x_ + (size_.x_ - minSize_.x_)), 
+            Clamp(dragBeginPosition_.y_ + delta.y_, position_.y_ - (maxSize_.y_ - size_.y_), position_.y_ + (size_.y_ - minSize_.y_)));
         SetSize(dragBeginSize_ - delta);
         SetSize(dragBeginSize_ - delta);
         break;
         break;
         
         
     case DRAG_RESIZE_TOP:
     case DRAG_RESIZE_TOP:
-        SetPosition(dragBeginPosition_.x_, dragBeginPosition_.y_ + delta.y_);
+        SetPosition(dragBeginPosition_.x_, Clamp(dragBeginPosition_.y_ + delta.y_, position_.y_ - (maxSize_.y_ - size_.y_), position_.y_ + (size_.y_ - minSize_.y_)));
         SetSize(dragBeginSize_.x_, dragBeginSize_.y_ - delta.y_);
         SetSize(dragBeginSize_.x_, dragBeginSize_.y_ - delta.y_);
         break;
         break;
         
         
@@ -129,12 +135,12 @@ void Window::OnDragMove(const IntVector2& position, const IntVector2& screenPosi
         break;
         break;
         
         
     case DRAG_RESIZE_BOTTOMLEFT:
     case DRAG_RESIZE_BOTTOMLEFT:
-        SetPosition(dragBeginPosition_.x_ + delta.x_, dragBeginPosition_.y_);
+        SetPosition(Clamp(dragBeginPosition_.x_ + delta.x_, position_.x_ - (maxSize_.x_ - size_.x_), position_.x_ + (size_.x_ - minSize_.x_)), dragBeginPosition_.y_);
         SetSize(dragBeginSize_.x_ - delta.x_, dragBeginSize_.y_ + delta.y_);
         SetSize(dragBeginSize_.x_ - delta.x_, dragBeginSize_.y_ + delta.y_);
         break;
         break;
         
         
     case DRAG_RESIZE_LEFT:
     case DRAG_RESIZE_LEFT:
-        SetPosition(dragBeginPosition_.x_ + delta.x_, dragBeginPosition_.y_);
+        SetPosition(Clamp(dragBeginPosition_.x_ + delta.x_, position_.x_ - (maxSize_.x_ - size_.x_), position_.x_ + (size_.x_ - minSize_.x_)), dragBeginPosition_.y_);
         SetSize(dragBeginSize_.x_ - delta.x_, dragBeginSize_.y_);
         SetSize(dragBeginSize_.x_ - delta.x_, dragBeginSize_.y_);
         break;
         break;