Exemplo n.º 1
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;
}
Exemplo n.º 2
0
int    GLUI_Scrollbar::mouse_down_handler( int local_x, int local_y )
{
  last_update_time=GLUI_Time()-1.0;
  this->state = find_arrow( local_x, local_y );
  GLUI_Master.glui_setIdleFuncIfNecessary();

  /*  printf( "spinner: mouse down  : %d/%d   arrow:%d\n", local_x, local_y,
      find_arrow( local_x, local_y ));
      */

  if ( state != GLUI_SCROLL_STATE_UP AND state != GLUI_SCROLL_STATE_DOWN)
    return true;

  reset_growth();

  /*** ints and floats behave a bit differently.  When you click on
    an int spinner, you expect the value to immediately go up by 1, whereas
    for a float it'll go up only by a fractional amount.  Therefore, we
    go ahead and increment by one for int spinners ***/
#if 1
  if ( data_type == GLUI_SCROLL_INT ) {
    // Allow for possibility of reversed limits
    int lo = std::min(int_min,int_max);
    int hi = std::max(int_min,int_max);
    int increase = int_min < int_max ? 1 : -1;
    int new_val = int_val;
    if ( state == GLUI_SCROLL_STATE_UP ) {
      new_val += increase;
    } else if ( state == GLUI_SCROLL_STATE_DOWN ) {
      new_val -= increase;
    }
    if (new_val >= lo && new_val <= hi && new_val!=int_val) {
      set_int_val(new_val);
      do_callbacks();
    }
  }
#endif
  do_click();
  redraw();

  return false;
}
Exemplo n.º 3
0
GLUI_RadioButton::GLUI_RadioButton( GLUI_RadioGroup *grp, const char *name ) :
    GLUI_Container(name)
{
  common_init();

  set_int_val( 0 );

  /** A radio button's user id is always its ordinal number (zero-indexed)
      within the group */
  user_id    = grp->num_buttons;
  group = grp;

  group->num_buttons++;   /* Increments radiogroup's button count */
  group->add_control( this );

  /*** Now update button states ***/
  group->set_int_val( group->int_val ); /* This tells the group to
                                           reset itself to its
                                           current value, thereby
                                           updating all its buttons */
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
int    GLUI_ActiveText::mouse_up_handler( int local_x, int local_y, bool new_inside )
{
   bool old_inside;

   set_int_val( 0 );

   old_inside  = currently_inside;
   currently_inside = new_inside;

   currently_pressed = false;

   if ( old_inside )
   {
      draw_translated_active_area();
   }

   if ( currently_inside )
   {
      execute_callback();
   }

   return false;
}
Exemplo n.º 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;
}
Exemplo n.º 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" );
}
Exemplo n.º 8
0
void edit_value(int curr)
{
    struct passwd *pw = NULL;
    char ctdluidname[256];
    char buf[SIZ];
    char *default_value = NULL;
    int ctdluid = 0;
    int portnum = 0;
    int auth = 0;
    int lportnum = 0;

    if (setup_type == UI_SILENT)
    {
        default_value = getenv(EnvNames[curr]);
    }
    if (default_value == NULL) {
        default_value = "";
    }

    switch (curr) {

    case eSysAdminName:
        getconf_str(admin_name, "c_sysadm");
        set_str_val(curr, admin_name, default_value);
        setconf_str("c_sysadm", admin_name);
        break;

    case eSysAdminPW:
        set_str_val(curr, admin_pass, default_value);
        break;

    case eUID:

        if (setup_type == UI_SILENT)
        {
            if (default_value) {
                ctdluid = atoi(default_value);
            }
        }
        else
        {
#ifdef __CYGWIN__
            ctdluid = 0;	/* work-around for Windows */
#else
            pw = getpwuid(ctdluid);
            if (pw == NULL) {
                set_int_val(curr, &ctdluid, default_value);
            }
            else {
                strcpy(ctdluidname, pw->pw_name);
                set_str_val(curr, ctdluidname, default_value);
                pw = getpwnam(ctdluidname);
                if (pw != NULL) {
                    ctdluid = pw->pw_uid;
                }
                else if (atoi(ctdluidname) > 0) {
                    ctdluid = atoi(ctdluidname);
                }
            }
#endif
        }
        setconf_int("c_ctdluid", ctdluid);
        break;

    case eIP_ADDR:
        getconf_str(buf, "c_ip_addr");
        set_str_val(curr, buf, default_value);
        setconf_str("c_ip_addr", buf);
        break;

    case eCTDL_Port:
        portnum = getconf_int("c_port_number");
        set_int_val(curr, &portnum, default_value);
        setconf_int("c_port_number", portnum);
        break;

    case eAuthType:
        auth = getconf_int("c_auth_mode");
        if (setup_type == UI_SILENT)
        {
            if ( (default_value) && (!strcasecmp(default_value, "yes")) ) auth = AUTHMODE_HOST;
            if ( (default_value) && (!strcasecmp(default_value, "host")) ) auth = AUTHMODE_HOST;
            if ( (default_value) && (!strcasecmp(default_value, "ldap")) ) auth = AUTHMODE_LDAP;
            if ( (default_value) && (!strcasecmp(default_value, "ldap_ad")) ) auth = AUTHMODE_LDAP_AD;
            if ( (default_value) && (!strcasecmp(default_value, "active directory")) ) auth = AUTHMODE_LDAP_AD;
        }
        else {
            set_int_val(curr, &auth, default_value);
        }
        setconf_int("c_auth_mode", auth);
        break;

    case eLDAP_Host:
        getconf_str(buf, "c_ldap_host");
        if (IsEmptyStr(buf)) {
            strcpy(buf, "localhost");
        }
        set_str_val(curr, buf, default_value);
        setconf_str("c_ldap_host", buf);
        break;

    case eLDAP_Port:
        lportnum = getconf_int("c_ldap_port");
        if (lportnum == 0) {
            lportnum = 389;
        }
        set_int_val(curr, &lportnum, default_value);
        setconf_int("c_ldap_port", lportnum);
        break;

    case eLDAP_Base_DN:
        getconf_str(buf, "c_ldap_base_dn");
        set_str_val(curr, buf, default_value);
        setconf_str("c_ldap_base_dn", buf);
        break;

    case eLDAP_Bind_DN:
        getconf_str(buf, "c_ldap_bind_dn");
        set_str_val(curr, buf, default_value);
        setconf_str("c_ldap_bind_dn", buf);
        break;

    case eLDAP_Bind_PW:
        getconf_str(buf, "c_ldap_bind_pw");
        set_str_val(curr, buf, default_value);
        setconf_str("c_ldap_bind_pw", buf);
        break;
    }
}