Compare commits

...

111 Commits

Author SHA1 Message Date
Xeverous
a315d25b4c
Update Nuklear 2024-11-07 19:45:55 -05:00
Alexander W. Schultz
a13a60e998 updates nuklear.h after paq'ing 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
2a4e3fbc92 updates gitignore 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
80805cdfc0 updates makefile to handle documentaion generation a little better 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
d1821eebc7 removing old documentation generator 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
7cb39a360d C89 style comment blocks
nuklear.h has been converted to C89 style comment blocks instead of the
amalgamation it was before (presummably a relic of the other
documentation system).

examples compile. more testing is required.
2024-11-07 19:24:40 -05:00
Alexander W. Schultz
d3ea630a84 Adds HEADER to the doxygen output
HEADER is the intro API section of the paq'd files, which is the most
critical part of our documentation. Ideally, this file needs to stay the
same style because it needs to be incorporated into the header file;
however, we can make a minor modification to allow doxygen to render it.
with this commit, I change the name to HEADER.c to allow doxygen
processing. This shouldn't have any affect on the generated paq file.
Eventually, I would like to move this HEADER file into a different name
and the overall mainpage of the documentation.
2024-11-07 19:24:40 -05:00
Alexander W. Schultz
2ac678a94d converts nuklear.h to doxygen comment styles
the difference isnt staggering by any means. the original comment blocks
had most everything we needed. More work is required and there are still
questions to be had about how much information / styling is desired to
be retained in the code comments, verses removing some styling because
doxygen handles that conversion into html with styling automatically.
2024-11-07 19:24:40 -05:00
Alexander W. Schultz
050fbbaf9a whoops. forgot to add Doxyfile to previous commit 2024-11-07 19:24:40 -05:00
Alexander W. Schultz
3723ca585b adds source file processing to doxygen.
this commit adds the proper source file directory, so now doxygen picks
up all of the C files for processing. Some minor cleanup and file
exclusions have also been added such that things like `paq.sh` and sub
`Readme.md` files are not picked up.
2024-11-07 19:24:40 -05:00
Alexander W. Schultz
abb3e406aa initial commit of doxygen files
Adds initial doxyfile for doxygen configuration. Has some basic settings
for getting up and running with decent results.

Also, the beautiful doxygen-awesome-css project has been included in the
makefile such that we can pull (on your own time) a nice package to make
the doxygen output so much prettier to look at than the default.
2024-11-07 19:24:40 -05:00
Rob Loach
d5969abb86
Merge pull request #728 from Immediate-Mode-UI/revert-721-const-correctness
Revert "const correctness in public API"
2024-11-07 19:24:02 -05:00
Rob Loach
d123122a27
Revert "const correctness in public API" 2024-11-07 19:22:55 -05:00
Rob Loach
f169ee68d1
Merge pull request #721 from Xeverous/const-correctness
const correctness in public API
2024-11-07 18:52:54 -05:00
Rob Loach
985ddcbccb
Merge pull request #723 from awschult002/sdl_intrin
disables intrinsics on SDL demos
2024-11-05 09:43:49 -05:00
Alexander W. Schultz
b6a7791d13 disables intrinsics on SDL demos
SDL library has an issue where it expects intrinsics headers to be
provided, but intrinsics are not exactly part of a standard, so there is
no guarantee that they will be available. As such, the library allows
you to turn them off. I am disabling them to allow for better
portability and ease of compilation.
2024-10-20 23:17:02 -04:00
Antti Keränen
6566d9075d
Improve Vulkan demo (#717)
* demo: fix errors and warnings in GLFW Vulkan demo

* demo: improve resize handling in GLFW Vulkan demo

On my machine (x86_64 Linux, Wayland) VK_SUBOPTIMAL or
VK_OUT_OF_DATE_KHR were never returned so the resizing of the swapchain
never happened.

Fix by using GLFW's resize callback to detect a window resize and a
swapchain recreation. Vulkan tutorial uses the same approach.

fb_scale was never used in the Vulkan backend, so it was removed.

* demo: fix copy&paste typo in GLFW Vulkan demo

* demo: sync nuklear_glfw_vulkan.in.h with nuklear_glfw_vulkan.h

Over time people have not been noticing that the expected workflow is to
build nuklear_glfw_vulkan.h from nuklear_glfw_vulkan.in.h
2024-10-19 04:04:28 -04:00
Antti Keränen
b2ffce5131 demo/backend: add vulkan SDL backend and demo
Based on other SDL demos and GLFW Vulkan demo.
2024-10-19 04:03:54 -04:00
Xeverous
748f0dafe7 const correctness in public API 2024-10-15 19:27:56 +02:00
Stephen-Zulauf
03198a016b
Add Catppucin color styles (#695) 2024-10-02 23:08:10 -04:00
Rob Loach
8f45d37cf6 demo: Rename zahnrad binaries to demo 2024-10-02 23:02:35 -04:00
JS Deck
e360f267ed add up/down/ctrl-b/ctrl-e key handling to d3d11 demo 2024-10-02 12:12:51 -04:00
Rob Loach
2ad47c08f1 Rebuild nuklear.h 2024-09-30 13:41:55 -04:00
Rob Loach
0a28e3002b Fix incompatible pointer types warning 2024-09-30 13:33:55 -04:00
Kirill Rodriguez
fa9f257c7b untyped pointers fail when you use c++ compiler 2024-09-29 01:59:17 -04:00
Rob Loach
2156b95a5d
Merge pull request #709 from ryuukk/rounding
Round layout widget position to nearest 0
2024-09-29 01:59:01 -04:00
ryuukk
b6e261b508 Round layout widget position to nearest 0 2024-09-28 21:44:42 +02:00
Rob Loach
964cc81fad
Merge pull request #697 from ryuukk/patch-2
Update proggyfont urls
2024-09-25 11:34:03 -04:00
ryuukk
5c89e05538
Change proggyfont urls 2024-09-23 15:32:17 +02:00
Rob Loach
ca8aaf3f65
Merge pull request #690 from lockie/master
allegro5: take image region into account for NK_COMMAND_IMAGE
2024-09-19 10:56:09 -04:00
Andrew Kravchuk
a02e1824b8
allegro5: correctly handle subimages NK_COMMAND_IMAGE 2024-09-18 09:07:28 +02:00
Andrew Kravchuk
e4901c5358
allegro5: correctly handle zero region in NK_COMMAND_IMAGE 2024-09-18 06:46:14 +02:00
Andrew Kravchuk
19dc0131f3
allegro5: take image region into account for NK_COMMAND_IMAGE 2024-09-17 20:52:58 +02:00
Rob Loach
4ffef5eb11
Merge pull request #689 from mark-summerfield/patch-1
Update nuklear_xcb.h: eliminate two warnings in C99 mode
2024-09-14 14:20:37 -04:00
Mark
f3de6a0cb3
Update nuklear_xcb.h: eliminate two warnings in C99 mode
Function `NK_API int nk_cairo_render(struct nk_cairo_context *cairo_ctx, struct nk_context *nk_ctx)` returns an int but `return;` is used twice. Now replaced with `return nk_false;`. This makes for clean compilation with both C89 _and_ C99.
2024-09-14 10:37:45 +01:00
Rob Loach
18f7e7a948
demo: Add headers to overview.c (#684)
This adds the required C headers directly to the top of the overview.c demo so that they don't need to be added in the renders themselves.
2024-09-08 12:34:09 -04:00
Rob Loach
ec113a0f7c
Merge pull request #680 from Immediate-Mode-UI/demo-overview--time
demo: Add time.h to overview.c
2024-09-04 11:43:17 -04:00
Rob Loach
4373fd03cc
Merge pull request #682 from PROP65/func_fix
Fixes for nk_strtod, nk_strtof, and nk_strtoi
2024-09-03 20:07:35 -04:00
PROP 65
19bb57b893
Update nuklear.h 2024-09-03 03:46:11 +00:00
PROP 65
cb9dc9635a
Update nuklear_util.c 2024-09-03 03:39:49 +00:00
Rob Loach
458112efd3
demo: Add time.h to overview.c
This adds the `time.h` include to the top of overview.c so that the renders don't need to include it manually.
2024-09-02 14:15:44 -04:00
Rob Loach
f7847e6024
Add delta_time_seconds to a few renderers (#628) 2024-08-29 22:22:55 -04:00
Rob Loach
9eeb910d01
Merge pull request #672 from PROP65/delta
Add delta_time_seconds to X11 and SFML renderers
2024-08-29 10:50:22 -04:00
PROP 65
751d2bfbff
Update nuklear_sdl_gl2.h 2024-08-29 03:17:04 +00:00
PROP 65
1d03d421c5
Update nuklear_sdl_gl3.h 2024-08-29 03:16:51 +00:00
PROP 65
f180a5c423
Update nuklear_sdl_gles2.h 2024-08-29 03:16:40 +00:00
PROP 65
49fd23e13c
sfml_gl2: add delta_time_seconds 2024-08-29 03:15:45 +00:00
PROP 65
81ae780756
sfml_gl3: add delta_time_seconds 2024-08-29 03:14:25 +00:00
PROP 65
4bfc027e08
xlib: add delta_time_seconds 2024-08-29 03:13:45 +00:00
PROP 65
c3fe64a487
xlib_gl2: add delta_time_seconds 2024-08-29 03:13:22 +00:00
PROP 65
42b9ea7943
xlib_gl3: add delta_time_seconds 2024-08-29 03:11:10 +00:00
PROP 65
d043803932
xlib: add delta_time_seconds 2024-08-29 03:09:28 +00:00
PROP 65
b3b400895d
Add delta_time_seconds to the SDL OpenGL renderers (#671)
RE: #627
2024-08-28 11:18:48 -04:00
Rob Loach
b1c2227fa9
Merge pull request #669 from PROP65/knob
New Widget: Knobs
2024-08-28 11:01:42 -04:00
PROP 65
1f0c22cc10
Merge branch 'Immediate-Mode-UI:master' into knob 2024-08-28 00:51:03 +00:00
Rob Loach
29b7be6de0
knob: Add color styles 2024-08-27 11:43:39 -04:00
Rob Loach
c3282bf274
Merge pull request #665 from PROP65/assert_delete
Remove unnecessary assert
2024-08-26 11:30:45 -04:00
PROP 65
eab9f225e6
Move copyright info to its own file (#667)
* Create LICENSE

* replace license with link to license
2024-08-26 11:29:47 -04:00
PROP 65
97fb6fffd6
Rebuild nuklear.h 2024-08-19 01:13:57 +00:00
PROP 65
8306b32465
Update nuklear_style.c 2024-08-19 01:10:19 +00:00
PROP 65
a6973c2d64
Update nuklear_style.c 2024-08-19 01:08:17 +00:00
PROP 65
48434308c6
Update nuklear_style.c 2024-08-19 01:06:30 +00:00
PROP 65
820eca5858
Update overview.c 2024-08-19 01:03:06 +00:00
PROP 65
0ddaeb7043
add atan(x) and atan2(y,x) 2024-08-19 01:00:05 +00:00
PROP 65
b7125d9b10
add atan(x) and atan2(y,x) 2024-08-19 00:58:22 +00:00
PROP 65
76ad5ebd3b
add knobs 2024-08-19 00:54:52 +00:00
PROP 65
3d5eb27f85
add knob widget 2024-08-19 00:48:39 +00:00
PROP 65
d0c557dd34
Update paq.sh 2024-08-19 00:47:46 +00:00
PROP 65
728e44b0a2
Update paq.bat 2024-08-19 00:47:45 +00:00
PROP 65
c048d6fbc3
add knobs 2024-08-19 00:44:47 +00:00
PROP 65
6556884274
Update nuklear.h 2024-08-14 00:38:46 +00:00
PROP 65
a33d01bd18
Update nuklear_window.c 2024-08-14 00:38:41 +00:00
Rob Loach
be0a3f6141
Fix for NK_OFFSETOF on Emscripten (#663)
Fixes the following error with Emscripten, where `__builtin_offset` isn't available. This disables the usage of it when on Emscripten.

```
nuklear.h:8978:38: error: defining a type within '__builtin_offsetof' is a C23 extension [-Werror,-Wc23-extensions]
 8978 |     NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_command);
```
2024-07-29 11:07:32 -04:00
Rob Loach
2795d90707
Merge pull request #661 from bolt-blue/glfw_demo_quickfix
Quickfix glfw shift-key handling
2024-07-23 11:40:40 -04:00
Rob Loach
8f3fc31ba5
Merge pull request #662 from bolt-blue/indentation_quickfix
Improve one poor case of indentation
2024-07-20 03:06:17 -04:00
bolt
a689b8efdf Improve one poor case of indentation
The original code was distinctly unclear. I've tried to keep to the
surrounding code style while making the code flow more comprehensible.

I've not looked elsewhere for any other similar occurrences; this became
apparent while investigating a specific line of thought.
2024-07-18 09:04:14 +01:00
bolt
0883109476 Quickfix glfw shift-key handling
All of the glfw demo headers unset shift keypresses when the ctrl key is not
also down.
I can't think of a reason this would be desired and it appears no other demo
code does this.
Unless I'm mistaken, simply removing these lines leaves us with the desired
behaviour.
2024-07-11 12:33:37 +01:00
Rob Loach
0319c0ff3b
Add triangle outline symbols (#654) 2024-06-30 13:30:17 -04:00
Rob Loach
74a12afc62
Rebuild nuklear.h 2024-06-27 13:58:56 -04:00
Rob Loach
aaee3007ea
Merge pull request #652 from SchelZ/master
Fix rounding of panels
2024-06-22 22:24:06 -04:00
SchelZ
d3d4a3e96e
Update nuklear_panel.c 2024-06-17 19:56:16 +03:00
Rob Loach
504f8319a8 Rebuild nuklear.h
Fixes #648
2024-06-14 03:17:37 -04:00
Rob Loach
47f570c048
Merge pull request #642 from SnootierMoon/master
Add `const` qualifiers to `nk_allocator` in more places.
2024-05-25 16:41:23 -04:00
Rob Loach
b9e84c03f0
Merge pull request #636 from Ryder17z/patch-1
Proposal: Update nuklear_sdl_renderer.h to use recommended path for SDL.h
2024-05-25 15:46:07 -04:00
Rob Loach
8e84d63c6c
sdl: Allow changing the SDL.h path 2024-05-23 13:33:28 -04:00
Rob Loach
6286f22996
Merge pull request #638 from ccawley2011/rawfb-pixel-format
Support arbitrary pixel formats with more rawfb demos
2024-05-23 13:32:31 -04:00
Rob Loach
72198bb2e1
Merge pull request #641 from idontcares31249/master
Fix missing nk_sdl_handle_grab declarations in SDL demo headers
2024-05-22 16:24:14 -04:00
Akshay Trivedi
dd61233c1f Add casts for stbtt alloc userdata 2024-05-21 12:43:04 -07:00
Akshay Trivedi
59b6277209 Add const qualifier to more nk_allocator parameters 2024-05-21 12:36:02 -07:00
User
b848bb0141 added nk_sdl_handle_grab declarations to demo/sdl_*/ headers 2024-05-17 08:13:14 +00:00
Cameron Cawley
488525745a Support arbitrary pixel formats with more rawfb demos 2024-05-03 11:46:23 +01:00
Rob Loach
37e54da201
property: Allow optional labels for properties with # (#634) 2024-04-28 02:42:54 -04:00
Rob Loach
7e9da57c09
Add Dracula style (#621)
This introduces a new Dracula color style inspired by the [Dracula theme](https://draculatheme.com).
2024-04-28 01:02:34 -04:00
Rob Loach
a10a830b0e
Merge pull request #635 from Immediate-Mode-UI/xcb-cairo
Add XCB-Cairo
2024-04-27 15:17:39 -04:00
TheExileFox
38be74be66
Update nuklear_sdl_renderer.h
change SDL include path to the recommended path
2024-04-27 11:03:55 +02:00
Rob Loach
7f5c642bb3
Standardize INCLUDE_OVERVIEW defines 2024-04-25 16:49:50 -04:00
Rob Loach
86da26fbc1
Have the height of the style dropdown be automatic 2024-04-25 16:39:17 -04:00
Rob Loach
4cfea49522
Remove STYLE_ defines as we have the style dropdown 2024-04-25 16:37:07 -04:00
Rob Loach
2f2474af45
Clean up the style dropdown 2024-04-25 16:22:36 -04:00
Rob Loach
3a7f458499
Merge branch 'master' into xcb-cairo 2024-04-17 15:19:53 -04:00
Rob Loach
0cbc6f43aa
Add CANVAS demo 2024-04-15 20:59:29 -04:00
Rob Loach
31b5729d66
[overview] Fix show_markers boolean type (#633) 2024-04-09 14:00:50 -04:00
Richard Gill
a4af91dd21 fixed common files location in demo 2022-08-04 20:57:46 +02:00
Richard Gill
93174aaadc Merge commit '93a057b3fe305254ce087ff1dbde34bc663c5bc8' into xcb-cairo 2022-08-04 20:50:27 +02:00
Richard Gill
abbd89896f added style and overview to xbc_cairo demo 2021-06-06 17:27:44 +02:00
Richard Gill
2b886bd2cd fixes for PR inclusion 2021-05-13 15:22:52 +02:00
Richard Gill
14531a23a5 fixed rect multi color 2021-05-13 01:00:19 +02:00
Richard Gill
ef9fef2189 last xcb try 2021-05-06 21:35:36 +02:00
Richard Gill
596e5d76d9 try to impl rect multicolor command with cairo 2021-05-01 20:50:31 +02:00
Richard Gill
1ae558aa7f added style selector in demo 2021-05-01 17:48:17 +02:00
Richard Gill
24594c8f75 working
from https://github.com/griebd/nuklear_xcb
2021-05-01 17:38:55 +02:00
109 changed files with 17981 additions and 11584 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ docs/xml
docs/build
docs/src
doc/doc*
doc/*
*.tmp
*.swo
*.swp

39
LICENSE Normal file
View File

@ -0,0 +1,39 @@
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Micha Mettke
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------

36
Makefile Normal file
View File

@ -0,0 +1,36 @@
docs_path:=./doc
doxyfile:=$(docs_path)/Doxyfile
.PHONY: usage
usage:
echo "make docs to create documentation"
echo "make nuke to rebuild the single header nuklear.h from source"
echo "make all to re-pack the header and create documentation"
echo "make install to "install" man files"
docs: $(docs_path)/html/index.html
$(docs_path)/html/index.html: $(docs_path)/doxygen-awesome-css/doxygen-awesome.css $(doxyfile)
doxygen $(doxyfile)
$(doxyfile):
doxygen -g $@
$(docs_path)/doxygen-awesome-css/doxygen-awesome.css:
git clone https://github.com/jothepro/doxygen-awesome-css.git $(docs_path)/doxygen-awesome-css --branch v2.3.4
nuke:
cd ./src && ./paq.sh
all: docs nuke
install:
clean:
rm -rf $(docs_path)/html

View File

@ -126,47 +126,8 @@ Barrett for his amazing single-header [libraries](https://github.com/nothings/st
in libraries and brought me to create some of my own. Finally Apoorva Joshi for his single-header [file packer](http://apoorvaj.io/single-header-packer.html).
## License
```
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Micha Mettke
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------
```
Nuklear is avaliable under either the MIT License or public domain.
See [LICENSE](LICENSE) for more info.
## Reviewers guide

View File

@ -41,7 +41,7 @@
/*#define INCLUDE_STYLE */
/*#define INCLUDE_CALCULATOR */
/*#define INCLUDE_CANVAS */
#define INCLUDE_OVERVIEW
/*#define INCLUDE_OVERVIEW */
/*#define INCLUDE_NODE_EDITOR */
#ifdef INCLUDE_ALL
@ -114,20 +114,6 @@ int main(void)
ctx = nk_allegro5_init(font, display, WINDOW_WIDTH, WINDOW_HEIGHT);
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
while(1)
{
bool get_event;

View File

@ -66,6 +66,7 @@ static struct nk_allegro5 {
int touch_down_id;
struct nk_context ctx;
struct nk_buffer cmds;
float delta_time_seconds_last;
} allegro5;
@ -177,6 +178,11 @@ nk_allegro5_render()
{
const struct nk_command *cmd;
/* Update the timer */
float now = (float)al_get_time();
allegro5.ctx.delta_time_seconds = now - allegro5.delta_time_seconds_last;
allegro5.delta_time_seconds_last = now;
al_set_target_backbuffer(allegro5.dsp);
nk_foreach(cmd, &allegro5.ctx)
@ -318,7 +324,17 @@ nk_allegro5_render()
} break;
case NK_COMMAND_IMAGE: {
const struct nk_command_image *i = (const struct nk_command_image *)cmd;
al_draw_bitmap_region(i->img.handle.ptr, 0, 0, i->w, i->h, i->x, i->y, 0);
nk_ushort
x = i->img.region[0],
y = i->img.region[1],
w = i->img.region[2],
h = i->img.region[3];
if(w == 0 && h == 0)
{
x = i->x; y = i->y; w = i->w; h = i->h;
}
al_draw_scaled_bitmap(i->img.handle.ptr,
x, y, w, h, i->x, i->y, i->w, i->h, 0);
} break;
case NK_COMMAND_RECT_MULTI_COLOR:
default: break;
@ -498,6 +514,7 @@ nk_allegro5_init(NkAllegro5Font *allegro5font, ALLEGRO_DISPLAY *dsp,
allegro5.height = height;
allegro5.is_touch_down = 0;
allegro5.touch_down_id = -1;
allegro5.delta_time_seconds_last = (float)al_get_time();
nk_init_default(&allegro5.ctx, font);
allegro5.ctx.clip.copy = nk_allegro5_clipboard_copy;

View File

@ -1,18 +1,29 @@
#include <limits.h> /* INT_MAX */
#include <time.h> /* struct tm, localtime */
static int
overview(struct nk_context *ctx)
{
/* window flags */
static nk_bool show_menu = nk_true;
static nk_flags window_flags = NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_SCALABLE|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE;
nk_flags actual_window_flags;
static nk_flags window_flags = NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_SCALABLE|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_SCROLL_AUTO_HIDE;
nk_flags actual_window_flags = 0;
/* widget flags */
static nk_bool disable_widgets = nk_false;
static nk_bool disable_widgets = nk_false;
/* popups */
static enum nk_style_header_align header_align = NK_HEADER_RIGHT;
static nk_bool show_app_about = nk_false;
#ifdef INCLUDE_STYLE
/* styles */
static const char* themes[] = {"Black", "White", "Red", "Blue", "Dark", "Dracula",
"Catppucin Latte", "Catppucin Frappe", "Catppucin Macchiato", "Catppucin Mocha"};
static int current_theme = 0;
#endif
/* window flags */
ctx->style.window.header.align = header_align;
actual_window_flags = window_flags;
@ -121,6 +132,20 @@ overview(struct nk_context *ctx)
} else show_app_about = nk_false;
}
#ifdef INCLUDE_STYLE
/* style selector */
nk_layout_row_dynamic(ctx, 0, 2);
{
int new_theme;
nk_label(ctx, "Style:", NK_TEXT_LEFT);
new_theme = nk_combo(ctx, themes, NK_LEN(themes), current_theme, 25, nk_vec2(200, 200));
if (new_theme != current_theme) {
current_theme = new_theme;
set_style(ctx, current_theme);
}
}
#endif
/* window flags */
if (nk_tree_push(ctx, NK_TREE_TAB, "Window", NK_MINIMIZED)) {
nk_layout_row_dynamic(ctx, 30, 2);
@ -132,7 +157,7 @@ overview(struct nk_context *ctx)
nk_checkbox_flags_label(ctx, "No Scrollbar", &window_flags, NK_WINDOW_NO_SCROLLBAR);
nk_checkbox_flags_label(ctx, "Minimizable", &window_flags, NK_WINDOW_MINIMIZABLE);
nk_checkbox_flags_label(ctx, "Scale Left", &window_flags, NK_WINDOW_SCALE_LEFT);
nk_checkbox_label(ctx, "Disable widgets", &disable_widgets);
nk_checkbox_label(ctx, "Disable widgets", &disable_widgets);
nk_tree_pop(ctx);
}
@ -184,9 +209,13 @@ overview(struct nk_context *ctx)
nk_button_symbol(ctx, NK_SYMBOL_RECT_SOLID);
nk_button_symbol(ctx, NK_SYMBOL_RECT_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_UP);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_UP_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_DOWN);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_DOWN_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_LEFT);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_LEFT_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE);
nk_layout_row_static(ctx, 30, 100, 2);
nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_LEFT, "prev", NK_TEXT_RIGHT);
@ -200,6 +229,8 @@ overview(struct nk_context *ctx)
/* Basic widgets */
static int int_slider = 5;
static float float_slider = 2.5f;
static int int_knob = 5;
static float float_knob = 2.5f;
static nk_size prog_value = 40;
static float property_float = 2;
static int property_int = 10;
@ -212,6 +243,7 @@ overview(struct nk_context *ctx)
static int range_int_value = 2048;
static int range_int_max = 4096;
static const float ratio[] = {120, 150};
static int range_int_value_hidden = 2048;
nk_layout_row_dynamic(ctx, 0, 1);
nk_checkbox_label(ctx, "CheckLeft TextLeft", &checkbox_left_text_left);
@ -238,6 +270,12 @@ overview(struct nk_context *ctx)
nk_labelf(ctx, NK_TEXT_LEFT, "Progressbar: %u" , (int)prog_value);
nk_progress(ctx, &prog_value, 100, NK_MODIFIABLE);
nk_layout_row(ctx, NK_STATIC, 40, 2, ratio);
nk_labelf(ctx, NK_TEXT_LEFT, "Knob int: %d", int_knob);
nk_knob_int(ctx, 0, &int_knob, 10, 1, NK_DOWN, 60.0f);
nk_labelf(ctx, NK_TEXT_LEFT, "Knob float: %.2f", float_knob);
nk_knob_float(ctx, 0, &float_knob, 5.0, 0.5f, NK_DOWN, 60.0f);
nk_layout_row(ctx, NK_STATIC, 25, 2, ratio);
nk_label(ctx, "Property float:", NK_TEXT_LEFT);
nk_property_float(ctx, "Float:", 0, &property_float, 64.0f, 0.1f, 0.2f);
@ -257,6 +295,10 @@ overview(struct nk_context *ctx)
nk_property_int(ctx, "#neg:", range_int_min, &range_int_value, range_int_max, 1, 10);
nk_property_int(ctx, "#max:", range_int_min, &range_int_max, INT_MAX, 1, 10);
nk_layout_row_dynamic(ctx, 0, 2);
nk_label(ctx, "Hidden Label:", NK_TEXT_LEFT);
nk_property_int(ctx, "##Hidden Label", range_int_min, &range_int_value_hidden, INT_MAX, 1, 10);
nk_tree_pop(ctx);
}
@ -633,7 +675,7 @@ overview(struct nk_context *ctx)
float id = 0;
static int col_index = -1;
static int line_index = -1;
static int show_markers = nk_true;
static nk_bool show_markers = nk_true;
float step = (2*3.141592654f) / 32;
int i;

View File

@ -1,132 +1,441 @@
enum theme {THEME_BLACK, THEME_WHITE, THEME_RED, THEME_BLUE, THEME_DARK};
enum theme {
THEME_BLACK,
THEME_WHITE,
THEME_RED,
THEME_BLUE,
THEME_DARK,
THEME_DRACULA,
THEME_CATPPUCCIN_LATTE,
THEME_CATPPUCCIN_FRAPPE,
THEME_CATPPUCCIN_MACCHIATO,
THEME_CATPPUCCIN_MOCHA
};
static void
set_style(struct nk_context *ctx, enum theme theme)
{
struct nk_color table[NK_COLOR_COUNT];
if (theme == THEME_WHITE) {
table[NK_COLOR_TEXT] = nk_rgba(70, 70, 70, 255);
table[NK_COLOR_WINDOW] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_HEADER] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_BORDER] = nk_rgba(0, 0, 0, 255);
table[NK_COLOR_BUTTON] = nk_rgba(185, 185, 185, 255);
table[NK_COLOR_BUTTON_HOVER] = nk_rgba(170, 170, 170, 255);
table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_TOGGLE] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(120, 120, 120, 255);
table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_SELECT] = nk_rgba(190, 190, 190, 255);
table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_SLIDER] = nk_rgba(190, 190, 190, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(80, 80, 80, 255);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(70, 70, 70, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(60, 60, 60, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_EDIT_CURSOR] = nk_rgba(0, 0, 0, 255);
table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255);
table[NK_COLOR_SCROLLBAR] = nk_rgba(180, 180, 180, 255);
table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(140, 140, 140, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255);
nk_style_from_table(ctx, table);
} else if (theme == THEME_RED) {
table[NK_COLOR_TEXT] = nk_rgba(190, 190, 190, 255);
table[NK_COLOR_WINDOW] = nk_rgba(30, 33, 40, 215);
table[NK_COLOR_HEADER] = nk_rgba(181, 45, 69, 220);
table[NK_COLOR_BORDER] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_BUTTON] = nk_rgba(181, 45, 69, 255);
table[NK_COLOR_BUTTON_HOVER] = nk_rgba(190, 50, 70, 255);
table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(195, 55, 75, 255);
table[NK_COLOR_TOGGLE] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 60, 60, 255);
table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(181, 45, 69, 255);
table[NK_COLOR_SELECT] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(181, 45, 69, 255);
table[NK_COLOR_SLIDER] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(181, 45, 69, 255);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(186, 50, 74, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(191, 55, 79, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_EDIT] = nk_rgba(51, 55, 67, 225);
table[NK_COLOR_EDIT_CURSOR] = nk_rgba(190, 190, 190, 255);
table[NK_COLOR_COMBO] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_CHART] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(170, 40, 60, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255);
table[NK_COLOR_SCROLLBAR] = nk_rgba(30, 33, 40, 255);
table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(181, 45, 69, 220);
nk_style_from_table(ctx, table);
} else if (theme == THEME_BLUE) {
table[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255);
table[NK_COLOR_WINDOW] = nk_rgba(202, 212, 214, 215);
table[NK_COLOR_HEADER] = nk_rgba(137, 182, 224, 220);
table[NK_COLOR_BORDER] = nk_rgba(140, 159, 173, 255);
table[NK_COLOR_BUTTON] = nk_rgba(137, 182, 224, 255);
table[NK_COLOR_BUTTON_HOVER] = nk_rgba(142, 187, 229, 255);
table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(147, 192, 234, 255);
table[NK_COLOR_TOGGLE] = nk_rgba(177, 210, 210, 255);
table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(182, 215, 215, 255);
table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(137, 182, 224, 255);
table[NK_COLOR_SELECT] = nk_rgba(177, 210, 210, 255);
table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(137, 182, 224, 255);
table[NK_COLOR_SLIDER] = nk_rgba(177, 210, 210, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(137, 182, 224, 245);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(142, 188, 229, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(147, 193, 234, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_EDIT] = nk_rgba(210, 210, 210, 225);
table[NK_COLOR_EDIT_CURSOR] = nk_rgba(20, 20, 20, 255);
table[NK_COLOR_COMBO] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_CHART] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(137, 182, 224, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255);
table[NK_COLOR_SCROLLBAR] = nk_rgba(190, 200, 200, 255);
table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255);
nk_style_from_table(ctx, table);
} else if (theme == THEME_DARK) {
table[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_WINDOW] = nk_rgba(57, 67, 71, 215);
table[NK_COLOR_HEADER] = nk_rgba(51, 51, 56, 220);
table[NK_COLOR_BORDER] = nk_rgba(46, 46, 46, 255);
table[NK_COLOR_BUTTON] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_BUTTON_HOVER] = nk_rgba(58, 93, 121, 255);
table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(63, 98, 126, 255);
table[NK_COLOR_TOGGLE] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 53, 56, 255);
table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_SELECT] = nk_rgba(57, 67, 61, 255);
table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_SLIDER] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(48, 83, 111, 245);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_EDIT] = nk_rgba(50, 58, 61, 225);
table[NK_COLOR_EDIT_CURSOR] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_COMBO] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_CHART] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255);
table[NK_COLOR_SCROLLBAR] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255);
nk_style_from_table(ctx, table);
} else {
nk_style_default(ctx);
}
static void set_style(struct nk_context *ctx, enum theme theme) {
struct nk_color table[NK_COLOR_COUNT];
if (theme == THEME_WHITE) {
table[NK_COLOR_TEXT] = nk_rgba(70, 70, 70, 255);
table[NK_COLOR_WINDOW] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_HEADER] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_BORDER] = nk_rgba(0, 0, 0, 255);
table[NK_COLOR_BUTTON] = nk_rgba(185, 185, 185, 255);
table[NK_COLOR_BUTTON_HOVER] = nk_rgba(170, 170, 170, 255);
table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_TOGGLE] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(120, 120, 120, 255);
table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_SELECT] = nk_rgba(190, 190, 190, 255);
table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_SLIDER] = nk_rgba(190, 190, 190, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(80, 80, 80, 255);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(70, 70, 70, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(60, 60, 60, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_EDIT_CURSOR] = nk_rgba(0, 0, 0, 255);
table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255);
table[NK_COLOR_SCROLLBAR] = nk_rgba(180, 180, 180, 255);
table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(140, 140, 140, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_RED) {
table[NK_COLOR_TEXT] = nk_rgba(190, 190, 190, 255);
table[NK_COLOR_WINDOW] = nk_rgba(30, 33, 40, 215);
table[NK_COLOR_HEADER] = nk_rgba(181, 45, 69, 220);
table[NK_COLOR_BORDER] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_BUTTON] = nk_rgba(181, 45, 69, 255);
table[NK_COLOR_BUTTON_HOVER] = nk_rgba(190, 50, 70, 255);
table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(195, 55, 75, 255);
table[NK_COLOR_TOGGLE] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 60, 60, 255);
table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(181, 45, 69, 255);
table[NK_COLOR_SELECT] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(181, 45, 69, 255);
table[NK_COLOR_SLIDER] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(181, 45, 69, 255);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(186, 50, 74, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(191, 55, 79, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_EDIT] = nk_rgba(51, 55, 67, 225);
table[NK_COLOR_EDIT_CURSOR] = nk_rgba(190, 190, 190, 255);
table[NK_COLOR_COMBO] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_CHART] = nk_rgba(51, 55, 67, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(170, 40, 60, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255);
table[NK_COLOR_SCROLLBAR] = nk_rgba(30, 33, 40, 255);
table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(181, 45, 69, 220);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_BLUE) {
table[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255);
table[NK_COLOR_WINDOW] = nk_rgba(202, 212, 214, 215);
table[NK_COLOR_HEADER] = nk_rgba(137, 182, 224, 220);
table[NK_COLOR_BORDER] = nk_rgba(140, 159, 173, 255);
table[NK_COLOR_BUTTON] = nk_rgba(137, 182, 224, 255);
table[NK_COLOR_BUTTON_HOVER] = nk_rgba(142, 187, 229, 255);
table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(147, 192, 234, 255);
table[NK_COLOR_TOGGLE] = nk_rgba(177, 210, 210, 255);
table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(182, 215, 215, 255);
table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(137, 182, 224, 255);
table[NK_COLOR_SELECT] = nk_rgba(177, 210, 210, 255);
table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(137, 182, 224, 255);
table[NK_COLOR_SLIDER] = nk_rgba(177, 210, 210, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(137, 182, 224, 245);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(142, 188, 229, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(147, 193, 234, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_EDIT] = nk_rgba(210, 210, 210, 225);
table[NK_COLOR_EDIT_CURSOR] = nk_rgba(20, 20, 20, 255);
table[NK_COLOR_COMBO] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_CHART] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(137, 182, 224, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255);
table[NK_COLOR_SCROLLBAR] = nk_rgba(190, 200, 200, 255);
table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_DARK) {
table[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_WINDOW] = nk_rgba(57, 67, 71, 215);
table[NK_COLOR_HEADER] = nk_rgba(51, 51, 56, 220);
table[NK_COLOR_BORDER] = nk_rgba(46, 46, 46, 255);
table[NK_COLOR_BUTTON] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_BUTTON_HOVER] = nk_rgba(58, 93, 121, 255);
table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(63, 98, 126, 255);
table[NK_COLOR_TOGGLE] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 53, 56, 255);
table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_SELECT] = nk_rgba(57, 67, 61, 255);
table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_SLIDER] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(48, 83, 111, 245);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_EDIT] = nk_rgba(50, 58, 61, 225);
table[NK_COLOR_EDIT_CURSOR] = nk_rgba(210, 210, 210, 255);
table[NK_COLOR_COMBO] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_CHART] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255);
table[NK_COLOR_SCROLLBAR] = nk_rgba(50, 58, 61, 255);
table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_DRACULA) {
struct nk_color background = nk_rgba(40, 42, 54, 255);
struct nk_color currentline = nk_rgba(68, 71, 90, 255);
struct nk_color foreground = nk_rgba(248, 248, 242, 255);
struct nk_color comment = nk_rgba(98, 114, 164, 255);
/* struct nk_color cyan = nk_rgba(139, 233, 253, 255); */
/* struct nk_color green = nk_rgba(80, 250, 123, 255); */
/* struct nk_color orange = nk_rgba(255, 184, 108, 255); */
struct nk_color pink = nk_rgba(255, 121, 198, 255);
struct nk_color purple = nk_rgba(189, 147, 249, 255);
/* struct nk_color red = nk_rgba(255, 85, 85, 255); */
/* struct nk_color yellow = nk_rgba(241, 250, 140, 255); */
table[NK_COLOR_TEXT] = foreground;
table[NK_COLOR_WINDOW] = background;
table[NK_COLOR_HEADER] = currentline;
table[NK_COLOR_BORDER] = currentline;
table[NK_COLOR_BUTTON] = currentline;
table[NK_COLOR_BUTTON_HOVER] = comment;
table[NK_COLOR_BUTTON_ACTIVE] = purple;
table[NK_COLOR_TOGGLE] = currentline;
table[NK_COLOR_TOGGLE_HOVER] = comment;
table[NK_COLOR_TOGGLE_CURSOR] = pink;
table[NK_COLOR_SELECT] = currentline;
table[NK_COLOR_SELECT_ACTIVE] = comment;
table[NK_COLOR_SLIDER] = background;
table[NK_COLOR_SLIDER_CURSOR] = currentline;
table[NK_COLOR_SLIDER_CURSOR_HOVER] = comment;
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = comment;
table[NK_COLOR_PROPERTY] = currentline;
table[NK_COLOR_EDIT] = currentline;
table[NK_COLOR_EDIT_CURSOR] = foreground;
table[NK_COLOR_COMBO] = currentline;
table[NK_COLOR_CHART] = currentline;
table[NK_COLOR_CHART_COLOR] = comment;
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = purple;
table[NK_COLOR_SCROLLBAR] = background;
table[NK_COLOR_SCROLLBAR_CURSOR] = currentline;
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = comment;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = purple;
table[NK_COLOR_TAB_HEADER] = currentline;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_CATPPUCCIN_LATTE) {
/*struct nk_color rosewater = nk_rgba(220, 138, 120, 255);*/
/*struct nk_color flamingo = nk_rgba(221, 120, 120, 255);*/
struct nk_color pink = nk_rgba(234, 118, 203, 255);
struct nk_color mauve = nk_rgba(136, 57, 239, 255);
/*struct nk_color red = nk_rgba(210, 15, 57, 255);*/
/*struct nk_color maroon = nk_rgba(230, 69, 83, 255);*/
/*struct nk_color peach = nk_rgba(254, 100, 11, 255);*/
struct nk_color yellow = nk_rgba(223, 142, 29, 255);
/*struct nk_color green = nk_rgba(64, 160, 43, 255);*/
struct nk_color teal = nk_rgba(23, 146, 153, 255);
/*struct nk_color sky = nk_rgba(4, 165, 229, 255);*/
/*struct nk_color sapphire = nk_rgba(32, 159, 181, 255);*/
/*struct nk_color blue = nk_rgba(30, 102, 245, 255);*/
/*struct nk_color lavender = nk_rgba(114, 135, 253, 255);*/
struct nk_color text = nk_rgba(76, 79, 105, 255);
/*struct nk_color subtext1 = nk_rgba(92, 95, 119, 255);*/
/*struct nk_color subtext0 = nk_rgba(108, 111, 133, 255);*/
struct nk_color overlay2 = nk_rgba(124, 127, 147, 55);
/*struct nk_color overlay1 = nk_rgba(140, 143, 161, 255);*/
struct nk_color overlay0 = nk_rgba(156, 160, 176, 255);
struct nk_color surface2 = nk_rgba(172, 176, 190, 255);
struct nk_color surface1 = nk_rgba(188, 192, 204, 255);
struct nk_color surface0 = nk_rgba(204, 208, 218, 255);
struct nk_color base = nk_rgba(239, 241, 245, 255);
struct nk_color mantle = nk_rgba(230, 233, 239, 255);
/*struct nk_color crust = nk_rgba(220, 224, 232, 255);*/
table[NK_COLOR_TEXT] = text;
table[NK_COLOR_WINDOW] = base;
table[NK_COLOR_HEADER] = mantle;
table[NK_COLOR_BORDER] = mantle;
table[NK_COLOR_BUTTON] = surface0;
table[NK_COLOR_BUTTON_HOVER] = overlay2;
table[NK_COLOR_BUTTON_ACTIVE] = overlay0;
table[NK_COLOR_TOGGLE] = surface2;
table[NK_COLOR_TOGGLE_HOVER] = overlay2;
table[NK_COLOR_TOGGLE_CURSOR] = yellow;
table[NK_COLOR_SELECT] = surface0;
table[NK_COLOR_SELECT_ACTIVE] = overlay0;
table[NK_COLOR_SLIDER] = surface1;
table[NK_COLOR_SLIDER_CURSOR] = teal;
table[NK_COLOR_SLIDER_CURSOR_HOVER] = teal;
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = teal;
table[NK_COLOR_PROPERTY] = surface0;
table[NK_COLOR_EDIT] = surface0;
table[NK_COLOR_EDIT_CURSOR] = mauve;
table[NK_COLOR_COMBO] = surface0;
table[NK_COLOR_CHART] = surface0;
table[NK_COLOR_CHART_COLOR] = teal;
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = mauve;
table[NK_COLOR_SCROLLBAR] = surface0;
table[NK_COLOR_SCROLLBAR_CURSOR] = overlay0;
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = mauve;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = mauve;
table[NK_COLOR_TAB_HEADER] = surface0;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = pink;
table[NK_COLOR_KNOB_CURSOR_HOVER] = pink;
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = pink;
nk_style_from_table(ctx, table);
} else if (theme == THEME_CATPPUCCIN_FRAPPE) {
/*struct nk_color rosewater = nk_rgba(242, 213, 207, 255);*/
/*struct nk_color flamingo = nk_rgba(238, 190, 190, 255);*/
struct nk_color pink = nk_rgba(244, 184, 228, 255);
/*struct nk_color mauve = nk_rgba(202, 158, 230, 255);*/
/*struct nk_color red = nk_rgba(231, 130, 132, 255);*/
/*struct nk_color maroon = nk_rgba(234, 153, 156, 255);*/
/*struct nk_color peach = nk_rgba(239, 159, 118, 255);*/
/*struct nk_color yellow = nk_rgba(229, 200, 144, 255);*/
struct nk_color green = nk_rgba(166, 209, 137, 255);
/*struct nk_color teal = nk_rgba(129, 200, 190, 255);*/
/*struct nk_color sky = nk_rgba(153, 209, 219, 255);*/
/*struct nk_color sapphire = nk_rgba(133, 193, 220, 255);*/
/*struct nk_color blue = nk_rgba(140, 170, 238, 255);*/
struct nk_color lavender = nk_rgba(186, 187, 241, 255);
struct nk_color text = nk_rgba(198, 208, 245, 255);
/*struct nk_color subtext1 = nk_rgba(181, 191, 226, 255);*/
/*struct nk_color subtext0 = nk_rgba(165, 173, 206, 255);*/
struct nk_color overlay2 = nk_rgba(148, 156, 187, 255);
struct nk_color overlay1 = nk_rgba(131, 139, 167, 255);
struct nk_color overlay0 = nk_rgba(115, 121, 148, 255);
struct nk_color surface2 = nk_rgba(98, 104, 128, 255);
struct nk_color surface1 = nk_rgba(81, 87, 109, 255);
struct nk_color surface0 = nk_rgba(65, 69, 89, 255);
struct nk_color base = nk_rgba(48, 52, 70, 255);
struct nk_color mantle = nk_rgba(41, 44, 60, 255);
/*struct nk_color crust = nk_rgba(35, 38, 52, 255);*/
table[NK_COLOR_TEXT] = text;
table[NK_COLOR_WINDOW] = base;
table[NK_COLOR_HEADER] = mantle;
table[NK_COLOR_BORDER] = mantle;
table[NK_COLOR_BUTTON] = surface0;
table[NK_COLOR_BUTTON_HOVER] = overlay1;
table[NK_COLOR_BUTTON_ACTIVE] = overlay0;
table[NK_COLOR_TOGGLE] = surface2;
table[NK_COLOR_TOGGLE_HOVER] = overlay2;
table[NK_COLOR_TOGGLE_CURSOR] = pink;
table[NK_COLOR_SELECT] = surface0;
table[NK_COLOR_SELECT_ACTIVE] = overlay0;
table[NK_COLOR_SLIDER] = surface1;
table[NK_COLOR_SLIDER_CURSOR] = green;
table[NK_COLOR_SLIDER_CURSOR_HOVER] = green;
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = green;
table[NK_COLOR_PROPERTY] = surface0;
table[NK_COLOR_EDIT] = surface0;
table[NK_COLOR_EDIT_CURSOR] = pink;
table[NK_COLOR_COMBO] = surface0;
table[NK_COLOR_CHART] = surface0;
table[NK_COLOR_CHART_COLOR] = lavender;
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = pink;
table[NK_COLOR_SCROLLBAR] = surface0;
table[NK_COLOR_SCROLLBAR_CURSOR] = overlay0;
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = lavender;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = lavender;
table[NK_COLOR_TAB_HEADER] = surface0;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = pink;
table[NK_COLOR_KNOB_CURSOR_HOVER] = pink;
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = pink;
nk_style_from_table(ctx, table);
} else if (theme == THEME_CATPPUCCIN_MACCHIATO) {
/*struct nk_color rosewater = nk_rgba(244, 219, 214, 255);*/
/*struct nk_color flamingo = nk_rgba(240, 198, 198, 255);*/
struct nk_color pink = nk_rgba(245, 189, 230, 255);
/*struct nk_color mauve = nk_rgba(198, 160, 246, 255);*/
/*struct nk_color red = nk_rgba(237, 135, 150, 255);*/
/*struct nk_color maroon = nk_rgba(238, 153, 160, 255);*/
/*struct nk_color peach = nk_rgba(245, 169, 127, 255);*/
struct nk_color yellow = nk_rgba(238, 212, 159, 255);
struct nk_color green = nk_rgba(166, 218, 149, 255);
/*struct nk_color teal = nk_rgba(139, 213, 202, 255);*/
/*struct nk_color sky = nk_rgba(145, 215, 227, 255);*/
/*struct nk_color sapphire = nk_rgba(125, 196, 228, 255);*/
/*struct nk_color blue = nk_rgba(138, 173, 244, 255);*/
struct nk_color lavender = nk_rgba(183, 189, 248, 255);
struct nk_color text = nk_rgba(202, 211, 245, 255);
/*struct nk_color subtext1 = nk_rgba(184, 192, 224, 255);*/
/*struct nk_color subtext0 = nk_rgba(165, 173, 203, 255);*/
struct nk_color overlay2 = nk_rgba(147, 154, 183, 255);
struct nk_color overlay1 = nk_rgba(128, 135, 162, 255);
struct nk_color overlay0 = nk_rgba(110, 115, 141, 255);
struct nk_color surface2 = nk_rgba(91, 96, 120, 255);
struct nk_color surface1 = nk_rgba(73, 77, 100, 255);
struct nk_color surface0 = nk_rgba(54, 58, 79, 255);
struct nk_color base = nk_rgba(36, 39, 58, 255);
struct nk_color mantle = nk_rgba(30, 32, 48, 255);
/*struct nk_color crust = nk_rgba(24, 25, 38, 255);*/
table[NK_COLOR_TEXT] = text;
table[NK_COLOR_WINDOW] = base;
table[NK_COLOR_HEADER] = mantle;
table[NK_COLOR_BORDER] = mantle;
table[NK_COLOR_BUTTON] = surface0;
table[NK_COLOR_BUTTON_HOVER] = overlay1;
table[NK_COLOR_BUTTON_ACTIVE] = overlay0;
table[NK_COLOR_TOGGLE] = surface2;
table[NK_COLOR_TOGGLE_HOVER] = overlay2;
table[NK_COLOR_TOGGLE_CURSOR] = yellow;
table[NK_COLOR_SELECT] = surface0;
table[NK_COLOR_SELECT_ACTIVE] = overlay0;
table[NK_COLOR_SLIDER] = surface1;
table[NK_COLOR_SLIDER_CURSOR] = green;
table[NK_COLOR_SLIDER_CURSOR_HOVER] = green;
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = green;
table[NK_COLOR_PROPERTY] = surface0;
table[NK_COLOR_EDIT] = surface0;
table[NK_COLOR_EDIT_CURSOR] = pink;
table[NK_COLOR_COMBO] = surface0;
table[NK_COLOR_CHART] = surface0;
table[NK_COLOR_CHART_COLOR] = lavender;
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = yellow;
table[NK_COLOR_SCROLLBAR] = surface0;
table[NK_COLOR_SCROLLBAR_CURSOR] = overlay0;
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = lavender;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = lavender;
table[NK_COLOR_TAB_HEADER] = surface0;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = pink;
table[NK_COLOR_KNOB_CURSOR_HOVER] = pink;
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = pink;
nk_style_from_table(ctx, table);
} else if (theme == THEME_CATPPUCCIN_MOCHA) {
/*struct nk_color rosewater = nk_rgba(245, 224, 220, 255);*/
/*struct nk_color flamingo = nk_rgba(242, 205, 205, 255);*/
struct nk_color pink = nk_rgba(245, 194, 231, 255);
/*struct nk_color mauve = nk_rgba(203, 166, 247, 255);*/
/*struct nk_color red = nk_rgba(243, 139, 168, 255);*/
/*struct nk_color maroon = nk_rgba(235, 160, 172, 255);*/
/*struct nk_color peach = nk_rgba(250, 179, 135, 255);*/
/*struct nk_color yellow = nk_rgba(249, 226, 175, 255);*/
struct nk_color green = nk_rgba(166, 227, 161, 255);
/*struct nk_color teal = nk_rgba(148, 226, 213, 255);*/
/*struct nk_color sky = nk_rgba(137, 220, 235, 255);*/
/*struct nk_color sapphire = nk_rgba(116, 199, 236, 255);*/
/*struct nk_color blue = nk_rgba(137, 180, 250, 255);*/
struct nk_color lavender = nk_rgba(180, 190, 254, 255);
struct nk_color text = nk_rgba(205, 214, 244, 255);
/*struct nk_color subtext1 = nk_rgba(186, 194, 222, 255);*/
/*struct nk_color subtext0 = nk_rgba(166, 173, 200, 255);*/
struct nk_color overlay2 = nk_rgba(147, 153, 178, 255);
struct nk_color overlay1 = nk_rgba(127, 132, 156, 255);
struct nk_color overlay0 = nk_rgba(108, 112, 134, 255);
struct nk_color surface2 = nk_rgba(88, 91, 112, 255);
struct nk_color surface1 = nk_rgba(69, 71, 90, 255);
struct nk_color surface0 = nk_rgba(49, 50, 68, 255);
struct nk_color base = nk_rgba(30, 30, 46, 255);
struct nk_color mantle = nk_rgba(24, 24, 37, 255);
/*struct nk_color crust = nk_rgba(17, 17, 27, 255);*/
table[NK_COLOR_TEXT] = text;
table[NK_COLOR_WINDOW] = base;
table[NK_COLOR_HEADER] = mantle;
table[NK_COLOR_BORDER] = mantle;
table[NK_COLOR_BUTTON] = surface0;
table[NK_COLOR_BUTTON_HOVER] = overlay1;
table[NK_COLOR_BUTTON_ACTIVE] = overlay0;
table[NK_COLOR_TOGGLE] = surface2;
table[NK_COLOR_TOGGLE_HOVER] = overlay2;
table[NK_COLOR_TOGGLE_CURSOR] = lavender;
table[NK_COLOR_SELECT] = surface0;
table[NK_COLOR_SELECT_ACTIVE] = overlay0;
table[NK_COLOR_SLIDER] = surface1;
table[NK_COLOR_SLIDER_CURSOR] = green;
table[NK_COLOR_SLIDER_CURSOR_HOVER] = green;
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = green;
table[NK_COLOR_PROPERTY] = surface0;
table[NK_COLOR_EDIT] = surface0;
table[NK_COLOR_EDIT_CURSOR] = lavender;
table[NK_COLOR_COMBO] = surface0;
table[NK_COLOR_CHART] = surface0;
table[NK_COLOR_CHART_COLOR] = lavender;
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = pink;
table[NK_COLOR_SCROLLBAR] = surface0;
table[NK_COLOR_SCROLLBAR_CURSOR] = overlay0;
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = lavender;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = pink;
table[NK_COLOR_TAB_HEADER] = surface0;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = pink;
table[NK_COLOR_KNOB_CURSOR_HOVER] = pink;
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = pink;
nk_style_from_table(ctx, table);
} else {
nk_style_default(ctx);
}
}

View File

@ -208,20 +208,6 @@ int main(void)
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle)*/;}
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{

View File

@ -239,6 +239,14 @@ nk_d3d11_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
nk_input_key(&d3d11.ctx, NK_KEY_TAB, down);
return 1;
case VK_UP:
nk_input_key(&d3d11.ctx, NK_KEY_UP, down);
return 1;
case VK_DOWN:
nk_input_key(&d3d11.ctx, NK_KEY_DOWN, down);
return 1;
case VK_LEFT:
if (ctrl)
nk_input_key(&d3d11.ctx, NK_KEY_TEXT_WORD_LEFT, down);
@ -275,6 +283,20 @@ nk_d3d11_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
nk_input_key(&d3d11.ctx, NK_KEY_SCROLL_UP, down);
return 1;
case 'B':
if (ctrl) {
nk_input_key(&d3d11.ctx, NK_KEY_TEXT_LINE_START, down);
return 1;
}
break;
case 'E':
if (ctrl) {
nk_input_key(&d3d11.ctx, NK_KEY_TEXT_LINE_END, down);
return 1;
}
break;
case 'C':
if (ctrl) {
nk_input_key(&d3d11.ctx, NK_KEY_COPY, down);

View File

@ -300,20 +300,6 @@ int main(void)
/* Now we can cleanup all resources consumed by font stashing that are no longer used */
nk_d3d12_font_stash_cleanup();
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{

View File

@ -214,20 +214,6 @@ int main(void)
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle)*/;}
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{

View File

@ -113,20 +113,6 @@ int main(void)
font = nk_gdifont_create("Arial", 14);
ctx = nk_gdi_init(font, dc, WINDOW_WIDTH, WINDOW_HEIGHT);
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
while (running)
{
/* Input */

View File

@ -109,20 +109,6 @@ int main(void)
font = nk_gdipfont_create("Arial", 12);
nk_gdip_set_font(font);
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
while (running)
{
/* Input */

View File

@ -40,7 +40,7 @@
/* #define INCLUDE_ALL */
/* #define INCLUDE_STYLE */
/* #define INCLUDE_CALCULATOR */
#define INCLUDE_CANVAS
/* #define INCLUDE_CANVAS */
/* #define INCLUDE_FILE_BROWSER */
/* #define INCLUDE_OVERVIEW */
/* #define INCLUDE_NODE_EDITOR */
@ -49,6 +49,7 @@
#define INCLUDE_STYLE
#define INCLUDE_CALCULATOR
#define INCLUDE_CANVAS
#define INCLUDE_FILE_BROWSER
#define INCLUDE_OVERVIEW
#define INCLUDE_NODE_EDITOR
#endif
@ -120,19 +121,6 @@ int main(void)
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle);*/}
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
#ifdef INCLUDE_FILE_BROWSER

View File

@ -79,6 +79,7 @@ static struct nk_glfw {
double last_button_click;
int is_double_click_down;
struct nk_vec2 double_click_pos;
float delta_time_seconds_last;
} glfw;
NK_INTERN void
@ -273,6 +274,8 @@ nk_glfw3_init(GLFWwindow *win, enum nk_glfw_init_state init_state)
glfw.is_double_click_down = nk_false;
glfw.double_click_pos = nk_vec2(0, 0);
glfw.delta_time_seconds_last = (float)glfwGetTime();
return &glfw.ctx;
}
@ -303,6 +306,11 @@ nk_glfw3_new_frame(void)
struct nk_context *ctx = &glfw.ctx;
struct GLFWwindow *win = glfw.win;
/* update the timer */
float delta_time_now = (float)glfwGetTime();
glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last;
glfw.delta_time_seconds_last = delta_time_now;
glfwGetWindowSize(win, &glfw.width, &glfw.height);
glfwGetFramebufferSize(win, &glfw.display_width, &glfw.display_height);
glfw.fb_scale.x = (float)glfw.display_width/(float)glfw.width;
@ -350,7 +358,6 @@ nk_glfw3_new_frame(void)
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);

View File

@ -42,7 +42,7 @@
/*#define INCLUDE_STYLE */
/*#define INCLUDE_CALCULATOR */
/*#define INCLUDE_CANVAS */
#define INCLUDE_OVERVIEW
/*#define INCLUDE_OVERVIEW */
/*#define INCLUDE_NODE_EDITOR */
#ifdef INCLUDE_ALL
@ -125,19 +125,6 @@ int main(void)
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle);*/}
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (!glfwWindowShouldClose(win))
{

View File

@ -53,6 +53,7 @@ struct nk_glfw {
double last_button_click;
int is_double_click_down;
struct nk_vec2 double_click_pos;
float delta_time_seconds_last;
};
NK_API struct nk_context* nk_glfw3_init(struct nk_glfw* glfw, GLFWwindow *win, enum nk_glfw_init_state);
@ -314,7 +315,7 @@ nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing AA, int max_vertex_b
NK_API void
nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint)
{
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
struct nk_glfw* glfw = (struct nk_glfw *)glfwGetWindowUserPointer(win);
if (glfw->text_len < NK_GLFW_TEXT_MAX)
glfw->text[glfw->text_len++] = codepoint;
}
@ -322,7 +323,7 @@ nk_glfw3_char_callback(GLFWwindow *win, unsigned int codepoint)
NK_API void
nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff)
{
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
struct nk_glfw* glfw = (struct nk_glfw *)glfwGetWindowUserPointer(win);
(void)xoff;
glfw->scroll.x += (float)xoff;
glfw->scroll.y += (float)yoff;
@ -331,7 +332,7 @@ nk_gflw3_scroll_callback(GLFWwindow *win, double xoff, double yoff)
NK_API void
nk_glfw3_mouse_button_callback(GLFWwindow* win, int button, int action, int mods)
{
struct nk_glfw* glfw = glfwGetWindowUserPointer(win);
struct nk_glfw* glfw = (struct nk_glfw *)glfwGetWindowUserPointer(win);
double x, y;
NK_UNUSED(mods);
if (button != GLFW_MOUSE_BUTTON_LEFT) return;
@ -389,6 +390,8 @@ nk_glfw3_init(struct nk_glfw* glfw, GLFWwindow *win, enum nk_glfw_init_state ini
glfw->is_double_click_down = nk_false;
glfw->double_click_pos = nk_vec2(0, 0);
glfw->delta_time_seconds_last = (float)glfwGetTime();
return &glfw->ctx;
}
@ -419,6 +422,11 @@ nk_glfw3_new_frame(struct nk_glfw* glfw)
struct nk_context *ctx = &glfw->ctx;
struct GLFWwindow *win = glfw->win;
/* update the timer */
float delta_time_now = (float)glfwGetTime();
glfw->ctx.delta_time_seconds = delta_time_now - glfw->delta_time_seconds_last;
glfw->delta_time_seconds_last = delta_time_now;
glfwGetWindowSize(win, &glfw->width, &glfw->height);
glfwGetFramebufferSize(win, &glfw->display_width, &glfw->display_height);
glfw->fb_scale.x = (float)glfw->display_width/(float)glfw->width;
@ -468,7 +476,6 @@ nk_glfw3_new_frame(struct nk_glfw* glfw)
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);

View File

@ -42,7 +42,7 @@
/*#define INCLUDE_STYLE */
/*#define INCLUDE_CALCULATOR */
/*#define INCLUDE_CANVAS */
#define INCLUDE_OVERVIEW
/*#define INCLUDE_OVERVIEW */
/*#define INCLUDE_NODE_EDITOR */
#ifdef INCLUDE_ALL
@ -125,19 +125,6 @@ int main(void)
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle);*/}
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
/* Create bindless texture.
* The index returned is not the opengl resource id.
* IF you need the GL resource id use: nk_glfw3_get_tex_ogl_id() */

View File

@ -619,7 +619,6 @@ nk_glfw3_new_frame(void)
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);

View File

@ -35,7 +35,7 @@
* ===============================================================*/
/* This are some code examples to provide a small overview of what can be
* done with this library. To try out an example uncomment the defines */
#define INCLUDE_ALL
/*#define INCLUDE_ALL */
/*#define INCLUDE_STYLE */
/*#define INCLUDE_CALCULATOR */
/*#define INCLUDE_CANVAS */
@ -139,8 +139,19 @@ struct vulkan_demo {
VkDeviceMemory demo_texture_memory;
VkFence render_fence;
bool framebuffer_resized;
};
static void glfw_framebuffer_resize_callback(GLFWwindow* window, int width, int height) {
struct vulkan_demo* demo;
(void)width;
(void)height;
demo = glfwGetWindowUserPointer(window);
demo->framebuffer_resized = true;
}
static void glfw_error_callback(int e, const char *d) {
fprintf(stderr, "Error %d: %s\n", e, d);
}
@ -299,7 +310,7 @@ bool create_instance(struct vulkan_demo *demo) {
if (i > 0) {
printf(", ");
}
printf(enabled_extensions[i]);
printf("%s\n", enabled_extensions[i]);
}
printf("\n");
for (i = 0; i < enabled_extension_count; i++) {
@ -1227,8 +1238,8 @@ bool create_graphics_pipeline(struct vulkan_demo *demo) {
bool ret = false;
char *vert_shader_code = NULL;
char *frag_shader_code = NULL;
VkShaderModule vert_shader_module;
VkShaderModule frag_shader_module;
VkShaderModule vert_shader_module = VK_NULL_HANDLE;
VkShaderModule frag_shader_module = VK_NULL_HANDLE;
FILE *fp;
size_t file_len;
VkPipelineShaderStageCreateInfo vert_shader_stage_info;
@ -1246,8 +1257,9 @@ bool create_graphics_pipeline(struct vulkan_demo *demo) {
VkPipelineLayoutCreateInfo pipeline_layout_info;
VkResult result;
VkGraphicsPipelineCreateInfo pipeline_info;
size_t read_result;
fp = fopen("shaders/demo.vert.spv", "r");
fp = fopen("shaders/demo.vert.spv", "rb");
if (!fp) {
fprintf(stderr, "Couldn't open shaders/demo.vert.spv\n");
return false;
@ -1256,15 +1268,19 @@ bool create_graphics_pipeline(struct vulkan_demo *demo) {
file_len = ftell(fp);
vert_shader_code = malloc(file_len);
fseek(fp, 0, 0);
fread(vert_shader_code, 1, file_len, fp);
read_result = fread(vert_shader_code, file_len, 1, fp);
fclose(fp);
if (read_result != 1) {
fprintf(stderr, "Could not read fragment shader\n");
goto cleanup;
}
if (!create_shader_module(demo->device, vert_shader_code, file_len,
&vert_shader_module)) {
goto cleanup;
}
fp = fopen("shaders/demo.frag.spv", "r");
fp = fopen("shaders/demo.frag.spv", "rb");
if (!fp) {
fprintf(stderr, "Couldn't open shaders/demo.frag.spv\n");
return false;
@ -1273,8 +1289,12 @@ bool create_graphics_pipeline(struct vulkan_demo *demo) {
file_len = ftell(fp);
frag_shader_code = malloc(file_len);
fseek(fp, 0, 0);
fread(frag_shader_code, 1, file_len, fp);
read_result = fread(frag_shader_code, file_len, 1, fp);
fclose(fp);
if (read_result != 1) {
fprintf(stderr, "Could not read fragment shader\n");
goto cleanup;
}
if (!create_shader_module(demo->device, frag_shader_code, file_len,
&frag_shader_module)) {
@ -1862,6 +1882,8 @@ bool create_vulkan_demo(struct vulkan_demo *demo) {
return false;
}
demo->framebuffer_resized = false;
return true;
}
@ -1876,6 +1898,9 @@ bool recreate_swap_chain(struct vulkan_demo *demo) {
update_descriptor_sets(demo);
nk_glfw3_resize(demo->swap_chain_image_extent.width,
demo->swap_chain_image_extent.height);
demo->framebuffer_resized = false;
return true;
}
@ -1961,7 +1986,7 @@ bool render(struct vulkan_demo *demo, struct nk_colorf *bg,
result = vkQueuePresentKHR(demo->present_queue, &present_info);
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) {
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || demo->framebuffer_resized) {
recreate_swap_chain(demo);
} else if (result != VK_SUCCESS) {
fprintf(stderr, "vkQueuePresentKHR failed: %d\n", result);
@ -2073,6 +2098,8 @@ int main(void) {
memset(&demo, 0, sizeof(struct vulkan_demo));
demo.win =
glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL);
glfwSetWindowUserPointer(demo.win, &demo);
glfwSetFramebufferSizeCallback(demo.win, glfw_framebuffer_resize_callback);
if (!create_vulkan_demo(&demo)) {
fprintf(stderr, "failed to create vulkan demo!\n");
@ -2104,20 +2131,6 @@ int main(void) {
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle);*/}
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for
* anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
img = nk_image_ptr(demo.demo_texture_image_view);
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (!glfwWindowShouldClose(demo.win)) {
@ -2206,6 +2219,10 @@ int main(void) {
demo.image_available, NULL, &image_index);
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
recreate_swap_chain(&demo);
/* If vkAcquireNextImageKHR does not successfully acquire an image,
* semaphore and fence are unaffected. */
continue;
}
if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) {

View File

@ -372,13 +372,13 @@ static struct nk_glfw {
struct nk_glfw_device vulkan;
struct nk_context ctx;
struct nk_font_atlas atlas;
struct nk_vec2 fb_scale;
unsigned int text[NK_GLFW_TEXT_MAX];
int text_len;
struct nk_vec2 scroll;
double last_button_click;
int is_double_click_down;
struct nk_vec2 double_click_pos;
float delta_time_seconds_last;
} glfw;
struct Mat4f {
@ -1178,8 +1178,6 @@ NK_API void nk_glfw3_resize(uint32_t framebuffer_width,
struct nk_glfw_device *dev = &glfw.vulkan;
glfwGetWindowSize(glfw.win, &glfw.width, &glfw.height);
glfwGetFramebufferSize(glfw.win, &glfw.display_width, &glfw.display_height);
glfw.fb_scale.x = (float)glfw.display_width / (float)glfw.width;
glfw.fb_scale.y = (float)glfw.display_height / (float)glfw.height;
nk_glfw3_destroy_render_resources(dev);
nk_glfw3_create_render_resources(dev, framebuffer_width,
@ -1254,11 +1252,16 @@ NK_API void nk_glfw3_new_frame(void) {
struct nk_context *ctx = &glfw.ctx;
struct GLFWwindow *win = glfw.win;
/* update the timer */
float delta_time_now = (float)glfwGetTime();
glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last;
glfw.delta_time_seconds_last = delta_time_now;
nk_input_begin(ctx);
for (i = 0; i < glfw.text_len; ++i)
nk_input_unicode(ctx, glfw.text[i]);
#ifdef NK_GLFW_GL4_MOUSE_GRABBING
#ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
/* optional grabbing behavior */
if (ctx->input.mouse.grab)
glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
@ -1322,12 +1325,11 @@ NK_API void nk_glfw3_new_frame(void) {
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);
nk_input_motion(ctx, (int)x, (int)y);
#ifdef NK_GLFW_GL4_MOUSE_GRABBING
#ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
if (ctx->input.mouse.grabbed) {
glfwSetCursorPos(glfw.win, ctx->input.mouse.prev.x,
ctx->input.mouse.prev.y);

View File

@ -24,6 +24,7 @@ unsigned char nuklearshaders_nuklear_frag_spv[] = {};
unsigned int nuklearshaders_nuklear_frag_spv_len = 0;
// NUKLEAR_SHADERS_END
#include <assert.h>
#include <stddef.h>
#include <string.h>
#define GLFW_INCLUDE_VULKAN
@ -71,7 +72,6 @@ NK_API void nk_glfw3_mouse_button_callback(GLFWwindow *win, int button,
*/
#ifdef NK_GLFW_VULKAN_IMPLEMENTATION
#undef NK_GLFW_VULKAN_IMPLEMENTATION
#include <assert.h>
#include <stdlib.h>
#ifndef NK_GLFW_TEXT_MAX
@ -149,13 +149,13 @@ static struct nk_glfw {
struct nk_glfw_device vulkan;
struct nk_context ctx;
struct nk_font_atlas atlas;
struct nk_vec2 fb_scale;
unsigned int text[NK_GLFW_TEXT_MAX];
int text_len;
struct nk_vec2 scroll;
double last_button_click;
int is_double_click_down;
struct nk_vec2 double_click_pos;
float delta_time_seconds_last;
} glfw;
struct Mat4f {
@ -955,8 +955,6 @@ NK_API void nk_glfw3_resize(uint32_t framebuffer_width,
struct nk_glfw_device *dev = &glfw.vulkan;
glfwGetWindowSize(glfw.win, &glfw.width, &glfw.height);
glfwGetFramebufferSize(glfw.win, &glfw.display_width, &glfw.display_height);
glfw.fb_scale.x = (float)glfw.display_width / (float)glfw.width;
glfw.fb_scale.y = (float)glfw.display_height / (float)glfw.height;
nk_glfw3_destroy_render_resources(dev);
nk_glfw3_create_render_resources(dev, framebuffer_width,
@ -1031,11 +1029,16 @@ NK_API void nk_glfw3_new_frame(void) {
struct nk_context *ctx = &glfw.ctx;
struct GLFWwindow *win = glfw.win;
/* update the timer */
float delta_time_now = (float)glfwGetTime();
glfw.ctx.delta_time_seconds = delta_time_now - glfw.delta_time_seconds_last;
glfw.delta_time_seconds_last = delta_time_now;
nk_input_begin(ctx);
for (i = 0; i < glfw.text_len; ++i)
nk_input_unicode(ctx, glfw.text[i]);
#ifdef NK_GLFW_GL4_MOUSE_GRABBING
#ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
/* optional grabbing behavior */
if (ctx->input.mouse.grab)
glfwSetInputMode(glfw.win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
@ -1099,12 +1102,11 @@ NK_API void nk_glfw3_new_frame(void) {
nk_input_key(ctx, NK_KEY_COPY, 0);
nk_input_key(ctx, NK_KEY_PASTE, 0);
nk_input_key(ctx, NK_KEY_CUT, 0);
nk_input_key(ctx, NK_KEY_SHIFT, 0);
}
glfwGetCursorPos(win, &x, &y);
nk_input_motion(ctx, (int)x, (int)y);
#ifdef NK_GLFW_GL4_MOUSE_GRABBING
#ifdef NK_GLFW_VULKAN_MOUSE_GRABBING
if (ctx->input.mouse.grabbed) {
glfwSetCursorPos(glfw.win, ctx->input.mouse.prev.x,
ctx->input.mouse.prev.y);

View File

@ -28,23 +28,23 @@
*
* ===============================================================
*/
#ifndef NK_RAWFB_H_
#define NK_RAWFB_H_
struct rawfb_context;
typedef enum rawfb_pixel_layout {
PIXEL_LAYOUT_XRGB_8888,
PIXEL_LAYOUT_RGBX_8888
}
rawfb_pl;
struct rawfb_pl {
unsigned char bytesPerPixel;
unsigned char rshift, gshift, bshift, ashift;
unsigned char rloss, gloss, bloss, aloss;
};
/* All functions are thread-safe */
NK_API struct rawfb_context *nk_rawfb_init(void *fb, void *tex_mem, const unsigned int w, const unsigned int h, const unsigned int pitch, const rawfb_pl pl);
NK_API struct rawfb_context *nk_rawfb_init(void *fb, void *tex_mem, const unsigned int w, const unsigned int h, const unsigned int pitch, const struct rawfb_pl pl);
NK_API void nk_rawfb_render(const struct rawfb_context *rawfb, const struct nk_color clear, const unsigned char enable_clear);
NK_API void nk_rawfb_shutdown(struct rawfb_context *rawfb);
NK_API void nk_rawfb_resize_fb(struct rawfb_context *rawfb, void *fb, const unsigned int w, const unsigned int h, const unsigned int pitch, const rawfb_pl pl);
NK_API void nk_rawfb_resize_fb(struct rawfb_context *rawfb, void *fb, const unsigned int w, const unsigned int h, const unsigned int pitch, const struct rawfb_pl pl);
#endif
/*
@ -62,8 +62,7 @@ NK_API void nk_rawfb_resize_fb(struct rawfb_context *rawfb, voi
struct rawfb_image {
void *pixels;
int w, h, pitch;
rawfb_pl pl;
enum nk_font_atlas_format format;
struct rawfb_pl pl;
};
struct rawfb_context {
struct nk_context ctx;
@ -81,54 +80,28 @@ struct rawfb_context {
#endif
static unsigned int
nk_rawfb_color2int(const struct nk_color c, rawfb_pl pl)
nk_rawfb_color2int(const struct nk_color c, const struct rawfb_pl pl)
{
unsigned int res = 0;
switch (pl) {
case PIXEL_LAYOUT_RGBX_8888:
res |= c.r << 24;
res |= c.g << 16;
res |= c.b << 8;
res |= c.a;
break;
case PIXEL_LAYOUT_XRGB_8888:
res |= c.a << 24;
res |= c.r << 16;
res |= c.g << 8;
res |= c.b;
break;
res |= (c.r >> pl.rloss) << pl.rshift;
res |= (c.g >> pl.gloss) << pl.gshift;
res |= (c.b >> pl.bloss) << pl.bshift;
res |= (c.a >> pl.aloss) << pl.ashift;
default:
perror("nk_rawfb_color2int(): Unsupported pixel layout.\n");
break;
}
return (res);
}
static struct nk_color
nk_rawfb_int2color(const unsigned int i, rawfb_pl pl)
nk_rawfb_int2color(const unsigned int i, const struct rawfb_pl pl)
{
struct nk_color col = {0,0,0,0};
switch (pl) {
case PIXEL_LAYOUT_RGBX_8888:
col.r = (i >> 24) & 0xff;
col.g = (i >> 16) & 0xff;
col.b = (i >> 8) & 0xff;
col.a = i & 0xff;
break;
case PIXEL_LAYOUT_XRGB_8888:
col.a = (i >> 24) & 0xff;
col.r = (i >> 16) & 0xff;
col.g = (i >> 8) & 0xff;
col.b = i & 0xff;
break;
col.r = (pl.rloss == 8) ? 0xff : ((i >> pl.rshift) << pl.rloss) & 0xff;
col.g = (pl.gloss == 8) ? 0xff : ((i >> pl.gshift) << pl.gloss) & 0xff;
col.b = (pl.bloss == 8) ? 0xff : ((i >> pl.bshift) << pl.bloss) & 0xff;
col.a = (pl.aloss == 8) ? 0xff : ((i >> pl.ashift) << pl.aloss) & 0xff;
default:
perror("nk_rawfb_int2color(): Unsupported pixel layout.\n");
break;
}
return col;
}
@ -138,14 +111,20 @@ nk_rawfb_ctx_setpixel(const struct rawfb_context *rawfb,
{
unsigned int c = nk_rawfb_color2int(col, rawfb->fb.pl);
unsigned char *pixels = rawfb->fb.pixels;
unsigned int *ptr;
pixels += y0 * rawfb->fb.pitch;
ptr = (unsigned int *)pixels + x0;
if (y0 < rawfb->scissors.h && y0 >= rawfb->scissors.y &&
x0 >= rawfb->scissors.x && x0 < rawfb->scissors.w)
*ptr = c;
x0 >= rawfb->scissors.x && x0 < rawfb->scissors.w) {
if (rawfb->fb.pl.bytesPerPixel == sizeof(unsigned int)) {
*((unsigned int *)pixels + x0) = c;
} else if (rawfb->fb.pl.bytesPerPixel == sizeof(unsigned short)) {
*((unsigned short *)pixels + x0) = c;
} else {
*((unsigned char *)pixels + x0) = c;
}
}
}
static void
@ -156,22 +135,29 @@ nk_rawfb_line_horizontal(const struct rawfb_context *rawfb,
* It does not check for scissors or image borders.
* The caller has to make sure it does no exceed bounds. */
unsigned int i, n;
unsigned int c[16];
unsigned char c[16 * 4];
unsigned char *pixels = rawfb->fb.pixels;
unsigned int *ptr;
unsigned int bpp = rawfb->fb.pl.bytesPerPixel;
pixels += y * rawfb->fb.pitch;
ptr = (unsigned int *)pixels + x0;
pixels += (y * rawfb->fb.pitch) + (x0 * bpp);
n = x1 - x0;
for (i = 0; i < sizeof(c) / sizeof(c[0]); i++)
c[i] = nk_rawfb_color2int(col, rawfb->fb.pl);
n = (x1 - x0) * bpp;
if (bpp == sizeof(unsigned int)) {
for (i = 0; i < sizeof(c) / bpp; i++)
((unsigned int *)c)[i] = nk_rawfb_color2int(col, rawfb->fb.pl);
} else if (bpp == sizeof(unsigned short)) {
for (i = 0; i < sizeof(c) / bpp; i++)
((unsigned short *)c)[i] = nk_rawfb_color2int(col, rawfb->fb.pl);
} else {
for (i = 0; i < sizeof(c) / bpp; i++)
((unsigned char *)c)[i] = nk_rawfb_color2int(col, rawfb->fb.pl);
}
while (n > 16) {
memcpy((void *)ptr, c, sizeof(c));
n -= 16; ptr += 16;
while (n > sizeof(c)) {
memcpy((void*)pixels, c, sizeof(c));
n -= sizeof(c); pixels += sizeof(c);
} for (i = 0; i < n; i++)
ptr[i] = c[i];
pixels[i] = c[i];
}
static void
@ -180,16 +166,16 @@ nk_rawfb_img_setpixel(const struct rawfb_image *img,
{
unsigned int c = nk_rawfb_color2int(col, img->pl);
unsigned char *ptr;
unsigned int *pixel;
NK_ASSERT(img);
if (y0 < img->h && y0 >= 0 && x0 >= 0 && x0 < img->w) {
ptr = (unsigned char *)img->pixels + (img->pitch * y0);
pixel = (unsigned int *)ptr;
if (img->format == NK_FONT_ATLAS_ALPHA8) {
ptr[x0] = col.a;
if (img->pl.bytesPerPixel == sizeof(unsigned int)) {
((unsigned int *)ptr)[x0] = c;
} else if (img->pl.bytesPerPixel == sizeof(unsigned short)) {
((unsigned short *)ptr)[x0] = c;
} else {
pixel[x0] = c;
((unsigned char *)ptr)[x0] = c;
}
}
}
@ -204,12 +190,15 @@ nk_rawfb_img_getpixel(const struct rawfb_image *img, const int x0, const int y0)
if (y0 < img->h && y0 >= 0 && x0 >= 0 && x0 < img->w) {
ptr = (unsigned char *)img->pixels + (img->pitch * y0);
if (img->format == NK_FONT_ATLAS_ALPHA8) {
col.a = ptr[x0];
col.b = col.g = col.r = 0xff;
} else {
if (img->pl.bytesPerPixel == sizeof(unsigned int)) {
pixel = ((unsigned int *)ptr)[x0];
col = nk_rawfb_int2color(pixel, img->pl);
} else if (img->pl.bytesPerPixel == sizeof(unsigned short)) {
pixel = ((unsigned short *)ptr)[x0];
col = nk_rawfb_int2color(pixel, img->pl);
} else {
pixel = ((unsigned char *)ptr)[x0];
col = nk_rawfb_int2color(pixel, img->pl);
}
} return col;
}
@ -823,33 +812,34 @@ nk_rawfb_clear(const struct rawfb_context *rawfb, const struct nk_color col)
NK_API struct rawfb_context*
nk_rawfb_init(void *fb, void *tex_mem, const unsigned int w, const unsigned int h,
const unsigned int pitch, const rawfb_pl pl)
const unsigned int pitch, const struct rawfb_pl pl)
{
const void *tex;
struct rawfb_context *rawfb;
rawfb = malloc(sizeof(struct rawfb_context));
if (!rawfb)
return NULL;
memset(rawfb, 0, sizeof(struct rawfb_context));
rawfb->font_tex.pixels = tex_mem;
rawfb->font_tex.format = NK_FONT_ATLAS_ALPHA8;
rawfb->font_tex.w = rawfb->font_tex.h = 0;
rawfb->font_tex.pl.bytesPerPixel = 1;
rawfb->font_tex.pl.rshift = 0;
rawfb->font_tex.pl.gshift = 0;
rawfb->font_tex.pl.bshift = 0;
rawfb->font_tex.pl.ashift = 0;
rawfb->font_tex.pl.rloss = 8;
rawfb->font_tex.pl.gloss = 8;
rawfb->font_tex.pl.bloss = 8;
rawfb->font_tex.pl.aloss = 0;
rawfb->font_tex.w = rawfb->font_tex.h = rawfb->font_tex.pitch = 0;
rawfb->fb.pixels = fb;
rawfb->fb.w = w;
rawfb->fb.h = h;
rawfb->fb.pitch = pitch;
rawfb->fb.pl = pl;
if (pl == PIXEL_LAYOUT_RGBX_8888 || pl == PIXEL_LAYOUT_XRGB_8888) {
rawfb->fb.format = NK_FONT_ATLAS_RGBA32;
rawfb->fb.pitch = pitch;
} else {
perror("nk_rawfb_init(): Unsupported pixel layout.\n");
free(rawfb);
return NULL;
}
if (0 == nk_init_default(&rawfb->ctx, 0)) {
free(rawfb);
return NULL;
@ -857,21 +847,13 @@ nk_rawfb_init(void *fb, void *tex_mem, const unsigned int w, const unsigned int
nk_font_atlas_init_default(&rawfb->atlas);
nk_font_atlas_begin(&rawfb->atlas);
tex = nk_font_atlas_bake(&rawfb->atlas, &rawfb->font_tex.w, &rawfb->font_tex.h, rawfb->font_tex.format);
tex = nk_font_atlas_bake(&rawfb->atlas, &rawfb->font_tex.w, &rawfb->font_tex.h, NK_FONT_ATLAS_ALPHA8);
if (!tex) {
free(rawfb);
return NULL;
}
switch(rawfb->font_tex.format) {
case NK_FONT_ATLAS_ALPHA8:
rawfb->font_tex.pitch = rawfb->font_tex.w * 1;
break;
case NK_FONT_ATLAS_RGBA32:
rawfb->font_tex.pitch = rawfb->font_tex.w * 4;
break;
};
/* Store the font texture in tex scratch memory */
rawfb->font_tex.pitch = rawfb->font_tex.w * 1;
memcpy(rawfb->font_tex.pixels, tex, rawfb->font_tex.pitch * rawfb->font_tex.h);
nk_font_atlas_end(&rawfb->atlas, nk_handle_ptr(NULL), NULL);
if (rawfb->atlas.default_font)
@ -1036,7 +1018,7 @@ nk_rawfb_resize_fb(struct rawfb_context *rawfb,
const unsigned int w,
const unsigned int h,
const unsigned int pitch,
const rawfb_pl pl)
const struct rawfb_pl pl)
{
rawfb->fb.w = w;
rawfb->fb.h = h;
@ -1051,6 +1033,7 @@ nk_rawfb_render(const struct rawfb_context *rawfb,
const unsigned char enable_clear)
{
const struct nk_command *cmd;
if (enable_clear)
nk_rawfb_clear(rawfb, clear);

View File

@ -2,7 +2,7 @@ CFLAGS=`sdl2-config --cflags --libs` -std=c89 -Wall -Wextra -pedantic -Wno-unu
.PHONY: clean
demo: main.c nuklear_sdl_rawfb.h
demo: main.c ../nuklear_rawfb.h
$(CC) -o demo *.c $(CFLAGS) -lrt -lm
clean:

View File

@ -20,7 +20,7 @@
#define NK_INCLUDE_SOFTWARE_FONT
#include "../../../nuklear.h"
#define NK_RAWFB_IMPLEMENTATION
#include "nuklear_sdl_rawfb.h"
#include "../nuklear_rawfb.h"
/* ===============================================================
*
@ -132,6 +132,8 @@ int main(int argc, char **argv)
struct nk_vec2 vec;
struct nk_rect bounds = {40,40,0,0};
struct rawfb_context *context;
struct rawfb_pl pl;
unsigned char tex_scratch[512 * 512];
SDL_DisplayMode dm;
SDL_Window *window;
@ -164,8 +166,17 @@ int main(int argc, char **argv)
surface = SDL_CreateRGBSurfaceWithFormat(0, dm.w-200, dm.h-200, 32, SDL_PIXELFORMAT_ARGB8888);
pl.bytesPerPixel = surface->format->BytesPerPixel;
pl.rshift = surface->format->Rshift;
pl.gshift = surface->format->Gshift;
pl.bshift = surface->format->Bshift;
pl.ashift = surface->format->Ashift;
pl.rloss = surface->format->Rloss;
pl.gloss = surface->format->Gloss;
pl.bloss = surface->format->Bloss;
pl.aloss = surface->format->Aloss;
context = nk_rawfb_init(surface, 13.0f);
context = nk_rawfb_init(surface->pixels, tex_scratch, surface->w, surface->h, surface->pitch, pl);
while(1)

File diff suppressed because it is too large Load Diff

View File

@ -450,6 +450,7 @@ int main ()
struct nk_wayland nk_wayland_ctx;
struct wl_registry *registry;
int running = 1;
struct rawfb_pl pl;
//1. Initialize display
nk_wayland_ctx.display = wl_display_connect (NULL);
@ -495,7 +496,17 @@ int main ()
wl_surface_attach (nk_wayland_ctx.surface, nk_wayland_ctx.front_buffer, 0, 0);
wl_surface_commit (nk_wayland_ctx.surface);
nk_rawfb_init(nk_wayland_ctx.data, nk_wayland_ctx.tex_scratch, WIDTH, HEIGHT, WIDTH*4, PIXEL_LAYOUT_XRGB_8888);
pl.bytesPerPixel = 4;
pl.ashift = 24;
pl.rshift = 16;
pl.gshift = 8;
pl.bshift = 0;
pl.aloss = 0;
pl.rloss = 0;
pl.gloss = 0;
pl.bloss = 0;
nk_rawfb_init(nk_wayland_ctx.data, nk_wayland_ctx.tex_scratch, WIDTH, HEIGHT, WIDTH*4, pl);
//4. rendering UI

View File

@ -1,5 +1,5 @@
# Install
BIN = zahnrad
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function -O2

View File

@ -156,7 +156,7 @@ main(void)
XWindow xw;
struct rawfb_context *rawfb;
void *fb = NULL;
rawfb_pl pl;
struct rawfb_pl pl;
unsigned char tex_scratch[512 * 512];
/* X11 */
@ -193,19 +193,6 @@ main(void)
rawfb = nk_rawfb_init(fb, tex_scratch, xw.width, xw.height, xw.width * 4, pl);
if (!rawfb) running = 0;
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(&rawfb->ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(&rawfb->ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(&rawfb->ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(&rawfb->ctx, THEME_DARK);
#endif
#endif
while (running) {
/* Input */
XEvent evt;

View File

@ -35,7 +35,7 @@
#include <X11/Xlib.h>
NK_API int nk_xlib_init(Display *dpy, Visual *vis, int screen, Window root, unsigned int w, unsigned int h, void **fb, rawfb_pl *pl);
NK_API int nk_xlib_init(Display *dpy, Visual *vis, int screen, Window root, unsigned int w, unsigned int h, void **fb, struct rawfb_pl *pl);
NK_API int nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt, struct rawfb_context *rawfb);
NK_API void nk_xlib_render(Drawable screen);
NK_API void nk_xlib_shutdown(void);
@ -74,7 +74,7 @@ static struct {
NK_API int
nk_xlib_init(Display *dpy, Visual *vis, int screen, Window root,
unsigned int w, unsigned int h, void **fb, rawfb_pl *pl)
unsigned int w, unsigned int h, void **fb, struct rawfb_pl *pl)
{
unsigned int depth = XDefaultDepth(dpy, screen);
xlib.dpy = dpy;
@ -138,22 +138,15 @@ nk_xlib_init(Display *dpy, Visual *vis, int screen, Window root,
xlib.gc = XDefaultGC(dpy, screen);
*fb = xlib.ximg->data;
if (xlib.ximg->red_mask == 0xff0000 &&
xlib.ximg->green_mask == 0xff00 &&
xlib.ximg->blue_mask == 0xff &&
xlib.ximg->bits_per_pixel == 32) {
*pl = PIXEL_LAYOUT_XRGB_8888;
}
else if (xlib.ximg->red_mask == 0xff000000 &&
xlib.ximg->green_mask == 0xff0000 &&
xlib.ximg->blue_mask == 0xff00 &&
xlib.ximg->bits_per_pixel == 32) {
*pl = PIXEL_LAYOUT_RGBX_8888;
}
else {
perror("nk_xlib_init(): Unrecognized pixel layout.\n");
return 0;
}
pl->bytesPerPixel = xlib.ximg->bits_per_pixel / 8;
pl->rshift = __builtin_ctzl(xlib.ximg->red_mask);
pl->gshift = __builtin_ctzl(xlib.ximg->green_mask);
pl->bshift = __builtin_ctzl(xlib.ximg->blue_mask);
pl->ashift = 0;
pl->rloss = 8 - __builtin_popcount(xlib.ximg->red_mask);
pl->gloss = 8 - __builtin_popcount(xlib.ximg->green_mask);
pl->bloss = 8 - __builtin_popcount(xlib.ximg->blue_mask);
pl->aloss = 8;
return 1;
}
@ -257,7 +250,7 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt, struct r
} else if (evt->type == Expose || evt->type == ConfigureNotify) {
/* Window resize handler */
void *fb;
rawfb_pl pl;
struct rawfb_pl pl;
unsigned int width, height;
XWindowAttributes attr;
XGetWindowAttributes(dpy, win, &attr);

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2 -DSDL_DISABLE_IMMINTRIN_H
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -34,7 +34,7 @@
* ===============================================================*/
/* This are some code examples to provide a small overview of what can be
* done with this library. To try out an example uncomment the defines */
/*#define INCLUDE_ALL */
#define INCLUDE_ALL
/*#define INCLUDE_STYLE */
/*#define INCLUDE_CALCULATOR */
/*#define INCLUDE_CANVAS */
@ -116,19 +116,6 @@ main(int argc, char *argv[])
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &roboto->handle)*/;}
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{

View File

@ -20,6 +20,7 @@ NK_API void nk_sdl_font_stash_end(void);
NK_API int nk_sdl_handle_event(SDL_Event *evt);
NK_API void nk_sdl_render(enum nk_anti_aliasing);
NK_API void nk_sdl_shutdown(void);
NK_API void nk_sdl_handle_grab(void);
#endif
/*
@ -50,6 +51,7 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
Uint64 time_of_last_frame;
} sdl;
NK_INTERN void
@ -73,6 +75,10 @@ nk_sdl_render(enum nk_anti_aliasing AA)
int display_width, display_height;
struct nk_vec2 scale;
Uint64 now = SDL_GetTicks64();
sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
sdl.time_of_last_frame = now;
SDL_GetWindowSize(sdl.win, &width, &height);
SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
scale.x = (float)display_width/(float)width;
@ -211,6 +217,7 @@ nk_sdl_init(SDL_Window *win)
sdl.ctx.clip.paste = nk_sdl_clipboard_paste;
sdl.ctx.clip.userdata = nk_handle_ptr(0);
nk_buffer_init_default(&sdl.ogl.cmds);
sdl.time_of_last_frame = SDL_GetTicks64();
return &sdl.ctx;
}

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2 -DSDL_DISABLE_IMMINTRIN_H
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -126,20 +126,6 @@ int main(int argc, char *argv[])
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &roboto->handle);*/}
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{

View File

@ -24,6 +24,7 @@ NK_API void nk_sdl_render(enum nk_anti_aliasing , int max_vertex
NK_API void nk_sdl_shutdown(void);
NK_API void nk_sdl_device_destroy(void);
NK_API void nk_sdl_device_create(void);
NK_API void nk_sdl_handle_grab(void);
#endif
@ -66,6 +67,7 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
Uint64 time_of_last_frame;
} sdl;
#ifdef __APPLE__
@ -191,11 +193,16 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
int display_width, display_height;
struct nk_vec2 scale;
GLfloat ortho[4][4] = {
{2.0f, 0.0f, 0.0f, 0.0f},
{0.0f,-2.0f, 0.0f, 0.0f},
{0.0f, 0.0f,-1.0f, 0.0f},
{-1.0f,1.0f, 0.0f, 1.0f},
{ 2.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, -2.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
Uint64 now = SDL_GetTicks64();
sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
sdl.time_of_last_frame = now;
SDL_GetWindowSize(sdl.win, &width, &height);
SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
ortho[0][0] /= (GLfloat)width;
@ -319,6 +326,7 @@ nk_sdl_init(SDL_Window *win)
sdl.ctx.clip.paste = nk_sdl_clipboard_paste;
sdl.ctx.clip.userdata = nk_handle_ptr(0);
nk_sdl_device_create();
sdl.time_of_last_frame = SDL_GetTicks64();
return &sdl.ctx;
}

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2 -DSDL_DISABLE_IMMINTRIN_H
SRC = main.c
OBJ = $(SRC:.c=.o)

View File

@ -209,20 +209,6 @@ int main(int argc, char* argv[])
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &roboto->handle)*/;}
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
emscripten_set_main_loop_arg(MainLoop, (void*)ctx, 0, nk_true);

View File

@ -27,6 +27,7 @@ NK_API void nk_sdl_render(enum nk_anti_aliasing , int max_vertex
NK_API void nk_sdl_shutdown(void);
NK_API void nk_sdl_device_destroy(void);
NK_API void nk_sdl_device_create(void);
NK_API void nk_sdl_handle_grab(void);
#endif
@ -70,6 +71,7 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
Uint64 time_of_last_frame;
} sdl;
@ -179,11 +181,16 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
int display_width, display_height;
struct nk_vec2 scale;
GLfloat ortho[4][4] = {
{2.0f, 0.0f, 0.0f, 0.0f},
{0.0f,-2.0f, 0.0f, 0.0f},
{0.0f, 0.0f,-1.0f, 0.0f},
{-1.0f,1.0f, 0.0f, 1.0f},
{ 2.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, -2.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
Uint64 now = SDL_GetTicks64();
sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
sdl.time_of_last_frame = now;
SDL_GetWindowSize(sdl.win, &width, &height);
SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
ortho[0][0] /= (GLfloat)width;
@ -319,6 +326,7 @@ nk_sdl_init(SDL_Window *win)
sdl.ctx.clip.paste = nk_sdl_clipboard_paste;
sdl.ctx.clip.userdata = nk_handle_ptr(0);
nk_sdl_device_create();
sdl.time_of_last_frame = SDL_GetTicks64();
return &sdl.ctx;
}

View File

@ -2,7 +2,7 @@
BIN = demo
# Flags
CFLAGS += -std=c89 -pedantic -O0
CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2 -DSDL_DISABLE_IMMINTRIN_H
CFLAGS += `sdl2-config --cflags`
SRC = main.c

View File

@ -36,6 +36,7 @@
/*#define INCLUDE_ALL */
/*#define INCLUDE_STYLE */
/*#define INCLUDE_CALCULATOR */
/*#define INCLUDE_CANVAS */
/*#define INCLUDE_OVERVIEW */
/*#define INCLUDE_NODE_EDITOR */
@ -154,19 +155,6 @@ main(int argc, char *argv[])
nk_style_set_font(ctx, &font->handle);
}
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{

View File

@ -11,13 +11,17 @@
#ifndef NK_SDL_RENDERER_H_
#define NK_SDL_RENDERER_H_
#include <SDL2/SDL.h>
#ifndef NK_SDL_RENDERER_SDL_H
#define NK_SDL_RENDERER_SDL_H <SDL.h>
#endif
#include NK_SDL_RENDERER_SDL_H
NK_API struct nk_context* nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer);
NK_API void nk_sdl_font_stash_begin(struct nk_font_atlas **atlas);
NK_API void nk_sdl_font_stash_end(void);
NK_API int nk_sdl_handle_event(SDL_Event *evt);
NK_API void nk_sdl_render(enum nk_anti_aliasing);
NK_API void nk_sdl_shutdown(void);
NK_API void nk_sdl_handle_grab(void);
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 22)
/* Metal API does not support cliprects with negative coordinates or large
@ -60,10 +64,9 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
Uint64 time_of_last_frame;
} sdl;
NK_INTERN void
nk_sdl_device_upload_atlas(const void *image, int width, int height)
{
@ -109,6 +112,11 @@ nk_sdl_render(enum nk_anti_aliasing AA)
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_sdl_vertex, col)},
{NK_VERTEX_LAYOUT_END}
};
Uint64 now = SDL_GetTicks64();
sdl.ctx.delta_time_seconds = (float)(now - sdl.time_of_last_frame) / 1000;
sdl.time_of_last_frame = now;
NK_MEMSET(&config, 0, sizeof(config));
config.vertex_layout = vertex_layout;
config.vertex_size = sizeof(struct nk_sdl_vertex);
@ -237,6 +245,7 @@ nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer)
#endif
sdl.win = win;
sdl.renderer = renderer;
sdl.time_of_last_frame = SDL_GetTicks64();
nk_init_default(&sdl.ctx, 0);
sdl.ctx.clip.copy = nk_sdl_clipboard_copy;
sdl.ctx.clip.paste = nk_sdl_clipboard_paste;

3
demo/sdl_vulkan/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
src/nuklearshaders/*.spv
src/nuklear_sdl_vulkan.h
shaders/*.spv

30
demo/sdl_vulkan/Makefile Normal file
View File

@ -0,0 +1,30 @@
# Install
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -fsanitize=address -O2
CFLAGS += -DSDL_DISABLE_IMMINTRIN_H
SRC = main.c
OBJ = $(SRC:.c=.o)
ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS = -lsdl2 -lvulkan -lm
else
UNAME_S := $(shell uname -s)
SDL2 := $(shell pkg-config --libs sdl2)
LIBS = $(SDL2) -lvulkan -lm
endif
$(BIN): shaders/demo.vert.spv shaders/demo.frag.spv
@mkdir -p bin
rm -f bin/$(BIN) $(OBJS)
$(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS)
shaders/demo.vert.spv: shaders/demo.vert
glslc --target-env=vulkan shaders/demo.vert -o shaders/demo.vert.spv
shaders/demo.frag.spv: shaders/demo.frag
glslc --target-env=vulkan shaders/demo.frag -o shaders/demo.frag.spv

52
demo/sdl_vulkan/README.md Normal file
View File

@ -0,0 +1,52 @@
# nuklear sdl vulkan
## Theory of operation
The nuklear SDL vulkan integration creates an independent graphics pipeline that will render the nuklear UI to separate render targets.
The application is responsible to fully manage these render targets. So it must ensure they are properly sized (and resized when requested).
Furthermore it is assumed that you will have a swap chain in place and the number of nuklear overlay images and number of swap chain images match.
This is how you can integrate it in your application:
```
/*
Setup: overlay_images have been created and their number match with the number
of the swap_chain_images of your application. The overlay_images in this
example have the same format as your swap_chain images (optional)
*/
struct nk_context *ctx = nk_sdl_init(
demo.win, demo.device, demo.physical_device, demo.indices.graphics,
demo.overlay_image_views, demo.swap_chain_images_len,
demo.swap_chain_image_format, 0,
MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
[...]
/*
in your draw loop draw you can then render to the overlay image at
`image_index`
your own application can then wait for the semaphore and produce
the swap_chain_image at `image_index`
this should simply sample from the overlay_image (see example)
*/
nk_semaphore semaphore =
nk_sdl_render(demo.graphics_queue, image_index,
demo.image_available, NK_ANTI_ALIASING_ON);
if (!render(&demo, &bg, nk_semaphore, image_index)) {
fprintf(stderr, "render failed\n");
return false;
}
```
You must call `nk_sdl_resize` whenever the size of the overlay_images resize.
## Using images
Images can be used by providing a VkImageView as an nk_image_ptr to nuklear:
```
img = nk_image_ptr(demo.demo_texture_image_view);
```
Note that they must have SHADER_READ_OPTIMAL layout
It is currently not possible to specify how they are being sampled. The nuklear SDL vulkan integration uses a fixed sampler that does linear filtering.

2251
demo/sdl_vulkan/main.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(binding = 0) uniform sampler2D overlay;
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec4 outColor;
void main() {
outColor = texture(overlay, inUV);
}

View File

@ -0,0 +1,10 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout (location = 0) out vec2 outUV;
void main()
{
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
gl_Position = vec4(outUV * 2.0f + -1.0f, 0.0f, 1.0f);
}

View File

@ -0,0 +1,11 @@
create_shader_inlined_header: nuklearshaders/nuklear.vert.spv nuklearshaders/nuklear.frag.spv
awk -v st='// NUKLEAR_SHADERS_START' -v et='// NUKLEAR_SHADERS_END' -v repl="$$(xxd -i nuklearshaders/nuklear.vert.spv && xxd -i nuklearshaders/nuklear.frag.spv)" '$$0 == st{del=1} $$0 == et{$$0 = repl; del=0} !del' nuklear_sdl_vulkan.in.h > nuklear_sdl_vulkan.h
nuklearshaders/nuklear.vert.spv: nuklearshaders/nuklear.vert
glslc --target-env=vulkan nuklearshaders/nuklear.vert -o nuklearshaders/nuklear.vert.spv
nuklearshaders/nuklear.frag.spv: nuklearshaders/nuklear.frag
glslc --target-env=vulkan nuklearshaders/nuklear.frag -o nuklearshaders/nuklear.frag.spv
clean:
rm nuklearshaders/nuklear.vert.spv nuklearshaders/nuklear.frag.spv nuklear_sdl_vulkan.h

View File

@ -0,0 +1,5 @@
Contrary to OpenGL Vulkan needs precompiled shaders in the SPIR-V format which makes it a bit more difficult to inline the shadercode.
After executing `make` the result should be a self contained `nuklear_sdl_vulkan.h`. Copy the result file to the parent directory and the "release" should be done.
You will need to have `xxd`, `glslc` and `awk` installed for this.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(binding = 0, set = 1) uniform sampler2D currentTexture;
layout(location = 0) in vec4 fragColor;
layout(location = 1) in vec2 fragUv;
layout(location = 0) out vec4 outColor;
void main() {
vec4 texColor = texture(currentTexture, fragUv);
outColor = fragColor * texColor;
}

View File

@ -0,0 +1,23 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
out gl_PerVertex {
vec4 gl_Position;
};
layout(binding = 0) uniform UniformBufferObject {
mat4 projection;
} ubo;
layout(location = 0) in vec2 position;
layout(location = 1) in vec2 uv;
layout(location = 2) in uvec4 color;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec2 fragUv;
void main() {
gl_Position = ubo.projection * vec4(position, 0.0, 1.0);
gl_Position.y = -gl_Position.y;
fragColor = vec4(color[0]/255.0, color[1]/255.0, color[2]/255.0, color[3]/255.0);
fragUv = uv;
}

View File

@ -96,20 +96,6 @@ int main(void)
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle);*/
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
struct nk_colorf bg;
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (win.isOpen())

View File

@ -14,6 +14,7 @@
#define NK_SFML_GL2_H_
#include <SFML/Window.hpp>
#include <SFML/System/Clock.hpp>
NK_API struct nk_context* nk_sfml_init(sf::Window* window);
NK_API void nk_sfml_font_stash_begin(struct nk_font_atlas** atlas);
@ -51,6 +52,7 @@ static struct nk_sfml {
struct nk_sfml_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
sf::Clock* frame_delta_clock;
} sfml;
NK_INTERN void
@ -74,6 +76,9 @@ nk_sfml_render(enum nk_anti_aliasing AA)
int window_width = sfml.window->getSize().x;
int window_height = sfml.window->getSize().y;
sfml.ctx.delta_time_seconds = (float)((double)sfml.frame_delta_clock->getElapsedTime().asMicroseconds() / 1000000);
sfml.frame_delta_clock->restart();
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
@ -229,6 +234,7 @@ nk_sfml_init(sf::Window* window)
sfml.ctx.clip.paste = nk_sfml_clipboard_paste;
sfml.ctx.clip.userdata = nk_handle_ptr(0);
nk_buffer_init_default(&sfml.ogl.cmds);
sfml.frame_delta_clock = new sf::Clock();
return &sfml.ctx;
}
@ -334,8 +340,8 @@ nk_sfml_handle_event(sf::Event* evt)
} else if(evt->type == sf::Event::TouchBegan || evt->type == sf::Event::TouchEnded) {
int down = evt->type == sf::Event::TouchBegan;
const int x = evt->touch.x, y = evt->touch.y;
ctx->input.mouse.pos.x = x;
ctx->input.mouse.pos.y = y;
ctx->input.mouse.pos.x = x;
ctx->input.mouse.pos.y = y;
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
return 1;
} else if(evt->type == sf::Event::TouchMoved) {
@ -363,6 +369,7 @@ void nk_sfml_shutdown(void)
nk_free(&sfml.ctx);
glDeleteTextures(1, &dev->font_tex);
nk_buffer_free(&dev->cmds);
delete sfml.frame_delta_clock;
memset(&sfml, 0, sizeof(sfml));
}

View File

@ -102,20 +102,6 @@ int main(void)
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle);*/
/* style.c */
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
struct nk_colorf bg;
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (win.isOpen())

View File

@ -66,6 +66,7 @@ static struct nk_sfml {
struct nk_sfml_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
sf::Clock* frame_delta_clock;
} sfml;
#ifdef __APPLE__
@ -197,11 +198,15 @@ nk_sfml_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_
int window_width = sfml.window->getSize().x;
int window_height = sfml.window->getSize().y;
GLfloat ortho[4][4] = {
{2.0f, 0.0f, 0.0f, 0.0f},
{0.0f,-2.0f, 0.0f, 0.0f},
{0.0f, 0.0f,-1.0f, 0.0f},
{-1.0f,1.0f, 0.0f, 1.0f},
{ 2.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, -2.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
sfml.ctx.delta_time_seconds = (float)((double)sfml.frame_delta_clock->getElapsedTime().asMicroseconds() / 1000000);
sfml.frame_delta_clock->restart();
ortho[0][0] /= (GLfloat)window_width;
ortho[1][1] /= (GLfloat)window_height;
@ -336,6 +341,7 @@ nk_sfml_init(sf::Window* window)
sfml.ctx.clip.paste = nk_sfml_clipboard_paste;
sfml.ctx.clip.userdata = nk_handle_ptr(0);
nk_sfml_device_create();
sfml.frame_delta_clock = new sf::Clock();
return &sfml.ctx;
}
@ -451,10 +457,10 @@ nk_sfml_handle_event(sf::Event* evt)
} else nk_input_motion(ctx, evt->touch.x, evt->touch.y);
return 1;
} else if(evt->type == sf::Event::TextEntered) {
/* 8 ~ backspace */
if (evt->text.unicode != 8) {
nk_input_unicode(ctx, evt->text.unicode);
}
/* 8 ~ backspace */
if (evt->text.unicode != 8) {
nk_input_unicode(ctx, evt->text.unicode);
}
return 1;
} else if(evt->type == sf::Event::MouseWheelScrolled) {
nk_input_scroll(ctx, nk_vec2(0,evt->mouseWheelScroll.delta));
@ -469,6 +475,7 @@ void nk_sfml_shutdown()
nk_font_atlas_clear(&sfml.atlas);
nk_free(&sfml.ctx);
nk_sfml_device_destroy();
delete sfml.frame_delta_clock;
memset(&sfml, 0, sizeof(sfml));
}

View File

@ -1,5 +1,5 @@
# Install
BIN = zahnrad
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function -O2

View File

@ -152,19 +152,6 @@ main(void)
xw.font = nk_xfont_create(xw.dpy, "fixed");
ctx = nk_xlib_init(xw.font, xw.dpy, xw.screen, xw.win, xw.width, xw.height);
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
while (running)
{
/* Input */

View File

@ -68,10 +68,10 @@ NK_API void nk_xfont_del(Display *dpy, XFont *font);
#ifndef NK_X11_DOUBLE_CLICK_LO
#define NK_X11_DOUBLE_CLICK_LO 20
#define NK_X11_DOUBLE_CLICK_LO 0.02
#endif
#ifndef NK_X11_DOUBLE_CLICK_HI
#define NK_X11_DOUBLE_CLICK_HI 200
#define NK_X11_DOUBLE_CLICK_HI 0.20
#endif
typedef struct XSurface XSurface;
@ -112,15 +112,16 @@ static struct {
Cursor cursor;
Display *dpy;
Window root;
long last_button_click;
double last_button_click;
double time_of_last_frame;
} xlib;
NK_INTERN long
nk_timestamp(void)
NK_INTERN double
nk_get_time(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) return 0;
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
return ((double)tv.tv_sec + (double)tv.tv_usec/1000000);
}
NK_INTERN unsigned long
@ -662,6 +663,7 @@ nk_xlib_init(XFont *xfont, Display *dpy, int screen, Window root,
xlib.surf = nk_xsurf_create(screen, w, h);
nk_init_default(&xlib.ctx, font);
xlib.time_of_last_frame = nk_get_time();
return &xlib.ctx;
}
@ -793,10 +795,10 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
const int x = evt->xbutton.x, y = evt->xbutton.y;
if (evt->xbutton.button == Button1) {
if (down) { /* Double-Click Button handler */
long dt = nk_timestamp() - xlib.last_button_click;
float dt = nk_get_time() - xlib.last_button_click;
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
xlib.last_button_click = nk_timestamp();
xlib.last_button_click = nk_get_time();
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
} else if (evt->xbutton.button == Button2)
@ -905,6 +907,10 @@ nk_xlib_render(Drawable screen, struct nk_color clear)
struct nk_context *ctx = &xlib.ctx;
XSurface *surf = xlib.surf;
double now = nk_get_time();
xlib.ctx.delta_time_seconds = now - xlib.time_of_last_frame;
xlib.time_of_last_frame = now;
nk_xsurf_clear(xlib.surf, nk_color_from_byte(&clear.r));
nk_foreach(cmd, &xlib.ctx)
{

View File

@ -2,7 +2,7 @@
BIN = demo
# Compiler
CC = clang
CC ?= clang
DCC = gcc
# Flags
@ -13,11 +13,11 @@ OBJ = $(SRC:.c=.o)
# Modes
.PHONY: gcc
gcc: CC = gcc
gcc: CC ?= gcc
gcc: $(BIN)
.PHONY: clang
clang: CC = clang
clang: CC ?= clang
clang: $(BIN)
$(BIN):

View File

@ -256,19 +256,6 @@ int main(void)
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle);*/}
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{

View File

@ -46,10 +46,10 @@ NK_API void nk_x11_shutdown(void);
#include <GL/gl.h>
#ifndef NK_X11_DOUBLE_CLICK_LO
#define NK_X11_DOUBLE_CLICK_LO 20
#define NK_X11_DOUBLE_CLICK_LO 0.02
#endif
#ifndef NK_X11_DOUBLE_CLICK_HI
#define NK_X11_DOUBLE_CLICK_HI 200
#define NK_X11_DOUBLE_CLICK_HI 0.20
#endif
struct nk_x11_vertex {
@ -71,15 +71,16 @@ static struct nk_x11 {
Cursor cursor;
Display *dpy;
Window win;
long last_button_click;
double last_button_click;
double time_of_last_frame;
} x11;
NK_INTERN long
nk_timestamp(void)
NK_INTERN double
nk_get_time(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) return 0;
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
return ((double)tv.tv_sec + (double)tv.tv_usec/1000000);
}
NK_INTERN void
@ -102,6 +103,10 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
int width, height;
XWindowAttributes attr;
double now = nk_get_time();
x11.ctx.delta_time_seconds = now - x11.time_of_last_frame;
x11.time_of_last_frame = now;
NK_UNUSED(max_vertex_buffer);
NK_UNUSED(max_element_buffer);
@ -311,10 +316,10 @@ nk_x11_handle_event(XEvent *evt)
const int x = evt->xbutton.x, y = evt->xbutton.y;
if (evt->xbutton.button == Button1) {
if (down) { /* Double-Click Button handler */
long dt = nk_timestamp() - x11.last_button_click;
float dt = nk_get_time() - x11.last_button_click;
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
x11.last_button_click = nk_timestamp();
x11.last_button_click = nk_get_time();
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
} else if (evt->xbutton.button == Button2)
@ -363,6 +368,7 @@ nk_x11_init(Display *dpy, Window win)
nk_buffer_init_default(&x11.ogl.cmds);
nk_init_default(&x11.ctx, 0);
x11.time_of_last_frame = nk_get_time();
return &x11.ctx;
}

View File

@ -2,7 +2,7 @@
BIN = demo
# Compiler
CC = clang
CC ?= clang
DCC = gcc
# Flags
@ -13,11 +13,11 @@ OBJ = $(SRC:.c=.o)
# Modes
.PHONY: gcc
gcc: CC = gcc
gcc: CC ?= gcc
gcc: $(BIN)
.PHONY: clang
clang: CC = clang
clang: CC ?= clang
clang: $(BIN)
$(BIN):

View File

@ -253,19 +253,6 @@ int main(void)
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle);*/}
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{

View File

@ -50,10 +50,10 @@ NK_API void nk_x11_device_destroy(void);
#include <GL/glx.h>
#ifndef NK_X11_DOUBLE_CLICK_LO
#define NK_X11_DOUBLE_CLICK_LO 20
#define NK_X11_DOUBLE_CLICK_LO 0.02
#endif
#ifndef NK_X11_DOUBLE_CLICK_HI
#define NK_X11_DOUBLE_CLICK_HI 200
#define NK_X11_DOUBLE_CLICK_HI 0.20
#endif
#ifdef NK_XLIB_LOAD_OPENGL_EXTENSIONS
@ -194,7 +194,8 @@ static struct nk_x11 {
Cursor cursor;
Display *dpy;
Window win;
long last_button_click;
double last_button_click;
double time_of_last_frame;
} x11;
#ifdef __APPLE__
@ -206,12 +207,12 @@ static struct nk_x11 {
#ifdef NK_XLIB_LOAD_OPENGL_EXTENSIONS
#include <GL/glx.h>
NK_INTERN long
nk_timestamp(void)
NK_INTERN double
nk_get_time(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) return 0;
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
return ((double)tv.tv_sec + (double)tv.tv_usec/1000000);
}
NK_INTERN int
@ -480,11 +481,15 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
XWindowAttributes attr;
struct nk_x11_device *dev = &x11.ogl;
GLfloat ortho[4][4] = {
{2.0f, 0.0f, 0.0f, 0.0f},
{0.0f,-2.0f, 0.0f, 0.0f},
{0.0f, 0.0f,-1.0f, 0.0f},
{-1.0f,1.0f, 0.0f, 1.0f},
{ 2.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, -2.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
double now = nk_get_time();
x11.ctx.delta_time_seconds = now - x11.time_of_last_frame;
x11.time_of_last_frame = now;
XGetWindowAttributes(x11.dpy, x11.win, &attr);
width = attr.width;
height = attr.height;
@ -678,10 +683,10 @@ nk_x11_handle_event(XEvent *evt)
const int x = evt->xbutton.x, y = evt->xbutton.y;
if (evt->xbutton.button == Button1) {
if (down) { /* Double-Click Button handler */
long dt = nk_timestamp() - x11.last_button_click;
float dt = nk_get_time() - x11.last_button_click;
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
x11.last_button_click = nk_timestamp();
x11.last_button_click = nk_get_time();
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
} else if (evt->xbutton.button == Button2)
@ -730,6 +735,7 @@ nk_x11_init(Display *dpy, Window win)
XFreePixmap(dpy, blank);}
nk_init_default(&x11.ctx, 0);
x11.time_of_last_frame = nk_get_time();
return &x11.ctx;
}

View File

@ -1,5 +1,5 @@
# Install
BIN = zahnrad
BIN = demo
# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function -O2

View File

@ -156,19 +156,6 @@ main(void)
#endif
xw.width, xw.height);
#ifdef INCLUDE_STYLE
/* ease regression testing during Nuklear release process; not needed for anything else */
#ifdef STYLE_WHITE
set_style(ctx, THEME_WHITE);
#elif defined(STYLE_RED)
set_style(ctx, THEME_RED);
#elif defined(STYLE_BLUE)
set_style(ctx, THEME_BLUE);
#elif defined(STYLE_DARK)
set_style(ctx, THEME_DARK);
#endif
#endif
while (running)
{
/* Input */

View File

@ -76,10 +76,10 @@ NK_API void nk_xfont_del(Display *dpy, XFont *font);
#ifndef NK_X11_DOUBLE_CLICK_LO
#define NK_X11_DOUBLE_CLICK_LO 20
#define NK_X11_DOUBLE_CLICK_LO 0.02
#endif
#ifndef NK_X11_DOUBLE_CLICK_HI
#define NK_X11_DOUBLE_CLICK_HI 200
#define NK_X11_DOUBLE_CLICK_HI 0.20
#endif
typedef struct XSurface XSurface;
@ -131,15 +131,16 @@ static struct {
Visual *vis;
Colormap cmap;
#endif
long last_button_click;
double last_button_click;
double time_of_last_frame;
} xlib;
NK_INTERN long
nk_timestamp(void)
NK_INTERN double
nk_get_time(void)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) return 0;
return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000);
return ((double)tv.tv_sec + (double)tv.tv_usec/1000000);
}
NK_INTERN unsigned long
@ -182,9 +183,9 @@ nk_xsurf_resize(XSurface *surf, unsigned int w, unsigned int h)
surf->drawable = XCreatePixmap(surf->dpy, surf->root, w, h,
(unsigned int)DefaultDepth(surf->dpy, surf->screen));
#ifdef NK_XLIB_USE_XFT
XftDrawChange(surf->ftdraw, surf->drawable);
XftDrawChange(surf->ftdraw, surf->drawable);
#endif
return;
return;
}
NK_INTERN void
@ -198,9 +199,9 @@ nk_xsurf_scissor(XSurface *surf, float x, float y, float w, float h)
XSetClipRectangles(surf->dpy, surf->gc, 0, 0, &clip_rect, 1, Unsorted);
#ifdef NK_XLIB_USE_XFT
XftDrawSetClipRectangles(surf->ftdraw, 0, 0, &clip_rect, 1);
XftDrawSetClipRectangles(surf->ftdraw, 0, 0, &clip_rect, 1);
#endif
return;
return;
}
NK_INTERN void
@ -465,13 +466,13 @@ nk_xsurf_draw_text(XSurface *surf, short x, short y, const char *text, int len,
xrc.alpha = cfg.a * 257;
XftColorAllocValue(surf->dpy, xlib.vis, xlib.cmap, &xrc, &color);
XftDrawStringUtf8(surf->ftdraw, &color, font->ft, tx, ty, (FcChar8*)text, len);
XftColorFree(surf->dpy, xlib.vis, xlib.cmap, &color);
XftColorFree(surf->dpy, xlib.vis, xlib.cmap, &color);
#else
XSetForeground(surf->dpy, surf->gc, fg);
if(font->set) XmbDrawString(surf->dpy,surf->drawable, font->set, surf->gc, tx, ty, (const char*)text, (int)len);
else XDrawString(surf->dpy, surf->drawable, surf->gc, tx, ty, (const char*)text, (int)len);
#endif
return;
return;
}
@ -610,7 +611,7 @@ NK_INTERN void
nk_xsurf_del(XSurface *surf)
{
#ifdef NK_XLIB_USE_XFT
XftDrawDestroy(surf->ftdraw);
XftDrawDestroy(surf->ftdraw);
#endif
XFreePixmap(surf->dpy, surf->drawable);
XFreeGC(surf->dpy, surf->gc);
@ -674,8 +675,8 @@ nk_xfont_get_text_width(nk_handle handle, float height, const char *text, int le
NK_UNUSED(height);
if(!font || !text)
return 0;
if(!font || !text)
return 0;
XftTextExtentsUtf8(xlib.dpy, font->ft, (FcChar8*)text, len, &g);
return g.xOff;
@ -684,8 +685,8 @@ nk_xfont_get_text_width(nk_handle handle, float height, const char *text, int le
NK_UNUSED(height);
if(!font || !text)
return 0;
if(!font || !text)
return 0;
if(font->set) {
XmbTextExtents(font->set, (const char*)text, len, NULL, &r);
@ -702,7 +703,7 @@ nk_xfont_del(Display *dpy, XFont *font)
{
if(!font) return;
#ifdef NK_XLIB_USE_XFT
XftFontClose(dpy, font->ft);
XftFontClose(dpy, font->ft);
#else
if(font->set)
XFreeFontSet(dpy, font->set);
@ -747,6 +748,7 @@ nk_xlib_init(XFont *xfont, Display *dpy, int screen, Window root,
XFreePixmap(dpy, blank);}
xlib.surf = nk_xsurf_create(screen, w, h);
nk_init_default(&xlib.ctx, font);
xlib.time_of_last_frame = nk_get_time();
return &xlib.ctx;
}
@ -878,10 +880,10 @@ nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt)
const int x = evt->xbutton.x, y = evt->xbutton.y;
if (evt->xbutton.button == Button1) {
if (down) { /* Double-Click Button handler */
long dt = nk_timestamp() - xlib.last_button_click;
float dt = nk_get_time() - xlib.last_button_click;
if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI)
nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true);
xlib.last_button_click = nk_timestamp();
xlib.last_button_click = nk_get_time();
} else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false);
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
} else if (evt->xbutton.button == Button2)
@ -990,6 +992,10 @@ nk_xlib_render(Drawable screen, struct nk_color clear)
struct nk_context *ctx = &xlib.ctx;
XSurface *surf = xlib.surf;
double now = nk_get_time();
xlib.ctx.delta_time_seconds = now - xlib.time_of_last_frame;
xlib.time_of_last_frame = now;
nk_xsurf_clear(xlib.surf, nk_color_from_byte(&clear.r));
nk_foreach(cmd, &xlib.ctx)
{

24
demo/xcb_cairo/Makefile Normal file
View File

@ -0,0 +1,24 @@
# Target
BIN = demo
CFLAGS += -std=c89 -pedantic -O2
LDFLAGS += -lm
SRC = ${wildcard *.c}
OBJ = $(SRC:.c=.o)
# Freetype
CFLAGS += ${shell pkg-config --cflags freetype2}
LDFLAGS += ${shell pkg-config --libs freetype2}
# XCB
CFLAGS += ${shell pkg-config --cflags xcb xcb-util xcb-keysyms}
LDFLAGS += ${shell pkg-config --libs xcb xcb-util xcb-keysyms}
# Cairo
CFLAGS += ${shell pkg-config --cflags cairo}
LDFLAGS += ${shell pkg-config --libs cairo}
# Rules
$(BIN):
@mkdir -p bin
rm -f bin/$(BIN) $(OBJS)
$(CC) $(SRC) $(CFLAGS) -D_POSIX_C_SOURCE=200809L -o bin/$(BIN) ${LDFLAGS}

168
demo/xcb_cairo/main.c Normal file
View File

@ -0,0 +1,168 @@
/* nuklear - v1.32.0 - public domain */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_IMPLEMENTATION
#include "../../nuklear.h"
#define NK_XCB_CAIRO_IMPLEMENTATION
#include "nuklear_xcb.h"
static void die(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fputs("\n", stderr);
exit(EXIT_FAILURE);
}
/* ===============================================================
*
* EXAMPLE
*
* ===============================================================*/
/* This are some code examples to provide a small overview of what can be
* done with this library. To try out an example uncomment the defines */
/*#define INCLUDE_ALL */
/*#define INCLUDE_STYLE */
/*#define INCLUDE_CALCULATOR */
/*#define INCLUDE_OVERVIEW */
/*#define INCLUDE_NODE_EDITOR */
/*#define INCLUDE_CANVAS */
#ifdef INCLUDE_ALL
#define INCLUDE_STYLE
#define INCLUDE_CALCULATOR
#define INCLUDE_OVERVIEW
#define INCLUDE_NODE_EDITOR
#define INCLUDE_CANVAS
#endif
#ifdef INCLUDE_STYLE
#include "../common/style.c"
#endif
#ifdef INCLUDE_CALCULATOR
#include "../common/calculator.c"
#endif
#ifdef INCLUDE_OVERVIEW
#include "../common/overview.c"
#endif
#ifdef INCLUDE_NODE_EDITOR
#include "../common/node_editor.c"
#endif
#ifdef INCLUDE_CANVAS
#include "../common/canvas.c"
#endif
/* ===============================================================
*
* DEMO
*
* ===============================================================*/
int
main(void)
{
struct nk_xcb_context *xcb_ctx;
struct nk_color background = nk_rgb(0, 0, 0);
struct nk_cairo_context *cairo_ctx;
struct nk_user_font *font;
struct nk_context* ctx;
int running = 1;
int events;
xcb_ctx = nk_xcb_init("Nuklear XCB/Cairo", 20, 20, 600, 800);
cairo_ctx = nk_cairo_init(&background, NULL, 0, nk_xcb_create_cairo_surface(xcb_ctx));
/*cairo_ctx = nk_cairo_init(&background, "../../extra_font/DroidSans.ttf", 0, nk_xcb_create_surface(xcb_ctx));*/
font = nk_cairo_default_font(cairo_ctx);
ctx = malloc(sizeof(struct nk_context));
nk_init_default(ctx, font);
#ifdef INCLUDE_STYLE
set_style(ctx, THEME_BLACK);
/*nk_style_push_float(ctx, &ctx->style.window.rounding, 20.0f);*/
/*set_style(ctx, THEME_WHITE);*/
/*set_style(ctx, THEME_RED);*/
/*set_style(ctx, THEME_BLUE);*/
/*set_style(ctx, THEME_DARK);*/
#endif
while (running)
{
/* Events */
events = nk_xcb_handle_event(xcb_ctx, ctx);
if (events & NK_XCB_EVENT_STOP) {
break;
}
if (events & NK_XCB_EVENT_PAINT) {
nk_cairo_damage(cairo_ctx);
}
if (events & NK_XCB_EVENT_RESIZED) {
nk_xcb_resize_cairo_surface(xcb_ctx, nk_cairo_surface(cairo_ctx));
}
/* GUI */
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
enum {EASY, HARD};
static int op = EASY;
static int property = 20;
nk_layout_row_static(ctx, 30, 80, 1);
if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");
nk_layout_row_dynamic(ctx, 30, 2);
if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
}
nk_end(ctx);
if (nk_window_is_hidden(ctx, "Demo")) {
break;
}
/* -------------- EXAMPLES ---------------- */
#ifdef INCLUDE_CALCULATOR
calculator(ctx);
#endif
#ifdef INCLUDE_OVERVIEW
overview(ctx);
#endif
#ifdef INCLUDE_NODE_EDITOR
node_editor(ctx);
#endif
#ifdef INCLUDE_CANVAS
canvas(ctx);
#endif
/* ----------------------------------------- */
/* Render */
nk_cairo_render(cairo_ctx, ctx);
nk_xcb_render(xcb_ctx);
nk_clear(ctx);
}
nk_free(ctx);
free(ctx);
nk_cairo_free(cairo_ctx);
nk_xcb_free(xcb_ctx);
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,836 @@
/*****************************************************************************
*
* Nuklear XCB/Cairo Render Backend - v0.0.2
* Copyright 2021 Richard Gill
*
* Grabbed and adapted from https://github.com/griebd/nuklear_xcb
* Copyright 2017 Adriano Grieb
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
****************************************************************************/
/*****************************************************************************
*
* API
*
****************************************************************************/
#ifndef NK_XCB_CAIRO_H
#define NK_XCB_CAIRO_H
struct nk_xcb_context;
struct nk_cairo_context;
/* With Xcb, we work mostly on events, so to do something only when
* needed it's good to know what kind of events pulled us from sleep
*/
enum nk_xcb_event_type {
NK_XCB_EVENT_PAINT = 0x02,
NK_XCB_EVENT_RESIZED = 0x04,
NK_XCB_EVENT_STOP = 0x08
};
/* Xcb part: work on windows */
NK_API struct nk_xcb_context *nk_xcb_init(const char *title, int pos_x, int pos_y, int width, int height);
NK_API void nk_xcb_free(struct nk_xcb_context *xcb_ctx);
NK_API int nk_xcb_handle_event(struct nk_xcb_context *xcb_ctx, struct nk_context *nk_ctx);
NK_API void nk_xcb_render(struct nk_xcb_context *xcb_ctx);
NK_API void nk_xcb_size(struct nk_xcb_context *xcb_ctx, int *width, int *height);
/* TODO: copy/paste */
/* Cairo part: work on painting */
NK_API struct nk_cairo_context *nk_cairo_init(struct nk_color *bg, const char *font_file, double font_size, void *surface);
NK_API void nk_cairo_free(struct nk_cairo_context *cairo_ctx);
NK_API struct nk_user_font *nk_cairo_default_font(struct nk_cairo_context *cairo_ctx);
NK_API void nk_cairo_damage(struct nk_cairo_context *cairo_ctx);
NK_API int nk_cairo_render(struct nk_cairo_context *cairo_ctx, struct nk_context *ctx);
/* Bridge between xcb and cairo (so it's possible to use them like legos) */
NK_API void *nk_xcb_create_cairo_surface(struct nk_xcb_context *xcb_ctx);
NK_API void nk_xcb_resize_cairo_surface(struct nk_xcb_context *xcb_ctx, void *surface);
#endif /* NK_XCB_CAIRO_H */
/*****************************************************************************
*
* IMPLEMENTATION
*
****************************************************************************/
#ifdef NK_XCB_CAIRO_IMPLEMENTATION
#include <xcb/xcb.h>
#include <xcb/xcb_util.h>
#include <xcb/xcb_keysyms.h>
#include <X11/keysym.h>
#include <cairo/cairo-xcb.h>
#include <cairo/cairo-ft.h>
#if defined _XOPEN_SOURCE && _XOPEN_SOURCE >= 600 || \
defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 200112L
#include <time.h>
#include <errno.h>
#ifndef NK_XCB_FPS
#define NK_XCB_FPS 30
#endif /* NK_XCB_FPS */
#define NK_XCB_NSEC 1000000000
#define NK_XCB_MIN_FRAME_TIME (NK_XCB_NSEC / NK_XCB_FPS)
#endif
#include <math.h>
#ifdef __USE_GNU
#define NK_XCB_PI M_PIl
#elif defined __USE_BSD || defined __USE_XOPEN
#define NK_XCB_PI M_PI
#else
#define NK_XCB_PI acos(-1.0)
#endif
#define NK_XCB_TO_CAIRO(x) ((double) x / 255.0)
#define NK_XCB_DEG_TO_RAD(x) ((double) x * NK_XCB_PI / 180.0)
struct nk_cairo_context {
cairo_surface_t *surface;
cairo_t *cr;
struct nk_user_font *font;
struct nk_color *bg;
void *last_buffer;
nk_size buffer_size;
int repaint;
};
struct nk_xcb_context {
xcb_connection_t *conn;
int screennum;
xcb_window_t window;
xcb_key_symbols_t *key_symbols;
#ifdef NK_XCB_MIN_FRAME_TIME
unsigned long last_render;
#endif /* NK_XCB_MIN_FRAME_TIME */
int events;
xcb_intern_atom_reply_t* del_atom;
int width, height;
};
NK_API struct nk_xcb_context *nk_xcb_init(const char *title, int pos_x, int pos_y, int width, int height)
{
int screenNum;
xcb_connection_t *conn;
xcb_screen_t *screen;
xcb_window_t window;
uint32_t values[1];
struct nk_xcb_context *xcb_ctx;
xcb_intern_atom_cookie_t cookie;
xcb_intern_atom_reply_t *reply, *del_atom;
conn = xcb_connect(NULL, &screenNum);
if (xcb_connection_has_error(conn)) {
xcb_disconnect(conn);
return NULL;
}
screen = xcb_aux_get_screen(conn, screenNum);
window = xcb_generate_id(conn);
values[0] = XCB_EVENT_MASK_KEY_PRESS
| XCB_EVENT_MASK_KEY_RELEASE
| XCB_EVENT_MASK_BUTTON_PRESS
| XCB_EVENT_MASK_BUTTON_RELEASE
| XCB_EVENT_MASK_POINTER_MOTION
| XCB_EVENT_MASK_BUTTON_1_MOTION
| XCB_EVENT_MASK_BUTTON_2_MOTION
| XCB_EVENT_MASK_BUTTON_3_MOTION
| XCB_EVENT_MASK_BUTTON_4_MOTION
| XCB_EVENT_MASK_BUTTON_5_MOTION
| XCB_EVENT_MASK_BUTTON_MOTION
| XCB_EVENT_MASK_KEYMAP_STATE
| XCB_EVENT_MASK_EXPOSURE
| XCB_EVENT_MASK_STRUCTURE_NOTIFY
;
xcb_create_window(conn, XCB_COPY_FROM_PARENT, window, screen->root,
pos_x, pos_y, width, height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
XCB_COPY_FROM_PARENT, XCB_CW_EVENT_MASK, values);
cookie = xcb_intern_atom(conn, 1, 12, "WM_PROTOCOLS");
reply = xcb_intern_atom_reply(conn, cookie, 0);
cookie = xcb_intern_atom(conn, 0, 16, "WM_DELETE_WINDOW");
del_atom = xcb_intern_atom_reply(conn, cookie, 0);
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, window, reply->atom, 4, 32, 1, &del_atom->atom);
free(reply);
xcb_map_window(conn, window);
xcb_flush(conn);
xcb_ctx = malloc(sizeof (struct nk_xcb_context));
xcb_ctx->conn = conn;
xcb_ctx->screennum = screenNum;
xcb_ctx->window = window;
xcb_ctx->key_symbols = xcb_key_symbols_alloc(xcb_ctx->conn);
xcb_ctx->del_atom = del_atom;
xcb_ctx->width = width;
xcb_ctx->height = height;
return xcb_ctx;
}
NK_API void nk_xcb_free(struct nk_xcb_context *xcb_ctx)
{
free(xcb_ctx->del_atom);
xcb_key_symbols_free(xcb_ctx->key_symbols);
xcb_disconnect(xcb_ctx->conn);
free(xcb_ctx);
}
NK_API int nk_xcb_handle_event(struct nk_xcb_context *xcb_ctx, struct nk_context *nk_ctx)
{
int events = 0;
xcb_generic_event_t *event;
#ifdef NK_XCB_MIN_FRAME_TIME
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC_COARSE, &tp);
xcb_ctx->last_render = tp.tv_sec * NK_XCB_NSEC + tp.tv_nsec;
#endif /* NK_XCB_MIN_FRAME_TIME */
event = xcb_wait_for_event(xcb_ctx->conn);
nk_input_begin(nk_ctx);
do {
switch (XCB_EVENT_RESPONSE_TYPE(event)) {
case XCB_KEY_PRESS:
case XCB_KEY_RELEASE:
{
int press = (XCB_EVENT_RESPONSE_TYPE(event)) == XCB_KEY_PRESS;
xcb_key_press_event_t *kp = (xcb_key_press_event_t *)event;
xcb_keysym_t sym = xcb_key_symbols_get_keysym(xcb_ctx->key_symbols, kp->detail, kp->state);
switch (sym) {
case XK_Shift_L:
case XK_Shift_R:
nk_input_key(nk_ctx, NK_KEY_SHIFT, press);
break;
case XK_Control_L:
case XK_Control_R:
nk_input_key(nk_ctx, NK_KEY_CTRL, press);
break;
case XK_Delete:
nk_input_key(nk_ctx, NK_KEY_DEL, press);
break;
case XK_Return:
nk_input_key(nk_ctx, NK_KEY_ENTER, press);
break;
case XK_Tab:
nk_input_key(nk_ctx, NK_KEY_TAB, press);
break;
case XK_BackSpace:
nk_input_key(nk_ctx, NK_KEY_BACKSPACE, press);
break;
/* case NK_KEY_COPY */
/* case NK_KEY_CUT */
/* case NK_KEY_PASTE */
case XK_Up:
nk_input_key(nk_ctx, NK_KEY_UP, press);
break;
case XK_Down:
nk_input_key(nk_ctx, NK_KEY_DOWN, press);
break;
case XK_Left:
nk_input_key(nk_ctx, NK_KEY_LEFT, press);
break;
case XK_Right:
nk_input_key(nk_ctx, NK_KEY_RIGHT, press);
break;
/* NK_KEY_TEXT_INSERT_MODE, */
/* NK_KEY_TEXT_REPLACE_MODE, */
case XK_Escape:
nk_input_key(nk_ctx, NK_KEY_TEXT_RESET_MODE, press);
break;
/* NK_KEY_TEXT_LINE_START, */
/* NK_KEY_TEXT_LINE_END, */
case XK_Home:
{
nk_input_key(nk_ctx, NK_KEY_TEXT_START, press);
nk_input_key(nk_ctx, NK_KEY_SCROLL_START, press);
}
break;
case XK_End:
{
nk_input_key(nk_ctx, NK_KEY_TEXT_END, press);
nk_input_key(nk_ctx, NK_KEY_SCROLL_END, press);
}
break;
/* NK_KEY_TEXT_UNDO, */
/* NK_KEY_TEXT_REDO, */
/* NK_KEY_TEXT_SELECT_ALL, */
/* NK_KEY_TEXT_WORD_LEFT, */
/* NK_KEY_TEXT_WORD_RIGHT, */
case XK_Page_Down:
nk_input_key(nk_ctx, NK_KEY_SCROLL_DOWN, press);
break;
case XK_Page_Up:
nk_input_key(nk_ctx, NK_KEY_SCROLL_UP, press);
break;
default:
if (press &&
!xcb_is_keypad_key(sym) &&
!xcb_is_private_keypad_key(sym) &&
!xcb_is_cursor_key(sym) &&
!xcb_is_pf_key(sym) &&
!xcb_is_function_key(sym) &&
!xcb_is_misc_function_key(sym) &&
!xcb_is_modifier_key(sym)
) {
nk_input_char(nk_ctx, sym);
}
else {
printf("state: %x code: %x sum: %x\n", kp->state, kp->detail, sym);
}
break;
}
}
break;
case XCB_BUTTON_PRESS:
case XCB_BUTTON_RELEASE:
{
int press = (XCB_EVENT_RESPONSE_TYPE(event)) == XCB_BUTTON_PRESS;
xcb_button_press_event_t *bp = (xcb_button_press_event_t *)event;
switch (bp->detail) {
case XCB_BUTTON_INDEX_1:
nk_input_button(nk_ctx, NK_BUTTON_LEFT, bp->event_x, bp->event_y, press);
break;
case XCB_BUTTON_INDEX_2:
nk_input_button(nk_ctx, NK_BUTTON_MIDDLE, bp->event_x, bp->event_y, press);
break;
case XCB_BUTTON_INDEX_3:
nk_input_button(nk_ctx, NK_BUTTON_RIGHT, bp->event_x, bp->event_y, press);
break;
case XCB_BUTTON_INDEX_4:
nk_input_scroll(nk_ctx, nk_vec2(0, 1.0f));
break;
case XCB_BUTTON_INDEX_5:
nk_input_scroll(nk_ctx, nk_vec2(0, -1.0f));
break;
default: break;
}
}
break;
case XCB_MOTION_NOTIFY:
{
xcb_motion_notify_event_t *mn = (xcb_motion_notify_event_t *)event;
nk_input_motion(nk_ctx, mn->event_x, mn->event_y);
}
break;
case XCB_SELECTION_CLEAR:
{
printf("Unhandled event: %s\n", xcb_event_get_label(event->response_type));
}
break;
case XCB_SELECTION_REQUEST:
{
printf("Unhandled event: %s\n", xcb_event_get_label(event->response_type));
}
break;
case XCB_SELECTION_NOTIFY:
{
printf("Unhandled event: %s\n", xcb_event_get_label(event->response_type));
}
break;
case XCB_CONFIGURE_NOTIFY:
{
xcb_configure_notify_event_t *cn = (xcb_configure_notify_event_t *)event;
xcb_ctx->width = cn->width;
xcb_ctx->height = cn->height;
events |= NK_XCB_EVENT_RESIZED;
}
break;
case XCB_KEYMAP_NOTIFY:
xcb_refresh_keyboard_mapping(xcb_ctx->key_symbols, (xcb_mapping_notify_event_t *)event);
break;
case XCB_EXPOSE:
case XCB_REPARENT_NOTIFY:
case XCB_MAP_NOTIFY:
events |= NK_XCB_EVENT_PAINT;
break;
case XCB_CLIENT_MESSAGE:
{
xcb_client_message_event_t *cm = (xcb_client_message_event_t *)event;
if (cm->data.data32[0] == xcb_ctx->del_atom->atom)
{
return NK_XCB_EVENT_STOP;
}
}
break;
default:
printf ("Unhandled event: %s\n", xcb_event_get_label(event->response_type));
break;
}
free(event);
}
while ((event = xcb_poll_for_event(xcb_ctx->conn)));
nk_input_end(nk_ctx);
return events;
}
NK_API void nk_xcb_render(struct nk_xcb_context *xcb_ctx)
{
xcb_flush (xcb_ctx->conn);
#ifdef NK_XCB_MIN_FRAME_TIME
{
struct timespec tp;
unsigned long spent;
clock_gettime(CLOCK_MONOTONIC_COARSE, &tp);
spent = tp.tv_sec * NK_XCB_NSEC + tp.tv_nsec - xcb_ctx->last_render;
if (NK_XCB_MIN_FRAME_TIME > spent) {
tp.tv_sec = 0;
tp.tv_nsec = NK_XCB_MIN_FRAME_TIME - spent;
while (clock_nanosleep(CLOCK_MONOTONIC, 0, &tp, &tp) == EINTR);
}
}
#endif /* NK_XCB_MIN_FRAME_TIME */
}
NK_API void nk_xcb_size(struct nk_xcb_context *xcb_ctx, int *width, int *height)
{
*width = xcb_ctx->width;
*height = xcb_ctx->height;
}
NK_API void *nk_xcb_create_cairo_surface(struct nk_xcb_context *xcb_ctx)
{
xcb_screen_t *screen;
xcb_visualtype_t *visual;
screen = xcb_aux_get_screen(xcb_ctx->conn, xcb_ctx->screennum);
visual = xcb_aux_get_visualtype(xcb_ctx->conn, xcb_ctx->screennum, screen->root_visual);
return cairo_xcb_surface_create(xcb_ctx->conn, xcb_ctx->window, visual, xcb_ctx->width, xcb_ctx->height);
}
NK_API void nk_xcb_resize_cairo_surface(struct nk_xcb_context *xcb_ctx, void *surface)
{
cairo_xcb_surface_set_size((cairo_surface_t *)surface, xcb_ctx->width, xcb_ctx->height);
}
#define NK_TO_CAIRO(x) ((double) x / 255.0)
NK_INTERN float nk_cairo_text_width(nk_handle handle, float height __attribute__ ((__unused__)), const char *text, int len)
{
cairo_scaled_font_t *font = handle.ptr;
cairo_glyph_t *glyphs = NULL;
int num_glyphs;
cairo_text_extents_t extents;
cairo_scaled_font_text_to_glyphs(font, 0, 0, text, len, &glyphs, &num_glyphs, NULL, NULL, NULL);
cairo_scaled_font_glyph_extents(font, glyphs, num_glyphs, &extents);
cairo_glyph_free(glyphs);
return extents.x_advance;
}
NK_API struct nk_cairo_context *nk_cairo_init(struct nk_color *bg, const char *font_file, double font_size, void *surf)
{
cairo_surface_t *surface = surf;
struct nk_cairo_context *cairo_ctx;
cairo_t *cr;
cairo_font_extents_t extents;
cairo_scaled_font_t *default_font;
struct nk_user_font *font;
cr = cairo_create(surface);
font = malloc(sizeof (struct nk_user_font));
if (font_file != NULL) {
FT_Library library;
FT_Face face;
cairo_font_face_t *font_face;
static const cairo_user_data_key_t key;
FT_Init_FreeType(&library);
FT_New_Face(library, font_file, 0, &face);
font_face = cairo_ft_font_face_create_for_ft_face(face, 0);
cairo_font_face_set_user_data(font_face, &key, face, (cairo_destroy_func_t)FT_Done_Face);
cairo_set_font_face(cr, font_face);
}
if (font_size < 0.01) {
font_size = 11.0;
}
cairo_set_font_size(cr, font_size);
default_font = cairo_get_scaled_font(cr);
cairo_scaled_font_extents(default_font, &extents);
font->userdata.ptr = default_font;
font->height = extents.height;
font->width = nk_cairo_text_width;
cairo_ctx = malloc(sizeof(struct nk_cairo_context));
cairo_ctx->surface = (cairo_surface_t *)surface;
cairo_ctx->cr = cr;
cairo_ctx->font = font;
cairo_ctx->bg = bg;
cairo_ctx->last_buffer = NULL;
cairo_ctx->buffer_size = 0;
cairo_ctx->repaint = nk_false;
return cairo_ctx;
}
NK_API cairo_surface_t *nk_cairo_surface(struct nk_cairo_context *cairo_ctx)
{
return cairo_ctx->surface;
}
NK_API struct nk_user_font *nk_cairo_default_font(struct nk_cairo_context *cairo_ctx)
{
return cairo_ctx->font;
}
NK_API void nk_cairo_free(struct nk_cairo_context *cairo_ctx)
{
free (cairo_ctx->last_buffer);
cairo_destroy(cairo_ctx->cr);
cairo_surface_destroy(cairo_ctx->surface);
free(cairo_ctx->font);
free(cairo_ctx);
}
NK_API void nk_cairo_damage(struct nk_cairo_context *cairo_ctx)
{
cairo_ctx->repaint = nk_true;
}
NK_API int nk_cairo_render(struct nk_cairo_context *cairo_ctx, struct nk_context *nk_ctx)
{
cairo_t *cr;
const struct nk_command *cmd = NULL;
void *cmds = nk_buffer_memory(&nk_ctx->memory);
if (cairo_ctx->buffer_size != nk_ctx->memory.allocated) {
cairo_ctx->buffer_size = nk_ctx->memory.allocated;
cairo_ctx->last_buffer = realloc(cairo_ctx->last_buffer, cairo_ctx->buffer_size);
memcpy(cairo_ctx->last_buffer, cmds, cairo_ctx->buffer_size);
}
else if (!memcmp(cmds, cairo_ctx->last_buffer, cairo_ctx->buffer_size)) {
if (!cairo_ctx->repaint) {
return nk_false;
}
cairo_ctx->repaint = nk_false;
}
else {
memcpy(cairo_ctx->last_buffer, cmds, cairo_ctx->buffer_size);
}
cr = cairo_ctx->cr;
cairo_push_group(cr);
cairo_set_source_rgb(cr, NK_TO_CAIRO(cairo_ctx->bg->r), NK_TO_CAIRO(cairo_ctx->bg->g), NK_TO_CAIRO(cairo_ctx->bg->b));
cairo_paint(cr);
nk_foreach(cmd, nk_ctx) {
switch (cmd->type) {
case NK_COMMAND_NOP:
break;
case NK_COMMAND_SCISSOR:
{
const struct nk_command_scissor *s = (const struct nk_command_scissor *)cmd;
cairo_reset_clip(cr);
if (s->x >= 0) {
cairo_rectangle(cr, s->x - 1, s->y - 1, s->w + 2, s->h + 2);
cairo_clip(cr);
}
}
break;
case NK_COMMAND_LINE:
{
const struct nk_command_line *l = (const struct nk_command_line *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(l->color.r), NK_TO_CAIRO(l->color.g), NK_TO_CAIRO(l->color.b), NK_TO_CAIRO(l->color.a));
cairo_set_line_width(cr, l->line_thickness);
cairo_move_to(cr, l->begin.x, l->begin.y);
cairo_line_to(cr, l->end.x, l->end.y);
cairo_stroke(cr);
}
break;
case NK_COMMAND_CURVE:
{
const struct nk_command_curve *q = (const struct nk_command_curve *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(q->color.r), NK_TO_CAIRO(q->color.g), NK_TO_CAIRO(q->color.b), NK_TO_CAIRO(q->color.a));
cairo_set_line_width(cr, q->line_thickness);
cairo_move_to(cr, q->begin.x, q->begin.y);
cairo_curve_to(cr, q->ctrl[0].x, q->ctrl[0].y, q->ctrl[1].x, q->ctrl[1].y, q->end.x, q->end.y);
cairo_stroke(cr);
}
break;
case NK_COMMAND_RECT:
{
const struct nk_command_rect *r = (const struct nk_command_rect *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(r->color.r), NK_TO_CAIRO(r->color.g), NK_TO_CAIRO(r->color.b), NK_TO_CAIRO(r->color.a));
cairo_set_line_width(cr, r->line_thickness);
if (r->rounding == 0) {
cairo_rectangle(cr, r->x, r->y, r->w, r->h);
}
else {
int xl = r->x + r->w - r->rounding;
int xr = r->x + r->rounding;
int yl = r->y + r->h - r->rounding;
int yr = r->y + r->rounding;
cairo_new_sub_path(cr);
cairo_arc(cr, xl, yr, r->rounding, NK_XCB_DEG_TO_RAD(-90), NK_XCB_DEG_TO_RAD(0));
cairo_arc(cr, xl, yl, r->rounding, NK_XCB_DEG_TO_RAD(0), NK_XCB_DEG_TO_RAD(90));
cairo_arc(cr, xr, yl, r->rounding, NK_XCB_DEG_TO_RAD(90), NK_XCB_DEG_TO_RAD(180));
cairo_arc(cr, xr, yr, r->rounding, NK_XCB_DEG_TO_RAD(180), NK_XCB_DEG_TO_RAD(270));
cairo_close_path(cr);
}
cairo_stroke(cr);
}
break;
case NK_COMMAND_RECT_FILLED:
{
const struct nk_command_rect_filled *r = (const struct nk_command_rect_filled *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(r->color.r), NK_TO_CAIRO(r->color.g), NK_TO_CAIRO(r->color.b), NK_TO_CAIRO(r->color.a));
if (r->rounding == 0) {
cairo_rectangle(cr, r->x, r->y, r->w, r->h);
} else {
int xl = r->x + r->w - r->rounding;
int xr = r->x + r->rounding;
int yl = r->y + r->h - r->rounding;
int yr = r->y + r->rounding;
cairo_new_sub_path(cr);
cairo_arc(cr, xl, yr, r->rounding, NK_XCB_DEG_TO_RAD(-90), NK_XCB_DEG_TO_RAD(0));
cairo_arc(cr, xl, yl, r->rounding, NK_XCB_DEG_TO_RAD(0), NK_XCB_DEG_TO_RAD(90));
cairo_arc(cr, xr, yl, r->rounding, NK_XCB_DEG_TO_RAD(90), NK_XCB_DEG_TO_RAD(180));
cairo_arc(cr, xr, yr, r->rounding, NK_XCB_DEG_TO_RAD(180), NK_XCB_DEG_TO_RAD(270));
cairo_close_path(cr);
}
cairo_fill(cr);
}
break;
case NK_COMMAND_RECT_MULTI_COLOR:
{
/* from https://github.com/taiwins/twidgets/blob/master/src/nk_wl_cairo.c */
const struct nk_command_rect_multi_color *r = (const struct nk_command_rect_multi_color *)cmd;
cairo_pattern_t *pat = cairo_pattern_create_mesh();
if (pat) {
cairo_mesh_pattern_begin_patch(pat);
cairo_mesh_pattern_move_to(pat, r->x, r->y);
cairo_mesh_pattern_line_to(pat, r->x, r->y + r->h);
cairo_mesh_pattern_line_to(pat, r->x + r->w, r->y + r->h);
cairo_mesh_pattern_line_to(pat, r->x + r->w, r->y);
cairo_mesh_pattern_set_corner_color_rgba(pat, 0, NK_TO_CAIRO(r->left.r), NK_TO_CAIRO(r->left.g), NK_TO_CAIRO(r->left.b), NK_TO_CAIRO(r->left.a));
cairo_mesh_pattern_set_corner_color_rgba(pat, 1, NK_TO_CAIRO(r->bottom.r), NK_TO_CAIRO(r->bottom.g), NK_TO_CAIRO(r->bottom.b), NK_TO_CAIRO(r->bottom.a));
cairo_mesh_pattern_set_corner_color_rgba(pat, 2, NK_TO_CAIRO(r->right.r), NK_TO_CAIRO(r->right.g), NK_TO_CAIRO(r->right.b), NK_TO_CAIRO(r->right.a));
cairo_mesh_pattern_set_corner_color_rgba(pat, 3, NK_TO_CAIRO(r->top.r), NK_TO_CAIRO(r->top.g), NK_TO_CAIRO(r->top.b), NK_TO_CAIRO(r->top.a));
cairo_mesh_pattern_end_patch(pat);
cairo_rectangle(cr, r->x, r->y, r->w, r->h);
cairo_set_source(cr, pat);
cairo_fill(cr);
cairo_pattern_destroy(pat);
}
}
break;
case NK_COMMAND_CIRCLE:
{
const struct nk_command_circle *c = (const struct nk_command_circle *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(c->color.r), NK_TO_CAIRO(c->color.g), NK_TO_CAIRO(c->color.b), NK_TO_CAIRO(c->color.a));
cairo_set_line_width(cr, c->line_thickness);
cairo_save(cr);
cairo_translate(cr, c->x + c->w / 2.0, c->y + c->h / 2.0);
cairo_scale(cr, c->w / 2.0, c->h / 2.0);
cairo_arc(cr, 0, 0, 1, NK_XCB_DEG_TO_RAD(0), NK_XCB_DEG_TO_RAD(360));
cairo_restore(cr);
cairo_stroke(cr);
}
break;
case NK_COMMAND_CIRCLE_FILLED:
{
const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(c->color.r), NK_TO_CAIRO(c->color.g), NK_TO_CAIRO(c->color.b), NK_TO_CAIRO(c->color.a));
cairo_save(cr);
cairo_translate(cr, c->x + c->w / 2.0, c->y + c->h / 2.0);
cairo_scale(cr, c->w / 2.0, c->h / 2.0);
cairo_arc(cr, 0, 0, 1, NK_XCB_DEG_TO_RAD(0), NK_XCB_DEG_TO_RAD(360));
cairo_restore(cr);
cairo_fill(cr);
}
break;
case NK_COMMAND_ARC:
{
const struct nk_command_arc *a = (const struct nk_command_arc*) cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(a->color.r), NK_TO_CAIRO(a->color.g), NK_TO_CAIRO(a->color.b), NK_TO_CAIRO(a->color.a));
cairo_set_line_width(cr, a->line_thickness);
cairo_arc(cr, a->cx, a->cy, a->r, NK_XCB_DEG_TO_RAD(a->a[0]), NK_XCB_DEG_TO_RAD(a->a[1]));
cairo_stroke(cr);
}
break;
case NK_COMMAND_ARC_FILLED:
{
const struct nk_command_arc_filled *a = (const struct nk_command_arc_filled*)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(a->color.r), NK_TO_CAIRO(a->color.g), NK_TO_CAIRO(a->color.b), NK_TO_CAIRO(a->color.a));
cairo_arc(cr, a->cx, a->cy, a->r, NK_XCB_DEG_TO_RAD(a->a[0]), NK_XCB_DEG_TO_RAD(a->a[1]));
cairo_fill(cr);
}
break;
case NK_COMMAND_TRIANGLE:
{
const struct nk_command_triangle *t = (const struct nk_command_triangle *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(t->color.r), NK_TO_CAIRO(t->color.g), NK_TO_CAIRO(t->color.b), NK_TO_CAIRO(t->color.a));
cairo_set_line_width(cr, t->line_thickness);
cairo_move_to(cr, t->a.x, t->a.y);
cairo_line_to(cr, t->b.x, t->b.y);
cairo_line_to(cr, t->c.x, t->c.y);
cairo_close_path(cr);
cairo_stroke(cr);
}
break;
case NK_COMMAND_TRIANGLE_FILLED:
{
const struct nk_command_triangle_filled *t = (const struct nk_command_triangle_filled *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(t->color.r), NK_TO_CAIRO(t->color.g), NK_TO_CAIRO(t->color.b), NK_TO_CAIRO(t->color.a));
cairo_move_to(cr, t->a.x, t->a.y);
cairo_line_to(cr, t->b.x, t->b.y);
cairo_line_to(cr, t->c.x, t->c.y);
cairo_close_path(cr);
cairo_fill(cr);
}
break;
case NK_COMMAND_POLYGON:
{
int i;
const struct nk_command_polygon *p = (const struct nk_command_polygon *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(p->color.r), NK_TO_CAIRO(p->color.g), NK_TO_CAIRO(p->color.b), NK_TO_CAIRO(p->color.a));
cairo_set_line_width(cr, p->line_thickness);
cairo_move_to(cr, p->points[0].x, p->points[0].y);
for (i = 1; i < p->point_count; ++i) {
cairo_line_to(cr, p->points[i].x, p->points[i].y);
}
cairo_close_path(cr);
cairo_stroke(cr);
}
break;
case NK_COMMAND_POLYGON_FILLED:
{
int i;
const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled *)cmd;
cairo_set_source_rgba (cr, NK_TO_CAIRO(p->color.r), NK_TO_CAIRO(p->color.g), NK_TO_CAIRO(p->color.b), NK_TO_CAIRO(p->color.a));
cairo_move_to(cr, p->points[0].x, p->points[0].y);
for (i = 1; i < p->point_count; ++i) {
cairo_line_to(cr, p->points[i].x, p->points[i].y);
}
cairo_close_path(cr);
cairo_fill(cr);
}
break;
case NK_COMMAND_POLYLINE:
{
int i;
const struct nk_command_polyline *p = (const struct nk_command_polyline *)cmd;
cairo_set_source_rgba(cr, NK_TO_CAIRO(p->color.r), NK_TO_CAIRO(p->color.g), NK_TO_CAIRO(p->color.b), NK_TO_CAIRO(p->color.a));
cairo_set_line_width(cr, p->line_thickness);
cairo_move_to(cr, p->points[0].x, p->points[0].y);
for (i = 1; i < p->point_count; ++i) {
cairo_line_to(cr, p->points[i].x, p->points[i].y);
}
cairo_stroke(cr);
}
break;
case NK_COMMAND_TEXT:
{
const struct nk_command_text *t = (const struct nk_command_text *)cmd;
cairo_glyph_t *glyphs = NULL;
int num_glyphs;
cairo_text_cluster_t *clusters = NULL;
int num_clusters;
cairo_text_cluster_flags_t cluster_flags;
cairo_font_extents_t extents;
cairo_set_source_rgba(cr, NK_TO_CAIRO(t->foreground.r), NK_TO_CAIRO(t->foreground.g), NK_TO_CAIRO(t->foreground.b), NK_TO_CAIRO(t->foreground.a));
cairo_scaled_font_extents(t->font->userdata.ptr, &extents);
cairo_scaled_font_text_to_glyphs(t->font->userdata.ptr,
t->x, t->y + extents.ascent, t->string, t->length,
&glyphs, &num_glyphs, &clusters, &num_clusters,
&cluster_flags);
cairo_show_text_glyphs(cr, t->string, t->length, glyphs,
num_glyphs, clusters, num_clusters,
cluster_flags);
cairo_glyph_free(glyphs);
cairo_text_cluster_free(clusters);
}
break;
case NK_COMMAND_IMAGE:
{
/* from https://github.com/taiwins/twidgets/blob/master/src/nk_wl_cairo.c */
const struct nk_command_image *im = (const struct nk_command_image *)cmd;
cairo_surface_t *img_surf;
double sw = (double)im->w / (double)im->img.region[2];
double sh = (double)im->h / (double)im->img.region[3];
cairo_format_t format = CAIRO_FORMAT_ARGB32;
int stride = cairo_format_stride_for_width(format, im->img.w);
if (!im->img.handle.ptr) return nk_false;
img_surf = cairo_image_surface_create_for_data(im->img.handle.ptr, format, im->img.w, im->img.h, stride);
if (!img_surf) return nk_false;
cairo_save(cr);
cairo_rectangle(cr, im->x, im->y, im->w, im->h);
/* scale here, if after source set, the scale would not apply to source
* surface
*/
cairo_scale(cr, sw, sh);
/* the coordinates system in cairo is not intuitive, scale, translate,
* are applied to source. Refer to
* "https://www.cairographics.org/FAQ/#paint_from_a_surface" for details
*
* if you set source_origin to (0,0), it would be like source origin
* aligned to dest origin, then if you draw a rectangle on (x, y, w, h).
* it would clip out the (x, y, w, h) of the source on you dest as well.
*/
cairo_set_source_surface(cr, img_surf, im->x/sw - im->img.region[0], im->y/sh - im->img.region[1]);
cairo_fill(cr);
cairo_restore(cr);
cairo_surface_destroy(img_surf);
}
break;
case NK_COMMAND_CUSTOM:
{
const struct nk_command_custom *cu = (const struct nk_command_custom *)cmd;
if (cu->callback) {
cu->callback(cr, cu->x, cu->y, cu->w, cu->h, cu->callback_data);
}
}
default:
break;
}
}
cairo_pop_group_to_source(cr);
cairo_paint(cr);
cairo_surface_flush(cairo_ctx->surface);
return nk_true;
}
#endif /* NK_XCB_CAIRO_IMPLEMENTATION */

2739
doc/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +0,0 @@
# Install
BIN = doc
# Flags
CFLAGS += -std=c99 -pedantic -O2
SRC = stddoc.c
OBJ = $(SRC:.c=.o)
ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS =
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LIBS =
else
LIBS =
endif
endif
$(BIN): clean
$(CC) $(SRC) $(CFLAGS) -o $(BIN)
clean:
rm -f $(BIN) $(OBJS)

View File

@ -1,2 +0,0 @@
#!/bin/sh
cat ../nuklear.h|./doc > index.html

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +0,0 @@
<!--
This page is here in order to allow redirecting the old nuklear.html URL over to index.html
-->
<html>
<head>
<meta http-equiv="refresh" content="0; URL=index.html" />
</head>
<body>
<p>If you are not redirected in five seconds, <a href="index.html">click here</a>.</p>
</body>
</html>

View File

@ -1,141 +0,0 @@
/// ## About
/// - _stddoc.c_ is a tiny documentation generator for 60 programming languages.
/// - This page sample was auto-generated from the code comments found in `stddoc.c` file.
///
/// ## How does it work?
/// - Markdeep code comments are extracted from stdin and printed into stdout as a HTML file.
///
/// ## Supported languages
/// - `/// Three slashes comment` [ActionScript, AngelScript, C (C99), C#, C++, ChaiScript, D,
/// GameMonkey, GML, Go, Java, JavaScript, JetScript, jtc, Jx9, Kotlin, Neko, Object Pascal (Delphi),
/// Objective-C, Pawn, PHP, QuakeC, Rust, SASS, Scala, Squirrel, Swift, Vala, Wren, Xojo].
/// - `--- Three dashes comment` [Ada, AppleScript, Eiffel, Euphoria, Haskell, Lua, Occam,
/// PL/SQL, PSL, SGML, SPARK, SQL, Terra, TSQL, VHDL].
/// - `### Three hashes comment` [AWK, Bash, Bourne shell, C shell, Cobra, Maple, Maple,
/// Perl, Perl6, PowerShell, Python, R, Ruby, Seed7, Tcl].
///
/// ## Usage
/// - `stddoc < source.code > documentation.html`
///
/// ## Changelog
/// 2018/01/07
/// : Initial version (_v1.0.0_)
///
/// ## License
/// - rlyeh, unlicensed (~public domain).
#include <stdio.h>
int main() {
printf("%s\n", "<meta charset='utf-8' emacsmode='-*- markdown -*-'>");
printf("%s\n", "<link rel='stylesheet' href='https://casual-effects.com/markdeep/latest/apidoc.css?'>");
for( int fsm_S = 0, fsm_D = 0, fsm_H = 0; !feof(stdin); ) {
int chr = getc(stdin);
if( fsm_S > 3 || fsm_D > 3 || fsm_H > 3 ) {
putc(chr, stdout);
if( chr != '\r' && chr != '\n' ) continue;
}
/**/ if( fsm_S <= 2 && chr == '/' && !fsm_D && !fsm_H ) fsm_S++;
else if( fsm_S == 3 && chr == ' ' && !fsm_D && !fsm_H ) fsm_S++;
else if( fsm_D <= 2 && chr == '-' && !fsm_S && !fsm_H ) fsm_D++;
else if( fsm_D == 3 && chr == ' ' && !fsm_S && !fsm_H ) fsm_D++;
else if( fsm_H <= 2 && chr == '#' && !fsm_S && !fsm_D ) fsm_H++;
else if( fsm_H == 3 && chr == ' ' && !fsm_S && !fsm_D ) fsm_H++;
else fsm_S = fsm_D = fsm_H = 0;
}
printf("%s\n", "<script>markdeepOptions={tocStyle:'medium'};</script>");
printf("%s\n", "<!-- Markdeep: --><script src='https://casual-effects.com/markdeep/latest/markdeep.min.js?'></script>");
}
///
/// ## **Example page!**
///
/// Imaginary documentation page. Here would be some introduction text.
///
/// The table of contents that Markdeep produces is stuffed on the right side,
/// if the browser window is wide enough. Otherwise it is hidden.
///
/// ### Basic Markdeep
///
/// Regular styling like **bold**, _italics_, ~~strikethrough~~, `inline code`, etc. Lists as:
///
/// * A
/// * Bullet
/// * List
///
/// And:
///
/// 1. A
/// 1. Numbered
/// 1. List!
///
/// Symbol substitutions: a 45-degree turn; some x -> y arrows; some whoa ==> fancy <==> arrows.
///
/// Is this a definition list?
/// : Looks like one to me
/// Is that right?
/// : Possibly!
///
/// And a code listing:
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// int main()
/// {
/// return 1;
/// }
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
///
/// ### Tables
///
/// Thing Name | Description |Notes
/// ------------------------|--------------------|-----
/// Yes | Yup! |
/// No | Nope :( |
/// FileNotFound | Doesn't find files | Pass `-sFIND_FILE=maybe` to maybe find them
///
///
/// ### Diagrams
///
/// ******************************************* Here's a text to the right of the diagram,
/// * +-----------------+ .-. * ain't that fancy. Pretty fancy indeed, I
/// * |\ | .-+ | * must say! Markdeep diagrams are generally
/// * | \ A-B *---+--> .--+ '--. * enclosed into a rectangle full made of `*`
/// * | \ | | Cloud! | * symbols; and are "drawn" using ASCII-art
/// * +---+-------------+ '-------------' * style, with `- | + / \ * o` etc.
/// ******************************************* Suh-weet!
///
/// Another random diagram, just because:
///
/// ********************
/// * +-+-+-+-*-o *
/// * / / ^ / *
/// * / v / / *
/// * +-+-+-+ *
/// ********************
///
/// ### Special notes
///
/// !!! Note
/// Hey I'm a note. Don't mind me, I'm just sitting here.
///
/// !!! WARNING
/// I'm a warning, perhaps. *Something might happen!*
///
/// !!! Error: Never Pass `nullptr` to a Shader
/// Invoking a shader with a null argument can seg fault.
/// This is a multi-line admonition.
///
/// Seriously, don't call shaders like that.
///
/// ### Embedding HTML
///
/// <pre>
/// This is an embedded html node by the way!
/// </pre>
///
/// ## Credits
/// - API doc style created by [Aras Pranckevičius](https://github.com/aras-p)
/// - Markdeep by [Morgan McGuire](https://casual-effects.com/markdeep/).

7210
nuklear.h

File diff suppressed because it is too large Load Diff

View File

@ -1,216 +0,0 @@
/// # Nuklear
/// ![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif)
///
/// ## Contents
/// 1. About section
/// 2. Highlights section
/// 3. Features section
/// 4. Usage section
/// 1. Flags section
/// 2. Constants section
/// 3. Dependencies section
/// 5. Example section
/// 6. API section
/// 1. Context section
/// 2. Input section
/// 3. Drawing section
/// 4. Window section
/// 5. Layouting section
/// 6. Groups section
/// 7. Tree section
/// 8. Properties section
/// 7. License section
/// 8. Changelog section
/// 9. Gallery section
/// 10. Credits section
///
/// ## About
/// This is a minimal state immediate mode graphical user interface toolkit
/// written in ANSI C and licensed under public domain. It was designed as a simple
/// embeddable user interface for application and does not have any dependencies,
/// a default renderbackend or OS window and input handling but instead provides a very modular
/// library approach by using simple input state for input and draw
/// commands describing primitive shapes as output. So instead of providing a
/// layered library that tries to abstract over a number of platform and
/// render backends it only focuses on the actual UI.
///
/// ## Highlights
/// - Graphical user interface toolkit
/// - Single header library
/// - Written in C89 (a.k.a. ANSI C or ISO C90)
/// - Small codebase (~18kLOC)
/// - Focus on portability, efficiency and simplicity
/// - No dependencies (not even the standard library if not wanted)
/// - Fully skinnable and customizable
/// - Low memory footprint with total memory control if needed or wanted
/// - UTF-8 support
/// - No global or hidden state
/// - Customizable library modules (you can compile and use only what you need)
/// - Optional font baker and vertex buffer output
/// - [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/)
///
/// ## Features
/// - Absolutely no platform dependent code
/// - Memory management control ranging from/to
/// - Ease of use by allocating everything from standard library
/// - Control every byte of memory inside the library
/// - Font handling control ranging from/to
/// - Use your own font implementation for everything
/// - Use this libraries internal font baking and handling API
/// - Drawing output control ranging from/to
/// - Simple shapes for more high level APIs which already have drawing capabilities
/// - Hardware accessible anti-aliased vertex buffer output
/// - Customizable colors and properties ranging from/to
/// - Simple changes to color by filling a simple color table
/// - Complete control with ability to use skinning to decorate widgets
/// - Bendable UI library with widget ranging from/to
/// - Basic widgets like buttons, checkboxes, slider, ...
/// - Advanced widget like abstract comboboxes, contextual menus,...
/// - Compile time configuration to only compile what you need
/// - Subset which can be used if you do not want to link or use the standard library
/// - Can be easily modified to only update on user input instead of frame updates
///
/// ## Usage
/// This library is self contained in one single header file and can be used either
/// in header only mode or in implementation mode. The header only mode is used
/// by default when included and allows including this header in other headers
/// and does not contain the actual implementation. <br /><br />
///
/// The implementation mode requires to define the preprocessor macro
/// NK_IMPLEMENTATION in *one* .c/.cpp file before #including this file, e.g.:
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C
/// #define NK_IMPLEMENTATION
/// #include "nuklear.h"
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// Also optionally define the symbols listed in the section "OPTIONAL DEFINES"
/// below in header and implementation mode if you want to use additional functionality
/// or need more control over the library.
///
/// !!! WARNING
/// Every time nuklear is included define the same compiler flags. This very important not doing so could lead to compiler errors or even worse stack corruptions.
///
/// ### Flags
/// Flag | Description
/// --------------------------------|------------------------------------------
/// NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation
/// NK_INCLUDE_FIXED_TYPES | If defined it will include header `<stdint.h>` for fixed sized types otherwise nuklear tries to select the correct type. If that fails it will throw a compiler error and you have to select the correct types yourself.
/// NK_INCLUDE_DEFAULT_ALLOCATOR | If defined it will include header `<stdlib.h>` and provide additional functions to use this library without caring for memory allocation control and therefore ease memory management.
/// NK_INCLUDE_STANDARD_IO | If defined it will include header `<stdio.h>` and provide additional functions depending on file loading.
/// NK_INCLUDE_STANDARD_VARARGS | If defined it will include header <stdarg.h> and provide additional functions depending on file loading.
/// NK_INCLUDE_STANDARD_BOOL | If defined it will include header `<stdbool.h>` for nk_bool otherwise nuklear defines nk_bool as int.
/// NK_INCLUDE_VERTEX_BUFFER_OUTPUT | Defining this adds a vertex draw command list backend to this library, which allows you to convert queue commands into vertex draw commands. This is mainly if you need a hardware accessible format for OpenGL, DirectX, Vulkan, Metal,...
/// NK_INCLUDE_FONT_BAKING | Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it.
/// NK_INCLUDE_DEFAULT_FONT | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font
/// NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures.
/// NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released.
/// NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame.
/// NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit
/// NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events
///
/// !!! WARNING
/// The following flags will pull in the standard C library:
/// - NK_INCLUDE_DEFAULT_ALLOCATOR
/// - NK_INCLUDE_STANDARD_IO
/// - NK_INCLUDE_STANDARD_VARARGS
///
/// !!! WARNING
/// The following flags if defined need to be defined for both header and implementation:
/// - NK_INCLUDE_FIXED_TYPES
/// - NK_INCLUDE_DEFAULT_ALLOCATOR
/// - NK_INCLUDE_STANDARD_VARARGS
/// - NK_INCLUDE_STANDARD_BOOL
/// - NK_INCLUDE_VERTEX_BUFFER_OUTPUT
/// - NK_INCLUDE_FONT_BAKING
/// - NK_INCLUDE_DEFAULT_FONT
/// - NK_INCLUDE_STANDARD_VARARGS
/// - NK_INCLUDE_COMMAND_USERDATA
/// - NK_UINT_DRAW_INDEX
///
/// ### Constants
/// Define | Description
/// --------------------------------|---------------------------------------
/// NK_BUFFER_DEFAULT_INITIAL_SIZE | Initial buffer size allocated by all buffers while using the default allocator functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't want to allocate the default 4k memory then redefine it.
/// NK_MAX_NUMBER_BUFFER | Maximum buffer size for the conversion buffer between float and string Under normal circumstances this should be more than sufficient.
/// NK_INPUT_MAX | Defines the max number of bytes which can be added as text input in one frame. Under normal circumstances this should be more than sufficient.
///
/// !!! WARNING
/// The following constants if defined need to be defined for both header and implementation:
/// - NK_MAX_NUMBER_BUFFER
/// - NK_BUFFER_DEFAULT_INITIAL_SIZE
/// - NK_INPUT_MAX
///
/// ### Dependencies
/// Function | Description
/// ------------|---------------------------------------------------------------
/// NK_ASSERT | If you don't define this, nuklear will use <assert.h> with assert().
/// NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version.
/// NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version.
/// NK_INV_SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version.
/// NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation.
/// NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation.
/// NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!).
/// NK_DTOA | You can define this to `dtoa` or your own double to string conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!).
/// NK_VSNPRINTF| If you define `NK_INCLUDE_STANDARD_VARARGS` as well as `NK_INCLUDE_STANDARD_IO` and want to be safe define this to `vsnprintf` on compilers supporting later versions of C or C++. By default nuklear will check for your stdlib version in C as well as compiler version in C++. if `vsnprintf` is available it will define it to `vsnprintf` directly. If not defined and if you have older versions of C or C++ it will be defined to `vsprintf` which is unsafe.
///
/// !!! WARNING
/// The following dependencies will pull in the standard C library if not redefined:
/// - NK_ASSERT
///
/// !!! WARNING
/// The following dependencies if defined need to be defined for both header and implementation:
/// - NK_ASSERT
///
/// !!! WARNING
/// The following dependencies if defined need to be defined only for the implementation part:
/// - NK_MEMSET
/// - NK_MEMCPY
/// - NK_SQRT
/// - NK_SIN
/// - NK_COS
/// - NK_STRTOD
/// - NK_DTOA
/// - NK_VSNPRINTF
///
/// ## Example
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// // init gui state
/// enum {EASY, HARD};
/// static int op = EASY;
/// static float value = 0.6f;
/// static int i = 20;
/// struct nk_context ctx;
///
/// nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
/// if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
/// NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
/// // fixed widget pixel width
/// nk_layout_row_static(&ctx, 30, 80, 1);
/// if (nk_button_label(&ctx, "button")) {
/// // event handling
/// }
///
/// // fixed widget window ratio width
/// nk_layout_row_dynamic(&ctx, 30, 2);
/// if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
/// if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;
///
/// // custom widget pixel width
/// nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
/// {
/// nk_layout_row_push(&ctx, 50);
/// nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
/// nk_layout_row_push(&ctx, 110);
/// nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
/// }
/// nk_layout_row_end(&ctx);
/// }
/// nk_end(&ctx);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// ![](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png)
///
/// ## API
///

216
src/HEADER.md Normal file
View File

@ -0,0 +1,216 @@
# Nuklear
![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif)
## Contents
1. About section
2. Highlights section
3. Features section
4. Usage section
1. Flags section
2. Constants section
3. Dependencies section
5. Example section
6. API section
1. Context section
2. Input section
3. Drawing section
4. Window section
5. Layouting section
6. Groups section
7. Tree section
8. Properties section
7. License section
8. Changelog section
9. Gallery section
10. Credits section
## About
This is a minimal state immediate mode graphical user interface toolkit
written in ANSI C and licensed under public domain. It was designed as a simple
embeddable user interface for application and does not have any dependencies,
a default renderbackend or OS window and input handling but instead provides a very modular
library approach by using simple input state for input and draw
commands describing primitive shapes as output. So instead of providing a
layered library that tries to abstract over a number of platform and
render backends it only focuses on the actual UI.
## Highlights
- Graphical user interface toolkit
- Single header library
- Written in C89 (a.k.a. ANSI C or ISO C90)
- Small codebase (~18kLOC)
- Focus on portability, efficiency and simplicity
- No dependencies (not even the standard library if not wanted)
- Fully skinnable and customizable
- Low memory footprint with total memory control if needed or wanted
- UTF-8 support
- No global or hidden state
- Customizable library modules (you can compile and use only what you need)
- Optional font baker and vertex buffer output
- [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/)
## Features
- Absolutely no platform dependent code
- Memory management control ranging from/to
- Ease of use by allocating everything from standard library
- Control every byte of memory inside the library
- Font handling control ranging from/to
- Use your own font implementation for everything
- Use this libraries internal font baking and handling API
- Drawing output control ranging from/to
- Simple shapes for more high level APIs which already have drawing capabilities
- Hardware accessible anti-aliased vertex buffer output
- Customizable colors and properties ranging from/to
- Simple changes to color by filling a simple color table
- Complete control with ability to use skinning to decorate widgets
- Bendable UI library with widget ranging from/to
- Basic widgets like buttons, checkboxes, slider, ...
- Advanced widget like abstract comboboxes, contextual menus,...
- Compile time configuration to only compile what you need
- Subset which can be used if you do not want to link or use the standard library
- Can be easily modified to only update on user input instead of frame updates
## Usage
This library is self contained in one single header file and can be used either
in header only mode or in implementation mode. The header only mode is used
by default when included and allows including this header in other headers
and does not contain the actual implementation. <br /><br />
The implementation mode requires to define the preprocessor macro
NK_IMPLEMENTATION in *one* .c/.cpp file before #including this file, e.g.:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C
#define NK_IMPLEMENTATION
#include "nuklear.h"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Also optionally define the symbols listed in the section "OPTIONAL DEFINES"
below in header and implementation mode if you want to use additional functionality
or need more control over the library.
!!! WARNING
Every time nuklear is included define the same compiler flags. This very important not doing so could lead to compiler errors or even worse stack corruptions.
### Flags
Flag | Description
--------------------------------|------------------------------------------
NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation
NK_INCLUDE_FIXED_TYPES | If defined it will include header `<stdint.h>` for fixed sized types otherwise nuklear tries to select the correct type. If that fails it will throw a compiler error and you have to select the correct types yourself.
NK_INCLUDE_DEFAULT_ALLOCATOR | If defined it will include header `<stdlib.h>` and provide additional functions to use this library without caring for memory allocation control and therefore ease memory management.
NK_INCLUDE_STANDARD_IO | If defined it will include header `<stdio.h>` and provide additional functions depending on file loading.
NK_INCLUDE_STANDARD_VARARGS | If defined it will include header <stdarg.h> and provide additional functions depending on file loading.
NK_INCLUDE_STANDARD_BOOL | If defined it will include header `<stdbool.h>` for nk_bool otherwise nuklear defines nk_bool as int.
NK_INCLUDE_VERTEX_BUFFER_OUTPUT | Defining this adds a vertex draw command list backend to this library, which allows you to convert queue commands into vertex draw commands. This is mainly if you need a hardware accessible format for OpenGL, DirectX, Vulkan, Metal,...
NK_INCLUDE_FONT_BAKING | Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it.
NK_INCLUDE_DEFAULT_FONT | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font
NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures.
NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released.
NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame.
NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit
NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events
!!! WARNING
The following flags will pull in the standard C library:
- NK_INCLUDE_DEFAULT_ALLOCATOR
- NK_INCLUDE_STANDARD_IO
- NK_INCLUDE_STANDARD_VARARGS
!!! WARNING
The following flags if defined need to be defined for both header and implementation:
- NK_INCLUDE_FIXED_TYPES
- NK_INCLUDE_DEFAULT_ALLOCATOR
- NK_INCLUDE_STANDARD_VARARGS
- NK_INCLUDE_STANDARD_BOOL
- NK_INCLUDE_VERTEX_BUFFER_OUTPUT
- NK_INCLUDE_FONT_BAKING
- NK_INCLUDE_DEFAULT_FONT
- NK_INCLUDE_STANDARD_VARARGS
- NK_INCLUDE_COMMAND_USERDATA
- NK_UINT_DRAW_INDEX
### Constants
Define | Description
--------------------------------|---------------------------------------
NK_BUFFER_DEFAULT_INITIAL_SIZE | Initial buffer size allocated by all buffers while using the default allocator functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't want to allocate the default 4k memory then redefine it.
NK_MAX_NUMBER_BUFFER | Maximum buffer size for the conversion buffer between float and string Under normal circumstances this should be more than sufficient.
NK_INPUT_MAX | Defines the max number of bytes which can be added as text input in one frame. Under normal circumstances this should be more than sufficient.
!!! WARNING
The following constants if defined need to be defined for both header and implementation:
- NK_MAX_NUMBER_BUFFER
- NK_BUFFER_DEFAULT_INITIAL_SIZE
- NK_INPUT_MAX
### Dependencies
Function | Description
------------|---------------------------------------------------------------
NK_ASSERT | If you don't define this, nuklear will use <assert.h> with assert().
NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version.
NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version.
NK_INV_SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version.
NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation.
NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation.
NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!).
NK_DTOA | You can define this to `dtoa` or your own double to string conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!).
NK_VSNPRINTF| If you define `NK_INCLUDE_STANDARD_VARARGS` as well as `NK_INCLUDE_STANDARD_IO` and want to be safe define this to `vsnprintf` on compilers supporting later versions of C or C++. By default nuklear will check for your stdlib version in C as well as compiler version in C++. if `vsnprintf` is available it will define it to `vsnprintf` directly. If not defined and if you have older versions of C or C++ it will be defined to `vsprintf` which is unsafe.
!!! WARNING
The following dependencies will pull in the standard C library if not redefined:
- NK_ASSERT
!!! WARNING
The following dependencies if defined need to be defined for both header and implementation:
- NK_ASSERT
!!! WARNING
The following dependencies if defined need to be defined only for the implementation part:
- NK_MEMSET
- NK_MEMCPY
- NK_SQRT
- NK_SIN
- NK_COS
- NK_STRTOD
- NK_DTOA
- NK_VSNPRINTF
## Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
// init gui state
enum {EASY, HARD};
static int op = EASY;
static float value = 0.6f;
static int i = 20;
struct nk_context ctx;
nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
// fixed widget pixel width
nk_layout_row_static(&ctx, 30, 80, 1);
if (nk_button_label(&ctx, "button")) {
// event handling
}
// fixed widget window ratio width
nk_layout_row_dynamic(&ctx, 30, 2);
if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;
// custom widget pixel width
nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
{
nk_layout_row_push(&ctx, 50);
nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
nk_layout_row_push(&ctx, 110);
nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
}
nk_layout_row_end(&ctx);
}
nk_end(&ctx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
![](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png)
## API

File diff suppressed because it is too large Load Diff

View File

@ -242,7 +242,7 @@ nk_buffer_free(struct nk_buffer *b)
b->pool.free(b->pool.userdata, b->memory.ptr);
}
NK_API void
nk_buffer_info(struct nk_memory_status *s, struct nk_buffer *b)
nk_buffer_info(struct nk_memory_status *s, const struct nk_buffer *b)
{
NK_ASSERT(b);
NK_ASSERT(s);
@ -268,10 +268,9 @@ nk_buffer_memory_const(const struct nk_buffer *buffer)
return buffer->memory.ptr;
}
NK_API nk_size
nk_buffer_total(struct nk_buffer *buffer)
nk_buffer_total(const struct nk_buffer *buffer)
{
NK_ASSERT(buffer);
if (!buffer) return 0;
return buffer->memory.size;
}

View File

@ -54,6 +54,19 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
nk_fill_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y,
points[2].x, points[2].y, foreground);
} break;
case NK_SYMBOL_TRIANGLE_UP_OUTLINE:
case NK_SYMBOL_TRIANGLE_DOWN_OUTLINE:
case NK_SYMBOL_TRIANGLE_LEFT_OUTLINE:
case NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE: {
enum nk_heading heading;
struct nk_vec2 points[3];
heading = (type == NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE) ? NK_RIGHT :
(type == NK_SYMBOL_TRIANGLE_LEFT_OUTLINE) ? NK_LEFT:
(type == NK_SYMBOL_TRIANGLE_UP_OUTLINE) ? NK_UP: NK_DOWN;
nk_triangle_from_direction(points, content, 0, 0, heading);
nk_stroke_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y,
points[2].x, points[2].y, border_width, foreground);
} break;
default:
case NK_SYMBOL_NONE:
case NK_SYMBOL_MAX: break;

View File

@ -23,7 +23,7 @@ nk_parse_hex(const char *p, int length)
return i;
}
NK_API struct nk_color
nk_rgb_factor(struct nk_color col, const float factor)
nk_rgb_factor(struct nk_color col, float factor)
{
if (factor == 1.0f)
return col;
@ -246,7 +246,7 @@ nk_hsva_colorf(float h, float s, float v, float a)
return out;
}
NK_API struct nk_colorf
nk_hsva_colorfv(float *c)
nk_hsva_colorfv(const float *c)
{
return nk_hsva_colorf(c[0], c[1], c[2], c[3]);
}
@ -421,4 +421,3 @@ nk_color_hsv_bv(nk_byte *out, struct nk_color in)
out[1] = (nk_byte)tmp[1];
out[2] = (nk_byte)tmp[2];
}

View File

@ -702,7 +702,7 @@ NK_API void nk_combo_close(struct nk_context *ctx)
nk_contextual_close(ctx);
}
NK_API int
nk_combo(struct nk_context *ctx, const char **items, int count,
nk_combo(struct nk_context *ctx, const char *const *items, int count,
int selected, int item_height, struct nk_vec2 size)
{
int i = 0;
@ -820,7 +820,7 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c
} return selected;
}
NK_API void
nk_combobox(struct nk_context *ctx, const char **items, int count,
nk_combobox(struct nk_context *ctx, const char *const *items, int count,
int *selected, int item_height, struct nk_vec2 size)
{
*selected = nk_combo(ctx, items, count, *selected, item_height, size);
@ -845,4 +845,3 @@ nk_combobox_callback(struct nk_context *ctx,
{
*selected = nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size);
}

View File

@ -63,7 +63,7 @@ nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds,
return 1;
}
NK_API nk_bool
nk_init(struct nk_context *ctx, struct nk_allocator *alloc,
nk_init(struct nk_context *ctx, const struct nk_allocator *alloc,
const struct nk_user_font *font)
{
NK_ASSERT(alloc);

View File

@ -329,7 +329,7 @@ nk_fill_triangle(struct nk_command_buffer *b, float x0, float y0, float x1,
cmd->color = c;
}
NK_API void
nk_stroke_polygon(struct nk_command_buffer *b, float *points, int point_count,
nk_stroke_polygon(struct nk_command_buffer *b, const float *points, int point_count,
float line_thickness, struct nk_color col)
{
int i;
@ -350,7 +350,7 @@ nk_stroke_polygon(struct nk_command_buffer *b, float *points, int point_count,
}
}
NK_API void
nk_fill_polygon(struct nk_command_buffer *b, float *points, int point_count,
nk_fill_polygon(struct nk_command_buffer *b, const float *points, int point_count,
struct nk_color col)
{
int i;
@ -371,7 +371,7 @@ nk_fill_polygon(struct nk_command_buffer *b, float *points, int point_count,
}
}
NK_API void
nk_stroke_polyline(struct nk_command_buffer *b, float *points, int point_count,
nk_stroke_polyline(struct nk_command_buffer *b, const float *points, int point_count,
float line_thickness, struct nk_color col)
{
int i;
@ -555,4 +555,3 @@ nk_draw_text(struct nk_command_buffer *b, struct nk_rect r,
NK_MEMCPY(cmd->string, string, (nk_size)length);
cmd->string[length] = '\0';
}

View File

@ -146,7 +146,7 @@ nk_font_baker_memory(nk_size *temp, int *glyph_count,
*temp += nk_build_align + nk_baker_align;
}
NK_INTERN struct nk_font_baker*
nk_font_baker(void *memory, int glyph_count, int count, struct nk_allocator *alloc)
nk_font_baker(void *memory, int glyph_count, int count, const struct nk_allocator *alloc)
{
struct nk_font_baker *baker;
if (!memory) return 0;
@ -163,7 +163,7 @@ NK_INTERN int
nk_font_bake_pack(struct nk_font_baker *baker,
nk_size *image_memory, int *width, int *height, struct nk_recti *custom,
const struct nk_font_config *config_list, int count,
struct nk_allocator *alloc)
const struct nk_allocator *alloc)
{
NK_STORAGE const nk_size max_height = 1024 * 32;
const struct nk_font_config *config_iter, *it;
@ -192,7 +192,7 @@ nk_font_bake_pack(struct nk_font_baker *baker,
it = config_iter;
do {
struct stbtt_fontinfo *font_info = &baker->build[i++].info;
font_info->userdata = alloc;
font_info->userdata = (void*)alloc;
if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, stbtt_GetFontOffsetForIndex((const unsigned char*)it->ttf_blob, 0)))
return nk_false;
@ -200,7 +200,7 @@ nk_font_bake_pack(struct nk_font_baker *baker,
}
*height = 0;
*width = (total_glyph_count > 1000) ? 1024 : 512;
stbtt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, alloc);
stbtt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, (void*)alloc);
{
int input_i = 0;
int range_n = 0;
@ -504,7 +504,7 @@ nk_font_query_font_glyph(nk_handle handle, float height,
}
#endif
NK_API const struct nk_font_glyph*
nk_font_find_glyph(struct nk_font *font, nk_rune unicode)
nk_font_find_glyph(const struct nk_font *font, nk_rune unicode)
{
int i = 0;
int count;
@ -567,8 +567,8 @@ nk_font_init(struct nk_font *font, float pixel_height,
*
* ProggyClean.ttf
* Copyright (c) 2004, 2005 Tristan Grimmer
* MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip)
* Download and more information at http://upperbounds.net
* MIT license https://github.com/bluescan/proggyfonts/blob/master/LICENSE
* Download and more information at https://github.com/bluescan/proggyfonts
*-----------------------------------------------------------------------------*/
#ifdef __clang__
#pragma clang diagnostic push
@ -893,7 +893,7 @@ nk_font_atlas_init_default(struct nk_font_atlas *atlas)
}
#endif
NK_API void
nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc)
nk_font_atlas_init(struct nk_font_atlas *atlas, const struct nk_allocator *alloc)
{
NK_ASSERT(atlas);
NK_ASSERT(alloc);
@ -904,7 +904,7 @@ nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc)
}
NK_API void
nk_font_atlas_init_custom(struct nk_font_atlas *atlas,
struct nk_allocator *permanent, struct nk_allocator *temporary)
const struct nk_allocator *permanent, const struct nk_allocator *temporary)
{
NK_ASSERT(atlas);
NK_ASSERT(permanent);
@ -1370,4 +1370,3 @@ nk_font_atlas_clear(struct nk_font_atlas *atlas)
nk_zero_struct(*atlas);
}
#endif

View File

@ -103,6 +103,12 @@ NK_LIB float nk_sin(float x);
#ifndef NK_COS
NK_LIB float nk_cos(float x);
#endif
#ifndef NK_ATAN
NK_LIB float nk_atan(float x);
#endif
#ifndef NK_ATAN2
NK_LIB float nk_atan2(float y, float x);
#endif
NK_LIB nk_uint nk_round_up_pow2(nk_uint v);
NK_LIB struct nk_rect nk_shrink_rect(struct nk_rect r, float amount);
NK_LIB struct nk_rect nk_pad_rect(struct nk_rect r, struct nk_vec2 pad);
@ -112,6 +118,7 @@ NK_LIB int nk_ifloord(double x);
NK_LIB int nk_ifloorf(float x);
NK_LIB int nk_iceilf(float x);
NK_LIB int nk_log10(double n);
NK_LIB float nk_roundf(float x);
/* util */
enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE};
@ -138,7 +145,7 @@ NK_LIB struct nk_vec2 nk_text_calculate_text_bounds(const struct nk_user_font *f
NK_LIB int nk_strfmt(char *buf, int buf_size, const char *fmt, va_list args);
#endif
#ifdef NK_INCLUDE_STANDARD_IO
NK_LIB char *nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc);
NK_LIB char *nk_file_load(const char* path, nk_size* siz, const struct nk_allocator *alloc);
#endif
/* buffer */
@ -179,11 +186,11 @@ enum nk_window_insert_location {
NK_LIB void *nk_create_window(struct nk_context *ctx);
NK_LIB void nk_remove_window(struct nk_context*, struct nk_window*);
NK_LIB void nk_free_window(struct nk_context *ctx, struct nk_window *win);
NK_LIB struct nk_window *nk_find_window(struct nk_context *ctx, nk_hash hash, const char *name);
NK_LIB struct nk_window *nk_find_window(const struct nk_context *ctx, nk_hash hash, const char *name);
NK_LIB void nk_insert_window(struct nk_context *ctx, struct nk_window *win, enum nk_window_insert_location loc);
/* pool */
NK_LIB void nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, unsigned int capacity);
NK_LIB void nk_pool_init(struct nk_pool *pool, const struct nk_allocator *alloc, unsigned int capacity);
NK_LIB void nk_pool_free(struct nk_pool *pool);
NK_LIB void nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size);
NK_LIB struct nk_page_element *nk_pool_alloc(struct nk_pool *pool);
@ -199,7 +206,7 @@ NK_LIB void nk_remove_table(struct nk_window *win, struct nk_table *tbl);
NK_LIB void nk_free_table(struct nk_context *ctx, struct nk_table *tbl);
NK_LIB void nk_push_table(struct nk_window *win, struct nk_table *tbl);
NK_LIB nk_uint *nk_add_value(struct nk_context *ctx, struct nk_window *win, nk_hash name, nk_uint value);
NK_LIB nk_uint *nk_find_value(struct nk_window *win, nk_hash name);
NK_LIB nk_uint *nk_find_value(const struct nk_window *win, nk_hash name);
/* panel */
NK_LIB void *nk_create_panel(struct nk_context *ctx);
@ -220,7 +227,7 @@ NK_LIB void nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, flo
NK_LIB void nk_panel_alloc_row(const struct nk_context *ctx, struct nk_window *win);
NK_LIB void nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, struct nk_window *win, int modify);
NK_LIB void nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx);
NK_LIB void nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx);
NK_LIB void nk_layout_peek(struct nk_rect *bounds, const struct nk_context *ctx);
/* popup */
NK_LIB nk_bool nk_nonblock_begin(struct nk_context *ctx, nk_flags flags, struct nk_rect body, struct nk_rect header, enum nk_panel_type panel_type);
@ -368,4 +375,3 @@ nk_stbtt_free(void *ptr, void *user_data) {
#endif /* NK_INCLUDE_FONT_BAKING */
#endif

250
src/nuklear_knob.c Normal file
View File

@ -0,0 +1,250 @@
#include "nuklear.h"
#include "nuklear_internal.h"
/* ===============================================================
*
* KNOB
*
* ===============================================================*/
NK_LIB float
nk_knob_behavior(nk_flags *state, struct nk_input *in,
struct nk_rect bounds, float knob_min, float knob_max, float knob_value,
float knob_step, float knob_steps,
enum nk_heading zero_direction, float dead_zone_percent)
{
struct nk_vec2 origin;
float angle = 0.0f;
origin.x = bounds.x + (bounds.w / 2);
origin.y = bounds.y + (bounds.h / 2);
nk_widget_state_reset(state);
/* handle click and drag input */
if(in &&
in->mouse.buttons[NK_BUTTON_LEFT].down &&
nk_input_has_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, bounds, nk_true)){
/* calculate angle from origin and rotate */
const float direction_rads[4] = {
NK_PI * 2.5f, /* 90 NK_UP */
NK_PI * 2.0f, /* 0 NK_RIGHT */
NK_PI * 1.5f, /* 270 NK_DOWN */
NK_PI, /* 180 NK_LEFT */
};
*state = NK_WIDGET_STATE_ACTIVE;
angle = NK_ATAN2(in->mouse.pos.y - origin.y, in->mouse.pos.x - origin.x) + direction_rads[zero_direction];
angle -= (angle > NK_PI * 2) ? NK_PI * 3 : NK_PI;
/* account for dead space applied when drawing */
angle *= 1.0f / (1.0f - dead_zone_percent);
angle = NK_CLAMP(-NK_PI, angle, NK_PI);
/* convert -pi -> pi range to 0.0 -> 1.0 */
angle = (angle + NK_PI) / (NK_PI * 2);
/* click to closest step */
knob_value = knob_min + ( (int)(angle * knob_steps + (knob_step / 2)) ) * knob_step;
knob_value = NK_CLAMP(knob_min, knob_value, knob_max);
}
/* knob widget state */
if (nk_input_is_mouse_hovering_rect(in, bounds)){
*state = NK_WIDGET_STATE_HOVERED;
if (in) {
/* handle scroll and arrow inputs */
if (in->mouse.scroll_delta.y > 0 ||
(in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked))
knob_value += knob_step;
if (in->mouse.scroll_delta.y < 0 ||
(in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked))
knob_value -= knob_step;
}
knob_value = NK_CLAMP(knob_min, knob_value, knob_max);
}
if (*state & NK_WIDGET_STATE_HOVER &&
!nk_input_is_mouse_prev_hovering_rect(in, bounds))
*state |= NK_WIDGET_STATE_ENTERED;
else if (nk_input_is_mouse_prev_hovering_rect(in, bounds))
*state |= NK_WIDGET_STATE_LEFT;
return knob_value;
}
NK_LIB void
nk_draw_knob(struct nk_command_buffer *out, nk_flags state,
const struct nk_style_knob *style, const struct nk_rect *bounds, float min, float value, float max,
enum nk_heading zero_direction, float dead_zone_percent)
{
const struct nk_style_item *background;
struct nk_color knob_color, cursor;
NK_UNUSED(min);
NK_UNUSED(max);
NK_UNUSED(value);
if (state & NK_WIDGET_STATE_ACTIVED) {
background = &style->active;
knob_color = style->knob_active;
cursor = style->cursor_active;
} else if (state & NK_WIDGET_STATE_HOVER) {
background = &style->hover;
knob_color = style->knob_hover;
cursor = style->cursor_hover;
} else {
background = &style->normal;
knob_color = style->knob_normal;
cursor = style->cursor_normal;
}
/* draw background */
switch(background->type) {
case NK_STYLE_ITEM_IMAGE:
nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor));
break;
case NK_STYLE_ITEM_NINE_SLICE:
nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor));
break;
case NK_STYLE_ITEM_COLOR:
nk_fill_rect(out, *bounds, 0, nk_rgb_factor(background->data.color, style->color_factor));
nk_stroke_rect(out, *bounds, 0, style->border, nk_rgb_factor(style->border_color, style->color_factor));
break;
}
/* draw knob */
nk_fill_circle(out, *bounds, nk_rgb_factor(knob_color, style->color_factor));
if(style->knob_border > 0){
struct nk_rect border_bounds = *bounds;
border_bounds.x += style->knob_border / 2;
border_bounds.y += style->knob_border / 2;
border_bounds.w -= style->knob_border;
border_bounds.h -= style->knob_border;
nk_stroke_circle(out, border_bounds, style->knob_border, nk_rgb_factor(style->knob_border_color, style->color_factor));
}
{ /* calculate cursor line cords */
float half_circle_size = (bounds->w / 2);
float angle = (value - min) / (max - min);
float alive_zone = 1.0f - dead_zone_percent;
struct nk_vec2 cursor_start, cursor_end;
const float direction_rads[4] = {
NK_PI * 1.5f, /* 90 NK_UP */
0.0f, /* 0 NK_RIGHT */
NK_PI * 0.5f, /* 270 NK_DOWN */
NK_PI, /* 180 NK_LEFT */
};
/* calculate + apply dead zone */
angle = (angle * alive_zone) + (dead_zone_percent / 2);
/* percentage 0.0 -> 1.0 to radians, rads are 0.0 to (2*pi) NOT -pi to pi */
angle *= NK_PI * 2;
/* apply zero angle */
angle += direction_rads[zero_direction];
if(angle > NK_PI * 2)
angle -= NK_PI * 2;
cursor_start.x = bounds->x + half_circle_size + (angle > NK_PI);
cursor_start.y = bounds->y + half_circle_size + (angle < NK_PI_HALF || angle > (NK_PI * 1.5f));
cursor_end.x = cursor_start.x + (half_circle_size * NK_COS(angle));
cursor_end.y = cursor_start.y + (half_circle_size * NK_SIN(angle));
/* cut off half of the cursor */
cursor_start.x = (cursor_start.x + cursor_end.x) / 2;
cursor_start.y = (cursor_start.y + cursor_end.y) / 2;
/* draw cursor */
nk_stroke_line(out, cursor_start.x, cursor_start.y, cursor_end.x, cursor_end.y, 2, nk_rgb_factor(cursor, style->color_factor));
}
}
NK_LIB float
nk_do_knob(nk_flags *state,
struct nk_command_buffer *out, struct nk_rect bounds,
float min, float val, float max, float step,
enum nk_heading zero_direction, float dead_zone_percent,
const struct nk_style_knob *style, struct nk_input *in)
{
float knob_range;
float knob_min;
float knob_max;
float knob_value;
float knob_steps;
NK_ASSERT(style);
NK_ASSERT(out);
if (!out || !style)
return 0;
/* remove padding from knob bounds */
bounds.y = bounds.y + style->padding.y;
bounds.x = bounds.x + style->padding.x;
bounds.h = NK_MAX(bounds.h, 2*style->padding.y);
bounds.w = NK_MAX(bounds.w, 2*style->padding.x);
bounds.w -= 2 * style->padding.x;
bounds.h -= 2 * style->padding.y;
if(bounds.h < bounds.w){
bounds.x += (bounds.w - bounds.h) / 2;
bounds.w = bounds.h;
}
/* make sure the provided values are correct */
knob_max = NK_MAX(min, max);
knob_min = NK_MIN(min, max);
knob_value = NK_CLAMP(knob_min, val, knob_max);
knob_range = knob_max - knob_min;
knob_steps = knob_range / step;
knob_value = nk_knob_behavior(state, in, bounds, knob_min, knob_max, knob_value, step, knob_steps, zero_direction, dead_zone_percent);
/* draw knob */
if (style->draw_begin) style->draw_begin(out, style->userdata);
nk_draw_knob(out, *state, style, &bounds, knob_min, knob_value, knob_max, zero_direction, dead_zone_percent);
if (style->draw_end) style->draw_end(out, style->userdata);
return knob_value;
}
NK_API nk_bool
nk_knob_float(struct nk_context *ctx, float min_value, float *value, float max_value,
float value_step, enum nk_heading zero_direction, float dead_zone_degrees)
{
struct nk_window *win;
struct nk_panel *layout;
struct nk_input *in;
const struct nk_style *style;
int ret = 0;
float old_value;
struct nk_rect bounds;
enum nk_widget_layout_states state;
NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
NK_ASSERT(value);
NK_ASSERT(NK_BETWEEN(dead_zone_degrees, 0.0f, 360.0f));
if (!ctx || !ctx->current || !ctx->current->layout || !value)
return ret;
win = ctx->current;
style = &ctx->style;
layout = win->layout;
state = nk_widget(&bounds, ctx);
if (!state) return ret;
in = (state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
old_value = *value;
*value = nk_do_knob(&ctx->last_widget_state, &win->buffer, bounds, min_value,
old_value, max_value, value_step, zero_direction, dead_zone_degrees / 360.0f, &style->knob, in);
return (old_value > *value || old_value < *value);
}
NK_API nk_bool
nk_knob_int(struct nk_context *ctx, int min, int *val, int max, int step,
enum nk_heading zero_direction, float dead_zone_degrees)
{
int ret;
float value = (float)*val;
ret = nk_knob_float(ctx, (float)min, &value, (float)max, (float)step, zero_direction, dead_zone_degrees);
*val = (int)value;
return ret;
}

View File

@ -134,7 +134,7 @@ nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt,
win->layout->row.item_width = (float)width;
}
NK_API float
nk_layout_ratio_from_pixel(struct nk_context *ctx, float pixel_width)
nk_layout_ratio_from_pixel(const struct nk_context *ctx, float pixel_width)
{
struct nk_window *win;
NK_ASSERT(ctx);
@ -463,7 +463,7 @@ nk_layout_space_push(struct nk_context *ctx, struct nk_rect rect)
layout->row.item = rect;
}
NK_API struct nk_rect
nk_layout_space_bounds(struct nk_context *ctx)
nk_layout_space_bounds(const struct nk_context *ctx)
{
struct nk_rect ret;
struct nk_window *win;
@ -482,7 +482,7 @@ nk_layout_space_bounds(struct nk_context *ctx)
return ret;
}
NK_API struct nk_rect
nk_layout_widget_bounds(struct nk_context *ctx)
nk_layout_widget_bounds(const struct nk_context *ctx)
{
struct nk_rect ret;
struct nk_window *win;
@ -501,7 +501,7 @@ nk_layout_widget_bounds(struct nk_context *ctx)
return ret;
}
NK_API struct nk_vec2
nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret)
nk_layout_space_to_screen(const struct nk_context *ctx, struct nk_vec2 ret)
{
struct nk_window *win;
struct nk_panel *layout;
@ -517,7 +517,7 @@ nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret)
return ret;
}
NK_API struct nk_vec2
nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret)
nk_layout_space_to_local(const struct nk_context *ctx, struct nk_vec2 ret)
{
struct nk_window *win;
struct nk_panel *layout;
@ -533,7 +533,7 @@ nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret)
return ret;
}
NK_API struct nk_rect
nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret)
nk_layout_space_rect_to_screen(const struct nk_context *ctx, struct nk_rect ret)
{
struct nk_window *win;
struct nk_panel *layout;
@ -549,7 +549,7 @@ nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret)
return ret;
}
NK_API struct nk_rect
nk_layout_space_rect_to_local(struct nk_context *ctx, struct nk_rect ret)
nk_layout_space_rect_to_local(const struct nk_context *ctx, struct nk_rect ret)
{
struct nk_window *win;
struct nk_panel *layout;
@ -601,7 +601,7 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
panel_space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type,
layout->bounds.w, layout->row.columns);
#define NK_FRAC(x) (x - (float)(int)x) /* will be used to remove fookin gaps */
#define NK_FRAC(x) (x - (float)(int)nk_roundf(x)) /* will be used to remove fookin gaps */
/* calculate the width of one item inside the current layout space */
switch (layout->row.type) {
case NK_LAYOUT_DYNAMIC_FIXED: {
@ -730,7 +730,7 @@ nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx)
layout->row.index++;
}
NK_LIB void
nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx)
nk_layout_peek(struct nk_rect *bounds, const struct nk_context *ctx)
{
float y;
int index;

View File

@ -84,6 +84,52 @@ nk_cos(float x)
return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*(a7 + x*a8)))))));
}
#endif
#ifndef NK_ATAN
#define NK_ATAN nk_atan
NK_LIB float
nk_atan(float x)
{
/* ./lolremez --progress --float -d 9 -r "0:pi*2" "atan(x)" */
float u = -1.0989005e-05f;
NK_ASSERT(x >= 0.0f && "TODO support negative floats");
u = u * x + 0.00034117949f;
u = u * x + -0.0044932296f;
u = u * x + 0.032596264f;
u = u * x + -0.14088021f;
u = u * x + 0.36040401f;
u = u * x + -0.47017866f;
u = u * x + 0.00050198776f;
u = u * x + 1.0077682f;
u = u * x + -0.0004765437f;
return u;
}
#endif
#ifndef NK_ATAN2
#define NK_ATAN2 nk_atan2
NK_LIB float
nk_atan2(float y, float x)
{
float ax = NK_ABS(x),
ay = NK_ABS(y);
/* 0 = +y +x 1 = -y +x
2 = +y -x 3 = -y -x */
nk_uint signs = (y < 0) | ((x < 0) << 1);
float a;
if(y == 0.0 && x == 0.0) return 0.0f;
a = (ay > ax)
? NK_PI_HALF - NK_ATAN(ax / ay)
: NK_ATAN(ay / ax);
switch(signs){
case 0: return a;
case 1: return -a;
case 2: return -a + NK_PI;
case 3: return a - NK_PI;
}
return 0.0f; /* prevents warning */
}
#endif
NK_LIB nk_uint
nk_round_up_pow2(nk_uint v)
{
@ -151,6 +197,11 @@ nk_log10(double n)
if (neg) exp = -exp;
return exp;
}
NK_LIB float
nk_roundf(float x)
{
return (x >= 0.0) ? nk_ifloorf(x + 0.5) : nk_iceilf(x - 0.5);
}
NK_API struct nk_rect
nk_get_null_rect(void)
{

View File

@ -309,7 +309,7 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
nk_draw_nine_slice(out, body, &style->window.fixed_background.data.slice, nk_white);
break;
case NK_STYLE_ITEM_COLOR:
nk_fill_rect(out, body, 0, style->window.fixed_background.data.color);
nk_fill_rect(out, body, style->window.rounding, style->window.fixed_background.data.color);
break;
}
}
@ -505,7 +505,7 @@ nk_panel_end(struct nk_context *ctx)
: (window->bounds.y + window->bounds.h));
struct nk_rect b = window->bounds;
b.h = padding_y - window->bounds.y;
nk_stroke_rect(out, b, 0, layout->border, border_color);
nk_stroke_rect(out, b, style->window.rounding, layout->border, border_color);
}
/* scaler */

View File

@ -7,7 +7,7 @@
*
* ===============================================================*/
NK_LIB void
nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc,
nk_pool_init(struct nk_pool *pool, const struct nk_allocator *alloc,
unsigned int capacity)
{
NK_ASSERT(capacity >= 1);

View File

@ -230,7 +230,7 @@ nk_popup_end(struct nk_context *ctx)
nk_push_scissor(&win->buffer, win->layout->clip);
}
NK_API void
nk_popup_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
nk_popup_get_scroll(const struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y)
{
struct nk_window *popup;

View File

@ -106,7 +106,9 @@ nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property *
/* draw label */
text.padding = nk_vec2(0,0);
nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font);
if (name && name[0] != '#') {
nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font);
}
}
NK_LIB void
nk_do_property(nk_flags *ws,
@ -124,7 +126,7 @@ nk_do_property(nk_flags *ws,
nk_filter_float
};
nk_bool active, old;
int num_len = 0, name_len;
int num_len = 0, name_len = 0;
char string[NK_MAX_NUMBER_BUFFER];
float size;
@ -144,7 +146,9 @@ nk_do_property(nk_flags *ws,
left.y = property.y + style->border + property.h/2.0f - left.h/2;
/* text label */
name_len = nk_strlen(name);
if (name && name[0] != '#') {
name_len = nk_strlen(name);
}
size = font->width(font->userdata, font->height, name, name_len);
label.x = left.x + left.w + style->padding.x;
label.w = (float)size + 2 * style->padding.x;

View File

@ -419,14 +419,14 @@ nk_str_get_const(const struct nk_str *s)
return (const char*)s->buffer.memory.ptr;
}
NK_API int
nk_str_len(struct nk_str *s)
nk_str_len(const struct nk_str *s)
{
NK_ASSERT(s);
if (!s || !s->len || !s->buffer.allocated) return 0;
return s->len;
}
NK_API int
nk_str_len_char(struct nk_str *s)
nk_str_len_char(const struct nk_str *s)
{
NK_ASSERT(s);
if (!s || !s->len || !s->buffer.allocated) return 0;
@ -446,4 +446,3 @@ nk_str_free(struct nk_str *str)
nk_buffer_free(&str->buffer);
str->len = 0;
}

Some files were not shown because too many files have changed in this diff Show More