Преглед изворни кода

Add color var in lua

Add SafeEnum var in lua
MeshViewer SceneSetup is operational
Added imGui to vs-solution, not implemented yet
undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> пре 9 година
родитељ
комит
a8c3a80eb1
85 измењених фајлова са 29102 додато и 5406 уклоњено
  1. +13
    -0
      build/Lol (vs2013).sln
  2. +13
    -13
      doc/samples/data/mesh-buffer.txt
  3. +0
    -164
      doc/samples/generated/location.hh
  4. +0
    -161
      doc/samples/generated/position.hh
  5. +0
    -1160
      doc/samples/generated/scenesetup-parser.cpp
  6. +0
    -333
      doc/samples/generated/scenesetup-parser.h
  7. +0
    -879
      doc/samples/generated/scenesetup-parser.output
  8. +0
    -1821
      doc/samples/generated/scenesetup-scanner.cpp
  9. +0
    -135
      doc/samples/generated/stack.hh
  10. +8
    -1
      doc/samples/meshviewer.cpp
  11. +116
    -125
      doc/samples/meshviewer.vcxproj
  12. +19
    -0
      doc/samples/meshviewer_init.lua
  13. +0
    -55
      doc/samples/scenesetup-compiler.cpp
  14. +0
    -60
      doc/samples/scenesetup-compiler.h
  15. +0
    -213
      doc/samples/scenesetup-parser.y
  16. +0
    -149
      doc/samples/scenesetup-scanner.l
  17. +232
    -9
      doc/samples/scenesetup.cpp
  18. +179
    -10
      doc/samples/scenesetup.h
  19. +7
    -32
      src/easymesh/easymeshlua.h
  20. +1
    -0
      src/imgui/.gitignore
  21. +17
    -0
      src/imgui/.travis.yml
  22. +21
    -0
      src/imgui/LICENSE
  23. +137
    -0
      src/imgui/README.md
  24. +28
    -0
      src/imgui/examples/.gitignore
  25. +18
    -0
      src/imgui/examples/README.txt
  26. +90
    -0
      src/imgui/examples/directx11_example/directx11_example.vcxproj
  27. +33
    -0
      src/imgui/examples/directx11_example/directx11_example.vcxproj.filters
  28. +465
    -0
      src/imgui/examples/directx11_example/imgui_impl_dx11.cpp
  29. +20
    -0
      src/imgui/examples/directx11_example/imgui_impl_dx11.h
  30. +210
    -0
      src/imgui/examples/directx11_example/main.cpp
  31. +90
    -0
      src/imgui/examples/directx9_example/directx9_example.vcxproj
  32. +34
    -0
      src/imgui/examples/directx9_example/directx9_example.vcxproj.filters
  33. +286
    -0
      src/imgui/examples/directx9_example/imgui_impl_dx9.cpp
  34. +19
    -0
      src/imgui/examples/directx9_example/imgui_impl_dx9.h
  35. +146
    -0
      src/imgui/examples/directx9_example/main.cpp
  36. +38
    -0
      src/imgui/examples/imgui_examples_msvc2010.sln
  37. +51
    -0
      src/imgui/examples/opengl3_example/Makefile
  38. +1339
    -0
      src/imgui/examples/opengl3_example/gl3w/GL/gl3w.c
  39. +1234
    -0
      src/imgui/examples/opengl3_example/gl3w/GL/gl3w.h
  40. +4533
    -0
      src/imgui/examples/opengl3_example/gl3w/GL/glcorearb.h
  41. +348
    -0
      src/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.cpp
  42. +20
    -0
      src/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.h
  43. +87
    -0
      src/imgui/examples/opengl3_example/main.cpp
  44. +98
    -0
      src/imgui/examples/opengl3_example/opengl3_example.vcxproj
  45. +46
    -0
      src/imgui/examples/opengl3_example/opengl3_example.vcxproj.filters
  46. +51
    -0
      src/imgui/examples/opengl_example/Makefile
  47. +22
    -0
      src/imgui/examples/opengl_example/glfw/COPYING.txt
  48. +2281
    -0
      src/imgui/examples/opengl_example/glfw/include/GLFW/glfw3.h
  49. +180
    -0
      src/imgui/examples/opengl_example/glfw/include/GLFW/glfw3native.h
  50. BIN
      src/imgui/examples/opengl_example/glfw/lib-msvc100/glfw3.lib
  51. BIN
      src/imgui/examples/opengl_example/glfw/lib-msvc110/glfw3.lib
  52. +252
    -0
      src/imgui/examples/opengl_example/imgui_impl_glfw.cpp
  53. +20
    -0
      src/imgui/examples/opengl_example/imgui_impl_glfw.h
  54. +81
    -0
      src/imgui/examples/opengl_example/main.cpp
  55. +95
    -0
      src/imgui/examples/opengl_example/opengl_example.vcxproj
  56. +34
    -0
      src/imgui/examples/opengl_example/opengl_example.vcxproj.filters
  57. BIN
      src/imgui/extra_fonts/DroidSans.ttf
  58. BIN
      src/imgui/extra_fonts/Karla-Regular.ttf
  59. BIN
      src/imgui/extra_fonts/ProggyClean.ttf
  60. BIN
      src/imgui/extra_fonts/ProggyTiny.ttf
  61. +60
    -0
      src/imgui/extra_fonts/README.txt
  62. +52
    -0
      src/imgui/imconfig.h
  63. +10056
    -0
      src/imgui/imgui.cpp
  64. +974
    -0
      src/imgui/imgui.h
  65. +77
    -0
      src/imgui/lolimgui.vcxproj
  66. +1
    -0
      src/imgui/revision.txt
  67. +547
    -0
      src/imgui/stb_rect_pack.h
  68. +1254
    -0
      src/imgui/stb_textedit.h
  69. +2658
    -0
      src/imgui/stb_truetype.h
  70. BIN
      src/imgui/web/code_sample_01.png
  71. BIN
      src/imgui/web/code_sample_01_jp.png
  72. BIN
      src/imgui/web/examples_01.png
  73. BIN
      src/imgui/web/examples_02.png
  74. BIN
      src/imgui/web/performance_01.png
  75. BIN
      src/imgui/web/performance_01_close_up.png
  76. BIN
      src/imgui/web/skinning_sample_01.png
  77. BIN
      src/imgui/web/test_window_01.png
  78. BIN
      src/imgui/web/test_window_02.png
  79. BIN
      src/imgui/web/test_window_03.png
  80. BIN
      src/imgui/web/test_window_04.png
  81. BIN
      src/imgui/web/utf8_sample_01.png
  82. +22
    -0
      src/lol/base/enum.h
  83. +111
    -69
      src/lol/math/vector.h
  84. +273
    -16
      src/lolua/baselua.h
  85. +5
    -1
      src/utils.h

+ 13
- 0
build/Lol (vs2013).sln Прегледај датотеку

@@ -155,6 +155,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "..\people\touky\s
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "14_lol_lua", "..\doc\tutorial\14_lol_lua.vcxproj", "{81C83B42-D00A-4FA3-9A3D-80F9D46524BF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lolimgui", "..\src\imgui\lolimgui.vcxproj", "{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ORBIS = Debug|ORBIS
@@ -638,6 +640,16 @@ Global
{81C83B42-D00A-4FA3-9A3D-80F9D46524BF}.Release|Win32.Build.0 = Release|Win32
{81C83B42-D00A-4FA3-9A3D-80F9D46524BF}.Release|x64.ActiveCfg = Release|x64
{81C83B42-D00A-4FA3-9A3D-80F9D46524BF}.Release|x64.Build.0 = Release|x64
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Debug|ORBIS.ActiveCfg = Debug|Win32
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Debug|Win32.ActiveCfg = Debug|Win32
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Debug|Win32.Build.0 = Debug|Win32
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Debug|x64.ActiveCfg = Debug|x64
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Debug|x64.Build.0 = Debug|x64
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Release|ORBIS.ActiveCfg = Release|Win32
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Release|Win32.ActiveCfg = Release|Win32
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Release|Win32.Build.0 = Release|Win32
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Release|x64.ActiveCfg = Release|x64
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -661,6 +673,7 @@ Global
{D84021CA-B233-4E0F-8A52-071B83BBCCC4} = {1AFD580B-98B8-4689-B661-38C41132C60E}
{E4DFEBF9-C310-462F-9876-7EB59C1E4D4E} = {1AFD580B-98B8-4689-B661-38C41132C60E}
{9E62F2FE-3408-4EAE-8238-FD84238CEEDA} = {1AFD580B-98B8-4689-B661-38C41132C60E}
{A7F6FDF8-937E-41EF-B44D-04CD1A48C179} = {1AFD580B-98B8-4689-B661-38C41132C60E}
{962D4E25-45D3-4ACE-8C02-69FA3713ABD4} = {E4DFEBF9-C310-462F-9876-7EB59C1E4D4E}
{1782F849-B6E1-466D-9F02-A751F3F8712C} = {E4DFEBF9-C310-462F-9876-7EB59C1E4D4E}
{5A27FF18-A1EC-49BE-9455-415F1C701153} = {E4DFEBF9-C310-462F-9876-7EB59C1E4D4E}


+ 13
- 13
doc/samples/data/mesh-buffer.txt Прегледај датотеку

@@ -1,16 +1,16 @@
addlight 0 position (0 0 15) color #bbb
addlight 1 position (0 0 15) color #bbb
//addlight 1 position (3 10 0) color #444
clearcolor #ddd
showgizmo true
showlight true
//SCENE SETUP END
//addlight 0.0 position (1 0 1) color #0ff
//addlight 0.0 position (-0.2 -1 -0.5) color (.0 .2 .5 1)
addlight 0 position (0 0 15) color #bbb
addlight 1 position (0 0 15) color #bbb
//addlight 1 position (3 10 0) color #444
clearcolor #ddd
showgizmo true
showlight true
//SCENE SETUP END
//addlight 0.0 position (1 0 1) color #0ff
//addlight 0.0 position (-0.2 -1 -0.5) color (.0 .2 .5 1)
//custom setmesh "sc#f00 ab 2 ty 1.5 ab 2"
custom setmesh "


+ 0
- 164
doc/samples/generated/location.hh Прегледај датотеку

@@ -1,164 +0,0 @@
/* A Bison parser, made by GNU Bison 2.4.2. */

/* Locations for Bison parsers in C++
Copyright (C) 2002-2007, 2009-2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */

/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */

/**
** \file location.hh
** Define the lol::location class.
*/

#ifndef BISON_LOCATION_HH
# define BISON_LOCATION_HH

# include <iostream>
# include <string>
# include "position.hh"


namespace lol {

/* Line 162 of location.cc */
#line 50 "generated/location.hh"

/// Abstract a location.
class location
{
public:

/// Construct a location.
location ()
: begin (), end ()
{
}


/// Initialization.
inline void initialize (std::string* fn)
{
begin.initialize (fn);
end = begin;
}

/** \name Line and Column related manipulators
** \{ */
public:
/// Reset initial location to final location.
inline void step ()
{
begin = end;
}

/// Extend the current location to the COUNT next columns.
inline void columns (unsigned int count = 1)
{
end += count;
}

/// Extend the current location to the COUNT next lines.
inline void lines (unsigned int count = 1)
{
end.lines (count);
}
/** \} */


public:
/// Beginning of the located region.
position begin;
/// End of the located region.
position end;
};

/// Join two location objects to create a location.
inline const location operator+ (const location& begin, const location& end)
{
location res = begin;
res.end = end.end;
return res;
}

/// Add two location objects.
inline const location operator+ (const location& begin, unsigned int width)
{
location res = begin;
res.columns (width);
return res;
}

/// Add and assign a location.
inline location& operator+= (location& res, unsigned int width)
{
res.columns (width);
return res;
}

/// Compare two location objects.
inline bool
operator== (const location& loc1, const location& loc2)
{
return loc1.begin == loc2.begin && loc1.end == loc2.end;
}

/// Compare two location objects.
inline bool
operator!= (const location& loc1, const location& loc2)
{
return !(loc1 == loc2);
}

/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param loc a reference to the location to redirect
**
** Avoid duplicate information.
*/
inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
{
position last = loc.end - 1;
ostr << loc.begin;
if (last.filename
&& (!loc.begin.filename
|| *loc.begin.filename != *last.filename))
ostr << '-' << last;
else if (loc.begin.line != last.line)
ostr << '-' << last.line << '.' << last.column;
else if (loc.begin.column != last.column)
ostr << '-' << last.column;
return ostr;
}


} // lol

/* Line 271 of location.cc */
#line 163 "generated/location.hh"

#endif // not BISON_LOCATION_HH

+ 0
- 161
doc/samples/generated/position.hh Прегледај датотеку

@@ -1,161 +0,0 @@
/* A Bison parser, made by GNU Bison 2.4.2. */

/* Positions for Bison parsers in C++
Copyright (C) 2002-2007, 2009-2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */

/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */

/**
** \file position.hh
** Define the lol::position class.
*/

#ifndef BISON_POSITION_HH
# define BISON_POSITION_HH

# include <iostream>
# include <string>
# include <algorithm>


namespace lol {

/* Line 37 of location.cc */
#line 50 "generated/position.hh"
/// Abstract a position.
class position
{
public:

/// Construct a position.
position ()
: filename (0), line (1), column (1)
{
}


/// Initialization.
inline void initialize (std::string* fn)
{
filename = fn;
line = 1;
column = 1;
}

/** \name Line and Column related manipulators
** \{ */
public:
/// (line related) Advance to the COUNT next lines.
inline void lines (int count = 1)
{
column = 1;
line += count;
}

/// (column related) Advance to the COUNT next columns.
inline void columns (int count = 1)
{
column = std::max (1u, column + count);
}
/** \} */

public:
/// File name to which this position refers.
std::string* filename;
/// Current line number.
unsigned int line;
/// Current column number.
unsigned int column;
};

/// Add and assign a position.
inline const position&
operator+= (position& res, const int width)
{
res.columns (width);
return res;
}

/// Add two position objects.
inline const position
operator+ (const position& begin, const int width)
{
position res = begin;
return res += width;
}

/// Add and assign a position.
inline const position&
operator-= (position& res, const int width)
{
return res += -width;
}

/// Add two position objects.
inline const position
operator- (const position& begin, const int width)
{
return begin + -width;
}

/// Compare two position objects.
inline bool
operator== (const position& pos1, const position& pos2)
{
return (pos1.line == pos2.line
&& pos1.column == pos2.column
&& (pos1.filename == pos2.filename
|| (pos1.filename && pos2.filename
&& *pos1.filename == *pos2.filename)));
}

/// Compare two position objects.
inline bool
operator!= (const position& pos1, const position& pos2)
{
return !(pos1 == pos2);
}

/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param pos a reference to the position to redirect
*/
inline std::ostream&
operator<< (std::ostream& ostr, const position& pos)
{
if (pos.filename)
ostr << *pos.filename << ':';
return ostr << pos.line << '.' << pos.column;
}


} // lol

/* Line 144 of location.cc */
#line 161 "generated/position.hh"
#endif // not BISON_POSITION_HH

+ 0
- 1160
doc/samples/generated/scenesetup-parser.cpp
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 0
- 333
doc/samples/generated/scenesetup-parser.h Прегледај датотеку

@@ -1,333 +0,0 @@
/* A Bison parser, made by GNU Bison 2.4.2. */

/* Skeleton interface for Bison LALR(1) parsers in C++
Copyright (C) 2002-2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */

/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */

/* C++ LALR(1) parser skeleton written by Akim Demaille. */

#ifndef PARSER_HEADER_H
# define PARSER_HEADER_H



#include <string>
#include <iostream>
#include "stack.hh"


namespace lol {

/* Line 34 of lalr1.cc */
#line 49 "generated/scenesetup-parser.h"
class position;
class location;

} // lol

/* Line 34 of lalr1.cc */
#line 56 "generated/scenesetup-parser.h"

#include "location.hh"

/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif

/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 1
#endif

/* Enabling the token table. */
#ifndef YYTOKEN_TABLE
# define YYTOKEN_TABLE 0
#endif

/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */

#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
if (N) \
{ \
(Current).begin = (Rhs)[1].begin; \
(Current).end = (Rhs)[N].end; \
} \
else \
{ \
(Current).begin = (Current).end = (Rhs)[0].end; \
} \
} while (false)
#endif


namespace lol {

/* Line 34 of lalr1.cc */
#line 101 "generated/scenesetup-parser.h"

/// A Bison parser.
class SceneSetupParser
{
public:
/// Symbol semantic values.
#ifndef YYSTYPE
union semantic_type
{

/* Line 34 of lalr1.cc */
#line 33 "scenesetup-parser.y"

float fval;
int ival;
bool bval;
float vval[4];
int ivval[4];
char* sval;
char* svval;
/* Can't use uin32_t here for some reason */
unsigned u32val;



/* Line 34 of lalr1.cc */
#line 128 "generated/scenesetup-parser.h"
};
#else
typedef YYSTYPE semantic_type;
#endif
/// Symbol locations.
typedef location location_type;
/// Tokens.
struct token
{
/* Tokens. */
enum yytokentype {
T_END = 0,
T_COLOR = 258,
T_ADDLIGHT = 259,
T_OBJPOSITION = 260,
T_OBJLOOKAT = 261,
T_OBJCOLOR = 262,
T_CLEARCOLOR = 263,
T_SHOWGIZMO = 264,
T_SHOWLIGHT = 265,
T_CUSTOMCMD = 266,
T_ERROR = 267,
F_NUMBER = 268,
I_NUMBER = 269,
STRING = 270,
STRING_VAR = 271,
BOOLEAN = 272,
COLOR = 273
};

};
/// Token type.
typedef token::yytokentype token_type;

/// Build a parser object.
SceneSetupParser (class SceneSetupCompiler& uc_yyarg);
virtual ~SceneSetupParser ();

/// Parse.
/// \returns 0 iff parsing succeeded.
virtual int parse ();

#if YYDEBUG
/// The current debugging stream.
std::ostream& debug_stream () const;
/// Set the current debugging stream.
void set_debug_stream (std::ostream &);

/// Type for debugging levels.
typedef int debug_level_type;
/// The current debugging level.
debug_level_type debug_level () const;
/// Set the current debugging level.
void set_debug_level (debug_level_type l);
#endif

private:
/// Report a syntax error.
/// \param loc where the syntax error is found.
/// \param msg a description of the syntax error.
virtual void error (const location_type& loc, const std::string& msg);

/// Generate an error message.
/// \param state the state where the error occurred.
/// \param tok the lookahead token.
virtual std::string yysyntax_error_ (int yystate, int tok);

#if YYDEBUG
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
virtual void yy_symbol_value_print_ (int yytype,
const semantic_type* yyvaluep,
const location_type* yylocationp);
/// \brief Report a symbol on the debug stream.
/// \param yytype The token type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
virtual void yy_symbol_print_ (int yytype,
const semantic_type* yyvaluep,
const location_type* yylocationp);
#endif


/// State numbers.
typedef int state_type;
/// State stack type.
typedef stack<state_type> state_stack_type;
/// Semantic value stack type.
typedef stack<semantic_type> semantic_stack_type;
/// location stack type.
typedef stack<location_type> location_stack_type;

/// The state stack.
state_stack_type yystate_stack_;
/// The semantic value stack.
semantic_stack_type yysemantic_stack_;
/// The location stack.
location_stack_type yylocation_stack_;

/// Internal symbol numbers.
typedef unsigned char token_number_type;
/* Tables. */
/// For a state, the index in \a yytable_ of its portion.
static const signed char yypact_[];
static const signed char yypact_ninf_;

/// For a state, default rule to reduce.
/// Unless\a yytable_ specifies something else to do.
/// Zero means the default is an error.
static const unsigned char yydefact_[];

static const signed char yypgoto_[];
static const signed char yydefgoto_[];

/// What to do in a state.
/// \a yytable_[yypact_[s]]: what to do in state \a s.
/// - if positive, shift that token.
/// - if negative, reduce the rule which number is the opposite.
/// - if zero, do what YYDEFACT says.
static const unsigned char yytable_[];
static const signed char yytable_ninf_;

static const signed char yycheck_[];

/// For a state, its accessing symbol.
static const unsigned char yystos_[];

/// For a rule, its LHS.
static const unsigned char yyr1_[];
/// For a rule, its RHS length.
static const unsigned char yyr2_[];

#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/// For a symbol, its name in clear.
static const char* const yytname_[];
#endif

#if YYERROR_VERBOSE
/// Convert the symbol name \a n to a form suitable for a diagnostic.
virtual std::string yytnamerr_ (const char *n);
#endif

#if YYDEBUG
/// A type to store symbol numbers and -1.
typedef signed char rhs_number_type;
/// A `-1'-separated list of the rules' RHS.
static const rhs_number_type yyrhs_[];
/// For each rule, the index of the first RHS symbol in \a yyrhs_.
static const unsigned char yyprhs_[];
/// For each rule, its source line number.
static const unsigned char yyrline_[];
/// For each scanner token number, its symbol number.
static const unsigned short int yytoken_number_[];
/// Report on the debug stream that the rule \a r is going to be reduced.
virtual void yy_reduce_print_ (int r);
/// Print the state stack on the debug stream.
virtual void yystack_print_ ();

/* Debugging. */
int yydebug_;
std::ostream* yycdebug_;
#endif

/// Convert a scanner token number \a t to a symbol number.
token_number_type yytranslate_ (int t);

/// \brief Reclaim the memory associated to a symbol.
/// \param yymsg Why this token is reclaimed.
/// \param yytype The symbol type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
inline void yydestruct_ (const char* yymsg,
int yytype,
semantic_type* yyvaluep,
location_type* yylocationp);

/// Pop \a n symbols the three stacks.
inline void yypop_ (unsigned int n = 1);

/* Constants. */
static const int yyeof_;
/* LAST_ -- Last index in TABLE_. */
static const int yylast_;
static const int yynnts_;
static const int yyempty_;
static const int yyfinal_;
static const int yyterror_;
static const int yyerrcode_;
static const int yyntokens_;
static const unsigned int yyuser_token_number_max_;
static const token_number_type yyundef_token_;

/* User arguments. */
class SceneSetupCompiler& uc;
};

} // lol

/* Line 34 of lalr1.cc */
#line 330 "generated/scenesetup-parser.h"



#endif /* ! defined PARSER_HEADER_H */

+ 0
- 879
doc/samples/generated/scenesetup-parser.output Прегледај датотеку

@@ -1,879 +0,0 @@
Nonterminals useless in grammar

iv3


Terminals unused in grammar

T_COLOR
T_ERROR


Rules useless in grammar

42 iv3: '(' iv ')'
43 | '(' iv iv iv ')'


Rules useless in parser due to conflicts

28 iv: I_NUMBER
29 | '-' iv
30 | F_NUMBER
31 | '-' fv


State 12 conflicts: 8 shift/reduce
State 42 conflicts: 13 reduce/reduce
State 43 conflicts: 13 reduce/reduce
State 52 conflicts: 13 reduce/reduce
State 53 conflicts: 13 reduce/reduce


Grammar

0 $accept: sstp_description T_END

1 sstp_description: sstp_expression_list T_END

2 sstp_expression_list: sstp_expression
3 | sstp_expression sstp_expression_list

4 sstp_expression: sstp_command_list

5 sstp_command_list: sstp_command
6 | sstp_command_list sstp_command

7 sstp_command: light_command
8 | setup_command
9 | scene_command
10 | custom_command

11 light_command: T_ADDLIGHT
12 | T_ADDLIGHT fv
13 | T_ADDLIGHT svv

14 setup_command: T_OBJPOSITION v3
15 | T_OBJLOOKAT v3
16 | T_OBJCOLOR v4
17 | T_OBJCOLOR COLOR

18 $@1: /* empty */

19 scene_command: T_CLEARCOLOR v4 $@1 T_CLEARCOLOR v3
20 | T_CLEARCOLOR COLOR
21 | T_SHOWGIZMO bv
22 | T_SHOWLIGHT bv

23 custom_command: T_CUSTOMCMD svv sv

24 fv: F_NUMBER
25 | '-' fv
26 | I_NUMBER
27 | '-' iv

28 iv: I_NUMBER
29 | '-' iv
30 | F_NUMBER
31 | '-' fv

32 v3: '(' fv ')'
33 | '(' fv fv fv ')'

34 v4: '(' fv ')'
35 | '(' fv fv fv fv ')'

36 bv: BOOLEAN
37 | I_NUMBER
38 | F_NUMBER

39 svv: STRING_VAR

40 sv: STRING
41 | STRING sv


Terminals, with rules where they appear

T_END (0) 0 1
'(' (40) 32 33 34 35
')' (41) 32 33 34 35
'-' (45) 25 27 29 31
error (256)
T_COLOR (258)
T_ADDLIGHT (259) 11 12 13
T_OBJPOSITION (260) 14
T_OBJLOOKAT (261) 15
T_OBJCOLOR (262) 16 17
T_CLEARCOLOR (263) 19 20
T_SHOWGIZMO (264) 21
T_SHOWLIGHT (265) 22
T_CUSTOMCMD (266) 23
T_ERROR (267)
F_NUMBER (268) 24 30 38
I_NUMBER (269) 26 28 37
STRING (270) 40 41
STRING_VAR (271) 39
BOOLEAN (272) 36
COLOR (273) 17 20


Nonterminals, with rules where they appear

$accept (22)
on left: 0
sstp_description (23)
on left: 1, on right: 0
sstp_expression_list (24)
on left: 2 3, on right: 1 3
sstp_expression (25)
on left: 4, on right: 2 3
sstp_command_list (26)
on left: 5 6, on right: 4 6
sstp_command (27)
on left: 7 8 9 10, on right: 5 6
light_command (28)
on left: 11 12 13, on right: 7
setup_command (29)
on left: 14 15 16 17, on right: 8
scene_command (30)
on left: 19 20 21 22, on right: 9
$@1 (31)
on left: 18, on right: 19
custom_command (32)
on left: 23, on right: 10
fv (33)
on left: 24 25 26 27, on right: 12 25 31 32 33 34 35
iv (34)
on left: 28 29 30 31, on right: 27 29
v3 (35)
on left: 32 33, on right: 14 15 19
v4 (36)
on left: 34 35, on right: 16 19
bv (37)
on left: 36 37 38, on right: 21 22
svv (38)
on left: 39, on right: 13 23
sv (39)
on left: 40 41, on right: 23 41


state 0

0 $accept: . sstp_description T_END

T_ADDLIGHT shift, and go to state 1
T_OBJPOSITION shift, and go to state 2
T_OBJLOOKAT shift, and go to state 3
T_OBJCOLOR shift, and go to state 4
T_CLEARCOLOR shift, and go to state 5
T_SHOWGIZMO shift, and go to state 6
T_SHOWLIGHT shift, and go to state 7
T_CUSTOMCMD shift, and go to state 8

sstp_description go to state 9
sstp_expression_list go to state 10
sstp_expression go to state 11
sstp_command_list go to state 12
sstp_command go to state 13
light_command go to state 14
setup_command go to state 15
scene_command go to state 16
custom_command go to state 17


state 1

11 light_command: T_ADDLIGHT .
12 | T_ADDLIGHT . fv
13 | T_ADDLIGHT . svv

F_NUMBER shift, and go to state 18
I_NUMBER shift, and go to state 19
STRING_VAR shift, and go to state 20
'-' shift, and go to state 21

$default reduce using rule 11 (light_command)

fv go to state 22
svv go to state 23


state 2

14 setup_command: T_OBJPOSITION . v3

'(' shift, and go to state 24

v3 go to state 25


state 3

15 setup_command: T_OBJLOOKAT . v3

'(' shift, and go to state 24

v3 go to state 26


state 4

16 setup_command: T_OBJCOLOR . v4
17 | T_OBJCOLOR . COLOR

COLOR shift, and go to state 27
'(' shift, and go to state 28

v4 go to state 29


state 5

19 scene_command: T_CLEARCOLOR . v4 $@1 T_CLEARCOLOR v3
20 | T_CLEARCOLOR . COLOR

COLOR shift, and go to state 30
'(' shift, and go to state 28

v4 go to state 31


state 6

21 scene_command: T_SHOWGIZMO . bv

F_NUMBER shift, and go to state 32
I_NUMBER shift, and go to state 33
BOOLEAN shift, and go to state 34

bv go to state 35


state 7

22 scene_command: T_SHOWLIGHT . bv

F_NUMBER shift, and go to state 32
I_NUMBER shift, and go to state 33
BOOLEAN shift, and go to state 34

bv go to state 36


state 8

23 custom_command: T_CUSTOMCMD . svv sv

STRING_VAR shift, and go to state 20

svv go to state 37


state 9

0 $accept: sstp_description . T_END

T_END shift, and go to state 38


state 10

1 sstp_description: sstp_expression_list . T_END

T_END shift, and go to state 39


state 11

2 sstp_expression_list: sstp_expression .
3 | sstp_expression . sstp_expression_list

T_ADDLIGHT shift, and go to state 1
T_OBJPOSITION shift, and go to state 2
T_OBJLOOKAT shift, and go to state 3
T_OBJCOLOR shift, and go to state 4
T_CLEARCOLOR shift, and go to state 5
T_SHOWGIZMO shift, and go to state 6
T_SHOWLIGHT shift, and go to state 7
T_CUSTOMCMD shift, and go to state 8

$default reduce using rule 2 (sstp_expression_list)

sstp_expression_list go to state 40
sstp_expression go to state 11
sstp_command_list go to state 12
sstp_command go to state 13
light_command go to state 14
setup_command go to state 15
scene_command go to state 16
custom_command go to state 17


state 12

4 sstp_expression: sstp_command_list .
6 sstp_command_list: sstp_command_list . sstp_command

T_ADDLIGHT shift, and go to state 1
T_OBJPOSITION shift, and go to state 2
T_OBJLOOKAT shift, and go to state 3
T_OBJCOLOR shift, and go to state 4
T_CLEARCOLOR shift, and go to state 5
T_SHOWGIZMO shift, and go to state 6
T_SHOWLIGHT shift, and go to state 7
T_CUSTOMCMD shift, and go to state 8

T_ADDLIGHT [reduce using rule 4 (sstp_expression)]
T_OBJPOSITION [reduce using rule 4 (sstp_expression)]
T_OBJLOOKAT [reduce using rule 4 (sstp_expression)]
T_OBJCOLOR [reduce using rule 4 (sstp_expression)]
T_CLEARCOLOR [reduce using rule 4 (sstp_expression)]
T_SHOWGIZMO [reduce using rule 4 (sstp_expression)]
T_SHOWLIGHT [reduce using rule 4 (sstp_expression)]
T_CUSTOMCMD [reduce using rule 4 (sstp_expression)]
$default reduce using rule 4 (sstp_expression)

sstp_command go to state 41
light_command go to state 14
setup_command go to state 15
scene_command go to state 16
custom_command go to state 17


state 13

5 sstp_command_list: sstp_command .

$default reduce using rule 5 (sstp_command_list)


state 14

7 sstp_command: light_command .

$default reduce using rule 7 (sstp_command)


state 15

8 sstp_command: setup_command .

$default reduce using rule 8 (sstp_command)


state 16

9 sstp_command: scene_command .

$default reduce using rule 9 (sstp_command)


state 17

10 sstp_command: custom_command .

$default reduce using rule 10 (sstp_command)


state 18

24 fv: F_NUMBER .

$default reduce using rule 24 (fv)


state 19

26 fv: I_NUMBER .

$default reduce using rule 26 (fv)


state 20

39 svv: STRING_VAR .

$default reduce using rule 39 (svv)


state 21

25 fv: '-' . fv
27 | '-' . iv

F_NUMBER shift, and go to state 42
I_NUMBER shift, and go to state 43
'-' shift, and go to state 44

fv go to state 45
iv go to state 46


state 22

12 light_command: T_ADDLIGHT fv .

$default reduce using rule 12 (light_command)


state 23

13 light_command: T_ADDLIGHT svv .

$default reduce using rule 13 (light_command)


state 24

32 v3: '(' . fv ')'
33 | '(' . fv fv fv ')'

F_NUMBER shift, and go to state 18
I_NUMBER shift, and go to state 19
'-' shift, and go to state 21

fv go to state 47


state 25

14 setup_command: T_OBJPOSITION v3 .

$default reduce using rule 14 (setup_command)


state 26

15 setup_command: T_OBJLOOKAT v3 .

$default reduce using rule 15 (setup_command)


state 27

17 setup_command: T_OBJCOLOR COLOR .

$default reduce using rule 17 (setup_command)


state 28

34 v4: '(' . fv ')'
35 | '(' . fv fv fv fv ')'

F_NUMBER shift, and go to state 18
I_NUMBER shift, and go to state 19
'-' shift, and go to state 21

fv go to state 48


state 29

16 setup_command: T_OBJCOLOR v4 .

$default reduce using rule 16 (setup_command)


state 30

20 scene_command: T_CLEARCOLOR COLOR .

$default reduce using rule 20 (scene_command)


state 31

19 scene_command: T_CLEARCOLOR v4 . $@1 T_CLEARCOLOR v3

$default reduce using rule 18 ($@1)

$@1 go to state 49


state 32

38 bv: F_NUMBER .

$default reduce using rule 38 (bv)


state 33

37 bv: I_NUMBER .

$default reduce using rule 37 (bv)


state 34

36 bv: BOOLEAN .

$default reduce using rule 36 (bv)


state 35

21 scene_command: T_SHOWGIZMO bv .

$default reduce using rule 21 (scene_command)


state 36

22 scene_command: T_SHOWLIGHT bv .

$default reduce using rule 22 (scene_command)


state 37

23 custom_command: T_CUSTOMCMD svv . sv

STRING shift, and go to state 50

sv go to state 51


state 38

0 $accept: sstp_description T_END .

$default accept


state 39

1 sstp_description: sstp_expression_list T_END .

$default reduce using rule 1 (sstp_description)


state 40

3 sstp_expression_list: sstp_expression sstp_expression_list .

$default reduce using rule 3 (sstp_expression_list)


state 41

6 sstp_command_list: sstp_command_list sstp_command .

$default reduce using rule 6 (sstp_command_list)


state 42

24 fv: F_NUMBER .
30 iv: F_NUMBER .

T_END reduce using rule 24 (fv)
T_END [reduce using rule 30 (iv)]
T_ADDLIGHT reduce using rule 24 (fv)
T_ADDLIGHT [reduce using rule 30 (iv)]
T_OBJPOSITION reduce using rule 24 (fv)
T_OBJPOSITION [reduce using rule 30 (iv)]
T_OBJLOOKAT reduce using rule 24 (fv)
T_OBJLOOKAT [reduce using rule 30 (iv)]
T_OBJCOLOR reduce using rule 24 (fv)
T_OBJCOLOR [reduce using rule 30 (iv)]
T_CLEARCOLOR reduce using rule 24 (fv)
T_CLEARCOLOR [reduce using rule 30 (iv)]
T_SHOWGIZMO reduce using rule 24 (fv)
T_SHOWGIZMO [reduce using rule 30 (iv)]
T_SHOWLIGHT reduce using rule 24 (fv)
T_SHOWLIGHT [reduce using rule 30 (iv)]
T_CUSTOMCMD reduce using rule 24 (fv)
T_CUSTOMCMD [reduce using rule 30 (iv)]
F_NUMBER reduce using rule 24 (fv)
F_NUMBER [reduce using rule 30 (iv)]
I_NUMBER reduce using rule 24 (fv)
I_NUMBER [reduce using rule 30 (iv)]
'-' reduce using rule 24 (fv)
'-' [reduce using rule 30 (iv)]
')' reduce using rule 24 (fv)
')' [reduce using rule 30 (iv)]
$default reduce using rule 24 (fv)


state 43

26 fv: I_NUMBER .
28 iv: I_NUMBER .

T_END reduce using rule 26 (fv)
T_END [reduce using rule 28 (iv)]
T_ADDLIGHT reduce using rule 26 (fv)
T_ADDLIGHT [reduce using rule 28 (iv)]
T_OBJPOSITION reduce using rule 26 (fv)
T_OBJPOSITION [reduce using rule 28 (iv)]
T_OBJLOOKAT reduce using rule 26 (fv)
T_OBJLOOKAT [reduce using rule 28 (iv)]
T_OBJCOLOR reduce using rule 26 (fv)
T_OBJCOLOR [reduce using rule 28 (iv)]
T_CLEARCOLOR reduce using rule 26 (fv)
T_CLEARCOLOR [reduce using rule 28 (iv)]
T_SHOWGIZMO reduce using rule 26 (fv)
T_SHOWGIZMO [reduce using rule 28 (iv)]
T_SHOWLIGHT reduce using rule 26 (fv)
T_SHOWLIGHT [reduce using rule 28 (iv)]
T_CUSTOMCMD reduce using rule 26 (fv)
T_CUSTOMCMD [reduce using rule 28 (iv)]
F_NUMBER reduce using rule 26 (fv)
F_NUMBER [reduce using rule 28 (iv)]
I_NUMBER reduce using rule 26 (fv)
I_NUMBER [reduce using rule 28 (iv)]
'-' reduce using rule 26 (fv)
'-' [reduce using rule 28 (iv)]
')' reduce using rule 26 (fv)
')' [reduce using rule 28 (iv)]
$default reduce using rule 26 (fv)


state 44

25 fv: '-' . fv
27 | '-' . iv
29 iv: '-' . iv
31 | '-' . fv

F_NUMBER shift, and go to state 42
I_NUMBER shift, and go to state 43
'-' shift, and go to state 44

fv go to state 52
iv go to state 53


state 45

25 fv: '-' fv .

$default reduce using rule 25 (fv)


state 46

27 fv: '-' iv .

$default reduce using rule 27 (fv)


state 47

32 v3: '(' fv . ')'
33 | '(' fv . fv fv ')'

F_NUMBER shift, and go to state 18
I_NUMBER shift, and go to state 19
'-' shift, and go to state 21
')' shift, and go to state 54

fv go to state 55


state 48

34 v4: '(' fv . ')'
35 | '(' fv . fv fv fv ')'

F_NUMBER shift, and go to state 18
I_NUMBER shift, and go to state 19
'-' shift, and go to state 21
')' shift, and go to state 56

fv go to state 57


state 49

19 scene_command: T_CLEARCOLOR v4 $@1 . T_CLEARCOLOR v3

T_CLEARCOLOR shift, and go to state 58


state 50

40 sv: STRING .
41 | STRING . sv

STRING shift, and go to state 50

$default reduce using rule 40 (sv)

sv go to state 59


state 51

23 custom_command: T_CUSTOMCMD svv sv .

$default reduce using rule 23 (custom_command)


state 52

25 fv: '-' fv .
31 iv: '-' fv .

T_END reduce using rule 25 (fv)
T_END [reduce using rule 31 (iv)]
T_ADDLIGHT reduce using rule 25 (fv)
T_ADDLIGHT [reduce using rule 31 (iv)]
T_OBJPOSITION reduce using rule 25 (fv)
T_OBJPOSITION [reduce using rule 31 (iv)]
T_OBJLOOKAT reduce using rule 25 (fv)
T_OBJLOOKAT [reduce using rule 31 (iv)]
T_OBJCOLOR reduce using rule 25 (fv)
T_OBJCOLOR [reduce using rule 31 (iv)]
T_CLEARCOLOR reduce using rule 25 (fv)
T_CLEARCOLOR [reduce using rule 31 (iv)]
T_SHOWGIZMO reduce using rule 25 (fv)
T_SHOWGIZMO [reduce using rule 31 (iv)]
T_SHOWLIGHT reduce using rule 25 (fv)
T_SHOWLIGHT [reduce using rule 31 (iv)]
T_CUSTOMCMD reduce using rule 25 (fv)
T_CUSTOMCMD [reduce using rule 31 (iv)]
F_NUMBER reduce using rule 25 (fv)
F_NUMBER [reduce using rule 31 (iv)]
I_NUMBER reduce using rule 25 (fv)
I_NUMBER [reduce using rule 31 (iv)]
'-' reduce using rule 25 (fv)
'-' [reduce using rule 31 (iv)]
')' reduce using rule 25 (fv)
')' [reduce using rule 31 (iv)]
$default reduce using rule 25 (fv)


state 53

27 fv: '-' iv .
29 iv: '-' iv .

T_END reduce using rule 27 (fv)
T_END [reduce using rule 29 (iv)]
T_ADDLIGHT reduce using rule 27 (fv)
T_ADDLIGHT [reduce using rule 29 (iv)]
T_OBJPOSITION reduce using rule 27 (fv)
T_OBJPOSITION [reduce using rule 29 (iv)]
T_OBJLOOKAT reduce using rule 27 (fv)
T_OBJLOOKAT [reduce using rule 29 (iv)]
T_OBJCOLOR reduce using rule 27 (fv)
T_OBJCOLOR [reduce using rule 29 (iv)]
T_CLEARCOLOR reduce using rule 27 (fv)
T_CLEARCOLOR [reduce using rule 29 (iv)]
T_SHOWGIZMO reduce using rule 27 (fv)
T_SHOWGIZMO [reduce using rule 29 (iv)]
T_SHOWLIGHT reduce using rule 27 (fv)
T_SHOWLIGHT [reduce using rule 29 (iv)]
T_CUSTOMCMD reduce using rule 27 (fv)
T_CUSTOMCMD [reduce using rule 29 (iv)]
F_NUMBER reduce using rule 27 (fv)
F_NUMBER [reduce using rule 29 (iv)]
I_NUMBER reduce using rule 27 (fv)
I_NUMBER [reduce using rule 29 (iv)]
'-' reduce using rule 27 (fv)
'-' [reduce using rule 29 (iv)]
')' reduce using rule 27 (fv)
')' [reduce using rule 29 (iv)]
$default reduce using rule 27 (fv)


state 54

32 v3: '(' fv ')' .

$default reduce using rule 32 (v3)


state 55

33 v3: '(' fv fv . fv ')'

F_NUMBER shift, and go to state 18
I_NUMBER shift, and go to state 19
'-' shift, and go to state 21

fv go to state 60


state 56

34 v4: '(' fv ')' .

$default reduce using rule 34 (v4)


state 57

35 v4: '(' fv fv . fv fv ')'

F_NUMBER shift, and go to state 18
I_NUMBER shift, and go to state 19
'-' shift, and go to state 21

fv go to state 61


state 58

19 scene_command: T_CLEARCOLOR v4 $@1 T_CLEARCOLOR . v3

'(' shift, and go to state 24

v3 go to state 62


state 59

41 sv: STRING sv .

$default reduce using rule 41 (sv)


state 60

33 v3: '(' fv fv fv . ')'

')' shift, and go to state 63


state 61

35 v4: '(' fv fv fv . fv ')'

F_NUMBER shift, and go to state 18
I_NUMBER shift, and go to state 19
'-' shift, and go to state 21

fv go to state 64


state 62

19 scene_command: T_CLEARCOLOR v4 $@1 T_CLEARCOLOR v3 .

$default reduce using rule 19 (scene_command)


state 63

33 v3: '(' fv fv fv ')' .

$default reduce using rule 33 (v3)


state 64

35 v4: '(' fv fv fv fv . ')'

')' shift, and go to state 65


state 65

35 v4: '(' fv fv fv fv ')' .

$default reduce using rule 35 (v4)

+ 0
- 1821
doc/samples/generated/scenesetup-scanner.cpp
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 0
- 135
doc/samples/generated/stack.hh Прегледај датотеку

@@ -1,135 +0,0 @@
/* A Bison parser, made by GNU Bison 2.4.2. */

/* Stack handling for Bison parsers in C++
Copyright (C) 2002-2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */

/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */

#ifndef BISON_STACK_HH
# define BISON_STACK_HH

#include <deque>


namespace lol {

/* Line 1066 of lalr1.cc */
#line 43 "generated/stack.hh"
template <class T, class S = std::deque<T> >
class stack
{
public:

// Hide our reversed order.
typedef typename S::reverse_iterator iterator;
typedef typename S::const_reverse_iterator const_iterator;

stack () : seq_ ()
{
}

stack (unsigned int n) : seq_ (n)
{
}

inline
T&
operator [] (unsigned int i)
{
return seq_[i];
}

inline
const T&
operator [] (unsigned int i) const
{
return seq_[i];
}

inline
void
push (const T& t)
{
seq_.push_front (t);
}

inline
void
pop (unsigned int n = 1)
{
for (; n; --n)
seq_.pop_front ();
}

inline
unsigned int
height () const
{
return seq_.size ();
}

inline const_iterator begin () const { return seq_.rbegin (); }
inline const_iterator end () const { return seq_.rend (); }

private:

S seq_;
};

/// Present a slice of the top of a stack.
template <class T, class S = stack<T> >
class slice
{
public:

slice (const S& stack,
unsigned int range) : stack_ (stack),
range_ (range)
{
}

inline
const T&
operator [] (unsigned int i) const
{
return stack_[range_ - i];
}

private:

const S& stack_;
unsigned int range_;
};

} // lol

/* Line 1152 of lalr1.cc */
#line 133 "generated/stack.hh"

#endif // not BISON_STACK_HH[]dnl


+ 8
- 1
doc/samples/meshviewer.cpp Прегледај датотеку

@@ -183,6 +183,9 @@ public:
m_camera = nullptr;
m_controller = nullptr;

//Scene setup
m_setup_loader.ExecLua("meshviewer_init.lua");

//Compile ref meshes
m_gizmos << new EasyMesh();
m_gizmos.Last()->Compile("[sc#0f0 ac 3 .5 .4 0 ty .25 [ad 3 .4 sy -1] ty .5 ac 3 1 .075 ty .5 dup[rz 90 ry 90 scv#00f dup[ry 90 scv#f00]]][sc#fff ab .1]");
@@ -331,9 +334,12 @@ public:
m_meshes.Push(em, nullptr);
}
#else
//TOUKY CHANGE THAT
/*
m_ssetup->Compile("addlight 0.0 position (4 -1 -4) color (.0 .2 .5 1) "
"addlight 0.0 position (8 2 6) color #ffff "
"showgizmo true ");
*/
m_ssetup->Startup();
#endif //NO_SC_SETUP
for (int i = 0; i < m_ssetup->m_lights.Count(); ++i)
@@ -577,7 +583,7 @@ public:
while (o-- > 0)
{
SceneSetup* new_ssetup = new SceneSetup();
if (new_ssetup->Compile(mesh.C()) && new_ssetup->m_lights.Count())
if (false) //new_ssetup->Compile(mesh.C()) && new_ssetup->m_lights.Count())
{
//Store current light datas, in World
array<LightData> light_datas;
@@ -889,6 +895,7 @@ public:

private:
SceneSetup* m_ssetup;
SceneSetupLuaLoader m_setup_loader;
array<LightData> m_light_datas;
Controller* m_controller;
short m_input_usage;


+ 116
- 125
doc/samples/meshviewer.vcxproj Прегледај датотеку

@@ -1,125 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ORBIS">
<Configuration>Debug</Configuration>
<Platform>ORBIS</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Xbox 360">
<Configuration>Debug</Configuration>
<Platform>Xbox 360</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ORBIS">
<Configuration>Release</Configuration>
<Platform>ORBIS</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Xbox 360">
<Configuration>Release</Configuration>
<Platform>Xbox 360</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="generated\scenesetup-parser.cpp" />
<ClCompile Include="generated\scenesetup-scanner.cpp" />
<ClCompile Include="meshviewer.cpp" />
<ClCompile Include="scenesetup-compiler.cpp" />
<ClCompile Include="scenesetup.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\..\src\lolcore.vcxproj">
<Project>{9e62f2fe-3408-4eae-8238-fd84238ceeda}</Project>
</ProjectReference>
<ProjectReference Include="$(SolutionDir)\..\src\bullet\lolbullet.vcxproj">
<Project>{83d3b207-c601-4025-8f41-01dedc354661}</Project>
</ProjectReference>
<ProjectReference Include="$(SolutionDir)\..\src\lua\lollua.vcxproj">
<Project>{d84021ca-b233-4e0f-8a52-071b83bbccc4}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="data\mesh-buffer.txt">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</None>
<None Include="generated\location.hh" />
<None Include="generated\position.hh" />
<None Include="generated\scenesetup-parser.output" />
<None Include="generated\stack.hh" />
<None Include="meshviewer.index.html">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="meshviewer.nacl.html">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="meshviewer.em.html">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="meshviewer.nacl.nmf">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="scenesetup-parser.y" />
<None Include="scenesetup-scanner.l" />
<None Include="easymeshdictionnary.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="scenesetupdictionnary.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="javascript/naclloading.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="javascript/progressstatus.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="javascript/utils.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="javascript/typedictionnary.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
</ItemGroup>
<ItemGroup>
<LolFxCompile Include="shinyfur.lolfx" />
<LolFxCompile Include="shinymvtexture.lolfx" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="generated\scenesetup-parser.h" />
<ClInclude Include="scenesetup-compiler.h" />
<ClInclude Include="scenesetup.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E}</ProjectGuid>
<ConfigurationType>Application</ConfigurationType>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(SolutionDir)\msbuild\lol.config.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(SolutionDir)\msbuild\lolfx.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)\msbuild\lol.vars.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<Import Project="$(SolutionDir)\msbuild\lol.rules.props" />
<ItemDefinitionGroup />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(SolutionDir)\msbuild\lolfx.targets" />
</ImportGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ORBIS">
<Configuration>Debug</Configuration>
<Platform>ORBIS</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Xbox 360">
<Configuration>Debug</Configuration>
<Platform>Xbox 360</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ORBIS">
<Configuration>Release</Configuration>
<Platform>ORBIS</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Xbox 360">
<Configuration>Release</Configuration>
<Platform>Xbox 360</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="meshviewer.cpp" />
<ClCompile Include="scenesetup.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\..\src\lolcore.vcxproj">
<Project>{9e62f2fe-3408-4eae-8238-fd84238ceeda}</Project>
</ProjectReference>
<ProjectReference Include="$(SolutionDir)\..\src\bullet\lolbullet.vcxproj">
<Project>{83d3b207-c601-4025-8f41-01dedc354661}</Project>
</ProjectReference>
<ProjectReference Include="$(SolutionDir)\..\src\lua\lollua.vcxproj">
<Project>{d84021ca-b233-4e0f-8a52-071b83bbccc4}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="data\mesh-buffer.txt">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</None>
<None Include="meshviewer.index.html">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="meshviewer.nacl.html">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="meshviewer.em.html">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="meshviewer.nacl.nmf">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="easymeshdictionnary.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="meshviewer_buffer.lua" />
<None Include="meshviewer_init.lua" />
<None Include="scenesetupdictionnary.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="javascript/naclloading.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="javascript/progressstatus.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="javascript/utils.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="javascript/typedictionnary.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
</ItemGroup>
<ItemGroup>
<LolFxCompile Include="shinyfur.lolfx" />
<LolFxCompile Include="shinymvtexture.lolfx" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="scenesetup.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E}</ProjectGuid>
<ConfigurationType>Application</ConfigurationType>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(SolutionDir)\msbuild\lol.config.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(SolutionDir)\msbuild\lolfx.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)\msbuild\lol.vars.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<Import Project="$(SolutionDir)\msbuild\lol.rules.props" />
<ItemDefinitionGroup />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(SolutionDir)\msbuild\lolfx.targets" />
</ImportGroup>
</Project>

+ 19
- 0
doc/samples/meshviewer_init.lua Прегледај датотеку

@@ -0,0 +1,19 @@
s0 = SceneSetup.New("DefaultSetup")

s0:AddLight("Point")
s0:Position(0, 0, 15)
s0:Color("#bbb")
s0:AddLight("Directional")
s0:Position(0, 0, 15)
s0:Color("#bbb")
--addlight 1 position (3 10 0) color #444

s0:Setup()
s0:Color("#ddd")
s0:Show("Gizmo")
s0:Show("Light")

--SCENE SETUP END

--addlight 0.0 position (1 0 1) color #0ff
--addlight 0.0 position (-0.2 -1 -0.5) color (.0 .2 .5 1)

+ 0
- 55
doc/samples/scenesetup-compiler.cpp Прегледај датотеку

@@ -1,55 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include <string>

#include <lol/engine.h>
#include "scenesetup.h"
#include "scenesetup-compiler.h"

namespace lol
{

SceneSetupCompiler::SceneSetupCompiler(SceneSetup &uro)
: m_sstp(uro), m_last_cmd("")
{
}

bool SceneSetupCompiler::ParseString(char const *command)
{
SceneSetupScanner scanner(command);
m_lexer = &scanner;
SceneSetupParser parser(*this);
if (parser.parse() != 0)
{
Log::Debug("Uro source: %s\n", command);
return false;
}
return true;
}

void SceneSetupCompiler::Error(const class location& l, const std::string& m)
{
Log::Error("SceneSetup syntax error line %d column %d: %s\n",
l.begin.line, l.begin.column, m.c_str());
}

void SceneSetupCompiler::Error(const std::string& m)
{
Log::Error("SceneSetup syntax error: %s\n", m.c_str());
}

} /* namespace lol */


+ 0
- 60
doc/samples/scenesetup-compiler.h Прегледај датотеку

@@ -1,60 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

#pragma once

#include <string>

#ifndef __FLEX_LEXER_H
# define yyFlexLexer SceneSetupFlexLexer
# include "FlexLexer.h"
# undef yyFlexLexer
#endif

#include "generated/scenesetup-parser.h"

class SceneSetup;

namespace lol
{

//----
class SceneSetupScanner : public SceneSetupFlexLexer
{
public:
SceneSetupScanner(char const *command);
virtual ~SceneSetupScanner();
virtual int LexerInput(char* buf, int max_size);
virtual SceneSetupParser::token_type lex(SceneSetupParser::semantic_type* yylval,
SceneSetupParser::location_type* yylloc);

private:
char const *m_input;
};

//----
class SceneSetupCompiler
{
public:
SceneSetupCompiler(class SceneSetup &uro);

bool ParseString(char const *command);

void Error(const class location& l, const std::string& m);
void Error(const std::string& m);

class SceneSetupScanner* m_lexer;
class SceneSetup& m_sstp;
String m_last_cmd;
};

} /* namespace lol */


+ 0
- 213
doc/samples/scenesetup-parser.y Прегледај датотеку

@@ -1,213 +0,0 @@
%{
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include "core.h"
#include "../scenesetup.h"

%}

%require "2.3"
%debug
%defines
%skeleton "lalr1.cc"
%name-prefix="lol"
%define parser_class_name "SceneSetupParser"
%locations
%parse-param { class SceneSetupCompiler& uc }
%error-verbose

%union
{
float fval;
int ival;
bool bval;
float vval[4];
int ivval[4];
char* sval;
char* svval;
/* Can't use uin32_t here for some reason */
unsigned u32val;
}

%start sstp_description

%token T_COLOR

%token T_ADDLIGHT T_OBJPOSITION T_OBJLOOKAT T_OBJCOLOR T_CLEARCOLOR
%token T_SHOWGIZMO T_SHOWLIGHT
%token T_CUSTOMCMD

%token T_END 0
%token T_ERROR

%token <fval> F_NUMBER
%token <ival> I_NUMBER
%token <sval> STRING
%token <svval> STRING_VAR
%token <bval> BOOLEAN
%token <u32val> COLOR

/* Base Number types */
%type <fval> fv
%type <ival> iv
/* Vector types */
%type <vval> v3
%type <ivval> iv3
%type <vval> v4
/* Special types */
%type <bval> bv
%type <sval> sv
%type <svval> svv


%{
#include "../scenesetup-compiler.h"

#undef yylex
#define yylex uc.m_lexer->lex

/* HACK: workaround for Bison who insists on using exceptions */
#define try if (true)
#define catch(...) if (false)
#define throw (void)0
%}

%%

sstp_description:
sstp_expression_list T_END
;

sstp_expression_list:
sstp_expression
| sstp_expression sstp_expression_list
;

sstp_expression:
sstp_command_list
;

sstp_command_list:
sstp_command
| sstp_command_list sstp_command
;

sstp_command:
light_command
| setup_command
| scene_command
| custom_command
;

light_command:
T_ADDLIGHT { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; }
| T_ADDLIGHT fv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
uc.m_sstp.m_lights.Last()->SetType(LightType($2)); }
| T_ADDLIGHT svv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
uc.m_sstp.m_lights.Last()->SetType(FindValue<LightType>($2)); }
;

setup_command:
T_OBJPOSITION v3 { if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetPosition(vec3($2[0], $2[1], $2[2])); }
| T_OBJLOOKAT v3 { if (uc.m_last_cmd == "ADDLIGHT")
{ /* */ } }
| T_OBJCOLOR v4 { if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetColor(vec4($2[0], $2[1], $2[2], $2[3])); }
| T_OBJCOLOR COLOR { uint32_t x = $2;
ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff);
vec4 vv = vec4(v) * (1.f / 255.f);
if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetColor(vv); }
;

scene_command:
T_CLEARCOLOR v4 { uc.m_sstp.m_clear_color = vec4($2[0], $2[1], $2[2], $2[3]); }
T_CLEARCOLOR v3 { uc.m_sstp.m_clear_color = vec4($2[0], $2[1], $2[2], 1.f); }
| T_CLEARCOLOR COLOR { uint32_t x = $2; ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff);
uc.m_sstp.m_clear_color = vec4(v) * (1.f / 255.f); }
| T_SHOWGIZMO bv { uc.m_sstp.m_show_gizmo = $2; }
| T_SHOWLIGHT bv { uc.m_sstp.m_show_lights = $2; }
;

custom_command:
T_CUSTOMCMD svv sv { uc.m_sstp.m_custom_cmd.Push($2, $3); }
;


/* Base Number types */
fv:
F_NUMBER { $$ = $1; }
| '-' fv { $$ = -$2; }
| I_NUMBER { $$ = (float)$1; }
| '-' iv { $$ = -(float)$2; }
;

iv:
I_NUMBER { $$ = $1; }
| '-' iv { $$ = -$2; }
| F_NUMBER { $$ = (int)$1; }
| '-' fv { $$ = -(int)$2; }
;

/* Vector types */
v3:
'('fv')' { $$[0] = $2; $$[1] = $2; $$[2] = $2; }
| '('fv fv fv')' { $$[0] = $2; $$[1] = $3; $$[2] = $4; }
;

iv3:
'('iv')' { $$[0] = $2; $$[1] = $2; $$[2] = $2; }
| '('iv iv iv')' { $$[0] = $2; $$[1] = $3; $$[2] = $4; }
;

v4:
'('fv')' { $$[0] = $2; $$[1] = $2; $$[2] = $2; $$[3] = $2; }
| '('fv fv fv fv')' { $$[0] = $2; $$[1] = $3; $$[2] = $4; $$[3] = $5; }
;

/* Special types */
bv:
BOOLEAN { $$ = $1; }
| I_NUMBER { $$ = !!$1; }
| F_NUMBER { $$ = !!$1; }
;

svv:
STRING_VAR { $$ = $1; }
;

sv:
STRING { String t = $1;
t.Replace('"', ' ', true);
free($1);
$$ = strdup((const char *)t.C()); }
| STRING sv { String t = $1;
t += $2;
t.Replace('"', ' ', true);
free($1);
free($2);
$$ = strdup((const char *)t.C()); }
;

%%

void lol::SceneSetupParser::error(const SceneSetupParser::location_type& l,
const std::string& m)
{
uc.Error(l, m);
}


+ 0
- 149
doc/samples/scenesetup-scanner.l Прегледај датотеку

@@ -1,149 +0,0 @@
%{
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstdlib>
using std::exit;
using std::malloc;
using std::realloc;
using std::free;

#include "core.h"
#include "../scenesetup.h"
#include "../scenesetup-compiler.h"

typedef lol::SceneSetupParser::token token;
typedef lol::SceneSetupParser::token_type token_type;

#ifndef YY_DECL
# define YY_DECL lol::SceneSetupParser::token_type \
lol::SceneSetupScanner::lex(lol::SceneSetupParser::semantic_type* yylval, \
lol::SceneSetupParser::location_type* yylloc)
#endif

#define yyterminate() return token::T_END
#define YY_NO_UNISTD_H
#define YY_USER_ACTION yylloc->columns(yyleng);
%}

%option c++ prefix="SceneSetup"
%option batch yywrap nounput stack

%%

%{ /* reset location at the beginning of yylex() */
yylloc->step();
%}

addlight { return token::T_ADDLIGHT; }
position { return token::T_OBJPOSITION; }
lookat { return token::T_OBJLOOKAT; }
color { return token::T_OBJCOLOR; }
clearcolor { return token::T_CLEARCOLOR; }

showgizmo { return token::T_SHOWGIZMO; }
showlight { return token::T_SHOWLIGHT; }
custom { return token::T_CUSTOMCMD; }

custom { return token::T_CUSTOMCMD; }

%{ /* ======= BASE COLOR TYPES ========================================= */ %}
%{ /* COLOR */ %}
#[0-9a-fA-F]{3} {
uint32_t tmp = std::strtol(yytext + 1, nullptr, 16);
yylval->u32val = 0x11000000u * (tmp >> 8)
| 0x00110000u * ((tmp >> 4) & 0xf)
| 0x00001100u * (tmp & 0xf)
| 0x000000ffu;
return token::COLOR; }
#[0-9a-fA-F]{4} {
uint32_t tmp = std::strtol(yytext + 1, nullptr, 16);
yylval->u32val = 0x11000000u * (tmp >> 12)
| 0x00110000u * ((tmp >> 8) & 0xf)
| 0x00001100u * ((tmp >> 4) & 0xf)
| 0x00000011u * (tmp & 0xf);
return token::COLOR; }
#[0-9a-fA-F]{6} {
yylval->u32val = 0xffu
| 0x100u * (uint32_t)std::strtol(yytext + 1, nullptr, 16);
return token::COLOR; }
#[0-9a-fA-F]{8} {
yylval->u32val = (uint32_t)std::strtol(yytext + 1, nullptr, 16);
return token::COLOR; }

%{ /* ======= BASE DATA TYPES ========================================= */ %}
%{ /* BOOL */ %}
true { yylval->bval = true; return token::BOOLEAN; }
false { yylval->bval = false; return token::BOOLEAN; }
%{ /* FLOAT */ %}
[-+]?[0-9]*\.[0-9]+([eE][-+]?[0-9]+)? {
yylval->fval = (float)std::atof(yytext); return token::F_NUMBER; }
%{ /* INT */ %}
[-+]?[0-9]+ {
yylval->ival = std::atoi(yytext); return token::I_NUMBER; }
%{ /* STRING */ %}
[\"][^\"]*[\"] {
yylval->sval = strdup(yytext); return token::STRING; }
%{ /* STRING VAR */ %}
[a-zA-Z][a-zA-Z_\-]+ {
yylval->svval = strdup(yytext); return token::STRING_VAR; }

%{ /* ======= COMMENTS ======= */ %}
"//".* { /* ignore this */ }

%{ /* Semantics tokens */ %}
"-" { return token_type('-'); }
"(" { return token_type('('); }
")" { return token_type(')'); }
[ ,] { /* ignore this */ }
[\n] { /* ignore this */ }
. { return token::T_ERROR; }

%%

lol::SceneSetupScanner::SceneSetupScanner(char const *command)
: SceneSetupFlexLexer(0, 0),
m_input(command)
{
}

lol::SceneSetupScanner::~SceneSetupScanner()
{
}

int lol::SceneSetupScanner::LexerInput(char* buf, int max_size)
{
(void)max_size; /* unused for now */

buf[0] = m_input[0];
if (buf[0])
++m_input;
return buf[0] ? 1 : 0;
}

#ifdef yylex
#undef yylex
#endif
int SceneSetupFlexLexer::yylex()
{
std::cerr << "in SceneSetupFlexLexer::yylex() !" << std::endl;
return 0;
}

int SceneSetupFlexLexer::yywrap()
{
return 1;
}


+ 232
- 9
doc/samples/scenesetup.cpp Прегледај датотеку

@@ -15,15 +15,15 @@

#include <lol/engine.h>
#include "scenesetup.h"
#include "scenesetup-compiler.h"

namespace lol
{

//-----------------------------------------------------------------------------
//CTor/DTor
SceneSetup::SceneSetup()
SceneSetup::SceneSetup(String const& name)
{
m_name = name;
m_clear_color = vec4(vec3::zero, 1.f);
m_show_gizmo = true;
m_show_lights = true;
@@ -35,13 +35,6 @@ SceneSetup::~SceneSetup()
Shutdown(true);
}

//-----------------------------------------------------------------------------
bool SceneSetup::Compile(char const *command)
{
SceneSetupCompiler mc(*this);
return mc.ParseString(command);
}

//-----------------------------------------------------------------------------
bool SceneSetup::Startup()
{
@@ -62,4 +55,234 @@ bool SceneSetup::Shutdown(bool destroy)
return true;
}

//-----------------------------------------------------------------------------
void SceneSetup::AddLight(LightType type)
{
m_last_cmd = SceneSetup::Command::AddLight;
m_lights << new Light();
m_lights.Last()->SetType(type);
}

//-----------------------------------------------------------------------------
void SceneSetup::SetupScene()
{
m_last_cmd = SceneSetup::Command::SetupScene;
}

//-----------------------------------------------------------------------------
void SceneSetup::SetPosition(vec3 const& v)
{
switch (m_last_cmd.ToScalar())
{
case SceneSetup::Command::AddLight:
m_lights.Last()->SetPosition(v);
break;
}
}

//-----------------------------------------------------------------------------
void SceneSetup::SetLookAt(vec3 const& v)
{
switch (m_last_cmd.ToScalar())
{
case SceneSetup::Command::AddLight:
//TODO: Do better
m_lights.Last()->SetPosition(v - m_lights.Last()->GetPosition());
break;
}
}

//-----------------------------------------------------------------------------
void SceneSetup::SetColor(vec4 const& c)
{
switch (m_last_cmd.ToScalar())
{
case SceneSetup::Command::AddLight:
m_lights.Last()->SetColor(c);
break;
case SceneSetup::Command::SetupScene:
m_clear_color = c;
break;
}
}

//-----------------------------------------------------------------------------
void SceneSetup::Show(SceneSetup::Display const& d)
{
Set(d, DisplayFlag::On);
}

//-----------------------------------------------------------------------------
void SceneSetup::Hide(SceneSetup::Display const& d)
{
Set(d, DisplayFlag::Off);
}

//-----------------------------------------------------------------------------
void SceneSetup::Toggle(SceneSetup::Display const& d)
{
Set(d, DisplayFlag::Toggle);
}

//-----------------------------------------------------------------------------
void SceneSetup::Set(SceneSetup::Display const& d, DisplayFlag const& f)
{
bool value = f == DisplayFlag::On ? true : false;
switch (m_last_cmd.ToScalar())
{
case SceneSetup::Command::SetupScene:
switch (d.ToScalar())
{
case SceneSetup::Display::Gizmo:
m_show_gizmo = f == DisplayFlag::Toggle ? !m_show_gizmo : value;
break;
case SceneSetup::Display::Light:
m_show_lights = f == DisplayFlag::Toggle ? !m_show_lights : value;
break;
}
break;
}
}

//-----------------------------------------------------------------------------
SceneSetupLuaObject::SceneSetupLuaObject(String& name) : LuaObjectDef()
{
m_setup = new SceneSetup(name);
SceneSetupLuaLoader::RegisterSetup(m_setup);
}

//-----------------------------------------------------------------------------
SceneSetupLuaObject::~SceneSetupLuaObject()
{
}

//-----------------------------------------------------------------------------
SceneSetupLuaObject* SceneSetupLuaObject::New(LuaState* l, int arg_nb)
{
UNUSED(l);
UNUSED(arg_nb);
LuaStack s(l);
LuaString n;
s >> n;
return new SceneSetupLuaObject(n());
}

//-- Setup command ------------------------------------------------------------
int SceneSetupLuaObject::AddLight(LuaState* l)
{
LuaStack s(l);
LuaSSetupPtr o;
LuaString t;
s >> o >> t;
o->m_setup->AddLight(FindValue<LightType>(t().C()));
return 0;
}
int SceneSetupLuaObject::SetupScene(LuaState* l)
{
LuaStack s(l);
LuaSSetupPtr o;
s >> o;
o->m_setup->SetupScene();
return 0;
}
//-- main funcs ---------------------------------------------------------------
int SceneSetupLuaObject::SetPosition(LuaState* l)
{
LuaStack s(l);
LuaSSetupPtr o;
LuaVec3 c;
s >> o >> c;
o->m_setup->SetPosition(c);
return 0;
}
int SceneSetupLuaObject::SetLookAt(LuaState* l)
{
LuaStack s(l);
LuaSSetupPtr o;
LuaVec3 c;
s >> o >> c;
o->m_setup->SetLookAt(c);
return 0;
}
int SceneSetupLuaObject::SetColor(LuaState* l)
{
LuaStack s(l);
LuaSSetupPtr o;
LuaColor c;
s >> o >> c;
o->m_setup->SetColor(c);
return 0;
}
int SceneSetupLuaObject::Show(LuaState* l)
{
LuaStack s(l);
LuaSSetupPtr o;
LuaDisplay e;
s >> o >> e;
o->m_setup->Show(e);
return 0;
}
int SceneSetupLuaObject::Hide(LuaState* l)
{
LuaStack s(l);
LuaSSetupPtr o;
LuaDisplay e;
s >> o >> e;
o->m_setup->Hide(e);
return 0;
}
int SceneSetupLuaObject::Toggle(LuaState* l)
{
LuaStack s(l);
LuaSSetupPtr o;
LuaDisplay e;
s >> o >> e;
o->m_setup->Toggle(e);
return 0;
}

//-----------------------------------------------------------------------------
const LuaObjectLib* SceneSetupLuaObject::GetLib()
{
typedef SceneSetupLuaObject SSLO;
static const LuaObjectLib lib = LuaObjectLib(
"SceneSetup",
//Statics
{ { nullptr, nullptr } },
//Methods
{
//-----------------------------------------------------------------
{ "AddLight", AddLight },
{ "Setup", SetupScene },
//-- main funcs
{ "Position", SetPosition },
{ "LookAt", SetLookAt },
{ "Color", SetColor },
{ "Show", Show },
{ "Hide", Hide },
{ "Toggle", Toggle },
},
//Variables
{ { nullptr, nullptr, nullptr } });
return &lib;
}

//-----------------------------------------------------------------------------
map<String, SceneSetup*> SceneSetupLuaLoader::m_setups;
SceneSetupLuaLoader::SceneSetupLuaLoader() : LuaLoader()
{
LuaState* l = GetLuaState();

LuaObject::Register<SceneSetupLuaObject>(l);
}

//-----------------------------------------------------------------------------
SceneSetupLuaLoader::~SceneSetupLuaLoader() { }

//-----------------------------------------------------------------------------
void SceneSetupLuaLoader::RegisterSetup(SceneSetup* setup)
{
m_setups[setup->m_name] = setup;
}

} /* namespace lol */

+ 179
- 10
doc/samples/scenesetup.h Прегледај датотеку

@@ -19,31 +19,200 @@
namespace lol
{

//-----------------------------------------------------------------------------
class SceneSetup
{
friend class SceneSetupParser;
friend class SceneSetupLuaLoader;
friend class SceneSetupLuaObject;

public:
//CTor/DTor
SceneSetup();
SceneSetup() : SceneSetup("default") { }
SceneSetup(String const& name);
~SceneSetup();

static char const *GetName() { return "<scenesetup>"; }

//--
bool Compile(char const *command);

//--
bool Startup();
bool Shutdown(bool destroy=false);

//-- Setup command
void AddLight(LightType type);
void SetupScene();

//-- main funcs
void SetPosition(vec3 const& v);
void SetLookAt(vec3 const& v);
void SetColor(vec4 const& c);

//-------------------------------------------------------------------------
struct DisplayBase : public StructSafeEnum
{
enum Type
{
Gizmo,
Light,

Max
};
protected:
virtual bool BuildEnumMap(map<int64_t, String>& enum_map)
{
enum_map[Gizmo] = "Gizmo";
enum_map[Light] = "Light";
return true;
}
};
typedef SafeEnum<DisplayBase> Display;

void Show(Display const& d);
void Hide(Display const& d);
void Toggle(Display const& d);
protected:
void Set(Display const& d, DisplayFlag const& f);

protected:
//-------------------------------------------------------------------------
struct CommandBase : public StructSafeEnum
{
enum Type
{
AddLight,
SetupScene,

Max
};
protected:
virtual bool BuildEnumMap(map<int64_t, String>& enum_map)
{
enum_map[AddLight] = "AddLight";
enum_map[SetupScene] = "SetupScene";
return true;
}
};
typedef SafeEnum<CommandBase> Command;

public:
//--
vec4 m_clear_color;
array<Light *> m_lights;
array<String, String> m_custom_cmd;
bool m_show_gizmo;
bool m_show_lights;
String m_name;
Command m_last_cmd;
vec4 m_clear_color;
array<Light *> m_lights;
array<String, String> m_custom_cmd;
bool m_show_gizmo;
bool m_show_lights;
};
typedef Lolua::VarEnum<SceneSetup::DisplayBase> LuaDisplay;

//-----------------------------------------------------------------------------
class SceneSetupLuaObject : public LuaObjectDef
{
typedef Lolua::VarPtr<SceneSetupLuaObject> LuaSSetupPtr;
public:
//-------------------------------------------------------------------------
SceneSetupLuaObject(String& name);
virtual ~SceneSetupLuaObject();

//-------------------------------------------------------------------------
static SceneSetupLuaObject* New(LuaState* l, int arg_nb);
static const LuaObjectLib* GetLib();

//-------------------------------------------------------------------------
public:
//-- Setup command
static int AddLight(LuaState* l);
static int SetupScene(LuaState* l);
//-- main funcs
static int SetPosition(LuaState* l);
static int SetLookAt(LuaState* l);
static int SetColor(LuaState* l);
static int Show(LuaState* l);
static int Hide(LuaState* l);
static int Toggle(LuaState* l);

//-- Setup command
void AddLight(LightType type);
void SetupScene();

//-- main funcs
void SetPosition(vec3& v);
void SetLookAt(vec3& v);
void SetColor(vec4& c);
void Show(SceneSetup::Display const& d);
void Hide(SceneSetup::Display const& d);
void Toggle(SceneSetup::Display const& d);

private:
SceneSetup* m_setup = nullptr;
};

//-----------------------------------------------------------------------------
class SceneSetupLuaLoader : public LuaLoader
{
friend class SceneSetupLuaObject;
public:
SceneSetupLuaLoader();
virtual ~SceneSetupLuaLoader();

//-------------------------------------------------------------------------
protected:
static void RegisterSetup(SceneSetup* setup);

private:
static map<String, SceneSetup*> m_setups;
};

/*
addlight { return token::T_ADDLIGHT; }
position { return token::T_OBJPOSITION; }
lookat { return token::T_OBJLOOKAT; }
color { return token::T_OBJCOLOR; }
clearcolor { return token::T_CLEARCOLOR; }

showgizmo { return token::T_SHOWGIZMO; }
showlight { return token::T_SHOWLIGHT; }
custom { return token::T_CUSTOMCMD; }

custom { return token::T_CUSTOMCMD; }

light_command:
T_ADDLIGHT { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; }
| T_ADDLIGHT fv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
uc.m_sstp.m_lights.Last()->SetType(LightType($2)); }
| T_ADDLIGHT svv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT";
uc.m_sstp.m_lights.Last()->SetType(FindValue<LightType>($2)); }
;

setup_command:
T_OBJPOSITION v3 { if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetPosition(vec3($2[0], $2[1], $2[2])); }
| T_OBJLOOKAT v3 { if (uc.m_last_cmd == "ADDLIGHT")
{
} }
| T_OBJCOLOR v4{ if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetColor(vec4($2[0], $2[1], $2[2], $2[3])); }
| T_OBJCOLOR COLOR{ uint32_t x = $2;
ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff);
vec4 vv = vec4(v) * (1.f / 255.f);
if (uc.m_last_cmd == "ADDLIGHT")
uc.m_sstp.m_lights.Last()->SetColor(vv); }
;

scene_command:
T_CLEARCOLOR v4{ uc.m_sstp.m_clear_color = vec4($2[0], $2[1], $2[2], $2[3]); }
T_CLEARCOLOR v3{ uc.m_sstp.m_clear_color = vec4($2[0], $2[1], $2[2], 1.f); }
| T_CLEARCOLOR COLOR{ uint32_t x = $2; ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff);
uc.m_sstp.m_clear_color = vec4(v) * (1.f / 255.f); }
| T_SHOWGIZMO bv{ uc.m_sstp.m_show_gizmo = $2; }
| T_SHOWLIGHT bv{ uc.m_sstp.m_show_lights = $2; }
;

custom_command:
T_CUSTOMCMD svv sv{ uc.m_sstp.m_custom_cmd.Push($2, $3); }
;

*/

} /* namespace lol */


+ 7
- 32
src/easymesh/easymeshlua.h Прегледај датотеку

@@ -609,14 +609,8 @@ public:
{
LuaStack s(l);
EzMeshPtr m;
s >> m;
LuaVec4 c;
if (s.GetArgs() == 2 && !c.IsValid(l, 2))
{
LuaString str;
s >> str;
c = Color::C8BppHexString(str);
}
LuaColor c;
s >> m >> c;
m->m_instance.SetCurColor(c);
return 0;
}
@@ -624,14 +618,8 @@ public:
{
LuaStack s(l);
EzMeshPtr m;
s >> m;
LuaVec4 c;
if (s.GetArgs() == 1 && !c.IsValid(l, 2))
{
LuaString str;
s >> str;
c = Color::C8BppHexString(str);
}
LuaColor c;
s >> m >> c;
m->m_instance.SetCurColorA(c);
return 0;
}
@@ -639,14 +627,7 @@ public:
{
LuaStack s(l);
EzMeshPtr m;
s >> m;
LuaVec4 c;
if (s.GetArgs() == 1 && !c.IsValid(l, 2))
{
LuaString str;
s >> str;
c = Color::C8BppHexString(str);
}
LuaColor c;
m->m_instance.SetCurColorB(c);
return 0;
}
@@ -654,14 +635,8 @@ public:
{
LuaStack s(l);
EzMeshPtr m;
s >> m;
LuaVec4 c;
if (s.GetArgs() == 1 && !c.IsValid(l, 2))
{
LuaString str;
s >> str;
c = Color::C8BppHexString(str);
}
LuaColor c;
s >> m >> c;
m->m_instance.SetVertColor(c);
return 0;
}


+ 1
- 0
src/imgui/.gitignore Прегледај датотеку

@@ -0,0 +1 @@
imgui.ini

+ 17
- 0
src/imgui/.travis.yml Прегледај датотеку

@@ -0,0 +1,17 @@
language: cpp

os:
- linux

compiler:
- gcc
- clang

before_install:
- if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:pyglfw/pyglfw && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3-dev libxrandr-dev libxi-dev libxxf86vm-dev; fi
- if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install glfw3; fi

script:
- make -C examples/opengl_example
- make -C examples/opengl3_example


+ 21
- 0
src/imgui/LICENSE Прегледај датотеку

@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Omar Cornut

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

+ 137
- 0
src/imgui/README.md Прегледај датотеку

@@ -0,0 +1,137 @@
ImGui
=====
[![Build Status](https://travis-ci.org/ocornut/imgui.svg?branch=master)](https://travis-ci.org/ocornut/imgui)

[![Patreon](https://cloud.githubusercontent.com/assets/8225057/5990484/70413560-a9ab-11e4-8942-1a63607c0b00.png)](http://www.patreon.com/imgui) [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5Q73FPZ9C526U)

ImGui is a bloat-free graphical user interface library for C++. It outputs vertex buffers that you can render in your 3D-pipeline enabled application. It is portable, renderer agnostic and carries minimal amount of dependencies. It is based on an "immediate" graphical user interface paradigm which allows you to build user interfaces with ease.

ImGui is designed to enable fast iteration and allow programmers to create "content creation" or "debug" tools (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal, and thus lacks certain features normally found in more high-level libraries.

ImGui is particularly suited to integration in 3D applications, fullscreen applications, embedded applications, games, or any applications on consoles platforms where operating system features are non-standard.

ImGui is self-contained within 6 files that you can easily copy and compile into your application/engine:

- imgui.cpp
- imgui.h
- imconfig.h (empty by default, user-editable)
- stb_rect_pack.h
- stb_textedit.h
- stb_truetype.h

Your code passes mouse/keyboard inputs and settings to ImGui (see example applications for more details). After ImGui is setup, you can use it like in this example:

![screenshot of sample code alongside its output with ImGui](/web/code_sample_01.png?raw=true)

ImGui outputs vertex buffers and simple command-lists that you can render in your application. Because it doesn't know or touch graphics state directly, you can call ImGui commands anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate ImGui with your existing codebase.

ImGui allows you create elaborate tools as well as very short-lived ones. On the extreme side of short-liveness: using the Edit&Continue feature of compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, etc.

Gallery
-------

![screenshot 1](/web/test_window_01.png?raw=true)
![screenshot 2](/web/test_window_02.png?raw=true)
![screenshot 3](/web/test_window_03.png?raw=true)
![screenshot 4](/web/test_window_04.png?raw=true)
![screenshot 4](/web/examples_02.png?raw=true)

ImGui can load TTF fonts. UTF-8 is supported for text display and input. Here using Arial Unicode font to display Japanese. Initialize custom font with:
```
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
```
For Microsoft IME, pass your HWND to enable IME positioning:
```
io.ImeWindowHandle = my_hwnd;
```
![Japanese screenshot](/web/code_sample_01_jp.png?raw=true)

References
----------

The Immediate Mode GUI paradigm may at first appear unusual to some users. This is mainly because "Retained Mode" GUIs have been so widespread and predominant. The following links can give you a better understanding about how Immediate Mode GUIs works.
- [Johannes 'johno' Norneby's article](http://www.johno.se/book/imgui.html).
- [A presentation by Rickard Gustafsson and Johannes Algelind](http://www.cse.chalmers.se/edu/year/2011/course/TDA361/Advanced%20Computer%20Graphics/IMGUI.pdf).
- [Jari Komppa's tutorial on building an ImGui library](http://iki.fi/sol/imgui/).
- [Casey Muratori's original video that popularized the concept](https://mollyrocket.com/861).

Frequently Asked Question
-------------------------

<b>Where are samples?</b>

The bulk of example user code is contained within the ImGui::ShowTestWindow() function. It covers most features of ImGui so you can read the code and call the function itself to see its output. Ready-to-go example applications covering different versions of OpenGL/DirectX are provided in the examples/ folder.

<b>How do you use ImGui on a platform that may not have a mouse or keyboard?</b>

I recommend using [Synergy](http://synergy-project.org). With the uSynergy.c micro client running on your platform and connecting to your PC, you can seamlessly use your PC input devices from a video game console or a tablet. ImGui allows to increase the hit box of widgets (via the _TouchPadding_ setting) to accomodate a little for the lack of precision of touch inputs, but it is recommended you use a mouse to allow optimising for screen real-estate.

<b>I integrated ImGui in my engine and the text or lines are blurry..</b>

In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f).

<b>Can you create elaborate/serious tools with ImGui?</b>

Yes. I have written data browsers, debuggers, profilers and all sort of non-trivial tools with the library. There's no reason you cannot, and in my experience the simplicity of the API is very empowering. However note that ImGui is programmer centric and the immediate-mode GUI paradigm might requires a bit of adaptation before you can realize its full potential.

<b>Is ImGui fast?</b>

Down the fundation of its visual design, ImGui is engineered to be fairly performant both in term of CPU and GPU usage. Running elaborate code and creating elaborate UI will of course have a cost but ImGui aims to minimize it.

Mileage may vary but the following screenshot may give you a rough idea of the cost of running and rendering UI code (In the case of a trivial demo application like this one, your driver/os setup may be a bottleneck and cause higher variation or throttled framerate. Testing performance as part of a real application is recommended).

![performance screenshot](/web/performance_01_close_up.png?raw=true)

This is showing framerate for the full application loop on my 2011 iMac running Windows 7, OpenGL, AMD Radeon HD 6700M with an optimized executable. ([click here for the full-size picture](/web/performance_01.png)).
In contrast, librairies featuring higher-quality rendering and layouting techniques may have a higher resources footprint.

If you intend to display large lists of items (say, 1000+) it can be beneficial for your code to perform clipping manually - using helpers such as CalcListClipping() - in order to avoid submitting them to ImGui in the first place. Even though ImGui will discard your clipped items it still needs to calculate their size and that overhead will add up if you have thousands of items.

<b>Can you reskin the look of ImGui?</b>

You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as ImGui is designed and optimised to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface.

<b>Why using C++ (as opposed to C)?</b>

ImGui takes advantage of a few C++ features for convenience but nothing anywhere Boost-insanity/quagmire. In particular, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience but could be removed.

Shall someone wants to use ImGui from another language, it should be possible to wrap ImGui to be used from a raw C API in the future.

Donate
------

<b>Can I donate to support the development of ImGui?</b>

[![Patreon](https://cloud.githubusercontent.com/assets/8225057/5990484/70413560-a9ab-11e4-8942-1a63607c0b00.png)](http://www.patreon.com/imgui) [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5Q73FPZ9C526U)

I'm currently an independant developer and your contributions are very meaningful to me. I have setup an [**ImGui Patreon page**](http://www.patreon.com/imgui) if you want to donate and enable me to spend more time improving the library. If your company uses ImGui please consider making a contribution. One-off donations are also greatly appreciated (PayPal link above). I am also available for hire to work on or with ImGui. Thanks!

Credits
-------

Developed by [Omar Cornut](http://www.miracleworld.net) and every direct or indirect contributors to the GitHub. The early version of this library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com).

Embeds [ProggyClean.ttf](http://upperbounds.net) font by Tristan Grimmer (MIT license).

Embeds [stb_textedit.h, stb_truetype.h, stb_rectpack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain).

Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. And everybody posting feedback, questions and patches on the GitHub.

ImGui is financially supported on [**Patreon**](http://www.patreon.com/imgui).

Special supporters
- Jetha Chan
- Pastagames
- Wild Sheep Studio

And
- Dale Kim
- Michel Courtine

And other supporters; thanks!

License
-------

ImGui is licensed under the MIT License, see LICENSE for more information.

+ 28
- 0
src/imgui/examples/.gitignore Прегледај датотеку

@@ -0,0 +1,28 @@
## Visual Studio files
Debug/*
Release/*
ipch/*
x64/*
directx9_example/Debug/*
directx9_example/Release/*
directx9_example/ipch/*
directx9_example/x64/*
directx11_example/Debug/*
directx11_example/Release/*
directx11_example/ipch/*
directx11_example/x64/*
opengl_example/Debug/*
opengl_example/Release/*
opengl_example/ipch/*
opengl_example/x64/*
opengl3_example/Debug/*
opengl3_example/Release/*
opengl3_example/ipch/*
opengl3_example/x64/*
*.opensdf
*.sdf
*.suo
*.vcxproj.user

## Ini files
imgui.ini

+ 18
- 0
src/imgui/examples/README.txt Прегледај датотеку

@@ -0,0 +1,18 @@

opengl_example/
OpenGL example, using GLFW + fixed pipeline.
This is simple and should work for all OpenGL enabled applications.
Prefer following this example since it is the shortest one!

opengl3_example/
OpenGL exemple, using GLFW/GL3W + programmable pipeline.
This uses more modern calls and custom shaders.
I don't think there is an advantage using this over the simpler example, but it is provided for reference.

directx9_example/
DirectX9 example, Windows only.
directx11_example/
DirectX11 example, Windows only.
This is quite long and tedious, because: DirectX11.

+ 90
- 0
src/imgui/examples/directx11_example/directx11_example.vcxproj Прегледај датотеку

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9F316E83-5AE5-4939-A723-305A94F48005}</ProjectGuid>
<RootNamespace>directx11_example</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..;$(DXSDK_DIR)/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\..;$(DXSDK_DIR)/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\imconfig.h" />
<ClInclude Include="..\..\imgui.h" />
<ClInclude Include="imgui_impl_dx11.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\imgui.cpp" />
<ClCompile Include="imgui_impl_dx11.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

+ 33
- 0
src/imgui/examples/directx11_example/directx11_example.vcxproj.filters Прегледај датотеку

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="imgui">
<UniqueIdentifier>{0587d7a3-f2ce-4d56-b84f-a0005d3bfce6}</UniqueIdentifier>
</Filter>
<Filter Include="sources">
<UniqueIdentifier>{08e36723-ce4f-4cff-9662-c40801cf1acf}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\imconfig.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\..\imgui.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="imgui_impl_dx11.h">
<Filter>sources</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\imgui.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>sources</Filter>
</ClCompile>
<ClCompile Include="imgui_impl_dx11.cpp">
<Filter>sources</Filter>
</ClCompile>
</ItemGroup>
</Project>

+ 465
- 0
src/imgui/examples/directx11_example/imgui_impl_dx11.cpp Прегледај датотеку

@@ -0,0 +1,465 @@
// ImGui Win32 + DirectX11 binding
// https://github.com/ocornut/imgui

#include <imgui.h>
#include "imgui_impl_dx11.h"

// DirectX
#include <d3d11.h>
#include <d3dcompiler.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

// Data
static INT64 g_Time = 0;
static INT64 g_TicksPerSecond = 0;

static HWND g_hWnd = 0;
static ID3D11Device* g_pd3dDevice = NULL;
static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
static ID3D11Buffer* g_pVB = NULL;
static ID3D10Blob * g_pVertexShaderBlob = NULL;
static ID3D11VertexShader* g_pVertexShader = NULL;
static ID3D11InputLayout* g_pInputLayout = NULL;
static ID3D11Buffer* g_pVertexConstantBuffer = NULL;
static ID3D10Blob * g_pPixelShaderBlob = NULL;
static ID3D11PixelShader* g_pPixelShader = NULL;
static ID3D11SamplerState* g_pFontSampler = NULL;
static ID3D11ShaderResourceView*g_pFontTextureView = NULL;
static ID3D11BlendState* g_blendState = NULL;

struct CUSTOMVERTEX
{
float pos[2];
float uv[2];
unsigned int col;
};

struct VERTEX_CONSTANT_BUFFER
{
float mvp[4][4];
};

// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
// If text or lines are blurry when integrating ImGui in your engine:
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
static void ImGui_ImplDX11_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
{
// Copy and convert all vertices into a single contiguous buffer
D3D11_MAPPED_SUBRESOURCE mappedResource;
if (g_pd3dDeviceContext->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK)
return;
CUSTOMVERTEX* vtx_dst = (CUSTOMVERTEX*)mappedResource.pData;
for (int n = 0; n < cmd_lists_count; n++)
{
const ImDrawList* cmd_list = cmd_lists[n];
const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0];
for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++)
{
vtx_dst->pos[0] = vtx_src->pos.x;
vtx_dst->pos[1] = vtx_src->pos.y;
vtx_dst->uv[0] = vtx_src->uv.x;
vtx_dst->uv[1] = vtx_src->uv.y;
vtx_dst->col = vtx_src->col;
vtx_dst++;
vtx_src++;
}
}
g_pd3dDeviceContext->Unmap(g_pVB, 0);

// Setup orthographic projection matrix into our constant buffer
{
D3D11_MAPPED_SUBRESOURCE mappedResource;
if (g_pd3dDeviceContext->Map(g_pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK)
return;

VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)mappedResource.pData;
const float L = 0.0f;
const float R = ImGui::GetIO().DisplaySize.x;
const float B = ImGui::GetIO().DisplaySize.y;
const float T = 0.0f;
const float mvp[4][4] =
{
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f},
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f,},
{ 0.0f, 0.0f, 0.5f, 0.0f },
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
};
memcpy(&pConstantBuffer->mvp, mvp, sizeof(mvp));
g_pd3dDeviceContext->Unmap(g_pVertexConstantBuffer, 0);
}

// Setup viewport
{
D3D11_VIEWPORT vp;
memset(&vp, 0, sizeof(D3D11_VIEWPORT));
vp.Width = ImGui::GetIO().DisplaySize.x;
vp.Height = ImGui::GetIO().DisplaySize.y;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
g_pd3dDeviceContext->RSSetViewports(1, &vp);
}

// Bind shader and vertex buffers
unsigned int stride = sizeof(CUSTOMVERTEX);
unsigned int offset = 0;
g_pd3dDeviceContext->IASetInputLayout(g_pInputLayout);
g_pd3dDeviceContext->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
g_pd3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
g_pd3dDeviceContext->VSSetShader(g_pVertexShader, NULL, 0);
g_pd3dDeviceContext->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
g_pd3dDeviceContext->PSSetShader(g_pPixelShader, NULL, 0);
g_pd3dDeviceContext->PSSetSamplers(0, 1, &g_pFontSampler);

// Setup render state
const float blendFactor[4] = { 0.f, 0.f, 0.f, 0.f };
g_pd3dDeviceContext->OMSetBlendState(g_blendState, blendFactor, 0xffffffff);

// Render command lists
int vtx_offset = 0;
for (int n = 0; n < cmd_lists_count; n++)
{
const ImDrawList* cmd_list = cmd_lists[n];
for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
if (pcmd->user_callback)
{
pcmd->user_callback(cmd_list, pcmd);
}
else
{
const D3D11_RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w };
g_pd3dDeviceContext->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&pcmd->texture_id);
g_pd3dDeviceContext->RSSetScissorRects(1, &r);
g_pd3dDeviceContext->Draw(pcmd->vtx_count, vtx_offset);
}
vtx_offset += pcmd->vtx_count;
}
}

// Restore modified state
g_pd3dDeviceContext->IASetInputLayout(NULL);
g_pd3dDeviceContext->PSSetShader(NULL, NULL, 0);
g_pd3dDeviceContext->VSSetShader(NULL, NULL, 0);
}

LRESULT ImGui_ImplDX11_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
ImGuiIO& io = ImGui::GetIO();
switch (msg)
{
case WM_LBUTTONDOWN:
io.MouseDown[0] = true;
return true;
case WM_LBUTTONUP:
io.MouseDown[0] = false;
return true;
case WM_RBUTTONDOWN:
io.MouseDown[1] = true;
return true;
case WM_RBUTTONUP:
io.MouseDown[1] = false;
return true;
case WM_MOUSEWHEEL:
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
return true;
case WM_MOUSEMOVE:
io.MousePos.x = (signed short)(lParam);
io.MousePos.y = (signed short)(lParam >> 16);
return true;
case WM_KEYDOWN:
if (wParam >= 0 && wParam < 256)
io.KeysDown[wParam] = 1;
return true;
case WM_KEYUP:
if (wParam >= 0 && wParam < 256)
io.KeysDown[wParam] = 0;
return true;
case WM_CHAR:
// You can also use ToAscii()+GetKeyboardState() to retrieve characters.
if (wParam > 0 && wParam < 0x10000)
io.AddInputCharacter((unsigned short)wParam);
return true;
}
return 0;
}

static void ImGui_ImplDX11_CreateFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();

// Build
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

// Create DX11 texture
{
D3D11_TEXTURE2D_DESC texDesc;
ZeroMemory(&texDesc, sizeof(texDesc));
texDesc.Width = width;
texDesc.Height = height;
texDesc.MipLevels = 1;
texDesc.ArraySize = 1;
texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texDesc.SampleDesc.Count = 1;
texDesc.Usage = D3D11_USAGE_DEFAULT;
texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
texDesc.CPUAccessFlags = 0;

ID3D11Texture2D *pTexture = NULL;
D3D11_SUBRESOURCE_DATA subResource;
subResource.pSysMem = pixels;
subResource.SysMemPitch = texDesc.Width * 4;
subResource.SysMemSlicePitch = 0;
g_pd3dDevice->CreateTexture2D(&texDesc, &subResource, &pTexture);

// Create texture view
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
ZeroMemory(&srvDesc, sizeof(srvDesc));
srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = texDesc.MipLevels;
srvDesc.Texture2D.MostDetailedMip = 0;
g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &g_pFontTextureView);
pTexture->Release();
}

// Store our identifier
io.Fonts->TexID = (void *)g_pFontTextureView;

// Create texture sampler
{
D3D11_SAMPLER_DESC samplerDesc;
ZeroMemory(&samplerDesc, sizeof(samplerDesc));
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.MipLODBias = 0.f;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.MinLOD = 0.f;
samplerDesc.MaxLOD = 0.f;
g_pd3dDevice->CreateSamplerState(&samplerDesc, &g_pFontSampler);
}
}

bool ImGui_ImplDX11_CreateDeviceObjects()
{
if (!g_pd3dDevice)
return false;
if (g_pVB)
ImGui_ImplDX11_InvalidateDeviceObjects();

// Create the vertex shader
{
static const char* vertexShader =
"cbuffer vertexBuffer : register(c0) \
{\
float4x4 ProjectionMatrix; \
};\
struct VS_INPUT\
{\
float2 pos : POSITION;\
float4 col : COLOR0;\
float2 uv : TEXCOORD0;\
};\
\
struct PS_INPUT\
{\
float4 pos : SV_POSITION;\
float4 col : COLOR0;\
float2 uv : TEXCOORD0;\
};\
\
PS_INPUT main(VS_INPUT input)\
{\
PS_INPUT output;\
output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\
output.col = input.col;\
output.uv = input.uv;\
return output;\
}";

D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, NULL);
if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
return false;
if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK)
return false;

// Create the input layout
D3D11_INPUT_ELEMENT_DESC localLayout[] = {
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((CUSTOMVERTEX*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((CUSTOMVERTEX*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

if (g_pd3dDevice->CreateInputLayout(localLayout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK)
return false;

// Create the constant buffer
{
D3D11_BUFFER_DESC cbDesc;
cbDesc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER);
cbDesc.Usage = D3D11_USAGE_DYNAMIC;
cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbDesc.MiscFlags = 0;
g_pd3dDevice->CreateBuffer(&cbDesc, NULL, &g_pVertexConstantBuffer);
}
}

// Create the pixel shader
{
static const char* pixelShader =
"struct PS_INPUT\
{\
float4 pos : SV_POSITION;\
float4 col : COLOR0;\
float2 uv : TEXCOORD0;\
};\
sampler sampler0;\
Texture2D texture0;\
\
float4 main(PS_INPUT input) : SV_Target\
{\
float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \
return out_col; \
}";

D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, NULL);
if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
return false;
if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK)
return false;
}

// Create the blending setup
{
D3D11_BLEND_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.AlphaToCoverageEnable = false;
desc.RenderTarget[0].BlendEnable = true;
desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
g_pd3dDevice->CreateBlendState(&desc, &g_blendState);
}

// Create the vertex buffer
{
D3D11_BUFFER_DESC bufferDesc;
memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
bufferDesc.ByteWidth = 100000 * sizeof(CUSTOMVERTEX); // Maybe we should handle that more dynamically?
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
bufferDesc.MiscFlags = 0;
if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pVB) < 0)
return false;
}

ImGui_ImplDX11_CreateFontsTexture();

return true;
}

void ImGui_ImplDX11_InvalidateDeviceObjects()
{
if (!g_pd3dDevice)
return;

if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
if (g_pFontTextureView) { g_pFontTextureView->Release(); ImGui::GetIO().Fonts->TexID = 0; }
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }

if (g_blendState) { g_blendState->Release(); g_blendState = NULL; }
if (g_pPixelShader) { g_pPixelShader->Release(); g_pPixelShader = NULL; }
if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; }
if (g_pVertexConstantBuffer) { g_pVertexConstantBuffer->Release(); g_pVertexConstantBuffer = NULL; }
if (g_pInputLayout) { g_pInputLayout->Release(); g_pInputLayout = NULL; }
if (g_pVertexShader) { g_pVertexShader->Release(); g_pVertexShader = NULL; }
if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; }
}

bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context)
{
g_hWnd = (HWND)hwnd;
g_pd3dDevice = device;
g_pd3dDeviceContext = device_context;

if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond))
return false;
if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time))
return false;

ImGuiIO& io = ImGui::GetIO();
io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime.
io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
io.KeyMap[ImGuiKey_DownArrow] = VK_UP;
io.KeyMap[ImGuiKey_Home] = VK_HOME;
io.KeyMap[ImGuiKey_End] = VK_END;
io.KeyMap[ImGuiKey_Delete] = VK_DELETE;
io.KeyMap[ImGuiKey_Backspace] = VK_BACK;
io.KeyMap[ImGuiKey_Enter] = VK_RETURN;
io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE;
io.KeyMap[ImGuiKey_A] = 'A';
io.KeyMap[ImGuiKey_C] = 'C';
io.KeyMap[ImGuiKey_V] = 'V';
io.KeyMap[ImGuiKey_X] = 'X';
io.KeyMap[ImGuiKey_Y] = 'Y';
io.KeyMap[ImGuiKey_Z] = 'Z';

io.RenderDrawListsFn = ImGui_ImplDX11_RenderDrawLists;
io.ImeWindowHandle = g_hWnd;

return true;
}

void ImGui_ImplDX11_Shutdown()
{
ImGui_ImplDX11_InvalidateDeviceObjects();
ImGui::Shutdown();
g_pd3dDevice = NULL;
g_pd3dDeviceContext = NULL;
g_hWnd = (HWND)0;
}

void ImGui_ImplDX11_NewFrame()
{
if (!g_pVB)
ImGui_ImplDX11_CreateDeviceObjects();

ImGuiIO& io = ImGui::GetIO();

// Setup display size (every frame to accommodate for window resizing)
RECT rect;
GetClientRect(g_hWnd, &rect);
io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));

// Setup time step
INT64 current_time;
QueryPerformanceCounter((LARGE_INTEGER *)&current_time);
io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond;
g_Time = current_time;

// Read keyboard modifiers inputs
io.KeyCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
io.KeyShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
// io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events
// io.MousePos : filled by WM_MOUSEMOVE events
// io.MouseDown : filled by WM_*BUTTON* events
// io.MouseWheel : filled by WM_MOUSEWHEEL events

// Start the frame
ImGui::NewFrame();
}

+ 20
- 0
src/imgui/examples/directx11_example/imgui_impl_dx11.h Прегледај датотеку

@@ -0,0 +1,20 @@
// ImGui Win32 + DirectX11 binding
// https://github.com/ocornut/imgui

struct ID3D11Device;
struct ID3D11DeviceContext;

bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context);
void ImGui_ImplDX11_Shutdown();
void ImGui_ImplDX11_NewFrame();

// Use if you want to reset your rendering device without losing ImGui state.
void ImGui_ImplDX11_InvalidateDeviceObjects();
bool ImGui_ImplDX11_CreateDeviceObjects();

// Handler for Win32 messages, update mouse/keyboard data.
// You may or not need this for your implementation, but it can serve as reference for handling inputs.
// Commented out to avoid dragging dependencies on <windows.h> types. You can copy the extern declaration in your code.
/*
extern LRESULT ImGui_ImplDX11_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
*/

+ 210
- 0
src/imgui/examples/directx11_example/main.cpp Прегледај датотеку

@@ -0,0 +1,210 @@
// ImGui - standalone example application for DirectX 11

#include <imgui.h>
#include "imgui_impl_dx11.h"
#include <d3d11.h>
#include <d3dcompiler.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

// Data
static ID3D11Device* g_pd3dDevice = NULL;
static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
static IDXGISwapChain* g_pSwapChain = NULL;
static ID3D11RenderTargetView* g_mainRenderTargetView = NULL;

void CreateRenderTarget()
{
DXGI_SWAP_CHAIN_DESC sd;
g_pSwapChain->GetDesc(&sd);

// Create the render target
ID3D11Texture2D* pBackBuffer;
D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc;
ZeroMemory(&render_target_view_desc, sizeof(render_target_view_desc));
render_target_view_desc.Format = sd.BufferDesc.Format;
render_target_view_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
g_pd3dDevice->CreateRenderTargetView(pBackBuffer, &render_target_view_desc, &g_mainRenderTargetView);
g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL);
pBackBuffer->Release();
}

void CleanupRenderTarget()
{
if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; }
}

HRESULT CreateDeviceD3D(HWND hWnd)
{
// Setup swap chain
DXGI_SWAP_CHAIN_DESC sd;
{
ZeroMemory(&sd, sizeof(sd));
sd.BufferCount = 2;
sd.BufferDesc.Width = 0;
sd.BufferDesc.Height = 0;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
}

UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_FEATURE_LEVEL featureLevel;
const D3D_FEATURE_LEVEL featureLevelArray[1] = { D3D_FEATURE_LEVEL_11_0, };
if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 1, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK)
return E_FAIL;

// Setup rasterizer
{
D3D11_RASTERIZER_DESC RSDesc;
memset(&RSDesc, 0, sizeof(D3D11_RASTERIZER_DESC));
RSDesc.FillMode = D3D11_FILL_SOLID;
RSDesc.CullMode = D3D11_CULL_NONE;
RSDesc.FrontCounterClockwise = FALSE;
RSDesc.DepthBias = 0;
RSDesc.SlopeScaledDepthBias = 0.0f;
RSDesc.DepthBiasClamp = 0;
RSDesc.DepthClipEnable = TRUE;
RSDesc.ScissorEnable = TRUE;
RSDesc.AntialiasedLineEnable = FALSE;
RSDesc.MultisampleEnable = (sd.SampleDesc.Count > 1) ? TRUE : FALSE;

ID3D11RasterizerState* pRState = NULL;
g_pd3dDevice->CreateRasterizerState(&RSDesc, &pRState);
g_pd3dDeviceContext->RSSetState(pRState);
pRState->Release();
}

CreateRenderTarget();

return S_OK;
}

void CleanupDeviceD3D()
{
CleanupRenderTarget();
if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = NULL; }
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
}

extern LRESULT ImGui_ImplDX11_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (ImGui_ImplDX11_WndProcHandler(hWnd, msg, wParam, lParam))
return true;

switch (msg)
{
case WM_SIZE:
if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
{
ImGui_ImplDX11_InvalidateDeviceObjects();
CleanupRenderTarget();
g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0);
CreateRenderTarget();
ImGui_ImplDX11_CreateDeviceObjects();
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}

int main(int argc, char** argv)
{
// Create application window
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, L"ImGui Example", NULL };
RegisterClassEx(&wc);
HWND hwnd = CreateWindow(L"ImGui Example", L"ImGui DirectX11 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);

// Initialize Direct3D
if (CreateDeviceD3D(hwnd) < 0)
{
CleanupDeviceD3D();
UnregisterClass(L"ImGui Example", wc.hInstance);
return 1;
}

// Show the window
ShowWindow(hwnd, SW_SHOWDEFAULT);
UpdateWindow(hwnd);

// Setup ImGui binding
ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext);
//ImGuiIO& io = ImGui::GetIO();
//ImFont* my_font1 = io.Fonts->AddFontDefault();
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());

bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_col = ImColor(114, 144, 154);

// Main loop
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
continue;
}
ImGui_ImplDX11_NewFrame();

// 1. Show a simple window
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
{
static float f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color", (float*)&clear_col);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
}

// 2. Show another simple window, this time using an explicit Begin/End pair
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100));
ImGui::Text("Hello");
ImGui::End();
}

// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
if (show_test_window)
{
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
ImGui::ShowTestWindow(&show_test_window);
}

// Rendering
g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
ImGui::Render();
g_pSwapChain->Present(0, 0);
}

ImGui_ImplDX11_Shutdown();
CleanupDeviceD3D();
UnregisterClass(L"ImGui Example", wc.hInstance);

return 0;
}

+ 90
- 0
src/imgui/examples/directx9_example/directx9_example.vcxproj Прегледај датотеку

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4165A294-21F2-44CA-9B38-E3F935ABADF5}</ProjectGuid>
<RootNamespace>directx9_example</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..;$(DXSDK_DIR)Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\..;$(DXSDK_DIR)Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>d3d9.lib;d3dx9d.lib;dxerr.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\imgui.cpp" />
<ClCompile Include="imgui_impl_dx9.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\imconfig.h" />
<ClInclude Include="..\..\imgui.h" />
<ClInclude Include="imgui_impl_dx9.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

+ 34
- 0
src/imgui/examples/directx9_example/directx9_example.vcxproj.filters Прегледај датотеку

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="sources">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="imgui">
<UniqueIdentifier>{a82cba23-9de0-45c2-b1e3-2eb1666702de}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>sources</Filter>
</ClCompile>
<ClCompile Include="..\..\imgui.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="imgui_impl_dx9.cpp">
<Filter>sources</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\imconfig.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\..\imgui.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="imgui_impl_dx9.h">
<Filter>sources</Filter>
</ClInclude>
</ItemGroup>
</Project>

+ 286
- 0
src/imgui/examples/directx9_example/imgui_impl_dx9.cpp Прегледај датотеку

@@ -0,0 +1,286 @@
// ImGui Win32 + DirectX9 binding
// https://github.com/ocornut/imgui

#include <imgui.h>
#include "imgui_impl_dx9.h"

// DirectX
#include <d3dx9.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

// Data
static HWND g_hWnd = 0;
static INT64 g_Time = 0;
static INT64 g_TicksPerSecond = 0;
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;

struct CUSTOMVERTEX
{
D3DXVECTOR3 pos;
D3DCOLOR col;
D3DXVECTOR2 uv;
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)

// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
// If text or lines are blurry when integrating ImGui in your engine:
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
static void ImGui_ImplDX9_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
{
size_t total_vtx_count = 0;
for (int n = 0; n < cmd_lists_count; n++)
total_vtx_count += cmd_lists[n]->vtx_buffer.size();
if (total_vtx_count == 0)
return;

// Copy and convert all vertices into a single contiguous buffer
CUSTOMVERTEX* vtx_dst;
if (g_pVB->Lock(0, (UINT)total_vtx_count, (void**)&vtx_dst, D3DLOCK_DISCARD) < 0)
return;
for (int n = 0; n < cmd_lists_count; n++)
{
const ImDrawList* cmd_list = cmd_lists[n];
const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0];
for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++)
{
vtx_dst->pos.x = vtx_src->pos.x;
vtx_dst->pos.y = vtx_src->pos.y;
vtx_dst->pos.z = 0.0f;
vtx_dst->col = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000)>>16) | ((vtx_src->col & 0xFF) << 16); // RGBA --> ARGB for DirectX9
vtx_dst->uv.x = vtx_src->uv.x;
vtx_dst->uv.y = vtx_src->uv.y;
vtx_dst++;
vtx_src++;
}
}
g_pVB->Unlock();

g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

// Setup render state: alpha-blending, no face culling, no depth testing
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, false );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, false );
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true );
g_pd3dDevice->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD );
g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, false );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, true );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );

// Setup orthographic projection matrix
D3DXMATRIXA16 mat;
D3DXMatrixIdentity(&mat);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat);
g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat);
D3DXMatrixOrthoOffCenterLH(&mat, 0.5f, ImGui::GetIO().DisplaySize.x+0.5f, ImGui::GetIO().DisplaySize.y+0.5f, 0.5f, -1.0f, +1.0f);
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat);

// Render command lists
int vtx_offset = 0;
for (int n = 0; n < cmd_lists_count; n++)
{
const ImDrawList* cmd_list = cmd_lists[n];
for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
if (pcmd->user_callback)
{
pcmd->user_callback(cmd_list, pcmd);
}
else
{
const RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w };
g_pd3dDevice->SetTexture( 0, (LPDIRECT3DTEXTURE9)pcmd->texture_id );
g_pd3dDevice->SetScissorRect(&r);
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, vtx_offset, pcmd->vtx_count/3);
}
vtx_offset += pcmd->vtx_count;
}
}
}

LRESULT ImGui_ImplDX9_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
ImGuiIO& io = ImGui::GetIO();
switch (msg)
{
case WM_LBUTTONDOWN:
io.MouseDown[0] = true;
return true;
case WM_LBUTTONUP:
io.MouseDown[0] = false;
return true;
case WM_RBUTTONDOWN:
io.MouseDown[1] = true;
return true;
case WM_RBUTTONUP:
io.MouseDown[1] = false;
return true;
case WM_MOUSEWHEEL:
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
return true;
case WM_MOUSEMOVE:
io.MousePos.x = (signed short)(lParam);
io.MousePos.y = (signed short)(lParam >> 16);
return true;
case WM_KEYDOWN:
if (wParam >= 0 && wParam < 256)
io.KeysDown[wParam] = 1;
return true;
case WM_KEYUP:
if (wParam >= 0 && wParam < 256)
io.KeysDown[wParam] = 0;
return true;
case WM_CHAR:
// You can also use ToAscii()+GetKeyboardState() to retrieve characters.
if (wParam > 0 && wParam < 0x10000)
io.AddInputCharacter((unsigned short)wParam);
return true;
}
return 0;
}

bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device)
{
g_hWnd = (HWND)hwnd;
g_pd3dDevice = device;

if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond))
return false;
if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time))
return false;

ImGuiIO& io = ImGui::GetIO();
io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime.
io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
io.KeyMap[ImGuiKey_DownArrow] = VK_UP;
io.KeyMap[ImGuiKey_Home] = VK_HOME;
io.KeyMap[ImGuiKey_End] = VK_END;
io.KeyMap[ImGuiKey_Delete] = VK_DELETE;
io.KeyMap[ImGuiKey_Backspace] = VK_BACK;
io.KeyMap[ImGuiKey_Enter] = VK_RETURN;
io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE;
io.KeyMap[ImGuiKey_A] = 'A';
io.KeyMap[ImGuiKey_C] = 'C';
io.KeyMap[ImGuiKey_V] = 'V';
io.KeyMap[ImGuiKey_X] = 'X';
io.KeyMap[ImGuiKey_Y] = 'Y';
io.KeyMap[ImGuiKey_Z] = 'Z';

io.RenderDrawListsFn = ImGui_ImplDX9_RenderDrawLists;
io.ImeWindowHandle = g_hWnd;

if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
return false;

return true;
}

void ImGui_ImplDX9_Shutdown()
{
ImGui_ImplDX9_InvalidateDeviceObjects();
ImGui::Shutdown();
g_pd3dDevice = NULL;
g_hWnd = 0;
}

static void ImGui_ImplDX9_CreateFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();

// Build
unsigned char* pixels;
int width, height, bytes_per_pixel;
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height, &bytes_per_pixel);

// Create DX9 texture
LPDIRECT3DTEXTURE9 pTexture = NULL;
if (D3DXCreateTexture(g_pd3dDevice, width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8, D3DPOOL_DEFAULT, &pTexture) < 0)
{
IM_ASSERT(0);
return;
}
D3DLOCKED_RECT tex_locked_rect;
if (pTexture->LockRect(0, &tex_locked_rect, NULL, 0) != D3D_OK)
{
IM_ASSERT(0);
return;
}
for (int y = 0; y < height; y++)
memcpy((unsigned char *)tex_locked_rect.pBits + tex_locked_rect.Pitch * y, pixels + (width * bytes_per_pixel) * y, (width * bytes_per_pixel));
pTexture->UnlockRect(0);

// Store our identifier
io.Fonts->TexID = (void *)pTexture;
}

bool ImGui_ImplDX9_CreateDeviceObjects()
{
if (!g_pd3dDevice)
return false;

if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
return false;

ImGui_ImplDX9_CreateFontsTexture();
return true;
}

void ImGui_ImplDX9_InvalidateDeviceObjects()
{
if (!g_pd3dDevice)
return;
if (g_pVB)
{
g_pVB->Release();
g_pVB = NULL;
}
if (LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)ImGui::GetIO().Fonts->TexID)
{
tex->Release();
ImGui::GetIO().Fonts->TexID = 0;
}
}

void ImGui_ImplDX9_NewFrame()
{
if (!g_pVB)
ImGui_ImplDX9_CreateDeviceObjects();

ImGuiIO& io = ImGui::GetIO();

// Setup display size (every frame to accommodate for window resizing)
RECT rect;
GetClientRect(g_hWnd, &rect);
io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));

// Setup time step
INT64 current_time;
QueryPerformanceCounter((LARGE_INTEGER *)&current_time);
io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond;
g_Time = current_time;

// Read keyboard modifiers inputs
io.KeyCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
io.KeyShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
// io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events
// io.MousePos : filled by WM_MOUSEMOVE events
// io.MouseDown : filled by WM_*BUTTON* events
// io.MouseWheel : filled by WM_MOUSEWHEEL events

// Start the frame
ImGui::NewFrame();
}

+ 19
- 0
src/imgui/examples/directx9_example/imgui_impl_dx9.h Прегледај датотеку

@@ -0,0 +1,19 @@
// ImGui Win32 + DirectX9 binding
// https://github.com/ocornut/imgui

struct IDirect3DDevice9;

bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device);
void ImGui_ImplDX9_Shutdown();
void ImGui_ImplDX9_NewFrame();

// Use if you want to reset your rendering device without losing ImGui state.
void ImGui_ImplDX9_InvalidateDeviceObjects();
bool ImGui_ImplDX9_CreateDeviceObjects();

// Handler for Win32 messages, update mouse/keyboard data.
// You may or not need this for your implementation, but it can serve as reference for handling inputs.
// Commented out to avoid dragging dependencies on <windows.h> types. You can copy the extern declaration in your code.
/*
extern LRESULT ImGui_ImplDX9_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
*/

+ 146
- 0
src/imgui/examples/directx9_example/main.cpp Прегледај датотеку

@@ -0,0 +1,146 @@
// ImGui - standalone example application for DirectX 9

#include <imgui.h>
#include "imgui_impl_dx9.h"
#include <d3dx9.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

// Data
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
static D3DPRESENT_PARAMETERS g_d3dpp;

extern LRESULT ImGui_ImplDX9_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (ImGui_ImplDX9_WndProcHandler(hWnd, msg, wParam, lParam))
return true;

switch (msg)
{
case WM_SIZE:
if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
{
ImGui_ImplDX9_InvalidateDeviceObjects();
g_d3dpp.BackBufferWidth = LOWORD(lParam);
g_d3dpp.BackBufferHeight = HIWORD(lParam);
HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp);
if (hr == D3DERR_INVALIDCALL)
IM_ASSERT(0);
ImGui_ImplDX9_CreateDeviceObjects();
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}

int main(int argc, char** argv)
{
// Create application window
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, L"ImGui Example", NULL };
RegisterClassEx(&wc);
HWND hwnd = CreateWindow(L"ImGui Example", L"ImGui DirectX9 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);

// Initialize Direct3D
LPDIRECT3D9 pD3D;
if ((pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
{
UnregisterClass(L"ImGui Example", wc.hInstance);
return 0;
}
ZeroMemory(&g_d3dpp, sizeof(g_d3dpp));
g_d3dpp.Windowed = TRUE;
g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
g_d3dpp.EnableAutoDepthStencil = TRUE;
g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

// Create the D3DDevice
if (pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)
{
pD3D->Release();
UnregisterClass(L"ImGui Example", wc.hInstance);
return 0;
}

// Setup ImGui binding
ImGui_ImplDX9_Init(hwnd, g_pd3dDevice);
//ImGuiIO& io = ImGui::GetIO();
//ImFont* my_font1 = io.Fonts->AddFontDefault();
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());

ShowWindow(hwnd, SW_SHOWDEFAULT);
UpdateWindow(hwnd);

bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_col = ImColor(114, 144, 154);

// Main loop
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
continue;
}
ImGui_ImplDX9_NewFrame();

// 1. Show a simple window
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
{
static float f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color", (float*)&clear_col);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
}

// 2. Show another simple window, this time using an explicit Begin/End pair
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100));
ImGui::Text("Hello");
ImGui::End();
}

// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
if (show_test_window)
{
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
ImGui::ShowTestWindow(&show_test_window);
}

// Rendering
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_col.x*255.0f), (int)(clear_col.y*255.0f), (int)(clear_col.z*255.0f), (int)(clear_col.w*255.0f));
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0);
if (g_pd3dDevice->BeginScene() >= 0)
{
ImGui::Render();
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}

ImGui_ImplDX9_Shutdown();
if (g_pd3dDevice) g_pd3dDevice->Release();
if (pD3D) pD3D->Release();
UnregisterClass(L"ImGui Example", wc.hInstance);

return 0;
}

+ 38
- 0
src/imgui/examples/imgui_examples_msvc2010.sln Прегледај датотеку

@@ -0,0 +1,38 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl_example", "opengl_example\opengl_example.vcxproj", "{9CDA7840-B7A5-496D-A527-E95571496D18}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx9_example", "directx9_example\directx9_example.vcxproj", "{4165A294-21F2-44CA-9B38-E3F935ABADF5}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx11_example", "directx11_example\directx11_example.vcxproj", "{9F316E83-5AE5-4939-A723-305A94F48005}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl3_example", "opengl3_example\opengl3_example.vcxproj", "{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.ActiveCfg = Debug|Win32
{9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.Build.0 = Debug|Win32
{9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.ActiveCfg = Release|Win32
{9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.Build.0 = Release|Win32
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|Win32.ActiveCfg = Debug|Win32
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|Win32.Build.0 = Debug|Win32
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|Win32.ActiveCfg = Release|Win32
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|Win32.Build.0 = Release|Win32
{9F316E83-5AE5-4939-A723-305A94F48005}.Debug|Win32.ActiveCfg = Debug|Win32
{9F316E83-5AE5-4939-A723-305A94F48005}.Debug|Win32.Build.0 = Debug|Win32
{9F316E83-5AE5-4939-A723-305A94F48005}.Release|Win32.ActiveCfg = Release|Win32
{9F316E83-5AE5-4939-A723-305A94F48005}.Release|Win32.Build.0 = Release|Win32
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|Win32.ActiveCfg = Debug|Win32
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|Win32.Build.0 = Debug|Win32
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|Win32.ActiveCfg = Release|Win32
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

+ 51
- 0
src/imgui/examples/opengl3_example/Makefile Прегледај датотеку

@@ -0,0 +1,51 @@
#
# Cross Platform Makefile
# Compatible with Ubuntu 14.04.1 and Mac OS X
#
#
# if you using Mac OS X:
# You'll need glfw
# http://www.glfw.org
#

#CXX = g++

OBJS = main.o imgui_impl_glfw_gl3.o gl3w/GL/gl3w.o
OBJS += ../../imgui.o

UNAME_S := $(shell uname -s)


ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
LIBS = `pkg-config --static --libs glfw3`

CXXFLAGS = -I../../ -Igl3w `pkg-config --cflags glfw3`
CXXFLAGS += -Wall
CFLAGS = $(CXXFLAGS)
endif

ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "Mac OS X"
LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
LIBS += -L/usr/local/lib
LIBS += -lglfw3

CXXFLAGS = -I../../ -Igl3w -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include
CXXFLAGS += -Wall
# CXXFLAGS += -D__APPLE__
CFLAGS = $(CXXFLAGS)
endif

.cpp.o:
$(CXX) $(CXXFLAGS) -c -o $@ $<

all:imgui_example
@echo Build complete for $(ECHO_MESSAGE)

imgui_example:$(OBJS)
$(CXX) -o imgui_example $(OBJS) $(CXXFLAGS) $(LIBS)

clean:
rm $(OBJS)


+ 1339
- 0
src/imgui/examples/opengl3_example/gl3w/GL/gl3w.c
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 1234
- 0
src/imgui/examples/opengl3_example/gl3w/GL/gl3w.h
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 4533
- 0
src/imgui/examples/opengl3_example/gl3w/GL/glcorearb.h
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 348
- 0
src/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.cpp Прегледај датотеку

@@ -0,0 +1,348 @@
// ImGui GLFW binding with OpenGL3 + shaders
// https://github.com/ocornut/imgui

#include <imgui.h>
#include "imgui_impl_glfw_gl3.h"

// GL3W/GLFW
#include <GL/gl3w.h>
#include <GLFW/glfw3.h>
#ifdef _MSC_VER
#undef APIENTRY
#define GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WGL
#include <GLFW/glfw3native.h>
#endif

// Data
static GLFWwindow* g_Window = NULL;
static double g_Time = 0.0f;
static bool g_MousePressed[3] = { false, false, false };
static float g_MouseWheel = 0.0f;
static GLuint g_FontTexture = 0;
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
static int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0;
static size_t g_VboMaxSize = 20000;
static unsigned int g_VboHandle = 0, g_VaoHandle = 0;

// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
// If text or lines are blurry when integrating ImGui in your engine:
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
{
if (cmd_lists_count == 0)
return;

// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
glActiveTexture(GL_TEXTURE0);

// Setup orthographic projection matrix
const float width = ImGui::GetIO().DisplaySize.x;
const float height = ImGui::GetIO().DisplaySize.y;
const float ortho_projection[4][4] =
{
{ 2.0f/width, 0.0f, 0.0f, 0.0f },
{ 0.0f, 2.0f/-height, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
glUseProgram(g_ShaderHandle);
glUniform1i(g_AttribLocationTex, 0);
glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);

// Grow our buffer according to what we need
size_t total_vtx_count = 0;
for (int n = 0; n < cmd_lists_count; n++)
total_vtx_count += cmd_lists[n]->vtx_buffer.size();
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
size_t neededBufferSize = total_vtx_count * sizeof(ImDrawVert);
if (neededBufferSize > g_VboMaxSize)
{
g_VboMaxSize = neededBufferSize + 5000; // Grow buffer
glBufferData(GL_ARRAY_BUFFER, g_VboMaxSize, NULL, GL_STREAM_DRAW);
}

// Copy and convert all vertices into a single contiguous buffer
unsigned char* buffer_data = (unsigned char*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
if (!buffer_data)
return;
for (int n = 0; n < cmd_lists_count; n++)
{
const ImDrawList* cmd_list = cmd_lists[n];
memcpy(buffer_data, &cmd_list->vtx_buffer[0], cmd_list->vtx_buffer.size() * sizeof(ImDrawVert));
buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert);
}
glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(g_VaoHandle);

int cmd_offset = 0;
for (int n = 0; n < cmd_lists_count; n++)
{
const ImDrawList* cmd_list = cmd_lists[n];
int vtx_offset = cmd_offset;
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
{
if (pcmd->user_callback)
{
pcmd->user_callback(cmd_list, pcmd);
}
else
{
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->texture_id);
glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
}
vtx_offset += pcmd->vtx_count;
}
cmd_offset = vtx_offset;
}

// Restore modified state
glBindVertexArray(0);
glUseProgram(0);
glDisable(GL_SCISSOR_TEST);
glBindTexture(GL_TEXTURE_2D, 0);
}

static const char* ImGui_ImplGlfwGL3_GetClipboardText()
{
return glfwGetClipboardString(g_Window);
}

static void ImGui_ImplGlfwGL3_SetClipboardText(const char* text)
{
glfwSetClipboardString(g_Window, text);
}

void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{
if (action == GLFW_PRESS && button >= 0 && button < 3)
g_MousePressed[button] = true;
}

void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
{
g_MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines.
}

void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
ImGuiIO& io = ImGui::GetIO();
if (action == GLFW_PRESS)
io.KeysDown[key] = true;
if (action == GLFW_RELEASE)
io.KeysDown[key] = false;
io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0;
io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0;
}

void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow* window, unsigned int c)
{
ImGuiIO& io = ImGui::GetIO();
if (c > 0 && c < 0x10000)
io.AddInputCharacter((unsigned short)c);
}

void ImGui_ImplGlfwGL3_CreateFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();

unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits for OpenGL3 demo because it is more likely to be compatible with user's existing shader.

glGenTextures(1, &g_FontTexture);
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

// Store our identifier
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
}

bool ImGui_ImplGlfwGL3_CreateDeviceObjects()
{
const GLchar *vertex_shader =
"#version 330\n"
"uniform mat4 ProjMtx;\n"
"in vec2 Position;\n"
"in vec2 UV;\n"
"in vec4 Color;\n"
"out vec2 Frag_UV;\n"
"out vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" Frag_UV = UV;\n"
" Frag_Color = Color;\n"
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
"}\n";

const GLchar* fragment_shader =
"#version 330\n"
"uniform sampler2D Texture;\n"
"in vec2 Frag_UV;\n"
"in vec4 Frag_Color;\n"
"out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * texture( Texture, Frag_UV.st);\n"
"}\n";

g_ShaderHandle = glCreateProgram();
g_VertHandle = glCreateShader(GL_VERTEX_SHADER);
g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(g_VertHandle, 1, &vertex_shader, 0);
glShaderSource(g_FragHandle, 1, &fragment_shader, 0);
glCompileShader(g_VertHandle);
glCompileShader(g_FragHandle);
glAttachShader(g_ShaderHandle, g_VertHandle);
glAttachShader(g_ShaderHandle, g_FragHandle);
glLinkProgram(g_ShaderHandle);

g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture");
g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx");
g_AttribLocationPosition = glGetAttribLocation(g_ShaderHandle, "Position");
g_AttribLocationUV = glGetAttribLocation(g_ShaderHandle, "UV");
g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color");

glGenBuffers(1, &g_VboHandle);
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
glBufferData(GL_ARRAY_BUFFER, g_VboMaxSize, NULL, GL_DYNAMIC_DRAW);

glGenVertexArrays(1, &g_VaoHandle);
glBindVertexArray(g_VaoHandle);
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
glEnableVertexAttribArray(g_AttribLocationPosition);
glEnableVertexAttribArray(g_AttribLocationUV);
glEnableVertexAttribArray(g_AttribLocationColor);

#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos));
glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv));
glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col));
#undef OFFSETOF
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

ImGui_ImplGlfwGL3_CreateFontsTexture();

return true;
}

bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks)
{
g_Window = window;

ImGuiIO& io = ImGui::GetIO();
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN;
io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME;
io.KeyMap[ImGuiKey_End] = GLFW_KEY_END;
io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE;
io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE;
io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;

io.RenderDrawListsFn = ImGui_ImplGlfwGL3_RenderDrawLists;
io.SetClipboardTextFn = ImGui_ImplGlfwGL3_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplGlfwGL3_GetClipboardText;
#ifdef _MSC_VER
io.ImeWindowHandle = glfwGetWin32Window(g_Window);
#endif

if (install_callbacks)
{
glfwSetMouseButtonCallback(window, ImGui_ImplGlfwGL3_MouseButtonCallback);
glfwSetScrollCallback(window, ImGui_ImplGlfwGL3_ScrollCallback);
glfwSetKeyCallback(window, ImGui_ImplGlfwGL3_KeyCallback);
glfwSetCharCallback(window, ImGui_ImplGlfwGL3_CharCallback);
}

return true;
}

void ImGui_ImplGlfwGL3_Shutdown()
{
if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle);
if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle);
g_VaoHandle = 0;
g_VboHandle = 0;

glDetachShader(g_ShaderHandle, g_VertHandle);
glDeleteShader(g_VertHandle);
g_VertHandle = 0;

glDetachShader(g_ShaderHandle, g_FragHandle);
glDeleteShader(g_FragHandle);
g_FragHandle = 0;

glDeleteProgram(g_ShaderHandle);
g_ShaderHandle = 0;

if (g_FontTexture)
{
glDeleteTextures(1, &g_FontTexture);
ImGui::GetIO().Fonts->TexID = 0;
g_FontTexture = 0;
}
ImGui::Shutdown();
}

void ImGui_ImplGlfwGL3_NewFrame()
{
if (!g_FontTexture)
ImGui_ImplGlfwGL3_CreateDeviceObjects();

ImGuiIO& io = ImGui::GetIO();

// Setup display size (every frame to accommodate for window resizing)
int w, h;
int display_w, display_h;
glfwGetWindowSize(g_Window, &w, &h);
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
io.DisplaySize = ImVec2((float)display_w, (float)display_h);

// Setup time step
double current_time = glfwGetTime();
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
g_Time = current_time;

// Setup inputs
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
double mouse_x, mouse_y;
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels
mouse_y *= (float)display_h / h;
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)

for (int i = 0; i < 3; i++)
{
io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
g_MousePressed[i] = false;
}

io.MouseWheel = g_MouseWheel;
g_MouseWheel = 0.0f;

// Start the frame
ImGui::NewFrame();
}

+ 20
- 0
src/imgui/examples/opengl3_example/imgui_impl_glfw_gl3.h Прегледај датотеку

@@ -0,0 +1,20 @@
// ImGui GLFW binding with OpenGL3 + shaders
// https://github.com/ocornut/imgui

struct GLFWwindow;

bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks);
void ImGui_ImplGlfwGL3_Shutdown();
void ImGui_ImplGlfwGL3_NewFrame();

// Use if you want to reset your rendering device without losing ImGui state.
void ImGui_ImplGlfwGL3_InvalidateDeviceObjects();
bool ImGui_ImplGlfwGL3_CreateDeviceObjects();

// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
// Provided here if you want to chain callbacks.
// You can also handle inputs yourself and use those as a reference.
void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
void ImGui_ImplGlFwGL3_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow* window, unsigned int c);

+ 87
- 0
src/imgui/examples/opengl3_example/main.cpp Прегледај датотеку

@@ -0,0 +1,87 @@
// ImGui - standalone example application for Glfw + OpenGL 3, using programmable pipeline

#include <imgui.h>
#include "imgui_impl_glfw_gl3.h"
#include <stdio.h>
#include <GL/gl3w.h>
#include <GLFW/glfw3.h>

static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}

int main(int argc, char** argv)
{
// Setup window
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(1);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
glfwMakeContextCurrent(window);
gl3wInit();

// Setup ImGui binding
ImGui_ImplGlfwGL3_Init(window, true);
//ImGuiIO& io = ImGui::GetIO();
//ImFont* my_font1 = io.Fonts->AddFontDefault();
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());

bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);

// Main loop
while (!glfwWindowShouldClose(window))
{
ImGuiIO& io = ImGui::GetIO();
glfwPollEvents();
ImGui_ImplGlfwGL3_NewFrame();

// 1. Show a simple window
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
{
static float f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color", (float*)&clear_color);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
}

// 2. Show another simple window, this time using an explicit Begin/End pair
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100));
ImGui::Text("Hello");
ImGui::End();
}

// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
if (show_test_window)
{
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
ImGui::ShowTestWindow(&show_test_window);
}
// Rendering
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui::Render();
glfwSwapBuffers(window);
}

// Cleanup
ImGui_ImplGlfwGL3_Shutdown();
glfwTerminate();

return 0;
}

+ 98
- 0
src/imgui/examples/opengl3_example/opengl3_example.vcxproj Прегледај датотеку

@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4a1fb5ea-22f5-42a8-ab92-1d2df5d47fb9}</ProjectGuid>
<RootNamespace>opengl3_example</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
<IncludePath>$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
<IncludePath>$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(ProjectDir)..\opengl_example\glfw\include;gl3w;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(ProjectDir)..\opengl_example\glfw\lib-msvc100;$(ProjectDir)..\opengl_example\glew\lib\Release\Win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opengl32.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<IgnoreSpecificDefaultLibraries>msvcrt.lib</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(ProjectDir)..\opengl_example\glfw\include;gl3w;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(ProjectDir)..\opengl_example\glfw\lib-msvc100;$(ProjectDir)..\opengl_example\glew\lib\Release\Win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opengl32.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\imgui.cpp" />
<ClCompile Include="gl3w\GL\gl3w.c" />
<ClCompile Include="imgui_impl_glfw_gl3.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\imconfig.h" />
<ClInclude Include="..\..\imgui.h" />
<ClInclude Include="gl3w\GL\gl3w.h" />
<ClInclude Include="gl3w\GL\glcorearb.h" />
<ClInclude Include="imgui_impl_glfw_gl3.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

+ 46
- 0
src/imgui/examples/opengl3_example/opengl3_example.vcxproj.filters Прегледај датотеку

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="imgui">
<UniqueIdentifier>{20b90ce4-7fcb-4731-b9a0-075f875de82d}</UniqueIdentifier>
</Filter>
<Filter Include="sources">
<UniqueIdentifier>{f18ab499-84e1-499f-8eff-9754361e0e52}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="gl3w">
<UniqueIdentifier>{42f99867-3108-43b8-99d0-fabefaf1f2e3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>sources</Filter>
</ClCompile>
<ClCompile Include="..\..\imgui.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="imgui_impl_glfw_gl3.cpp">
<Filter>sources</Filter>
</ClCompile>
<ClCompile Include="gl3w\GL\gl3w.c">
<Filter>gl3w</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\imconfig.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\..\imgui.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="imgui_impl_glfw_gl3.h">
<Filter>sources</Filter>
</ClInclude>
<ClInclude Include="gl3w\GL\gl3w.h">
<Filter>gl3w</Filter>
</ClInclude>
<ClInclude Include="gl3w\GL\glcorearb.h">
<Filter>gl3w</Filter>
</ClInclude>
</ItemGroup>
</Project>

+ 51
- 0
src/imgui/examples/opengl_example/Makefile Прегледај датотеку

@@ -0,0 +1,51 @@
#
# Cross Platform Makefile
# Compatible with Ubuntu 14.04.1 and Mac OS X
#
#
# if you using Mac OS X:
# You'll need glfw
# http://www.glfw.org
#

#CXX = g++

OBJS = main.o imgui_impl_glfw.o
OBJS += ../../imgui.o

UNAME_S := $(shell uname -s)


ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
LIBS = `pkg-config --static --libs glfw3`

CXXFLAGS = -I../../ `pkg-config --cflags glfw3`
CXXFLAGS += -Wall
CFLAGS = $(CXXFLAGS)
endif

ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "Mac OS X"
LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
LIBS += -L/usr/local/lib
LIBS += -lglfw3

CXXFLAGS = -I../../ -I/usr/local/include
CXXFLAGS += -Wall
# CXXFLAGS += -D__APPLE__
CFLAGS = $(CXXFLAGS)
endif

.cpp.o:
$(CXX) $(CXXFLAGS) -c -o $@ $<

all:imgui_example
@echo Build complete for $(ECHO_MESSAGE)

imgui_example:$(OBJS)
$(CXX) -o imgui_example $(OBJS) $(CXXFLAGS) $(LIBS)

clean:
rm $(OBJS)


+ 22
- 0
src/imgui/examples/opengl_example/glfw/COPYING.txt Прегледај датотеку

@@ -0,0 +1,22 @@
Copyright (c) 2002-2006 Marcus Geelnard
Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would
be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.


+ 2281
- 0
src/imgui/examples/opengl_example/glfw/include/GLFW/glfw3.h
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 180
- 0
src/imgui/examples/opengl_example/glfw/include/GLFW/glfw3native.h Прегледај датотеку

@@ -0,0 +1,180 @@
/*************************************************************************
* GLFW 3.0 - www.glfw.org
* A library for OpenGL, window and input
*------------------------------------------------------------------------
* Copyright (c) 2002-2006 Marcus Geelnard
* Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would
* be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*
*************************************************************************/

#ifndef _glfw3_native_h_
#define _glfw3_native_h_

#ifdef __cplusplus
extern "C" {
#endif


/*************************************************************************
* Doxygen documentation
*************************************************************************/

/*! @defgroup native Native access
*
* **By using the native API, you assert that you know what you're doing and
* how to fix problems caused by using it. If you don't, you shouldn't be
* using it.**
*
* Before the inclusion of @ref glfw3native.h, you must define exactly one
* window API macro and exactly one context API macro. Failure to do this
* will cause a compile-time error.
*
* The available window API macros are:
* * `GLFW_EXPOSE_NATIVE_WIN32`
* * `GLFW_EXPOSE_NATIVE_COCOA`
* * `GLFW_EXPOSE_NATIVE_X11`
*
* The available context API macros are:
* * `GLFW_EXPOSE_NATIVE_WGL`
* * `GLFW_EXPOSE_NATIVE_NSGL`
* * `GLFW_EXPOSE_NATIVE_GLX`
* * `GLFW_EXPOSE_NATIVE_EGL`
*
* These macros select which of the native access functions that are declared
* and which platform-specific headers to include. It is then up your (by
* definition platform-specific) code to handle which of these should be
* defined.
*/


/*************************************************************************
* System headers and types
*************************************************************************/

#if defined(GLFW_EXPOSE_NATIVE_WIN32)
#include <windows.h>
#elif defined(GLFW_EXPOSE_NATIVE_COCOA)
#if defined(__OBJC__)
#import <Cocoa/Cocoa.h>
#else
typedef void* id;
#endif
#elif defined(GLFW_EXPOSE_NATIVE_X11)
#include <X11/Xlib.h>
#else
#error "No window API specified"
#endif

#if defined(GLFW_EXPOSE_NATIVE_WGL)
/* WGL is declared by windows.h */
#elif defined(GLFW_EXPOSE_NATIVE_NSGL)
/* NSGL is declared by Cocoa.h */
#elif defined(GLFW_EXPOSE_NATIVE_GLX)
#include <GL/glx.h>
#elif defined(GLFW_EXPOSE_NATIVE_EGL)
#include <EGL/egl.h>
#else
#error "No context API specified"
#endif


/*************************************************************************
* Functions
*************************************************************************/

#if defined(GLFW_EXPOSE_NATIVE_WIN32)
/*! @brief Returns the `HWND` of the specified window.
* @return The `HWND` of the specified window.
* @ingroup native
*/
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window);
#endif

#if defined(GLFW_EXPOSE_NATIVE_WGL)
/*! @brief Returns the `HGLRC` of the specified window.
* @return The `HGLRC` of the specified window.
* @ingroup native
*/
GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window);
#endif

#if defined(GLFW_EXPOSE_NATIVE_COCOA)
/*! @brief Returns the `NSWindow` of the specified window.
* @return The `NSWindow` of the specified window.
* @ingroup native
*/
GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
#endif

#if defined(GLFW_EXPOSE_NATIVE_NSGL)
/*! @brief Returns the `NSOpenGLContext` of the specified window.
* @return The `NSOpenGLContext` of the specified window.
* @ingroup native
*/
GLFWAPI id glfwGetNSGLContext(GLFWwindow* window);
#endif

#if defined(GLFW_EXPOSE_NATIVE_X11)
/*! @brief Returns the `Display` used by GLFW.
* @return The `Display` used by GLFW.
* @ingroup native
*/
GLFWAPI Display* glfwGetX11Display(void);
/*! @brief Returns the `Window` of the specified window.
* @return The `Window` of the specified window.
* @ingroup native
*/
GLFWAPI Window glfwGetX11Window(GLFWwindow* window);
#endif

#if defined(GLFW_EXPOSE_NATIVE_GLX)
/*! @brief Returns the `GLXContext` of the specified window.
* @return The `GLXContext` of the specified window.
* @ingroup native
*/
GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window);
#endif

#if defined(GLFW_EXPOSE_NATIVE_EGL)
/*! @brief Returns the `EGLDisplay` used by GLFW.
* @return The `EGLDisplay` used by GLFW.
* @ingroup native
*/
GLFWAPI EGLDisplay glfwGetEGLDisplay(void);
/*! @brief Returns the `EGLContext` of the specified window.
* @return The `EGLContext` of the specified window.
* @ingroup native
*/
GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window);
/*! @brief Returns the `EGLSurface` of the specified window.
* @return The `EGLSurface` of the specified window.
* @ingroup native
*/
GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window);
#endif

#ifdef __cplusplus
}
#endif

#endif /* _glfw3_native_h_ */


BIN
src/imgui/examples/opengl_example/glfw/lib-msvc100/glfw3.lib Прегледај датотеку


BIN
src/imgui/examples/opengl_example/glfw/lib-msvc110/glfw3.lib Прегледај датотеку


+ 252
- 0
src/imgui/examples/opengl_example/imgui_impl_glfw.cpp Прегледај датотеку

@@ -0,0 +1,252 @@
// ImGui GLFW binding with OpenGL
// https://github.com/ocornut/imgui

#include <imgui.h>
#include "imgui_impl_glfw.h"

// GLFW
#include <GLFW/glfw3.h>
#ifdef _MSC_VER
#undef APIENTRY
#define GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WGL
#include <GLFW/glfw3native.h>
#endif

// Data
static GLFWwindow* g_Window = NULL;
static double g_Time = 0.0f;
static bool g_MousePressed[3] = { false, false, false };
static float g_MouseWheel = 0.0f;
static GLuint g_FontTexture = 0;

// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
// If text or lines are blurry when integrating ImGui in your engine:
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
static void ImGui_ImplGlfw_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
{
if (cmd_lists_count == 0)
return;

// We are using the OpenGL fixed pipeline to make the example code simpler to read!
// A probable faster way to render would be to collate all vertices from all cmd_lists into a single vertex buffer.
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnable(GL_TEXTURE_2D);

// Setup orthographic projection matrix
const float width = ImGui::GetIO().DisplaySize.x;
const float height = ImGui::GetIO().DisplaySize.y;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, width, height, 0.0f, -1.0f, +1.0f);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

// Render command lists
#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
for (int n = 0; n < cmd_lists_count; n++)
{
const ImDrawList* cmd_list = cmd_lists[n];
const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->vtx_buffer.front();
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, pos)));
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, uv)));
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, col)));

int vtx_offset = 0;
for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i];
if (pcmd->user_callback)
{
pcmd->user_callback(cmd_list, pcmd);
}
else
{
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->texture_id);
glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
}
vtx_offset += pcmd->vtx_count;
}
}
#undef OFFSETOF

// Restore modified state
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
}

static const char* ImGui_ImplGlfw_GetClipboardText()
{
return glfwGetClipboardString(g_Window);
}

static void ImGui_ImplGlfw_SetClipboardText(const char* text)
{
glfwSetClipboardString(g_Window, text);
}

void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{
if (action == GLFW_PRESS && button >= 0 && button < 3)
g_MousePressed[button] = true;
}

void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
{
g_MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines.
}

void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
ImGuiIO& io = ImGui::GetIO();
if (action == GLFW_PRESS)
io.KeysDown[key] = true;
if (action == GLFW_RELEASE)
io.KeysDown[key] = false;
io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0;
io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0;
}

void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
{
ImGuiIO& io = ImGui::GetIO();
if (c > 0 && c < 0x10000)
io.AddInputCharacter((unsigned short)c);
}

bool ImGui_ImplGlfw_CreateDeviceObjects()
{
ImGuiIO& io = ImGui::GetIO();

// Build texture
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);

// Create texture
glGenTextures(1, &g_FontTexture);
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels);

// Store our identifier
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;

return true;
}

void ImGui_ImplGlfw_InvalidateDeviceObjects()
{
if (g_FontTexture)
{
glDeleteTextures(1, &g_FontTexture);
ImGui::GetIO().Fonts->TexID = 0;
g_FontTexture = 0;
}
}

bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks)
{
g_Window = window;

ImGuiIO& io = ImGui::GetIO();
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN;
io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME;
io.KeyMap[ImGuiKey_End] = GLFW_KEY_END;
io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE;
io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE;
io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;

io.RenderDrawListsFn = ImGui_ImplGlfw_RenderDrawLists;
io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
#ifdef _MSC_VER
io.ImeWindowHandle = glfwGetWin32Window(g_Window);
#endif

if (install_callbacks)
{
glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
glfwSetKeyCallback(window, ImGui_ImplGlFw_KeyCallback);
glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
}

return true;
}

void ImGui_ImplGlfw_Shutdown()
{
ImGui_ImplGlfw_InvalidateDeviceObjects();
ImGui::Shutdown();
}

void ImGui_ImplGlfw_NewFrame()
{
if (!g_FontTexture)
ImGui_ImplGlfw_CreateDeviceObjects();

ImGuiIO& io = ImGui::GetIO();

// Setup display size (every frame to accommodate for window resizing)
int w, h;
int display_w, display_h;
glfwGetWindowSize(g_Window, &w, &h);
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
io.DisplaySize = ImVec2((float)display_w, (float)display_h);

// Setup time step
double current_time = glfwGetTime();
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
g_Time = current_time;

// Setup inputs
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
double mouse_x, mouse_y;
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels
mouse_y *= (float)display_h / h;
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
for (int i = 0; i < 3; i++)
{
io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
g_MousePressed[i] = false;
}

io.MouseWheel = g_MouseWheel;
g_MouseWheel = 0.0f;

// Start the frame
ImGui::NewFrame();
}

+ 20
- 0
src/imgui/examples/opengl_example/imgui_impl_glfw.h Прегледај датотеку

@@ -0,0 +1,20 @@
// ImGui GLFW binding with OpenGL
// https://github.com/ocornut/imgui

struct GLFWwindow;

bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks);
void ImGui_ImplGlfw_Shutdown();
void ImGui_ImplGlfw_NewFrame();

// Use if you want to reset your rendering device without losing ImGui state.
void ImGui_ImplGlfw_InvalidateDeviceObjects();
bool ImGui_ImplGlfw_CreateDeviceObjects();

// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
// Provided here if you want to chain callbacks.
// You can also handle inputs yourself and use those as a reference.
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);

+ 81
- 0
src/imgui/examples/opengl_example/main.cpp Прегледај датотеку

@@ -0,0 +1,81 @@
// ImGui - standalone example application for Glfw + OpenGL 2, using fixed pipeline

#include <imgui.h>
#include "imgui_impl_glfw.h"
#include <stdio.h>
#include <GLFW/glfw3.h>

static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}

int main(int argc, char** argv)
{
// Setup window
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(1);
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL);
glfwMakeContextCurrent(window);

// Setup ImGui binding
ImGui_ImplGlfw_Init(window, true);
//ImGuiIO& io = ImGui::GetIO();
//ImFont* my_font1 = io.Fonts->AddFontDefault();
//ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("extra_fonts/Karla-Regular.ttf", 15.0f);
//ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
//ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
//ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());

bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);

// Main loop
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
ImGui_ImplGlfw_NewFrame();

// 1. Show a simple window
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
{
static float f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color", (float*)&clear_color);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
}

// 2. Show another simple window, this time using an explicit Begin/End pair
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100));
ImGui::Text("Hello");
ImGui::End();
}

// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
if (show_test_window)
{
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
ImGui::ShowTestWindow(&show_test_window);
}

// Rendering
glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui::Render();
glfwSwapBuffers(window);
}

// Cleanup
ImGui_ImplGlfw_Shutdown();
glfwTerminate();

return 0;
}

+ 95
- 0
src/imgui/examples/opengl_example/opengl_example.vcxproj Прегледај датотеку

@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9CDA7840-B7A5-496D-A527-E95571496D18}</ProjectGuid>
<RootNamespace>opengl_example</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
<IncludePath>$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
<IncludePath>$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(ProjectDir)\glfw\include;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(ProjectDir)\glfw\lib-msvc100;$(ProjectDir)\glew\lib\Release\Win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opengl32.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<IgnoreSpecificDefaultLibraries>msvcrt.lib</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(ProjectDir)\glfw\include;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(ProjectDir)\glfw\lib-msvc100;$(ProjectDir)\glew\lib\Release\Win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opengl32.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\imgui.cpp" />
<ClCompile Include="imgui_impl_glfw.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\imconfig.h" />
<ClInclude Include="..\..\imgui.h" />
<ClInclude Include="imgui_impl_glfw.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

+ 34
- 0
src/imgui/examples/opengl_example/opengl_example.vcxproj.filters Прегледај датотеку

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="imgui">
<UniqueIdentifier>{c336cfe3-f0c4-464c-9ef0-a9e17a7ff222}</UniqueIdentifier>
</Filter>
<Filter Include="sources">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>sources</Filter>
</ClCompile>
<ClCompile Include="..\..\imgui.cpp">
<Filter>imgui</Filter>
</ClCompile>
<ClCompile Include="imgui_impl_glfw.cpp">
<Filter>sources</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\imconfig.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\..\imgui.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="imgui_impl_glfw.h">
<Filter>sources</Filter>
</ClInclude>
</ItemGroup>
</Project>

BIN
src/imgui/extra_fonts/DroidSans.ttf Прегледај датотеку


BIN
src/imgui/extra_fonts/Karla-Regular.ttf Прегледај датотеку


BIN
src/imgui/extra_fonts/ProggyClean.ttf Прегледај датотеку


BIN
src/imgui/extra_fonts/ProggyTiny.ttf Прегледај датотеку


+ 60
- 0
src/imgui/extra_fonts/README.txt Прегледај датотеку

@@ -0,0 +1,60 @@

The code in imgui.cpp embeds a copy of 'ProggyClean.ttf' that you can use without any external files.

---------------------------------
EXTRA FONTS FOR IMGUI
---------------------------------

DroidSans.ttf
Copyright (c) Steve Matteson
Apache License, version 2.0
http://www.google.com/fonts/specimen/Droid+Sans

ProggyClean.ttf
Copyright (c) 2004, 2005 Tristan Grimmer
MIT License
recommended loading setting in ImGui: Size = 13.0, DisplayOffset.Y = +1

ProggyTiny.ttf
Copyright (c) 2004, 2005 Tristan Grimmer
MIT License
recommended loading setting in ImGui: Size = 10.0, DisplayOffset.Y = +1

Karla-Regular
Copyright (c) 2012, Jonathan Pinhorn
SIL OPEN FONT LICENSE Version 1.1

---------------------------------
OTHER FONTS
---------------------------------

For Japanese:
M+ fonts by Coji Morishita are free and include most useful Kanjis you would need.
mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html
For Japanese, Chinese, Korean:
You can use Arial Unicode or other Unicode fonts provided with Windows (not sure of their license).
Other suggestions?

---------------------------------
LOADING INSTRUCTIONS
---------------------------------

Load .TTF file with:

ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels);
Add a third parameter to bake specific font ranges:

io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, io.Fonts->GetGlyphRangesDefault()); // Basic Latin, Extended Latin
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, io.Fonts->GetGlyphRangesJapanese()); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, io.Fonts->GetGlyphRangesChinese()); // Include full set of about 21000 CJK Unified Ideographs

Offset font by altering the io.Font->DisplayOffset value:

ImFont* font = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels);
font->DisplayOffset.y += 1; // Render 1 pixel down


+ 52
- 0
src/imgui/imconfig.h Прегледај датотеку

@@ -0,0 +1,52 @@
//-----------------------------------------------------------------------------
// USER IMPLEMENTATION
// This file contains compile-time options for ImGui.
// Other options (memory allocation overrides, callbacks, etc.) can be set at runtime via the ImGuiIO structure - ImGui::GetIO().
//-----------------------------------------------------------------------------

#pragma once

//---- Define your own ImVector<> type if you don't want to use the provided implementation defined in imgui.h
//#include <vector>
//#define ImVector std::vector
//#define ImVector MyVector

//---- Define assertion handler. Defaults to calling assert().
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)

//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )

//---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS

//---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
//#define IMGUI_INCLUDE_IMGUI_USER_INL

//---- Include imgui_user.h at the end of imgui.h
//#define IMGUI_INCLUDE_IMGUI_USER_H

//---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
/*
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
operator MyVec2() const { return MyVec2(x,y); }

#define IM_VEC4_CLASS_EXTRA \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/

//---- Freely implement extra functions within the ImGui:: namespace.
//---- Declare helpers or widgets implemented in imgui_user.inl or elsewhere, so end-user doesn't need to include multiple files.
//---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers.
/*
namespace ImGui
{
void Value(const char* prefix, const MyVec2& v, const char* float_format = NULL);
void Value(const char* prefix, const MyVec4& v, const char* float_format = NULL);
}
*/


+ 10056
- 0
src/imgui/imgui.cpp
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 974
- 0
src/imgui/imgui.h Прегледај датотеку

@@ -0,0 +1,974 @@
// ImGui library v1.36 WIP
// See .cpp file for documentation.
// See ImGui::ShowTestWindow() for sample code.
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
// Get latest version at https://github.com/ocornut/imgui

#pragma once

#include "imconfig.h" // User-editable configuration file
#include <float.h> // FLT_MAX
#include <stdarg.h> // va_list
#include <stddef.h> // ptrdiff_t
#include <stdlib.h> // NULL, malloc
#include <string.h> // memset, memmove

#define IMGUI_VERSION "1.36 WIP"

// Define assertion handler.
#ifndef IM_ASSERT
#include <assert.h>
#define IM_ASSERT(_EXPR) assert(_EXPR)
#endif

// Define attributes of all API symbols declarations, e.g. for DLL under Windows.
#ifndef IMGUI_API
#define IMGUI_API
#endif

// Forward declarations
struct ImDrawCmd;
struct ImDrawList;
struct ImFont;
struct ImFontAtlas;
struct ImGuiIO;
struct ImGuiStorage;
struct ImGuiStyle;

typedef unsigned int ImU32;
typedef unsigned short ImWchar; // character for display
typedef void* ImTextureID; // user data to refer to a texture (e.g. store your texture handle/id)
typedef ImU32 ImGuiID; // unique ID used by widgets (typically hashed from a stack of string)
typedef int ImGuiCol; // enum ImGuiCol_
typedef int ImGuiStyleVar; // enum ImGuiStyleVar_
typedef int ImGuiKey; // enum ImGuiKey_
typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_
typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_
typedef int ImGuiSetCond; // enum ImGuiSetCondition_
typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_
struct ImGuiTextEditCallbackData; // for advanced uses of InputText()
typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data);

struct ImVec2
{
float x, y;
ImVec2() {}
ImVec2(float _x, float _y) { x = _x; y = _y; }

#ifdef IM_VEC2_CLASS_EXTRA
IM_VEC2_CLASS_EXTRA
#endif
};

struct ImVec4
{
float x, y, z, w;
ImVec4() {}
ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; }

#ifdef IM_VEC4_CLASS_EXTRA
IM_VEC4_CLASS_EXTRA
#endif
};

namespace ImGui
{
// Proxy functions to access the MemAllocFn/MemFreeFn pointers in ImGui::GetIO(). The only reason they exist here is to allow ImVector<> to compile inline.
IMGUI_API void* MemAlloc(size_t sz);
IMGUI_API void MemFree(void* ptr);
}

// std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
// Use '#define ImVector std::vector' if you want to use the STL type or your own type.
// Our implementation does NOT call c++ constructors! because the data types we use don't need them (but that could be added as well). Only provide the minimum functionalities we need.
#ifndef ImVector
template<typename T>
class ImVector
{
protected:
size_t Size;
size_t Capacity;
T* Data;

public:
typedef T value_type;
typedef value_type* iterator;
typedef const value_type* const_iterator;

ImVector() { Size = Capacity = 0; Data = NULL; }
~ImVector() { if (Data) ImGui::MemFree(Data); }

inline bool empty() const { return Size == 0; }
inline size_t size() const { return Size; }
inline size_t capacity() const { return Capacity; }

inline value_type& at(size_t i) { IM_ASSERT(i < Size); return Data[i]; }
inline const value_type& at(size_t i) const { IM_ASSERT(i < Size); return Data[i]; }
inline value_type& operator[](size_t i) { IM_ASSERT(i < Size); return Data[i]; }
inline const value_type& operator[](size_t i) const { IM_ASSERT(i < Size); return Data[i]; }

inline void clear() { if (Data) { Size = Capacity = 0; ImGui::MemFree(Data); Data = NULL; } }
inline iterator begin() { return Data; }
inline const_iterator begin() const { return Data; }
inline iterator end() { return Data + Size; }
inline const_iterator end() const { return Data + Size; }
inline value_type& front() { IM_ASSERT(Size > 0); return Data[0]; }
inline const value_type& front() const { IM_ASSERT(Size > 0); return Data[0]; }
inline value_type& back() { IM_ASSERT(Size > 0); return Data[Size-1]; }
inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size-1]; }
inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; }

inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; }
inline void reserve(size_t new_capacity)
{
if (new_capacity <= Capacity) return;
T* new_data = (value_type*)ImGui::MemAlloc(new_capacity * sizeof(value_type));
memcpy(new_data, Data, Size * sizeof(value_type));
ImGui::MemFree(Data);
Data = new_data;
Capacity = new_capacity;
}

inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; }
inline void pop_back() { IM_ASSERT(Size > 0); Size--; }

inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const ptrdiff_t off = it - begin(); memmove(Data + off, Data + off + 1, (Size - (size_t)off - 1) * sizeof(value_type)); Size--; return Data + off; }
inline iterator insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= begin() && it <= end()); const ptrdiff_t off = it - begin(); if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, (Size - (size_t)off) * sizeof(value_type)); Data[off] = v; Size++; return Data + off; }
};
#endif // #ifndef ImVector

// Helpers at bottom of the file:
// - IMGUI_ONCE_UPON_A_FRAME // Execute a block of code once per frame only (convenient for creating UI within deep-nested code that runs multiple times)
// - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
// - struct ImDrawList // Draw command list
// - struct ImFont // TTF font loader, bake glyphs into bitmap

// ImGui end-user API
// In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types)
namespace ImGui
{
// Main
IMGUI_API ImGuiIO& GetIO();
IMGUI_API ImGuiStyle& GetStyle();
IMGUI_API void NewFrame();
IMGUI_API void Render();
IMGUI_API void Shutdown();
IMGUI_API void ShowUserGuide();
IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL);
IMGUI_API void ShowTestWindow(bool* open = NULL);

// Window
// See implementation in .cpp for details
IMGUI_API bool Begin(const char* name = "Debug", bool* p_opened = NULL, const ImVec2& initial_size = ImVec2(0,0), float bg_alpha = -1.0f, ImGuiWindowFlags flags = 0); // return false when window is collapsed, so you can early out in your code. passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
IMGUI_API void End();
IMGUI_API bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). on each axis.
IMGUI_API bool BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // "
IMGUI_API void EndChild();
IMGUI_API bool GetWindowIsFocused();
IMGUI_API ImVec2 GetContentRegionMax(); // window or current column boundaries, in windows coordinates
IMGUI_API ImVec2 GetWindowContentRegionMin(); // window boundaries, in windows coordinates
IMGUI_API ImVec2 GetWindowContentRegionMax();
IMGUI_API ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
IMGUI_API ImFont* GetWindowFont();
IMGUI_API float GetWindowFontSize(); // size (also height in pixels) of current font with current scale applied
IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows.
IMGUI_API ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to do your own drawing.
IMGUI_API ImVec2 GetWindowSize(); // get current window position.
IMGUI_API float GetWindowWidth();
IMGUI_API bool GetWindowCollapsed();

IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position - call before Begin().
IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit.
IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set next window collapsed state.
IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most
IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set current window position - call within Begin()/End(). may incur tearing.
IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing.
IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set current window collapsed state.
IMGUI_API void SetWindowFocus(); // set current window to be focused / front-most
IMGUI_API void SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond = 0); // set named window position - call within Begin()/End(). may incur tearing.
IMGUI_API void SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond = 0); // set named window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing.
IMGUI_API void SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond = 0); // set named window collapsed state.
IMGUI_API void SetWindowFocus(const char* name); // set named window to be focused / front-most

IMGUI_API float GetScrollPosY(); // get scrolling position (0..GetScrollMaxY())
IMGUI_API float GetScrollMaxY(); // get maximum scrolling position == ContentSize.Y - WindowSize.Y
IMGUI_API void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position.
IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget.
IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
IMGUI_API ImGuiStorage* GetStateStorage();

// Parameters stacks (shared)
IMGUI_API void PushFont(ImFont* font); // use NULL as a shortcut to push default font
IMGUI_API void PopFont();
IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4& col);
IMGUI_API void PopStyleColor(int count = 1);
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val);
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val);
IMGUI_API void PopStyleVar(int count = 1);

// Parameters stacks (current window)
IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case, pixels. 0.0f = default to ~2/3 of windows width, >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -0.01f always align width to the right side)
IMGUI_API void PopItemWidth();
IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position
IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets.
IMGUI_API void PopAllowKeyboardFocus();
IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space.
IMGUI_API void PopTextWrapPos();

// Tooltip
IMGUI_API void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins.
IMGUI_API void SetTooltipV(const char* fmt, va_list args);
IMGUI_API void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text.
IMGUI_API void EndTooltip();

// Layout
IMGUI_API void Separator(); // horizontal line
IMGUI_API void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets to layout them horizontally
IMGUI_API void Spacing();
IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns
IMGUI_API void NextColumn(); // next column
IMGUI_API int GetColumnIndex(); // get current column index
IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetcolumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this.
IMGUI_API void SetColumnOffset(int column_index, float offset_x); // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column.
IMGUI_API float GetColumnWidth(int column_index = -1); // column width (== GetColumnOffset(GetColumnIndex()+1) - GetColumnOffset(GetColumnOffset())
IMGUI_API int GetColumnsCount(); // number of columns (what was passed to Columns())
IMGUI_API ImVec2 GetCursorPos(); // cursor position is relative to window position
IMGUI_API float GetCursorPosX(); // "
IMGUI_API float GetCursorPosY(); // "
IMGUI_API void SetCursorPos(const ImVec2& pos); // "
IMGUI_API void SetCursorPosX(float x); // "
IMGUI_API void SetCursorPosY(float y); // "
IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute screen coordinates (0..io.DisplaySize)
IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates (0..io.DisplaySize)
IMGUI_API void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets.
IMGUI_API float GetTextLineHeight(); // height of font == GetWindowFontSize()
IMGUI_API float GetTextLineHeightWithSpacing(); // spacing (in pixels) between 2 consecutive lines of text == GetWindowFontSize() + GetStyle().ItemSpacing.y

// ID scopes
// If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them.
// You can also use "##extra" within your widget name to distinguish them from each others (see 'Programmer Guide')
IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack!
IMGUI_API void PushID(const void* ptr_id);
IMGUI_API void PushID(const int int_id);
IMGUI_API void PopID();
IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). useful if you want to query into ImGuiStorage yourself. otherwise rarely needed.
IMGUI_API ImGuiID GetID(const void* ptr_id);

// Widgets
IMGUI_API void Text(const char* fmt, ...);
IMGUI_API void TextV(const char* fmt, va_list args);
IMGUI_API void TextColored(const ImVec4& col, const char* fmt, ...); // shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextColoredV(const ImVec4& col, const char* fmt, va_list args);
IMGUI_API void TextWrapped(const char* fmt, ...); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();
IMGUI_API void TextWrappedV(const char* fmt, va_list args);
IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text.
IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets
IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args);
IMGUI_API void Bullet();
IMGUI_API void BulletText(const char* fmt, ...);
IMGUI_API void BulletTextV(const char* fmt, va_list args);
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0), bool repeat_when_held = false);
IMGUI_API bool SmallButton(const char* label);
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size);
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,1), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no paddnig.
IMGUI_API bool CollapsingHeader(const char* label, const char* str_id = NULL, bool display_frame = true, bool default_open = false);
IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders.
IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); // *v in radians
IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format = "%.0f");
IMGUI_API void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
IMGUI_API void PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
IMGUI_API void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
IMGUI_API void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
IMGUI_API bool Checkbox(const char* label, bool* v);
IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
IMGUI_API bool RadioButton(const char* label, bool active);
IMGUI_API bool RadioButton(const char* label, int* v, int v_button);
IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
IMGUI_API bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0);
IMGUI_API bool InputFloat2(const char* label, float v[2], int decimal_precision = -1);
IMGUI_API bool InputFloat3(const char* label, float v[3], int decimal_precision = -1);
IMGUI_API bool InputFloat4(const char* label, float v[4], int decimal_precision = -1);
IMGUI_API bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100, ImGuiInputTextFlags extra_flags = 0);
IMGUI_API bool Combo(const char* label, int* current_item, const char** items, int items_count, int height_in_items = -1);
IMGUI_API bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items = -1); // separate items with \0, end item-list with \0\0
IMGUI_API bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1);
IMGUI_API bool ColorButton(const ImVec4& col, bool small_height = false, bool outline_border = true);
IMGUI_API bool ColorEdit3(const char* label, float col[3]);
IMGUI_API bool ColorEdit4(const char* label, float col[4], bool show_alpha = true);
IMGUI_API void ColorEditMode(ImGuiColorEditMode mode);

// Trees
IMGUI_API bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop
IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...); // "
IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...); // "
IMGUI_API bool TreeNodeV(const char* str_id, const char* fmt, va_list args); // "
IMGUI_API bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args); // "
IMGUI_API void TreePush(const char* str_id = NULL); // already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose
IMGUI_API void TreePush(const void* ptr_id = NULL); // "
IMGUI_API void TreePop();
IMGUI_API void SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond = 0); // set next tree node to be opened.

// Selectable / Lists
IMGUI_API bool Selectable(const char* label, bool selected, const ImVec2& size = ImVec2(0,0));
IMGUI_API bool Selectable(const char* label, bool* p_selected, const ImVec2& size = ImVec2(0,0));
IMGUI_API bool ListBox(const char* label, int* current_item, const char** items, int items_count, int height_in_items = -1);
IMGUI_API bool ListBox(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1);
IMGUI_API bool ListBoxHeader(const char* label, const ImVec2& size = ImVec2(0,0)); // use if you want to reimplement ListBox() will custom data or interactions. make sure to call ListBoxFooter() afterwards.
IMGUI_API bool ListBoxHeader(const char* label, int items_count, int height_in_items = -1); // "
IMGUI_API void ListBoxFooter(); // terminate the scrolling region

// Value() Helpers: output single value in "name: value" format. Tip: freely declare your own within the ImGui namespace!
IMGUI_API void Value(const char* prefix, bool b);
IMGUI_API void Value(const char* prefix, int v);
IMGUI_API void Value(const char* prefix, unsigned int v);
IMGUI_API void Value(const char* prefix, float v, const char* float_format = NULL);
IMGUI_API void Color(const char* prefix, const ImVec4& v);
IMGUI_API void Color(const char* prefix, unsigned int v);

// Logging: All text output from your interface are redirected to tty/file/clipboard. Tree nodes are automatically opened.
IMGUI_API void LogToTTY(int max_depth = -1); // start logging to tty
IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL); // start logging to file
IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard
IMGUI_API void LogFinish(); // stop logging (close file, etc.)
IMGUI_API void LogButtons(); // helper to display buttons for logging to tty/file/clipboard
IMGUI_API void LogText(const char* fmt, ...); // pass text data straight to log (without being displayed)

// Utilities
IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse?
IMGUI_API bool IsItemActive(); // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false)
IMGUI_API bool IsAnyItemActive(); //
IMGUI_API ImVec2 GetItemBoxMin(); // get bounding box of last item
IMGUI_API ImVec2 GetItemBoxMax(); // get bounding box of last item
IMGUI_API bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimization)
IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry
IMGUI_API bool IsMouseClicked(int button, bool repeat = false);
IMGUI_API bool IsMouseDoubleClicked(int button);
IMGUI_API bool IsMouseHoveringWindow(); // is mouse hovering current window ("window" in API names always refer to current window)
IMGUI_API bool IsMouseHoveringAnyWindow(); // is mouse hovering any active imgui window
IMGUI_API bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max); // is mouse hovering given bounding box
IMGUI_API bool IsPosHoveringAnyWindow(const ImVec2& pos); // is given position hovering any active imgui window
IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
IMGUI_API float GetTime();
IMGUI_API int GetFrameCount();
IMGUI_API const char* GetStyleColName(ImGuiCol idx);
IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f);
IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // helper to manually clip large list of items. see comments in implementation.

IMGUI_API void BeginChildFrame(ImGuiID id, const ImVec2& size); // helper to create a child window / scrolling region that looks like a normal widget frame.
IMGUI_API void EndChildFrame();

IMGUI_API ImU32 ColorConvertFloat4ToU32(const ImVec4& in);
IMGUI_API void ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v);
IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b);

// Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself
IMGUI_API const char* GetVersion();
IMGUI_API void* GetInternalState();
IMGUI_API size_t GetInternalStateSize();
IMGUI_API void SetInternalState(void* state, bool construct = false);

// Obsolete (will be removed)
IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
static inline void OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); }

} // namespace ImGui

// Flags for ImGui::Begin()
enum ImGuiWindowFlags_
{
// Default: 0
ImGuiWindowFlags_NoTitleBar = 1 << 0, // Disable title-bar
ImGuiWindowFlags_NoResize = 1 << 1, // Disable user resizing with the lower-right grip
ImGuiWindowFlags_NoMove = 1 << 2, // Disable user moving the window
ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scrollbar (window can still scroll with mouse or programatically)
ImGuiWindowFlags_NoScrollWithMouse = 1 << 4, // Disable user scrolling with mouse wheel
ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it
ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame
ImGuiWindowFlags_ShowBorders = 1 << 7, // Show borders around windows and items
ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file
// [Internal]
ImGuiWindowFlags_ChildWindow = 1 << 9, // For internal use by BeginChild()
ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 10, // For internal use by BeginChild()
ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 11, // For internal use by BeginChild()
ImGuiWindowFlags_ComboBox = 1 << 12, // For internal use by ComboBox()
ImGuiWindowFlags_Tooltip = 1 << 13 // For internal use by BeginTooltip()
};

// Flags for ImGui::InputText()
enum ImGuiInputTextFlags_
{
// Default: 0
ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/
ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef
ImGuiInputTextFlags_CharsUppercase = 1 << 2, // Turn a..z into A..Z
ImGuiInputTextFlags_CharsNoBlank = 1 << 3, // Filter out spaces, tabs
ImGuiInputTextFlags_AutoSelectAll = 1 << 4, // Select entire text when first taking mouse focus
ImGuiInputTextFlags_EnterReturnsTrue = 1 << 5, // Return 'true' when Enter is pressed (as opposed to when the value was modified)
ImGuiInputTextFlags_CallbackCompletion = 1 << 6, // Call user function on pressing TAB (for completion handling)
ImGuiInputTextFlags_CallbackHistory = 1 << 7, // Call user function on pressing Up/Down arrows (for history handling)
ImGuiInputTextFlags_CallbackAlways = 1 << 8, // Call user function every time
ImGuiInputTextFlags_CallbackCharFilter = 1 << 9 // Call user function to filter character. Modify data->EventChar to replace/filter input, or return 1 to discard character.
};

// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
enum ImGuiKey_
{
ImGuiKey_Tab,
ImGuiKey_LeftArrow,
ImGuiKey_RightArrow,
ImGuiKey_UpArrow,
ImGuiKey_DownArrow,
ImGuiKey_Home,
ImGuiKey_End,
ImGuiKey_Delete,
ImGuiKey_Backspace,
ImGuiKey_Enter,
ImGuiKey_Escape,
ImGuiKey_A, // for CTRL+A: select all
ImGuiKey_C, // for CTRL+C: copy
ImGuiKey_V, // for CTRL+V: paste
ImGuiKey_X, // for CTRL+X: cut
ImGuiKey_Y, // for CTRL+Y: redo
ImGuiKey_Z, // for CTRL+Z: undo
ImGuiKey_COUNT
};

// Enumeration for PushStyleColor() / PopStyleColor()
enum ImGuiCol_
{
ImGuiCol_Text,
ImGuiCol_WindowBg,
ImGuiCol_ChildWindowBg,
ImGuiCol_Border,
ImGuiCol_BorderShadow,
ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input
ImGuiCol_TitleBg,
ImGuiCol_TitleBgCollapsed,
ImGuiCol_ScrollbarBg,
ImGuiCol_ScrollbarGrab,
ImGuiCol_ScrollbarGrabHovered,
ImGuiCol_ScrollbarGrabActive,
ImGuiCol_ComboBg,
ImGuiCol_CheckHovered,
ImGuiCol_CheckActive,
ImGuiCol_CheckMark,
ImGuiCol_SliderGrab,
ImGuiCol_SliderGrabActive,
ImGuiCol_Button,
ImGuiCol_ButtonHovered,
ImGuiCol_ButtonActive,
ImGuiCol_Header,
ImGuiCol_HeaderHovered,
ImGuiCol_HeaderActive,
ImGuiCol_Column,
ImGuiCol_ColumnHovered,
ImGuiCol_ColumnActive,
ImGuiCol_ResizeGrip,
ImGuiCol_ResizeGripHovered,
ImGuiCol_ResizeGripActive,
ImGuiCol_CloseButton,
ImGuiCol_CloseButtonHovered,
ImGuiCol_CloseButtonActive,
ImGuiCol_PlotLines,
ImGuiCol_PlotLinesHovered,
ImGuiCol_PlotHistogram,
ImGuiCol_PlotHistogramHovered,
ImGuiCol_TextSelectedBg,
ImGuiCol_TooltipBg,
ImGuiCol_COUNT
};

// Enumeration for PushStyleVar() / PopStyleVar()
// NB: the enum only refers to fields of ImGuiStyle() which makes sense to be pushed/poped in UI code. Feel free to add others.
enum ImGuiStyleVar_
{
ImGuiStyleVar_Alpha, // float
ImGuiStyleVar_WindowPadding, // ImVec2
ImGuiStyleVar_WindowRounding, // float
ImGuiStyleVar_ChildWindowRounding, // float
ImGuiStyleVar_FramePadding, // ImVec2
ImGuiStyleVar_FrameRounding, // float
ImGuiStyleVar_ItemSpacing, // ImVec2
ImGuiStyleVar_ItemInnerSpacing, // ImVec2
ImGuiStyleVar_TreeNodeSpacing // float
};

// Enumeration for ColorEditMode()
enum ImGuiColorEditMode_
{
ImGuiColorEditMode_UserSelect = -2,
ImGuiColorEditMode_UserSelectShowButton = -1,
ImGuiColorEditMode_RGB = 0,
ImGuiColorEditMode_HSV = 1,
ImGuiColorEditMode_HEX = 2
};

// Condition flags for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions
// All those functions treat 0 as a shortcut to ImGuiSetCond_Always
enum ImGuiSetCond_
{
ImGuiSetCond_Always = 1 << 0, // Set the variable
ImGuiSetCond_Once = 1 << 1, // Only set the variable on the first call per runtime session
ImGuiSetCond_FirstUseEver = 1 << 2 // Only set the variable if the window doesn't exist in the .ini file
};

struct ImGuiStyle
{
float Alpha; // Global alpha applies to everything in ImGui
ImVec2 WindowPadding; // Padding within a window
ImVec2 WindowMinSize; // Minimum window size
float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
float ChildWindowRounding; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows
ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets)
float FrameRounding; // Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets).
ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines
ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much!
ImVec2 AutoFitPadding; // Extra space after auto-fit (double-clicking on resize grip)
float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin()
float TreeNodeSpacing; // Horizontal spacing when entering a tree node
float ColumnsMinSpacing; // Minimum horizontal spacing between two columns
float ScrollbarWidth; // Width of the vertical scrollbar
float GrabMinSize; // Minimum width/height of a slider or scrollbar grab
ImVec4 Colors[ImGuiCol_COUNT];

IMGUI_API ImGuiStyle();
};

// This is where your app communicate with ImGui. Call ImGui::GetIO() to access.
// Read 'Programmer guide' section in .cpp file for general usage.
struct ImGuiIO
{
//------------------------------------------------------------------
// Settings (fill once) // Default value:
//------------------------------------------------------------------

ImVec2 DisplaySize; // <unset> // Display size, in pixels. For clamping windows positions.
float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds.
float IniSavingRate; // = 5.0f // Maximum time between saving positions/sizes to .ini file, in seconds.
const char* IniFilename; // = "imgui.ini" // Path to .ini file. NULL to disable .ini saving.
const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified).
float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds.
float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
void* UserData; // = NULL // Store your own data for retrieval by callbacks.

ImFontAtlas* Fonts; // <auto> // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array.
float FontGlobalScale; // = 1.0f // Global scale all fonts
bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
ImVec2 DisplayVisibleMin; // <unset> (0.0f,0.0f) // If you use DisplaySize as a virtual space larger than your screen, set DisplayVisibleMin/Max to the visible area.
ImVec2 DisplayVisibleMax; // <unset> (0.0f,0.0f) // If the values are the same, we defaults to Min=(0.0f) and Max=DisplaySize

//------------------------------------------------------------------
// User Functions
//------------------------------------------------------------------

// REQUIRED: rendering function.
// See example code if you are unsure of how to implement this.
void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);

// Optional: access OS clipboard
// (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures)
const char* (*GetClipboardTextFn)();
void (*SetClipboardTextFn)(const char* text);

// Optional: override memory allocations. MemFreeFn() may be called with a NULL pointer.
// (default to posix malloc/free)
void* (*MemAllocFn)(size_t sz);
void (*MemFreeFn)(void* ptr);

// Optional: notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese IME in Windows)
// (default to use native imm32 api on Windows)
void (*ImeSetInputScreenPosFn)(int x, int y);
void* ImeWindowHandle; // (Windows) Set this to your HWND to get automatic IME cursor positioning.

//------------------------------------------------------------------
// Input - Fill before calling NewFrame()
//------------------------------------------------------------------

ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button). Others buttons allows to track if mouse is being used by your application + available to user as a convenience via IsMouse** API.
float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text.
bool MouseDrawCursor; // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor).
bool KeyCtrl; // Keyboard modifier pressed: Control
bool KeyShift; // Keyboard modifier pressed: Shift
bool KeysDown[512]; // Keyboard keys that are pressed (in whatever storage order you naturally have access to keyboard data)
ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.

// Function
IMGUI_API void AddInputCharacter(ImWchar c); // Helper to add a new character into InputCharacters[]

//------------------------------------------------------------------
// Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application
//------------------------------------------------------------------

bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input)
float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames

//------------------------------------------------------------------
// [Internal] ImGui will maintain those fields for you
//------------------------------------------------------------------

ImVec2 MousePosPrev; // Previous mouse position
ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are negative to allow mouse enabling/disabling.
bool MouseClicked[5]; // Mouse button went from !Down to Down
ImVec2 MouseClickedPos[5]; // Position at time of clicking
float MouseClickedTime[5]; // Time of last click (used to figure out double-click)
bool MouseDoubleClicked[5]; // Has mouse button been double-clicked?
bool MouseDownOwned[5]; // Track if button was clicked inside a window. We don't request mouse capture from the application if click started outside ImGui bounds.
float MouseDownTime[5]; // Time the mouse button has been down
float KeysDownTime[512]; // Time the keyboard key has been down

IMGUI_API ImGuiIO();
};

//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------

// Helper: execute a block of code once a frame only
// Convenient if you want to quickly create an UI within deep-nested code that runs multiple times every frame.
// Usage:
// IMGUI_ONCE_UPON_A_FRAME
// {
// // code block will be executed one per frame
// }
// Attention! the macro expands into 2 statement so make sure you don't use it within e.g. an if() statement without curly braces.
#define IMGUI_ONCE_UPON_A_FRAME static ImGuiOnceUponAFrame imgui_oaf##__LINE__; if (imgui_oaf##__LINE__)
struct ImGuiOnceUponAFrame
{
ImGuiOnceUponAFrame() { RefFrame = -1; }
mutable int RefFrame;
operator bool() const { const int current_frame = ImGui::GetFrameCount(); if (RefFrame == current_frame) return false; RefFrame = current_frame; return true; }
};

// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
struct ImGuiTextFilter
{
struct TextRange
{
const char* b;
const char* e;

TextRange() { b = e = NULL; }
TextRange(const char* _b, const char* _e) { b = _b; e = _e; }
const char* begin() const { return b; }
const char* end() const { return e; }
bool empty() const { return b == e; }
char front() const { return *b; }
static bool isblank(char c) { return c == ' ' || c == '\t'; }
void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; }
IMGUI_API void split(char separator, ImVector<TextRange>& out);
};

char InputBuf[256];
ImVector<TextRange> Filters;
int CountGrep;

ImGuiTextFilter(const char* default_filter = "");
void Clear() { InputBuf[0] = 0; Build(); }
void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f); // Helper calling InputText+Build
bool PassFilter(const char* val) const;
bool IsActive() const { return !Filters.empty(); }
IMGUI_API void Build();
};

// Helper: Text buffer for logging/accumulating text
struct ImGuiTextBuffer
{
ImVector<char> Buf;

ImGuiTextBuffer() { Buf.push_back(0); }
~ImGuiTextBuffer() { }
const char* begin() const { return &Buf.front(); }
const char* end() const { return &Buf.back(); } // Buf is zero-terminated, so end() will point on the zero-terminator
size_t size() const { return Buf.size()-1; }
bool empty() { return size() >= 1; }
void clear() { Buf.clear(); Buf.push_back(0); }
IMGUI_API void append(const char* fmt, ...);
IMGUI_API void appendv(const char* fmt, va_list args);
};

// Helper: Key->value storage
// - Store collapse state for a tree (Int 0/1)
// - Store color edit options (Int using values in ImGuiColorEditMode enum).
// - Custom user storage for temporary values.
// Typically you don't have to worry about this since a storage is held within each Window.
// Declare your own storage if:
// - You want to manipulate the open/close state of a particular sub-tree in your interface (tree node uses Int 0/1 to store their state).
// - You want to store custom debug data easily without adding or editing structures in your code.
struct ImGuiStorage
{
struct Pair
{
ImGuiID key;
union { int val_i; float val_f; void* val_p; };
Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
};
ImVector<Pair> Data;

// - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N)
// - Set***() functions find pair, insertion on demand if missing.
// - Sorted insertion is costly but should amortize. A typical frame shouldn't need to insert any new pair.
IMGUI_API void Clear();
IMGUI_API int GetInt(ImGuiID key, int default_val = 0) const;
IMGUI_API void SetInt(ImGuiID key, int val);
IMGUI_API float GetFloat(ImGuiID key, float default_val = 0.0f) const;
IMGUI_API void SetFloat(ImGuiID key, float val);
IMGUI_API void* GetVoidPtr(ImGuiID key) const; // default_val is NULL
IMGUI_API void SetVoidPtr(ImGuiID key, void* val);

// - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set.
// - References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer.
// - A typical use case where this is convenient:
// float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar;
// - You can also use this to quickly create temporary editable values during a session of using Edit&Continue, without restarting your application.
IMGUI_API int* GetIntRef(ImGuiID key, int default_val = 0);
IMGUI_API float* GetFloatRef(ImGuiID key, float default_val = 0);

// Use on your own storage if you know only integer are being stored (open/close all tree nodes)
IMGUI_API void SetAllInt(int val);
};

// Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used.
struct ImGuiTextEditCallbackData
{
ImGuiInputTextFlags EventFlag; // One of ImGuiInputTextFlags_Callback* // Read-only
ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only
void* UserData; // What user passed to InputText() // Read-only

// CharFilter event:
ImWchar EventChar; // Character input // Read-write (replace character or set to zero)

// Completion,History,Always events:
ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only
char* Buf; // Current text // Read-write (pointed data only)
size_t BufSize; // // Read-only
bool BufDirty; // Set if you modify Buf directly // Write
int CursorPos; // // Read-write
int SelectionStart; // // Read-write (== to SelectionEnd when no selection)
int SelectionEnd; // // Read-write

// NB: calling those function loses selection.
void DeleteChars(int pos, int bytes_count);
void InsertChars(int pos, const char* text, const char* text_end = NULL);
};

// ImColor() is just a helper that implicity converts to either ImU32 (packed 4x1 byte) or ImVec4 (4x1 float)
// None of the ImGui API are using ImColor directly but you can use it as a convenience to pass colors in either formats.
struct ImColor
{
ImVec4 Value;

ImColor(int r, int g, int b, int a = 255) { Value.x = (float)r / 255.0f; Value.y = (float)g / 255.0f; Value.z = (float)b / 255.0f; Value.w = (float)a / 255.0f; }
ImColor(float r, float g, float b, float a = 1.0f) { Value.x = r; Value.y = g; Value.z = b; Value.w = a; }
ImColor(const ImVec4& col) { Value = col; }
operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); }
operator ImVec4() const { return Value; }

static ImColor HSV(float h, float s, float v, float a = 1.0f) { float r,g,b; ImGui::ColorConvertHSVtoRGB(h, s, v, r, g, b); return ImColor(r,g,b,a); }
};

//-----------------------------------------------------------------------------
// Draw List
// Hold a series of drawing commands. The user provides a renderer for ImDrawList.
//-----------------------------------------------------------------------------

// Draw callbacks for advanced uses.
// NB- You most likely DO NOT need to care about draw callbacks just to create your own widget or customized UI rendering (you can poke into the draw list for that)
// Draw callback are useful for example if you want to render a complex 3D scene inside a UI element.
// The expected behavior from your rendering loop is:
// if (cmd.user_callback != NULL)
// cmd.user_callback(parent_list, cmd);
// else
// RenderTriangles()
// It is up to you to decide if your rendering loop or the callback should be responsible for backup/restoring rendering state.
typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd);

// Typically, 1 command = 1 gpu draw call (unless command is a callback)
struct ImDrawCmd
{
unsigned int vtx_count; // Number of vertices (multiple of 3) to be drawn as triangles. The vertices are stored in the callee ImDrawList's vtx_buffer[] array.
ImVec4 clip_rect; // Clipping rectangle (x1, y1, x2, y2)
ImTextureID texture_id; // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas.
ImDrawCallback user_callback; // If != NULL, call the function instead of rendering the vertices. vtx_count will be 0. clip_rect and texture_id will be set normally.
void* user_callback_data; // The draw callback code can access this.
};

// Vertex layout
#ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT
struct ImDrawVert
{
ImVec2 pos;
ImVec2 uv;
ImU32 col;
};
#else
// You can change the vertex format layout by defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT in imconfig.h
// The code expect ImVec2 pos (8 bytes), ImVec2 uv (8 bytes), ImU32 col (4 bytes), but you can re-order them or add other fields as needed to simplify integration in your engine.
// The type has to be described by the #define (you can either declare the struct or use a typedef)
IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT;
#endif

// Draw command list
// This is the low-level list of polygons that ImGui functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
// At the moment, each ImGui window contains its own ImDrawList but they could potentially be merged in the future.
// If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives.
// You can interleave normal ImGui:: calls and adding primitives to the current draw list.
// Note that this only gives you access to rendering polygons. If your intent is to create custom widgets and the publicly exposed functions/data aren't sufficient, you can add code in imgui_user.inl
struct ImDrawList
{
// This is what you have to render
ImVector<ImDrawCmd> commands; // Commands. Typically 1 command = 1 gpu draw call.
ImVector<ImDrawVert> vtx_buffer; // Vertex buffer. Each command consume ImDrawCmd::vtx_count of those

// [Internal to ImGui]
ImVector<ImVec4> clip_rect_stack; // [Internal]
ImVector<ImTextureID> texture_id_stack; // [Internal]
ImDrawVert* vtx_write; // [Internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)

ImDrawList() { Clear(); }
IMGUI_API void Clear();
IMGUI_API void PushClipRect(const ImVec4& clip_rect); // Scissoring. The values are x1, y1, x2, y2.
IMGUI_API void PopClipRect();
IMGUI_API void PushTextureID(const ImTextureID& texture_id);
IMGUI_API void PopTextureID();

// Primitives
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col);
IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
IMGUI_API void AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris = false, const ImVec2& third_point_offset = ImVec2(0,0));
IMGUI_API void AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec2* cpu_clip_max = NULL);
IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col = 0xFFFFFFFF);

// Advanced
IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'user_callback' in ImDrawCmd and call the function instead of rendering triangles.
IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible

// Internal helpers
IMGUI_API void ReserveVertices(unsigned int vtx_count);
IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col);
IMGUI_API void AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv);
IMGUI_API void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col);
IMGUI_API void UpdateClipRect();
IMGUI_API void UpdateTextureID();
};

// Load and rasterize multiple TTF fonts into a same texture.
// Sharing a texture for multiple fonts allows us to reduce the number of draw calls during rendering.
// We also add custom graphic data into the texture that serves for ImGui.
// 1. (Optional) Call AddFont*** functions. If you don't call any, the default font will be loaded for you.
// 2. Call GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data.
// 3. Upload the pixels data into a texture within your graphics system.
// 4. Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture. This value will be passed back to you during rendering to identify the texture.
// 5. Call ClearPixelsData() to free textures memory on the heap.
struct ImFontAtlas
{
IMGUI_API ImFontAtlas();
IMGUI_API ~ImFontAtlas();
IMGUI_API ImFont* AddFontDefault();
IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0);
IMGUI_API ImFont* AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_size, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0); // Pass ownership of 'in_ttf_data' memory.
IMGUI_API void ClearTexData(); // Saves RAM once the texture has been copied to graphics memory.
IMGUI_API void Clear();

// Retrieve texture data
// User is in charge of copying the pixels into graphics memory, then call SetTextureUserID()
// After loading the texture into your graphic system, store your texture handle in 'TexID' (ignore if you aren't using multiple fonts nor images)
// RGBA32 format is provided for convenience and high compatibility, but note that all RGB pixels are white, so 75% of the memory is wasted.
// Pitch = Width * BytesPerPixels
IMGUI_API void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 1 byte per-pixel
IMGUI_API void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 4 bytes-per-pixel
IMGUI_API void SetTexID(void* id) { TexID = id; }

// Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
// (Those functions could be static, aren't so simple use case doesn't have to refer to the ImFontAtlas:: type ever if in their code)
IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
IMGUI_API const ImWchar* GetGlyphRangesChinese(); // Japanese + full set of about 21000 CJK Unified Ideographs

// Members
// (Access texture data via GetTexData*() calls which will setup a default font for you.)
void* TexID; // User data to refer to the texture once it has been uploaded to user's graphic systems. It ia passed back to you during rendering.
unsigned char* TexPixelsAlpha8; // 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight
unsigned int* TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
int TexWidth;
int TexHeight;
ImVec2 TexExtraDataPos; // Position of our rectangle where we draw non-font graphics
ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block)
ImVector<ImFont*> Fonts;

// Private
struct ImFontAtlasData;
ImVector<ImFontAtlasData*> InputData; // Internal data
IMGUI_API bool Build(); // Build pixels data. This is automatically for you by the GetTexData*** functions.
IMGUI_API void ClearInputData(); // Clear the input TTF data.
IMGUI_API void RenderCustomTexData();
};

// TTF font loading and rendering
// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
// Kerning isn't supported. At the moment some ImGui code does per-character CalcTextSize calls, need something more state-ful.
struct ImFont
{
// Members: Settings
float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()

// Members: Runtime data
struct Glyph
{
ImWchar Codepoint;
signed short XAdvance;
signed short Width, Height;
signed short XOffset, YOffset;
float U0, V0, U1, V1; // Texture coordinates
};
ImFontAtlas* ContainerAtlas; // What we has been loaded into
ImVector<Glyph> Glyphs;
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
float FallbackXAdvance; //
ImVector<float> IndexXAdvance; // Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
ImVector<int> IndexLookup; // Index glyphs by Unicode code-point

// Methods
IMGUI_API ImFont();
IMGUI_API ~ImFont() { Clear(); }
IMGUI_API void Clear();
IMGUI_API void BuildLookupTable();
IMGUI_API const Glyph* FindGlyph(unsigned short c) const;
IMGUI_API void SetFallbackChar(ImWchar c);
IMGUI_API bool IsLoaded() const { return ContainerAtlas != NULL; }

// 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
// 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8
IMGUI_API ImVec2 CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL) const; // wchar
IMGUI_API void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width = 0.0f, const ImVec2* cpu_clip_max = NULL) const;
IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const;
};

//---- Include imgui_user.h at the end of imgui.h
//---- So you can include code that extends ImGui using any of the types declared above.
//---- (also convenient for user to only explicitly include vanilla imgui.h)
#ifdef IMGUI_INCLUDE_IMGUI_USER_H
#include "imgui_user.h"
#endif

+ 77
- 0
src/imgui/lolimgui.vcxproj Прегледај датотеку

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ORBIS">
<Configuration>Debug</Configuration>
<Platform>ORBIS</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Xbox 360">
<Configuration>Debug</Configuration>
<Platform>Xbox 360</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ORBIS">
<Configuration>Release</Configuration>
<Platform>ORBIS</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Xbox 360">
<Configuration>Release</Configuration>
<Platform>Xbox 360</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{A7F6FDF8-937E-41EF-B44D-04CD1A48C179}</ProjectGuid>
<ConfigurationType>StaticLibrary</ConfigurationType>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(SolutionDir)\msbuild\lol.config.props" />
<PropertyGroup Label="Configuration">
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)\msbuild\lol.vars.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<Import Project="$(SolutionDir)\msbuild\lol.rules.props" />
<ItemDefinitionGroup>
<ClCompile>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="imgui.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="imgui.h" />
<ClInclude Include="imconfig.h" />
<ClInclude Include="stb_rect_pack.h" />
<ClInclude Include="stb_textedit.h" />
<ClInclude Include="stb_truetype.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(SolutionDir)\msbuild\lolfx.targets" />
</ImportGroup>
</Project>

+ 1
- 0
src/imgui/revision.txt Прегледај датотеку

@@ -0,0 +1 @@
this is #127

+ 547
- 0
src/imgui/stb_rect_pack.h Прегледај датотеку

@@ -0,0 +1,547 @@
// stb_rect_pack.h - v0.05 - public domain - rectangle packing
// Sean Barrett 2014
//
// Useful for e.g. packing rectangular textures into an atlas.
// Does not do rotation.
//
// Not necessarily the awesomest packing method, but better than
// the totally naive one in stb_truetype (which is primarily what
// this is meant to replace).
//
// Has only had a few tests run, may have issues.
//
// More docs to come.
//
// No memory allocations; uses qsort() and assert() from stdlib.
//
// This library currently uses the Skyline Bottom-Left algorithm.
//
// Please note: better rectangle packers are welcome! Please
// implement them to the same API, but with a different init
// function.
//
// Version history:
//
// 0.05: added STBRP_ASSERT to allow replacing assert
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
// 0.01: initial release

//////////////////////////////////////////////////////////////////////////////
//
// INCLUDE SECTION
//

#ifndef STB_INCLUDE_STB_RECT_PACK_H
#define STB_INCLUDE_STB_RECT_PACK_H

#define STB_RECT_PACK_VERSION 1

#ifdef STBRP_STATIC
#define STBRP_DEF static
#else
#define STBRP_DEF extern
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct stbrp_context stbrp_context;
typedef struct stbrp_node stbrp_node;
typedef struct stbrp_rect stbrp_rect;

#ifdef STBRP_LARGE_RECTS
typedef int stbrp_coord;
#else
typedef unsigned short stbrp_coord;
#endif

STBRP_DEF void stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
// Assign packed locations to rectangles. The rectangles are of type
// 'stbrp_rect' defined below, stored in the array 'rects', and there
// are 'num_rects' many of them.
//
// Rectangles which are successfully packed have the 'was_packed' flag
// set to a non-zero value and 'x' and 'y' store the minimum location
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
// if you imagine y increasing downwards). Rectangles which do not fit
// have the 'was_packed' flag set to 0.
//
// You should not try to access the 'rects' array from another thread
// while this function is running, as the function temporarily reorders
// the array while it executes.
//
// To pack into another rectangle, you need to call stbrp_init_target
// again. To continue packing into the same rectangle, you can call
// this function again. Calling this multiple times with multiple rect
// arrays will probably produce worse packing results than calling it
// a single time with the full rectangle array, but the option is
// available.

struct stbrp_rect
{
// reserved for your use:
int id;

// input:
stbrp_coord w, h;

// output:
stbrp_coord x, y;
int was_packed; // non-zero if valid packing

}; // 16 bytes, nominally


STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
// Initialize a rectangle packer to:
// pack a rectangle that is 'width' by 'height' in dimensions
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
//
// You must call this function every time you start packing into a new target.
//
// There is no "shutdown" function. The 'nodes' memory must stay valid for
// the following stbrp_pack_rects() call (or calls), but can be freed after
// the call (or calls) finish.
//
// Note: to guarantee best results, either:
// 1. make sure 'num_nodes' >= 'width'
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
//
// If you don't do either of the above things, widths will be quantized to multiples
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
//
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
// may run out of temporary storage and be unable to pack some rectangles.

STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
// Optionally call this function after init but before doing any packing to
// change the handling of the out-of-temp-memory scenario, described above.
// If you call init again, this will be reset to the default (false).


STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
// Optionally select which packing heuristic the library should use. Different
// heuristics will produce better/worse results for different data sets.
// If you call init again, this will be reset to the default.

enum
{
STBRP_HEURISTIC_Skyline_default=0,
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
STBRP_HEURISTIC_Skyline_BF_sortHeight
};


//////////////////////////////////////////////////////////////////////////////
//
// the details of the following structures don't matter to you, but they must
// be visible so you can handle the memory allocations for them

struct stbrp_node
{
stbrp_coord x,y;
stbrp_node *next;
};

struct stbrp_context
{
int width;
int height;
int align;
int init_mode;
int heuristic;
int num_nodes;
stbrp_node *active_head;
stbrp_node *free_head;
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
};

#ifdef __cplusplus
}
#endif

#endif

//////////////////////////////////////////////////////////////////////////////
//
// IMPLEMENTATION SECTION
//

#ifdef STB_RECT_PACK_IMPLEMENTATION
#include <stdlib.h>

#ifndef STBRP_ASSERT
#include <assert.h>
#define STBRP_ASSERT assert
#endif

enum
{
STBRP__INIT_skyline = 1
};

STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
{
switch (context->init_mode) {
case STBRP__INIT_skyline:
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
context->heuristic = heuristic;
break;
default:
STBRP_ASSERT(0);
}
}

STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
{
if (allow_out_of_mem)
// if it's ok to run out of memory, then don't bother aligning them;
// this gives better packing, but may fail due to OOM (even though
// the rectangles easily fit). @TODO a smarter approach would be to only
// quantize once we've hit OOM, then we could get rid of this parameter.
context->align = 1;
else {
// if it's not ok to run out of memory, then quantize the widths
// so that num_nodes is always enough nodes.
//
// I.e. num_nodes * align >= width
// align >= width / num_nodes
// align = ceil(width/num_nodes)

context->align = (context->width + context->num_nodes-1) / context->num_nodes;
}
}

STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
{
int i;
#ifndef STBRP_LARGE_RECTS
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
#endif

for (i=0; i < num_nodes-1; ++i)
nodes[i].next = &nodes[i+1];
nodes[i].next = NULL;
context->init_mode = STBRP__INIT_skyline;
context->heuristic = STBRP_HEURISTIC_Skyline_default;
context->free_head = &nodes[0];
context->active_head = &context->extra[0];
context->width = width;
context->height = height;
context->num_nodes = num_nodes;
stbrp_setup_allow_out_of_mem(context, 0);

// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
context->extra[0].x = 0;
context->extra[0].y = 0;
context->extra[0].next = &context->extra[1];
context->extra[1].x = (stbrp_coord) width;
#ifdef STBRP_LARGE_RECTS
context->extra[1].y = (1<<30);
#else
context->extra[1].y = 65535;
#endif
context->extra[1].next = NULL;
}

// find minimum y position if it starts at x1
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
{
(void)c;
stbrp_node *node = first;
int x1 = x0 + width;
int min_y, visited_width, waste_area;
STBRP_ASSERT(first->x <= x0);

#if 0
// skip in case we're past the node
while (node->next->x <= x0)
++node;
#else
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
#endif

STBRP_ASSERT(node->x <= x0);

min_y = 0;
waste_area = 0;
visited_width = 0;
while (node->x < x1) {
if (node->y > min_y) {
// raise min_y higher.
// we've accounted for all waste up to min_y,
// but we'll now add more waste for everything we've visted
waste_area += visited_width * (node->y - min_y);
min_y = node->y;
// the first time through, visited_width might be reduced
if (node->x < x0)
visited_width += node->next->x - x0;
else
visited_width += node->next->x - node->x;
} else {
// add waste area
int under_width = node->next->x - node->x;
if (under_width + visited_width > width)
under_width = width - visited_width;
waste_area += under_width * (min_y - node->y);
visited_width += under_width;
}
node = node->next;
}

*pwaste = waste_area;
return min_y;
}

typedef struct
{
int x,y;
stbrp_node **prev_link;
} stbrp__findresult;

static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
{
int best_waste = (1<<30), best_x, best_y = (1 << 30);
stbrp__findresult fr;
stbrp_node **prev, *node, *tail, **best = NULL;

// align to multiple of c->align
width = (width + c->align - 1);
width -= width % c->align;
STBRP_ASSERT(width % c->align == 0);

node = c->active_head;
prev = &c->active_head;
while (node->x + width <= c->width) {
int y,waste;
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
// bottom left
if (y < best_y) {
best_y = y;
best = prev;
}
} else {
// best-fit
if (y + height <= c->height) {
// can only use it if it first vertically
if (y < best_y || (y == best_y && waste < best_waste)) {
best_y = y;
best_waste = waste;
best = prev;
}
}
}
prev = &node->next;
node = node->next;
}

best_x = (best == NULL) ? 0 : (*best)->x;

// if doing best-fit (BF), we also have to try aligning right edge to each node position
//
// e.g, if fitting
//
// ____________________
// |____________________|
//
// into
//
// | |
// | ____________|
// |____________|
//
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
//
// This makes BF take about 2x the time

if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
tail = c->active_head;
node = c->active_head;
prev = &c->active_head;
// find first node that's admissible
while (tail->x < width)
tail = tail->next;
while (tail) {
int xpos = tail->x - width;
int y,waste;
STBRP_ASSERT(xpos >= 0);
// find the left position that matches this
while (node->next->x <= xpos) {
prev = &node->next;
node = node->next;
}
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
if (y + height < c->height) {
if (y <= best_y) {
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
best_x = xpos;
STBRP_ASSERT(y <= best_y);
best_y = y;
best_waste = waste;
best = prev;
}
}
}
tail = tail->next;
}
}

fr.prev_link = best;
fr.x = best_x;
fr.y = best_y;
return fr;
}

static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
{
// find best position according to heuristic
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
stbrp_node *node, *cur;

// bail if:
// 1. it failed
// 2. the best node doesn't fit (we don't always check this)
// 3. we're out of memory
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
res.prev_link = NULL;
return res;
}

// on success, create new node
node = context->free_head;
node->x = (stbrp_coord) res.x;
node->y = (stbrp_coord) (res.y + height);

context->free_head = node->next;

// insert the new node into the right starting point, and
// let 'cur' point to the remaining nodes needing to be
// stiched back in

cur = *res.prev_link;
if (cur->x < res.x) {
// preserve the existing one, so start testing with the next one
stbrp_node *next = cur->next;
cur->next = node;
cur = next;
} else {
*res.prev_link = node;
}

// from here, traverse cur and free the nodes, until we get to one
// that shouldn't be freed
while (cur->next && cur->next->x <= res.x + width) {
stbrp_node *next = cur->next;
// move the current node to the free list
cur->next = context->free_head;
context->free_head = cur;
cur = next;
}

// stitch the list back in
node->next = cur;

if (cur->x < res.x + width)
cur->x = (stbrp_coord) (res.x + width);

#ifdef _DEBUG
cur = context->active_head;
while (cur->x < context->width) {
STBRP_ASSERT(cur->x < cur->next->x);
cur = cur->next;
}
STBRP_ASSERT(cur->next == NULL);

{
stbrp_node *L1 = NULL, *L2 = NULL;
int count=0;
cur = context->active_head;
while (cur) {
L1 = cur;
cur = cur->next;
++count;
}
cur = context->free_head;
while (cur) {
L2 = cur;
cur = cur->next;
++count;
}
STBRP_ASSERT(count == context->num_nodes+2);
}
#endif

return res;
}

static int rect_height_compare(const void *a, const void *b)
{
stbrp_rect *p = (stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b;
if (p->h > q->h)
return -1;
if (p->h < q->h)
return 1;
return (p->w > q->w) ? -1 : (p->w < q->w);
}

static int rect_width_compare(const void *a, const void *b)
{
stbrp_rect *p = (stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b;
if (p->w > q->w)
return -1;
if (p->w < q->w)
return 1;
return (p->h > q->h) ? -1 : (p->h < q->h);
}

static int rect_original_order(const void *a, const void *b)
{
stbrp_rect *p = (stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b;
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
}

#ifdef STBRP_LARGE_RECTS
#define STBRP__MAXVAL 0xffffffff
#else
#define STBRP__MAXVAL 0xffff
#endif

STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
{
int i;

// we use the 'was_packed' field internally to allow sorting/unsorting
for (i=0; i < num_rects; ++i) {
rects[i].was_packed = i;
#ifndef STBRP_LARGE_RECTS
STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff);
#endif
}

// sort according to heuristic
qsort(rects, num_rects, sizeof(rects[0]), rect_height_compare);

for (i=0; i < num_rects; ++i) {
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
if (fr.prev_link) {
rects[i].x = (stbrp_coord) fr.x;
rects[i].y = (stbrp_coord) fr.y;
} else {
rects[i].x = rects[i].y = STBRP__MAXVAL;
}
}

// unsort
qsort(rects, num_rects, sizeof(rects[0]), rect_original_order);

// set was_packed flags
for (i=0; i < num_rects; ++i)
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
}
#endif

+ 1254
- 0
src/imgui/stb_textedit.h
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 2658
- 0
src/imgui/stb_truetype.h
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


BIN
src/imgui/web/code_sample_01.png Прегледај датотеку

Before After
Width: 692  |  Height: 234  |  Size: 9.4 KiB

BIN
src/imgui/web/code_sample_01_jp.png Прегледај датотеку

Before After
Width: 692  |  Height: 234  |  Size: 14 KiB

BIN
src/imgui/web/examples_01.png Прегледај датотеку

Before After
Width: 1128  |  Height: 735  |  Size: 14 KiB

BIN
src/imgui/web/examples_02.png Прегледај датотеку

Before After
Width: 822  |  Height: 729  |  Size: 9.5 KiB

BIN
src/imgui/web/performance_01.png Прегледај датотеку

Before After
Width: 1178  |  Height: 716  |  Size: 14 KiB

BIN
src/imgui/web/performance_01_close_up.png Прегледај датотеку

Before After
Width: 589  |  Height: 503  |  Size: 7.8 KiB

BIN
src/imgui/web/skinning_sample_01.png Прегледај датотеку

Before After
Width: 394  |  Height: 586  |  Size: 7.1 KiB

BIN
src/imgui/web/test_window_01.png Прегледај датотеку

Before After
Width: 581  |  Height: 731  |  Size: 5.5 KiB

BIN
src/imgui/web/test_window_02.png Прегледај датотеку

Before After
Width: 581  |  Height: 731  |  Size: 5.5 KiB

BIN
src/imgui/web/test_window_03.png Прегледај датотеку

Before After
Width: 581  |  Height: 731  |  Size: 5.6 KiB

BIN
src/imgui/web/test_window_04.png Прегледај датотеку

Before After
Width: 581  |  Height: 731  |  Size: 5.9 KiB

BIN
src/imgui/web/utf8_sample_01.png Прегледај датотеку

Before After
Width: 630  |  Height: 186  |  Size: 16 KiB

+ 22
- 0
src/lol/base/enum.h Прегледај датотеку

@@ -99,5 +99,27 @@ public:
}
};

//-------------------------------------------------------------------------
struct DisplayFlagBase : public StructSafeEnum
{
enum Type
{
On,
Off,
Toggle,

MAX
};
protected:
virtual bool BuildEnumMap(map<int64_t, String>& enum_map)
{
enum_map[On] = "On";
enum_map[Off] = "Off";
enum_map[Toggle] = "Toggle";
return true;
}
};
typedef SafeEnum<DisplayFlagBase> DisplayFlag;

} /* namespace lol */


+ 111
- 69
src/lol/math/vector.h Прегледај датотеку

@@ -280,38 +280,39 @@ struct vec_t<T,2>
struct { T x, y; };
struct { T r, g; };
struct { T s, t; };
struct { T r, t; };

#if !_DOXYGEN_SKIP_ME
vec_t<T,2,9000> const xx, rr, ss;
vec_t<T,2,9001> _____ xy, rg, st;
vec_t<T,2,9010> _____ yx, gr, ts;
vec_t<T,2,9011> const yy, gg, tt;
vec_t<T,3,90000> const xxx, rrr, sss;
vec_t<T,3,90001> const xxy, rrg, sst;
vec_t<T,3,90010> const xyx, rgr, sts;
vec_t<T,3,90011> const xyy, rgg, stt;
vec_t<T,3,90100> const yxx, grr, tss;
vec_t<T,3,90101> const yxy, grg, tst;
vec_t<T,3,90110> const yyx, ggr, tts;
vec_t<T,3,90111> const yyy, ggg, ttt;
vec_t<T,4,900000> const xxxx, rrrr, ssss;
vec_t<T,4,900001> const xxxy, rrrg, ssst;
vec_t<T,4,900010> const xxyx, rrgr, ssts;
vec_t<T,4,900011> const xxyy, rrgg, sstt;
vec_t<T,4,900100> const xyxx, rgrr, stss;
vec_t<T,4,900101> const xyxy, rgrg, stst;
vec_t<T,4,900110> const xyyx, rggr, stts;
vec_t<T,4,900111> const xyyy, rggg, sttt;
vec_t<T,4,901000> const yxxx, grrr, tsss;
vec_t<T,4,901001> const yxxy, grrg, tsst;
vec_t<T,4,901010> const yxyx, grgr, tsts;
vec_t<T,4,901011> const yxyy, grgg, tstt;
vec_t<T,4,901100> const yyxx, ggrr, ttss;
vec_t<T,4,901101> const yyxy, ggrg, ttst;
vec_t<T,4,901110> const yyyx, gggr, ttts;
vec_t<T,4,901111> const yyyy, gggg, tttt;
vec_t<T, 2, 9000> const xx, rr, ss/**/;
vec_t<T, 2, 9001> _____ xy, rg, st, rt;
vec_t<T, 2, 9010> _____ yx, gr, ts, tr;
vec_t<T, 2, 9011> const yy, gg, tt/**/;
vec_t<T, 3, 90000> const xxx, rrr, sss /**/;
vec_t<T, 3, 90001> const xxy, rrg, sst, rrt;
vec_t<T, 3, 90010> const xyx, rgr, sts, rtr;
vec_t<T, 3, 90011> const xyy, rgg, stt, rtt;
vec_t<T, 3, 90100> const yxx, grr, tss, trr;
vec_t<T, 3, 90101> const yxy, grg, tst, trt;
vec_t<T, 3, 90110> const yyx, ggr, tts, ttr;
vec_t<T, 3, 90111> const yyy, ggg, ttt /**/;
vec_t<T, 4, 900000> const xxxx, rrrr, ssss /**/;
vec_t<T, 4, 900001> const xxxy, rrrg, ssst, rrrt;
vec_t<T, 4, 900010> const xxyx, rrgr, ssts, rrtr;
vec_t<T, 4, 900011> const xxyy, rrgg, sstt, rrtt;
vec_t<T, 4, 900100> const xyxx, rgrr, stss, rtrr;
vec_t<T, 4, 900101> const xyxy, rgrg, stst, rtrt;
vec_t<T, 4, 900110> const xyyx, rggr, stts, rttr;
vec_t<T, 4, 900111> const xyyy, rggg, sttt, rttt;
vec_t<T, 4, 901000> const yxxx, grrr, tsss, trrr;
vec_t<T, 4, 901001> const yxxy, grrg, tsst, trrt;
vec_t<T, 4, 901010> const yxyx, grgr, tsts, trtr;
vec_t<T, 4, 901011> const yxyy, grgg, tstt, trtt;
vec_t<T, 4, 901100> const yyxx, ggrr, ttss, ttrr;
vec_t<T, 4, 901101> const yyxy, ggrg, ttst, ttrt;
vec_t<T, 4, 901110> const yyyx, gggr, ttts, tttr;
vec_t<T, 4, 901111> const yyyy, gggg, tttt /**/;
#endif

T m_data[count];
@@ -436,45 +437,46 @@ struct vec_t<T,3>
struct { T x, y, z; };
struct { T r, g, b; };
struct { T s, t, p; };
struct { T r, t, p; };

#if !_DOXYGEN_SKIP_ME
vec_t<T,2,9000> const xx, rr, ss;
vec_t<T,2,9001> _____ xy, rg, st;
vec_t<T,2,9002> _____ xz, rb, sp;
vec_t<T,2,9010> _____ yx, gr, ts;
vec_t<T,2,9011> const yy, gg, tt;
vec_t<T,2,9012> _____ yz, gb, tp;
vec_t<T,2,9020> _____ zx, br, ps;
vec_t<T,2,9021> _____ zy, bg, pt;
vec_t<T,2,9022> const zz, bb, pp;
vec_t<T,3,90000> const xxx, rrr, sss;
vec_t<T,3,90001> const xxy, rrg, sst;
vec_t<T,3,90002> const xxz, rrb, ssp;
vec_t<T,3,90010> const xyx, rgr, sts;
vec_t<T,3,90011> const xyy, rgg, stt;
vec_t<T,3,90012> _____ xyz, rgb, stp;
vec_t<T,3,90020> const xzx, rbr, sps;
vec_t<T,3,90021> _____ xzy, rbg, spt;
vec_t<T,3,90022> const xzz, rbb, spp;
vec_t<T,3,90100> const yxx, grr, tss;
vec_t<T,3,90101> const yxy, grg, tst;
vec_t<T,3,90102> _____ yxz, grb, tsp;
vec_t<T,3,90110> const yyx, ggr, tts;
vec_t<T,3,90111> const yyy, ggg, ttt;
vec_t<T,3,90112> const yyz, ggb, ttp;
vec_t<T,3,90120> _____ yzx, gbr, tps;
vec_t<T,3,90121> const yzy, gbg, tpt;
vec_t<T,3,90122> const yzz, gbb, tpp;
vec_t<T,3,90200> const zxx, brr, pss;
vec_t<T,3,90201> _____ zxy, brg, pst;
vec_t<T,3,90202> const zxz, brb, psp;
vec_t<T,3,90210> _____ zyx, bgr, pts;
vec_t<T,3,90211> const zyy, bgg, ptt;
vec_t<T,3,90212> const zyz, bgb, ptp;
vec_t<T,3,90220> const zzx, bbr, pps;
vec_t<T,3,90221> const zzy, bbg, ppt;
vec_t<T,3,90222> const zzz, bbb, ppp;
vec_t<T, 2, 9000> const xx, rr, ss/**/;
vec_t<T, 2, 9001> _____ xy, rg, st, rt;
vec_t<T, 2, 9002> _____ xz, rb, sp, rp;
vec_t<T, 2, 9010> _____ yx, gr, ts, tr;
vec_t<T, 2, 9011> const yy, gg, tt/**/;
vec_t<T, 2, 9012> _____ yz, gb, tp/**/;
vec_t<T, 2, 9020> _____ zx, br, ps, pr;
vec_t<T, 2, 9021> _____ zy, bg, pt/**/;
vec_t<T, 2, 9022> const zz, bb, pp/**/;
vec_t<T, 3, 90000> const xxx, rrr, sss /**/;
vec_t<T, 3, 90001> const xxy, rrg, sst, rrt;
vec_t<T, 3, 90002> const xxz, rrb, ssp, rrp;
vec_t<T, 3, 90010> const xyx, rgr, sts, rtr;
vec_t<T, 3, 90011> const xyy, rgg, stt, rtt;
vec_t<T, 3, 90012> _____ xyz, rgb, stp, rtp;
vec_t<T, 3, 90020> const xzx, rbr, sps, rpr;
vec_t<T, 3, 90021> _____ xzy, rbg, spt, rpt;
vec_t<T, 3, 90022> const xzz, rbb, spp, rpp;
vec_t<T, 3, 90100> const yxx, grr, tss, trr;
vec_t<T, 3, 90101> const yxy, grg, tst, trt;
vec_t<T, 3, 90102> _____ yxz, grb, tsp, trp;
vec_t<T, 3, 90110> const yyx, ggr, tts, ttr;
vec_t<T, 3, 90111> const yyy, ggg, ttt /**/;
vec_t<T, 3, 90112> const yyz, ggb, ttp /**/;
vec_t<T, 3, 90120> _____ yzx, gbr, tps, tpr;
vec_t<T, 3, 90121> const yzy, gbg, tpt /**/;
vec_t<T, 3, 90122> const yzz, gbb, tpp /**/;
vec_t<T, 3, 90200> const zxx, brr, pss, prr;
vec_t<T, 3, 90201> _____ zxy, brg, pst, prt;
vec_t<T, 3, 90202> const zxz, brb, psp, prp;
vec_t<T, 3, 90210> _____ zyx, bgr, pts, ptr;
vec_t<T, 3, 90211> const zyy, bgg, ptt /**/;
vec_t<T, 3, 90212> const zyz, bgb, ptp /**/;
vec_t<T, 3, 90220> const zzx, bbr, pps, ppr;
vec_t<T, 3, 90221> const zzy, bbg, ppt /**/;
vec_t<T, 3, 90222> const zzz, bbb, ppp /**/;

vec_t<T,4,900000> const xxxx, rrrr, ssss;
vec_t<T,4,900001> const xxxy, rrrg, ssst;
@@ -1218,14 +1220,54 @@ static inline vec_t<T,N> degrees(vec_t<T,N,SWIZZLE> const &a)
}

template<typename T, int N, int SWIZZLE>
static inline vec_t<T,N> radians(vec_t<T,N,SWIZZLE> const &a)
static inline vec_t<T, N> radians(vec_t<T, N, SWIZZLE> const &a)
{
vec_t<T,N> ret;
vec_t<T, N> ret;
for (int i = 0; i < N; ++i)
ret[i] = lol::radians(a[i]);
return ret;
}

//Cartesian operation consider that you're in spherical coordinate
template<typename T, int SWIZZLE>
static inline vec_t<T, 2> cartesian(vec_t<T, 2, SWIZZLE> const &a)
{
vec_t<T, 2> ret;
ret.x = r * lol::cos(t);
ret.y = r * lol::sin(t);
return ret;
}

template<typename T, int SWIZZLE>
static inline vec_t<T, 3> cartesian(vec_t<T, 3, SWIZZLE> const &a)
{
vec_t<T, 3> ret;
ret.x = r * lol::sin(t) * lol::cos(p);
ret.y = r * lol::sin(t) * lol::sin(p);
ret.z = r * lol::cos(t);
return ret;
}

//Spherical operation consider that you're in cartesian coordinate
template<typename T, int SWIZZLE>
static inline vec_t<T, 2> spherical(vec_t<T, 2, SWIZZLE> const &a)
{
vec_t<T, 2> ret;
ret.r = lol::sqrt(lol::sq(x) + lol::sq(y));
ret.t = lol::atan2(y, x);
return ret;
}

template<typename T, int SWIZZLE>
static inline vec_t<T, 3> spherical(vec_t<T, 3, SWIZZLE> const &a)
{
vec_t<T, 3> ret;
ret.r = lol::sqrt(lol::sq(x) + lol::sq(y) + lol::sq(z));
ret.t = lol::acos(z / ret.x);
ret.p = lol::atan(y / x);
return ret;
}

/*
* C++11 iterators
*/


+ 273
- 16
src/lolua/baselua.h Прегледај датотеку

@@ -257,15 +257,23 @@ protected:
bool m_optional = false;

public:
VarPtr() { }
VarPtr(bool optional = false)
{
m_optional = optional;
}
VarPtr(T* value, bool optional = false)
: VarPtr(optional)
{
m_value = value;
m_optional = optional;
}
VarPtr(LuaState* l, int& index, bool optional = false)
: VarPtr(optional)
{
GetInc(l, index);
}
VarPtr(T* value, LuaState* l, int& index, bool optional = false)
: VarPtr(value, optional)
{
m_optional = optional;
GetInc(l, index);
}
inline T* operator ()() { return m_value; }
@@ -318,9 +326,10 @@ template<typename T>
class VarPtrLight
{
public:
VarPtrLight() : VarPtr() { }
VarPtrLight(bool optional = false) : VarPtr(optional) { }
VarPtrLight(T* value, bool optional = false) : VarPtr(value, optional) { }
VarPtrLight(LuaState* l, int& index, bool optional = false) : VarPtr(l, index, optional) { }
VarPtrLight(T* value, LuaState* l, int& index, bool optional = false) : VarPtr(value, l, index, optional) { }
protected:
virtual void InnerGet(LuaState* l, int& index)
{
@@ -333,7 +342,7 @@ protected:
template<typename T>
class Var
{
private:
protected:
bool m_optional = false;
T m_value;

@@ -353,12 +362,23 @@ public:
m_optional = optional;
GetInc(l, index);
}
inline operator T() { return m_value; }
inline T& operator ()() { return m_value; }
Var(T value, LuaState* l, int& index, bool optional = false)
{
m_optional = optional;
m_value = value;
GetInc(l, index);
}
inline operator T() { return m_value; }
inline T& operator ()() { return m_value; }
inline T& GetValue() { return m_value; }
inline bool IsValid(LuaState* l, int index)
{
return InnerIsValid(l, index);
}
inline bool IsOptional()
{
return m_optional;
}
private:
void GetInc(LuaState* l, int& index)
{
@@ -402,7 +422,7 @@ public:
inline bool operator==(const Var<T>& o) { return m_value == o.m_value; }
inline bool operator!=(const Var<T>& o) { return m_value != o.m_value; }

private:
protected:
void InnerInit() { m_value = T(0); }
bool InnerIsValid(LuaState* l, int index) { UNUSED(l); UNUSED(index); ASSERT(false); return false; }
void InnerGet(LuaState* l, int& index) { UNUSED(l); UNUSED(index); ASSERT(false); }
@@ -557,7 +577,7 @@ template<> inline bool Var<vec2>::InnerIsValid(LuaState* l, int index)
template<> inline void Var<vec2>::InnerGet(LuaState* l, int& index)
{
Var<float> x(l, index);
Var<float> y(x(), true); y.Get(l, index);
Var<float> y(x(), l, index, true);
m_value = vec2(x, y);
}
template<> inline int Var<vec2>::InnerPush(LuaState* l)
@@ -575,8 +595,8 @@ template<> inline bool Var<vec3>::InnerIsValid(LuaState* l, int index)
template<> inline void Var<vec3>::InnerGet(LuaState* l, int& index)
{
Var<float> x(l, index);
Var<float> y(x(), true); y.Get(l, index);
Var<float> z(x(), true); z.Get(l, index);
Var<float> y(x(), l, index, true);
Var<float> z(x(), l, index, true);
m_value = vec3(x, y, z);
}
template<> inline int Var<vec3>::InnerPush(LuaState* l)
@@ -595,9 +615,9 @@ template<> inline bool Var<vec4>::InnerIsValid(LuaState* l, int index)
template<> inline void Var<vec4>::InnerGet(LuaState* l, int& index)
{
Var<float> x(l, index);
Var<float> y(x(), true); y.Get(l, index);
Var<float> z(x(), true); z.Get(l, index);
Var<float> w(x(), true); w.Get(l, index);
Var<float> y(x(), l, index, true);
Var<float> z(x(), l, index, true);
Var<float> w(x(), l, index, true);
m_value = vec4(x, y, z, w);
}
template<> inline int Var<vec4>::InnerPush(LuaState* l)
@@ -609,6 +629,226 @@ template<> inline int Var<vec4>::InnerPush(LuaState* l)
return (x.Return(l) + y.Return(l) + z.Return(l) + w.Return(l));
}

//-----------------------------------------------------------------------------
class VarColor
{
protected:
Var<vec4> m_value;

public:
VarColor(bool optional = false)
{
m_value = Var<vec4>(optional);
InnerInit();
}
VarColor(vec4 value, bool optional = false)
{
m_value = Var<vec4>(value, optional);
}
VarColor(LuaState* l, int& index, bool optional = false)
: VarColor(optional)
{
GetInc(l, index);
}
VarColor(vec4 value, LuaState* l, int& index, bool optional = false)
: VarColor(value, optional)
{
GetInc(l, index);
}

inline operator vec4() { return m_value; }
inline vec4& operator ()() { return m_value(); }
inline vec4& GetValue() { return m_value.GetValue(); }
inline bool IsValid(LuaState* l, int index)
{
return InnerIsValid(l, index);
}
private:
void GetInc(LuaState* l, int& index)
{
bool is_nil = lua_isnil(l, index);
if (!m_value.IsOptional() || (!is_nil && InnerIsValid(l, index)))
{
ASSERT(!is_nil);
InnerGet(l, index);
}
}
public:
inline void Get(LuaState* l, int index)
{
int idx = index;
GetInc(l, idx);
}
inline int Return(LuaState* l)
{
return InnerPush(l);
}
inline VarColor& operator-(const vec4& value) { m_value - value; return *this; }
inline VarColor& operator+(const vec4& value) { m_value + value; return *this; }
inline VarColor& operator*(const vec4& value) { m_value * value; return *this; }
inline VarColor& operator/(const vec4& value) { m_value / value; return *this; }
inline VarColor& operator=(const vec4& value) { m_value = value; return *this; }
inline VarColor& operator-=(const vec4& value) { m_value -= value; return *this; }
inline VarColor& operator+=(const vec4& value) { m_value += value; return *this; }
inline VarColor& operator*=(const vec4& value) { m_value *= value; return *this; }
inline VarColor& operator/=(const vec4& value) { m_value /= value; return *this; }
inline VarColor& operator-(const Var<vec4>& o) { m_value - o; return *this; }
inline VarColor& operator+(const Var<vec4>& o) { m_value + o; return *this; }
inline VarColor& operator*(const Var<vec4>& o) { m_value * o; return *this; }
inline VarColor& operator/(const Var<vec4>& o) { m_value / o; return *this; }
inline VarColor& operator=(const Var<vec4>& o) { m_value = o; return *this; }
inline VarColor& operator-=(const Var<vec4>& o) { m_value -= o; return *this; }
inline VarColor& operator+=(const Var<vec4>& o) { m_value += o; return *this; }
inline VarColor& operator*=(const Var<vec4>& o) { m_value *= o; return *this; }
inline VarColor& operator/=(const Var<vec4>& o) { m_value /= o; return *this; }
inline bool operator==(const vec4& value) { return m_value == value; }
inline bool operator!=(const vec4& value) { return m_value != value; }
inline bool operator==(const Var<vec4>& o) { return m_value == o; }
inline bool operator!=(const Var<vec4>& o) { return m_value != o; }
inline VarColor& operator-(const VarColor& v) { m_value - v.m_value; return *this; }
inline VarColor& operator+(const VarColor& v) { m_value + v.m_value; return *this; }
inline VarColor& operator*(const VarColor& v) { m_value * v.m_value; return *this; }
inline VarColor& operator/(const VarColor& v) { m_value / v.m_value; return *this; }
inline VarColor& operator=(const VarColor& v) { m_value = v.m_value; return *this; }
inline VarColor& operator-=(const VarColor& v) { m_value -= v.m_value; return *this; }
inline VarColor& operator+=(const VarColor& v) { m_value += v.m_value; return *this; }
inline VarColor& operator*=(const VarColor& v) { m_value *= v.m_value; return *this; }
inline VarColor& operator/=(const VarColor& v) { m_value /= v.m_value; return *this; }
inline bool operator==(const VarColor& v) { return m_value == v.m_value; }
inline bool operator!=(const VarColor& v) { return m_value != v.m_value; }

protected:
void InnerInit()
{
m_value = vec4::zero;
}
bool InnerIsValid(LuaState* l, int index)
{
Var<String> s;
return m_value.IsValid(l, index) || s.IsValid(l, index);
}
void InnerGet(LuaState* l, int& index)
{
//Try vec4 first
if (m_value.IsValid(l, index))
{
m_value.Get(l, index);
}
else
{
Var<String> c(l, index);
*this = Color::C8BppHexString(c);
}
}
int InnerPush(LuaState* l)
{
Var<String> c = Color::HexString8Bpp(m_value);
return c.Return(l);
}
};

//-----------------------------------------------------------------------------
template<typename E>
class VarEnum
{
protected:
SafeEnum<E> m_value;
bool m_optional = false;

public:
VarEnum(bool optional = false)
{
m_optional = optional;
InnerInit();
}
VarEnum(SafeEnum<E> value, bool optional = false)
: VarEnum(optional)
{
m_value = value;
}
VarEnum(LuaState* l, int& index, bool optional = false)
: VarEnum(optional)
{
GetInc(l, index);
}
VarEnum(vec4 value, LuaState* l, int& index, bool optional = false)
: VarEnum(value, optional)
{
GetInc(l, index);
}

inline operator SafeEnum<E>() { return m_value; }
inline SafeEnum<E>& operator ()() { return m_value; }
inline SafeEnum<E>& GetValue() { return m_value; }
inline bool IsValid(LuaState* l, int index)
{
return InnerIsValid(l, index);
}
private:
void GetInc(LuaState* l, int& index)
{
bool is_nil = lua_isnil(l, index);
if (!m_optional || (!is_nil && InnerIsValid(l, index)))
{
ASSERT(!is_nil);
InnerGet(l, index);
}
}
public:
inline void Get(LuaState* l, int index)
{
int idx = index;
GetInc(l, idx);
}
inline int Return(LuaState* l)
{
return InnerPush(l);
}
inline VarEnum<E>& operator-(const SafeEnum<E>& value) { m_value - value; return *this; }
inline VarEnum<E>& operator+(const SafeEnum<E>& value) { m_value + value; return *this; }
inline VarEnum<E>& operator*(const SafeEnum<E>& value) { m_value * value; return *this; }
inline VarEnum<E>& operator/(const SafeEnum<E>& value) { m_value / value; return *this; }
inline VarEnum<E>& operator=(const SafeEnum<E>& value) { m_value = value; return *this; }
inline VarEnum<E>& operator-=(const SafeEnum<E>& value) { m_value -= value; return *this; }
inline VarEnum<E>& operator+=(const SafeEnum<E>& value) { m_value += value; return *this; }
inline VarEnum<E>& operator*=(const SafeEnum<E>& value) { m_value *= value; return *this; }
inline VarEnum<E>& operator/=(const SafeEnum<E>& value) { m_value /= value; return *this; }
inline bool operator==(const SafeEnum<E>& value) { return m_value == value; }
inline bool operator!=(const SafeEnum<E>& value) { return m_value != value; }
inline VarEnum<E>& operator-(const VarEnum<E>& v) { m_value - v.m_value; return *this; }
inline VarEnum<E>& operator+(const VarEnum<E>& v) { m_value + v.m_value; return *this; }
inline VarEnum<E>& operator*(const VarEnum<E>& v) { m_value * v.m_value; return *this; }
inline VarEnum<E>& operator/(const VarEnum<E>& v) { m_value / v.m_value; return *this; }
inline VarEnum<E>& operator=(const VarEnum<E>& v) { m_value = v.m_value; return *this; }
inline VarEnum<E>& operator-=(const VarEnum<E>& v) { m_value -= v.m_value; return *this; }
inline VarEnum<E>& operator+=(const VarEnum<E>& v) { m_value += v.m_value; return *this; }
inline VarEnum<E>& operator*=(const VarEnum<E>& v) { m_value *= v.m_value; return *this; }
inline VarEnum<E>& operator/=(const VarEnum<E>& v) { m_value /= v.m_value; return *this; }
inline bool operator==(const VarEnum<E>& v) { return m_value == v.m_value; }
inline bool operator!=(const VarEnum<E>& v) { return m_value != v.m_value; }

protected:
void InnerInit()
{
m_value = SafeEnum<E>(0);
}
bool InnerIsValid(LuaState* l, int index)
{
Var<String> s;
return s.IsValid(l, index);
}
void InnerGet(LuaState* l, int& index)
{
Var<String> c(l, index);
*this = FindValue<SafeEnum<E> >(c);
}
int InnerPush(LuaState* l)
{
Var<String> s = this->GetValue().ToString();
return s.Return(l);
}
};

//-----------------------------------------------------------------------------
class Stack
{
@@ -627,11 +867,18 @@ public:

//-------------------------------------------------------------------------
template<typename T>
Stack& operator>>(Var<T>& var)
Stack& operator>>(T& var)
{
var = Var<T>(m_state, m_index);
var = T(m_state, m_index);
return *this;
}
/*
template<typename T>
Stack& operator>>(Var<T>& var)
{
var = Var<T>(m_state, m_index);
return *this;
}
template<typename T>
Stack& operator>>(VarPtr<T>& var)
{
@@ -644,9 +891,17 @@ public:
var = VarPtrLight<T>(m_state, m_index);
return *this;
}
*/

//-------------------------------------------------------------------------
template<typename T>
Stack& operator<<(T& var)
{
m_result += var.Return(m_state);
return *this;
}
/*
template<typename T>
Stack& operator<<(Var<T>& var)
{
m_result += var.Return(m_state);
@@ -664,6 +919,7 @@ public:
m_result += var.Return(m_state);
return *this;
}
*/

private:
LuaState* m_state = nullptr;
@@ -723,6 +979,7 @@ typedef Lolua::Var<uint64_t> LuaUInt64;
typedef Lolua::Var<vec2> LuaVec2;
typedef Lolua::Var<vec3> LuaVec3;
typedef Lolua::Var<vec4> LuaVec4;
typedef Lolua::VarColor LuaColor;
typedef Lolua::Stack LuaStack;

} /* namespace lol */

+ 5
- 1
src/utils.h Прегледај датотеку

@@ -68,11 +68,15 @@ template<class T> inline T FindValue(const char* name)
for (int i = 0; i < T::Max; ++i)
{
String s = T(i).ToString().to_lower();
if (s == n)
if (s.Contains(n))
return T(i);
}
return T::Max;
}
template<class T> inline T FindValue(String const& name)
{
return FindValue<T>(name.C());
}

} /* namespace lol */


Loading…
Откажи
Сачувај