2
0
Эх сурвалжийг харах

Revert some changes in Serializable and flag sets. Fix Camera compilation.

[cache clear]
Eugene Kozlov 7 жил өмнө
parent
commit
7cb72d451b

+ 13 - 2
Source/Urho3D/Container/FlagSet.h

@@ -213,13 +213,24 @@ public:
         return value_ != rhs.value_;
     }
 
-    /// Returns true if specified enum value is set.
+    /// Return true if specified enum value is set.
     inline bool Test(const Enum value) const
     {
-        Integer flags = (Integer) value;
+        return Test((Integer)value);
+    }
+
+    /// Return true if specified bits are set.
+    inline bool Test(const Integer flags) const
+    {
         return (value_ & flags) == flags && (flags != 0 || value_ == flags);
     }
 
+    /// Return underlying integer (constant).
+    Integer AsInteger() const { return value_; }
+
+    /// Return underlying integer (non-constant).
+    Integer& AsInteger() { return value_; }
+
 protected:
     /// Value
     Integer value_ = 0;

+ 1 - 1
Source/Urho3D/Graphics/Camera.cpp

@@ -96,7 +96,7 @@ void Camera::RegisterObject(Context* context)
     URHO3D_ACCESSOR_ATTRIBUTE("Zoom", GetZoom, SetZoom, float, 1.0f, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("LOD Bias", GetLodBias, SetLodBias, float, 1.0f, AM_DEFAULT);
     URHO3D_ATTRIBUTE("View Mask", int, viewMask_, DEFAULT_VIEWMASK, AM_DEFAULT);
-    URHO3D_ATTRIBUTE("View Override Flags", unsigned, viewOverrideFlags_, VO_NONE, AM_DEFAULT);
+    URHO3D_ATTRIBUTE("View Override Flags", unsigned, viewOverrideFlags_.AsInteger(), VO_NONE, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("Projection Offset", GetProjectionOffset, SetProjectionOffset, Vector2, Vector2::ZERO, AM_DEFAULT);
     URHO3D_MIXED_ACCESSOR_ATTRIBUTE("Reflection Plane", GetReflectionPlaneAttr, SetReflectionPlaneAttr, Vector4,
         Vector4(0.0f, 1.0f, 0.0f, 0.0f), AM_DEFAULT);

+ 8 - 2
Source/Urho3D/Input/Input.cpp

@@ -1930,7 +1930,10 @@ void Input::HandleSDLEvent(void* sdlEvent)
 
     case SDL_MOUSEBUTTONDOWN:
         if (!touchEmulation_)
-            SetMouseButton(static_cast<MouseButton>(1u << (evt.button.button - 1)), true);
+        {
+            const auto mouseButton = static_cast<MouseButton>(1u << (static_cast<MouseButtonFlags::Integer>(evt.button.button) - 1));
+            SetMouseButton(mouseButton, true);
+        }
         else
         {
             int x, y;
@@ -1953,7 +1956,10 @@ void Input::HandleSDLEvent(void* sdlEvent)
 
     case SDL_MOUSEBUTTONUP:
         if (!touchEmulation_)
-            SetMouseButton(static_cast<MouseButton>(1u << (evt.button.button - 1)), false);
+        {
+            const auto mouseButton = static_cast<MouseButton>(1u << (static_cast<MouseButtonFlags::Integer>(evt.button.button) - 1));
+            SetMouseButton(mouseButton, false);
+        }
         else
         {
             int x, y;

+ 2 - 3
Source/Urho3D/Scene/Serializable.h

@@ -26,7 +26,6 @@
 #include "../Core/Object.h"
 
 #include <cstddef>
-#include <type_traits>
 
 namespace Urho3D
 {
@@ -192,8 +191,8 @@ SharedPtr<AttributeAccessor> MakeVariantAttributeAccessor(TGetFunction getFuncti
 
 /// Make member attribute accessor.
 #define URHO3D_MAKE_MEMBER_ATTRIBUTE_ACCESSOR(typeName, variable) Urho3D::MakeVariantAttributeAccessor<ClassName>( \
-    [](const ClassName& self, Urho3D::Variant& value) { value = static_cast<typeName>(self.variable); }, \
-    [](ClassName& self, const Urho3D::Variant& value) { self.variable = static_cast<std::remove_reference<decltype(variable)>::type>(value.Get<typeName>()); })
+    [](const ClassName& self, Urho3D::Variant& value) { value = self.variable; }, \
+    [](ClassName& self, const Urho3D::Variant& value) { self.variable = value.Get<typeName>(); })
 
 /// Make member attribute accessor with custom post-set callback.
 #define URHO3D_MAKE_MEMBER_ATTRIBUTE_ACCESSOR_EX(typeName, variable, postSetCallback) Urho3D::MakeVariantAttributeAccessor<ClassName>( \

+ 6 - 5
Source/Urho3D/UI/UI.cpp

@@ -67,7 +67,7 @@
 
 #include "../DebugNew.h"
 
-#define TOUCHID_MASK(id) MouseButton(1u << (unsigned)(id))
+#define TOUCHID_MASK(id) MouseButton(1u << static_cast<MouseButtonFlags::Integer>(id))
 
 namespace Urho3D
 {
@@ -1839,7 +1839,7 @@ void UI::HandleTouchEnd(StringHash eventType, VariantMap& eventData)
     pos.y_ = int(pos.y_ / uiScale_);
 
     // Get the touch index
-    auto touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
+    const MouseButton touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
 
     // Transmit hover end to the position where the finger was lifted
     WeakPtr<UIElement> element(GetElementAt(pos));
@@ -1847,8 +1847,8 @@ void UI::HandleTouchEnd(StringHash eventType, VariantMap& eventData)
     // Clear any drag events that were using the touch id
     for (auto i = touchDragElements_.Begin(); i != touchDragElements_.End();)
     {
-        auto touches = i->second_;
-        if (touches.Test(touchId))
+        const MouseButtonFlags touches = i->second_;
+        if (touches & touchId)
             i = touchDragElements_.Erase(i);
         else
             ++i;
@@ -2069,7 +2069,8 @@ IntVector2 UI::SumTouchPositions(UI::DragData* dragData, const IntVector2& oldSe
         auto* input = GetSubsystem<Input>();
         for (unsigned i = 0; (1u << i) <= (unsigned)buttons; i++)
         {
-            if (buttons.Test(MouseButton(1u << i)))
+            auto mouseButton = static_cast<MouseButton>(1u << i);
+            if (buttons & mouseButton)
             {
                 TouchState* ts = input->GetTouch((unsigned)i);
                 if (!ts)