comparison src/X_main.c @ 30:e06a4a667ce2

Accept mouse/pointer event and hint the shape that the pointer is over. - add find_shape_at_pos()
author Thinker K.F. Li <thinker@branda.to>
date Tue, 05 Aug 2008 12:40:45 +0800
parents 19c603dd6ff9
children da770188a44d
comparison
equal deleted inserted replaced
29:f56c96b035a8 30:e06a4a667ce2
9 #include "shapes.h" 9 #include "shapes.h"
10 #include "redraw_man.h" 10 #include "redraw_man.h"
11 #include "paint.h" 11 #include "paint.h"
12 12
13 Display *display; 13 Display *display;
14 Window win;
15
16 void hint_shape(redraw_man_t *rdman, shape_t *shape) {
17 static shape_t *last_shape = NULL;
18 if(last_shape != shape) {
19 if(last_shape != NULL && last_shape != NULL) {
20 last_shape->stroke_width -= 2;
21 rdman_shape_changed(rdman, last_shape);
22 }
23 if(shape != NULL && shape->stroke != NULL) {
24 shape->stroke_width += 2;
25 rdman_shape_changed(rdman, shape);
26 rdman_redraw_changed(rdman);
27 XFlush(display);
28 }
29 }
30 last_shape = shape;
31 }
32
33 void event_interaction(Display *display,
34 redraw_man_t *rdman, int w, int h) {
35 XEvent evt;
36 XMotionEvent *mevt;
37 int r;
38 co_aix x, y;
39 shape_t *shape = NULL;
40 int in_stroke;
41
42 XSelectInput(display, win, PointerMotionMask);
43 while((r = XNextEvent(display, &evt)) == 0) {
44 switch(evt.type) {
45 case MotionNotify:
46 mevt = (XMotionEvent *)&evt;
47 x = mevt->x;
48 y = mevt->y;
49 shape = find_shape_at_pos(rdman, x, y, &in_stroke);
50 hint_shape(rdman, shape);
51 break;
52 }
53 }
54 }
14 55
15 void draw_path(cairo_t *cr, int w, int h) { 56 void draw_path(cairo_t *cr, int w, int h) {
16 cairo_t *tmpcr; 57 cairo_t *tmpcr;
17 cairo_surface_t *tmpsuf; 58 cairo_surface_t *tmpsuf;
18 redraw_man_t rdman; 59 redraw_man_t rdman;
166 rdman_coord_changed(&rdman, coord3); 207 rdman_coord_changed(&rdman, coord3);
167 rdman_redraw_changed(&rdman); 208 rdman_redraw_changed(&rdman);
168 XFlush(display); 209 XFlush(display);
169 } 210 }
170 211
212 event_interaction(display, &rdman, w, h);
213
171 fill1->free(fill1); 214 fill1->free(fill1);
172 fill2->free(fill2); 215 fill2->free(fill2);
173 stroke->free(stroke); 216 stroke->free(stroke);
174 text_stroke->free(text_stroke); 217 text_stroke->free(text_stroke);
175 redraw_man_destroy(&rdman); 218 redraw_man_destroy(&rdman);
194 main(int argc, char * const argv[]) { 237 main(int argc, char * const argv[]) {
195 Window root; 238 Window root;
196 Visual *visual; 239 Visual *visual;
197 int screen; 240 int screen;
198 XSetWindowAttributes wattr; 241 XSetWindowAttributes wattr;
199 Window win;
200 int depth; 242 int depth;
201 cairo_surface_t *surface; 243 cairo_surface_t *surface;
202 int w, h; 244 int w, h;
203 int x, y; 245 int x, y;
204 int r; 246 int r;