add glui library
This commit is contained in:
@@ -2,6 +2,7 @@ SubDir TOP Extras ;
|
||||
|
||||
SubInclude TOP Extras ConvexDecomposition ;
|
||||
SubInclude TOP Extras COLLADA_DOM ;
|
||||
SubInclude TOP Extras glui ;
|
||||
SubInclude TOP Extras LibXML ;
|
||||
SubInclude TOP Extras BulletColladaConverter ;
|
||||
#SubInclude TOP Extras BulletMultiThreaded ;
|
||||
|
||||
2586
Extras/glui/GL/glui.h
Normal file
2586
Extras/glui/GL/glui.h
Normal file
File diff suppressed because it is too large
Load Diff
18
Extras/glui/Jamfile
Normal file
18
Extras/glui/Jamfile
Normal file
@@ -0,0 +1,18 @@
|
||||
SubDir TOP Extras glui ;
|
||||
|
||||
if $(GLUT.AVAILABLE) = "yes"
|
||||
{
|
||||
|
||||
|
||||
Description glui : "glui" ;
|
||||
Library glui :
|
||||
[ Wildcard *.h *.cpp ] : noinstall
|
||||
;
|
||||
|
||||
CFlags glui :
|
||||
;
|
||||
|
||||
LibDepends glui : ;
|
||||
|
||||
ExternalLibs bulletopenglsupport : GLUT ;
|
||||
}
|
||||
1609
Extras/glui/algebra3.cpp
Normal file
1609
Extras/glui/algebra3.cpp
Normal file
File diff suppressed because it is too large
Load Diff
475
Extras/glui/algebra3.h
Normal file
475
Extras/glui/algebra3.h
Normal file
@@ -0,0 +1,475 @@
|
||||
/*
|
||||
|
||||
algebra3.cpp, algebra3.h - C++ Vector and Matrix Algebra routines
|
||||
|
||||
GLUI User Interface Toolkit (LGPL)
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
There are three vector classes and two matrix classes: vec2, vec3,
|
||||
vec4, mat3, and mat4.
|
||||
|
||||
All the standard arithmetic operations are defined, with '*'
|
||||
for dot product of two vectors and multiplication of two matrices,
|
||||
and '^' for cross product of two vectors.
|
||||
|
||||
Additional functions include length(), normalize(), homogenize for
|
||||
vectors, and print(), set(), apply() for all classes.
|
||||
|
||||
There is a function transpose() for matrices, but note that it
|
||||
does not actually change the matrix,
|
||||
|
||||
When multiplied with a matrix, a vector is treated as a row vector
|
||||
if it precedes the matrix (v*M), and as a column vector if it
|
||||
follows the matrix (M*v).
|
||||
|
||||
Matrices are stored in row-major form.
|
||||
|
||||
A vector of one dimension (2d, 3d, or 4d) can be cast to a vector
|
||||
of a higher or lower dimension. If casting to a higher dimension,
|
||||
the new component is set by default to 1.0, unless a value is
|
||||
specified:
|
||||
vec3 a(1.0, 2.0, 3.0 );
|
||||
vec4 b( a, 4.0 ); // now b == {1.0, 2.0, 3.0, 4.0};
|
||||
When casting to a lower dimension, the vector is homogenized in
|
||||
the lower dimension. E.g., if a 4d {X,Y,Z,W} is cast to 3d, the
|
||||
resulting vector is {X/W, Y/W, Z/W}. It is up to the user to
|
||||
insure the fourth component is not zero before casting.
|
||||
|
||||
There are also the following function for building matrices:
|
||||
identity2D(), translation2D(), rotation2D(),
|
||||
scaling2D(), identity3D(), translation3D(),
|
||||
rotation3D(), rotation3Drad(), scaling3D(),
|
||||
perspective3D()
|
||||
|
||||
NOTE: When compiling for Windows, include this file first, to avoid
|
||||
certain name conflicts
|
||||
|
||||
---------------------------------------------------------------------
|
||||
|
||||
Author: Jean-Francois DOUEg
|
||||
Revised: Paul Rademacher
|
||||
Version 3.2 - Feb 1998
|
||||
Revised: Nigel Stewart (GLUI Code Cleaning)
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef GLUI_ALGEBRA3_H
|
||||
#define GLUI_ALGEBRA3_H
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
// this line defines a new type: pointer to a function which returns a
|
||||
// float and takes as argument a float
|
||||
typedef float (*V_FCT_PTR)(float);
|
||||
|
||||
class vec2;
|
||||
class vec3;
|
||||
class vec4;
|
||||
class mat3;
|
||||
class mat4;
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592654
|
||||
#endif
|
||||
|
||||
enum {VX, VY, VZ, VW}; // axes
|
||||
enum {PA, PB, PC, PD}; // planes
|
||||
enum {RED, GREEN, BLUE, ALPHA}; // colors
|
||||
enum {KA, KD, KS, ES}; // phong coefficients
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* 2D Vector *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
class vec2
|
||||
{
|
||||
friend class vec3;
|
||||
|
||||
protected:
|
||||
|
||||
float n[2];
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
vec2();
|
||||
vec2(float x, float y);
|
||||
vec2(const vec2 &v); // copy constructor
|
||||
vec2(const vec3 &v); // cast v3 to v2
|
||||
vec2(const vec3 &v, int dropAxis); // cast v3 to v2
|
||||
|
||||
// Assignment operators
|
||||
|
||||
vec2 &operator = (const vec2 &v); // assignment of a vec2
|
||||
vec2 &operator += (const vec2 &v); // incrementation by a vec2
|
||||
vec2 &operator -= (const vec2 &v); // decrementation by a vec2
|
||||
vec2 &operator *= (float d); // multiplication by a constant
|
||||
vec2 &operator /= (float d); // division by a constant
|
||||
|
||||
// special functions
|
||||
|
||||
float length() const; // length of a vec2
|
||||
float length2() const; // squared length of a vec2
|
||||
vec2 &normalize(); // normalize a vec2
|
||||
vec2 &apply(V_FCT_PTR fct); // apply a func. to each component
|
||||
void set(float x, float y); // set vector
|
||||
|
||||
float &operator [] (int i); // indexing
|
||||
const float &operator [] (int i) const; // indexing
|
||||
|
||||
// friends
|
||||
|
||||
friend vec2 operator - (const vec2 &v); // -v1
|
||||
friend vec2 operator + (const vec2 &a, const vec2 &b); // v1 + v2
|
||||
friend vec2 operator - (const vec2 &a, const vec2 &b); // v1 - v2
|
||||
friend vec2 operator * (const vec2 &a, float d); // v1 * 3.0
|
||||
friend vec2 operator * (float d, const vec2 &a); // 3.0 * v1
|
||||
friend vec2 operator * (const mat3 &a, const vec2 &v); // M . v
|
||||
friend vec2 operator * (const vec2 &v, const mat3 &a); // v . M
|
||||
friend float operator * (const vec2 &a, const vec2 &b); // dot product
|
||||
friend vec2 operator / (const vec2 &a, float d); // v1 / 3.0
|
||||
friend vec3 operator ^ (const vec2 &a, const vec2 &b); // cross product
|
||||
friend int operator == (const vec2 &a, const vec2 &b); // v1 == v2 ?
|
||||
friend int operator != (const vec2 &a, const vec2 &b); // v1 != v2 ?
|
||||
//friend ostream& operator << (ostream& s, vec2& v); // output to stream
|
||||
//friend istream& operator >> (istream& s, vec2& v); // input from strm.
|
||||
friend void swap(vec2 &a, vec2 &b); // swap v1 & v2
|
||||
friend vec2 min_vec(const vec2 &a, const vec2 &b); // min(v1, v2)
|
||||
friend vec2 max_vec(const vec2 &a, const vec2 &b); // max(v1, v2)
|
||||
friend vec2 prod (const vec2 &a, const vec2 &b); // term by term *
|
||||
};
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* 3D Vector *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
class vec3
|
||||
{
|
||||
friend class vec2;
|
||||
friend class vec4;
|
||||
friend class mat3;
|
||||
|
||||
protected:
|
||||
|
||||
float n[3];
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
vec3();
|
||||
vec3(float x, float y, float z);
|
||||
vec3(const vec3 &v); // copy constructor
|
||||
vec3(const vec2 &v); // cast v2 to v3
|
||||
vec3(const vec2 &v, float d); // cast v2 to v3
|
||||
vec3(const vec4 &v); // cast v4 to v3
|
||||
vec3(const vec4 &v, int dropAxis); // cast v4 to v3
|
||||
|
||||
// Assignment operators
|
||||
|
||||
vec3 &operator = (const vec3 &v); // assignment of a vec3
|
||||
vec3 &operator += (const vec3 &v); // incrementation by a vec3
|
||||
vec3 &operator -= (const vec3 &v); // decrementation by a vec3
|
||||
vec3 &operator *= (float d); // multiplication by a constant
|
||||
vec3 &operator /= (float d); // division by a constant
|
||||
|
||||
// special functions
|
||||
|
||||
float length() const; // length of a vec3
|
||||
float length2() const; // squared length of a vec3
|
||||
vec3& normalize(); // normalize a vec3
|
||||
vec3& homogenize(); // homogenize (div by Z)
|
||||
vec3& apply(V_FCT_PTR fct); // apply a func. to each component
|
||||
void set(float x, float y, float z); // set vector
|
||||
|
||||
void print(FILE *file, const char *name) const; // print vector to a file
|
||||
|
||||
|
||||
float &operator [] (int i); // indexing
|
||||
const float &operator [] (int i) const; // indexing
|
||||
|
||||
// friends
|
||||
|
||||
friend vec3 operator - (const vec3 &v); // -v1
|
||||
friend vec3 operator + (const vec3 &a, const vec3 &b); // v1 + v2
|
||||
friend vec3 operator - (const vec3 &a, const vec3 &b); // v1 - v2
|
||||
friend vec3 operator * (const vec3 &a, float d); // v1 * 3.0
|
||||
friend vec3 operator * (float d, const vec3 &a); // 3.0 * v1
|
||||
friend vec3 operator * (const mat4 &a, const vec3 &v); // M . v
|
||||
friend vec3 operator * (const vec3 &v, const mat4 &a); // v . M
|
||||
friend float operator * (const vec3 &a, const vec3 &b); // dot product
|
||||
friend vec3 operator / (const vec3 &a, float d); // v1 / 3.0
|
||||
friend vec3 operator ^ (const vec3 &a, const vec3 &b); // cross product
|
||||
friend int operator == (const vec3 &a, const vec3 &b); // v1 == v2 ?
|
||||
friend int operator != (const vec3 &a, const vec3 &b); // v1 != v2 ?
|
||||
//friend ostream& operator << (ostream& s, vec3& v); // output to stream
|
||||
//friend istream& operator >> (istream& s, vec3& v); // input from strm.
|
||||
friend void swap(vec3 &a, vec3 &b); // swap v1 & v2
|
||||
friend vec3 min_vec(const vec3 &a, const vec3 &b); // min(v1, v2)
|
||||
friend vec3 max_vec(const vec3 &a, const vec3 &b); // max(v1, v2)
|
||||
friend vec3 prod(const vec3 &a, const vec3 &b); // term by term *
|
||||
|
||||
// necessary friend declarations
|
||||
|
||||
friend vec2 operator * (const mat3 &a, const vec2 &v); // linear transform
|
||||
friend vec3 operator * (const mat3 &a, const vec3 &v); // linear transform
|
||||
friend mat3 operator * (const mat3 &a, const mat3 &b); // matrix 3 product
|
||||
};
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* 4D Vector *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
class vec4
|
||||
{
|
||||
friend class vec3;
|
||||
friend class mat4;
|
||||
|
||||
protected:
|
||||
|
||||
float n[4];
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
vec4();
|
||||
vec4(float x, float y, float z, float w);
|
||||
vec4(const vec4 &v); // copy constructor
|
||||
vec4(const vec3 &v); // cast vec3 to vec4
|
||||
vec4(const vec3 &v, float d); // cast vec3 to vec4
|
||||
|
||||
// Assignment operators
|
||||
|
||||
vec4 &operator = (const vec4 &v); // assignment of a vec4
|
||||
vec4 &operator += (const vec4 &v); // incrementation by a vec4
|
||||
vec4 &operator -= (const vec4 &v); // decrementation by a vec4
|
||||
vec4 &operator *= (float d); // multiplication by a constant
|
||||
vec4 &operator /= (float d); // division by a constant
|
||||
|
||||
// special functions
|
||||
|
||||
float length() const; // length of a vec4
|
||||
float length2() const; // squared length of a vec4
|
||||
vec4 &normalize(); // normalize a vec4
|
||||
vec4 &apply(V_FCT_PTR fct); // apply a func. to each component
|
||||
vec4 &homogenize();
|
||||
|
||||
void print(FILE *file, const char *name) const; // print vector to a file
|
||||
|
||||
void set(float x, float y, float z, float a);
|
||||
|
||||
float &operator [] (int i); // indexing
|
||||
const float &operator [] (int i) const; // indexing
|
||||
|
||||
// friends
|
||||
|
||||
friend vec4 operator - (const vec4 &v); // -v1
|
||||
friend vec4 operator + (const vec4 &a, const vec4 &b); // v1 + v2
|
||||
friend vec4 operator - (const vec4 &a, const vec4 &b); // v1 - v2
|
||||
friend vec4 operator * (const vec4 &a, float d); // v1 * 3.0
|
||||
friend vec4 operator * (float d, const vec4 &a); // 3.0 * v1
|
||||
friend vec4 operator * (const mat4 &a, const vec4 &v); // M . v
|
||||
friend vec4 operator * (const vec4 &v, const mat4 &a); // v . M
|
||||
friend float operator * (const vec4 &a, const vec4 &b); // dot product
|
||||
friend vec4 operator / (const vec4 &a, float d); // v1 / 3.0
|
||||
friend int operator == (const vec4 &a, const vec4 &b); // v1 == v2 ?
|
||||
friend int operator != (const vec4 &a, const vec4 &b); // v1 != v2 ?
|
||||
//friend ostream& operator << (ostream& s, vec4& v); // output to stream
|
||||
//friend istream& operator >> (istream& s, vec4& v); // input from strm.
|
||||
friend void swap(vec4 &a, vec4 &b); // swap v1 & v2
|
||||
friend vec4 min_vec(const vec4 &a, const vec4 &b); // min(v1, v2)
|
||||
friend vec4 max_vec(const vec4 &a, const vec4 &b); // max(v1, v2)
|
||||
friend vec4 prod (const vec4 &a, const vec4 &b); // term by term *
|
||||
|
||||
// necessary friend declarations
|
||||
|
||||
friend vec3 operator * (const mat4 &a, const vec3 &v); // linear transform
|
||||
friend mat4 operator * (const mat4 &a, const mat4 &b); // matrix 4 product
|
||||
};
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* 3x3 Matrix *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
class mat3
|
||||
{
|
||||
protected:
|
||||
|
||||
vec3 v[3];
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
mat3();
|
||||
mat3(const vec3 &v0, const vec3 &v1, const vec3 &v2);
|
||||
mat3(const mat3 &m);
|
||||
|
||||
// Assignment operators
|
||||
|
||||
mat3 &operator = (const mat3 &m); // assignment of a mat3
|
||||
mat3 &operator += (const mat3 &m); // incrementation by a mat3
|
||||
mat3 &operator -= (const mat3 &m); // decrementation by a mat3
|
||||
mat3 &operator *= (float d); // multiplication by a constant
|
||||
mat3 &operator /= (float d); // division by a constant
|
||||
|
||||
// special functions
|
||||
|
||||
mat3 transpose() const; // transpose
|
||||
mat3 inverse() const; // inverse
|
||||
mat3 &apply(V_FCT_PTR fct); // apply a func. to each element
|
||||
|
||||
void print(FILE *file, const char *name ) const; // print matrix to a file
|
||||
|
||||
void set(const vec3 &v0, const vec3 &v1, const vec3 &v2);
|
||||
|
||||
vec3 &operator [] (int i); // indexing
|
||||
const vec3 &operator [] (int i) const; // indexing
|
||||
|
||||
// friends
|
||||
|
||||
friend mat3 operator - (const mat3 &a); // -m1
|
||||
friend mat3 operator + (const mat3 &a, const mat3 &b); // m1 + m2
|
||||
friend mat3 operator - (const mat3 &a, const mat3 &b); // m1 - m2
|
||||
friend mat3 operator * (const mat3 &a, const mat3 &b); // m1 * m2
|
||||
friend mat3 operator * (const mat3 &a, float d); // m1 * 3.0
|
||||
friend mat3 operator * (float d, const mat3 &a); // 3.0 * m1
|
||||
friend mat3 operator / (const mat3 &a, float d); // m1 / 3.0
|
||||
friend int operator == (const mat3 &a, const mat3 &b); // m1 == m2 ?
|
||||
friend int operator != (const mat3 &a, const mat3 &b); // m1 != m2 ?
|
||||
//friend ostream& operator << (ostream& s, mat3& m); // output to stream
|
||||
//friend istream& operator >> (istream& s, mat3& m); // input from strm.
|
||||
friend void swap(mat3 &a, mat3 &b); // swap m1 & m2
|
||||
|
||||
// necessary friend declarations
|
||||
|
||||
friend vec3 operator * (const mat3 &a, const vec3 &v); // linear transform
|
||||
friend vec2 operator * (const mat3 &a, const vec2 &v); // linear transform
|
||||
};
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* 4x4 Matrix *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
class mat4
|
||||
{
|
||||
protected:
|
||||
|
||||
vec4 v[4];
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
mat4();
|
||||
mat4(const vec4 &v0, const vec4 &v1, const vec4 &v2, const vec4 &v3);
|
||||
mat4(const mat4 &m);
|
||||
mat4(float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23,
|
||||
float a30, float a31, float a32, float a33 );
|
||||
|
||||
|
||||
// Assignment operators
|
||||
|
||||
mat4 &operator = (const mat4 &m); // assignment of a mat4
|
||||
mat4 &operator += (const mat4 &m); // incrementation by a mat4
|
||||
mat4 &operator -= (const mat4 &m); // decrementation by a mat4
|
||||
mat4 &operator *= (float d); // multiplication by a constant
|
||||
mat4 &operator /= (float d); // division by a constant
|
||||
|
||||
// special functions
|
||||
|
||||
mat4 transpose() const; // transpose
|
||||
mat4 inverse() const; // inverse
|
||||
mat4 &apply(V_FCT_PTR fct); // apply a func. to each element
|
||||
|
||||
void print(FILE *file, const char *name) const; // print matrix to a file
|
||||
|
||||
vec4 &operator [] (int i); // indexing
|
||||
const vec4 &operator [] (int i) const; // indexing
|
||||
|
||||
void swap_rows(int i, int j); // swap rows i and j
|
||||
void swap_cols(int i, int j); // swap cols i and j
|
||||
|
||||
// friends
|
||||
|
||||
friend mat4 operator - (const mat4 &a); // -m1
|
||||
friend mat4 operator + (const mat4 &a, const mat4 &b); // m1 + m2
|
||||
friend mat4 operator - (const mat4 &a, const mat4 &b); // m1 - m2
|
||||
friend mat4 operator * (const mat4 &a, const mat4 &b); // m1 * m2
|
||||
friend mat4 operator * (const mat4 &a, float d); // m1 * 4.0
|
||||
friend mat4 operator * (float d, const mat4 &a); // 4.0 * m1
|
||||
friend mat4 operator / (const mat4 &a, float d); // m1 / 3.0
|
||||
friend int operator == (const mat4 &a, const mat4 &b); // m1 == m2 ?
|
||||
friend int operator != (const mat4 &a, const mat4 &b); // m1 != m2 ?
|
||||
//friend ostream& operator << (ostream& s, mat4& m); // output to stream
|
||||
//friend istream& operator >> (istream& s, mat4& m); // input from strm.
|
||||
friend void swap(mat4 &a, mat4 &b); // swap m1 & m2
|
||||
|
||||
// necessary friend declarations
|
||||
|
||||
friend vec4 operator * (const mat4 &a, const vec4 &v); // linear transform
|
||||
//friend vec4 operator * (const vec4& v, const mat4& a); // linear transform
|
||||
friend vec3 operator * (const mat4 &a, const vec3 &v); // linear transform
|
||||
friend vec3 operator * (const vec3 &v, const mat4 &a); // linear transform
|
||||
};
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* 2D functions and 3D functions *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
mat3 identity2D (); // identity 2D
|
||||
mat3 translation2D(const vec2 &v); // translation 2D
|
||||
mat3 rotation2D (const vec2 &Center, float angleDeg); // rotation 2D
|
||||
mat3 scaling2D (const vec2 &scaleVector); // scaling 2D
|
||||
mat4 identity3D (); // identity 3D
|
||||
mat4 translation3D(const vec3 &v); // translation 3D
|
||||
mat4 rotation3D (const vec3 &Axis, float angleDeg); // rotation 3D
|
||||
mat4 rotation3Drad(const vec3 &Axis, float angleRad); // rotation 3D
|
||||
mat4 scaling3D (const vec3 &scaleVector); // scaling 3D
|
||||
mat4 perspective3D(float d); // perspective 3D
|
||||
|
||||
vec3 operator * (const vec3 &v, const mat3 &a);
|
||||
vec2 operator * (const vec2 &v, const mat3 &a);
|
||||
vec3 operator * (const vec3 &v, const mat4 &a);
|
||||
vec4 operator * (const vec4 &v, const mat4 &a);
|
||||
|
||||
#endif
|
||||
237
Extras/glui/arcball.cpp
Normal file
237
Extras/glui/arcball.cpp
Normal file
@@ -0,0 +1,237 @@
|
||||
/**********************************************************************
|
||||
|
||||
arcball.cpp
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
GLUI User Interface Toolkit (LGPL)
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
Feb 1998, Paul Rademacher (rademach@cs.unc.edu)
|
||||
Oct 2003, Nigel Stewart - GLUI Code Cleaning
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#include "arcball.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
/**************************************** Arcball::Arcball() ****/
|
||||
/* Default (void) constructor for Arcball */
|
||||
|
||||
Arcball::Arcball()
|
||||
{
|
||||
rot_ptr = &rot;
|
||||
init();
|
||||
}
|
||||
|
||||
/**************************************** Arcball::Arcball() ****/
|
||||
/* Takes as argument a mat4 to use instead of the internal rot */
|
||||
|
||||
Arcball::Arcball(mat4 *mtx)
|
||||
{
|
||||
rot_ptr = mtx;
|
||||
}
|
||||
|
||||
|
||||
/**************************************** Arcball::Arcball() ****/
|
||||
/* A constructor that accepts the screen center and arcball radius*/
|
||||
|
||||
Arcball::Arcball(const vec2 &_center, float _radius)
|
||||
{
|
||||
rot_ptr = &rot;
|
||||
init();
|
||||
set_params(_center, _radius);
|
||||
}
|
||||
|
||||
|
||||
/************************************** Arcball::set_params() ****/
|
||||
|
||||
void Arcball::set_params(const vec2 &_center, float _radius)
|
||||
{
|
||||
center = _center;
|
||||
radius = _radius;
|
||||
}
|
||||
|
||||
/*************************************** Arcball::init() **********/
|
||||
|
||||
void Arcball::init()
|
||||
{
|
||||
center.set( 0.0, 0.0 );
|
||||
radius = 1.0;
|
||||
q_now = quat_identity();
|
||||
*rot_ptr = identity3D();
|
||||
q_increment = quat_identity();
|
||||
rot_increment = identity3D();
|
||||
is_mouse_down = false;
|
||||
is_spinning = false;
|
||||
damp_factor = 0.0;
|
||||
zero_increment = true;
|
||||
}
|
||||
|
||||
/*********************************** Arcball::mouse_to_sphere() ****/
|
||||
|
||||
vec3 Arcball::mouse_to_sphere(const vec2 &p)
|
||||
{
|
||||
float mag;
|
||||
vec2 v2 = (p - center) / radius;
|
||||
vec3 v3( v2[0], v2[1], 0.0 );
|
||||
|
||||
mag = v2*v2;
|
||||
|
||||
if ( mag > 1.0 )
|
||||
v3.normalize();
|
||||
else
|
||||
v3[VZ] = (float) sqrt( 1.0 - mag );
|
||||
|
||||
/* Now we add constraints - X takes precedence over Y */
|
||||
if ( constraint_x )
|
||||
{
|
||||
v3 = constrain_vector( v3, vec3( 1.0, 0.0, 0.0 ));
|
||||
}
|
||||
else if ( constraint_y )
|
||||
{
|
||||
v3 = constrain_vector( v3, vec3( 0.0, 1.0, 0.0 ));
|
||||
}
|
||||
|
||||
return v3;
|
||||
}
|
||||
|
||||
|
||||
/************************************ Arcball::constrain_vector() ****/
|
||||
|
||||
vec3 Arcball::constrain_vector(const vec3 &vector, const vec3 &axis)
|
||||
{
|
||||
return (vector-(vector*axis)*axis).normalize();
|
||||
}
|
||||
|
||||
/************************************ Arcball::mouse_down() **********/
|
||||
|
||||
void Arcball::mouse_down(int x, int y)
|
||||
{
|
||||
down_pt.set( (float)x, (float) y );
|
||||
is_mouse_down = true;
|
||||
|
||||
q_increment = quat_identity();
|
||||
rot_increment = identity3D();
|
||||
zero_increment = true;
|
||||
}
|
||||
|
||||
|
||||
/************************************ Arcball::mouse_up() **********/
|
||||
|
||||
void Arcball::mouse_up()
|
||||
{
|
||||
q_now = q_drag * q_now;
|
||||
is_mouse_down = false;
|
||||
}
|
||||
|
||||
|
||||
/********************************** Arcball::mouse_motion() **********/
|
||||
|
||||
void Arcball::mouse_motion(int x, int y, int shift, int ctrl, int alt)
|
||||
{
|
||||
/* Set the X constraint if CONTROL key is pressed, Y if ALT key */
|
||||
set_constraints( ctrl != 0, alt != 0 );
|
||||
|
||||
vec2 new_pt( (float)x, (float) y );
|
||||
vec3 v0 = mouse_to_sphere( down_pt );
|
||||
vec3 v1 = mouse_to_sphere( new_pt );
|
||||
|
||||
vec3 cross = v0^v1;
|
||||
|
||||
q_drag.set( cross, v0 * v1 );
|
||||
|
||||
// *rot_ptr = (q_drag * q_now).to_mat4();
|
||||
mat4 temp = q_drag.to_mat4();
|
||||
*rot_ptr = *rot_ptr * temp;
|
||||
|
||||
down_pt = new_pt;
|
||||
|
||||
/* We keep a copy of the current incremental rotation (= q_drag) */
|
||||
q_increment = q_drag;
|
||||
rot_increment = q_increment.to_mat4();
|
||||
|
||||
set_constraints(false, false);
|
||||
|
||||
if ( q_increment.s < .999999 )
|
||||
{
|
||||
is_spinning = true;
|
||||
zero_increment = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_spinning = false;
|
||||
zero_increment = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/********************************** Arcball::mouse_motion() **********/
|
||||
|
||||
void Arcball::mouse_motion(int x, int y)
|
||||
{
|
||||
mouse_motion(x, y, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
/***************************** Arcball::set_constraints() **********/
|
||||
|
||||
void Arcball::set_constraints(bool _constraint_x, bool _constraint_y)
|
||||
{
|
||||
constraint_x = _constraint_x;
|
||||
constraint_y = _constraint_y;
|
||||
}
|
||||
|
||||
/***************************** Arcball::idle() *********************/
|
||||
|
||||
void Arcball::idle()
|
||||
{
|
||||
if (is_mouse_down)
|
||||
{
|
||||
is_spinning = false;
|
||||
zero_increment = true;
|
||||
}
|
||||
|
||||
if (damp_factor < 1.0f)
|
||||
q_increment.scale_angle(1.0f - damp_factor);
|
||||
|
||||
rot_increment = q_increment.to_mat4();
|
||||
|
||||
if (q_increment.s >= .999999f)
|
||||
{
|
||||
is_spinning = false;
|
||||
zero_increment = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************ Arcball::set_damping() *********************/
|
||||
|
||||
void Arcball::set_damping(float d)
|
||||
{
|
||||
damp_factor = d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
97
Extras/glui/arcball.h
Normal file
97
Extras/glui/arcball.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/**********************************************************************
|
||||
|
||||
arcball.h
|
||||
|
||||
GLUI User Interface Toolkit (LGPL)
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
Feb 1998, Paul Rademacher (rademach@cs.unc.edu)
|
||||
Oct 2003, Nigel Stewart - GLUI Code Cleaning
|
||||
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
---------------------------------------------------------------------
|
||||
|
||||
A C++ class that implements the Arcball, as described by Ken
|
||||
Shoemake in Graphics Gems IV.
|
||||
This class takes as input mouse events (mouse down, mouse drag,
|
||||
mouse up), and creates the appropriate quaternions and 4x4 matrices
|
||||
to represent the rotation given by the mouse.
|
||||
|
||||
This class is used as follows:
|
||||
- initialize [either in the constructor or with set_params()], the
|
||||
center position (x,y) of the arcball on the screen, and the radius
|
||||
- on mouse down, call mouse_down(x,y) with the mouse position
|
||||
- as the mouse is dragged, repeatedly call mouse_motion() with the
|
||||
current x and y positions. One can optionally pass in the current
|
||||
state of the SHIFT, ALT, and CONTROL keys (passing zero if keys
|
||||
are not pressed, non-zero otherwise), which constrains
|
||||
the rotation to certain axes (X for CONTROL, Y for ALT).
|
||||
- when the mouse button is released, call mouse_up()
|
||||
|
||||
Axis constraints can also be explicitly set with the
|
||||
set_constraints() function.
|
||||
|
||||
The current rotation is stored in the 4x4 float matrix 'rot'.
|
||||
It is also stored in the quaternion 'q_now'.
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef GLUI_ARCBALL_H
|
||||
#define GLUI_ARCBALL_H
|
||||
|
||||
#include "glui_internal.h"
|
||||
#include "algebra3.h"
|
||||
#include "quaternion.h"
|
||||
|
||||
class Arcball
|
||||
{
|
||||
public:
|
||||
Arcball();
|
||||
Arcball(mat4 *mtx);
|
||||
Arcball(const vec2 ¢er, float radius);
|
||||
|
||||
void set_damping(float d);
|
||||
void idle();
|
||||
void mouse_down(int x, int y);
|
||||
void mouse_up();
|
||||
void mouse_motion(int x, int y, int shift, int ctrl, int alt);
|
||||
void mouse_motion(int x, int y);
|
||||
void set_constraints(bool constrain_x, bool constrain_y);
|
||||
void set_params(const vec2 ¢er, float radius);
|
||||
void reset_mouse();
|
||||
void init();
|
||||
|
||||
vec3 constrain_vector(const vec3 &vector, const vec3 &axis);
|
||||
vec3 mouse_to_sphere(const vec2 &p);
|
||||
|
||||
//public:
|
||||
int is_mouse_down; /* true for down, false for up */
|
||||
int is_spinning;
|
||||
quat q_now, q_down, q_drag, q_increment;
|
||||
vec2 down_pt;
|
||||
mat4 rot, rot_increment;
|
||||
mat4 *rot_ptr;
|
||||
|
||||
bool constraint_x, constraint_y;
|
||||
vec2 center;
|
||||
float radius, damp_factor;
|
||||
int zero_increment;
|
||||
};
|
||||
|
||||
#endif
|
||||
2105
Extras/glui/glui.cpp
Normal file
2105
Extras/glui/glui.cpp
Normal file
File diff suppressed because it is too large
Load Diff
319
Extras/glui/glui_add_controls.cpp
Normal file
319
Extras/glui/glui_add_controls.cpp
Normal file
@@ -0,0 +1,319 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit (LGPL)
|
||||
---------------------------
|
||||
|
||||
glui_add_controls.cpp - Routines for adding controls to a GLUI window
|
||||
|
||||
Note: these routines are all deprecated. Keeping them all here
|
||||
prevents the linker from dragging in all the .o files, even for controls
|
||||
that aren't used.
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "GL/glui.h"
|
||||
#include "glui_internal.h"
|
||||
|
||||
|
||||
/*********************************** GLUI:: add_checkbox() ************/
|
||||
|
||||
GLUI_Checkbox *GLUI:: add_checkbox( const char *name, int *value_ptr,
|
||||
int id, GLUI_CB callback )
|
||||
{
|
||||
return add_checkbox_to_panel( main_panel,
|
||||
name, value_ptr, id, callback );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI:: add_checkbox_to_panel() **********/
|
||||
|
||||
GLUI_Checkbox *GLUI::add_checkbox_to_panel( GLUI_Panel *panel,
|
||||
const char *name, int *value_ptr,
|
||||
int id,
|
||||
GLUI_CB callback )
|
||||
{
|
||||
return new GLUI_Checkbox( panel, name, value_ptr, id, callback );
|
||||
}
|
||||
|
||||
/********************************************* GLUI::add_panel() *************/
|
||||
|
||||
GLUI_Panel *GLUI::add_panel( const char *name, int type )
|
||||
{
|
||||
return add_panel_to_panel( main_panel, name, type );
|
||||
}
|
||||
|
||||
|
||||
/**************************************** GLUI::add_panel_to_panel() *********/
|
||||
|
||||
GLUI_Panel *GLUI::add_panel_to_panel( GLUI_Panel *parent_panel,
|
||||
const char *name, int type )
|
||||
{
|
||||
return new GLUI_Panel( parent_panel, name, type );
|
||||
}
|
||||
|
||||
|
||||
/***************************** GLUI::add_radiogroup() ***************/
|
||||
|
||||
GLUI_RadioGroup *GLUI::add_radiogroup( int *value_ptr,
|
||||
int user_id, GLUI_CB callback)
|
||||
{
|
||||
return add_radiogroup_to_panel( main_panel, value_ptr,
|
||||
user_id, callback );
|
||||
}
|
||||
|
||||
|
||||
/***************************** GLUI::add_radiogroup_to_panel() ***************/
|
||||
|
||||
GLUI_RadioGroup *GLUI::add_radiogroup_to_panel(
|
||||
GLUI_Panel *panel, int *value_ptr,
|
||||
int user_id, GLUI_CB callback
|
||||
)
|
||||
{
|
||||
return new GLUI_RadioGroup( panel, value_ptr, user_id, callback );
|
||||
}
|
||||
|
||||
|
||||
/***************************** GLUI::add_radiobutton_to_group() *************/
|
||||
|
||||
GLUI_RadioButton *GLUI::add_radiobutton_to_group( GLUI_RadioGroup *group,
|
||||
const char *name )
|
||||
{
|
||||
return new GLUI_RadioButton( group, name );
|
||||
}
|
||||
|
||||
|
||||
/********************************** GLUI::add_statictext() ************/
|
||||
|
||||
GLUI_StaticText *GLUI::add_statictext( const char *name )
|
||||
{
|
||||
return add_statictext_to_panel( main_panel, name );
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI::add_statictext_to_panel() **********/
|
||||
|
||||
GLUI_StaticText *GLUI::add_statictext_to_panel( GLUI_Panel *panel,
|
||||
const char *name )
|
||||
{
|
||||
return new GLUI_StaticText( panel, name );
|
||||
}
|
||||
|
||||
|
||||
/***************************************** GLUI:: add_button() ************/
|
||||
|
||||
GLUI_Button *GLUI:: add_button( const char *name,
|
||||
int id, GLUI_CB callback )
|
||||
{
|
||||
return add_button_to_panel( main_panel,
|
||||
name, id, callback );
|
||||
}
|
||||
|
||||
/*********************************** GLUI:: add_button_to_panel() **********/
|
||||
|
||||
GLUI_Button *GLUI::add_button_to_panel( GLUI_Panel *panel,
|
||||
const char *name,
|
||||
int id,
|
||||
GLUI_CB callback )
|
||||
{
|
||||
return new GLUI_Button( panel, name, id, callback );
|
||||
}
|
||||
|
||||
/********************************** GLUI::add_separator() ************/
|
||||
|
||||
void GLUI::add_separator( void )
|
||||
{
|
||||
add_separator_to_panel( main_panel );
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI::add_separator_to_panel() **********/
|
||||
|
||||
void GLUI::add_separator_to_panel( GLUI_Panel *panel )
|
||||
{
|
||||
new GLUI_Separator( panel );
|
||||
}
|
||||
|
||||
|
||||
/********************************** GLUI::add_edittext() ************/
|
||||
|
||||
GLUI_EditText *GLUI::add_edittext( const char *name,
|
||||
int data_type, void *data,
|
||||
int id, GLUI_CB callback)
|
||||
{
|
||||
return add_edittext_to_panel( main_panel, name, data_type, data,
|
||||
id, callback );
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI::add_edittext_to_panel() **********/
|
||||
|
||||
GLUI_EditText *GLUI::add_edittext_to_panel( GLUI_Panel *panel,
|
||||
const char *name,
|
||||
int data_type, void *data,
|
||||
int id, GLUI_CB callback)
|
||||
{
|
||||
return new GLUI_EditText( panel, name, data_type, data, id, callback );
|
||||
}
|
||||
|
||||
/********************************** GLUI::add_edittext() ************/
|
||||
|
||||
GLUI_EditText *GLUI::add_edittext( const char *name,
|
||||
GLUI_String & data,
|
||||
int id, GLUI_CB callback)
|
||||
{
|
||||
return add_edittext_to_panel( main_panel, name, data, id, callback );
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI::add_edittext_to_panel() **********/
|
||||
|
||||
GLUI_EditText*
|
||||
GLUI::add_edittext_to_panel( GLUI_Panel *panel, const char *name,
|
||||
GLUI_String& data,
|
||||
int id, GLUI_CB callback)
|
||||
{
|
||||
return new GLUI_EditText( panel, name, GLUI_EDITTEXT_STRING, &data, id, callback );
|
||||
}
|
||||
|
||||
/********************************** GLUI::add_spinner() ************/
|
||||
|
||||
GLUI_Spinner *GLUI::add_spinner( const char *name,
|
||||
int data_type, void *data,
|
||||
int id, GLUI_CB callback)
|
||||
{
|
||||
return add_spinner_to_panel( main_panel, name, data_type, data,
|
||||
id, callback );
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI::add_spinner_to_panel() **********/
|
||||
|
||||
GLUI_Spinner *GLUI::add_spinner_to_panel(
|
||||
GLUI_Panel *panel, const char *name,
|
||||
int data_type, void *data,
|
||||
int id, GLUI_CB callback
|
||||
)
|
||||
{
|
||||
return new GLUI_Spinner( panel, name, data_type, data, id, callback );
|
||||
}
|
||||
|
||||
|
||||
/********************************** GLUI::add_column() ************/
|
||||
|
||||
void GLUI::add_column( int draw_bar )
|
||||
{
|
||||
add_column_to_panel( main_panel, draw_bar );
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI::add_column_to_panel() **********/
|
||||
|
||||
void GLUI::add_column_to_panel( GLUI_Panel *panel, int draw_bar )
|
||||
{
|
||||
new GLUI_Column( panel, draw_bar );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI:: add_listbox() ************/
|
||||
|
||||
GLUI_Listbox *GLUI:: add_listbox( const char *name, int *value_ptr,
|
||||
int id, GLUI_CB callback )
|
||||
{
|
||||
return add_listbox_to_panel( main_panel,
|
||||
name, value_ptr, id, callback );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI:: add_listbox_to_panel() **********/
|
||||
|
||||
GLUI_Listbox *GLUI::add_listbox_to_panel( GLUI_Panel *panel,
|
||||
const char *name, int *value_ptr,
|
||||
int id,
|
||||
GLUI_CB callback )
|
||||
{
|
||||
return new GLUI_Listbox( panel, name, value_ptr, id, callback );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI:: add_rotation() ************/
|
||||
|
||||
GLUI_Rotation *GLUI:: add_rotation( const char *name, float *value_ptr,
|
||||
int id, GLUI_CB callback )
|
||||
{
|
||||
return add_rotation_to_panel( main_panel, name, value_ptr, id, callback );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI:: add_rotation_to_panel() **********/
|
||||
|
||||
GLUI_Rotation *GLUI::add_rotation_to_panel( GLUI_Panel *panel,
|
||||
const char *name, float *value_ptr,
|
||||
int id,
|
||||
GLUI_CB callback )
|
||||
{
|
||||
return new GLUI_Rotation( panel, name, value_ptr, id, callback );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI:: add_translation() ************/
|
||||
|
||||
GLUI_Translation *GLUI:: add_translation( const char *name, int trans_type,
|
||||
float *value_ptr, int id,
|
||||
GLUI_CB callback )
|
||||
{
|
||||
return add_translation_to_panel( main_panel,name,trans_type,
|
||||
value_ptr, id, callback );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI:: add_translation_to_panel() **********/
|
||||
|
||||
GLUI_Translation *GLUI::add_translation_to_panel(
|
||||
GLUI_Panel *panel, const char *name,
|
||||
int trans_type, float *value_ptr,
|
||||
int id, GLUI_CB callback
|
||||
)
|
||||
{
|
||||
return new GLUI_Translation(panel, name, trans_type, value_ptr, id, callback);
|
||||
}
|
||||
|
||||
|
||||
/********************************** GLUI::add_rollout() **************/
|
||||
|
||||
GLUI_Rollout *GLUI::add_rollout( const char *name, int open, int type)
|
||||
{
|
||||
return add_rollout_to_panel( main_panel, name, open, type);
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI::add_rollout_to_panel() *********/
|
||||
|
||||
GLUI_Rollout *GLUI::add_rollout_to_panel(GLUI_Panel *panel, const char *name,
|
||||
int open, int type)
|
||||
{
|
||||
return new GLUI_Rollout( panel, name, open, type );
|
||||
}
|
||||
|
||||
|
||||
|
||||
138
Extras/glui/glui_bitmap_img_data.cpp
Normal file
138
Extras/glui/glui_bitmap_img_data.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
Bitmaps for all GLUI images.
|
||||
|
||||
These were converted from original PPM images
|
||||
(mostly lost) with the tools/ppm2array program.
|
||||
|
||||
The images here are extracted in typical OpenGL
|
||||
bottom-to-top fashion.
|
||||
|
||||
FIXME: don't use greyscale brightness here--this prevents
|
||||
people changing the background color. Instead, use a code
|
||||
indicating the underlying purpose of the pixel:
|
||||
0 = shadows; outlines; UI elements (check boxes, arrows)
|
||||
64 = disabled shadows and UI elements
|
||||
128 = shadowing, disabled
|
||||
192 = disabled white; background
|
||||
255 = highlights; checkbox/radio background
|
||||
|
||||
I'm thinking the way to do this would be to have an
|
||||
enum {
|
||||
BG = 0, // Background shines through-- totally alpha transparent
|
||||
BS, // Background of scrollbar/spin box-- opaque gray
|
||||
SB, // Shadowed-black element-- strong alpha blend to black
|
||||
SD, // Shadowed-dark element-- weak alpha blend to black
|
||||
HL, // Highlight-light-- weak alpha blend to white
|
||||
HW, // Highlight-white-- strong alpha blend to white
|
||||
UB, // User-interface black-- arrows, checkboxes, radio buttons
|
||||
UW, // User-interface white-- backgrounds of checkboxes and radio buttons
|
||||
};
|
||||
|
||||
Orion Sky Lawlor, olawlor@acm.org, 2006/05/04 (LGPL)
|
||||
*/
|
||||
|
||||
/*----------------------- checkboxes --------------------------*/
|
||||
unsigned char glui_img_checkbox_0[] = { 13, 13, /* width, height */
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_checkbox_0_dis[] = { 13, 13, /* width, height */
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_checkbox_1[] = { 13, 13, /* width, height */
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 255, 0, 255, 255, 255, 255, 255, 192, 255, 128, 0, 255, 255, 0, 0, 0, 255, 255, 255, 255, 192, 255, 128, 0, 255, 0, 0, 0, 0, 0, 255, 255, 255, 192, 255, 128, 0, 255, 0, 0, 255, 0, 0, 0, 255, 255, 192, 255, 128, 0, 255, 0, 255, 255, 255, 0, 0, 0, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 0, 0, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 0, 255, 192, 255, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_checkbox_1_dis[] = { 13, 13, /* width, height */
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 192, 64, 192, 192, 192, 192, 192, 192, 255, 128, 64, 192, 192, 64, 64, 64, 192, 192, 192, 192, 192, 255, 128, 64, 192, 64, 64, 64, 64, 64, 192, 192, 192, 192, 255, 128, 64, 192, 64, 64, 192, 64, 64, 64, 192, 192, 192, 255, 128, 64, 192, 64, 192, 192, 192, 64, 64, 64, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 64, 64, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 64, 192, 192, 255, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 128, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 255,
|
||||
};
|
||||
|
||||
|
||||
/*------------------------------- arrows -------------------------------------*/
|
||||
unsigned char glui_img_downarrow[] = { 16, 16, /* width, height */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 0, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 0, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 0, 0, 0, 0, 0, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 0,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_leftarrow[] = { 16, 16, /* width, height */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 0, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 0, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 0, 0, 0, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 0, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 0, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 0,
|
||||
};
|
||||
|
||||
unsigned char glui_img_rightarrow[] = { 16, 16, /* width, height */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 0, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 0, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 0, 0, 0, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 0, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 0, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 0,
|
||||
};
|
||||
|
||||
unsigned char glui_img_uparrow[] = { 16, 16, /* width, height */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 0, 0, 0, 0, 0, 0, 0, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 0, 0, 0, 0, 0, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 0, 0, 0, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 0, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 128, 0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 0,
|
||||
};
|
||||
|
||||
/*------------------ listboxes ---------------------*/
|
||||
unsigned char glui_img_listbox_down[] = { 11, 17, /* width, height */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 127, 191, 191, 191, 127, 0, 127, 191, 191, 191, 127, 127, 127, 191, 191, 127, 0, 127, 191, 191, 127, 127, 127, 127, 127, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 0,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_listbox_up[] = { 11, 17, /* width, height */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 127, 127, 127, 127, 127, 127, 127, 127, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 191, 191, 191, 0, 191, 191, 191, 127, 0, 191, 255, 191, 191, 0, 0, 0, 191, 191, 127, 0, 191, 255, 191, 0, 0, 0, 0, 0, 191, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 0, 191, 255, 255, 255, 255, 255, 255, 255, 255, 127, 0, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 0,
|
||||
};
|
||||
|
||||
unsigned char glui_img_listbox_up_dis[] = { 11, 17, /* width, height */
|
||||
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 191, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 191, 191, 191, 254, 191, 191, 191, 127, 127, 191, 255, 191, 191, 127, 127, 254, 191, 191, 127, 127, 191, 255, 191, 127, 127, 127, 127, 254, 191, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 191, 191, 191, 191, 191, 191, 191, 127, 127, 191, 255, 255, 255, 255, 255, 255, 255, 255, 127, 127, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 127,
|
||||
};
|
||||
|
||||
/*--------------------------- radio buttons -------------------------*/
|
||||
unsigned char glui_img_radiobutton_0[] = { 14, 14, /* width, height */
|
||||
192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 255, 255, 255, 192, 192, 192, 192, 192, 192, 192, 192, 255, 255, 192, 192, 192, 192, 255, 255, 192, 192, 192, 192, 192, 128, 192, 192, 255, 255, 255, 255, 192, 192, 255, 192, 192, 192, 192, 128, 0, 255, 255, 255, 255, 255, 255, 192, 255, 192, 192, 192, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 192, 192, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 192, 192, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 192, 192, 128, 0, 255, 255, 255, 255, 255, 255, 255, 255, 192, 255, 192, 192, 192, 128, 0, 255, 255, 255, 255, 255, 255, 192, 255, 192, 192, 192, 192, 128, 0, 0, 255, 255, 255, 255, 0, 0, 255, 192, 192, 192, 192, 192, 128, 128, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 128, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_radiobutton_0_dis[] = { 14, 14, /* width, height */
|
||||
192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 255, 255, 255, 192, 192, 192, 192, 192, 192, 192, 192, 255, 255, 192, 192, 192, 192, 255, 255, 192, 192, 192, 192, 192, 128, 192, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 192, 192, 128, 64, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 192, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 128, 64, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 192, 128, 64, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 192, 192, 128, 64, 64, 192, 192, 192, 192, 64, 64, 255, 192, 192, 192, 192, 192, 128, 128, 64, 64, 64, 64, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 128, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_radiobutton_1[] = { 14, 14, /* width, height */
|
||||
192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 255, 255, 255, 192, 192, 192, 192, 192, 192, 192, 192, 255, 255, 192, 192, 192, 192, 255, 255, 192, 192, 192, 192, 192, 128, 192, 192, 255, 255, 255, 255, 192, 192, 255, 192, 192, 192, 192, 128, 0, 255, 255, 255, 255, 255, 255, 192, 255, 192, 192, 192, 128, 0, 255, 255, 255, 0, 0, 255, 255, 255, 192, 255, 192, 192, 128, 0, 255, 255, 0, 0, 0, 0, 255, 255, 192, 255, 192, 192, 128, 0, 255, 255, 0, 0, 0, 0, 255, 255, 192, 255, 192, 192, 128, 0, 255, 255, 255, 0, 0, 255, 255, 255, 192, 255, 192, 192, 192, 128, 0, 255, 255, 255, 255, 255, 255, 192, 255, 192, 192, 192, 192, 128, 0, 0, 255, 255, 255, 255, 0, 0, 255, 192, 192, 192, 192, 192, 128, 128, 0, 0, 0, 0, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 128, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_radiobutton_1_dis[] = { 14, 14, /* width, height */
|
||||
192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 255, 255, 255, 255, 192, 192, 192, 192, 192, 192, 192, 192, 255, 255, 192, 192, 192, 192, 255, 255, 192, 192, 192, 192, 192, 128, 192, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 192, 192, 128, 64, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 192, 128, 64, 192, 192, 192, 64, 64, 192, 192, 192, 192, 255, 192, 192, 128, 64, 192, 192, 64, 64, 64, 64, 192, 192, 192, 255, 192, 192, 128, 64, 192, 192, 64, 64, 64, 64, 192, 192, 192, 255, 192, 192, 128, 64, 192, 192, 192, 64, 64, 192, 192, 192, 192, 255, 192, 192, 192, 128, 64, 192, 192, 192, 192, 192, 192, 192, 255, 192, 192, 192, 192, 128, 64, 64, 192, 192, 192, 192, 64, 64, 255, 192, 192, 192, 192, 192, 128, 128, 64, 64, 64, 64, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 128, 128, 128, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*----------------- spinners ----------------------------*/
|
||||
unsigned char glui_img_spindown_0[] = { 12, 8, /* width, height */
|
||||
255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 0, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 255, 191, 191, 191, 191, 0, 127, 191, 191, 191, 127, 0, 255, 191, 191, 191, 0, 0, 0, 127, 191, 191, 127, 0, 255, 191, 191, 0, 0, 0, 0, 0, 127, 191, 127, 0, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_spindown_1[] = { 12, 8, /* width, height */
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 191, 255, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 191, 255, 0, 127, 191, 191, 191, 127, 0, 191, 191, 191, 191, 255, 0, 127, 191, 191, 127, 0, 0, 0, 191, 191, 191, 255, 0, 127, 191, 127, 0, 0, 0, 0, 0, 191, 191, 255, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 191, 255, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 191, 255,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_spindown_dis[] = { 12, 8, /* width, height */
|
||||
255, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 255, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 64, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 127, 64, 255, 191, 191, 191, 191, 127, 255, 191, 191, 191, 127, 64, 255, 191, 191, 191, 127, 127, 127, 255, 191, 191, 127, 64, 255, 191, 191, 127, 127, 127, 127, 127, 255, 191, 127, 64, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 127, 64, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 64,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_spinup_0[] = { 12, 8, /* width, height */
|
||||
255, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 0, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 255, 191, 191, 0, 0, 0, 0, 0, 127, 191, 127, 0, 255, 191, 191, 191, 0, 0, 0, 127, 191, 191, 127, 0, 255, 191, 191, 191, 191, 0, 127, 191, 191, 191, 127, 0, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 127, 0, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_spinup_1[] = { 12, 8, /* width, height */
|
||||
0, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 191, 255, 0, 127, 191, 127, 0, 0, 0, 0, 0, 191, 191, 255, 0, 127, 191, 191, 127, 0, 0, 0, 191, 191, 191, 255, 0, 127, 191, 191, 191, 127, 0, 191, 191, 191, 191, 255, 0, 127, 191, 191, 191, 191, 191, 191, 191, 191, 191, 255, 0, 127, 127, 127, 127, 127, 127, 127, 127, 127, 191, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,
|
||||
};
|
||||
|
||||
|
||||
unsigned char glui_img_spinup_dis[] = { 12, 8, /* width, height */
|
||||
255, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 64, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 127, 64, 255, 191, 191, 127, 127, 127, 127, 127, 255, 191, 127, 64, 255, 191, 191, 191, 127, 127, 127, 255, 191, 191, 127, 64, 255, 191, 191, 191, 191, 127, 255, 191, 191, 191, 127, 64, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 127, 64, 255, 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, 64, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
};
|
||||
|
||||
176
Extras/glui/glui_bitmaps.cpp
Normal file
176
Extras/glui/glui_bitmaps.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_bitmaps.cpp
|
||||
|
||||
Draws the hardcoded images listed in glui_bitmap_img_data with OpenGL.
|
||||
|
||||
FIXME: upload the images to a texture. This will allow them to be:
|
||||
- Drawn with alpha blending
|
||||
- Drawn at random sizes and angles onscreen
|
||||
- Drawn much faster than with glDrawPixels
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "GL/glui.h"
|
||||
#include "glui_internal.h"
|
||||
#include <cassert>
|
||||
|
||||
/************ Image Bitmap arrays **********/
|
||||
|
||||
extern unsigned char glui_img_checkbox_0[];
|
||||
extern unsigned char glui_img_checkbox_1[];
|
||||
extern unsigned char glui_img_radiobutton_0[];
|
||||
extern unsigned char glui_img_radiobutton_1[];
|
||||
extern unsigned char glui_img_uparrow[];
|
||||
extern unsigned char glui_img_downarrow[];
|
||||
extern unsigned char glui_img_leftarrow[];
|
||||
extern unsigned char glui_img_rightarrow[];
|
||||
extern unsigned char glui_img_spinup_0[];
|
||||
extern unsigned char glui_img_spinup_1[];
|
||||
extern unsigned char glui_img_spindown_0[];
|
||||
extern unsigned char glui_img_spindown_1[];
|
||||
extern unsigned char glui_img_checkbox_0_dis[];
|
||||
extern unsigned char glui_img_checkbox_1_dis[];
|
||||
extern unsigned char glui_img_radiobutton_0_dis[];
|
||||
extern unsigned char glui_img_radiobutton_1_dis[];
|
||||
extern unsigned char glui_img_spinup_dis[];
|
||||
extern unsigned char glui_img_spindown_dis[];
|
||||
extern unsigned char glui_img_listbox_up[];
|
||||
extern unsigned char glui_img_listbox_down[];
|
||||
extern unsigned char glui_img_listbox_up_dis[];
|
||||
|
||||
|
||||
// These must be in the same order as the GLUI_STDBITMAP enums from glui.h!
|
||||
unsigned char *bitmap_arrays[] = {
|
||||
glui_img_checkbox_0,
|
||||
glui_img_checkbox_1,
|
||||
glui_img_radiobutton_0,
|
||||
glui_img_radiobutton_1,
|
||||
glui_img_uparrow,
|
||||
glui_img_downarrow,
|
||||
glui_img_leftarrow,
|
||||
glui_img_rightarrow,
|
||||
glui_img_spinup_0,
|
||||
glui_img_spinup_1,
|
||||
glui_img_spindown_0,
|
||||
glui_img_spindown_1,
|
||||
glui_img_checkbox_0_dis,
|
||||
glui_img_checkbox_1_dis,
|
||||
glui_img_radiobutton_0_dis,
|
||||
glui_img_radiobutton_1_dis,
|
||||
glui_img_spinup_dis,
|
||||
glui_img_spindown_dis,
|
||||
glui_img_listbox_up,
|
||||
glui_img_listbox_down,
|
||||
glui_img_listbox_up_dis,
|
||||
};
|
||||
|
||||
|
||||
/************************************ GLUI_Bitmap::load_from_array() ********/
|
||||
|
||||
GLUI_Bitmap::GLUI_Bitmap()
|
||||
: pixels(NULL),
|
||||
w(0),
|
||||
h(0)
|
||||
{
|
||||
}
|
||||
|
||||
GLUI_Bitmap::~GLUI_Bitmap()
|
||||
{
|
||||
if (pixels)
|
||||
{
|
||||
free(pixels);
|
||||
pixels = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create bitmap from greyscale byte array */
|
||||
void GLUI_Bitmap::init_grey(unsigned char *array)
|
||||
{
|
||||
w = array[0]; h = array[1];
|
||||
pixels = (unsigned char *) malloc(w*h*3);
|
||||
assert(pixels);
|
||||
|
||||
for(int i = 0; i<w*h; i++ )
|
||||
for (int j = 0; j<3; j++) /* copy grey to r,g,b channels */
|
||||
pixels[i*3+j] = (unsigned char) array[i+2];
|
||||
}
|
||||
|
||||
|
||||
/* Create bitmap from color int array.
|
||||
(OSL) This used to be how all GLUI bitmaps were stored, which was horribly
|
||||
inefficient--three ints per pixel, or 12 bytes per pixel!
|
||||
*/
|
||||
void GLUI_Bitmap::init(int *array)
|
||||
{
|
||||
w = array[0]; h = array[1];
|
||||
pixels = (unsigned char *) malloc(w*h*3);
|
||||
assert(pixels);
|
||||
|
||||
for (int i = 0; i<w*h*3; i++)
|
||||
pixels[i] = (unsigned char) array[i+2];
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_StdBitmaps::draw() *****************/
|
||||
|
||||
GLUI_StdBitmaps::GLUI_StdBitmaps()
|
||||
{
|
||||
for (int i=0; i<GLUI_STDBITMAP_NUM_ITEMS; i++)
|
||||
bitmaps[i].init_grey(bitmap_arrays[i]);
|
||||
}
|
||||
|
||||
GLUI_StdBitmaps::~GLUI_StdBitmaps()
|
||||
{
|
||||
}
|
||||
|
||||
int GLUI_StdBitmaps::width(int i) const
|
||||
{
|
||||
assert(i>=0 && i<GLUI_STDBITMAP_NUM_ITEMS);
|
||||
return bitmaps[i].w;
|
||||
}
|
||||
|
||||
int GLUI_StdBitmaps::height(int i) const
|
||||
{
|
||||
assert(i>=0 && i<GLUI_STDBITMAP_NUM_ITEMS);
|
||||
return bitmaps[i].h;
|
||||
}
|
||||
|
||||
void GLUI_StdBitmaps::draw(int i, int x, int y) const
|
||||
{
|
||||
assert(i>=0 && i<GLUI_STDBITMAP_NUM_ITEMS);
|
||||
|
||||
if (bitmaps[i].pixels != NULL )
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
||||
glRasterPos2f(0.5f+x, 0.5f+y+bitmaps[i].h);
|
||||
glDrawPixels(
|
||||
bitmaps[i].w, bitmaps[i].h,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, bitmaps[i].pixels);
|
||||
}
|
||||
}
|
||||
|
||||
186
Extras/glui/glui_button.cpp
Normal file
186
Extras/glui/glui_button.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_button.cpp - GLUI_Button control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
/****************************** GLUI_Button::GLUI_Button() **********/
|
||||
|
||||
GLUI_Button::GLUI_Button( GLUI_Node *parent, const char *name,
|
||||
int id, GLUI_CB cb )
|
||||
{
|
||||
common_init();
|
||||
user_id = id;
|
||||
callback = cb;
|
||||
set_name( name );
|
||||
currently_inside = false;
|
||||
|
||||
parent->add_control( this );
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Button::mouse_down_handler() **********/
|
||||
|
||||
int GLUI_Button::mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
int_val = 1; /** A button always in unpressed before here, so
|
||||
now we invariably set it to 'depressed' **/
|
||||
|
||||
currently_inside = true;
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Button::mouse_up_handler() **********/
|
||||
|
||||
int GLUI_Button::mouse_up_handler( int local_x, int local_y, bool inside )
|
||||
{
|
||||
set_int_val( 0 ); /** A button always turns off after you press it **/
|
||||
|
||||
currently_inside = false;
|
||||
redraw();
|
||||
|
||||
if ( inside ) {
|
||||
/*** Invoke the user's callback ***/
|
||||
execute_callback();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Button::mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_Button::mouse_held_down_handler( int local_x, int local_y,
|
||||
bool new_inside)
|
||||
{
|
||||
if (new_inside != currently_inside) {
|
||||
currently_inside = new_inside;
|
||||
redraw();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Button::key_handler() **********/
|
||||
|
||||
int GLUI_Button::key_handler( unsigned char key,int modifiers )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/********************************************** GLUI_Button::draw() **********/
|
||||
|
||||
void GLUI_Button::draw( int x, int y )
|
||||
{
|
||||
if (currently_inside) draw_pressed();
|
||||
else {
|
||||
glui->draw_raised_box( 0, 0, w, h );
|
||||
draw_text( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************** GLUI_Button::draw_pressed() ******/
|
||||
|
||||
void GLUI_Button::draw_pressed( void )
|
||||
{
|
||||
glColor3f( 0.0, 0.0, 0.0 );
|
||||
|
||||
draw_text( 1 );
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( 0, 0 ); glVertex2i( w, 0 );
|
||||
glVertex2i( w, h ); glVertex2i( 0, h );
|
||||
glEnd();
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( 1, 1 ); glVertex2i( w-1, 1 );
|
||||
glVertex2i( w-1, h-1 ); glVertex2i( 1, h-1 );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
/**************************************** GLUI_Button::draw_text() **********/
|
||||
|
||||
void GLUI_Button::draw_text( int sunken )
|
||||
{
|
||||
int string_width;
|
||||
|
||||
glColor3ub( glui->bkgd_color.r, glui->bkgd_color.g, glui->bkgd_color.b );
|
||||
glDisable( GL_CULL_FACE );
|
||||
glBegin( GL_QUADS );
|
||||
glVertex2i( 2, 2 ); glVertex2i( w-2, 2 );
|
||||
glVertex2i( w-2, h-2 ); glVertex2i( 2, h-2 );
|
||||
glEnd();
|
||||
|
||||
glColor3ub( 0,0,0 );
|
||||
|
||||
string_width = _glutBitmapWidthString( glui->font,
|
||||
this->name.c_str() );
|
||||
if ( NOT sunken ) {
|
||||
draw_name( MAX((w-string_width),0)/2, 13);
|
||||
}
|
||||
else {
|
||||
draw_name( MAX((w-string_width),0)/2 + 1, 13 + 1);
|
||||
}
|
||||
|
||||
if ( active ) {
|
||||
glEnable( GL_LINE_STIPPLE );
|
||||
glLineStipple( 1, 0x5555 );
|
||||
|
||||
glColor3f( 0., 0., 0. );
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( 3, 3 ); glVertex2i( w-3, 3 );
|
||||
glVertex2i( w-3, h-3 ); glVertex2i( 3, h-3 );
|
||||
glEnd();
|
||||
|
||||
glDisable( GL_LINE_STIPPLE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************** GLUI_Button::update_size() **********/
|
||||
|
||||
void GLUI_Button::update_size( void )
|
||||
{
|
||||
int text_size;
|
||||
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
text_size = string_width( name );
|
||||
|
||||
if ( w < text_size + 16 )
|
||||
w = text_size + 16 ;
|
||||
}
|
||||
188
Extras/glui/glui_checkbox.cpp
Normal file
188
Extras/glui/glui_checkbox.cpp
Normal file
@@ -0,0 +1,188 @@
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit (LGPL)
|
||||
---------------------------
|
||||
|
||||
glui_checkbox - GLUI_Checkbox control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
/****************************** GLUI_Checkbox::GLUI_Checkbox() **********/
|
||||
|
||||
GLUI_Checkbox::GLUI_Checkbox( GLUI_Node *parent,
|
||||
const char *name, int *value_ptr,
|
||||
int id,
|
||||
GLUI_CB cb )
|
||||
{
|
||||
common_init();
|
||||
|
||||
set_ptr_val( value_ptr );
|
||||
set_name( name );
|
||||
user_id = id;
|
||||
callback = cb;
|
||||
|
||||
parent->add_control( this );
|
||||
|
||||
init_live();
|
||||
}
|
||||
|
||||
/****************************** GLUI_Checkbox::mouse_down_handler() **********/
|
||||
|
||||
int GLUI_Checkbox::mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
orig_value = int_val;
|
||||
int_val = !int_val;
|
||||
|
||||
currently_inside = true;
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Checkbox::mouse_up_handler() **********/
|
||||
|
||||
int GLUI_Checkbox::mouse_up_handler( int local_x, int local_y, bool inside )
|
||||
{
|
||||
if ( NOT inside ) { /* undo effect on value */
|
||||
int_val = orig_value;
|
||||
}
|
||||
else {
|
||||
set_int_val( int_val );
|
||||
|
||||
/*** Invoke the callback ***/
|
||||
execute_callback();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Checkbox::mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_Checkbox::mouse_held_down_handler( int local_x, int local_y,
|
||||
bool inside)
|
||||
{
|
||||
/********** Toggle checked and unchecked bitmap if we're entering or
|
||||
leaving the checkbox area **********/
|
||||
if ( inside != currently_inside ) {
|
||||
int_val = !int_val;
|
||||
currently_inside = inside;
|
||||
redraw();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Checkbox::key_handler() **********/
|
||||
|
||||
int GLUI_Checkbox::key_handler( unsigned char key,int modifiers )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Checkbox::draw() **********/
|
||||
|
||||
void GLUI_Checkbox::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
if ( int_val != 0 ) {
|
||||
if ( enabled )
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_CHECKBOX_ON, 0, 0 );
|
||||
else
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_CHECKBOX_ON_DIS, 0, 0 );
|
||||
}
|
||||
else {
|
||||
if ( enabled )
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_CHECKBOX_OFF, 0, 0 );
|
||||
else
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_CHECKBOX_OFF_DIS, 0, 0 );
|
||||
}
|
||||
|
||||
draw_active_area();
|
||||
|
||||
draw_name( text_x_offset, 10);
|
||||
}
|
||||
|
||||
/**************************** GLUI_Checkbox::draw_active_area() **************/
|
||||
|
||||
void GLUI_Checkbox::draw_active_area( void )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
int text_width, left, right;
|
||||
|
||||
text_width = _glutBitmapWidthString( glui->font, name.c_str() );
|
||||
left = text_x_offset-3;
|
||||
right = left + 7 + text_width;
|
||||
|
||||
if ( active ) {
|
||||
glEnable( GL_LINE_STIPPLE );
|
||||
glLineStipple( 1, 0x5555 );
|
||||
glColor3f( 0., 0., 0. );
|
||||
} else {
|
||||
glColor3ub( glui->bkgd_color.r, glui->bkgd_color.g, glui->bkgd_color.b );
|
||||
}
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i(left,0); glVertex2i( right,0);
|
||||
glVertex2i(right,h+1); glVertex2i( left,h+1);
|
||||
glEnd();
|
||||
|
||||
glDisable( GL_LINE_STIPPLE );
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Checkbox::update_size() **********/
|
||||
|
||||
void GLUI_Checkbox::update_size( void )
|
||||
{
|
||||
int text_size;
|
||||
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
text_size = _glutBitmapWidthString( glui->font, name.c_str() );
|
||||
|
||||
/* if ( w < text_x_offset + text_size + 6 ) */
|
||||
w = text_x_offset + text_size + 6 ;
|
||||
}
|
||||
|
||||
|
||||
/********************************* GLUI_Checkbox::set_int_val() **************/
|
||||
|
||||
void GLUI_Checkbox::set_int_val( int new_val )
|
||||
{
|
||||
int_val = new_val;
|
||||
|
||||
/*** Update the variable we're (possibly) pointing to ***/
|
||||
output_live(true);
|
||||
redraw();
|
||||
}
|
||||
89
Extras/glui/glui_column.cpp
Normal file
89
Extras/glui/glui_column.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_column.cpp - GLUI_Column control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
/******************************** GLUI_Column::GLUI_Column() ************/
|
||||
|
||||
GLUI_Column::GLUI_Column( GLUI_Node *parent, int draw_bar )
|
||||
{
|
||||
common_init();
|
||||
int_val = draw_bar; /* Whether to draw vertical bar or not */
|
||||
|
||||
parent->add_control( this );
|
||||
}
|
||||
|
||||
/**************************************** GLUI_Column::draw() ************/
|
||||
|
||||
void GLUI_Column::draw( int x, int y )
|
||||
{
|
||||
int panel_x, panel_y, panel_w, panel_h, panel_x_off, panel_y_off;
|
||||
int y_diff;
|
||||
|
||||
if ( int_val == 1 ) { /* Draw a vertical bar */
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
if ( parent() != NULL ) {
|
||||
get_this_column_dims(&panel_x, &panel_y, &panel_w, &panel_h,
|
||||
&panel_x_off, &panel_y_off);
|
||||
|
||||
y_diff = y_abs - panel_y;
|
||||
|
||||
if ( 0 ) {
|
||||
glLineWidth(1.0);
|
||||
glBegin( GL_LINES );
|
||||
glColor3f( .5, .5, .5 );
|
||||
glVertex2i( -GLUI_XOFF+1, -y_diff + GLUI_SEPARATOR_HEIGHT/2 );
|
||||
glVertex2i( -GLUI_XOFF+1, -y_diff + panel_h - GLUI_SEPARATOR_HEIGHT/2);
|
||||
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glVertex2i( -GLUI_XOFF+2, -y_diff + GLUI_SEPARATOR_HEIGHT/2 );
|
||||
glVertex2i( -GLUI_XOFF+2, -y_diff + panel_h - GLUI_SEPARATOR_HEIGHT/2);
|
||||
glEnd();
|
||||
}
|
||||
else {
|
||||
glLineWidth(1.0);
|
||||
glBegin( GL_LINES );
|
||||
glColor3f( .5, .5, .5 );
|
||||
glVertex2i( -2, 0 );
|
||||
glVertex2i( -2, h );
|
||||
/*glVertex2i( 0, -y_diff + GLUI_SEPARATOR_HEIGHT/2 ); */
|
||||
/*glVertex2i( 0, -y_diff + panel_h - GLUI_SEPARATOR_HEIGHT/2); */
|
||||
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glVertex2i( -1, 0 );
|
||||
glVertex2i( -1, h );
|
||||
/*glVertex2i( 1, -y_diff + GLUI_SEPARATOR_HEIGHT/2 ); */
|
||||
/*glVertex2i( 1, -y_diff + panel_h - GLUI_SEPARATOR_HEIGHT/2); */
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
197
Extras/glui/glui_commandline.cpp
Normal file
197
Extras/glui/glui_commandline.cpp
Normal file
@@ -0,0 +1,197 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_commandline.cpp - GLUI_CommandLine control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher, 2005 William Baxter
|
||||
|
||||
This library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA
|
||||
|
||||
This program is -not- in the public domain.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "GL/glui.h"
|
||||
#include "glui_internal.h"
|
||||
|
||||
/****************************** GLUI_CommandLine::GLUI_CommandLine() **********/
|
||||
GLUI_CommandLine::GLUI_CommandLine( GLUI_Node *parent, const char *name,
|
||||
void *data, int id, GLUI_CB cb )
|
||||
{
|
||||
common_init();
|
||||
set_name( name );
|
||||
|
||||
data_type = GLUI_EDITTEXT_TEXT;
|
||||
ptr_val = data;
|
||||
user_id = id;
|
||||
callback = cb;
|
||||
|
||||
live_type = GLUI_LIVE_TEXT;
|
||||
|
||||
parent->add_control( this );
|
||||
|
||||
init_live();
|
||||
}
|
||||
|
||||
/****************************** GLUI_CommandLine::key_handler() **********/
|
||||
|
||||
int GLUI_CommandLine::key_handler( unsigned char key,int modifiers )
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ( NOT glui )
|
||||
return false;
|
||||
|
||||
if ( debug )
|
||||
dump( stdout, "-> CMD_TEXT KEY HANDLER" );
|
||||
|
||||
if ( key == 13 ) { /* RETURN */
|
||||
commit_flag = true;
|
||||
}
|
||||
|
||||
ret = Super::key_handler( key, modifiers );
|
||||
|
||||
if ( debug )
|
||||
dump( stdout, "<- CMD_TEXT KEY HANDLER" );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_CommandLine::deactivate() **********/
|
||||
|
||||
void GLUI_CommandLine::deactivate( void )
|
||||
{
|
||||
// if the commit_flag is set, add the current command to
|
||||
// history and call deactivate as normal
|
||||
|
||||
// Trick deactivate into calling callback if and only if commit_flag set.
|
||||
// A bit subtle, but deactivate checks that orig_text and text
|
||||
// are the same to decide whether or not to call the callback.
|
||||
// Force them to be different for commit, and the same for no commit.
|
||||
if (commit_flag) {
|
||||
add_to_history(text.c_str());
|
||||
orig_text = "";
|
||||
Super::deactivate( );
|
||||
set_text( "" );
|
||||
commit_flag = false;
|
||||
}
|
||||
else {
|
||||
orig_text = text;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************** GLUI_CommandLine::special_handler() **********/
|
||||
|
||||
int GLUI_CommandLine::special_handler( int key,int modifiers )
|
||||
{
|
||||
if ( NOT glui )
|
||||
return false;
|
||||
|
||||
if ( debug )
|
||||
printf( "CMD_TEXT SPECIAL:%d - mod:%d subs:%d/%d ins:%d sel:%d/%d\n",
|
||||
key, modifiers, substring_start, substring_end,insertion_pt,
|
||||
sel_start, sel_end );
|
||||
|
||||
if ( key == GLUT_KEY_UP ) // PREVIOUS HISTORY
|
||||
{
|
||||
scroll_history(-1);
|
||||
}
|
||||
else if ( key == GLUT_KEY_DOWN ) // NEXT HISTORY
|
||||
{
|
||||
scroll_history(+1);
|
||||
}
|
||||
else {
|
||||
return Super::special_handler( key, modifiers );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************** GLUI_CommandLine::scroll_history() ********/
|
||||
|
||||
void GLUI_CommandLine::scroll_history( int direction )
|
||||
{
|
||||
recall_history(curr_hist + direction);
|
||||
}
|
||||
|
||||
/**************************** GLUI_CommandLine::recall_history() ********/
|
||||
|
||||
void GLUI_CommandLine::recall_history( int hist_num )
|
||||
{
|
||||
if (hist_num < oldest_hist OR
|
||||
hist_num > newest_hist OR
|
||||
hist_num == curr_hist)
|
||||
return;
|
||||
|
||||
// Commit the current text first before we blow it away!
|
||||
if (curr_hist == newest_hist) {
|
||||
get_history_str(newest_hist) = text;
|
||||
}
|
||||
|
||||
curr_hist = hist_num;
|
||||
set_text(get_history_str(curr_hist));
|
||||
sel_end = sel_start = insertion_pt = (int)text.length();
|
||||
update_and_draw_text();
|
||||
}
|
||||
|
||||
/**************************** GLUI_CommandLine::add_to_history() ********/
|
||||
|
||||
void GLUI_CommandLine::add_to_history( const char *cmd )
|
||||
{
|
||||
if (cmd[0]=='\0') return; // don't add if it's empty
|
||||
|
||||
curr_hist = newest_hist;
|
||||
get_history_str(newest_hist) = text;
|
||||
|
||||
newest_hist = ++curr_hist;
|
||||
if ( newest_hist >= HIST_SIZE )
|
||||
{
|
||||
// bump oldest off the list
|
||||
hist_list.erase(hist_list.begin());
|
||||
hist_list.push_back("");
|
||||
|
||||
oldest_hist++;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************** GLUI_CommandLine::reset_history() ********/
|
||||
|
||||
void GLUI_CommandLine::reset_history( void )
|
||||
{
|
||||
oldest_hist = newest_hist = curr_hist = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************** GLUI_CommandLine::dump() **************/
|
||||
|
||||
void GLUI_CommandLine::dump( FILE *out, const char *name )
|
||||
{
|
||||
fprintf( out,
|
||||
"%s (commandline@%p): ins_pt:%d subs:%d/%d sel:%d/%d len:%d\n",
|
||||
name, this,
|
||||
insertion_pt, substring_start, substring_end, sel_start, sel_end,
|
||||
(int)text.length());
|
||||
}
|
||||
|
||||
|
||||
1203
Extras/glui/glui_control.cpp
Normal file
1203
Extras/glui/glui_control.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1198
Extras/glui/glui_edittext.cpp
Normal file
1198
Extras/glui/glui_edittext.cpp
Normal file
File diff suppressed because it is too large
Load Diff
165
Extras/glui/glui_filebrowser.cpp
Normal file
165
Extras/glui/glui_filebrowser.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_filebrowser.cpp - GLUI_FileBrowser control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
This program is freely distributable without licensing fees and is
|
||||
provided without guarantee or warrantee expressed or implied. This
|
||||
program is -not- in the public domain.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "GL/glui.h"
|
||||
#include "glui_internal.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
GLUI_FileBrowser::GLUI_FileBrowser( GLUI_Node *parent,
|
||||
const char *name,
|
||||
int type,
|
||||
int id,
|
||||
GLUI_CB cb)
|
||||
{
|
||||
common_init();
|
||||
|
||||
set_name( name );
|
||||
user_id = id;
|
||||
int_val = type;
|
||||
callback = cb;
|
||||
|
||||
parent->add_control( this );
|
||||
list = new GLUI_List(this, true, 1);
|
||||
list->set_object_callback( GLUI_FileBrowser::dir_list_callback, this );
|
||||
list->set_click_type(GLUI_DOUBLE_CLICK);
|
||||
this->fbreaddir(this->current_dir.c_str());
|
||||
}
|
||||
|
||||
/****************************** GLUI_FileBrowser::draw() **********/
|
||||
|
||||
void GLUI_FileBrowser::dir_list_callback(GLUI_Control *glui_object) {
|
||||
GLUI_List *list = dynamic_cast<GLUI_List*>(glui_object);
|
||||
if (!list)
|
||||
return;
|
||||
GLUI_FileBrowser* me = dynamic_cast<GLUI_FileBrowser*>(list->associated_object);
|
||||
if (!me)
|
||||
return;
|
||||
int this_item;
|
||||
const char *selected;
|
||||
this_item = list->get_current_item();
|
||||
if (this_item > 0) { /* file or directory selected */
|
||||
selected = list->get_item_ptr( this_item )->text.c_str();
|
||||
if (selected[0] == '/' || selected[0] == '\\') {
|
||||
if (me->allow_change_dir) {
|
||||
#ifdef __GNUC__
|
||||
chdir(selected+1);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
SetCurrentDirectory(selected+1);
|
||||
#endif
|
||||
me->fbreaddir(".");
|
||||
}
|
||||
} else {
|
||||
me->file = selected;
|
||||
me->execute_callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GLUI_FileBrowser::fbreaddir(const char *d) {
|
||||
GLUI_String item;
|
||||
int i = 0;
|
||||
|
||||
if (!d)
|
||||
return;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
WIN32_FIND_DATA FN;
|
||||
HANDLE hFind;
|
||||
//char search_arg[MAX_PATH], new_file_path[MAX_PATH];
|
||||
//sprintf(search_arg, "%s\\*.*", path_name);
|
||||
|
||||
hFind = FindFirstFile("*.*", &FN);
|
||||
if (list) {
|
||||
list->delete_all();
|
||||
if (hFind != INVALID_HANDLE_VALUE) {
|
||||
do {
|
||||
int len = strlen(FN.cFileName);
|
||||
if (FN.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
item = '\\';
|
||||
item += FN.cFileName;
|
||||
} else {
|
||||
item = FN.cFileName;
|
||||
}
|
||||
list->add_item(i,item.c_str());
|
||||
i++;
|
||||
} while (FindNextFile(hFind, &FN) != 0);
|
||||
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
FindClose(&FN);
|
||||
else
|
||||
perror("fbreaddir");
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
DIR *dir;
|
||||
struct dirent *dirp;
|
||||
struct stat dr;
|
||||
|
||||
if (list) {
|
||||
list->delete_all();
|
||||
if ((dir = opendir(d)) == NULL)
|
||||
perror("fbreaddir:");
|
||||
else {
|
||||
while ((dirp = readdir(dir)) != NULL) /* open directory */
|
||||
{
|
||||
if (!lstat(dirp->d_name,&dr) && S_ISDIR(dr.st_mode)) /* dir is directory */
|
||||
item = dirp->d_name + GLUI_String("/");
|
||||
else
|
||||
item = dirp->d_name;
|
||||
|
||||
list->add_item(i,item.c_str());
|
||||
i++;
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProcessFiles(const char *path_name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GLUI_FileBrowser::set_w(int w)
|
||||
{
|
||||
if (list) list->set_w(w);
|
||||
}
|
||||
|
||||
void GLUI_FileBrowser::set_h(int h)
|
||||
{
|
||||
if (list) list->set_h(h);
|
||||
}
|
||||
105
Extras/glui/glui_internal.h
Normal file
105
Extras/glui/glui_internal.h
Normal file
@@ -0,0 +1,105 @@
|
||||
#ifndef GLUI_INTERNAL_H
|
||||
#define GLUI_INTERNAL_H
|
||||
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
|
||||
#ifndef AND
|
||||
#define AND &&
|
||||
#define OR ||
|
||||
#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
|
||||
|
||||
/******************** bit comparisons and operations ***************/
|
||||
#ifndef TEST_BIT
|
||||
#define TEST_BIT( x, b ) (((x) & (1<<(b))) != 0 )
|
||||
#define SET_BIT( x, b ) ((x) |= (1 << (b)))
|
||||
#define CLEAR_BIT( x, b ) ((x) &= ~(1 << (b)))
|
||||
#define TOGGLE_BIT( x, b ) ((TEST_BIT(x,b)) ?(CLEAR_BIT(x,b)):(SET_BIT(x,b)))
|
||||
#endif
|
||||
|
||||
#ifndef TEST_AND
|
||||
#define TEST_AND( a, b ) ((a&b)==b)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592654
|
||||
#endif
|
||||
|
||||
/*********** flush the stdout and stderr output streams *************/
|
||||
#ifndef flushout
|
||||
#define flushout fflush(stdout)
|
||||
#define flusherr fflush(stderr)
|
||||
#endif
|
||||
|
||||
/********** Debugging functions *************************************/
|
||||
#ifndef error_return
|
||||
#define error_return( c ); {fprintf(stderr,c);return;}
|
||||
#endif
|
||||
|
||||
/************************* floating-point random ********************/
|
||||
#ifndef randf
|
||||
#define randf() ((float) rand() / (float)RAND_MAX )
|
||||
#endif
|
||||
|
||||
#ifndef SIGN
|
||||
#define SIGN(x) ((x)>=0 ? 1 : -1)
|
||||
#endif
|
||||
|
||||
/****************** conversion between degrees and radians **********/
|
||||
#ifndef DEG2RAD
|
||||
#define DEG2RAD(x) ((x)/180.0*M_PI)
|
||||
#define RAD2DEG(x) ((x)/M_PI*180.0)
|
||||
#endif
|
||||
|
||||
/***************** clamp a value to some fixed interval *************/
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,lo,hi) {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)) {(x)=(hi);}}
|
||||
#endif
|
||||
|
||||
/************ check if a value lies within a closed interval *********/
|
||||
#ifndef IN_BOUNDS
|
||||
#define IN_BOUNDS( x, lo, hi ) ( (x) >= (lo) AND (x) <= (hi) )
|
||||
#endif
|
||||
|
||||
/************ check if a 2D point lies within a 2D box ***************/
|
||||
#ifndef PT_IN_BOX
|
||||
#define PT_IN_BOX( x, y, lo_x, hi_x, lo_y, hi_y ) \
|
||||
( IN_BOUNDS(x,lo_x,hi_x) AND IN_BOUNDS(y,lo_y,hi_y) )
|
||||
#endif
|
||||
|
||||
/****** check if value lies on proper side of another value *****/
|
||||
/*** if side is positive => proper side is positive, else negative **/
|
||||
#ifndef CHECK_PROPER_SIDE
|
||||
#define CHECK_PROPER_SIDE(x,val,side) ((side) > 0 ? (x) > (val) : (x) < (val))
|
||||
#endif
|
||||
|
||||
|
||||
/***** Small value when we want to do a comparison to 'close to zero' *****/
|
||||
#ifndef FUDGE
|
||||
#define FUDGE .00001
|
||||
#endif
|
||||
|
||||
|
||||
/******************* swap two values, using a temp variable *********/
|
||||
#ifndef SWAP2
|
||||
#define SWAP2(a,b,t) {t=a;a=b;b=t;}
|
||||
#endif
|
||||
|
||||
#define VEC3_TO_ARRAY(v,a) a[0]=v[0], a[1]=v[1], a[2]=v[2]
|
||||
|
||||
/**** Return the ASCII control code given the non-control ASCII character */
|
||||
#define CTRL(c) ( (c>=('a'-1)) ? (c-'a'+1) : (c-'A'+1) )
|
||||
|
||||
|
||||
#endif /* GLUI_INTERNAL_H */
|
||||
45
Extras/glui/glui_internal_control.h
Normal file
45
Extras/glui/glui_internal_control.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Header file for use by GLUI controls.
|
||||
Everything you need is right here.
|
||||
|
||||
|
||||
*/
|
||||
#ifndef __GLUI_INTERNAL_CONTROL_H
|
||||
#define __GLUI_INTERNAL_CONTROL_H
|
||||
|
||||
/* This is the main GLUI external header */
|
||||
#include "GL/glui.h"
|
||||
|
||||
/* Here's some utility routines */
|
||||
#include "glui_internal.h"
|
||||
|
||||
|
||||
/**
|
||||
A GLUI_Control-drawing sentinal object.
|
||||
On creation, saves the current draw buffer and window.
|
||||
On destruction, restores draw buffer and window.
|
||||
This is way nicer than calling save/restore manually.
|
||||
*/
|
||||
class GLUI_DrawingSentinal {
|
||||
int orig_buf, orig_win;
|
||||
GLUI_Control *c;
|
||||
public:
|
||||
/** The constructor sets up the drawing system */
|
||||
GLUI_DrawingSentinal(GLUI_Control *c_);
|
||||
/** The destructor cleans up drawing back how it was */
|
||||
~GLUI_DrawingSentinal();
|
||||
|
||||
// Do-nothing routine to avoid compiler warning about unused variable
|
||||
inline void avoid_warning(void) {}
|
||||
};
|
||||
/** Just drop a GLUI_DRAWINGSENTINAL_IDIOM at the start of your draw methods,
|
||||
and they'll return if we can't be drawn, and
|
||||
automatically save and restore all needed state.
|
||||
*/
|
||||
#define GLUI_DRAWINGSENTINAL_IDIOM if (NOT can_draw()) return; GLUI_DrawingSentinal drawSentinal(this); drawSentinal.avoid_warning();
|
||||
|
||||
|
||||
/** Return the time, in seconds. */
|
||||
inline double GLUI_Time(void) {return 0.001*glutGet(GLUT_ELAPSED_TIME);}
|
||||
|
||||
#endif
|
||||
540
Extras/glui/glui_list.cpp
Normal file
540
Extras/glui/glui_list.cpp
Normal file
@@ -0,0 +1,540 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_list.cpp - GLUI_List control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 John Kew
|
||||
|
||||
This program is freely distributable without licensing fees and is
|
||||
provided without guarantee or warrantee expressed or implied. This
|
||||
program is -not- in the public domain.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
#include <cmath>
|
||||
#include <sys/timeb.h>
|
||||
|
||||
/****************************** GLUI_List::GLUI_List() **********/
|
||||
|
||||
GLUI_List::GLUI_List( GLUI_Node *parent, bool scroll,
|
||||
int id, GLUI_CB callback
|
||||
/*,GLUI_Control *object
|
||||
GLUI_InterObject_CB obj_cb*/)
|
||||
{
|
||||
common_construct(parent, NULL, scroll, id, callback/*, object, obj_cb*/);
|
||||
}
|
||||
|
||||
/****************************** GLUI_List::GLUI_List() **********/
|
||||
|
||||
GLUI_List::GLUI_List( GLUI_Node *parent,
|
||||
GLUI_String& live_var, bool scroll,
|
||||
int id,
|
||||
GLUI_CB callback
|
||||
/* ,GLUI_Control *object
|
||||
,GLUI_InterObject_CB obj_cb*/ )
|
||||
{
|
||||
common_construct(parent, &live_var, scroll, id, callback/*, object, obj_cb*/);
|
||||
}
|
||||
|
||||
/****************************** GLUI_List::common_construct() **********/
|
||||
|
||||
void GLUI_List::common_construct(
|
||||
GLUI_Node *parent,
|
||||
GLUI_String* data, bool scroll,
|
||||
int id,
|
||||
GLUI_CB callback
|
||||
/*,GLUI_Control *object
|
||||
, GLUI_InterObject_CB obj_cb*/)
|
||||
{
|
||||
common_init();
|
||||
GLUI_Node *list_panel = parent;
|
||||
|
||||
if (scroll) {
|
||||
GLUI_Panel *p = new GLUI_Panel(parent,"",GLUI_PANEL_NONE);
|
||||
p->x_off = 1;
|
||||
list_panel = p;
|
||||
}
|
||||
this->ptr_val = data;
|
||||
if (data) {
|
||||
this->live_type = GLUI_LIVE_STRING;
|
||||
}
|
||||
this->user_id = id;
|
||||
this->callback = callback;
|
||||
this->name = "list";
|
||||
list_panel->add_control( this );
|
||||
if (scroll)
|
||||
{
|
||||
new GLUI_Column(list_panel, false);
|
||||
scrollbar =
|
||||
new GLUI_Scrollbar(list_panel,
|
||||
"scrollbar",
|
||||
GLUI_SCROLL_VERTICAL,
|
||||
GLUI_SCROLL_INT);
|
||||
scrollbar->set_object_callback(GLUI_List::scrollbar_callback, this);
|
||||
scrollbar->set_alignment(GLUI_ALIGN_LEFT);
|
||||
// scrollbar->can_activate = false; //kills ability to mouse drag too
|
||||
}
|
||||
init_live();
|
||||
}
|
||||
|
||||
/****************************** GLUI_List::mouse_down_handler() **********/
|
||||
int GLUI_List::mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
int tmp_line;
|
||||
unsigned long int ms;
|
||||
timeb time;
|
||||
ftime(&time);
|
||||
ms = time.millitm + (time.time)*1000;
|
||||
|
||||
tmp_line = find_line( local_x-x_abs, local_y-y_abs-5 );
|
||||
if ( tmp_line == -1 ) {
|
||||
if ( glui )
|
||||
glui->deactivate_current_control( );
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tmp_line < num_lines) {
|
||||
curr_line = tmp_line;
|
||||
if (scrollbar)
|
||||
scrollbar->set_int_val(curr_line);
|
||||
this->execute_callback();
|
||||
if (associated_object != NULL)
|
||||
if (cb_click_type == GLUI_SINGLE_CLICK) {
|
||||
if (obj_cb) {
|
||||
// obj_cb(associated_object, user_id);
|
||||
obj_cb(this);
|
||||
}
|
||||
} else {
|
||||
if (last_line == curr_line && (ms - last_click_time) < 300) {
|
||||
//obj_cb(associated_object, user_id);
|
||||
obj_cb(this);
|
||||
} else {
|
||||
last_click_time = ms;
|
||||
last_line = curr_line;
|
||||
}
|
||||
}
|
||||
if ( can_draw())
|
||||
update_and_draw_text();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************** GLUI_List::mouse_up_handler() **********/
|
||||
|
||||
int GLUI_List::mouse_up_handler( int local_x, int local_y, bool inside )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/***************************** GLUI_List::mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_List::mouse_held_down_handler( int local_x, int local_y,
|
||||
bool new_inside)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_List::key_handler() **********/
|
||||
|
||||
int GLUI_List::key_handler( unsigned char key,int modifiers )
|
||||
{
|
||||
|
||||
|
||||
draw_text_only = false; /** Well, hack is not yet working **/
|
||||
update_and_draw_text();
|
||||
draw_text_only = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_List::activate() **********/
|
||||
|
||||
void GLUI_List::activate( int how )
|
||||
{
|
||||
// if ( debug )
|
||||
// dump( stdout, "-> ACTIVATE" );
|
||||
active = true;
|
||||
|
||||
if ( how == GLUI_ACTIVATE_MOUSE )
|
||||
return; /* Don't select everything if activated with mouse */
|
||||
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_List::deactivate() **********/
|
||||
|
||||
void GLUI_List::deactivate( void )
|
||||
{
|
||||
active = false;
|
||||
redraw();
|
||||
}
|
||||
|
||||
/****************************** GLUI_List::draw() **********/
|
||||
|
||||
void GLUI_List::draw( int x, int y )
|
||||
{
|
||||
int line = 0;
|
||||
int box_width;
|
||||
GLUI_List_Item *item;
|
||||
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
/* Bevelled Border */
|
||||
glBegin( GL_LINES );
|
||||
glColor3f( .5, .5, .5 );
|
||||
glVertex2i( 0, 0 ); glVertex2i( w, 0 );
|
||||
glVertex2i( 0, 0 ); glVertex2i( 0, h );
|
||||
|
||||
glColor3f( 1., 1., 1. );
|
||||
glVertex2i( 0, h ); glVertex2i( w, h );
|
||||
glVertex2i( w, h ); glVertex2i( w, 0 );
|
||||
|
||||
if ( enabled )
|
||||
glColor3f( 0., 0., 0. );
|
||||
else
|
||||
glColor3f( .25, .25, .25 );
|
||||
glVertex2i( 1, 1 ); glVertex2i( w-1, 1 );
|
||||
glVertex2i( 1, 1 ); glVertex2i( 1, h-1 );
|
||||
|
||||
glColor3f( .75, .75, .75 );
|
||||
glVertex2i( 1, h-1 ); glVertex2i( w-1, h-1 );
|
||||
glVertex2i( w-1, h-1 ); glVertex2i( w-1, 1 );
|
||||
glEnd();
|
||||
|
||||
/* Draw Background if enabled*/
|
||||
if (enabled) {
|
||||
glColor3f( 1., 1., 1. );
|
||||
glDisable( GL_CULL_FACE );
|
||||
glBegin( GL_QUADS );
|
||||
glVertex2i( 2, 2 ); glVertex2i( w-2, 2 );
|
||||
glVertex2i( w-2, h-2 ); glVertex2i(2, h-2 );
|
||||
glEnd();
|
||||
} else {
|
||||
glColor3f( .8, .8, .8 );
|
||||
glDisable( GL_CULL_FACE );
|
||||
glBegin( GL_QUADS );
|
||||
glVertex2i( 2, 2 ); glVertex2i( w-2, 2 );
|
||||
glVertex2i( w-2, h-2 ); glVertex2i(2, h-2 );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/* Figure out how wide the box is */
|
||||
box_width = get_box_width();
|
||||
|
||||
/* Figure out which lines are visible*/
|
||||
|
||||
visible_lines = (int)(h-20)/15;
|
||||
|
||||
item = (GLUI_List_Item *) items_list.first_child();
|
||||
|
||||
line = 0;
|
||||
while (item) {
|
||||
if (line < start_line) {
|
||||
line++;
|
||||
item = (GLUI_List_Item *) item->next();
|
||||
continue;
|
||||
}
|
||||
if (line >= start_line && line <= (start_line+visible_lines)) {
|
||||
if (curr_line == line)
|
||||
draw_text(item->text.c_str(),1,0,(line - start_line)*15);
|
||||
else
|
||||
draw_text(item->text.c_str(),0,0,(line - start_line)*15);
|
||||
}
|
||||
line++;
|
||||
item = (GLUI_List_Item *) item->next();
|
||||
}
|
||||
|
||||
if (scrollbar) {
|
||||
scrollbar->set_int_limits(MAX(0,num_lines-visible_lines), 0);
|
||||
glPushMatrix();
|
||||
glTranslatef(scrollbar->x_abs-x_abs, scrollbar->y_abs-y_abs,0.0);
|
||||
scrollbar->draw_scroll();
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
/********************************* GLUI_List::draw_text() ****************/
|
||||
|
||||
void GLUI_List::draw_text(const char *t, int selected, int x, int y )
|
||||
{
|
||||
int text_x, i, x_pos;
|
||||
int box_width;
|
||||
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
/** Find where to draw the text **/
|
||||
|
||||
text_x = 2 + GLUI_LIST_BOXINNERMARGINX;
|
||||
|
||||
/** Draw selection area dark **/
|
||||
if ( enabled && selected ) {
|
||||
glColor3f( 0.0f, 0.0f, .6f );
|
||||
glBegin( GL_QUADS );
|
||||
glVertex2i(text_x, y+5 ); glVertex2i( w-text_x, y+5 );
|
||||
glVertex2i(w-text_x, y+19 ); glVertex2i(text_x, y+19 );
|
||||
glEnd();
|
||||
}
|
||||
box_width = get_box_width();
|
||||
|
||||
if ( !selected || !enabled ) { /* No current selection */
|
||||
x_pos = text_x; /* or control disabled */
|
||||
if ( enabled )
|
||||
glColor3b( 0, 0, 0 );
|
||||
else
|
||||
glColor3b( 32, 32, 32 );
|
||||
|
||||
glRasterPos2i( text_x, y+15);
|
||||
i = 0;
|
||||
while( t[i] != '\0' && substring_width(t,0,i) < box_width) {
|
||||
glutBitmapCharacter( get_font(), t[i] );
|
||||
x_pos += char_width( t[i] );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else { /* There is a selection */
|
||||
i = 0;
|
||||
x_pos = text_x;
|
||||
glColor3f( 1., 1., 1. );
|
||||
glRasterPos2i( text_x, y+15);
|
||||
while( t[i] != '\0' && substring_width(t,0,i) < box_width) {
|
||||
glutBitmapCharacter( get_font(), t[i] );
|
||||
x_pos += char_width( t[i] );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int GLUI_List::find_line(int x, int y) {
|
||||
return start_line + ((int)(y/15));
|
||||
}
|
||||
|
||||
int GLUI_List::get_box_width() {
|
||||
return MAX( this->w
|
||||
- 6 /* 2 * the two-line box border */
|
||||
- 2 * GLUI_LIST_BOXINNERMARGINX, 0 );
|
||||
|
||||
}
|
||||
|
||||
/******************************** GLUI_List::substring_width() *********/
|
||||
int GLUI_List::substring_width( const char *t, int start, int end )
|
||||
{
|
||||
int i, width;
|
||||
|
||||
width = 0;
|
||||
|
||||
for( i=start; i<=end; i++ )
|
||||
width += char_width( t[i] );
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
/***************************** GLUI_List::update_and_draw_text() ********/
|
||||
|
||||
void GLUI_List::update_and_draw_text( void )
|
||||
{
|
||||
if ( NOT can_draw() )
|
||||
return;
|
||||
|
||||
//update_substring_bounds();
|
||||
/* printf( "ss: %d/%d\n", substring_start, substring_end ); */
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
|
||||
/********************************* GLUI_List::special_handler() **********/
|
||||
|
||||
int GLUI_List::special_handler( int key,int modifiers )
|
||||
{
|
||||
if ( NOT glui )
|
||||
return false;
|
||||
|
||||
if ( key == GLUT_KEY_DOWN ) {
|
||||
if (curr_line < num_lines) {
|
||||
curr_line++;
|
||||
if (curr_line > start_line+visible_lines)
|
||||
start_line++;
|
||||
}
|
||||
} else if ( key == GLUT_KEY_UP ) {
|
||||
if (curr_line > 0) {
|
||||
curr_line--;
|
||||
if (curr_line < start_line)
|
||||
start_line--;
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollbar)
|
||||
scrollbar->set_int_val(curr_line);
|
||||
redraw();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_List::update_size() **********/
|
||||
|
||||
void GLUI_List::update_size( void )
|
||||
{
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
if ( w < GLUI_LIST_MIN_TEXT_WIDTH )
|
||||
w = GLUI_LIST_MIN_TEXT_WIDTH;
|
||||
}
|
||||
|
||||
/**************************************** GLUI_Listbox::add_item() **********/
|
||||
|
||||
int GLUI_List::add_item( int id, const char *new_text )
|
||||
{
|
||||
GLUI_List_Item *new_node = new GLUI_List_Item;
|
||||
GLUI_List_Item *head;
|
||||
|
||||
new_node->text = new_text;
|
||||
new_node->id = id;
|
||||
|
||||
head = (GLUI_List_Item*) items_list.first_child();
|
||||
new_node->link_this_to_parent_last( &items_list );
|
||||
|
||||
if ( head == NULL ) {
|
||||
/*** This is first item added ***/
|
||||
|
||||
int_val = id+1; /** Different than id **/
|
||||
// do_selection( id );
|
||||
last_live_int = id;
|
||||
|
||||
if( glui )
|
||||
glui->post_update_main_gfx();
|
||||
}
|
||||
num_lines++;
|
||||
if (scrollbar)
|
||||
scrollbar->set_int_limits(MAX(num_lines-visible_lines,0), 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/************************************** GLUI_Listbox::delete_() **********/
|
||||
|
||||
int GLUI_List::delete_all()
|
||||
{
|
||||
GLUI_List_Item *item;
|
||||
|
||||
item = (GLUI_List_Item *) items_list.first_child();
|
||||
while( item ) {
|
||||
item->unlink();
|
||||
delete item;
|
||||
item = (GLUI_List_Item *) items_list.first_child();
|
||||
}
|
||||
|
||||
num_lines = 0;
|
||||
curr_line = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/************************************** GLUI_Listbox::delete_item() **********/
|
||||
|
||||
int GLUI_List::delete_item( const char *text )
|
||||
{
|
||||
GLUI_List_Item *node = get_item_ptr( text );
|
||||
|
||||
if ( node ) {
|
||||
node->unlink();
|
||||
delete node;
|
||||
num_lines--;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************** GLUI_Listbox::delete_item() **********/
|
||||
|
||||
int GLUI_List::delete_item( int id )
|
||||
{
|
||||
GLUI_List_Item *node = get_item_ptr( id );
|
||||
|
||||
if ( node ) {
|
||||
node->unlink();
|
||||
delete node;
|
||||
num_lines--;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Listbox::get_item_ptr() **********/
|
||||
|
||||
GLUI_List_Item *GLUI_List::get_item_ptr( const char *text )
|
||||
{
|
||||
GLUI_List_Item *item;
|
||||
|
||||
item = (GLUI_List_Item *) items_list.first_child();
|
||||
while( item ) {
|
||||
if ( item->text == text )
|
||||
return item;
|
||||
|
||||
item = (GLUI_List_Item *) item->next();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Listbox::get_item_ptr() **********/
|
||||
|
||||
GLUI_List_Item *GLUI_List::get_item_ptr( int id )
|
||||
{
|
||||
GLUI_List_Item *item;
|
||||
|
||||
item = (GLUI_List_Item *) items_list.first_child();
|
||||
while( item ) {
|
||||
if ( item->id == id )
|
||||
return item;
|
||||
|
||||
item = (GLUI_List_Item *) item->next();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**************************************** GLUI_List::mouse_over() ********/
|
||||
|
||||
int GLUI_List::mouse_over( int state, int x, int y )
|
||||
{
|
||||
glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLUI_List::scrollbar_callback(GLUI_Control *my_scrollbar) {
|
||||
GLUI_Scrollbar *sb = dynamic_cast<GLUI_Scrollbar*>(my_scrollbar);
|
||||
if (!sb) return;
|
||||
GLUI_List* me = (GLUI_List*) sb->associated_object;
|
||||
if (me->scrollbar == NULL)
|
||||
return;
|
||||
int new_start_line = sb->get_int_val(); // TODO!!
|
||||
me->start_line = new_start_line;
|
||||
|
||||
if ( me->can_draw() )
|
||||
me->update_and_draw_text();
|
||||
}
|
||||
448
Extras/glui/glui_listbox.cpp
Normal file
448
Extras/glui/glui_listbox.cpp
Normal file
@@ -0,0 +1,448 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_listbox - GLUI_ListBox control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
/****************************** GLUI_Listbox::GLUI_Listbox() **********/
|
||||
GLUI_Listbox::GLUI_Listbox( GLUI_Node *parent,
|
||||
const char *name, int *value_ptr,
|
||||
int id,
|
||||
GLUI_CB cb)
|
||||
{
|
||||
common_init();
|
||||
set_ptr_val( value_ptr );
|
||||
user_id = id;
|
||||
set_name( name );
|
||||
callback = cb;
|
||||
|
||||
parent->add_control( this );
|
||||
|
||||
init_live();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Listbox::mouse_down_handler() **********/
|
||||
|
||||
int GLUI_Listbox::mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Listbox::mouse_up_handler() **********/
|
||||
|
||||
int GLUI_Listbox::mouse_up_handler( int local_x, int local_y, bool inside )
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Listbox::mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_Listbox::mouse_held_down_handler( int local_x, int local_y,
|
||||
bool inside)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Listbox::key_handler() **********/
|
||||
|
||||
int GLUI_Listbox::key_handler( unsigned char key,int modifiers )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Listbox::draw() **********/
|
||||
|
||||
void GLUI_Listbox::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
int name_x;
|
||||
|
||||
/* draw_active_area(); */
|
||||
|
||||
name_x = 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 );
|
||||
|
||||
if ( NOT active ) {
|
||||
draw_box( text_x_offset+3, w-2, 2, h-2, 1.0, 1.0, 1.0 );
|
||||
if ( NOT enabled )
|
||||
glColor3b( 32, 32, 32 );
|
||||
else
|
||||
glColor3f( 0.0, 0.0, 0.0 );
|
||||
glRasterPos2i( text_x_offset+5, 13 );
|
||||
draw_string( curr_text );
|
||||
}
|
||||
else {
|
||||
draw_box( text_x_offset+3, w-2, 2, h-2, .0, .0, .6 );
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glRasterPos2i( text_x_offset+5, 13 );
|
||||
draw_string( curr_text );
|
||||
}
|
||||
|
||||
|
||||
if ( enabled ) {
|
||||
glui->std_bitmaps.
|
||||
draw(GLUI_STDBITMAP_LISTBOX_UP,
|
||||
w-glui->std_bitmaps.width(GLUI_STDBITMAP_LISTBOX_UP)-1,
|
||||
2 );
|
||||
}
|
||||
else {
|
||||
glui->std_bitmaps.
|
||||
draw(GLUI_STDBITMAP_LISTBOX_UP_DIS,
|
||||
w-glui->std_bitmaps.width(GLUI_STDBITMAP_LISTBOX_UP)-1,
|
||||
2 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Listbox::update_si() **********/
|
||||
void GLUI_Listbox::update_size( void )
|
||||
{
|
||||
recalculate_item_width();
|
||||
}
|
||||
|
||||
/********************************* GLUI_Listbox::set_int_val() **************/
|
||||
|
||||
void GLUI_Listbox::set_int_val( int new_val )
|
||||
{
|
||||
/* int_val = new_val; */
|
||||
|
||||
do_selection( new_val );
|
||||
|
||||
/*** Update the variable we're (possibly) pointing to, and update the main gfx ***/
|
||||
output_live(true);
|
||||
}
|
||||
|
||||
/**************************************** GLUI_Listbox::add_item() **********/
|
||||
|
||||
int GLUI_Listbox::add_item( int id, const char *new_text )
|
||||
{
|
||||
GLUI_Listbox_Item *new_node = new GLUI_Listbox_Item;
|
||||
GLUI_Listbox_Item *head;
|
||||
|
||||
new_node->text = new_text;
|
||||
new_node->id = id;
|
||||
|
||||
head = (GLUI_Listbox_Item*) items_list.first_child();
|
||||
new_node->link_this_to_parent_last( &items_list );
|
||||
|
||||
if ( head == NULL ) {
|
||||
/*** This is first item added ***/
|
||||
|
||||
int_val = id+1; /** Different than id **/
|
||||
do_selection( id );
|
||||
last_live_int = id;
|
||||
|
||||
if( glui )
|
||||
glui->post_update_main_gfx();
|
||||
}
|
||||
if (recalculate_item_width()) glui->refresh();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/************************************** GLUI_Listbox::delete_item() **********/
|
||||
|
||||
int GLUI_Listbox::delete_item( const char *text )
|
||||
{
|
||||
GLUI_Listbox_Item *node = get_item_ptr(text);
|
||||
|
||||
if (node)
|
||||
{
|
||||
node->unlink();
|
||||
delete node;
|
||||
return true;
|
||||
}
|
||||
if (recalculate_item_width()) glui->refresh();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/************************************** GLUI_Listbox::delete_item() **********/
|
||||
|
||||
int GLUI_Listbox::delete_item(int id)
|
||||
{
|
||||
GLUI_Listbox_Item *node = get_item_ptr(id);
|
||||
|
||||
if (node)
|
||||
{
|
||||
node->unlink();
|
||||
delete node;
|
||||
return true;
|
||||
}
|
||||
if (recalculate_item_width()) glui->refresh();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/************************************** GLUI_Listbox::sort_items() **********/
|
||||
|
||||
int GLUI_Listbox::sort_items( void )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/********************************************* GLUI_Listbox::dump() **********/
|
||||
|
||||
void GLUI_Listbox::dump( FILE *output )
|
||||
{
|
||||
GLUI_Listbox_Item *item;
|
||||
|
||||
/* printf( "%p\n", (char*) name ); */
|
||||
|
||||
fprintf( output, "Listbox: %s\n", name.c_str() );
|
||||
|
||||
item = (GLUI_Listbox_Item *) items_list.first_child();
|
||||
while( item ) {
|
||||
fprintf( output, " %3d : %s\n", item->id, item->text.c_str() );
|
||||
|
||||
item = (GLUI_Listbox_Item *) item->next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Listbox::get_item_ptr() **********/
|
||||
|
||||
GLUI_Listbox_Item *GLUI_Listbox::get_item_ptr( const char *text )
|
||||
{
|
||||
GLUI_Listbox_Item *item;
|
||||
|
||||
item = (GLUI_Listbox_Item *) items_list.first_child();
|
||||
while( item ) {
|
||||
if ( item->text == text )
|
||||
return item;
|
||||
|
||||
item = (GLUI_Listbox_Item *) item->next();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Listbox::get_item_ptr() **********/
|
||||
|
||||
GLUI_Listbox_Item *GLUI_Listbox::get_item_ptr( int id )
|
||||
{
|
||||
GLUI_Listbox_Item *item;
|
||||
|
||||
item = (GLUI_Listbox_Item *) items_list.first_child();
|
||||
while( item ) {
|
||||
if ( item->id == id )
|
||||
return item;
|
||||
|
||||
item = (GLUI_Listbox_Item *) item->next();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Listbox::mouse_over() **********/
|
||||
|
||||
static void listbox_callback( int i )
|
||||
{
|
||||
int old_val;
|
||||
|
||||
if ( NOT GLUI_Master.curr_left_button_glut_menu OR
|
||||
!dynamic_cast<GLUI_Listbox*>(GLUI_Master.curr_left_button_glut_menu) )
|
||||
return;
|
||||
|
||||
old_val = ((GLUI_Listbox*)GLUI_Master.curr_left_button_glut_menu)->int_val;
|
||||
((GLUI_Listbox*)GLUI_Master.curr_left_button_glut_menu)->set_int_val(i);
|
||||
|
||||
/**** If value changed, execute callback ****/
|
||||
if ( old_val !=
|
||||
((GLUI_Listbox*)GLUI_Master.curr_left_button_glut_menu)->int_val ) {
|
||||
((GLUI_Listbox*)GLUI_Master.curr_left_button_glut_menu)->execute_callback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*************************************** GLUI_Listbox::mouse_over() **********/
|
||||
|
||||
int GLUI_Listbox::mouse_over( int state, int x, int y )
|
||||
{
|
||||
GLUI_Listbox_Item *item;
|
||||
|
||||
/* printf( "x/y: %d/%d\n", x, y ); */
|
||||
|
||||
if ( state AND enabled AND x > x_abs + text_x_offset) {
|
||||
/**** Build a GLUT menu for this listbox ***/
|
||||
|
||||
/* printf( "%d %d\n", x, y ); */
|
||||
|
||||
glut_menu_id = glutCreateMenu(listbox_callback);
|
||||
|
||||
item = (GLUI_Listbox_Item *) items_list.first_child();
|
||||
while( item ) {
|
||||
glutAddMenuEntry( item->text.c_str(), item->id );
|
||||
item = (GLUI_Listbox_Item *) item->next();
|
||||
}
|
||||
|
||||
glutAttachMenu( GLUT_LEFT_BUTTON);
|
||||
|
||||
GLUI_Master.set_left_button_glut_menu_control( this );
|
||||
}
|
||||
else if ( glut_menu_id != -1 ) {
|
||||
/* printf( "OUT\n" ); */
|
||||
glutDetachMenu( GLUT_LEFT_BUTTON );
|
||||
glutDestroyMenu( glut_menu_id );
|
||||
glut_menu_id = -1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Listbox::do_selection() **********/
|
||||
|
||||
int GLUI_Listbox::do_selection( int item_num )
|
||||
{
|
||||
GLUI_Listbox_Item *item, *sel_item;
|
||||
|
||||
/*** Is this item already selected? ***/
|
||||
if ( item_num == int_val )
|
||||
return false;
|
||||
|
||||
sel_item = NULL;
|
||||
item = (GLUI_Listbox_Item *) items_list.first_child();
|
||||
while( item ) {
|
||||
if ( item->id == item_num ) {
|
||||
sel_item = item;
|
||||
break;
|
||||
}
|
||||
|
||||
item = (GLUI_Listbox_Item *) item->next();
|
||||
}
|
||||
|
||||
if ( NOT sel_item )
|
||||
return false;
|
||||
|
||||
/* printf( "-> %s\n", (char*) sel_item->text ); */
|
||||
|
||||
int_val = item_num;
|
||||
curr_text = sel_item->text;
|
||||
redraw();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_Listbox::~GLUI_Listbox() **********/
|
||||
|
||||
GLUI_Listbox::~GLUI_Listbox()
|
||||
{
|
||||
GLUI_Listbox_Item *item = (GLUI_Listbox_Item *) items_list.first_child();
|
||||
|
||||
while (item)
|
||||
{
|
||||
GLUI_Listbox_Item *tmp = item;
|
||||
item = (GLUI_Listbox_Item *) item->next();
|
||||
delete tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************** GLUI_Listbox::special_handler() **********/
|
||||
|
||||
int GLUI_Listbox::special_handler( int key,int modifiers )
|
||||
{
|
||||
GLUI_Listbox_Item *node, *new_node;
|
||||
|
||||
node = get_item_ptr( int_val );
|
||||
new_node = NULL;
|
||||
|
||||
if ( key == GLUT_KEY_DOWN ) {
|
||||
new_node = (GLUI_Listbox_Item*) node->next();
|
||||
}
|
||||
else if ( key == GLUT_KEY_UP ) {
|
||||
new_node = (GLUI_Listbox_Item*) node->prev();
|
||||
}
|
||||
else if ( key == GLUT_KEY_HOME ) {
|
||||
new_node = (GLUI_Listbox_Item*) items_list.first_child();
|
||||
}
|
||||
else if ( key == GLUT_KEY_END ) {
|
||||
new_node = (GLUI_Listbox_Item*) items_list.last_child();
|
||||
}
|
||||
|
||||
if ( new_node != NULL AND new_node != node ) {
|
||||
node = new_node;
|
||||
set_int_val( node->id );
|
||||
execute_callback();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************* GLUI_Listbox::recalculate_item_width( void ) ***********/
|
||||
/** Change w and return true if we need to be widened to fit the current items. */
|
||||
bool GLUI_Listbox::recalculate_item_width( void )
|
||||
{
|
||||
int item_text_size;
|
||||
|
||||
if ( NOT glui )
|
||||
return false;
|
||||
|
||||
/* Find the title size */
|
||||
text_x_offset = string_width( name );
|
||||
|
||||
/* Find the longest item string ***/
|
||||
item_text_size = 0;
|
||||
|
||||
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 = (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;
|
||||
if ( w != new_wid) {
|
||||
w = new_wid;
|
||||
return true; /* we gotta be shortened or widened */
|
||||
}
|
||||
else {
|
||||
return false; /* our current width is OK */
|
||||
}
|
||||
}
|
||||
210
Extras/glui/glui_mouse_iaction.cpp
Normal file
210
Extras/glui/glui_mouse_iaction.cpp
Normal file
@@ -0,0 +1,210 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_mouse_iaction - GLUI Mouse Interaction control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
/********************** GLUI_Mouse_Interaction::mouse_down_handler() ******/
|
||||
|
||||
int GLUI_Mouse_Interaction::mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
/* int win_h = glutGet( GLUT_WINDOW_HEIGHT ); */
|
||||
|
||||
/* iaction_mouse_down_handler( local_x, local_y ); */
|
||||
iaction_mouse_down_handler( local_x-x_abs, local_y-y_abs );
|
||||
/*local_x-x_abs, ((glui->h-local_y)-y_abs) ); */
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**************************** GLUI_Mouse_Interaction::mouse_up_handler() */
|
||||
|
||||
int GLUI_Mouse_Interaction::mouse_up_handler( int local_x, int local_y, bool inside )
|
||||
{
|
||||
iaction_mouse_up_handler( local_x-x_abs, local_y-y_abs, inside );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Mouse_Interaction::mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_Mouse_Interaction::mouse_held_down_handler( int local_x, int local_y,
|
||||
bool inside)
|
||||
{
|
||||
iaction_mouse_held_down_handler( local_x-x_abs, local_y-y_abs , inside );
|
||||
|
||||
redraw();
|
||||
|
||||
/** Tell the main graphics window to update iteself **/
|
||||
if( glui )
|
||||
glui->post_update_main_gfx();
|
||||
|
||||
execute_callback();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************** GLUI_Mouse_Interaction::draw() **********/
|
||||
|
||||
void GLUI_Mouse_Interaction::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
int text_width = string_width( this->name );
|
||||
int x_left = this->w/2 - text_width/2;
|
||||
|
||||
if ( NOT draw_active_area_only ) {
|
||||
draw_name( x_left, h-4 );
|
||||
draw_active_box( x_left-4, x_left+string_width( name )+4,
|
||||
h, h-14 );
|
||||
}
|
||||
|
||||
draw_active_area();
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Mouse_Interaction::update_size() **********/
|
||||
|
||||
void GLUI_Mouse_Interaction::update_size( void )
|
||||
{
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
int text_width = string_width( this->name );
|
||||
|
||||
if ( w < text_width+6 )
|
||||
w = text_width+6;
|
||||
|
||||
if ( h - 18 > w )
|
||||
w = h - 18;
|
||||
|
||||
iaction_init();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Mouse_Interaction::special_handler() **********/
|
||||
|
||||
int GLUI_Mouse_Interaction::special_handler( int key,int modifiers )
|
||||
{
|
||||
int center_x, center_y;
|
||||
int drag_x, drag_y;
|
||||
|
||||
center_x = w/2;
|
||||
center_y = (h-18)/2;
|
||||
drag_x = 0;
|
||||
drag_y = 0;
|
||||
|
||||
if ( key == GLUT_KEY_LEFT )
|
||||
drag_x = -6;
|
||||
else if ( key == GLUT_KEY_RIGHT )
|
||||
drag_x = 6;
|
||||
else if ( key == GLUT_KEY_UP )
|
||||
drag_y = -6;
|
||||
else if ( key == GLUT_KEY_DOWN )
|
||||
drag_y = 6;
|
||||
|
||||
if ( drag_x != 0 OR drag_y != 0 ) {
|
||||
mouse_down_handler( center_x, center_y );
|
||||
mouse_held_down_handler( center_x + drag_x, center_y + drag_y,true );
|
||||
mouse_up_handler( center_x + drag_x, center_y + drag_y, true );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Mouse_Interaction::draw_active_area() **********/
|
||||
|
||||
void GLUI_Mouse_Interaction::draw_active_area( void )
|
||||
{
|
||||
int win_h = glutGet( GLUT_WINDOW_HEIGHT ), win_w = glutGet(GLUT_WINDOW_WIDTH);
|
||||
|
||||
int text_height = 18; /* what a kludge */
|
||||
|
||||
int viewport_size = h-text_height; /*MIN(w,h); */
|
||||
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glTranslatef( (float) win_w/2.0, (float) win_h/2.0, 0.0 );
|
||||
glRotatef( 180.0, 0.0, 1.0, 0.0 );
|
||||
glRotatef( 180.0, 0.0, 0.0, 1.0 );
|
||||
glTranslatef( (float) -win_w/2.0, (float) -win_h/2.0, 0.0 );
|
||||
|
||||
glTranslatef( (float) this->x_abs + .5, (float) this->y_abs + .5, 0.0 );
|
||||
|
||||
glTranslatef( (float)this->w/2.0, (float)viewport_size/2.0 + 2.0 , 0.0 );
|
||||
|
||||
/*** Draw the interaction control's orthographic elements ***/
|
||||
iaction_draw_active_area_ortho();
|
||||
|
||||
/*** Setup and draw the interaction control's perspective elements ***/
|
||||
|
||||
/*** Set the viewport to just the square of the drawing area ***/
|
||||
/* glViewport( this->x_abs , glui->main_panel->h - this->y_abs - this->h,*/
|
||||
/*glViewport( this->x_abs+1+(this->w/2-viewport_size/2),
|
||||
this->h-this->y_abs-viewport_size-1,
|
||||
viewport_size, viewport_size );*/
|
||||
|
||||
viewport_size -= 4;
|
||||
int offset = 0;
|
||||
if ( ((this->w-viewport_size) % 2) == 1 )
|
||||
offset = 1;
|
||||
|
||||
glViewport( this->x_abs + (this->w-viewport_size)/2 + offset,
|
||||
win_h - this->y_abs - this->h + text_height,
|
||||
viewport_size, viewport_size );
|
||||
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
double xy=1.00,zc=50.0; /* X-Y size, and Z origin */
|
||||
glFrustum( -1.0*xy, 1.0*xy, -xy, xy, zc*0.7, zc*1.3 );
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glTranslatef( 0.0, 0.0, -zc );
|
||||
glScalef(xy,xy,1.0); // xy);
|
||||
|
||||
/* glutSolidTeapot( 1.0 ); */
|
||||
iaction_draw_active_area_persp();
|
||||
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPopMatrix();
|
||||
|
||||
glui->set_viewport();
|
||||
glui->set_ortho_projection();
|
||||
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
212
Extras/glui/glui_node.cpp
Normal file
212
Extras/glui/glui_node.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_node.cpp - linked-list tree structure
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "GL/glui.h"
|
||||
#include "glui_internal.h"
|
||||
|
||||
/********************************************* GLUI_Node::GLUI_Node() *******/
|
||||
|
||||
GLUI_Node::GLUI_Node()
|
||||
:
|
||||
parent_node(NULL),
|
||||
child_head(NULL),
|
||||
child_tail(NULL),
|
||||
next_sibling(NULL),
|
||||
prev_sibling(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/********************************************* GLUI_Node::first() *******/
|
||||
/* Returns first sibling in 'this' node's sibling list */
|
||||
|
||||
GLUI_Node *GLUI_Node::first_sibling( void )
|
||||
{
|
||||
if ( parent_node == NULL )
|
||||
return this; /* root node has no siblings */
|
||||
else
|
||||
return parent_node->child_head;
|
||||
}
|
||||
|
||||
|
||||
/******************************************** GLUI_Node::next() ********/
|
||||
/* Returns next sibling in 'this' node's sibling list */
|
||||
|
||||
GLUI_Node *GLUI_Node::next( void )
|
||||
{
|
||||
return next_sibling;
|
||||
}
|
||||
|
||||
|
||||
/******************************************** GLUI_Node::prev() ********/
|
||||
/* Returns prev sibling in 'this' node's sibling list */
|
||||
|
||||
GLUI_Node *GLUI_Node::prev( void )
|
||||
{
|
||||
return prev_sibling;
|
||||
}
|
||||
|
||||
|
||||
/********************************************* GLUI_Node::last() *******/
|
||||
/* Returns last sibling in 'this' node's sibling list */
|
||||
|
||||
GLUI_Node *GLUI_Node::last_sibling( void )
|
||||
{
|
||||
if ( parent_node == NULL )
|
||||
return this; /* root node has no siblings */
|
||||
else
|
||||
return parent_node->child_tail;
|
||||
}
|
||||
|
||||
|
||||
/*************************** GLUI_Node::link_this_to_parent_last() *******/
|
||||
/* Links as last child of parent */
|
||||
|
||||
void GLUI_Node::link_this_to_parent_last( GLUI_Node *new_parent )
|
||||
{
|
||||
if ( new_parent->child_tail == NULL ) { /* parent has no children */
|
||||
new_parent->child_head = this;
|
||||
new_parent->child_tail = this;
|
||||
this->parent_node = new_parent;
|
||||
}
|
||||
else { /* parent has children */
|
||||
new_parent->child_tail->next_sibling = this;
|
||||
this->prev_sibling = new_parent->child_tail;
|
||||
new_parent->child_tail = this;
|
||||
this->parent_node = new_parent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*************************** GLUI_Node::link_this_to_parent_first() *******/
|
||||
/* Links as first child of parent */
|
||||
|
||||
void GLUI_Node::link_this_to_parent_first( GLUI_Node *new_parent )
|
||||
{
|
||||
if ( new_parent->child_head == NULL ) { /* parent has no children */
|
||||
new_parent->child_head = this;
|
||||
new_parent->child_tail = this;
|
||||
this->parent_node = new_parent;
|
||||
}
|
||||
else { /* parent has children */
|
||||
new_parent->child_head->prev_sibling = this;
|
||||
this->next_sibling = new_parent->child_head;
|
||||
new_parent->child_head = this;
|
||||
this->parent_node = new_parent;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************** GLUI_Node::link_this_to_sibling_next() *****/
|
||||
|
||||
void GLUI_Node::link_this_to_sibling_next( GLUI_Node *sibling )
|
||||
{
|
||||
if ( sibling->next_sibling == NULL ) { /* node has no next sibling */
|
||||
sibling->next_sibling = this;
|
||||
this->prev_sibling = sibling;
|
||||
|
||||
/* This was the parent's last child, so update that as well */
|
||||
if ( sibling->parent_node != NULL ) {
|
||||
sibling->parent_node->child_tail = this;
|
||||
}
|
||||
}
|
||||
else { /* node already has a next sibling */
|
||||
sibling->next_sibling->prev_sibling = this;
|
||||
this->next_sibling = sibling->next_sibling;
|
||||
sibling->next_sibling = this;
|
||||
this->prev_sibling = sibling;
|
||||
}
|
||||
|
||||
this->parent_node = sibling->parent_node;
|
||||
}
|
||||
|
||||
|
||||
/**************************** GLUI_Node::link_this_to_sibling_prev() *****/
|
||||
|
||||
void GLUI_Node::link_this_to_sibling_prev( GLUI_Node *sibling )
|
||||
{
|
||||
if ( sibling->prev_sibling == NULL ) { /* node has no prev sibling */
|
||||
sibling->prev_sibling = this;
|
||||
this->next_sibling = sibling;
|
||||
|
||||
/* This was the parent's first child, so update that as well */
|
||||
if ( sibling->parent_node != NULL ) {
|
||||
sibling->parent_node->child_head = this;
|
||||
}
|
||||
}
|
||||
else { /* node already has a prev sibling */
|
||||
sibling->prev_sibling->next_sibling = this;
|
||||
this->prev_sibling = sibling->prev_sibling;
|
||||
sibling->prev_sibling = this;
|
||||
this->next_sibling = sibling;
|
||||
}
|
||||
|
||||
this->parent_node = sibling->parent_node;
|
||||
}
|
||||
|
||||
/**************************************** GLUI_Node::unlink() **************/
|
||||
|
||||
void GLUI_Node::unlink( void )
|
||||
{
|
||||
/* Unlink from prev sibling */
|
||||
if ( this->prev_sibling != NULL ) {
|
||||
this->prev_sibling->next_sibling = this->next_sibling;
|
||||
}
|
||||
else { /* No prev sibling: this was parent's first child */
|
||||
this->parent_node->child_head = this->next_sibling;
|
||||
}
|
||||
|
||||
/* Unlink from next sibling */
|
||||
if ( this->next_sibling != NULL ) {
|
||||
this->next_sibling->prev_sibling = this->prev_sibling;
|
||||
}
|
||||
else { /* No next sibling: this was parent's last child */
|
||||
this->parent_node->child_tail = this->prev_sibling;
|
||||
}
|
||||
|
||||
this->parent_node = NULL;
|
||||
this->next_sibling = NULL;
|
||||
this->prev_sibling = NULL;
|
||||
this->child_head = NULL;
|
||||
this->child_tail = NULL;
|
||||
}
|
||||
|
||||
/**************************************** GLUI_Node::dump() **************/
|
||||
|
||||
void GLUI_Node::dump( FILE *out, const char *name )
|
||||
{
|
||||
fprintf( out, "GLUI_node: %s\n", name );
|
||||
fprintf( out, " parent: %p child_head: %p child_tail: %p\n",
|
||||
(void *) parent_node,
|
||||
(void *) child_head,
|
||||
(void *) child_tail );
|
||||
fprintf( out, " next: %p prev: %p\n",
|
||||
(void *) next_sibling,
|
||||
(void *) prev_sibling );
|
||||
}
|
||||
186
Extras/glui/glui_panel.cpp
Normal file
186
Extras/glui/glui_panel.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_panel.cpp - GLUI_Panel control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
GLUI_Panel::GLUI_Panel( GLUI_Node *parent, const char *name, int type )
|
||||
{
|
||||
common_init();
|
||||
set_name( name );
|
||||
user_id = -1;
|
||||
int_val = type;
|
||||
|
||||
parent->add_control( this );
|
||||
}
|
||||
|
||||
/****************************** GLUI_Panel::draw() **********/
|
||||
|
||||
void GLUI_Panel::draw( int x, int y )
|
||||
{
|
||||
int top;
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
if ( int_val == GLUI_PANEL_RAISED ) {
|
||||
top = 0;
|
||||
glLineWidth( 1.0 );
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( 0, top ); glVertex2i( w, top );
|
||||
glVertex2i( 0, top ); glVertex2i( 0, h );
|
||||
glEnd();
|
||||
|
||||
glColor3f( .5, .5, .5 );
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( w, top );
|
||||
glVertex2i( w, h );
|
||||
glVertex2i( 0, h );
|
||||
glVertex2i( w, h );
|
||||
glEnd();
|
||||
|
||||
/** ORIGINAL RAISED PANEL METHOD - A LITTLE TOO HIGH **
|
||||
glLineWidth(1.0);
|
||||
glBegin( GL_LINES );
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glVertex2i( 1, 1 ); glVertex2i( w-2, 1 );
|
||||
glVertex2i( 1, 1 ); glVertex2i( 1, h-2 );
|
||||
|
||||
glColor3f( .5, .5, .5 );
|
||||
glVertex2i( w-1, 1 ); glVertex2i( w-1, h-1 );
|
||||
glVertex2i( 1, h-1 ); glVertex2i( w-1, h-1 );
|
||||
|
||||
glColor3f( 0.0, 0.0, 0.0 );
|
||||
glVertex2i( 0, h ); glVertex2i( w, h );
|
||||
glVertex2i( w, 0 ); glVertex2i( w, h );
|
||||
glEnd();
|
||||
|
||||
-- Touch up the lines a bit (needed in some opengl implementations
|
||||
glBegin( GL_POINTS );
|
||||
glColor3f( .5, .5, .5 );
|
||||
glVertex2i( w-1, h-1 );
|
||||
glColor3f( 0.0, 0.0, 0.0 );
|
||||
glVertex2i( w, h );
|
||||
glEnd();
|
||||
**/
|
||||
}
|
||||
else if ( int_val == GLUI_PANEL_EMBOSSED ) {
|
||||
if ( parent_node == NULL || name == "" ) {
|
||||
top = 0;
|
||||
}
|
||||
else {
|
||||
top = GLUI_PANEL_EMBOSS_TOP;
|
||||
}
|
||||
|
||||
glLineWidth( 1.0 );
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( 0, top ); glVertex2i( w, top );
|
||||
glVertex2i( w, h ); glVertex2i( 0, h );
|
||||
|
||||
glVertex2i( 1, top+1 ); glVertex2i( w-1, top+1 );
|
||||
glVertex2i( w-1, h-1 ); glVertex2i( 1, h-1 );
|
||||
glEnd();
|
||||
|
||||
glColor3f( .5, .5, .5 );
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( 0, top );
|
||||
glVertex2i( w-1, top );
|
||||
glVertex2i( w-1, h-1 );
|
||||
glVertex2i( 0, h-1 );
|
||||
glEnd();
|
||||
|
||||
/**** Only display text in embossed panel ****/
|
||||
if ( parent_node != NULL && name != "" ) { /* Only draw non-null strings */
|
||||
int left = 7, height=GLUI_PANEL_NAME_DROP+1;
|
||||
int str_width;
|
||||
|
||||
str_width = string_width(name);
|
||||
|
||||
if ( glui )
|
||||
glColor3ub(glui->bkgd_color.r,glui->bkgd_color.g,glui->bkgd_color.b);
|
||||
glDisable( GL_CULL_FACE );
|
||||
glBegin( GL_QUADS );
|
||||
glVertex2i( left-3, 0 ); glVertex2i( left+str_width+3, 0 );
|
||||
glVertex2i( left+str_width+3, height ); glVertex2i( left-3, height );
|
||||
glEnd();
|
||||
|
||||
draw_name( left, GLUI_PANEL_NAME_DROP );
|
||||
}
|
||||
}
|
||||
|
||||
glLineWidth( 1.0 );
|
||||
}
|
||||
|
||||
/****************************** GLUI_Panel::set_name() **********/
|
||||
|
||||
void GLUI_Panel::set_name( const char *new_name )
|
||||
{
|
||||
name = new_name ? new_name : "";
|
||||
|
||||
update_size();
|
||||
|
||||
if ( glui )
|
||||
glui->refresh();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Panel::set_type() **********/
|
||||
|
||||
void GLUI_Panel::set_type( int new_type )
|
||||
{
|
||||
if ( new_type != int_val ) {
|
||||
int_val = new_type;
|
||||
update_size();
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************** GLUI_Panel::update_size() **********/
|
||||
|
||||
void GLUI_Panel::update_size( void )
|
||||
{
|
||||
int text_size;
|
||||
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
text_size = string_width(name);
|
||||
|
||||
if ( w < text_size + 16 )
|
||||
w = text_size + 16 ;
|
||||
|
||||
if ( name != "" AND int_val == GLUI_PANEL_EMBOSSED ) {
|
||||
this->y_off_top = GLUI_YOFF + 8;
|
||||
}
|
||||
else {
|
||||
this->y_off_top = GLUI_YOFF;
|
||||
}
|
||||
}
|
||||
362
Extras/glui/glui_radio.cpp
Normal file
362
Extras/glui/glui_radio.cpp
Normal file
@@ -0,0 +1,362 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_radio.cpp - GLUI_RadioGroup and GLUI_RadioButton control classes
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
#include <cassert>
|
||||
|
||||
/****************************** GLUI_RadioGroup::GLUI_RadioGroup() **********/
|
||||
|
||||
GLUI_RadioGroup::GLUI_RadioGroup(GLUI_Node *parent,
|
||||
int *value_ptr,
|
||||
int id, GLUI_CB cb)
|
||||
{
|
||||
common_init();
|
||||
GLUI_String buf;
|
||||
|
||||
set_ptr_val( value_ptr );
|
||||
if ( value_ptr ) {
|
||||
int_val = *value_ptr; /** Can't call set_int_val(), b/c that
|
||||
function will try to call the
|
||||
callback, etc */
|
||||
/** Actually, maybe not **/
|
||||
last_live_int = *value_ptr;
|
||||
}
|
||||
|
||||
user_id = id;
|
||||
glui_format_str( buf, "RadioGroup: %p", this );
|
||||
set_name( buf.c_str() );
|
||||
callback = cb;
|
||||
|
||||
parent->add_control( this );
|
||||
|
||||
init_live();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_RadioGroup::draw() **********/
|
||||
|
||||
void GLUI_RadioGroup::draw( int x, int y )
|
||||
{
|
||||
if ( NOT can_draw() )
|
||||
return;
|
||||
|
||||
draw_group(false);
|
||||
}
|
||||
|
||||
|
||||
/********************* GLUI_RadioGroup::draw_group(int translate) **********/
|
||||
|
||||
void GLUI_RadioGroup::draw_group( int translate )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
GLUI_RadioButton *button;
|
||||
this->int_val = int_val;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW );
|
||||
|
||||
button = (GLUI_RadioButton*) first_child();
|
||||
while( button != NULL ) {
|
||||
glPushMatrix();
|
||||
if (translate) {
|
||||
button->translate_to_origin();
|
||||
}
|
||||
else {
|
||||
glTranslatef(button->x_abs-x_abs,
|
||||
button->y_abs-y_abs,0.0);
|
||||
}
|
||||
|
||||
if ( button->int_val )
|
||||
button->draw_checked();
|
||||
else
|
||||
button->draw_unchecked();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
button = (GLUI_RadioButton*) button->next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_RadioGroup::set_name() **********/
|
||||
|
||||
void GLUI_RadioGroup::set_name( const char *text )
|
||||
{
|
||||
name = text;
|
||||
|
||||
if ( glui )
|
||||
glui->refresh();
|
||||
}
|
||||
|
||||
|
||||
/********************************* GLUI_RadioGroup::set_selected() **********/
|
||||
|
||||
void GLUI_RadioGroup::set_selected( int int_val )
|
||||
{
|
||||
GLUI_RadioButton *button;
|
||||
|
||||
this->int_val = int_val;
|
||||
|
||||
button = (GLUI_RadioButton*) first_child();
|
||||
while( button != NULL ) {
|
||||
if ( int_val == -1 ) { /*** All buttons in group are deselected ***/
|
||||
button->set_int_val(0);
|
||||
}
|
||||
else if ( int_val == button->user_id ) { /*** This is selected button ***/
|
||||
button->set_int_val(1);
|
||||
}
|
||||
else { /*** This is NOT selected button ***/
|
||||
button->set_int_val(0);
|
||||
|
||||
}
|
||||
button = (GLUI_RadioButton*) button->next();
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
|
||||
|
||||
/************************ GLUI_RadioButton::GLUI_RadioButton() **********/
|
||||
|
||||
GLUI_RadioButton::GLUI_RadioButton( GLUI_RadioGroup *grp, const char *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;
|
||||
set_name( name );
|
||||
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 */
|
||||
}
|
||||
|
||||
|
||||
/************************ GLUI_RadioButton::mouse_down_handler() **********/
|
||||
|
||||
int GLUI_RadioButton::mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
if ( NOT group )
|
||||
return false;
|
||||
|
||||
orig_value = group->int_val;
|
||||
|
||||
currently_inside = true;
|
||||
|
||||
group->set_selected( this->user_id );
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/********************** GLUI_RadioButton::mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_RadioButton::mouse_held_down_handler( int local_x, int local_y,
|
||||
bool inside)
|
||||
{
|
||||
if (inside != currently_inside) {
|
||||
if (inside) group->set_selected( this->user_id );
|
||||
else group->set_selected( orig_value );
|
||||
currently_inside = inside;
|
||||
redraw();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*************************** GLUI_RadioButton::mouse_up_handler() **********/
|
||||
|
||||
int GLUI_RadioButton::mouse_up_handler( int local_x, int local_y,
|
||||
bool inside )
|
||||
{
|
||||
if ( NOT group )
|
||||
return false;
|
||||
|
||||
if ( NOT inside ) {
|
||||
group->set_selected( orig_value );
|
||||
redraw();
|
||||
}
|
||||
else {
|
||||
/** Now we update the radio button group. We tell the group
|
||||
handler to set the currently-selected item to this button, which
|
||||
is reference by its user_id/ordinal number within group **/
|
||||
|
||||
group->set_selected( this->user_id );
|
||||
redraw();
|
||||
|
||||
/*** Now update the linked variable, and call the callback,
|
||||
but ONLY if the value of the radio group actually changed ***/
|
||||
if ( group->int_val != orig_value ) {
|
||||
group->output_live(true); /** Output live and update gfx ***/
|
||||
|
||||
group->execute_callback();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/****************************** GLUI_RadioButton::draw() **********/
|
||||
|
||||
void GLUI_RadioButton::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
if ( NOT group OR NOT can_draw() )
|
||||
return;
|
||||
|
||||
/*** See if we're the currently-selected button. If so, draw ***/
|
||||
if ( group->int_val == this->user_id ) {
|
||||
if ( enabled )
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_RADIOBUTTON_ON, 0, 0 );
|
||||
else
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_RADIOBUTTON_ON_DIS, 0, 0 );
|
||||
}
|
||||
else {
|
||||
if ( enabled )
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_RADIOBUTTON_OFF, 0, 0 );
|
||||
else
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_RADIOBUTTON_OFF_DIS, 0, 0 );
|
||||
}
|
||||
|
||||
draw_active_area();
|
||||
|
||||
draw_name( text_x_offset, 10 );
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_RadioButton::draw_checked() ******/
|
||||
|
||||
void GLUI_RadioButton::draw_checked( void )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
if ( enabled )
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_RADIOBUTTON_ON, 0, 0 );
|
||||
else
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_RADIOBUTTON_ON_DIS, 0, 0 );
|
||||
draw_active_area();
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_RadioButton::draw_unchecked() ******/
|
||||
|
||||
void GLUI_RadioButton::draw_unchecked( void )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
if ( enabled )
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_RADIOBUTTON_OFF, 0, 0 );
|
||||
else
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_RADIOBUTTON_OFF_DIS, 0, 0 );
|
||||
draw_active_area();
|
||||
}
|
||||
|
||||
|
||||
/**************************************** GLUI_RadioButton::draw_O() ********/
|
||||
|
||||
void GLUI_RadioButton::draw_O( void )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
int i, j;
|
||||
|
||||
glBegin( GL_POINTS );
|
||||
for(i=3; i<=GLUI_RADIOBUTTON_SIZE-3; i++ )
|
||||
for(j=3; j<=GLUI_RADIOBUTTON_SIZE-3; j++ )
|
||||
glVertex2i(i,j);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
/******************************** GLUI_RadioButton::update_size() **********/
|
||||
|
||||
void GLUI_RadioButton::update_size( void )
|
||||
{
|
||||
int text_size;
|
||||
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
text_size = _glutBitmapWidthString( glui->font, name.c_str() );
|
||||
|
||||
/* if ( w < text_x_offset + text_size + 6 ) */
|
||||
w = text_x_offset + text_size + 6 ;
|
||||
}
|
||||
|
||||
|
||||
/************************* GLUI_RadioButton::draw_active_area() **************/
|
||||
|
||||
void GLUI_RadioButton::draw_active_area( void )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
int text_width, left, right;
|
||||
|
||||
text_width = _glutBitmapWidthString( glui->font, name.c_str() );
|
||||
left = text_x_offset-3;
|
||||
right = left + 7 + text_width;
|
||||
|
||||
if ( active ) {
|
||||
glEnable( GL_LINE_STIPPLE );
|
||||
glLineStipple( 1, 0x5555 );
|
||||
glColor3f( 0., 0., 0. );
|
||||
} else {
|
||||
glColor3ub( glui->bkgd_color.r, glui->bkgd_color.g, glui->bkgd_color.b );
|
||||
}
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i(left,0); glVertex2i( right,0);
|
||||
glVertex2i(right,h+1); glVertex2i( left,h+1);
|
||||
glEnd();
|
||||
|
||||
glDisable( GL_LINE_STIPPLE );
|
||||
}
|
||||
|
||||
|
||||
/********************************* GLUI_RadioGroup::set_int_val() **********/
|
||||
|
||||
void GLUI_RadioGroup::set_int_val( int new_val )
|
||||
{
|
||||
if ( new_val == int_val )
|
||||
return;
|
||||
|
||||
set_selected( new_val );
|
||||
redraw();
|
||||
|
||||
output_live(true);
|
||||
|
||||
}
|
||||
275
Extras/glui/glui_rollout.cpp
Normal file
275
Extras/glui/glui_rollout.cpp
Normal file
@@ -0,0 +1,275 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_panel.cpp - GLUI_Panel control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
enum {rollout_height_pixels=GLUI_DEFAULT_CONTROL_HEIGHT + 7};
|
||||
|
||||
/****************************** GLUI_Rollout::GLUI_Rollout() **********/
|
||||
|
||||
GLUI_Rollout::GLUI_Rollout( GLUI_Node *parent, const char *name,
|
||||
int open, int type )
|
||||
{
|
||||
common_init();
|
||||
set_name( name );
|
||||
user_id = -1;
|
||||
int_val = type;
|
||||
|
||||
if ( NOT open ) {
|
||||
is_open = false;
|
||||
h = rollout_height_pixels;
|
||||
}
|
||||
|
||||
parent->add_control( this );
|
||||
}
|
||||
|
||||
/****************************** GLUI_Rollout::open() **********/
|
||||
|
||||
void GLUI_Rollout::open( void )
|
||||
{
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
if ( is_open )
|
||||
return;
|
||||
is_open = true;
|
||||
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
/* Copy hidden children into our private list "collapsed_node" */
|
||||
child_head = collapsed_node.child_head;
|
||||
child_tail = collapsed_node.child_tail;
|
||||
collapsed_node.child_head = NULL;
|
||||
collapsed_node.child_tail = NULL;
|
||||
|
||||
if ( child_head != NULL ) {
|
||||
((GLUI_Control*) child_head)->unhide_internal( true );
|
||||
}
|
||||
|
||||
glui->refresh();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Rollout::close() **********/
|
||||
|
||||
void GLUI_Rollout::close( void )
|
||||
{
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
if ( NOT is_open )
|
||||
return;
|
||||
is_open = false;
|
||||
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
if ( child_head != NULL ) {
|
||||
((GLUI_Control*) child_head)->hide_internal( true );
|
||||
}
|
||||
|
||||
/* Move all children into a private list of hidden children */
|
||||
collapsed_node.child_head = first_child();
|
||||
collapsed_node.child_tail = last_child();
|
||||
child_head = NULL;
|
||||
child_tail = NULL;
|
||||
|
||||
this->h = rollout_height_pixels;
|
||||
|
||||
glui->refresh();
|
||||
}
|
||||
|
||||
|
||||
/**************************** GLUI_Rollout::mouse_down_handler() **********/
|
||||
|
||||
|
||||
int GLUI_Rollout::mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
if ( local_y - y_abs > rollout_height_pixels ) {
|
||||
initially_inside = currently_inside = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
currently_inside = true;
|
||||
initially_inside = true;
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**************************** GLUI_Rollout::mouse_held_down_handler() ****/
|
||||
|
||||
int GLUI_Rollout::mouse_held_down_handler(
|
||||
int local_x, int local_y,
|
||||
bool new_inside )
|
||||
{
|
||||
if ( NOT initially_inside )
|
||||
return false;
|
||||
|
||||
if ( local_y - y_abs> rollout_height_pixels )
|
||||
new_inside = false;
|
||||
|
||||
if (new_inside != currently_inside) {
|
||||
currently_inside = new_inside;
|
||||
redraw();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**************************** GLUI_Rollout::mouse_down_handler() **********/
|
||||
|
||||
int GLUI_Rollout::mouse_up_handler( int local_x, int local_y, bool inside )
|
||||
{
|
||||
if ( currently_inside ) {
|
||||
if ( is_open )
|
||||
close();
|
||||
else
|
||||
open();
|
||||
}
|
||||
|
||||
currently_inside = false;
|
||||
initially_inside = false;
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/********************************* GLUI_Rollout::draw() ***********/
|
||||
|
||||
void GLUI_Rollout::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
int left, right, top, bottom;
|
||||
|
||||
left = 5;
|
||||
right = w-left;
|
||||
top = 3;
|
||||
bottom = 3+16;
|
||||
|
||||
if ( is_open )
|
||||
draw_emboss_box( 0, w, top+3, h );
|
||||
else
|
||||
draw_emboss_box( 0, w, top+3, h-7 );
|
||||
|
||||
glui->draw_raised_box( left, top, w-left*2, 16 );
|
||||
|
||||
if ( glui )
|
||||
glColor3ub(glui->bkgd_color.r,glui->bkgd_color.g,glui->bkgd_color.b);
|
||||
glDisable( GL_CULL_FACE );
|
||||
glBegin( GL_QUADS );
|
||||
glVertex2i( left+1, top+1 ); glVertex2i( right-1, top+1 );
|
||||
glVertex2i( right-1, bottom-1 ); glVertex2i( left+1, bottom-1 );
|
||||
glEnd();
|
||||
|
||||
draw_name( left+8, top+11 );
|
||||
|
||||
if ( active )
|
||||
/*draw_active_box( left+4, left+string_width( name.c_str() )+12, */
|
||||
draw_active_box( left+4, right-17,
|
||||
top+2, bottom-2 );
|
||||
|
||||
|
||||
/** Draw '+' or '-' **/
|
||||
|
||||
glBegin( GL_LINES );
|
||||
if ( is_open ) {
|
||||
if ( enabled ) glColor3f( 0.0, 0.0, 0.0 );
|
||||
else glColor3f( 0.5, 0.5, 0.5 );
|
||||
glVertex2i(right-14,(top+bottom)/2); glVertex2i(right-5,(top+bottom)/2);
|
||||
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glVertex2i(right-14,1+(top+bottom)/2);glVertex2i(right-5,1+(top+bottom)/2);
|
||||
}
|
||||
else
|
||||
{
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glVertex2i(right-9,top+3); glVertex2i(right-9,bottom-4);
|
||||
glVertex2i(right-14,(top+bottom)/2); glVertex2i(right-5,(top+bottom)/2);
|
||||
|
||||
if ( enabled ) glColor3f( 0.0, 0.0, 0.0 );
|
||||
else glColor3f( 0.5, 0.5, 0.5 );
|
||||
glVertex2i(right-14,-1+(top+bottom)/2);
|
||||
glVertex2i(right-5,-1+(top+bottom)/2);
|
||||
glVertex2i(right-10,top+3);
|
||||
glVertex2i(right-10,bottom-4);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glLineWidth( 1.0 );
|
||||
|
||||
if (currently_inside) {draw_pressed(); /* heavy black outline when pressed */ }
|
||||
}
|
||||
|
||||
|
||||
/***************************** GLUI_Rollout::update_size() **********/
|
||||
|
||||
void GLUI_Rollout::update_size( void )
|
||||
{
|
||||
int text_size;
|
||||
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
text_size = string_width(name);
|
||||
|
||||
if ( w < text_size + 36 )
|
||||
w = text_size + 36;
|
||||
}
|
||||
|
||||
|
||||
/**************************** GLUI_Rollout::draw_pressed() ***********/
|
||||
|
||||
void GLUI_Rollout::draw_pressed( void )
|
||||
{
|
||||
int left, right, top, bottom;
|
||||
|
||||
left = 5;
|
||||
right = w-left;
|
||||
top = 3;
|
||||
bottom = 3+16;
|
||||
|
||||
|
||||
glColor3f( 0.0, 0.0, 0.0 );
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( left, top ); glVertex2i( right, top );
|
||||
glVertex2i( right, bottom ); glVertex2i( left,bottom );
|
||||
glEnd();
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( left+1, top+1 ); glVertex2i( right-1, top+1 );
|
||||
glVertex2i( right-1, bottom-1 ); glVertex2i( left+1,bottom-1 );
|
||||
glEnd();
|
||||
}
|
||||
473
Extras/glui/glui_rotation.cpp
Normal file
473
Extras/glui/glui_rotation.cpp
Normal file
@@ -0,0 +1,473 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_rotation - GLUI_Rotation control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "GL/glui.h"
|
||||
#include "arcball.h"
|
||||
#include "algebra3.h"
|
||||
|
||||
/*************************** GLUI_Rotation::iaction_mouse_down_handler() ***/
|
||||
|
||||
int GLUI_Rotation::iaction_mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
copy_float_array_to_ball();
|
||||
|
||||
init_ball();
|
||||
|
||||
local_y = (int) floor(2.0 * ball->center[1] - local_y);
|
||||
|
||||
ball->mouse_down( local_x, local_y );
|
||||
|
||||
/* printf( "%d %d - %f %f\n", local_x, local_y, ball->center[0], ball->center[1] ); */
|
||||
|
||||
copy_ball_to_float_array();
|
||||
|
||||
spinning = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*********************** GLUI_Rotation::iaction_mouse_up_handler() **********/
|
||||
|
||||
int GLUI_Rotation::iaction_mouse_up_handler( int local_x, int local_y,
|
||||
bool inside )
|
||||
{
|
||||
copy_float_array_to_ball();
|
||||
|
||||
ball->mouse_up();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/******************* GLUI_Rotation::iaction_mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_Rotation::iaction_mouse_held_down_handler( int local_x, int local_y,
|
||||
bool inside)
|
||||
{
|
||||
if ( NOT glui )
|
||||
return 0;
|
||||
|
||||
copy_float_array_to_ball();
|
||||
|
||||
local_y = (int) floor(2.0 * ball->center[1] - local_y);
|
||||
|
||||
/* printf( "%d %d\n", local_x, local_y ); */
|
||||
|
||||
ball->mouse_motion( local_x, local_y, 0,
|
||||
(glui->curr_modifiers & GLUT_ACTIVE_ALT) != 0,
|
||||
(glui->curr_modifiers & GLUT_ACTIVE_CTRL) != 0 );
|
||||
|
||||
copy_ball_to_float_array();
|
||||
|
||||
if ( can_spin )
|
||||
spinning = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/******************** GLUI_Rotation::iaction_draw_active_area_persp() **************/
|
||||
|
||||
void GLUI_Rotation::iaction_draw_active_area_persp( void )
|
||||
{
|
||||
/********** arcball *******/
|
||||
copy_float_array_to_ball();
|
||||
|
||||
setup_texture();
|
||||
setup_lights();
|
||||
|
||||
glEnable(GL_CULL_FACE );
|
||||
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
|
||||
mat4 tmp_rot = *ball->rot_ptr;
|
||||
glMultMatrixf( (float*) &tmp_rot[0][0] );
|
||||
|
||||
/*** Draw the checkered box ***/
|
||||
/*glDisable( GL_TEXTURE_2D ); */
|
||||
draw_ball(1.35); // 1.96 );
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D,0); /* unhook our checkerboard texture */
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
glDisable( GL_LIGHTING );
|
||||
glDisable( GL_CULL_FACE );
|
||||
}
|
||||
|
||||
|
||||
/******************** GLUI_Rotation::iaction_draw_active_area_ortho() **********/
|
||||
|
||||
void GLUI_Rotation::iaction_draw_active_area_ortho( void )
|
||||
{
|
||||
float radius;
|
||||
radius = (float)(h-22)/2.0; /*MIN((float)w/2.0, (float)h/2.0); */
|
||||
|
||||
/********* Draw emboss circles around arcball control *********/
|
||||
int k;
|
||||
glLineWidth( 1.0 );
|
||||
glBegin( GL_LINE_LOOP);
|
||||
for( k=0; k<60; k++ ) {
|
||||
float phi = 2*M_PI*(float)k/60.0;
|
||||
vec2 p( cos(phi) * (2.0 + radius), sin(phi) * (2.0 + radius));
|
||||
if ( p[1] < -p[0] ) glColor3ub( 128,128,128 );
|
||||
else glColor3ub( 255,255,255 );
|
||||
glVertex2fv((float*)&p[0]);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glBegin( GL_LINE_LOOP);
|
||||
for( k=0; k<60; k++ ) {
|
||||
float phi = 2*M_PI*(float)k/60.0;
|
||||
vec2 p( cos(phi) * (1.0 + radius), sin(phi) * (1.0 + radius));
|
||||
if ( enabled ) {
|
||||
if ( p[1] < -p[0] ) glColor3ub( 0,0,0);
|
||||
else glColor3ub( 192,192,192);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( p[1] < -p[0] ) glColor3ub( 180,180,180);
|
||||
else glColor3ub( 192,192,192);
|
||||
}
|
||||
glVertex2fv((float*)&p[0]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
/******************************** GLUI_Rotation::iaction_dump() **********/
|
||||
|
||||
void GLUI_Rotation::iaction_dump( FILE *output )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/******************** GLUI_Rotation::iaction_special_handler() **********/
|
||||
|
||||
int GLUI_Rotation::iaction_special_handler( int key,int modifiers )
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/********************************** GLUI_Rotation::init_ball() **********/
|
||||
|
||||
void GLUI_Rotation::init_ball( void )
|
||||
{
|
||||
/*printf( "%f %f %f", float( MIN(w/2,h/2)), (float) w/2, (float) h/2 ); */
|
||||
|
||||
ball->set_params( vec2( (float)(w/2), (float)((h-18)/2)),
|
||||
(float) 2.0*(h-18) );
|
||||
/*ball->set_damping( .05 ); */
|
||||
/*float( MIN(w/2,h/2))*2.0 ); */
|
||||
/* ball->reset_mouse(); */
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Rotation::setup_texture() *********/
|
||||
|
||||
void GLUI_Rotation::setup_texture( void )
|
||||
{
|
||||
static GLuint tex=0u;
|
||||
GLenum t=GL_TEXTURE_2D;
|
||||
glEnable(t);
|
||||
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
if (tex!=0u) {
|
||||
/* (OSL 2006/06) Just use glBindTexture to avoid having to re-upload the whole checkerboard every frame. */
|
||||
glBindTexture(t,tex);
|
||||
return;
|
||||
} /* Else need to make a new checkerboard texture */
|
||||
glGenTextures(1,&tex);
|
||||
glBindTexture(t,tex);
|
||||
glEnable(t);
|
||||
|
||||
unsigned int i, j;
|
||||
int dark, light; /*** Dark and light colors for ball checkerboard ***/
|
||||
|
||||
/* Note: you can change the number of checkers across there sphere in draw_ball */
|
||||
#define CHECKBOARD_SIZE 64 /* pixels across whole texture */
|
||||
#define CHECKBOARD_REPEAT 32u /* pixels across one black/white sector */
|
||||
unsigned char texture_image[CHECKBOARD_SIZE] [CHECKBOARD_SIZE] [3];
|
||||
unsigned char c;
|
||||
for( i=0; i<CHECKBOARD_SIZE; i++ )
|
||||
{
|
||||
for( j=0; j<CHECKBOARD_SIZE; j++ )
|
||||
{
|
||||
dark = 110;
|
||||
light = 220;
|
||||
|
||||
if ((((i/CHECKBOARD_REPEAT)&0x1)==0) ^ (((j/CHECKBOARD_REPEAT)&0x1)==0))
|
||||
c = light;
|
||||
else
|
||||
c = dark;
|
||||
|
||||
texture_image[i][j][0] = c;
|
||||
texture_image[i][j][1] = c;
|
||||
texture_image[i][j][2] = c;
|
||||
}
|
||||
}
|
||||
|
||||
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
||||
glTexParameteri( t, GL_TEXTURE_WRAP_S, GL_REPEAT );
|
||||
glTexParameteri( t, GL_TEXTURE_WRAP_T, GL_REPEAT );
|
||||
glTexParameteri( t, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( t, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
|
||||
gluBuild2DMipmaps(t, GL_RGB, CHECKBOARD_SIZE, CHECKBOARD_SIZE,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, texture_image);
|
||||
|
||||
/* Add some mipmapping LOD bias, to keep sphere texture sharp */
|
||||
float bias=-0.5;
|
||||
/* glTexEnvf(TEXTURE_FILTER_CONTROL_EXT,TEXTURE_LOD_BIAS_EXT,bias); */
|
||||
/* glTexParameteri( t, GL_TEXTURE_MAX_LEVEL,1);*/
|
||||
glTexEnvf(0x8500,0x8501,bias); /* <- numeric version for older OpenGL headers */
|
||||
/* Cap out the mipmap level, to prevent blurring on horizon */
|
||||
glTexParameteri(t, 0x813D, 1);
|
||||
if (glGetError()) {
|
||||
/* Ignore errors in setting funky texture state-- go with defaults.
|
||||
If somebody knows how to check OpenGL 1.2 before doing this, please do!
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/****************************** GLUI_Rotation::setup_lights() ***********/
|
||||
|
||||
void GLUI_Rotation::setup_lights( void )
|
||||
{
|
||||
glEnable( GL_LIGHTING );
|
||||
/* if ( enabled )
|
||||
glEnable( GL_LIGHTING );
|
||||
else
|
||||
glDisable( GL_LIGHTING );*/
|
||||
glEnable(GL_LIGHT0);
|
||||
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE );
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
GLfloat light0_position[] = {-1.f, 1.f, 1.0f, 0.0f};
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
|
||||
if (enabled) { /* enabled colors */
|
||||
GLfloat light0_ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
|
||||
GLfloat light0_diffuse[] = {1.f, 1.f, 1.0f, 1.0f};
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
|
||||
}
|
||||
else { /* disabled colors */
|
||||
GLfloat light0_ambient[] = {0.6f, 0.6f, 0.6f, 1.0f};
|
||||
GLfloat light0_diffuse[] = {0.2f, 0.2f, 0.2f, 1.0f};
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Rotation::draw_ball() **************/
|
||||
|
||||
void GLUI_Rotation::draw_ball( float radius )
|
||||
{
|
||||
if ( NOT can_draw() )
|
||||
return;
|
||||
|
||||
if (quadObj == NULL) quadObj = gluNewQuadric();
|
||||
if (quadObj) {
|
||||
gluQuadricDrawStyle(quadObj, GLU_FILL);
|
||||
gluQuadricNormals(quadObj, GLU_SMOOTH);
|
||||
gluQuadricTexture(quadObj, true );
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glLoadIdentity();
|
||||
double checkerTiles=2.0; /* black-white checker tiles across whole sphere */
|
||||
glScalef(checkerTiles,checkerTiles,1.0);
|
||||
gluSphere(quadObj, radius, 32, 16);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Rotation::reset() **********/
|
||||
|
||||
void GLUI_Rotation::reset( void )
|
||||
{
|
||||
ball->init(); /** reset quaternion, etc. **/
|
||||
ball->set_params( vec2( (float)(w/2), (float)((h-18)/2)),
|
||||
(float) 2.0*(h-18) );
|
||||
|
||||
set_spin( this->damping );
|
||||
|
||||
copy_ball_to_float_array();
|
||||
|
||||
translate_and_draw_front();
|
||||
|
||||
output_live(true); /*** Output live and draw main grx window ***/
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Rotation::needs_idle() *********/
|
||||
|
||||
bool GLUI_Rotation::needs_idle( void ) const
|
||||
{
|
||||
return can_spin;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Rotation::idle() ***************/
|
||||
|
||||
void GLUI_Rotation::idle( void )
|
||||
{
|
||||
spinning = ball->is_spinning?true:false;
|
||||
|
||||
if ( can_spin AND spinning ) {
|
||||
copy_float_array_to_ball();
|
||||
ball->idle();
|
||||
|
||||
*ball->rot_ptr = *ball->rot_ptr * ball->rot_increment;
|
||||
|
||||
mat4 tmp_rot;
|
||||
tmp_rot = *ball->rot_ptr;
|
||||
|
||||
copy_ball_to_float_array();
|
||||
|
||||
draw_active_area_only = true;
|
||||
translate_and_draw_front();
|
||||
draw_active_area_only = false;
|
||||
|
||||
output_live(true); /** output live and update gfx **/
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/********************** GLUI_Rotation::copy_float_array_to_ball() *********/
|
||||
|
||||
void GLUI_Rotation::copy_float_array_to_ball( void )
|
||||
{
|
||||
int i;
|
||||
float *fp_src, *fp_dst;
|
||||
|
||||
fp_src = &float_array_val[0];
|
||||
fp_dst = &((*ball->rot_ptr)[0][0]);
|
||||
|
||||
for( i=0; i<16; i++ ) {
|
||||
*fp_dst = *fp_src;
|
||||
|
||||
fp_src++;
|
||||
fp_dst++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/********************** GLUI_Rotation::copy_ball_to_float_array() *********/
|
||||
|
||||
void GLUI_Rotation::copy_ball_to_float_array( void )
|
||||
{
|
||||
mat4 tmp_rot;
|
||||
tmp_rot = *ball->rot_ptr;
|
||||
|
||||
set_float_array_val( (float*) &tmp_rot[0][0] );
|
||||
}
|
||||
|
||||
|
||||
/************************ GLUI_Rotation::set_spin() **********************/
|
||||
|
||||
void GLUI_Rotation::set_spin( float damp_factor )
|
||||
{
|
||||
if ( damp_factor == 0.0 )
|
||||
can_spin = false;
|
||||
else
|
||||
can_spin = true;
|
||||
|
||||
ball->set_damping( 1.0 - damp_factor );
|
||||
|
||||
this->damping = damp_factor;
|
||||
}
|
||||
|
||||
|
||||
/************** GLUI_Rotation::GLUI_Rotation() ********************/
|
||||
|
||||
GLUI_Rotation::GLUI_Rotation( GLUI_Node *parent,
|
||||
const char *name, float *value_ptr,
|
||||
int id,
|
||||
GLUI_CB cb )
|
||||
{
|
||||
common_init();
|
||||
set_ptr_val( value_ptr );
|
||||
user_id = id;
|
||||
set_name( name );
|
||||
callback = cb;
|
||||
parent->add_control( this );
|
||||
init_live();
|
||||
|
||||
/*** Init the live 4x4 matrix. This is different than the standard
|
||||
live variable behavior, since the original value of the 4x4 matrix
|
||||
is ignored and reset to Identity ***/
|
||||
/*
|
||||
NO! WVB
|
||||
if ( value_ptr != NULL ) {
|
||||
int i, j, index;
|
||||
for( i=0; i<4; i++ ) {
|
||||
for( j=0; j<4; j++ ) {
|
||||
index = i*4+j;
|
||||
if ( i==j )
|
||||
value_ptr[index] = 1.0;
|
||||
else
|
||||
value_ptr[index] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*init_ball(); */
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/************** GLUI_Rotation::common_init() ********************/
|
||||
|
||||
void GLUI_Rotation::common_init( void )
|
||||
{
|
||||
glui_format_str( name, "Rotation: %p", this );
|
||||
// type = GLUI_CONTROL_ROTATION;
|
||||
w = GLUI_ROTATION_WIDTH;
|
||||
h = GLUI_ROTATION_HEIGHT;
|
||||
can_activate = true;
|
||||
live_type = GLUI_LIVE_FLOAT_ARRAY;
|
||||
float_array_size = 16;
|
||||
quadObj = NULL;
|
||||
alignment = GLUI_ALIGN_CENTER;
|
||||
can_spin = false;
|
||||
spinning = false;
|
||||
damping = 0.0;
|
||||
ball = new Arcball;
|
||||
|
||||
reset();
|
||||
}
|
||||
832
Extras/glui/glui_scrollbar.cpp
Normal file
832
Extras/glui/glui_scrollbar.cpp
Normal file
@@ -0,0 +1,832 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_scrollbar.cpp - GLUI_Scrollbar class
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 John Kew, 1998 Paul Rademacher
|
||||
|
||||
This program is freely distributable without licensing fees and is
|
||||
provided without guarantee or warrantee expressed or implied. This
|
||||
program is -not- in the public domain.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
|
||||
/*static int __debug=0; */
|
||||
|
||||
#define GLUI_SCROLL_GROWTH_STEPS 800
|
||||
#define GLUI_SCROLL_MIN_GROWTH_STEPS 100
|
||||
#define GLUI_SCROLL_CALLBACK_INTERVAL 1 /* Execute the user's callback every this many clicks */
|
||||
|
||||
enum {
|
||||
GLUI_SCROLL_ARROW_UP,
|
||||
GLUI_SCROLL_ARROW_DOWN,
|
||||
GLUI_SCROLL_ARROW_LEFT,
|
||||
GLUI_SCROLL_ARROW_RIGHT
|
||||
};
|
||||
|
||||
|
||||
/****************************** GLUI_Scrollbar::GLUI_Scrollbar() **********/
|
||||
// Constructor, no live var
|
||||
GLUI_Scrollbar::GLUI_Scrollbar( GLUI_Node *parent,
|
||||
const char *name,
|
||||
int horz_vert,
|
||||
int data_type,
|
||||
int id, GLUI_CB callback
|
||||
/*,GLUI_Control *object
|
||||
,GLUI_InterObject_CB obj_cb*/
|
||||
)
|
||||
{
|
||||
common_construct(parent, name, horz_vert, data_type, NULL, id, callback/*, object, obj_cb*/);
|
||||
}
|
||||
|
||||
/****************************** GLUI_Scrollbar::GLUI_Scrollbar() **********/
|
||||
// Constructor, int live var
|
||||
GLUI_Scrollbar::GLUI_Scrollbar( GLUI_Node *parent, const char *name,
|
||||
int horz_vert,
|
||||
int *live_var,
|
||||
int id, GLUI_CB callback
|
||||
/*,GLUI_Control *object
|
||||
,GLUI_InterObject_CB obj_cb*/
|
||||
)
|
||||
{
|
||||
common_construct(parent, name, horz_vert, GLUI_SCROLL_INT, live_var, id, callback/*, object, obj_cb*/);
|
||||
}
|
||||
|
||||
/****************************** GLUI_Scrollbar::GLUI_Scrollbar() **********/
|
||||
// Constructor, float live var
|
||||
GLUI_Scrollbar::GLUI_Scrollbar( GLUI_Node *parent, const char *name,
|
||||
int horz_vert,
|
||||
float *live_var,
|
||||
int id, GLUI_CB callback
|
||||
/*,GLUI_Control *object
|
||||
,GLUI_InterObject_CB obj_cb*/
|
||||
)
|
||||
{
|
||||
common_construct(parent, name, horz_vert, GLUI_SCROLL_FLOAT, live_var, id, callback/*, object, obj_cb*/);
|
||||
}
|
||||
|
||||
/****************************** GLUI_Scrollbar::common_init() **********/
|
||||
void GLUI_Scrollbar::common_init(void)
|
||||
{
|
||||
horizontal = true;
|
||||
h = GLUI_SCROLL_ARROW_HEIGHT;
|
||||
w = GLUI_TEXTBOX_WIDTH;
|
||||
alignment = GLUI_ALIGN_CENTER;
|
||||
x_off = 0;
|
||||
y_off_top = 0;
|
||||
y_off_bot = 0;
|
||||
can_activate = true;
|
||||
state = GLUI_SCROLL_STATE_NONE;
|
||||
growth_exp = GLUI_SCROLL_DEFAULT_GROWTH_EXP;
|
||||
callback_count = 0;
|
||||
first_callback = true;
|
||||
user_speed = 1.0;
|
||||
float_min = 0.0;
|
||||
float_max = 0.0;
|
||||
int_min = 0;
|
||||
int_max = 0;
|
||||
associated_object = NULL;
|
||||
last_update_time=0;
|
||||
velocity_limit=50.0; /* Change value by at most 50 per second */
|
||||
box_length = 0;
|
||||
box_start_position = 0;
|
||||
box_end_position = 0;
|
||||
track_length = 0;
|
||||
}
|
||||
|
||||
/****************************** GLUI_Scrollbar::common_construct() **********/
|
||||
void GLUI_Scrollbar::common_construct(
|
||||
GLUI_Node *parent,
|
||||
const char *name,
|
||||
int horz_vert,
|
||||
int data_type,
|
||||
void *data,
|
||||
int id, GLUI_CB callback
|
||||
/*,GLUI_Control *object,
|
||||
GLUI_InterObject_CB obj_cb*/
|
||||
)
|
||||
{
|
||||
common_init();
|
||||
|
||||
// make sure limits are wide enough to hold live value
|
||||
if (data_type==GLUI_SCROLL_FLOAT) {
|
||||
float lo = 0.0f, hi=1.0f;
|
||||
if (data) {
|
||||
float d = *(float*)(data);
|
||||
lo = MIN(lo, d);
|
||||
hi = MAX(hi, d);
|
||||
}
|
||||
this->set_float_limits(lo,hi);
|
||||
this->set_float_val(lo);
|
||||
this->live_type = GLUI_LIVE_FLOAT;
|
||||
} else {
|
||||
int lo = 0, hi=100;
|
||||
if (data) {
|
||||
int d = *(int*)(data);
|
||||
lo = MIN(lo, d);
|
||||
hi = MAX(hi, d);
|
||||
}
|
||||
this->set_int_limits(lo,hi);
|
||||
this->set_int_val(0);
|
||||
this->live_type = GLUI_LIVE_INT;
|
||||
}
|
||||
this->data_type = data_type;
|
||||
this->set_ptr_val( data );
|
||||
this->set_name(name);
|
||||
this->user_id = id;
|
||||
this->callback = callback;
|
||||
//this->associated_object = object;
|
||||
//this->object_cb = obj_cb;
|
||||
this->horizontal=(horz_vert==GLUI_SCROLL_HORIZONTAL);
|
||||
if (this->horizontal) {
|
||||
this->h = GLUI_SCROLL_ARROW_HEIGHT;
|
||||
this->w = GLUI_TEXTBOX_WIDTH;
|
||||
} else {
|
||||
this->h = GLUI_TEXTBOX_HEIGHT;
|
||||
this->w = GLUI_SCROLL_ARROW_WIDTH;
|
||||
}
|
||||
parent->add_control( this );
|
||||
this->init_live();
|
||||
}
|
||||
|
||||
/****************************** GLUI_Scrollbar::mouse_down_handler() **********/
|
||||
|
||||
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 = MIN(int_min,int_max);
|
||||
int hi = 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;
|
||||
}
|
||||
|
||||
|
||||
/******************************** GLUI_Scrollbar::mouse_up_handler() **********/
|
||||
|
||||
int GLUI_Scrollbar::mouse_up_handler( int local_x, int local_y, bool inside )
|
||||
{
|
||||
state = GLUI_SCROLL_STATE_NONE;
|
||||
GLUI_Master.glui_setIdleFuncIfNecessary();
|
||||
|
||||
/* printf("spinner: mouse up : %d/%d inside: %d\n",local_x,local_y,inside); */
|
||||
|
||||
/*glutSetCursor( GLUT_CURSOR_INHERIT ); */
|
||||
glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
|
||||
|
||||
redraw();
|
||||
|
||||
/* do_callbacks(); --- stub */
|
||||
/* if ( callback ) */
|
||||
/* callback( this->user_id ); */
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/***************************** GLUI_Scrollbar::mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_Scrollbar::mouse_held_down_handler( int local_x, int local_y,
|
||||
bool new_inside)
|
||||
{
|
||||
int new_state;
|
||||
if ( state == GLUI_SCROLL_STATE_NONE )
|
||||
return false;
|
||||
|
||||
/* printf("spinner: mouse held: %d/%d inside: %d\n",local_x,local_y,
|
||||
new_inside);
|
||||
*/
|
||||
|
||||
if ( state == GLUI_SCROLL_STATE_SCROLL) { /* dragging? */
|
||||
do_drag( local_x-x_abs, local_y-y_abs );
|
||||
}
|
||||
else { /* not dragging */
|
||||
new_state = find_arrow( local_x, local_y );
|
||||
|
||||
if ( new_state == state ) {
|
||||
/** Still in same arrow **/
|
||||
do_click();
|
||||
}
|
||||
}
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Scrollbar::key_handler() **********/
|
||||
|
||||
int GLUI_Scrollbar::key_handler( unsigned char key,int modifiers )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Scrollbar::draw() **********/
|
||||
|
||||
void GLUI_Scrollbar::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
if ( horizontal ) {
|
||||
draw_scroll_arrow(GLUI_SCROLL_ARROW_LEFT, 0, 0);
|
||||
draw_scroll_arrow(GLUI_SCROLL_ARROW_RIGHT, w-GLUI_SCROLL_ARROW_WIDTH, 0);
|
||||
} else {
|
||||
draw_scroll_arrow(GLUI_SCROLL_ARROW_UP, 0, 0);
|
||||
draw_scroll_arrow(GLUI_SCROLL_ARROW_DOWN, 0, h-GLUI_SCROLL_ARROW_HEIGHT);
|
||||
}
|
||||
draw_scroll();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Scrollbar::draw_scroll_arrow() **********/
|
||||
|
||||
void GLUI_Scrollbar::draw_scroll_arrow(int arrowtype, int x, int y)
|
||||
{
|
||||
float offset=0;
|
||||
float L=3.5f,HC=7.f,R=10.5f;
|
||||
float T=4.5f,VC=8.f,B=11.5;
|
||||
const float verts[][6]={
|
||||
{ L,10.5f, R, 10.5f, HC, 6.5f }, // up arrow
|
||||
{ L,6.5f, R, 6.5f, HC,10.5f }, // down arrow
|
||||
{ R-2,T, R-2, B, L+1, VC }, // left arrow
|
||||
{ L+2,T, L+2, B, R-1, VC } // right arrow
|
||||
};
|
||||
|
||||
const float *tri = NULL;
|
||||
|
||||
switch (arrowtype)
|
||||
{
|
||||
case GLUI_SCROLL_ARROW_UP:
|
||||
tri = verts[0];
|
||||
if (state & GLUI_SCROLL_STATE_UP) offset = 1;
|
||||
break;
|
||||
|
||||
case GLUI_SCROLL_ARROW_DOWN:
|
||||
tri = verts[1];
|
||||
if (state & GLUI_SCROLL_STATE_DOWN) offset = 1;
|
||||
break;
|
||||
|
||||
case GLUI_SCROLL_ARROW_LEFT:
|
||||
tri = verts[2];
|
||||
if (state & GLUI_SCROLL_STATE_DOWN) offset = 1;
|
||||
break;
|
||||
|
||||
case GLUI_SCROLL_ARROW_RIGHT:
|
||||
tri = verts[3];
|
||||
if (state & GLUI_SCROLL_STATE_UP) offset = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return; /* tri is NULL */
|
||||
}
|
||||
|
||||
glColor3ubv(&glui->bkgd_color.r);
|
||||
glRecti(x,y,x+GLUI_SCROLL_ARROW_WIDTH,y+GLUI_SCROLL_ARROW_HEIGHT);
|
||||
if (!offset) {
|
||||
glui->draw_raised_box(x,y+1,GLUI_SCROLL_ARROW_WIDTH-1,GLUI_SCROLL_ARROW_HEIGHT-1);
|
||||
} else {
|
||||
glColor3ub(128,128,128);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
int x2=x+GLUI_SCROLL_ARROW_WIDTH, y2=y+GLUI_SCROLL_ARROW_HEIGHT;
|
||||
glVertex2i(x ,y);
|
||||
glVertex2i(x2,y);
|
||||
glVertex2i(x2,y2);
|
||||
glVertex2i(x ,y2);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
GLubyte black[]={0,0,0};
|
||||
GLubyte white[]={255,255,255};
|
||||
GLubyte gray[]={128,128,128};
|
||||
GLubyte *color=black;
|
||||
if (!enabled) {
|
||||
offset = 1;
|
||||
color = white;
|
||||
}
|
||||
glTranslatef(x+offset,y+offset,0);
|
||||
glColor3ubv(color);
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex2fv(tri); glVertex2fv(tri+2), glVertex2fv(tri+4);
|
||||
glEnd();
|
||||
glTranslatef(-(x+offset),-(y+offset),0);
|
||||
|
||||
if (!enabled) { // once more!
|
||||
glTranslatef(x,y,0);
|
||||
glColor3ubv(gray);
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex2fv(tri); glVertex2fv(tri+2), glVertex2fv(tri+4);
|
||||
glEnd();
|
||||
glTranslatef(-x,-y,0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GLUI_Scrollbar::draw_scroll() {
|
||||
update_scroll_parameters();
|
||||
|
||||
// Draw track using a checkerboard background
|
||||
const unsigned char scroll_bg[] = {
|
||||
0xD4, 0xD0, 0xC8, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xD4, 0xD0, 0xC8
|
||||
};
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
||||
glEnable( GL_TEXTURE_2D);
|
||||
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
|
||||
scroll_bg);
|
||||
|
||||
float y0 = horizontal? 0 : GLUI_SCROLL_ARROW_HEIGHT;
|
||||
float y1 = horizontal? h : h-GLUI_SCROLL_ARROW_HEIGHT;
|
||||
float x0 = horizontal? GLUI_SCROLL_ARROW_WIDTH : 0;
|
||||
float x1 = horizontal? w-GLUI_SCROLL_ARROW_WIDTH : w;
|
||||
x0-=0.5; y0+=0.5;
|
||||
x1-=0.5; y1+=0.5;
|
||||
float dy = y1-y0;
|
||||
float dx = x1-x0;
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2f(x0,y0);
|
||||
glTexCoord2f(dx*0.5f,0); glVertex2f(x1,y0);
|
||||
glTexCoord2f(dx*0.5f,dy*0.5f); glVertex2f(x1,y1);
|
||||
glTexCoord2f(0, dy*0.5f); glVertex2f(x0,y1);
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
// Draw scroll box
|
||||
int box = box_start_position;
|
||||
if (horizontal) {
|
||||
box += GLUI_SCROLL_ARROW_WIDTH;
|
||||
draw_scroll_box(box,1,box_length,h);
|
||||
} else {
|
||||
box += GLUI_SCROLL_ARROW_HEIGHT+1;
|
||||
draw_scroll_box(0,box,w,box_length);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************** GLUI_Scrollbar::draw_scroll_box() **********/
|
||||
|
||||
void GLUI_Scrollbar::draw_scroll_box(int x, int y, int w, int h)
|
||||
{
|
||||
if (!enabled) return;
|
||||
glColor3ubv(&glui->bkgd_color.r);
|
||||
glRecti(x,y,x+w,y+h);
|
||||
glui->draw_raised_box(x,y, w-1, h-1);
|
||||
|
||||
if (active) {
|
||||
glEnable( GL_LINE_STIPPLE );
|
||||
glLineStipple( 1, 0x5555 );
|
||||
glColor3f( 0., 0., 0. );
|
||||
glBegin(GL_LINE_LOOP);
|
||||
int x1 = x+2, y1 = y+2, x2 = x+w-4, y2 = y+h-4;
|
||||
glVertex2i(x1,y1);
|
||||
glVertex2i(x2,y1);
|
||||
glVertex2i(x2,y2);
|
||||
glVertex2i(x1,y2);
|
||||
glEnd();
|
||||
glDisable( GL_LINE_STIPPLE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************** update_scroll_parameters ***********/
|
||||
|
||||
void GLUI_Scrollbar::update_scroll_parameters() {
|
||||
track_length = horizontal?
|
||||
this->w-GLUI_SCROLL_ARROW_WIDTH*2 :
|
||||
this->h-GLUI_SCROLL_ARROW_HEIGHT*2;
|
||||
if (data_type==GLUI_SCROLL_INT)
|
||||
{
|
||||
if (int_max==int_min)
|
||||
box_length=track_length;
|
||||
else {
|
||||
const int MIN_TAB = GLUI_SCROLL_BOX_STD_HEIGHT;
|
||||
//box_length = int(track_length/float(visible_range));
|
||||
//if (box_length < MIN_TAB)
|
||||
box_length = MIN_TAB;
|
||||
}
|
||||
float pixels_per_unit = (track_length-box_length)/float(int_max-int_min);
|
||||
if (horizontal)
|
||||
box_start_position = int((int_val-int_min)*pixels_per_unit);
|
||||
else
|
||||
box_start_position = int((int_max-int_val)*pixels_per_unit);
|
||||
box_end_position = box_start_position+box_length;
|
||||
}
|
||||
else if (data_type==GLUI_SCROLL_FLOAT)
|
||||
{
|
||||
if (float_max==float_min)
|
||||
box_length=track_length;
|
||||
else {
|
||||
box_length = GLUI_SCROLL_BOX_STD_HEIGHT;
|
||||
}
|
||||
float pixels_per_unit = (track_length-box_length)/float(float_max-float_min);
|
||||
if (horizontal)
|
||||
box_start_position = int((float_val-float_min)*pixels_per_unit);
|
||||
else
|
||||
box_start_position = int((float_max-float_val)*pixels_per_unit);
|
||||
box_end_position = box_start_position+box_length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/********************************* GLUI_Scrollbar::special_handler() **********/
|
||||
|
||||
int GLUI_Scrollbar::special_handler( int key,int modifiers )
|
||||
{
|
||||
if ( !horizontal && key == GLUT_KEY_UP ) {
|
||||
mouse_down_handler( x_abs + w - GLUI_SCROLL_ARROW_WIDTH + 1,
|
||||
y_abs + 1 );
|
||||
mouse_up_handler( x_abs + w - GLUI_SCROLL_ARROW_WIDTH + 1,
|
||||
y_abs + 1, true );
|
||||
}
|
||||
else if ( !horizontal && key == GLUT_KEY_DOWN ) {
|
||||
mouse_down_handler(x_abs + w - GLUI_SCROLL_ARROW_WIDTH + 1,
|
||||
y_abs+1+GLUI_SCROLL_ARROW_HEIGHT);
|
||||
mouse_up_handler( x_abs + w - GLUI_SCROLL_ARROW_WIDTH + 1,
|
||||
y_abs+1 +GLUI_SCROLL_ARROW_HEIGHT,
|
||||
true );
|
||||
}
|
||||
if ( horizontal && key == GLUT_KEY_LEFT ) {
|
||||
mouse_down_handler( x_abs + 1,y_abs + 1 );
|
||||
mouse_up_handler( x_abs + 1, y_abs + 1, true );
|
||||
}
|
||||
else if ( horizontal && key == GLUT_KEY_RIGHT ) {
|
||||
mouse_down_handler(x_abs + w - GLUI_SCROLL_ARROW_WIDTH + 1,
|
||||
y_abs+1);
|
||||
mouse_up_handler( x_abs + w - GLUI_SCROLL_ARROW_WIDTH + 1,
|
||||
y_abs+1,
|
||||
true );
|
||||
}
|
||||
else if ( key == GLUT_KEY_HOME ) { /** Set value to limit top -
|
||||
or increment by 10 **/
|
||||
}
|
||||
else if ( key == GLUT_KEY_END ) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Scrollbar::update_size() **********/
|
||||
|
||||
void GLUI_Scrollbar::update_size( void )
|
||||
{
|
||||
if (horizontal) {
|
||||
h = GLUI_SCROLL_ARROW_HEIGHT;
|
||||
if (associated_object) {
|
||||
this->w = ((GLUI_Control *)associated_object)->w;
|
||||
}
|
||||
}
|
||||
else {
|
||||
w = GLUI_SCROLL_ARROW_WIDTH;
|
||||
if (associated_object) {
|
||||
this->h = ((GLUI_Control *)associated_object)->h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Scrollbar::find_arrow() ************/
|
||||
|
||||
int GLUI_Scrollbar::find_arrow( int local_x, int local_y )
|
||||
{
|
||||
|
||||
local_x = local_x-x_abs;
|
||||
local_y = local_y-y_abs;
|
||||
|
||||
if (horizontal)
|
||||
{
|
||||
if ( local_y >= h-GLUI_SCROLL_ARROW_HEIGHT-3 && local_y <= h)
|
||||
{
|
||||
update_scroll_parameters();
|
||||
if ( local_x >= 0 AND local_x <= (GLUI_SCROLL_ARROW_WIDTH+box_start_position) )
|
||||
{
|
||||
return GLUI_SCROLL_STATE_DOWN;
|
||||
}
|
||||
if ( local_x >= (GLUI_SCROLL_ARROW_WIDTH+box_end_position)
|
||||
AND local_x <= (w+GLUI_SCROLL_ARROW_WIDTH) )
|
||||
{
|
||||
return GLUI_SCROLL_STATE_UP;
|
||||
}
|
||||
return GLUI_SCROLL_STATE_SCROLL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( local_x >= w-GLUI_SCROLL_ARROW_WIDTH-3 && local_x <= w)
|
||||
{
|
||||
update_scroll_parameters();
|
||||
if ( local_y >= 0 AND local_y <= (GLUI_SCROLL_ARROW_HEIGHT+box_start_position) )
|
||||
{
|
||||
return GLUI_SCROLL_STATE_UP;
|
||||
}
|
||||
if ( local_y >= (GLUI_SCROLL_ARROW_HEIGHT+box_end_position)
|
||||
AND local_y <= (h+GLUI_SCROLL_ARROW_HEIGHT) )
|
||||
{
|
||||
return GLUI_SCROLL_STATE_DOWN;
|
||||
}
|
||||
return GLUI_SCROLL_STATE_SCROLL;
|
||||
}
|
||||
}
|
||||
|
||||
return GLUI_SCROLL_STATE_NONE;
|
||||
}
|
||||
|
||||
/***************************************** GLUI_Scrollbar::do_click() **********/
|
||||
|
||||
void GLUI_Scrollbar::do_click( void )
|
||||
{
|
||||
int direction = 0;
|
||||
|
||||
if ( state == GLUI_SCROLL_STATE_UP )
|
||||
direction = +1;
|
||||
else if ( state == GLUI_SCROLL_STATE_DOWN )
|
||||
direction = -1;
|
||||
|
||||
if (data_type==GLUI_SCROLL_INT&&int_min>int_max) direction*=-1;
|
||||
if (data_type==GLUI_SCROLL_FLOAT&&float_min>float_max) direction*=-1;
|
||||
|
||||
increase_growth();
|
||||
|
||||
float modifier_factor = 1.0;
|
||||
float incr = growth * modifier_factor * user_speed ;
|
||||
|
||||
double frame_time=GLUI_Time()-last_update_time;
|
||||
double frame_limit=velocity_limit*frame_time;
|
||||
if (incr>frame_limit) incr=frame_limit; /* don't scroll faster than limit */
|
||||
last_update_time=GLUI_Time();
|
||||
|
||||
float new_val = float_val;
|
||||
|
||||
new_val += direction * incr;
|
||||
if (1 || data_type==GLUI_SCROLL_FLOAT) set_float_val(new_val);
|
||||
if (0 && data_type==GLUI_SCROLL_INT) set_int_val((int)new_val);
|
||||
//printf("do_click: incr %f val=%f float_val=%f\n",incr,new_val,float_val);
|
||||
|
||||
/*** Now update live variable and do callback. We don't want
|
||||
to do the callback on each iteration of this function, just on every
|
||||
i^th iteration, where i is given by GLUI_SCROLL_CALLBACK_INTERVAL ****/
|
||||
callback_count++;
|
||||
if ( (callback_count % GLUI_SCROLL_CALLBACK_INTERVAL ) == 0 )
|
||||
do_callbacks();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***************************************** GLUI_Scrollbar::do_drag() **********/
|
||||
|
||||
void GLUI_Scrollbar::do_drag( int x, int y )
|
||||
{
|
||||
int direction = 0;
|
||||
float incr, modifier_factor;
|
||||
/* int delta_x; */
|
||||
int new_int_val = int_val;
|
||||
float new_float_val = float_val;
|
||||
|
||||
int free_len = track_length-box_length;
|
||||
if (free_len == 0) return;
|
||||
|
||||
modifier_factor = 1.0;
|
||||
if ( state == GLUI_SCROLL_STATE_SCROLL) {
|
||||
update_scroll_parameters();
|
||||
|
||||
int hbox = box_length/2;
|
||||
if (horizontal) {
|
||||
int track_v = x-GLUI_SCROLL_ARROW_WIDTH;
|
||||
new_int_val = int_min + (track_v-hbox)*(int_max-int_min)/free_len;
|
||||
new_float_val = float_min + (track_v-hbox)*(float_max-float_min)/float(free_len);
|
||||
} else {
|
||||
int track_v = y-GLUI_SCROLL_ARROW_HEIGHT;
|
||||
new_int_val = int_max - (track_v-hbox)*(int_max-int_min)/free_len;
|
||||
new_float_val = float_max - (track_v-hbox)*(float_max-float_min)/float(free_len);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( state == GLUI_SCROLL_STATE_UP )
|
||||
direction = +1;
|
||||
else if ( state == GLUI_SCROLL_STATE_DOWN )
|
||||
direction = -1;
|
||||
incr = growth * direction * modifier_factor * user_speed;
|
||||
new_int_val += direction;
|
||||
new_float_val += direction * (float_max-float_min)/free_len;
|
||||
}
|
||||
last_y = y;
|
||||
last_x = x;
|
||||
|
||||
/*** Now update live variable and do callback. We don't want
|
||||
to do the callback on each iteration of this function, just on every
|
||||
i^th iteration, where i is given by GLUI_SCROLL_CALLBACK_INTERVAL ****/
|
||||
if(data_type==GLUI_SCROLL_INT)
|
||||
set_int_val(new_int_val);
|
||||
else if (data_type==GLUI_SCROLL_FLOAT)
|
||||
set_float_val(new_float_val);
|
||||
|
||||
callback_count++;
|
||||
if ( (callback_count % GLUI_SCROLL_CALLBACK_INTERVAL ) == 0 )
|
||||
do_callbacks();
|
||||
}
|
||||
|
||||
|
||||
/***************************************** GLUI_Scrollbar::needs_idle() ******/
|
||||
|
||||
bool GLUI_Scrollbar::needs_idle( void ) const
|
||||
{
|
||||
if (state == GLUI_SCROLL_STATE_UP OR state == GLUI_SCROLL_STATE_DOWN ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************** GLUI_Scrollbar::idle() **********/
|
||||
|
||||
void GLUI_Scrollbar::idle( void )
|
||||
{
|
||||
if ( NOT needs_idle() )
|
||||
return;
|
||||
else
|
||||
do_click();
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Scrollbar::do_callbacks() **********/
|
||||
|
||||
void GLUI_Scrollbar::do_callbacks( void )
|
||||
{
|
||||
|
||||
/* *******************************************/
|
||||
|
||||
if ( NOT first_callback ) {
|
||||
if ( data_type == GLUI_SCROLL_INT AND int_val == last_int_val ) {
|
||||
return;
|
||||
}
|
||||
if ( data_type == GLUI_SPINNER_FLOAT AND float_val == last_float_val ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (associated_object == NULL) {
|
||||
this->execute_callback();
|
||||
}
|
||||
else { // Use internal Callbacks
|
||||
if (object_cb) {
|
||||
//object_cb(associated_object, int_val);
|
||||
object_cb(this);
|
||||
}
|
||||
}
|
||||
last_int_val = int_val;
|
||||
last_float_val = float_val;
|
||||
first_callback = false;
|
||||
}
|
||||
|
||||
|
||||
/********************************** GLUI_Scrollbar::set_float_val() ************/
|
||||
|
||||
void GLUI_Scrollbar::set_float_val( float new_val )
|
||||
{
|
||||
// Allow for the possibility that the limits are reversed
|
||||
float hi = MAX(float_min,float_max);
|
||||
float lo = MIN(float_min,float_max);
|
||||
if (new_val > hi)
|
||||
new_val = hi;
|
||||
if (new_val < lo)
|
||||
new_val = lo;
|
||||
last_float_val = float_val;
|
||||
float_val = new_val;
|
||||
int_val = (int)new_val;
|
||||
|
||||
redraw();
|
||||
|
||||
/*** Now update the live variable ***/
|
||||
output_live(true);
|
||||
}
|
||||
|
||||
|
||||
/********************************** GLUI_Scrollbar::set_int_val() ************/
|
||||
|
||||
void GLUI_Scrollbar::set_int_val( int new_val )
|
||||
{
|
||||
// Allow for the possibility that the limits are reversed
|
||||
int hi = MAX(int_min,int_max);
|
||||
int lo = MIN(int_min,int_max);
|
||||
if (new_val > hi)
|
||||
new_val = hi;
|
||||
if (new_val < lo)
|
||||
new_val = lo;
|
||||
last_int_val = int_val;
|
||||
float_val = int_val = new_val;
|
||||
|
||||
redraw();
|
||||
|
||||
/*** Now update the live variable ***/
|
||||
output_live(true);
|
||||
}
|
||||
|
||||
/*********************************** GLUI_Scrollbar::set_float_limits() *********/
|
||||
|
||||
void GLUI_Scrollbar::set_float_limits( float low, float high, int limit_type )
|
||||
{
|
||||
if (limit_type != GLUI_LIMIT_CLAMP) {
|
||||
// error!
|
||||
}
|
||||
float_min = low;
|
||||
float_max = high;
|
||||
// Allow for possiblitly of reversed limits
|
||||
float lo = MIN(low,high);
|
||||
float hi = MAX(low,high);
|
||||
if (float_val<lo) set_float_val(lo);
|
||||
if (float_val>hi) set_float_val(hi);
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_Scrollbar::set_int_limits() *********/
|
||||
|
||||
void GLUI_Scrollbar::set_int_limits( int low, int high, int limit_type )
|
||||
{
|
||||
if (limit_type != GLUI_LIMIT_CLAMP) {
|
||||
// error!
|
||||
}
|
||||
int_min = low;
|
||||
int_max = high;
|
||||
// Allow for possiblitly of reversed limits
|
||||
int lo = MIN(low,high);
|
||||
int hi = MAX(low,high);
|
||||
if (int_val<lo) set_int_val(lo);
|
||||
if (int_val>hi) set_int_val(hi);
|
||||
float_min = low;
|
||||
float_max = high;
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_Scrollbar::reset_growth() *************/
|
||||
|
||||
void GLUI_Scrollbar::reset_growth( void )
|
||||
{
|
||||
growth = fabs(float_max - float_min) / float(GLUI_SCROLL_GROWTH_STEPS);
|
||||
if (data_type == GLUI_SCROLL_INT && growth<1) growth=1;
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI_Scrollbar::increase_growth() *************/
|
||||
|
||||
void GLUI_Scrollbar::increase_growth( void )
|
||||
{
|
||||
float range=0;
|
||||
if (data_type==GLUI_SCROLL_FLOAT)
|
||||
range = fabs(float_max-float_min);
|
||||
else
|
||||
range = fabs(float(int_max-int_min));
|
||||
if ( growth < (range / float(GLUI_SCROLL_MIN_GROWTH_STEPS)) )
|
||||
growth *= growth_exp;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
75
Extras/glui/glui_separator.cpp
Normal file
75
Extras/glui/glui_separator.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_separator.cpp - GLUI_Separator control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
/****************************** GLUI_Separator::GLUI_Separator() **********/
|
||||
|
||||
GLUI_Separator::GLUI_Separator( GLUI_Node *parent )
|
||||
{
|
||||
common_init();
|
||||
parent->add_control( this );
|
||||
}
|
||||
|
||||
/****************************** GLUI_Separator::draw() **********/
|
||||
|
||||
void GLUI_Separator::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
int width, indent;
|
||||
int cont_x, cont_y, cont_w, cont_h, cont_x_off, cont_y_off;
|
||||
|
||||
if ( parent() != NULL ) {
|
||||
get_this_column_dims(&cont_x, &cont_y, &cont_w, &cont_h,
|
||||
&cont_x_off, &cont_y_off);
|
||||
|
||||
width = cont_w - cont_x_off*2;
|
||||
}
|
||||
else {
|
||||
width = this->w;
|
||||
}
|
||||
|
||||
indent = (int) floor(width * .05);
|
||||
|
||||
glLineWidth( 1.0 );
|
||||
glBegin( GL_LINES );
|
||||
glColor3f( .5, .5, .5 );
|
||||
glVertex2i( indent, GLUI_SEPARATOR_HEIGHT/2-1 );
|
||||
glVertex2i( width-indent, GLUI_SEPARATOR_HEIGHT/2-1 );
|
||||
|
||||
glColor3f( 1., 1., 1. );
|
||||
glVertex2i( indent, GLUI_SEPARATOR_HEIGHT/2 );
|
||||
glVertex2i( width-indent, GLUI_SEPARATOR_HEIGHT/2 );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
647
Extras/glui/glui_spinner.cpp
Normal file
647
Extras/glui/glui_spinner.cpp
Normal file
@@ -0,0 +1,647 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_spinner.cpp - GLUI_Spinner class
|
||||
|
||||
|
||||
notes:
|
||||
spinner does not explicitly keep track of the current value - this is all
|
||||
handled by the underlying edittext control
|
||||
-> thus, spinner->sync_live() has no meaning, nor spinner->output_live
|
||||
-> BUT, edittext will alter this spinner's float_val and int_val,
|
||||
so that spinner->get/set will work
|
||||
|
||||
|
||||
FIXME: there's a heck of a lot of duplication between this and glui_scrollbar.cpp.
|
||||
(OSL, 2006/06)
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
|
||||
/*static int __debug=0; */
|
||||
|
||||
#define GLUI_SPINNER_GROWTH_STEPS 800
|
||||
#define GLUI_SPINNER_MIN_GROWTH_STEPS 100
|
||||
#define GLUI_SPINNER_CALLBACK_INTERVAL 1
|
||||
|
||||
|
||||
/****************************** spinner_edittext_callback() ******************/
|
||||
/* This function is not used anymore. It has been replaced by directly */
|
||||
/* Including an optional pointer to a spinner from an edittext box */
|
||||
|
||||
void spinner_edittext_callback( int id )
|
||||
{
|
||||
GLUI_Spinner *spinner;
|
||||
|
||||
putchar( '.' ); flushout;
|
||||
|
||||
spinner = (GLUI_Spinner*) id;
|
||||
|
||||
if ( NOT spinner )
|
||||
return;
|
||||
|
||||
spinner->do_callbacks();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Spinner::GLUI_Spinner() ****************/
|
||||
|
||||
GLUI_Spinner::GLUI_Spinner( GLUI_Node* parent, const char *name,
|
||||
int data_type, int id, GLUI_CB callback )
|
||||
{
|
||||
common_construct(parent, name, data_type, NULL, id, callback);
|
||||
}
|
||||
|
||||
/****************************** GLUI_Spinner::GLUI_Spinner() ****************/
|
||||
|
||||
GLUI_Spinner::GLUI_Spinner( GLUI_Node* parent, const char *name,
|
||||
int *live_var, int id, GLUI_CB callback )
|
||||
{
|
||||
common_construct(parent, name, GLUI_SPINNER_INT, live_var, id, callback);
|
||||
}
|
||||
|
||||
/****************************** GLUI_Spinner::GLUI_Spinner() ****************/
|
||||
|
||||
GLUI_Spinner::GLUI_Spinner( GLUI_Node* parent, const char *name,
|
||||
float *live_var, int id, GLUI_CB callback )
|
||||
{
|
||||
common_construct(parent, name, GLUI_SPINNER_FLOAT, live_var, id, callback);
|
||||
}
|
||||
|
||||
/****************************** GLUI_Spinner::GLUI_Spinner() ****************/
|
||||
|
||||
GLUI_Spinner::GLUI_Spinner( GLUI_Node *parent, const char *name,
|
||||
int data_t, void *live_var,
|
||||
int id, GLUI_CB callback )
|
||||
{
|
||||
common_construct(parent, name, data_t, live_var, id, callback);
|
||||
}
|
||||
|
||||
/****************************** GLUI_Spinner::common_construct() ************/
|
||||
|
||||
void GLUI_Spinner::common_construct( GLUI_Node* parent, const char *name,
|
||||
int data_t, void *data,
|
||||
int id, GLUI_CB cb )
|
||||
{
|
||||
common_init();
|
||||
|
||||
if ( NOT strcmp( name, "Spinner Test" ))
|
||||
id=id;
|
||||
|
||||
int text_type;
|
||||
if ( data_t == GLUI_SPINNER_INT ) {
|
||||
text_type = GLUI_EDITTEXT_INT;
|
||||
}
|
||||
else if ( data_t == GLUI_SPINNER_FLOAT ) {
|
||||
text_type = GLUI_EDITTEXT_FLOAT;
|
||||
}
|
||||
else {
|
||||
assert(0); /* Did not pass in a valid data type */
|
||||
}
|
||||
|
||||
user_id = id;
|
||||
data_type = data_t;
|
||||
callback = cb;
|
||||
set_name( name );
|
||||
//glui = parent->get_glui();
|
||||
|
||||
parent->add_control( this );
|
||||
|
||||
GLUI_EditText *txt =
|
||||
new GLUI_EditText( this, name, text_type, data, id, cb);
|
||||
|
||||
edittext = txt; /* Link the edittext to the spinner */
|
||||
/* control->ptr_val = data; */
|
||||
|
||||
edittext->spinner = this; /* Link the spinner to the edittext */
|
||||
|
||||
}
|
||||
|
||||
/****************************** GLUI_Spinner::mouse_down_handler() **********/
|
||||
|
||||
int GLUI_Spinner::mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
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_SPINNER_STATE_UP AND state != GLUI_SPINNER_STATE_DOWN )
|
||||
return true;
|
||||
|
||||
reset_growth();
|
||||
redraw();
|
||||
|
||||
/*** 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 ( data_type == GLUI_SPINNER_INT ) {
|
||||
if ( state == GLUI_SPINNER_STATE_UP )
|
||||
edittext->set_float_val( edittext->float_val + 1.0 );
|
||||
else if ( state == GLUI_SPINNER_STATE_DOWN )
|
||||
edittext->set_float_val( edittext->float_val - .9 );
|
||||
}
|
||||
|
||||
do_click();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/******************************** GLUI_Spinner::mouse_up_handler() **********/
|
||||
|
||||
int GLUI_Spinner::mouse_up_handler( int local_x, int local_y, bool inside )
|
||||
{
|
||||
state = GLUI_SPINNER_STATE_NONE;
|
||||
GLUI_Master.glui_setIdleFuncIfNecessary();
|
||||
|
||||
/* printf("spinner: mouse up : %d/%d inside: %d\n",local_x,local_y,inside); */
|
||||
|
||||
/*glutSetCursor( GLUT_CURSOR_INHERIT ); */
|
||||
glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
|
||||
redraw();
|
||||
|
||||
/* do_callbacks(); --- stub */
|
||||
/* if ( callback ) */
|
||||
/* callback( this->user_id ); */
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/***************************** GLUI_Spinner::mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_Spinner::mouse_held_down_handler( int local_x, int local_y,
|
||||
bool new_inside)
|
||||
{
|
||||
int new_state;
|
||||
|
||||
if ( state == GLUI_SPINNER_STATE_NONE )
|
||||
return false;
|
||||
|
||||
/* printf("spinner: mouse held: %d/%d inside: %d\n",local_x,local_y,
|
||||
new_inside);
|
||||
*/
|
||||
|
||||
if ( state == GLUI_SPINNER_STATE_BOTH ) { /* dragging? */
|
||||
do_drag( local_x, local_y );
|
||||
}
|
||||
else { /* not dragging */
|
||||
new_state = find_arrow( local_x, local_y );
|
||||
|
||||
if ( new_state == state ) {
|
||||
/** Still in same arrow **/
|
||||
do_click();
|
||||
}
|
||||
else {
|
||||
if ( new_inside OR 1) {
|
||||
/** The state changed, but we're still inside - that
|
||||
means we moved off the arrow: begin dragging **/
|
||||
state = GLUI_SPINNER_STATE_BOTH;
|
||||
}
|
||||
else {
|
||||
/*** Here check y of mouse position to determine whether to
|
||||
drag ***/
|
||||
|
||||
/* ... */
|
||||
}
|
||||
}
|
||||
|
||||
/*** We switched to up/down dragging ***/
|
||||
if ( state == GLUI_SPINNER_STATE_BOTH ) {
|
||||
glutSetCursor( GLUT_CURSOR_UP_DOWN );
|
||||
last_x = local_x;
|
||||
last_y = local_y;
|
||||
|
||||
/** If the spinner has limits, we reset the growth value, since
|
||||
reset_growth() will compute a new growth value for dragging
|
||||
vs. clicking. If the spinner has no limits, then we just let the
|
||||
growth remain at whatever the user has incremented it up to **/
|
||||
if ( edittext->has_limits != GLUI_LIMIT_NONE )
|
||||
reset_growth();
|
||||
}
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Spinner::key_handler() **********/
|
||||
|
||||
int GLUI_Spinner::key_handler( unsigned char key,int modifiers )
|
||||
{
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Spinner::draw() **********/
|
||||
|
||||
void GLUI_Spinner::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
if ( enabled ) {
|
||||
/*** Draw the up arrow either pressed or unrpessed ***/
|
||||
if ( state == GLUI_SPINNER_STATE_UP OR state == GLUI_SPINNER_STATE_BOTH )
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_SPINNER_UP_ON,
|
||||
w-GLUI_SPINNER_ARROW_WIDTH-1,
|
||||
GLUI_SPINNER_ARROW_Y);
|
||||
else
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_SPINNER_UP_OFF,
|
||||
w-GLUI_SPINNER_ARROW_WIDTH-1,
|
||||
GLUI_SPINNER_ARROW_Y);
|
||||
|
||||
/*** Draw the down arrow either pressed or unrpessed ***/
|
||||
if (state == GLUI_SPINNER_STATE_DOWN OR state == GLUI_SPINNER_STATE_BOTH)
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_SPINNER_DOWN_ON,
|
||||
w-GLUI_SPINNER_ARROW_WIDTH-1,
|
||||
GLUI_SPINNER_ARROW_HEIGHT+GLUI_SPINNER_ARROW_Y);
|
||||
else
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_SPINNER_DOWN_OFF,
|
||||
w-GLUI_SPINNER_ARROW_WIDTH-1,
|
||||
GLUI_SPINNER_ARROW_HEIGHT+GLUI_SPINNER_ARROW_Y);
|
||||
}
|
||||
else { /**** The spinner is disabled ****/
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_SPINNER_UP_DIS,
|
||||
w-GLUI_SPINNER_ARROW_WIDTH-1,
|
||||
GLUI_SPINNER_ARROW_Y);
|
||||
glui->std_bitmaps.draw( GLUI_STDBITMAP_SPINNER_DOWN_DIS,
|
||||
w-GLUI_SPINNER_ARROW_WIDTH-1,
|
||||
GLUI_SPINNER_ARROW_HEIGHT+GLUI_SPINNER_ARROW_Y);
|
||||
}
|
||||
|
||||
if ( active ) {
|
||||
glColor3ub( 0, 0, 0 );
|
||||
glEnable( GL_LINE_STIPPLE );
|
||||
glLineStipple( 1, 0x5555 );
|
||||
}
|
||||
else {
|
||||
glColor3ub( glui->bkgd_color.r,glui->bkgd_color.g,glui->bkgd_color.b );
|
||||
}
|
||||
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||||
glDisable( GL_CULL_FACE );
|
||||
glBegin( GL_QUADS );
|
||||
glVertex2i( w-GLUI_SPINNER_ARROW_WIDTH-2, 0 );
|
||||
glVertex2i( w, 0 );
|
||||
glVertex2i( w, h );
|
||||
glVertex2i( w-GLUI_SPINNER_ARROW_WIDTH-2, h );
|
||||
glEnd();
|
||||
glDisable( GL_LINE_STIPPLE );
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||||
}
|
||||
|
||||
|
||||
/********************************* GLUI_Spinner::special_handler() **********/
|
||||
|
||||
int GLUI_Spinner::special_handler( int key,int modifiers )
|
||||
{
|
||||
if ( key == GLUT_KEY_UP ) { /** Simulate a click in the up arrow **/
|
||||
mouse_down_handler( x_abs + w - GLUI_SPINNER_ARROW_WIDTH + 1,
|
||||
y_abs + GLUI_SPINNER_ARROW_Y+1 );
|
||||
mouse_up_handler( x_abs + w - GLUI_SPINNER_ARROW_WIDTH + 1,
|
||||
y_abs + GLUI_SPINNER_ARROW_Y+1, true );
|
||||
}
|
||||
else if ( key == GLUT_KEY_DOWN ) { /** Simulate a click in the up arrow **/
|
||||
mouse_down_handler(x_abs + w - GLUI_SPINNER_ARROW_WIDTH + 1,
|
||||
y_abs+GLUI_SPINNER_ARROW_Y+1+GLUI_SPINNER_ARROW_HEIGHT);
|
||||
mouse_up_handler( x_abs + w - GLUI_SPINNER_ARROW_WIDTH + 1,
|
||||
y_abs+GLUI_SPINNER_ARROW_Y+1 +GLUI_SPINNER_ARROW_HEIGHT,
|
||||
true );
|
||||
}
|
||||
else if ( key == GLUT_KEY_HOME ) { /** Set value to limit top -
|
||||
or increment by 10 **/
|
||||
}
|
||||
else if ( key == GLUT_KEY_END ) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI_Spinner::set_float_val() ************/
|
||||
|
||||
void GLUI_Spinner::set_float_val( float new_val )
|
||||
{
|
||||
if ( NOT edittext )
|
||||
return;
|
||||
|
||||
edittext->set_float_val( new_val );
|
||||
}
|
||||
|
||||
|
||||
/********************************** GLUI_Spinner::set_int_val() ************/
|
||||
|
||||
void GLUI_Spinner::set_int_val( int new_val )
|
||||
{
|
||||
if ( NOT edittext )
|
||||
return;
|
||||
|
||||
edittext->set_int_val( new_val );
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Spinner::update_size() **********/
|
||||
|
||||
void GLUI_Spinner::update_size( void )
|
||||
{
|
||||
if (!edittext) return;
|
||||
/*edittext->w = this->w - GLUI_SPINNER_ARROW_WIDTH-3; */
|
||||
this->w = edittext->w + GLUI_SPINNER_ARROW_WIDTH + 3;
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Spinner::find_arrow() ************/
|
||||
|
||||
int GLUI_Spinner::find_arrow( int local_x, int local_y )
|
||||
{
|
||||
local_x -= x_abs;
|
||||
local_y -= y_abs;
|
||||
|
||||
if ( local_x >= (w - GLUI_SPINNER_ARROW_WIDTH) AND
|
||||
local_x <= w ) {
|
||||
|
||||
if ( local_y >= GLUI_SPINNER_ARROW_Y AND
|
||||
local_y <= (GLUI_SPINNER_ARROW_Y+GLUI_SPINNER_ARROW_HEIGHT) )
|
||||
return GLUI_SPINNER_STATE_UP;
|
||||
|
||||
if ( local_y >= GLUI_SPINNER_ARROW_Y+GLUI_SPINNER_ARROW_HEIGHT AND
|
||||
local_y <= (GLUI_SPINNER_ARROW_Y+GLUI_SPINNER_ARROW_HEIGHT*2) )
|
||||
return GLUI_SPINNER_STATE_DOWN;
|
||||
|
||||
}
|
||||
|
||||
return GLUI_SPINNER_STATE_NONE;
|
||||
}
|
||||
|
||||
|
||||
/***************************************** GLUI_Spinner::do_click() **********/
|
||||
|
||||
void GLUI_Spinner::do_click( void )
|
||||
{
|
||||
int direction = 0;
|
||||
float incr;
|
||||
float modifier_factor;
|
||||
|
||||
if ( state == GLUI_SPINNER_STATE_UP )
|
||||
direction = +1;
|
||||
else if ( state == GLUI_SPINNER_STATE_DOWN )
|
||||
direction = -1;
|
||||
|
||||
increase_growth();
|
||||
|
||||
modifier_factor = 1.0;
|
||||
if ( glui ) {
|
||||
if ( glui->curr_modifiers & GLUT_ACTIVE_SHIFT )
|
||||
modifier_factor = 100.0f;
|
||||
else if ( glui->curr_modifiers & GLUT_ACTIVE_CTRL )
|
||||
modifier_factor = .01f;
|
||||
}
|
||||
|
||||
if ( this->data_type == GLUI_SPINNER_FLOAT OR 1) {
|
||||
incr = growth * direction * modifier_factor * user_speed;
|
||||
edittext->set_float_val( edittext->float_val + incr );
|
||||
/** Remember, edittext mirrors the float and int values ***/
|
||||
}
|
||||
|
||||
/*** Now update live variable and do callback. We don't want
|
||||
to do the callback on each iteration of this function, just on every
|
||||
i^th iteration, where i is given by GLUI_SPINNER_CALLBACK_INTERVAL ****/
|
||||
callback_count++;
|
||||
if ( (callback_count % GLUI_SPINNER_CALLBACK_INTERVAL ) == 0 )
|
||||
do_callbacks();
|
||||
}
|
||||
|
||||
|
||||
/***************************************** GLUI_Spinner::do_drag() **********/
|
||||
|
||||
void GLUI_Spinner::do_drag( int x, int y )
|
||||
{
|
||||
int delta_y;
|
||||
float incr, modifier_factor;
|
||||
/* int delta_x; */
|
||||
|
||||
modifier_factor = 1.0f;
|
||||
if ( glui ) {
|
||||
if ( glui->curr_modifiers & GLUT_ACTIVE_SHIFT )
|
||||
modifier_factor = 100.0f;
|
||||
else if ( glui->curr_modifiers & GLUT_ACTIVE_CTRL )
|
||||
modifier_factor = .01f;
|
||||
}
|
||||
|
||||
/* delta_x = x - last_x; */
|
||||
delta_y = -(y - last_y);
|
||||
|
||||
if ( this->data_type == GLUI_SPINNER_FLOAT OR 1 ) {
|
||||
incr = growth * delta_y * modifier_factor * user_speed;
|
||||
edittext->set_float_val( edittext->float_val + incr );
|
||||
/** Remember, edittext mirrors the float and int values ***/
|
||||
}
|
||||
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
|
||||
/*** Now update live variable and do callback. We don't want
|
||||
to do the callback on each iteration of this function, just on every
|
||||
i^th iteration, where i is given by GLUI_SPINNER_CALLBACK_INTERVAL ****/
|
||||
|
||||
callback_count++;
|
||||
if ( (callback_count % GLUI_SPINNER_CALLBACK_INTERVAL ) == 0 )
|
||||
do_callbacks();
|
||||
}
|
||||
|
||||
|
||||
/***************************************** GLUI_Spinner::needs_idle() ******/
|
||||
|
||||
bool GLUI_Spinner::needs_idle( void ) const
|
||||
{
|
||||
if (state == GLUI_SPINNER_STATE_UP OR state == GLUI_SPINNER_STATE_DOWN ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************** GLUI_Spinner::idle() **********/
|
||||
|
||||
void GLUI_Spinner::idle( void )
|
||||
{
|
||||
if ( NOT needs_idle() )
|
||||
return;
|
||||
else
|
||||
do_click();
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_Spinner::do_callbacks() **********/
|
||||
|
||||
void GLUI_Spinner::do_callbacks( void )
|
||||
{
|
||||
/*** This is not necessary, b/c edittext automatically updates us ***/
|
||||
if ( NOT edittext )
|
||||
return;
|
||||
this->float_val = edittext->float_val;
|
||||
this->int_val = edittext->int_val;
|
||||
/* *******************************************/
|
||||
|
||||
if ( NOT first_callback ) {
|
||||
if ( data_type == GLUI_SPINNER_INT AND int_val == last_int_val ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( data_type == GLUI_SPINNER_FLOAT AND float_val == last_float_val ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this->execute_callback();
|
||||
|
||||
last_int_val = int_val;
|
||||
last_float_val = float_val;
|
||||
first_callback = false;
|
||||
}
|
||||
|
||||
|
||||
/********************************* GLUI_Spinner::set_float_limits() *********/
|
||||
|
||||
void GLUI_Spinner::set_float_limits( float low, float high, int limit_type )
|
||||
{
|
||||
if ( NOT edittext )
|
||||
return;
|
||||
|
||||
edittext->set_float_limits( low, high, limit_type );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_Spinner::set_int_limits() *********/
|
||||
|
||||
void GLUI_Spinner::set_int_limits( int low, int high, int limit_type )
|
||||
{
|
||||
if ( NOT edittext )
|
||||
return;
|
||||
|
||||
edittext->set_int_limits( low, high, limit_type );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_Spinner:reset_growth() *************/
|
||||
|
||||
void GLUI_Spinner::reset_growth( void )
|
||||
{
|
||||
float lo, hi;
|
||||
|
||||
if ( edittext->has_limits == GLUI_LIMIT_NONE ) {
|
||||
if ( data_type == GLUI_SPINNER_FLOAT )
|
||||
growth = sqrt(ABS(edittext->float_val)) * .05f;
|
||||
else if ( data_type == GLUI_SPINNER_INT )
|
||||
growth = .4f;
|
||||
}
|
||||
else {
|
||||
if ( data_type == GLUI_SPINNER_FLOAT ) {
|
||||
lo = edittext->float_low;
|
||||
hi = edittext->float_high;
|
||||
growth = (hi-lo) / GLUI_SPINNER_GROWTH_STEPS;
|
||||
}
|
||||
else if ( data_type == GLUI_SPINNER_INT ) {
|
||||
lo = (float) edittext->int_low;
|
||||
hi = (float) edittext->int_high;
|
||||
|
||||
growth = (hi-lo) / GLUI_SPINNER_GROWTH_STEPS;
|
||||
}
|
||||
}
|
||||
|
||||
if ( growth == 0.0f )
|
||||
growth = .001f;
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI_Spinner:increase_growth() *************/
|
||||
|
||||
void GLUI_Spinner::increase_growth( void )
|
||||
{
|
||||
float hi = 0.0,lo = 0.0;
|
||||
|
||||
if ( data_type == GLUI_SPINNER_FLOAT ) {
|
||||
lo = edittext->float_low;
|
||||
hi = edittext->float_high;
|
||||
}
|
||||
else if ( data_type == GLUI_SPINNER_INT ) {
|
||||
lo = (float) edittext->int_low;
|
||||
hi = (float) edittext->int_high;
|
||||
}
|
||||
|
||||
if ( growth < (hi-lo) / GLUI_SPINNER_MIN_GROWTH_STEPS )
|
||||
growth *= growth_exp;
|
||||
|
||||
/* printf( "growth: %f\n", growth ); */
|
||||
}
|
||||
|
||||
|
||||
/*************************************** GLUI_Spinner:get_text() *************/
|
||||
|
||||
const char *GLUI_Spinner::get_text( void )
|
||||
{
|
||||
if (edittext)
|
||||
return edittext->text.c_str();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/********************************** GLUI_Spinner:get_float_val() *************/
|
||||
|
||||
float GLUI_Spinner::get_float_val( void )
|
||||
{
|
||||
if (edittext)
|
||||
return edittext->float_val;
|
||||
else
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
/********************************** GLUI_Spinner:get_int_val() *************/
|
||||
|
||||
int GLUI_Spinner::get_int_val( void )
|
||||
{
|
||||
if (edittext)
|
||||
return edittext->int_val;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
105
Extras/glui/glui_statictext.cpp
Normal file
105
Extras/glui/glui_statictext.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_statictext.cpp - GLUI_StaticText Control
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
/****************************** GLUI_StaticText::GLUI_StaticText() **********/
|
||||
GLUI_StaticText::GLUI_StaticText( GLUI_Node *parent, const char *name )
|
||||
{
|
||||
common_init();
|
||||
set_name( name );
|
||||
parent->add_control( this );
|
||||
}
|
||||
|
||||
/****************************** GLUI_StaticText::draw() **********/
|
||||
|
||||
void GLUI_StaticText::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
draw_text();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_StaticText::set_text() **********/
|
||||
|
||||
void GLUI_StaticText::set_text( const char *text )
|
||||
{
|
||||
set_name( text );
|
||||
redraw();
|
||||
}
|
||||
|
||||
|
||||
/************************************ GLUI_StaticText::update_size() **********/
|
||||
|
||||
void GLUI_StaticText::update_size( void )
|
||||
{
|
||||
int text_size;
|
||||
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
text_size = string_width( name );
|
||||
|
||||
if ( w < text_size )
|
||||
w = text_size;
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_StaticText::draw_text() **********/
|
||||
|
||||
void GLUI_StaticText::draw_text( void )
|
||||
{
|
||||
if ( NOT can_draw() )
|
||||
return;
|
||||
|
||||
erase_text();
|
||||
draw_name( 0, 9 );
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_StaticText::erase_text() **********/
|
||||
|
||||
void GLUI_StaticText::erase_text( void )
|
||||
{
|
||||
if ( NOT can_draw() )
|
||||
return;
|
||||
|
||||
set_to_bkgd_color();
|
||||
glDisable( GL_CULL_FACE );
|
||||
glBegin( GL_TRIANGLES );
|
||||
glVertex2i( 0,0 ); glVertex2i( w, 0 ); glVertex2i( w, h );
|
||||
glVertex2i( 0, 0 ); glVertex2i( w, h ); glVertex2i( 0, h );
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
62
Extras/glui/glui_string.cpp
Normal file
62
Extras/glui/glui_string.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui.cpp
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher (this file, Bill Baxter 2005)
|
||||
|
||||
This library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA
|
||||
|
||||
This program is -not- in the public domain.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#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,299,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;
|
||||
}
|
||||
1108
Extras/glui/glui_textbox.cpp
Normal file
1108
Extras/glui/glui_textbox.cpp
Normal file
File diff suppressed because it is too large
Load Diff
559
Extras/glui/glui_translation.cpp
Normal file
559
Extras/glui/glui_translation.cpp
Normal file
@@ -0,0 +1,559 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_translation - GLUI_Translation control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "GL/glui.h"
|
||||
#include "glui_internal.h"
|
||||
#include "algebra3.h"
|
||||
|
||||
/********************** GLUI_Translation::GLUI_Translation() ***/
|
||||
|
||||
GLUI_Translation::GLUI_Translation(
|
||||
GLUI_Node *parent, const char *name,
|
||||
int trans_t, float *value_ptr,
|
||||
int id, GLUI_CB cb )
|
||||
{
|
||||
common_init();
|
||||
|
||||
set_ptr_val( value_ptr );
|
||||
user_id = id;
|
||||
set_name( name );
|
||||
callback = cb;
|
||||
parent->add_control( this );
|
||||
//init_live();
|
||||
|
||||
trans_type = trans_t;
|
||||
|
||||
if ( trans_type == GLUI_TRANSLATION_XY ) {
|
||||
float_array_size = 2;
|
||||
}
|
||||
else if ( trans_type == GLUI_TRANSLATION_X ) {
|
||||
float_array_size = 1;
|
||||
}
|
||||
else if ( trans_type == GLUI_TRANSLATION_Y ) {
|
||||
float_array_size = 1;
|
||||
}
|
||||
else if ( trans_type == GLUI_TRANSLATION_Z ) {
|
||||
float_array_size = 1;
|
||||
}
|
||||
init_live();
|
||||
}
|
||||
|
||||
/********************** GLUI_Translation::iaction_mouse_down_handler() ***/
|
||||
/* These are really in local coords (5/10/99) */
|
||||
|
||||
int GLUI_Translation::iaction_mouse_down_handler( int local_x,
|
||||
int local_y )
|
||||
{
|
||||
int center_x, center_y;
|
||||
|
||||
down_x = local_x;
|
||||
down_y = local_y;
|
||||
|
||||
if ( trans_type == GLUI_TRANSLATION_XY ) {
|
||||
orig_x = float_array_val[0];
|
||||
orig_y = float_array_val[1];
|
||||
|
||||
/** Check if the Alt key is down, which means lock to an axis **/
|
||||
|
||||
center_x = w/2;
|
||||
center_y = (h-18)/2;
|
||||
|
||||
if ( glui->curr_modifiers & GLUT_ACTIVE_ALT ) {
|
||||
if ( ABS(local_y-center_y) > ABS(local_x-center_x) ) {
|
||||
locked = GLUI_TRANSLATION_LOCK_Y;
|
||||
glutSetCursor( GLUT_CURSOR_UP_DOWN );
|
||||
}
|
||||
else {
|
||||
locked = GLUI_TRANSLATION_LOCK_X;
|
||||
glutSetCursor( GLUT_CURSOR_LEFT_RIGHT );
|
||||
}
|
||||
}
|
||||
else {
|
||||
locked = GLUI_TRANSLATION_LOCK_NONE;
|
||||
glutSetCursor( GLUT_CURSOR_SPRAY );
|
||||
}
|
||||
}
|
||||
else if ( trans_type == GLUI_TRANSLATION_X ) {
|
||||
glutSetCursor( GLUT_CURSOR_LEFT_RIGHT );
|
||||
orig_x = float_array_val[0];
|
||||
}
|
||||
else if ( trans_type == GLUI_TRANSLATION_Y ) {
|
||||
glutSetCursor( GLUT_CURSOR_UP_DOWN );
|
||||
orig_y = float_array_val[0];
|
||||
}
|
||||
else if ( trans_type == GLUI_TRANSLATION_Z ) {
|
||||
glutSetCursor( GLUT_CURSOR_UP_DOWN );
|
||||
orig_z = float_array_val[0];
|
||||
}
|
||||
|
||||
trans_mouse_code = 1;
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*********************** GLUI_Translation::iaction_mouse_up_handler() **********/
|
||||
|
||||
int GLUI_Translation::iaction_mouse_up_handler( int local_x, int local_y,
|
||||
bool inside )
|
||||
{
|
||||
trans_mouse_code = GLUI_TRANSLATION_MOUSE_NONE;
|
||||
locked = GLUI_TRANSLATION_LOCK_NONE;
|
||||
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/******************* GLUI_Translation::iaction_mouse_held_down_handler() ******/
|
||||
|
||||
int GLUI_Translation::iaction_mouse_held_down_handler( int local_x, int local_y,
|
||||
bool inside)
|
||||
{
|
||||
float x_off, y_off;
|
||||
float off_array[2];
|
||||
|
||||
x_off = scale_factor * (float)(local_x - down_x);
|
||||
y_off = -scale_factor * (float)(local_y - down_y);
|
||||
|
||||
if ( glui->curr_modifiers & GLUT_ACTIVE_SHIFT ) {
|
||||
x_off *= 100.0f;
|
||||
y_off *= 100.0f;
|
||||
}
|
||||
else if ( glui->curr_modifiers & GLUT_ACTIVE_CTRL ) {
|
||||
x_off *= .01f;
|
||||
y_off *= .01f;
|
||||
}
|
||||
|
||||
|
||||
if ( trans_type == GLUI_TRANSLATION_XY ) {
|
||||
|
||||
if ( locked == GLUI_TRANSLATION_LOCK_X )
|
||||
y_off = 0.0;
|
||||
else if ( locked == GLUI_TRANSLATION_LOCK_Y )
|
||||
x_off = 0.0;
|
||||
|
||||
off_array[0] = x_off + orig_x;
|
||||
off_array[1] = y_off + orig_y;
|
||||
}
|
||||
else if ( trans_type == GLUI_TRANSLATION_X ) {
|
||||
off_array[0] = x_off + orig_x;
|
||||
}
|
||||
else if ( trans_type == GLUI_TRANSLATION_Y ) {
|
||||
off_array[0] = y_off + orig_y;
|
||||
}
|
||||
else if ( trans_type == GLUI_TRANSLATION_Z ) {
|
||||
off_array[0] = y_off + orig_z;
|
||||
}
|
||||
|
||||
set_float_array_val( (float*) &off_array[0] );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/******************** GLUI_Translation::iaction_draw_active_area_persp() **************/
|
||||
|
||||
void GLUI_Translation::iaction_draw_active_area_persp( void )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/******************** GLUI_Translation::iaction_draw_active_area_ortho() **********/
|
||||
|
||||
void GLUI_Translation::iaction_draw_active_area_ortho( void )
|
||||
{
|
||||
/********* Draw emboss circles around arcball control *********/
|
||||
float radius;
|
||||
radius = (float)(h-22)/2.0; /* MIN((float)w/2.0, (float)h/2.0); */
|
||||
glLineWidth( 1.0 );
|
||||
|
||||
draw_emboss_box( (int) -radius-2, (int)radius+2,
|
||||
(int)-radius-2, (int)radius+2 );
|
||||
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
glTranslatef( .5, .5, .5 );
|
||||
/* glScalef( radius-1.0, radius-1.0, radius-1.0 ); */
|
||||
if ( trans_type == GLUI_TRANSLATION_Z )
|
||||
draw_2d_z_arrows((int)radius-1);
|
||||
else if ( trans_type == GLUI_TRANSLATION_XY )
|
||||
draw_2d_xy_arrows((int)radius-1);
|
||||
else if ( trans_type == GLUI_TRANSLATION_X )
|
||||
draw_2d_x_arrows((int)radius-1);
|
||||
else if ( trans_type == GLUI_TRANSLATION_Y )
|
||||
draw_2d_y_arrows((int)radius-1);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
/******************************** GLUI_Translation::iaction_dump() **********/
|
||||
|
||||
void GLUI_Translation::iaction_dump( FILE *output )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/******************** GLUI_Translation::iaction_special_handler() **********/
|
||||
|
||||
int GLUI_Translation::iaction_special_handler( int key,int modifiers )
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************** GLUI_Translation::draw_2d_z_arrows() **************/
|
||||
|
||||
void GLUI_Translation::draw_2d_z_arrows( int radius )
|
||||
{
|
||||
if ( trans_mouse_code != GLUI_TRANSLATION_MOUSE_NONE ) {
|
||||
draw_2d_arrow(radius, true, 2);
|
||||
draw_2d_arrow(radius, true, 0);
|
||||
}
|
||||
else {
|
||||
draw_2d_arrow(radius, false, 2);
|
||||
draw_2d_arrow(radius, false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*************************** GLUI_Translation::draw_2d_x_arrows() **************/
|
||||
|
||||
void GLUI_Translation::draw_2d_x_arrows( int radius )
|
||||
{
|
||||
if ( trans_mouse_code != GLUI_TRANSLATION_MOUSE_NONE ) {
|
||||
draw_2d_arrow(radius, true, 1);
|
||||
draw_2d_arrow(radius, true, 3);
|
||||
}
|
||||
else {
|
||||
draw_2d_arrow(radius, false, 1);
|
||||
draw_2d_arrow(radius, false, 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*************************** GLUI_Translation::draw_2d_y_arrows() **************/
|
||||
|
||||
void GLUI_Translation::draw_2d_y_arrows( int radius )
|
||||
{
|
||||
if ( trans_mouse_code != GLUI_TRANSLATION_MOUSE_NONE ) {
|
||||
draw_2d_arrow(radius, true, 0);
|
||||
draw_2d_arrow(radius, true, 2);
|
||||
}
|
||||
else {
|
||||
draw_2d_arrow(radius, false, 0);
|
||||
draw_2d_arrow(radius, false, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************** GLUI_Translation::draw_2d_xy_arrows() **************/
|
||||
|
||||
void GLUI_Translation::draw_2d_xy_arrows( int radius)
|
||||
{
|
||||
if ( trans_mouse_code != GLUI_TRANSLATION_MOUSE_NONE ) {
|
||||
if ( locked == GLUI_TRANSLATION_LOCK_X ) {
|
||||
draw_2d_arrow(radius, false, 0);
|
||||
draw_2d_arrow(radius, false, 2);
|
||||
draw_2d_arrow(radius, true, 1);
|
||||
draw_2d_arrow(radius, true, 3);
|
||||
}
|
||||
else if ( locked == GLUI_TRANSLATION_LOCK_Y ) {
|
||||
draw_2d_arrow(radius, false, 1);
|
||||
draw_2d_arrow(radius, false, 3);
|
||||
draw_2d_arrow(radius, true, 0);
|
||||
draw_2d_arrow(radius, true, 2);
|
||||
}
|
||||
else {
|
||||
draw_2d_arrow(radius, true, 0);
|
||||
draw_2d_arrow(radius, true, 1);
|
||||
draw_2d_arrow(radius, true, 2);
|
||||
draw_2d_arrow(radius, true, 3);
|
||||
}
|
||||
}
|
||||
else {
|
||||
draw_2d_arrow(radius, false, 0);
|
||||
draw_2d_arrow(radius, false, 1);
|
||||
draw_2d_arrow(radius, false, 2);
|
||||
draw_2d_arrow(radius, false, 3);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*************************** GLUI_Translation::draw_2d_arrow() **************/
|
||||
/* ori: 0=up, 1=left, 2=down, 3=right */
|
||||
/* */
|
||||
/* */
|
||||
/* 0, y2 */
|
||||
/* / \ */
|
||||
/* / \ */
|
||||
/* / \ */
|
||||
/* / \ */
|
||||
/* / \ */
|
||||
/* / \ */
|
||||
/* / \ */
|
||||
/* / \ */
|
||||
/* -x2,y1 -x1b,y1 x1b,y1 x2,y1 */
|
||||
/* | | */
|
||||
/* | | */
|
||||
/* | | */
|
||||
/* | | */
|
||||
/* | | */
|
||||
/* -x1a,y0 x1a,y0 */
|
||||
/* */
|
||||
|
||||
|
||||
void GLUI_Translation::draw_2d_arrow( int radius, int filled, int orientation )
|
||||
{
|
||||
float x1 = .2, x2 = .4, y1 = .54, y2 = .94, y0;
|
||||
float x1a, x1b;
|
||||
/*
|
||||
vec3 col1( 0.0, 0.0, 0.0 ), col2( .45, .45, .45 ),
|
||||
col3( .7, .7, .7 ), col4( 1.0, 1.0, 1.0 );
|
||||
vec3 c1, c2, c3, c4, c5, c6;
|
||||
*/
|
||||
vec3 white(1.0,1.0,1.0), black(0.0,0.0,0.0), gray(.45,.45,.45),
|
||||
bkgd(.7,.7,.7);
|
||||
int c_off=0; /* color index offset */
|
||||
|
||||
if ( glui )
|
||||
bkgd.set(glui->bkgd_color_f[0],
|
||||
glui->bkgd_color_f[1],
|
||||
glui->bkgd_color_f[2]);
|
||||
|
||||
/* bkgd[0] = 255.0; bkgd[1] = 0; */
|
||||
|
||||
/** The following 8 colors define the shading of an octagon, in
|
||||
clockwise order, starting from the upstroke on the left **/
|
||||
/** This is for an outside and inside octagons **/
|
||||
vec3 colors_out[]={white, white, white, gray, black, black, black, gray};
|
||||
vec3 colors_in[] ={bkgd,white,bkgd,gray,gray,gray,gray,gray};
|
||||
|
||||
#define SET_COL_OUT(i) glColor3fv((float*) &colors_out[(i)%8][0]);
|
||||
#define SET_COL_IN(i) glColor3fv((float*) &colors_in[(i)%8][0]);
|
||||
|
||||
x1 = (float)radius * .2;
|
||||
x2 = x1 * 2;
|
||||
y1 = (float)radius * .54;
|
||||
y2 = y1 + x2;
|
||||
x1a = x1;
|
||||
x1b = x1;
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
#define DRAW_SEG( xa,ya,xb,yb ) glVertex2f(xa,ya); glVertex2f(xb,yb);
|
||||
|
||||
glScalef( -1.0, 1.0, 1.0 );
|
||||
|
||||
if ( orientation == 2 ) {
|
||||
c_off = 4;
|
||||
}
|
||||
else if ( orientation == 0 ) {
|
||||
c_off = 0;
|
||||
glRotatef( 180.0, 0.0, 0.0, 1.0 );
|
||||
}
|
||||
else if ( orientation == 1 ) {
|
||||
c_off = 2;
|
||||
glRotatef( 90.0, 0.0, 0.0, 1.0 );
|
||||
}
|
||||
else if ( orientation == 3 ) {
|
||||
c_off = 6;
|
||||
glRotatef( -90.0, 0.0, 0.0, 1.0 );
|
||||
}
|
||||
|
||||
if ( trans_type == GLUI_TRANSLATION_Z )
|
||||
y0 = 0.0;
|
||||
else if ( trans_type == GLUI_TRANSLATION_XY )
|
||||
y0 = x1;
|
||||
else
|
||||
y0 = 0.0;
|
||||
|
||||
|
||||
if ( trans_type == GLUI_TRANSLATION_Z ) {
|
||||
if ( orientation == 0 ) {
|
||||
y1 += 2.0;
|
||||
y2 += 0.0;
|
||||
|
||||
x1b -= 2.0;
|
||||
x2 -= 2.0;
|
||||
x1a += 2.0;
|
||||
}
|
||||
else if ( orientation == 2 ) {
|
||||
y1 -= 6.0;
|
||||
x1a += 2.0;
|
||||
x1b += 4.0;
|
||||
x2 += 6.0;
|
||||
}
|
||||
}
|
||||
|
||||
/*** Fill in inside of arrow ***/
|
||||
if ( NOT filled ) { /*** Means button is up - control is not clicked ***/
|
||||
/*glColor3f( .8, .8, .8 ); */
|
||||
set_to_bkgd_color();
|
||||
glColor3f( bkgd[0]+.07, bkgd[1]+.07, bkgd[2]+.07 );
|
||||
}
|
||||
else { /*** Button is down on control ***/
|
||||
glColor3f( .6, .6, .6 );
|
||||
c_off += 4; /* Indents the shadows - goes from a raised look to embossed */
|
||||
}
|
||||
|
||||
/*** Check if control is enabled or not ***/
|
||||
if ( NOT enabled ) {
|
||||
set_to_bkgd_color();
|
||||
/*c_off += 4; -- Indents the shadows - goes from a raised look to embossed */
|
||||
colors_out[0] = colors_out[1] = colors_out[2] = colors_out[7] = gray;
|
||||
colors_out[3] = colors_out[4] = colors_out[5] = colors_out[6] = white;
|
||||
colors_in[0] = colors_in[1] = colors_in[2] = colors_in[7] = white;
|
||||
colors_in[3] = colors_in[4] = colors_in[5] = colors_in[6] = gray;
|
||||
|
||||
}
|
||||
|
||||
glBegin( GL_POLYGON );
|
||||
glVertex2f( 0.0, 0.0 ); glVertex2f( -x1a, 0.0 );
|
||||
glVertex2f( -x1a, 0.0 ); glVertex2f( -x1b, y1 );
|
||||
glVertex2f( x1b, y1); glVertex2f( x1a, 0.0 );
|
||||
glVertex2f( x1a, 0.0 ); glVertex2f( 0.0, 0.0 );
|
||||
glEnd();
|
||||
glBegin( GL_TRIANGLES );
|
||||
glVertex2f( -x2, y1 ); glVertex2f( 0.0, y2 ); glVertex2f( x2, y1 );
|
||||
glEnd();
|
||||
|
||||
glLineWidth( 1.0 );
|
||||
/*** Draw arrow outline ***/
|
||||
glBegin( GL_LINES );
|
||||
|
||||
SET_COL_IN(1+c_off); DRAW_SEG( 0.0, y2-1.0, -x2, y1-1.0 );
|
||||
SET_COL_IN(6+c_off); DRAW_SEG( -x2+2.0, y1+1.0, -x1b+1.0, y1+1.0 );
|
||||
SET_COL_IN(0+c_off); DRAW_SEG( -x1b+1.0, y1+1.0, -x1a+1.0, y0 );
|
||||
SET_COL_IN(3+c_off); DRAW_SEG( 0.0, y2-1.0, x2, y1-1.0 );
|
||||
SET_COL_IN(6+c_off); DRAW_SEG( x2-1.0, y1+1.0, x1b-1.0, y1+1.0 );
|
||||
SET_COL_IN(4+c_off); DRAW_SEG( x1b-1.0, y1+1.0, x1a-1.0, y0 );
|
||||
|
||||
SET_COL_OUT(0+c_off); DRAW_SEG( -x1a, y0, -x1b, y1 );
|
||||
SET_COL_OUT(6+c_off); DRAW_SEG( -x1b, y1, -x2, y1 );
|
||||
SET_COL_OUT(1+c_off); DRAW_SEG( -x2, y1, 0.0, y2 );
|
||||
SET_COL_OUT(3+c_off); DRAW_SEG( 0.0, y2, x2, y1 );
|
||||
SET_COL_OUT(6+c_off); DRAW_SEG( x2, y1, x1b, y1 );
|
||||
SET_COL_OUT(4+c_off); DRAW_SEG( x1b, y1, x1a, y0 );
|
||||
|
||||
glEnd();
|
||||
|
||||
#undef DRAW_SEG
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
/*************************** GLUI_Translation::get_mouse_code() *************/
|
||||
|
||||
int GLUI_Translation::get_mouse_code( int x, int y )
|
||||
{
|
||||
if ( x == 0 AND y < 0 )
|
||||
return GLUI_TRANSLATION_MOUSE_DOWN;
|
||||
else if ( x == 0 AND y > 0 )
|
||||
return GLUI_TRANSLATION_MOUSE_UP;
|
||||
else if ( x > 0 AND y == 0 )
|
||||
return GLUI_TRANSLATION_MOUSE_LEFT;
|
||||
else if ( x < 0 AND y == 0 )
|
||||
return GLUI_TRANSLATION_MOUSE_RIGHT;
|
||||
else if ( x < 0 AND y < 0 )
|
||||
return GLUI_TRANSLATION_MOUSE_DOWN_LEFT;
|
||||
else if ( x < 0 AND y > 0 )
|
||||
return GLUI_TRANSLATION_MOUSE_DOWN_RIGHT;
|
||||
else if ( x > 0 AND y < 0 )
|
||||
return GLUI_TRANSLATION_MOUSE_UP_LEFT;
|
||||
else if ( x > 0 AND y > 0 )
|
||||
return GLUI_TRANSLATION_MOUSE_UP_RIGHT;
|
||||
|
||||
|
||||
return GLUI_TRANSLATION_MOUSE_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_Translation::set_x() ******/
|
||||
|
||||
void GLUI_Translation::set_x( float val )
|
||||
{
|
||||
set_one_val( val, 0 );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_Translation::set_y() ******/
|
||||
|
||||
void GLUI_Translation::set_y( float val )
|
||||
{
|
||||
if ( trans_type == GLUI_TRANSLATION_XY )
|
||||
set_one_val( val, 1 );
|
||||
else
|
||||
set_one_val( val, 0 );
|
||||
}
|
||||
|
||||
|
||||
/*********************************** GLUI_Translation::set_z() ******/
|
||||
|
||||
void GLUI_Translation::set_z( float val )
|
||||
{
|
||||
set_one_val( val, 0 );
|
||||
}
|
||||
|
||||
|
||||
/******************************* GLUI_Translation::set_one_val() ****/
|
||||
|
||||
void GLUI_Translation::set_one_val( float val, int index )
|
||||
{
|
||||
float *fp;
|
||||
|
||||
float_array_val[index] = val; /* set value in array */
|
||||
|
||||
/*** The code below is like output_live, except it only operates on
|
||||
a single member of the float array (given by 'index') instead of
|
||||
outputting the entire array ****/
|
||||
|
||||
if ( ptr_val == NULL OR NOT live_inited )
|
||||
return;
|
||||
|
||||
fp = (float*) ptr_val;
|
||||
fp[index] = float_array_val[index];
|
||||
last_live_float_array[index] = float_array_val[index];
|
||||
|
||||
/** Update the main gfx window? **/
|
||||
if ( this->glui != NULL ) {
|
||||
this->glui->post_update_main_gfx();
|
||||
}
|
||||
}
|
||||
278
Extras/glui/glui_tree.cpp
Normal file
278
Extras/glui/glui_tree.cpp
Normal file
@@ -0,0 +1,278 @@
|
||||
/****************************************************************************
|
||||
|
||||
GLUI User Interface Toolkit
|
||||
---------------------------
|
||||
|
||||
glui_panel.cpp - GLUI_Panel control class
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
This program is freely distributable without licensing fees and is
|
||||
provided without guarantee or warrantee expressed or implied. This
|
||||
program is -not- in the public domain.
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include "glui_internal_control.h"
|
||||
|
||||
|
||||
/****************************** GLUI_Tree::GLUI_Tree() **********/
|
||||
GLUI_Tree::GLUI_Tree(GLUI_Node *parent, const char *name,
|
||||
int open, int inset)
|
||||
{
|
||||
common_init();
|
||||
GLUI_StaticText *inset_label;
|
||||
GLUI_Column *col;
|
||||
|
||||
this->set_name( name );
|
||||
this->user_id = -1;
|
||||
|
||||
if ( NOT open ) {
|
||||
this->is_open = false;
|
||||
this->h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
|
||||
}
|
||||
|
||||
parent->add_control( this );
|
||||
inset_label = new GLUI_StaticText(this,"");
|
||||
inset_label->set_w(inset);
|
||||
col = new GLUI_Column(this,true);
|
||||
this->set_column(col);
|
||||
this->set_alignment(GLUI_ALIGN_LEFT);
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Tree::open() **********/
|
||||
|
||||
void GLUI_Tree::open( void )
|
||||
{
|
||||
if ( is_open )
|
||||
return;
|
||||
is_open = true;
|
||||
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
child_head = collapsed_node.child_head;
|
||||
child_tail = collapsed_node.child_tail;
|
||||
|
||||
collapsed_node.child_head = NULL;
|
||||
collapsed_node.child_tail = NULL;
|
||||
|
||||
if ( child_head != NULL ) {
|
||||
((GLUI_Control*) child_head)->unhide_internal( true );
|
||||
}
|
||||
|
||||
glui->refresh();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_Tree::close() **********/
|
||||
|
||||
void GLUI_Tree::close( void )
|
||||
{
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
if ( NOT is_open )
|
||||
return;
|
||||
is_open = false;
|
||||
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
|
||||
if ( child_head != NULL ) {
|
||||
((GLUI_Control*) child_head)->hide_internal( true );
|
||||
}
|
||||
|
||||
collapsed_node.child_head = first_child();
|
||||
collapsed_node.child_tail = last_child();
|
||||
|
||||
child_head = NULL;
|
||||
child_tail = NULL;
|
||||
|
||||
this->h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
|
||||
|
||||
glui->refresh();
|
||||
}
|
||||
|
||||
|
||||
/**************************** GLUI_Tree::mouse_down_handler() **********/
|
||||
|
||||
|
||||
int GLUI_Tree::mouse_down_handler( int local_x, int local_y )
|
||||
{
|
||||
if ( local_y - y_abs > 18 ) {
|
||||
initially_inside = currently_inside = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
currently_inside = true;
|
||||
initially_inside = true;
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**************************** GLUI_Tree::mouse_held_down_handler() ****/
|
||||
|
||||
int GLUI_Tree::mouse_held_down_handler(
|
||||
int local_x, int local_y,
|
||||
bool new_inside )
|
||||
{
|
||||
if ( NOT initially_inside )
|
||||
return false;
|
||||
|
||||
if ( local_y - y_abs> 18 )
|
||||
new_inside = false;
|
||||
|
||||
if (currently_inside != new_inside)
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**************************** GLUI_Tree::mouse_down_handler() **********/
|
||||
|
||||
int GLUI_Tree::mouse_up_handler( int local_x, int local_y, bool inside )
|
||||
{
|
||||
if ( currently_inside ) {
|
||||
if ( is_open )
|
||||
close();
|
||||
else
|
||||
open();
|
||||
}
|
||||
|
||||
currently_inside = false;
|
||||
initially_inside = false;
|
||||
redraw();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/********************************* GLUI_Tree::draw() ***********/
|
||||
|
||||
void GLUI_Tree::draw( int x, int y )
|
||||
{
|
||||
GLUI_DRAWINGSENTINAL_IDIOM
|
||||
int left, right, top, bottom, delta_x;
|
||||
|
||||
left = 5;
|
||||
right = w-left;
|
||||
top = 3;
|
||||
bottom = 3+16;
|
||||
delta_x = 0;
|
||||
|
||||
glui->draw_raised_box( left, top, 16, 16 );
|
||||
|
||||
if ( glui )
|
||||
glColor3ub(glui->bkgd_color.r,glui->bkgd_color.g,glui->bkgd_color.b);
|
||||
glDisable( GL_CULL_FACE );
|
||||
glBegin( GL_QUADS );
|
||||
glVertex2i( left+17, top+1 ); glVertex2i( right-1, top+1 );
|
||||
glVertex2i( right-1, bottom-1 ); glVertex2i( left+17, bottom-1 );
|
||||
glEnd();
|
||||
|
||||
if (format & GLUI_TREEPANEL_DISPLAY_HIERARCHY) {
|
||||
delta_x = string_width( level_name ) + char_width(' ');
|
||||
glColor3f( lred, lgreen, lblue); /* The hierarchy is drawn in bold */
|
||||
glRasterPos2i(left + 25, top + 11);
|
||||
draw_string(level_name);
|
||||
glRasterPos2i(left + 24, top + 11);
|
||||
draw_string(level_name);
|
||||
}
|
||||
|
||||
draw_name( delta_x+left+24, top+11 );
|
||||
|
||||
if ( active )
|
||||
draw_active_box( left+22, delta_x+left+string_width( name )+32,
|
||||
top, bottom-2 );
|
||||
|
||||
|
||||
/** Draw '+' or '-' **/
|
||||
|
||||
glBegin( GL_LINES );
|
||||
if ( is_open ) {
|
||||
if ( enabled )
|
||||
if (is_current)
|
||||
glColor3f( 0, 0, 1 );
|
||||
else
|
||||
glColor3f( 0.0, 0.0, 0.0 );
|
||||
else
|
||||
glColor3f( 0.5, 0.5, 0.5 );
|
||||
glVertex2i(left+4,(top+bottom)/2); glVertex2i(left+13,(top+bottom)/2);
|
||||
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glVertex2i(left+4,1+(top+bottom)/2);glVertex2i(left+13,1+(top+bottom)/2);
|
||||
}
|
||||
else
|
||||
{
|
||||
glColor3f( 1.0, 1.0, 1.0 );
|
||||
glVertex2i(left+9,top+3); glVertex2i(left+9,bottom-4);
|
||||
glVertex2i(left+4,(top+bottom)/2); glVertex2i(left+13,(top+bottom)/2);
|
||||
|
||||
if ( enabled )
|
||||
if (is_current)
|
||||
glColor3f( 0, 0, 1 );
|
||||
else
|
||||
glColor3f( 0.0, 0.0, 0.0 );
|
||||
else
|
||||
glColor3f( 0.5, 0.5, 0.5 );
|
||||
glVertex2i(left+4,-1+(top+bottom)/2);
|
||||
glVertex2i(left+13,-1+(top+bottom)/2);
|
||||
glVertex2i(left+8,top+3);
|
||||
glVertex2i(left+8,bottom-4);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glLineWidth( 1.0 );
|
||||
|
||||
if (currently_inside) draw_pressed();
|
||||
}
|
||||
|
||||
|
||||
/***************************** GLUI_Tree::update_size() **********/
|
||||
|
||||
void GLUI_Tree::update_size( void )
|
||||
{
|
||||
int text_size = 0, delta_x = 0;
|
||||
|
||||
if ( NOT glui )
|
||||
return;
|
||||
|
||||
text_size = string_width(name);
|
||||
|
||||
if (format & GLUI_TREEPANEL_DISPLAY_HIERARCHY) {
|
||||
delta_x = string_width( level_name );
|
||||
}
|
||||
|
||||
if ( w < text_size + 36 + delta_x)
|
||||
w = text_size + 36 + delta_x;
|
||||
}
|
||||
|
||||
|
||||
/**************************** GLUI_Tree::draw_pressed() ***********/
|
||||
|
||||
void GLUI_Tree::draw_pressed( void )
|
||||
{
|
||||
int left, right, top, bottom;
|
||||
|
||||
left = 5;
|
||||
right = w-left;
|
||||
top = 3;
|
||||
bottom = 3+16;
|
||||
|
||||
glColor3f( 0.0, 0.0, 0.0 );
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( left, top ); glVertex2i( right, top );
|
||||
glVertex2i( right, bottom ); glVertex2i( left,bottom );
|
||||
glEnd();
|
||||
|
||||
glBegin( GL_LINE_LOOP );
|
||||
glVertex2i( left+1, top+1 ); glVertex2i( right-1, top+1 );
|
||||
glVertex2i( right-1, bottom-1 ); glVertex2i( left+1,bottom-1 );
|
||||
glEnd();
|
||||
}
|
||||
387
Extras/glui/glui_treepanel.cpp
Normal file
387
Extras/glui/glui_treepanel.cpp
Normal file
@@ -0,0 +1,387 @@
|
||||
#include "GL/glui.h"
|
||||
|
||||
|
||||
/****************************** GLUI_TreePanel::GLUI_TreePanel() *********/
|
||||
|
||||
GLUI_TreePanel::GLUI_TreePanel(GLUI_Node *parent, const char *name,
|
||||
bool open, int inset)
|
||||
{
|
||||
common_init();
|
||||
|
||||
set_name( name );
|
||||
user_id = -1;
|
||||
|
||||
if ( !open ) {
|
||||
is_open = false;
|
||||
h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
|
||||
}
|
||||
|
||||
parent->add_control( this );
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::set_color() *********/
|
||||
|
||||
void GLUI_TreePanel::set_color(float r, float g, float b)
|
||||
{
|
||||
red = r;
|
||||
green = g;
|
||||
blue = b;
|
||||
redraw();
|
||||
}
|
||||
|
||||
/************************ GLUI_TreePanel::set_level_color() *********/
|
||||
|
||||
void GLUI_TreePanel::set_level_color(float r, float g, float b)
|
||||
{
|
||||
lred = r;
|
||||
lgreen = g;
|
||||
lblue = b;
|
||||
redraw();
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::ab() *********/
|
||||
|
||||
/* Adds branch to curr_root */
|
||||
GLUI_Tree *GLUI_TreePanel::ab(const char *name, GLUI_Tree *root)
|
||||
{
|
||||
GLUI_Tree *temp;
|
||||
|
||||
|
||||
if (root != NULL) {
|
||||
resetToRoot(root);
|
||||
}
|
||||
|
||||
temp = new GLUI_Tree(curr_root, name);
|
||||
initNode(temp);
|
||||
formatNode(temp);
|
||||
|
||||
curr_root = temp;
|
||||
curr_branch = NULL; /* Currently at leaf */
|
||||
|
||||
if (dynamic_cast<GLUI_Tree*>(temp))
|
||||
((GLUI_Tree *)temp)->set_current(true);
|
||||
//refresh();
|
||||
// glui->deactivate_current_control();
|
||||
//glui->activate_control( temp, GLUI_ACTIVATE_TAB );
|
||||
return temp;
|
||||
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::fb() *********/
|
||||
|
||||
/* Goes up one level, resets curr_root and curr_branch to parents*/
|
||||
void GLUI_TreePanel::fb(GLUI_Tree *branch)
|
||||
{
|
||||
if (((GLUI_Panel *)branch) == ((GLUI_Panel *)this))
|
||||
return;
|
||||
|
||||
if (((GLUI_Panel *)curr_branch) == ((GLUI_Panel *)this)) {
|
||||
resetToRoot();
|
||||
return;
|
||||
}
|
||||
if (((GLUI_Panel *)curr_root) == ((GLUI_Panel *)this)) {
|
||||
resetToRoot();
|
||||
return;
|
||||
}
|
||||
|
||||
if (branch != NULL) {
|
||||
|
||||
if ( dynamic_cast<GLUI_Tree*>(branch) )
|
||||
((GLUI_Tree *)branch)->set_current(false);
|
||||
|
||||
curr_branch = (GLUI_Tree *)branch->next();
|
||||
curr_root = (GLUI_Panel *)branch->parent();
|
||||
|
||||
if (curr_branch == NULL && (curr_root->collapsed_node).first_child() != NULL)
|
||||
curr_branch = (GLUI_Tree *)(curr_root->collapsed_node).first_child();
|
||||
|
||||
if ( dynamic_cast<GLUI_Tree*>(curr_root) )
|
||||
((GLUI_Tree *)curr_root)->set_current(true);
|
||||
|
||||
} else {
|
||||
if (curr_root != NULL) { /* up one parent */
|
||||
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root))
|
||||
((GLUI_Tree *)curr_root)->set_current(false);
|
||||
|
||||
curr_branch = (GLUI_Tree *) curr_root->next();
|
||||
curr_root = (GLUI_Panel *) curr_root->parent();
|
||||
|
||||
if (curr_branch == NULL && (curr_root->collapsed_node).first_child() != NULL)
|
||||
curr_branch = (GLUI_Tree *)(curr_root->collapsed_node).first_child();
|
||||
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root))
|
||||
((GLUI_Tree *)curr_root)->set_current(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//refresh();
|
||||
}
|
||||
|
||||
|
||||
/****************************** GLUI_TreePanel::refresh() *********/
|
||||
|
||||
void GLUI_TreePanel::refresh()
|
||||
{
|
||||
glui->deactivate_current_control();
|
||||
glui->activate_control( curr_root, GLUI_ACTIVATE_TAB );
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::initNode() *********/
|
||||
|
||||
void GLUI_TreePanel::initNode(GLUI_Tree *temp)
|
||||
{
|
||||
if (temp == NULL)
|
||||
return;
|
||||
int level = temp->get_level();
|
||||
int child_number = 1;
|
||||
|
||||
GLUI_Tree *ptree = dynamic_cast<GLUI_Tree*>(temp->parent());
|
||||
if (ptree) {
|
||||
level = ptree->get_level() + 1;
|
||||
GLUI_Tree *prevTree = dynamic_cast<GLUI_Tree*>(temp->prev());
|
||||
if (prevTree) {
|
||||
child_number = prevTree->get_child_number() + 1;
|
||||
}
|
||||
} else if (dynamic_cast<GLUI_Tree*>(temp) &&
|
||||
dynamic_cast<GLUI_TreePanel*>(temp->parent())) {
|
||||
child_number = ++root_children;
|
||||
}
|
||||
temp->set_id(uniqueID()); // -1 if unset
|
||||
temp->set_level(level);
|
||||
temp->set_child_number(child_number);
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::formatNode() *********/
|
||||
|
||||
void GLUI_TreePanel::formatNode(GLUI_Tree *temp)
|
||||
{
|
||||
if (temp == NULL)
|
||||
return;
|
||||
int level = temp->get_level();
|
||||
int child_number = temp->get_child_number();
|
||||
GLUI_String level_name="";
|
||||
GLUI_String full_name="";
|
||||
|
||||
temp->level_name == "";
|
||||
|
||||
if (format & GLUI_TREEPANEL_DISPLAY_HIERARCHY) {
|
||||
if (format & GLUI_TREEPANEL_HIERARCHY_LEVEL_ONLY) {
|
||||
glui_format_str(level_name, "%d", level);
|
||||
}
|
||||
if (format & GLUI_TREEPANEL_HIERARCHY_NUMERICDOT) {
|
||||
if ( dynamic_cast<GLUI_Tree*>(temp->parent()) )
|
||||
glui_format_str(level_name, "%s.%d",
|
||||
((GLUI_Tree *)(temp->parent()))->level_name.c_str(),
|
||||
child_number);
|
||||
else
|
||||
glui_format_str(level_name, "%d", child_number);
|
||||
}
|
||||
}
|
||||
|
||||
temp->set_level_color(lred, lgreen, lblue);
|
||||
temp->set_format(format);
|
||||
temp->level_name = level_name;
|
||||
|
||||
if (format & GLUI_TREEPANEL_ALTERNATE_COLOR) {
|
||||
switch (level%8) {
|
||||
case (7): temp->set_color(.5,.5,.5); break;
|
||||
case (6): temp->set_color(.3,.5,.5); break;
|
||||
case (5): temp->set_color(.5,.3,.5); break;
|
||||
case (4): temp->set_color(.3,.3,.5); break;
|
||||
case (3): temp->set_color(.5,.5,.3); break;
|
||||
case (2): temp->set_color(.3,.5,.3); break;
|
||||
case (1): temp->set_color(.5,.3,.3); break;
|
||||
default: temp->set_color(.3,.3,.3);
|
||||
}
|
||||
} else {
|
||||
temp->set_color(red,green,blue);
|
||||
}
|
||||
|
||||
if (format & GLUI_TREEPANEL_DISABLE_BAR) {
|
||||
temp->disable_bar();
|
||||
} else {
|
||||
if (format & GLUI_TREEPANEL_DISABLE_DEEPEST_BAR) {
|
||||
temp->disable_bar();
|
||||
if ( dynamic_cast<GLUI_Tree*>(curr_root) )
|
||||
((GLUI_Tree *)curr_root)->enable_bar();
|
||||
} else
|
||||
if (format & GLUI_TREEPANEL_CONNECT_CHILDREN_ONLY) {
|
||||
temp->disable_bar();
|
||||
if (temp->prev() && dynamic_cast<GLUI_Tree*>(temp->prev()) )
|
||||
{
|
||||
((GLUI_Tree *)temp->prev())->enable_bar();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::update_all() *********/
|
||||
|
||||
void GLUI_TreePanel::update_all()
|
||||
{
|
||||
printf("GLUI_TreePanel::update_all() doesn't work yet. - JVK\n");
|
||||
return;
|
||||
GLUI_Panel *saved_root = curr_root;
|
||||
GLUI_Tree *saved_branch = curr_branch;
|
||||
root_children = 0;
|
||||
resetToRoot(this);
|
||||
if (curr_branch && dynamic_cast<GLUI_Tree*>(curr_branch))
|
||||
formatNode((GLUI_Tree *)curr_branch);
|
||||
next();
|
||||
while (curr_root && curr_branch != this->first_child()) {
|
||||
if (curr_branch && dynamic_cast<GLUI_Tree*>(curr_branch)) {
|
||||
formatNode((GLUI_Tree *)curr_branch);
|
||||
}
|
||||
next();
|
||||
}
|
||||
curr_root = saved_root;
|
||||
curr_branch = saved_branch;
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::expand_all() *********/
|
||||
|
||||
void GLUI_TreePanel::expand_all()
|
||||
{
|
||||
GLUI_Panel *saved_root = curr_root;
|
||||
GLUI_Tree *saved_branch = curr_branch;
|
||||
|
||||
resetToRoot(this);
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root))
|
||||
((GLUI_Tree*)curr_root)->open();
|
||||
next();
|
||||
while (curr_root != NULL && curr_branch != this->first_child()) {
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root))
|
||||
((GLUI_Tree*)curr_root)->open();
|
||||
next();
|
||||
}
|
||||
|
||||
curr_root = saved_root;
|
||||
curr_branch = saved_branch;
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::collapse_all() *********/
|
||||
|
||||
void GLUI_TreePanel::collapse_all()
|
||||
{
|
||||
GLUI_Panel *saved_root = curr_root;
|
||||
GLUI_Tree *saved_branch = curr_branch;
|
||||
|
||||
resetToRoot(this);
|
||||
next();
|
||||
while (curr_root != NULL && curr_branch != this->first_child()) {
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root) &&
|
||||
curr_branch == NULL) { /* we want to close everything leaf-first */
|
||||
((GLUI_Tree*)curr_root)->close();
|
||||
/* Rather than simply next(), we need to manually move the
|
||||
curr_root because this node has been moved to the
|
||||
collapsed_node list */
|
||||
curr_branch = (GLUI_Tree *)curr_root->next();
|
||||
curr_root = (GLUI_Panel *)curr_root->parent();
|
||||
} else
|
||||
next();
|
||||
}
|
||||
|
||||
curr_root = saved_root;
|
||||
curr_branch = saved_branch;
|
||||
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::db() *********/
|
||||
|
||||
/* Deletes the curr_root */
|
||||
void GLUI_TreePanel::db(GLUI_Tree *root)
|
||||
{
|
||||
GLUI_Tree *temp_branch;
|
||||
GLUI_Panel *temp_root;
|
||||
|
||||
if (((GLUI_Control *)root) == ((GLUI_Control *)this))
|
||||
return;
|
||||
|
||||
if (root != NULL) {
|
||||
curr_root = (GLUI_Tree *)root;
|
||||
curr_branch = NULL;
|
||||
}
|
||||
|
||||
if (curr_root == NULL || ((GLUI_Panel *)curr_root) == ((GLUI_Panel *)this)) {
|
||||
resetToRoot();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
temp_branch = (GLUI_Tree *)curr_root->next(); /* Next branch, if any */
|
||||
temp_root = (GLUI_Panel *)curr_root->parent(); /* new root */
|
||||
curr_root->unlink();
|
||||
delete curr_root;
|
||||
curr_branch = (GLUI_Tree *) temp_branch;
|
||||
curr_root = (GLUI_Panel *) temp_root;
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root))
|
||||
((GLUI_Tree *)curr_root)->open();
|
||||
|
||||
if ((format & GLUI_TREEPANEL_DISABLE_DEEPEST_BAR) == GLUI_TREEPANEL_DISABLE_DEEPEST_BAR) {
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root) && ((GLUI_Tree *)curr_root->next()) == NULL)
|
||||
((GLUI_Tree *)curr_root)->disable_bar();
|
||||
}
|
||||
//refresh();
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::descendBranch() *********/
|
||||
|
||||
/* Finds the very last branch of curr_root, resets vars */
|
||||
void GLUI_TreePanel::descendBranch(GLUI_Panel *root) {
|
||||
if (root)
|
||||
resetToRoot(root);
|
||||
else
|
||||
resetToRoot(curr_root);
|
||||
if (curr_branch != NULL && curr_branch != ((GLUI_Panel *)this)) {
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root))
|
||||
((GLUI_Tree *)curr_root)->set_current(false);
|
||||
descendBranch(curr_branch);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::next() *********/
|
||||
|
||||
void GLUI_TreePanel::next()
|
||||
{
|
||||
if (curr_root == NULL)
|
||||
resetToRoot(this);
|
||||
|
||||
if (curr_branch == NULL && (curr_root->collapsed_node).first_child() != NULL)
|
||||
curr_branch = (GLUI_Tree *)(curr_root->collapsed_node).first_child();
|
||||
|
||||
|
||||
if (curr_branch != NULL && curr_branch != ((GLUI_Panel *)this)) { /* Descend into branch */
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root))
|
||||
((GLUI_Tree *)curr_root)->set_current(false);
|
||||
resetToRoot(curr_branch);
|
||||
} else if (curr_branch == NULL) {
|
||||
fb(NULL); /* Backup and move on */
|
||||
}
|
||||
}
|
||||
|
||||
/****************************** GLUI_TreePanel::resetToRoot() *********/
|
||||
|
||||
/* Resets curr_root and curr branch to TreePanel and lastChild */
|
||||
void GLUI_TreePanel::resetToRoot(GLUI_Panel *new_root)
|
||||
{
|
||||
GLUI_Panel *root = this;
|
||||
if (new_root != NULL)
|
||||
root = new_root;
|
||||
curr_root = root;
|
||||
if (dynamic_cast<GLUI_Tree*>(curr_root))
|
||||
((GLUI_Tree *)curr_root)->set_current(true);
|
||||
curr_branch = (GLUI_Tree *)root->first_child();
|
||||
|
||||
/* since Trees are collapsable, we need to check the collapsed nodes
|
||||
in case the curr_root is collapsed */
|
||||
if (curr_branch == NULL && (root->collapsed_node).first_child() != NULL) {
|
||||
curr_branch = (GLUI_Tree *)(root->collapsed_node).first_child();
|
||||
}
|
||||
while (curr_branch && dynamic_cast<GLUI_Tree*>(curr_branch)) {
|
||||
curr_branch=(GLUI_Tree *)curr_branch->next();
|
||||
}
|
||||
}
|
||||
44
Extras/glui/glui_window.cpp
Normal file
44
Extras/glui/glui_window.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
glui_window.cpp - GLUI_Button control class
|
||||
|
||||
GLUI User Interface Toolkit (LGPL)
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#include "GL/glui.h"
|
||||
#include "glui_internal.h"
|
||||
|
||||
GLUI_Glut_Window::GLUI_Glut_Window()
|
||||
: GLUI_Node(),
|
||||
|
||||
glut_window_id(0),
|
||||
glut_keyboard_CB(NULL),
|
||||
glut_special_CB(NULL),
|
||||
glut_reshape_CB(NULL),
|
||||
glut_passive_motion_CB(NULL),
|
||||
glut_mouse_CB(NULL),
|
||||
glut_visibility_CB(NULL),
|
||||
glut_motion_CB(NULL),
|
||||
glut_display_CB(NULL),
|
||||
glut_entry_CB(NULL)
|
||||
{
|
||||
}
|
||||
243
Extras/glui/quaternion.cpp
Normal file
243
Extras/glui/quaternion.cpp
Normal file
@@ -0,0 +1,243 @@
|
||||
/***********************************************************************
|
||||
|
||||
quaternion.cpp - A quaternion class
|
||||
|
||||
-------------------------------------------------------------------
|
||||
|
||||
GLUI User Interface Toolkit (LGPL)
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
************************************************************************
|
||||
|
||||
Feb 1998, Paul Rademacher (rademach@cs.unc.edu)
|
||||
Oct 2003, Nigel Stewart - GLUI Code Cleaning
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#include "quaternion.h"
|
||||
#include <cmath>
|
||||
#include "glui_internal.h"
|
||||
|
||||
/******************************************* constructors **************/
|
||||
|
||||
quat::quat()
|
||||
{
|
||||
*this = quat_identity();
|
||||
}
|
||||
|
||||
quat::quat(const float x, const float y, const float z, const float w)
|
||||
{
|
||||
v.set( x, y, z );
|
||||
s = w;
|
||||
}
|
||||
|
||||
quat::quat(const vec3 &_v, const float _s)
|
||||
{
|
||||
set( _v, _s );
|
||||
}
|
||||
|
||||
quat::quat(const float _s, const vec3 &_v)
|
||||
{
|
||||
set( _v, _s );
|
||||
}
|
||||
|
||||
quat::quat(const float *d)
|
||||
{
|
||||
v[0] = d[0];
|
||||
v[1] = d[1];
|
||||
v[2] = d[2];
|
||||
s = d[3];
|
||||
}
|
||||
|
||||
quat::quat(const double *d)
|
||||
{
|
||||
v[0] = (float) d[0];
|
||||
v[1] = (float) d[1];
|
||||
v[2] = (float) d[2];
|
||||
s = (float) d[3];
|
||||
}
|
||||
|
||||
quat::quat(const quat &q)
|
||||
{
|
||||
v = q.v;
|
||||
s = q.s;
|
||||
}
|
||||
|
||||
void quat::set(const vec3 &_v, const float _s)
|
||||
{
|
||||
v = _v;
|
||||
s = _s;
|
||||
}
|
||||
|
||||
quat &quat::operator=(const quat &q)
|
||||
{
|
||||
v = q.v;
|
||||
s = q.s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/******** quat friends ************/
|
||||
|
||||
quat operator + (const quat &a, const quat &b)
|
||||
{
|
||||
return quat( a.s+b.s, a.v+b.v );
|
||||
}
|
||||
|
||||
quat operator - (const quat &a, const quat &b)
|
||||
{
|
||||
return quat( a.s-b.s, a.v-b.v );
|
||||
}
|
||||
|
||||
quat operator - (const quat &a )
|
||||
{
|
||||
return quat( -a.s, -a.v );
|
||||
}
|
||||
|
||||
quat operator * ( const quat &a, const quat &b)
|
||||
{
|
||||
return quat( a.s*b.s - a.v*b.v, a.s*b.v + b.s*a.v + a.v^b.v );
|
||||
}
|
||||
|
||||
quat operator * ( const quat &a, const float t)
|
||||
{
|
||||
return quat( a.v * t, a.s * t );
|
||||
}
|
||||
|
||||
quat operator * ( const float t, const quat &a )
|
||||
{
|
||||
return quat( a.v * t, a.s * t );
|
||||
}
|
||||
|
||||
mat4 quat::to_mat4() const
|
||||
{
|
||||
float xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
|
||||
|
||||
float t = 2.0f / (v*v + s*s);
|
||||
|
||||
xs = v[VX]*t; ys = v[VY]*t; zs = v[VZ]*t;
|
||||
wx = s*xs; wy = s*ys; wz = s*zs;
|
||||
xx = v[VX]*xs; xy = v[VX]*ys; xz = v[VX]*zs;
|
||||
yy = v[VY]*ys; yz = v[VY]*zs; zz = v[VZ]*zs;
|
||||
|
||||
mat4 matrix(
|
||||
1.0f-(yy+zz), xy+wz, xz-wy, 0.0f,
|
||||
xy-wz, 1.0f-(xx+zz), yz+wx, 0.0f,
|
||||
xz+wy, yz-wx, 1.0f-(xx+yy), 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f );
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
/************************************************* quat_identity() *****/
|
||||
/* Returns quaternion identity element */
|
||||
|
||||
quat quat_identity()
|
||||
{
|
||||
return quat( vec3( 0.0, 0.0, 0.0 ), 1.0 );
|
||||
}
|
||||
|
||||
/************************************************ quat_slerp() ********/
|
||||
/* Quaternion spherical interpolation */
|
||||
|
||||
quat quat_slerp(const quat &from, const quat &to, float t)
|
||||
{
|
||||
quat to1;
|
||||
float omega, cosom, sinom, scale0, scale1;
|
||||
|
||||
/* calculate cosine */
|
||||
cosom = from.v * to.v + from.s + to.s;
|
||||
|
||||
/* Adjust signs (if necessary) */
|
||||
if ( cosom < 0.0 )
|
||||
{
|
||||
cosom = -cosom;
|
||||
to1 = -to;
|
||||
}
|
||||
else
|
||||
{
|
||||
to1 = to;
|
||||
}
|
||||
|
||||
/* Calculate coefficients */
|
||||
if ((1.0 - cosom) > FUDGE )
|
||||
{
|
||||
/* standard case (slerp) */
|
||||
omega = (float) acos( cosom );
|
||||
sinom = (float) sin( omega );
|
||||
scale0 = (float) sin((1.0 - t) * omega) / sinom;
|
||||
scale1 = (float) sin(t * omega) / sinom;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 'from' and 'to' are very close - just do linear interpolation */
|
||||
scale0 = 1.0f - t;
|
||||
scale1 = t;
|
||||
}
|
||||
|
||||
return scale0 * from + scale1 * to1;
|
||||
}
|
||||
|
||||
/********************************************** set_angle() ************/
|
||||
/* set rot angle (degrees) */
|
||||
|
||||
void quat::set_angle(float f)
|
||||
{
|
||||
vec3 axis = get_axis();
|
||||
|
||||
s = (float) cos( DEG2RAD( f ) / 2.0 );
|
||||
|
||||
v = axis * (float) sin(DEG2RAD(f) / 2.0);
|
||||
}
|
||||
|
||||
/********************************************** scale_angle() ************/
|
||||
/* scale rot angle (degrees) */
|
||||
|
||||
void quat::scale_angle(float f)
|
||||
{
|
||||
set_angle( f * get_angle() );
|
||||
}
|
||||
|
||||
/********************************************** get_angle() ************/
|
||||
/* get rot angle (degrees). Assumes s is between -1 and 1 */
|
||||
|
||||
float quat::get_angle() const
|
||||
{
|
||||
return (float) RAD2DEG( 2.0 * acos( s ) );
|
||||
}
|
||||
|
||||
/********************************************* get_axis() **************/
|
||||
|
||||
vec3 quat::get_axis() const
|
||||
{
|
||||
float scale = (float) sin( acos( s ) );
|
||||
|
||||
if ( scale < FUDGE AND scale > -FUDGE )
|
||||
return vec3( 0.0, 0.0, 0.0 );
|
||||
else
|
||||
return v / scale;
|
||||
}
|
||||
|
||||
/******************************************* quat::print() ************/
|
||||
|
||||
void quat::print(FILE *dest, const char *name) const
|
||||
{
|
||||
fprintf( dest, "%s: v:<%3.2f %3.2f %3.2f> s:%3.2f\n",
|
||||
name, v[0], v[1], v[2], s );
|
||||
}
|
||||
114
Extras/glui/quaternion.h
Normal file
114
Extras/glui/quaternion.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/****************************************************************************
|
||||
|
||||
quaternion.h - A quaternion class
|
||||
|
||||
GLUI User Interface Toolkit (LGPL)
|
||||
Copyright (c) 1998 Paul Rademacher
|
||||
|
||||
---------------------------------------------------------------------
|
||||
|
||||
WWW: http://sourceforge.net/projects/glui/
|
||||
Forums: http://sourceforge.net/forum/?group_id=92496
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef GLUI_QUATERNION_H
|
||||
#define GLUI_QUATERNION_H
|
||||
|
||||
#include "algebra3.h"
|
||||
#include <cstdio>
|
||||
|
||||
/* this line defines a new type: pointer to a function which returns a */
|
||||
/* float and takes as argument a float */
|
||||
typedef float (*V_FCT_PTR)(float);
|
||||
|
||||
/****************************************************************
|
||||
* Quaternion *
|
||||
****************************************************************/
|
||||
|
||||
class quat
|
||||
{
|
||||
/*protected: */
|
||||
public:
|
||||
|
||||
vec3 v; /* vector component */
|
||||
float s; /* scalar component */
|
||||
|
||||
/*public: */
|
||||
|
||||
/* Constructors */
|
||||
|
||||
quat();
|
||||
quat(float x, float y, float z, float w);
|
||||
quat(const vec3 &v, float s);
|
||||
quat(float s, const vec3 &v);
|
||||
quat(const float *d); /* copy from four-element float array */
|
||||
quat(const double *f); /* copy from four-element double array */
|
||||
quat(const quat &q); /* copy from other quat */
|
||||
|
||||
/* Assignment operators */
|
||||
|
||||
quat &operator = (const quat &v); /* assignment of a quat */
|
||||
quat &operator += (const quat &v); /* incrementation by a quat */
|
||||
quat &operator -= (const quat &v); /* decrementation by a quat */
|
||||
quat &operator *= (float d); /* multiplication by a constant */
|
||||
quat &operator /= (float d); /* division by a constant */
|
||||
|
||||
/* special functions */
|
||||
|
||||
float length() const; /* length of a quat */
|
||||
float length2() const; /* squared length of a quat */
|
||||
quat &normalize(); /* normalize a quat */
|
||||
quat &apply(V_FCT_PTR fct); /* apply a func. to each component */
|
||||
vec3 xform(const vec3 &v ); /* q*v*q-1 */
|
||||
mat4 to_mat4() const;
|
||||
void set_angle(float f); /* set rot angle (degrees) */
|
||||
void scale_angle(float f); /* scale rot angle (degrees) */
|
||||
float get_angle() const; /* set rot angle (degrees) */
|
||||
vec3 get_axis() const; /* get axis */
|
||||
|
||||
void print( FILE *file, const char *name ) const; /* print to a file */
|
||||
|
||||
float &operator [] (int i); /* indexing */
|
||||
const float &operator [] (int i) const; /* indexing */
|
||||
|
||||
void set(float x, float y, float z); /* set quat */
|
||||
void set(const vec3 &v, float s); /* set quat */
|
||||
|
||||
/* friends */
|
||||
|
||||
friend quat operator - (const quat &v); /* -q1 */
|
||||
friend quat operator + (const quat &a, const quat &b); /* q1 + q2 */
|
||||
friend quat operator - (const quat &a, const quat &b); /* q1 - q2 */
|
||||
friend quat operator * (const quat &a, float d); /* q1 * 3.0 */
|
||||
friend quat operator * (float d, const quat &a); /* 3.0 * q1 */
|
||||
friend quat operator * (const quat &a, const quat &b); /* q1 * q2 */
|
||||
friend quat operator / (const quat &a, float d); /* q1 / 3.0 */
|
||||
friend int operator == (const quat &a, const quat &b); /* q1 == q2 ? */
|
||||
friend int operator != (const quat &a, const quat &b); /* q1 != q2 ? */
|
||||
friend void swap(quat &a, quat &b); /* swap q1 &q2 */
|
||||
/*friend quat min(const quat &a, const quat &b); -- min(q1, q2) */
|
||||
/*friend quat max(const quat &a, const quat &b); -- max(q1, q2) */
|
||||
friend quat prod(const quat &a, const quat &b); /* term by term mult*/
|
||||
};
|
||||
|
||||
/* Utility functions */
|
||||
|
||||
quat quat_identity(); /* Returns quaternion identity element */
|
||||
quat quat_slerp(const quat &from, const quat &to, float t);
|
||||
|
||||
#endif
|
||||
228
Extras/glui/readme.txt
Normal file
228
Extras/glui/readme.txt
Normal file
@@ -0,0 +1,228 @@
|
||||
Welcome to the GLUI User Interface Library, v2.3!
|
||||
March 22, 2005
|
||||
-------------------------------------------------
|
||||
|
||||
This distribution contains the latest community-maintained fork of the
|
||||
GLUI Library. It is based on the GLUI v2.1 beta version from Paul
|
||||
Rademacher (http://www.cs.unc.edu/~rademach/glui/) plus the
|
||||
compatibility changes made by Nigel Stewart in his "GLUI v2.2"
|
||||
(http://www.nigels.com/glt/glui) In accordance with the LGPL under
|
||||
which the library is released (according to Paul's web page at least),
|
||||
these changes are available to everyone in the community.
|
||||
|
||||
WARNING: This version (2.3) introduces some incompatible changes with
|
||||
previous versions!!
|
||||
|
||||
CHANGES:
|
||||
|
||||
----------------------------------
|
||||
- GLUI_String is now a std::string
|
||||
This is the main source of most incopatibilities, but I felt it was
|
||||
a necessary change, because the previous usage of a fixed-sized
|
||||
buffer was just too unsafe. I myself was bitten a few times passing
|
||||
a char* buffer of insufficient size into GLUI as a live variable.
|
||||
It is still possible to use a char buffer, but it is not recommended.
|
||||
|
||||
If you used GLUI_String before as a live var type, the easiest way
|
||||
to get your code compiling again is to change those to "char
|
||||
buf[300]". The better way, though, is to update your code to treat
|
||||
it as a std::string.
|
||||
|
||||
For instance, if you used to pass mystr to functions that take
|
||||
'const char*', now use mystr.c_str() method, instead.
|
||||
If you used strcpy(mystr, b) to set the value, now just do mystr=b.
|
||||
If you used sprintf(mystr,...) to set the value, now do
|
||||
glui_format_string(mystr,...).
|
||||
If you used to clear the string with mystr[0]='\0', now just clear
|
||||
it with mystr="".
|
||||
|
||||
----------------------------------
|
||||
- Enhanced GLUI_EditText
|
||||
Control keys can be used for navigation and control. The bindings
|
||||
are bash-like: Ctrl-B for previous char, Ctrl-F for forward char, etc.
|
||||
bindings. Also control keys that aren't bound to commands are
|
||||
simply ignored, whereas before they would be inserted as invisible
|
||||
characters.
|
||||
|
||||
----------------------------------
|
||||
- Added GLUI_CommandLine class
|
||||
This is a GLUI_EditText with a history mechanism.
|
||||
|
||||
----------------------------------
|
||||
- New, more object oriented construction API.
|
||||
Now instead of calling
|
||||
|
||||
glui->add_button_to_panel( panel, "my button", myid, mycallback );
|
||||
|
||||
you should just call the button constructor:
|
||||
|
||||
new GLUI_Button( panel, "my button", myid, mycallback );
|
||||
|
||||
And similarly to add it to a GLUI instead of a panel, rather than:
|
||||
|
||||
glui->add_button( glui, "my button", myid, mycallback );
|
||||
|
||||
just call the constructor with the GLUI as the first argument:
|
||||
|
||||
new GLUI_Button( glui, "my button", myid, mycallback );
|
||||
|
||||
The old scheme is now deprecated, but still works. The benefit of
|
||||
this new scheme is that now the GLUI class doesn't have to know
|
||||
about all the different types of GLUI_Controls that exist.
|
||||
Previously GLUI had to both know about all the controls, and know
|
||||
how to initialize them. Now the responsibility for initialization
|
||||
belongs to the GLUI_Control subclasses themselves, where it
|
||||
belongs. Additionally it means that you can create your own
|
||||
GLUI_Control subclasses which will be on equal footing with the
|
||||
built-in controls, whereas before any user-created controls would
|
||||
always be "second-class citizens" since they would have to be
|
||||
constructed differently from the built-ins.
|
||||
|
||||
|
||||
----------------------------------
|
||||
- Removed need for type-declaring arguments when argment type suffices.
|
||||
This effects GLUI_Spinner and GLUI_EditText (and GLUI_CommandLine?).
|
||||
|
||||
For example, instead of calling
|
||||
|
||||
new GLUI_Spinner( glui, "myspin", GLUI_SPINNER_INT, &live_int_var );
|
||||
|
||||
you can just omit the GLUI_SPINNER_INT part, because the type of the
|
||||
live_int_var tells the compiler which type you want.
|
||||
|
||||
new GLUI_Spinner( glui, "myspin", &live_int_var );
|
||||
|
||||
If you're not using a live, var, you can still use the
|
||||
GLUI_SPINNER_INT type argument. See glui.h for all the new
|
||||
constructor signatures. Note this only works with the new
|
||||
construction API, not with the old "add_blah_to_panel" style of
|
||||
API.
|
||||
|
||||
----------------------------------
|
||||
- GLUI_Rotation uses your matrix live-variable now.
|
||||
GLUI used to ignore the matrix in your live variable. This version
|
||||
doesn't ignore it, so you'll need to set it to the identity matrix
|
||||
yourself if that's what you want it to start as. There could
|
||||
probably be some improvements to this API, though.
|
||||
|
||||
----------------------------------
|
||||
- Improvements to 'const' usage.
|
||||
Most char*'s in GLUI functions used to be non-const even when the
|
||||
functions did not modify the string. I changed everywhere
|
||||
appropriate to use const char* instead.
|
||||
|
||||
----------------------------------
|
||||
- Updated license info in the headers
|
||||
Paul's web page says that GLUI is LGPL, but that wasn't declared in
|
||||
the code itself. I've modified all the headers with the standard
|
||||
LGPL notice.
|
||||
|
||||
----------------------------------
|
||||
- Updated examples for the API changes
|
||||
|
||||
----------------------------------
|
||||
- Created project files for Visual Studio .NET (MSVC7.1)
|
||||
|
||||
|
||||
That's about it. Enjoy!
|
||||
|
||||
|
||||
If you find yourself with too much time on your hands, the things I
|
||||
think would be most useful for future improvements to GLUI would be:
|
||||
|
||||
1. The GLUI_TextBox and GLUI_Tree definitely need some work, still.
|
||||
2. Clipboard integration under Windows/X-Win. I have some code that
|
||||
works on Win32 that I once integrated with GLUI, but I lost that
|
||||
version somewhere. I still have the Win32 clipboard code, though
|
||||
if anyone wants to work on integrating it. I have some X-Win
|
||||
clipboard code, too, but I never got it working quite right.
|
||||
3. Remove the dependency on GLUT, making the connection with window
|
||||
system APIs into a more plug-in/adapter modular design.
|
||||
So e.g. if you want to use GLUT, you'd link with the GLUI lib and a
|
||||
GLUI_GLUT lib, and call one extra GLUI_glut_init() function or
|
||||
something.
|
||||
|
||||
|
||||
Definitly consider submitting a patch if you've made some nice improvements
|
||||
to GLUI. Hopefully being an LGPL sourceforge project will attract some new
|
||||
interest to the GLUI project.
|
||||
|
||||
Bill Baxter
|
||||
baxter
|
||||
at
|
||||
cs unc edu
|
||||
|
||||
=================================================
|
||||
JOHN KEW'S ADDITIONS (March 2005)
|
||||
=================================================
|
||||
|
||||
Thanks to John Kew of Natural Solutions Inc.,
|
||||
there are some new widgets. These are demonstrated in example6.cpp.
|
||||
|
||||
The new widgets are:
|
||||
|
||||
* GLUI_Scrollbar - A scrollbar slider widget
|
||||
* GLUI_TextBox - A multi-line text widget
|
||||
* GLUI_List - A static choice list
|
||||
* GLUI_FileBrowser - A simple filebrowser based on GLUI_List
|
||||
* GLUI_Tree - Hierarchical tree widget
|
||||
* GLUI_TreePanel - Manager for the tree widget
|
||||
|
||||
And one other change:
|
||||
|
||||
* GLUI_Rollout has optional embossed border
|
||||
|
||||
=================================================
|
||||
PAUL'S ORIGINAL GLUI 2.0/2.1 README
|
||||
=================================================
|
||||
|
||||
Welcome to the GLUI User Interface Library, v2.0 beta!
|
||||
-------------------------------------------------
|
||||
|
||||
This distribution contains the full GLUI sources, as well as 5 example
|
||||
programs. You'll find the full manual under "glui_manual.pdf". The
|
||||
GLUI web page is at
|
||||
|
||||
http://www.cs.unc.edu/~rademach/glui
|
||||
|
||||
|
||||
---------- Windows ----------
|
||||
|
||||
The directory 'msvc' contains a Visual C++ workspace entitled
|
||||
'glui.dsw'. To recompile the library and examples, open this
|
||||
workspace and run the menu command "Build:Batch Build:Build". The 3
|
||||
executables will be in the 'bin' directory, and the library in the
|
||||
'lib' directory.
|
||||
|
||||
To create a new Windows executable using GLUI, create a "Win32 Console
|
||||
Application" in VC++, add the GLUI library (in 'msvc/lib/glui32.lib'),
|
||||
and add the OpenGL libs:
|
||||
|
||||
glui32.lib glut32.lib glu32.lib opengl32.lib (Microsoft OpenGL)
|
||||
|
||||
Include the file "glui.h" in any file that uses the GLUI library.
|
||||
|
||||
|
||||
---------- Unix ----------
|
||||
|
||||
An SGI/HP makefile is found in the file 'makefile' (certain lines may need
|
||||
to be commented/uncommented).
|
||||
|
||||
To include GLUI in your own apps, add the glui library to your
|
||||
makefile (before the glut library 'libglut.a'), and include "glui.h"
|
||||
in your sources.
|
||||
|
||||
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Please let me know what you think, what you'd like to change or add,
|
||||
and especially what bugs you encounter. Also, please send me your
|
||||
e-mail so I can add you to a mailing list for updates.
|
||||
|
||||
Good luck, and thanks for trying this out!
|
||||
|
||||
Paul Rademacher
|
||||
rademach
|
||||
at
|
||||
cs unc edu
|
||||
Reference in New Issue
Block a user