Monday, May 21, 2012

Drawing With Mouse in Xwindow

Here i am giving a code block which takes two points and draw the line between those two points. Where point is a structure

struct Point {
                      double x;
                      double y;

/ * Function Start */ 

void Draw_Gesture(Point p, Point q)
                 Drawable d = w;
                 XGCValues values;
                 values.line_width = prefs.trace_width.get();
                 values.line_style = LineSolid;
                 GC gc = XCreateGC(dpy, d, GCLineWidth, &values);
                 XDrawLine(dpy, w, gc, p.x, p.y, q.x, q.y);

/ * Function End */ 

Now to draw line, as long as Moving the mouse, we have to write a function to Listen mouse events. From that event variable we will get x and y coordinates of current mouse locations. We assign these x and y coordinates to x and y of Point structure. Then we will send these Point Structure variables to Draw_Gesture functions. Now Draw_Gesture  function Draws the line as long as mouse moves in window w.

Drawing with Mouse
Drawing With Mouse

No comments:

Post a Comment