예제 #1
0
void GLUI_EditText::common_construct( GLUI_Node *parent, const char *name, 
                                      int data_t, int live_t, void *data, int id, 
                                      GLUI_CB cb )
{
  common_init();
  set_name( name );
    
  live_type   = live_t;
  data_type   = data_t;
  ptr_val     = data;
  user_id     = id;
  callback    = cb;
    

  if ( live_type == GLUI_LIVE_INT) {
    if ( data == NULL )
      set_int_val(int_val);   /** Set to some default, in case of no live var **/
  }
  else if ( live_type == GLUI_LIVE_FLOAT ) {
    num_periods = 1;
    if ( data == NULL )
      set_float_val(float_val);   /** Set to some default, in case of no live var **/
  }
  else if ( live_type == GLUI_LIVE_DOUBLE ) {
    num_periods = 1;
    if ( data == NULL )
      set_double_val(double_val);   /** Set to some default, in case of no live var **/
  }


  parent->add_control( this );

  init_live();
}
예제 #2
0
void    GLUI_Slider::update_val( int x, int y )
{

   int grads;

   int min_x, max_x, wid_x;

   int g;
   double g_f;

   min_x = 2 + GLUI_SLIDER_KNOB_SIDE_BORDER + GLUI_SLIDER_KNOB_HALF_WIDTH;
   max_x = w - 2 - GLUI_SLIDER_KNOB_HALF_WIDTH - GLUI_SLIDER_KNOB_SIDE_BORDER;
   wid_x = max_x - min_x + 1;

   if (graduations == 0)
      grads = wid_x;
   else
      grads = graduations;

   if (x < min_x)
      x = min_x;
   else if (x > max_x)
      x = max_x;

   if (x == max_x)
      g = grads-1;
   else
      g = (int) ((double)(((double)grads)*((double)(x-min_x))/((double)(max_x - min_x))));

   g_f = ((double)g)/((double)(grads-1));

   switch (data_type) {
   case GLUI_SLIDER_INT:
      set_int_val((int)(((double)int_low)+0.5+((double)(g_f*((double)(int_high-int_low))))));
      set_float_val((float)(int_val));
      break;
   case GLUI_SLIDER_FLOAT:
      set_float_val((float)(((double)float_low) + g_f*((double)(float_high-float_low))));
      set_int_val((int)(float_val));
      break;
   default:
      fprintf(stderr,"GLUI_Slider::upate_knob - Impossible data type!\n");
      abort();
   }

}
void GLUI_EditText::set_float_limits( float low, float high, int limit_type )
{
  has_limits  = limit_type;
  float_low   = low;
  float_high  = high;
  
  if ( NOT IN_BOUNDS( float_val, float_low, float_high ))
    set_float_val( float_low );

  int_low     = (int) float_low;
  int_high    = (int) float_high;
}
예제 #4
0
void   GLUI_Slider::set_int_limits( int low, int high)
{
   if (low > high) {
      fprintf(stderr,"GLUI_Slider::set_int_limits - Ignoring: low > hi\n");
      return;
   }

   int_low     = low;
   int_high    = high;

   if ( NOT IN_BOUNDS( int_val, int_low, int_high )) {
      set_int_val( int_low );
      set_float_val( (float)int_val );
   }

   float_low   = (float) int_low;
   float_high  = (float) int_high;
}
예제 #5
0
GLUI_Slider::GLUI_Slider(GLUI_Node *parent, const char *name,
                         int id, GLUI_CB cb,
                         int the_data_type,
                         float limit_lo,
                         float limit_hi,
                         void *data)
{
   common_init();
   user_id = id;
   callback = cb;
   set_name( name );
   data_type = the_data_type;
   ptr_val = data;

   if ( data_type == GLUI_SLIDER_INT ) {
      set_int_limits((int)limit_lo, (int)limit_hi);
      if ( data == NULL ) {
         set_int_val(int_low);
         live_type = GLUI_LIVE_NONE;
      } else
         live_type = GLUI_LIVE_INT;

   } else if ( data_type == GLUI_SLIDER_FLOAT ) {
      set_float_limits(limit_lo, limit_hi);
      if ( data == NULL ) {
         set_float_val(float_low);
         live_type = GLUI_LIVE_NONE;
      } else
         live_type = GLUI_LIVE_FLOAT;
   }

   parent->add_control( this );

   init_live();

   //In case the live var was out of range,
   //(and got clamped) we update the live
   //var to the internal value
   output_live(false);
}
예제 #6
0
int    GLUI_Slider::special_handler( int key,int mods )
{
   int grads;

   int min_x, max_x, wid_x;

   int g;
   double g_f;

   int new_int;

   min_x = 2 + GLUI_SLIDER_KNOB_SIDE_BORDER + GLUI_SLIDER_KNOB_HALF_WIDTH;
   max_x = w - 2 - GLUI_SLIDER_KNOB_HALF_WIDTH - GLUI_SLIDER_KNOB_SIDE_BORDER;
   wid_x = max_x - min_x + 1;

   //The arrows adjust the slider's value.
   //Without mods (shift, ctrl, alt), the current
   //value is rounded to the nearest grad and then
   //one grad is added/subtracted.  However, shift,
   //ctrl, alt modify the grad size by 1/2,1/10,
   //1/100. If this is an int slider, the min
   //change is 1.
   //Note, by default, grads=0 which takes the
   //num of grads to be equal to the pixel
   //width of the slider...

   if (graduations == 0)
      grads = wid_x;
   else
      grads = graduations;

   if (mods == 0) {
      //Use unmodified grads
   } else if (mods & GLUT_ACTIVE_SHIFT) {
      grads = 2*(grads-1) + 1;
   } else if (mods & GLUT_ACTIVE_CTRL) {
      grads = 10*(grads-1) + 1;
   } else if (mods & GLUT_ACTIVE_ALT) {
      grads = 100*(grads-1) + 1;
   } else {
      return false;
   }

   switch (data_type) {
   case GLUI_SLIDER_INT:
      if (int_low != int_high) {
         if (int_val == int_high)
            g = grads-1;
         else
            g = ((int)(((double)grads)*((double)(int_val-int_low))/((double)(int_high - int_low))));
      } else
         g = 0;
      break;
   case GLUI_SLIDER_FLOAT:
      if (float_low != float_high) {
         if (float_val == float_high)
            g = grads-1;
         else
            g = ((int)(((double)grads)*((double)(float_val-float_low))/((double)(float_high - float_low))));
      } else
         g = 0;
      break;
   default:
      fprintf(stderr,"GLUI_Slider::upate_knob - Impossible data type!\n");
      abort();
   }

   switch (key) {
   case GLUT_KEY_RIGHT:
      g += 1;
      if (g > (grads-1))
         g = grads-1;
      break;
   case GLUT_KEY_LEFT:
      g -= 1;
      if (g < 0)
         g = 0;
      break;
   default:
      return false;
      break;
   }

   g_f = ((double)g)/((double)(grads-1));

   switch (data_type) {
   case GLUI_SLIDER_INT:
      new_int = (int) (((double)int_low) + ((double)(g_f*((double)(int_high-int_low)) )));

      if (new_int == int_val) {
         switch (key) {
         case GLUT_KEY_RIGHT:
            new_int += 1;
            if (new_int > int_high)
               new_int = int_high;
            break;
         case GLUT_KEY_LEFT:
            new_int -= 1;
            if (new_int < int_low)
               new_int = int_low;
            break;
         }
      }
      set_int_val(new_int);
      set_float_val((float)(int_val));
      break;
   case GLUI_SLIDER_FLOAT:
      set_float_val((double)float_low + ((double)g_f)*((double)(float_high-float_low)));
      set_int_val((int)(float_val));
      break;
   default:
      fprintf(stderr,"GLUI_Slider::upate_knob - Impossible data type!\n");
      abort();
   }

   draw_translated_active_area();
   if ( glui ) glui->post_update_main_gfx();
   execute_callback();

   return false;
}
예제 #7
0
void    GLUI_EditText::deactivate( void )
{
  int    new_int_val;
  float  new_float_val;
  double  new_double_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.length() == 0 ) /* zero-length string - make it "0.0" */
      text = "0.0";

    new_float_val = atof( text.c_str() );

    set_float_val( new_float_val );
  }
  else if ( data_type == GLUI_EDITTEXT_DOUBLE ) {
    if ( text.length() == 0 ) /* zero-length string - make it "0.0" */
      text = "0.0";

    new_double_val = atof( text.c_str() );

    set_double_val( new_double_val );
  }
  else if ( data_type == GLUI_EDITTEXT_INT ) {
    if ( text.length() == 0 ) /* zero-length string - make it "0" */
      text = "0";

    new_int_val = atoi( text.c_str() );

    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 ***********/
  redraw();

  /***** Now do callbacks if value changed ******/
  if ( orig_text != text ) {
    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 );              
        }              
      }              
      else {                      /* We're attached to a spinner */              
        spinner->do_callbacks();  /* Let the spinner do the callback stuff */  
      }              
    }
  }

  if ( debug )
    dump( stdout, "<- DISACTIVATE" );
}