📄 glui.h
字号:
/*********** Controls ************/
virtual int add_control( GLUI_Node *parent, GLUI_Control *control );
/********** Constructors and Destructors ***********/
GLUI_Main( void );
public:
GLUI_StdBitmaps std_bitmaps;
GLUI_String window_name;
unsigned char bkgd_color[3];
float bkgd_color_f[3];
void *font;
int curr_modifiers;
void adjust_glut_xy( int &x, int &y ) { y = h-y; }
void activate_control( GLUI_Control *control, int how );
void align_controls( GLUI_Control *control );
void deactivate_current_control( void );
/** Draw a 3D-look pushed-out box around this rectangle */
void draw_raised_box( int x, int y, int w, int h );
/** Draw a 3D-look pushed-in box around this rectangle */
void draw_lowered_box( int x, int y, int w, int h );
/** Return true if this control should redraw itself immediately (front buffer);
Or queue up a redraw and return false if it shouldn't (back buffer).
*/
bool should_redraw_now(GLUI_Control *ctl);
/** Switch to the appropriate draw buffer now. Returns the old draw buffer.
This routine should probably only be called from inside the GLUI_DrawingSentinal,
in glui_internal_control.h
*/
int set_current_draw_buffer();
/** Go back to using this draw buffer. Undoes set_current_draw_buffer. */
void restore_draw_buffer( int buffer_state );
/** Pack, resize the window, and redraw all the controls. */
void refresh();
/** Redraw the main graphics window */
void post_update_main_gfx();
/** Recompute the sizes and positions of all controls */
void pack_controls();
void close_internal();
void check_subwindow_position();
void set_ortho_projection();
void set_viewport();
int get_glut_window_id( void ) { return glut_window_id; } /* JVK */
};
/************************************************************/
/* */
/* GLUI_Control: base class for all controls */
/* */
/************************************************************/
/**
All the GUI objects inherit from GLUI_Control: buttons,
checkboxes, labels, edit boxes, scrollbars, etc.
Most of the work of this class is in routing events,
like keystrokes, mouseclicks, redraws, and sizing events.
Yes, this is a huge and hideous class. It needs to be
split up into simpler subobjects. None of the data members
should be directly accessed by users (they should be protected,
not public); only subclasses.
*/
class GLUIAPI GLUI_Control : public GLUI_Node
{
public:
/** Onscreen coordinates */
int w, h; /* dimensions of control */
int x_abs, y_abs;
int x_off, y_off_top, y_off_bot; /* INNER margins, by which child
controls are indented */
int contain_x, contain_y;
int contain_w, contain_h;
/* if this is a container control (e.g.,
radiogroup or panel) this indicated dimensions
of inner area in which controls reside */
/** "activation" for tabbing between controls. */
int active_type; ///< "GLUI_CONTROL_ACTIVE_..."
bool active; ///< If true, we've got the focus
bool can_activate; ///< If false, remove from tab order.
bool spacebar_mouse_click; ///< Spacebar simulates click.
/** Callbacks */
long user_id; ///< Integer to pass to callback function.
GLUI_CB callback; ///< User callback function, or NULL.
/** Variable value storage */
float float_val; /**< Our float value */
int int_val; /**< Our integer value */
float float_array_val[GLUI_DEF_MAX_ARRAY];
int float_array_size;
GLUI_String text; /**< The text inside this control */
/** "Live variable" updating */
void *ptr_val; /**< A pointer to the user's live variable value */
int live_type;
bool live_inited;
/* These variables store the last value that live variable was known to have. */
int last_live_int;
float last_live_float;
GLUI_String last_live_text;
float last_live_float_array[GLUI_DEF_MAX_ARRAY];
/** Properties of our control */
GLUI *glui; /**< Our containing event handler (NEVER NULL during event processing!) */
bool is_container; /**< Is this a container class (e.g., panel) */
int alignment;
bool enabled; /**< Is this control grayed out? */
GLUI_String name; /**< The name of this control */
void *font; /**< Our glutbitmap font */
bool collapsible, is_open;
GLUI_Node collapsed_node;
bool hidden; /* Collapsed controls (and children) are hidden */
int char_widths[CHAR_WIDTH_HASH_SIZE][2]; /* Character width hash table */
public:
/*** Get/Set values ***/
virtual void set_name( const char *string );
virtual void set_int_val( int new_int ) { int_val = new_int; output_live(true); }
virtual void set_float_val( float new_float ) { float_val = new_float; output_live(true); }
virtual void set_ptr_val( void *new_ptr ) { ptr_val = new_ptr; output_live(true); }
virtual void set_float_array_val( float *array_ptr );
virtual float get_float_val( void ) { return float_val; }
virtual int get_int_val( void ) { return int_val; }
virtual void get_float_array_val( float *array_ptr );
virtual int get_id( void ) const { return user_id; }
virtual void set_id( int id ) { user_id=id; }
virtual int mouse_down_handler( int local_x, int local_y ) { return false; }
virtual int mouse_up_handler( int local_x, int local_y, bool inside ) { return false; }
virtual int mouse_held_down_handler( int local_x, int local_y, bool inside) { return false; }
virtual int key_handler( unsigned char key, int modifiers ) { return false; }
virtual int special_handler( int key,int modifiers ) { return false; }
virtual void update_size( void ) { }
virtual void idle( void ) { }
virtual int mouse_over( int state, int x, int y ) { return false; }
virtual void enable( void );
virtual void disable( void );
virtual void activate( int how ) { active = true; }
virtual void deactivate( void ) { active = false; }
/** Hide (shrink into a rollout) and unhide (expose from a rollout) */
void hide_internal( int recurse );
void unhide_internal( int recurse );
/** Return true if it currently makes sense to draw this class. */
int can_draw( void ) { return (glui != NULL && hidden == false); }
/** Redraw this control.
In single-buffering mode (drawing to GL_FRONT), this is just
a call to translate_and_draw_front (after a can_draw() check).
In double-buffering mode (drawing to GL_BACK), this queues up
a redraw and returns false, since you shouldn't draw yet.
*/
void redraw(void);
/** Redraw everybody in our window. */
void redraw_window(void);
virtual void align( void );
void pack( int x, int y ); /* Recalculate positions and offsets */
void pack_old( int x, int y );
void draw_recursive( int x, int y );
int set_to_glut_window( void );
void restore_window( int orig );
void translate_and_draw_front( void );
void translate_to_origin( void )
{glTranslatef((float)x_abs+.5,(float)y_abs+.5,0.0);}
virtual void draw( int x, int y )=0;
void set_font( void *new_font );
void *get_font( void );
int string_width( const char *text );
int string_width( const GLUI_String &str )
{ return string_width(str.c_str()); }
int char_width( char c );
void draw_name( int x, int y );
void draw_box_inwards_outline( int x_min, int x_max,
int y_min, int y_max );
void draw_box( int x_min, int x_max, int y_min, int y_max,
float r, float g, float b );
void draw_bkgd_box( int x_min, int x_max, int y_min, int y_max );
void draw_emboss_box( int x_min, int x_max,int y_min,int y_max);
void draw_string( const char *text );
void draw_string( const GLUI_String &s )
{ draw_string(s.c_str()); }
void draw_char( char c );
void draw_active_box( int x_min, int x_max, int y_min, int y_max );
void set_to_bkgd_color( void );
void set_w( int new_w );
void set_h( int new_w );
void set_alignment( int new_align );
void sync_live( int recurse, int draw ); /* Reads live variable */
void init_live( void );
void output_live( int update_main_gfx ); /** Writes live variable **/
virtual void set_text( const char *t ) {}
void execute_callback( void );
void get_this_column_dims( int *col_x, int *col_y,
int *col_w, int *col_h,
int *col_x_off, int *col_y_off );
virtual bool needs_idle( void ) const;
virtual bool wants_tabs() const { return false; }
GLUI_Control(void)
{
x_off = GLUI_XOFF;
y_off_top = GLUI_YOFF;
y_off_bot = GLUI_YOFF;
x_abs = GLUI_XOFF;
y_abs = GLUI_YOFF;
active = false;
enabled = true;
int_val = 0;
last_live_int = 0;
float_array_size = 0;
glui_format_str(name, "Control: %p", this);
float_val = 0.0;
last_live_float = 0.0;
ptr_val = NULL;
glui = NULL;
w = GLUI_DEFAULT_CONTROL_WIDTH;
h = GLUI_DEFAULT_CONTROL_HEIGHT;
font = NULL;
active_type = GLUI_CONTROL_ACTIVE_MOUSEDOWN;
alignment = GLUI_ALIGN_LEFT;
is_container = false;
can_activate = true; /* By default, you can activate a control */
spacebar_mouse_click = true; /* Does spacebar simulate a mouse click? */
live_type = GLUI_LIVE_NONE;
text = "";
last_live_text == "";
live_inited = false;
collapsible = false;
is_open = true;
hidden = false;
memset(char_widths, -1, sizeof(char_widths)); /* JVK */
int i;
for( i=0; i<GLUI_DEF_MAX_ARRAY; i++ )
float_array_val[i] = last_live_float_array[i] = 0.0;
}
virtual ~GLUI_Control();
};
/************************************************************/
/* */
/* Button class (container) */
/* */
/************************************************************/
/**
An onscreen, clickable button--an outlined label that
can be clicked. When clicked, a button
calls its GLUI_CB callback with its ID.
*/
class GLUIAPI GLUI_Button : public GLUI_Control
{
public:
bool currently_inside;
int mouse_down_handler( int local_x, int local_y );
int mouse_up_handler( int local_x, int local_y, bool inside );
int mouse_held_down_handler( int local_x, int local_y, bool inside );
int key_handler( unsigned char key,int modifiers );
void draw( int x, int y );
void draw_pressed( void );
void draw_text( int sunken );
void update_size( void );
/**
Create a new button.
@param parent The panel our object is inside; or the main GLUI object.
@param name The text inside the button.
@param id Optional ID number, to pass to the optional callback function.
@param callback Optional callback function, taking either the int ID or control.
*/
GLUI_Button( GLUI_Node *parent, const char *name,
int id=-1, GLUI_CB cb=GLUI_CB() );
GLUI_Button( void ) { common_init(); };
protected:
void common_init(void) {
glui_format_str(name, "Button: %p", this );
h = GLUI_BUTTON_SIZE;
w = 100;
alignment = GLUI_ALIGN_CENTER;
can_activate = true;
}
};
/************************************************************/
/* */
/* Checkbox class (container) */
/* */
/************************************************************/
/**
A checkbox, which can be checked on or off. Can be linked
to an int value, which gets 1 for on and 0 for off.
*/
class GLUIAPI GLUI_Checkbox : public GLUI_Control
{
public:
int orig_value;
bool currently_inside;
int text_x_offset;
int mouse_down_handler( int local_x, int local_y );
int mouse_up_handler( int local_x, int local_y, bool inside );
int mouse_held_down_handler( int local_x, int local_y, bool inside );
int key_handler( unsigned char key,int modifiers );
void update_size( void );
void draw( int x, int y );
void draw_active_area( void );
void draw_empty_box( void );
void set_int_val( int new_val );
/**
Create a new checkbox object.
@param parent The panel our object is inside; or the main GLUI object.
@param name Label next to our checkbox.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -