Beispiel #1
0
ENTRYPOINT Bool jigglypuff_handle_event(ModeInfo *mi, XEvent *event)
{
    jigglystruct *js = &jss[MI_SCREEN(mi)];

    if(event->xany.type == ButtonPress &&
            event->xbutton.button == Button1) {
        js->button_down = 1;
        gltrackball_start(js->trackball, event->xbutton.x, event->xbutton.y,
                          MI_WIDTH(mi), MI_HEIGHT(mi));
        return True;
    }
    else if(event->xany.type == ButtonRelease &&
            event->xbutton.button == Button1) {
        js->button_down = 0;
        return True;
    }
    else if (event->xany.type == ButtonPress &&
             (event->xbutton.button == Button4 ||
              event->xbutton.button == Button5 ||
              event->xbutton.button == Button6 ||
              event->xbutton.button == Button7))
    {
        gltrackball_mousewheel (js->trackball, event->xbutton.button, 10,
                                !!event->xbutton.state);
        return True;
    }
    else if(event->xany.type == MotionNotify && js->button_down) {
        gltrackball_track(js->trackball, event->xmotion.x, event->xmotion.y,
                          MI_WIDTH(mi), MI_HEIGHT(mi));
        return True;
    }
    return False;
}
Beispiel #2
0
/* Call this when a mouse-wheel click is detected.
   Clicks act like horizontal or vertical drags.
   Percent is the length of the drag as a percentage of the screen size.
   Button is 'Button4' or 'Button5' (for the vertical wheel)
   or 'Button5' or 'Button6' (for the horizontal wheel).
   If `flip_p' is true, swap the horizontal and vertical axes.
 */
void
gltrackball_mousewheel (trackball_state *ts,
                        int button, int percent, int flip_p)
{
  int up_p;
  int horizontal_p;
  int mx, my, move, scale;

#ifdef HAVE_JWXYZ
  flip_p = 0;      /* MacOS has already handled this. */
#endif

  switch (button) {
  case Button4: up_p = 1; horizontal_p = 0; break;
  case Button5: up_p = 0; horizontal_p = 0; break;
  case Button6: up_p = 1; horizontal_p = 1; break;
  case Button7: up_p = 0; horizontal_p = 1; break;
  default: abort(); break;
  }

  if (flip_p)
    {
      horizontal_p = !horizontal_p;
      up_p = !up_p;
    }

  scale = mx = my = 1000;
  move = (up_p
          ? floor (scale * (1.0 - (percent / 100.0)))
          : ceil  (scale * (1.0 + (percent / 100.0))));
  if (horizontal_p) mx = move;
  else              my = move;
  gltrackball_start (ts, scale, scale, scale*2, scale*2);
  gltrackball_track (ts, mx, my, scale*2, scale*2);
}
	ENTRYPOINT Bool antinspect_handle_event (ModeInfo *mi, XEvent *event) 
	{
	  antinspectstruct *mp = &antinspect[MI_SCREEN(mi)];
	  
	  if(event->xany.type == ButtonPress && event->xbutton.button == Button1) {
		mp->button_down_p = True;
		gltrackball_start(mp->trackball,
						  event->xbutton.x, event->xbutton.y,
						  MI_WIDTH (mi), MI_HEIGHT (mi));
		return True;
	  }
	  else if(event->xany.type == ButtonRelease && 
			  event->xbutton.button == Button1) {
		mp->button_down_p = False;
		return True;
	  }
	  else if (event->xany.type == ButtonPress &&
			   (event->xbutton.button == Button4 ||
				event->xbutton.button == Button5 ||
				event->xbutton.button == Button6 ||
				event->xbutton.button == Button7))
		{
		  gltrackball_mousewheel (mp->trackball, event->xbutton.button, 5,
								  !event->xbutton.state);
		  return True;
		}
	  else if(event->xany.type == MotionNotify && mp->button_down_p) {
		gltrackball_track (mp->trackball,
						   event->xmotion.x, event->xmotion.y,
						   MI_WIDTH (mi), MI_HEIGHT (mi));
		return True;
	  }
	  
	  return False;
	}
	ENTRYPOINT Bool
	rubikblocks_handle_event (ModeInfo *mi, XEvent *event)
	{
	  rubikblocks_conf *cp = &rubikblocks[MI_SCREEN(mi)];
	  if(event->xany.type == ButtonPress && event->xbutton.button == Button1)
	  {
	    cp->button_down = True;
	    gltrackball_start(cp->trackball, event->xbutton.x, event->xbutton.y,
	        MI_WIDTH(mi), MI_HEIGHT(mi));
	    return True;
	  }
	  else if(event->xany.type == ButtonRelease && event->xbutton.button == Button1)
	  {
	    cp->button_down = False;
	    return True;
	  }
	  else if(event->xany.type == ButtonPress &&
	      (event->xbutton.button == Button4 || event->xbutton.button == Button5 ||
	       event->xbutton.button == Button6 || event->xbutton.button == Button7))
	  {
	    gltrackball_mousewheel(cp->trackball,
	        event->xbutton.button, 5, !!event->xbutton.state);
	    return True;
	  }
	  else if(event->xany.type == MotionNotify && cp->button_down)
	  {
	    gltrackball_track(cp->trackball, event->xmotion.x, event->xmotion.y,
	        MI_WIDTH (mi), MI_HEIGHT (mi));
	    return True;
	  }
	  return False;
	}
Beispiel #5
0
/** handle X event (trackball) */
ENTRYPOINT Bool chess_handle_event (ModeInfo *mi, XEvent *event) 
{
  Chesscreen *cs = &qs[MI_SCREEN(mi)];

  if(event->xany.type == ButtonPress && event->xbutton.button == Button1) {
    cs->button_down_p = True;
    gltrackball_start (cs->trackball,
		       event->xbutton.x, event->xbutton.y,
		       MI_WIDTH (mi), MI_HEIGHT (mi));
    return True;
  }
  else if(event->xany.type == ButtonRelease 
	  && event->xbutton.button == Button1) {
    cs->button_down_p = False;
    return True;
  }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (cs->trackball, event->xbutton.button, 5,
                              !event->xbutton.state);
      return True;
    }
  else if(event->xany.type == MotionNotify && cs->button_down_p) {
    gltrackball_track (cs->trackball,
		       event->xmotion.x, event->xmotion.y,
		       MI_WIDTH (mi), MI_HEIGHT (mi));
    return True;
  }
  
  return False;
}
Beispiel #6
0
ENTRYPOINT Bool hypertorus_handle_event(ModeInfo *mi, XEvent *event)
{
  hypertorusstruct *hp = &hyper[MI_SCREEN(mi)];
  KeySym  sym = 0;
  char c = 0;

  if (event->xany.type == KeyPress || event->xany.type == KeyRelease)
    XLookupString (&event->xkey, &c, 1, &sym, 0);

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
  {
    hp->button_pressed = True;
    gltrackball_start(hp->trackballs[hp->current_trackball],
                      event->xbutton.x, event->xbutton.y,
                      MI_WIDTH(mi), MI_HEIGHT(mi));
    return True;
  }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
  {
    hp->button_pressed = False;
    return True;
  }
  else if (event->xany.type == KeyPress)
  {
    if (sym == XK_Shift_L || sym == XK_Shift_R)
    {
      hp->current_trackball = 1;
      if (hp->button_pressed)
        gltrackball_start(hp->trackballs[hp->current_trackball],
                          event->xbutton.x, event->xbutton.y,
                          MI_WIDTH(mi), MI_HEIGHT(mi));
      return True;
    }
  }
  else if (event->xany.type == KeyRelease)
  {
    if (sym == XK_Shift_L || sym == XK_Shift_R)
    {
      hp->current_trackball = 0;
      if (hp->button_pressed)
        gltrackball_start(hp->trackballs[hp->current_trackball],
                          event->xbutton.x, event->xbutton.y,
                          MI_WIDTH(mi), MI_HEIGHT(mi));
      return True;
    }
  }
  else if (event->xany.type == MotionNotify && hp->button_pressed)
  {
    gltrackball_track(hp->trackballs[hp->current_trackball],
                      event->xmotion.x, event->xmotion.y,
                      MI_WIDTH(mi), MI_HEIGHT(mi));
    return True;
  }

  return False;
}
ENTRYPOINT Bool hypertorus_handle_event(ModeInfo *mi, XEvent *event)
{
  Display *display = MI_DISPLAY(mi);
  hypertorusstruct *hp = &hyper[MI_SCREEN(mi)];
  KeySym  sym;

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
  {
    hp->button_pressed = True;
    gltrackball_start(hp->trackballs[hp->current_trackball],
                      event->xbutton.x, event->xbutton.y,
                      MI_WIDTH(mi), MI_HEIGHT(mi));
    return True;
  }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
  {
    hp->button_pressed = False;
    return True;
  }
  else if (event->xany.type == KeyPress)
  {
    sym = XKeycodeToKeysym(display,event->xkey.keycode,0);
    if (sym == XK_Shift_L || sym == XK_Shift_R)
    {
      hp->current_trackball = 1;
      if (hp->button_pressed)
        gltrackball_start(hp->trackballs[hp->current_trackball],
                          event->xbutton.x, event->xbutton.y,
                          MI_WIDTH(mi), MI_HEIGHT(mi));
      return True;
    }
  }
  else if (event->xany.type == KeyRelease)
  {
    sym = XKeycodeToKeysym(display,event->xkey.keycode,0);
    if (sym == XK_Shift_L || sym == XK_Shift_R)
    {
      hp->current_trackball = 0;
      if (hp->button_pressed)
        gltrackball_start(hp->trackballs[hp->current_trackball],
                          event->xbutton.x, event->xbutton.y,
                          MI_WIDTH(mi), MI_HEIGHT(mi));
      return True;
    }
  }
  else if (event->xany.type == MotionNotify && hp->button_pressed)
  {
    gltrackball_track(hp->trackballs[hp->current_trackball],
                      event->xmotion.x, event->xmotion.y,
                      MI_WIDTH(mi), MI_HEIGHT(mi));
    return True;
  }

  return False;
}
Beispiel #8
0
ENTRYPOINT Bool
cube_handle_event (ModeInfo *mi, XEvent *event)
{
  cube_configuration *bp = &bps[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      bp->button_down_p = True;
      gltrackball_start (bp->trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      bp->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (bp->trackball, event->xbutton.button, 10,
                              !!event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           bp->button_down_p)
    {
      gltrackball_track (bp->trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == KeyPress)
    {
      KeySym keysym;
      char c = 0;
      XLookupString (&event->xkey, &c, 1, &keysym, 0);
      if (c == ' ')
        {
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
          return True;
        }
      else if (c == '\r' || c == '\n')
        {
          new_cube_colors (mi);
          return True;
        }
    }
  return False;
}
Beispiel #9
0
ENTRYPOINT Bool
molecule_handle_event (ModeInfo *mi, XEvent *event)
{
  molecule_configuration *mc = &mcs[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      mc->button_down_p = True;
      gltrackball_start (mc->trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      mc->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (mc->trackball, event->xbutton.button, 10,
                              !!event->xbutton.state);
      return True;
    }
  else if (event->xany.type == KeyPress)
    {
      KeySym keysym;
      char c = 0;
      XLookupString (&event->xkey, &c, 1, &keysym, 0);

      if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
        {
          GLfloat speed = 4.0;
          mc->mode = 1;
          mc->mode_tick = 10 * speed;
          return True;
        }
    }
  else if (event->xany.type == MotionNotify &&
           mc->button_down_p)
    {
      gltrackball_track (mc->trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }

  return False;
}
Beispiel #10
0
	ENTRYPOINT Bool antmaze_handle_event (ModeInfo *mi, XEvent *event) 
	{
	  antmazestruct *mp = &antmaze[MI_SCREEN(mi)];

	  switch(event->xany.type) {
	  case ButtonPress:

	    switch(event->xbutton.button) {

	    case Button1:
	      mp->button_down_p = True;
	      gltrackball_start(mp->trackball, 
				event->xbutton.x, event->xbutton.y,
				MI_WIDTH (mi), MI_HEIGHT (mi));
	      break;

	    case Button3:
	      mp->focus = (mp->focus + 1) % ANTCOUNT;
	      break;
	      
	    case Button4:
	      mp->mag = max(mp->mag-1, 1);
	      break;

	    case Button5:
	      mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
	      break;
	    }

	    break;
	    
	  case ButtonRelease:

	    switch(event->xbutton.button) {
	    case Button1:
	      mp->button_down_p = False;
	      break;
	    }

	    break;

	  case MotionNotify:
	    if(mp->button_down_p)
	      gltrackball_track(mp->trackball,
				event->xmotion.x, event->xmotion.y,
				MI_WIDTH (mi), MI_HEIGHT (mi));
	    break;
	    
	  default:
	    return False;
	  }

	  return True;
	}
ENTRYPOINT Bool
carousel_handle_event (ModeInfo *mi, XEvent *event)
{
  carousel_state *ss = &sss[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      if (! ss->button_down_p)
        ss->button_down_time = time((time_t *) 0);
      ss->button_down_p = True;
      gltrackball_start (ss->trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      if (ss->button_down_p)
        {
          /* Add the time the mouse was held to the expire times of all
             frames, so that mouse-dragging doesn't count against
             image expiration.
           */
          int secs = time((time_t *) 0) - ss->button_down_time;
          int i;
          for (i = 0; i < ss->nframes; i++)
            ss->frames[i]->expires += secs;
        }
      ss->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (ss->trackball, event->xbutton.button, 5,
                              !event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           ss->button_down_p)
    {
      gltrackball_track (ss->trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }

  return False;
}
Beispiel #12
0
	ENTRYPOINT Bool
	extrusion_handle_event (ModeInfo *mi, XEvent *event)
	{
	  extrusionstruct *gp = &Extrusion[MI_SCREEN(mi)];

	  if (event->xany.type == ButtonPress &&
	      (event->xbutton.button == Button4 ||
	       event->xbutton.button == Button5 ||
	       event->xbutton.button == Button6 ||
	       event->xbutton.button == Button7))
	    {
	      gltrackball_mousewheel (gp->trackball, event->xbutton.button, 10,
	                              !!event->xbutton.state);
	      return True;
	    }
	  else if (event->xany.type == ButtonPress &&   /* rotate with left button */
	           !event->xbutton.state)		/* if no modifier keys */
	    {
	      gp->button_down_p = True;
	      gltrackball_start (gp->trackball,
	                         event->xbutton.x, event->xbutton.y,
	                         MI_WIDTH (mi), MI_HEIGHT (mi));
	      return True;
	    }
	  else if (event->xany.type == ButtonPress)  /* deform with other buttons */
	    {                                        /* or with modifier keys */
	      gp->button2_down_p = True;
	      gp->mouse_start_x = gp->mouse_x = event->xbutton.x;
	      gp->mouse_start_y = gp->mouse_y = event->xbutton.y;
	      return True;
	    }
	  else if (event->xany.type == ButtonRelease)
	    {
	      gp->button_down_p = False;
	      gp->button2_down_p = False;
	      return True;
	    }
	  else if (event->xany.type == MotionNotify)
	    {
	      if (gp->button_down_p)
	        gltrackball_track (gp->trackball,
	                           event->xmotion.x, event->xmotion.y,
	                           MI_WIDTH (mi), MI_HEIGHT (mi));
	      if (gp->button2_down_p)
	        {
	          gp->mouse_x = event->xmotion.x;
	          gp->mouse_y = event->xmotion.y;
	        }
	      return True;
	    }

	  return False;
	}
ENTRYPOINT Bool
pinion_handle_event (ModeInfo *mi, XEvent *event)
{
  pinion_configuration *pp = &pps[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      pp->button_down_p = True;
      gltrackball_start (pp->trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      pp->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (pp->trackball, event->xbutton.button, 5,
                              !!event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           pp->button_down_p)
    {
      gltrackball_track (pp->trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == KeyPress)
    {
      KeySym keysym;
      char c = 0;
      XLookupString (&event->xkey, &c, 1, &keysym, 0);
      if (c == ' ' && debug_one_gear_p && pp->ngears)
        {
          delete_gear (mi, pp->gears[0]);
          return True;
        }
    }

  return False;
}
ENTRYPOINT Bool
stairs_handle_event (ModeInfo *mi, XEvent *event)
{
  stairsstruct *sp = &stairs[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      sp->button_down_p = True;
      gltrackball_start (sp->trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      sp->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (sp->trackball, event->xbutton.button, 10,
                              !!event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           sp->button_down_p)
    {
      gltrackball_track (sp->trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == KeyPress)
    {
      KeySym keysym;
      char c = 0;
      XLookupString (&event->xkey, &c, 1, &keysym, 0);
      if (c == ' ')
        {
          gltrackball_reset (sp->trackball);
          return True;
        }
    }

  return False;
}
Beispiel #15
0
ENTRYPOINT Bool
bit_handle_event (ModeInfo *mi, XEvent *event)
{
  bit_configuration *bp = &bps[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      bp->button_down_p = True;
      gltrackball_start (bp->trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      bp->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (bp->trackball, event->xbutton.button, 3,
                              !!event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           bp->button_down_p)
    {
      gltrackball_track (bp->trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == KeyPress)
    {
      KeySym keysym;
      char c = 0;
      XLookupString (&event->xkey, &c, 1, &keysym, 0);
      if (c == ' ' || c == '1' || c == '0')
        {
          bp->kbd = c;
          return True;
        }
    }

  return False;
}
Beispiel #16
0
/* event handling */
ENTRYPOINT Bool providence_handle_event(ModeInfo *mi, XEvent *event) 
{
  providencestruct *mp = &providence[MI_SCREEN(mi)];

  switch(event->xany.type) {
  case ButtonPress:

    switch(event->xbutton.button) {

    case Button1:
      mp->button_down_p = True;
      gltrackball_start(mp->trackball, 
			event->xbutton.x, event->xbutton.y,
			MI_WIDTH (mi), MI_HEIGHT (mi));
      break;
      
    case Button4:
      mp->camera_velocity += 1.0;
      break;

    case Button5:
      mp->camera_velocity -= 1.0;
      break;
    }

    break;
    
  case ButtonRelease:

    switch(event->xbutton.button) {
    case Button1:
      mp->button_down_p = False;
      break;
    }

    break;

  case MotionNotify:
    if(mp->button_down_p)
      gltrackball_track(mp->trackball,
			event->xmotion.x, event->xmotion.y,
			MI_WIDTH (mi), MI_HEIGHT (mi));
    break;
    
  default:
    return False;
  }

  return True;
}
Beispiel #17
0
ENTRYPOINT Bool
fire_handle_event (ModeInfo *mi, XEvent *event)
{
  firestruct *fs = &fire[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      fs->button_down_p = True;
      event->xbutton.x = MI_WIDTH(mi)  - event->xbutton.x; /* kludge! */
      event->xbutton.y = MI_HEIGHT(mi) - event->xbutton.y;
      gltrackball_start (fs->trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      fs->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (fs->trackball, event->xbutton.button, 5,
                              !!event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           fs->button_down_p)
    {
      event->xmotion.x = MI_WIDTH(mi)  - event->xmotion.x; /* kludge! */
      event->xmotion.y = MI_HEIGHT(mi) - event->xmotion.y;
      gltrackball_track (fs->trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }

  return False;
}
Beispiel #18
0
/* A utility function for event-handler functions:
   Handles the various motion and click events related to trackballs.
   Returns True if the event was handled.
 */
Bool
gltrackball_event_handler (XEvent *event,
                           trackball_state *ts,
                           int window_width, int window_height,
                           Bool *button_down_p)
{
  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      *button_down_p = True;
      gltrackball_start (ts,
                         event->xbutton.x, event->xbutton.y,
                         window_width, window_height);
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      *button_down_p = False;
      gltrackball_stop (ts);
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (ts, event->xbutton.button, 10,
                              !!event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           *button_down_p)
    {
      gltrackball_track (ts,
                         event->xmotion.x, event->xmotion.y,
                         window_width, window_height);
      return True;
    }

  return False;
}
ENTRYPOINT Bool
toasters_handle_event (ModeInfo *mi, XEvent *event)
{
  toaster_configuration *bp = &bps[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      bp->button_down_p = True;
      gltrackball_start (bp->user_trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      bp->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (bp->user_trackball, event->xbutton.button, 5,
                              !event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           bp->button_down_p)
    {
      gltrackball_track (bp->user_trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }

  return False;
}
Beispiel #20
0
	ENTRYPOINT Bool
	gflux_handle_event (ModeInfo *mi, XEvent *event)
	{
	  gfluxstruct *gp = &gfluxes[MI_SCREEN(mi)];

	  if (event->xany.type == ButtonPress &&
	      event->xbutton.button == Button1)
	    {
	      gp->button_down_p = True;
	      gltrackball_start (gp->trackball,
	                         event->xbutton.x, event->xbutton.y,
	                         MI_WIDTH (mi), MI_HEIGHT (mi));
	      return True;
	    }
	  else if (event->xany.type == ButtonRelease &&
	           event->xbutton.button == Button1)
	    {
	      gp->button_down_p = False;
	      return True;
	    }
	  else if (event->xany.type == ButtonPress &&
	           (event->xbutton.button == Button4 ||
	            event->xbutton.button == Button5 ||
	            event->xbutton.button == Button6 ||
	            event->xbutton.button == Button7))
	    {
	      gltrackball_mousewheel (gp->trackball, event->xbutton.button, 10,
	                              !!event->xbutton.state);
	      return True;
	    }
	  else if (event->xany.type == MotionNotify &&
	           gp->button_down_p)
	    {
	      gltrackball_track (gp->trackball,
	                         event->xmotion.x, event->xmotion.y,
	                         MI_WIDTH (mi), MI_HEIGHT (mi));
	      return True;
	    }

	  return False;
	}
Beispiel #21
0
ENTRYPOINT Bool
logo_handle_event (ModeInfo *mi, XEvent *event)
{
  logo_configuration *dc = &dcs[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      dc->button_down_p = True;
      gltrackball_start (dc->trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      dc->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (dc->trackball, event->xbutton.button, 10,
                              !!event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           dc->button_down_p)
    {
      gltrackball_track (dc->trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }

  return False;
}
Beispiel #22
0
	/* handle input events or not if daemon running the show */
	ENTRYPOINT Bool 
	topBlock_handle_event (ModeInfo *mi, XEvent *event)
	{
	  topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
		if (event->xany.type == KeyPress)    {
	    KeySym keysym;
	    char c = 0;
	    XLookupString (&event->xkey, &c, 1, &keysym, 0);
	    if (c == 'a') {
				tb->eyeX++;
				return True;
			} else if (c == 'z') {
				tb->eyeX--;
				return True;
			} else if (c == 's') {
				tb->eyeY--;
				return True;
			} else if (c == 'x') {
				tb->eyeY++;
				return True;
			} else if (c == 'd') {
				tb->eyeZ++;
				return True;
			} else if (c == 'c') {
				tb->eyeZ--;
				return True;
			} else if (c == 'f') {
				camX++;
				return True;
			} else if (c == 'v') {
				camX--;
				return True;
			} else if (c == 'g') {
				camY++;
				return True;
			} else if (c == 'b') {
				camY--;
				return True;
			} else if (c == 'h') {
				camZ++;
				return True;
			} else if (c == 'n') {
				camZ--;
				return True;
			} else if (c == 'r') {
				tb->rotation++;
				return True;
			}
		}
	  if (event->xany.type == ButtonPress &&
	      event->xbutton.button == Button1)
	    {
	      tb->button_down_p = True;
	      gltrackball_start (tb->trackball,
	                         event->xbutton.x, event->xbutton.y,
	                         MI_WIDTH (mi), MI_HEIGHT (mi));
	      return True;
	    }
	  else if (event->xany.type == ButtonRelease &&
	           event->xbutton.button == Button1)
	    {
	      tb->button_down_p = False;
	      return True;
	    }
	  else if (event->xany.type == ButtonPress &&
	           (event->xbutton.button == Button4 ||
	            event->xbutton.button == Button5 ||
	            event->xbutton.button == Button6 ||
	            event->xbutton.button == Button7))
	    {
	      gltrackball_mousewheel (tb->trackball, event->xbutton.button, 10,
	                              !!event->xbutton.state);
	      return True;
	    }
	  else if (event->xany.type == MotionNotify &&
	           tb->button_down_p)
	    {
	      gltrackball_track (tb->trackball,
	                         event->xmotion.x, event->xmotion.y,
	                         MI_WIDTH (mi), MI_HEIGHT (mi));
	      return True;
	    }
		return False;
	}
ENTRYPOINT void 
init_lavalite (ModeInfo *mi)
{
  lavalite_configuration *bp;
  int wire = MI_IS_WIREFRAME(mi);

  if (!bps) {
    bps = (lavalite_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (lavalite_configuration));
    if (!bps) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }

    bp = &bps[MI_SCREEN(mi)];
  }

  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_lavalite (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  {
    char *s = do_style;
    if (!s || !*s || !strcasecmp (s, "classic")) bp->style = CLASSIC;
    else if (!strcasecmp (s, "giant"))  bp->style = GIANT;
    else if (!strcasecmp (s, "cone"))   bp->style = CONE;
    else if (!strcasecmp (s, "rocket")) bp->style = ROCKET;
    else if (!strcasecmp (s, "random"))
      {
        if (random() & 1) bp->style = CLASSIC;  /* half the time */
        else bp->style = (random() % ((int) ROCKET+1));
      }
    else
      {
        fprintf (stderr,
         "%s: style must be Classic, Giant, Cone, or Rocket (not \"%s\")\n",
                 progname, s);
        exit (1);
      }
  }

  parse_color (mi, "lava",  lava_color_str,  lava_color);
  parse_color (mi, "fluid", fluid_color_str, fluid_color);
  parse_color (mi, "base",  base_color_str,  base_color);
  parse_color (mi, "table", table_color_str, table_color);

  if (!wire)
    {
      GLfloat amb[4]  = {0.0, 0.0, 0.0, 1.0};
      GLfloat dif[4]  = {1.0, 1.0, 1.0, 1.0};
      GLfloat spc0[4] = {0.0, 1.0, 1.0, 1.0};
      GLfloat spc1[4] = {1.0, 0.0, 1.0, 1.0};

      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_LIGHT1);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
      glEnable(GL_NORMALIZE);
      glShadeModel(GL_SMOOTH);

      glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc0);

      glLightfv(GL_LIGHT1, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT1, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT1, GL_SPECULAR, spc1);

      glLightfv(GL_LIGHT2, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT2, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT2, GL_SPECULAR, spc0);
    }

  {
    Bool spinx=False, spiny=False, spinz=False;
    double spin_speed   = 0.4;
    double wander_speed = 0.03;

    char *s = do_spin;
    while (*s)
      {
        if      (*s == 'x' || *s == 'X') spinx = True;
        else if (*s == 'y' || *s == 'Y') spiny = True;
        else if (*s == 'z' || *s == 'Z') spinz = True;
        else if (*s == '0') ;
        else
          {
            fprintf (stderr,
         "%s: spin must contain only the characters X, Y, or Z (not \"%s\")\n",
                     progname, do_spin);
            exit (1);
          }
        s++;
      }

    bp->rot = make_rotator (spinx ? spin_speed : 0,
                            spiny ? spin_speed : 0,
                            spinz ? spin_speed : 0,
                            1.0,
                            do_wander ? wander_speed : 0,
                            False);
    bp->rot2 = make_rotator (spin_speed, 0, 0,
                             1, 0.1,
                             False);
    bp->trackball = gltrackball_init ();

    /* move initial camera position up by around 15 degrees:
       in other words, tilt the scene toward the viewer. */
    gltrackball_start (bp->trackball, 50, 50, 100, 100);
    gltrackball_track (bp->trackball, 50,  5, 100, 100);

    /* Oh, but if it's the "Giant" model, tilt the scene away: make it
       look like we're looking up at it instead of down at it! */
    if (bp->style == GIANT)
      gltrackball_track (bp->trackball, 50, -12, 100, 100);
    else if (bp->style == ROCKET)  /* same for rocket, but not as much */
      gltrackball_track (bp->trackball, 50, -4, 100, 100);
  }

  switch (bp->style)
    {
    case CLASSIC: bp->model = classic_lamp; break;
    case GIANT:   bp->model = giant_lamp;   break;
    case CONE:    bp->model = cone_lamp;    break;
    case ROCKET:  bp->model = rocket_lamp;  break;
    default: abort(); break;
    }

  bp->max_bottle_radius = max_bottle_radius (bp);

  bp->launch_chance = speed;
  bp->blobs_per_group = BLOBS_PER_GROUP;
  bp->just_started_p = True;

  bp->nballs = (((MI_COUNT (mi) + 1) * bp->blobs_per_group)
                + 2);
  bp->balls = (metaball *) calloc (sizeof(*bp->balls), bp->nballs+1);

  bp->bottle_list = glGenLists (1);
  bp->ball_list = glGenLists (1);

  generate_bottle (mi);
  generate_static_blobs (mi);
}