GL Studio 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) 2015 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 _GLS_RUNTIME_UTIL_H
43 #define _GLS_RUNTIME_UTIL_H
44 
45 #include "gls_include.h"
46 
47 #ifdef _WIN32
48 # include <direct.h>
49 #else
50 # include <unistd.h>
51 #endif
52 
53 #include "disti_assert.h"
54 #include "dynamic_array.h"
55 #include "gls_cpp_lang_support.h"
56 #include "gls_matrix_affine.h"
57 #include "unhide_globals.h"
58 #include <iostream>
59 #include <math.h>
60 #include <sstream>
61 #include <stdio.h>
62 #include <string>
63 #include <typeinfo>
64 #include <vector>
65 
66 #ifdef ANDROID
67 #include <android/asset_manager.h>
68 #endif
69 
70 #if defined(_MSC_VER)
71 // Hide std template warnings
72 #pragma warning (disable:4786)
73 #endif
74 
75 const int DIALOG_MAX_DIRECTORY_LENGTH = 1024; // Limited by FLTK FileBrowser
76 
77 class Fl_Window;
78 
79 namespace disti
80 {
81 
82 class Vertex;
83 class DisplayObject;
84 class DisplayFrame;
85 
86 #ifndef TRUE
87 #define TRUE 1
88 #endif
89 
90 #ifndef FALSE
91 #define FALSE 0
92 #endif
93 
94 #ifdef _WIN32
95 #define strcasecmp(x,y) _stricmp(x,y)
96 #endif
97 
98 /** Used to generate inline textures. The writing and reading
99  * of the lines need to know the length. */
101 
102 /* Used for parsing lines of clear text */
103 #define PARSER_CLEARSTRING_DELIMETER_START "#$STRING_START$#"
104 #define PARSER_CLEARSTRING_DELIMETER_END "#$STRING_END$#"
105 
106 #ifndef M_PI
107 #define M_PI 3.14159265358979323846
108 #endif
109 
110 /* DEG_TO_RAD Converts degrees to radians */
111 
112 #define DEG_TO_RAD (M_PI/180.0)
113 
114 /* RAD_TO_DEG Converts radians to degrees */
115 #define RAD_TO_DEG (180.0/M_PI)
116 
117 #define HIT_TOLERANCE 5.0
118 
119 /* BETWEEN(x,x1,x2) Determines if x is included in the range
120  x1 to x2 */
121 #define BETWEEN(x,x1,x2) ((((x) >= (x1)) && ((x) <= (x2))) || \
122  (((x) >= (x2)) && ((x) <= (x1))))
123 
124 /* IS_NEGATIVE(x) Determines if the argument is negative */
125 #define IS_NEGATIVE(x) ((fabs(x) > 0.0001)?(x < 0.0):0)
126 
127 /* IS_POSITIVE(x) Determines if the argument is positive */
128 #define IS_POSITIVE(x) ((fabs(x) > 0.0001)?(x > 0.0):0)
129 
130 /* CloseToZero(x) Determines if the argument is small (< 10E-1) */
131 #define CloseToZero(x) (fabs((x)) < 0.1)
132 
133 /* VeryCloseToZero(x) Determines if the argument is extremely small (< 10E-4) */
134 #define VeryCloseToZero(x) (fabs((x)) < 0.0001)
135 
136 /* IS_ZERO(x) Determines if the argument is very small (< 10E-3) */
137 #define IS_ZERO(x) (fabs((x)) < 0.001)
138 
139 /* MIN(A,B) Determines which argument is smallest */
140 #ifndef MIN
141 #define MIN(A,B) ((A) < (B) ? (A) : (B))
142 #endif
143 
144 /* MIN(A,B) Determines which argument is largest */
145 #ifndef MAX
146 #define MAX(A,B) ((A) > (B) ? (A) : (B))
147 #endif
148 
149 /** Use for determining the current OpenGL version available in the current
150  * runtime environment.
151  * It may not be valid until called after a valid rendering context has been assigned.
152  */
153 GLS_EXPORT float OpenGLVersion();
154 
155 GLS_EXPORT bool gltIsExtSupported(const char *extension);
156 
157 // Additional #defines
158 //From glext.h Available at http://oss.sgi.com/projects/ogl-sample/registry/ */
159 #ifndef GLES
160 # define GLSTUDIO_CLAMP_TO_EDGE ( OpenGLVersion() >= 1.2f ? 0x812F : GL_CLAMP)
161 #else
162 # define GLSTUDIO_CLAMP_TO_EDGE GL_CLAMP_TO_EDGE
163 #endif
164 
165 /** GL Studio color defines
166  */
167 // \enum color enumerations for use with GlsDefinedColor methods
169 {
170  GLS_COLOR_WHITE,
171  GLS_COLOR_CYAN,
172  GLS_COLOR_RED,
173  GLS_COLOR_AMBER,
174  GLS_COLOR_GREEN,
175  GLS_COLOR_YELLOW,
176  GLS_COLOR_MAGENTA,
177  GLS_COLOR_BLACK,
178  GLS_COLOR_BLUE,
179  GLS_COLOR_MAX
180 };
181 
182 /**
183 * \param GLS specific color index
184 * \return An RGBA color value
185 */
186 GLS_EXPORT extern unsigned char glsDefinedColors[GLS_COLOR_MAX][4];
187 
188 /**
189 * \param index of defined color
190 * \return an unsigned char array of the specified index
191 */
192 inline unsigned char *GlsDefinedColor(GlsDefinedColorEnum index)
193 {
194 
195  if ((index <0) || (index >= GLS_COLOR_MAX))
196  return glsDefinedColors[0];
197  else
198  return glsDefinedColors[index];
199 }
200 /**
201  * Allows the user to change the predefined colors
202  */
204  unsigned char red,
205  unsigned char green,
206  unsigned char blue,
207  unsigned char alpha)
208 {
209  if ((index >= 0) && (index < GLS_COLOR_MAX))
210  {
211  glsDefinedColors[index][0] = red;
212  glsDefinedColors[index][1] = green;
213  glsDefinedColors[index][2] = blue;
214  glsDefinedColors[index][3] = alpha;
215  }
216 }
217 
218 //---------------------------------------------------------------------------
219 /**
220 * Return whether two numbers are "equal" to eachother taking into account
221 * a certain precision. You can use this method on any numeric types and
222 * even mix types as the parameters. Eg. you can compare integers with
223 * floating point types or compare floats and doubles without casting.
224 *
225 * \param x first number to use in the comparison which determines the range
226 * \param y number to check if within the range determined by x and precision
227 * \param precision number that is added to and subtracted from x to
228 * determine the range to check y against.
229 */
230 template<class T1, class T2>
231 bool Equal(T1 x, T2 y, float precision = 0.001f)
232 {
233  return (x - precision) <= y && y <= (x + precision);
234 }
235 
236 //---------------------------------------------------------------------------
237 /**
238 * Return the minimum of two objects. The class T must have the < operator
239 * defined.
240 */
241 template<class T>
242 const T& Min(const T& x, const T& y)
243 {
244  return x < y ? x : y;
245 }
246 
247 //---------------------------------------------------------------------------
248 /**
249 * Return the maximum of two objects. The class T must have the < operator
250 * defined.
251 */
252 template<class T>
253 const T& Max(const T& x, const T& y)
254 {
255  return x < y ? y : x;
256 }
257 
258 //---------------------------------------------------------------------------
259 /**
260 * Return the minimum of two objects determined by a predicate.
261 * If pr(x, y) is true, x is returned else y.
262 */
263 template<class T, class Pred>
264 const T& Min(const T& x, const T& y, Pred pr)
265 {
266  return pr(x, y) ? x : y;
267 }
268 
269 //---------------------------------------------------------------------------
270 /**
271 * Return the maximum of two objects determined by a predicate.
272 * If pr(x, y) is true, y is returned else x.
273 */
274 template<class T, class Pred>
275 const T& Max(const T& x, const T& y, Pred pr)
276 {
277  return pr(x, y) ? y : x;
278 }
279 
280 /** \brief Class to contain current OpenGL view, projection and draw matrices */
282 {
283 private:
284  bool _needsDelete;
285 public:
286  int* viewMatrix;
287  GlsMatrixType* projMatrix;
288  GlsMatrixType* modelMatrix;
289 
290  /** Default constructor
291  * Keeps everything NULL */
292  GLS_EXPORT OpenGLMatrices();
293 
294  /** Copy constructor
295  * Pointers are copied as-is, copies of the
296  * data are NOT made. */
297  GLS_EXPORT OpenGLMatrices(const OpenGLMatrices& src);
298 
299  /** Another constructor.
300  * Pointers are copied as-is, copies of the
301  * data are NOT made. */
302  GLS_EXPORT OpenGLMatrices(int* view,
303  GlsMatrixType* proj,
304  GlsMatrixType* model);
305 
306  /** Destructor */
307  GLS_EXPORT ~OpenGLMatrices();
308 
309  /** Retrieves the current OpenGL Matrices from the
310  * OpenGL Subsystem */
311  GLS_EXPORT void GetCurrent();
312 };
313 
314 /** Stack class that uses DynamicArray
315  */
316 template <class T, bool TypeIsSimple>
318 {
319 private:
321 public:
322  unsigned int size() { return array.Count(); }
323 
324  void push(const T& item)
325  {
326  array[array.Count()] = item;
327  }
328 
329  T& top()
330  {
331  // This returns garbage if size < 1
332  return array[array.Count()-1];
333  }
334 
335  void pop()
336  {
337  if(array.Count() > 0)
338  {
339  array.Count(array.Count()-1);
340  }
341  }
342 };
343 
344 /** Find a transformation that will convert to a new coordinate
345  * system defined by the given origin and basis vectors (i,j,k).
346  * \note The new i,j,k vectors are in respect to the current origin.
347  * (i.e. for transformation that moves the origin
348  * along the x axis by 5 units you should pass in
349  * (Vector(5,0,0), Vector(1,0,0), Vector(0,1,0) , Vector(0,0,1))
350  * NOT (Vector(5,0,0), Vector(6,0,0), Vector(5,1,0) , Vector(5,0,1))
351  * Template argument is either double or float.
352  * \param new_origin Vector to the new coordinate system origin.
353  * \param new_i Vector parallel to the new x-axis with magnitude equal to one unit in the new coordinate system.
354  * \param new_j Vector parallel to the new y-axis with magnitude equal to one unit in the new coordinate system.
355  * \param new_k Vector parallel to the new z-axis with magnitude equal to one unit in the new coordinate system.
356  *
357  * \returns transformation matrix to the new coordinate system
358  */
359 template < class T >
360 GlsMatrixAffine<T> FindCoordinateTransformation(const Vector& new_origin, const Vector& new_i, const Vector& new_j, const Vector& new_k)
361 {
362  GlsMatrixAffine<T> transform;
363  GlsMatrixAffine<T> rotation_scaling;
364 
365  // First translate to the new origin
366 
367  transform.Translate(-new_origin);
368 
369  // Build a matrix taking the standard basis vectors to the new basis vectors
370 
371  rotation_scaling(0,0) = new_i.x; rotation_scaling(0,1) = new_j.x; rotation_scaling(0,2) = new_k.x;
372  rotation_scaling(1,0) = new_i.y; rotation_scaling(1,1) = new_j.y; rotation_scaling(1,2) = new_k.y;
373  rotation_scaling(2,0) = new_i.z; rotation_scaling(2,1) = new_j.z; rotation_scaling(2,2) = new_k.z;
374 
375  // Invert because we want the new basis vectors to become the standard basis vectors
376  rotation_scaling.Invert();
377 
378  // Combine the translation and rotation to produce the complete transformation
379  return rotation_scaling * transform;
380 
381 }
382 
383 template < class T >
384 void FindCoordinateTransformation(const Vector& new_origin, const Vector& new_i, const Vector& new_j, const Vector& new_k,GlsMatrixAffine<T> &result)
385 {
386  GlsMatrixAffine<T> transform;
387  GlsMatrixAffine<T> rotation_scaling;
388 
389  // First translate to the new origin
390 
391  transform.Translate(-new_origin);
392 
393  // Build a matrix taking the standard basis vectors to the new basis vectors
394 
395  rotation_scaling(0,0) = new_i.x; rotation_scaling(0,1) = new_j.x; rotation_scaling(0,2) = new_k.x;
396  rotation_scaling(1,0) = new_i.y; rotation_scaling(1,1) = new_j.y; rotation_scaling(1,2) = new_k.y;
397  rotation_scaling(2,0) = new_i.z; rotation_scaling(2,1) = new_j.z; rotation_scaling(2,2) = new_k.z;
398 
399  // Invert because we want the new basis vectors to become the standard basis vectors
400  rotation_scaling.Invert();
401 
402  // Combine the translation and rotation to produce the complete transformation
403  result = rotation_scaling * transform;
404 }
405 
406 /** Gets the transformation from one DisplayObject's object coordinates to another's
407  * 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.
408  * Use GetObjectCoordinatesTransform unless GetObjectCoordinatesTransformSameView is required.
409  *
410  * \sa GetObjectCoordinatesTransform
411  *
412  * \param from The DisplayObject to start at
413  * \param to The DisplayObject to end at
414  * \param outTransform Out parameter - If the function returns true, this will contain the resulting transformation.
415  * \returns true on success, false if there was an error
416  */
417 GLS_EXPORT bool GetObjectCoordinatesTransformSameView( DisplayObject* from, DisplayObject* to, GlsMatrixType* outTransform);
418 
419 /** Gets the transformation from one DisplayObject's object coordinates to another's (if possible)
420  * This is the preferred method for determining the coordinate space relationship between two objects that have DynamicTransforms applied.
421  * Note: This method requires that the two objects are part of the same object heirarchy.
422  * Consider using GetObjectCoordinatesTransformSameView if your situation does not meet this requirement.
423  *
424  * \code
425  * // Example: Move objB to be in the same location as objA (including all DynamicTransforms)
426  * // Change Location of objB so that it's RotationPoint aligns with the RotationPoint of objA
427  * GlsMatrixType transform;
428  * if( GetObjectCoordinatesTransform( objA, objB, &transform ) )
429  * {
430  * Vector objA_rotationPoint_transformed = transform * (objA->Location() + objA->RotationPoint());
431  * objB->Location( objA_rotationPoint_transformed - objB->RotationPoint() );
432  * }
433  * else
434  * {
435  * // Error: objects are not in the same heirarchy
436  * }
437  * \endcode
438  *
439  * \sa GetObjectCoordinatesTransform
440  *
441  * \param from The DisplayObject to start at
442  * \param to The DisplayObject to end at
443  * \param outTransform Out parameter - If the function returns true, this will contain the resulting transformation.
444  * \returns true on success, false if the objects are not in the same heirarchy.
445  */
446 GLS_EXPORT bool GetObjectCoordinatesTransform( DisplayObject* from, DisplayObject* to, GlsMatrixType* outTransform);
447 
448 /** Test if the given points are not colinear (they are not in a line)
449  * \return true if the points are not colinear
450  * \return false if the points are colinear
451  */
452 GLS_EXPORT bool NotColinear(const Vector& a, const Vector& b, const Vector& c);
453 
454 /** Search the given Vertex array for the first three
455  * non-colinear vertices.
456  *
457  * \param arraySize The size of vertex_array
458  * \param array The Vertex array
459  * \param index1 variable to receive 1st array index
460  * \param index2 variable to receive 2nd array index
461  * \param index3 variable to receive 3rd array index
462  * \param isVectorArray true if array points to a Vector array, false if it
463  * points to a Vertex array
464  *
465  * \return true If the vertices were found
466  * \returns false If there are not three non-colinear vertices in the array
467  * if this occurs, the index values are undefined
468  */
469 GLS_EXPORT bool FindNonColinearVertices(int arraySize, Vector array[],
470  int& index1, int& index2, int& index3,
471  bool isVectorArray = true);
472 
473 /** Vertex version of FindNonColinearVertices */
474 inline bool FindNonColinearVertices(int arraySize, Vertex array[], int& index1, int& index2, int& index3)
475 {
476  return FindNonColinearVertices(arraySize, array, index1, index2, index3, false);
477 }
478 
479 /** Recalculate the texture points of a given DisplayObject
480  * based on its valid texture coordinates
481  *
482  * \return true On success
483  * \return false If the texture points could not be calculated.
484  * (The object doesn't have three non-colinear vertices or doesn't have texture coordinates.)
485  */
486 GLS_EXPORT bool CalculateTexPointsFromTexCoords(DisplayObject* object);
487 
488 /** Encodes a string such that if it contains newlines, it will be wrapped with the "#$STRING_START$#" and "#$STRING_END$#" delimiters.
489  * \param dest Destination string
490  * \param src Source string
491  * \param dest_str_length Size of the destination buffer
492  * \return The length of the encoded string.
493  */
494 GLS_EXPORT int EncodeString( char* dest, const char* src, const int dest_str_length );
495 
496 /** Encodes a std::string such that there are no whitespace characters in the string
497  * \param src Source string
498  * \return The encoded string
499  */
500 GLS_EXPORT std::string EncodeString(const std::string& src);
501 
502 /** Returns a minimum length for a call to EncodeString.
503  * This is based on the clear text delimeters
504  */
505 GLS_EXPORT int EncodedStringMinLength();
506 
507 /** Encodes a string using C language encoding
508  * \param dest Destination string
509  * \param src Source string
510  * \param dest_str_length Size of the destination buffer
511  * \return The length of the encoded string
512  */
513 GLS_EXPORT int C_EncodeString( char *dest, const char *src, const int dest_str_length );
514 
515 /** Returns and encoded std::string using C language encoding
516  * \param src Source string
517  * \return The encoded string
518  */
519 GLS_EXPORT std::string C_EncodeString(const std::string& src);
520 
521 /** Decodes a string that was encoded using EncodeString
522  * \param dest Destination string
523  * \param src Source string
524  * \param dest_str_length Size of the destination buffer
525  * \return The length of the encoded string
526  */
527 GLS_EXPORT int DecodeString(char *dest,const char *src, const int dest_str_length);
528 
529 /** Decodes a std::string that was encoded using EncodeString
530  * \param src Encoded Source string
531  * \return The decoded string
532  */
533 GLS_EXPORT std::string DecodeString(const std::string& src);
534 
535 /** The InlinePixmap structure
536  */
537 typedef struct
538 {
539  int width;
540  int height;
541  int comprSize;
542  unsigned char *pixels;
543 } InlinePixmap;
544 
545 GLS_EXPORT char *MakeRelativePath(const char *originalPath, const char *relativePath);
546 GLS_EXPORT void ConvertBackslashToSlash(char *str);
547 GLS_EXPORT void ConvertBackslashToSlash(std::string &str);
548 
549 /** Determines if the given value falls in any of the ranges passed in.
550 
551  range_check(int number_of_ranges, double test_value,
552  int index_0,double range_0_min,double range_0_max,
553 
554  ...
555 
556  int index_n,double range_n_min,double range_n_max);
557 
558  For example, to return 1 for values 0-10 and 2 for values 10-20:
559 
560  index = range_check(2,val,
561  1, 0.0, 10.0,
562  2, 10.0, 20.0);
563 */
564 
565 GLS_EXPORT int range_check(int num,double val,...);
566 
567 /** Attempts to open the given file. Pops up an error message box if the
568  * attempt fails
569  * \param filename The name of the file to open
570  * \param flags fopen style file arguments (e.g. "r")
571  * \param f Contains file pointer on success
572  * \return True if the operation was successful
573  */
574 GLS_EXPORT int Safe_fopen(const char *filename,char *flags,FILE **f);
575 /** Stream version */
576 GLS_EXPORT int Safe_fopen(const char *filename,char *flags,std::fstream &outstr);
577 
578 #ifdef ANDROID
579 /** Sets if assets should be loaded directly from the apk (default true).
580  * This only affects Android builds.
581  * \param enableDirectAssetLoading true to allow assets to be loaded directly from the apk
582  * false to force assets to be read from the resource directory (\see SetResourcePath)
583  * \post HasAssetExtension returns false for all filetypes if direct asset loading was disabled
584  */
585 GLS_EXPORT void EnableDirectAssetLoading(bool enableDirectAssetLoading);
586 
587 /** Returns if the filetype is one that can be loaded directly from the apk assets.
588  * This only affects Android builds.
589  * \param filename The filename with extension to check
590  * \return True if the filetype can be loaded directly from the apk assets,
591  * False if the file is loaded from internal or external storage
592  */
593 GLS_EXPORT bool HasAssetExtension(const char *filename);
594 
595 /** Returns if the file exists in the apk assets.
596  * This only affects Android builds.
597  * \param filename The name of the file
598  * \return True if the file is an asset that can be opened.
599  * Returns false if no asset exists with filename or the pointer to the AAssetManager, set with SetAssetManager, is null.
600  */
601 GLS_EXPORT bool AssetExists(const char *filename);
602 
603 /** Sets the Android Asset Manager to use.
604  * When the assetManager is null, apk assets cannot be loaded.
605  * This only affects Android builds.
606  * \param assetManager The pointer to the AAssetManager
607  */
608 GLS_EXPORT void SetAssetManager(AAssetManager *assetManager);
609 #endif
610 
611 #if defined(ANDROID) || ( defined(LINUX) && defined(GLES) )
612 /** Prepends the resource path to a file name.
613  * \param[in] filename_ The name of the file
614  * \return string containing ResourcePath+filename_, with OS specific path.
615  * On Android, apk asset files are not prepended with a path.
616  */
617 GLS_EXPORT std::string ResolvePath(const char* filename_);
618 
619 /** Sets the path for locating resource files.
620  * On Android, this is the location where resources outside of apk assets are found.
621  * \param resourcePath The path where application resources will be found
622  */
623 GLS_EXPORT void SetResourcePath(const char *resourcePath);
624 
625 /** Attempts to open the given file. Prepends the filename with the path from SetResourcePath
626  * for non-absolute paths.
627  * On Android, filenames that match an apk asset are opened. Opened assets should be closed
628  * with fclose to free resources, not with the Android Asset Manager close function (AAsset_close)
629  * \param filename The name of the file to open
630  * \param flags fopen style file arguments (e.g. "r")
631  * \pre On Android, Asset Manager != NULL, set with SetAssetManager, when opening an apk asset
632  * \return FILE pointer or NULL otherwise
633  */
634 GLS_EXPORT FILE *gls_fopen(const char *filename,const char *flags);
635 #else
636 /** Pushes a resource search path onto the stack. The CWD is always
637  * implicitly searched first. The resource search paths are local to
638  * the calling thread only. This function should be called from the same
639  * thread as the resources are loaded from.
640  * \param resourcePath The directory path to add to the search paths
641  */
642 GLS_EXPORT void PushResourcePath(const char *resourcePath);
643 
644 /** Remove the first search path from the stack. The resource search paths
645  * are local to the calling thread only. This function should be called from
646  * the same thread as the matching PushResourcePath.
647  */
648 GLS_EXPORT void PopResourcePath();
649 
650 /** Pushes a function that can locate resources. The Resources finders are applied after the resource paths are searched
651  * \param finder The function that can locate resources to add to the search paths
652  */
653 GLS_EXPORT void PushResourceFinder( std::string (*finder)( const std::string&) );
654 
655 /** Resolves the given path searching the resource path list. The
656  * CWD is always implicity searched first.
657  * \param path The relative path to resolve
658  */
659 GLS_EXPORT std::string ResolvePath(const char *path);
660 
661 // helper method taking a std::string
662 inline std::string ResolvePath( const std::string& path )
663 {
664  return ResolvePath( path.c_str() );
665 }
666 
667 /** Attempts to open the given file. Relative file paths
668  * are resolved using ResolvePath.
669  * \param filename The name of the file to open
670  * \param flags fopen style file arguments (e.g. "r")
671  * \return FILE pointer or NULL otherwise
672  */
673 GLS_EXPORT FILE *gls_fopen(const char *filename,const char *flags);
674 #endif
675 
676 #ifdef __APPLE__
677 /** \return a string indicating the location of a specific file in the default resource bundle.
678  * This method is designed for runtime platforms that have a pre-defined bundle
679  * location that is not immediately known to the application until runtime.
680  * in iOS, this returns the path to the main application bundle with the file name appended.
681  * \param fileName A string referring to the file without a path.
682  */
683  GLS_EXPORT std::string GetAbsolutePathAndFileNameInDefaultResourceBundle(const char* fileName);
684 #endif
685 
686 /** Prepends the resource path to a file name.
687  * \param[in] fileName The name of the file
688  * \return string containing ResourcePath + fileName, with OS specific path.
689  * On Android, apk asset files are not prepended with a path.
690  */
691 GLS_EXPORT std::string ResolveRuntimeResourcePath( const char* fileName );
692 
693 /** \return true if the file exists, false otherwise
694  * \param filename The filename to check
695  */
696 GLS_EXPORT bool FileExists(const char *filename);
697 GLS_EXPORT bool FileExists(const std::string &filename);
698 
699 /** \return true if the file exists and is a directory, false otherwise
700  * \param filename The filename to check
701  */
702 GLS_EXPORT bool IsDirectory( const char* filename );
703 GLS_EXPORT bool IsDirectory( const std::string& filename );
704 
705 /** \return The file extension for a filepath
706  * \param filepath Filepath to get extension from
707  */
708 GLS_EXPORT std::string FileExtension(const std::string& filepath);
709 
710 /** \return The filename from a file path by stripping off anything to the left of a slash
711  * \param filepath
712  */
713 GLS_EXPORT std::string FileName(const std::string& filepath);
714 
715 /** \return a string containing the path portion of a filename
716  * by stripping off everything to the right of the rightmost slash
717  * \param filepath A string containing a file with a path
718  */
719 GLS_EXPORT std::string FilePath(const std::string& filepath);
720 
721 /** \return a pointer to the string containing the path portion of a filename
722  * by stripping off everything to the right of the rightmost slash
723  * \param name A string containing a file with a path
724  */
725 GLS_EXPORT const char *GetFilePath(const char *name);
726 
727 /** \return The filename from a file path by stripping off anything to the left of a slash
728  * \param name A string containing just the file name without a path
729  */
730 GLS_EXPORT char *GetFileName(const char *name);
731 
732 /** Appends a trailing slash to a path string, if one isn't there already
733  * \param s File path
734  */
735 GLS_EXPORT void AppendTrailingSlash(char *s);
736 
737 /** Appends a trailing slash to a path string, if one isn't there already
738  * \param s File path
739  */
740 GLS_EXPORT void AppendTrailingSlash(std::string &s);
741 
742 /** Convert a directory path to have the correct OS
743  * slashes /, or \. Also make sure that the path ends in a \, or /.
744  * So you always have the form <name 1>\\<name 2>...<name n>\\\, or <name 1>/<name 2>...<name n>/
745  * \param path A path to convert
746  * \return a "new-ed" string which may be longer than the original.
747  * It is the calling functions responsibility to free the memory.
748  */
749 GLS_EXPORT char *PathToOS(const char *path);
750 
751 /** \return The file extension for a filename
752  * \param filename Filename to get extension from
753  * No longer allocates memory, you can let the returned string
754  * be colected as it falls out of scope
755  */
756 GLS_EXPORT std::string GetExtension(const std::string &filename);
757 
758 /** Gets the file name from a filename with path
759  * It does not allocate new memory, but rather just returns
760  * a pointer inside the original string
761  */
762 GLS_EXPORT const char* GetBaseName(const char* path);
763 
764 /** \return Pointer to a position within the given \a path where the filename starts.
765  * \deprecated This function is not const-correct. Prefer the const-correct version.
766  * \sa GetBaseName( const char* )
767  */
768 GLS_EXPORT char* GetBaseName( char* path );
769 
770 /** Removes and double slashes from a path.
771  * It will look for the specified type of slash.
772  * It will modify path, but since it can only shrink,
773  * no allocation is done.
774  * \param path The path to operate on.
775  * \param slash The type of slash to search for.
776  */
777 GLS_EXPORT void RemoveDoubleSlashes(char* path, char slash = '/');
778 
779 /** \return The minimum angular distance between angle1 and angle2 in degrees
780  * \param angle1 First angle
781  * \param angle2 Second angle
782  */
783 GLS_EXPORT float AngularDistanceDeg(float angle1, float angle2);
784 
785 /** \return The minimum angular distance between angle1 and angle2 in radians
786  * \param angle1 First angle
787  * \param angle2 Second angle
788  */
789 GLS_EXPORT float AngularDistanceRad(float angle1, float angle2);
790 
791 GLS_EXPORT bool ContainsNonBlank( const std::string& val );
792 
793 GLS_EXPORT bool GetNoSpaces(FILE *f, char *result, int maxLen);
794 GLS_EXPORT bool GetToEnd(std::istream &instr, std::string &result, bool decode);
795 GLS_EXPORT bool GetVertex(std::istream &instr, Vertex* vert, bool getColor);
796 
797 /** Searches the specified binary file for the specified tag, and adds what immediatly follows the tag to the nameList.
798  * Returns true if at least one is found, false otherwise.
799  */
800 GLS_EXPORT bool GetComponentClassNames(const char* dllFileName, DynamicArray<std::string,false>& nameList, const char* createClassTag = "CreateComponent_" );
801 
802 /** Opens the DLL and attempts to run GlsDefaultClassName(), if found.
803  * Returns an empty string if not found. */
804 GLS_EXPORT std::string GetDefaultComponentClassName(const char* dllFileName);
805 
806 /** Returns the qualified instance name of an object that is
807  * contained within given DisplayFrame. (e.g "cockpit.altimeter.needle")
808  * Note that names are only added for each DisplayFrame (not every Group)
809  * and the name of the topFrame is not included in the qualified name.
810  * \param topFrame The frame in which the qualification will make sense.
811  * \param obj The object which is a direct child or located somewhere below topFrame.
812  * \returns The qualified instance name or an empty string if the qualified
813  * instance name could not be determined. */
814 GLS_EXPORT std::string GetQualifiedInstanceName(const DisplayFrame* topFrame, const DisplayObject* obj);
815 
816 #ifndef GLES
817 GLS_EXPORT bool OpenFileDialog(Fl_Window *win, char *filePath, unsigned int filePathSize,
818  char *directory = NULL, const char *filterStr = NULL,
819  const char *defaultExt = NULL, const char *title = NULL,
820  bool multiSelect = false, bool createFile = false,
821  bool fileMustExist = false, bool pathMustExist = false,
822  bool noChangeDirectory = false);
823 
824 GLS_EXPORT bool SaveFileDialog(Fl_Window *win, char *filePath, unsigned int filePathSize,
825  char *directory = NULL, const char *filterStr = NULL,
826  const char *defaultExt = NULL, const char *title = NULL,
827  bool createFile = false,
828  bool fileMustExist = false, bool pathMustExist = false,
829  bool noChangeDirectory = false);
830 #endif
831 GLS_EXPORT void CheckGLError(void);
832 
833 //---------------------------------------------------------------------------
834 /**
835 * Returns a string which is the uppercase version of the passed parameter.
836 *
837 * \param str original string to convert to Uppercase
838 *
839 * \return a string copy of the original but in all caps.
840 */
841 GLS_EXPORT std::string Uppercase(const std::string& str);
842 
843 GLS_EXPORT std::string ReplaceEnvironmentVariables(const char* originalPath);
844 
845 /** A singleton used for accessing the command line arguments in generated code
846  */
848 {
849 
850  bool _silentMode; /** Whether or not the app should run in silent mode */
851 
852 public:
853  GLS_EXPORT glsCommandLine(void);
854  GLS_EXPORT void ReadCommandLine(int argc, char **argv );
855  GLS_EXPORT void Usage();
856 
857  int _argc;
858  char **_argv;
859 
860  bool SilentMode(void) { return _silentMode; }
861 
862  static GLS_EXPORT glsCommandLine* Instance();
863  static glsCommandLine *_instance;
864 };
865 
866 /** Used to make interface information visible to the user at design time*/
868 {
869 protected:
870  char* _code; // e.g. "DynamicRotate("
871  char* _usage; // e.g. "void DynamicRotate(float angle, int axis)"
872  char* _comment; // e.g. "Sets dynamic rotation in degrees for the specified axis"
873 public:
874  // Default constructor
875  GLS_EXPORT InterfaceDescriptionClass();
876  // Copy constructor
877  GLS_EXPORT InterfaceDescriptionClass(const InterfaceDescriptionClass& source);
878  // Destructor
879  GLS_EXPORT ~InterfaceDescriptionClass();
880  // Copy operator
881  GLS_EXPORT InterfaceDescriptionClass(const char* code, const char* usage, const char* comment);
882 
883  GLS_EXPORT void operator=(const InterfaceDescriptionClass& source);
884  GLS_EXPORT void Code(const char*);
885  GLS_EXPORT const char* Code() const;
886  GLS_EXPORT void Usage(const char*);
887  GLS_EXPORT const char* Usage() const;
888  GLS_EXPORT void Comment(const char*);
889  GLS_EXPORT const char* Comment() const;
890 };
892 
893 /** Base class for GlsMultiVal template
894  */
896 {
897 public:
898  virtual ~GlsMultiValBase() {}
899 
900  //These are used to avoid template problems with VC6.0
901  typedef std::ostream ostreamType;
902  typedef std::istream istreamType;
903 
904  virtual void StreamOut(ostreamType & outstr) const = 0;
905  virtual void StreamIn(istreamType & instr) = 0;
906 };
907 
908 
909 /** GlsMultiVal is used to effectivly create a structure containing up
910  * to 10 values of varying types. An instance of the class is capable
911  * of streaming itself to and from a text stream. The individual values
912  * will be separated by spaces when written and read from the stream.
913  * The types have to follow some rules:
914  * - They must themselves have the << and >> stream operators defined.
915  * - operator>> must read all data written by operator<< and must not consume spaces or other characters that follow it
916  * - They must have a default constructor
917  * - They must have a copy constructor
918  * - They shall not be void* (it is used for determining the end of the desired types).
919  * - If a GlsPropString is used, there must be only one, and it *must* be the
920  * last entry in the GlsMultiVal instance.
921  * - A GlsPropStringQuoted will work in any position.
922  * This is intended primarily for the GL Studio end user to use as a Class Property type.
923  */
924 template < class T1,
925  class T2 = void*,
926  class T3 = void*,
927  class T4 = void*,
928  class T5 = void*,
929  class T6 = void*,
930  class T7 = void*,
931  class T8 = void*,
932  class T9 = void*,
933  class T10 = void*>
935 {
936  int _numVals;
937  void CalcNumVals()
938  {
939  _numVals = 1;
940  if (typeid(T2) != typeid(void*)) _numVals++; else return;
941  if (typeid(T3) != typeid(void*)) _numVals++; else return;
942  if (typeid(T4) != typeid(void*)) _numVals++; else return;
943  if (typeid(T5) != typeid(void*)) _numVals++; else return;
944  if (typeid(T6) != typeid(void*)) _numVals++; else return;
945  if (typeid(T7) != typeid(void*)) _numVals++; else return;
946  if (typeid(T8) != typeid(void*)) _numVals++; else return;
947  if (typeid(T9) != typeid(void*)) _numVals++; else return;
948  if (typeid(T10) != typeid(void*)) _numVals++; else return;
949 
950  }
951 public:
952 
953 
954  T1 _val1;
955  T2 _val2;
956  T3 _val3;
957  T4 _val4;
958  T5 _val5;
959  T6 _val6;
960  T7 _val7;
961  T8 _val8;
962  T9 _val9;
963  T10 _val10;
964 
965 
966  /**
967  Default constructor.
968 
969  The _val member types must have default constructors.
970  */
972  {
973  CalcNumVals();
974  }
975 
976  /**
977  Copy constructor.
978 
979  This GlsMultiVal will copy values from the src GlsMultiVal.
980 
981  \param src GlsMultiVal object to use for initialization.
982  \return
983  */
984  GlsMultiVal(const GlsMultiVal& src) :
985  _val1(src._val1),
986  _val2(src._val2),
987  _val3(src._val3),
988  _val4(src._val4),
989  _val5(src._val5),
990  _val6(src._val6),
991  _val7(src._val7),
992  _val8(src._val8),
993  _val9(src._val9),
994  _val10(src._val10)
995  {
996  CalcNumVals();
997  }
998  /**
999  Full constructor. Creates a GlsMultiVal object with the provided data.
1000 
1001  \param val1 First value to use for intialization of type T1.
1002  \param val2 First value to use for intialization of type T2.
1003  \param val3 First value to use for intialization of type T3.
1004  \param val4 First value to use for intialization of type T4.
1005  \param val5 First value to use for intialization of type T5.
1006  \param val6 First value to use for intialization of type T6.
1007  \param val7 First value to use for intialization of type T7.
1008  \param val8 First value to use for intialization of type T8.
1009  \param val9 First value to use for intialization of type T9.
1010  \param val10 First value to use for intialization of type T10.
1011  \return
1012  */
1014  const T1& val1,
1015  const T2& val2 = T2(),
1016  const T3& val3 = T3(),
1017  const T4& val4 = T4(),
1018  const T5& val5 = T5(),
1019  const T6& val6 = T6(),
1020  const T7& val7 = T7(),
1021  const T8& val8 = T8(),
1022  const T9& val9 = T9(),
1023  const T10& val10 = T10() ) :
1024  _val1(val1),
1025  _val2(val2),
1026  _val3(val3),
1027  _val4(val4),
1028  _val5(val5),
1029  _val6(val6),
1030  _val7(val7),
1031  _val8(val8),
1032  _val9(val9),
1033  _val10(val10)
1034  {
1035  CalcNumVals();
1036  }
1037 
1038  /** Compares two multival objects for equality */
1039  virtual bool operator==(const GlsMultiVal& val) const
1040  {
1041  bool rval = true;
1042  // Only compare the number of used values.
1043  switch (_numVals)
1044  {
1045  // No breaks is intentional
1046  case 10: rval &= (_val10 == val._val10);
1047  case 9: rval &= (_val9 == val._val9);
1048  case 8: rval &= (_val8 == val._val8);
1049  case 7: rval &= (_val7 == val._val7);
1050  case 6: rval &= (_val6 == val._val6);
1051  case 5: rval &= (_val5 == val._val5);
1052  case 4: rval &= (_val4 == val._val4);
1053  case 3: rval &= (_val3 == val._val3);
1054  case 2: rval &= (_val2 == val._val2);
1055  case 1: rval &= (_val1 == val._val1);
1056  break;
1057  default:
1058  rval = false;
1059  }
1060  return rval;
1061  }
1062 
1063  /** Inverse of equality */
1064  virtual bool operator!=( const GlsMultiVal& val ) const
1065  {
1066  return !( *this == val );
1067  }
1068 
1069  /**
1070  StreamOut(). This function serializes itself into the provided stream object.
1071 
1072  \param outstr This is the object used by the GlsMultiVal class to serialize itself onto.
1073  \return
1074  */
1075  virtual void StreamOut(ostreamType & outstr) const
1076  {
1077  outstr << _val1;
1078  if (_numVals >= 2)
1079  outstr << " " <<_val2;
1080  if (_numVals >= 3)
1081  outstr << " " <<_val3;
1082  if (_numVals >= 4)
1083  outstr << " " <<_val4;
1084  if (_numVals >= 5)
1085  outstr << " " <<_val5;
1086  if (_numVals >= 6)
1087  outstr << " " <<_val6;
1088  if (_numVals >= 7)
1089  outstr << " " <<_val7;
1090  if (_numVals >= 8)
1091  outstr << " " <<_val8;
1092  if (_numVals >= 9)
1093  outstr << " " <<_val9;
1094  if (_numVals >= 10)
1095  outstr << " " <<_val10;
1096  }
1097 
1098  /**
1099  StreamIn(). Uses the provided istream object to populate the current GlsMultiVal object
1100 
1101  \param instr This is the stream object used by the GlsMultiVal instance to populate itself.
1102  \return
1103  */
1104  virtual void StreamIn(istreamType & instr)
1105  {
1106  instr >> _val1;
1107  if (_numVals >= 2)
1108  {
1109  instr.get(); // The separating space
1110  instr >> _val2;
1111  }
1112  if (_numVals >= 3)
1113  {
1114  instr.get();
1115  instr >> _val3;
1116  }
1117  if (_numVals >= 4)
1118  {
1119  instr.get();
1120  instr >> _val4;
1121  }
1122  if (_numVals >= 5)
1123  {
1124  instr.get();
1125  instr >> _val5;
1126  }
1127  if (_numVals >= 6)
1128  {
1129  instr.get();
1130  instr >> _val6;
1131  }
1132  if (_numVals >= 7)
1133  {
1134  instr.get();
1135  instr >> _val7;
1136  }
1137  if (_numVals >= 8)
1138  {
1139  instr.get();
1140  instr >> _val8;
1141  }
1142  if (_numVals >= 9)
1143  {
1144  instr.get();
1145  instr >> _val9;
1146  }
1147  if (_numVals >= 10)
1148  {
1149  instr.get();
1150  instr >> _val10;
1151  }
1152  }
1153 };
1154 
1155 GLS_EXPORT std::ostream & operator<<(std::ostream & outstr, const GlsMultiValBase & multiVal);
1156 GLS_EXPORT std::istream & operator>>(std::istream & instr, GlsMultiValBase & multiVal);
1157 
1158 /** GlsPropString is designed to be used as a string in GL Studio Class Properties.
1159  * It writes itself out as a single line, and will read in up to the next newline.
1160  * It will attempt to convert itself to and from std::strings.
1161  * If it is used in a GlsMultiVal, there must be only one, and it *must* be the
1162  * last entry in the GlsMultiVal instance.
1163  * See GlsPropStringQuoted for more usefulness in GlsMultiVal.
1164  */
1166 {
1167 public:
1168  std::string _string;
1169 
1170  /** Default constructor Creates an empty GlsPropString. */
1171  GlsPropString() : _string( "" )
1172  {
1173  }
1174  /**
1175  Create a new GlsPropString using the provided std string.
1176 
1177  \param str std::string to use to create the GlsPropString
1178  \return
1179  */
1180  GlsPropString(const std::string& str) : _string( str )
1181  {
1182  }
1183 
1184  /**
1185  Create a new GlsPropString using the provided c-style string.
1186 
1187  \param str c-style string to use to create the GlsPropString.
1188  \return
1189  */
1190  GlsPropString( const char* str ) : _string( str ? str : "" )
1191  {
1192  }
1193 
1194  operator std::string() const
1195  {
1196  return _string;
1197  }
1198 
1199  /**
1200  Get the string value for this object.
1201  \return std::string containing the string value for this object.
1202  */
1203  std::string& String()
1204  {
1205  return _string;
1206  }
1207 
1208  /** Checks lexicographic equality of the two arguments */
1209  friend inline bool operator==( const GlsPropString& str1, const GlsPropString& str2 )
1210  {
1211  return str1._string == str2._string;
1212  }
1213 
1214  /** Checks lexicographic inequality of the two arguments */
1215  friend inline bool operator!=( const GlsPropString& str1, const GlsPropString& str2 )
1216  {
1217  return !(str1 == str2 );
1218  }
1219 };
1220 
1221 inline std::ostream & operator<<(std::ostream & outstr, const GlsPropString & str)
1222 {
1223  outstr << disti::C_EncodeString(str._string);
1224  return outstr;
1225 }
1226 inline std::istream & operator>>(std::istream & instr, GlsPropString & str)
1227 {
1228  std::string temp;
1229  disti::GetToEnd(instr, temp, false);
1230  str._string = disti::DecodeString(temp);
1231 
1232  return instr;
1233 }
1234 /** GlsPropStringQuoted is designed to be used as a string in GL Studio Class Properties.
1235  * It writes itself out as a single line surrounded with quotes (""), and will read in up to the next un-escaped quote.
1236  * It will attempt to convert itself to and from std::strings.
1237  * Use of GlsPropStringQuoted is preferred over GlsPropString for use in a GlsMultiVal.
1238  */
1240 {
1241 public:
1242  std::string _string;
1243  /** Default constructor, create an empty GlsPropStringQuoted object. */
1245  {
1246  }
1247  /**
1248  Constructor, create a new GlsPropStringQuoted object using the provided std::string object
1249 
1250  \param str std::string object to use to create the GlsPropStringQuoted object
1251  \return
1252  */
1253  GlsPropStringQuoted(const std::string& str) : _string(str)
1254  {
1255  }
1256  /**
1257  Constructor, create a new GlsPropStringQuoted object using the provided c-style string
1258 
1259  \param str c-style string to use to create the GlsPropStringQuoted object
1260  \return
1261  */
1262  GlsPropStringQuoted(const char* str) : _string(str)
1263  {
1264  }
1265  operator std::string() const
1266  {
1267  return _string;
1268  }
1269  std::string& String()
1270  {
1271  return _string;
1272  }
1273  bool operator == (const GlsPropStringQuoted& str) const
1274  {
1275  return str._string == _string;
1276  }
1277 };
1278 inline std::ostream & operator<<(std::ostream & outstr, const GlsPropStringQuoted & str)
1279 {
1280  outstr << '\"' <<disti::C_EncodeString(str._string) <<'\"';
1281  return outstr;
1282 }
1283 inline std::istream & operator>>(std::istream & instr, GlsPropStringQuoted & str)
1284 {
1285  std::string temp;
1286  str._string = "";
1287 
1288  // The next character should be a quote.
1289  // If it is not, we will attempt to do something useful anyway.
1290  if (instr.peek() != '\"')
1291  {
1292  disti::GetToEnd(instr, temp, false);
1293  }
1294  else // Starts with quote
1295  {
1296  // Go ahead and consume the quote
1297  instr.get();
1298 
1299  int lastChar = 0;
1300  int currChar = 0;
1301  // Loop until we find an un-escaped quote or we run out of stream.
1302  while (instr.good())
1303  {
1304  lastChar = currChar;
1305  currChar = instr.get();
1306  if (currChar != -1)
1307  {
1308  if (currChar == '\"' && lastChar != '\\')
1309  break; // We found the trailing quote
1310  temp += (char)currChar;
1311  }
1312  }
1313  }
1314 
1315  str._string = disti::DecodeString(temp);
1316 
1317  return instr;
1318 }
1319 
1320 #ifndef WIN32
1321 void SpawnBrowser(const char *url);
1322 #endif
1323 
1324 /** Call this to check for the availability of a DiSTI conrolled license.
1325  It does not hold the license. It only checks it out and checks it back in.
1326  \param licenseGroupName A name for what this license allows. i.e. "GL Studio Runtime".
1327  \param feature The specific feature that will be checked out.
1328  \param version The specific version that will be checked out.
1329  \param quiet When true, no popup will occur upon missing license.
1330  */
1331 GLS_EXPORT bool CheckDistiLicense(const char* licenseGroupName, const char *feature, const char *version, bool quiet);
1332 
1333 /** This will set the m parameter to an orthographic projection.
1334  * The current value of m is ignored.
1335  * This does NOT make any OpenGL calls.
1336  */
1337 GLS_EXPORT void GlsGetOrtho(GlsMatrixType& m,
1338  double left,
1339  double right,
1340  double bottom,
1341  double top,
1342  double zNear,
1343  double zFar);
1344 
1345 /** This will set the m parameter to a perspective projection.
1346  * The current value of m is ignored
1347  * This does NOT make any OpenGL calls.
1348  */
1349 GLS_EXPORT void GlsGetPerspective(GlsMatrixType& m,
1350  double fovy,
1351  double aspect,
1352  double zNear,
1353  double zFar);
1354 
1355 // using a namespace to help avoid collisions with user code. Future functionality should prefer to go here
1356 namespace Util
1357 {
1358  ////////////////////////////////////////////////////////////////////////////////
1359  /// Clamps a value to the range [min, max]
1360  /// \param val The value to clamp
1361  /// \param min The minimum value in the range
1362  /// \param max The maximum value in the range
1363  ////////////////////////////////////////////////////////////////////////////////
1364  template<class T>
1365  T Clamp( const T& val, const T& min, const T& max )
1366  {
1367  return std::min( max, std::max( min, val ) );
1368  }
1369 
1370  ////////////////////////////////////////////////////////////////////////////////
1371  /// Split a string and add to existing vector of elements with delimeters removed.
1372  /// \param s The string to split
1373  /// \param delim The delimiter to split the string on.
1374  /// \param elems The vector of elements to append each split string to.
1375  /// \param maxElems The maximum number of elements to split. Remaining elements
1376  /// are appended unsplit as the last value. If 0, it does not
1377  /// have a maximum.
1378  /// \note Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c
1379  ////////////////////////////////////////////////////////////////////////////////
1380  inline void Split( const std::string& s, const char delim, std::vector<std::string>& elems, const std::size_t maxElems = 0 )
1381  {
1382  std::istringstream ss( s );
1383  std::string item;
1384  while( std::getline( ss, item, delim ) )
1385  {
1386  elems.push_back( DISTI_RVAL_MOVE( item ) );
1387  if( elems.size() == maxElems )
1388  {
1389  break;
1390  }
1391  }
1392  if( elems.size() == maxElems && ss.good() && maxElems > 0 )
1393  {
1394  std::string remainder;
1395  std::getline( ss, remainder, '\0' );
1396  elems.back() += delim + remainder;
1397  }
1398  }
1399 
1400  ////////////////////////////////////////////////////////////////////////////////
1401  /// Split a string return a vector of the elements with delimeters removed.
1402  /// \param s The string to split
1403  /// \param delim The delimiter to split the string on.
1404  /// \param maxElems The maximum number of elements to split. Remaining elements
1405  /// are appended unsplit as the last value. If 0, it does not
1406  /// have a maximum.
1407  /// \return The vector of split elements.
1408  /// \note Adapted from http://stackoverflow.com/questions/236129/split-a-string-in-c
1409  ////////////////////////////////////////////////////////////////////////////////
1410  inline std::vector<std::string> Split( const std::string& s, const char delim, const std::size_t maxElems = 0 )
1411  {
1412  std::vector<std::string> elems;
1413  Split( s, delim, elems, maxElems );
1414  return DISTI_RVAL_MOVE( elems );
1415  }
1416 
1417  /// Passing null to std::string is not well-defined. Create a string safely.
1418  inline std::string MakeString( const char* const cStr )
1419  {
1420  return ( cStr ? cStr : "" );
1421  }
1422 } // namespace Util
1423 
1424 } // namespace disti
1425 
1426 // Our own local versions of a few glu methods to avoid needing to include the GL Utility library
1427 GLS_EXPORT void glsPerspective(double fovy, double aspect, double zNear, double zFar);
1428 
1429 
1430 #ifdef MATRIX_TYPE_FLOAT
1431 GLS_EXPORT bool glsProject(double objx, double objy, double objz,
1432  const float modelMatrix[16],
1433  const float projMatrix[16],
1434  const int viewport[4],
1435  double *winx, double *winy, double *winz);
1436 
1437 GLS_EXPORT bool glsUnProject(double winx, double winy, double winz,
1438  const float modelMatrix[16],
1439  const float projMatrix[16],
1440  const int viewport[4],
1441  double *objx, double *objy, double *objz);
1442 #else
1443 GLS_EXPORT bool glsProject(double objx, double objy, double objz,
1444  const double modelMatrix[16],
1445  const double projMatrix[16],
1446  const int viewport[4],
1447  double *winx, double *winy, double *winz);
1448 
1449 GLS_EXPORT bool glsUnProject(double winx, double winy, double winz,
1450  const double modelMatrix[16],
1451  const double projMatrix[16],
1452  const int viewport[4],
1453  double *objx, double *objy, double *objz);
1454 #endif
1455 
1456 
1457 #endif
The DistiUnhideGlobalsDummyClass class.
const T & Min(const T &x, const T &y)
Definition: util.h:242
int EncodedStringMinLength()
GlsPropStringQuoted(const std::string &str)
Definition: util.h:1253
virtual void StreamOut(ostreamType &outstr) const
Definition: util.h:1075
std::string GetExtension(const std::string &filename)
Definition: vertex.h:365
GlsDefinedColorEnum
Definition: util.h:168
const int INLINE_TEXTURE_LINE_LENGTH
Definition: util.h:100
Definition: util.h:1239
std::string & String()
Definition: util.h:1203
std::string FileExtension(const std::string &filepath)
void GlsGetPerspective(GlsMatrixType &m, double fovy, double aspect, double zNear, double zFar)
GlsPropString(const char *str)
Definition: util.h:1190
unsigned char glsDefinedColors[GLS_COLOR_MAX][4]
virtual bool operator!=(const GlsMultiVal &val) const
Definition: util.h:1064
Definition: dynamic_array.h:63
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:281
std::string FileName(const std::string &filepath)
const char * GetBaseName(const char *path)
int EncodeString(char *dest, const char *src, const int dest_str_length)
The GlsMatrixAffine class.
Definition: util.h:847
void AppendTrailingSlash(char *s)
Definition: util.h:934
void RemoveDoubleSlashes(char *path, char slash= '/')
bool CheckDistiLicense(const char *licenseGroupName, const char *feature, const char *version, bool quiet)
std::string GetQualifiedInstanceName(const DisplayFrame *topFrame, const DisplayObject *obj)
std::string GetDefaultComponentClassName(const char *dllFileName)
Definition: util.h:895
GlsMultiVal()
Definition: util.h:971
char * PathToOS(const char *path)
float OpenGLVersion()
Definition: util.h:317
const T & Max(const T &x, const T &y)
Definition: util.h:253
virtual bool operator==(const GlsMultiVal &val) const
Definition: util.h:1039
GlsPropStringQuoted(const char *str)
Definition: util.h:1262
A file for all GL Studio files to include.
int range_check(int num, double val,...)
bool GetObjectCoordinatesTransformSameView(DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
float AngularDistanceRad(float angle1, float angle2)
std::string Uppercase(const std::string &str)
void ChangeGlsDefinedColor(GlsDefinedColorEnum index, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
Definition: util.h:203
GlsPropString()
Definition: util.h:1171
void PopResourcePath()
VertexNoColor Vector
Definition: gls_font_base.h:68
GlsMatrixAffine< T > FindCoordinateTransformation(const Vector &new_origin, const Vector &new_i, const Vector &new_j, const Vector &new_k)
Definition: util.h:360
bool FindNonColinearVertices(int arraySize, Vector array[], int &index1, int &index2, int &index3, bool isVectorArray=true)
Definition: util.h:1165
bool GetObjectCoordinatesTransform(DisplayObject *from, DisplayObject *to, GlsMatrixType *outTransform)
int DecodeString(char *dest, const char *src, const int dest_str_length)
bool GetComponentClassNames(const char *dllFileName, DynamicArray< std::string, false > &nameList, const char *createClassTag="CreateComponent_")
void Count(const unsigned int count)
Definition: dynamic_array.h:120
bool CalculateTexPointsFromTexCoords(DisplayObject *object)
friend bool operator!=(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1215
Definition: util.h:537
GlsMultiVal(const GlsMultiVal &src)
Definition: util.h:984
void PushResourcePath(const char *resourcePath)
void Translate(Type x, Type y, Type z)
Definition: gls_matrix_affine.h:197
bool FileExists(const char *filename)
int C_EncodeString(char *dest, const char *src, const int dest_str_length)
virtual void StreamIn(istreamType &instr)
Definition: util.h:1104
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:1013
FILE * gls_fopen(const char *filename, const char *flags)
bool IsDirectory(const char *filename)
float AngularDistanceDeg(float angle1, float angle2)
std::string FilePath(const std::string &filepath)
bool Equal(T1 x, T2 y, float precision=0.001f)
Definition: util.h:231
char * GetFileName(const char *name)
bool NotColinear(const Vector &a, const Vector &b, const Vector &c)
const char * GetFilePath(const char *name)
Definition: vertex.h:84
std::string ResolveRuntimeResourcePath(const char *fileName)
void PushResourceFinder(std::string(*finder)(const std::string &))
std::string ResolvePath(const char *path)
friend bool operator==(const GlsPropString &str1, const GlsPropString &str2)
Definition: util.h:1209
Contains the DistiAssert macro.
Definition: util.h:867
Macros and helper code to determine what subset of C++11/14/17 is available.
void GlsGetOrtho(GlsMatrixType &m, double left, double right, double bottom, double top, double zNear, double zFar)
GlsPropString(const std::string &str)
Definition: util.h:1180
int Safe_fopen(const char *filename, char *flags, FILE **f)
unsigned char * GlsDefinedColor(GlsDefinedColorEnum index)
Definition: util.h:192
Definition: bmpimage.h:46
GlsPropStringQuoted()
Definition: util.h:1244