Permalink
Browse files

Code Tidy-up: Replace glui_format_str with c42f/tinyformat for string…

… formatting
  • Loading branch information...
nigels-com committed Jun 24, 2017
1 parent bbbccf7 commit 642101483f1ca669009dc1be707a4104d0567463
Showing with 1,214 additions and 202 deletions.
  1. +0 −1 CMakeLists.txt
  2. +2 −2 glui.cpp
  3. +10 −0 glui_button.cpp
  4. +13 −0 glui_checkbox.cpp
  5. +56 −14 glui_control.cpp
  6. +16 −0 glui_listbox.cpp
  7. +13 −0 glui_mouse_iaction.cpp
  8. +13 −2 glui_radio.cpp
  9. +2 −1 glui_rotation.cpp
  10. +19 −0 glui_spinner.cpp
  11. +0 −61 glui_string.cpp
  12. +17 −0 glui_translation.cpp
  13. +5 −5 glui_treepanel.cpp
  14. +8 −115 include/GL/glui.h
  15. +1 −1 makefile
  16. +1,039 −0 tinyformat.h
View
@@ -41,7 +41,6 @@ SET(GLUI_SRCS
glui_separator.cpp
glui_spinner.cpp
glui_statictext.cpp
glui_string.cpp
glui_textbox.cpp
glui_translation.cpp
glui_tree.cpp
View
@@ -31,6 +31,7 @@
*****************************************************************************/
#include "glui_internal_control.h"
#include "tinyformat.h"
/**
Note: moving this routine here from glui_add_controls.cpp prevents the linker
@@ -512,8 +513,7 @@ GLUI *GLUI_Master_Object::create_glui_subwindow( int parent_window,
long flags )
{
GLUI *new_glui = new GLUI;
GLUI_String new_name;
glui_format_str( new_name, "subwin_%p", this );
GLUI_String new_name = tfm::format("subwin_%p", this );
new_glui->init( new_name.c_str(), flags | GLUI_SUBWINDOW, 0,0,
parent_window );
View
@@ -30,6 +30,8 @@
*****************************************************************************/
#include "glui_internal_control.h"
#include "tinyformat.h"
/****************************** GLUI_Button::GLUI_Button() **********/
GLUI_Button::GLUI_Button( GLUI_Node *parent, const char *name,
@@ -44,6 +46,14 @@ GLUI_Button::GLUI_Button( GLUI_Node *parent, const char *name,
parent->add_control( this );
}
void GLUI_Button::common_init()
{
name = tfm::format("Button: %p", this);
h = GLUI_BUTTON_SIZE;
w = 100;
alignment = GLUI_ALIGN_CENTER;
can_activate = true;
}
/****************************** GLUI_Button::mouse_down_handler() **********/
View
@@ -34,6 +34,8 @@
#include "glui_internal_control.h"
#include "tinyformat.h"
/****************************** GLUI_Checkbox::GLUI_Checkbox() **********/
GLUI_Checkbox::GLUI_Checkbox( GLUI_Node *parent,
@@ -53,6 +55,17 @@ GLUI_Checkbox::GLUI_Checkbox( GLUI_Node *parent,
init_live();
}
void GLUI_Checkbox::common_init()
{
name = tfm::format("Checkbox: %p", this);
w = 100;
h = GLUI_CHECKBOX_SIZE;
orig_value = -1;
text_x_offset = 18;
can_activate = true;
live_type = GLUI_LIVE_INT; /* This control has an 'int' live var */
}
/****************************** GLUI_Checkbox::mouse_down_handler() **********/
int GLUI_Checkbox::mouse_down_handler( int local_x, int local_y )
View
@@ -33,8 +33,64 @@
#include "glui_internal_control.h"
#include "tinyformat.h"
int _glui_draw_border_only = 0;
/********* GLUI_Control::GLUI_Control() **********/
GLUI_Control::GLUI_Control()
{
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;
name = tfm::format("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;
}
/********* GLUI_Control::~GLUI_Control() **********/
GLUI_Control::~GLUI_Control()
{
GLUI_Control *item = (GLUI_Control*) this->first_child();
while (item)
{
GLUI_Control *tmp = item;
item = (GLUI_Control*) item->next();
delete tmp;
}
}
/*************************** Drawing Utility routines *********************/
/* Redraw this control. */
@@ -1129,20 +1185,6 @@ bool GLUI_Control::needs_idle() const
}
/********* GLUI_Control::~GLUI_Control() **********/
GLUI_Control::~GLUI_Control()
{
GLUI_Control *item = (GLUI_Control*) this->first_child();
while (item)
{
GLUI_Control *tmp = item;
item = (GLUI_Control*) item->next();
delete tmp;
}
}
/********* GLUI_Control::hide_internal() ********/
/** Sets hidden==true for this control and all its siblings. */
/** If recurse is true, we go to children as well */
View
@@ -33,6 +33,8 @@
#include "glui_internal_control.h"
#include "tinyformat.h"
/****************************** GLUI_Listbox::GLUI_Listbox() **********/
GLUI_Listbox::GLUI_Listbox( GLUI_Node *parent,
const char *name, int *value_ptr,
@@ -50,6 +52,20 @@ GLUI_Listbox::GLUI_Listbox( GLUI_Node *parent,
init_live();
}
void GLUI_Listbox::common_init()
{
name = tfm::format("Listbox: %p", this);
w = GLUI_EDITTEXT_WIDTH;
h = GLUI_EDITTEXT_HEIGHT;
orig_value = -1;
title_x_offset = 0;
text_x_offset = 55;
can_activate = true;
curr_text = "";
live_type = GLUI_LIVE_INT; /* This has an integer live var */
depressed = false;
glut_menu_id = -1;
}
/****************************** GLUI_Listbox::mouse_down_handler() **********/
View
@@ -33,6 +33,19 @@
#include "glui_internal_control.h"
#include "tinyformat.h"
GLUI_Mouse_Interaction::GLUI_Mouse_Interaction()
{
name = tfm::format("Mouse_Interaction: %p", this );
w = GLUI_MOUSE_INTERACTION_WIDTH;
h = GLUI_MOUSE_INTERACTION_HEIGHT;
can_activate = true;
live_type = GLUI_LIVE_NONE;
alignment = GLUI_ALIGN_CENTER;
draw_active_area_only = false;
}
/********************** GLUI_Mouse_Interaction::mouse_down_handler() ******/
int GLUI_Mouse_Interaction::mouse_down_handler( int local_x, int local_y )
View
@@ -32,6 +32,9 @@
*****************************************************************************/
#include "glui_internal_control.h"
#include "tinyformat.h"
#include <cassert>
/****************************** GLUI_RadioGroup::GLUI_RadioGroup() **********/
@@ -41,7 +44,6 @@ GLUI_RadioGroup::GLUI_RadioGroup(GLUI_Node *parent,
int id, GLUI_CB cb)
{
common_init();
GLUI_String buf;
set_ptr_val( value_ptr );
if ( value_ptr ) {
@@ -53,7 +55,7 @@ GLUI_RadioGroup::GLUI_RadioGroup(GLUI_Node *parent,
}
user_id = id;
glui_format_str( buf, "RadioGroup: %p", this );
GLUI_String buf = tfm::format("RadioGroup: %p", this );
set_name( buf.c_str() );
callback = cb;
@@ -168,6 +170,15 @@ GLUI_RadioButton::GLUI_RadioButton( GLUI_RadioGroup *grp, const char *name )
updating all its buttons */
}
void GLUI_RadioButton::common_init()
{
name = tfm::format("RadioButton: %p", this );
h = GLUI_RADIOBUTTON_SIZE;
group = NULL;
orig_value = -1;
text_x_offset = 18;
can_activate = true;
}
/************************ GLUI_RadioButton::mouse_down_handler() **********/
View
@@ -34,6 +34,7 @@
#include "GL/glui.h"
#include "arcball.h"
#include "algebra3.h"
#include "tinyformat.h"
/*************************** GLUI_Rotation::iaction_mouse_down_handler() ***/
@@ -457,7 +458,7 @@ NO! WVB
void GLUI_Rotation::common_init()
{
glui_format_str( name, "Rotation: %p", this );
name = tfm::format("Rotation: %p", this );
// type = GLUI_CONTROL_ROTATION;
w = GLUI_ROTATION_WIDTH;
h = GLUI_ROTATION_HEIGHT;
View
@@ -44,6 +44,9 @@ FIXME: there's a heck of a lot of duplication between this and glui_scrollbar.cp
*****************************************************************************/
#include "glui_internal_control.h"
#include "tinyformat.h"
#include <cmath>
#include <cassert>
@@ -53,6 +56,22 @@ FIXME: there's a heck of a lot of duplication between this and glui_scrollbar.cp
#define GLUI_SPINNER_MIN_GROWTH_STEPS 100
#define GLUI_SPINNER_CALLBACK_INTERVAL 1
void GLUI_Spinner::common_init()
{
name = tfm::format("Spinner: %p", this);
h = GLUI_EDITTEXT_HEIGHT;
w = GLUI_EDITTEXT_WIDTH;
x_off = 0;
y_off_top = 0;
y_off_bot = 0;
can_activate = true;
state = GLUI_SPINNER_STATE_NONE;
edittext = NULL;
growth_exp = GLUI_SPINNER_DEFAULT_GROWTH_EXP;
callback_count = 0;
first_callback = true;
user_speed = 1.0;
}
/****************************** GLUI_Spinner::GLUI_Spinner() ****************/
View
@@ -1,61 +0,0 @@
/****************************************************************************
GLUI User Interface Toolkit
---------------------------
glui.cpp
--------------------------------------------------
Copyright (c) 1998 Paul Rademacher (this file, Bill Baxter 2005)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*****************************************************************************/
#include "GL/glui.h"
#include <stdarg.h>
#ifdef _MSC_VER
#define vsnprintf _vsnprintf
#endif
GLUI_String& glui_format_str(GLUI_String& str, const char* fmt, ...)
{
const size_t ISIZE = 128;
char stackbuf[ISIZE];
size_t bufsz = ISIZE;
char *buf = stackbuf;
str = "";
va_list arg;
while (1) {
va_start(arg, fmt);
int ret = vsnprintf(buf,bufsz-1,fmt,arg);
va_end(arg);
if (ret>=0) {
break;
}
// else make a bigger buf, try again
bufsz <<= 1;
if (buf==stackbuf) buf = (char*)malloc(sizeof(char)*bufsz);
else buf = (char*)realloc(buf, sizeof(char)*bufsz);
}
if (buf!=stackbuf) free(buf);
str=buf;
return str;
}
View
@@ -34,6 +34,7 @@
#include "GL/glui.h"
#include "glui_internal.h"
#include "algebra3.h"
#include "tinyformat.h"
/********************** GLUI_Translation::GLUI_Translation() ***/
@@ -68,6 +69,22 @@ GLUI_Translation::GLUI_Translation(
init_live();
}
void GLUI_Translation::common_init()
{
locked = GLUI_TRANSLATION_LOCK_NONE;
name = tfm::format("Translation: %p", this);
w = GLUI_MOUSE_INTERACTION_WIDTH;
h = GLUI_MOUSE_INTERACTION_HEIGHT;
can_activate = true;
live_type = GLUI_LIVE_FLOAT_ARRAY;
float_array_size = 0;
alignment = GLUI_ALIGN_CENTER;
trans_type = GLUI_TRANSLATION_XY;
scale_factor = 1.0;
quadObj = NULL;
trans_mouse_code = GLUI_TRANSLATION_MOUSE_NONE;
}
/********************** GLUI_Translation::iaction_mouse_down_handler() ***/
/* These are really in local coords (5/10/99) */
Oops, something went wrong.

0 comments on commit 6421014

Please sign in to comment.