Permalink
Browse files

Replace MIN and MAX with std::min and std::max

  • Loading branch information...
nigels-com committed Jun 28, 2017
1 parent d25f348 commit 635814446e4db2465991de0e21e499b440adb4d3
Showing with 105 additions and 88 deletions.
  1. +19 −16 algebra3.cpp
  2. +11 −9 glui.cpp
  3. +4 −2 glui_button.cpp
  4. +3 −1 glui_control.cpp
  5. +22 −19 glui_edittext.cpp
  6. +0 −5 glui_internal.h
  7. +6 −3 glui_list.cpp
  8. +5 −3 glui_listbox.cpp
  9. +17 −14 glui_scrollbar.cpp
  10. +16 −15 glui_textbox.cpp
  11. +2 −0 glui_translation.cpp
  12. +0 −1 include/GL/glui.h
View
@@ -76,6 +76,9 @@
#include "algebra3.h"
#include "glui_internal.h"
#include <algorithm>
#include <cmath>
#ifdef VEC_ERROR_FATAL
@@ -335,12 +338,12 @@ void swap(vec2 &a, vec2 &b)
vec2 min_vec(const vec2 &a, const vec2 &b)
{
return vec2(MIN(a.n[VX], b.n[VX]), MIN(a.n[VY], b.n[VY]));
return vec2(std::min(a.n[VX], b.n[VX]), std::min(a.n[VY], b.n[VY]));
}
vec2 max_vec(const vec2 &a, const vec2 &b)
{
return vec2(MAX(a.n[VX], b.n[VX]), MAX(a.n[VY], b.n[VY]));
return vec2(std::max(a.n[VX], b.n[VX]), std::max(a.n[VY], b.n[VY]));
}
vec2 prod(const vec2 &a, const vec2 &b)
@@ -615,17 +618,17 @@ void swap(vec3 &a, vec3 &b)
vec3 min_vec(const vec3 &a, const vec3 &b)
{
return vec3(
MIN(a.n[VX], b.n[VX]),
MIN(a.n[VY], b.n[VY]),
MIN(a.n[VZ], b.n[VZ]));
std::min(a.n[VX], b.n[VX]),
std::min(a.n[VY], b.n[VY]),
std::min(a.n[VZ], b.n[VZ]));
}
vec3 max_vec(const vec3 &a, const vec3 &b)
{
return vec3(
MAX(a.n[VX], b.n[VX]),
MAX(a.n[VY], b.n[VY]),
MAX(a.n[VZ], b.n[VZ]));
std::max(a.n[VX], b.n[VX]),
std::max(a.n[VY], b.n[VY]),
std::max(a.n[VZ], b.n[VZ]));
}
vec3 prod(const vec3 &a, const vec3 &b)
@@ -918,19 +921,19 @@ void swap(vec4 &a, vec4 &b)
vec4 min_vec(const vec4 &a, const vec4 &b)
{
return vec4(
MIN(a.n[VX], b.n[VX]),
MIN(a.n[VY], b.n[VY]),
MIN(a.n[VZ], b.n[VZ]),
MIN(a.n[VW], b.n[VW]));
std::min(a.n[VX], b.n[VX]),
std::min(a.n[VY], b.n[VY]),
std::min(a.n[VZ], b.n[VZ]),
std::min(a.n[VW], b.n[VW]));
}
vec4 max_vec(const vec4 &a, const vec4 &b)
{
return vec4(
MAX(a.n[VX], b.n[VX]),
MAX(a.n[VY], b.n[VY]),
MAX(a.n[VZ], b.n[VZ]),
MAX(a.n[VW], b.n[VW]));
std::max(a.n[VX], b.n[VX]),
std::max(a.n[VY], b.n[VY]),
std::max(a.n[VZ], b.n[VZ]),
std::max(a.n[VW], b.n[VW]));
}
vec4 prod(const vec4 &a, const vec4 &b)
View
@@ -33,6 +33,8 @@
#include "tinyformat.h"
#include <algorithm>
/**
Note: moving this routine here from glui_add_controls.cpp prevents the linker
from touching glui_add_controls.o in non-deprecated programs, which
@@ -989,16 +991,16 @@ void GLUI_Main::pack_controls()
if ( 1 ) {
if ( TEST_AND(this->flags,GLUI_SUBWINDOW_TOP )) {
main_panel->w = MAX( main_panel->w, parent_w );
main_panel->w = std::max( main_panel->w, parent_w );
}
else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
main_panel->h = MAX( main_panel->h, parent_h );
main_panel->h = std::max( main_panel->h, parent_h );
}
else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_BOTTOM )) {
main_panel->w = MAX( main_panel->w, parent_w );
main_panel->w = std::max( main_panel->w, parent_w );
}
else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_RIGHT )) {
main_panel->h = MAX( main_panel->h, parent_h );
main_panel->h = std::max( main_panel->h, parent_h );
}
}
}
@@ -2013,10 +2015,10 @@ void GLUI_Master_Object::get_viewport_area( int *x, int *y,
curr_glui = (GLUI*) curr_glui->next();
}
curr_x = MAX( 0, curr_x );
curr_y = MAX( 0, curr_y );
curr_w = MAX( 0, curr_w );
curr_h = MAX( 0, curr_h );
curr_x = std::max( 0, curr_x );
curr_y = std::max( 0, curr_y );
curr_w = std::max( 0, curr_w );
curr_h = std::max( 0, curr_h );
*x = curr_x;
*y = curr_y;
@@ -2032,7 +2034,7 @@ void GLUI_Master_Object::auto_set_viewport()
int x, y, w, h;
get_viewport_area( &x, &y, &w, &h );
glViewport( MAX(x,0), MAX(y,0), MAX(w,0), MAX(h,0) );
glViewport( std::max(x,0), std::max(y,0), std::max(w,0), std::max(h,0) );
}
View
@@ -32,6 +32,8 @@
#include "tinyformat.h"
#include <algorithm>
/****************************** GLUI_Button::GLUI_Button() **********/
GLUI_Button::GLUI_Button( GLUI_Node *parent, const GLUI_String &name,
@@ -158,10 +160,10 @@ void GLUI_Button::draw_text( int sunken )
string_width = _glutBitmapWidthString( glui->font,
this->name.c_str() );
if ( NOT sunken ) {
draw_name( MAX((w-string_width),0)/2, 13);
draw_name( std::max((w-string_width),0)/2, 13);
}
else {
draw_name( MAX((w-string_width),0)/2 + 1, 13 + 1);
draw_name( std::max((w-string_width),0)/2 + 1, 13 + 1);
}
if ( active ) {
View
@@ -35,6 +35,8 @@
#include "tinyformat.h"
#include <algorithm>
int _glui_draw_border_only = 0;
/********* GLUI_Control::GLUI_Control() **********/
@@ -567,7 +569,7 @@ void GLUI_Control::pack_old(int x, int y)
if ( dynamic_cast<GLUI_Rollout*>(this) ) {
/** We don't want the rollout to shrink in width when it's
closed **/
this->w = MAX(this->w, column_x + max_w + 2 * x_margin );
this->w = std::max(this->w, column_x + max_w + 2 * x_margin );
}
else {
this->w = column_x + max_w + 2 * x_margin;
View
@@ -32,7 +32,10 @@
*****************************************************************************/
#include "glui_internal_control.h"
#include "tinyformat.h"
#include <algorithm>
#include <cassert>
/****************************** GLUI_EditText::GLUI_EditText() **********/
@@ -246,8 +249,8 @@ int GLUI_EditText::key_handler( unsigned char key,int modifiers )
}
}
else { /* There is a selection */
clear_substring( MIN(sel_start,sel_end), MAX(sel_start,sel_end ));
insertion_pt = MIN(sel_start,sel_end);
clear_substring( std::min(sel_start,sel_end), std::max(sel_start,sel_end ));
insertion_pt = std::min(sel_start,sel_end);
sel_start = sel_end = insertion_pt;
}
}
@@ -259,8 +262,8 @@ int GLUI_EditText::key_handler( unsigned char key,int modifiers )
sel_end = find_word_break( insertion_pt, +1 );
}
clear_substring( MIN(sel_start,sel_end), MAX(sel_start,sel_end ));
insertion_pt = MIN(sel_start,sel_end);
clear_substring( std::min(sel_start,sel_end), std::max(sel_start,sel_end ));
insertion_pt = std::min(sel_start,sel_end);
sel_start = sel_end = insertion_pt;
}
else if ( key == CTRL('h') ) { /* BACKSPACE */
@@ -276,8 +279,8 @@ int GLUI_EditText::key_handler( unsigned char key,int modifiers )
}
}
else { /* There is a selection */
clear_substring( MIN(sel_start,sel_end), MAX(sel_start,sel_end ));
insertion_pt = MIN(sel_start,sel_end);
clear_substring( std::min(sel_start,sel_end), std::max(sel_start,sel_end ));
insertion_pt = std::min(sel_start,sel_end);
sel_start = sel_end = insertion_pt;
}
}
@@ -338,8 +341,8 @@ int GLUI_EditText::key_handler( unsigned char key,int modifiers )
if ( key == '-' ) { /* User typed a '-' */
/* If user has first character selected, then '-' is allowed */
if ( NOT ( MIN(sel_start,sel_end) == 0 AND
MAX(sel_start,sel_end) > 0 ) ) {
if ( NOT ( std::min(sel_start,sel_end) == 0 AND
std::max(sel_start,sel_end) > 0 ) ) {
/* User does not have 1st char selected */
if (insertion_pt != 0 OR text[0] == '-' ) {
@@ -359,7 +362,7 @@ int GLUI_EditText::key_handler( unsigned char key,int modifiers )
int period_found = false;
if ( sel_start != sel_end ) {
for( i=MIN(sel_end,sel_start); i<MAX(sel_start,sel_end); i++ ) {
for( i=std::min(sel_end,sel_start); i<std::max(sel_start,sel_end); i++ ) {
/* printf( "%c ", text[i] ); */
if ( text[i] == '.' ) {
period_found = true;
@@ -383,8 +386,8 @@ int GLUI_EditText::key_handler( unsigned char key,int modifiers )
if ( key == '-' ) { /* User typed a '-' */
/* If user has first character selected, then '-' is allowed */
if ( NOT ( MIN(sel_start,sel_end) == 0 AND
MAX(sel_start,sel_end) > 0 ) ) {
if ( NOT ( std::min(sel_start,sel_end) == 0 AND
std::max(sel_start,sel_end) > 0 ) ) {
/* User does not have 1st char selected */
if (insertion_pt != 0 OR text[0] == '-' ) {
@@ -403,8 +406,8 @@ int GLUI_EditText::key_handler( unsigned char key,int modifiers )
/**** If there's a current selection, erase it ******/
if ( sel_start != sel_end ) {
clear_substring( MIN(sel_start,sel_end), MAX(sel_start,sel_end ));
insertion_pt = MIN(sel_start,sel_end);
clear_substring( std::min(sel_start,sel_end), std::max(sel_start,sel_end ));
insertion_pt = std::min(sel_start,sel_end);
sel_start = sel_end = insertion_pt;
}
@@ -540,7 +543,7 @@ void GLUI_EditText::draw( int x, int y )
GLUI_DRAWINGSENTINAL_IDIOM
int name_x;
name_x = MAX(text_x_offset - string_width(this->name) - 3,0);
name_x = std::max(text_x_offset - string_width(this->name) - 3,0);
draw_name( name_x , 13);
glBegin( GL_LINES );
@@ -585,12 +588,12 @@ int GLUI_EditText::update_substring_bounds()
old_end = substring_end;
/*** Calculate the width of the usable area of the edit box ***/
box_width = MAX( this->w - this->text_x_offset
box_width = std::max( this->w - this->text_x_offset
- 4 /* 2 * the two-line box border */
- 2 * GLUI_EDITTEXT_BOXINNERMARGINX, 0 );
CLAMP( substring_end, 0, MAX(text_len-1,0) );
CLAMP( substring_start, 0, MAX(text_len-1,0) );
CLAMP( substring_end, 0, std::max(text_len-1,0) );
CLAMP( substring_start, 0, std::max(text_len-1,0) );
if ( debug ) dump( stdout, "-> UPDATE SS" );
@@ -676,8 +679,8 @@ void GLUI_EditText::draw_text( int x, int y )
substring_start, substring_end );
*/
/** Find lower and upper selection bounds **/
sel_lo = MIN(sel_start, sel_end );
sel_hi = MAX(sel_start, sel_end );
sel_lo = std::min(sel_start, sel_end );
sel_hi = std::max(sel_start, sel_end );
int sel_x_start, sel_x_end, delta;
View
@@ -52,11 +52,6 @@
#define NOT !
#endif
#ifndef MAX
#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#endif
#ifndef ABS
#define ABS(a) ((a)>=0 ? (a) : (-(a)))
#endif
View
@@ -29,6 +29,9 @@
*****************************************************************************/
#include "glui_internal_control.h"
#include <algorithm>
#include <cmath>
#include <sys/timeb.h>
@@ -270,7 +273,7 @@ void GLUI_List::draw( int x, int y )
}
if (scrollbar) {
scrollbar->set_int_limits(MAX(0,num_lines-visible_lines), 0);
scrollbar->set_int_limits(std::max(0,num_lines-visible_lines), 0);
glPushMatrix();
glTranslatef(scrollbar->x_abs-x_abs, scrollbar->y_abs-y_abs,0.0);
scrollbar->draw_scroll();
@@ -335,7 +338,7 @@ int GLUI_List::find_line(int x, int y) {
}
int GLUI_List::get_box_width() {
return MAX( this->w
return std::max( this->w
- 6 /* 2 * the two-line box border */
- 2 * GLUI_LIST_BOXINNERMARGINX, 0 );
@@ -433,7 +436,7 @@ int GLUI_List::add_item( int id, const GLUI_String &new_text )
}
num_lines++;
if (scrollbar)
scrollbar->set_int_limits(MAX(num_lines-visible_lines,0), 0);
scrollbar->set_int_limits(std::max(num_lines-visible_lines,0), 0);
return true;
}
View
@@ -35,6 +35,8 @@
#include "tinyformat.h"
#include <algorithm>
/****************************** GLUI_Listbox::GLUI_Listbox() **********/
GLUI_Listbox::GLUI_Listbox( GLUI_Node *parent,
const GLUI_String &name, int *value_ptr,
@@ -111,7 +113,7 @@ void GLUI_Listbox::draw( int x, int y )
/* draw_active_area(); */
name_x = MAX(text_x_offset - string_width(this->name) - 3,0);
name_x = std::max(text_x_offset - string_width(this->name) - 3,0);
draw_name( name_x , 13);
draw_box_inwards_outline( text_x_offset, w,
0, h );
@@ -450,12 +452,12 @@ bool GLUI_Listbox::recalculate_item_width()
GLUI_Listbox_Item *item = (GLUI_Listbox_Item *) items_list.first_child();
while( item ) {
item_text_size = MAX(item_text_size,string_width(item->text));
item_text_size = std::max(item_text_size,string_width(item->text));
item = (GLUI_Listbox_Item *) item->next();
}
/* Sum up our layout: name, item, and drop-down marker */
int new_wid=text_x_offset+MAX(GLUI_EDITTEXT_MIN_TEXT_WIDTH,item_text_size)+20;
int new_wid=text_x_offset+std::max(GLUI_EDITTEXT_MIN_TEXT_WIDTH,item_text_size)+20;
if ( w != new_wid) {
w = new_wid;
return true; /* we gotta be shortened or widened */
Oops, something went wrong.

0 comments on commit 6358144

Please sign in to comment.