GlistEngine
Loading...
Searching...
No Matches
gUtils.h File Reference
#include <string>
#include <sstream>
#include <ostream>
#include <iostream>
#include <iomanip>
#include "utf8.h"
#include <stdlib.h>
#include <wchar.h>
#include <vector>
#include <memory>
#include "gConstants.h"
#include "gKeyCode.h"
#include "gGUIEvents.h"
#include "tinyfiledialogs.h"
#include "gColor.h"
#include <cstdint>
#include <deque>
Include dependency graph for gUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  gUTF8Iterator
 
class  gLog
 
class  gLogi
 
class  gLogd
 
class  gLogw
 
class  gLoge
 
class  gUtils
 

Macros

#define UTILS_GUTILS_H_
 
#define PI   3.14159265358979323846
 

Functions

int gDefaultWidth ()
 
int gDefaultHeight ()
 
int gDefaultUnitWidth ()
 
int gDefaultUnitHeight ()
 
int gDefaultMonitorWidth ()
 
int gDefaultMonitorHeight ()
 
int gDefaultScreenScaling ()
 
float gRadToDeg (float radians)
 
float gDegToRad (float degrees)
 
void gSeedRandom ()
 
float gRandom (float max)
 
float gRandomf ()
 
uint64_t gGetSystemTimeMillis ()
 
unsigned int gGetUnixTime ()
 
int gGetYear ()
 
int gGetMonth ()
 
int gGetDay ()
 
int gGetWeekday ()
 
int gGetHours ()
 
int gGetMinutes ()
 
int gGetSeconds ()
 
void gFlipImageDataVertically (unsigned char *pixelData, int width, int height, int numChannels)
 
std::string gGetTimestampString ()
 
std::string gGetTimestampString (const std::string &format)
 
void gStringReplace (std::string &input, const std::string &searchStr, const std::string &replaceStr)
 
std::locale gGetLocale (const std::string &locale)
 
std::string gToLower (const std::string &src, const std::string &locale="")
 
std::string gToUpper (const std::string &src, const std::string &locale="")
 
std::vector< std::string > gSplitString (const std::string &textToSplit, const std::string &delimiter)
 
std::deque< std::string > gSplitStringToDeque (const std::string &textToSplit, const std::string &delimiter)
 
std::string gReplaceAll (const std::string &source, const std::string &from, const std::string &to)
 
bool gIsValidFilename (std::string fileName)
 
std::string gGetFirstLineOfTextFile (std::string fullFilepath)
 
bool gIsInt (const std::string &str)
 
bool gIsFloat (const std::string &str)
 
bool gIsNumber (const std::string &str)
 
bool gIsString (const std::string &str)
 
template<class T >
std::string gToStr (const T &numValue)
 
template<class T >
std::string gToHex (const T &numValue, int width=sizeof(T) *2)
 
template<class T >
std::string gToStr (const T &value, int width, char fill)
 
int gToInt (const std::string &intString)
 
float gToFloat (const std::string &floatString)
 
double gToDouble (const std::string &doubleString)
 
std::string gWStrToStr (const std::wstring &s)
 
template<typename T >
int gSign (T val)
 
std::string gCodepointToStr (unsigned int codepoint)
 
std::string gEncodeBase64 (unsigned char *data, int len)
 
std::string gDecodeBase64 (const std::string &encoded_string)
 
bool gIsBase64 (char c)
 
bool gIsOnline ()
 
void gOpenUrlInDefaultBrowser (std::string url)
 
void gEnableLogging ()
 
void gDisableLogging ()
 
bool gIsLoggingEnabled ()
 
template<typename T >
gClamp (T t, T min, T max)
 
std::string gShowOpenFileDialog (const std::string &dialogTitle, const std::string &defaultPathAndFile, int filterNum, const std::string *filterPatterns, const std::string &filterDescription, bool isMultipleSelectionAllowed=false)
 
std::string gShowOpenFileDialog (const std::string &dialogTitle, const std::string &defaultPathAndFile, std::initializer_list< const char * > filterPatterns, const std::string &filterDescription, bool isMultipleSelectionAllowed=false)
 
std::string gShowOpenFileDialog (const std::string &dialogTitle, const std::string &defaultPathAndFile, int filterNum, const char **filterPatterns, const std::string &filterDescription, bool isMultipleSelectionAllowed=false)
 
std::string gShowSaveFileDialog (const std::string &dialogTitle, const std::string &defaultPathAndFile, int filterNum, const std::string *filterPatterns, const std::string &filterDescription)
 
std::string gShowSaveFileDialog (const std::string &dialogTitle, const std::string &defaultPathAndFile, std::initializer_list< const char * > filterPatterns, const std::string &filterDescription)
 
std::string gShowSaveFileDialog (const std::string &dialogTitle, const std::string &defaultPathAndFile, int filterNum, const char **filterPatterns, const std::string &filterDescription)
 
std::string gShowSelectFolderDialog (const std::string &dialogTitle, const std::string &defaultPath)
 
int gShowMessageBox (const std::string &title, const std::string &message, const std::string &dialogue, const std::string &iconType, int defaultButton)
 
std::string gShowInputBox (const std::string &title, const std::string &message, const std::string &defaultInput)
 
gColor gShowColorChooser (const std::string &title, const std::string &defaultHex, unsigned char const defaultRGB[3])
 
bool gCheckCollision (int xLeft1, int yUp1, int xRight1, int yBottom1, int xLeft2, int yUp2, int xRight2, int yBottom2)
 
bool gCheckPixelPerfectCollision (gImage *image1, int x1, int y1, gImage *image2, int x2, int y2)
 
std::string gFixPath (const std::string &path)
 

Macro Definition Documentation

◆ PI

#define PI   3.14159265358979323846

◆ UTILS_GUTILS_H_

#define UTILS_GUTILS_H_

Function Documentation

◆ gCheckCollision()

bool gCheckCollision ( int  xLeft1,
int  yUp1,
int  xRight1,
int  yBottom1,
int  xLeft2,
int  yUp2,
int  xRight2,
int  yBottom2 
)

◆ gCheckPixelPerfectCollision()

bool gCheckPixelPerfectCollision ( gImage image1,
int  x1,
int  y1,
gImage image2,
int  x2,
int  y2 
)

◆ gClamp()

template<typename T >
T gClamp ( t,
min,
max 
)

◆ gCodepointToStr()

std::string gCodepointToStr ( unsigned int  codepoint)

◆ gDecodeBase64()

std::string gDecodeBase64 ( const std::string &  encoded_string)

◆ gDefaultHeight()

int gDefaultHeight ( )

◆ gDefaultMonitorHeight()

int gDefaultMonitorHeight ( )

◆ gDefaultMonitorWidth()

int gDefaultMonitorWidth ( )

◆ gDefaultScreenScaling()

int gDefaultScreenScaling ( )

◆ gDefaultUnitHeight()

int gDefaultUnitHeight ( )

◆ gDefaultUnitWidth()

int gDefaultUnitWidth ( )

◆ gDefaultWidth()

int gDefaultWidth ( )

◆ gDegToRad()

float gDegToRad ( float  degrees)

◆ gDisableLogging()

void gDisableLogging ( )

◆ gEnableLogging()

void gEnableLogging ( )

◆ gEncodeBase64()

std::string gEncodeBase64 ( unsigned char *  data,
int  len 
)

◆ gFixPath()

std::string gFixPath ( const std::string &  path)

◆ gFlipImageDataVertically()

void gFlipImageDataVertically ( unsigned char *  pixelData,
int  width,
int  height,
int  numChannels 
)

◆ gGetDay()

int gGetDay ( )

◆ gGetFirstLineOfTextFile()

std::string gGetFirstLineOfTextFile ( std::string  fullFilepath)

◆ gGetHours()

int gGetHours ( )

◆ gGetLocale()

std::locale gGetLocale ( const std::string &  locale)

◆ gGetMinutes()

int gGetMinutes ( )

◆ gGetMonth()

int gGetMonth ( )

◆ gGetSeconds()

int gGetSeconds ( )

◆ gGetSystemTimeMillis()

uint64_t gGetSystemTimeMillis ( )

◆ gGetTimestampString() [1/2]

std::string gGetTimestampString ( )

◆ gGetTimestampString() [2/2]

std::string gGetTimestampString ( const std::string &  format)

◆ gGetUnixTime()

unsigned int gGetUnixTime ( )

◆ gGetWeekday()

int gGetWeekday ( )

◆ gGetYear()

int gGetYear ( )

◆ gIsBase64()

bool gIsBase64 ( char  c)

◆ gIsFloat()

bool gIsFloat ( const std::string &  str)

◆ gIsInt()

bool gIsInt ( const std::string &  str)

◆ gIsLoggingEnabled()

bool gIsLoggingEnabled ( )

◆ gIsNumber()

bool gIsNumber ( const std::string &  str)

◆ gIsOnline()

bool gIsOnline ( )

◆ gIsString()

bool gIsString ( const std::string &  str)

◆ gIsValidFilename()

bool gIsValidFilename ( std::string  fileName)

◆ gOpenUrlInDefaultBrowser()

void gOpenUrlInDefaultBrowser ( std::string  url)

◆ gRadToDeg()

float gRadToDeg ( float  radians)

◆ gRandom()

float gRandom ( float  max)

◆ gRandomf()

float gRandomf ( )

◆ gReplaceAll()

std::string gReplaceAll ( const std::string &  source,
const std::string &  from,
const std::string &  to 
)

◆ gSeedRandom()

void gSeedRandom ( )

◆ gShowColorChooser()

gColor gShowColorChooser ( const std::string &  title,
const std::string &  defaultHex,
unsigned char const  defaultRGB[3] 
)

Shows operating system's color chooser dialog box

Parameters
titleDialog's title. Can be empty.
defaultHexDefault color in hexadecimal format (e.g., "#FF0000"). Can be empty.
defaultRGBDefault color in RGB format as an array of three unsigned char values (e.g., {0, 255, 255}).
Returns
Selected color as a gColor object.

◆ gShowInputBox()

std::string gShowInputBox ( const std::string &  title,
const std::string &  message,
const std::string &  defaultInput 
)

Shows operating system's input dialog box

Parameters
titleDialog's title. Can be empty.
messageDialog's message text. May contain
and \t or be empty.
defaultInputDefault input text. If empty, it will display a password box.
Returns
User input as a string.

◆ gShowMessageBox()

int gShowMessageBox ( const std::string &  title,
const std::string &  message,
const std::string &  dialogue,
const std::string &  iconType,
int  defaultButton 
)

Shows operating system's message dialog box

Parameters
titleDialog's title
messageDialog's message text. May contain
and \t or be empty
dialogueDialog's type. Possible values are "ok", "okcancel", "yesno", "yesnocancel"
iconTypeDialog's type. Possible values are "info", "warning", "error", "question"
Returns
clicked button

◆ gShowOpenFileDialog() [1/3]

std::string gShowOpenFileDialog ( const std::string &  dialogTitle,
const std::string &  defaultPathAndFile,
int  filterNum,
const char **  filterPatterns,
const std::string &  filterDescription,
bool  isMultipleSelectionAllowed = false 
)

◆ gShowOpenFileDialog() [2/3]

std::string gShowOpenFileDialog ( const std::string &  dialogTitle,
const std::string &  defaultPathAndFile,
int  filterNum,
const std::string *  filterPatterns,
const std::string &  filterDescription,
bool  isMultipleSelectionAllowed = false 
)

Shows operating system's open file dialog

EXAMPLE USAGE

// GameCanvas.h:
static const int patternnum = 2;
std::string filterpatterns[patternnum];
std::string filepath;
// GameCanvas.cpp:
void GameCanvas::setup() {
filterpatterns[0] = "*.csv";
filterpatterns[1] = "*.txt";
filepath = "";
}
void GameCanvas::mouseReleased(int x, int y, int button) {
std::string openfilename = gShowOpenFileDialog("Open File", gGetFilesDir(), patternnum, filterpatterns, "Data files", false);
if(!openfilename.empty()) {
filepath = openfilename;
gLogi("GameCanvas") << "filepath:" << filepath;
} else {
gLogi("GameCanvas") << "No file selected!";
}
}
Definition gUtils.h:271
std::string gShowOpenFileDialog(const std::string &dialogTitle, const std::string &defaultPathAndFile, int filterNum, const std::string *filterPatterns, const std::string &filterDescription, bool isMultipleSelectionAllowed=false)
Parameters
dialogTitleDialog's title
defaultPathAndFileDefault path to show
filterNumFilter pattern number
filterPatternsA string array of the file patterns to browse
filterDescriptionDescription of the filter such as 'Image files'
isMultipleSelectionAllowedIs multiple selection allowed. Default value is false.
Returns
Chosen file's full path

◆ gShowOpenFileDialog() [3/3]

std::string gShowOpenFileDialog ( const std::string &  dialogTitle,
const std::string &  defaultPathAndFile,
std::initializer_list< const char * >  filterPatterns,
const std::string &  filterDescription,
bool  isMultipleSelectionAllowed = false 
)

Shows the operating system's open file dialog

EXAMPLE USAGE

std::string filepath = gShowOpenFileDialog(
"Open File",
gGetFilesDir(),
{"*.csv", "*.txt"},
"Data files",
false
);
if(!filepath.empty()) {
gLogi("FileDialog") << "Selected file: " << filepath;
}
Parameters
dialogTitleDialog's title.
defaultPathAndFileDefault path and file to display in the dialog.
filterPatternsAn initializer list of file patterns to filter (e.g., {"*.txt", "*.csv"}).
filterDescriptionDescription of the file filter (e.g., "Text files").
isMultipleSelectionAllowedIf true, allows multiple file selection. Default is false.
Returns
The full path of the selected file as a string. Returns an empty string if no file is selected.

◆ gShowSaveFileDialog() [1/3]

std::string gShowSaveFileDialog ( const std::string &  dialogTitle,
const std::string &  defaultPathAndFile,
int  filterNum,
const char **  filterPatterns,
const std::string &  filterDescription 
)

◆ gShowSaveFileDialog() [2/3]

std::string gShowSaveFileDialog ( const std::string &  dialogTitle,
const std::string &  defaultPathAndFile,
int  filterNum,
const std::string *  filterPatterns,
const std::string &  filterDescription 
)

◆ gShowSaveFileDialog() [3/3]

std::string gShowSaveFileDialog ( const std::string &  dialogTitle,
const std::string &  defaultPathAndFile,
std::initializer_list< const char * >  filterPatterns,
const std::string &  filterDescription 
)

◆ gShowSelectFolderDialog()

std::string gShowSelectFolderDialog ( const std::string &  dialogTitle,
const std::string &  defaultPath 
)

◆ gSign()

template<typename T >
int gSign ( val)

◆ gSplitString()

std::vector< std::string > gSplitString ( const std::string &  textToSplit,
const std::string &  delimiter 
)

◆ gSplitStringToDeque()

std::deque< std::string > gSplitStringToDeque ( const std::string &  textToSplit,
const std::string &  delimiter 
)

◆ gStringReplace()

void gStringReplace ( std::string &  input,
const std::string &  searchStr,
const std::string &  replaceStr 
)

◆ gToDouble()

double gToDouble ( const std::string &  doubleString)

◆ gToFloat()

float gToFloat ( const std::string &  floatString)

◆ gToHex()

template<class T >
std::string gToHex ( const T &  numValue,
int  width = sizeof(T)*2 
)

◆ gToInt()

int gToInt ( const std::string &  intString)

◆ gToLower()

std::string gToLower ( const std::string &  src,
const std::string &  locale = "" 
)

◆ gToStr() [1/2]

template<class T >
std::string gToStr ( const T &  numValue)

◆ gToStr() [2/2]

template<class T >
std::string gToStr ( const T &  value,
int  width,
char  fill 
)

◆ gToUpper()

std::string gToUpper ( const std::string &  src,
const std::string &  locale = "" 
)

◆ gWStrToStr()

std::string gWStrToStr ( const std::wstring &  s)