OSDN Git Service

libui: Add Rect(uint32_t, uint32_t)
authorDan Stoza <stoza@google.com>
Thu, 22 Jan 2015 01:36:06 +0000 (17:36 -0800)
committerDan Stoza <stoza@google.com>
Thu, 22 Jan 2015 01:39:13 +0000 (17:39 -0800)
Adds a Rect constructor that takes uint32_t instead of int32_t, as
required by a change to Region and -Werror

Change-Id: If91915e5b4ec9ce9e7ba0fb84f03b045d000b023

include/ui/Rect.h

index 31e28d2..40d1166 100644 (file)
@@ -18,6 +18,7 @@
 #define ANDROID_UI_RECT
 
 #include <utils/Flattenable.h>
+#include <utils/Log.h>
 #include <utils/TypeHelpers.h>
 #include <ui/Point.h>
 
@@ -43,6 +44,22 @@ public:
         bottom = h;
     }
 
+    inline Rect(uint32_t w, uint32_t h) {
+        if (w > INT32_MAX) {
+            ALOG(LOG_WARN, "Rect",
+                    "Width %u too large for Rect class, clamping", w);
+            w = INT32_MAX;
+        }
+        if (h > INT32_MAX) {
+            ALOG(LOG_WARN, "Rect",
+                    "Height %u too large for Rect class, clamping", h);
+            h = INT32_MAX;
+        }
+        left = top = 0;
+        right = w;
+        bottom = h;
+    }
+
     inline Rect(int32_t l, int32_t t, int32_t r, int32_t b) {
         left = l;
         top = t;