[PATCH 1/2 weston] clickdot: Reposition dot on resize.
Scott Moreau
oreaus at gmail.com
Fri Nov 9 00:11:33 PST 2012
Attempt to keep dot in the same position proportionate to the surface's size.
---
clients/clickdot.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/clients/clickdot.c b/clients/clickdot.c
index c74bc91..7358656 100644
--- a/clients/clickdot.c
+++ b/clients/clickdot.c
@@ -44,6 +44,7 @@ struct clickdot {
struct {
int32_t x, y;
+ float rw, rh;
} dot;
struct {
@@ -136,7 +137,7 @@ redraw_handler(struct widget *widget, void *data)
struct clickdot *clickdot = data;
cairo_surface_t *surface;
cairo_t *cr;
- struct rectangle allocation;
+ struct rectangle allocation, window;
widget_get_allocation(clickdot->widget, &allocation);
@@ -154,6 +155,10 @@ redraw_handler(struct widget *widget, void *data)
draw_line(clickdot, cr, &allocation);
+ window_get_allocation(clickdot->window, &window);
+ clickdot->dot.x = window.width * clickdot->dot.rw;
+ clickdot->dot.y = window.height * clickdot->dot.rh;
+
cairo_translate(cr, clickdot->dot.x + 0.5, clickdot->dot.y + 0.5);
cairo_set_line_width(cr, 1.0);
cairo_set_source_rgb(cr, 0.1, 0.9, 0.9);
@@ -202,9 +207,15 @@ button_handler(struct widget *widget,
enum wl_pointer_button_state state, void *data)
{
struct clickdot *clickdot = data;
+ struct rectangle allocation;
- if (state == WL_POINTER_BUTTON_STATE_PRESSED && button == BTN_LEFT)
+ window_get_allocation(clickdot->window, &allocation);
+
+ if (state == WL_POINTER_BUTTON_STATE_PRESSED && button == BTN_LEFT) {
input_get_position(input, &clickdot->dot.x, &clickdot->dot.y);
+ clickdot->dot.rw = (float) clickdot->dot.x / allocation.width;
+ clickdot->dot.rh = (float) clickdot->dot.y / allocation.height;
+ }
widget_schedule_redraw(widget);
}
@@ -270,6 +281,8 @@ clickdot_create(struct display *display)
widget_set_leave_handler(clickdot->widget, leave_handler);
widget_schedule_resize(clickdot->widget, 500, 400);
+ clickdot->dot.rw = 0.5;
+ clickdot->dot.rh = 0.5;
clickdot->dot.x = 250;
clickdot->dot.y = 200;
clickdot->line.x = -1;
--
1.7.11.7
More information about the wayland-devel
mailing list