| GL Studio C++ Runtime API

util.h
Go to the documentation of this file.
1/*! \file
2 \brief Generally useful defines, macros, enumerations and function
3 prototypes.
4
5 \par Copyright Information
6
7 Copyright (c) 2017 by The DiSTI Corporation.<br>
8 11301 Corporate Blvd; Suite 100<br>
9 Orlando, Florida 32817<br>
10 USA<br>
11 <br>
12 All rights reserved.<br>
13
14 This Software contains proprietary trade secrets of DiSTI and may not be
15 reproduced, in whole or part, in any form, or by any means of electronic,
16 mechanical, or otherwise, without the written permission of DiSTI. Said
17 permission may be derived through the purchase of applicable DiSTI product
18 licenses which detail the distribution rights of this content and any
19 Derivative Works based on this or other copyrighted DiSTI Software.
20
21 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
22 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
23 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
24 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
26 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
27
28 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
29 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
30 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
31 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
32 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
33 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
34 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
35 EXCEED FIVE DOLLARS (US$5.00).
36
37 The aforementioned terms and restrictions are governed by the laws of the
38 State of Florida and the United States of America.
39
40*/
41
42#ifndef INCLUDED_GLS_RUNTIME_UTIL_H
43#define INCLUDED_GLS_RUNTIME_UTIL_H
44
45#include "ConvertUTF.h"
46#include "disti_assert.h"
47#include "dynamic_array.h"
48#include "gls_cpp_lang_support.h"
49#include "gls_include.h"
50#include "gls_matrix_affine.h"
51#include "scoped_ptr.h"
52#include "unhide_globals.h"
53#include "vertex.h"
54
55#include <algorithm>
56#include <cmath>
57#include <iostream>
58#include <sstream>
59#include <string>
60#include <typeinfo>
61#include <vector>
62
63#ifdef WIN32
64# include <direct.h>
65
66# define _CRT_FUNCTIONS_REQUIRED 1
67#else
68# include <unistd.h>
69#endif
70
71#if defined( QNX )
72# include <stdio.h>
73#else
74# include <cstdio>
75#endif
76
77#if defined( LINUX ) || defined( __VXWORKS__ ) || defined( __APPLE__ ) || defined( QNX )
78# include <strings.h>
79#endif
80
81#ifdef ANDROID
82# include <android/asset_manager.h>
83#endif
84
85 const int DIALOG_MAX_DIRECTORY_LENGTH = 1024; ///< Limited by FLTK FileBrowser.
86
87 class Fl_Window;
88
89/// Wrap code that should only be compiled in debug in GLS_DEBUG_CODE().
90#if defined( GLS_DEBUG ) || !defined( NDEBUG )
91# define GLS_DEBUG_CODE( x ) x
92#else
93# define GLS_DEBUG_CODE( x )
94#endif
95
96 namespace disti
97{
98 class Vertex;
99 class DisplayObject;
100 class DisplayFrame;
101
102#ifndef TRUE
103# define TRUE 1 ///< True macro, for backward compatibility purposes.
104#endif
105
106#ifndef FALSE
107# define FALSE 0 ///< False macro, for backward compatibility purposes.
108#endif
109
110#ifdef WIN32
111 inline int strcasecmp( const char* const x, const char* const y )
112{
113 return _stricmp( x, y );
114}
115#endif
116
117/** Used to generate inline textures. The writing and reading of the lines need to know the length. */
118 const int INLINE_TEXTURE_LINE_LENGTH = 240;
119
120 const char PARSER_CLEARSTRING_DELIMETER_START[] = "#$STRING_START$#"; ///< Used for parsing lines of clear (multiline otherwise unencoded) text.
121 const char PARSER_CLEARSTRING_DELIMETER_END[] = "#$STRING_END$#"; ///< Used for parsing lines of clear (multiline otherwise unencoded) text.
122
123 const double HIT_TOLERANCE = 5.0; ///< The hit tolerance in logical units for selecting objects in the editor.
124
125/// Determines if x is included in the range x1 to x2.
126/// \param x The value to check.
127/// \param x1 The minimum range.
128/// \param x2 The maximum range.
129/// \return Whether or not x is in the range.
130 template<class X, class X1, class X2>
131 bool BETWEEN( const X& x, const X1& x1, const X2& x2 )
132{
133 return ( x >= x1 && x <= x2 )
134 || ( x >= x2 && x <= x1 );
135}
136
137/// Determines if the argument is negative.
138/// \param x The value to check.
139/// \return True if x is negative.
140 template<class X>
141 bool IS_NEGATIVE( const X& x ) { return std::fabs( x ) > 0.0001 ? ( x < 0.0 ) : 0; }
142
143/// Determines if the argument is positive.
144/// \param x The value to check.
145/// \return True if x is positive.
146 template<class X>
147 bool IS_POSITIVE( const X& x ) { return std::fabs( x ) > 0.0001 ? ( x > 0.0 ) : 0; }
148
149/// Determines if the argument is small (< 1e-1).
150/// \param x The value to check.
151/// \param threshold A small value near zero to check from.
152/// \return True if x is closer to zero than threshold.
153 template<class X>
154 bool CloseToZero( const X x, const X threshold = X( 1e-1 ) )
155{
156 return std::fabs( x ) < threshold;
157}
158
159/// Determines if the argument is extremely small (< 10E-4).
160/// \param x The value to check.
161/// \return True if x is very close to zero.
162 template<class X>
163 bool VeryCloseToZero( X x ) { return CloseToZero( x, X( 0.0001 ) ); }
164
165/// Determines if the argument is very small (< 10E-3).
166/// \param x The value to check.
167/// \return True if x is close to zero.
168 template<class X>
169 bool IsNearZero( X x ) { return CloseToZero( x, X( 0.001 ) ); }
170
171/// \deprecated Renamed to IsNearZero().
172/// \param x The value to check.
173/// \return True if x is close to zero.
174 template<class X>
175 bool IS_ZERO( X x ) { return IsNearZero( x ); }
176
177#ifndef MIN
178/// Determines which argument is smaller
179/// \deprecated Use disti::Min() instead.
180# define MIN( A, B ) ( ( A ) < ( B ) ? ( A ) : ( B ) )
181#endif
182
183#ifndef MAX
184/// Determines which argument is larger
185/// \deprecated Use disti::Min() instead.
186# define MAX( A, B ) ( ( A ) > ( B ) ? ( A ) : ( B ) )
187#endif
188
189/// Use for determining the current OpenGL version available in the current runtime environment.
190/// It may not be valid until called after a valid rendering context has been assigned.
191/// \return The X.Y OpenGL version.
192 GLS_EXPORT float OpenGLVersion();
193
194/// \return Whether or not the requested OpenGL extension is supported.
195/// \param extension The string name of the extension to check.
196 GLS_EXPORT bool gltIsExtSupported( const char* extension );
197
198// Additional #defines
199/// From glext.h Available at http://oss.sgi.com/projects/ogl-sample/registry/
200#ifndef GLES
201# define GLSTUDIO_CLAMP_TO_EDGE ( OpenGLVersion() >= 1.2f ? 0x812F : GL_CLAMP )
202#else
203# define GLSTUDIO_CLAMP_TO_EDGE GL_CLAMP_TO_EDGE
204#endif
205
206/** GL Studio color defines */
207// \enum color enumerations for use with GlsDefinedColor methods
208 enum GlsDefinedColorEnum
209{
210 GLS_COLOR_WHITE,
211 GLS_COLOR_CYAN,
212 GLS_COLOR_RED,
213 GLS_COLOR_AMBER,
214 GLS_COLOR_GREEN,
215 GLS_COLOR_YELLOW,
216 GLS_COLOR_MAGENTA,
217 GLS_COLOR_BLACK,
218 GLS_COLOR_BLUE,
219 GLS_COLOR_MAX
220};
221
222/** Predefined colors (see \sa GlsDefinedColorEnum for the values). Use \sa GlsDefinedColor() for a range-checked version. */
223 GLS_EXPORT extern unsigned char glsDefinedColors[ GLS_COLOR_MAX ][ 4 ];
224
225/** Gets a predefined color in \sa GlsDefinedColorEnum.
226 * \param index of defined color
227 * \return an unsigned char array of the specified index
228 */
229 inline unsigned char* GlsDefinedColor( GlsDefinedColorEnum index )
230{
231 if( ( index < 0 ) || ( index >= GLS_COLOR_MAX ) )
232 return glsDefinedColors[ 0 ];
233 else
234 return glsDefinedColors[ index ];
235}
236
237/// Allow the user to change the predefined colors.
238/// \param index The index of the color to change.
239/// \param red The new red channel value to set (0-255).
240/// \param green The new green channel value to set (0-255).
241/// \param blue The new blue channel value to set (0-255).
242/// \param alpha The new alpha channel value to set (0-255).
243 inline void ChangeGlsDefinedColor(
244 GlsDefinedColorEnum index,
245 unsigned char red,
246 unsigned char green,
247 unsigned char blue,
248 unsigned char alpha )
249{
250 if( ( index >= 0 ) && ( index < GLS_COLOR_MAX ) )
251 {
252 glsDefinedColors[ index ][ 0 ] = red;
253 glsDefinedColors[ index ][ 1 ] = green;
254 glsDefinedColors[ index ][ 2 ] = blue;
255 glsDefinedColors[ index ][ 3 ] = alpha;
256 }
257}
258
259#ifndef WIN32
260/** helper class that enables use of basic_string< unsigned short > on unix
261 * \see std::char_traits
262 */
263 struct CharTraitsUnsignedShort
264{
265 typedef unsigned short char_type; ///< Typedef for the underlying char type.
266 typedef int int_type; ///< Typedef for the underlying int type.
267 typedef std::streampos pos_type; ///< Typedef for the underlying stream position type.
268 typedef std::streamoff off_type; ///< Typedef for the underlying stream offset type.
269 typedef std::mbstate_t state_type; ///< Typedef for the underlying multibyte conversion state type.
270
271 /// \see std::char_traits::assign
272 /// \param c1
273 /// \param c2
274 static void assign( char_type& c1, const char_type& c2 )
275 {
276 c1 = c2;
277 }
278
279 /// \see std::char_traits::eq
280 /// \param c1
281 /// \param c2
282 /// \return
283 static bool eq( const char_type& c1, const char_type& c2 )
284 {
285 return c1 == c2;
286 }
287
288 /// \see std::char_traits::lt
289 /// \param c1
290 /// \param c2
291 /// \return
292 static bool lt( const char_type& c1, const char_type& c2 )
293 {
294 return c1 < c2;
295 }
296
297 /// \see std::char_traits::compare
298 /// \param s1
299 /// \param s2
300 /// \param n
301 /// \return
302 static int compare( const char_type* s1, const char_type* s2, size_t n )
303 {
304 if( n == 0 )
305 {
306 return ( 0 );
307 }
308 do
309 {
310 if( *s1 != *s2++ )
311 {
312 return ( *s1 - *( s2 - 1 ) );
313 }
314 if( *s1++ == 0 )
315 {
316 break;
317 }
318 } while( --n != 0 );
319 return ( 0 );
320 }
321
322 /// \see std::char_traits::length
323 /// \param s
324 /// \return
325 static size_t length( const char_type* s )
326 {
327 size_t x = 0u;
328 while( *s++ )
329 {
330 ++x;
331 }
332 return ( x );
333 }
334
335 /// \see std::char_traits::find
336 /// \param s
337 /// \param n
338 /// \param a
339 /// \return
340 static const char_type* find( const char_type* s, size_t n, const char_type& a )
341 {
342 while( n-- > 0 )
343 {
344 if( *s == a )
345 {
346 return s;
347 }
348 s++;
349 }
350 return NULL;
351 }
352
353 /// \see std::char_traits::move
354 /// \param s1
355 /// \param s2
356 /// \param n
357 /// \return
358 static char_type* move( char_type* s1, const char_type* s2, size_t n )
359 {
360 return static_cast<char_type*>( memmove( s1, s2, n * sizeof( char_type ) ) );
361 }
362
363 /// \see std::char_traits::copy
364 /// \param s1
365 /// \param s2
366 /// \param n
367 /// \return
368 static char_type* copy( char_type* s1, const char_type* s2, size_t n )
369 {
370 return static_cast<char_type*>( memcpy( s1, s2, n * sizeof( char_type ) ) );
371 }
372
373 /// \see std::char_traits::assign
374 /// \param s
375 /// \param n
376 /// \param a
377 /// \return
378 static char_type* assign( char_type* s, size_t n, char_type a )
379 {
380 for( size_t idx = 0u; idx < n; ++idx )
381 {
382 s[ idx ] = a;
383 }
384 return ( s );
385 }
386
387 /// \see std::char_traits::to_char_type
388 /// \param c
389 /// \return
390 static char_type to_char_type( const int_type& c )
391 {
392 return static_cast<char_type>( c );
393 }
394
395 /// \see std::char_traits::to_int_type
396 /// \param c
397 /// \return
398 static int_type to_int_type( const char_type& c )
399 {
400 return static_cast<int_type>( c );
401 }
402
403 /// \see std::char_traits::eq_int_type
404 /// \param c1
405 /// \param c2
406 /// \return
407 static bool eq_int_type( const int_type& c1, const int_type& c2 )
408 {
409 return c1 == c2;
410 }
411
412 /// \see std::char_traits::eof
413 /// \return
414 static int_type eof()
415 {
416 return static_cast<int_type>( EOF );
417 }
418
419 /// \see std::char_traits::not_eof
420 /// \param c
421 /// \return
422 static int_type not_eof( const int_type& c )
423 {
424 return ( c == eof() ) ? 0 : c;
425 }
426};
427
428 typedef std::basic_string<unsigned short, CharTraitsUnsignedShort> UTF16String; ///< A cross platform UTF-16 encoded string.
429 typedef std::ofstream UTF16Outfilestream; ///< A cross platform UTF-16 encoded ofstream.
430 typedef std::ostream UTF16Outstream; ///< A cross platform UTF-16 encoded ostream.
431 typedef std::string UnicodeString; ///< A cross platform UTF-8 encoded string.
432 typedef std::ofstream UnicodeOutfilestream; ///< A cross platform UTF-8 encoded ofstream.
433 typedef std::ostream UnicodeOutstream; ///< A cross platform UTF-8 encoded string.
434
435#else
436
437 typedef std::wstring UTF16String; ///< A cross platform UTF-16 encoded string.
438 typedef std::wofstream UTF16Outfilestream; ///< A cross platform UTF-16 encoded ofstream.
439 typedef std::wostream UTF16Outstream; ///< A cross platform UTF-16 encoded ostream.
440 typedef std::wstring UnicodeString; ///< A cross platform UTF-8 encoded string.
441 typedef std::wofstream UnicodeOutfilestream; ///< A cross platform UTF-8 encoded ofstream.
442 typedef std::wostream UnicodeOutstream; ///< A cross platform UTF-8 encoded string.
443
444#endif
445
446/// Convert the given UTF8 string to UTF16.
447/// \param src The string in question.
448/// \return The given string in UTF16.
449 inline UTF16String
450 ConvertUTF8ToWide( const std::string& src )
451{
452 UTF16String ret;
453 if( src.size() > 0u )
454 {
455 // allocate buffer for string plus terminator
456 const unsigned int srcLen = (unsigned int)src.size();
457 const unsigned int utf16BufLen = (unsigned int)( src.size() + 1u );
458 UTF16* utf16Buf = new UTF16[ src.size() + 1u ];
459 // NULL out buffer
460 memset( utf16Buf, 0, ( utf16BufLen * sizeof( UTF16 ) ) );
461
462 // convert UTF8 to UTF16
463 {
464 const UTF8* srcUTF8 = (const UTF8*)( src.c_str() );
465 UTF16* targetUTF16 = utf16Buf;
466 ConvertUTF8toUTF16( &srcUTF8, &srcUTF8[ srcLen ], &targetUTF16, &( targetUTF16[ utf16BufLen - 1u ] ), strictConversion );
467 }
468 // force terminate
469 utf16Buf[ utf16BufLen - 1u ] = 0;
470 // store out
471#ifdef WIN32
472 ret.assign( (wchar_t*)utf16Buf );
473#else
474 ret.assign( (unsigned short*)utf16Buf );
475#endif
476
477 // done with buf
478 delete[]( utf16Buf );
479 utf16Buf = NULL;
480 }
481
482 return ( ret );
483}
484
485/// Return whether two numbers are "equal" to eachother taking into account
486/// a certain precision. You can use this method on any numeric types and
487/// even mix types as the parameters. Eg. you can compare integers with
488/// floating point types or compare floats and doubles without casting.
489/// \param x First number to use in the comparison which determines the range
490/// \param y Number to check if within the range determined by x and precision
491/// \param precision Number that is added to and subtracted from x to
492/// determine the range to check y against.
493/// \return True if the numbers are close enough to be considered equal.
494 template<class T1, class T2>
495 bool Equal( T1 x, T2 y, float precision = 0.001f )
496{
497 return ( x - precision ) <= y && y <= ( x + precision );
498}
499
500/// \return The minimum of two objects.
501/// \param x The first object to compare.
502/// \param y The second object to compare.
503/// \note The class T must have the < operator defined.
504 template<class T>
505 const T& Min( const T& x, const T& y )
506{
507 return x < y ? x : y;
508}
509
510/// \return The maximum of two objects.
511/// \param x The first object to compare.
512/// \param y The second object to compare.
513/// \note The class T must have the < operator defined.
514 template<class T>
515 const T& Max( const T& x, const T& y )
516{
517 return x < y ? y : x;
518}
519
520/// \return The minimum of two objects determined by a predicate.
521/// If pr(x, y) is true, x is returned else y.
522/// \param x The first object to compare.
523/// \param y The second object to compare.
524/// \param pr The function to serve as the predicate.
525 template<class T, class Pred>
526 const T& Min( const T& x, const T& y, Pred pr )
527{
528 return pr( x, y ) ? x : y;
529}
530
531/// \return The maximum of two objects determined by a predicate.
532/// If pr(x, y) is true, y is returned else x.
533/// \param x The first object to compare.
534/// \param y The second object to compare.
535/// \param pr The function to serve as the predicate.
536 template<class T, class Pred>
537 const T& Max( const T& x, const T& y, Pred pr )
538{
539 return pr( x, y ) ? y : x;
540}
541
542/** \brief Class to contain current OpenGL view, projection and draw matrices */
543 class OpenGLMatrices
544{
545 private:
546 bool _needsDelete;
547
548 public:
549 int* viewMatrix; ///< The viewport matrix.
550 GlsMatrixType* projMatrix; ///< The projection matrix.
551 GlsMatrixType* modelMatrix; ///< The modelview matrix.
552
553 /// Default constructor.
554 /// Keeps everything NULL.
555 GLS_EXPORT OpenGLMatrices();
556
557 /// Copy constructor.
558 /// \note Pointers are copied as-is, copies of the data are NOT made.
559 /// \param src The object to copy from.
560 GLS_EXPORT OpenGLMatrices( const OpenGLMatrices& src );
561
562 /// Another constructor.
563 /// \note Pointers are copied as-is, copies of the data are NOT made.
564 /// \param view The viewport matrix to use.
565 /// \param proj The projection matrix to use.
566 /// \param model The modelview matrix to use.
567 GLS_EXPORT OpenGLMatrices( int* view, GlsMatrixType* proj, GlsMatrixType* model );
568
569 /// Destructor.
570 GLS_EXPORT ~OpenGLMatrices();
571
572 /// Retrieves the current OpenGL Matrices from the OpenGL Subsystem.
573 GLS_EXPORT void GetCurrent();
574};
575
576/// Find a transformation that will convert to a new coordinate
577/// system defined by the given origin and basis vectors (i,j,k).
578/// \note The new i,j,k vectors are in respect to the current origin.
579/// (i.e. for transformation that moves the origin
580/// along the x axis by 5 units you should pass in
581/// (Vector(5,0,0), Vector(1,0,0), Vector(0,1,0) , Vector(0,0,1))
582/// NOT (Vector(5,0,0), Vector(6,0,0), Vector(5,1,0) , Vector(5,0,1))
583/// Template argument is either double or float.
584/// \param new_origin Vector to the new coordinate system origin.
585/// \param new_i Vector parallel to the new x-axis with magnitude equal to one unit in the new coordinate system.
586/// \param new_j Vector parallel to the new y-axis with magnitude equal to one unit in the new coordinate system.
587/// \param new_k Vector parallel to the new z-axis with magnitude equal to one unit in the new coordinate system.
588/// \returns transformation matrix to the new coordinate system
589 template<class T>
590 GlsMatrixAffine<T> FindCoordinateTransformation( const Vector& new_origin, const Vector& new_i, const Vector& new_j, const Vector& new_k )
591{
592 GlsMatrixAffine<T> transform;
593 GlsMatrixAffine<T> rotation_scaling;
594
595 // First translate to the new origin
596
597 transform.Translate( -new_origin );
598
599 // Build a matrix taking the standard basis vectors to the new basis vectors
600
601 rotation_scaling( 0, 0 ) = new_i.x;
602 rotation_scaling( 0, 1 ) = new_j.x;
603 rotation_scaling( 0, 2 ) = new_k.x;
604 rotation_scaling( 1, 0 ) = new_i.y;
605 rotation_scaling( 1, 1 ) = new_j.y;
606 rotation_scaling( 1, 2 ) = new_k.y;
607 rotation_scaling( 2, 0 ) = new_i.z;
608 rotation_scaling( 2, 1 ) = new_j.z;
609 rotation_scaling( 2, 2 ) = new_k.z;
610
611 // Invert because we want the new basis vectors to become the standard basis vectors
612 rotation_scaling.Invert();
613
614 // Combine the translation and rotation to produce the complete transformation
615 return rotation_scaling * transform;
616}
617
618/// Find a transformation that will convert to a new coordinate
619/// system defined by the given origin and basis vectors (i,j,k).
620/// \note The new i,j,k vectors are in respect to the current origin.
621/// (i.e. for transformation that moves the origin
622/// along the x axis by 5 units you should pass in
623/// (Vector(5,0,0), Vector(1,0,0), Vector(0,1,0) , Vector(0,0,1))
624/// NOT (Vector(5,0,0), Vector(6,0,0), Vector(5,1,0) , Vector(5,0,1))
625/// Template argument is either double or float.
626/// \param new_origin Vector to the new coordinate system origin.
627/// \param new_i Vector parallel to the new x-axis with magnitude equal to one unit in the new coordinate system.
628/// \param new_j Vector parallel to the new y-axis with magnitude equal to one unit in the new coordinate system.
629/// \param new_k Vector parallel to the new z-axis with magnitude equal to one unit in the new coordinate system.
630/// \param result The returned transformation matrix to the new coordinate system.
631 template<class T>
632 void FindCoordinateTransformation( const Vector& new_origin, const Vector& new_i, const Vector& new_j, const Vector& new_k, GlsMatrixAffine<T>& result )
633{
634 GlsMatrixAffine<T> transform;
635 GlsMatrixAffine<T> rotation_scaling;
636
637 // First translate to the new origin
638
639 transform.Translate( -new_origin );
640
641 // Build a matrix taking the standard basis vectors to the new basis vectors
642
643 rotation_scaling( 0, 0 ) = new_i.x;
644 rotation_scaling( 0, 1 ) = new_j.x;
645 rotation_scaling( 0, 2 ) = new_k.x;
646 rotation_scaling( 1, 0 ) = new_i.y;
647 rotation_scaling( 1, 1 ) = new_j.y;
648 rotation_scaling( 1, 2 ) = new_k.y;
649 rotation_scaling( 2, 0 ) = new_i.z;
650 rotation_scaling( 2, 1 ) = new_j.z;
651 rotation_scaling( 2, 2 ) = new_k.z;
652
653 // Invert because we want the new basis vectors to become the standard basis vectors
654 rotation_scaling.Invert();
655
656 // Combine the translation and rotation to produce the complete transformation
657 result = rotation_scaling * transform;
658}
659
660/** Gets the transformation from one DisplayObject's object coordinates to another's
661 * Note: This method uses a screen-space transformation (DisplayObject::ModelMatrix). This requires that the two objects have been PreDrawn with the same view, but they do not need to be part of the same object heirarchy.
662 * Use GetObjectCoordinatesTransform unless GetObjectCoordinatesTransformSameView is required.
663 *
664 * \sa GetObjectCoordinatesTransform
665 *
666 * \param from The DisplayObject to start at
667 * \param to The DisplayObject to end at
668 * \param outTransform Out parameter - If the function returns true, this will contain the resulting transformation.
669 * \returns true on success, false if there was an error
670 */
671 GLS_EXPORT bool GetObjectCoordinatesTransformSameView( DisplayObject* from, DisplayObject* to, GlsMatrixType* outTransform );
672
673/// \param frame The DisplayFrame to start at.
674/// \return the Topmost Display Frame.
675 GLS_EXPORT DisplayFrame* GetTopLevelDisplayFrame( DisplayFrame* frame );
676
677/** Gets the transformation from one DisplayObject's object coordinates to another's (if possible)
678 * This is the preferred method for determining the coordinate space relationship between two objects that have DynamicTransforms applied.
679 * Note: This method requires that the two objects are part of the same object heirarchy.
680 * Consider using GetObjectCoordinatesTransformSameView if your situation does not meet this requirement.
681 *
682 * \code
683 * // Example: Move objB to be in the same location as objA (including all DynamicTransforms)
684 * // Change Location of objB so that it's RotationPoint aligns with the RotationPoint of objA
685 * GlsMatrixType transform;
686 * if( GetObjectCoordinatesTransform( objA, objB, &transform ) )
687 * {
688 * Vector objA_rotationPoint_transformed = transform * (objA->Location() + objA->RotationPoint());
689 * objB->Location( objA_rotationPoint_transformed - objB->RotationPoint() );
690 * }
691 * else
692 * {
693 * // Error: objects are not in the same heirarchy
694 * }
695 * \endcode
696 *
697 * \sa GetObjectCoordinatesTransform
698 *
699 * \param from The DisplayObject to start at
700 * \param to The DisplayObject to end at
701 * \param outTransform Out parameter - If the function returns true, this will contain the resulting transformation.
702 * \returns true on success, false if the objects are not in the same heirarchy.
703 */
704 GLS_EXPORT bool GetObjectCoordinatesTransform( DisplayObject* from, DisplayObject* to, GlsMatrixType* outTransform );
705
706/// Test if the given points are not colinear (they are not in a line).
707/// \param a The first point to check.
708/// \param b The second point to check.
709/// \param c The third point to check.
710/// \return True if the points are not colinear.
711/// \return False if the points are colinear.
712 GLS_EXPORT bool NotColinear( const Vector& a, const Vector& b, const Vector& c );
713
714/// Search the given Vertex array for the first three non-colinear vertices.
715/// \param arraySize The size of vertex_array.
716/// \param array The Vertex array.
717/// \param index1 variable to receive 1st array index.
718/// \param index2 variable to receive 2nd array index.
719/// \param index3 variable to receive 3rd array index.
720/// \param isVectorArray true if array points to a Vector array, false if it
721/// points to a Vertex array.
722/// \return true If the vertices were found.
723/// \return false If there are not three non-colinear vertices in the array
724/// if this occurs, the index values are undefined.
725 GLS_EXPORT bool FindNonColinearVertices( int arraySize, Vector array[],
726 int& index1, int& index2, int& index3,
727 bool isVectorArray = true );
728
729/// Vertex version of FindNonColinearVertices.
730/// \param arraySize The size of vertex_array.
731/// \param array The Vertex array.
732/// \param index1 variable to receive 1st array index.
733/// \param index2 variable to receive 2nd array index.
734/// \param index3 variable to receive 3rd array index.
735/// \return true If the vertices were found.
736/// \return false If there are not three non-colinear vertices in the array
737/// if this occurs, the index values are undefined.
738 inline bool FindNonColinearVertices( int arraySize, Vertex array[], int& index1, int& index2, int& index3 )
739{
740 return FindNonColinearVertices( arraySize, array, index1, index2, index3, false );
741}
742
743/// Recalculate the texture points of a given DisplayObject based on its valid texture coordinates.
744/// \param object the object whose texture points are to be calculated
745/// \return true On success.
746/// \return false If the texture points could not be calculated.
747/// (The object doesn't have three non-colinear vertices or doesn't have texture coordinates.)
748 GLS_EXPORT bool CalculateTexPointsFromTexCoords( DisplayObject* object );
749
750/** Encodes a string such that if it contains newlines, it will be wrapped with the "#$STRING_START$#" and "#$STRING_END$#" delimiters.
751 * \param dest Destination string
752 * \param src Source string
753 * \param dest_str_length Size of the destination buffer
754 * \return The length of the encoded string.
755 */
756 GLS_EXPORT int EncodeString( char* dest, const char* src, const int dest_str_length );
757
758/** Encodes a std::string such that there are no whitespace characters in the string
759 * \param src Source string
760 * \return The encoded string
761 */
762 GLS_EXPORT std::string EncodeString( const std::string& src );
763
764/// \return A minimum length for a call to EncodeString.
765/// \note This is based on the clear text delimeters.
766 GLS_EXPORT int EncodedStringMinLength();
767
768/** Encodes a string using C language encoding
769 * \param dest Destination string
770 * \param src Source string
771 * \param dest_str_length Size of the destination buffer
772 * \return The length of the encoded string
773 */
774 GLS_EXPORT int C_EncodeString( char* dest, const char* src, const int dest_str_length );
775
776/** Returns and encoded std::string using C language encoding
777 * \param src Source string
778 * \return The encoded string
779 */
780 GLS_EXPORT std::string C_EncodeString( const std::string& src );
781
782/** Decodes a string that was encoded using EncodeString
783 * \param dest Destination string
784 * \param src Source string
785 * \param dest_str_length Size of the destination buffer
786 * \return The length of the encoded string
787 */
788 GLS_EXPORT int DecodeString( char* dest, const char* src, const int dest_str_length );
789
790/** Decodes a std::string that was encoded using EncodeString
791 * \param src Encoded Source string
792 * \return The decoded string
793 */
794 GLS_EXPORT std::string DecodeString( const std::string& src );
795
796/** The InlinePixmap structure */
797 typedef struct
798{
799 int width; ///< The width in pixels.
800 int height; ///< The height in pixels.
801 int comprSize; ///< The size in bytes.
802 unsigned char* pixels; ///< Pointer to the underlying data buffer.
803} InlinePixmap;
804
805/// Make the incoming path relative to another path.
806/// \param originalPath The path to make relative.
807/// \param relativePath The path to make the path relative from.
808/// \return The resulting relative path, or empty string if not possible.
809 GLS_EXPORT char* MakeRelativePath( const char* originalPath, const char* relativePath );
810
811/// Converts backslashes to forward slashes in the given string.
812/// \param str A pointer to a string that is changed in place.
813 GLS_EXPORT void ConvertBackslashToSlash( char* str );
814
815/// Converts backslashes to forward slashes in the given string.
816/// \param str Reference to a string that is changed in place.
817 GLS_EXPORT void ConvertBackslashToSlash( std::string& str );
818
819/// Determines if the given value falls in any of the ranges passed in.
820/// range_check(int number_of_ranges, double test_value,
821/// int index_0,double range_0_min,double range_0_max,
822/// ...
823/// int index_n,double range_n_min,double range_n_max);
824/// For example, to return 1 for values 0-10 and 2 for values 10-20:
825/// index = range_check(2, val,
826/// 1, 0.0, 10.0,
827/// 2, 10.0, 20.0);
828/// \param num The number of ranges.
829/// \param val The value to test.
830/// \return True if the value is within any of the ranges.
831 GLS_EXPORT int range_check( int num, double val, ... );
832
833/// Attempts to open the given file. Pops up an error message box if the attempt fails.
834/// \param filename The name of the file to open.
835/// \param flags fopen style file arguments (e.g. "r").
836/// \param f Contains file pointer on success.
837/// \return True if the operation was successful.
838 GLS_EXPORT int Safe_fopen( const char* filename, char* flags, FILE** f );
839
840/// Stream version.
841/// \param filename The name of the file to open.
842/// \param flags fopen style file arguments (e.g. "r").
843/// \param outstr The stream to write to.
844/// \return True if the operation was successful.
845 GLS_EXPORT int Safe_fopen( const char* filename, char* flags, std::fstream& outstr );
846
847#ifdef ANDROID
848/** Sets if assets should be loaded directly from the apk (default true).
849 * This only affects Android builds.
850 * \param enableDirectAssetLoading true to allow assets to be loaded directly from the apk
851 * false to force assets to be read from the resource directory (\see SetResourcePath)
852 * \post HasAssetExtension returns false for all filetypes if direct asset loading was disabled
853 */
854 GLS_EXPORT void EnableDirectAssetLoading( bool enableDirectAssetLoading );
855
856/** Returns if the filetype is one that can be loaded directly from the apk assets.
857 * This only affects Android builds.
858 * \param filename The filename with extension to check
859 * \return True if the filetype can be loaded directly from the apk assets,
860 * False if the file is loaded from internal or external storage
861 */
862 GLS_EXPORT bool HasAssetExtension( const char* filename );
863
864/** Returns if the file exists in the apk assets.
865 * This only affects Android builds.
866 * \param filename The name of the file
867 * \return True if the file is an asset that can be opened.
868 * Returns false if no asset exists with filename or the pointer to the AAssetManager, set with SetAssetManager, is null.
869 */
870 GLS_EXPORT bool AssetExists( const char* filename );
871
872/** Sets the Android Asset Manager to use.
873 * When the assetManager is null, apk assets cannot be loaded.
874 * This only affects Android builds.
875 * \param assetManager The pointer to the AAssetManager
876 */
877 GLS_EXPORT void SetAssetManager( AAssetManager* assetManager );
878#endif
879
880#if defined( ANDROID ) || ( defined( __APPLE__ ) && defined( GLES ) && !defined( GLES_ANGLE ) ) || ( defined( LINUX ) && defined( GLES ) && !defined( GLES_ANGLE ) ) || defined( QNX ) || defined( INTEGRITY )
881/** Prepends the resource path to a file name.
882 * \param[in] filename_ The name of the file
883 * \return string containing ResourcePath+filename_, with OS specific path.
884 * On Android, apk asset files are not prepended with a path.
885 */
886 GLS_EXPORT std::string ResolvePath( const char* filename_ );
887
888/** Sets the path for locating resource files.
889 * On Android, this is the location where resources outside of apk assets are found.
890 * \param resourcePath The path where application resources will be found
891 */
892 GLS_EXPORT void SetResourcePath( const char* resourcePath );
893
894/** Attempts to open the given file. Prepends the filename with the path from SetResourcePath
895 * for non-absolute paths.
896 * On Android, filenames that match an apk asset are opened. Opened assets should be closed
897 * with fclose to free resources, not with the Android Asset Manager close function (AAsset_close)
898 * \param filename The name of the file to open
899 * \param flags fopen style file arguments (e.g. "r")
900 * \pre On Android, Asset Manager != NULL, set with SetAssetManager, when opening an apk asset
901 * \return FILE pointer or NULL otherwise
902 */
903 GLS_EXPORT FILE* gls_fopen( const char* filename, const char* flags );
904#else
905/** Pushes a resource search path onto the stack. The CWD is always
906 * implicitly searched first. The resource search paths are local to
907 * the calling thread only. This function should be called from the same
908 * thread as the resources are loaded from.
909 * \param resourcePath The directory path to add to the search paths
910 */
911 GLS_EXPORT void PushResourcePath( const char* resourcePath );
912
913/** Remove the first search path from the stack. The resource search paths
914 * are local to the calling thread only. This function should be called from
915 * the same thread as the matching PushResourcePath.
916 */
917 GLS_EXPORT void PopResourcePath();
918
919/** Pushes a function that can locate resources. The Resources finders are applied after the resource paths are searched
920 * \param finder The function that can locate resources to add to the search paths
921 */
922 GLS_EXPORT void PushResourceFinder( std::string ( *finder )( const std::string& ) );
923
924/// Resolves the given path searching the resource path list.
925/// The CWD is always implicity searched first.
926/// \param path The relative path to resolve.
927/// \return The appropriate resulting resolved path, prepended with the resource path.
928 GLS_EXPORT std::string ResolvePath( const char* path );
929
930/// Helper method taking a std::string.
931/// \param path The relative path to resolve
932/// \return The appropriate resulting resolved path, prepended with the resource path.
933 inline std::string ResolvePath( const std::string& path )
934{
935 return ResolvePath( path.c_str() );
936}
937
938/** Attempts to open the given file. Relative file paths
939 * are resolved using ResolvePath.
940 * \param filename The name of the file to open
941 * \param flags fopen style file arguments (e.g. "r")
942 * \return FILE pointer or NULL otherwise
943 */
944 GLS_EXPORT FILE* gls_fopen( const char* filename, const char* flags );
945#endif
946
947/** Attempts to unlink (delete) a file given
948 a UTF-8 encoded filename.
949 This function is especially useful on Windows platforms where the
950 standard function expects UTF-16 encoded wide character filenames.
951 \param filename The filename to unlink
952 \return Returns 0 is successful, otherwise returns -1 and sets errno.
953*/
954 int gls_unlink( const char* filename );
955
956#if defined( __APPLE__ ) && defined( GLES ) && !defined( GLES_ANGLE )
957/** \return a string indicating the location of a specific file in the default resource bundle.
958 * This method is designed for runtime platforms that have a pre-defined bundle
959 * location that is not immediately known to the application until runtime.
960 * in iOS, this returns the path to the main application bundle with the file name appended.
961 * \param fileName A string referring to the file without a path.
962 */
963 GLS_EXPORT std::string GetAbsolutePathAndFileNameInDefaultResourceBundle( const char* fileName );
964#endif
965
966/** Prepends the resource path to a file name.
967 * \param[in] fileName The name of the file
968 * \return string containing ResourcePath + fileName, with OS specific path.
969 * On Android, apk asset files are not prepended with a path.
970 */
971 GLS_EXPORT std::string ResolveRuntimeResourcePath( const char* fileName );
972
973/// \return True if the file exists, false otherwise.
974/// \param filename The filename to check.
975 GLS_EXPORT bool FileExists( const char* filename );
976
977/// \return True if the file exists, false otherwise.
978/// \param filename The filename to check.
979 GLS_EXPORT bool FileExists( const std::string& filename );
980
981/// \return True if the file exists and is a directory, false otherwise.
982/// \param filename The filename to check.
983 GLS_EXPORT bool IsDirectory( const char* filename );
984
985/// \return True if the file exists and is a directory, false otherwise.
986/// \param filename The filename to check.
987 GLS_EXPORT bool IsDirectory( const std::string& filename );
988
989/** \return The file extension for a filepath
990 * \param filepath Filepath to get extension from
991 */
992 GLS_EXPORT std::string FileExtension( const std::string& filepath );
993
994/** \return The filename from a file path by stripping off anything to the left of a slash
995 * \param filepath
996 */
997 GLS_EXPORT std::string FileName( const std::string& filepath );
998
999/** \return a string containing the path portion of a filename
1000 * by stripping off everything to the right of the rightmost slash
1001 * \param filepath A string containing a file with a path
1002 */
1003 GLS_EXPORT std::string FilePath( const std::string& filepath );
1004
1005/** \return a pointer to the string containing the path portion of a filename
1006 * by stripping off everything to the right of the rightmost slash
1007 * \param name A string containing a file with a path
1008 * \warning If this function is called more than once all previous values WILL CHANGE to contain the newest value
1009 * \deprecated Use FilePath instead
1010 */
1011 GLS_EXPORT const char* GetFilePath( const char* name );
1012
1013/** \return The filename from a file path by stripping off anything to the left of a slash
1014 * \param name A string containing just the file name without a path
1015 * \warning If this function is called more than once all previous values WILL CHANGE to contain the newest value
1016 * \deprecated Use FileName instead
1017 */
1018 GLS_EXPORT char* GetFileName( const char* name );
1019
1020/** Appends a trailing slash to a path string, if one isn't there already
1021 * \param s File path
1022 */
1023 GLS_EXPORT void AppendTrailingSlash( char* s );
1024
1025/** Appends a trailing slash to a path string, if one isn't there already
1026 * \param s File path
1027 */
1028 GLS_EXPORT void AppendTrailingSlash( std::string& s );
1029
1030/** Convert a directory path to have the correct OS
1031 * slashes /, or \. Also make sure that the path ends in a \, or /.
1032 * So you always have the form <name 1>\\<name 2>...<name n>\\\, or <name 1>/<name 2>...<name n>/
1033 * \param path A path to convert
1034 * \return a "new-ed" string which may be longer than the original.
1035 * It is the calling functions responsibility to free the memory.
1036 */
1037 GLS_EXPORT char* PathToOS( const char* path );
1038
1039/** \return The file extension for a filename
1040 * \param filename Filename to get extension from
1041 * No longer allocates memory, you can let the returned string
1042 * be colected as it falls out of scope
1043 */
1044 GLS_EXPORT std::string GetExtension( const std::string& filename );
1045
1046/// \return The file name from a filename with path.
1047/// \note This does not allocate new memory, but rather just returns a pointer inside the original string.
1048/// \param path The path to return the file (base) name from.
1049 GLS_EXPORT const char* GetBaseName( const char* path );
1050
1051/// \return Pointer to a position within the given \a path where the filename starts.
1052/// \deprecated This function is not const-correct. Prefer the const-correct version.
1053/// \param path The path to return the file (base) name from.
1054/// \sa GetBaseName( const char* )
1055 GLS_EXPORT char* GetBaseName( char* path );
1056
1057/** Removes and double slashes from a path.
1058 * It will look for the specified type of slash.
1059 * It will modify path, but since it can only shrink,
1060 * no allocation is done.
1061 * \param path The path to operate on.
1062 * \param slash The type of slash to search for.
1063 */
1064 GLS_EXPORT void RemoveDoubleSlashes( char* path, char slash = '/' );
1065
1066/** Remove all space ' ' characters from the incoming string.
1067 * \param entry String to be manupulated.
1068 */
1069 GLS_EXPORT void RemoveSpaces( std::string& entry );
1070
1071/** Remove all space ' ' characters from the beginning and end of the string.
1072 * \param entry String to be manupulated.
1073 */
1074 GLS_EXPORT void TrimSpaces( std::string& entry );
1075
1076/** \return The minimum angular distance between angle1 and angle2 in degrees
1077 * \param angle1 First angle
1078 * \param angle2 Second angle
1079 */
1080 GLS_EXPORT float AngularDistanceDeg( float angle1, float angle2 );
1081
1082/** \return The minimum angular distance between angle1 and angle2 in radians
1083 * \param angle1 First angle
1084 * \param angle2 Second angle
1085 */
1086 GLS_EXPORT float AngularDistanceRad( float angle1, float angle2 );
1087
1088/// \return Whether or not the incoming string contains something other than whitespace.
1089/// \param val The string to check.
1090 GLS_EXPORT bool ContainsNonBlank( const std::string& val );
1091
1092/// Read bytes from the incoming file, excluding spaces.
1093/// \param f The file to read from.
1094/// \param result A pointer to storage to contain the result modified in place.
1095/// \param maxLen The length of the memory allocated to result in bytes.
1096/// \return True if operation was successful.
1097 GLS_EXPORT bool GetNoSpaces( FILE* f, char* result, int maxLen );
1098
1099/// Reads to the next end of line and stores the result.
1100/// \param instr The stream to read from.
1101/// \param result The string reference to write the result to.
1102/// \param decode Whether or not to decode the string.
1103/// \return True if successful.
1104 GLS_EXPORT bool GetToEnd( std::istream& instr, std::string& result, bool decode );
1105
1106/// Reads a Vertex from the stream.
1107/// \param instr The stream to read from.
1108/// \param vert The Vertex pointer to write the result to.
1109/// \param getColor Whether or not to parse the color also.
1110/// \return True if successful.
1111 GLS_EXPORT bool GetVertex( std::istream& instr, Vertex* vert, bool getColor );
1112
1113/// Searches the specified binary file for the specified tag, and adds what immediatly follows the tag to the nameList.
1114/// \param dllFileName The path of the binary to search.
1115/// \param nameList The returned list of relevant symbol names.
1116/// \param createClassTag The symbol prefix to search for.
1117/// \return True if at least one is found, false otherwise.
1118 GLS_EXPORT bool GetComponentClassNames( const char* dllFileName, DynamicArray<std::string>& nameList, const char* createClassTag = "CreateComponent_" );
1119
1120/// Opens the shared library and attempts to run GlsDefaultClassName(), if found.
1121/// \param dllFileName The file name of the shared library to search in.
1122/// \return The located class name, or an empty string if not found.
1123 GLS_EXPORT std::string GetDefaultComponentClassName( const char* dllFileName );
1124
1125/** Returns the qualified instance name of an object that is
1126 * contained within given DisplayFrame. (e.g "cockpit.altimeter.needle")
1127 * Note that names are only added for each DisplayFrame (not every Group)
1128 * and the name of the topFrame is not included in the qualified name.
1129 * \param topFrame The frame in which the qualification will make sense.
1130 * \param obj The object which is a direct child or located somewhere below topFrame.
1131 * \returns The qualified instance name or an empty string if the qualified
1132 * instance name could not be determined. */
1133 GLS_EXPORT std::string GetQualifiedInstanceName( const DisplayFrame* topFrame, const DisplayObject* obj );
1134
1135#if !defined( GLES ) || defined( GLES_ANGLE )
1136/// Opens a native WIN32 open file dialog on Windows, a FLTK dialog on other platforms.
1137/// \param win The FLTK window to open the dialog on top of.
1138/// \param filePath The initially selected / returned file.
1139/// \param filePathSize The size of the filePath buffer in bytes.
1140/// \param directory The initially selected / returned directory.
1141/// \param filterStr The file type filter string.
1142/// \param defaultExt The default file extension.
1143/// \param title The window title for the dialog.
1144/// \param multiSelect Whether or not to allow multiple files to be selected.
1145/// \param createFile Whether or not the dialog will allow a new file to be created.
1146/// \param fileMustExist Whether or not the specified file must already exist.
1147/// \param pathMustExist Whether or not the specified directory must already exist.
1148/// \param noChangeDirectory Whether or not the dialog will allow the user to change CWD.
1149/// \return True if a file was located successfully.
1150 GLS_EXPORT bool OpenFileDialog( Fl_Window* win, char* filePath, unsigned int filePathSize,
1151 char* directory = NULL, const char* filterStr = NULL,
1152 const char* defaultExt = NULL, const char* title = NULL,
1153 bool multiSelect = false, bool createFile = false,
1154 bool fileMustExist = false, bool pathMustExist = false,
1155 bool noChangeDirectory = false );
1156
1157/// Opens a native WIN32 save file dialog on Windows, a FLTK dialog on other platforms.
1158/// \param win The FLTK window to open the dialog on top of.
1159/// \param filePath The initially selected / returned file.
1160/// \param filePathSize The size of the filePath buffer in bytes.
1161/// \param directory The initially selected / returned directory.
1162/// \param filterStr The file type filter string.
1163/// \param defaultExt The default file extension.
1164/// \param title The window title for the dialog.
1165/// \param createFile Whether or not the dialog will allow a new file to be created.
1166/// \param fileMustExist Whether or not the specified file must already exist.
1167/// \param pathMustExist Whether or not the specified directory must already exist.
1168/// \param noChangeDirectory Whether or not the dialog will allow the user to change CWD.
1169/// \return True if a file was located successfully.
1170 GLS_EXPORT bool SaveFileDialog( Fl_Window* win, char* filePath, unsigned int filePathSize,
1171 char* directory = NULL, const char* filterStr = NULL,
1172 const char* defaultExt = NULL, const char* title = NULL,
1173 bool createFile = false,
1174 bool fileMustExist = false, bool pathMustExist = false,
1175 bool noChangeDirectory = false );
1176#endif
1177
1178/// Checks the OpenGL error state, and prints to stdout if there was an error.
1179 GLS_EXPORT void CheckGLError();
1180
1181//---------------------------------------------------------------------------
1182/**
1183 * Returns a string which is the uppercase version of the passed parameter.
1184 *
1185 * \param str original string to convert to Uppercase
1186 *
1187 * \return a string copy of the original but in all caps.
1188 */
1189 GLS_EXPORT std::string Uppercase( const std::string& str );
1190
1191/// Substitutes environment variables for their actual values in the incoming path.
1192/// \param originalPath Path to substitute environment variables.
1193/// \return The string with environment variables replaced with their actual paths.
1194 GLS_EXPORT std::string ReplaceEnvironmentVariables( const char* originalPath );
1195
1196/** A singleton used for accessing the command line arguments in generated code */
1197 class glsCommandLine
1198{
1199 public:
1200 GLS_EXPORT glsCommandLine();
1201
1202 /// Parses the command line and takes action accordingly.
1203 /// \param argc The number of arguments.
1204 /// \param argv The array of arguments.
1205 GLS_EXPORT void ReadCommandLine( int argc, char** argv );
1206
1207 /// Prints the usage instructions for the command line operations to stdout.
1208 GLS_EXPORT void Usage();
1209
1210 int _argc; ///< The number of arguments.
1211 char** _argv; ///< The array of arguments.
1212
1213 /// \return Whether or not the app should run in silent mode.
1214 bool SilentMode() const { return _silentMode; }
1215
1216 /// \return The glsCommandLine singleton instance.
1217 static GLS_EXPORT glsCommandLine* Instance();
1218
1219 private:
1220 bool _silentMode;
1221 static ScopedPtr<glsCommandLine> _instance;
1222};
1223
1224/** Used to make interface information visible to the user at design time*/
1225 class InterfaceDescriptionClass DISTI_FINAL
1226{
1227 char* _code; ///< e.g. "DynamicRotate("
1228 char* _usage; ///< e.g. "void DynamicRotate(float angle, int axis)"
1229 char* _comment; ///< e.g. "Sets dynamic rotation in degrees for the specified axis"
1230
1231 public:
1232 GLS_EXPORT InterfaceDescriptionClass();
1233
1234 /// Constructor
1235 /// \param code Method name only.
1236 /// \param usage Full method signature.
1237 /// \param comment Associated comment.
1238 GLS_EXPORT InterfaceDescriptionClass( const char* code, const char* usage, const char* comment );
1239
1240 GLS_EXPORT ~InterfaceDescriptionClass();
1241
1242 /// Copy constructor
1243 /// \param source The object to copy from.
1244 GLS_EXPORT InterfaceDescriptionClass( const InterfaceDescriptionClass& source );
1245
1246 /// Assignment constructor
1247 /// \param source The object to copy from.
1248 /// \return The resulting object (this).
1249 GLS_EXPORT InterfaceDescriptionClass& operator=( const InterfaceDescriptionClass& source );
1250
1251 /// Set the code member to a new value.
1252 GLS_EXPORT void Code( const char* );
1253
1254 /// Set the usage member to a new value.
1255 GLS_EXPORT void Usage( const char* );
1256
1257 /// Set the comment member to a new value.
1258 GLS_EXPORT void Comment( const char* );
1259
1260 /// \return The current code member.
1261 const char* Code() const { return _code; }
1262
1263 /// \return The current usage member.
1264 const char* Usage() const { return _usage; }
1265
1266 /// \return The current comment member.
1267 const char* Comment() const { return _comment; }
1268
1269#if defined( DISTI_HAS_RVAL_REFS )
1270 /// Move constructor
1271 /// \param source The object to move from.
1272 InterfaceDescriptionClass( InterfaceDescriptionClass&& source )
1273 : _code( NULL )
1274 , _usage( NULL )
1275 , _comment( NULL )
1276 {
1277 StealFrom( source );
1278 }
1279
1280 /// Assignment move operator
1281 /// \param source The object to move from.
1282 /// \return The resulting object (this).
1283 InterfaceDescriptionClass& operator=( InterfaceDescriptionClass&& source )
1284 {
1285 if( this != &source )
1286 {
1287 // Destroy current values
1288 delete[] _code;
1289 delete[] _usage;
1290 delete[] _comment;
1291
1292 StealFrom( source );
1293 }
1294 return *this;
1295 }
1296
1297 private:
1298 void StealFrom( InterfaceDescriptionClass& source )
1299 {
1300 // Take ownership
1301 _code = source._code;
1302 _usage = source._usage;
1303 _comment = source._comment;
1304
1305 // Relieve of ownership
1306 source._code = NULL;
1307 source._usage = NULL;
1308 source._comment = NULL;
1309 }
1310#endif
1311};
1312
1313 typedef DynamicArray<InterfaceDescriptionClass> InterfaceListType; ///< Typedef for a list of interface description objects.
1314
1315/** Base class for GlsMultiVal template */
1316 class GlsMultiValBase
1317{
1318 public:
1319 virtual ~GlsMultiValBase() {}
1320
1321 // These are used to avoid template problems with VC6.0
1322 typedef std::ostream ostreamType; ///< Typedef shorthand for std::ostream.
1323 typedef std::istream istreamType; ///< Typedef shorthand for std::istream.
1324
1325 /// This function serializes itself into the provided stream object.
1326 /// \param outstr This is the object used by the GlsMultiVal class to serialize itself onto.
1327 virtual void StreamOut( ostreamType& outstr ) const = 0;
1328
1329 /// Uses the provided istream object to populate the current GlsMultiVal object.
1330 /// \param instr This is the stream object used by the GlsMultiVal instance to populate itself.
1331 virtual void StreamIn( istreamType& instr ) = 0;
1332};
1333
1334/** GlsMultiVal is used to effectivly create a structure containing up
1335 * to 10 values of varying types. An instance of the class is capable
1336 * of streaming itself to and from a text stream. The individual values
1337 * will be separated by spaces when written and read from the stream.
1338 * The types have to follow some rules:
1339 * - They must themselves have the << and >> stream operators defined.
1340 * - operator>> must read all data written by operator<< and must not consume spaces or other characters that follow it
1341 * - They must have a default constructor
1342 * - They must have a copy constructor
1343 * - They shall not be void* (it is used for determining the end of the desired types).
1344 * - If a GlsPropString is used, there must be only one, and it *must* be the
1345 * last entry in the GlsMultiVal instance.
1346 * - A GlsPropStringQuoted will work in any position.
1347 * This is intended primarily for the GL Studio end user to use as a Class Property type.
1348 */
1349 template<class T1,
1350 class T2 = void*,
1351 class T3 = void*,
1352 class T4 = void*,
1353 class T5 = void*,
1354 class T6 = void*,
1355 class T7 = void*,
1356 class T8 = void*,
1357 class T9 = void*,
1358 class T10 = void*>
1359 class GlsMultiVal : public GlsMultiValBase
1360{
1361 int _numVals;
1362 void CalcNumVals()
1363 {
1364 _numVals = 1;
1365 if( typeid( T2 ) != typeid( void* ) )
1366 _numVals++;
1367 else
1368 return;
1369 if( typeid( T3 ) != typeid( void* ) )
1370 _numVals++;
1371 else
1372 return;
1373 if( typeid( T4 ) != typeid( void* ) )
1374 _numVals++;
1375 else
1376 return;
1377 if( typeid( T5 ) != typeid( void* ) )
1378 _numVals++;
1379 else
1380 return;
1381 if( typeid( T6 ) != typeid( void* ) )
1382 _numVals++;
1383 else
1384 return;
1385 if( typeid( T7 ) != typeid( void* ) )
1386 _numVals++;
1387 else
1388 return;
1389 if( typeid( T8 ) != typeid( void* ) )
1390 _numVals++;
1391 else
1392 return;
1393 if( typeid( T9 ) != typeid( void* ) )
1394 _numVals++;
1395 else
1396 return;
1397 if( typeid( T10 ) != typeid( void* ) )
1398 _numVals++;
1399 else
1400 return;
1401 }
1402
1403 public:
1404 T1 _val1; ///< The first value.
1405 T2 _val2; ///< The second value.
1406 T3 _val3; ///< The third value.
1407 T4 _val4; ///< The fourth value.
1408 T5 _val5; ///< The fifth value.
1409 T6 _val6; ///< The sixth value.
1410 T7 _val7; ///< The seventh value.
1411 T8 _val8; ///< The eighth value.
1412 T9 _val9; ///< The ninth value.
1413 T10 _val10; ///< The tenth value.
1414
1415 /** Default constructor.
1416 * The _val member types must have default constructors.
1417 */
1418 GlsMultiVal()
1419 {
1420 CalcNumVals();
1421 }
1422
1423 /// Copy constructor.
1424 /// This GlsMultiVal will copy values from the src GlsMultiVal.
1425 /// \param src GlsMultiVal object to use for initialization.
1426 GlsMultiVal( const GlsMultiVal& src )
1427 : _val1( src._val1 )
1428 , _val2( src._val2 )
1429 , _val3( src._val3 )
1430 , _val4( src._val4 )
1431 , _val5( src._val5 )
1432 , _val6( src._val6 )
1433 , _val7( src._val7 )
1434 , _val8( src._val8 )
1435 , _val9( src._val9 )
1436 , _val10( src._val10 )
1437 {
1438 CalcNumVals();
1439 }
1440
1441 /// Full constructor. Creates a GlsMultiVal object with the provided data.
1442 /// \param val1 First value to use for intialization of type T1.
1443 /// \param val2 Second value to use for intialization of type T2.
1444 /// \param val3 Third value to use for intialization of type T3.
1445 /// \param val4 Fourth value to use for intialization of type T4.
1446 /// \param val5 Fifth value to use for intialization of type T5.
1447 /// \param val6 Sixth value to use for intialization of type T6.
1448 /// \param val7 Seventh value to use for intialization of type T7.
1449 /// \param val8 Eighth value to use for intialization of type T8.
1450 /// \param val9 Ninth value to use for intialization of type T9.
1451 /// \param val10 Tenth value to use for intialization of type T10.
1452 GlsMultiVal(
1453 const T1& val1,
1454 const T2& val2 = T2(),
1455 const T3& val3 = T3(),
1456 const T4& val4 = T4(),
1457 const T5& val5 = T5(),
1458 const T6& val6 = T6(),
1459 const T7& val7 = T7(),
1460 const T8& val8 = T8(),
1461 const T9& val9 = T9(),
1462 const T10& val10 = T10() )
1463 : _val1( val1 )
1464 , _val2( val2 )
1465 , _val3( val3 )
1466 , _val4( val4 )
1467 , _val5( val5 )
1468 , _val6( val6 )
1469 , _val7( val7 )
1470 , _val8( val8 )
1471 , _val9( val9 )
1472 , _val10( val10 )
1473 {
1474 CalcNumVals();
1475 }
1476
1477 /// Equality operator
1478 /// \param val The object to compare against.
1479 /// \return True if the objects are equal.
1480 virtual bool operator==( const GlsMultiVal& val ) const
1481 {
1482 bool rval = true;
1483 // Only compare the number of used values.
1484 switch( _numVals )
1485 {
1486 // No breaks is intentional
1487 case 10: rval &= ( _val10 == val._val10 );
1488 case 9: rval &= ( _val9 == val._val9 );
1489 case 8: rval &= ( _val8 == val._val8 );
1490 case 7: rval &= ( _val7 == val._val7 );
1491 case 6: rval &= ( _val6 == val._val6 );
1492 case 5: rval &= ( _val5 == val._val5 );
1493 case 4: rval &= ( _val4 == val._val4 );
1494 case 3: rval &= ( _val3 == val._val3 );
1495 case 2: rval &= ( _val2 == val._val2 );
1496 case 1:
1497 rval &= ( _val1 == val._val1 );
1498 break;
1499 default:
1500 rval = false;
1501 }
1502 return rval;
1503 }
1504
1505 /// Inequality operator
1506 /// \param val The object to compare against.
1507 /// \return True if the objects are not equal.
1508 virtual bool operator!=( const GlsMultiVal& val ) const
1509 {
1510 return !( *this == val );
1511 }
1512
1513 virtual void StreamOut( ostreamType& outstr ) const DISTI_METHOD_OVERRIDE
1514 {
1515 outstr << _val1;
1516 if( _numVals >= 2 )
1517 outstr << " " << _val2;
1518 if( _numVals >= 3 )
1519 outstr << " " << _val3;
1520 if( _numVals >= 4 )
1521 outstr << " " << _val4;
1522 if( _numVals >= 5 )
1523 outstr << " " << _val5;
1524 if( _numVals >= 6 )
1525 outstr << " " << _val6;
1526 if( _numVals >= 7 )
1527 outstr << " " << _val7;
1528 if( _numVals >= 8 )
1529 outstr << " " << _val8;
1530 if( _numVals >= 9 )
1531 outstr << " " << _val9;
1532 if( _numVals >= 10 )
1533 outstr << " " << _val10;
1534 }
1535
1536 virtual void StreamIn( istreamType& instr ) DISTI_METHOD_OVERRIDE
1537 {
1538 instr >> _val1;
1539 if( _numVals >= 2 )
1540 {
1541 instr.get(); // The separating space
1542 instr >> _val2;
1543 }
1544 if( _numVals >= 3 )
1545 {
1546 instr.get();
1547 instr >> _val3;
1548 }
1549 if( _numVals >= 4 )
1550 {
1551 instr.get();
1552 instr >> _val4;
1553 }
1554 if( _numVals >= 5 )
1555 {
1556 instr.get();
1557 instr >> _val5;
1558 }
1559 if( _numVals >= 6 )
1560 {
1561 instr.get();
1562 instr >> _val6;
1563 }
1564 if( _numVals >= 7 )
1565 {
1566 instr.get();
1567 instr >> _val7;
1568 }
1569 if( _numVals >= 8 )
1570 {
1571 instr.get();
1572 instr >> _val8;
1573 }
1574 if( _numVals >= 9 )
1575 {
1576 instr.get();
1577 instr >> _val9;
1578 }
1579 if( _numVals >= 10 )
1580 {
1581 instr.get();
1582 instr >> _val10;
1583 }
1584 }
1585};
1586
1587/// Stream out operator
1588/// \param outstr The stream to write to.
1589/// \param multiVal The value to write to the stream.
1590/// \return The stream in its current state.
1591 GLS_EXPORT std::ostream& operator<<( std::ostream& outstr, const GlsMultiValBase& multiVal );
1592
1593/// Stream in operator
1594/// \param instr The stream to read from.
1595/// \param multiVal The returned value read from the stream.
1596/// \return The stream in its current state.
1597 GLS_EXPORT std::istream& operator>>( std::istream& instr, GlsMultiValBase& multiVal );
1598
1599/** GlsPropString is designed to be used as a string in GL Studio Class Properties.
1600 * It writes itself out as a single line, and will read in up to the next newline.
1601 * It will attempt to convert itself to and from std::strings.
1602 * If it is used in a GlsMultiVal, there must be only one, and it *must* be the
1603 * last entry in the GlsMultiVal instance.
1604 * See GlsPropStringQuoted for more usefulness in GlsMultiVal.
1605 */
1606 class GlsPropString
1607{
1608 public:
1609 std::string _string; ///< The underlying wrapped string.
1610
1611 /// Default constructor. Creates an empty GlsPropString.
1612 GlsPropString()
1613 : _string( "" )
1614 {
1615 }
1616
1617 /// Create a new GlsPropString using the provided std string.
1618 /// \param str The std::string to use to create the GlsPropString.
1619 GlsPropString( const std::string& str )
1620 : _string( str )
1621 {
1622 }
1623
1624 /// Create a new GlsPropString using the provided C-style string.
1625 /// \param str The C-style string to use to create the GlsPropString.
1626 GlsPropString( const char* str )
1627 : _string( str ? str : "" )
1628 {
1629 }
1630
1631 /// \return The underlying string value for this object.
1632 operator std::string() const
1633 {
1634 return _string;
1635 }
1636
1637 /** Get the string value for this object.
1638 * \return std::string containing the string value for this object.
1639 */
1640 std::string& String()
1641 {
1642 return _string;
1643 }
1644
1645 /// Checks lexicographic equality of the two arguments.
1646 /// \param str1 One object to compare.
1647 /// \param str2 The other object to compare.
1648 /// \return True if the objects are equal.
1649 friend inline bool operator==( const GlsPropString& str1, const GlsPropString& str2 )
1650 {
1651 return str1._string == str2._string;
1652 }
1653
1654 /// Checks lexicographic inequality of the two arguments.
1655 /// \param str1 One object to compare.
1656 /// \param str2 The other object to compare.
1657 /// \return True if the objects are not equal.
1658 friend inline bool operator!=( const GlsPropString& str1, const GlsPropString& str2 )
1659 {
1660 return !( str1 == str2 );
1661 }
1662};
1663
1664/// Stream out operator
1665/// \param outstr The stream to write to.
1666/// \param str The value to write to the stream.
1667/// \return The stream in its current state.
1668 inline std::ostream& operator<<( std::ostream& outstr, const GlsPropString& str )
1669{
1670 outstr << disti::C_EncodeString( str._string );
1671 return outstr;
1672}
1673
1674/// Stream in operator
1675/// \param instr The stream to read from.
1676/// \param str The returned value read from the stream.
1677/// \return The stream in its current state.
1678 inline std::istream& operator>>( std::istream& instr, GlsPropString& str )
1679{
1680 std::string temp;
1681 disti::GetToEnd( instr, temp, false );
1682 str._string = disti::DecodeString( temp );
1683
1684 return instr;
1685}
1686
1687/** GlsPropStringQuoted is designed to be used as a string in GL Studio Class Properties.
1688 * It writes itself out as a single line surrounded with quotes (""), and will read in up to the next un-escaped quote.
1689 * It will attempt to convert itself to and from std::strings.
1690 * Use of GlsPropStringQuoted is preferred over GlsPropString for use in a GlsMultiVal.
1691 */
1692 class GlsPropStringQuoted
1693{
1694 public:
1695 std::string _string; ///< The underlying wrapped string.
1696
1697 /// Default constructor, create an empty GlsPropStringQuoted object.
1698 GlsPropStringQuoted()
1699 {
1700 }
1701
1702 /// Constructor, create a new GlsPropStringQuoted object using the provided std::string object.
1703 /// \param str The std::string object to use to create the GlsPropStringQuoted object
1704 GlsPropStringQuoted( const std::string& str )
1705 : _string( str )
1706 {
1707 }
1708
1709 /// Constructor, create a new GlsPropStringQuoted object using the provided C-style string.
1710 /// \param str the C-style string to use to create the GlsPropStringQuoted object.
1711 GlsPropStringQuoted( const char* str )
1712 : _string( str )
1713 {
1714 }
1715
1716 /// \return The underlying string value for this object.
1717 operator std::string() const
1718 {
1719 return _string;
1720 }
1721
1722 /// \return The underlying string value for this object.
1723 std::string& String()
1724 {
1725 return _string;
1726 }
1727
1728 /// Equality operator
1729 /// \param str The object to compare.
1730 /// \return True if the objects are equal.
1731 bool operator==( const GlsPropStringQuoted& str ) const
1732 {
1733 return str._string == _string;
1734 }
1735};
1736
1737/// Stream out operator
1738/// \param outstr The stream to write to.
1739/// \param str The value to write to the stream.
1740/// \return The stream in its current state.
1741 inline std::ostream& operator<<( std::ostream& outstr, const GlsPropStringQuoted& str )
1742{
1743 outstr << '\"' << disti::C_EncodeString( str._string ) << '\"';
1744 return outstr;
1745}
1746
1747/// Stream in operator
1748/// \param instr The stream to read from.
1749/// \param str The returned value read from the stream.
1750/// \return The stream in its current state.
1751 inline std::istream& operator>>( std::istream& instr, GlsPropStringQuoted& str )
1752{
1753 std::string temp;
1754 str._string = "";
1755
1756 // The next character should be a quote.
1757 // If it is not, we will attempt to do something useful anyway.
1758 if( instr.peek() != '\"' )
1759 {
1760 disti::GetToEnd( instr, temp, false );
1761 }
1762 else // Starts with quote
1763 {
1764 // Go ahead and consume the quote
1765 instr.get();
1766
1767 int lastChar = 0;
1768 int currChar = 0;
1769 // Loop until we find an un-escaped quote or we run out of stream.
1770 while( instr.good() )
1771 {
1772 lastChar = currChar;
1773 currChar = instr.get();
1774 if( currChar != -1 )
1775 {
1776 if( currChar == '\"' && lastChar != '\\' )
1777 break; // We found the trailing quote
1778 temp += (char)currChar;
1779 }
1780 }
1781 }
1782
1783 str._string = disti::DecodeString( temp );
1784
1785 return instr;
1786}
1787
1788/// String concatenation operator
1789/// \param a First string in concatenation.
1790/// \param b Second string in concatenation.
1791/// \return Value of \p a concatenated with \p b.
1792 inline GlsPropString operator+( const GlsPropString& a, GlsPropString& b )
1793{
1794 return GlsPropString( a._string + b._string );
1795}
1796
1797/// String concatenation operator
1798/// \param a First string in concatenation.
1799/// \param b Second string in concatenation.
1800/// \return Value of \p a concatenated with \p b.
1801 inline GlsPropString operator+( const GlsPropString& a, const GlsPropStringQuoted& b )
1802{
1803 return GlsPropString( a._string + b._string );
1804}
1805
1806/// String concatenation operator
1807/// \param a First string in concatenation.
1808/// \param b Second string in concatenation.
1809/// \return Value of \p a concatenated with \p b.
1810 inline GlsPropStringQuoted operator+( const GlsPropStringQuoted& a, GlsPropStringQuoted& b )
1811{
1812 return GlsPropStringQuoted( a._string + b._string );
1813}
1814
1815/// String concatenation operator
1816/// \param a First string in concatenation.
1817/// \param b Second string in concatenation.
1818/// \return Value of \p a concatenated with \p b.
1819 inline GlsPropStringQuoted operator+( const GlsPropStringQuoted& a, const GlsPropString& b )
1820{
1821 return GlsPropStringQuoted( a._string + b._string );
1822}
1823
1824/// String concatenation operator
1825/// \param a First string in concatenation.
1826/// \param b Second string in concatenation.
1827/// \return Value of \p a concatenated with \p b.
1828 inline std::string operator+( const std::string& a, const GlsPropString& b )
1829{
1830 return std::string( a + b._string );
1831}
1832
1833/// String concatenation operator
1834/// \param a First string in concatenation.
1835/// \param b Second string in concatenation.
1836/// \return Value of \p a concatenated with \p b.
1837 inline std::string operator+( const std::string& a, const GlsPropStringQuoted& b )
1838{
1839 return std::string( a + b._string );
1840}
1841
1842/// String append operator
1843/// \param a String that will be appended.
1844/// \param b String that will be appended to \p a.
1845/// \return Reference to \p a after value of \p b has been appended to \p a.
1846 inline GlsPropString& operator+=( GlsPropString& a, const GlsPropString& b )
1847{
1848 a._string += b._string;
1849 return a;
1850}
1851
1852/// String append operator
1853/// \param a String that will be appended.
1854/// \param b String that will be appended to \p a.
1855/// \return Reference to \p a after value of \p b has been appended to \p a.
1856 inline GlsPropString& operator+=( GlsPropString& a, const GlsPropStringQuoted& b )
1857{
1858 a._string += b._string;
1859 return a;
1860}
1861
1862/// String append operator
1863/// \param a String that will be appended.
1864/// \param b String that will be appended to \p a.
1865/// \return Reference to \p a after value of \p b has been appended to \p a.
1866 inline GlsPropString& operator+=( GlsPropString& a, const char* b )
1867{
1868 a._string += b;
1869 return a;
1870}
1871
1872/// String append operator
1873/// \param a String that will be appended.
1874/// \param b String that will be appended to \p a.
1875/// \return Reference to \p a after value of \p b has been appended to \p a.
1876 inline GlsPropString& operator+=( GlsPropString& a, const std::string& b )
1877{
1878 a._string += b;
1879 return a;
1880}
1881
1882/// String append operator
1883/// \param a String that will be appended.
1884/// \param b String that will be appended to \p a.
1885/// \return Reference to \p a after value of \p b has been appended to \p a.
1886 inline GlsPropStringQuoted& operator+=( GlsPropStringQuoted& a, const GlsPropStringQuoted& b )
1887{
1888 a._string += b._string;
1889 return a;
1890}
1891
1892/// String append operator
1893/// \param a String that will be appended.
1894/// \param b String that will be appended to \p a.
1895/// \return Reference to \p a after value of \p b has been appended to \p a.
1896 inline GlsPropStringQuoted& operator+=( GlsPropStringQuoted& a, const GlsPropString& b )
1897{
1898 a._string += b._string;
1899 return a;
1900}
1901
1902/// String append operator
1903/// \param a String that will be appended.
1904/// \param b String that will be appended to \p a.
1905/// \return Reference to \p a after value of \p b has been appended to \p a.
1906 inline GlsPropStringQuoted& operator+=( GlsPropStringQuoted& a, const char* b )
1907{
1908 a._string += b;
1909 return a;
1910}
1911
1912/// String append operator
1913/// \param a String that will be appended.
1914/// \param b String that will be appended to \p a.
1915/// \return Reference to \p a after value of \p b has been appended to \p a.
1916 inline GlsPropStringQuoted& operator+=( GlsPropStringQuoted& a, const std::string& b )
1917{
1918 a._string += b;
1919 return a;
1920}
1921
1922/// String append operator
1923/// \param a String that will be appended.
1924/// \param b String that will be appended to \p a.
1925/// \return Reference to \p a after value of \p b has been appended to \p a.
1926 inline std::string& operator+=( std::string& a, const GlsPropString& b )
1927{
1928 a += b._string;
1929 return a;
1930}
1931
1932/// String append operator
1933/// \param a String that will be appended.
1934/// \param b String that will be appended to \p a.
1935/// \return Reference to \p a after value of \p b has been appended to \p a.
1936 inline std::string& operator+=( std::string& a, const GlsPropStringQuoted& b )
1937{
1938 a += b._string;
1939 return a;
1940}
1941
1942#ifndef WIN32
1943/// Open the default web browser and go to the specified URL.
1944/// \param url The URL to navigate to.
1945 void SpawnBrowser( const char* url );
1946#endif
1947
1948/// Call this to check for the availability of a DiSTI controlled license.
1949/// It does not hold the license. It only checks it out and checks it back in.
1950/// \param licenseGroupName A name for what this license allows. i.e. "GL Studio Runtime".
1951/// \param feature The specific feature that will be checked out.
1952/// \param version The specific version that will be checked out.
1953/// \param quiet When true, no popup will occur upon missing license.
1954/// \return true if the license is available
1955 GLS_EXPORT bool CheckDistiLicense( const char* licenseGroupName, const char* feature, const char* version, bool quiet );
1956
1957/// This will set the m parameter to an orthographic projection.
1958/// The current value of m is ignored.
1959/// This does NOT make any OpenGL calls.
1960/// \param m The matrix to hold the resulting orthographic projection.
1961/// \param left The left side coordinate.
1962/// \param right The right side coordinate.
1963/// \param bottom The bottom side coordinate.
1964/// \param top The top side coordinate.
1965/// \param zNear The near clipping coordinate.
1966/// \param zFar The far clipping coordinate.
1967 GLS_EXPORT void GlsGetOrtho( GlsMatrixType& m,
1968 double left,
1969 double right,
1970 double bottom,
1971 double top,
1972 double zNear,
1973 double zFar );
1974
1975/// This will set the m parameter to a perspective projection.
1976/// The current value of m is ignored.
1977/// This does NOT make any OpenGL calls.
1978/// \param m The matrix to hold the resulting perspective projection.
1979/// \param fovy The vertical FOV in degrees.
1980/// \param aspect The aspect ratio.
1981/// \param zNear The near clipping distance.
1982/// \param zFar The far clipping distance.
1983 GLS_EXPORT void GlsGetPerspective( GlsMatrixType& m,
1984 double fovy,
1985 double aspect,
1986 double zNear,
1987 double zFar );
1988
1989// using a namespace to help avoid collisions with user code. Future functionality should prefer to go here
1990 namespace Util
1991{
1992 /// Clamps a value to the range [min, max].
1993 /// \param val The value to clamp.
1994 /// \param min The minimum value in the range.
1995 /// \param max The maximum value in the range.
1996 /// \return The value clamped between min and max.
1997 template<class T>
1998 T Clamp( const T& val, const T& min, const T& max )
1999 {
2000 return std::min( max, std::max( min, val ) );
2001 }
2002
2003 /// Split a string and add to existing vector of elements with delimeters removed.
2004 /// \param s The string to split
2005 /// \param delim The delimiter to split the string on.
2006 /// \param elems The vector of elements to append each split string to.
2007 /// \param maxElems The maximum number of elements to split. Remaining elements
2008 /// are appended unsplit as the last value. If 0, it does not
2009 /// have a maximum.
2010 /// \note Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c
2011 inline void Split( const std::string& s, const char delim, std::vector<std::string>& elems, const std::size_t maxElems = 0 )
2012 {
2013 std::istringstream ss( s );
2014 std::string item;
2015 while( std::getline( ss, item, delim ) )
2016 {
2017 elems.push_back( DISTI_RVAL_MOVE( item ) );
2018 if( elems.size() == maxElems )
2019 {
2020 break;
2021 }
2022 }
2023
2024 if( maxElems > 0 && elems.size() == maxElems && ss.good() )
2025 {
2026 std::string remainder;
2027 std::getline( ss, remainder, '\0' );
2028 elems.back() += delim + remainder;
2029 }
2030 else if( s.size() && s.at( s.size() - 1 ) == delim )
2031 {
2032 // Handle the case where the last item is an empty string.
2033 elems.push_back( "" );
2034 }
2035 }
2036
2037 /// Split a string return a vector of the elements with delimeters removed.
2038 /// \param s The string to split
2039 /// \param delim The delimiter to split the string on.
2040 /// \param maxElems The maximum number of elements to split. Remaining elements
2041 /// are appended unsplit as the last value. If 0, it does not
2042 /// have a maximum.
2043 /// \return The vector of split elements.
2044 /// \note Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c
2045 inline std::vector<std::string> Split( const std::string& s, const char delim, const std::size_t maxElems = 0 )
2046 {
2047 std::vector<std::string> elems;
2048 Split( s, delim, elems, maxElems );
2049 return elems;
2050 }
2051
2052 /// Passing null to std::string is not well-defined. Creates a string safely.
2053 /// \param cStr The string to create a std::string from.
2054 /// \return A std::string created from the incoming C string.
2055 inline std::string MakeString( const char* const cStr )
2056 {
2057 return ( cStr ? cStr : "" );
2058 }
2059} // namespace Util
2060
2061///////////////////////////////////////////////////////////////////////////////////////////////////
2062// Forward declarations for globals managed by GlsGlobals.
2063 class GlsFontMan;
2064 class IGlsStateManager;
2065 class List_c;
2066 class Mutex;
2067 class TextureLoaderList;
2068
2069/// Hold global objects so we can control order of destruction.
2070 class GlsGlobals
2071{
2072 public:
2073 /// \return The GlsGlobals singleton instance.
2074 GLS_EXPORT static GlsGlobals& Instance();
2075
2076 /// \return The image list.
2077 /// \sa GetImageListMutex()
2078 GLS_EXPORT List_c& GetImageList();
2079
2080 /// \return The mutex for protecting the image list.
2081 /// \sa GetImageList()
2082 GLS_EXPORT Mutex& GetImageListMutex();
2083
2084 /// \return The global font manager.
2085 GLS_EXPORT GlsFontMan& GetFontMan();
2086
2087 /// \return The global state manager instance.
2088 GLS_EXPORT IGlsStateManager& GetStateManager();
2089
2090 /// \return The global list of texture loaders.
2091 GLS_EXPORT TextureLoaderList& GetTextureLoaders();
2092
2093 private:
2094 // Order of objects is important here since they are destroyed in the reverse order listed
2095 ScopedPtr<List_c> _imageList;
2096 ScopedPtr<Mutex> _imageListMutex;
2097 ScopedPtr<GlsFontMan> _fontMan;
2098 ScopedPtr<IGlsStateManager> _stateManager;
2099 ScopedPtr<TextureLoaderList> _textureLoaders;
2100
2101 GlsGlobals();
2102 GlsGlobals( const GlsGlobals& ) DISTI_SPECIAL_MEM_FUN_DELETE;
2103 void operator=( const GlsGlobals& ) DISTI_SPECIAL_MEM_FUN_DELETE;
2104};
2105
2106// Check that bitness matches detected value
2107 namespace Detail
2108{
2109 /// We need this function because 'static_assert' replacements for pre-C++11 compilers cannot be at file scope.
2110 inline void _checkPointerSize()
2111 {
2112 // clang-format off
2113 DISTI_STATIC_ASSERT_STR( ( DISTI_IS_BITNESS( 64 ) && sizeof( void* ) == 8 )
2114 || ( DISTI_IS_BITNESS( 32 ) && sizeof( void* ) == 4 ),
2115 "Pointer size is unexpected for this bitness" );
2116 DISTI_STATIC_ASSERT_STR( DISTI_IS_BITNESS( 64 ) ^ DISTI_IS_BITNESS( 32 ), "Expected one bitness to be detected." );
2117 // clang-format on
2118 }
2119} // namespace Detail
2120} // namespace disti
2121
2122// Our own local versions of a few glu methods to avoid needing to include the GL Utility library
2123/// Set up a perspective projection. Functions the same as gluPerspective().
2124/// \param fovy The vertical FOV in degrees.
2125/// \param aspect The aspect ratio.
2126/// \param zNear The near clipping distance.
2127/// \param zFar The far clipping distance.
2128 GLS_EXPORT void glsPerspective( double fovy, double aspect, double zNear, double zFar );
2129
2130/// Projects a point from object space into window space. Functions the same as gluProject().
2131/// \param objx The X coordinate to project.
2132/// \param objy The Y coordinate to project.
2133/// \param objz The Z coordinate to project.
2134/// \param modelMatrix The modelview matrix to project with.
2135/// \param projMatrix The projection matrix to project with.
2136/// \param viewport The viewport to project with.
2137/// \param winx The returned projected X coordinate.
2138/// \param winy The returned projected Y coordinate.
2139/// \param winz The returned projected Z coordinate.
2140/// \return True if the operation was successful.
2141#ifdef MATRIX_TYPE_FLOAT
2142 GLS_EXPORT bool glsProject( double objx, double objy, double objz,
2143 const float modelMatrix[ 16 ],
2144 const float projMatrix[ 16 ],
2145 const int viewport[ 4 ],
2146 double* winx, double* winy, double* winz );
2147#else
2148 GLS_EXPORT bool glsProject( double objx, double objy, double objz,
2149 const double modelMatrix[ 16 ],
2150 const double projMatrix[ 16 ],
2151 const int viewport[ 4 ],
2152 double* winx, double* winy, double* winz );
2153#endif
2154
2155/// Unprojects a point from window space into object space. Functions the same as gluUnproject().
2156/// \param winx The X coordinate to unproject.
2157/// \param winy The Y coordinate to unproject.
2158/// \param winz The Z coordinate to unproject.
2159/// \param modelMatrix The modelview matrix to project with.
2160/// \param projMatrix The projection matrix to project with.
2161/// \param viewport The viewport to project with.
2162/// \param objx The returned unprojected X coordinate.
2163/// \param objy The returned unprojected Y coordinate.
2164/// \param objz The returned unprojected Z coordinate.
2165/// \return True if the operation was successful.
2166#ifdef MATRIX_TYPE_FLOAT
2167 GLS_EXPORT bool glsUnProject( double winx, double winy, double winz,
2168 const float modelMatrix[ 16 ],
2169 const float projMatrix[ 16 ],
2170 const int viewport[ 4 ],
2171 double* objx, double* objy, double* objz );
2172#else
2173 GLS_EXPORT bool glsUnProject( double winx, double winy, double winz,
2174 const double modelMatrix[ 16 ],
2175 const double projMatrix[ 16 ],
2176 const int viewport[ 4 ],
2177 double* objx, double* objy, double* objz );
2178#endif
2179
2180#endif
disti::DisplayFrame
Definition: display_frame.h:87
disti::DisplayObject
Definition: display.h:96
disti::DynamicArray
Definition: dynamic_array.h:79
disti::GlsFontMan
Definition: gls_font_man.h:60
disti::GlsGlobals
Hold global objects so we can control order of destruction.
Definition: util.h:2071
disti::GlsGlobals::GetImageListMutex
Mutex & GetImageListMutex()
disti::GlsGlobals::GetStateManager
IGlsStateManager & GetStateManager()
disti::GlsGlobals::Instance
static GlsGlobals & Instance()
disti::GlsGlobals::GetFontMan
GlsFontMan & GetFontMan()
disti::GlsGlobals::GetTextureLoaders
TextureLoaderList & GetTextureLoaders()
disti::GlsGlobals::GetImageList
List_c & GetImageList()
disti::GlsMatrixAffine< double >
disti::GlsMatrixAffine::Translate
void Translate(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:205
disti::GlsMatrix::Invert
void Invert()
Definition: gls_matrix.h:752
disti::GlsMultiValBase
Definition: util.h:1317
disti::GlsMultiValBase::ostreamType
std::ostream ostreamType
Typedef shorthand for std::ostream.
Definition: util.h:1322
disti::GlsMultiValBase::StreamOut
virtual void StreamOut(ostreamType &outstr) const =0
disti::GlsMultiValBase::StreamIn
virtual void StreamIn(istreamType &instr)=0
disti::GlsMultiValBase::istreamType
std::istream istreamType
Typedef shorthand for std::istream.
Definition: util.h:1323
disti::GlsMultiVal
Definition: util.h:1360
disti::GlsMultiVal::_val6
T6 _val6
The sixth value.
Definition: util.h:1409
disti::GlsMultiVal::GlsMultiVal
GlsMultiVal()
Definition: util.h:1418
disti::GlsMultiVal::StreamIn
virtual void StreamIn(istreamType &instr) override
Definition: util.h:1536
disti::GlsMultiVal::_val7
T7 _val7
The seventh value.
Definition: util.h:1410
disti::GlsMultiVal::GlsMultiVal
GlsMultiVal(const GlsMultiVal &src)
Definition: util.h:1426
disti::GlsMultiVal::_val5
T5 _val5
The fifth value.
Definition: util.h:1408
disti::GlsMultiVal::_val4
T4 _val4
The fourth value.
Definition: util.h:1407
disti::GlsMultiVal::_val3
T3 _val3
The third value.
Definition: util.h:1406
disti::GlsMultiVal::operator==
virtual bool operator==(const GlsMultiVal &val) const
Definition: util.h:1480
disti::GlsMultiVal::_val10
T10 _val10
The tenth value.
Definition: util.h:1413
disti::GlsMultiVal::StreamOut
virtual void StreamOut(ostreamType &outstr) const override
Definition: util.h:1513
disti::GlsMultiVal::_val2
T2 _val2
The second value.
Definition: util.h:1405
disti::GlsMultiVal::GlsMultiVal
GlsMultiVal(const T1 &val1, const T2 &val2=T2(), const T3 &val3=T3(), const T4 &val4=T4(), const T5 &val5=T5(), const T6 &val6=T6(), const T7 &val7=T7(), const T8 &val8=T8(), const T9 &val9=T9(), const T10 &val10=T10())
Definition: util.h:1452
disti::GlsMultiVal::_val8
T8 _val8
The eighth value.
Definition: util.h:1411
disti::GlsMultiVal::operator!=
virtual bool operator!=(const GlsMultiVal &val) const
Definition: util.h:1508
disti::GlsMultiVal::_val1
T1 _val1
The first value.
Definition: util.h:1404
disti::GlsMultiVal::_val9
T9 _val9
The ninth value.
Definition: util.h:1412
disti::GlsPropStringQuoted
Definition: util.h:1693
disti::GlsPropStringQuoted::GlsPropStringQuoted
GlsPropStringQuoted()
Default constructor, create an empty GlsPropStringQuoted object.
Definition: util.h:1698
disti::GlsPropStringQuoted::GlsPropStringQuoted
GlsPropStringQuoted(const std::string &str)
Definition: util.h:1704
disti::GlsPropStringQuoted::operator==
bool operator==(const GlsPropStringQuoted &str) const
Definition: util.h:1731
disti::GlsPropStringQuoted::_string
std::string _string
The underlying wrapped string.
Definition: util.h:1695
disti::GlsPropStringQuoted::GlsPropStringQuoted
GlsPropStringQuoted(const char *str)
Definition: util.h:1711
disti::GlsPropStringQuoted::String
std::string & String()
Definition: util.h:1723
disti::GlsPropString
Definition: util.h:1607
disti::GlsPropString::GlsPropString
GlsPropString(const char *str)
Definition: util.h:1626
disti::GlsPropString::GlsPropString
GlsPropString()
Default constructor. Creates an empty GlsPropString.
Definition: util.h:1612
disti::GlsPropString::operator==
friend bool operator==(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1649
disti::GlsPropString::GlsPropString
GlsPropString(const std::string &str)
Definition: util.h:1619
disti::GlsPropString::_string
std::string _string
The underlying wrapped string.
Definition: util.h:1609
disti::GlsPropString::String
std::string & String()
Definition: util.h:1640
disti::GlsPropString::operator!=
friend bool operator!=(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1658
disti::IGlsStateManager
Definition: gls_state_manager_interface.h:69
disti::InterfaceDescriptionClass
Definition: util.h:1226
disti::InterfaceDescriptionClass::Code
const char * Code() const
Definition: util.h:1261
disti::InterfaceDescriptionClass::operator=
InterfaceDescriptionClass & operator=(const InterfaceDescriptionClass &source)
disti::InterfaceDescriptionClass::Comment
void Comment(const char *)
Set the comment member to a new value.
disti::InterfaceDescriptionClass::InterfaceDescriptionClass
InterfaceDescriptionClass(const char *code, const char *usage, const char *comment)
disti::InterfaceDescriptionClass::Code
void Code(const char *)
Set the code member to a new value.
disti::InterfaceDescriptionClass::Usage
const char * Usage() const
Definition: util.h:1264
disti::InterfaceDescriptionClass::InterfaceDescriptionClass
InterfaceDescriptionClass(const InterfaceDescriptionClass &source)
disti::InterfaceDescriptionClass::InterfaceDescriptionClass
InterfaceDescriptionClass(InterfaceDescriptionClass &&source)
Definition: util.h:1272
disti::InterfaceDescriptionClass::Usage
void Usage(const char *)
Set the usage member to a new value.
disti::InterfaceDescriptionClass::operator=
InterfaceDescriptionClass & operator=(InterfaceDescriptionClass &&source)
Definition: util.h:1283
disti::InterfaceDescriptionClass::Comment
const char * Comment() const
Definition: util.h:1267
disti::List_c
Definition: list.h:135
disti::Mutex
Definition: gls_mutex.h:53
disti::OpenGLMatrices
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:544
disti::OpenGLMatrices::GetCurrent
void GetCurrent()
Retrieves the current OpenGL Matrices from the OpenGL Subsystem.
disti::OpenGLMatrices::OpenGLMatrices
OpenGLMatrices(int *view, GlsMatrixType *proj, GlsMatrixType *model)
disti::OpenGLMatrices::modelMatrix
GlsMatrixType * modelMatrix
The modelview matrix.
Definition: util.h:551
disti::OpenGLMatrices::viewMatrix
int * viewMatrix
The viewport matrix.
Definition: util.h:549
disti::OpenGLMatrices::OpenGLMatrices
OpenGLMatrices()
disti::OpenGLMatrices::~OpenGLMatrices
~OpenGLMatrices()
Destructor.
disti::OpenGLMatrices::projMatrix
GlsMatrixType * projMatrix
The projection matrix.
Definition: util.h:550
disti::OpenGLMatrices::OpenGLMatrices
OpenGLMatrices(const OpenGLMatrices &src)
disti::ScopedPtr
Definition: scoped_ptr.h:54
disti::TextureLoaderList
Definition: texture_loader.h:56
disti::VertexNoColor
Definition: vertex.h:85
disti::VertexNoColor::y
float y
The Y component.
Definition: vertex.h:88
disti::VertexNoColor::x
float x
The X component.
Definition: vertex.h:87
disti::VertexNoColor::z
float z
The Z component.
Definition: vertex.h:89
disti::Vertex
Definition: vertex.h:420
disti::glsCommandLine
Definition: util.h:1198
disti::glsCommandLine::_argc
int _argc
The number of arguments.
Definition: util.h:1210
disti::glsCommandLine::Instance
static glsCommandLine * Instance()
disti::glsCommandLine::ReadCommandLine
void ReadCommandLine(int argc, char **argv)
disti::glsCommandLine::Usage
void Usage()
Prints the usage instructions for the command line operations to stdout.
disti::glsCommandLine::SilentMode
bool SilentMode() const
Definition: util.h:1214
disti::glsCommandLine::_argv
char ** _argv
The array of arguments.
Definition: util.h:1211
disti_assert.h
Contains the DistiAssert macro.
dynamic_array.h
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_RVAL_MOVE
#define DISTI_RVAL_MOVE(x)
Macro to wrap std::move, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:196
DISTI_SPECIAL_MEM_FUN_DELETE
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:246
DISTI_STATIC_ASSERT_STR
#define DISTI_STATIC_ASSERT_STR(expr, msg)
Uses C++11's static_assert() because it is available on this platform.
Definition: gls_cpp_lang_support.h:433
DISTI_FINAL
#define DISTI_FINAL
Macro to wrap the final keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:224
DISTI_METHOD_OVERRIDE
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:222
gls_include.h
A file for all GL Studio files to include.
GLS_EXPORT
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
DISTI_IS_BITNESS
#define DISTI_IS_BITNESS(X)
Macro for checking bitness (safer macros borrowed from https://www.fluentcpp.com/2019/05/28/better-ma...
Definition: gls_include.h:207
gls_matrix_affine.h
The GlsMatrixAffine class.
disti
Definition: bmpimage.h:47
disti::ResolvePath
std::string ResolvePath(const char *path)
disti::VeryCloseToZero
bool VeryCloseToZero(X x)
Definition: util.h:163
disti::UTF16Outstream
std::ostream UTF16Outstream
A cross platform UTF-16 encoded ostream.
Definition: util.h:430
disti::ConvertBackslashToSlash
void ConvertBackslashToSlash(char *str)
disti::PARSER_CLEARSTRING_DELIMETER_END
const char PARSER_CLEARSTRING_DELIMETER_END[]
Used for parsing lines of clear (multiline otherwise unencoded) text.
Definition: util.h:121
disti::Equal
bool Equal(T1 x, T2 y, float precision=0.001f)
Definition: util.h:495
disti::GetBaseName
const char * GetBaseName(const char *path)
disti::UnicodeOutfilestream
std::ofstream UnicodeOutfilestream
A cross platform UTF-8 encoded ofstream.
Definition: util.h:432
disti::PopResourcePath
void PopResourcePath()
disti::IsNearZero
bool IsNearZero(X x)
Definition: util.h:169
disti::EncodeString
int EncodeString(char *dest, const char *src, const int dest_str_length)
disti::Safe_fopen
int Safe_fopen(const char *filename, char *flags, FILE **f)
disti::gltIsExtSupported
bool gltIsExtSupported(const char *extension)
disti::GetNoSpaces
bool GetNoSpaces(FILE *f, char *result, int maxLen)
disti::BETWEEN
bool BETWEEN(const X &x, const X1 &x1, const X2 &x2)
Definition: util.h:131
disti::INLINE_TEXTURE_LINE_LENGTH
const int INLINE_TEXTURE_LINE_LENGTH
Definition: util.h:118
disti::HIT_TOLERANCE
const double HIT_TOLERANCE
The hit tolerance in logical units for selecting objects in the editor.
Definition: util.h:123
disti::AppendTrailingSlash
void AppendTrailingSlash(char *s)
disti::ResolveRuntimeResourcePath
std::string ResolveRuntimeResourcePath(const char *fileName)
disti::InterfaceListType
DynamicArray< InterfaceDescriptionClass > InterfaceListType
Typedef for a list of interface description objects.
Definition: util.h:1313
disti::FileExists
bool FileExists(const char *filename)
disti::EncodedStringMinLength
int EncodedStringMinLength()
disti::GetObjectCoordinatesTransformSameView
bool GetObjectCoordinatesTransformSameView(DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
disti::CheckDistiLicense
bool CheckDistiLicense(const char *licenseGroupName, const char *feature, const char *version, bool quiet)
disti::operator<<
std::ostream & operator<<(std::ostream &outstr, const AttributeName &name)
disti::PushResourceFinder
void PushResourceFinder(std::string(*finder)(const std::string &))
disti::GetFileName
char * GetFileName(const char *name)
disti::FileName
std::string FileName(const std::string &filepath)
disti::RemoveSpaces
void RemoveSpaces(std::string &entry)
disti::UTF16Outfilestream
std::ofstream UTF16Outfilestream
A cross platform UTF-16 encoded ofstream.
Definition: util.h:429
disti::CalculateTexPointsFromTexCoords
bool CalculateTexPointsFromTexCoords(DisplayObject *object)
disti::CloseToZero
bool CloseToZero(const X x, const X threshold=X(1e-1))
Definition: util.h:154
disti::GetVertex
bool GetVertex(std::istream &instr, Vertex *vert, bool getColor)
disti::GetFilePath
const char * GetFilePath(const char *name)
disti::GlsGetOrtho
void GlsGetOrtho(GlsMatrixType &m, double left, double right, double bottom, double top, double zNear, double zFar)
disti::AngularDistanceRad
float AngularDistanceRad(float angle1, float angle2)
disti::GlsDefinedColor
unsigned char * GlsDefinedColor(GlsDefinedColorEnum index)
Definition: util.h:229
disti::FileExtension
std::string FileExtension(const std::string &filepath)
disti::PathToOS
char * PathToOS(const char *path)
disti::Uppercase
std::string Uppercase(const std::string &str)
disti::MakeRelativePath
char * MakeRelativePath(const char *originalPath, const char *relativePath)
disti::ConvertUTF8ToWide
UTF16String ConvertUTF8ToWide(const std::string &src)
Definition: util.h:450
disti::GetQualifiedInstanceName
std::string GetQualifiedInstanceName(const DisplayFrame *topFrame, const DisplayObject *obj)
disti::GetToEnd
bool GetToEnd(std::istream &instr, std::string &result, bool decode)
disti::IS_ZERO
bool IS_ZERO(X x)
Definition: util.h:175
disti::PARSER_CLEARSTRING_DELIMETER_START
const char PARSER_CLEARSTRING_DELIMETER_START[]
Used for parsing lines of clear (multiline otherwise unencoded) text.
Definition: util.h:120
disti::SpawnBrowser
void SpawnBrowser(const char *url)
disti::FindNonColinearVertices
bool FindNonColinearVertices(int arraySize, Vector array[], int &index1, int &index2, int &index3, bool isVectorArray=true)
disti::RemoveDoubleSlashes
void RemoveDoubleSlashes(char *path, char slash='/')
disti::CheckGLError
void CheckGLError()
Checks the OpenGL error state, and prints to stdout if there was an error.
disti::Max
const T & Max(const T &x, const T &y)
Definition: util.h:515
disti::Min
const T & Min(const T &x, const T &y)
Definition: util.h:505
disti::IS_NEGATIVE
bool IS_NEGATIVE(const X &x)
Definition: util.h:141
disti::DecodeString
int DecodeString(char *dest, const char *src, const int dest_str_length)
disti::PushResourcePath
void PushResourcePath(const char *resourcePath)
disti::UnicodeString
std::string UnicodeString
A cross platform UTF-8 encoded string.
Definition: util.h:431
disti::TrimSpaces
void TrimSpaces(std::string &entry)
disti::ContainsNonBlank
bool ContainsNonBlank(const std::string &val)
disti::operator+
GlsPropString operator+(const GlsPropString &a, GlsPropString &b)
Definition: util.h:1792
disti::AngularDistanceDeg
float AngularDistanceDeg(float angle1, float angle2)
disti::range_check
int range_check(int num, double val,...)
disti::operator>>
std::istream & operator>>(std::istream &instr, GlsColor &color)
disti::UTF16String
std::basic_string< unsigned short, CharTraitsUnsignedShort > UTF16String
A cross platform UTF-16 encoded string.
Definition: util.h:428
disti::gls_fopen
FILE * gls_fopen(const char *filename, const char *flags)
disti::OpenGLVersion
float OpenGLVersion()
disti::IsDirectory
bool IsDirectory(const char *filename)
disti::NotColinear
bool NotColinear(const Vector &a, const Vector &b, const Vector &c)
disti::GlsGetPerspective
void GlsGetPerspective(GlsMatrixType &m, double fovy, double aspect, double zNear, double zFar)
disti::ChangeGlsDefinedColor
void ChangeGlsDefinedColor(GlsDefinedColorEnum index, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
Definition: util.h:243
disti::GetExtension
std::string GetExtension(const std::string &filename)
disti::UnicodeOutstream
std::ostream UnicodeOutstream
A cross platform UTF-8 encoded string.
Definition: util.h:433
disti::GetObjectCoordinatesTransform
bool GetObjectCoordinatesTransform(DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
disti::ReplaceEnvironmentVariables
std::string ReplaceEnvironmentVariables(const char *originalPath)
disti::glsDefinedColors
unsigned char glsDefinedColors[GLS_COLOR_MAX][4]
disti::GetDefaultComponentClassName
std::string GetDefaultComponentClassName(const char *dllFileName)
disti::operator+=
GlsPropString & operator+=(GlsPropString &a, const GlsPropString &b)
Definition: util.h:1846
disti::FindCoordinateTransformation
GlsMatrixAffine< T > FindCoordinateTransformation(const Vector &new_origin, const Vector &new_i, const Vector &new_j, const Vector &new_k)
Definition: util.h:590
disti::IS_POSITIVE
bool IS_POSITIVE(const X &x)
Definition: util.h:147
disti::GlsDefinedColorEnum
GlsDefinedColorEnum
Definition: util.h:209
disti::GetTopLevelDisplayFrame
DisplayFrame * GetTopLevelDisplayFrame(DisplayFrame *frame)
disti::gls_unlink
int gls_unlink(const char *filename)
disti::C_EncodeString
int C_EncodeString(char *dest, const char *src, const int dest_str_length)
disti::GetComponentClassNames
bool GetComponentClassNames(const char *dllFileName, DynamicArray< std::string > &nameList, const char *createClassTag="CreateComponent_")
disti::FilePath
std::string FilePath(const std::string &filepath)
scoped_ptr.h
A smart pointer with unique ownership – poor man's std::unique_ptr.
disti::CharTraitsUnsignedShort
Definition: util.h:264
disti::CharTraitsUnsignedShort::lt
static bool lt(const char_type &c1, const char_type &c2)
Definition: util.h:292
disti::CharTraitsUnsignedShort::assign
static void assign(char_type &c1, const char_type &c2)
Definition: util.h:274
disti::CharTraitsUnsignedShort::to_int_type
static int_type to_int_type(const char_type &c)
Definition: util.h:398
disti::CharTraitsUnsignedShort::move
static char_type * move(char_type *s1, const char_type *s2, size_t n)
Definition: util.h:358
disti::CharTraitsUnsignedShort::state_type
std::mbstate_t state_type
Typedef for the underlying multibyte conversion state type.
Definition: util.h:269
disti::CharTraitsUnsignedShort::find
static const char_type * find(const char_type *s, size_t n, const char_type &a)
Definition: util.h:340
disti::CharTraitsUnsignedShort::eq
static bool eq(const char_type &c1, const char_type &c2)
Definition: util.h:283
disti::CharTraitsUnsignedShort::compare
static int compare(const char_type *s1, const char_type *s2, size_t n)
Definition: util.h:302
disti::CharTraitsUnsignedShort::to_char_type
static char_type to_char_type(const int_type &c)
Definition: util.h:390
disti::CharTraitsUnsignedShort::copy
static char_type * copy(char_type *s1, const char_type *s2, size_t n)
Definition: util.h:368
disti::CharTraitsUnsignedShort::eof
static int_type eof()
Definition: util.h:414
disti::CharTraitsUnsignedShort::pos_type
std::streampos pos_type
Typedef for the underlying stream position type.
Definition: util.h:267
disti::CharTraitsUnsignedShort::char_type
unsigned short char_type
Typedef for the underlying char type.
Definition: util.h:265
disti::CharTraitsUnsignedShort::not_eof
static int_type not_eof(const int_type &c)
Definition: util.h:422
disti::CharTraitsUnsignedShort::int_type
int int_type
Typedef for the underlying int type.
Definition: util.h:266
disti::CharTraitsUnsignedShort::length
static size_t length(const char_type *s)
Definition: util.h:325
disti::CharTraitsUnsignedShort::eq_int_type
static bool eq_int_type(const int_type &c1, const int_type &c2)
Definition: util.h:407
disti::CharTraitsUnsignedShort::off_type
std::streamoff off_type
Typedef for the underlying stream offset type.
Definition: util.h:268
disti::CharTraitsUnsignedShort::assign
static char_type * assign(char_type *s, size_t n, char_type a)
Definition: util.h:378
disti::InlinePixmap
Definition: util.h:798
disti::InlinePixmap::width
int width
The width in pixels.
Definition: util.h:799
disti::InlinePixmap::pixels
unsigned char * pixels
Pointer to the underlying data buffer.
Definition: util.h:802
disti::InlinePixmap::height
int height
The height in pixels.
Definition: util.h:800
disti::InlinePixmap::comprSize
int comprSize
The size in bytes.
Definition: util.h:801
unhide_globals.h
The DistiUnhideGlobalsDummyClass class.
disti::Detail::_checkPointerSize
void _checkPointerSize()
We need this function because 'static_assert' replacements for pre-C++11 compilers cannot be at file ...
Definition: util.h:2110
disti::Util::MakeString
std::string MakeString(const char *const cStr)
Definition: util.h:2055
disti::Util::Split
void Split(const std::string &s, const char delim, std::vector< std::string > &elems, const std::size_t maxElems=0)
Definition: util.h:2011
disti::Util::Clamp
T Clamp(const T &val, const T &min, const T &max)
Definition: util.h:1998
glsUnProject
bool glsUnProject(double winx, double winy, double winz, const double modelMatrix[16], const double projMatrix[16], const int viewport[4], double *objx, double *objy, double *objz)
glsPerspective
void glsPerspective(double fovy, double aspect, double zNear, double zFar)
glsProject
bool glsProject(double objx, double objy, double objz, const double modelMatrix[16], const double projMatrix[16], const int viewport[4], double *winx, double *winy, double *winz)
DIALOG_MAX_DIRECTORY_LENGTH
const int DIALOG_MAX_DIRECTORY_LENGTH
Limited by FLTK FileBrowser.
Definition: util.h:85
vertex.h
The disti::Vertex class. A class for manipulating 3D vertices.