コード例 #1
0
ファイル: glui_rotation.cpp プロジェクト: 4ian/GD
void  GLUI_Rotation::reset( void )
{
  ball->init(); /** reset quaternion, etc. **/
  ball->set_params( vec2( (float)(w/2), (float)((h-18)/2)), 
		   (float) 2.0*(h-18) );

  set_spin( this->damping );	

  copy_ball_to_float_array();

  translate_and_draw_front();

  output_live(true); /*** Output live and draw main grx window ***/
}
コード例 #2
0
int    GLUI_Translation::iaction_mouse_down_handler( int local_x, 
						     int local_y )
{
  int center_x, center_y;

  down_x = local_x;
  down_y = local_y;

  if ( trans_type == GLUI_TRANSLATION_XY ) {
    orig_x = float_array_val[0];
    orig_y = float_array_val[1];

    /** Check if the Alt key is down, which means lock to an axis **/

    center_x = w/2;
    center_y = (h-18)/2;

    if ( glui->curr_modifiers & GLUT_ACTIVE_ALT ) {
      if ( ABS(local_y-center_y) > ABS(local_x-center_x) ) {
	locked = GLUI_TRANSLATION_LOCK_Y;
	glutSetCursor( GLUT_CURSOR_UP_DOWN );
      }
      else {
	locked = GLUI_TRANSLATION_LOCK_X;
	glutSetCursor( GLUT_CURSOR_LEFT_RIGHT );
      }
    }
    else {
      locked = GLUI_TRANSLATION_LOCK_NONE;
      glutSetCursor( GLUT_CURSOR_SPRAY );
    }
  }
  else if ( trans_type == GLUI_TRANSLATION_X ) {
    glutSetCursor( GLUT_CURSOR_LEFT_RIGHT );
    orig_x = float_array_val[0];
  }
  else if ( trans_type == GLUI_TRANSLATION_Y ) {
    glutSetCursor( GLUT_CURSOR_UP_DOWN );
    orig_y = float_array_val[0];
  }
  else if ( trans_type == GLUI_TRANSLATION_Z ) {
    glutSetCursor( GLUT_CURSOR_UP_DOWN );
    orig_z = float_array_val[0];
  }

  trans_mouse_code = 1;
  translate_and_draw_front();

  return false;
}
コード例 #3
0
ファイル: glui_rotation.C プロジェクト: Benignoperez/jot-lib
void        GLUI_Rotation::idle( void )
{
  spinning = ball->is_spinning;

  if ( can_spin == true AND spinning == true ) {
    copy_float_array_to_ball();
    ball->idle();

    *ball->rot_ptr = *ball->rot_ptr * ball->rot_increment;

    mat4 tmp_rot;
    tmp_rot = *ball->rot_ptr;

    copy_ball_to_float_array();

    draw_active_area_only = true;
    translate_and_draw_front();
    draw_active_area_only = false;

    output_live(true); /** output live and update gfx **/
  }
  else { 
  }
}
コード例 #4
0
int    GLUI_EditText::key_handler( unsigned char key,int modifiers )
{
  int i, regular_key;
  /* int has_selection;              */

  if ( NOT glui )
    return false;

  if ( debug )
    dump( stdout, "-> KEY HANDLER" );

  regular_key = false;
  /*  has_selection = (sel_start != sel_end);              */

  if ( key == 21 AND (modifiers & GLUT_ACTIVE_CTRL )!=0) { /* DEL all text */
    /** This one (key==21) may not port!! */
    
    insertion_pt = -1;  
    text[0] = '\0';
    sel_start = sel_end = -1;
  }
  else if ( key == 13 ) {           /* RETURN */
    /*    glui->disactivate_current_control();              */
    disactivate();  /** Force callbacks, etc **/
    activate(GLUI_ACTIVATE_TAB);     /** Reselect all text **/
    translate_and_draw_front();
    return true;
  }
  else if ( key  == 27 ) {         /* ESCAPE */
    glui->disactivate_current_control();
    return true;
  }
  else if ( key == 8 ) {       /* BACKSPACE */
    if ( sel_start == sel_end ) {   /* no selection */
      if ( insertion_pt > 0 ) {
	/*** See if we're deleting a period in a float data-type box ***/
	if ( data_type == GLUI_EDITTEXT_FLOAT AND text[insertion_pt-1]=='.' )
	  num_periods--;
	
	/*** Shift over string first ***/
	insertion_pt--;
	for( i=insertion_pt; i< (int)strlen( text ); i++ )
	  text[i] = text[i+1];    
      }
    }
    else {                         /* There is a selection */
      clear_substring( MIN(sel_start,sel_end), MAX(sel_start,sel_end ));
      insertion_pt = MIN(sel_start,sel_end);
      sel_start = sel_end = insertion_pt;
    }
  }
  else {                      /* Regular key */    
    regular_key = true;
    
    /** Check if we only accept numbers **/
    if (data_type == GLUI_EDITTEXT_FLOAT ) {
      if ( (key < '0' OR key > '9') AND key != '.' AND key != '-' )
	return true;

      if ( key == '-' ) { /* User typed a '-' */

	/* If user has first character selected, then '-' is allowed */
	if ( NOT ( MIN(sel_start,sel_end) == 0 AND
		   MAX(sel_start,sel_end) > 0 ) ) {

	  /* User does not have 1st char selected */
	  if (insertion_pt != 0 OR text[0] == '-' ) {
	    return true; /* Can only place negative at beginning of text,
			    and only one of them */
	  }
	}
      }

      if ( key == '.' ) {
	/*printf( "PERIOD: %d\n", num_periods );              */

	if ( num_periods > 0 ) {
	  /** We're trying to type a period, but the text already contains
	    a period.  Check whether the period is contained within
	    is current selection (thus it will be safely replaced) **/

	  int period_found = false; 
	  if ( sel_start != sel_end ) {
	    for( i=MIN(sel_end,sel_start); i<MAX(sel_start,sel_end); i++ ) {
	      /*  printf( "%c ", text[i] );              */
	      if ( text[i] == '.' ) {
		period_found = true;
		break;
	      }
	    }
	  }

	  /* printf( "found: %d    num: %d\n", period_found, num_periods );              */
	  
	  if ( NOT period_found )
	    return true;
	}
      }
    } 
    else if (data_type == GLUI_EDITTEXT_INT)	
    {
      if ( (key < '0' OR key > '9') AND key != '-' )
	return true;

      if ( key == '-' ) { /* User typed a '-' */

	/* If user has first character selected, then '-' is allowed */
	if ( NOT ( MIN(sel_start,sel_end) == 0 AND
		   MAX(sel_start,sel_end) > 0 ) ) {

	  /* User does not have 1st char selected */
	  if (insertion_pt != 0 OR text[0] == '-' ) {
	    return true; /* Can only place negative at beginning of text,
			    and only one of them */
	  }
	}
      }
    }

    /** This is just to get rid of warnings - the flag regular_key is 
      set if the key was not a backspace, return, whatever.  But I
      believe if we're here, we know it was a regular key anyway */
    if ( regular_key ) {
    }

    /**** If there's a current selection, erase it ******/
    if ( sel_start != sel_end ) {
      clear_substring( MIN(sel_start,sel_end), MAX(sel_start,sel_end ));
      insertion_pt = MIN(sel_start,sel_end);
      sel_start = sel_end = insertion_pt;
    }

    /******** check whether we have space ******/
    if ( (int)strlen( text ) + 2 >= sizeof( GLUI_String ))
      return false;

    /******** We insert the character into the string ***/
     
    /*** Shift over string first ***/
    for( i=(int)strlen( text ); i >= insertion_pt; i-- )
      text[i+1] = text[i];
    
    /******** Now insert the character ********/
    text[insertion_pt] = key;    

    /******** Move the insertion point and substring_end one over ******/
    insertion_pt++;
    substring_end++;

    sel_start = sel_end = insertion_pt;
  }
  
  /******** Now redraw text ***********/
  /* Hack to prevent text box from being cleared first **/  
  /**  int substring_change =  update_substring_bounds();
    draw_text_only = 
    (NOT substring_change AND NOT has_selection AND regular_key ); 
    */

  draw_text_only = false;  /** Well, hack is not yet working **/
  update_and_draw_text();
  draw_text_only = false;


  if ( debug )
    dump( stdout, "<- KEY HANDLER" );

  /*** Now look to see if this string has a period ***/
  num_periods = 0;
  for( i=0; i<(int)strlen(text); i++ )
    if ( text[i] == '.' )
      num_periods++;

  return true;
}
コード例 #5
0
void    GLUI_EditText::disactivate( void )
{
  int    new_int_val;
  float  new_float_val;

  active = false;

  if ( NOT glui )
    return;

  if ( debug )
    dump( stdout, "-> DISACTIVATE" );

  sel_start = sel_end = insertion_pt = -1; 

  /***** Retrieve the current value from the text *****/
  /***** The live variable will be updated by set_text() ****/
  if ( data_type == GLUI_EDITTEXT_FLOAT ) {
    if ( text[0] == '\0' ) /* zero-length string - make it "0.0" */
      strcpy( text, "0.0" );

    new_float_val = atof( text );

    set_float_val( new_float_val );
  }
  else if ( data_type == GLUI_EDITTEXT_INT ) {
    if ( text[0] == '\0' ) /* zero-length string - make it "0" */
      strcpy( text, "0" );

    new_int_val = atoi( text );

    set_int_val( new_int_val );
  }
  else 
    if ( data_type == GLUI_EDITTEXT_TEXT ) {
      set_text(text); /* This will force callbacks and gfx refresh */
    }

  update_substring_bounds();

  /******** redraw text without insertion point ***********/
  translate_and_draw_front();

  /***** Now do callbacks if value changed ******/
  if ( strcmp( orig_text, text ) != 0 ) {
    this->execute_callback();
    
    if ( 0 ) {
      /* THE CODE BELOW IS FROM WHEN SPINNER ALSO MAINTAINED CALLBACKS    */
      if ( spinner == NULL ) {   /** Are we independent of a spinner?  **/  
	if ( callback ) {              
	  callback( this->user_id );              
	}              
      }              
      else {                      /* We're attached to a spinner */              
	spinner->do_callbacks();  /* Let the spinner do the callback stuff */  
      }              
    }
  }

  if ( debug )
    dump( stdout, "<- DISACTIVATE" );
}
コード例 #6
0
ファイル: glui_control.cpp プロジェクト: 383530895/liquidfun
/* Redraw this control. */
void	      GLUI_Control::redraw(void) {
    if (glui==NULL || hidden) return;
    if (glui->should_redraw_now(this))
      translate_and_draw_front();
}