nanogui: Mouse events


Previous by date: 16 Oct 2005 21:09:19 +0100 Re: pixmaps and transparency for gif file, tj
Next by date: 16 Oct 2005 21:09:19 +0100 How to write text through an ico?, tj
Previous in thread:
Next in thread: 16 Oct 2005 21:09:19 +0100 Re: Mouse events, Greg Haerr

Subject: Mouse events
From: "Dave Stuart" ####@####.####
Date: 16 Oct 2005 21:09:19 +0100
Message-Id: <009901c5d28d$657ade60$2003a8c0@house>

I am trying to write code to drag windows around the screen.  I have 
tried using MOUSE_POSITION and MOUSE_MOTION but they don't seem to do 
what I need.  If you drag the windows slowly it works fine but if you 
move the mouse too fast the screen goes wonky.  Any help would be 
appreciated.  I can't seem to attach the whole program but here is the pertinent area.  

Also, is there a way to search the mailing list archive 
without having to go through month by month?

Thanks

dave

Sample Program:

/* Draw a main window with borders and background */
           
    wid = GrNewWindow(GR_ROOT_WINDOW_ID, MARGIN, MARGIN,
                      si.cols - MARGIN * 2, si.rows - MARGIN * 2,
                      1, BACKGROUND_COLOR, BORDER_COLOR);

    GrSelectEvents(wid, GR_EVENT_MASK_BUTTON_DOWN | 
                        GR_EVENT_MASK_MOUSE_MOTION |
                        GR_EVENT_MASK_EXPOSURE);

    GrMapWindow(wid);

/*  Define the windows that are being used */

    for (i = 0; i < 50; i++) {
      if (devices[i].in_use) {
        devices[i].window_id = GrNewWindow (wid, 
                 devices[i].horizontal_location, 
                 devices[i].vertical_location,
                 devices[i].horizontal_size,
                 devices[i].vertical_size,
                 1, devices[i].background, devices[i].foreground);
        GrSelectEvents (devices[i].window_id, GR_EVENT_MASK_EXPOSURE);
        GrMapWindow (devices[i].window_id);
        }
      }

    gc = GrNewGC();
                                      
    while (1) {
      GrGetNextEvent(&event);
      switch (event.type) {
        case GR_EVENT_TYPE_MOUSE_MOTION:
          if (mouse_down_window >= 0) {
            devices[mouse_down_window].horizontal_location -= mouse_down_horizontal - event.mouse.rootx;
            devices[mouse_down_window].vertical_location -= mouse_down_vertical - event.mouse.rooty;
            mouse_down_vertical = event.mouse.rooty;
            mouse_down_horizontal = event.mouse.rootx;
            GrMoveWindow (event.mouse.subwid, devices[mouse_down_window].horizontal_location, devices[mouse_down_window].vertical_location);
          }
          break;
        
        case GR_EVENT_TYPE_BUTTON_UP:
          if (!(event.button.changebuttons & GR_BUTTON_L))
            break;
/* Left mouse button released */
/* Drop the window and don't look for mouse up data anymore */
          if (mouse_down_window >= 0) {
            GrSelectEvents (wid, GR_EVENT_MASK_BUTTON_DOWN |
                                 GR_EVENT_MASK_MOUSE_MOTION |
                                 GR_EVENT_MASK_EXPOSURE);

            mouse_down_window = -1;
          }
          break;
        
        case GR_EVENT_TYPE_BUTTON_DOWN:
          if (event.button.subwid == wid) {
            GrClose();
            exit(0);
          }
          if (!(event.button.changebuttons & GR_BUTTON_L))
            break;
/* Left mouse button pressed down */
/* Remember where we started and which window we're dragging and watch for mouse button up. */
          GrSelectEvents (wid, GR_EVENT_MASK_BUTTON_UP | 
                               GR_EVENT_MASK_MOUSE_MOTION |
                               GR_EVENT_MASK_EXPOSURE); 
          mouse_down_horizontal = event.button.rootx;
          mouse_down_vertical = event.button.rooty;
          for (i = 0; i < 50; i++)
            if (devices[i].in_use)
              if (event.button.subwid == devices[i].window_id)
                mouse_down_window = i;
          break;
          
        case GR_EVENT_TYPE_EXPOSURE:
/* Display the windows when exposed */
          for (i = 0; i < 50; i++) {
            if (devices[i].in_use)
              if (event.exposure.wid == devices[i].window_id) {
                GrSetGCBackground (gc, devices[i].background);
                GrSetGCForeground (gc, devices[i].foreground);
                GrSetGCFont (gc, small_font);
                GrGetGCTextSize (gc, devices[i].name, strlen(devices[i].name),
                        0, &width, &height, &base);
                GrText (devices[i].window_id, gc, 
                ((devices[i].horizontal_size - width)/2),
                         10, devices[i].name, strlen(devices[i].name), 0);
                GrSetGCFont (gc, big_font);
                sprintf(temp, "%d %s", devices[i].current_value[0], 
                                       devices[i].units);
                GrGetGCTextSize (gc, temp, strlen (temp), 0, &width, &height, &base);
                GrText (devices[i].window_id, gc, 
                       ((devices[i].horizontal_size - width)/2),
                       35, temp, strlen (temp), 0);
              }
          }
          break;
        }
      }
    }

Previous by date: 16 Oct 2005 21:09:19 +0100 Re: pixmaps and transparency for gif file, tj
Next by date: 16 Oct 2005 21:09:19 +0100 How to write text through an ico?, tj
Previous in thread:
Next in thread: 16 Oct 2005 21:09:19 +0100 Re: Mouse events, Greg Haerr


Powered by ezmlm-browse 0.20.