removed the need for RTTI/runtime type checking/dynamic_cast in glui. It is unnecessary to overhaul the build systems just for this feature. Replaced by upcasting virtual methods

if ( !dynamic_cast<GLUI_Rollout*>(this) &&
becomes
if ( !this->dynamicCastGLUI_Rollout() &&
etc.
This commit is contained in:
ejcoumans
2007-10-21 03:02:11 +00:00
parent fb1a4bd37e
commit 11a0589732
8 changed files with 158 additions and 47 deletions

View File

@@ -315,6 +315,13 @@ private:
/************************************************************/
class GLUI_Control;
class GLUI_Column;
class GLUI_Panel;
class GLUI_FileBrowser;
class GLUI_Scrollbar;
class GLUI_Listbox;
class GLUI_List;
/**
GLUI_Node is a node in a sort of tree of GLUI controls.
@@ -354,6 +361,56 @@ public:
void dump( FILE *out, const char *name );
virtual GLUI_Panel* dynamicCastGLUI_Panel()
{
return 0;
}
virtual GLUI_Column* dynamicCastGLUI_Column()
{
return 0;
}
virtual GLUI_EditText* dynamicCastGLUI_EditText()
{
return 0;
}
virtual GLUI_Rollout* dynamicCastGLUI_Rollout()
{
return 0;
}
virtual GLUI_Tree* dynamicCastGLUI_Tree()
{
return 0;
}
virtual GLUI_List* dynamicCastGLUI_List()
{
return 0;
}
virtual GLUI_FileBrowser* dynamicCastGLUI_FileBrowser()
{
return 0;
}
virtual GLUI_Scrollbar* dynamicCastGLUI_Scrollbar()
{
return 0;
}
virtual GLUI_Listbox* dynamicCastGLUI_Listbox()
{
return 0;
}
virtual GLUI_TreePanel* dynamicCastGLUI_TreePanel()
{
return 0;
}
protected:
static void add_child_to_control(GLUI_Node *parent,GLUI_Control *child);
GLUI_Node *parent_node;
@@ -745,6 +802,9 @@ public:
/* */
/************************************************************/
//get rid of the dynamic_cast/RTTI requirements, just do a virtual function
/**
All the GUI objects inherit from GLUI_Control: buttons,
checkboxes, labels, edit boxes, scrollbars, etc.
@@ -843,6 +903,7 @@ public:
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); }
@@ -1073,6 +1134,10 @@ public:
GLUI_Column( GLUI_Node *parent, int draw_bar = true );
GLUI_Column( void ) { common_init(); }
virtual GLUI_Column* dynamicCastGLUI_Column()
{
return this;
}
protected:
void common_init() {
w = 0;
@@ -1115,6 +1180,11 @@ public:
void update_size( void );
virtual GLUI_Panel* dynamicCastGLUI_Panel()
{
return this;
}
protected:
void common_init( void ) {
w = 300;
@@ -1167,6 +1237,11 @@ public:
const char* get_file() { return file.c_str(); }
void set_allow_change_dir(int c) { allow_change_dir = c; }
virtual GLUI_FileBrowser* dynamicCastGLUI_FileBrowser()
{
return this;
}
protected:
void common_init()
{
@@ -1235,6 +1310,11 @@ public:
void update_size( void );
virtual GLUI_Rollout* dynamicCastGLUI_Rollout()
{
return 0;
}
protected:
void common_init() {
currently_inside = false;
@@ -1316,6 +1396,11 @@ public:
green = g;
blue = b;
}
virtual GLUI_Tree* dynamicCastGLUI_Tree()
{
return this;
}
protected:
void common_init()
{
@@ -1403,6 +1488,10 @@ public:
void update_all( void );
void initNode(GLUI_Tree *temp);
void formatNode(GLUI_Tree *temp);
virtual GLUI_TreePanel* dynamicCastGLUI_TreePanel()
{
return this;
}
protected:
int uniqueID( void ) { next_id++; return next_id - 1; }
@@ -1660,6 +1749,12 @@ public:
// Deprecated constructor, only called internally
GLUI_EditText( void ) { common_init(); }
virtual GLUI_EditText* dynamicCastGLUI_EditText()
{
return this;
}
protected:
void common_init( void ) {
h = GLUI_EDITTEXT_HEIGHT;
@@ -2161,6 +2256,11 @@ public:
void set_object_callback(GLUI_CB cb=GLUI_CB(), GLUI_Control*obj=NULL)
{ obj_cb=cb; associated_object=obj; }
virtual GLUI_List* dynamicCastGLUI_List()
{
return this;
}
protected:
void common_init()
{
@@ -2288,6 +2388,11 @@ public:
void set_object_callback(GLUI_CB cb=GLUI_CB(), GLUI_Control*obj=NULL)
{ object_cb=cb; associated_object=obj; }
virtual GLUI_Scrollbar* dynamicCastGLUI_Scrollbar()
{
return this;
}
protected:
void common_init ( void );
void common_construct(
@@ -2358,6 +2463,11 @@ public:
int id=-1, GLUI_CB callback=GLUI_CB() );
GLUI_Listbox( void ) { common_init(); }
virtual GLUI_Listbox* dynamicCastGLUI_Listbox()
{
return this;
}
protected:
/** Change w and return true if we need to be widened to fit the current item. */
bool recalculate_item_width( void );