mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-13 08:19:55 +02:00
Compare commits
450 Commits
Author | SHA1 | Date | |
---|---|---|---|
24d186753e | |||
1c5aa32d2b | |||
1bdd3b8e00 | |||
2849596069 | |||
8de3f4843c | |||
f631ae26ca | |||
e4cf44e967 | |||
25c9448dda | |||
e34b4b46da | |||
f3b41b35c2 | |||
40ddf8e287 | |||
96e2b925b1 | |||
fc7a3d07bb | |||
4723d97cfb | |||
6102aa1375 | |||
66886405f6 | |||
217a6c875a | |||
2e5577f44f | |||
21f0d64a74 | |||
0b10bec71f | |||
0873da85ec | |||
370de414ef | |||
2e5352786a | |||
558430ca8f | |||
5084f90a0d | |||
76ab5587e4 | |||
9b6b1bc0f3 | |||
7bcebdc207 | |||
8afbdd1ade | |||
7b0bf23071 | |||
02ce1a2b32 | |||
56c4f5b7dc | |||
b49a985324 | |||
18223fd3ab | |||
a9bdda0d95 | |||
b1b759938e | |||
9583868bab | |||
6c7f8efe1e | |||
4bfd5cd95f | |||
bf83ac8b55 | |||
de4ae2d53a | |||
5dec997fbe | |||
c80e2274f1 | |||
ecc97bda7d | |||
18724f021a | |||
9596e6f794 | |||
dadd03fc11 | |||
59f0db6f15 | |||
32c1a3e46c | |||
730e8119fe | |||
1f3a0e78cc | |||
fe2972e8b2 | |||
6adf644448 | |||
1b7aee7b9d | |||
632f9ec36a | |||
5f8200d52c | |||
d1b4159b51 | |||
9dca2ca960 | |||
b7e1ae4bf9 | |||
a500c0daf7 | |||
4006fb77bc | |||
546962351b | |||
6cee2fca94 | |||
6269859315 | |||
3aebddc4ac | |||
94ec3d534e | |||
6800939e73 | |||
5c52e9ec0d | |||
d673db3092 | |||
9735563b65 | |||
eb6575508f | |||
b2b4bbe5ea | |||
79b09e7d10 | |||
f505a372fd | |||
ba77166432 | |||
32d2768734 | |||
d3df39fed1 | |||
4ca34a879d | |||
a9009b133c | |||
6e2e60ffad | |||
e4ba6e525b | |||
807d4ff92c | |||
c0ec9f4e63 | |||
aa6cb32bd4 | |||
b4556c404d | |||
bfacd250df | |||
58b23b4785 | |||
1aac69c937 | |||
95138fa8d6 | |||
3102c0c97e | |||
60b75d78ea | |||
10ba61f882 | |||
5d84f4b450 | |||
b959c74488 | |||
83e6cfbec0 | |||
dc86a8a0bf | |||
38cfdafbaf | |||
1e69a86d30 | |||
92c518a420 | |||
6b03ddbcb1 | |||
e2ecc02e02 | |||
f96de74e05 | |||
899cb3b4e9 | |||
ab7e91b65e | |||
9d0caa2e66 | |||
624adb1b23 | |||
9a8cbf128d | |||
693efccb62 | |||
5549744e0f | |||
f87deff0f3 | |||
9243aee62c | |||
3b2fdf27a8 | |||
0b47edcefe | |||
4dee8473b5 | |||
1d76890526 | |||
e4fb14a9e0 | |||
e46c7b70eb | |||
4982cd136e | |||
b168c72dd1 | |||
d963ff13ca | |||
acc87f7f5e | |||
6b23fca1ff | |||
0a23e2c832 | |||
980ca286fe | |||
6ffe0fddbf | |||
1a42a3f91b | |||
3eabad0321 | |||
e858d229a0 | |||
d0afb23a3f | |||
e1bc0dd7d5 | |||
0b0c460324 | |||
7245599f04 | |||
d86dd37091 | |||
f11adc1c08 | |||
217ef444d4 | |||
5f0db60a57 | |||
42529f1270 | |||
e4d916a4b3 | |||
72dde4d323 | |||
fbdcb51dde | |||
8b9c0b2545 | |||
7a61b7dd57 | |||
465e6839a4 | |||
5b7a2149fc | |||
43ff5a41be | |||
a0d24ac03d | |||
64b6e87f54 | |||
b090d711e2 | |||
214e87d59c | |||
bc34ac882f | |||
2b3fb5c0f7 | |||
81927b073e | |||
ba9c469ff0 | |||
ebf4f1fa02 | |||
79ca203850 | |||
5d53f37a5d | |||
1c69b3d0df | |||
d4d2e5bc62 | |||
a5c895f791 | |||
59cedca02e | |||
509ac33abe | |||
a5132286b7 | |||
8eb4df0dd6 | |||
8c5c0c41fc | |||
b93e787f51 | |||
8a6bde3527 | |||
fae7b34a3f | |||
50b25b6c75 | |||
b8281d96bd | |||
a77e534ded | |||
379079ac42 | |||
80173fec96 | |||
edf730b672 | |||
48bb3c8026 | |||
de92bc873f | |||
0298603040 | |||
bd78892164 | |||
e83b529846 | |||
d087671369 | |||
06d594e86b | |||
54805fd22a | |||
a465b2b3d8 | |||
7508d30b83 | |||
69678d1ed2 | |||
e031fe484c | |||
69e6f299f3 | |||
c1983d5c3f | |||
f21fda1231 | |||
6e4d959953 | |||
c9d51d99b4 | |||
5d3d136733 | |||
b92daf0ba2 | |||
ea66a34f9d | |||
e130b09d91 | |||
a76b75c2d5 | |||
572bf91006 | |||
ecb63ff8f3 | |||
963f6b782d | |||
9d89e03346 | |||
cc53d31764 | |||
d5502cdd6d | |||
98465d401b | |||
914516110c | |||
127f44c12b | |||
ab5def6ad8 | |||
e268303c02 | |||
994c286f61 | |||
93200a6c37 | |||
774099918a | |||
fee9e07e61 | |||
ff12afbd18 | |||
0e86ed9361 | |||
08bfe9bc7c | |||
c4562ac573 | |||
3b01b0a2f2 | |||
0a1d6b6b74 | |||
ec7eb05e88 | |||
f9928e96c7 | |||
0abe668221 | |||
bc8eb5e9cf | |||
7b1168eb30 | |||
4d83519244 | |||
25b4b88a7a | |||
ad4c962224 | |||
853f265025 | |||
167c02d502 | |||
951e1bd9a8 | |||
2903c98bca | |||
07776595c2 | |||
c31ca3e2d5 | |||
1793c1a991 | |||
cafe8b0cd7 | |||
fcbbb0070e | |||
b4f1e88860 | |||
f5fb5f0c1e | |||
a09411b936 | |||
8a3593257f | |||
7d6ddbe5c8 | |||
dafad3903e | |||
93f9ad9ddf | |||
e34ad0a05a | |||
dbc7903da8 | |||
09f659271e | |||
fc052e24b2 | |||
965fa3cb16 | |||
c9e19f8953 | |||
77bcb7152b | |||
f195bf744f | |||
4ab43dce19 | |||
13daaf78a2 | |||
e4ef140e10 | |||
350d96466e | |||
1eef2c9108 | |||
71026d3655 | |||
7a31030978 | |||
e5e9c5cfbe | |||
bbf09fd47d | |||
a3cad2ff06 | |||
6eed3dc7c8 | |||
73e73e6ef9 | |||
afa0346a0b | |||
e1f8fed734 | |||
f128a8bce1 | |||
8edbdb9775 | |||
e68d3c614e | |||
9e5fb40ddd | |||
65a191c005 | |||
9eed672725 | |||
d88b73a8b7 | |||
fc13ae2aa5 | |||
e0c375e7b8 | |||
b326c8fd1f | |||
b994dd777a | |||
0aa353868f | |||
aa35547f94 | |||
2d565d4bfb | |||
64fcb5e568 | |||
65fe60f2b2 | |||
0bb46c824e | |||
f2c68109a6 | |||
c381d58fb1 | |||
62a3142036 | |||
da807e55ea | |||
5ebd61f89c | |||
e7cc048d81 | |||
0a11024459 | |||
30461345aa | |||
8430c88451 | |||
b803d284c3 | |||
90e5c97f13 | |||
d2e529e533 | |||
80ad773c87 | |||
55ea2988d2 | |||
e58f99179a | |||
a36001212f | |||
8b225923f8 | |||
59d498f3d0 | |||
62671ef96e | |||
8cf7df7ec4 | |||
822eaf1751 | |||
08b345efd9 | |||
77b82ecad7 | |||
ad00d88923 | |||
f0aca186cc | |||
ad3c9f620d | |||
466f01b313 | |||
43d073db1e | |||
b76353bbb1 | |||
063d26a191 | |||
9a0650dbd0 | |||
b1987d697f | |||
425c6cb3a3 | |||
73917115a8 | |||
7eca754094 | |||
01a17aa78e | |||
e885b08914 | |||
0e898fb480 | |||
5f4cbed7ce | |||
b28858b33b | |||
23ce837dc7 | |||
d80869189a | |||
06c7453ee2 | |||
bbced3f0f0 | |||
4ac4d1ac37 | |||
ccbc72e98b | |||
97be3428f1 | |||
215747635d | |||
c016f6c171 | |||
698c7cae85 | |||
ede5956b28 | |||
0a6d6da732 | |||
67b2b5f3a9 | |||
07de0448f9 | |||
307ed78006 | |||
b770f3ffaf | |||
42567a9516 | |||
72d3fca52f | |||
d36a634ac8 | |||
c98318a914 | |||
f421f2f47e | |||
bcb83ed24e | |||
4630815fb0 | |||
f1f4d68f7f | |||
0c9fcdbe71 | |||
915b46f1c1 | |||
48ed0a10d7 | |||
9a97ef673e | |||
6a90ac2094 | |||
3604aecf8f | |||
23e7bdebcf | |||
32f15b9c9a | |||
aa3c26fd30 | |||
b637850260 | |||
14822609bd | |||
947cf3434f | |||
a99ba42a39 | |||
20cc65788d | |||
27961401c6 | |||
88a00f77e9 | |||
f1fb62fa6d | |||
b6313577bb | |||
0911597550 | |||
80fc576d07 | |||
96a7873622 | |||
470200ee5c | |||
85dab1a680 | |||
15cfa63e97 | |||
692a38c0fc | |||
f2b652a39e | |||
e7f1e28b6b | |||
4b4f6d78ee | |||
a54995eace | |||
9b19f8c19d | |||
12d941a42a | |||
f6e21b7ab7 | |||
cc8ff4c8d1 | |||
f0f2afa87d | |||
a793ad682d | |||
ebd25cf1a3 | |||
7fea3eacfe | |||
e20b90154c | |||
3ee2fac892 | |||
e42bec5ba2 | |||
155873a6b0 | |||
1b0a8f9ac3 | |||
60b46cc712 | |||
8be4d41540 | |||
1befd21b37 | |||
3658314638 | |||
a526b423e8 | |||
d667de9490 | |||
815d1d9be4 | |||
3aca446817 | |||
da3baebd43 | |||
e099798c97 | |||
3ccbdc8423 | |||
4b29cc9e10 | |||
e47bf041bf | |||
11d91a27a4 | |||
040e427dad | |||
f158617551 | |||
1e76c63bb6 | |||
2d8c134747 | |||
26a992c6f6 | |||
6c63d80aa4 | |||
f63beeae86 | |||
faa609a43c | |||
f8646338c3 | |||
7650d4cc67 | |||
abf823c6f6 | |||
58ee08f214 | |||
040f3950a3 | |||
e6b29b70b4 | |||
a7e5945206 | |||
c639f65eb7 | |||
02fbb36918 | |||
a79ee94fc4 | |||
709c4c3168 | |||
527208ad7c | |||
fddc871870 | |||
fc9ee2bc9b | |||
8d45c89352 | |||
4468ec001e | |||
fb83323b1d | |||
62c888177a | |||
e1ac5a3198 | |||
68962ae683 | |||
7552f48d7b | |||
94f085aa3e | |||
5a29eef1fa | |||
e32f0931e8 | |||
52a74701f5 | |||
dace68b6fd | |||
60dce8bc22 | |||
0eb196d544 | |||
dc1cb9e625 | |||
d184730dd2 | |||
bc9bae6d01 | |||
83ebbebadd | |||
5a4b521855 | |||
74908a9513 | |||
479211808f | |||
82727d7119 | |||
cdbf71ac12 | |||
0ab620c2b9 | |||
20db726a9a | |||
4015414978 | |||
3b53a6513a | |||
eca26ae91d | |||
99c5f5735c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
imgui.ini
|
|
93
README.md
93
README.md
@ -1,61 +1,67 @@
|
|||||||
ImGui
|
dear imgui,
|
||||||
=====
|
=====
|
||||||
[](https://travis-ci.org/ocornut/imgui)
|
[](https://travis-ci.org/ocornut/imgui)
|
||||||
[](https://scan.coverity.com/projects/4720)
|
[](https://scan.coverity.com/projects/4720)
|
||||||
|
|
||||||
|
(This library is free and will stay free, but needs your support to sustain its development. There are lots of desirable new features and maintenance to do. If you work for a company using ImGui or have the means to do so, please consider financial support)
|
||||||
|
|
||||||
[](http://www.patreon.com/imgui) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5Q73FPZ9C526U)
|
[](http://www.patreon.com/imgui) [](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 enables you to build user interfaces with ease.
|
dear imgui (AKA 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 fast, portable, renderer agnostic and self-contained (no external dependencies).
|
||||||
|
|
||||||
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 designed to enable fast iteration and empower programmers to create content creation tools and visualization/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 realtime 3D applications, fullscreen applications, embedded applications, games, or any applications on consoles platforms where operating system features are non-standard. pa
|
ImGui is particularly suited to integration in realtime 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 is self-contained within a few files that you can easily copy and compile into your application/engine:
|
||||||
|
|
||||||
- imgui.cpp
|
- imgui.cpp
|
||||||
- imgui.h
|
- imgui.h
|
||||||
|
- imgui_demo.cpp
|
||||||
|
- imgui_draw.cpp
|
||||||
|
- imgui_internal.h
|
||||||
- imconfig.h (empty by default, user-editable)
|
- imconfig.h (empty by default, user-editable)
|
||||||
- stb_rect_pack.h
|
- stb_rect_pack.h
|
||||||
- stb_textedit.h
|
- stb_textedit.h
|
||||||
- stb_truetype.h
|
- stb_truetype.h
|
||||||
|
|
||||||
|
No specific build process is required. You can add the .cpp files to your project or #include them from an existing file.
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
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 outputs vertex buffers and simple command-lists that you can render in your application. The number of draw calls and state changes is typically very small. 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.
|
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 modern 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.
|
||||||
|
|
||||||
Demo
|
Demo
|
||||||
----
|
----
|
||||||
|
|
||||||
You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at the features of ImGui, you can download binaries of the demo app here.
|
You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at the features of ImGui, you can download Windows binaries of the demo app here.
|
||||||
- [imgui-demo-binaries-20150716.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20150716.zip) (Windows binaries, ImGui 1.43 WIP 2015/07/16, 4 executables, 475 KB)
|
- [imgui-demo-binaries-20150909.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20150909.zip) (Windows binaries, ImGui 1.46 WIP 2015/09/09, 4 executables, 505 KB)
|
||||||
|
|
||||||
|
|
||||||
Gallery
|
Gallery
|
||||||
-------
|
-------
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|

|
||||||

|

|
||||||

|

|
||||||

|
|
||||||

|

|
||||||
|
|
||||||
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:
|
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();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.Fonts->AddFontFromFileTTF("ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());
|
io.Fonts->AddFontFromFileTTF("ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
```
|
|
||||||
For Microsoft IME, pass your HWND to enable IME positioning:
|
// For Microsoft IME, pass your HWND to enable IME positioning:
|
||||||
```
|
|
||||||
io.ImeWindowHandle = my_hwnd;
|
io.ImeWindowHandle = my_hwnd;
|
||||||
```
|
```
|
||||||

|

|
||||||
|
|
||||||
References
|
References
|
||||||
----------
|
----------
|
||||||
@ -66,32 +72,45 @@ The Immediate Mode GUI paradigm may at first appear unusual to some users. This
|
|||||||
- [Jari Komppa's tutorial on building an ImGui library](http://iki.fi/sol/imgui/).
|
- [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).
|
- [Casey Muratori's original video that popularized the concept](https://mollyrocket.com/861).
|
||||||
|
|
||||||
Frequently Asked Question
|
See the [Links page](https://github.com/ocornut/imgui/wiki/Links) for third-party bindings to different languages and frameworks.
|
||||||
-------------------------
|
|
||||||
|
Frequently Asked Question (FAQ)
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
<b>Where is the documentation?</b>
|
<b>Where is the documentation?</b>
|
||||||
|
|
||||||
- The documentation is at the top of imgui.cpp + effectively imgui.h.
|
- The documentation is at the top of imgui.cpp + effectively imgui.h.
|
||||||
- Example code is in 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.
|
- Example code is in imgui_demo.cpp and particularly 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.
|
||||||
- Standalone example applications using OpenGL/DirectX are provided in the examples/ folder.
|
- Standalone example applications using e.g. OpenGL/DirectX are provided in the examples/ folder.
|
||||||
|
- We obviously needs better documentation! Consider contributing or becoming a [Patron](http://www.patreon.com/imgui) to promote this effort.
|
||||||
|
|
||||||
|
<b>Why the odd dual naming, "dear imgui" vs "ImGui"?</b>
|
||||||
|
|
||||||
|
The library started its life and is best known as "ImGui" only due to the fact that I didn't give it a proper name when I released it. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations. It seemed confusing and unfair to hog the name. To reduce the ambiguity without affecting existing codebases, I have decided on an alternate, longer name "dear imgui" that people can use to refer to this specific library in ambiguous situations.
|
||||||
|
|
||||||
|
<b>How do I update to a newer version of ImGui?</b>
|
||||||
|
<br><b>Can I have multiple widgets with the same label? Can I have widget without a label? (Yes)</b>
|
||||||
|
<br><b>I integrated ImGui in my engine and the text or lines are blurry..</b>
|
||||||
|
<br><b>I integrated ImGui in my engine and some elements are disappearing when I move windows around..</b>
|
||||||
|
<br><b>How can I load a different font than the default?</b>
|
||||||
|
<br><b>How can I load multiple fonts?</b>
|
||||||
|
<br><b>How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?</b>
|
||||||
|
|
||||||
|
See the FAQ in imgui.cpp for answers.
|
||||||
|
|
||||||
<b>How do you use ImGui on a platform that may not have a mouse or keyboard?</b>
|
<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) ([sources](https://github.com/synergy/synergy)). In particular, the _src/micro/uSynergy.c_ file contains a small client that you can use on any platform to connect to your host 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.
|
I recommend using [Synergy](http://synergy-project.org) ([sources](https://github.com/synergy/synergy)). In particular, the _src/micro/uSynergy.c_ file contains a small client that you can use on any platform to connect to your host 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 accommodate 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>
|
<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. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools).
|
Yes. I have written data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools).
|
||||||
|
|
||||||
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. Many programmers have unfortunately been taught by their environment to make complicated unproductive things. Strip yourself out of all those heavy layers and start making lots of useful tools!
|
ImGui is very programmer centric and the immediate-mode GUI paradigm might requires you to readjust some habits before you can realize its full potential. Many programmers have unfortunately been taught by their environment to make unnecessarily complicated things. ImGui is about making things that are simple, efficient and powerful.
|
||||||
|
|
||||||
<b>Is ImGui fast?</b>
|
<b>Is ImGui fast?</b>
|
||||||
|
|
||||||
Down to 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.
|
Probably fast enough for most uses. Down to 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 can 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 are likely to be the bottleneck. Testing performance as part of a real application is recommended).
|
Mileage may vary but the following screenshot can 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 are likely to be the bottleneck. Testing performance as part of a real application is recommended).
|
||||||
|
|
||||||
@ -99,7 +118,7 @@ Mileage may vary but the following screenshot can give you a rough idea of the c
|
|||||||
|
|
||||||
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. In contrast, librairies featuring higher-quality rendering and layouting techniques may have a higher resources footprint.
|
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. 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 ImGuiListClipper - 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. If you can handle clipping and height positionning yourself then browsing a list with millions of items isn't a problem.
|
If you intend to display large lists of items (say, 1000+) it can be beneficial for your code to perform clipping manually - one way is using helpers such as ImGuiListClipper - 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. If you can handle clipping and height positionning yourself then browsing a list with millions of items isn't a problem.
|
||||||
|
|
||||||
<b>Can you reskin the look of ImGui?</b>
|
<b>Can you reskin the look of ImGui?</b>
|
||||||
|
|
||||||
@ -109,7 +128,7 @@ You can alter the look of the interface to some degree: changing colors, sizes,
|
|||||||
|
|
||||||
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.
|
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 really need to use ImGui from another language, there is an unofficial but reasonably maintained [c-api for ImGui](https://github.com/Extrawurst/cimgui) by Stephan Dilly. I would suggest using your target language functionality to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. It was really designed with C++ in mind and may not make the same amount of sense with another language.
|
There is an unofficial but reasonably maintained [c-api for ImGui](https://github.com/Extrawurst/cimgui) by Stephan Dilly. I would suggest using your target language functionality to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. It was really designed with C++ in mind and may not make the same amount of sense with another language. Also see [Links](https://github.com/ocornut/imgui/wiki/Links) for third-party bindings to other languages.
|
||||||
|
|
||||||
Donate
|
Donate
|
||||||
------
|
------
|
||||||
@ -118,13 +137,15 @@ Donate
|
|||||||
|
|
||||||
[](http://www.patreon.com/imgui) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5Q73FPZ9C526U)
|
[](http://www.patreon.com/imgui) [](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!
|
I'm currently an independent developer and your contributions are useful. 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. I am available for hire to work on or with ImGui. Thanks!
|
||||||
|
|
||||||
Credits
|
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).
|
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).
|
||||||
|
|
||||||
|
I first discovered imgui principles at [Q-Games](http://www.q-games.com) where Atman had dropped his own simple imgui implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating on it.
|
||||||
|
|
||||||
Embeds [ProggyClean.ttf](http://upperbounds.net) font by Tristan Grimmer (MIT license).
|
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).
|
Embeds [stb_textedit.h, stb_truetype.h, stb_rectpack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain).
|
||||||
@ -137,11 +158,11 @@ Special supporters:
|
|||||||
- Jetha Chan, Wild Sheep Studio, Pastagames, Mārtiņš Možeiko, Daniel Collin, Stefano Cristiano.
|
- Jetha Chan, Wild Sheep Studio, Pastagames, Mārtiņš Možeiko, Daniel Collin, Stefano Cristiano.
|
||||||
|
|
||||||
And:
|
And:
|
||||||
- Michel Courtine, César Leblic, Dale Kim, Alex Evans, Rui Figueira, Paul Patrashcu, Jerome Lanquetot, Ctrl Alt Ninja, Paul Fleming, Neil Henning, Stephan Dilly, Neil Blakey-Milner, Aleksei.
|
- Michel Courtine, César Leblic, Dale Kim, Alex Evans, Rui Figueira, Paul Patrashcu, Jerome Lanquetot, Ctrl Alt Ninja, Paul Fleming, Neil Henning, Stephan Dilly, Neil Blakey-Milner, Aleksei, NeiloGD, Justin Paver, FiniteSol, Vincent Pancaldi, James Billot, Robin Hübner, furrtek, Eric, Simon Barratt, Game Atelier, Julian Bosch, Simon Lundmark, Vincent Hamm.
|
||||||
|
|
||||||
And other supporters; thanks!
|
And other supporters; thanks!
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|
||||||
ImGui is licensed under the MIT License, see LICENSE for more information.
|
Dear ImGui is licensed under the MIT License, see LICENSE for more information.
|
||||||
|
10
examples/.gitignore
vendored
10
examples/.gitignore
vendored
@ -7,6 +7,10 @@ directx9_example/Debug/*
|
|||||||
directx9_example/Release/*
|
directx9_example/Release/*
|
||||||
directx9_example/ipch/*
|
directx9_example/ipch/*
|
||||||
directx9_example/x64/*
|
directx9_example/x64/*
|
||||||
|
directx10_example/Debug/*
|
||||||
|
directx10_example/Release/*
|
||||||
|
directx10_example/ipch/*
|
||||||
|
directx10_example/x64/*
|
||||||
directx11_example/Debug/*
|
directx11_example/Debug/*
|
||||||
directx11_example/Release/*
|
directx11_example/Release/*
|
||||||
directx11_example/ipch/*
|
directx11_example/ipch/*
|
||||||
@ -15,14 +19,20 @@ opengl_example/Debug/*
|
|||||||
opengl_example/Release/*
|
opengl_example/Release/*
|
||||||
opengl_example/ipch/*
|
opengl_example/ipch/*
|
||||||
opengl_example/x64/*
|
opengl_example/x64/*
|
||||||
|
opengl_example/opengl_example
|
||||||
opengl3_example/Debug/*
|
opengl3_example/Debug/*
|
||||||
opengl3_example/Release/*
|
opengl3_example/Release/*
|
||||||
opengl3_example/ipch/*
|
opengl3_example/ipch/*
|
||||||
opengl3_example/x64/*
|
opengl3_example/x64/*
|
||||||
|
opengl3_example/opengl3_example
|
||||||
*.opensdf
|
*.opensdf
|
||||||
*.sdf
|
*.sdf
|
||||||
*.suo
|
*.suo
|
||||||
*.vcxproj.user
|
*.vcxproj.user
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.exe
|
||||||
|
*.pdb
|
||||||
|
|
||||||
## Ini files
|
## Ini files
|
||||||
imgui.ini
|
imgui.ini
|
||||||
|
@ -1,22 +1,28 @@
|
|||||||
Those are standalone ready-to-build applications to demonstrate ImGui.
|
Those are standalone ready-to-build applications to demonstrate ImGui.
|
||||||
Binaries of those demos are available from the main GitHub page.
|
Binaries of some of those demos are available at http://www.miracleworld.net/imgui/binaries
|
||||||
|
|
||||||
TL;DR;
|
TL;DR;
|
||||||
Refer to 'opengl_example' (not 'opengl3_example') to understand how the library is setup.
|
- Newcomers, read 'PROGRAMMER GUIDE' in imgui.cpp for notes on how to setup ImGui in your codebase.
|
||||||
Copy the imgui_impl_xxx.cpp/.h file you need if you are using one of the rendering backend used in an example.
|
- Refer to 'opengl_example' to understand how the library is setup, it is the simplest one.
|
||||||
If you are using a different or your own backend, copy opengl_example/imgui_impl_opengl.cpp/.h to get started.
|
The other examples requires more boilerplate and are harder to read.
|
||||||
|
- If you are using of the backend provided here, so you can copy the imgui_impl_xxx.cpp/h files
|
||||||
|
to your project and use them unmodified.
|
||||||
|
- If you have your own engine, you probably want to start from 'opengl_example' and adapt it to
|
||||||
|
your engine, but you can read the other examples as well.
|
||||||
|
|
||||||
ImGui is highly portable and only requires a few things to run:
|
ImGui is highly portable and only requires a few things to run:
|
||||||
- Providing mouse/keyboard inputs
|
- Providing mouse/keyboard inputs
|
||||||
- Load the font atlas texture into GPU memory
|
- Load the font atlas texture into graphics memory
|
||||||
- Providing a render function to process the drawing commands (we rendere indexed textured triangles)
|
- Providing a render function to render indexed textured triangles
|
||||||
- Extra just as clipboard support, mouse cursor supports, Windows IME support.
|
- Optional: clipboard support, mouse cursor supports, Windows IME support, etc.
|
||||||
So this is essentially what those examples are doing + the obligatory cruft for portability.
|
So this is essentially what those examples are doing + the obligatory cruft for portability.
|
||||||
|
|
||||||
Unfortunately in 2015 it is still a massive pain to create and maintain portable build files using
|
Unfortunately in 2015 it is still tedious to create and maintain portable build files using external
|
||||||
external library like the ones we're using here.
|
libraries (the kind we're using here to create a window and render 3D triangles) without relying on
|
||||||
For most example here I choose to provide Visual Studio 10 .sln files and Makefile for Linux/OSX.
|
third party software. For most examples here I choose to provide:
|
||||||
|
- Makefiles for Linux/OSX
|
||||||
|
- Batch files for Visual Studio 2008+
|
||||||
|
- A .sln project file for Visual Studio 2010+
|
||||||
Please let me know if they don't work with your setup!
|
Please let me know if they don't work with your setup!
|
||||||
You can probably just import the imgui_impl_xxx.cpp/.h files into your own codebase or compile those
|
You can probably just import the imgui_impl_xxx.cpp/.h files into your own codebase or compile those
|
||||||
directly with a command-line compiler.
|
directly with a command-line compiler.
|
||||||
@ -25,26 +31,38 @@ opengl_example/
|
|||||||
OpenGL example, using GLFW + fixed pipeline.
|
OpenGL example, using GLFW + fixed pipeline.
|
||||||
This is simple and should work for all OpenGL enabled applications.
|
This is simple and should work for all OpenGL enabled applications.
|
||||||
Prefer following this example to learn how ImGui works!
|
Prefer following this example to learn how ImGui works!
|
||||||
|
(You can use this code in a GL3/GL4 context but make sure you disable the programmable pipeline
|
||||||
|
by calling "glUseProgram(0)" before ImGui::Render.)
|
||||||
|
|
||||||
opengl3_example/
|
opengl3_example/
|
||||||
OpenGL example, using GLFW/GL3W + programmable pipeline.
|
OpenGL example, using GLFW/GL3W + programmable pipeline.
|
||||||
This uses more modern OpenGL calls and custom shaders.
|
This uses more modern OpenGL calls and custom shaders. It's more messy.
|
||||||
Even if your application is using modern OpenGL you are better off copying the code from the fixed pipeline version!
|
|
||||||
I don't think there is an advantage using this over the simpler example, but it is provided for reference.
|
|
||||||
|
|
||||||
directx9_example/
|
directx9_example/
|
||||||
DirectX9 example, Windows only.
|
DirectX9 example, Windows only.
|
||||||
|
|
||||||
|
directx10_example/
|
||||||
|
DirectX10 example, Windows only.
|
||||||
|
This is quite long and tedious, because: DirectX10.
|
||||||
|
|
||||||
directx11_example/
|
directx11_example/
|
||||||
DirectX11 example, Windows only.
|
DirectX11 example, Windows only.
|
||||||
This is quite long and tedious, because: DirectX11.
|
This is quite long and tedious, because: DirectX11.
|
||||||
|
|
||||||
ios_example/
|
ios_example/
|
||||||
iOS example.
|
iOS example.
|
||||||
Using Synergy to access keyboard/mouse data from server computer. Synergy keyboard integration is rather hacky.
|
Using Synergy to access keyboard/mouse data from server computer.
|
||||||
|
Synergy keyboard integration is rather hacky.
|
||||||
|
|
||||||
sdl_opengl_example/
|
sdl_opengl_example/
|
||||||
SDL2 + OpenGL example.
|
SDL2 + OpenGL example.
|
||||||
|
|
||||||
|
sdl_opengl_example/
|
||||||
|
SDL2 + OpenGL3 example.
|
||||||
|
|
||||||
allegro5_example/
|
allegro5_example/
|
||||||
Allegro 5 example.
|
Allegro 5 example.
|
||||||
|
|
||||||
|
marmalade_example/
|
||||||
|
Marmalade example using IwGx
|
||||||
|
|
||||||
|
@ -4,13 +4,12 @@
|
|||||||
- On Ubuntu 14.04+
|
- On Ubuntu 14.04+
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
g++ -I ../imgui main.cpp imgui_impl_a5.cpp ../imgui/imgui.cpp -lallegro -lallegro_primitives
|
g++ -I ../imgui main.cpp imgui_impl_a5.cpp ../imgui/imgui*.cpp -lallegro -lallegro_primitives
|
||||||
```
|
```
|
||||||
|
|
||||||
- On Windows with Visual Studio's CLI
|
- On Windows with Visual Studio's CLI
|
||||||
|
|
||||||
\<a5path\> is your allegro5 folder.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
cl /MD /I <a5path\include> /I ..\imgui main.cpp imgui_impl_a5.cpp ..\imgui\imgui.cpp /link /LIBPATH:<a5path\lib> allegro-5.0.10-monolith-md.lib user32.lib
|
set ALLEGRODIR=path_to_your_allegro5_folder
|
||||||
|
cl /Zi /MD /I %ALLEGRODIR%\include /I ..\.. main.cpp imgui_impl_a5.cpp ..\..\imgui*.cpp /link /LIBPATH:%ALLEGRODIR%\lib allegro-5.0.10-monolith-md.lib user32.lib
|
||||||
```
|
```
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
// ImGui Allegro 5 bindings
|
// ImGui Allegro 5 bindings
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
// by @birthggd
|
// by @birthggd
|
||||||
|
|
||||||
@ -29,7 +32,7 @@ struct ImDrawVertAllegro
|
|||||||
ALLEGRO_COLOR col;
|
ALLEGRO_COLOR col;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data)
|
void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
int op, src, dst;
|
int op, src, dst;
|
||||||
al_get_blender(&op, &src, &dst);
|
al_get_blender(&op, &src, &dst);
|
||||||
@ -53,7 +56,8 @@ static void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
vertices[i] = v;
|
vertices[i] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME-OPT: Unfortunately Allegro doesn't support 16-bit vertices
|
// FIXME-OPT: Unfortunately Allegro doesn't support 16-bit indices
|
||||||
|
// You can also use '#define ImDrawIdx unsigned int' in imconfig.h and request ImGui to output 32-bit indices
|
||||||
static ImVector<int> indices;
|
static ImVector<int> indices;
|
||||||
indices.resize(cmd_list->IdxBuffer.size());
|
indices.resize(cmd_list->IdxBuffer.size());
|
||||||
for (int i = 0; i < cmd_list->IdxBuffer.size(); ++i)
|
for (int i = 0; i < cmd_list->IdxBuffer.size(); ++i)
|
||||||
@ -84,9 +88,8 @@ static void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
|
|
||||||
bool Imgui_ImplA5_CreateDeviceObjects()
|
bool Imgui_ImplA5_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
|
// Build texture atlas
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
|
||||||
// Build texture
|
|
||||||
unsigned char *pixels;
|
unsigned char *pixels;
|
||||||
int width, height;
|
int width, height;
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
||||||
@ -121,10 +124,6 @@ bool Imgui_ImplA5_CreateDeviceObjects()
|
|||||||
io.Fonts->TexID = (void*)cloned_img;
|
io.Fonts->TexID = (void*)cloned_img;
|
||||||
g_Texture = cloned_img;
|
g_Texture = cloned_img;
|
||||||
|
|
||||||
// Cleanup (don't clear the input data if you want to append new fonts later)
|
|
||||||
io.Fonts->ClearInputData();
|
|
||||||
io.Fonts->ClearTexData();
|
|
||||||
|
|
||||||
// Create an invisible mouse cursor
|
// Create an invisible mouse cursor
|
||||||
// Because al_hide_mouse_cursor() seems to mess up with the actual inputs..
|
// Because al_hide_mouse_cursor() seems to mess up with the actual inputs..
|
||||||
ALLEGRO_BITMAP* mouse_cursor = al_create_bitmap(8,8);
|
ALLEGRO_BITMAP* mouse_cursor = al_create_bitmap(8,8);
|
||||||
@ -186,7 +185,7 @@ bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY* display)
|
|||||||
io.KeyMap[ImGuiKey_Y] = ALLEGRO_KEY_Y;
|
io.KeyMap[ImGuiKey_Y] = ALLEGRO_KEY_Y;
|
||||||
io.KeyMap[ImGuiKey_Z] = ALLEGRO_KEY_Z;
|
io.KeyMap[ImGuiKey_Z] = ALLEGRO_KEY_Z;
|
||||||
|
|
||||||
io.RenderDrawListsFn = ImGui_ImplA5_RenderDrawLists;
|
io.RenderDrawListsFn = ImGui_ImplA5_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
io.ImeWindowHandle = al_get_win_window_handle(g_Display);
|
io.ImeWindowHandle = al_get_win_window_handle(g_Display);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
// ImGui Allegro 5 bindings
|
// ImGui Allegro 5 bindings
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
// by @birthggd
|
// by @birthggd
|
||||||
|
|
||||||
@ -7,12 +10,11 @@
|
|||||||
struct ALLEGRO_DISPLAY;
|
struct ALLEGRO_DISPLAY;
|
||||||
union ALLEGRO_EVENT;
|
union ALLEGRO_EVENT;
|
||||||
|
|
||||||
bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY* display);
|
IMGUI_API bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY* display);
|
||||||
void ImGui_ImplA5_Shutdown();
|
IMGUI_API void ImGui_ImplA5_Shutdown();
|
||||||
void ImGui_ImplA5_NewFrame();
|
IMGUI_API void ImGui_ImplA5_NewFrame();
|
||||||
|
IMGUI_API bool ImGui_ImplA5_ProcessEvent(ALLEGRO_EVENT* event);
|
||||||
bool ImGui_ImplA5_ProcessEvent(ALLEGRO_EVENT* event);
|
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing ImGui state.
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
bool Imgui_ImplA5_CreateDeviceObjects();
|
IMGUI_API bool Imgui_ImplA5_CreateDeviceObjects();
|
||||||
void ImGui_ImplA5_InvalidateDeviceObjects();
|
IMGUI_API void ImGui_ImplA5_InvalidateDeviceObjects();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// ImGui - standalone example application for Allegro 5
|
// ImGui - standalone example application for Allegro 5
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <allegro5/allegro.h>
|
#include <allegro5/allegro.h>
|
||||||
@ -25,7 +26,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplA5_Init(display);
|
ImGui_ImplA5_Init(display);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// (see extra_fonts/README.txt for more details)
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
//ImGuiIO& io = ImGui::GetIO();
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
@ -34,12 +35,6 @@ int main(int, char**)
|
|||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
|
||||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
|
||||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
|
||||||
|
|
||||||
bool show_test_window = true;
|
bool show_test_window = true;
|
||||||
bool show_another_window = false;
|
bool show_another_window = false;
|
||||||
ImVec4 clear_color = ImColor(114, 144, 154);
|
ImVec4 clear_color = ImColor(114, 144, 154);
|
||||||
|
4
examples/directx10_example/build_win32.bat
Normal file
4
examples/directx10_example/build_win32.bat
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler.
|
||||||
|
mkdir Debug
|
||||||
|
cl /nologo /Zi /MD /I ..\.. /I "%WindowsSdkDir%Include\um" /I "%WindowsSdkDir%Include\shared" /I "%DXSDK_DIR%Include" /D UNICODE /D _UNICODE *.cpp ..\..\*.cpp /FeDebug/directx10_example.exe /FoDebug/ /link /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d10.lib d3dcompiler.lib
|
||||||
|
|
159
examples/directx10_example/directx10_example.vcxproj
Normal file
159
examples/directx10_example/directx10_example.vcxproj
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
<?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="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>{345A953E-A004-4648-B442-DC5F9F11068C}</ProjectGuid>
|
||||||
|
<RootNamespace>directx10_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)'=='Debug|x64'" 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>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" 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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||||
|
<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>
|
||||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||||
|
<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)'=='Debug|x64'">
|
||||||
|
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
|
||||||
|
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
|
||||||
|
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
|
||||||
|
<IntDir>$(ProjectDir)$(Configuration)\</IntDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<AdditionalIncludeDirectories>..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>d3d10.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<AdditionalIncludeDirectories>..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>d3d10.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<AdditionalIncludeDirectories>..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<AdditionalDependencies>d3d10.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<AdditionalIncludeDirectories>..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<AdditionalDependencies>d3d10.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\imconfig.h" />
|
||||||
|
<ClInclude Include="..\..\imgui.h" />
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h" />
|
||||||
|
<ClInclude Include="imgui_impl_dx10.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\imgui.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp" />
|
||||||
|
<ClCompile Include="imgui_impl_dx10.cpp" />
|
||||||
|
<ClCompile Include="main.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
45
examples/directx10_example/directx10_example.vcxproj.filters
Normal file
45
examples/directx10_example/directx10_example.vcxproj.filters
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?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_dx10.h">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\imgui.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="main.cpp">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="imgui_impl_dx10.cpp">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
507
examples/directx10_example/imgui_impl_dx10.cpp
Normal file
507
examples/directx10_example/imgui_impl_dx10.cpp
Normal file
@ -0,0 +1,507 @@
|
|||||||
|
// ImGui Win32 + DirectX10 binding
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_dx10.h"
|
||||||
|
|
||||||
|
// DirectX
|
||||||
|
#include <d3d10_1.h>
|
||||||
|
#include <d3d10.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 ID3D10Device* g_pd3dDevice = NULL;
|
||||||
|
static ID3D10Buffer* g_pVB = NULL;
|
||||||
|
static ID3D10Buffer* g_pIB = NULL;
|
||||||
|
static ID3D10Blob * g_pVertexShaderBlob = NULL;
|
||||||
|
static ID3D10VertexShader* g_pVertexShader = NULL;
|
||||||
|
static ID3D10InputLayout* g_pInputLayout = NULL;
|
||||||
|
static ID3D10Buffer* g_pVertexConstantBuffer = NULL;
|
||||||
|
static ID3D10Blob * g_pPixelShaderBlob = NULL;
|
||||||
|
static ID3D10PixelShader* g_pPixelShader = NULL;
|
||||||
|
static ID3D10SamplerState* g_pFontSampler = NULL;
|
||||||
|
static ID3D10ShaderResourceView*g_pFontTextureView = NULL;
|
||||||
|
static ID3D10RasterizerState* g_pRasterizerState = NULL;
|
||||||
|
static ID3D10BlendState* g_pBlendState = NULL;
|
||||||
|
static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000;
|
||||||
|
|
||||||
|
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)
|
||||||
|
void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data)
|
||||||
|
{
|
||||||
|
// Create and grow vertex/index buffers if needed
|
||||||
|
if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
|
||||||
|
{
|
||||||
|
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||||
|
g_VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
||||||
|
D3D10_BUFFER_DESC desc;
|
||||||
|
memset(&desc, 0, sizeof(D3D10_BUFFER_DESC));
|
||||||
|
desc.Usage = D3D10_USAGE_DYNAMIC;
|
||||||
|
desc.ByteWidth = g_VertexBufferSize * sizeof(ImDrawVert);
|
||||||
|
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||||
|
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||||
|
desc.MiscFlags = 0;
|
||||||
|
if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVB) < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount)
|
||||||
|
{
|
||||||
|
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||||
|
g_IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
||||||
|
D3D10_BUFFER_DESC bufferDesc;
|
||||||
|
memset(&bufferDesc, 0, sizeof(D3D10_BUFFER_DESC));
|
||||||
|
bufferDesc.Usage = D3D10_USAGE_DYNAMIC;
|
||||||
|
bufferDesc.ByteWidth = g_IndexBufferSize * sizeof(ImDrawIdx);
|
||||||
|
bufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
||||||
|
bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||||
|
if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pIB) < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy and convert all vertices into a single contiguous buffer
|
||||||
|
ImDrawVert* vtx_dst = NULL;
|
||||||
|
ImDrawIdx* idx_dst = NULL;
|
||||||
|
g_pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&vtx_dst);
|
||||||
|
g_pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&idx_dst);
|
||||||
|
|
||||||
|
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||||
|
{
|
||||||
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||||
|
memcpy(vtx_dst, &cmd_list->VtxBuffer[0], cmd_list->VtxBuffer.size() * sizeof(ImDrawVert));
|
||||||
|
memcpy(idx_dst, &cmd_list->IdxBuffer[0], cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx));
|
||||||
|
vtx_dst += cmd_list->VtxBuffer.size();
|
||||||
|
idx_dst += cmd_list->IdxBuffer.size();
|
||||||
|
}
|
||||||
|
g_pVB->Unmap();
|
||||||
|
g_pIB->Unmap();
|
||||||
|
|
||||||
|
// Setup orthographic projection matrix into our constant buffer
|
||||||
|
{
|
||||||
|
void* mappedResource;
|
||||||
|
if (g_pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mappedResource) != S_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
VERTEX_CONSTANT_BUFFER* pConstantBuffer = (VERTEX_CONSTANT_BUFFER*)mappedResource;
|
||||||
|
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_pVertexConstantBuffer->Unmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup viewport
|
||||||
|
{
|
||||||
|
D3D10_VIEWPORT vp;
|
||||||
|
memset(&vp, 0, sizeof(D3D10_VIEWPORT));
|
||||||
|
vp.Width = (UINT)ImGui::GetIO().DisplaySize.x;
|
||||||
|
vp.Height = (UINT)ImGui::GetIO().DisplaySize.y;
|
||||||
|
vp.MinDepth = 0.0f;
|
||||||
|
vp.MaxDepth = 1.0f;
|
||||||
|
vp.TopLeftX = 0;
|
||||||
|
vp.TopLeftY = 0;
|
||||||
|
g_pd3dDevice->RSSetViewports(1, &vp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind shader and vertex buffers
|
||||||
|
unsigned int stride = sizeof(ImDrawVert);
|
||||||
|
unsigned int offset = 0;
|
||||||
|
g_pd3dDevice->IASetInputLayout(g_pInputLayout);
|
||||||
|
g_pd3dDevice->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
|
||||||
|
g_pd3dDevice->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
|
||||||
|
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||||
|
g_pd3dDevice->VSSetShader(g_pVertexShader);
|
||||||
|
g_pd3dDevice->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
|
||||||
|
g_pd3dDevice->PSSetShader(g_pPixelShader);
|
||||||
|
g_pd3dDevice->PSSetSamplers(0, 1, &g_pFontSampler);
|
||||||
|
|
||||||
|
// Setup render state
|
||||||
|
const float blendFactor[4] = { 0.f, 0.f, 0.f, 0.f };
|
||||||
|
g_pd3dDevice->OMSetBlendState(g_pBlendState, blendFactor, 0xffffffff);
|
||||||
|
g_pd3dDevice->RSSetState(g_pRasterizerState);
|
||||||
|
|
||||||
|
// Render command lists
|
||||||
|
int vtx_offset = 0;
|
||||||
|
int idx_offset = 0;
|
||||||
|
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||||
|
{
|
||||||
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||||
|
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
|
||||||
|
{
|
||||||
|
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||||
|
if (pcmd->UserCallback)
|
||||||
|
{
|
||||||
|
pcmd->UserCallback(cmd_list, pcmd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const D3D10_RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w };
|
||||||
|
g_pd3dDevice->PSSetShaderResources(0, 1, (ID3D10ShaderResourceView**)&pcmd->TextureId);
|
||||||
|
g_pd3dDevice->RSSetScissorRects(1, &r);
|
||||||
|
g_pd3dDevice->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
|
||||||
|
}
|
||||||
|
idx_offset += pcmd->ElemCount;
|
||||||
|
}
|
||||||
|
vtx_offset += cmd_list->VtxBuffer.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore modified state
|
||||||
|
g_pd3dDevice->IASetInputLayout(NULL);
|
||||||
|
g_pd3dDevice->PSSetShader(NULL);
|
||||||
|
g_pd3dDevice->VSSetShader(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
IMGUI_API LRESULT ImGui_ImplDX10_WndProcHandler(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_MBUTTONDOWN:
|
||||||
|
io.MouseDown[2] = true;
|
||||||
|
return true;
|
||||||
|
case WM_MBUTTONUP:
|
||||||
|
io.MouseDown[2] = 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 < 256)
|
||||||
|
io.KeysDown[wParam] = 1;
|
||||||
|
return true;
|
||||||
|
case WM_KEYUP:
|
||||||
|
if (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_ImplDX10_CreateFontsTexture()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// Build
|
||||||
|
unsigned char* pixels;
|
||||||
|
int width, height;
|
||||||
|
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
||||||
|
|
||||||
|
// Create DX10 texture
|
||||||
|
{
|
||||||
|
D3D10_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 = D3D10_USAGE_DEFAULT;
|
||||||
|
texDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
|
||||||
|
texDesc.CPUAccessFlags = 0;
|
||||||
|
|
||||||
|
ID3D10Texture2D *pTexture = NULL;
|
||||||
|
D3D10_SUBRESOURCE_DATA subResource;
|
||||||
|
subResource.pSysMem = pixels;
|
||||||
|
subResource.SysMemPitch = texDesc.Width * 4;
|
||||||
|
subResource.SysMemSlicePitch = 0;
|
||||||
|
g_pd3dDevice->CreateTexture2D(&texDesc, &subResource, &pTexture);
|
||||||
|
|
||||||
|
// Create texture view
|
||||||
|
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
||||||
|
ZeroMemory(&srvDesc, sizeof(srvDesc));
|
||||||
|
srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
srvDesc.ViewDimension = D3D10_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
|
||||||
|
{
|
||||||
|
D3D10_SAMPLER_DESC samplerDesc;
|
||||||
|
ZeroMemory(&samplerDesc, sizeof(samplerDesc));
|
||||||
|
samplerDesc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
|
||||||
|
samplerDesc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
|
||||||
|
samplerDesc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
|
||||||
|
samplerDesc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
|
||||||
|
samplerDesc.MipLODBias = 0.f;
|
||||||
|
samplerDesc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
|
||||||
|
samplerDesc.MinLOD = 0.f;
|
||||||
|
samplerDesc.MaxLOD = 0.f;
|
||||||
|
g_pd3dDevice->CreateSamplerState(&samplerDesc, &g_pFontSampler);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup (don't clear the input data if you want to append new fonts later)
|
||||||
|
io.Fonts->ClearInputData();
|
||||||
|
io.Fonts->ClearTexData();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplDX10_CreateDeviceObjects()
|
||||||
|
{
|
||||||
|
if (!g_pd3dDevice)
|
||||||
|
return false;
|
||||||
|
if (g_pFontSampler)
|
||||||
|
ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||||
|
|
||||||
|
// Create the vertex shader
|
||||||
|
{
|
||||||
|
static const char* vertexShader =
|
||||||
|
"cbuffer vertexBuffer : register(b0) \
|
||||||
|
{\
|
||||||
|
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_4_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(), &g_pVertexShader) != S_OK)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Create the input layout
|
||||||
|
D3D10_INPUT_ELEMENT_DESC localLayout[] = {
|
||||||
|
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||||
|
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||||
|
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D10_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
|
||||||
|
{
|
||||||
|
D3D10_BUFFER_DESC cbDesc;
|
||||||
|
cbDesc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER);
|
||||||
|
cbDesc.Usage = D3D10_USAGE_DYNAMIC;
|
||||||
|
cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
|
||||||
|
cbDesc.CPUAccessFlags = D3D10_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_4_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(), &g_pPixelShader) != S_OK)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the blending setup
|
||||||
|
{
|
||||||
|
D3D10_BLEND_DESC desc;
|
||||||
|
ZeroMemory(&desc, sizeof(desc));
|
||||||
|
desc.AlphaToCoverageEnable = false;
|
||||||
|
desc.BlendEnable[0] = true;
|
||||||
|
desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
|
||||||
|
desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
|
||||||
|
desc.BlendOp = D3D10_BLEND_OP_ADD;
|
||||||
|
desc.SrcBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
|
||||||
|
desc.DestBlendAlpha = D3D10_BLEND_ZERO;
|
||||||
|
desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
|
||||||
|
desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
|
||||||
|
g_pd3dDevice->CreateBlendState(&desc, &g_pBlendState);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the rasterizer state
|
||||||
|
{
|
||||||
|
D3D10_RASTERIZER_DESC desc;
|
||||||
|
ZeroMemory(&desc, sizeof(desc));
|
||||||
|
desc.FillMode = D3D10_FILL_SOLID;
|
||||||
|
desc.CullMode = D3D10_CULL_NONE;
|
||||||
|
desc.ScissorEnable = true;
|
||||||
|
desc.DepthClipEnable = true;
|
||||||
|
g_pd3dDevice->CreateRasterizerState(&desc, &g_pRasterizerState);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui_ImplDX10_CreateFontsTexture();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplDX10_InvalidateDeviceObjects()
|
||||||
|
{
|
||||||
|
if (!g_pd3dDevice)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
|
||||||
|
if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->TexID = 0; }
|
||||||
|
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||||
|
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||||
|
|
||||||
|
if (g_pBlendState) { g_pBlendState->Release(); g_pBlendState = NULL; }
|
||||||
|
if (g_pRasterizerState) { g_pRasterizerState->Release(); g_pRasterizerState = 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_ImplDX10_Init(void* hwnd, ID3D10Device* 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_DOWN;
|
||||||
|
io.KeyMap[ImGuiKey_PageUp] = VK_PRIOR;
|
||||||
|
io.KeyMap[ImGuiKey_PageDown] = VK_NEXT;
|
||||||
|
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_ImplDX10_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
|
||||||
|
io.ImeWindowHandle = g_hWnd;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplDX10_Shutdown()
|
||||||
|
{
|
||||||
|
ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||||
|
ImGui::Shutdown();
|
||||||
|
g_pd3dDevice = NULL;
|
||||||
|
g_hWnd = (HWND)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplDX10_NewFrame()
|
||||||
|
{
|
||||||
|
if (!g_pVB)
|
||||||
|
ImGui_ImplDX10_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 *)¤t_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.KeyAlt = (GetKeyState(VK_MENU) & 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
|
||||||
|
|
||||||
|
// Hide OS mouse cursor if ImGui is drawing it
|
||||||
|
SetCursor(io.MouseDrawCursor ? NULL : LoadCursor(NULL, IDC_ARROW));
|
||||||
|
|
||||||
|
// Start the frame
|
||||||
|
ImGui::NewFrame();
|
||||||
|
}
|
22
examples/directx10_example/imgui_impl_dx10.h
Normal file
22
examples/directx10_example/imgui_impl_dx10.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// ImGui Win32 + DirectX10 binding
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
|
struct ID3D10Device;
|
||||||
|
|
||||||
|
IMGUI_API bool ImGui_ImplDX10_Init(void* hwnd, ID3D10Device* device);
|
||||||
|
IMGUI_API void ImGui_ImplDX10_Shutdown();
|
||||||
|
IMGUI_API void ImGui_ImplDX10_NewFrame();
|
||||||
|
|
||||||
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
|
IMGUI_API void ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||||
|
IMGUI_API bool ImGui_ImplDX10_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.
|
||||||
|
/*
|
||||||
|
IMGUI_API LRESULT ImGui_ImplDX10_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
*/
|
216
examples/directx10_example/main.cpp
Normal file
216
examples/directx10_example/main.cpp
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
// ImGui - standalone example application for DirectX 10
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
|
#include <imgui.h>
|
||||||
|
#include "imgui_impl_dx10.h"
|
||||||
|
#include <d3d10_1.h>
|
||||||
|
#include <d3d10.h>
|
||||||
|
#include <d3dcompiler.h>
|
||||||
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
|
#include <dinput.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static ID3D10Device* g_pd3dDevice = NULL;
|
||||||
|
static IDXGISwapChain* g_pSwapChain = NULL;
|
||||||
|
static ID3D10RenderTargetView* g_mainRenderTargetView = NULL;
|
||||||
|
|
||||||
|
void CreateRenderTarget()
|
||||||
|
{
|
||||||
|
DXGI_SWAP_CHAIN_DESC sd;
|
||||||
|
g_pSwapChain->GetDesc(&sd);
|
||||||
|
|
||||||
|
// Create the render target
|
||||||
|
ID3D10Texture2D* pBackBuffer;
|
||||||
|
D3D10_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 = D3D10_RTV_DIMENSION_TEXTURE2D;
|
||||||
|
g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
|
||||||
|
g_pd3dDevice->CreateRenderTargetView(pBackBuffer, &render_target_view_desc, &g_mainRenderTargetView);
|
||||||
|
g_pd3dDevice->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;
|
||||||
|
//createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
|
||||||
|
if (D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice) != S_OK)
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
|
// Setup rasterizer
|
||||||
|
{
|
||||||
|
D3D10_RASTERIZER_DESC RSDesc;
|
||||||
|
memset(&RSDesc, 0, sizeof(D3D10_RASTERIZER_DESC));
|
||||||
|
RSDesc.FillMode = D3D10_FILL_SOLID;
|
||||||
|
RSDesc.CullMode = D3D10_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;
|
||||||
|
|
||||||
|
ID3D10RasterizerState* pRState = NULL;
|
||||||
|
g_pd3dDevice->CreateRasterizerState(&RSDesc, &pRState);
|
||||||
|
g_pd3dDevice->RSSetState(pRState);
|
||||||
|
pRState->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateRenderTarget();
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CleanupDeviceD3D()
|
||||||
|
{
|
||||||
|
CleanupRenderTarget();
|
||||||
|
if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
|
||||||
|
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
|
||||||
|
}
|
||||||
|
|
||||||
|
extern LRESULT ImGui_ImplDX10_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
if (ImGui_ImplDX10_WndProcHandler(hWnd, msg, wParam, lParam))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
switch (msg)
|
||||||
|
{
|
||||||
|
case WM_SIZE:
|
||||||
|
if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
|
||||||
|
{
|
||||||
|
ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||||
|
CleanupRenderTarget();
|
||||||
|
g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0);
|
||||||
|
CreateRenderTarget();
|
||||||
|
ImGui_ImplDX10_CreateDeviceObjects();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
case WM_SYSCOMMAND:
|
||||||
|
if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
case WM_DESTROY:
|
||||||
|
PostQuitMessage(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int, char**)
|
||||||
|
{
|
||||||
|
// Create application window
|
||||||
|
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("ImGui Example"), NULL };
|
||||||
|
RegisterClassEx(&wc);
|
||||||
|
HWND hwnd = CreateWindow(_T("ImGui Example"), _T("ImGui DirectX10 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
|
||||||
|
|
||||||
|
// Initialize Direct3D
|
||||||
|
if (CreateDeviceD3D(hwnd) < 0)
|
||||||
|
{
|
||||||
|
CleanupDeviceD3D();
|
||||||
|
UnregisterClass(_T("ImGui Example"), wc.hInstance);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the window
|
||||||
|
ShowWindow(hwnd, SW_SHOWDEFAULT);
|
||||||
|
UpdateWindow(hwnd);
|
||||||
|
|
||||||
|
// Setup ImGui binding
|
||||||
|
ImGui_ImplDX10_Init(hwnd, g_pd3dDevice);
|
||||||
|
|
||||||
|
// Load Fonts
|
||||||
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
|
//io.Fonts->AddFontDefault();
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, 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_ImplDX10_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 = 0.0f;
|
||||||
|
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::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver);
|
||||||
|
ImGui::Begin("Another Window", &show_another_window);
|
||||||
|
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_pd3dDevice->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
|
||||||
|
ImGui::Render();
|
||||||
|
g_pSwapChain->Present(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui_ImplDX10_Shutdown();
|
||||||
|
CleanupDeviceD3D();
|
||||||
|
UnregisterClass(_T("ImGui Example"), wc.hInstance);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
4
examples/directx11_example/build_win32.bat
Normal file
4
examples/directx11_example/build_win32.bat
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler.
|
||||||
|
mkdir Debug
|
||||||
|
cl /nologo /Zi /MD /I ..\.. /I "%WindowsSdkDir%Include\um" /I "%WindowsSdkDir%Include\shared" /I "%DXSDK_DIR%Include" /D UNICODE /D _UNICODE *.cpp ..\..\*.cpp /FeDebug/directx11_example.exe /FoDebug/ /link /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d11.lib d3dcompiler.lib
|
||||||
|
|
@ -140,13 +140,19 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\imconfig.h" />
|
<ClInclude Include="..\..\imconfig.h" />
|
||||||
<ClInclude Include="..\..\imgui.h" />
|
<ClInclude Include="..\..\imgui.h" />
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h" />
|
||||||
<ClInclude Include="imgui_impl_dx11.h" />
|
<ClInclude Include="imgui_impl_dx11.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\imgui.cpp" />
|
<ClCompile Include="..\..\imgui.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp" />
|
||||||
<ClCompile Include="imgui_impl_dx11.cpp" />
|
<ClCompile Include="imgui_impl_dx11.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
<ClInclude Include="imgui_impl_dx11.h">
|
<ClInclude Include="imgui_impl_dx11.h">
|
||||||
<Filter>sources</Filter>
|
<Filter>sources</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\imgui.cpp">
|
<ClCompile Include="..\..\imgui.cpp">
|
||||||
@ -29,5 +32,14 @@
|
|||||||
<ClCompile Include="imgui_impl_dx11.cpp">
|
<ClCompile Include="imgui_impl_dx11.cpp">
|
||||||
<Filter>sources</Filter>
|
<Filter>sources</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -1,4 +1,7 @@
|
|||||||
// ImGui Win32 + DirectX11 binding
|
// ImGui Win32 + DirectX11 binding
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@ -29,8 +32,7 @@ static ID3D11SamplerState* g_pFontSampler = NULL;
|
|||||||
static ID3D11ShaderResourceView*g_pFontTextureView = NULL;
|
static ID3D11ShaderResourceView*g_pFontTextureView = NULL;
|
||||||
static ID3D11RasterizerState* g_pRasterizerState = NULL;
|
static ID3D11RasterizerState* g_pRasterizerState = NULL;
|
||||||
static ID3D11BlendState* g_pBlendState = NULL;
|
static ID3D11BlendState* g_pBlendState = NULL;
|
||||||
static int VERTEX_BUFFER_SIZE = 20000; // TODO: Make buffers smaller and grow dynamically as needed.
|
static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000;
|
||||||
static int INDEX_BUFFER_SIZE = 40000; // TODO: Make buffers smaller and grow dynamically as needed.
|
|
||||||
|
|
||||||
struct VERTEX_CONSTANT_BUFFER
|
struct VERTEX_CONSTANT_BUFFER
|
||||||
{
|
{
|
||||||
@ -40,8 +42,37 @@ struct VERTEX_CONSTANT_BUFFER
|
|||||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
// 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:
|
// 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)
|
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||||
static void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data)
|
void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
|
// Create and grow vertex/index buffers if needed
|
||||||
|
if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
|
||||||
|
{
|
||||||
|
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||||
|
g_VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
||||||
|
D3D11_BUFFER_DESC desc;
|
||||||
|
memset(&desc, 0, sizeof(D3D11_BUFFER_DESC));
|
||||||
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||||
|
desc.ByteWidth = g_VertexBufferSize * sizeof(ImDrawVert);
|
||||||
|
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||||
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||||
|
desc.MiscFlags = 0;
|
||||||
|
if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVB) < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount)
|
||||||
|
{
|
||||||
|
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||||
|
g_IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
||||||
|
D3D11_BUFFER_DESC bufferDesc;
|
||||||
|
memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
|
||||||
|
bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||||
|
bufferDesc.ByteWidth = g_IndexBufferSize * sizeof(ImDrawIdx);
|
||||||
|
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||||
|
bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||||
|
if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pIB) < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy and convert all vertices into a single contiguous buffer
|
// Copy and convert all vertices into a single contiguous buffer
|
||||||
D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource;
|
D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource;
|
||||||
if (g_pd3dDeviceContext->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK)
|
if (g_pd3dDeviceContext->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK)
|
||||||
@ -72,10 +103,10 @@ static void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
const float R = ImGui::GetIO().DisplaySize.x;
|
const float R = ImGui::GetIO().DisplaySize.x;
|
||||||
const float B = ImGui::GetIO().DisplaySize.y;
|
const float B = ImGui::GetIO().DisplaySize.y;
|
||||||
const float T = 0.0f;
|
const float T = 0.0f;
|
||||||
const float mvp[4][4] =
|
const float mvp[4][4] =
|
||||||
{
|
{
|
||||||
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f},
|
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
||||||
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f,},
|
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
|
||||||
{ 0.0f, 0.0f, 0.5f, 0.0f },
|
{ 0.0f, 0.0f, 0.5f, 0.0f },
|
||||||
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
||||||
};
|
};
|
||||||
@ -101,7 +132,7 @@ static void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
unsigned int offset = 0;
|
unsigned int offset = 0;
|
||||||
g_pd3dDeviceContext->IASetInputLayout(g_pInputLayout);
|
g_pd3dDeviceContext->IASetInputLayout(g_pInputLayout);
|
||||||
g_pd3dDeviceContext->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
|
g_pd3dDeviceContext->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
|
||||||
g_pd3dDeviceContext->IASetIndexBuffer(g_pIB, DXGI_FORMAT_R16_UINT, 0);
|
g_pd3dDeviceContext->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
|
||||||
g_pd3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
g_pd3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||||
g_pd3dDeviceContext->VSSetShader(g_pVertexShader, NULL, 0);
|
g_pd3dDeviceContext->VSSetShader(g_pVertexShader, NULL, 0);
|
||||||
g_pd3dDeviceContext->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
|
g_pd3dDeviceContext->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
|
||||||
@ -144,7 +175,7 @@ static void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
g_pd3dDeviceContext->VSSetShader(NULL, NULL, 0);
|
g_pd3dDeviceContext->VSSetShader(NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam)
|
IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
switch (msg)
|
switch (msg)
|
||||||
@ -153,20 +184,26 @@ LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lPar
|
|||||||
io.MouseDown[0] = true;
|
io.MouseDown[0] = true;
|
||||||
return true;
|
return true;
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
io.MouseDown[0] = false;
|
io.MouseDown[0] = false;
|
||||||
return true;
|
return true;
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
io.MouseDown[1] = true;
|
io.MouseDown[1] = true;
|
||||||
return true;
|
return true;
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
io.MouseDown[1] = false;
|
io.MouseDown[1] = false;
|
||||||
|
return true;
|
||||||
|
case WM_MBUTTONDOWN:
|
||||||
|
io.MouseDown[2] = true;
|
||||||
|
return true;
|
||||||
|
case WM_MBUTTONUP:
|
||||||
|
io.MouseDown[2] = false;
|
||||||
return true;
|
return true;
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
||||||
return true;
|
return true;
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
io.MousePos.x = (signed short)(lParam);
|
io.MousePos.x = (signed short)(lParam);
|
||||||
io.MousePos.y = (signed short)(lParam >> 16);
|
io.MousePos.y = (signed short)(lParam >> 16);
|
||||||
return true;
|
return true;
|
||||||
case WM_KEYDOWN:
|
case WM_KEYDOWN:
|
||||||
if (wParam < 256)
|
if (wParam < 256)
|
||||||
@ -187,14 +224,13 @@ LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lPar
|
|||||||
|
|
||||||
static void ImGui_ImplDX11_CreateFontsTexture()
|
static void ImGui_ImplDX11_CreateFontsTexture()
|
||||||
{
|
{
|
||||||
|
// Build texture atlas
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
// Build
|
|
||||||
unsigned char* pixels;
|
unsigned char* pixels;
|
||||||
int width, height;
|
int width, height;
|
||||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
||||||
|
|
||||||
// Create DX11 texture
|
// Upload texture to graphics system
|
||||||
{
|
{
|
||||||
D3D11_TEXTURE2D_DESC texDesc;
|
D3D11_TEXTURE2D_DESC texDesc;
|
||||||
ZeroMemory(&texDesc, sizeof(texDesc));
|
ZeroMemory(&texDesc, sizeof(texDesc));
|
||||||
@ -243,23 +279,19 @@ static void ImGui_ImplDX11_CreateFontsTexture()
|
|||||||
samplerDesc.MaxLOD = 0.f;
|
samplerDesc.MaxLOD = 0.f;
|
||||||
g_pd3dDevice->CreateSamplerState(&samplerDesc, &g_pFontSampler);
|
g_pd3dDevice->CreateSamplerState(&samplerDesc, &g_pFontSampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup (don't clear the input data if you want to append new fonts later)
|
|
||||||
io.Fonts->ClearInputData();
|
|
||||||
io.Fonts->ClearTexData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGui_ImplDX11_CreateDeviceObjects()
|
bool ImGui_ImplDX11_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
if (!g_pd3dDevice)
|
if (!g_pd3dDevice)
|
||||||
return false;
|
return false;
|
||||||
if (g_pVB)
|
if (g_pFontSampler)
|
||||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||||
|
|
||||||
// Create the vertex shader
|
// Create the vertex shader
|
||||||
{
|
{
|
||||||
static const char* vertexShader =
|
static const char* vertexShader =
|
||||||
"cbuffer vertexBuffer : register(c0) \
|
"cbuffer vertexBuffer : register(b0) \
|
||||||
{\
|
{\
|
||||||
float4x4 ProjectionMatrix; \
|
float4x4 ProjectionMatrix; \
|
||||||
};\
|
};\
|
||||||
@ -286,7 +318,7 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||||||
return output;\
|
return output;\
|
||||||
}";
|
}";
|
||||||
|
|
||||||
D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &g_pVertexShaderBlob, NULL);
|
D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_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!
|
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;
|
return false;
|
||||||
if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK)
|
if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK)
|
||||||
@ -294,9 +326,9 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||||||
|
|
||||||
// Create the input layout
|
// Create the input layout
|
||||||
D3D11_INPUT_ELEMENT_DESC localLayout[] = {
|
D3D11_INPUT_ELEMENT_DESC localLayout[] = {
|
||||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (g_pd3dDevice->CreateInputLayout(localLayout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK)
|
if (g_pd3dDevice->CreateInputLayout(localLayout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK)
|
||||||
@ -316,7 +348,7 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||||||
|
|
||||||
// Create the pixel shader
|
// Create the pixel shader
|
||||||
{
|
{
|
||||||
static const char* pixelShader =
|
static const char* pixelShader =
|
||||||
"struct PS_INPUT\
|
"struct PS_INPUT\
|
||||||
{\
|
{\
|
||||||
float4 pos : SV_POSITION;\
|
float4 pos : SV_POSITION;\
|
||||||
@ -332,7 +364,7 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||||||
return out_col; \
|
return out_col; \
|
||||||
}";
|
}";
|
||||||
|
|
||||||
D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &g_pPixelShaderBlob, NULL);
|
D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_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!
|
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;
|
return false;
|
||||||
if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK)
|
if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK)
|
||||||
@ -366,31 +398,6 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||||||
g_pd3dDevice->CreateRasterizerState(&desc, &g_pRasterizerState);
|
g_pd3dDevice->CreateRasterizerState(&desc, &g_pRasterizerState);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the vertex buffer
|
|
||||||
{
|
|
||||||
D3D11_BUFFER_DESC desc;
|
|
||||||
memset(&desc, 0, sizeof(D3D11_BUFFER_DESC));
|
|
||||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
||||||
desc.ByteWidth = VERTEX_BUFFER_SIZE * sizeof(ImDrawVert);
|
|
||||||
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
||||||
desc.MiscFlags = 0;
|
|
||||||
if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVB) < 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the index buffer
|
|
||||||
{
|
|
||||||
D3D11_BUFFER_DESC bufferDesc;
|
|
||||||
memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
|
|
||||||
bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
|
|
||||||
bufferDesc.ByteWidth = INDEX_BUFFER_SIZE * sizeof(ImDrawIdx);
|
|
||||||
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
|
||||||
bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
||||||
if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pIB) < 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui_ImplDX11_CreateFontsTexture();
|
ImGui_ImplDX11_CreateFontsTexture();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -402,7 +409,7 @@ void ImGui_ImplDX11_InvalidateDeviceObjects()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
|
if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
|
||||||
if (g_pFontTextureView) { g_pFontTextureView->Release(); ImGui::GetIO().Fonts->TexID = 0; }
|
if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->TexID = 0; }
|
||||||
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||||
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||||
|
|
||||||
@ -422,13 +429,13 @@ bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContex
|
|||||||
g_pd3dDevice = device;
|
g_pd3dDevice = device;
|
||||||
g_pd3dDeviceContext = device_context;
|
g_pd3dDeviceContext = device_context;
|
||||||
|
|
||||||
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond))
|
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond))
|
||||||
return false;
|
return false;
|
||||||
if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time))
|
if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
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_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_LeftArrow] = VK_LEFT;
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
|
io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
|
||||||
io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
|
io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
|
||||||
@ -448,7 +455,7 @@ bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContex
|
|||||||
io.KeyMap[ImGuiKey_Y] = 'Y';
|
io.KeyMap[ImGuiKey_Y] = 'Y';
|
||||||
io.KeyMap[ImGuiKey_Z] = 'Z';
|
io.KeyMap[ImGuiKey_Z] = 'Z';
|
||||||
|
|
||||||
io.RenderDrawListsFn = ImGui_ImplDX11_RenderDrawLists;
|
io.RenderDrawListsFn = ImGui_ImplDX11_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
|
||||||
io.ImeWindowHandle = g_hWnd;
|
io.ImeWindowHandle = g_hWnd;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -477,7 +484,7 @@ void ImGui_ImplDX11_NewFrame()
|
|||||||
|
|
||||||
// Setup time step
|
// Setup time step
|
||||||
INT64 current_time;
|
INT64 current_time;
|
||||||
QueryPerformanceCounter((LARGE_INTEGER *)¤t_time);
|
QueryPerformanceCounter((LARGE_INTEGER *)¤t_time);
|
||||||
io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond;
|
io.DeltaTime = (float)(current_time - g_Time) / g_TicksPerSecond;
|
||||||
g_Time = current_time;
|
g_Time = current_time;
|
||||||
|
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
// ImGui Win32 + DirectX11 binding
|
// ImGui Win32 + DirectX11 binding
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
struct ID3D11Device;
|
struct ID3D11Device;
|
||||||
struct ID3D11DeviceContext;
|
struct ID3D11DeviceContext;
|
||||||
|
|
||||||
bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context);
|
IMGUI_API bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context);
|
||||||
void ImGui_ImplDX11_Shutdown();
|
IMGUI_API void ImGui_ImplDX11_Shutdown();
|
||||||
void ImGui_ImplDX11_NewFrame();
|
IMGUI_API void ImGui_ImplDX11_NewFrame();
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing ImGui state.
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
void ImGui_ImplDX11_InvalidateDeviceObjects();
|
IMGUI_API void ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||||
bool ImGui_ImplDX11_CreateDeviceObjects();
|
IMGUI_API bool ImGui_ImplDX11_CreateDeviceObjects();
|
||||||
|
|
||||||
// Handler for Win32 messages, update mouse/keyboard data.
|
// 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.
|
// 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.
|
// 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);
|
IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
*/
|
*/
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// ImGui - standalone example application for DirectX 11
|
// ImGui - standalone example application for DirectX 11
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "imgui_impl_dx11.h"
|
#include "imgui_impl_dx11.h"
|
||||||
@ -6,6 +7,7 @@
|
|||||||
#include <d3dcompiler.h>
|
#include <d3dcompiler.h>
|
||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
static ID3D11Device* g_pd3dDevice = NULL;
|
static ID3D11Device* g_pd3dDevice = NULL;
|
||||||
@ -57,9 +59,7 @@ HRESULT CreateDeviceD3D(HWND hWnd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
UINT createDeviceFlags = 0;
|
UINT createDeviceFlags = 0;
|
||||||
#ifdef _DEBUG
|
//createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||||
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
|
||||||
#endif
|
|
||||||
D3D_FEATURE_LEVEL featureLevel;
|
D3D_FEATURE_LEVEL featureLevel;
|
||||||
const D3D_FEATURE_LEVEL featureLevelArray[1] = { D3D_FEATURE_LEVEL_11_0, };
|
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)
|
if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 1, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK)
|
||||||
@ -131,15 +131,15 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Create application window
|
// 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 };
|
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("ImGui Example"), NULL };
|
||||||
RegisterClassEx(&wc);
|
RegisterClassEx(&wc);
|
||||||
HWND hwnd = CreateWindow(L"ImGui Example", L"ImGui DirectX11 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
|
HWND hwnd = CreateWindow(_T("ImGui Example"), _T("ImGui DirectX11 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
|
||||||
|
|
||||||
// Initialize Direct3D
|
// Initialize Direct3D
|
||||||
if (CreateDeviceD3D(hwnd) < 0)
|
if (CreateDeviceD3D(hwnd) < 0)
|
||||||
{
|
{
|
||||||
CleanupDeviceD3D();
|
CleanupDeviceD3D();
|
||||||
UnregisterClass(L"ImGui Example", wc.hInstance);
|
UnregisterClass(_T("ImGui Example"), wc.hInstance);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext);
|
ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// (see extra_fonts/README.txt for more details)
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
//ImGuiIO& io = ImGui::GetIO();
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
@ -160,12 +160,6 @@ int main(int, char**)
|
|||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
|
||||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
|
||||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
|
||||||
|
|
||||||
bool show_test_window = true;
|
bool show_test_window = true;
|
||||||
bool show_another_window = false;
|
bool show_another_window = false;
|
||||||
ImVec4 clear_col = ImColor(114, 144, 154);
|
ImVec4 clear_col = ImColor(114, 144, 154);
|
||||||
@ -219,7 +213,7 @@ int main(int, char**)
|
|||||||
|
|
||||||
ImGui_ImplDX11_Shutdown();
|
ImGui_ImplDX11_Shutdown();
|
||||||
CleanupDeviceD3D();
|
CleanupDeviceD3D();
|
||||||
UnregisterClass(L"ImGui Example", wc.hInstance);
|
UnregisterClass(_T("ImGui Example"), wc.hInstance);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
3
examples/directx9_example/build_win32.bat
Normal file
3
examples/directx9_example/build_win32.bat
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler.
|
||||||
|
mkdir Debug
|
||||||
|
cl /nologo /Zi /MD /I ..\.. /I "%DXSDK_DIR%/Include" /D UNICODE /D _UNICODE *.cpp ..\..\*.cpp /FeDebug/directx9_example.exe /FoDebug/ /link /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d9.lib d3dx9d.lib
|
@ -139,14 +139,20 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\imgui.cpp" />
|
<ClCompile Include="..\..\imgui.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp" />
|
||||||
<ClCompile Include="imgui_impl_dx9.cpp" />
|
<ClCompile Include="imgui_impl_dx9.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\imconfig.h" />
|
<ClInclude Include="..\..\imconfig.h" />
|
||||||
<ClInclude Include="..\..\imgui.h" />
|
<ClInclude Include="..\..\imgui.h" />
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h" />
|
||||||
<ClInclude Include="imgui_impl_dx9.h" />
|
<ClInclude Include="imgui_impl_dx9.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -19,6 +19,12 @@
|
|||||||
<ClCompile Include="imgui_impl_dx9.cpp">
|
<ClCompile Include="imgui_impl_dx9.cpp">
|
||||||
<Filter>sources</Filter>
|
<Filter>sources</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\imconfig.h">
|
<ClInclude Include="..\..\imconfig.h">
|
||||||
@ -30,5 +36,11 @@
|
|||||||
<ClInclude Include="imgui_impl_dx9.h">
|
<ClInclude Include="imgui_impl_dx9.h">
|
||||||
<Filter>sources</Filter>
|
<Filter>sources</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -1,4 +1,7 @@
|
|||||||
// ImGui Win32 + DirectX9 binding
|
// ImGui Win32 + DirectX9 binding
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@ -16,8 +19,8 @@ static INT64 g_TicksPerSecond = 0;
|
|||||||
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
|
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
|
||||||
static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;
|
static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;
|
||||||
static LPDIRECT3DINDEXBUFFER9 g_pIB = NULL;
|
static LPDIRECT3DINDEXBUFFER9 g_pIB = NULL;
|
||||||
static int VERTEX_BUFFER_SIZE = 20000; // TODO: Make buffers smaller and grow dynamically as needed.
|
static LPDIRECT3DTEXTURE9 g_FontTexture = NULL;
|
||||||
static int INDEX_BUFFER_SIZE = 40000; // TODO: Make buffers smaller and grow dynamically as needed.
|
static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000;
|
||||||
|
|
||||||
struct CUSTOMVERTEX
|
struct CUSTOMVERTEX
|
||||||
{
|
{
|
||||||
@ -30,8 +33,24 @@ struct CUSTOMVERTEX
|
|||||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
// 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:
|
// 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)
|
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||||
static void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data)
|
void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
|
// Create and grow buffers if needed
|
||||||
|
if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
|
||||||
|
{
|
||||||
|
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||||
|
g_VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
||||||
|
if (g_pd3dDevice->CreateVertexBuffer(g_VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount)
|
||||||
|
{
|
||||||
|
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||||
|
g_IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
||||||
|
if (g_pd3dDevice->CreateIndexBuffer(g_IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &g_pIB, NULL) < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy and convert all vertices into a single contiguous buffer
|
// Copy and convert all vertices into a single contiguous buffer
|
||||||
CUSTOMVERTEX* vtx_dst;
|
CUSTOMVERTEX* vtx_dst;
|
||||||
ImDrawIdx* idx_dst;
|
ImDrawIdx* idx_dst;
|
||||||
@ -86,10 +105,10 @@ static void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
// Setup orthographic projection matrix
|
// Setup orthographic projection matrix
|
||||||
D3DXMATRIXA16 mat;
|
D3DXMATRIXA16 mat;
|
||||||
D3DXMatrixIdentity(&mat);
|
D3DXMatrixIdentity(&mat);
|
||||||
g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat);
|
g_pd3dDevice->SetTransform( D3DTS_WORLD, &mat );
|
||||||
g_pd3dDevice->SetTransform(D3DTS_VIEW, &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);
|
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);
|
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &mat );
|
||||||
|
|
||||||
// Render command lists
|
// Render command lists
|
||||||
int vtx_offset = 0;
|
int vtx_offset = 0;
|
||||||
@ -108,8 +127,8 @@ static void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
{
|
{
|
||||||
const RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w };
|
const RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w };
|
||||||
g_pd3dDevice->SetTexture( 0, (LPDIRECT3DTEXTURE9)pcmd->TextureId );
|
g_pd3dDevice->SetTexture( 0, (LPDIRECT3DTEXTURE9)pcmd->TextureId );
|
||||||
g_pd3dDevice->SetScissorRect(&r);
|
g_pd3dDevice->SetScissorRect( &r );
|
||||||
g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vtx_offset, 0, (UINT)cmd_list->VtxBuffer.size(), idx_offset, pcmd->ElemCount/3);
|
g_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, vtx_offset, 0, (UINT)cmd_list->VtxBuffer.size(), idx_offset, pcmd->ElemCount/3 );
|
||||||
}
|
}
|
||||||
idx_offset += pcmd->ElemCount;
|
idx_offset += pcmd->ElemCount;
|
||||||
}
|
}
|
||||||
@ -117,7 +136,7 @@ static void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT ImGui_ImplDX9_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam)
|
IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
switch (msg)
|
switch (msg)
|
||||||
@ -134,6 +153,12 @@ LRESULT ImGui_ImplDX9_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lPara
|
|||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
io.MouseDown[1] = false;
|
io.MouseDown[1] = false;
|
||||||
return true;
|
return true;
|
||||||
|
case WM_MBUTTONDOWN:
|
||||||
|
io.MouseDown[2] = true;
|
||||||
|
return true;
|
||||||
|
case WM_MBUTTONUP:
|
||||||
|
io.MouseDown[2] = false;
|
||||||
|
return true;
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
||||||
return true;
|
return true;
|
||||||
@ -169,7 +194,7 @@ bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
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_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_LeftArrow] = VK_LEFT;
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
|
io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT;
|
||||||
io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
|
io.KeyMap[ImGuiKey_UpArrow] = VK_UP;
|
||||||
@ -189,7 +214,7 @@ bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device)
|
|||||||
io.KeyMap[ImGuiKey_Y] = 'Y';
|
io.KeyMap[ImGuiKey_Y] = 'Y';
|
||||||
io.KeyMap[ImGuiKey_Z] = 'Z';
|
io.KeyMap[ImGuiKey_Z] = 'Z';
|
||||||
|
|
||||||
io.RenderDrawListsFn = ImGui_ImplDX9_RenderDrawLists;
|
io.RenderDrawListsFn = ImGui_ImplDX9_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
|
||||||
io.ImeWindowHandle = g_hWnd;
|
io.ImeWindowHandle = g_hWnd;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -203,52 +228,37 @@ void ImGui_ImplDX9_Shutdown()
|
|||||||
g_hWnd = 0;
|
g_hWnd = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX9_CreateFontsTexture()
|
static bool ImGui_ImplDX9_CreateFontsTexture()
|
||||||
{
|
{
|
||||||
|
// Build texture atlas
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
// Build
|
|
||||||
unsigned char* pixels;
|
unsigned char* pixels;
|
||||||
int width, height, bytes_per_pixel;
|
int width, height, bytes_per_pixel;
|
||||||
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height, &bytes_per_pixel);
|
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height, &bytes_per_pixel);
|
||||||
|
|
||||||
// Create DX9 texture
|
// Upload texture to graphics system
|
||||||
LPDIRECT3DTEXTURE9 pTexture = NULL;
|
g_FontTexture = NULL;
|
||||||
if (D3DXCreateTexture(g_pd3dDevice, width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8, D3DPOOL_DEFAULT, &pTexture) < 0)
|
if (D3DXCreateTexture(g_pd3dDevice, width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8, D3DPOOL_DEFAULT, &g_FontTexture) < 0)
|
||||||
{
|
return false;
|
||||||
IM_ASSERT(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
D3DLOCKED_RECT tex_locked_rect;
|
D3DLOCKED_RECT tex_locked_rect;
|
||||||
if (pTexture->LockRect(0, &tex_locked_rect, NULL, 0) != D3D_OK)
|
if (g_FontTexture->LockRect(0, &tex_locked_rect, NULL, 0) != D3D_OK)
|
||||||
{
|
return false;
|
||||||
IM_ASSERT(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int y = 0; y < height; y++)
|
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));
|
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);
|
g_FontTexture->UnlockRect(0);
|
||||||
|
|
||||||
// Store our identifier
|
// Store our identifier
|
||||||
io.Fonts->TexID = (void *)pTexture;
|
io.Fonts->TexID = (void *)g_FontTexture;
|
||||||
|
|
||||||
// Cleanup (don't clear the input data if you want to append new fonts later)
|
return true;
|
||||||
io.Fonts->ClearInputData();
|
|
||||||
io.Fonts->ClearTexData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGui_ImplDX9_CreateDeviceObjects()
|
bool ImGui_ImplDX9_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
if (!g_pd3dDevice)
|
if (!g_pd3dDevice)
|
||||||
return false;
|
return false;
|
||||||
|
if (!ImGui_ImplDX9_CreateFontsTexture())
|
||||||
if (g_pd3dDevice->CreateVertexBuffer(VERTEX_BUFFER_SIZE * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (g_pd3dDevice->CreateIndexBuffer(INDEX_BUFFER_SIZE * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIB, NULL) < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ImGui_ImplDX9_CreateFontsTexture();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,11 +281,12 @@ void ImGui_ImplDX9_InvalidateDeviceObjects()
|
|||||||
tex->Release();
|
tex->Release();
|
||||||
ImGui::GetIO().Fonts->TexID = 0;
|
ImGui::GetIO().Fonts->TexID = 0;
|
||||||
}
|
}
|
||||||
|
g_FontTexture = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX9_NewFrame()
|
void ImGui_ImplDX9_NewFrame()
|
||||||
{
|
{
|
||||||
if (!g_pVB)
|
if (!g_FontTexture)
|
||||||
ImGui_ImplDX9_CreateDeviceObjects();
|
ImGui_ImplDX9_CreateDeviceObjects();
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
// ImGui Win32 + DirectX9 binding
|
// ImGui Win32 + DirectX9 binding
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
struct IDirect3DDevice9;
|
struct IDirect3DDevice9;
|
||||||
|
|
||||||
bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device);
|
IMGUI_API bool ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device);
|
||||||
void ImGui_ImplDX9_Shutdown();
|
IMGUI_API void ImGui_ImplDX9_Shutdown();
|
||||||
void ImGui_ImplDX9_NewFrame();
|
IMGUI_API void ImGui_ImplDX9_NewFrame();
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing ImGui state.
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
void ImGui_ImplDX9_InvalidateDeviceObjects();
|
IMGUI_API void ImGui_ImplDX9_InvalidateDeviceObjects();
|
||||||
bool ImGui_ImplDX9_CreateDeviceObjects();
|
IMGUI_API bool ImGui_ImplDX9_CreateDeviceObjects();
|
||||||
|
|
||||||
// Handler for Win32 messages, update mouse/keyboard data.
|
// 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.
|
// 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.
|
// 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);
|
IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
*/
|
*/
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
// ImGui - standalone example application for DirectX 9
|
// ImGui - standalone example application for DirectX 9
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "imgui_impl_dx9.h"
|
#include "imgui_impl_dx9.h"
|
||||||
#include <d3dx9.h>
|
#include <d3dx9.h>
|
||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
|
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
|
||||||
@ -44,15 +46,15 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Create application window
|
// 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 };
|
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("ImGui Example"), NULL };
|
||||||
RegisterClassEx(&wc);
|
RegisterClassEx(&wc);
|
||||||
HWND hwnd = CreateWindow(L"ImGui Example", L"ImGui DirectX9 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
|
HWND hwnd = CreateWindow(_T("ImGui Example"), _T("ImGui DirectX9 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
|
||||||
|
|
||||||
// Initialize Direct3D
|
// Initialize Direct3D
|
||||||
LPDIRECT3D9 pD3D;
|
LPDIRECT3D9 pD3D;
|
||||||
if ((pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
|
if ((pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
|
||||||
{
|
{
|
||||||
UnregisterClass(L"ImGui Example", wc.hInstance);
|
UnregisterClass(_T("ImGui Example"), wc.hInstance);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ZeroMemory(&g_d3dpp, sizeof(g_d3dpp));
|
ZeroMemory(&g_d3dpp, sizeof(g_d3dpp));
|
||||||
@ -67,7 +69,7 @@ int main(int, char**)
|
|||||||
if (pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)
|
if (pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)
|
||||||
{
|
{
|
||||||
pD3D->Release();
|
pD3D->Release();
|
||||||
UnregisterClass(L"ImGui Example", wc.hInstance);
|
UnregisterClass(_T("ImGui Example"), wc.hInstance);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +77,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplDX9_Init(hwnd, g_pd3dDevice);
|
ImGui_ImplDX9_Init(hwnd, g_pd3dDevice);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// (see extra_fonts/README.txt for more details)
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
//ImGuiIO& io = ImGui::GetIO();
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
@ -84,12 +86,6 @@ int main(int, char**)
|
|||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
|
||||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
|
||||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
|
||||||
|
|
||||||
bool show_test_window = true;
|
bool show_test_window = true;
|
||||||
bool show_another_window = false;
|
bool show_another_window = false;
|
||||||
ImVec4 clear_col = ImColor(114, 144, 154);
|
ImVec4 clear_col = ImColor(114, 144, 154);
|
||||||
@ -154,7 +150,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplDX9_Shutdown();
|
ImGui_ImplDX9_Shutdown();
|
||||||
if (g_pd3dDevice) g_pd3dDevice->Release();
|
if (g_pd3dDevice) g_pd3dDevice->Release();
|
||||||
if (pD3D) pD3D->Release();
|
if (pD3D) pD3D->Release();
|
||||||
UnregisterClass(L"ImGui Example", wc.hInstance);
|
UnregisterClass(_T("ImGui Example"), wc.hInstance);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx11_example", "direct
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl3_example", "opengl3_example\opengl3_example.vcxproj", "{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl3_example", "opengl3_example\opengl3_example.vcxproj", "{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directx10_example", "directx10_example\directx10_example.vcxproj", "{345A953E-A004-4648-B442-DC5F9F11068C}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Win32 = Debug|Win32
|
Debug|Win32 = Debug|Win32
|
||||||
@ -49,6 +51,14 @@ Global
|
|||||||
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|Win32.Build.0 = Release|Win32
|
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|Win32.Build.0 = Release|Win32
|
||||||
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|x64.ActiveCfg = Release|x64
|
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|x64.ActiveCfg = Release|x64
|
||||||
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|x64.Build.0 = Release|x64
|
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|x64.Build.0 = Release|x64
|
||||||
|
{345A953E-A004-4648-B442-DC5F9F11068C}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||||
|
{345A953E-A004-4648-B442-DC5F9F11068C}.Debug|Win32.Build.0 = Debug|Win32
|
||||||
|
{345A953E-A004-4648-B442-DC5F9F11068C}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{345A953E-A004-4648-B442-DC5F9F11068C}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{345A953E-A004-4648-B442-DC5F9F11068C}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
|
{345A953E-A004-4648-B442-DC5F9F11068C}.Release|Win32.Build.0 = Release|Win32
|
||||||
|
{345A953E-A004-4648-B442-DC5F9F11068C}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{345A953E-A004-4648-B442-DC5F9F11068C}.Release|x64.Build.0 = Release|x64
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
# iOS example
|
# iOS example
|
||||||
|
|
||||||
----
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
This example is the default XCode "OpenGL" example code, modified to support ImGui and [Synergy](http://synergy-project.org/).
|
This example is the default XCode "OpenGL" example code, modified to support ImGui and [Synergy](http://synergy-project.org/).
|
||||||
|
|
||||||
|
It is a rather complex example because of all of the faff required to get an XCode/iOS application running. Refer to the regular OpenGL examples if you want to learn about integrating ImGui.
|
||||||
|
|
||||||
Synergy (remote keyboard/mouse) is not required, but it's pretty hard to use ImGui without it. Synergy includes a "uSynergy" library that allows embedding a synergy client, this is what is used here. ImGui supports "TouchPadding", and this is enabled when Synergy is not active.
|
Synergy (remote keyboard/mouse) is not required, but it's pretty hard to use ImGui without it. Synergy includes a "uSynergy" library that allows embedding a synergy client, this is what is used here. ImGui supports "TouchPadding", and this is enabled when Synergy is not active.
|
||||||
|
|
||||||
## How to Use
|
## How to Use
|
||||||
----
|
|
||||||
|
|
||||||
0. In Synergy, go to Preferences, and uncheck "Use SSL encryption"
|
0. In Synergy, go to Preferences, and uncheck "Use SSL encryption"
|
||||||
0. Run the example app.
|
0. Run the example app.
|
||||||
@ -16,7 +16,6 @@ Synergy (remote keyboard/mouse) is not required, but it's pretty hard to use ImG
|
|||||||
0. Enter the name or the IP of your synergy host
|
0. Enter the name or the IP of your synergy host
|
||||||
0. If you had previously connected to a server, you may need to kill and re-start the app.
|
0. If you had previously connected to a server, you may need to kill and re-start the app.
|
||||||
|
|
||||||
----
|
|
||||||
## Notes and TODOs
|
## Notes and TODOs
|
||||||
|
|
||||||
Things that would be nice but I didn't get around to doing:
|
Things that would be nice but I didn't get around to doing:
|
||||||
@ -26,7 +25,6 @@ Things that would be nice but I didn't get around to doing:
|
|||||||
* Graceful disconnect/reconnect from uSynergy.
|
* Graceful disconnect/reconnect from uSynergy.
|
||||||
* Copy/Paste not well-supported
|
* Copy/Paste not well-supported
|
||||||
|
|
||||||
----
|
|
||||||
## C++ on iOS
|
## C++ on iOS
|
||||||
ImGui is a c++ library. If you want to include it directly, rename your Obj-C file to have the ".mm" extension.
|
ImGui is a c++ library. If you want to include it directly, rename your Obj-C file to have the ".mm" extension.
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
|
197E1E871B8943FE00E3FE6A /* imgui_draw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 197E1E861B8943FE00E3FE6A /* imgui_draw.cpp */; };
|
||||||
|
197E1E891B89443600E3FE6A /* imgui_demo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 197E1E881B89443600E3FE6A /* imgui_demo.cpp */; };
|
||||||
6D1E39171B35EEF10017B40F /* uSynergy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6D1E39151B35EEF10017B40F /* uSynergy.c */; };
|
6D1E39171B35EEF10017B40F /* uSynergy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6D1E39151B35EEF10017B40F /* uSynergy.c */; };
|
||||||
6D2FC55A1B2E632000C130BA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC5591B2E632000C130BA /* main.m */; };
|
6D2FC55A1B2E632000C130BA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC5591B2E632000C130BA /* main.m */; };
|
||||||
6D2FC55D1B2E632000C130BA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC55C1B2E632000C130BA /* AppDelegate.m */; };
|
6D2FC55D1B2E632000C130BA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D2FC55C1B2E632000C130BA /* AppDelegate.m */; };
|
||||||
@ -24,6 +26,8 @@
|
|||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
197E1E861B8943FE00E3FE6A /* imgui_draw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imgui_draw.cpp; path = ../../imgui_draw.cpp; sourceTree = "<group>"; };
|
||||||
|
197E1E881B89443600E3FE6A /* imgui_demo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imgui_demo.cpp; path = ../../../imgui_demo.cpp; sourceTree = "<group>"; };
|
||||||
6D1E39151B35EEF10017B40F /* uSynergy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = uSynergy.c; sourceTree = "<group>"; };
|
6D1E39151B35EEF10017B40F /* uSynergy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = uSynergy.c; sourceTree = "<group>"; };
|
||||||
6D1E39161B35EEF10017B40F /* uSynergy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uSynergy.h; sourceTree = "<group>"; };
|
6D1E39161B35EEF10017B40F /* uSynergy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uSynergy.h; sourceTree = "<group>"; };
|
||||||
6D2FC5541B2E632000C130BA /* imguiex.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = imguiex.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
6D2FC5541B2E632000C130BA /* imguiex.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = imguiex.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
@ -95,6 +99,7 @@
|
|||||||
children = (
|
children = (
|
||||||
6D2FC5811B2E63A100C130BA /* imgui_impl_ios.mm */,
|
6D2FC5811B2E63A100C130BA /* imgui_impl_ios.mm */,
|
||||||
6D2FC5821B2E63A100C130BA /* imgui_impl_ios.h */,
|
6D2FC5821B2E63A100C130BA /* imgui_impl_ios.h */,
|
||||||
|
197E1E881B89443600E3FE6A /* imgui_demo.cpp */,
|
||||||
6D2FC5891B2E6A5500C130BA /* debug_hud.cpp */,
|
6D2FC5891B2E6A5500C130BA /* debug_hud.cpp */,
|
||||||
6D2FC58A1B2E6A5500C130BA /* debug_hud.h */,
|
6D2FC58A1B2E6A5500C130BA /* debug_hud.h */,
|
||||||
6D2FC55B1B2E632000C130BA /* AppDelegate.h */,
|
6D2FC55B1B2E632000C130BA /* AppDelegate.h */,
|
||||||
@ -126,6 +131,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
6D2FC5851B2E64AB00C130BA /* imconfig.h */,
|
6D2FC5851B2E64AB00C130BA /* imconfig.h */,
|
||||||
|
197E1E861B8943FE00E3FE6A /* imgui_draw.cpp */,
|
||||||
6D2FC5861B2E64AB00C130BA /* imgui.cpp */,
|
6D2FC5861B2E64AB00C130BA /* imgui.cpp */,
|
||||||
6D2FC5871B2E64AB00C130BA /* imgui.h */,
|
6D2FC5871B2E64AB00C130BA /* imgui.h */,
|
||||||
);
|
);
|
||||||
@ -211,6 +217,8 @@
|
|||||||
6D2FC55A1B2E632000C130BA /* main.m in Sources */,
|
6D2FC55A1B2E632000C130BA /* main.m in Sources */,
|
||||||
6D2FC5881B2E64AB00C130BA /* imgui.cpp in Sources */,
|
6D2FC5881B2E64AB00C130BA /* imgui.cpp in Sources */,
|
||||||
6D2FC58B1B2E6A5500C130BA /* debug_hud.cpp in Sources */,
|
6D2FC58B1B2E6A5500C130BA /* debug_hud.cpp in Sources */,
|
||||||
|
197E1E871B8943FE00E3FE6A /* imgui_draw.cpp in Sources */,
|
||||||
|
197E1E891B89443600E3FE6A /* imgui_demo.cpp in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -692,12 +692,15 @@ static void ImGui_ImplIOS_RenderDrawLists (ImDrawData *draw_data)
|
|||||||
|
|
||||||
void ImGui_ImplIOS_CreateFontsTexture()
|
void ImGui_ImplIOS_CreateFontsTexture()
|
||||||
{
|
{
|
||||||
|
// Build texture atlas
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
unsigned char* pixels;
|
unsigned char* pixels;
|
||||||
int width, height;
|
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.
|
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.
|
||||||
|
|
||||||
|
// Upload texture to graphics system
|
||||||
|
GLint last_texture;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
glGenTextures(1, &g_FontTexture);
|
glGenTextures(1, &g_FontTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
@ -706,10 +709,9 @@ void ImGui_ImplIOS_CreateFontsTexture()
|
|||||||
|
|
||||||
// Store our identifier
|
// Store our identifier
|
||||||
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
||||||
|
|
||||||
// Cleanup (don't clear the input data if you want to append new fonts later)
|
// Restore state
|
||||||
io.Fonts->ClearInputData();
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
io.Fonts->ClearTexData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGui_ImplIOS_CreateDeviceObjects()
|
bool ImGui_ImplIOS_CreateDeviceObjects()
|
||||||
@ -767,7 +769,6 @@ bool ImGui_ImplIOS_CreateDeviceObjects()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
glAttachShader(g_ShaderHandle, g_VertHandle);
|
glAttachShader(g_ShaderHandle, g_VertHandle);
|
||||||
glAttachShader(g_ShaderHandle, g_FragHandle);
|
glAttachShader(g_ShaderHandle, g_FragHandle);
|
||||||
glLinkProgram(g_ShaderHandle);
|
glLinkProgram(g_ShaderHandle);
|
||||||
|
@ -82,7 +82,7 @@ static void *get_proc(const char *proc)
|
|||||||
{
|
{
|
||||||
void *res;
|
void *res;
|
||||||
|
|
||||||
res = glXGetProcAddress((const GLubyte *) proc);
|
res = (void*)glXGetProcAddress((const GLubyte *) proc);
|
||||||
if (!res)
|
if (!res)
|
||||||
res = dlsym(libgl, proc);
|
res = dlsym(libgl, proc);
|
||||||
return res;
|
return res;
|
||||||
|
32
examples/marmalade_example/data/app.icf
Normal file
32
examples/marmalade_example/data/app.icf
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# This file is for configuration settings for your
|
||||||
|
# application.
|
||||||
|
#
|
||||||
|
# The syntax is similar to windows .ini files ie
|
||||||
|
#
|
||||||
|
# [GroupName]
|
||||||
|
# Setting = Value
|
||||||
|
#
|
||||||
|
# Which can be read by your application using
|
||||||
|
# e.g s3eConfigGetString("GroupName", "Setting", string)
|
||||||
|
#
|
||||||
|
# All settings must be documented in .config.txt files.
|
||||||
|
# New settings specific to this application should be
|
||||||
|
# documented in app.config.txt
|
||||||
|
#
|
||||||
|
# Some conditional operations are also permitted, see the
|
||||||
|
# S3E documentation for details.
|
||||||
|
|
||||||
|
[S3E]
|
||||||
|
MemSize=6000000
|
||||||
|
MemSizeDebug=6000000
|
||||||
|
DispFixRot=FixedLandscape
|
||||||
|
|
||||||
|
# emulate iphone 5 resolution, change these settings to emulate other display resolution
|
||||||
|
WinWidth=1136
|
||||||
|
WinHeight=640
|
||||||
|
|
||||||
|
[GX]
|
||||||
|
DataCacheSize=131070
|
||||||
|
|
||||||
|
[Util]
|
||||||
|
#MemoryBreakpoint=1282
|
314
examples/marmalade_example/imgui_impl_marmalade.cpp
Normal file
314
examples/marmalade_example/imgui_impl_marmalade.cpp
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
// ImGui Marmalade binding with IwGx
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
|
// Copyright (C) 2015 by Giovanni Zito
|
||||||
|
// This file is part of ImGui
|
||||||
|
|
||||||
|
#include <imgui.h>
|
||||||
|
#include "imgui_impl_marmalade.h"
|
||||||
|
|
||||||
|
#include <s3eClipboard.h>
|
||||||
|
#include <s3ePointer.h>
|
||||||
|
#include <s3eKeyboard.h>
|
||||||
|
#include <IwTexture.h>
|
||||||
|
#include <IwGx.h>
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static double g_Time = 0.0f;
|
||||||
|
static bool g_MousePressed[3] = { false, false, false };
|
||||||
|
static float g_MouseWheel = 0.0f;
|
||||||
|
static CIwTexture* g_FontTexture = NULL;
|
||||||
|
static char* g_ClipboardText = NULL;
|
||||||
|
static bool g_osdKeyboardEnabled = false;
|
||||||
|
|
||||||
|
// use this setting to scale the interface - e.g. on device you could use 2 or 3 scale factor
|
||||||
|
static ImVec2 g_scale = ImVec2(1.0f,1.0f);
|
||||||
|
|
||||||
|
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||||
|
void ImGui_Marmalade_RenderDrawLists(ImDrawData* draw_data)
|
||||||
|
{
|
||||||
|
// Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
draw_data->ScaleClipRects(io.DisplayFramebufferScale);
|
||||||
|
|
||||||
|
// Render command lists
|
||||||
|
for(int n = 0; n < draw_data->CmdListsCount; n++)
|
||||||
|
{
|
||||||
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||||
|
const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->VtxBuffer.front();
|
||||||
|
const ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front();
|
||||||
|
int nVert = cmd_list->VtxBuffer.size();
|
||||||
|
CIwFVec2* pVertStream = IW_GX_ALLOC(CIwFVec2, nVert);
|
||||||
|
CIwFVec2* pUVStream = IW_GX_ALLOC(CIwFVec2, nVert);
|
||||||
|
CIwColour* pColStream = IW_GX_ALLOC(CIwColour, nVert);
|
||||||
|
|
||||||
|
for( int i=0; i < nVert; i++ )
|
||||||
|
{
|
||||||
|
// TODO: optimize multiplication on gpu using vertex shader
|
||||||
|
pVertStream[i].x = cmd_list->VtxBuffer[i].pos.x * g_scale.x;
|
||||||
|
pVertStream[i].y = cmd_list->VtxBuffer[i].pos.y * g_scale.y;
|
||||||
|
pUVStream[i].x = cmd_list->VtxBuffer[i].uv.x;
|
||||||
|
pUVStream[i].y = cmd_list->VtxBuffer[i].uv.y;
|
||||||
|
pColStream[i] = cmd_list->VtxBuffer[i].col;
|
||||||
|
}
|
||||||
|
|
||||||
|
IwGxSetVertStreamScreenSpace(pVertStream, nVert);
|
||||||
|
IwGxSetUVStream(pUVStream);
|
||||||
|
IwGxSetColStream(pColStream, nVert);
|
||||||
|
IwGxSetNormStream(0);
|
||||||
|
|
||||||
|
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
|
||||||
|
{
|
||||||
|
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||||||
|
if (pcmd->UserCallback)
|
||||||
|
{
|
||||||
|
pcmd->UserCallback(cmd_list,pcmd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CIwMaterial* pCurrentMaterial = IW_GX_ALLOC_MATERIAL();
|
||||||
|
pCurrentMaterial->SetShadeMode(CIwMaterial::SHADE_FLAT);
|
||||||
|
pCurrentMaterial->SetCullMode(CIwMaterial::CULL_NONE);
|
||||||
|
pCurrentMaterial->SetFiltering(false);
|
||||||
|
pCurrentMaterial->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
|
||||||
|
pCurrentMaterial->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_NORMAL);
|
||||||
|
pCurrentMaterial->SetAlphaTestMode(CIwMaterial::ALPHATEST_DISABLED);
|
||||||
|
pCurrentMaterial->SetTexture((CIwTexture*)pcmd->TextureId);
|
||||||
|
IwGxSetMaterial(pCurrentMaterial);
|
||||||
|
IwGxDrawPrims(IW_GX_TRI_LIST, (uint16*)idx_buffer, pcmd->ElemCount);
|
||||||
|
}
|
||||||
|
idx_buffer += pcmd->ElemCount;
|
||||||
|
}
|
||||||
|
IwGxFlush();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: restore modified state (i.e. mvp matrix)
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* ImGui_Marmalade_GetClipboardText()
|
||||||
|
{
|
||||||
|
if (s3eClipboardAvailable())
|
||||||
|
{
|
||||||
|
int size = s3eClipboardGetText(NULL, 0);
|
||||||
|
if (size > 0)
|
||||||
|
{
|
||||||
|
if (g_ClipboardText)
|
||||||
|
{
|
||||||
|
delete[] g_ClipboardText;
|
||||||
|
g_ClipboardText = NULL;
|
||||||
|
}
|
||||||
|
g_ClipboardText = new char[size];
|
||||||
|
g_ClipboardText[0] = '\0';
|
||||||
|
s3eClipboardGetText(g_ClipboardText, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_ClipboardText;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_Marmalade_SetClipboardText(const char* text)
|
||||||
|
{
|
||||||
|
if (s3eClipboardAvailable())
|
||||||
|
s3eClipboardSetText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 ImGui_Marmalade_PointerButtonEventCallback(void* SystemData, void* pUserData)
|
||||||
|
{
|
||||||
|
// pEvent->m_Button is of type s3ePointerButton and indicates which mouse
|
||||||
|
// button was pressed. For touchscreen this should always have the value
|
||||||
|
// S3E_POINTER_BUTTON_SELECT
|
||||||
|
s3ePointerEvent* pEvent = (s3ePointerEvent*)SystemData;
|
||||||
|
|
||||||
|
if (pEvent->m_Pressed == 1)
|
||||||
|
{
|
||||||
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_LEFTMOUSE)
|
||||||
|
g_MousePressed[0] = true;
|
||||||
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_RIGHTMOUSE)
|
||||||
|
g_MousePressed[1] = true;
|
||||||
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_MIDDLEMOUSE)
|
||||||
|
g_MousePressed[2] = true;
|
||||||
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELUP)
|
||||||
|
g_MouseWheel += pEvent->m_y;
|
||||||
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELDOWN)
|
||||||
|
g_MouseWheel += pEvent->m_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 ImGui_Marmalade_KeyCallback(void* SystemData, void* userData)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
s3eKeyboardEvent* e = (s3eKeyboardEvent*)SystemData;
|
||||||
|
if (e->m_Pressed == 1)
|
||||||
|
io.KeysDown[e->m_Key] = true;
|
||||||
|
if (e->m_Pressed == 0)
|
||||||
|
io.KeysDown[e->m_Key] = false;
|
||||||
|
|
||||||
|
io.KeyCtrl = s3eKeyboardGetState(s3eKeyLeftControl) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightControl) == S3E_KEY_STATE_DOWN;
|
||||||
|
io.KeyShift = s3eKeyboardGetState(s3eKeyLeftShift) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightShift) == S3E_KEY_STATE_DOWN;
|
||||||
|
io.KeyAlt = s3eKeyboardGetState(s3eKeyLeftAlt) == S3E_KEY_STATE_DOWN || s3eKeyboardGetState(s3eKeyRightAlt) == S3E_KEY_STATE_DOWN;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 ImGui_Marmalade_CharCallback(void* SystemData, void* userData)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
s3eKeyboardCharEvent* e = (s3eKeyboardCharEvent*)SystemData;
|
||||||
|
if ((e->m_Char > 0 && e->m_Char < 0x10000))
|
||||||
|
io.AddInputCharacter((unsigned short)e->m_Char);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_Marmalade_CreateDeviceObjects()
|
||||||
|
{
|
||||||
|
// Build texture atlas
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
unsigned char* pixels;
|
||||||
|
int width, height;
|
||||||
|
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
||||||
|
|
||||||
|
// Upload texture to graphics system
|
||||||
|
g_FontTexture = new CIwTexture();
|
||||||
|
g_FontTexture->SetModifiable(true);
|
||||||
|
CIwImage& image = g_FontTexture->GetImage();
|
||||||
|
image.SetFormat(CIwImage::ARGB_8888);
|
||||||
|
image.SetWidth(width);
|
||||||
|
image.SetHeight(height);
|
||||||
|
image.SetBuffers(); // allocates and own buffers
|
||||||
|
image.ReadTexels(pixels);
|
||||||
|
g_FontTexture->SetMipMapping(false);
|
||||||
|
g_FontTexture->SetFiltering(false);
|
||||||
|
g_FontTexture->Upload();
|
||||||
|
|
||||||
|
// Store our identifier
|
||||||
|
io.Fonts->TexID = (void *)g_FontTexture;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_Marmalade_InvalidateDeviceObjects()
|
||||||
|
{
|
||||||
|
if (g_ClipboardText)
|
||||||
|
{
|
||||||
|
delete[] g_ClipboardText;
|
||||||
|
g_ClipboardText = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_FontTexture)
|
||||||
|
{
|
||||||
|
delete g_FontTexture;
|
||||||
|
ImGui::GetIO().Fonts->TexID = 0;
|
||||||
|
g_FontTexture = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_Marmalade_Init(bool install_callbacks)
|
||||||
|
{
|
||||||
|
IwGxInit();
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.KeyMap[ImGuiKey_Tab] = s3eKeyTab; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
|
||||||
|
io.KeyMap[ImGuiKey_LeftArrow] = s3eKeyLeft;
|
||||||
|
io.KeyMap[ImGuiKey_RightArrow] = s3eKeyRight;
|
||||||
|
io.KeyMap[ImGuiKey_UpArrow] = s3eKeyUp;
|
||||||
|
io.KeyMap[ImGuiKey_DownArrow] = s3eKeyDown;
|
||||||
|
io.KeyMap[ImGuiKey_PageUp] = s3eKeyPageUp;
|
||||||
|
io.KeyMap[ImGuiKey_PageDown] = s3eKeyPageDown;
|
||||||
|
io.KeyMap[ImGuiKey_Home] = s3eKeyHome;
|
||||||
|
io.KeyMap[ImGuiKey_End] = s3eKeyEnd;
|
||||||
|
io.KeyMap[ImGuiKey_Delete] = s3eKeyDelete;
|
||||||
|
io.KeyMap[ImGuiKey_Backspace] = s3eKeyBackspace;
|
||||||
|
io.KeyMap[ImGuiKey_Enter] = s3eKeyEnter;
|
||||||
|
io.KeyMap[ImGuiKey_Escape] = s3eKeyEsc;
|
||||||
|
io.KeyMap[ImGuiKey_A] = s3eKeyA;
|
||||||
|
io.KeyMap[ImGuiKey_C] = s3eKeyC;
|
||||||
|
io.KeyMap[ImGuiKey_V] = s3eKeyV;
|
||||||
|
io.KeyMap[ImGuiKey_X] = s3eKeyX;
|
||||||
|
io.KeyMap[ImGuiKey_Y] = s3eKeyY;
|
||||||
|
io.KeyMap[ImGuiKey_Z] = s3eKeyZ;
|
||||||
|
|
||||||
|
io.RenderDrawListsFn = ImGui_Marmalade_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
|
||||||
|
io.SetClipboardTextFn = ImGui_Marmalade_SetClipboardText;
|
||||||
|
io.GetClipboardTextFn = ImGui_Marmalade_GetClipboardText;
|
||||||
|
|
||||||
|
if (install_callbacks)
|
||||||
|
{
|
||||||
|
s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, ImGui_Marmalade_PointerButtonEventCallback, 0);
|
||||||
|
s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, ImGui_Marmalade_KeyCallback, 0);
|
||||||
|
s3eKeyboardRegister(S3E_KEYBOARD_CHAR_EVENT, ImGui_Marmalade_CharCallback, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_Marmalade_Shutdown()
|
||||||
|
{
|
||||||
|
ImGui_Marmalade_InvalidateDeviceObjects();
|
||||||
|
ImGui::Shutdown();
|
||||||
|
IwGxTerminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_Marmalade_NewFrame()
|
||||||
|
{
|
||||||
|
if (!g_FontTexture)
|
||||||
|
ImGui_Marmalade_CreateDeviceObjects();
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// Setup display size (every frame to accommodate for window resizing)
|
||||||
|
int w = IwGxGetScreenWidth(), h = IwGxGetScreenHeight();
|
||||||
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||||
|
// For retina display or other situations where window coordinates are different from framebuffer coordinates. User storage only, presently not used by ImGui.
|
||||||
|
io.DisplayFramebufferScale = g_scale;
|
||||||
|
|
||||||
|
// Setup time step
|
||||||
|
double current_time = s3eTimerGetUST() / 1000.0f;
|
||||||
|
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
|
||||||
|
g_Time = current_time;
|
||||||
|
|
||||||
|
double mouse_x, mouse_y;
|
||||||
|
mouse_x = s3ePointerGetX();
|
||||||
|
mouse_y = s3ePointerGetY();
|
||||||
|
io.MousePos = ImVec2((float)mouse_x/g_scale.x, (float)mouse_y/g_scale.y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
io.MouseDown[i] = g_MousePressed[i] || s3ePointerGetState((s3ePointerButton)i) != S3E_POINTER_STATE_UP; // 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;
|
||||||
|
|
||||||
|
// TODO: Hide OS mouse cursor if ImGui is drawing it
|
||||||
|
// s3ePointerSetInt(S3E_POINTER_HIDE_CURSOR,(io.MouseDrawCursor ? 0 : 1));
|
||||||
|
|
||||||
|
// Start the frame
|
||||||
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Show/hide OSD keyboard
|
||||||
|
if (io.WantTextInput)
|
||||||
|
{
|
||||||
|
// Some text input widget is active?
|
||||||
|
if (!g_osdKeyboardEnabled)
|
||||||
|
{
|
||||||
|
g_osdKeyboardEnabled = true;
|
||||||
|
s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 1); // show OSD keyboard
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No text input widget is active
|
||||||
|
if (g_osdKeyboardEnabled)
|
||||||
|
{
|
||||||
|
g_osdKeyboardEnabled = false;
|
||||||
|
s3eKeyboardSetInt(S3E_KEYBOARD_GET_CHAR, 0); // hide OSD keyboard
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
examples/marmalade_example/imgui_impl_marmalade.h
Normal file
22
examples/marmalade_example/imgui_impl_marmalade.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// ImGui Marmalade binding with IwGx
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
|
// Copyright (C) 2015 by Giovanni Zito
|
||||||
|
// This file is part of ImGui
|
||||||
|
|
||||||
|
IMGUI_API bool ImGui_Marmalade_Init(bool install_callbacks);
|
||||||
|
IMGUI_API void ImGui_Marmalade_Shutdown();
|
||||||
|
IMGUI_API void ImGui_Marmalade_NewFrame();
|
||||||
|
|
||||||
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
|
IMGUI_API void ImGui_Marmalade_InvalidateDeviceObjects();
|
||||||
|
IMGUI_API bool ImGui_Marmalade_CreateDeviceObjects();
|
||||||
|
|
||||||
|
// callbacks (installed by default if you enable 'install_callbacks' during initialization)
|
||||||
|
// You can also handle inputs yourself and use those as a reference.
|
||||||
|
IMGUI_API int32 ImGui_Marmalade_PointerButtonEventCallback(void* SystemData, void* pUserData);
|
||||||
|
IMGUI_API int32 ImGui_Marmalade_KeyCallback(void* SystemData, void* userData);
|
||||||
|
IMGUI_API int32 ImGui_Marmalade_CharCallback(void* SystemData, void* userData);
|
85
examples/marmalade_example/main.cpp
Normal file
85
examples/marmalade_example/main.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// ImGui - standalone example application for Marmalade
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
|
// Copyright (C) 2015 by Giovanni Zito
|
||||||
|
// This file is part of ImGui
|
||||||
|
|
||||||
|
#include <imgui.h>
|
||||||
|
#include "imgui_impl_marmalade.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <s3eKeyboard.h>
|
||||||
|
#include <s3ePointer.h>
|
||||||
|
#include <IwGx.h>
|
||||||
|
|
||||||
|
int main(int, char**)
|
||||||
|
{
|
||||||
|
// Setup ImGui binding
|
||||||
|
ImGui_Marmalade_Init(true);
|
||||||
|
|
||||||
|
// Load Fonts
|
||||||
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
|
//io.Fonts->AddFontDefault();
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
|
bool show_test_window = true;
|
||||||
|
bool show_another_window = false;
|
||||||
|
ImVec4 clear_color = ImColor(114, 144, 154);
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (s3eDeviceCheckQuitRequest())
|
||||||
|
break;
|
||||||
|
|
||||||
|
s3eKeyboardUpdate();
|
||||||
|
s3ePointerUpdate();
|
||||||
|
ImGui_Marmalade_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 = 0.0f;
|
||||||
|
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::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver);
|
||||||
|
ImGui::Begin("Another Window", &show_another_window);
|
||||||
|
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
|
||||||
|
IwGxSetColClear(clear_color.x*255,clear_color.y*255,clear_color.z*255,clear_color.w*255) ;
|
||||||
|
IwGxClear();
|
||||||
|
ImGui::Render();
|
||||||
|
IwGxSwapBuffers();
|
||||||
|
|
||||||
|
s3eDeviceYield(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_Marmalade_Shutdown();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
44
examples/marmalade_example/marmalade_example.mkb
Normal file
44
examples/marmalade_example/marmalade_example.mkb
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env mkb
|
||||||
|
|
||||||
|
# ImGui - standalone example application for Marmalade
|
||||||
|
# Copyright (C) 2015 by Giovanni Zito
|
||||||
|
# This file is part of ImGui
|
||||||
|
# https://github.com/ocornut/imgui
|
||||||
|
|
||||||
|
define IMGUI_DISABLE_INCLUDE_IMCONFIG_H
|
||||||
|
define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
|
||||||
|
define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS
|
||||||
|
define _snprintf=snprintf
|
||||||
|
|
||||||
|
options
|
||||||
|
{
|
||||||
|
optimise-speed=1
|
||||||
|
}
|
||||||
|
|
||||||
|
includepaths
|
||||||
|
{
|
||||||
|
../..
|
||||||
|
}
|
||||||
|
|
||||||
|
subprojects
|
||||||
|
{
|
||||||
|
iwgx
|
||||||
|
}
|
||||||
|
|
||||||
|
files
|
||||||
|
{
|
||||||
|
(.)
|
||||||
|
["imgui"]
|
||||||
|
../../imgui.cpp
|
||||||
|
../../imgui_demo.cpp
|
||||||
|
../../imgui_draw.cpp
|
||||||
|
../../imconfig.h
|
||||||
|
../../imgui.h
|
||||||
|
../../imgui_internal.h
|
||||||
|
|
||||||
|
["imgui","Marmalade binding"]
|
||||||
|
imgui_impl_marmalade.h
|
||||||
|
imgui_impl_marmalade.cpp
|
||||||
|
main.cpp
|
||||||
|
|
||||||
|
}
|
@ -10,8 +10,9 @@
|
|||||||
|
|
||||||
#CXX = g++
|
#CXX = g++
|
||||||
|
|
||||||
|
EXE = opengl3_example
|
||||||
OBJS = main.o imgui_impl_glfw_gl3.o
|
OBJS = main.o imgui_impl_glfw_gl3.o
|
||||||
OBJS += ../../imgui.o
|
OBJS += ../../imgui.o ../../imgui_demo.o ../../imgui_draw.o
|
||||||
OBJS += ../libs/gl3w/GL/gl3w.o
|
OBJS += ../libs/gl3w/GL/gl3w.o
|
||||||
|
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
@ -22,7 +23,7 @@ ifeq ($(UNAME_S), Linux) #LINUX
|
|||||||
LIBS = `pkg-config --static --libs glfw3`
|
LIBS = `pkg-config --static --libs glfw3`
|
||||||
|
|
||||||
CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags glfw3`
|
CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags glfw3`
|
||||||
CXXFLAGS += -Wall
|
CXXFLAGS += -Wall -Wformat
|
||||||
CFLAGS = $(CXXFLAGS)
|
CFLAGS = $(CXXFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -33,20 +34,29 @@ ifeq ($(UNAME_S), Darwin) #APPLE
|
|||||||
LIBS += -lglfw3
|
LIBS += -lglfw3
|
||||||
|
|
||||||
CXXFLAGS = -I../../ -I../libs/gl3w -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include
|
CXXFLAGS = -I../../ -I../libs/gl3w -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include
|
||||||
CXXFLAGS += -Wall
|
CXXFLAGS += -Wall -Wformat
|
||||||
# CXXFLAGS += -D__APPLE__
|
# CXXFLAGS += -D__APPLE__
|
||||||
CFLAGS = $(CXXFLAGS)
|
CFLAGS = $(CXXFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(UNAME_S), MINGW64_NT-6.3)
|
||||||
|
ECHO_MESSAGE = "Windows"
|
||||||
|
LIBS = -lglfw3 -lgdi32 -lopengl32 -limm32
|
||||||
|
|
||||||
|
CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags glfw3`
|
||||||
|
CXXFLAGS += -Wall -Wformat
|
||||||
|
CFLAGS = $(CXXFLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
.cpp.o:
|
.cpp.o:
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
all:imgui_example
|
all: $(EXE)
|
||||||
@echo Build complete for $(ECHO_MESSAGE)
|
@echo Build complete for $(ECHO_MESSAGE)
|
||||||
|
|
||||||
imgui_example:$(OBJS)
|
$(EXE): $(OBJS)
|
||||||
$(CXX) -o imgui_example $(OBJS) $(CXXFLAGS) $(LIBS)
|
$(CXX) -o $(EXE) $(OBJS) $(CXXFLAGS) $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJS)
|
rm $(EXE) $(OBJS)
|
||||||
|
|
||||||
|
3
examples/opengl3_example/build_win32.bat
Normal file
3
examples/opengl3_example/build_win32.bat
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler.
|
||||||
|
mkdir Debug
|
||||||
|
cl /nologo /Zi /MD /I ..\.. /I ..\libs\glfw\include /I ..\libs\gl3w *.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /FeDebug/opengl_example3.exe /FoDebug/ /link /LIBPATH:..\libs\glfw\lib-vc2010-32 glfw3.lib opengl32.lib gdi32.lib shell32.lib
|
@ -1,4 +1,7 @@
|
|||||||
// ImGui GLFW binding with OpenGL3 + shaders
|
// ImGui GLFW binding with OpenGL3 + shaders
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@ -7,7 +10,7 @@
|
|||||||
// GL3W/GLFW
|
// GL3W/GLFW
|
||||||
#include <GL/gl3w.h>
|
#include <GL/gl3w.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#ifdef _MSC_VER
|
#ifdef _WIN32
|
||||||
#undef APIENTRY
|
#undef APIENTRY
|
||||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||||
#define GLFW_EXPOSE_NATIVE_WGL
|
#define GLFW_EXPOSE_NATIVE_WGL
|
||||||
@ -23,18 +26,30 @@ static GLuint g_FontTexture = 0;
|
|||||||
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
||||||
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
||||||
static int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0;
|
static int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0;
|
||||||
static int g_VboSize = 0;
|
static unsigned int g_VboHandle = 0, g_VaoHandle = 0, g_ElementsHandle = 0;
|
||||||
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)
|
// 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:
|
// 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)
|
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||||
static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)
|
void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
|
// Backup GL state
|
||||||
|
GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
||||||
|
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
|
GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||||
|
GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer);
|
||||||
|
GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||||
|
GLint last_blend_src; glGetIntegerv(GL_BLEND_SRC, &last_blend_src);
|
||||||
|
GLint last_blend_dst; glGetIntegerv(GL_BLEND_DST, &last_blend_dst);
|
||||||
|
GLint last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, &last_blend_equation_rgb);
|
||||||
|
GLint last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &last_blend_equation_alpha);
|
||||||
|
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
||||||
|
GLboolean last_enable_blend = glIsEnabled(GL_BLEND);
|
||||||
|
GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
|
||||||
|
GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||||
|
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
|
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
|
||||||
GLint last_program, last_texture;
|
|
||||||
glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
|
||||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendEquation(GL_FUNC_ADD);
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
@ -43,15 +58,20 @@ static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
// Setup orthographic projection matrix
|
// Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
|
||||||
const float width = ImGui::GetIO().DisplaySize.x;
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
const float height = ImGui::GetIO().DisplaySize.y;
|
int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x);
|
||||||
|
int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y);
|
||||||
|
draw_data->ScaleClipRects(io.DisplayFramebufferScale);
|
||||||
|
|
||||||
|
// Setup viewport, orthographic projection matrix
|
||||||
|
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
|
||||||
const float ortho_projection[4][4] =
|
const float ortho_projection[4][4] =
|
||||||
{
|
{
|
||||||
{ 2.0f/width, 0.0f, 0.0f, 0.0f },
|
{ 2.0f/io.DisplaySize.x, 0.0f, 0.0f, 0.0f },
|
||||||
{ 0.0f, 2.0f/-height, 0.0f, 0.0f },
|
{ 0.0f, 2.0f/-io.DisplaySize.y, 0.0f, 0.0f },
|
||||||
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
||||||
{ -1.0f, 1.0f, 0.0f, 1.0f },
|
{-1.0f, 1.0f, 0.0f, 1.0f },
|
||||||
};
|
};
|
||||||
glUseProgram(g_ShaderHandle);
|
glUseProgram(g_ShaderHandle);
|
||||||
glUniform1i(g_AttribLocationTex, 0);
|
glUniform1i(g_AttribLocationTex, 0);
|
||||||
@ -61,22 +81,13 @@ static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||||
{
|
{
|
||||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||||
const ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front();
|
const ImDrawIdx* idx_buffer_offset = 0;
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||||
int needed_vtx_size = cmd_list->VtxBuffer.size() * sizeof(ImDrawVert);
|
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.size() * sizeof(ImDrawVert), (GLvoid*)&cmd_list->VtxBuffer.front(), GL_STREAM_DRAW);
|
||||||
if (g_VboSize < needed_vtx_size)
|
|
||||||
{
|
|
||||||
// Grow our buffer if needed
|
|
||||||
g_VboSize = needed_vtx_size + 2000 * sizeof(ImDrawVert);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)g_VboSize, NULL, GL_STREAM_DRAW);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char* vtx_data = (unsigned char*)glMapBufferRange(GL_ARRAY_BUFFER, 0, needed_vtx_size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
|
||||||
if (!vtx_data)
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx), (GLvoid*)&cmd_list->IdxBuffer.front(), GL_STREAM_DRAW);
|
||||||
continue;
|
|
||||||
memcpy(vtx_data, &cmd_list->VtxBuffer[0], cmd_list->VtxBuffer.size() * sizeof(ImDrawVert));
|
|
||||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
|
||||||
|
|
||||||
for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != cmd_list->CmdBuffer.end(); pcmd++)
|
for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != cmd_list->CmdBuffer.end(); pcmd++)
|
||||||
{
|
{
|
||||||
@ -87,19 +98,26 @@ static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||||
glScissor((int)pcmd->ClipRect.x, (int)(height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer);
|
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
|
||||||
}
|
}
|
||||||
idx_buffer += pcmd->ElemCount;
|
idx_buffer_offset += pcmd->ElemCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore modified state
|
// Restore modified GL state
|
||||||
glBindVertexArray(0);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glUseProgram(last_program);
|
glUseProgram(last_program);
|
||||||
glDisable(GL_SCISSOR_TEST);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer);
|
||||||
|
glBindVertexArray(last_vertex_array);
|
||||||
|
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
|
||||||
|
glBlendFunc(last_blend_src, last_blend_dst);
|
||||||
|
if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
|
||||||
|
if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
|
||||||
|
if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
|
||||||
|
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
|
||||||
|
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* ImGui_ImplGlfwGL3_GetClipboardText()
|
static const char* ImGui_ImplGlfwGL3_GetClipboardText()
|
||||||
@ -144,14 +162,17 @@ void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow*, unsigned int c)
|
|||||||
io.AddInputCharacter((unsigned short)c);
|
io.AddInputCharacter((unsigned short)c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfwGL3_CreateFontsTexture()
|
bool ImGui_ImplGlfwGL3_CreateFontsTexture()
|
||||||
{
|
{
|
||||||
|
// Build texture atlas
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
unsigned char* pixels;
|
unsigned char* pixels;
|
||||||
int width, height;
|
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.
|
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.
|
||||||
|
|
||||||
|
// Upload texture to graphics system
|
||||||
|
GLint last_texture;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
glGenTextures(1, &g_FontTexture);
|
glGenTextures(1, &g_FontTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
@ -161,13 +182,20 @@ void ImGui_ImplGlfwGL3_CreateFontsTexture()
|
|||||||
// Store our identifier
|
// Store our identifier
|
||||||
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
||||||
|
|
||||||
// Cleanup (don't clear the input data if you want to append new fonts later)
|
// Restore state
|
||||||
io.Fonts->ClearInputData();
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
io.Fonts->ClearTexData();
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGui_ImplGlfwGL3_CreateDeviceObjects()
|
bool ImGui_ImplGlfwGL3_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
|
// Backup GL state
|
||||||
|
GLint last_texture, last_array_buffer, last_vertex_array;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
|
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||||
|
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||||
|
|
||||||
const GLchar *vertex_shader =
|
const GLchar *vertex_shader =
|
||||||
"#version 330\n"
|
"#version 330\n"
|
||||||
"uniform mat4 ProjMtx;\n"
|
"uniform mat4 ProjMtx;\n"
|
||||||
@ -212,6 +240,7 @@ bool ImGui_ImplGlfwGL3_CreateDeviceObjects()
|
|||||||
g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color");
|
g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color");
|
||||||
|
|
||||||
glGenBuffers(1, &g_VboHandle);
|
glGenBuffers(1, &g_VboHandle);
|
||||||
|
glGenBuffers(1, &g_ElementsHandle);
|
||||||
|
|
||||||
glGenVertexArrays(1, &g_VaoHandle);
|
glGenVertexArrays(1, &g_VaoHandle);
|
||||||
glBindVertexArray(g_VaoHandle);
|
glBindVertexArray(g_VaoHandle);
|
||||||
@ -225,20 +254,49 @@ bool ImGui_ImplGlfwGL3_CreateDeviceObjects()
|
|||||||
glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv));
|
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));
|
glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col));
|
||||||
#undef OFFSETOF
|
#undef OFFSETOF
|
||||||
glBindVertexArray(0);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
ImGui_ImplGlfwGL3_CreateFontsTexture();
|
ImGui_ImplGlfwGL3_CreateFontsTexture();
|
||||||
|
|
||||||
|
// Restore modified GL state
|
||||||
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||||
|
glBindVertexArray(last_vertex_array);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplGlfwGL3_InvalidateDeviceObjects()
|
||||||
|
{
|
||||||
|
if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle);
|
||||||
|
if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle);
|
||||||
|
if (g_ElementsHandle) glDeleteBuffers(1, &g_ElementsHandle);
|
||||||
|
g_VaoHandle = g_VboHandle = g_ElementsHandle = 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks)
|
bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks)
|
||||||
{
|
{
|
||||||
g_Window = window;
|
g_Window = window;
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
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_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_LeftArrow] = GLFW_KEY_LEFT;
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
||||||
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
||||||
@ -258,10 +316,10 @@ bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks)
|
|||||||
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
|
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
|
||||||
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
|
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
|
||||||
|
|
||||||
io.RenderDrawListsFn = ImGui_ImplGlfwGL3_RenderDrawLists;
|
io.RenderDrawListsFn = ImGui_ImplGlfwGL3_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
|
||||||
io.SetClipboardTextFn = ImGui_ImplGlfwGL3_SetClipboardText;
|
io.SetClipboardTextFn = ImGui_ImplGlfwGL3_SetClipboardText;
|
||||||
io.GetClipboardTextFn = ImGui_ImplGlfwGL3_GetClipboardText;
|
io.GetClipboardTextFn = ImGui_ImplGlfwGL3_GetClipboardText;
|
||||||
#ifdef _MSC_VER
|
#ifdef _WIN32
|
||||||
io.ImeWindowHandle = glfwGetWin32Window(g_Window);
|
io.ImeWindowHandle = glfwGetWin32Window(g_Window);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -278,28 +336,7 @@ bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks)
|
|||||||
|
|
||||||
void ImGui_ImplGlfwGL3_Shutdown()
|
void ImGui_ImplGlfwGL3_Shutdown()
|
||||||
{
|
{
|
||||||
if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle);
|
ImGui_ImplGlfwGL3_InvalidateDeviceObjects();
|
||||||
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();
|
ImGui::Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,7 +352,8 @@ void ImGui_ImplGlfwGL3_NewFrame()
|
|||||||
int display_w, display_h;
|
int display_w, display_h;
|
||||||
glfwGetWindowSize(g_Window, &w, &h);
|
glfwGetWindowSize(g_Window, &w, &h);
|
||||||
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
|
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
|
||||||
io.DisplaySize = ImVec2((float)display_w, (float)display_h);
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||||
|
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
||||||
|
|
||||||
// Setup time step
|
// Setup time step
|
||||||
double current_time = glfwGetTime();
|
double current_time = glfwGetTime();
|
||||||
@ -326,15 +364,13 @@ void ImGui_ImplGlfwGL3_NewFrame()
|
|||||||
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
|
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
|
||||||
if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED))
|
if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED))
|
||||||
{
|
{
|
||||||
double mouse_x, mouse_y;
|
double mouse_x, mouse_y;
|
||||||
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
|
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
|
||||||
mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels
|
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
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.)
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
io.MousePos = ImVec2(-1,-1);
|
io.MousePos = ImVec2(-1,-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
// ImGui GLFW binding with OpenGL3 + shaders
|
// ImGui GLFW binding with OpenGL3 + shaders
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
struct GLFWwindow;
|
struct GLFWwindow;
|
||||||
|
|
||||||
bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks);
|
IMGUI_API bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks);
|
||||||
void ImGui_ImplGlfwGL3_Shutdown();
|
IMGUI_API void ImGui_ImplGlfwGL3_Shutdown();
|
||||||
void ImGui_ImplGlfwGL3_NewFrame();
|
IMGUI_API void ImGui_ImplGlfwGL3_NewFrame();
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing ImGui state.
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
void ImGui_ImplGlfwGL3_InvalidateDeviceObjects();
|
IMGUI_API void ImGui_ImplGlfwGL3_InvalidateDeviceObjects();
|
||||||
bool ImGui_ImplGlfwGL3_CreateDeviceObjects();
|
IMGUI_API bool ImGui_ImplGlfwGL3_CreateDeviceObjects();
|
||||||
|
|
||||||
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
|
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
|
||||||
// Provided here if you want to chain callbacks.
|
// Provided here if you want to chain callbacks.
|
||||||
// You can also handle inputs yourself and use those as a reference.
|
// You can also handle inputs yourself and use those as a reference.
|
||||||
void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
IMGUI_API void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||||
void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
IMGUI_API void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
IMGUI_API void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow* window, unsigned int c);
|
IMGUI_API void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow* window, unsigned int c);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// ImGui - standalone example application for Glfw + OpenGL 3, using programmable pipeline
|
// ImGui - standalone example application for Glfw + OpenGL 3, using programmable pipeline
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "imgui_impl_glfw_gl3.h"
|
#include "imgui_impl_glfw_gl3.h"
|
||||||
@ -16,7 +17,7 @@ int main(int, char**)
|
|||||||
// Setup window
|
// Setup window
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
exit(1);
|
return 1;
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
@ -31,7 +32,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplGlfwGL3_Init(window, true);
|
ImGui_ImplGlfwGL3_Init(window, true);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// (see extra_fonts/README.txt for more details)
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
//ImGuiIO& io = ImGui::GetIO();
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
@ -40,12 +41,6 @@ int main(int, char**)
|
|||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
|
||||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
|
||||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
|
||||||
|
|
||||||
bool show_test_window = true;
|
bool show_test_window = true;
|
||||||
bool show_another_window = false;
|
bool show_another_window = false;
|
||||||
ImVec4 clear_color = ImColor(114, 144, 154);
|
ImVec4 clear_color = ImColor(114, 144, 154);
|
||||||
@ -53,7 +48,6 @@ int main(int, char**)
|
|||||||
// Main loop
|
// Main loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
ImGui_ImplGlfwGL3_NewFrame();
|
ImGui_ImplGlfwGL3_NewFrame();
|
||||||
|
|
||||||
@ -86,7 +80,9 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
int display_w, display_h;
|
||||||
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||||
|
glViewport(0, 0, display_w, display_h);
|
||||||
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
@ -149,6 +149,8 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\imgui.cpp" />
|
<ClCompile Include="..\..\imgui.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp" />
|
||||||
<ClCompile Include="..\libs\gl3w\GL\gl3w.c" />
|
<ClCompile Include="..\libs\gl3w\GL\gl3w.c" />
|
||||||
<ClCompile Include="imgui_impl_glfw_gl3.cpp" />
|
<ClCompile Include="imgui_impl_glfw_gl3.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
@ -156,10 +158,14 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\imconfig.h" />
|
<ClInclude Include="..\..\imconfig.h" />
|
||||||
<ClInclude Include="..\..\imgui.h" />
|
<ClInclude Include="..\..\imgui.h" />
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h" />
|
||||||
<ClInclude Include="..\libs\gl3w\GL\gl3w.h" />
|
<ClInclude Include="..\libs\gl3w\GL\gl3w.h" />
|
||||||
<ClInclude Include="..\libs\gl3w\GL\glcorearb.h" />
|
<ClInclude Include="..\libs\gl3w\GL\glcorearb.h" />
|
||||||
<ClInclude Include="imgui_impl_glfw_gl3.h" />
|
<ClInclude Include="imgui_impl_glfw_gl3.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -25,6 +25,12 @@
|
|||||||
<ClCompile Include="..\libs\gl3w\GL\gl3w.c">
|
<ClCompile Include="..\libs\gl3w\GL\gl3w.c">
|
||||||
<Filter>gl3w</Filter>
|
<Filter>gl3w</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\imconfig.h">
|
<ClInclude Include="..\..\imconfig.h">
|
||||||
@ -42,5 +48,11 @@
|
|||||||
<ClInclude Include="..\libs\gl3w\GL\glcorearb.h">
|
<ClInclude Include="..\libs\gl3w\GL\glcorearb.h">
|
||||||
<Filter>gl3w</Filter>
|
<Filter>gl3w</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -10,8 +10,9 @@
|
|||||||
|
|
||||||
#CXX = g++
|
#CXX = g++
|
||||||
|
|
||||||
|
EXE = opengl_example
|
||||||
OBJS = main.o imgui_impl_glfw.o
|
OBJS = main.o imgui_impl_glfw.o
|
||||||
OBJS += ../../imgui.o
|
OBJS += ../../imgui.o ../../imgui_demo.o ../../imgui_draw.o
|
||||||
|
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ ifeq ($(UNAME_S), Linux) #LINUX
|
|||||||
LIBS = `pkg-config --static --libs glfw3`
|
LIBS = `pkg-config --static --libs glfw3`
|
||||||
|
|
||||||
CXXFLAGS = -I../../ `pkg-config --cflags glfw3`
|
CXXFLAGS = -I../../ `pkg-config --cflags glfw3`
|
||||||
CXXFLAGS += -Wall
|
CXXFLAGS += -Wall -Wformat
|
||||||
CFLAGS = $(CXXFLAGS)
|
CFLAGS = $(CXXFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -32,20 +33,29 @@ ifeq ($(UNAME_S), Darwin) #APPLE
|
|||||||
LIBS += -lglfw3
|
LIBS += -lglfw3
|
||||||
|
|
||||||
CXXFLAGS = -I../../ -I/usr/local/include
|
CXXFLAGS = -I../../ -I/usr/local/include
|
||||||
CXXFLAGS += -Wall
|
CXXFLAGS += -Wall -Wformat
|
||||||
# CXXFLAGS += -D__APPLE__
|
# CXXFLAGS += -D__APPLE__
|
||||||
CFLAGS = $(CXXFLAGS)
|
CFLAGS = $(CXXFLAGS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(UNAME_S), MINGW64_NT-6.3)
|
||||||
|
ECHO_MESSAGE = "Windows"
|
||||||
|
LIBS = -lglfw3 -lgdi32 -lopengl32 -limm32
|
||||||
|
|
||||||
|
CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags glfw3`
|
||||||
|
CXXFLAGS += -Wall -Wformat
|
||||||
|
CFLAGS = $(CXXFLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
.cpp.o:
|
.cpp.o:
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
all:imgui_example
|
all: $(EXE)
|
||||||
@echo Build complete for $(ECHO_MESSAGE)
|
@echo Build complete for $(ECHO_MESSAGE)
|
||||||
|
|
||||||
imgui_example:$(OBJS)
|
$(EXE): $(OBJS)
|
||||||
$(CXX) -o imgui_example $(OBJS) $(CXXFLAGS) $(LIBS)
|
$(CXX) -o $(EXE) $(OBJS) $(CXXFLAGS) $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJS)
|
rm $(EXE) $(OBJS)
|
||||||
|
|
||||||
|
3
examples/opengl_example/build_win32.bat
Normal file
3
examples/opengl_example/build_win32.bat
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler.
|
||||||
|
mkdir Debug
|
||||||
|
cl /nologo /Zi /MD /I ..\.. /I ..\libs\glfw\include *.cpp ..\..\*.cpp /FeDebug/opengl_example.exe /FoDebug/ /link /LIBPATH:..\libs\glfw\lib-vc2010-32 glfw3.lib opengl32.lib gdi32.lib shell32.lib
|
@ -1,4 +1,7 @@
|
|||||||
// ImGui GLFW binding with OpenGL
|
// ImGui GLFW binding with OpenGL
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@ -6,7 +9,7 @@
|
|||||||
|
|
||||||
// GLFW
|
// GLFW
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#ifdef _MSC_VER
|
#ifdef _WIN32
|
||||||
#undef APIENTRY
|
#undef APIENTRY
|
||||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||||
#define GLFW_EXPOSE_NATIVE_WGL
|
#define GLFW_EXPOSE_NATIVE_WGL
|
||||||
@ -23,11 +26,12 @@ 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)
|
// 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:
|
// 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)
|
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||||
static void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data)
|
void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
|
// 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.
|
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
|
||||||
|
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
|
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
|
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
@ -40,13 +44,18 @@ static void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
//glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context
|
//glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context
|
||||||
|
|
||||||
// Setup orthographic projection matrix
|
// Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
|
||||||
const float width = ImGui::GetIO().DisplaySize.x;
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
const float height = ImGui::GetIO().DisplaySize.y;
|
int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x);
|
||||||
|
int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y);
|
||||||
|
draw_data->ScaleClipRects(io.DisplayFramebufferScale);
|
||||||
|
|
||||||
|
// Setup viewport, orthographic projection matrix
|
||||||
|
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(0.0f, width, height, 0.0f, -1.0f, +1.0f);
|
glOrtho(0.0f, io.DisplaySize.x, io.DisplaySize.y, 0.0f, -1.0f, +1.0f);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@ -72,8 +81,8 @@ static void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||||
glScissor((int)pcmd->ClipRect.x, (int)(height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer);
|
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer);
|
||||||
}
|
}
|
||||||
idx_buffer += pcmd->ElemCount;
|
idx_buffer += pcmd->ElemCount;
|
||||||
}
|
}
|
||||||
@ -84,12 +93,13 @@ static void ImGui_ImplGlfw_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
glDisableClientState(GL_COLOR_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
|
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* ImGui_ImplGlfw_GetClipboardText()
|
static const char* ImGui_ImplGlfw_GetClipboardText()
|
||||||
@ -136,14 +146,15 @@ void ImGui_ImplGlfw_CharCallback(GLFWwindow*, unsigned int c)
|
|||||||
|
|
||||||
bool ImGui_ImplGlfw_CreateDeviceObjects()
|
bool ImGui_ImplGlfw_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
|
// Build texture atlas
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
// Build texture
|
|
||||||
unsigned char* pixels;
|
unsigned char* pixels;
|
||||||
int width, height;
|
int width, height;
|
||||||
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
|
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
|
||||||
|
|
||||||
// Create texture
|
// Upload texture to graphics system
|
||||||
|
GLint last_texture;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
glGenTextures(1, &g_FontTexture);
|
glGenTextures(1, &g_FontTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
@ -153,9 +164,8 @@ bool ImGui_ImplGlfw_CreateDeviceObjects()
|
|||||||
// Store our identifier
|
// Store our identifier
|
||||||
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
||||||
|
|
||||||
// Cleanup (don't clear the input data if you want to append new fonts later)
|
// Restore state
|
||||||
io.Fonts->ClearInputData();
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
io.Fonts->ClearTexData();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -175,7 +185,7 @@ bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks)
|
|||||||
g_Window = window;
|
g_Window = window;
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
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_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_LeftArrow] = GLFW_KEY_LEFT;
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
||||||
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
||||||
@ -195,10 +205,10 @@ bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks)
|
|||||||
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
|
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
|
||||||
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
|
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
|
||||||
|
|
||||||
io.RenderDrawListsFn = ImGui_ImplGlfw_RenderDrawLists;
|
io.RenderDrawListsFn = ImGui_ImplGlfw_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
|
||||||
io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
|
io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
|
||||||
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
|
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
|
||||||
#ifdef _MSC_VER
|
#ifdef _WIN32
|
||||||
io.ImeWindowHandle = glfwGetWin32Window(g_Window);
|
io.ImeWindowHandle = glfwGetWin32Window(g_Window);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -231,7 +241,8 @@ void ImGui_ImplGlfw_NewFrame()
|
|||||||
int display_w, display_h;
|
int display_w, display_h;
|
||||||
glfwGetWindowSize(g_Window, &w, &h);
|
glfwGetWindowSize(g_Window, &w, &h);
|
||||||
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
|
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
|
||||||
io.DisplaySize = ImVec2((float)display_w, (float)display_h);
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||||
|
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
||||||
|
|
||||||
// Setup time step
|
// Setup time step
|
||||||
double current_time = glfwGetTime();
|
double current_time = glfwGetTime();
|
||||||
@ -242,15 +253,13 @@ void ImGui_ImplGlfw_NewFrame()
|
|||||||
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
|
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
|
||||||
if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED))
|
if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED))
|
||||||
{
|
{
|
||||||
double mouse_x, mouse_y;
|
double mouse_x, mouse_y;
|
||||||
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
|
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
|
||||||
mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels
|
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
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.)
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
io.MousePos = ImVec2(-1,-1);
|
io.MousePos = ImVec2(-1,-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
// ImGui GLFW binding with OpenGL
|
// ImGui GLFW binding with OpenGL
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
struct GLFWwindow;
|
struct GLFWwindow;
|
||||||
|
|
||||||
bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks);
|
IMGUI_API bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks);
|
||||||
void ImGui_ImplGlfw_Shutdown();
|
IMGUI_API void ImGui_ImplGlfw_Shutdown();
|
||||||
void ImGui_ImplGlfw_NewFrame();
|
IMGUI_API void ImGui_ImplGlfw_NewFrame();
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing ImGui state.
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
void ImGui_ImplGlfw_InvalidateDeviceObjects();
|
IMGUI_API void ImGui_ImplGlfw_InvalidateDeviceObjects();
|
||||||
bool ImGui_ImplGlfw_CreateDeviceObjects();
|
IMGUI_API bool ImGui_ImplGlfw_CreateDeviceObjects();
|
||||||
|
|
||||||
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
|
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
|
||||||
// Provided here if you want to chain callbacks.
|
// Provided here if you want to chain callbacks.
|
||||||
// You can also handle inputs yourself and use those as a reference.
|
// You can also handle inputs yourself and use those as a reference.
|
||||||
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
IMGUI_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||||
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
IMGUI_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
IMGUI_API void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
|
IMGUI_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// ImGui - standalone example application for Glfw + OpenGL 2, using fixed pipeline
|
// ImGui - standalone example application for Glfw + OpenGL 2, using fixed pipeline
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
@ -15,7 +16,7 @@ int main(int, char**)
|
|||||||
// Setup window
|
// Setup window
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
exit(1);
|
return 1;
|
||||||
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL);
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplGlfw_Init(window, true);
|
ImGui_ImplGlfw_Init(window, true);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// (see extra_fonts/README.txt for more details)
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
//ImGuiIO& io = ImGui::GetIO();
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
@ -32,12 +33,6 @@ int main(int, char**)
|
|||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
|
||||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
|
||||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
|
||||||
|
|
||||||
bool show_test_window = true;
|
bool show_test_window = true;
|
||||||
bool show_another_window = false;
|
bool show_another_window = false;
|
||||||
ImVec4 clear_color = ImColor(114, 144, 154);
|
ImVec4 clear_color = ImColor(114, 144, 154);
|
||||||
@ -77,7 +72,9 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);
|
int display_w, display_h;
|
||||||
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||||
|
glViewport(0, 0, display_w, display_h);
|
||||||
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
@ -149,14 +149,20 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\imgui.cpp" />
|
<ClCompile Include="..\..\imgui.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp" />
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp" />
|
||||||
<ClCompile Include="imgui_impl_glfw.cpp" />
|
<ClCompile Include="imgui_impl_glfw.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\imconfig.h" />
|
<ClInclude Include="..\..\imconfig.h" />
|
||||||
<ClInclude Include="..\..\imgui.h" />
|
<ClInclude Include="..\..\imgui.h" />
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h" />
|
||||||
<ClInclude Include="imgui_impl_glfw.h" />
|
<ClInclude Include="imgui_impl_glfw.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -19,6 +19,12 @@
|
|||||||
<ClCompile Include="imgui_impl_glfw.cpp">
|
<ClCompile Include="imgui_impl_glfw.cpp">
|
||||||
<Filter>sources</Filter>
|
<Filter>sources</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_demo.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\imgui_draw.cpp">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\imconfig.h">
|
<ClInclude Include="..\..\imconfig.h">
|
||||||
@ -30,5 +36,11 @@
|
|||||||
<ClInclude Include="imgui_impl_glfw.h">
|
<ClInclude Include="imgui_impl_glfw.h">
|
||||||
<Filter>sources</Filter>
|
<Filter>sources</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\imgui_internal.h">
|
||||||
|
<Filter>imgui</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
22
examples/sdl_opengl3_example/README.md
Normal file
22
examples/sdl_opengl3_example/README.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
# How to Build
|
||||||
|
|
||||||
|
- On Windows with Visual Studio's CLI
|
||||||
|
|
||||||
|
```
|
||||||
|
set SDL2DIR=path_to_your_sdl2_folder
|
||||||
|
cl /Zi /MD /I ..\.. /I ..\libs\gl3w /I %SDL2DIR%\include main.cpp imgui_impl_sdl_gl3.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /link /libpath:%SDL2DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console
|
||||||
|
```
|
||||||
|
|
||||||
|
- On Linux and similar Unixes
|
||||||
|
|
||||||
|
```
|
||||||
|
c++ `sdl2-config --cflags` -I ../.. -I ../libs/gl3w main.cpp imgui_impl_sdl_gl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c `sdl2-config --libs` -lGL -ldl -o sdl2example
|
||||||
|
```
|
||||||
|
|
||||||
|
- On Mac OS X
|
||||||
|
|
||||||
|
```
|
||||||
|
brew install sdl2
|
||||||
|
c++ `sdl2-config --cflags` -I ../.. -I ../libs/gl3w main.cpp imgui_impl_sdl_gl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c `sdl2-config --libs` -framework OpenGl -o sdl2example
|
||||||
|
```
|
381
examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp
Normal file
381
examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp
Normal file
@ -0,0 +1,381 @@
|
|||||||
|
// ImGui SDL2 binding with OpenGL3
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_sdl_gl3.h"
|
||||||
|
|
||||||
|
// SDL,GL3W
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <SDL_syswm.h>
|
||||||
|
#include <GL/gl3w.h>
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static SDL_Window* 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 unsigned int g_VboHandle = 0, g_VaoHandle = 0, g_ElementsHandle = 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)
|
||||||
|
void ImGui_ImplSdlGL3_RenderDrawLists(ImDrawData* draw_data)
|
||||||
|
{
|
||||||
|
// Backup GL state
|
||||||
|
GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
||||||
|
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
|
GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||||
|
GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer);
|
||||||
|
GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||||
|
GLint last_blend_src; glGetIntegerv(GL_BLEND_SRC, &last_blend_src);
|
||||||
|
GLint last_blend_dst; glGetIntegerv(GL_BLEND_DST, &last_blend_dst);
|
||||||
|
GLint last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, &last_blend_equation_rgb);
|
||||||
|
GLint last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &last_blend_equation_alpha);
|
||||||
|
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
||||||
|
GLboolean last_enable_blend = glIsEnabled(GL_BLEND);
|
||||||
|
GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
|
||||||
|
GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
|
||||||
|
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x);
|
||||||
|
int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y);
|
||||||
|
draw_data->ScaleClipRects(io.DisplayFramebufferScale);
|
||||||
|
|
||||||
|
// Setup orthographic projection matrix
|
||||||
|
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
|
||||||
|
const float ortho_projection[4][4] =
|
||||||
|
{
|
||||||
|
{ 2.0f/io.DisplaySize.x, 0.0f, 0.0f, 0.0f },
|
||||||
|
{ 0.0f, 2.0f/-io.DisplaySize.y, 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]);
|
||||||
|
glBindVertexArray(g_VaoHandle);
|
||||||
|
|
||||||
|
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||||||
|
{
|
||||||
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||||
|
const ImDrawIdx* idx_buffer_offset = 0;
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.size() * sizeof(ImDrawVert), (GLvoid*)&cmd_list->VtxBuffer.front(), GL_STREAM_DRAW);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx), (GLvoid*)&cmd_list->IdxBuffer.front(), GL_STREAM_DRAW);
|
||||||
|
|
||||||
|
for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != cmd_list->CmdBuffer.end(); pcmd++)
|
||||||
|
{
|
||||||
|
if (pcmd->UserCallback)
|
||||||
|
{
|
||||||
|
pcmd->UserCallback(cmd_list, pcmd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||||
|
glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||||
|
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
|
||||||
|
}
|
||||||
|
idx_buffer_offset += pcmd->ElemCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore modified GL state
|
||||||
|
glUseProgram(last_program);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer);
|
||||||
|
glBindVertexArray(last_vertex_array);
|
||||||
|
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
|
||||||
|
glBlendFunc(last_blend_src, last_blend_dst);
|
||||||
|
if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
|
||||||
|
if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
|
||||||
|
if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
|
||||||
|
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
|
||||||
|
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* ImGui_ImplSdlGL3_GetClipboardText()
|
||||||
|
{
|
||||||
|
return SDL_GetClipboardText();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ImGui_ImplSdlGL3_SetClipboardText(const char* text)
|
||||||
|
{
|
||||||
|
SDL_SetClipboardText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
switch (event->type)
|
||||||
|
{
|
||||||
|
case SDL_MOUSEWHEEL:
|
||||||
|
{
|
||||||
|
if (event->wheel.y > 0)
|
||||||
|
g_MouseWheel = 1;
|
||||||
|
if (event->wheel.y < 0)
|
||||||
|
g_MouseWheel = -1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
{
|
||||||
|
if (event->button.button == SDL_BUTTON_LEFT) g_MousePressed[0] = true;
|
||||||
|
if (event->button.button == SDL_BUTTON_RIGHT) g_MousePressed[1] = true;
|
||||||
|
if (event->button.button == SDL_BUTTON_MIDDLE) g_MousePressed[2] = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_TEXTINPUT:
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.AddInputCharactersUTF8(event->text.text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
case SDL_KEYUP:
|
||||||
|
{
|
||||||
|
int key = event->key.keysym.sym & ~SDLK_SCANCODE_MASK;
|
||||||
|
io.KeysDown[key] = (event->type == SDL_KEYDOWN);
|
||||||
|
io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
|
||||||
|
io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
|
||||||
|
io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSdlGL3_CreateFontsTexture()
|
||||||
|
{
|
||||||
|
// Build texture atlas
|
||||||
|
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.
|
||||||
|
|
||||||
|
// Upload texture to graphics system
|
||||||
|
GLint last_texture;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_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_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
|
// Store our identifier
|
||||||
|
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
||||||
|
|
||||||
|
// Restore state
|
||||||
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSdlGL3_CreateDeviceObjects()
|
||||||
|
{
|
||||||
|
// Backup GL state
|
||||||
|
GLint last_texture, last_array_buffer, last_vertex_array;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
|
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||||
|
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||||
|
|
||||||
|
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);
|
||||||
|
glGenBuffers(1, &g_ElementsHandle);
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
ImGui_ImplSdlGL3_CreateFontsTexture();
|
||||||
|
|
||||||
|
// Restore modified GL state
|
||||||
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||||
|
glBindVertexArray(last_vertex_array);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSdlGL3_InvalidateDeviceObjects()
|
||||||
|
{
|
||||||
|
if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle);
|
||||||
|
if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle);
|
||||||
|
if (g_ElementsHandle) glDeleteBuffers(1, &g_ElementsHandle);
|
||||||
|
g_VaoHandle = g_VboHandle = g_ElementsHandle = 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui_ImplSdlGL3_Init(SDL_Window *window)
|
||||||
|
{
|
||||||
|
g_Window = window;
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.KeyMap[ImGuiKey_Tab] = SDLK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
|
||||||
|
io.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT;
|
||||||
|
io.KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT;
|
||||||
|
io.KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP;
|
||||||
|
io.KeyMap[ImGuiKey_DownArrow] = SDL_SCANCODE_DOWN;
|
||||||
|
io.KeyMap[ImGuiKey_PageUp] = SDL_SCANCODE_PAGEUP;
|
||||||
|
io.KeyMap[ImGuiKey_PageDown] = SDL_SCANCODE_PAGEDOWN;
|
||||||
|
io.KeyMap[ImGuiKey_Home] = SDL_SCANCODE_HOME;
|
||||||
|
io.KeyMap[ImGuiKey_End] = SDL_SCANCODE_END;
|
||||||
|
io.KeyMap[ImGuiKey_Delete] = SDLK_DELETE;
|
||||||
|
io.KeyMap[ImGuiKey_Backspace] = SDLK_BACKSPACE;
|
||||||
|
io.KeyMap[ImGuiKey_Enter] = SDLK_RETURN;
|
||||||
|
io.KeyMap[ImGuiKey_Escape] = SDLK_ESCAPE;
|
||||||
|
io.KeyMap[ImGuiKey_A] = SDLK_a;
|
||||||
|
io.KeyMap[ImGuiKey_C] = SDLK_c;
|
||||||
|
io.KeyMap[ImGuiKey_V] = SDLK_v;
|
||||||
|
io.KeyMap[ImGuiKey_X] = SDLK_x;
|
||||||
|
io.KeyMap[ImGuiKey_Y] = SDLK_y;
|
||||||
|
io.KeyMap[ImGuiKey_Z] = SDLK_z;
|
||||||
|
|
||||||
|
io.RenderDrawListsFn = ImGui_ImplSdlGL3_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
|
||||||
|
io.SetClipboardTextFn = ImGui_ImplSdlGL3_SetClipboardText;
|
||||||
|
io.GetClipboardTextFn = ImGui_ImplSdlGL3_GetClipboardText;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
SDL_SysWMinfo wmInfo;
|
||||||
|
SDL_VERSION(&wmInfo.version);
|
||||||
|
SDL_GetWindowWMInfo(window, &wmInfo);
|
||||||
|
io.ImeWindowHandle = wmInfo.info.win.window;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSdlGL3_Shutdown()
|
||||||
|
{
|
||||||
|
ImGui_ImplSdlGL3_InvalidateDeviceObjects();
|
||||||
|
ImGui::Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplSdlGL3_NewFrame()
|
||||||
|
{
|
||||||
|
if (!g_FontTexture)
|
||||||
|
ImGui_ImplSdlGL3_CreateDeviceObjects();
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// Setup display size (every frame to accommodate for window resizing)
|
||||||
|
int w, h;
|
||||||
|
SDL_GetWindowSize(g_Window, &w, &h);
|
||||||
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||||
|
io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
|
||||||
|
|
||||||
|
// Setup time step
|
||||||
|
Uint32 time = SDL_GetTicks();
|
||||||
|
double current_time = time / 1000.0;
|
||||||
|
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 SDL_PollEvent())
|
||||||
|
int mx, my;
|
||||||
|
Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
|
||||||
|
if (SDL_GetWindowFlags(g_Window) & SDL_WINDOW_MOUSE_FOCUS)
|
||||||
|
io.MousePos = ImVec2((float)mx, (float)my); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
||||||
|
else
|
||||||
|
io.MousePos = ImVec2(-1, -1);
|
||||||
|
|
||||||
|
io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 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.
|
||||||
|
io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
|
||||||
|
io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
|
||||||
|
g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
|
||||||
|
|
||||||
|
io.MouseWheel = g_MouseWheel;
|
||||||
|
g_MouseWheel = 0.0f;
|
||||||
|
|
||||||
|
// Hide OS mouse cursor if ImGui is drawing it
|
||||||
|
SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1);
|
||||||
|
|
||||||
|
// Start the frame
|
||||||
|
ImGui::NewFrame();
|
||||||
|
}
|
17
examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h
Normal file
17
examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// ImGui SDL2 binding with OpenGL3
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
|
struct SDL_Window;
|
||||||
|
typedef union SDL_Event SDL_Event;
|
||||||
|
|
||||||
|
IMGUI_API bool ImGui_ImplSdlGL3_Init(SDL_Window *window);
|
||||||
|
IMGUI_API void ImGui_ImplSdlGL3_Shutdown();
|
||||||
|
IMGUI_API void ImGui_ImplSdlGL3_NewFrame();
|
||||||
|
IMGUI_API bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event);
|
||||||
|
|
||||||
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
|
IMGUI_API void ImGui_ImplSdlGL3_InvalidateDeviceObjects();
|
||||||
|
IMGUI_API bool ImGui_ImplSdlGL3_CreateDeviceObjects();
|
104
examples/sdl_opengl3_example/main.cpp
Normal file
104
examples/sdl_opengl3_example/main.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
// ImGui - standalone example application for SDL2 + OpenGL
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
|
#include <imgui.h>
|
||||||
|
#include "imgui_impl_sdl_gl3.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <GL/gl3w.h>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
int main(int, char**)
|
||||||
|
{
|
||||||
|
// Setup SDL
|
||||||
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: %s\n", SDL_GetError());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup window
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||||
|
SDL_DisplayMode current;
|
||||||
|
SDL_GetCurrentDisplayMode(0, ¤t);
|
||||||
|
SDL_Window *window = SDL_CreateWindow("ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
|
||||||
|
SDL_GLContext glcontext = SDL_GL_CreateContext(window);
|
||||||
|
gl3wInit();
|
||||||
|
|
||||||
|
// Setup ImGui binding
|
||||||
|
ImGui_ImplSdlGL3_Init(window);
|
||||||
|
|
||||||
|
// Load Fonts
|
||||||
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
|
//io.Fonts->AddFontDefault();
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
|
bool show_test_window = true;
|
||||||
|
bool show_another_window = false;
|
||||||
|
ImVec4 clear_color = ImColor(114, 144, 154);
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
bool done = false;
|
||||||
|
while (!done)
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
while (SDL_PollEvent(&event))
|
||||||
|
{
|
||||||
|
ImGui_ImplSdlGL3_ProcessEvent(&event);
|
||||||
|
if (event.type == SDL_QUIT)
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
ImGui_ImplSdlGL3_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 = 0.0f;
|
||||||
|
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::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver);
|
||||||
|
ImGui::Begin("Another Window", &show_another_window);
|
||||||
|
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();
|
||||||
|
SDL_GL_SwapWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplSdlGL3_Shutdown();
|
||||||
|
SDL_GL_DeleteContext(glcontext);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -3,14 +3,20 @@
|
|||||||
|
|
||||||
- On Windows with Visual Studio's CLI
|
- On Windows with Visual Studio's CLI
|
||||||
|
|
||||||
\<sdl2path\> is your SDL2 folder.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
cl /MD /I <sdl2path\include> /I ..\.. main.cpp imgui_impl_sdl.cpp ..\..\imgui.cpp /link /LIBPATH:<sdl2path\lib> SDL2.lib SDL2main.lib
|
set SDL2DIR=path_to_your_sdl2_folder
|
||||||
|
cl /Zi /MD /I %SDL2DIR%\include> /I ..\.. main.cpp imgui_impl_sdl.cpp ..\..\imgui*.cpp /link /LIBPATH:%SDL2DIR%\lib SDL2.lib SDL2main.lib
|
||||||
```
|
```
|
||||||
|
|
||||||
- On Linux and similar Unices
|
- On Linux and similar Unixes
|
||||||
|
|
||||||
```
|
```
|
||||||
c++ `sdl2-config --cflags` -I ../.. main.cpp imgui_impl_sdl.cpp ../../imgui.cpp `sdl2-config --libs` -lGL -o sdl2example
|
c++ `sdl2-config --cflags` -I ../.. main.cpp imgui_impl_sdl.cpp ../../imgui*.cpp `sdl2-config --libs` -lGL -o sdl2example
|
||||||
|
```
|
||||||
|
|
||||||
|
- On Mac OS X
|
||||||
|
|
||||||
|
```
|
||||||
|
brew install sdl2
|
||||||
|
c++ `sdl2-config --cflags` -I ../.. main.cpp imgui_impl_sdl.cpp ../../imgui*.cpp `sdl2-config --libs` -framework OpenGl -o sdl2example
|
||||||
```
|
```
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
// ImGui SDL2 binding with OpenGL
|
// ImGui SDL2 binding with OpenGL
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
@ -16,11 +19,12 @@ 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)
|
// 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:
|
// 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)
|
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
|
||||||
static void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data)
|
void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data)
|
||||||
{
|
{
|
||||||
// We are using the OpenGL fixed pipeline to make the example code simpler to read!
|
// 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.
|
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers.
|
||||||
|
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
|
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
|
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
@ -33,13 +37,18 @@ static void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
//glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context
|
//glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context
|
||||||
|
|
||||||
// Setup orthographic projection matrix
|
// Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
|
||||||
const float width = ImGui::GetIO().DisplaySize.x;
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
const float height = ImGui::GetIO().DisplaySize.y;
|
int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x);
|
||||||
|
int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y);
|
||||||
|
draw_data->ScaleClipRects(io.DisplayFramebufferScale);
|
||||||
|
|
||||||
|
// Setup viewport, orthographic projection matrix
|
||||||
|
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(0.0f, width, height, 0.0f, -1.0f, +1.0f);
|
glOrtho(0.0f, io.DisplaySize.x, io.DisplaySize.y, 0.0f, -1.0f, +1.0f);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@ -65,8 +74,8 @@ static void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||||
glScissor((int)pcmd->ClipRect.x, (int)(height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer);
|
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer);
|
||||||
}
|
}
|
||||||
idx_buffer += pcmd->ElemCount;
|
idx_buffer += pcmd->ElemCount;
|
||||||
}
|
}
|
||||||
@ -77,12 +86,13 @@ static void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
glDisableClientState(GL_COLOR_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
|
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* ImGui_ImplSdl_GetClipboardText()
|
static const char* ImGui_ImplSdl_GetClipboardText()
|
||||||
@ -137,14 +147,15 @@ bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event)
|
|||||||
|
|
||||||
bool ImGui_ImplSdl_CreateDeviceObjects()
|
bool ImGui_ImplSdl_CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
|
// Build texture atlas
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
// Build texture
|
|
||||||
unsigned char* pixels;
|
unsigned char* pixels;
|
||||||
int width, height;
|
int width, height;
|
||||||
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
|
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
|
||||||
|
|
||||||
// Create texture
|
// Upload texture to graphics system
|
||||||
|
GLint last_texture;
|
||||||
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||||
glGenTextures(1, &g_FontTexture);
|
glGenTextures(1, &g_FontTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
@ -154,9 +165,8 @@ bool ImGui_ImplSdl_CreateDeviceObjects()
|
|||||||
// Store our identifier
|
// Store our identifier
|
||||||
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
||||||
|
|
||||||
// Cleanup (don't clear the input data if you want to append new fonts later)
|
// Restore state
|
||||||
io.Fonts->ClearInputData();
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||||
io.Fonts->ClearTexData();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -174,7 +184,7 @@ void ImGui_ImplSdl_InvalidateDeviceObjects()
|
|||||||
bool ImGui_ImplSdl_Init(SDL_Window *window)
|
bool ImGui_ImplSdl_Init(SDL_Window *window)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.KeyMap[ImGuiKey_Tab] = SDLK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
|
io.KeyMap[ImGuiKey_Tab] = SDLK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
|
||||||
io.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT;
|
io.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT;
|
||||||
io.KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT;
|
io.KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT;
|
||||||
io.KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP;
|
io.KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP;
|
||||||
@ -194,11 +204,11 @@ bool ImGui_ImplSdl_Init(SDL_Window *window)
|
|||||||
io.KeyMap[ImGuiKey_Y] = SDLK_y;
|
io.KeyMap[ImGuiKey_Y] = SDLK_y;
|
||||||
io.KeyMap[ImGuiKey_Z] = SDLK_z;
|
io.KeyMap[ImGuiKey_Z] = SDLK_z;
|
||||||
|
|
||||||
io.RenderDrawListsFn = ImGui_ImplSdl_RenderDrawLists;
|
io.RenderDrawListsFn = ImGui_ImplSdl_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
|
||||||
io.SetClipboardTextFn = ImGui_ImplSdl_SetClipboardText;
|
io.SetClipboardTextFn = ImGui_ImplSdl_SetClipboardText;
|
||||||
io.GetClipboardTextFn = ImGui_ImplSdl_GetClipboardText;
|
io.GetClipboardTextFn = ImGui_ImplSdl_GetClipboardText;
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _WIN32
|
||||||
SDL_SysWMinfo wmInfo;
|
SDL_SysWMinfo wmInfo;
|
||||||
SDL_VERSION(&wmInfo.version);
|
SDL_VERSION(&wmInfo.version);
|
||||||
SDL_GetWindowWMInfo(window, &wmInfo);
|
SDL_GetWindowWMInfo(window, &wmInfo);
|
||||||
@ -233,7 +243,7 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window)
|
|||||||
g_Time = current_time;
|
g_Time = current_time;
|
||||||
|
|
||||||
// Setup inputs
|
// Setup inputs
|
||||||
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
|
// (we already got mouse wheel, keyboard keys & characters from SDL_PollEvent())
|
||||||
int mx, my;
|
int mx, my;
|
||||||
Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
|
Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
|
||||||
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS)
|
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS)
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
// ImGui SDL2 binding with OpenGL
|
// ImGui SDL2 binding with OpenGL
|
||||||
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
||||||
|
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
// https://github.com/ocornut/imgui
|
// https://github.com/ocornut/imgui
|
||||||
|
|
||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
typedef union SDL_Event SDL_Event;
|
typedef union SDL_Event SDL_Event;
|
||||||
|
|
||||||
bool ImGui_ImplSdl_Init(SDL_Window *window);
|
IMGUI_API bool ImGui_ImplSdl_Init(SDL_Window *window);
|
||||||
void ImGui_ImplSdl_Shutdown();
|
IMGUI_API void ImGui_ImplSdl_Shutdown();
|
||||||
void ImGui_ImplSdl_NewFrame(SDL_Window *window);
|
IMGUI_API void ImGui_ImplSdl_NewFrame(SDL_Window *window);
|
||||||
bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event);
|
IMGUI_API bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event);
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing ImGui state.
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
void ImGui_ImplSdl_InvalidateDeviceObjects();
|
IMGUI_API void ImGui_ImplSdl_InvalidateDeviceObjects();
|
||||||
bool ImGui_ImplSdl_CreateDeviceObjects();
|
IMGUI_API bool ImGui_ImplSdl_CreateDeviceObjects();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// ImGui - standalone example application for SDL2 + OpenGL
|
// ImGui - standalone example application for SDL2 + OpenGL
|
||||||
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "imgui_impl_sdl.h"
|
#include "imgui_impl_sdl.h"
|
||||||
@ -10,7 +11,10 @@ int main(int, char**)
|
|||||||
{
|
{
|
||||||
// Setup SDL
|
// Setup SDL
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Setup window
|
// Setup window
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
@ -27,7 +31,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplSdl_Init(window);
|
ImGui_ImplSdl_Init(window);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// (see extra_fonts/README.txt for more details)
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
||||||
//ImGuiIO& io = ImGui::GetIO();
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
@ -36,12 +40,6 @@ int main(int, char**)
|
|||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
|
|
||||||
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
|
||||||
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
|
|
||||||
|
|
||||||
bool show_test_window = true;
|
bool show_test_window = true;
|
||||||
bool show_another_window = false;
|
bool show_another_window = false;
|
||||||
ImVec4 clear_color = ImColor(114, 144, 154);
|
ImVec4 clear_color = ImColor(114, 144, 154);
|
||||||
|
@ -3,31 +3,71 @@
|
|||||||
Those are only provided as a convenience, you can load your own .TTF files.
|
Those are only provided as a convenience, you can load your own .TTF files.
|
||||||
|
|
||||||
---------------------------------
|
---------------------------------
|
||||||
LINKS
|
LOADING INSTRUCTIONS
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
Typefaces for source code beautification
|
Load default font with:
|
||||||
https://github.com/chrissimpkins/codeface
|
|
||||||
|
|
||||||
Proggy Programming Fonts
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
http://upperbounds.net
|
io.Fonts->AddFontDefault();
|
||||||
|
|
||||||
|
Load .TTF file with:
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels);
|
||||||
|
|
||||||
|
Detailed options:
|
||||||
|
|
||||||
|
ImFontConfig config;
|
||||||
|
config.OversampleH = 3;
|
||||||
|
config.OversampleV = 3;
|
||||||
|
config.GlyphExtraSpacing.x = 1.0f;
|
||||||
|
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config);
|
||||||
|
|
||||||
|
Combine two fonts into one:
|
||||||
|
|
||||||
|
// Load main font
|
||||||
|
io.Fonts->AddFontDefault();
|
||||||
|
|
||||||
|
// Add character ranges and merge into main font
|
||||||
|
// The ranges array is not copied by the AddFont* functions and is used lazily
|
||||||
|
// so ensure it is available for duration of font usage
|
||||||
|
static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
|
||||||
|
ImFontConfig config;
|
||||||
|
config.MergeMode = true;
|
||||||
|
io.Fonts->AddFontFromFileTTF("DroidSans.ttf", 18.0f, &config, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, &config, icons_ranges);
|
||||||
|
|
||||||
|
Add a fourth parameter to bake specific font ranges only:
|
||||||
|
|
||||||
|
// Basic Latin, Extended Latin
|
||||||
|
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesDefault());
|
||||||
|
|
||||||
Inconsolata
|
// Include full set of about 21000 CJK Unified Ideographs
|
||||||
http://www.levien.com/type/myfonts/inconsolata.html
|
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
|
||||||
|
// Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
|
||||||
|
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesChinese());
|
||||||
|
|
||||||
Adobe Source Code Pro: Monospaced font family for user interface and coding environments
|
Offset font vertically by altering the io.Font->DisplayOffset value:
|
||||||
https://github.com/adobe-fonts/source-code-pro
|
|
||||||
|
|
||||||
Monospace/Fixed Width Programmer's Fonts
|
ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels);
|
||||||
http://www.lowing.org/fonts/
|
font->DisplayOffset.y += 1; // Render 1 pixel down
|
||||||
|
|
||||||
(Japanese) M+ fonts by Coji Morishita are free and include most useful Kanjis you would need.
|
|
||||||
http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html
|
|
||||||
|
|
||||||
Or use Arial Unicode or other Unicode fonts provided with Windows for full characters coverage (not sure of their licensing).
|
|
||||||
|
|
||||||
---------------------------------
|
---------------------------------
|
||||||
INCLUDED FONTS
|
EMBED A FONT IN SOURCE CODE
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
Compile and use 'binary_to_compressed_c.cpp' to create a compressed C style array. Then load the font with:
|
||||||
|
|
||||||
|
ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels, ...);
|
||||||
|
|
||||||
|
Or
|
||||||
|
|
||||||
|
ImFont* font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(compressed_data_base85, size_pixels, ...);
|
||||||
|
|
||||||
|
---------------------------------
|
||||||
|
INCLUDED FONT FILES
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
Cousine-Regular.ttf
|
Cousine-Regular.ttf
|
||||||
@ -54,52 +94,32 @@
|
|||||||
SIL OPEN FONT LICENSE Version 1.1
|
SIL OPEN FONT LICENSE Version 1.1
|
||||||
|
|
||||||
---------------------------------
|
---------------------------------
|
||||||
LOADING INSTRUCTIONS
|
LINKS
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
Load default font with:
|
Icon fonts
|
||||||
|
https://fortawesome.github.io/Font-Awesome/
|
||||||
|
https://github.com/SamBrishes/kenney-icon-font
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
Typefaces for source code beautification
|
||||||
io.Fonts->AddFontDefault();
|
https://github.com/chrissimpkins/codeface
|
||||||
|
|
||||||
Load .TTF file with:
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels);
|
|
||||||
|
|
||||||
Detailed options:
|
|
||||||
|
|
||||||
ImFontConfig config;
|
|
||||||
config.OversampleH = 3;
|
|
||||||
config.OversampleV = 3;
|
|
||||||
config.GlyphExtraSpacing.x = 1.0f;
|
|
||||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, &config);
|
|
||||||
|
|
||||||
Merge two fonts:
|
|
||||||
|
|
||||||
// Load main font
|
|
||||||
io.Fonts->AddFontDefault();
|
|
||||||
|
|
||||||
// Add character ranges and merge into main font
|
|
||||||
ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
|
|
||||||
ImFontConfig config;
|
|
||||||
config.MergeMode = true;
|
|
||||||
io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges);
|
|
||||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, &config, io.Fonts->GetGlyphRangesJapanese());
|
|
||||||
|
|
||||||
Add a fourth parameter to bake specific font ranges only:
|
|
||||||
|
|
||||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesDefault()); // Basic Latin, Extended Latin
|
|
||||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
|
|
||||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesChinese()); // Include full set of about 21000 CJK Unified Ideographs
|
|
||||||
|
|
||||||
Offset font vertically by altering the io.Font->DisplayOffset value:
|
|
||||||
|
|
||||||
ImFont* font = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels);
|
|
||||||
font->DisplayOffset.y += 1; // Render 1 pixel down
|
|
||||||
|
|
||||||
If you want to embed the font in source code (e.g. in your engine, so it doesn't have file-system dependencies);
|
|
||||||
Compile and use 'binary_to_compressed_c.cpp' to create a compressed C style array. Then load the font with:
|
|
||||||
|
|
||||||
ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels, ...);
|
Programmation fonts
|
||||||
|
http://s9w.github.io/font_compare/
|
||||||
|
|
||||||
|
Proggy Programming Fonts
|
||||||
|
http://upperbounds.net
|
||||||
|
|
||||||
|
Inconsolata
|
||||||
|
http://www.levien.com/type/myfonts/inconsolata.html
|
||||||
|
|
||||||
|
Adobe Source Code Pro: Monospaced font family for user interface and coding environments
|
||||||
|
https://github.com/adobe-fonts/source-code-pro
|
||||||
|
|
||||||
|
Monospace/Fixed Width Programmer's Fonts
|
||||||
|
http://www.lowing.org/fonts/
|
||||||
|
|
||||||
|
(Japanese) M+ fonts by Coji Morishita are free and include most useful Kanjis you would need.
|
||||||
|
http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html
|
||||||
|
|
||||||
|
Or use Arial Unicode or other Unicode fonts provided with Windows for full characters coverage (not sure of their licensing).
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
// ImGui - binary_to_compressed_c.cpp
|
// ImGui - binary_to_compressed_c.cpp
|
||||||
// Helper tool to turn a file into a C array.
|
// Helper tool to turn a file into a C array.
|
||||||
// The data is first compressed with stb_compress() to reduce source code size a little.
|
// The data is first compressed with stb_compress() to reduce source code size.
|
||||||
|
// Then encoded in Base85 to fit in a string so we can fit roughly 4 bytes of compressed data into 5 bytes of source code (suggested by @mmalex)
|
||||||
|
// (If we used 32-bits constants it would require take 11 bytes of source code to encode 4 bytes.)
|
||||||
// Useful if you want to embed fonts into your code.
|
// Useful if you want to embed fonts into your code.
|
||||||
// Note that the output array is likely to be bigger than the binary file..
|
// Note that even with compression, the output array is likely to be bigger than the binary file..
|
||||||
// Load compressed TTF fonts with ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF()
|
// Load compressed TTF fonts with ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF()
|
||||||
|
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
@ -11,28 +13,46 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
const int COLUMNS = 12;
|
|
||||||
|
|
||||||
// stb_compress* from stb.h - declaration
|
// stb_compress* from stb.h - declaration
|
||||||
typedef unsigned int stb_uint;
|
typedef unsigned int stb_uint;
|
||||||
typedef unsigned char stb_uchar;
|
typedef unsigned char stb_uchar;
|
||||||
stb_uint stb_compress(stb_uchar *out,stb_uchar *in,stb_uint len);
|
stb_uint stb_compress(stb_uchar *out,stb_uchar *in,stb_uint len);
|
||||||
|
|
||||||
static bool binary_to_compressed_c(const char* filename, const char* symbol);
|
static bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression);
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
{
|
{
|
||||||
printf("Syntax: %s <inputfile> <symbolname>\n", argv[0]);
|
printf("Syntax: %s [-base85] [-nocompress] <inputfile> <symbolname>\n", argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
binary_to_compressed_c(argv[1], argv[2]);
|
int argn = 1;
|
||||||
|
bool use_base85_encoding = false;
|
||||||
|
bool use_compression = true;
|
||||||
|
if (argv[argn][0] == '-')
|
||||||
|
{
|
||||||
|
if (strcmp(argv[argn], "-base85") == 0) { use_base85_encoding = true; argn++; }
|
||||||
|
else if (strcmp(argv[argn], "-nocompress") == 0) { use_compression = false; argn++; }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Unknown argument: '%s'\n", argv[argn]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
binary_to_compressed_c(argv[argn], argv[argn+1], use_base85_encoding, use_compression);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool binary_to_compressed_c(const char* filename, const char* symbol)
|
char Encode85Byte(unsigned int x)
|
||||||
|
{
|
||||||
|
x = (x % 85) + 35;
|
||||||
|
return (x>='\\') ? x+1 : x;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression)
|
||||||
{
|
{
|
||||||
// Read file
|
// Read file
|
||||||
FILE* f = fopen(filename, "rb");
|
FILE* f = fopen(filename, "rb");
|
||||||
@ -46,30 +66,49 @@ bool binary_to_compressed_c(const char* filename, const char* symbol)
|
|||||||
|
|
||||||
// Compress
|
// Compress
|
||||||
int maxlen = data_sz + 512 + (data_sz >> 2) + sizeof(int); // total guess
|
int maxlen = data_sz + 512 + (data_sz >> 2) + sizeof(int); // total guess
|
||||||
char* compressed = new char[maxlen];
|
char* compressed = use_compression ? new char[maxlen] : data;
|
||||||
int compressed_sz = stb_compress((stb_uchar*)compressed, (stb_uchar*)data, data_sz);
|
int compressed_sz = use_compression ? stb_compress((stb_uchar*)compressed, (stb_uchar*)data, data_sz) : data_sz;
|
||||||
memset(compressed + compressed_sz, 0, maxlen - compressed_sz);
|
if (use_compression)
|
||||||
|
memset(compressed + compressed_sz, 0, maxlen - compressed_sz);
|
||||||
|
|
||||||
// Output
|
// Output as Base85 encoded
|
||||||
FILE* out = stdout;
|
FILE* out = stdout;
|
||||||
fprintf(out, "// File: '%s' (%d bytes)\n", filename, (int)data_sz);
|
fprintf(out, "// File: '%s' (%d bytes)\n", filename, (int)data_sz);
|
||||||
fprintf(out, "// Exported using binary_to_compressed_c\n");
|
fprintf(out, "// Exported using binary_to_compressed_c.cpp\n");
|
||||||
fprintf(out, "static const unsigned int %s_compressed_size = %d;\n", symbol, (int)compressed_sz);
|
const char* compressed_str = use_compression ? "compressed_" : "";
|
||||||
fprintf(out, "static const unsigned int %s_compressed_data[%d/4] =\n{", symbol, (int)((compressed_sz+3)/4)*4);
|
if (use_base85_encoding)
|
||||||
int column = 0;
|
|
||||||
for (int i = 0; i < compressed_sz; i += 4)
|
|
||||||
{
|
{
|
||||||
unsigned int d = *(unsigned int*)(compressed + i);
|
fprintf(out, "static const char %s_%sdata_base85[%d+1] =\n \"", symbol, compressed_str, (int)((compressed_sz+3)/4)*5);
|
||||||
if ((column++ % COLUMNS) == 0)
|
int column = 0;
|
||||||
fprintf(out, "\n 0x%08x, ", d);
|
for (int i = 0; i < compressed_sz; i += 4)
|
||||||
else
|
{
|
||||||
fprintf(out, "0x%08x, ", d);
|
unsigned int d = *(unsigned int*)(compressed + i);
|
||||||
|
fprintf(out, "%c%c%c%c%c", Encode85Byte(d), Encode85Byte(d/85), Encode85Byte(d/7225), Encode85Byte(d/614125), Encode85Byte(d/52200625));
|
||||||
|
if ((i % 112) == 112-4)
|
||||||
|
fprintf(out, "\"\n \"");
|
||||||
|
}
|
||||||
|
fprintf(out, "\";\n\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(out, "static const unsigned int %s_%ssize = %d;\n", symbol, compressed_str, (int)compressed_sz);
|
||||||
|
fprintf(out, "static const unsigned int %s_%sdata[%d/4] =\n{", symbol, compressed_str, (int)((compressed_sz+3)/4)*4);
|
||||||
|
int column = 0;
|
||||||
|
for (int i = 0; i < compressed_sz; i += 4)
|
||||||
|
{
|
||||||
|
unsigned int d = *(unsigned int*)(compressed + i);
|
||||||
|
if ((column++ % 12) == 0)
|
||||||
|
fprintf(out, "\n 0x%08x, ", d);
|
||||||
|
else
|
||||||
|
fprintf(out, "0x%08x, ", d);
|
||||||
|
}
|
||||||
|
fprintf(out, "\n};\n\n");
|
||||||
}
|
}
|
||||||
fprintf(out, "\n};\n\n");
|
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
delete[] data;
|
delete[] data;
|
||||||
delete[] compressed;
|
if (use_compression)
|
||||||
|
delete[] compressed;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
imconfig.h
13
imconfig.h
@ -13,9 +13,6 @@
|
|||||||
//#define IMGUI_API __declspec( dllexport )
|
//#define IMGUI_API __declspec( dllexport )
|
||||||
//#define IMGUI_API __declspec( dllimport )
|
//#define IMGUI_API __declspec( dllimport )
|
||||||
|
|
||||||
//---- 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
|
//---- Include imgui_user.h at the end of imgui.h
|
||||||
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||||
|
|
||||||
@ -30,7 +27,7 @@
|
|||||||
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
|
||||||
//---- Implement STB libraries in a namespace to avoid conflicts
|
//---- Implement STB libraries in a namespace to avoid conflicts
|
||||||
//#define IMGUI_STB_NAMESPACE ImStb
|
//#define IMGUI_STB_NAMESPACE ImGuiStb
|
||||||
|
|
||||||
//---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
|
//---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
|
||||||
/*
|
/*
|
||||||
@ -43,14 +40,12 @@
|
|||||||
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//---- Freely implement extra functions within the ImGui:: namespace.
|
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
|
||||||
//---- Declare helpers or widgets implemented in imgui_user.inl or elsewhere, so end-user doesn't need to include multiple files.
|
//---- e.g. create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers.
|
||||||
//---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers.
|
|
||||||
/*
|
/*
|
||||||
namespace ImGui
|
namespace ImGui
|
||||||
{
|
{
|
||||||
void Value(const char* prefix, const MyVec2& v, const char* float_format = NULL);
|
void Value(const char* prefix, const MyMatrix44& v, const char* float_format = NULL);
|
||||||
void Value(const char* prefix, const MyVec4& v, const char* float_format = NULL);
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
336
imgui.h
336
imgui.h
@ -1,7 +1,9 @@
|
|||||||
// ImGui library v1.43
|
// dear imgui, v1.47
|
||||||
// See .cpp file for documentation.
|
// (headers)
|
||||||
// See ImGui::ShowTestWindow() for sample code.
|
|
||||||
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
|
// See imgui.cpp file for documentation.
|
||||||
|
// See ImGui::ShowTestWindow() in imgui_demo.cpp for demo code.
|
||||||
|
// Read 'Programmer guide' in imgui.cpp for notes on how to setup ImGui in your codebase.
|
||||||
// Get latest version at https://github.com/ocornut/imgui
|
// Get latest version at https://github.com/ocornut/imgui
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -12,10 +14,9 @@
|
|||||||
#include <float.h> // FLT_MAX
|
#include <float.h> // FLT_MAX
|
||||||
#include <stdarg.h> // va_list
|
#include <stdarg.h> // va_list
|
||||||
#include <stddef.h> // ptrdiff_t, NULL
|
#include <stddef.h> // ptrdiff_t, NULL
|
||||||
#include <stdlib.h> // NULL, malloc, free, qsort, atoi
|
|
||||||
#include <string.h> // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp
|
#include <string.h> // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp
|
||||||
|
|
||||||
#define IMGUI_VERSION "1.43"
|
#define IMGUI_VERSION "1.47"
|
||||||
|
|
||||||
// Define assertion handler.
|
// Define assertion handler.
|
||||||
#ifndef IM_ASSERT
|
#ifndef IM_ASSERT
|
||||||
@ -28,12 +29,19 @@
|
|||||||
#define IMGUI_API
|
#define IMGUI_API
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
|
#define IM_PRINTFARGS(FMT) __attribute__((format(printf, FMT, (FMT+1))))
|
||||||
|
#else
|
||||||
|
#define IM_PRINTFARGS(FMT)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
struct ImDrawCmd;
|
struct ImDrawCmd;
|
||||||
struct ImDrawList;
|
struct ImDrawList;
|
||||||
struct ImDrawData;
|
struct ImDrawData;
|
||||||
struct ImFont;
|
struct ImFont;
|
||||||
struct ImFontAtlas;
|
struct ImFontAtlas;
|
||||||
|
struct ImColor;
|
||||||
struct ImGuiIO;
|
struct ImGuiIO;
|
||||||
struct ImGuiStorage;
|
struct ImGuiStorage;
|
||||||
struct ImGuiStyle;
|
struct ImGuiStyle;
|
||||||
@ -52,7 +60,7 @@ typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_
|
|||||||
typedef int ImGuiSetCond; // enum ImGuiSetCond_
|
typedef int ImGuiSetCond; // enum ImGuiSetCond_
|
||||||
typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_
|
typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_
|
||||||
typedef int ImGuiSelectableFlags; // enum ImGuiSelectableFlags_
|
typedef int ImGuiSelectableFlags; // enum ImGuiSelectableFlags_
|
||||||
struct ImGuiTextEditCallbackData; // for advanced uses of InputText()
|
struct ImGuiTextEditCallbackData; // for advanced uses of InputText()
|
||||||
typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data);
|
typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data);
|
||||||
|
|
||||||
struct ImVec2
|
struct ImVec2
|
||||||
@ -85,7 +93,7 @@ struct ImVec4
|
|||||||
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
|
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
|
||||||
// - struct ImGuiTextEditCallbackData // Shared state of ImGui::InputText() when using custom callbacks
|
// - struct ImGuiTextEditCallbackData // Shared state of ImGui::InputText() when using custom callbacks
|
||||||
// - struct ImGuiListClipper // Helper to manually clip large list of items.
|
// - struct ImGuiListClipper // Helper to manually clip large list of items.
|
||||||
// - struct ImColor // Helper functions to created packed 32-bit RGBA color values
|
// - struct ImColor // Helper functions to created packed 32-bit RGBA color values
|
||||||
// - struct ImDrawList // Draw command list
|
// - struct ImDrawList // Draw command list
|
||||||
// - struct ImFontAtlas // Bake multiple fonts into a single texture, TTF font loader, bake glyphs into bitmap
|
// - struct ImFontAtlas // Bake multiple fonts into a single texture, TTF font loader, bake glyphs into bitmap
|
||||||
// - struct ImFont // Single font
|
// - struct ImFont // Single font
|
||||||
@ -97,6 +105,7 @@ namespace ImGui
|
|||||||
// Main
|
// Main
|
||||||
IMGUI_API ImGuiIO& GetIO();
|
IMGUI_API ImGuiIO& GetIO();
|
||||||
IMGUI_API ImGuiStyle& GetStyle();
|
IMGUI_API ImGuiStyle& GetStyle();
|
||||||
|
IMGUI_API ImDrawData* GetDrawData(); // same value as passed to your RenderDrawListsFn() function. valid after Render() and until the next call to NewFrame()
|
||||||
IMGUI_API void NewFrame();
|
IMGUI_API void NewFrame();
|
||||||
IMGUI_API void Render();
|
IMGUI_API void Render();
|
||||||
IMGUI_API void Shutdown();
|
IMGUI_API void Shutdown();
|
||||||
@ -106,15 +115,18 @@ namespace ImGui
|
|||||||
IMGUI_API void ShowMetricsWindow(bool* opened = NULL); // metrics window for debugging imgui
|
IMGUI_API void ShowMetricsWindow(bool* opened = NULL); // metrics window for debugging imgui
|
||||||
|
|
||||||
// Window
|
// Window
|
||||||
IMGUI_API bool Begin(const char* name = "Debug", bool* p_opened = NULL, ImGuiWindowFlags flags = 0); // see .cpp for details. return false when window is collapsed, so you can early out in your code. 'bool* p_opened' creates a widget on the upper-right to close the window (which sets your bool to false).
|
IMGUI_API bool Begin(const char* name, bool* p_opened = NULL, ImGuiWindowFlags flags = 0); // see .cpp for details. return false when window is collapsed, so you can early out in your code. 'bool* p_opened' creates a widget on the upper-right to close the window (which sets your bool to false).
|
||||||
IMGUI_API bool Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_use, float bg_alpha = -1.0f, ImGuiWindowFlags flags = 0); // this is the older/longer API. call SetNextWindowSize() instead if you want to set a window size. For regular windows, 'size_on_first_use' only applies to the first time EVER the window is created and probably not what you want! maybe obsolete this API eventually.
|
IMGUI_API bool Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_use, float bg_alpha = -1.0f, ImGuiWindowFlags flags = 0); // this is the older/longer API. the extra parameters aren't very relevant. call SetNextWindowSize() instead if you want to set a window size. For regular windows, 'size_on_first_use' only applies to the first time EVER the window is created and probably not what you want! maybe obsolete this API eventually.
|
||||||
IMGUI_API void End();
|
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); // begin a scrolling region. size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). size>0.0f: fixed size. each axis can use a different mode, e.g. ImVec2(0,400).
|
IMGUI_API bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // begin a scrolling region. size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). size>0.0f: fixed size. each axis can use a different mode, e.g. ImVec2(0,400).
|
||||||
IMGUI_API bool BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // "
|
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 void EndChild();
|
||||||
IMGUI_API ImVec2 GetContentRegionMax(); // window or current column boundaries, in windows coordinates
|
IMGUI_API ImVec2 GetContentRegionMax(); // current content boundaries (typically window boundaries including scrolling, or current column boundaries), in windows coordinates
|
||||||
IMGUI_API ImVec2 GetWindowContentRegionMin(); // window boundaries, in windows coordinates
|
IMGUI_API ImVec2 GetContentRegionAvail(); // == GetContentRegionMax() - GetCursorPos()
|
||||||
IMGUI_API ImVec2 GetWindowContentRegionMax();
|
IMGUI_API float GetContentRegionAvailWidth(); //
|
||||||
|
IMGUI_API ImVec2 GetWindowContentRegionMin(); // content boundaries min (roughly (0,0)-Scroll), in window coordinates
|
||||||
|
IMGUI_API ImVec2 GetWindowContentRegionMax(); // content boundaries max (roughly (0,0)+Size-Scroll) where Size can be override with SetNextWindowContentSize(), in window coordinates
|
||||||
|
IMGUI_API float GetWindowContentRegionWidth(); //
|
||||||
IMGUI_API ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives
|
IMGUI_API ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives
|
||||||
IMGUI_API ImFont* GetWindowFont();
|
IMGUI_API ImFont* GetWindowFont();
|
||||||
IMGUI_API float GetWindowFontSize(); // size (also height in pixels) of current font with current scale applied
|
IMGUI_API float GetWindowFontSize(); // size (also height in pixels) of current font with current scale applied
|
||||||
@ -122,11 +134,14 @@ namespace ImGui
|
|||||||
IMGUI_API ImVec2 GetWindowPos(); // get current window position in screen space (useful if you want to do your own drawing via the DrawList api)
|
IMGUI_API ImVec2 GetWindowPos(); // get current window position in screen space (useful if you want to do your own drawing via the DrawList api)
|
||||||
IMGUI_API ImVec2 GetWindowSize(); // get current window size
|
IMGUI_API ImVec2 GetWindowSize(); // get current window size
|
||||||
IMGUI_API float GetWindowWidth();
|
IMGUI_API float GetWindowWidth();
|
||||||
|
IMGUI_API float GetWindowHeight();
|
||||||
IMGUI_API bool IsWindowCollapsed();
|
IMGUI_API bool IsWindowCollapsed();
|
||||||
|
|
||||||
IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position. call before Begin()
|
IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position. call before Begin()
|
||||||
IMGUI_API void SetNextWindowPosCenter(ImGuiSetCond cond = 0); // set next window position to be centered on screen. call before Begin()
|
IMGUI_API void SetNextWindowPosCenter(ImGuiSetCond cond = 0); // set next window position to be centered on screen. 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. call before Begin()
|
IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set next window size. set axis to 0.0f to force an auto-fit on this axis. call before Begin()
|
||||||
|
IMGUI_API void SetNextWindowContentSize(const ImVec2& size); // set next window content size (enforce the range of scrollbars). set axis to 0.0f to leave it automatic. call before Begin()
|
||||||
|
IMGUI_API void SetNextWindowContentWidth(float width); // set next window content width (enforce the range of horizontal scrollbar). call before Begin()
|
||||||
IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set next window collapsed state. call before Begin()
|
IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set next window collapsed state. call before Begin()
|
||||||
IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most. call before Begin()
|
IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most. call before Begin()
|
||||||
IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set current window position - call within Begin()/End(). may incur tearing
|
IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set current window position - call within Begin()/End(). may incur tearing
|
||||||
@ -134,12 +149,15 @@ namespace ImGui
|
|||||||
IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set current window collapsed state
|
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 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 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 SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond = 0); // set named window size. set axis to 0.0f to force an auto-fit on this axis. may incur tearing
|
||||||
IMGUI_API void SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond = 0); // set named window collapsed state
|
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. use NULL to remove focus.
|
IMGUI_API void SetWindowFocus(const char* name); // set named window to be focused / front-most. use NULL to remove focus.
|
||||||
|
|
||||||
|
IMGUI_API float GetScrollX(); // get scrolling amount [0..GetScrollMaxX()]
|
||||||
IMGUI_API float GetScrollY(); // get scrolling amount [0..GetScrollMaxY()]
|
IMGUI_API float GetScrollY(); // get scrolling amount [0..GetScrollMaxY()]
|
||||||
IMGUI_API float GetScrollMaxY(); // get maximum scrolling amount == ContentSize.Y - WindowSize.Y
|
IMGUI_API float GetScrollMaxX(); // get maximum scrolling amount ~~ ContentSize.X - WindowSize.X
|
||||||
|
IMGUI_API float GetScrollMaxY(); // get maximum scrolling amount ~~ ContentSize.Y - WindowSize.Y
|
||||||
|
IMGUI_API void SetScrollX(float scroll_x); // set scrolling amount [0..GetScrollMaxX()]
|
||||||
IMGUI_API void SetScrollY(float scroll_y); // set scrolling amount [0..GetScrollMaxY()]
|
IMGUI_API void SetScrollY(float scroll_y); // set scrolling amount [0..GetScrollMaxY()]
|
||||||
IMGUI_API void SetScrollHere(float center_y_ratio = 0.5f); // adjust scrolling amount to make current cursor position visible. center_y_ratio=0.0: top, 0.5: center, 1.0: bottom.
|
IMGUI_API void SetScrollHere(float center_y_ratio = 0.5f); // adjust scrolling amount to make current cursor position visible. center_y_ratio=0.0: top, 0.5: center, 1.0: bottom.
|
||||||
IMGUI_API void SetScrollFromPosY(float pos_y, float center_y_ratio = 0.5f); // adjust scrolling amount to make given position valid. use GetCursorPos() or GetCursorStartPos()+offset to get valid positions.
|
IMGUI_API void SetScrollFromPosY(float pos_y, float center_y_ratio = 0.5f); // adjust scrolling amount to make given position valid. use GetCursorPos() or GetCursorStartPos()+offset to get valid positions.
|
||||||
@ -155,28 +173,30 @@ namespace ImGui
|
|||||||
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val);
|
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val);
|
||||||
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val);
|
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val);
|
||||||
IMGUI_API void PopStyleVar(int count = 1);
|
IMGUI_API void PopStyleVar(int count = 1);
|
||||||
|
IMGUI_API ImU32 GetColorU32(ImGuiCol idx, float alpha_mul = 1.0f); // retrieve given style color with style alpha applied and optional extra alpha multiplier
|
||||||
|
IMGUI_API ImU32 GetColorU32(const ImVec4& col); // retrieve given color with style alpha applied
|
||||||
|
|
||||||
// Parameters stacks (current window)
|
// 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 -1.0f always align width to the right side)
|
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 -1.0f always align width to the right side)
|
||||||
IMGUI_API void PopItemWidth();
|
IMGUI_API void PopItemWidth();
|
||||||
IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position
|
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 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();
|
IMGUI_API void PopTextWrapPos();
|
||||||
IMGUI_API void PushButtonRepeat(bool repeat); // in 'repeat' mode, Button*() functions return true multiple times as you hold them (uses io.KeyRepeatDelay/io.KeyRepeatRate for now)
|
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 PushButtonRepeat(bool repeat); // in 'repeat' mode, Button*() functions return repeated true in a typematic manner (uses io.KeyRepeatDelay/io.KeyRepeatRate for now). Note that you can call IsItemActive() after any Button() to tell if the button is held in the current frame.
|
||||||
IMGUI_API void PopButtonRepeat();
|
IMGUI_API void PopButtonRepeat();
|
||||||
|
|
||||||
// Cursor / Layout
|
// Cursor / Layout
|
||||||
IMGUI_API void BeginGroup(); // once closing a group it is seen as a single item (so you can use IsItemHovered() on a group, SameLine() between groups, etc.
|
IMGUI_API void BeginGroup(); // lock horizontal starting position. once closing a group it is seen as a single item (so you can use IsItemHovered() on a group, SameLine() between groups, etc.
|
||||||
IMGUI_API void EndGroup();
|
IMGUI_API void EndGroup();
|
||||||
IMGUI_API void Separator(); // horizontal line
|
IMGUI_API void Separator(); // horizontal line
|
||||||
IMGUI_API void SameLine(float pos_x = 0.0f, float spacing_w = -1.0f); // call between widgets or groups to layout them horizontally
|
IMGUI_API void SameLine(float local_pos_x = 0.0f, float spacing_w = -1.0f); // call between widgets or groups to layout them horizontally
|
||||||
IMGUI_API void Spacing(); // add spacing
|
IMGUI_API void Spacing(); // add spacing
|
||||||
IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size
|
IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size
|
||||||
IMGUI_API void Indent(); // move content position toward the right by style.IndentSpacing pixels
|
IMGUI_API void Indent(); // move content position toward the right by style.IndentSpacing pixels
|
||||||
IMGUI_API void Unindent(); // move content position back to the left (cancel Indent)
|
IMGUI_API void Unindent(); // move content position back to the left (cancel Indent)
|
||||||
IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns. use an identifier to distinguish multiple column sets. close with Columns(1).
|
IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true); // setup number of columns. use an identifier to distinguish multiple column sets. close with Columns(1).
|
||||||
IMGUI_API void NextColumn(); // next column
|
IMGUI_API void NextColumn(); // next column
|
||||||
IMGUI_API int GetColumnIndex(); // get current column index
|
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 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
|
||||||
@ -186,10 +206,10 @@ namespace ImGui
|
|||||||
IMGUI_API ImVec2 GetCursorPos(); // cursor position is relative to window position
|
IMGUI_API ImVec2 GetCursorPos(); // cursor position is relative to window position
|
||||||
IMGUI_API float GetCursorPosX(); // "
|
IMGUI_API float GetCursorPosX(); // "
|
||||||
IMGUI_API float GetCursorPosY(); // "
|
IMGUI_API float GetCursorPosY(); // "
|
||||||
IMGUI_API void SetCursorPos(const ImVec2& pos); // "
|
IMGUI_API void SetCursorPos(const ImVec2& local_pos); // "
|
||||||
IMGUI_API void SetCursorPosX(float x); // "
|
IMGUI_API void SetCursorPosX(float x); // "
|
||||||
IMGUI_API void SetCursorPosY(float y); // "
|
IMGUI_API void SetCursorPosY(float y); // "
|
||||||
IMGUI_API ImVec2 GetCursorStartPos(); // initial cursor position
|
IMGUI_API ImVec2 GetCursorStartPos(); // initial cursor position
|
||||||
IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute screen coordinates [0..io.DisplaySize]
|
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 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 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
|
||||||
@ -199,7 +219,7 @@ namespace ImGui
|
|||||||
|
|
||||||
// ID scopes
|
// ID scopes
|
||||||
// If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them.
|
// 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. Read the FAQ for more details.
|
// You can also use the "##foobar" syntax within widget label to distinguish them from each others. Read "A primer on the use of labels/IDs" in the FAQ for more details.
|
||||||
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 char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack!
|
||||||
IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end);
|
IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end);
|
||||||
IMGUI_API void PushID(const void* ptr_id);
|
IMGUI_API void PushID(const void* ptr_id);
|
||||||
@ -210,19 +230,19 @@ namespace ImGui
|
|||||||
IMGUI_API ImGuiID GetID(const void* ptr_id);
|
IMGUI_API ImGuiID GetID(const void* ptr_id);
|
||||||
|
|
||||||
// Widgets
|
// Widgets
|
||||||
IMGUI_API void Text(const char* fmt, ...);
|
IMGUI_API void Text(const char* fmt, ...) IM_PRINTFARGS(1);
|
||||||
IMGUI_API void TextV(const char* fmt, va_list args);
|
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 TextColored(const ImVec4& col, const char* fmt, ...) IM_PRINTFARGS(2); // 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 TextColoredV(const ImVec4& col, const char* fmt, va_list args);
|
||||||
IMGUI_API void TextDisabled(const char* fmt, ...); // shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); Text(fmt, ...); PopStyleColor();
|
IMGUI_API void TextDisabled(const char* fmt, ...) IM_PRINTFARGS(1); // shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); Text(fmt, ...); PopStyleColor();
|
||||||
IMGUI_API void TextDisabledV(const char* fmt, va_list args);
|
IMGUI_API void TextDisabledV(const char* fmt, va_list args);
|
||||||
IMGUI_API void TextWrapped(const char* fmt, ...); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();. Note that this won't work on an auto-resizing window if there's no other widgets to extend the window width, yoy may need to set a size using SetNextWindowSize().
|
IMGUI_API void TextWrapped(const char* fmt, ...) IM_PRINTFARGS(1); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();. Note that this won't work on an auto-resizing window if there's no other widgets to extend the window width, yoy may need to set a size using SetNextWindowSize().
|
||||||
IMGUI_API void TextWrappedV(const char* fmt, va_list args);
|
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 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 LabelText(const char* label, const char* fmt, ...) IM_PRINTFARGS(2); // 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 LabelTextV(const char* label, const char* fmt, va_list args);
|
||||||
IMGUI_API void Bullet();
|
IMGUI_API void Bullet();
|
||||||
IMGUI_API void BulletText(const char* fmt, ...);
|
IMGUI_API void BulletText(const char* fmt, ...) IM_PRINTFARGS(1);
|
||||||
IMGUI_API void BulletTextV(const char* fmt, va_list args);
|
IMGUI_API void BulletTextV(const char* fmt, va_list args);
|
||||||
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0));
|
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0));
|
||||||
IMGUI_API bool SmallButton(const char* label);
|
IMGUI_API bool SmallButton(const char* label);
|
||||||
@ -240,11 +260,12 @@ namespace ImGui
|
|||||||
IMGUI_API bool ColorButton(const ImVec4& col, bool small_height = false, bool outline_border = true);
|
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 ColorEdit3(const char* label, float col[3]);
|
||||||
IMGUI_API bool ColorEdit4(const char* label, float col[4], bool show_alpha = true);
|
IMGUI_API bool ColorEdit4(const char* label, float col[4], bool show_alpha = true);
|
||||||
IMGUI_API void ColorEditMode(ImGuiColorEditMode mode);
|
IMGUI_API void ColorEditMode(ImGuiColorEditMode mode); // FIXME-OBSOLETE: This is inconsistent with most of the API and should be obsoleted.
|
||||||
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), int stride = sizeof(float));
|
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), int 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 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), int stride = sizeof(float));
|
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), int 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 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 void ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-1,0), const char* overlay = NULL);
|
||||||
|
|
||||||
// Widgets: Drags (tip: ctrl+click on a drag box to input text)
|
// Widgets: Drags (tip: ctrl+click on a drag box to input text)
|
||||||
IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound
|
IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound
|
||||||
@ -284,18 +305,18 @@ namespace ImGui
|
|||||||
IMGUI_API bool VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format = "%.0f");
|
IMGUI_API bool VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format = "%.0f");
|
||||||
|
|
||||||
// Widgets: Trees
|
// Widgets: 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_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 char* str_id, const char* fmt, ...) IM_PRINTFARGS(2); // "
|
||||||
IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...); // "
|
IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...) IM_PRINTFARGS(2); // "
|
||||||
IMGUI_API bool TreeNodeV(const char* str_id, const char* fmt, va_list args); // "
|
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 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 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 TreePush(const void* ptr_id = NULL); // "
|
||||||
IMGUI_API void TreePop();
|
IMGUI_API void TreePop();
|
||||||
IMGUI_API void SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond = 0); // set next tree node to be opened.
|
IMGUI_API void SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond = 0); // set next tree node to be opened.
|
||||||
|
|
||||||
// Widgets: Selectable / Lists
|
// Widgets: Selectable / Lists
|
||||||
IMGUI_API bool Selectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height
|
IMGUI_API bool Selectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height
|
||||||
IMGUI_API bool Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0));
|
IMGUI_API bool Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags = 0, 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, 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 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);
|
||||||
@ -308,11 +329,11 @@ namespace ImGui
|
|||||||
IMGUI_API void Value(const char* prefix, int v);
|
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, unsigned int v);
|
||||||
IMGUI_API void Value(const char* prefix, float v, const char* float_format = NULL);
|
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 ValueColor(const char* prefix, const ImVec4& v);
|
||||||
IMGUI_API void Color(const char* prefix, unsigned int v);
|
IMGUI_API void ValueColor(const char* prefix, unsigned int v);
|
||||||
|
|
||||||
// Tooltip
|
// Tooltip
|
||||||
IMGUI_API void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins
|
IMGUI_API void SetTooltip(const char* fmt, ...) IM_PRINTFARGS(1); // 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 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 BeginTooltip(); // use to create full-featured tooltip windows that aren't just text
|
||||||
IMGUI_API void EndTooltip();
|
IMGUI_API void EndTooltip();
|
||||||
@ -328,12 +349,12 @@ namespace ImGui
|
|||||||
IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled = true); // return true when activated + toggle (*p_selected) if p_selected != NULL
|
IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled = true); // return true when activated + toggle (*p_selected) if p_selected != NULL
|
||||||
|
|
||||||
// Popup
|
// Popup
|
||||||
IMGUI_API void OpenPopup(const char* str_id); // mark popup as open. popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level). close childs popups if any. will close popup when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block.
|
IMGUI_API void OpenPopup(const char* str_id); // mark popup as open. popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
|
||||||
IMGUI_API bool BeginPopup(const char* str_id); // return true if popup if opened and start outputting to it. only call EndPopup() if BeginPopup() returned true!
|
IMGUI_API bool BeginPopup(const char* str_id); // return true if popup if opened and start outputting to it. only call EndPopup() if BeginPopup() returned true!
|
||||||
IMGUI_API bool BeginPopupModal(const char* name, bool* p_opened = NULL, ImGuiWindowFlags extra_flags = 0); // modal dialog (can't close them by clicking outside)
|
IMGUI_API bool BeginPopupModal(const char* name, bool* p_opened = NULL, ImGuiWindowFlags extra_flags = 0); // modal dialog (can't close them by clicking outside)
|
||||||
IMGUI_API bool BeginPopupContextItem(const char* str_id, int mouse_button = 1); // helper to open and begin popup when clicked on last item
|
IMGUI_API bool BeginPopupContextItem(const char* str_id, int mouse_button = 1); // helper to open and begin popup when clicked on last item. read comments in .cpp!
|
||||||
IMGUI_API bool BeginPopupContextWindow(bool also_over_items = true, const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked on current window
|
IMGUI_API bool BeginPopupContextWindow(bool also_over_items = true, const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked on current window.
|
||||||
IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked in void (no window)
|
IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked in void (no window).
|
||||||
IMGUI_API void EndPopup();
|
IMGUI_API void EndPopup();
|
||||||
IMGUI_API void CloseCurrentPopup(); // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup.
|
IMGUI_API void CloseCurrentPopup(); // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup.
|
||||||
|
|
||||||
@ -343,20 +364,20 @@ namespace ImGui
|
|||||||
IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard
|
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 LogFinish(); // stop logging (close file, etc.)
|
||||||
IMGUI_API void LogButtons(); // helper to display buttons for logging to tty/file/clipboard
|
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)
|
IMGUI_API void LogText(const char* fmt, ...) IM_PRINTFARGS(1); // pass text data straight to log (without being displayed)
|
||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse?
|
IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse?
|
||||||
IMGUI_API bool IsItemHoveredRect(); // was the last item hovered by mouse? even if another item is active while we are hovering this
|
IMGUI_API bool IsItemHoveredRect(); // was the last item hovered by mouse? even if another item is active or window is blocked by popup while we are hovering this
|
||||||
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 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 IsItemVisible();
|
IMGUI_API bool IsItemVisible(); // was the last item visible? (aka not out of sight due to clipping/scrolling.)
|
||||||
IMGUI_API bool IsAnyItemHovered();
|
IMGUI_API bool IsAnyItemHovered();
|
||||||
IMGUI_API bool IsAnyItemActive();
|
IMGUI_API bool IsAnyItemActive();
|
||||||
IMGUI_API ImVec2 GetItemRectMin(); // get bounding rect of last item in screen space
|
IMGUI_API ImVec2 GetItemRectMin(); // get bounding rect of last item in screen space
|
||||||
IMGUI_API ImVec2 GetItemRectMax(); // "
|
IMGUI_API ImVec2 GetItemRectMax(); // "
|
||||||
IMGUI_API ImVec2 GetItemRectSize(); // "
|
IMGUI_API ImVec2 GetItemRectSize(); // "
|
||||||
IMGUI_API bool IsWindowHovered();
|
IMGUI_API bool IsWindowHovered(); // is current window hovered and hoverable (not blocked by a popup) (differentiate child windows from each others)
|
||||||
IMGUI_API bool IsWindowFocused(); // is current window focused (differentiate child windows from each others)
|
IMGUI_API bool IsWindowFocused(); // is current window focused
|
||||||
IMGUI_API bool IsRootWindowFocused(); // is current root window focused (top parent window in case of child windows)
|
IMGUI_API bool IsRootWindowFocused(); // is current root window focused (top parent window in case of child windows)
|
||||||
IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused
|
IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused
|
||||||
IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle of given size starting from cursor pos is visible (not clipped). to perform coarse clipping on user's side (as an optimization)
|
IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle of given size starting from cursor pos is visible (not clipped). to perform coarse clipping on user's side (as an optimization)
|
||||||
@ -368,9 +389,10 @@ namespace ImGui
|
|||||||
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 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); // calculate coarse clipping for large list of evenly sized items. Prefer using the ImGuiListClipper higher-level helper if you can.
|
IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // calculate coarse clipping for large list of evenly sized items. Prefer using the ImGuiListClipper higher-level helper if you can.
|
||||||
|
|
||||||
IMGUI_API bool BeginChildFrame(ImGuiID id, const ImVec2& size); // helper to create a child window / scrolling region that looks like a normal widget frame
|
IMGUI_API bool BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags extra_flags = 0); // helper to create a child window / scrolling region that looks like a normal widget frame
|
||||||
IMGUI_API void EndChildFrame();
|
IMGUI_API void EndChildFrame();
|
||||||
|
|
||||||
|
IMGUI_API ImVec4 ColorConvertU32ToFloat4(ImU32 in);
|
||||||
IMGUI_API ImU32 ColorConvertFloat4ToU32(const ImVec4& in);
|
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 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);
|
IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b);
|
||||||
@ -380,25 +402,28 @@ namespace ImGui
|
|||||||
IMGUI_API bool IsKeyDown(int key_index); // key_index into the keys_down[] array, imgui doesn't know the semantic of each entry, uses your own indices!
|
IMGUI_API bool IsKeyDown(int key_index); // key_index into the keys_down[] array, imgui doesn't know the semantic of each entry, uses your own indices!
|
||||||
IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // uses user's key indices as stored in the keys_down[] array. if repeat=true. uses io.KeyRepeatDelay / KeyRepeatRate
|
IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // uses user's key indices as stored in the keys_down[] array. if repeat=true. uses io.KeyRepeatDelay / KeyRepeatRate
|
||||||
IMGUI_API bool IsKeyReleased(int key_index); // "
|
IMGUI_API bool IsKeyReleased(int key_index); // "
|
||||||
IMGUI_API bool IsMouseDown(int button); // is mouse button held
|
IMGUI_API bool IsMouseDown(int button); // is mouse button held
|
||||||
IMGUI_API bool IsMouseClicked(int button, bool repeat = false); // did mouse button clicked (went from !Down to Down)
|
IMGUI_API bool IsMouseClicked(int button, bool repeat = false); // did mouse button clicked (went from !Down to Down)
|
||||||
IMGUI_API bool IsMouseDoubleClicked(int button); // did mouse button double-clicked. a double-click returns false in IsMouseClicked(). uses io.MouseDoubleClickTime.
|
IMGUI_API bool IsMouseDoubleClicked(int button); // did mouse button double-clicked. a double-click returns false in IsMouseClicked(). uses io.MouseDoubleClickTime.
|
||||||
IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down)
|
IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down)
|
||||||
IMGUI_API bool IsMouseHoveringWindow(); // is mouse hovering current window ("window" in API names always refer to current window)
|
IMGUI_API bool IsMouseHoveringWindow(); // is mouse hovering current window ("window" in API names always refer to current window). disregarding of any consideration of being blocked by a popup. (unlike IsWindowHovered() this will return true even if the window is blocked because of a popup)
|
||||||
IMGUI_API bool IsMouseHoveringAnyWindow(); // is mouse hovering any active imgui window
|
IMGUI_API bool IsMouseHoveringAnyWindow(); // is mouse hovering any visible window
|
||||||
IMGUI_API bool IsMouseHoveringRect(const ImVec2& rect_min, const ImVec2& rect_max);// is mouse hovering given bounding rect
|
IMGUI_API bool IsMouseHoveringRect(const ImVec2& pos_min, const ImVec2& pos_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings. disregarding of consideration of focus/window ordering/blocked by a popup.
|
||||||
IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
||||||
IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
|
IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
|
||||||
IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // dragging amount since clicking, also see: GetItemActiveDragDelta(). if lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse positioning at the time of opening popup we have BeginPopup() into
|
||||||
IMGUI_API void ResetMouseDragDelta(int button = 0); //
|
IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // dragging amount since clicking. if lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
||||||
|
IMGUI_API void ResetMouseDragDelta(int button = 0); //
|
||||||
IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you
|
IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you
|
||||||
IMGUI_API void SetMouseCursor(ImGuiMouseCursor type); // set desired cursor type
|
IMGUI_API void SetMouseCursor(ImGuiMouseCursor type); // set desired cursor type
|
||||||
IMGUI_API void CaptureKeyboardFromApp(); // manually enforce imgui setting the io.WantCaptureKeyboard flag next frame (your application needs to handle it). e.g. capture keyboard when your widget is being hovered.
|
IMGUI_API void CaptureKeyboardFromApp(); // manually enforce imgui setting the io.WantCaptureKeyboard flag next frame (your application needs to handle it). e.g. capture keyboard when your widget is being hovered.
|
||||||
IMGUI_API void CaptureMouseFromApp(); // manually enforce imgui setting the io.WantCaptureMouse flag next frame (your application needs to handle it).
|
IMGUI_API void CaptureMouseFromApp(); // manually enforce imgui setting the io.WantCaptureMouse flag next frame (your application needs to handle it).
|
||||||
|
|
||||||
// Helpers functions to access the MemAllocFn/MemFreeFn pointers in ImGui::GetIO()
|
// Helpers functions to access functions pointers in ImGui::GetIO()
|
||||||
IMGUI_API void* MemAlloc(size_t sz);
|
IMGUI_API void* MemAlloc(size_t sz);
|
||||||
IMGUI_API void MemFree(void* ptr);
|
IMGUI_API void MemFree(void* ptr);
|
||||||
|
IMGUI_API const char* GetClipboardText();
|
||||||
|
IMGUI_API void SetClipboardText(const char* text);
|
||||||
|
|
||||||
// Internal state/context access - if you want to use multiple ImGui context, or share context between modules (e.g. DLL), or allocate the memory yourself
|
// Internal state/context access - if you want to use multiple ImGui context, or share context between modules (e.g. DLL), or allocate the memory yourself
|
||||||
IMGUI_API const char* GetVersion();
|
IMGUI_API const char* GetVersion();
|
||||||
@ -434,7 +459,11 @@ enum ImGuiWindowFlags_
|
|||||||
ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame
|
ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame
|
||||||
ImGuiWindowFlags_ShowBorders = 1 << 7, // Show borders around windows and items
|
ImGuiWindowFlags_ShowBorders = 1 << 7, // Show borders around windows and items
|
||||||
ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file
|
ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file
|
||||||
ImGuiWindowFlags_MenuBar = 1 << 9, // Has a menu-bar
|
ImGuiWindowFlags_NoInputs = 1 << 9, // Disable catching mouse or keyboard inputs
|
||||||
|
ImGuiWindowFlags_MenuBar = 1 << 10, // Has a menu-bar
|
||||||
|
ImGuiWindowFlags_HorizontalScrollbar = 1 << 11, // Enable horizontal scrollbar (off by default). You need to use SetNextWindowContentSize(ImVec2(width,0.0f)); prior to calling Begin() to specify width. Read code in imgui_demo in the "Horizontal Scrolling" section.
|
||||||
|
ImGuiWindowFlags_NoFocusOnAppearing = 1 << 12, // Disable taking focus when transitioning from hidden to visible state
|
||||||
|
ImGuiWindowFlags_NoBringToFrontOnFocus = 1 << 13, // Disable bringing window to front when taking focus (e.g. clicking on it or programatically giving it focus)
|
||||||
// [Internal]
|
// [Internal]
|
||||||
ImGuiWindowFlags_ChildWindow = 1 << 20, // Don't use! For internal use by BeginChild()
|
ImGuiWindowFlags_ChildWindow = 1 << 20, // Don't use! For internal use by BeginChild()
|
||||||
ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 21, // Don't use! For internal use by BeginChild()
|
ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 21, // Don't use! For internal use by BeginChild()
|
||||||
@ -464,6 +493,8 @@ enum ImGuiInputTextFlags_
|
|||||||
ImGuiInputTextFlags_CtrlEnterForNewLine = 1 << 11, // In multi-line mode, allow exiting edition by pressing Enter. Ctrl+Enter to add new line (by default adds new lines with Enter).
|
ImGuiInputTextFlags_CtrlEnterForNewLine = 1 << 11, // In multi-line mode, allow exiting edition by pressing Enter. Ctrl+Enter to add new line (by default adds new lines with Enter).
|
||||||
ImGuiInputTextFlags_NoHorizontalScroll = 1 << 12, // Disable following the cursor horizontally
|
ImGuiInputTextFlags_NoHorizontalScroll = 1 << 12, // Disable following the cursor horizontally
|
||||||
ImGuiInputTextFlags_AlwaysInsertMode = 1 << 13, // Insert mode
|
ImGuiInputTextFlags_AlwaysInsertMode = 1 << 13, // Insert mode
|
||||||
|
ImGuiInputTextFlags_ReadOnly = 1 << 14, // Read-only mode
|
||||||
|
ImGuiInputTextFlags_Password = 1 << 15, // Password mode, display all characters as '*'
|
||||||
// [Internal]
|
// [Internal]
|
||||||
ImGuiInputTextFlags_Multiline = 1 << 20 // For internal use by InputTextMultiline()
|
ImGuiInputTextFlags_Multiline = 1 << 20 // For internal use by InputTextMultiline()
|
||||||
};
|
};
|
||||||
@ -626,7 +657,7 @@ struct ImGuiStyle
|
|||||||
float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin()
|
float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin()
|
||||||
float IndentSpacing; // Horizontal indentation when e.g. entering a tree node
|
float IndentSpacing; // Horizontal indentation when e.g. entering a tree node
|
||||||
float ColumnsMinSpacing; // Minimum horizontal spacing between two columns
|
float ColumnsMinSpacing; // Minimum horizontal spacing between two columns
|
||||||
float ScrollbarWidth; // Width of the vertical scrollbar
|
float ScrollbarSize; // Width of the vertical scrollbar, Height of the horizontal scrollbar
|
||||||
float ScrollbarRounding; // Radius of grab corners for scrollbar
|
float ScrollbarRounding; // Radius of grab corners for scrollbar
|
||||||
float GrabMinSize; // Minimum width/height of a grab box for slider/scrollbar
|
float GrabMinSize; // Minimum width/height of a grab box for slider/scrollbar
|
||||||
float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
||||||
@ -634,12 +665,13 @@ struct ImGuiStyle
|
|||||||
ImVec2 DisplaySafeAreaPadding; // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
|
ImVec2 DisplaySafeAreaPadding; // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
|
||||||
bool AntiAliasedLines; // Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU.
|
bool AntiAliasedLines; // Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU.
|
||||||
bool AntiAliasedShapes; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
|
bool AntiAliasedShapes; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
|
||||||
|
float CurveTessellationTol; // Tessellation tolerance. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
|
||||||
ImVec4 Colors[ImGuiCol_COUNT];
|
ImVec4 Colors[ImGuiCol_COUNT];
|
||||||
|
|
||||||
IMGUI_API ImGuiStyle();
|
IMGUI_API ImGuiStyle();
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is where your app communicate with ImGui. Call ImGui::GetIO() to access.
|
// This is where your app communicate with ImGui. Access via ImGui::GetIO().
|
||||||
// Read 'Programmer guide' section in .cpp file for general usage.
|
// Read 'Programmer guide' section in .cpp file for general usage.
|
||||||
struct ImGuiIO
|
struct ImGuiIO
|
||||||
{
|
{
|
||||||
@ -663,6 +695,7 @@ struct ImGuiIO
|
|||||||
ImFontAtlas* Fonts; // <auto> // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array.
|
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
|
float FontGlobalScale; // = 1.0f // Global scale all fonts
|
||||||
bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
|
bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
|
||||||
|
ImVec2 DisplayFramebufferScale; // = (1.0f,1.0f) // For retina display or other situations where window coordinates are different from framebuffer coordinates. User storage only, presently not used by ImGui.
|
||||||
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 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
|
ImVec2 DisplayVisibleMax; // <unset> (0.0f,0.0f) // If the values are the same, we defaults to Min=(0.0f) and Max=DisplaySize
|
||||||
|
|
||||||
@ -670,9 +703,10 @@ struct ImGuiIO
|
|||||||
// User Functions
|
// User Functions
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
// REQUIRED: rendering function.
|
// Rendering function, will be called in Render().
|
||||||
// See example code if you are unsure of how to implement this.
|
// Alternatively you can keep this to NULL and call GetDrawData() after Render() to get the same pointer.
|
||||||
void (*RenderDrawListsFn)(ImDrawData* data);
|
// See example applications if you are unsure of how to implement this.
|
||||||
|
void (*RenderDrawListsFn)(ImDrawData* data);
|
||||||
|
|
||||||
// Optional: access OS clipboard
|
// 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)
|
// (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures)
|
||||||
@ -694,8 +728,8 @@ struct ImGuiIO
|
|||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
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.
|
bool MouseDown[5]; // Mouse buttons: left, right, middle + extras. ImGui itself mostly only uses left button (BeginPopupContext** are using right button). Others buttons allows us to track if the 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.
|
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 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 KeyCtrl; // Keyboard modifier pressed: Control
|
||||||
bool KeyShift; // Keyboard modifier pressed: Shift
|
bool KeyShift; // Keyboard modifier pressed: Shift
|
||||||
@ -704,8 +738,9 @@ struct ImGuiIO
|
|||||||
ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
|
ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
IMGUI_API void AddInputCharacter(ImWchar c); // Helper to add a new character into InputCharacters[]
|
IMGUI_API void AddInputCharacter(ImWchar c); // Helper to add a new character into InputCharacters[]
|
||||||
IMGUI_API void AddInputCharactersUTF8(const char* utf8_chars); // Helper to add new characters into InputCharacters[] from an UTF-8 string
|
IMGUI_API void AddInputCharactersUTF8(const char* utf8_chars); // Helper to add new characters into InputCharacters[] from an UTF-8 string
|
||||||
|
IMGUI_API void ClearInputCharacters() { InputCharacters[0] = 0; } // Helper to clear the text input buffer
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
// Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application
|
// Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application
|
||||||
@ -713,10 +748,11 @@ struct ImGuiIO
|
|||||||
|
|
||||||
bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
|
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)
|
bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input)
|
||||||
|
bool WantTextInput; // Some text input widget is active, which will read input characters from the InputCharacters array.
|
||||||
float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames
|
float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames
|
||||||
int MetricsAllocs; // Number of active memory allocations
|
int MetricsAllocs; // Number of active memory allocations
|
||||||
int MetricsRenderVertices; // Vertices processed during last call to Render()
|
int MetricsRenderVertices; // Vertices output during last call to Render()
|
||||||
int MetricsRenderIndices; //
|
int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3
|
||||||
int MetricsActiveWindows; // Number of visible windows (exclude child windows)
|
int MetricsActiveWindows; // Number of visible windows (exclude child windows)
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
@ -744,7 +780,7 @@ struct ImGuiIO
|
|||||||
// Helpers
|
// Helpers
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Lightweight 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).
|
// Lightweight 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).
|
||||||
// Our implementation does NOT call c++ constructors because we don't use them in ImGui. Don't use this class as a straight std::vector replacement in your code!
|
// Our implementation does NOT call c++ constructors because we don't use them in ImGui. Don't use this class as a straight std::vector replacement in your code!
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ImVector
|
class ImVector
|
||||||
@ -782,14 +818,14 @@ public:
|
|||||||
inline int _grow_capacity(int new_size) { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > new_size ? new_capacity : new_size; }
|
inline int _grow_capacity(int new_size) { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > new_size ? new_capacity : new_size; }
|
||||||
|
|
||||||
inline void resize(int new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; }
|
inline void resize(int new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; }
|
||||||
inline void reserve(int new_capacity)
|
inline void reserve(int new_capacity)
|
||||||
{
|
{
|
||||||
if (new_capacity <= Capacity) return;
|
if (new_capacity <= Capacity) return;
|
||||||
T* new_data = (value_type*)ImGui::MemAlloc((size_t)new_capacity * sizeof(value_type));
|
T* new_data = (value_type*)ImGui::MemAlloc((size_t)new_capacity * sizeof(value_type));
|
||||||
memcpy(new_data, Data, (size_t)Size * sizeof(value_type));
|
memcpy(new_data, Data, (size_t)Size * sizeof(value_type));
|
||||||
ImGui::MemFree(Data);
|
ImGui::MemFree(Data);
|
||||||
Data = new_data;
|
Data = new_data;
|
||||||
Capacity = new_capacity;
|
Capacity = new_capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void push_back(const value_type& v) { if (Size == Capacity) reserve(_grow_capacity(Size+1)); Data[Size++] = v; }
|
inline void push_back(const value_type& v) { if (Size == Capacity) reserve(_grow_capacity(Size+1)); Data[Size++] = v; }
|
||||||
@ -839,11 +875,11 @@ struct ImGuiTextFilter
|
|||||||
int CountGrep;
|
int CountGrep;
|
||||||
|
|
||||||
ImGuiTextFilter(const char* default_filter = "");
|
ImGuiTextFilter(const char* default_filter = "");
|
||||||
void Clear() { InputBuf[0] = 0; Build(); }
|
void Clear() { InputBuf[0] = 0; Build(); }
|
||||||
void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f); // Helper calling InputText+Build
|
bool Draw(const char* label = "Filter (inc,-exc)", float width = 0.0f); // Helper calling InputText+Build
|
||||||
bool PassFilter(const char* val) const;
|
bool PassFilter(const char* text, const char* text_end = NULL) const;
|
||||||
bool IsActive() const { return !Filters.empty(); }
|
bool IsActive() const { return !Filters.empty(); }
|
||||||
IMGUI_API void Build();
|
IMGUI_API void Build();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper: Text buffer for logging/accumulating text
|
// Helper: Text buffer for logging/accumulating text
|
||||||
@ -852,12 +888,14 @@ struct ImGuiTextBuffer
|
|||||||
ImVector<char> Buf;
|
ImVector<char> Buf;
|
||||||
|
|
||||||
ImGuiTextBuffer() { Buf.push_back(0); }
|
ImGuiTextBuffer() { Buf.push_back(0); }
|
||||||
|
inline char operator[](int i) { return Buf.Data[i]; }
|
||||||
const char* begin() const { return &Buf.front(); }
|
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
|
const char* end() const { return &Buf.back(); } // Buf is zero-terminated, so end() will point on the zero-terminator
|
||||||
int size() const { return Buf.Size-1; }
|
int size() const { return Buf.Size - 1; }
|
||||||
bool empty() { return size() >= 1; }
|
bool empty() { return Buf.Size >= 2; }
|
||||||
void clear() { Buf.clear(); Buf.push_back(0); }
|
void clear() { Buf.clear(); Buf.push_back(0); }
|
||||||
IMGUI_API void append(const char* fmt, ...);
|
const char* c_str() const { return Buf.Data; }
|
||||||
|
IMGUI_API void append(const char* fmt, ...) IM_PRINTFARGS(2);
|
||||||
IMGUI_API void appendv(const char* fmt, va_list args);
|
IMGUI_API void appendv(const char* fmt, va_list args);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -871,13 +909,13 @@ struct ImGuiTextBuffer
|
|||||||
// - You want to store custom debug data easily without adding or editing structures in your code.
|
// - You want to store custom debug data easily without adding or editing structures in your code.
|
||||||
struct ImGuiStorage
|
struct ImGuiStorage
|
||||||
{
|
{
|
||||||
struct Pair
|
struct Pair
|
||||||
{
|
{
|
||||||
ImGuiID key;
|
ImGuiID key;
|
||||||
union { int val_i; float val_f; void* val_p; };
|
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, int _val_i) { key = _key; val_i = _val_i; }
|
||||||
Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
|
Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
|
||||||
Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
|
Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
|
||||||
};
|
};
|
||||||
ImVector<Pair> Data;
|
ImVector<Pair> Data;
|
||||||
|
|
||||||
@ -892,7 +930,7 @@ struct ImGuiStorage
|
|||||||
IMGUI_API void* GetVoidPtr(ImGuiID key) const; // default_val is NULL
|
IMGUI_API void* GetVoidPtr(ImGuiID key) const; // default_val is NULL
|
||||||
IMGUI_API void SetVoidPtr(ImGuiID key, void* val);
|
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.
|
// - 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.
|
// - 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:
|
// - A typical use case where this is convenient:
|
||||||
// float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar;
|
// float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar;
|
||||||
@ -911,6 +949,7 @@ struct ImGuiTextEditCallbackData
|
|||||||
ImGuiInputTextFlags EventFlag; // One of ImGuiInputTextFlags_Callback* // Read-only
|
ImGuiInputTextFlags EventFlag; // One of ImGuiInputTextFlags_Callback* // Read-only
|
||||||
ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only
|
ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only
|
||||||
void* UserData; // What user passed to InputText() // Read-only
|
void* UserData; // What user passed to InputText() // Read-only
|
||||||
|
bool ReadOnly; // Read-only mode // Read-only
|
||||||
|
|
||||||
// CharFilter event:
|
// CharFilter event:
|
||||||
ImWchar EventChar; // Character input // Read-write (replace character or set to zero)
|
ImWchar EventChar; // Character input // Read-write (replace character or set to zero)
|
||||||
@ -919,28 +958,32 @@ struct ImGuiTextEditCallbackData
|
|||||||
ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only
|
ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only
|
||||||
char* Buf; // Current text // Read-write (pointed data only)
|
char* Buf; // Current text // Read-write (pointed data only)
|
||||||
int BufSize; // // Read-only
|
int BufSize; // // Read-only
|
||||||
bool BufDirty; // Set if you modify Buf directly // Write
|
bool BufDirty; // Must set if you modify Buf directly // Write
|
||||||
int CursorPos; // // Read-write
|
int CursorPos; // // Read-write
|
||||||
int SelectionStart; // // Read-write (== to SelectionEnd when no selection)
|
int SelectionStart; // // Read-write (== to SelectionEnd when no selection)
|
||||||
int SelectionEnd; // // Read-write
|
int SelectionEnd; // // Read-write
|
||||||
|
|
||||||
// NB: calling those function loses selection.
|
// NB: calling those function loses selection.
|
||||||
void DeleteChars(int pos, int bytes_count);
|
void DeleteChars(int pos, int bytes_count);
|
||||||
void InsertChars(int pos, const char* text, const char* text_end = NULL);
|
void InsertChars(int pos, const char* text, const char* text_end = NULL);
|
||||||
bool HasSelection() const { return SelectionStart != SelectionEnd; }
|
bool HasSelection() const { return SelectionStart != SelectionEnd; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// ImColor() is just a helper that implicity converts to either ImU32 (packed 4x1 byte) or ImVec4 (4x1 float)
|
// 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.
|
// None of the ImGui API are using ImColor directly but you can use it as a convenience to pass colors in either ImU32 or ImVec4 formats.
|
||||||
struct ImColor
|
struct ImColor
|
||||||
{
|
{
|
||||||
ImVec4 Value;
|
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() { Value.x = Value.y = Value.z = Value.w = 0.0f; }
|
||||||
|
ImColor(int r, int g, int b, int a = 255) { float sc = 1.0f/255.0f; Value.x = (float)r * sc; Value.y = (float)g * sc; Value.z = (float)b * sc; Value.w = (float)a * sc; }
|
||||||
|
ImColor(ImU32 rgba) { float sc = 1.0f/255.0f; Value.x = (float)(rgba&0xFF) * sc; Value.y = (float)((rgba>>8)&0xFF) * sc; Value.z = (float)((rgba>>16)&0xFF) * sc; Value.w = (float)(rgba >> 24) * sc; }
|
||||||
ImColor(float r, float g, float b, float a = 1.0f) { Value.x = r; Value.y = g; Value.z = b; Value.w = a; }
|
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; }
|
ImColor(const ImVec4& col) { Value = col; }
|
||||||
operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); }
|
inline operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); }
|
||||||
operator ImVec4() const { return Value; }
|
inline operator ImVec4() const { return Value; }
|
||||||
|
|
||||||
|
inline void SetHSV(float h, float s, float v, float a = 1.0f){ ImGui::ColorConvertHSVtoRGB(h, s, v, Value.x, Value.y, Value.z); Value.w = a; }
|
||||||
|
|
||||||
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); }
|
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); }
|
||||||
};
|
};
|
||||||
@ -952,10 +995,11 @@ struct ImColor
|
|||||||
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) // display only visible items
|
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) // display only visible items
|
||||||
// ImGui::Text("line number %d", i);
|
// ImGui::Text("line number %d", i);
|
||||||
// clipper.End();
|
// clipper.End();
|
||||||
|
// NB: 'count' is only used to clamp the result, if you don't know your count you can use INT_MAX
|
||||||
struct ImGuiListClipper
|
struct ImGuiListClipper
|
||||||
{
|
{
|
||||||
float ItemsHeight;
|
float ItemsHeight;
|
||||||
int ItemsCount, DisplayStart, DisplayEnd;
|
int ItemsCount, DisplayStart, DisplayEnd;
|
||||||
|
|
||||||
ImGuiListClipper() { ItemsHeight = 0.0f; ItemsCount = DisplayStart = DisplayEnd = -1; }
|
ImGuiListClipper() { ItemsHeight = 0.0f; ItemsCount = DisplayStart = DisplayEnd = -1; }
|
||||||
ImGuiListClipper(int count, float height) { ItemsCount = -1; Begin(count, height); }
|
ImGuiListClipper(int count, float height) { ItemsCount = -1; Begin(count, height); }
|
||||||
@ -1001,10 +1045,14 @@ struct ImDrawCmd
|
|||||||
ImTextureID TextureId; // 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.
|
ImTextureID TextureId; // 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 UserCallback; // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally.
|
ImDrawCallback UserCallback; // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally.
|
||||||
void* UserCallbackData; // The draw callback code can access this.
|
void* UserCallbackData; // The draw callback code can access this.
|
||||||
|
|
||||||
|
ImDrawCmd() { ElemCount = 0; ClipRect.x = ClipRect.y = -8192.0f; ClipRect.z = ClipRect.w = +8192.0f; TextureId = NULL; UserCallback = NULL; UserCallbackData = NULL; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Vertex index
|
// Vertex index (override with, e.g. '#define ImDrawIdx unsigned int' in ImConfig)
|
||||||
|
#ifndef ImDrawIdx
|
||||||
typedef unsigned short ImDrawIdx;
|
typedef unsigned short ImDrawIdx;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Vertex layout
|
// Vertex layout
|
||||||
#ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT
|
#ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT
|
||||||
@ -1022,6 +1070,7 @@ IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Draw channels are used by the Columns API to "split" the render list into different channels while building, so items of each column can be batched together.
|
// Draw channels are used by the Columns API to "split" the render list into different channels while building, so items of each column can be batched together.
|
||||||
|
// You can also use them to simulate drawing layers and submit primitives in a different order than how they will be rendered.
|
||||||
struct ImDrawChannel
|
struct ImDrawChannel
|
||||||
{
|
{
|
||||||
ImVector<ImDrawCmd> CmdBuffer;
|
ImVector<ImDrawCmd> CmdBuffer;
|
||||||
@ -1048,22 +1097,21 @@ struct ImDrawList
|
|||||||
ImDrawVert* _VtxWritePtr; // [Internal] point within VtxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
|
ImDrawVert* _VtxWritePtr; // [Internal] point within VtxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
|
||||||
ImDrawIdx* _IdxWritePtr; // [Internal] point within IdxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
|
ImDrawIdx* _IdxWritePtr; // [Internal] point within IdxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
|
||||||
ImVector<ImVec4> _ClipRectStack; // [Internal]
|
ImVector<ImVec4> _ClipRectStack; // [Internal]
|
||||||
ImVector<ImTextureID> _TextureIdStack; // [Internal]
|
ImVector<ImTextureID> _TextureIdStack; // [Internal]
|
||||||
ImVector<ImVec2> _Path; // [Internal] current path building
|
ImVector<ImVec2> _Path; // [Internal] current path building
|
||||||
int _ChannelCurrent; // [Internal] current channel number (0)
|
int _ChannelsCurrent; // [Internal] current channel number (0)
|
||||||
ImVector<ImDrawChannel> _Channels; // [Internal] draw channels for columns API
|
int _ChannelsCount; // [Internal] number of active channels (1+)
|
||||||
|
ImVector<ImDrawChannel> _Channels; // [Internal] draw channels for columns API (not resized down so _ChannelsCount may be smaller than _Channels.Size)
|
||||||
|
|
||||||
ImDrawList() { _OwnerName = NULL; Clear(); }
|
ImDrawList() { _OwnerName = NULL; Clear(); }
|
||||||
~ImDrawList() { ClearFreeMemory(); }
|
~ImDrawList() { ClearFreeMemory(); }
|
||||||
IMGUI_API void Clear();
|
IMGUI_API void PushClipRect(const ImVec4& clip_rect); // Scissoring. The values are x1, y1, x2, y2. Only apply to rendering. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling)
|
||||||
IMGUI_API void ClearFreeMemory();
|
|
||||||
IMGUI_API void PushClipRect(const ImVec4& clip_rect); // Scissoring. The values are x1, y1, x2, y2.
|
|
||||||
IMGUI_API void PushClipRectFullScreen();
|
IMGUI_API void PushClipRectFullScreen();
|
||||||
IMGUI_API void PopClipRect();
|
IMGUI_API void PopClipRect();
|
||||||
IMGUI_API void PushTextureID(const ImTextureID& texture_id);
|
IMGUI_API void PushTextureID(const ImTextureID& texture_id);
|
||||||
IMGUI_API void PopTextureID();
|
IMGUI_API void PopTextureID();
|
||||||
|
|
||||||
// Primitives
|
// Primitives
|
||||||
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
|
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
|
||||||
IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F);
|
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 AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F);
|
||||||
@ -1071,29 +1119,39 @@ struct ImDrawList
|
|||||||
IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
|
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 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 AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
|
||||||
|
IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL);
|
||||||
IMGUI_API void AddText(const 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 ImVec4* cpu_fine_clip_rect = NULL);
|
IMGUI_API void AddText(const 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 ImVec4* cpu_fine_clip_rect = NULL);
|
||||||
IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col = 0xFFFFFFFF);
|
IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), ImU32 col = 0xFFFFFFFF);
|
||||||
IMGUI_API void AddPolyline(const ImVec2* points, const int num_points, ImU32 col, bool closed, float thickness, bool anti_aliased);
|
IMGUI_API void AddPolyline(const ImVec2* points, const int num_points, ImU32 col, bool closed, float thickness, bool anti_aliased);
|
||||||
IMGUI_API void AddConvexPolyFilled(const ImVec2* points, const int num_points, ImU32 col, bool anti_aliased);
|
IMGUI_API void AddConvexPolyFilled(const ImVec2* points, const int num_points, ImU32 col, bool anti_aliased);
|
||||||
|
IMGUI_API void AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments = 0);
|
||||||
|
|
||||||
// Stateful path API, add points then finish with PathFill() or PathStroke()
|
// Stateful path API, add points then finish with PathFill() or PathStroke()
|
||||||
inline void PathClear() { _Path.resize(0); }
|
inline void PathClear() { _Path.resize(0); }
|
||||||
inline void PathLineTo(const ImVec2& p) { _Path.push_back(p); }
|
inline void PathLineTo(const ImVec2& pos) { _Path.push_back(pos); }
|
||||||
IMGUI_API void PathArcToFast(const ImVec2& centre, float radius, int a_min, int a_max);
|
inline void PathLineToMergeDuplicate(const ImVec2& pos) { if (_Path.Size == 0 || _Path[_Path.Size-1].x != pos.x || _Path[_Path.Size-1].y != pos.y) _Path.push_back(pos); }
|
||||||
IMGUI_API void PathArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments = 12);
|
|
||||||
IMGUI_API void PathRect(const ImVec2& a, const ImVec2& b, float rounding = 0.0f, int rounding_corners = 0x0F);
|
|
||||||
inline void PathFill(ImU32 col) { AddConvexPolyFilled(_Path.Data, _Path.Size, col, true); PathClear(); }
|
inline void PathFill(ImU32 col) { AddConvexPolyFilled(_Path.Data, _Path.Size, col, true); PathClear(); }
|
||||||
inline void PathStroke(ImU32 col, bool closed, float thickness = 1.0f) { AddPolyline(_Path.Data, _Path.Size, col, closed, thickness, true); PathClear(); }
|
inline void PathStroke(ImU32 col, bool closed, float thickness = 1.0f) { AddPolyline(_Path.Data, _Path.Size, col, closed, thickness, true); PathClear(); }
|
||||||
|
IMGUI_API void PathArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments = 10);
|
||||||
|
IMGUI_API void PathArcToFast(const ImVec2& centre, float radius, int a_min_of_12, int a_max_of_12); // Use precomputed angles for a 12 steps circle
|
||||||
|
IMGUI_API void PathBezierCurveTo(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, int num_segments = 0);
|
||||||
|
IMGUI_API void PathRect(const ImVec2& rect_min, const ImVec2& rect_max, float rounding = 0.0f, int rounding_corners = 0x0F);
|
||||||
|
|
||||||
|
// Channels
|
||||||
|
// - Use to simulate layers. By switching channels to can render out-of-order (e.g. submit foreground primitives before background primitives)
|
||||||
|
// - Use to minimize draw calls (e.g. if going back-and-forth between multiple non-overlapping clipping rectangles, prefer to append into separate channels then merge at the end)
|
||||||
|
IMGUI_API void ChannelsSplit(int channels_count);
|
||||||
|
IMGUI_API void ChannelsMerge();
|
||||||
|
IMGUI_API void ChannelsSetCurrent(int channel_index);
|
||||||
|
|
||||||
// Advanced
|
// Advanced
|
||||||
IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'UserCallback' in ImDrawCmd and call the function instead of rendering triangles.
|
IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'UserCallback' 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
|
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
|
||||||
IMGUI_API void ChannelsSplit(int channel_count);
|
|
||||||
IMGUI_API void ChannelsMerge(int channel_count);
|
|
||||||
IMGUI_API void ChannelsSetCurrent(int idx);
|
|
||||||
|
|
||||||
// Internal helpers
|
// Internal helpers
|
||||||
// NB: all primitives needs to be reserved via PrimReserve() beforehand!
|
// NB: all primitives needs to be reserved via PrimReserve() beforehand!
|
||||||
|
IMGUI_API void Clear();
|
||||||
|
IMGUI_API void ClearFreeMemory();
|
||||||
IMGUI_API void PrimReserve(int idx_count, int vtx_count);
|
IMGUI_API void PrimReserve(int idx_count, int vtx_count);
|
||||||
IMGUI_API void PrimRect(const ImVec2& a, const ImVec2& b, ImU32 col);
|
IMGUI_API void PrimRect(const ImVec2& a, const ImVec2& b, ImU32 col);
|
||||||
IMGUI_API void PrimRectUV(const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col);
|
IMGUI_API void PrimRectUV(const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col);
|
||||||
@ -1107,29 +1165,32 @@ struct ImDrawList
|
|||||||
// All draw data to render an ImGui frame
|
// All draw data to render an ImGui frame
|
||||||
struct ImDrawData
|
struct ImDrawData
|
||||||
{
|
{
|
||||||
|
bool Valid; // Only valid after Render() is called and before the next NewFrame() is called.
|
||||||
ImDrawList** CmdLists;
|
ImDrawList** CmdLists;
|
||||||
int CmdListsCount;
|
int CmdListsCount;
|
||||||
int TotalVtxCount; // For convenience, sum of all cmd_lists vtx_buffer.Size
|
int TotalVtxCount; // For convenience, sum of all cmd_lists vtx_buffer.Size
|
||||||
int TotalIdxCount; // For convenience, sum of all cmd_lists idx_buffer.Size
|
int TotalIdxCount; // For convenience, sum of all cmd_lists idx_buffer.Size
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
void DeIndexAllBuffers(); // For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering!
|
ImDrawData() { Valid = false; CmdLists = NULL; CmdListsCount = TotalVtxCount = TotalIdxCount = 0; }
|
||||||
|
IMGUI_API void DeIndexAllBuffers(); // For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering!
|
||||||
|
IMGUI_API void ScaleClipRects(const ImVec2& sc); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution.
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ImFontConfig
|
struct ImFontConfig
|
||||||
{
|
{
|
||||||
void* FontData; // // TTF data
|
void* FontData; // // TTF data
|
||||||
int FontDataSize; // // TTF data size
|
int FontDataSize; // // TTF data size
|
||||||
bool FontDataOwnedByAtlas; // true // TTF data ownership taken by the container ImFontAtlas (will delete memory itself). Set to true
|
bool FontDataOwnedByAtlas; // true // TTF data ownership taken by the container ImFontAtlas (will delete memory itself). Set to true
|
||||||
int FontNo; // 0 // Index of font within TTF file
|
int FontNo; // 0 // Index of font within TTF file
|
||||||
float SizePixels; // // Size in pixels for rasterizer
|
float SizePixels; // // Size in pixels for rasterizer
|
||||||
int OversampleH, OversampleV; // 2, 2 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
|
int OversampleH, OversampleV; // 3, 1 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
|
||||||
bool PixelSnapH; // false // Align every character to pixel boundary (if enabled, set OversampleH/V to 1)
|
bool PixelSnapH; // false // Align every character to pixel boundary (if enabled, set OversampleH/V to 1)
|
||||||
ImVec2 GlyphExtraSpacing; // 0, 0 // Extra spacing (in pixels) between glyphs
|
ImVec2 GlyphExtraSpacing; // 0, 0 // Extra spacing (in pixels) between glyphs
|
||||||
const ImWchar* GlyphRanges; // // List of Unicode range (2 value per range, values are inclusive, zero-terminated list)
|
const ImWchar* GlyphRanges; // // List of Unicode range (2 value per range, values are inclusive, zero-terminated list)
|
||||||
bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs).
|
bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs).
|
||||||
bool MergeGlyphCenterV; // false // When merging (multiple ImFontInput for one ImFont), vertically center new glyphs instead of aligning their baseline
|
bool MergeGlyphCenterV; // false // When merging (multiple ImFontInput for one ImFont), vertically center new glyphs instead of aligning their baseline
|
||||||
|
|
||||||
// [Internal]
|
// [Internal]
|
||||||
char Name[32]; // Name (strictly for debugging)
|
char Name[32]; // Name (strictly for debugging)
|
||||||
ImFont* DstFont;
|
ImFont* DstFont;
|
||||||
@ -1153,7 +1214,8 @@ struct ImFontAtlas
|
|||||||
IMGUI_API ImFont* AddFontDefault(const ImFontConfig* font_cfg = NULL);
|
IMGUI_API ImFont* AddFontDefault(const ImFontConfig* font_cfg = NULL);
|
||||||
IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL);
|
IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL);
|
||||||
IMGUI_API ImFont* AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build()
|
IMGUI_API ImFont* AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build()
|
||||||
IMGUI_API ImFont* AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_ttf_data' untouched and still owned by caller. Compress with binary_to_compressed_c.cpp
|
IMGUI_API ImFont* AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_ttf_data' still owned by caller. Compress with binary_to_compressed_c.cpp
|
||||||
|
IMGUI_API ImFont* AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_ttf_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 paramaeter
|
||||||
IMGUI_API void ClearTexData(); // Clear the CPU-side texture data. Saves RAM once the texture has been copied to graphics memory.
|
IMGUI_API void ClearTexData(); // Clear the CPU-side texture data. Saves RAM once the texture has been copied to graphics memory.
|
||||||
IMGUI_API void ClearInputData(); // Clear the input TTF data (inc sizes, glyph ranges)
|
IMGUI_API void ClearInputData(); // Clear the input TTF data (inc sizes, glyph ranges)
|
||||||
IMGUI_API void ClearFonts(); // Clear the ImGui-side font data (glyphs storage, UV coordinates)
|
IMGUI_API void ClearFonts(); // Clear the ImGui-side font data (glyphs storage, UV coordinates)
|
||||||
@ -1166,11 +1228,12 @@ struct ImFontAtlas
|
|||||||
// Pitch = Width * BytesPerPixels
|
// 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 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 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; }
|
void SetTexID(void* id) { TexID = id; }
|
||||||
|
|
||||||
// Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
|
// Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
|
||||||
// (Those functions could be static but aren't so most users don't have to refer to the ImFontAtlas:: name ever if in their code; just using io.Fonts->)
|
// (Those functions could be static but aren't so most users don't have to refer to the ImFontAtlas:: name ever if in their code; just using io.Fonts->)
|
||||||
IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
|
IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
|
||||||
|
IMGUI_API const ImWchar* GetGlyphRangesKorean(); // Default + Korean characters
|
||||||
IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
|
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
|
IMGUI_API const ImWchar* GetGlyphRangesChinese(); // Japanese + full set of about 21000 CJK Unified Ideographs
|
||||||
IMGUI_API const ImWchar* GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters
|
IMGUI_API const ImWchar* GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters
|
||||||
@ -1180,8 +1243,9 @@ struct ImFontAtlas
|
|||||||
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.
|
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 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
|
unsigned int* TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
|
||||||
int TexWidth;
|
int TexWidth; // Texture width calculated during Build().
|
||||||
int TexHeight;
|
int TexHeight; // Texture height calculated during Build().
|
||||||
|
int TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height.
|
||||||
ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block)
|
ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block)
|
||||||
ImVector<ImFont*> Fonts;
|
ImVector<ImFont*> Fonts;
|
||||||
|
|
||||||
@ -1198,7 +1262,7 @@ struct ImFont
|
|||||||
// Members: Settings
|
// Members: Settings
|
||||||
float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
|
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()
|
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
|
ImVec2 DisplayOffset; // = (0.0f,1.0f) // Offset font rendering by xx pixels
|
||||||
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
|
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
|
||||||
ImFontConfig* ConfigData; // // Pointer within ImFontAtlas->ConfigData
|
ImFontConfig* ConfigData; // // Pointer within ImFontAtlas->ConfigData
|
||||||
int ConfigDataCount; //
|
int ConfigDataCount; //
|
||||||
@ -1216,18 +1280,18 @@ struct ImFont
|
|||||||
ImVector<Glyph> Glyphs;
|
ImVector<Glyph> Glyphs;
|
||||||
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
||||||
float FallbackXAdvance; //
|
float FallbackXAdvance; //
|
||||||
ImVector<float> IndexXAdvance; // Sparse. Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
|
ImVector<float> IndexXAdvance; // Sparse. Glyphs->XAdvance directly indexable (more cache-friendly that reading from Glyphs, for CalcTextSize functions which are often bottleneck in large UI)
|
||||||
ImVector<int> IndexLookup; // Sparse. Index glyphs by Unicode code-point
|
ImVector<int> IndexLookup; // Sparse. Index glyphs by Unicode code-point.
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
IMGUI_API ImFont();
|
IMGUI_API ImFont();
|
||||||
IMGUI_API ~ImFont();
|
IMGUI_API ~ImFont();
|
||||||
IMGUI_API void Clear();
|
IMGUI_API void Clear();
|
||||||
IMGUI_API void BuildLookupTable();
|
IMGUI_API void BuildLookupTable();
|
||||||
IMGUI_API float GetCharAdvance(unsigned short c) const { return ((int)c < IndexXAdvance.Size) ? IndexXAdvance[(int)c] : FallbackXAdvance; }
|
|
||||||
IMGUI_API const Glyph* FindGlyph(unsigned short c) const;
|
IMGUI_API const Glyph* FindGlyph(unsigned short c) const;
|
||||||
IMGUI_API void SetFallbackChar(ImWchar c);
|
IMGUI_API void SetFallbackChar(ImWchar c);
|
||||||
IMGUI_API bool IsLoaded() const { return ContainerAtlas != NULL; }
|
float GetCharAdvance(unsigned short c) const { return ((int)c < IndexXAdvance.Size) ? IndexXAdvance[(int)c] : FallbackXAdvance; }
|
||||||
|
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.
|
// '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.
|
// 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
|
||||||
|
2362
imgui_demo.cpp
Normal file
2362
imgui_demo.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2263
imgui_draw.cpp
Normal file
2263
imgui_draw.cpp
Normal file
File diff suppressed because it is too large
Load Diff
731
imgui_internal.h
Normal file
731
imgui_internal.h
Normal file
@ -0,0 +1,731 @@
|
|||||||
|
// dear imgui, v1.47
|
||||||
|
// (internals)
|
||||||
|
|
||||||
|
// You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility!
|
||||||
|
// Implement maths operators for ImVec2 (disabled by default to not collide with using IM_VEC2_CLASS_EXTRA along with your own math types+operators)
|
||||||
|
// #define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef IMGUI_VERSION
|
||||||
|
#error Must include imgui.h before imgui_internal.h
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h> // FILE*
|
||||||
|
#include <math.h> // sqrtf()
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (push)
|
||||||
|
#pragma warning (disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Forward Declarations
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct ImRect;
|
||||||
|
struct ImGuiColMod;
|
||||||
|
struct ImGuiStyleMod;
|
||||||
|
struct ImGuiGroupData;
|
||||||
|
struct ImGuiSimpleColumns;
|
||||||
|
struct ImGuiDrawContext;
|
||||||
|
struct ImGuiTextEditState;
|
||||||
|
struct ImGuiIniData;
|
||||||
|
struct ImGuiMouseCursorData;
|
||||||
|
struct ImGuiPopupRef;
|
||||||
|
struct ImGuiState;
|
||||||
|
struct ImGuiWindow;
|
||||||
|
|
||||||
|
typedef int ImGuiLayoutType; // enum ImGuiLayoutType_
|
||||||
|
typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_
|
||||||
|
typedef int ImGuiTreeNodeFlags; // enum ImGuiTreeNodeFlags_
|
||||||
|
typedef int ImGuiSliderFlags; // enum ImGuiSliderFlags_
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// STB libraries
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace ImGuiStb
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wunused-function"
|
||||||
|
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef STB_TEXTEDIT_STRING
|
||||||
|
#undef STB_TEXTEDIT_CHARTYPE
|
||||||
|
#define STB_TEXTEDIT_STRING ImGuiTextEditState
|
||||||
|
#define STB_TEXTEDIT_CHARTYPE ImWchar
|
||||||
|
#define STB_TEXTEDIT_GETWIDTH_NEWLINE -1.0f
|
||||||
|
#include "stb_textedit.h"
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace ImGuiStb
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Context
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern IMGUI_API ImGuiState* GImGui;
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Helpers
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
|
||||||
|
#define IM_PI 3.14159265358979323846f
|
||||||
|
|
||||||
|
// Helpers: UTF-8 <> wchar
|
||||||
|
IMGUI_API int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count
|
||||||
|
IMGUI_API int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
|
||||||
|
IMGUI_API int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count
|
||||||
|
IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count)
|
||||||
|
IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points
|
||||||
|
|
||||||
|
// Helpers: Misc
|
||||||
|
IMGUI_API ImU32 ImHash(const void* data, int data_size, ImU32 seed = 0); // Pass data_size==0 for zero-terminated strings
|
||||||
|
IMGUI_API void* ImLoadFileToMemory(const char* filename, const char* file_open_mode, int* out_file_size = NULL, int padding_bytes = 0);
|
||||||
|
IMGUI_API bool ImIsPointInTriangle(const ImVec2& p, const ImVec2& a, const ImVec2& b, const ImVec2& c);
|
||||||
|
static inline bool ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; }
|
||||||
|
static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
|
||||||
|
|
||||||
|
// Helpers: String
|
||||||
|
IMGUI_API int ImStricmp(const char* str1, const char* str2);
|
||||||
|
IMGUI_API int ImStrnicmp(const char* str1, const char* str2, int count);
|
||||||
|
IMGUI_API char* ImStrdup(const char* str);
|
||||||
|
IMGUI_API int ImStrlenW(const ImWchar* str);
|
||||||
|
IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line
|
||||||
|
IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end);
|
||||||
|
IMGUI_API int ImFormatString(char* buf, int buf_size, const char* fmt, ...) IM_PRINTFARGS(3);
|
||||||
|
IMGUI_API int ImFormatStringV(char* buf, int buf_size, const char* fmt, va_list args);
|
||||||
|
|
||||||
|
// Helpers: Math
|
||||||
|
// We are keeping those not leaking to the user by default, in the case the user has implicit cast operators between ImVec2 and its own types (when IM_VEC2_CLASS_EXTRA is defined)
|
||||||
|
#ifdef IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
|
||||||
|
static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
|
||||||
|
static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
|
||||||
|
static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
|
||||||
|
static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
|
||||||
|
static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
|
||||||
|
static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
|
||||||
|
static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
|
||||||
|
static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
|
||||||
|
static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
|
||||||
|
static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-rhs.w); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; }
|
||||||
|
static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; }
|
||||||
|
static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
|
||||||
|
static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
|
||||||
|
static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
|
||||||
|
static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
|
||||||
|
static inline int ImClamp(int v, int mn, int mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
|
||||||
|
static inline float ImClamp(float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
|
||||||
|
static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); }
|
||||||
|
static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
|
||||||
|
static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; }
|
||||||
|
static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); }
|
||||||
|
static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; }
|
||||||
|
static inline float ImLengthSqr(const ImVec4& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; }
|
||||||
|
static inline float ImInvLength(const ImVec2& lhs, float fail_value) { float d = lhs.x*lhs.x + lhs.y*lhs.y; if (d > 0.0f) return 1.0f / sqrtf(d); return fail_value; }
|
||||||
|
static inline ImVec2 ImRound(ImVec2 v) { return ImVec2((float)(int)v.x, (float)(int)v.y); }
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Types
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
enum ImGuiButtonFlags_
|
||||||
|
{
|
||||||
|
ImGuiButtonFlags_Repeat = 1 << 0,
|
||||||
|
ImGuiButtonFlags_PressedOnClick = 1 << 1, // return pressed on click only (default requires click+release)
|
||||||
|
ImGuiButtonFlags_PressedOnRelease = 1 << 2, // return pressed on release only (default requires click+release)
|
||||||
|
ImGuiButtonFlags_FlattenChilds = 1 << 3,
|
||||||
|
ImGuiButtonFlags_DontClosePopups = 1 << 4,
|
||||||
|
ImGuiButtonFlags_Disabled = 1 << 5,
|
||||||
|
ImGuiButtonFlags_AlignTextBaseLine = 1 << 6,
|
||||||
|
ImGuiButtonFlags_NoKeyModifiers = 1 << 7
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImGuiTreeNodeFlags_
|
||||||
|
{
|
||||||
|
ImGuiTreeNodeFlags_DefaultOpen = 1 << 0,
|
||||||
|
ImGuiTreeNodeFlags_NoAutoExpandOnLog = 1 << 1
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImGuiSliderFlags_
|
||||||
|
{
|
||||||
|
ImGuiSliderFlags_Vertical = 1 << 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImGuiSelectableFlagsPrivate_
|
||||||
|
{
|
||||||
|
// NB: need to be in sync with last value of ImGuiSelectableFlags_
|
||||||
|
ImGuiSelectableFlags_Menu = 1 << 2,
|
||||||
|
ImGuiSelectableFlags_MenuItem = 1 << 3,
|
||||||
|
ImGuiSelectableFlags_Disabled = 1 << 4,
|
||||||
|
ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 5
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIXME: this is in development, not exposed/functional as a generic feature yet.
|
||||||
|
enum ImGuiLayoutType_
|
||||||
|
{
|
||||||
|
ImGuiLayoutType_Vertical,
|
||||||
|
ImGuiLayoutType_Horizontal
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImGuiPlotType
|
||||||
|
{
|
||||||
|
ImGuiPlotType_Lines,
|
||||||
|
ImGuiPlotType_Histogram
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ImGuiDataType
|
||||||
|
{
|
||||||
|
ImGuiDataType_Int,
|
||||||
|
ImGuiDataType_Float
|
||||||
|
};
|
||||||
|
|
||||||
|
// 2D axis aligned bounding-box
|
||||||
|
// NB: we can't rely on ImVec2 math operators being available here
|
||||||
|
struct IMGUI_API ImRect
|
||||||
|
{
|
||||||
|
ImVec2 Min; // Upper-left
|
||||||
|
ImVec2 Max; // Lower-right
|
||||||
|
|
||||||
|
ImRect() : Min(FLT_MAX,FLT_MAX), Max(-FLT_MAX,-FLT_MAX) {}
|
||||||
|
ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {}
|
||||||
|
ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {}
|
||||||
|
ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {}
|
||||||
|
|
||||||
|
ImVec2 GetCenter() const { return ImVec2((Min.x+Max.x)*0.5f, (Min.y+Max.y)*0.5f); }
|
||||||
|
ImVec2 GetSize() const { return ImVec2(Max.x-Min.x, Max.y-Min.y); }
|
||||||
|
float GetWidth() const { return Max.x-Min.x; }
|
||||||
|
float GetHeight() const { return Max.y-Min.y; }
|
||||||
|
ImVec2 GetTL() const { return Min; } // Top-left
|
||||||
|
ImVec2 GetTR() const { return ImVec2(Max.x, Min.y); } // Top-right
|
||||||
|
ImVec2 GetBL() const { return ImVec2(Min.x, Max.y); } // Bottom-left
|
||||||
|
ImVec2 GetBR() const { return Max; } // Bottom-right
|
||||||
|
bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; }
|
||||||
|
bool Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x < Max.x && r.Max.y < Max.y; }
|
||||||
|
bool Overlaps(const ImRect& r) const { return r.Min.y < Max.y && r.Max.y > Min.y && r.Min.x < Max.x && r.Max.x > Min.x; }
|
||||||
|
void Add(const ImVec2& rhs) { if (Min.x > rhs.x) Min.x = rhs.x; if (Min.y > rhs.y) Min.y = rhs.y; if (Max.x < rhs.x) Max.x = rhs.x; if (Max.y < rhs.y) Max.y = rhs.y; }
|
||||||
|
void Add(const ImRect& rhs) { if (Min.x > rhs.Min.x) Min.x = rhs.Min.x; if (Min.y > rhs.Min.y) Min.y = rhs.Min.y; if (Max.x < rhs.Max.x) Max.x = rhs.Max.x; if (Max.y < rhs.Max.y) Max.y = rhs.Max.y; }
|
||||||
|
void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; }
|
||||||
|
void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; }
|
||||||
|
void Reduce(const ImVec2& amount) { Min.x += amount.x; Min.y += amount.y; Max.x -= amount.x; Max.y -= amount.y; }
|
||||||
|
void Clip(const ImRect& clip) { if (Min.x < clip.Min.x) Min.x = clip.Min.x; if (Min.y < clip.Min.y) Min.y = clip.Min.y; if (Max.x > clip.Max.x) Max.x = clip.Max.x; if (Max.y > clip.Max.y) Max.y = clip.Max.y; }
|
||||||
|
void Round() { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; }
|
||||||
|
ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const
|
||||||
|
{
|
||||||
|
if (!on_edge && Contains(p))
|
||||||
|
return p;
|
||||||
|
if (p.x > Max.x) p.x = Max.x;
|
||||||
|
else if (p.x < Min.x) p.x = Min.x;
|
||||||
|
if (p.y > Max.y) p.y = Max.y;
|
||||||
|
else if (p.y < Min.y) p.y = Min.y;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stacked color modifier, backup of modified data so we can restore it
|
||||||
|
struct ImGuiColMod
|
||||||
|
{
|
||||||
|
ImGuiCol Col;
|
||||||
|
ImVec4 PreviousValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stacked style modifier, backup of modified data so we can restore it
|
||||||
|
struct ImGuiStyleMod
|
||||||
|
{
|
||||||
|
ImGuiStyleVar Var;
|
||||||
|
ImVec2 PreviousValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stacked data for BeginGroup()/EndGroup()
|
||||||
|
struct ImGuiGroupData
|
||||||
|
{
|
||||||
|
ImVec2 BackupCursorPos;
|
||||||
|
ImVec2 BackupCursorMaxPos;
|
||||||
|
float BackupIndentX;
|
||||||
|
float BackupCurrentLineHeight;
|
||||||
|
float BackupCurrentLineTextBaseOffset;
|
||||||
|
float BackupLogLinePosY;
|
||||||
|
bool AdvanceCursor;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Per column data for Columns()
|
||||||
|
struct ImGuiColumnData
|
||||||
|
{
|
||||||
|
float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right)
|
||||||
|
//float IndentX;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Simple column measurement currently used for MenuItem() only. This is very short-sighted for now and NOT a generic helper.
|
||||||
|
struct IMGUI_API ImGuiSimpleColumns
|
||||||
|
{
|
||||||
|
int Count;
|
||||||
|
float Spacing;
|
||||||
|
float Width, NextWidth;
|
||||||
|
float Pos[8], NextWidths[8];
|
||||||
|
|
||||||
|
ImGuiSimpleColumns();
|
||||||
|
void Update(int count, float spacing, bool clear);
|
||||||
|
float DeclColumns(float w0, float w1, float w2);
|
||||||
|
float CalcExtraSpace(float avail_w);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Internal state of the currently focused/edited text input box
|
||||||
|
struct IMGUI_API ImGuiTextEditState
|
||||||
|
{
|
||||||
|
ImGuiID Id; // widget id owning the text state
|
||||||
|
ImVector<ImWchar> Text; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
|
||||||
|
ImVector<char> InitialText; // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
|
||||||
|
ImVector<char> TempTextBuffer;
|
||||||
|
int CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format.
|
||||||
|
int BufSizeA; // end-user buffer size
|
||||||
|
float ScrollX;
|
||||||
|
ImGuiStb::STB_TexteditState StbState;
|
||||||
|
float CursorAnim;
|
||||||
|
bool CursorFollow;
|
||||||
|
bool SelectedAllMouseLock;
|
||||||
|
|
||||||
|
ImGuiTextEditState() { memset(this, 0, sizeof(*this)); }
|
||||||
|
void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
|
||||||
|
void CursorClamp() { StbState.cursor = ImMin(StbState.cursor, CurLenW); StbState.select_start = ImMin(StbState.select_start, CurLenW); StbState.select_end = ImMin(StbState.select_end, CurLenW); }
|
||||||
|
bool HasSelection() const { return StbState.select_start != StbState.select_end; }
|
||||||
|
void ClearSelection() { StbState.select_start = StbState.select_end = StbState.cursor; }
|
||||||
|
void SelectAll() { StbState.select_start = 0; StbState.select_end = CurLenW; StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
|
||||||
|
void OnKeyPressed(int key);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Data saved in imgui.ini file
|
||||||
|
struct ImGuiIniData
|
||||||
|
{
|
||||||
|
char* Name;
|
||||||
|
ImGuiID ID;
|
||||||
|
ImVec2 Pos;
|
||||||
|
ImVec2 Size;
|
||||||
|
bool Collapsed;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mouse cursor data (used when io.MouseDrawCursor is set)
|
||||||
|
struct ImGuiMouseCursorData
|
||||||
|
{
|
||||||
|
ImGuiMouseCursor Type;
|
||||||
|
ImVec2 HotOffset;
|
||||||
|
ImVec2 Size;
|
||||||
|
ImVec2 TexUvMin[2];
|
||||||
|
ImVec2 TexUvMax[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Storage for current popup stack
|
||||||
|
struct ImGuiPopupRef
|
||||||
|
{
|
||||||
|
ImGuiID PopupID; // Set on OpenPopup()
|
||||||
|
ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup()
|
||||||
|
ImGuiWindow* ParentWindow; // Set on OpenPopup()
|
||||||
|
ImGuiID ParentMenuSet; // Set on OpenPopup()
|
||||||
|
ImVec2 MousePosOnOpen; // Copy of mouse position at the time of opening popup
|
||||||
|
|
||||||
|
ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupID = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Main state for ImGui
|
||||||
|
struct ImGuiState
|
||||||
|
{
|
||||||
|
bool Initialized;
|
||||||
|
ImGuiIO IO;
|
||||||
|
ImGuiStyle Style;
|
||||||
|
ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
|
||||||
|
float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize()
|
||||||
|
float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters.
|
||||||
|
ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite
|
||||||
|
|
||||||
|
float Time;
|
||||||
|
int FrameCount;
|
||||||
|
int FrameCountEnded;
|
||||||
|
int FrameCountRendered;
|
||||||
|
ImVector<ImGuiWindow*> Windows;
|
||||||
|
ImVector<ImGuiWindow*> WindowsSortBuffer;
|
||||||
|
ImGuiWindow* CurrentWindow; // Being drawn into
|
||||||
|
ImVector<ImGuiWindow*> CurrentWindowStack;
|
||||||
|
ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
|
||||||
|
ImGuiWindow* HoveredWindow; // Will catch mouse inputs
|
||||||
|
ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
|
||||||
|
ImGuiID HoveredId; // Hovered widget
|
||||||
|
bool HoveredIdAllowOverlap;
|
||||||
|
ImGuiID HoveredIdPreviousFrame;
|
||||||
|
ImGuiID ActiveId; // Active widget
|
||||||
|
ImGuiID ActiveIdPreviousFrame;
|
||||||
|
bool ActiveIdIsAlive;
|
||||||
|
bool ActiveIdIsJustActivated; // Set at the time of activation for one frame
|
||||||
|
bool ActiveIdAllowOverlap; // Set only by active widget
|
||||||
|
ImGuiWindow* ActiveIdWindow;
|
||||||
|
ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. Pointer is only valid if ActiveID is the "#MOVE" identifier of a window.
|
||||||
|
ImVector<ImGuiIniData> Settings; // .ini Settings
|
||||||
|
float SettingsDirtyTimer; // Save .ini settinngs on disk when time reaches zero
|
||||||
|
int DisableHideTextAfterDoubleHash;
|
||||||
|
ImVector<ImGuiColMod> ColorModifiers; // Stack for PushStyleColor()/PopStyleColor()
|
||||||
|
ImVector<ImGuiStyleMod> StyleModifiers; // Stack for PushStyleVar()/PopStyleVar()
|
||||||
|
ImVector<ImFont*> FontStack; // Stack for PushFont()/PopFont()
|
||||||
|
ImVector<ImGuiPopupRef> OpenedPopupStack; // Which popups are open (persistent)
|
||||||
|
ImVector<ImGuiPopupRef> CurrentPopupStack; // Which level of BeginPopup() we are in (reset every frame)
|
||||||
|
|
||||||
|
// Storage for SetNexWindow** and SetNextTreeNode*** functions
|
||||||
|
ImVec2 SetNextWindowPosVal;
|
||||||
|
ImVec2 SetNextWindowSizeVal;
|
||||||
|
ImVec2 SetNextWindowContentSizeVal;
|
||||||
|
bool SetNextWindowCollapsedVal;
|
||||||
|
ImGuiSetCond SetNextWindowPosCond;
|
||||||
|
ImGuiSetCond SetNextWindowSizeCond;
|
||||||
|
ImGuiSetCond SetNextWindowContentSizeCond;
|
||||||
|
ImGuiSetCond SetNextWindowCollapsedCond;
|
||||||
|
bool SetNextWindowFocus;
|
||||||
|
bool SetNextTreeNodeOpenedVal;
|
||||||
|
ImGuiSetCond SetNextTreeNodeOpenedCond;
|
||||||
|
|
||||||
|
// Render
|
||||||
|
ImDrawData RenderDrawData; // Main ImDrawData instance to pass render information to the user
|
||||||
|
ImVector<ImDrawList*> RenderDrawLists[3];
|
||||||
|
float ModalWindowDarkeningRatio;
|
||||||
|
ImDrawList OverlayDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays
|
||||||
|
ImGuiMouseCursor MouseCursor;
|
||||||
|
ImGuiMouseCursorData MouseCursorData[ImGuiMouseCursor_Count_];
|
||||||
|
|
||||||
|
// Widget state
|
||||||
|
ImGuiTextEditState InputTextState;
|
||||||
|
ImFont InputTextPasswordFont;
|
||||||
|
ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc.
|
||||||
|
ImGuiStorage ColorEditModeStorage; // Store user selection of color edit mode
|
||||||
|
ImVec2 ActiveClickDeltaToCenter;
|
||||||
|
float DragCurrentValue; // Currently dragged value, always float, not rounded by end-user precision settings
|
||||||
|
ImVec2 DragLastMouseDelta;
|
||||||
|
float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
|
||||||
|
float DragSpeedScaleSlow;
|
||||||
|
float DragSpeedScaleFast;
|
||||||
|
ImVec2 ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage?
|
||||||
|
char Tooltip[1024];
|
||||||
|
char* PrivateClipboard; // If no custom clipboard handler is defined
|
||||||
|
ImVec2 OsImePosRequest, OsImePosSet; // Cursor position request & last passed to the OS Input Method Editor
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
bool LogEnabled;
|
||||||
|
FILE* LogFile; // If != NULL log to stdout/ file
|
||||||
|
ImGuiTextBuffer* LogClipboard; // Else log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators.
|
||||||
|
int LogStartDepth;
|
||||||
|
int LogAutoExpandMaxDepth;
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
float FramerateSecPerFrame[120]; // calculate estimate of framerate for user
|
||||||
|
int FramerateSecPerFrameIdx;
|
||||||
|
float FramerateSecPerFrameAccum;
|
||||||
|
bool CaptureMouseNextFrame; // explicit capture via CaptureInputs() sets those flags
|
||||||
|
bool CaptureKeyboardNextFrame;
|
||||||
|
char TempBuffer[1024*3+1]; // temporary text buffer
|
||||||
|
|
||||||
|
ImGuiState()
|
||||||
|
{
|
||||||
|
Initialized = false;
|
||||||
|
Font = NULL;
|
||||||
|
FontSize = FontBaseSize = 0.0f;
|
||||||
|
FontTexUvWhitePixel = ImVec2(0.0f, 0.0f);
|
||||||
|
|
||||||
|
Time = 0.0f;
|
||||||
|
FrameCount = 0;
|
||||||
|
FrameCountEnded = FrameCountRendered = -1;
|
||||||
|
CurrentWindow = NULL;
|
||||||
|
FocusedWindow = NULL;
|
||||||
|
HoveredWindow = NULL;
|
||||||
|
HoveredRootWindow = NULL;
|
||||||
|
HoveredId = 0;
|
||||||
|
HoveredIdAllowOverlap = false;
|
||||||
|
HoveredIdPreviousFrame = 0;
|
||||||
|
ActiveId = 0;
|
||||||
|
ActiveIdPreviousFrame = 0;
|
||||||
|
ActiveIdIsAlive = false;
|
||||||
|
ActiveIdIsJustActivated = false;
|
||||||
|
ActiveIdAllowOverlap = false;
|
||||||
|
ActiveIdWindow = NULL;
|
||||||
|
MovedWindow = NULL;
|
||||||
|
SettingsDirtyTimer = 0.0f;
|
||||||
|
DisableHideTextAfterDoubleHash = 0;
|
||||||
|
|
||||||
|
SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
|
||||||
|
SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
|
||||||
|
SetNextWindowCollapsedVal = false;
|
||||||
|
SetNextWindowPosCond = 0;
|
||||||
|
SetNextWindowSizeCond = 0;
|
||||||
|
SetNextWindowCollapsedCond = 0;
|
||||||
|
SetNextWindowFocus = false;
|
||||||
|
SetNextTreeNodeOpenedVal = false;
|
||||||
|
SetNextTreeNodeOpenedCond = 0;
|
||||||
|
|
||||||
|
ScalarAsInputTextId = 0;
|
||||||
|
ActiveClickDeltaToCenter = ImVec2(0.0f, 0.0f);
|
||||||
|
DragCurrentValue = 0.0f;
|
||||||
|
DragLastMouseDelta = ImVec2(0.0f, 0.0f);
|
||||||
|
DragSpeedDefaultRatio = 0.01f;
|
||||||
|
DragSpeedScaleSlow = 0.01f;
|
||||||
|
DragSpeedScaleFast = 10.0f;
|
||||||
|
ScrollbarClickDeltaToGrabCenter = ImVec2(0.0f, 0.0f);
|
||||||
|
memset(Tooltip, 0, sizeof(Tooltip));
|
||||||
|
PrivateClipboard = NULL;
|
||||||
|
OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f);
|
||||||
|
|
||||||
|
ModalWindowDarkeningRatio = 0.0f;
|
||||||
|
OverlayDrawList._OwnerName = "##Overlay"; // Give it a name for debugging
|
||||||
|
MouseCursor = ImGuiMouseCursor_Arrow;
|
||||||
|
|
||||||
|
LogEnabled = false;
|
||||||
|
LogFile = NULL;
|
||||||
|
LogClipboard = NULL;
|
||||||
|
LogStartDepth = 0;
|
||||||
|
LogAutoExpandMaxDepth = 2;
|
||||||
|
|
||||||
|
memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
|
||||||
|
FramerateSecPerFrameIdx = 0;
|
||||||
|
FramerateSecPerFrameAccum = 0.0f;
|
||||||
|
CaptureMouseNextFrame = CaptureKeyboardNextFrame = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Transient per-window data, reset at the beginning of the frame
|
||||||
|
// FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiDrawContext is quite tenuous and could be reconsidered.
|
||||||
|
struct IMGUI_API ImGuiDrawContext
|
||||||
|
{
|
||||||
|
ImVec2 CursorPos;
|
||||||
|
ImVec2 CursorPosPrevLine;
|
||||||
|
ImVec2 CursorStartPos;
|
||||||
|
ImVec2 CursorMaxPos; // Implicitly calculate the size of our contents, always extending. Saved into window->SizeContents at the end of the frame
|
||||||
|
float CurrentLineHeight;
|
||||||
|
float CurrentLineTextBaseOffset;
|
||||||
|
float PrevLineHeight;
|
||||||
|
float PrevLineTextBaseOffset;
|
||||||
|
float LogLinePosY;
|
||||||
|
int TreeDepth;
|
||||||
|
ImGuiID LastItemID;
|
||||||
|
ImRect LastItemRect;
|
||||||
|
bool LastItemHoveredAndUsable; // Item rectangle is hovered, and its window is currently interactable with (not blocked by a popup preventing access to the window)
|
||||||
|
bool LastItemHoveredRect; // Item rectangle is hovered, but its window may or not be currently interactable with (might be blocked by a popup preventing access to the window)
|
||||||
|
bool MenuBarAppending;
|
||||||
|
float MenuBarOffsetX;
|
||||||
|
ImVector<ImGuiWindow*> ChildWindows;
|
||||||
|
ImGuiStorage* StateStorage;
|
||||||
|
ImGuiLayoutType LayoutType;
|
||||||
|
|
||||||
|
// We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings.
|
||||||
|
float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
|
||||||
|
float TextWrapPos; // == TextWrapPosStack.back() [empty == -1.0f]
|
||||||
|
bool AllowKeyboardFocus; // == AllowKeyboardFocusStack.back() [empty == true]
|
||||||
|
bool ButtonRepeat; // == ButtonRepeatStack.back() [empty == false]
|
||||||
|
ImVector<float> ItemWidthStack;
|
||||||
|
ImVector<float> TextWrapPosStack;
|
||||||
|
ImVector<bool> AllowKeyboardFocusStack;
|
||||||
|
ImVector<bool> ButtonRepeatStack;
|
||||||
|
ImVector<ImGuiGroupData>GroupStack;
|
||||||
|
ImGuiColorEditMode ColorEditMode;
|
||||||
|
int StackSizesBackup[6]; // Store size of various stacks for asserting
|
||||||
|
|
||||||
|
float IndentX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
|
||||||
|
float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API.
|
||||||
|
int ColumnsCurrent;
|
||||||
|
int ColumnsCount;
|
||||||
|
float ColumnsMinX;
|
||||||
|
float ColumnsMaxX;
|
||||||
|
float ColumnsStartPosY;
|
||||||
|
float ColumnsCellMinY;
|
||||||
|
float ColumnsCellMaxY;
|
||||||
|
bool ColumnsShowBorders;
|
||||||
|
ImGuiID ColumnsSetID;
|
||||||
|
ImVector<ImGuiColumnData> ColumnsData;
|
||||||
|
|
||||||
|
ImGuiDrawContext()
|
||||||
|
{
|
||||||
|
CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f);
|
||||||
|
CurrentLineHeight = PrevLineHeight = 0.0f;
|
||||||
|
CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f;
|
||||||
|
LogLinePosY = -1.0f;
|
||||||
|
TreeDepth = 0;
|
||||||
|
LastItemID = 0;
|
||||||
|
LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f);
|
||||||
|
LastItemHoveredAndUsable = LastItemHoveredRect = false;
|
||||||
|
MenuBarAppending = false;
|
||||||
|
MenuBarOffsetX = 0.0f;
|
||||||
|
StateStorage = NULL;
|
||||||
|
LayoutType = ImGuiLayoutType_Vertical;
|
||||||
|
ItemWidth = 0.0f;
|
||||||
|
ButtonRepeat = false;
|
||||||
|
AllowKeyboardFocus = true;
|
||||||
|
TextWrapPos = -1.0f;
|
||||||
|
ColorEditMode = ImGuiColorEditMode_RGB;
|
||||||
|
memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
|
||||||
|
|
||||||
|
IndentX = 0.0f;
|
||||||
|
ColumnsOffsetX = 0.0f;
|
||||||
|
ColumnsCurrent = 0;
|
||||||
|
ColumnsCount = 1;
|
||||||
|
ColumnsMinX = ColumnsMaxX = 0.0f;
|
||||||
|
ColumnsStartPosY = 0.0f;
|
||||||
|
ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
|
||||||
|
ColumnsShowBorders = true;
|
||||||
|
ColumnsSetID = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Windows data
|
||||||
|
struct IMGUI_API ImGuiWindow
|
||||||
|
{
|
||||||
|
char* Name;
|
||||||
|
ImGuiID ID;
|
||||||
|
ImGuiWindowFlags Flags;
|
||||||
|
ImVec2 PosFloat;
|
||||||
|
ImVec2 Pos; // Position rounded-up to nearest pixel
|
||||||
|
ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
|
||||||
|
ImVec2 SizeFull; // Size when non collapsed
|
||||||
|
ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame
|
||||||
|
ImVec2 SizeContentsExplicit; // Size of contents explicitly set by the user via SetNextWindowContentSize()
|
||||||
|
ImVec2 WindowPadding; // Window padding at the time of begin. We need to lock it, in particular manipulation of the ShowBorder would have an effect
|
||||||
|
ImGuiID MoveID; // == window->GetID("#MOVE")
|
||||||
|
ImVec2 Scroll;
|
||||||
|
ImVec2 ScrollTarget; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change)
|
||||||
|
ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered
|
||||||
|
bool ScrollbarX, ScrollbarY;
|
||||||
|
ImVec2 ScrollbarSizes; //
|
||||||
|
bool Active; // Set to true on Begin()
|
||||||
|
bool WasActive;
|
||||||
|
bool Accessed; // Set to true when any widget access the current window
|
||||||
|
bool Collapsed; // Set when collapsing window to become only title-bar
|
||||||
|
bool SkipItems; // == Visible && !Collapsed
|
||||||
|
int BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs)
|
||||||
|
ImGuiID PopupID; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling)
|
||||||
|
int AutoFitFramesX, AutoFitFramesY;
|
||||||
|
bool AutoFitOnlyGrows;
|
||||||
|
int AutoPosLastDirection;
|
||||||
|
int HiddenFrames;
|
||||||
|
int SetWindowPosAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowPos() call will succeed with this particular flag.
|
||||||
|
int SetWindowSizeAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowSize() call will succeed with this particular flag.
|
||||||
|
int SetWindowCollapsedAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call will succeed with this particular flag.
|
||||||
|
bool SetWindowPosCenterWanted;
|
||||||
|
|
||||||
|
ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame
|
||||||
|
ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack
|
||||||
|
ImRect ClipRect; // = DrawList->clip_rect_stack.back(). Scissoring / clipping rectangle. x1, y1, x2, y2.
|
||||||
|
ImRect ClippedWindowRect; // = ClipRect just after setup in Begin()
|
||||||
|
int LastFrameActive;
|
||||||
|
float ItemWidthDefault;
|
||||||
|
ImGuiSimpleColumns MenuColumns; // Simplified columns storage for menu items
|
||||||
|
ImGuiStorage StateStorage;
|
||||||
|
float FontWindowScale; // Scale multiplier per-window
|
||||||
|
ImDrawList* DrawList;
|
||||||
|
ImGuiWindow* RootWindow;
|
||||||
|
ImGuiWindow* RootNonPopupWindow;
|
||||||
|
|
||||||
|
// Focus
|
||||||
|
int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
|
||||||
|
int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
|
||||||
|
int FocusIdxAllRequestCurrent; // Item being requested for focus
|
||||||
|
int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
|
||||||
|
int FocusIdxAllRequestNext; // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame)
|
||||||
|
int FocusIdxTabRequestNext; // "
|
||||||
|
|
||||||
|
public:
|
||||||
|
ImGuiWindow(const char* name);
|
||||||
|
~ImGuiWindow();
|
||||||
|
|
||||||
|
ImGuiID GetID(const char* str, const char* str_end = NULL);
|
||||||
|
ImGuiID GetID(const void* ptr);
|
||||||
|
|
||||||
|
ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x+Size.x, Pos.y+Size.y); }
|
||||||
|
float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; }
|
||||||
|
float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; }
|
||||||
|
ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); }
|
||||||
|
float MenuBarHeight() const { return (Flags & ImGuiWindowFlags_MenuBar) ? CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; }
|
||||||
|
ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Internal API
|
||||||
|
// No guarantee of forward compatibility here.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace ImGui
|
||||||
|
{
|
||||||
|
// We should always have a CurrentWindow in the stack (there is an implicit "Debug" window)
|
||||||
|
// If this ever crash because g.CurrentWindow is NULL it means that either
|
||||||
|
// - ImGui::NewFrame() has never been called, which is illegal.
|
||||||
|
// - You are calling ImGui functions after ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal.
|
||||||
|
inline ImGuiWindow* GetCurrentWindowRead() { ImGuiState& g = *GImGui; return g.CurrentWindow; }
|
||||||
|
inline ImGuiWindow* GetCurrentWindow() { ImGuiState& g = *GImGui; g.CurrentWindow->Accessed = true; return g.CurrentWindow; }
|
||||||
|
IMGUI_API ImGuiWindow* GetParentWindow();
|
||||||
|
IMGUI_API void FocusWindow(ImGuiWindow* window);
|
||||||
|
|
||||||
|
IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window);
|
||||||
|
IMGUI_API void SetHoveredID(ImGuiID id);
|
||||||
|
IMGUI_API void KeepAliveID(ImGuiID id);
|
||||||
|
|
||||||
|
IMGUI_API void EndFrame(); // Automatically called by Render()
|
||||||
|
|
||||||
|
IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f);
|
||||||
|
IMGUI_API void ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
|
||||||
|
IMGUI_API bool ItemAdd(const ImRect& bb, const ImGuiID* id);
|
||||||
|
IMGUI_API bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged);
|
||||||
|
IMGUI_API bool IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs = false);
|
||||||
|
IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, bool is_active, bool tab_stop = true); // Return true if focus is requested
|
||||||
|
IMGUI_API void FocusableItemUnregister(ImGuiWindow* window);
|
||||||
|
IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_x, float default_y);
|
||||||
|
IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
|
||||||
|
IMGUI_API void SetItemAllowOverlap(); // Allow last item to be overlapped by a subsequent item
|
||||||
|
|
||||||
|
IMGUI_API void OpenPopupEx(const char* str_id, bool reopen_existing);
|
||||||
|
|
||||||
|
inline IMGUI_API ImU32 GetColorU32(ImGuiCol idx, float alpha_mul) { ImVec4 c = GImGui->Style.Colors[idx]; c.w *= GImGui->Style.Alpha * alpha_mul; return ImGui::ColorConvertFloat4ToU32(c); }
|
||||||
|
inline IMGUI_API ImU32 GetColorU32(const ImVec4& col) { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); }
|
||||||
|
|
||||||
|
// NB: All position are in absolute pixels coordinates (not window coordinates)
|
||||||
|
// FIXME: Refactor all RenderText* functions into one.
|
||||||
|
IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
|
||||||
|
IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
|
||||||
|
IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align = ImGuiAlign_Default, const ImVec2* clip_min = NULL, const ImVec2* clip_max = NULL);
|
||||||
|
IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
|
||||||
|
IMGUI_API void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
|
||||||
|
IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col);
|
||||||
|
|
||||||
|
IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_existing_clip_rect = true);
|
||||||
|
IMGUI_API void PopClipRect();
|
||||||
|
|
||||||
|
IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0);
|
||||||
|
IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0);
|
||||||
|
|
||||||
|
IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags = 0);
|
||||||
|
IMGUI_API bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power);
|
||||||
|
IMGUI_API bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format);
|
||||||
|
|
||||||
|
IMGUI_API bool DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power);
|
||||||
|
IMGUI_API bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power);
|
||||||
|
IMGUI_API bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format);
|
||||||
|
|
||||||
|
IMGUI_API bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
|
||||||
|
IMGUI_API bool InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags);
|
||||||
|
IMGUI_API bool InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags);
|
||||||
|
IMGUI_API bool InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags);
|
||||||
|
IMGUI_API bool InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision);
|
||||||
|
|
||||||
|
IMGUI_API bool TreeNodeBehaviorIsOpened(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging
|
||||||
|
|
||||||
|
IMGUI_API void PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size);
|
||||||
|
|
||||||
|
IMGUI_API int ParseFormatPrecision(const char* fmt, int default_value);
|
||||||
|
IMGUI_API float RoundScalar(float value, int decimal_precision);
|
||||||
|
|
||||||
|
} // namespace ImGuiP
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (pop)
|
||||||
|
#endif
|
@ -1,4 +1,4 @@
|
|||||||
// stb_rect_pack.h - v0.05 - public domain - rectangle packing
|
// stb_rect_pack.h - v0.08 - public domain - rectangle packing
|
||||||
// Sean Barrett 2014
|
// Sean Barrett 2014
|
||||||
//
|
//
|
||||||
// Useful for e.g. packing rectangular textures into an atlas.
|
// Useful for e.g. packing rectangular textures into an atlas.
|
||||||
@ -13,6 +13,7 @@
|
|||||||
// More docs to come.
|
// More docs to come.
|
||||||
//
|
//
|
||||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||||
|
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||||
//
|
//
|
||||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||||
//
|
//
|
||||||
@ -20,11 +21,29 @@
|
|||||||
// implement them to the same API, but with a different init
|
// implement them to the same API, but with a different init
|
||||||
// function.
|
// function.
|
||||||
//
|
//
|
||||||
|
// Credits
|
||||||
|
//
|
||||||
|
// Library
|
||||||
|
// Sean Barrett
|
||||||
|
// Minor features
|
||||||
|
// Martins Mozeiko
|
||||||
|
// Bugfixes / warning fixes
|
||||||
|
// Jeremy Jaussaud
|
||||||
|
//
|
||||||
// Version history:
|
// Version history:
|
||||||
//
|
//
|
||||||
|
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||||
|
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||||
|
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||||
// 0.01: initial release
|
// 0.01: initial release
|
||||||
|
//
|
||||||
|
// LICENSE
|
||||||
|
//
|
||||||
|
// This software is in the public domain. Where that dedication is not
|
||||||
|
// recognized, you are granted a perpetual, irrevocable license to copy,
|
||||||
|
// distribute, and modify this file as you see fit.
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@ -169,7 +188,10 @@ struct stbrp_context
|
|||||||
//
|
//
|
||||||
|
|
||||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
#ifndef STBRP_SORT
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#define STBRP_SORT qsort
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef STBRP_ASSERT
|
#ifndef STBRP_ASSERT
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -525,20 +547,24 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sort according to heuristic
|
// sort according to heuristic
|
||||||
qsort(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||||
|
|
||||||
for (i=0; i < num_rects; ++i) {
|
for (i=0; i < num_rects; ++i) {
|
||||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||||
if (fr.prev_link) {
|
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||||
rects[i].x = (stbrp_coord) fr.x;
|
|
||||||
rects[i].y = (stbrp_coord) fr.y;
|
|
||||||
} else {
|
} else {
|
||||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
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
|
// unsort
|
||||||
qsort(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||||
|
|
||||||
// set was_packed flags
|
// set was_packed flags
|
||||||
for (i=0; i < num_rects; ++i)
|
for (i=0; i < num_rects; ++i)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// [ImGui] this is a slightly modified version of stb_truetype.h 1.4
|
// [ImGui] this is a slightly modified version of stb_truetype.h 1.4
|
||||||
// [ImGui] we made a fix for using the END key on multi-line text edit, see https://github.com/ocornut/imgui/issues/275
|
// [ImGui] we made a fix for using the END key on multi-line text edit, see https://github.com/ocornut/imgui/issues/275
|
||||||
|
// [ImGui] we made a fix for using keyboard while using mouse, see https://github.com/nothings/stb/pull/209
|
||||||
|
|
||||||
// stb_textedit.h - v1.4 - public domain - Sean Barrett
|
// stb_textedit.h - v1.4 - public domain - Sean Barrett
|
||||||
// Development of this library was sponsored by RAD Game Tools
|
// Development of this library was sponsored by RAD Game Tools
|
||||||
@ -437,6 +438,8 @@ static void stb_textedit_click(STB_TEXTEDIT_STRING *str, STB_TexteditState *stat
|
|||||||
static void stb_textedit_drag(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, float x, float y)
|
static void stb_textedit_drag(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, float x, float y)
|
||||||
{
|
{
|
||||||
int p = stb_text_locate_coord(str, x, y);
|
int p = stb_text_locate_coord(str, x, y);
|
||||||
|
if (state->select_start == state->select_end)
|
||||||
|
state->select_start = state->cursor;
|
||||||
state->cursor = state->select_end = p;
|
state->cursor = state->select_end = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
351
stb_truetype.h
351
stb_truetype.h
@ -1,8 +1,5 @@
|
|||||||
// [ImGui] this is a slightly modified version of stb_truetype.h 1.06
|
// stb_truetype.h - v1.08 - public domain
|
||||||
// [ImGui] we added stbtt_PackFontRangesGatherRects() and stbtt_PackFontRangesRenderIntoRects() and modified stbtt_PackBegin()
|
// authored from 2009-2015 by Sean Barrett / RAD Game Tools
|
||||||
|
|
||||||
// stb_truetype.h - v1.06 - public domain
|
|
||||||
// authored from 2009-2014 by Sean Barrett / RAD Game Tools
|
|
||||||
//
|
//
|
||||||
// This library processes TrueType files:
|
// This library processes TrueType files:
|
||||||
// parse files
|
// parse files
|
||||||
@ -42,52 +39,35 @@
|
|||||||
// Omar Cornut
|
// Omar Cornut
|
||||||
// github:aloucks
|
// github:aloucks
|
||||||
// Peter LaValle
|
// Peter LaValle
|
||||||
|
// Sergey Popov
|
||||||
|
// Giumo X. Clanjor
|
||||||
|
// Higor Euripedes
|
||||||
//
|
//
|
||||||
// Misc other:
|
// Misc other:
|
||||||
// Ryan Gordon
|
// Ryan Gordon
|
||||||
//
|
//
|
||||||
// VERSION HISTORY
|
// VERSION HISTORY
|
||||||
//
|
//
|
||||||
|
// 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges
|
||||||
|
// 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints;
|
||||||
|
// variant PackFontRanges to pack and render in separate phases;
|
||||||
|
// fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?);
|
||||||
|
// fixed an assert() bug in the new rasterizer
|
||||||
|
// replace assert() with STBTT_assert() in new rasterizer
|
||||||
// 1.06 (2015-07-14) performance improvements (~35% faster on x86 and x64 on test machine)
|
// 1.06 (2015-07-14) performance improvements (~35% faster on x86 and x64 on test machine)
|
||||||
// also more precise AA rasterizer, except if shapes overlap
|
// also more precise AA rasterizer, except if shapes overlap
|
||||||
// remove need for STBTT_sort
|
// remove need for STBTT_sort
|
||||||
// 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC
|
// 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC
|
||||||
// 1.04 (2015-04-15) typo in example
|
// 1.04 (2015-04-15) typo in example
|
||||||
// 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes
|
// 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes
|
||||||
// 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++
|
//
|
||||||
// 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match
|
// Full history can be found at the end of this file.
|
||||||
// non-oversampled; STBTT_POINT_SIZE for packed case only
|
|
||||||
// 1.00 (2014-12-06) add new PackBegin etc. API, w/ support for oversampling
|
|
||||||
// 0.99 (2014-09-18) fix multiple bugs with subpixel rendering (ryg)
|
|
||||||
// 0.9 (2014-08-07) support certain mac/iOS fonts without an MS platformID
|
|
||||||
// 0.8b (2014-07-07) fix a warning
|
|
||||||
// 0.8 (2014-05-25) fix a few more warnings
|
|
||||||
// 0.7 (2013-09-25) bugfix: subpixel glyph bug fixed in 0.5 had come back
|
|
||||||
// 0.6c (2012-07-24) improve documentation
|
|
||||||
// 0.6b (2012-07-20) fix a few more warnings
|
|
||||||
// 0.6 (2012-07-17) fix warnings; added stbtt_ScaleForMappingEmToPixels,
|
|
||||||
// stbtt_GetFontBoundingBox, stbtt_IsGlyphEmpty
|
|
||||||
// 0.5 (2011-12-09) bugfixes:
|
|
||||||
// subpixel glyph renderer computed wrong bounding box
|
|
||||||
// first vertex of shape can be off-curve (FreeSans)
|
|
||||||
// 0.4b (2011-12-03) fixed an error in the font baking example
|
|
||||||
// 0.4 (2011-12-01) kerning, subpixel rendering (tor)
|
|
||||||
// bugfixes for:
|
|
||||||
// codepoint-to-glyph conversion using table fmt=12
|
|
||||||
// codepoint-to-glyph conversion using table fmt=4
|
|
||||||
// stbtt_GetBakedQuad with non-square texture (Zer)
|
|
||||||
// updated Hello World! sample to use kerning and subpixel
|
|
||||||
// fixed some warnings
|
|
||||||
// 0.3 (2009-06-24) cmap fmt=12, compound shapes (MM)
|
|
||||||
// userdata, malloc-from-userdata, non-zero fill (stb)
|
|
||||||
// 0.2 (2009-03-11) Fix unsigned/signed char warnings
|
|
||||||
// 0.1 (2009-03-09) First public release
|
|
||||||
//
|
//
|
||||||
// LICENSE
|
// LICENSE
|
||||||
//
|
//
|
||||||
// This software is in the public domain. Where that dedication is not
|
// This software is in the public domain. Where that dedication is not
|
||||||
// recognized, you are granted a perpetual, irrevokable license to copy
|
// recognized, you are granted a perpetual, irrevocable license to copy,
|
||||||
// and modify this file as you see fit.
|
// distribute, and modify this file as you see fit.
|
||||||
//
|
//
|
||||||
// USAGE
|
// USAGE
|
||||||
//
|
//
|
||||||
@ -538,7 +518,7 @@ STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, i
|
|||||||
// Future calls using this context will pack characters into the bitmap passed
|
// Future calls using this context will pack characters into the bitmap passed
|
||||||
// in here: a 1-channel bitmap that is weight x height. stride_in_bytes is
|
// in here: a 1-channel bitmap that is weight x height. stride_in_bytes is
|
||||||
// the distance from one row to the next (or 0 to mean they are packed tightly
|
// the distance from one row to the next (or 0 to mean they are packed tightly
|
||||||
// together). "padding" is // the amount of padding to leave between each
|
// together). "padding" is the amount of padding to leave between each
|
||||||
// character (normally you want '1' for bitmaps you'll use as textures with
|
// character (normally you want '1' for bitmaps you'll use as textures with
|
||||||
// bilinear filtering).
|
// bilinear filtering).
|
||||||
//
|
//
|
||||||
@ -567,34 +547,34 @@ STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontd
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float font_size;
|
float font_size;
|
||||||
int first_unicode_char_in_range;
|
int first_unicode_codepoint_in_range; // if non-zero, then the chars are continuous, and this is the first codepoint
|
||||||
int num_chars_in_range;
|
int *array_of_unicode_codepoints; // if non-zero, then this is an array of unicode codepoints
|
||||||
|
int num_chars;
|
||||||
stbtt_packedchar *chardata_for_range; // output
|
stbtt_packedchar *chardata_for_range; // output
|
||||||
|
unsigned char h_oversample, v_oversample; // don't set these, they're used internally
|
||||||
} stbtt_pack_range;
|
} stbtt_pack_range;
|
||||||
|
|
||||||
STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);
|
STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);
|
||||||
// Creates character bitmaps from multiple ranges of characters stored in
|
// Creates character bitmaps from multiple ranges of characters stored in
|
||||||
// ranges. This will usually create a better-packed bitmap than multiple
|
// ranges. This will usually create a better-packed bitmap than multiple
|
||||||
// calls to stbtt_PackFontRange.
|
// calls to stbtt_PackFontRange. Note that you can call this multiple
|
||||||
|
// times within a single PackBegin/PackEnd.
|
||||||
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
|
||||||
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
|
||||||
// Those functions are called by stbtt_PackFontRanges(). If you want to
|
|
||||||
// pack multiple fonts or custom data into a same texture, you may copy
|
|
||||||
// the contents of stbtt_PackFontRanges() and create a custom version
|
|
||||||
// using those functions.
|
|
||||||
|
|
||||||
STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);
|
STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);
|
||||||
// Oversampling a font increases the quality by allowing higher-quality subpixel
|
// Oversampling a font increases the quality by allowing higher-quality subpixel
|
||||||
// positioning, and is especially valuable at smaller text sizes.
|
// positioning, and is especially valuable at smaller text sizes.
|
||||||
//
|
//
|
||||||
// This function sets the amount of oversampling for all following calls to
|
// This function sets the amount of oversampling for all following calls to
|
||||||
// stbtt_PackFontRange(s). The default (no oversampling) is achieved by
|
// stbtt_PackFontRange(s) or stbtt_PackFontRangesGatherRects for a given
|
||||||
// h_oversample=1, v_oversample=1. The total number of pixels required is
|
// pack context. The default (no oversampling) is achieved by h_oversample=1
|
||||||
|
// and v_oversample=1. The total number of pixels required is
|
||||||
// h_oversample*v_oversample larger than the default; for example, 2x2
|
// h_oversample*v_oversample larger than the default; for example, 2x2
|
||||||
// oversampling requires 4x the storage of 1x1. For best results, render
|
// oversampling requires 4x the storage of 1x1. For best results, render
|
||||||
// oversampled textures with bilinear filtering. Look at the readme in
|
// oversampled textures with bilinear filtering. Look at the readme in
|
||||||
// stb/tests/oversample for information about oversampled fonts
|
// stb/tests/oversample for information about oversampled fonts
|
||||||
|
//
|
||||||
|
// To use with PackFontRangesGather etc., you must set it before calls
|
||||||
|
// call to PackFontRangesGatherRects.
|
||||||
|
|
||||||
STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above
|
STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above
|
||||||
int char_index, // character to display
|
int char_index, // character to display
|
||||||
@ -602,6 +582,19 @@ STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph,
|
|||||||
stbtt_aligned_quad *q, // output: quad to draw
|
stbtt_aligned_quad *q, // output: quad to draw
|
||||||
int align_to_integer);
|
int align_to_integer);
|
||||||
|
|
||||||
|
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||||
|
STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects);
|
||||||
|
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||||
|
// Calling these functions in sequence is roughly equivalent to calling
|
||||||
|
// stbtt_PackFontRanges(). If you more control over the packing of multiple
|
||||||
|
// fonts, or if you want to pack custom data into a font texture, take a look
|
||||||
|
// at the source to of stbtt_PackFontRanges() and create a custom version
|
||||||
|
// using these functions, e.g. call GatherRects multiple times,
|
||||||
|
// building up a single array of rects, then call PackRects once,
|
||||||
|
// then call RenderIntoRects repeatedly. This may result in a
|
||||||
|
// better packing than calling PackFontRanges multiple times
|
||||||
|
// (or it may not).
|
||||||
|
|
||||||
// this is an opaque structure that you shouldn't mess with which holds
|
// this is an opaque structure that you shouldn't mess with which holds
|
||||||
// all the context needed from PackBegin to PackEnd.
|
// all the context needed from PackBegin to PackEnd.
|
||||||
struct stbtt_pack_context {
|
struct stbtt_pack_context {
|
||||||
@ -812,7 +805,16 @@ typedef struct
|
|||||||
unsigned char *pixels;
|
unsigned char *pixels;
|
||||||
} stbtt__bitmap;
|
} stbtt__bitmap;
|
||||||
|
|
||||||
STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata);
|
// rasterize a shape with quadratic beziers into a bitmap
|
||||||
|
STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, // 1-channel bitmap to draw into
|
||||||
|
float flatness_in_pixels, // allowable error of curve in pixels
|
||||||
|
stbtt_vertex *vertices, // array of vertices defining shape
|
||||||
|
int num_verts, // number of vertices in above array
|
||||||
|
float scale_x, float scale_y, // scale applied to input vertices
|
||||||
|
float shift_x, float shift_y, // translation applied to input vertices
|
||||||
|
int x_off, int y_off, // another translation applied to input
|
||||||
|
int invert, // if non-zero, vertically flip shape
|
||||||
|
void *userdata); // context for to STBTT_MALLOC
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@ -927,6 +929,10 @@ enum { // languageID for STBTT_PLATFORM_ID_MAC
|
|||||||
#define STBTT_MAX_OVERSAMPLE 8
|
#define STBTT_MAX_OVERSAMPLE 8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if STBTT_MAX_OVERSAMPLE > 255
|
||||||
|
#error "STBTT_MAX_OVERSAMPLE cannot be > 255"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1];
|
typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1];
|
||||||
|
|
||||||
#ifndef STBTT_RASTERIZER_VERSION
|
#ifndef STBTT_RASTERIZER_VERSION
|
||||||
@ -1001,7 +1007,7 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection,
|
|||||||
stbtt_int32 n = ttLONG(font_collection+8);
|
stbtt_int32 n = ttLONG(font_collection+8);
|
||||||
if (index >= n)
|
if (index >= n)
|
||||||
return -1;
|
return -1;
|
||||||
return ttULONG(font_collection+12+index*14);
|
return ttULONG(font_collection+12+index*4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@ -1690,7 +1696,7 @@ static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, i
|
|||||||
//STBTT_assert(e->y0 <= start_point);
|
//STBTT_assert(e->y0 <= start_point);
|
||||||
if (!z) return z;
|
if (!z) return z;
|
||||||
z->fdx = dxdy;
|
z->fdx = dxdy;
|
||||||
z->fdy = (1/dxdy);
|
z->fdy = dxdy != 0.0f ? (1.0f/dxdy) : 0.0f;
|
||||||
z->fx = e->x0 + dxdy * (start_point - e->y0);
|
z->fx = e->x0 + dxdy * (start_point - e->y0);
|
||||||
z->fx -= off_x;
|
z->fx -= off_x;
|
||||||
z->direction = e->invert ? 1.0f : -1.0f;
|
z->direction = e->invert ? 1.0f : -1.0f;
|
||||||
@ -1751,7 +1757,7 @@ static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__ac
|
|||||||
|
|
||||||
static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata)
|
static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata)
|
||||||
{
|
{
|
||||||
stbtt__hheap hh = { 0 };
|
stbtt__hheap hh = { 0, 0, 0 };
|
||||||
stbtt__active_edge *active = NULL;
|
stbtt__active_edge *active = NULL;
|
||||||
int y,j=0;
|
int y,j=0;
|
||||||
int max_weight = (255 / vsubsample); // weight per vertical scanline
|
int max_weight = (255 / vsubsample); // weight per vertical scanline
|
||||||
@ -1854,8 +1860,8 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
|
|||||||
static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edge *e, float x0, float y0, float x1, float y1)
|
static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edge *e, float x0, float y0, float x1, float y1)
|
||||||
{
|
{
|
||||||
if (y0 == y1) return;
|
if (y0 == y1) return;
|
||||||
assert(y0 < y1);
|
STBTT_assert(y0 < y1);
|
||||||
assert(e->sy <= e->ey);
|
STBTT_assert(e->sy <= e->ey);
|
||||||
if (y0 > e->ey) return;
|
if (y0 > e->ey) return;
|
||||||
if (y1 < e->sy) return;
|
if (y1 < e->sy) return;
|
||||||
if (y0 < e->sy) {
|
if (y0 < e->sy) {
|
||||||
@ -1868,22 +1874,22 @@ static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edg
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (x0 == x)
|
if (x0 == x)
|
||||||
assert(x1 <= x+1);
|
STBTT_assert(x1 <= x+1);
|
||||||
else if (x0 == x+1)
|
else if (x0 == x+1)
|
||||||
assert(x1 >= x);
|
STBTT_assert(x1 >= x);
|
||||||
else if (x0 <= x)
|
else if (x0 <= x)
|
||||||
assert(x1 <= x);
|
STBTT_assert(x1 <= x);
|
||||||
else if (x0 >= x+1)
|
else if (x0 >= x+1)
|
||||||
assert(x1 >= x+1);
|
STBTT_assert(x1 >= x+1);
|
||||||
else
|
else
|
||||||
assert(x1 >= x && x1 <= x+1);
|
STBTT_assert(x1 >= x && x1 <= x+1);
|
||||||
|
|
||||||
if (x0 <= x && x1 <= x)
|
if (x0 <= x && x1 <= x)
|
||||||
scanline[x] += e->direction * (y1-y0);
|
scanline[x] += e->direction * (y1-y0);
|
||||||
else if (x0 >= x+1 && x1 >= x+1)
|
else if (x0 >= x+1 && x1 >= x+1)
|
||||||
;
|
;
|
||||||
else {
|
else {
|
||||||
assert(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1);
|
STBTT_assert(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1);
|
||||||
scanline[x] += e->direction * (y1-y0) * (1-((x0-x)+(x1-x))/2); // coverage = 1 - average x position
|
scanline[x] += e->direction * (y1-y0) * (1-((x0-x)+(x1-x))/2); // coverage = 1 - average x position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1896,7 +1902,7 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||||||
// brute force every pixel
|
// brute force every pixel
|
||||||
|
|
||||||
// compute intersection points with top & bottom
|
// compute intersection points with top & bottom
|
||||||
assert(e->ey >= y_top);
|
STBTT_assert(e->ey >= y_top);
|
||||||
|
|
||||||
if (e->fdx == 0) {
|
if (e->fdx == 0) {
|
||||||
float x0 = e->fx;
|
float x0 = e->fx;
|
||||||
@ -1913,26 +1919,26 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||||||
float dx = e->fdx;
|
float dx = e->fdx;
|
||||||
float xb = x0 + dx;
|
float xb = x0 + dx;
|
||||||
float x_top, x_bottom;
|
float x_top, x_bottom;
|
||||||
float y0,y1;
|
float sy0,sy1;
|
||||||
float dy = e->fdy;
|
float dy = e->fdy;
|
||||||
assert(e->sy <= y_bottom && e->ey >= y_top);
|
STBTT_assert(e->sy <= y_bottom && e->ey >= y_top);
|
||||||
|
|
||||||
// compute endpoints of line segment clipped to this scanline (if the
|
// compute endpoints of line segment clipped to this scanline (if the
|
||||||
// line segment starts on this scanline. x0 is the intersection of the
|
// line segment starts on this scanline. x0 is the intersection of the
|
||||||
// line with y_top, but that may be off the line segment.
|
// line with y_top, but that may be off the line segment.
|
||||||
if (e->sy > y_top) {
|
if (e->sy > y_top) {
|
||||||
x_top = x0 + dx * (e->sy - y_top);
|
x_top = x0 + dx * (e->sy - y_top);
|
||||||
y0 = e->sy;
|
sy0 = e->sy;
|
||||||
} else {
|
} else {
|
||||||
x_top = x0;
|
x_top = x0;
|
||||||
y0 = y_top;
|
sy0 = y_top;
|
||||||
}
|
}
|
||||||
if (e->ey < y_bottom) {
|
if (e->ey < y_bottom) {
|
||||||
x_bottom = x0 + dx * (e->ey - y_top);
|
x_bottom = x0 + dx * (e->ey - y_top);
|
||||||
y1 = e->ey;
|
sy1 = e->ey;
|
||||||
} else {
|
} else {
|
||||||
x_bottom = xb;
|
x_bottom = xb;
|
||||||
y1 = y_bottom;
|
sy1 = y_bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len) {
|
if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len) {
|
||||||
@ -1942,8 +1948,8 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||||||
float height;
|
float height;
|
||||||
// simple case, only spans one pixel
|
// simple case, only spans one pixel
|
||||||
int x = (int) x_top;
|
int x = (int) x_top;
|
||||||
height = y1 - y0;
|
height = sy1 - sy0;
|
||||||
assert(x >= 0 && x < len);
|
STBTT_assert(x >= 0 && x < len);
|
||||||
scanline[x] += e->direction * (1-((x_top - x) + (x_bottom-x))/2) * height;
|
scanline[x] += e->direction * (1-((x_top - x) + (x_bottom-x))/2) * height;
|
||||||
scanline_fill[x] += e->direction * height; // everything right of this pixel is filled
|
scanline_fill[x] += e->direction * height; // everything right of this pixel is filled
|
||||||
} else {
|
} else {
|
||||||
@ -1953,9 +1959,9 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||||||
if (x_top > x_bottom) {
|
if (x_top > x_bottom) {
|
||||||
// flip scanline vertically; signed area is the same
|
// flip scanline vertically; signed area is the same
|
||||||
float t;
|
float t;
|
||||||
y0 = y_bottom - (y0 - y_top);
|
sy0 = y_bottom - (sy0 - y_top);
|
||||||
y1 = y_bottom - (y1 - y_top);
|
sy1 = y_bottom - (sy1 - y_top);
|
||||||
t = y0, y0 = y1, y1 = t;
|
t = sy0, sy0 = sy1, sy1 = t;
|
||||||
t = x_bottom, x_bottom = x_top, x_top = t;
|
t = x_bottom, x_bottom = x_top, x_top = t;
|
||||||
dx = -dx;
|
dx = -dx;
|
||||||
dy = -dy;
|
dy = -dy;
|
||||||
@ -1969,7 +1975,7 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||||||
|
|
||||||
sign = e->direction;
|
sign = e->direction;
|
||||||
// area of the rectangle covered from y0..y_crossing
|
// area of the rectangle covered from y0..y_crossing
|
||||||
area = sign * (y_crossing-y0);
|
area = sign * (y_crossing-sy0);
|
||||||
// area of the triangle (x_top,y0), (x+1,y0), (x+1,y_crossing)
|
// area of the triangle (x_top,y0), (x+1,y0), (x+1,y_crossing)
|
||||||
scanline[x1] += area * (1-((x_top - x1)+(x1+1-x1))/2);
|
scanline[x1] += area * (1-((x_top - x1)+(x1+1-x1))/2);
|
||||||
|
|
||||||
@ -1980,11 +1986,11 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||||||
}
|
}
|
||||||
y_crossing += dy * (x2 - (x1+1));
|
y_crossing += dy * (x2 - (x1+1));
|
||||||
|
|
||||||
assert(fabs(area) <= 1.01f);
|
STBTT_assert(fabs(area) <= 1.01f);
|
||||||
|
|
||||||
scanline[x2] += area + sign * (1-((x2-x2)+(x_bottom-x2))/2) * (y1-y_crossing);
|
scanline[x2] += area + sign * (1-((x2-x2)+(x_bottom-x2))/2) * (sy1-y_crossing);
|
||||||
|
|
||||||
scanline_fill[x2] += sign * (y1-y0);
|
scanline_fill[x2] += sign * (sy1-sy0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if edge goes outside of box we're drawing, we require
|
// if edge goes outside of box we're drawing, we require
|
||||||
@ -1998,38 +2004,51 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||||||
// there can be up to two intersections with the pixel. any intersection
|
// there can be up to two intersections with the pixel. any intersection
|
||||||
// with left or right edges can be handled by splitting into two (or three)
|
// with left or right edges can be handled by splitting into two (or three)
|
||||||
// regions. intersections with top & bottom do not necessitate case-wise logic.
|
// regions. intersections with top & bottom do not necessitate case-wise logic.
|
||||||
float y0,y1;
|
//
|
||||||
float y_cur = y_top, x_cur = x0;
|
// the old way of doing this found the intersections with the left & right edges,
|
||||||
|
// then used some simple logic to produce up to three segments in sorted order
|
||||||
|
// from top-to-bottom. however, this had a problem: if an x edge was epsilon
|
||||||
|
// across the x border, then the corresponding y position might not be distinct
|
||||||
|
// from the other y segment, and it might ignored as an empty segment. to avoid
|
||||||
|
// that, we need to explicitly produce segments based on x positions.
|
||||||
|
|
||||||
|
// rename variables to clear pairs
|
||||||
|
float y0 = y_top;
|
||||||
|
float x1 = (float) (x);
|
||||||
|
float x2 = (float) (x+1);
|
||||||
|
float x3 = xb;
|
||||||
|
float y3 = y_bottom;
|
||||||
|
float y1,y2;
|
||||||
|
|
||||||
// x = e->x + e->dx * (y-y_top)
|
// x = e->x + e->dx * (y-y_top)
|
||||||
// (y-y_top) = (x - e->x) / e->dx
|
// (y-y_top) = (x - e->x) / e->dx
|
||||||
// y = (x - e->x) / e->dx + y_top
|
// y = (x - e->x) / e->dx + y_top
|
||||||
y0 = (x - x0) / dx + y_top;
|
y1 = (x - x0) / dx + y_top;
|
||||||
y1 = (x+1 - x0) / dx + y_top;
|
y2 = (x+1 - x0) / dx + y_top;
|
||||||
|
|
||||||
if (y0 < y1) {
|
if (x0 < x1 && x3 > x2) { // three segments descending down-right
|
||||||
if (y0 > y_top && y0 < y_bottom) {
|
stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1);
|
||||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x,y0);
|
stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x2,y2);
|
||||||
y_cur = y0;
|
stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3);
|
||||||
x_cur = (float) x;
|
} else if (x3 < x1 && x0 > x2) { // three segments descending down-left
|
||||||
}
|
stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2);
|
||||||
if (y1 >= y_cur && y1 < y_bottom) {
|
stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x1,y1);
|
||||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x+1,y1);
|
stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3);
|
||||||
y_cur = y1;
|
} else if (x0 < x1 && x3 > x1) { // two segments across x, down-right
|
||||||
x_cur = (float) x+1;
|
stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1);
|
||||||
}
|
stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3);
|
||||||
} else {
|
} else if (x3 < x1 && x0 > x1) { // two segments across x, down-left
|
||||||
if (y1 >= y_cur && y1 < y_bottom) {
|
stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1);
|
||||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x+1,y1);
|
stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3);
|
||||||
y_cur = y1;
|
} else if (x0 < x2 && x3 > x2) { // two segments across x+1, down-right
|
||||||
x_cur = (float) x+1;
|
stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2);
|
||||||
}
|
stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3);
|
||||||
if (y0 > y_top && y0 < y_bottom) {
|
} else if (x3 < x2 && x0 > x2) { // two segments across x+1, down-left
|
||||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x,y0);
|
stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2);
|
||||||
y_cur = y0;
|
stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3);
|
||||||
x_cur = (float) x;
|
} else { // one segment
|
||||||
}
|
stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x3,y3);
|
||||||
}
|
}
|
||||||
stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, xb,y_bottom);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2040,8 +2059,8 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||||||
// directly AA rasterize edges w/o supersampling
|
// directly AA rasterize edges w/o supersampling
|
||||||
static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata)
|
static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata)
|
||||||
{
|
{
|
||||||
(void)vsubsample;
|
(void)vsubsample;
|
||||||
stbtt__hheap hh = { 0 };
|
stbtt__hheap hh = { 0, 0, 0 };
|
||||||
stbtt__active_edge *active = NULL;
|
stbtt__active_edge *active = NULL;
|
||||||
int y,j=0, i;
|
int y,j=0, i;
|
||||||
float scanline_data[129], *scanline, *scanline2;
|
float scanline_data[129], *scanline, *scanline2;
|
||||||
@ -2081,11 +2100,13 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e,
|
|||||||
|
|
||||||
// insert all edges that start before the bottom of this scanline
|
// insert all edges that start before the bottom of this scanline
|
||||||
while (e->y0 <= scan_y_bottom) {
|
while (e->y0 <= scan_y_bottom) {
|
||||||
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
|
if (e->y0 != e->y1) {
|
||||||
assert(z->ey >= scan_y_top);
|
stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
|
||||||
// insert at front
|
STBTT_assert(z->ey >= scan_y_top);
|
||||||
z->next = active;
|
// insert at front
|
||||||
active = z;
|
z->next = active;
|
||||||
|
active = z;
|
||||||
|
}
|
||||||
++e;
|
++e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2716,6 +2737,13 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i
|
|||||||
pixels[i] = (unsigned char) (total / 4);
|
pixels[i] = (unsigned char) (total / 4);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 5:
|
||||||
|
for (i=0; i <= safe_w; ++i) {
|
||||||
|
total += pixels[i] - buffer[i & STBTT__OVER_MASK];
|
||||||
|
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i];
|
||||||
|
pixels[i] = (unsigned char) (total / 5);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
for (i=0; i <= safe_w; ++i) {
|
for (i=0; i <= safe_w; ++i) {
|
||||||
total += pixels[i] - buffer[i & STBTT__OVER_MASK];
|
total += pixels[i] - buffer[i & STBTT__OVER_MASK];
|
||||||
@ -2770,6 +2798,13 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i
|
|||||||
pixels[i*stride_in_bytes] = (unsigned char) (total / 4);
|
pixels[i*stride_in_bytes] = (unsigned char) (total / 4);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 5:
|
||||||
|
for (i=0; i <= safe_h; ++i) {
|
||||||
|
total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK];
|
||||||
|
buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes];
|
||||||
|
pixels[i*stride_in_bytes] = (unsigned char) (total / 5);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
for (i=0; i <= safe_h; ++i) {
|
for (i=0; i <= safe_h; ++i) {
|
||||||
total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK];
|
total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK];
|
||||||
@ -2810,9 +2845,12 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fon
|
|||||||
for (i=0; i < num_ranges; ++i) {
|
for (i=0; i < num_ranges; ++i) {
|
||||||
float fh = ranges[i].font_size;
|
float fh = ranges[i].font_size;
|
||||||
float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh);
|
float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh);
|
||||||
for (j=0; j < ranges[i].num_chars_in_range; ++j) {
|
ranges[i].h_oversample = (unsigned char) spc->h_oversample;
|
||||||
|
ranges[i].v_oversample = (unsigned char) spc->v_oversample;
|
||||||
|
for (j=0; j < ranges[i].num_chars; ++j) {
|
||||||
int x0,y0,x1,y1;
|
int x0,y0,x1,y1;
|
||||||
int glyph = stbtt_FindGlyphIndex(info,ranges[i].first_unicode_char_in_range + j);
|
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
||||||
|
int glyph = stbtt_FindGlyphIndex(info, codepoint);
|
||||||
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
|
stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
|
||||||
scale * spc->h_oversample,
|
scale * spc->h_oversample,
|
||||||
scale * spc->v_oversample,
|
scale * spc->v_oversample,
|
||||||
@ -2830,22 +2868,30 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fon
|
|||||||
// rects array must be big enough to accommodate all characters in the given ranges
|
// rects array must be big enough to accommodate all characters in the given ranges
|
||||||
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
||||||
{
|
{
|
||||||
float recip_h = 1.0f / spc->h_oversample;
|
|
||||||
float recip_v = 1.0f / spc->v_oversample;
|
|
||||||
float sub_x = stbtt__oversample_shift(spc->h_oversample);
|
|
||||||
float sub_y = stbtt__oversample_shift(spc->v_oversample);
|
|
||||||
int i,j,k, return_value = 1;
|
int i,j,k, return_value = 1;
|
||||||
|
|
||||||
|
// save current values
|
||||||
|
int old_h_over = spc->h_oversample;
|
||||||
|
int old_v_over = spc->v_oversample;
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
for (i=0; i < num_ranges; ++i) {
|
for (i=0; i < num_ranges; ++i) {
|
||||||
float fh = ranges[i].font_size;
|
float fh = ranges[i].font_size;
|
||||||
float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh);
|
float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh);
|
||||||
for (j=0; j < ranges[i].num_chars_in_range; ++j) {
|
float recip_h,recip_v,sub_x,sub_y;
|
||||||
|
spc->h_oversample = ranges[i].h_oversample;
|
||||||
|
spc->v_oversample = ranges[i].v_oversample;
|
||||||
|
recip_h = 1.0f / spc->h_oversample;
|
||||||
|
recip_v = 1.0f / spc->v_oversample;
|
||||||
|
sub_x = stbtt__oversample_shift(spc->h_oversample);
|
||||||
|
sub_y = stbtt__oversample_shift(spc->v_oversample);
|
||||||
|
for (j=0; j < ranges[i].num_chars; ++j) {
|
||||||
stbrp_rect *r = &rects[k];
|
stbrp_rect *r = &rects[k];
|
||||||
if (r->was_packed) {
|
if (r->was_packed) {
|
||||||
stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
|
stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
|
||||||
int advance, lsb, x0,y0,x1,y1;
|
int advance, lsb, x0,y0,x1,y1;
|
||||||
int glyph = stbtt_FindGlyphIndex(info, ranges[i].first_unicode_char_in_range + j);
|
int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
|
||||||
|
int glyph = stbtt_FindGlyphIndex(info, codepoint);
|
||||||
stbrp_coord pad = (stbrp_coord) spc->padding;
|
stbrp_coord pad = (stbrp_coord) spc->padding;
|
||||||
|
|
||||||
// pad on left and top
|
// pad on left and top
|
||||||
@ -2895,19 +2941,28 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restore original values
|
||||||
|
spc->h_oversample = old_h_over;
|
||||||
|
spc->v_oversample = old_v_over;
|
||||||
|
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects)
|
||||||
|
{
|
||||||
|
stbrp_pack_rects((stbrp_context *) spc->pack_info, rects, num_rects);
|
||||||
|
}
|
||||||
|
|
||||||
STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
|
STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
|
||||||
{
|
{
|
||||||
stbtt_fontinfo info;
|
stbtt_fontinfo info;
|
||||||
int i,j,n, return_value = 1;
|
int i,j,n, return_value = 1;
|
||||||
stbrp_context *context = (stbrp_context *) spc->pack_info;
|
//stbrp_context *context = (stbrp_context *) spc->pack_info;
|
||||||
stbrp_rect *rects;
|
stbrp_rect *rects;
|
||||||
|
|
||||||
// flag all characters as NOT packed
|
// flag all characters as NOT packed
|
||||||
for (i=0; i < num_ranges; ++i)
|
for (i=0; i < num_ranges; ++i)
|
||||||
for (j=0; j < ranges[i].num_chars_in_range; ++j)
|
for (j=0; j < ranges[i].num_chars; ++j)
|
||||||
ranges[i].chardata_for_range[j].x0 =
|
ranges[i].chardata_for_range[j].x0 =
|
||||||
ranges[i].chardata_for_range[j].y0 =
|
ranges[i].chardata_for_range[j].y0 =
|
||||||
ranges[i].chardata_for_range[j].x1 =
|
ranges[i].chardata_for_range[j].x1 =
|
||||||
@ -2915,7 +2970,7 @@ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontd
|
|||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
for (i=0; i < num_ranges; ++i)
|
for (i=0; i < num_ranges; ++i)
|
||||||
n += ranges[i].num_chars_in_range;
|
n += ranges[i].num_chars;
|
||||||
|
|
||||||
rects = (stbrp_rect *) STBTT_malloc(sizeof(*rects) * n, spc->user_allocator_context);
|
rects = (stbrp_rect *) STBTT_malloc(sizeof(*rects) * n, spc->user_allocator_context);
|
||||||
if (rects == NULL)
|
if (rects == NULL)
|
||||||
@ -2925,7 +2980,7 @@ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontd
|
|||||||
|
|
||||||
n = stbtt_PackFontRangesGatherRects(spc, &info, ranges, num_ranges, rects);
|
n = stbtt_PackFontRangesGatherRects(spc, &info, ranges, num_ranges, rects);
|
||||||
|
|
||||||
stbrp_pack_rects(context, rects, n);
|
stbtt_PackFontRangesPackRects(spc, rects, n);
|
||||||
|
|
||||||
return_value = stbtt_PackFontRangesRenderIntoRects(spc, &info, ranges, num_ranges, rects);
|
return_value = stbtt_PackFontRangesRenderIntoRects(spc, &info, ranges, num_ranges, rects);
|
||||||
|
|
||||||
@ -2934,11 +2989,12 @@ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontd
|
|||||||
}
|
}
|
||||||
|
|
||||||
STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
|
STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
|
||||||
int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)
|
int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)
|
||||||
{
|
{
|
||||||
stbtt_pack_range range;
|
stbtt_pack_range range;
|
||||||
range.first_unicode_char_in_range = first_unicode_char_in_range;
|
range.first_unicode_codepoint_in_range = first_unicode_codepoint_in_range;
|
||||||
range.num_chars_in_range = num_chars_in_range;
|
range.array_of_unicode_codepoints = NULL;
|
||||||
|
range.num_chars = num_chars_in_range;
|
||||||
range.chardata_for_range = chardata_for_range;
|
range.chardata_for_range = chardata_for_range;
|
||||||
range.font_size = font_size;
|
range.font_size = font_size;
|
||||||
return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);
|
return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);
|
||||||
@ -3133,3 +3189,48 @@ STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *font_collection, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // STB_TRUETYPE_IMPLEMENTATION
|
#endif // STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
|
||||||
|
|
||||||
|
// FULL VERSION HISTORY
|
||||||
|
//
|
||||||
|
// 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges
|
||||||
|
// 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints;
|
||||||
|
// allow PackFontRanges to pack and render in separate phases;
|
||||||
|
// fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?);
|
||||||
|
// fixed an assert() bug in the new rasterizer
|
||||||
|
// replace assert() with STBTT_assert() in new rasterizer
|
||||||
|
// 1.06 (2015-07-14) performance improvements (~35% faster on x86 and x64 on test machine)
|
||||||
|
// also more precise AA rasterizer, except if shapes overlap
|
||||||
|
// remove need for STBTT_sort
|
||||||
|
// 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC
|
||||||
|
// 1.04 (2015-04-15) typo in example
|
||||||
|
// 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes
|
||||||
|
// 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++
|
||||||
|
// 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match
|
||||||
|
// non-oversampled; STBTT_POINT_SIZE for packed case only
|
||||||
|
// 1.00 (2014-12-06) add new PackBegin etc. API, w/ support for oversampling
|
||||||
|
// 0.99 (2014-09-18) fix multiple bugs with subpixel rendering (ryg)
|
||||||
|
// 0.9 (2014-08-07) support certain mac/iOS fonts without an MS platformID
|
||||||
|
// 0.8b (2014-07-07) fix a warning
|
||||||
|
// 0.8 (2014-05-25) fix a few more warnings
|
||||||
|
// 0.7 (2013-09-25) bugfix: subpixel glyph bug fixed in 0.5 had come back
|
||||||
|
// 0.6c (2012-07-24) improve documentation
|
||||||
|
// 0.6b (2012-07-20) fix a few more warnings
|
||||||
|
// 0.6 (2012-07-17) fix warnings; added stbtt_ScaleForMappingEmToPixels,
|
||||||
|
// stbtt_GetFontBoundingBox, stbtt_IsGlyphEmpty
|
||||||
|
// 0.5 (2011-12-09) bugfixes:
|
||||||
|
// subpixel glyph renderer computed wrong bounding box
|
||||||
|
// first vertex of shape can be off-curve (FreeSans)
|
||||||
|
// 0.4b (2011-12-03) fixed an error in the font baking example
|
||||||
|
// 0.4 (2011-12-01) kerning, subpixel rendering (tor)
|
||||||
|
// bugfixes for:
|
||||||
|
// codepoint-to-glyph conversion using table fmt=12
|
||||||
|
// codepoint-to-glyph conversion using table fmt=4
|
||||||
|
// stbtt_GetBakedQuad with non-square texture (Zer)
|
||||||
|
// updated Hello World! sample to use kerning and subpixel
|
||||||
|
// fixed some warnings
|
||||||
|
// 0.3 (2009-06-24) cmap fmt=12, compound shapes (MM)
|
||||||
|
// userdata, malloc-from-userdata, non-zero fill (stb)
|
||||||
|
// 0.2 (2009-03-11) Fix unsigned/signed char warnings
|
||||||
|
// 0.1 (2009-03-09) First public release
|
||||||
|
//
|
||||||
|
Reference in New Issue
Block a user