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
15reproduced, in whole or part, in any form, or by any means of electronic,
16mechanical, or otherwise, without the written permission of DiSTI. Said
17permission may be derived through the purchase of applicable DiSTI product
18licenses which detail the distribution rights of this content and any
19Derivative Works based on this or other copyrighted DiSTI Software.
20
21 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
22AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
23PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
24AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
26PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
27
28 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
29IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
30INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
31DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
32INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
33INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
34OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
35EXCEED FIVE DOLLARS (US$5.00).
36
37 The aforementioned terms and restrictions are governed by the laws of the
38State 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"
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
85const int DIALOG_MAX_DIRECTORY_LENGTH = 1024; ///< Limited by FLTK FileBrowser.
86
87class 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
96namespace disti
97{
98class Vertex;
99class DisplayObject;
100class 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
111inline 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. */
119
120const char PARSER_CLEARSTRING_DELIMETER_START[] = "#$STRING_START$#"; ///< Used for parsing lines of clear (multiline otherwise unencoded) text.
121const char PARSER_CLEARSTRING_DELIMETER_END[] = "#$STRING_END$#"; ///< Used for parsing lines of clear (multiline otherwise unencoded) text.
122
123const 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.
130template<class X, class X1, class X2>
131bool 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.
140template<class X>
141bool 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.
146template<class X>
147bool 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.
153template<class X>
154bool 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.
162template<class X>
163bool 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.
168template<class X>
169bool 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.
174template<class X>
175bool 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.
193
194/// \return Whether or not the requested OpenGL extension is supported.
195/// \param extension The string name of the extension to check.
196GLS_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
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. */
223GLS_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 */
229inline 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).
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 */
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
428typedef std::basic_string<unsigned short, CharTraitsUnsignedShort> UTF16String; ///< A cross platform UTF-16 encoded string.
429typedef std::ofstream UTF16Outfilestream; ///< A cross platform UTF-16 encoded ofstream.
430typedef std::ostream UTF16Outstream; ///< A cross platform UTF-16 encoded ostream.
431typedef std::string UnicodeString; ///< A cross platform UTF-8 encoded string.
432typedef std::ofstream UnicodeOutfilestream; ///< A cross platform UTF-8 encoded ofstream.
433typedef std::ostream UnicodeOutstream; ///< A cross platform UTF-8 encoded string.
434
435#else
436
437typedef std::wstring UTF16String; ///< A cross platform UTF-16 encoded string.
438typedef std::wofstream UTF16Outfilestream; ///< A cross platform UTF-16 encoded ofstream.
439typedef std::wostream UTF16Outstream; ///< A cross platform UTF-16 encoded ostream.
440typedef std::wstring UnicodeString; ///< A cross platform UTF-8 encoded string.
441typedef std::wofstream UnicodeOutfilestream; ///< A cross platform UTF-8 encoded ofstream.
442typedef 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.
449inline UTF16String
450ConvertUTF8ToWide( 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.
494template<class T1, class T2>
495bool 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.
504template<class T>
505const 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.
514template<class T>
515const 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.
525template<class T, class Pred>
526const 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.
536template<class T, class Pred>
537const 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 */
544{
545private:
546 bool _needsDelete;
547
548public:
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.
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.
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.
568
569 /// Destructor.
571
572 /// Retrieves the current OpenGL Matrices from the OpenGL Subsystem.
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
589template<class T>
590GlsMatrixAffine<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.
631template<class T>
632void 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 */
672
673/// \param frame The DisplayFrame to start at.
674/// \return the Topmost Display 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 */
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.
712GLS_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.
725GLS_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.
738inline 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.)
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 */
756GLS_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 */
762GLS_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.
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 */
774GLS_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 */
780GLS_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 */
788GLS_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 */
794GLS_EXPORT std::string DecodeString( const std::string& src );
795
796/** The InlinePixmap structure */
797typedef 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.
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.
809GLS_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.
814
815/// Converts backslashes to forward slashes in the given string.
816/// \param str Reference to a string that is changed in place.
817GLS_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.
831GLS_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.
838GLS_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.
845GLS_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 */
854GLS_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 */
862GLS_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 */
870GLS_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 */
877GLS_EXPORT void SetAssetManager( AAssetManager* assetManager );
878#endif
879
880#if defined( ANDROID ) || ( defined( __APPLE__ ) && defined( GLES ) ) || ( defined( LINUX ) && defined( GLES ) ) || 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 */
886GLS_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 */
892GLS_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 */
903GLS_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 */
911GLS_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 */
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 */
922GLS_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.
928GLS_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.
933inline 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 */
944GLS_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*/
954int gls_unlink( const char* filename );
955
956#if defined( __APPLE__ ) && defined( GLES )
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 */
963GLS_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 */
971GLS_EXPORT std::string ResolveRuntimeResourcePath( const char* fileName );
972
973/// \return True if the file exists, false otherwise.
974/// \param filename The filename to check.
975GLS_EXPORT bool FileExists( const char* filename );
976
977/// \return True if the file exists, false otherwise.
978/// \param filename The filename to check.
979GLS_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.
983GLS_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.
987GLS_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 */
992GLS_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 */
997GLS_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 */
1003GLS_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 */
1011GLS_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 */
1018GLS_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 */
1024
1025/** Appends a trailing slash to a path string, if one isn't there already
1026 * \param s File path
1027 */
1028GLS_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 */
1037GLS_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 */
1044GLS_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.
1049GLS_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* )
1055GLS_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 */
1064GLS_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 */
1069GLS_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 */
1074GLS_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 */
1080GLS_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 */
1086GLS_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.
1090GLS_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.
1097GLS_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.
1104GLS_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.
1111GLS_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.
1118GLS_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.
1123GLS_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. */
1133GLS_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.
1150GLS_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.
1170GLS_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.
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 */
1189GLS_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.
1194GLS_EXPORT std::string ReplaceEnvironmentVariables( const char* originalPath );
1195
1196/** A singleton used for accessing the command line arguments in generated code */
1198{
1199public:
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.
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.
1218
1219private:
1220 bool _silentMode;
1221 static ScopedPtr<glsCommandLine> _instance;
1222};
1223
1224/** Used to make interface information visible to the user at design time*/
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
1231public:
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
1241
1242 /// Copy constructor
1243 /// \param source The object to copy from.
1245
1246 /// Assignment constructor
1247 /// \param source The object to copy from.
1248 /// \return The resulting object (this).
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.
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).
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
1297private:
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
1313typedef DynamicArray<InterfaceDescriptionClass> InterfaceListType; ///< Typedef for a list of interface description objects.
1314
1315/** Base class for GlsMultiVal template */
1317{
1318public:
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 */
1349template<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*>
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
1403public:
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 */
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.
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.
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
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.
1591GLS_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.
1597GLS_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 */
1607{
1608public:
1609 std::string _string; ///< The underlying wrapped string.
1610
1611 /// Default constructor. Creates an empty 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.
1668inline 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.
1678inline 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 */
1693{
1694public:
1695 std::string _string; ///< The underlying wrapped string.
1696
1697 /// Default constructor, create an empty GlsPropStringQuoted object.
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.
1741inline 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.
1751inline 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#ifndef WIN32
1789/// Open the default web browser and go to the specified URL.
1790/// \param url The URL to navigate to.
1791void SpawnBrowser( const char* url );
1792#endif
1793
1794/// Call this to check for the availability of a DiSTI controlled license.
1795/// It does not hold the license. It only checks it out and checks it back in.
1796/// \param licenseGroupName A name for what this license allows. i.e. "GL Studio Runtime".
1797/// \param feature The specific feature that will be checked out.
1798/// \param version The specific version that will be checked out.
1799/// \param quiet When true, no popup will occur upon missing license.
1800/// \return true if the license is available
1801GLS_EXPORT bool CheckDistiLicense( const char* licenseGroupName, const char* feature, const char* version, bool quiet );
1802
1803/// This will set the m parameter to an orthographic projection.
1804/// The current value of m is ignored.
1805/// This does NOT make any OpenGL calls.
1806/// \param m The matrix to hold the resulting orthographic projection.
1807/// \param left The left side coordinate.
1808/// \param right The right side coordinate.
1809/// \param bottom The bottom side coordinate.
1810/// \param top The top side coordinate.
1811/// \param zNear The near clipping coordinate.
1812/// \param zFar The far clipping coordinate.
1814 double left,
1815 double right,
1816 double bottom,
1817 double top,
1818 double zNear,
1819 double zFar );
1820
1821/// This will set the m parameter to a perspective projection.
1822/// The current value of m is ignored.
1823/// This does NOT make any OpenGL calls.
1824/// \param m The matrix to hold the resulting perspective projection.
1825/// \param fovy The vertical FOV in degrees.
1826/// \param aspect The aspect ratio.
1827/// \param zNear The near clipping distance.
1828/// \param zFar The far clipping distance.
1830 double fovy,
1831 double aspect,
1832 double zNear,
1833 double zFar );
1834
1835// using a namespace to help avoid collisions with user code. Future functionality should prefer to go here
1836namespace Util
1837{
1838 /// Clamps a value to the range [min, max].
1839 /// \param val The value to clamp.
1840 /// \param min The minimum value in the range.
1841 /// \param max The maximum value in the range.
1842 /// \return The value clamped between min and max.
1843 template<class T>
1844 T Clamp( const T& val, const T& min, const T& max )
1845 {
1846 return std::min( max, std::max( min, val ) );
1847 }
1848
1849 /// Split a string and add to existing vector of elements with delimeters removed.
1850 /// \param s The string to split
1851 /// \param delim The delimiter to split the string on.
1852 /// \param elems The vector of elements to append each split string to.
1853 /// \param maxElems The maximum number of elements to split. Remaining elements
1854 /// are appended unsplit as the last value. If 0, it does not
1855 /// have a maximum.
1856 /// \note Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c
1857 inline void Split( const std::string& s, const char delim, std::vector<std::string>& elems, const std::size_t maxElems = 0 )
1858 {
1859 std::istringstream ss( s );
1860 std::string item;
1861 while( std::getline( ss, item, delim ) )
1862 {
1863 elems.push_back( DISTI_RVAL_MOVE( item ) );
1864 if( elems.size() == maxElems )
1865 {
1866 break;
1867 }
1868 }
1869
1870 if( maxElems > 0 && elems.size() == maxElems && ss.good() )
1871 {
1872 std::string remainder;
1873 std::getline( ss, remainder, '\0' );
1874 elems.back() += delim + remainder;
1875 }
1876 else if( s.size() && s.at( s.size() - 1 ) == delim )
1877 {
1878 // Handle the case where the last item is an empty string.
1879 elems.push_back( "" );
1880 }
1881 }
1882
1883 /// Split a string return a vector of the elements with delimeters removed.
1884 /// \param s The string to split
1885 /// \param delim The delimiter to split the string on.
1886 /// \param maxElems The maximum number of elements to split. Remaining elements
1887 /// are appended unsplit as the last value. If 0, it does not
1888 /// have a maximum.
1889 /// \return The vector of split elements.
1890 /// \note Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c
1891 inline std::vector<std::string> Split( const std::string& s, const char delim, const std::size_t maxElems = 0 )
1892 {
1893 std::vector<std::string> elems;
1894 Split( s, delim, elems, maxElems );
1895 return elems;
1896 }
1897
1898 /// Passing null to std::string is not well-defined. Creates a string safely.
1899 /// \param cStr The string to create a std::string from.
1900 /// \return A std::string created from the incoming C string.
1901 inline std::string MakeString( const char* const cStr )
1902 {
1903 return ( cStr ? cStr : "" );
1904 }
1905} // namespace Util
1906
1907///////////////////////////////////////////////////////////////////////////////////////////////////
1908// Forward declarations for globals managed by GlsGlobals.
1909class GlsFontMan;
1910class IGlsStateManager;
1911class List_c;
1912class Mutex;
1913class TextureLoaderList;
1914
1915/// Hold global objects so we can control order of destruction.
1917{
1918public:
1919 /// \return The GlsGlobals singleton instance.
1921
1922 /// \return The image list.
1923 /// \sa GetImageListMutex()
1925
1926 /// \return The mutex for protecting the image list.
1927 /// \sa GetImageList()
1929
1930 /// \return The global font manager.
1932
1933 /// \return The global state manager instance.
1935
1936 /// \return The global list of texture loaders.
1938
1939private:
1940 // Order of objects is important here since they are destroyed in the reverse order listed
1941 ScopedPtr<List_c> _imageList;
1942 ScopedPtr<Mutex> _imageListMutex;
1943 ScopedPtr<GlsFontMan> _fontMan;
1944 ScopedPtr<IGlsStateManager> _stateManager;
1945 ScopedPtr<TextureLoaderList> _textureLoaders;
1946
1947 GlsGlobals();
1949 void operator=( const GlsGlobals& ) DISTI_SPECIAL_MEM_FUN_DELETE;
1950};
1951
1952// Check that bitness matches detected value
1953namespace Detail
1954{
1955 /// We need this function because 'static_assert' replacements for pre-C++11 compilers cannot be at file scope.
1956 inline void _checkPointerSize()
1957 {
1958 // clang-format off
1959 DISTI_STATIC_ASSERT_STR( ( DISTI_IS_BITNESS( 64 ) && sizeof( void* ) == 8 )
1960 || ( DISTI_IS_BITNESS( 32 ) && sizeof( void* ) == 4 ),
1961 "Pointer size is unexpected for this bitness" );
1962 DISTI_STATIC_ASSERT_STR( DISTI_IS_BITNESS( 64 ) ^ DISTI_IS_BITNESS( 32 ), "Expected one bitness to be detected." );
1963 // clang-format on
1964 }
1965} // namespace Detail
1966} // namespace disti
1967
1968// Our own local versions of a few glu methods to avoid needing to include the GL Utility library
1969/// Set up a perspective projection. Functions the same as gluPerspective().
1970/// \param fovy The vertical FOV in degrees.
1971/// \param aspect The aspect ratio.
1972/// \param zNear The near clipping distance.
1973/// \param zFar The far clipping distance.
1974GLS_EXPORT void glsPerspective( double fovy, double aspect, double zNear, double zFar );
1975
1976/// Projects a point from object space into window space. Functions the same as gluProject().
1977/// \param objx The X coordinate to project.
1978/// \param objy The Y coordinate to project.
1979/// \param objz The Z coordinate to project.
1980/// \param modelMatrix The modelview matrix to project with.
1981/// \param projMatrix The projection matrix to project with.
1982/// \param viewport The viewport to project with.
1983/// \param winx The returned projected X coordinate.
1984/// \param winy The returned projected Y coordinate.
1985/// \param winz The returned projected Z coordinate.
1986/// \return True if the operation was successful.
1987#ifdef MATRIX_TYPE_FLOAT
1988GLS_EXPORT bool glsProject( double objx, double objy, double objz,
1989 const float modelMatrix[ 16 ],
1990 const float projMatrix[ 16 ],
1991 const int viewport[ 4 ],
1992 double* winx, double* winy, double* winz );
1993#else
1994GLS_EXPORT bool glsProject( double objx, double objy, double objz,
1995 const double modelMatrix[ 16 ],
1996 const double projMatrix[ 16 ],
1997 const int viewport[ 4 ],
1998 double* winx, double* winy, double* winz );
1999#endif
2000
2001/// Unprojects a point from window space into object space. Functions the same as gluUnproject().
2002/// \param winx The X coordinate to unproject.
2003/// \param winy The Y coordinate to unproject.
2004/// \param winz The Z coordinate to unproject.
2005/// \param modelMatrix The modelview matrix to project with.
2006/// \param projMatrix The projection matrix to project with.
2007/// \param viewport The viewport to project with.
2008/// \param objx The returned unprojected X coordinate.
2009/// \param objy The returned unprojected Y coordinate.
2010/// \param objz The returned unprojected Z coordinate.
2011/// \return True if the operation was successful.
2012#ifdef MATRIX_TYPE_FLOAT
2013GLS_EXPORT bool glsUnProject( double winx, double winy, double winz,
2014 const float modelMatrix[ 16 ],
2015 const float projMatrix[ 16 ],
2016 const int viewport[ 4 ],
2017 double* objx, double* objy, double* objz );
2018#else
2019GLS_EXPORT bool glsUnProject( double winx, double winy, double winz,
2020 const double modelMatrix[ 16 ],
2021 const double projMatrix[ 16 ],
2022 const int viewport[ 4 ],
2023 double* objx, double* objy, double* objz );
2024#endif
2025
2026#endif
Definition: display_frame.h:87
Definition: display.h:96
Definition: dynamic_array.h:79
Definition: gls_font_man.h:60
Hold global objects so we can control order of destruction.
Definition: util.h:1917
Mutex & GetImageListMutex()
IGlsStateManager & GetStateManager()
static GlsGlobals & Instance()
GlsFontMan & GetFontMan()
TextureLoaderList & GetTextureLoaders()
List_c & GetImageList()
void Translate(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:205
void Invert()
Definition: gls_matrix.h:752
Definition: util.h:1317
std::ostream ostreamType
Typedef shorthand for std::ostream.
Definition: util.h:1322
virtual void StreamOut(ostreamType &outstr) const =0
virtual void StreamIn(istreamType &instr)=0
std::istream istreamType
Typedef shorthand for std::istream.
Definition: util.h:1323
Definition: util.h:1360
T6 _val6
The sixth value.
Definition: util.h:1409
GlsMultiVal()
Definition: util.h:1418
virtual void StreamIn(istreamType &instr) override
Definition: util.h:1536
T7 _val7
The seventh value.
Definition: util.h:1410
GlsMultiVal(const GlsMultiVal &src)
Definition: util.h:1426
T5 _val5
The fifth value.
Definition: util.h:1408
T4 _val4
The fourth value.
Definition: util.h:1407
T3 _val3
The third value.
Definition: util.h:1406
virtual bool operator==(const GlsMultiVal &val) const
Definition: util.h:1480
T10 _val10
The tenth value.
Definition: util.h:1413
virtual void StreamOut(ostreamType &outstr) const override
Definition: util.h:1513
T2 _val2
The second value.
Definition: util.h:1405
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
T8 _val8
The eighth value.
Definition: util.h:1411
virtual bool operator!=(const GlsMultiVal &val) const
Definition: util.h:1508
T1 _val1
The first value.
Definition: util.h:1404
T9 _val9
The ninth value.
Definition: util.h:1412
Definition: util.h:1693
GlsPropStringQuoted()
Default constructor, create an empty GlsPropStringQuoted object.
Definition: util.h:1698
GlsPropStringQuoted(const std::string &str)
Definition: util.h:1704
bool operator==(const GlsPropStringQuoted &str) const
Definition: util.h:1731
std::string _string
The underlying wrapped string.
Definition: util.h:1695
GlsPropStringQuoted(const char *str)
Definition: util.h:1711
std::string & String()
Definition: util.h:1723
Definition: util.h:1607
GlsPropString(const char *str)
Definition: util.h:1626
GlsPropString()
Default constructor. Creates an empty GlsPropString.
Definition: util.h:1612
friend bool operator==(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1649
GlsPropString(const std::string &str)
Definition: util.h:1619
std::string _string
The underlying wrapped string.
Definition: util.h:1609
std::string & String()
Definition: util.h:1640
friend bool operator!=(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1658
Definition: gls_state_manager_interface.h:69
Definition: util.h:1226
const char * Code() const
Definition: util.h:1261
InterfaceDescriptionClass & operator=(const InterfaceDescriptionClass &source)
void Comment(const char *)
Set the comment member to a new value.
InterfaceDescriptionClass(const char *code, const char *usage, const char *comment)
void Code(const char *)
Set the code member to a new value.
const char * Usage() const
Definition: util.h:1264
InterfaceDescriptionClass(const InterfaceDescriptionClass &source)
InterfaceDescriptionClass(InterfaceDescriptionClass &&source)
Definition: util.h:1272
void Usage(const char *)
Set the usage member to a new value.
InterfaceDescriptionClass & operator=(InterfaceDescriptionClass &&source)
Definition: util.h:1283
const char * Comment() const
Definition: util.h:1267
Definition: list.h:135
Definition: gls_mutex.h:53
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:544
void GetCurrent()
Retrieves the current OpenGL Matrices from the OpenGL Subsystem.
OpenGLMatrices(int *view, GlsMatrixType *proj, GlsMatrixType *model)
GlsMatrixType * modelMatrix
The modelview matrix.
Definition: util.h:551
int * viewMatrix
The viewport matrix.
Definition: util.h:549
~OpenGLMatrices()
Destructor.
GlsMatrixType * projMatrix
The projection matrix.
Definition: util.h:550
OpenGLMatrices(const OpenGLMatrices &src)
Definition: scoped_ptr.h:54
Definition: texture_loader.h:56
Definition: vertex.h:85
float y
The Y component.
Definition: vertex.h:88
float x
The X component.
Definition: vertex.h:87
float z
The Z component.
Definition: vertex.h:89
Definition: vertex.h:420
Definition: util.h:1198
int _argc
The number of arguments.
Definition: util.h:1210
static glsCommandLine * Instance()
void ReadCommandLine(int argc, char **argv)
void Usage()
Prints the usage instructions for the command line operations to stdout.
bool SilentMode() const
Definition: util.h:1214
char ** _argv
The array of arguments.
Definition: util.h:1211
Contains the DistiAssert macro.
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
Macros and helper code to determine what subset of C++11/14/17 is available.
#define DISTI_RVAL_MOVE(x)
Macro to wrap std::move, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:193
#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:235
#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:405
#define DISTI_FINAL
Macro to wrap the final keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:216
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:214
A file for all GL Studio files to include.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
#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
The GlsMatrixAffine class.
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47
std::string ResolvePath(const char *path)
bool VeryCloseToZero(X x)
Definition: util.h:163
std::ostream UTF16Outstream
A cross platform UTF-16 encoded ostream.
Definition: util.h:430
void ConvertBackslashToSlash(char *str)
const char PARSER_CLEARSTRING_DELIMETER_END[]
Used for parsing lines of clear (multiline otherwise unencoded) text.
Definition: util.h:121
bool Equal(T1 x, T2 y, float precision=0.001f)
Definition: util.h:495
const char * GetBaseName(const char *path)
std::ofstream UnicodeOutfilestream
A cross platform UTF-8 encoded ofstream.
Definition: util.h:432
void PopResourcePath()
bool IsNearZero(X x)
Definition: util.h:169
int EncodeString(char *dest, const char *src, const int dest_str_length)
int Safe_fopen(const char *filename, char *flags, FILE **f)
bool gltIsExtSupported(const char *extension)
bool GetNoSpaces(FILE *f, char *result, int maxLen)
bool BETWEEN(const X &x, const X1 &x1, const X2 &x2)
Definition: util.h:131
const int INLINE_TEXTURE_LINE_LENGTH
Definition: util.h:118
const double HIT_TOLERANCE
The hit tolerance in logical units for selecting objects in the editor.
Definition: util.h:123
void AppendTrailingSlash(char *s)
std::string ResolveRuntimeResourcePath(const char *fileName)
DynamicArray< InterfaceDescriptionClass > InterfaceListType
Typedef for a list of interface description objects.
Definition: util.h:1313
bool FileExists(const char *filename)
int EncodedStringMinLength()
bool GetObjectCoordinatesTransformSameView(DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
bool CheckDistiLicense(const char *licenseGroupName, const char *feature, const char *version, bool quiet)
std::ostream & operator<<(std::ostream &outstr, const AttributeName &name)
void PushResourceFinder(std::string(*finder)(const std::string &))
char * GetFileName(const char *name)
std::string FileName(const std::string &filepath)
void RemoveSpaces(std::string &entry)
std::ofstream UTF16Outfilestream
A cross platform UTF-16 encoded ofstream.
Definition: util.h:429
bool CalculateTexPointsFromTexCoords(DisplayObject *object)
bool CloseToZero(const X x, const X threshold=X(1e-1))
Definition: util.h:154
bool GetVertex(std::istream &instr, Vertex *vert, bool getColor)
const char * GetFilePath(const char *name)
void GlsGetOrtho(GlsMatrixType &m, double left, double right, double bottom, double top, double zNear, double zFar)
float AngularDistanceRad(float angle1, float angle2)
unsigned char * GlsDefinedColor(GlsDefinedColorEnum index)
Definition: util.h:229
std::string FileExtension(const std::string &filepath)
char * PathToOS(const char *path)
std::string Uppercase(const std::string &str)
char * MakeRelativePath(const char *originalPath, const char *relativePath)
UTF16String ConvertUTF8ToWide(const std::string &src)
Definition: util.h:450
std::string GetQualifiedInstanceName(const DisplayFrame *topFrame, const DisplayObject *obj)
bool GetToEnd(std::istream &instr, std::string &result, bool decode)
bool IS_ZERO(X x)
Definition: util.h:175
const char PARSER_CLEARSTRING_DELIMETER_START[]
Used for parsing lines of clear (multiline otherwise unencoded) text.
Definition: util.h:120
void SpawnBrowser(const char *url)
bool FindNonColinearVertices(int arraySize, Vector array[], int &index1, int &index2, int &index3, bool isVectorArray=true)
void RemoveDoubleSlashes(char *path, char slash='/')
void CheckGLError()
Checks the OpenGL error state, and prints to stdout if there was an error.
const T & Max(const T &x, const T &y)
Definition: util.h:515
const T & Min(const T &x, const T &y)
Definition: util.h:505
bool IS_NEGATIVE(const X &x)
Definition: util.h:141
int DecodeString(char *dest, const char *src, const int dest_str_length)
void PushResourcePath(const char *resourcePath)
std::string UnicodeString
A cross platform UTF-8 encoded string.
Definition: util.h:431
void TrimSpaces(std::string &entry)
bool ContainsNonBlank(const std::string &val)
float AngularDistanceDeg(float angle1, float angle2)
int range_check(int num, double val,...)
bool SaveFileDialog(Fl_Window *win, char *filePath, unsigned int filePathSize, char *directory=NULL, const char *filterStr=NULL, const char *defaultExt=NULL, const char *title=NULL, bool createFile=false, bool fileMustExist=false, bool pathMustExist=false, bool noChangeDirectory=false)
std::istream & operator>>(std::istream &instr, GlsColor &color)
std::basic_string< unsigned short, CharTraitsUnsignedShort > UTF16String
A cross platform UTF-16 encoded string.
Definition: util.h:428
FILE * gls_fopen(const char *filename, const char *flags)
float OpenGLVersion()
bool IsDirectory(const char *filename)
bool OpenFileDialog(Fl_Window *win, char *filePath, unsigned int filePathSize, char *directory=NULL, const char *filterStr=NULL, const char *defaultExt=NULL, const char *title=NULL, bool multiSelect=false, bool createFile=false, bool fileMustExist=false, bool pathMustExist=false, bool noChangeDirectory=false)
bool NotColinear(const Vector &a, const Vector &b, const Vector &c)
void GlsGetPerspective(GlsMatrixType &m, double fovy, double aspect, double zNear, double zFar)
void ChangeGlsDefinedColor(GlsDefinedColorEnum index, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
Definition: util.h:243
std::string GetExtension(const std::string &filename)
std::ostream UnicodeOutstream
A cross platform UTF-8 encoded string.
Definition: util.h:433
bool GetObjectCoordinatesTransform(DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
std::string ReplaceEnvironmentVariables(const char *originalPath)
unsigned char glsDefinedColors[GLS_COLOR_MAX][4]
std::string GetDefaultComponentClassName(const char *dllFileName)
GlsMatrixAffine< T > FindCoordinateTransformation(const Vector &new_origin, const Vector &new_i, const Vector &new_j, const Vector &new_k)
Definition: util.h:590
bool IS_POSITIVE(const X &x)
Definition: util.h:147
GlsDefinedColorEnum
Definition: util.h:209
DisplayFrame * GetTopLevelDisplayFrame(DisplayFrame *frame)
int gls_unlink(const char *filename)
int C_EncodeString(char *dest, const char *src, const int dest_str_length)
bool GetComponentClassNames(const char *dllFileName, DynamicArray< std::string > &nameList, const char *createClassTag="CreateComponent_")
std::string FilePath(const std::string &filepath)
A smart pointer with unique ownership – poor man's std::unique_ptr.
Definition: util.h:264
static bool lt(const char_type &c1, const char_type &c2)
Definition: util.h:292
static void assign(char_type &c1, const char_type &c2)
Definition: util.h:274
static int_type to_int_type(const char_type &c)
Definition: util.h:398
static char_type * move(char_type *s1, const char_type *s2, size_t n)
Definition: util.h:358
std::mbstate_t state_type
Typedef for the underlying multibyte conversion state type.
Definition: util.h:269
static const char_type * find(const char_type *s, size_t n, const char_type &a)
Definition: util.h:340
static bool eq(const char_type &c1, const char_type &c2)
Definition: util.h:283
static int compare(const char_type *s1, const char_type *s2, size_t n)
Definition: util.h:302
static char_type to_char_type(const int_type &c)
Definition: util.h:390
static char_type * copy(char_type *s1, const char_type *s2, size_t n)
Definition: util.h:368
static int_type eof()
Definition: util.h:414
std::streampos pos_type
Typedef for the underlying stream position type.
Definition: util.h:267
unsigned short char_type
Typedef for the underlying char type.
Definition: util.h:265
static int_type not_eof(const int_type &c)
Definition: util.h:422
int int_type
Typedef for the underlying int type.
Definition: util.h:266
static size_t length(const char_type *s)
Definition: util.h:325
static bool eq_int_type(const int_type &c1, const int_type &c2)
Definition: util.h:407
std::streamoff off_type
Typedef for the underlying stream offset type.
Definition: util.h:268
static char_type * assign(char_type *s, size_t n, char_type a)
Definition: util.h:378
Definition: util.h:798
int width
The width in pixels.
Definition: util.h:799
unsigned char * pixels
Pointer to the underlying data buffer.
Definition: util.h:802
int height
The height in pixels.
Definition: util.h:800
int comprSize
The size in bytes.
Definition: util.h:801
The DistiUnhideGlobalsDummyClass class.
void _checkPointerSize()
We need this function because 'static_assert' replacements for pre-C++11 compilers cannot be at file ...
Definition: util.h:1956
std::string MakeString(const char *const cStr)
Definition: util.h:1901
void Split(const std::string &s, const char delim, std::vector< std::string > &elems, const std::size_t maxElems=0)
Definition: util.h:1857
T Clamp(const T &val, const T &min, const T &max)
Definition: util.h:1844
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)
void glsPerspective(double fovy, double aspect, double zNear, double zFar)
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)
const int DIALOG_MAX_DIRECTORY_LENGTH
Limited by FLTK FileBrowser.
Definition: util.h:85
The disti::Vertex class. A class for manipulating 3D vertices.