[PATCH 06/19] toytoolkit: add method to determine whether a point is in rectangle.

ning.tang at intel.com ning.tang at intel.com
Mon Sep 24 19:39:51 PDT 2012


From: Ning Tang <ning.tang at intel.com>

 The method to determine whether a point is in an rectangle area is common and
 could be used by applications.

 Signed-off-by: Ning Tang <ning.tang at intel.com>
---
 clients/window.c | 17 +++++++++++++----
 clients/window.h |  3 +++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/clients/window.c b/clients/window.c
index 330d96f..ec3ee98 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -1007,10 +1007,7 @@ widget_find_widget(struct widget *widget, int32_t x, int32_t y)
 			return target;
 	}
 
-	if (widget->allocation.x <= x &&
-	    x < widget->allocation.x + widget->allocation.width &&
-	    widget->allocation.y <= y &&
-	    y < widget->allocation.y + widget->allocation.height) {
+	if (input_in_allocation(widget->allocation, x, y)) {
 		return widget;
 	}
 
@@ -2352,6 +2349,18 @@ input_get_focus_widget(struct input *input)
 	return input->focus_widget;
 }
 
+int
+input_in_allocation(struct rectangle allocation, int x, int y)
+{
+	if (allocation.x <= x &&
+	    x < allocation.x + allocation.width &&
+	    allocation.y <= y &&
+	    y < allocation.y + allocation.height) {
+		return 1;
+	}
+	return 0;
+}
+
 struct data_offer {
 	struct wl_data_offer *offer;
 	struct input *input;
diff --git a/clients/window.h b/clients/window.h
index 41f63da..7e3843b 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -388,6 +388,9 @@ input_set_pointer_image(struct input *input, int pointer);
 void
 input_get_position(struct input *input, int32_t *x, int32_t *y);
 
+int
+input_in_allocation(struct rectangle allocation, int x, int y);
+
 #define MOD_SHIFT_MASK		0x01
 #define MOD_ALT_MASK		0x02
 #define MOD_CONTROL_MASK	0x04
-- 
1.7.12.1



More information about the wayland-devel mailing list