├── .editorconfig ├── .gitattributes ├── .github └── workflows │ ├── ccpp.yml │ ├── create-tag.yml │ └── docs.yml ├── .gitignore ├── LICENSE ├── Makefile ├── Readme.md ├── clib.json ├── demo ├── allegro5 │ ├── KeyboardHandleriOS.h │ ├── KeyboardHandleriOS.m │ ├── Makefile │ ├── Readme.md │ ├── main.c │ └── nuklear_allegro5.h ├── common │ ├── calculator.c │ ├── canvas.c │ ├── file_browser.c │ ├── filebrowser │ │ ├── icon │ │ │ ├── checked.png │ │ │ ├── cloud.png │ │ │ ├── computer.png │ │ │ ├── copy.png │ │ │ ├── default.png │ │ │ ├── delete.png │ │ │ ├── desktop.png │ │ │ ├── directory.png │ │ │ ├── edit.png │ │ │ ├── export.png │ │ │ ├── font.png │ │ │ ├── home.png │ │ │ ├── img.png │ │ │ ├── movie.png │ │ │ ├── music.png │ │ │ ├── next.png │ │ │ ├── pause.png │ │ │ ├── pen.png │ │ │ ├── phone.png │ │ │ ├── plane.png │ │ │ ├── play.png │ │ │ ├── prev.png │ │ │ ├── rocket.png │ │ │ ├── settings.png │ │ │ ├── stop.png │ │ │ ├── text.png │ │ │ ├── tools.png │ │ │ ├── unchecked.png │ │ │ ├── volume.png │ │ │ └── wifi.png │ │ └── stb_image.h │ ├── node_editor.c │ ├── overview.c │ ├── style.c │ └── style_configurator.c ├── d3d11 │ ├── build.bat │ ├── main.c │ ├── nuklear_d3d11.h │ ├── nuklear_d3d11.hlsl │ ├── nuklear_d3d11_pixel_shader.h │ └── nuklear_d3d11_vertex_shader.h ├── d3d12 │ ├── build.bat │ ├── main.c │ ├── nuklear_d3d12.h │ ├── nuklear_d3d12.hlsl │ ├── nuklear_d3d12_pixel_shader.h │ └── nuklear_d3d12_vertex_shader.h ├── d3d9 │ ├── build.bat │ ├── main.c │ └── nuklear_d3d9.h ├── gdi │ ├── build.bat │ ├── main.c │ └── nuklear_gdi.h ├── gdi_native_nuklear │ ├── build.bat │ ├── main.c │ ├── nuklear_gdi.h │ └── window.h ├── gdip │ ├── build.bat │ ├── main.c │ └── nuklear_gdip.h ├── glfw_opengl2 │ ├── Makefile │ ├── main.c │ └── nuklear_glfw_gl2.h ├── glfw_opengl3 │ ├── Makefile │ ├── main.c │ └── nuklear_glfw_gl3.h ├── glfw_opengl4 │ ├── Makefile │ ├── main.c │ └── nuklear_glfw_gl4.h ├── glfw_vulkan │ ├── .clang-format │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── main.c │ ├── nuklear_glfw_vulkan.h │ ├── shaders │ │ ├── demo.frag │ │ └── demo.vert │ └── src │ │ ├── Makefile │ │ ├── README.md │ │ ├── nuklear_glfw_vulkan.in.h │ │ └── nuklearshaders │ │ ├── nuklear.frag │ │ └── nuklear.vert ├── rawfb │ ├── nuklear_rawfb.h │ ├── sdl │ │ ├── Makefile │ │ └── main.c │ ├── wayland │ │ ├── .gitignore │ │ ├── Makefile │ │ └── main.c │ └── x11 │ │ ├── Makefile │ │ ├── main.c │ │ └── nuklear_xlib.h ├── sdl_opengl2 │ ├── Makefile │ ├── main.c │ └── nuklear_sdl_gl2.h ├── sdl_opengl3 │ ├── Makefile │ ├── main.c │ └── nuklear_sdl_gl3.h ├── sdl_opengles2 │ ├── Makefile │ ├── Readme.md │ ├── main.c │ └── nuklear_sdl_gles2.h ├── sdl_renderer │ ├── Makefile │ ├── main.c │ └── nuklear_sdl_renderer.h ├── sdl_vulkan │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── main.c │ ├── nuklear_sdl_vulkan.h │ ├── shaders │ │ ├── demo.frag │ │ └── demo.vert │ └── src │ │ ├── Makefile │ │ ├── README.md │ │ ├── nuklear_sdl_vulkan.in.h │ │ └── nuklearshaders │ │ ├── nuklear.frag │ │ └── nuklear.vert ├── sfml_opengl2 │ ├── Makefile │ ├── Readme.md │ ├── main.cpp │ └── nuklear_sfml_gl2.h ├── sfml_opengl3 │ ├── Makefile │ ├── Readme.md │ ├── main.cpp │ └── nuklear_sfml_gl3.h ├── x11 │ ├── Makefile │ ├── main.c │ └── nuklear_xlib.h ├── x11_opengl2 │ ├── Makefile │ ├── main.c │ └── nuklear_xlib_gl2.h ├── x11_opengl3 │ ├── Makefile │ ├── main.c │ └── nuklear_xlib_gl3.h ├── x11_xft │ ├── Makefile │ ├── main.c │ └── nuklear_xlib.h └── xcb_cairo │ ├── Makefile │ ├── main.c │ └── nuklear_xcb.h ├── doc └── Doxyfile ├── example ├── Makefile ├── canvas.c ├── extended.c ├── file_browser.c ├── icon │ ├── checked.png │ ├── cloud.png │ ├── computer.png │ ├── copy.png │ ├── default.png │ ├── delete.png │ ├── desktop.png │ ├── directory.png │ ├── edit.png │ ├── export.png │ ├── font.png │ ├── home.png │ ├── img.png │ ├── movie.png │ ├── music.png │ ├── next.png │ ├── pause.png │ ├── pen.png │ ├── phone.png │ ├── plane.png │ ├── play.png │ ├── prev.png │ ├── rocket.png │ ├── settings.png │ ├── stop.png │ ├── text.png │ ├── tools.png │ ├── unchecked.png │ ├── volume.png │ └── wifi.png ├── images │ ├── image1.png │ ├── image2.png │ ├── image3.png │ ├── image4.png │ ├── image5.png │ ├── image6.png │ ├── image7.png │ ├── image8.png │ └── image9.png ├── skinning.c ├── skins │ └── gwen.png └── stb_image.h ├── extra_font ├── Cousine-Regular.ttf ├── DroidSans.ttf ├── Karla-Regular.ttf ├── ProggyClean.ttf ├── ProggyTiny.ttf ├── Raleway-Bold.ttf ├── Roboto-Bold.ttf ├── Roboto-Light.ttf ├── Roboto-Regular.ttf ├── kenvector_future.ttf └── kenvector_future_thin.ttf ├── nuklear.h └── src ├── CHANGELOG ├── CREDITS ├── HEADER.md ├── LICENSE ├── Readme.md ├── build.py ├── nuklear.h ├── nuklear_9slice.c ├── nuklear_buffer.c ├── nuklear_button.c ├── nuklear_chart.c ├── nuklear_color.c ├── nuklear_color_picker.c ├── nuklear_combo.c ├── nuklear_context.c ├── nuklear_contextual.c ├── nuklear_draw.c ├── nuklear_edit.c ├── nuklear_font.c ├── nuklear_group.c ├── nuklear_image.c ├── nuklear_input.c ├── nuklear_internal.h ├── nuklear_knob.c ├── nuklear_layout.c ├── nuklear_list_view.c ├── nuklear_math.c ├── nuklear_menu.c ├── nuklear_page_element.c ├── nuklear_panel.c ├── nuklear_pool.c ├── nuklear_popup.c ├── nuklear_progress.c ├── nuklear_property.c ├── nuklear_scrollbar.c ├── nuklear_selectable.c ├── nuklear_slider.c ├── nuklear_string.c ├── nuklear_style.c ├── nuklear_table.c ├── nuklear_text.c ├── nuklear_text_editor.c ├── nuklear_toggle.c ├── nuklear_tooltip.c ├── nuklear_tree.c ├── nuklear_utf8.c ├── nuklear_util.c ├── nuklear_vertex.c ├── nuklear_widget.c ├── nuklear_window.c ├── paq.bat ├── paq.sh ├── stb_rect_pack.h └── stb_truetype.h /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: https://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | charset = utf-8 8 | end_of_line = lf 9 | indent_size = 4 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [**.{json,yml}] 14 | indent_size = 2 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Github language settings 2 | *.h linguist-language=c 3 | *.c linguist-language=c 4 | 5 | *.h text eol=auto 6 | *.c text eol=auto 7 | -------------------------------------------------------------------------------- /.github/workflows/ccpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v4 12 | - name: apt-update 13 | run: sudo apt-get update -qq 14 | - name: apt get demo-libs 15 | run: sudo apt-get install -y --no-install-recommends glslc liballegro5-dev liballegro-image5-dev liballegro-ttf5-dev libcairo2-dev libglfw3 libglfw3-dev libglew-dev libsdl2-dev libvulkan-dev libwayland-dev libx11-dev libxcb1-dev libxcb-util0-dev libxcb-keysyms1-dev libxft-dev libxkbcommon-x11-dev wayland-protocols 16 | - name: build allegro5 17 | run: make -C demo/allegro5 18 | - name: build glfw_opengl2 19 | run: make -C demo/glfw_opengl2 20 | - name: build glfw_opengl3 21 | run: make -C demo/glfw_opengl3 22 | - name: build glfw_opengl4 23 | run: make -C demo/glfw_opengl4 24 | - name: build glfw_vulkan 25 | run: make -C demo/glfw_vulkan 26 | - name: build sdl_opengl2 27 | run: make -C demo/sdl_opengl2 28 | - name: build sdl_opengl3 29 | run: make -C demo/sdl_opengl3 30 | - name: build sdl_opengles2 31 | run: make -C demo/sdl_opengles2 32 | - name: build sdl_renderer 33 | run: make -C demo/sdl_renderer 34 | - name: build sdl_vulkan 35 | run: make -C demo/sdl_vulkan 36 | - name: build sdl_rawfb 37 | run: make -C demo/rawfb/sdl 38 | - name: build wayland_rawfb 39 | run: make -C demo/rawfb/wayland 40 | - name: build x11 41 | run: make -C demo/x11 42 | - name: build x11_opengl2 43 | run: make -C demo/x11_opengl2 44 | - name: build x11_opengl3 45 | run: make -C demo/x11_opengl3 46 | - name: build x11_rawfb 47 | run: make -C demo/rawfb/x11 48 | - name: build x11_xft 49 | run: make -C demo/x11_xft 50 | - name: build xcb_cairo 51 | run: make -C demo/xcb_cairo 52 | - name: build example 53 | run: make -C example 54 | -------------------------------------------------------------------------------- /.github/workflows/create-tag.yml: -------------------------------------------------------------------------------- 1 | name: Create Tag 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | - uses: butlerlogic/action-autotag@1.1.2 14 | env: 15 | GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 16 | with: 17 | root: clib.json 18 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Documentation on github.io 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | 7 | jobs: 8 | build-documentation: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: checkout 12 | uses: actions/checkout@v4 13 | - name: apt-update 14 | run: sudo apt-get update -qq 15 | - name: apt-get doxygen 16 | run: sudo apt-get install -y doxygen 17 | - name: build doc 18 | run: make docs 19 | - name: deploy 20 | uses: peaceiris/actions-gh-pages@v4 21 | with: 22 | github_token: ${{ secrets.GITHUB_TOKEN }} 23 | publish_dir: ./doc/html/ 24 | enable_jekyll: false 25 | allow_empty_commit: false 26 | force_orphan: true 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | demo/*/*/demo 2 | demo/*/bin/* 3 | example/bin/* 4 | docs/xml 5 | docs/build 6 | docs/src 7 | doc/doc* 8 | doc/* 9 | *.tmp 10 | *.swo 11 | *.swp 12 | *.o 13 | *.obj 14 | *.exe 15 | *.dSYM 16 | /private/ 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | This software is available under 2 licenses -- choose whichever you prefer. 3 | ------------------------------------------------------------------------------ 4 | ALTERNATIVE A - MIT License 5 | Copyright (c) 2017 Micha Mettke 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is furnished to do 11 | so, subject to the following conditions: 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | ------------------------------------------------------------------------------ 22 | ALTERNATIVE B - Public Domain (www.unlicense.org) 23 | This is free and unencumbered software released into the public domain. 24 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 25 | software, either in source code form or as a compiled binary, for any purpose, 26 | commercial or non-commercial, and by any means. 27 | In jurisdictions that recognize copyright laws, the author or authors of this 28 | software dedicate any and all copyright interest in the software to the public 29 | domain. We make this dedication for the benefit of the public at large and to 30 | the detriment of our heirs and successors. We intend this dedication to be an 31 | overt act of relinquishment in perpetuity of all present and future rights to 32 | this software under copyright law. 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 37 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 38 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 39 | ----------------------------------------------------------------------------- 40 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | ###################################################################################### 3 | ## SETTINGS ## 4 | ###################################################################################### 5 | 6 | ## path stuff 7 | DOCS_PATH:=./doc 8 | DEMO_PATH=demo 9 | SRC_PATH=src 10 | 11 | 12 | ## Documents settings 13 | DOXYFILE:=$(DOCS_PATH)/Doxyfile 14 | 15 | 16 | ## HEADER file packing settings 17 | ## note: source file paths are prefixed later, no need to add prefix here; just 18 | ## give it the name. 19 | MACRO = NK 20 | INTRO = HEADER.md 21 | PUB = nuklear.h 22 | OUTPUT = nuklear.h 23 | 24 | PRIV1 = nuklear_internal.h nuklear_math.c nuklear_util.c nuklear_color.c nuklear_utf8.c nuklear_buffer.c nuklear_string.c nuklear_draw.c nuklear_vertex.c 25 | 26 | EXTERN = stb_rect_pack.h stb_truetype.h 27 | 28 | PRIV2 = nuklear_font.c nuklear_input.c nuklear_style.c nuklear_context.c nuklear_pool.c nuklear_page_element.c nuklear_table.c nuklear_panel.c nuklear_window.c nuklear_popup.c nuklear_contextual.c nuklear_menu.c nuklear_layout.c nuklear_tree.c nuklear_group.c nuklear_list_view.c nuklear_widget.c nuklear_text.c nuklear_image.c nuklear_9slice.c nuklear_button.c nuklear_toggle.c nuklear_selectable.c nuklear_slider.c nuklear_knob.c nuklear_progress.c nuklear_scrollbar.c nuklear_text_editor.c nuklear_edit.c nuklear_property.c nuklear_chart.c nuklear_color_picker.c nuklear_combo.c nuklear_tooltip.c 29 | 30 | OUTRO = LICENSE CHANGELOG CREDITS 31 | 32 | ## Demo settings 33 | DEMO_LIST = $(shell find $(DEMO_PATH) -type f -name Makefile -printf "%h ") 34 | 35 | ###################################################################################### 36 | ## RECIPES ## 37 | ###################################################################################### 38 | 39 | 40 | .PHONY: usage all demos $(DEMO_LIST) 41 | 42 | usage: 43 | echo "make docs to create documentation" 44 | echo "make nuke to rebuild the single header nuklear.h from source" 45 | echo "make demos to build all of the demos" 46 | echo "make all to re-pack the header and create documentation" 47 | 48 | all: docs nuke demos 49 | demos: $(DEMO_LIST) 50 | 51 | 52 | ######################################################################################## 53 | ## Nuklear.h 54 | 55 | nuke: $(addprefix $(SRC_PATH)/, $(SRC)) 56 | python3 $(SRC_PATH)/build.py --macro $(MACRO) --intro $(addprefix $(SRC_PATH)/, $(INTRO)) --pub $(addprefix $(SRC_PATH)/, $(PUB)) --priv1 "$(addprefix $(SRC_PATH)/, $(PRIV1))" --extern "$(addprefix $(SRC_PATH)/, $(EXTERN))" --priv2 "$(addprefix $(SRC_PATH)/, $(PRIV2))" --outro "$(addprefix $(SRC_PATH)/, $(OUTRO))" > $(OUTPUT) 57 | 58 | 59 | 60 | 61 | 62 | ######################################################################################## 63 | ## Docs 64 | 65 | docs: $(DOCS_PATH)/html/index.html 66 | 67 | $(DOCS_PATH)/html/index.html: $(DOCS_PATH)/doxygen-awesome-css/doxygen-awesome.css $(DOXYFILE) 68 | doxygen $(DOXYFILE) 69 | 70 | $(DOXYFILE): 71 | doxygen -g $@ 72 | 73 | $(DOCS_PATH)/doxygen-awesome-css/doxygen-awesome.css: 74 | git clone https://github.com/jothepro/doxygen-awesome-css.git $(DOCS_PATH)/doxygen-awesome-css --branch v2.3.4 75 | 76 | 77 | 78 | ######################################################################################## 79 | ## Demos 80 | 81 | $(DEMO_LIST): 82 | $(MAKE) -C $@ 83 | 84 | 85 | 86 | ######################################################################################## 87 | ## Utility helpers 88 | 89 | clean: 90 | rm -rf $(DOCS_PATH)/html $(OUTPUT) 91 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Nuklear 2 | 3 | [![](https://github.com/Immediate-Mode-UI/Nuklear/workflows/C%2FC++%20CI/badge.svg )](https://github.com/Immediate-Mode-UI/Nuklear/actions) 4 | 5 | This is a minimal-state, immediate-mode graphical user interface toolkit 6 | written in ANSI C and licensed under public domain. It was designed as a simple 7 | embeddable user interface for application and does not have any dependencies, 8 | a default render backend or OS window/input handling but instead provides a 9 | highly modular, library-based approach, with simple input state for input and 10 | draw commands describing primitive shapes as output. So instead of providing a 11 | layered library that tries to abstract over a number of platform and 12 | render backends, it focuses only on the actual UI. 13 | 14 | ## Features 15 | 16 | - Immediate-mode graphical user interface toolkit 17 | - Single-header library 18 | - Written in C89 (ANSI C) 19 | - Small codebase (~18kLOC) 20 | - Focus on portability, efficiency and simplicity 21 | - No dependencies (not even the standard library if not wanted) 22 | - Fully skinnable and customizable 23 | - Low memory footprint with total control of memory usage if needed / wanted 24 | - UTF-8 support 25 | - No global or hidden state 26 | - Customizable library modules (you can compile and use only what you need) 27 | - Optional font baker and vertex buffer output 28 | - [Documentation](https://Immediate-Mode-UI.github.io/Nuklear/) 29 | 30 | ## Building 31 | 32 | This library is self-contained in one single header file and can be used either 33 | in header-only mode or in implementation mode. The header-only mode is used 34 | by default when included and allows including this header in other headers 35 | and does not contain the actual implementation. 36 | 37 | The implementation mode requires defining the preprocessor macro 38 | `NK_IMPLEMENTATION` in *one* .c/.cpp file before `#include`ing this file, e.g.: 39 | ```c 40 | #define NK_IMPLEMENTATION 41 | #include "nuklear.h" 42 | ``` 43 | IMPORTANT: Every time you include "nuklear.h" you have to define the same optional flags. 44 | This is very important; not doing it either leads to compiler errors, or even worse, stack corruptions. 45 | 46 | ## Gallery 47 | 48 | ![screenshot](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif) 49 | ![screen](https://cloud.githubusercontent.com/assets/8057201/13538240/acd96876-e249-11e5-9547-5ac0b19667a0.png) 50 | ![screen2](https://cloud.githubusercontent.com/assets/8057201/13538243/b04acd4c-e249-11e5-8fd2-ad7744a5b446.png) 51 | ![node](https://cloud.githubusercontent.com/assets/8057201/9976995/e81ac04a-5ef7-11e5-872b-acd54fbeee03.gif) 52 | ![skinning](https://cloud.githubusercontent.com/assets/8057201/15991632/76494854-30b8-11e6-9555-a69840d0d50b.png) 53 | ![gamepad](https://cloud.githubusercontent.com/assets/8057201/14902576/339926a8-0d9c-11e6-9fee-a8b73af04473.png) 54 | 55 | ## Example 56 | 57 | ```c 58 | /* init gui state */ 59 | struct nk_context ctx; 60 | nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font); 61 | 62 | enum {EASY, HARD}; 63 | static int op = EASY; 64 | static float value = 0.6f; 65 | static int i = 20; 66 | 67 | if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220), 68 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) { 69 | /* fixed widget pixel width */ 70 | nk_layout_row_static(&ctx, 30, 80, 1); 71 | if (nk_button_label(&ctx, "button")) { 72 | /* event handling */ 73 | } 74 | 75 | /* fixed widget window ratio width */ 76 | nk_layout_row_dynamic(&ctx, 30, 2); 77 | if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY; 78 | if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD; 79 | 80 | /* custom widget pixel width */ 81 | nk_layout_row_begin(&ctx, NK_STATIC, 30, 2); 82 | { 83 | nk_layout_row_push(&ctx, 50); 84 | nk_label(&ctx, "Volume:", NK_TEXT_LEFT); 85 | nk_layout_row_push(&ctx, 110); 86 | nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f); 87 | } 88 | nk_layout_row_end(&ctx); 89 | } 90 | nk_end(&ctx); 91 | ``` 92 | ![example](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png) 93 | 94 | ## Bindings 95 | There are a number of nuklear bindings for different languages created by other authors. 96 | I cannot attest for their quality since I am not necessarily proficient in any of these 97 | languages. Furthermore there are no guarantee that all bindings will always be kept up to date: 98 | 99 | - [Java](https://github.com/glegris/nuklear4j) by Guillaume Legris 100 | - [D](https://github.com/Timu5/bindbc-nuklear) by Mateusz Muszyński 101 | - [Golang](https://github.com/golang-ui/nuklear) by golang-ui@github.com 102 | - [Rust](https://github.com/snuk182/nuklear-rust) by snuk182@github.com 103 | - [Chicken](https://github.com/wasamasa/nuklear) by wasamasa@github.com 104 | - [Nim](https://github.com/zacharycarter/nuklear-nim) by zacharycarter@github.com 105 | - Lua 106 | - [LÖVE-Nuklear](https://github.com/keharriso/love-nuklear) by Kevin Harrison 107 | - [MoonNuklear](https://github.com/stetre/moonnuklear) by Stefano Trettel 108 | - Python 109 | - [pyNuklear](https://github.com/billsix/pyNuklear) by William Emerison Six (ctypes-based wrapper) 110 | - [pynk](https://github.com/nathanrw/nuklear-cffi) by nathanrw@github.com (cffi binding) 111 | - [CSharp/.NET](https://github.com/cartman300/NuklearDotNet) by cartman300@github.com 112 | - [V](https://github.com/nsauzede/vnk) by Nicolas Sauzede 113 | 114 | ## Credits 115 | Developed by Micha Mettke and every direct or indirect contributor to the GitHub. 116 | 117 | 118 | Embeds `stb_texedit`, `stb_truetype` and `stb_rectpack` by Sean Barrett (public domain) 119 | Embeds `ProggyClean.ttf` font by Tristan Grimmer (MIT license). 120 | 121 | 122 | Big thank you to Omar Cornut (ocornut@github) for his [imgui](https://github.com/ocornut/imgui) library and 123 | giving me the inspiration for this library, Casey Muratori for handmade hero 124 | and his original immediate-mode graphical user interface idea and Sean 125 | Barrett for his amazing single-header [libraries](https://github.com/nothings/stb) which restored my faith 126 | 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). 127 | 128 | ## License 129 | Nuklear is avaliable under either the MIT License or public domain. 130 | See [LICENSE](LICENSE) for more info. 131 | 132 | ## Reviewers guide 133 | 134 | When reviewing pull request there are common things a reviewer should keep 135 | in mind. 136 | 137 | Reviewing changes to `src/*` and `nuklear.h`: 138 | 139 | * Ensure C89 compatibility. 140 | * The code should work for several backends to an acceptable degree. 141 | * Check no other parts of `nuklear.h` are related to the PR and thus nothing is missing. 142 | * Recommend simple optimizations. 143 | * Pass small structs by value instead of by pointer. 144 | * Use local buffers over heap allocation when possible. 145 | * Check that the coding style is consistent with code around it. 146 | * Variable/function name casing. 147 | * Indentation. 148 | * Curly bracket (`{}`) placement. 149 | * Ensure that the contributor has bumped the appropriate version in 150 | [clib.json](https://github.com/Immediate-Mode-UI/Nuklear/blob/master/clib.json) 151 | and added their changes to the 152 | [CHANGELOG](https://github.com/Immediate-Mode-UI/Nuklear/blob/master/src/CHANGELOG). 153 | * Have at least one other person review the changes before merging. 154 | 155 | Reviewing changes to `demo/*`, `example/*` and other files in the repo: 156 | 157 | * Focus on getting working code merged. 158 | * We want to make it easy for people to get started with Nuklear, and any 159 | `demo` and `example` improvements helps in this regard. 160 | * Use of newer C features, or even other languages is not discouraged. 161 | * If another language is used, ensure that the build process is easy to figure out. 162 | * Messy or less efficient code can be merged so long as these outliers are pointed out 163 | and easy to find. 164 | * Version shouldn't be bumped for these changes. 165 | * Changes that improves code to be more inline with `nuklear.h` are ofc always welcome. 166 | 167 | -------------------------------------------------------------------------------- /clib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nuklear", 3 | "version": "4.12.7", 4 | "repo": "Immediate-Mode-UI/Nuklear", 5 | "description": "A small ANSI C gui toolkit", 6 | "keywords": ["gl", "ui", "toolkit"], 7 | "license": "MIT, Unlicense", 8 | "src": ["nuklear.h"] 9 | } 10 | -------------------------------------------------------------------------------- /demo/allegro5/KeyboardHandleriOS.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #include 4 | 5 | @interface KeyboardHandleriOS : UIView 6 | -(void)setCustomKeyboardEventSource:(ALLEGRO_EVENT_SOURCE*)ev_src; 7 | -(void)show; 8 | -(void)hide; 9 | @end 10 | 11 | -------------------------------------------------------------------------------- /demo/allegro5/KeyboardHandleriOS.m: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | #import "KeyboardHandleriOS.h" 5 | #include 6 | #include 7 | @interface KeyboardHandleriOS() 8 | { 9 | ALLEGRO_EVENT_SOURCE *event_source; 10 | ALLEGRO_DISPLAY *current_display; 11 | } 12 | @end 13 | @implementation KeyboardHandleriOS 14 | - (id)init { 15 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil]; 16 | self = [self initWithFrame:CGRectMake(-100, -100, 0, 0)]; 17 | event_source = NULL; 18 | current_display = al_get_current_display(); 19 | UIView* v = al_iphone_get_view(current_display); 20 | [v addSubview:self]; 21 | return self; 22 | } 23 | 24 | - (void)setCustomKeyboardEventSource:(ALLEGRO_EVENT_SOURCE *)ev_src { 25 | event_source = ev_src; 26 | } 27 | 28 | - (UIKeyboardType) keyboardType 29 | { 30 | return UIKeyboardTypeASCIICapable; 31 | } 32 | 33 | - (UITextAutocorrectionType) autocorrectionType 34 | { 35 | return UITextAutocorrectionTypeNo; 36 | } 37 | 38 | -(BOOL)canBecomeFirstResponder { 39 | return YES; 40 | } 41 | 42 | - (void)deleteBackward { 43 | 44 | if (!event_source) { 45 | NSLog(@"deleteBackward(): No event source found, not sending events"); 46 | return; 47 | } 48 | 49 | ALLEGRO_EVENT *event_down = (ALLEGRO_EVENT*)calloc(1, sizeof(ALLEGRO_EVENT)); 50 | ALLEGRO_EVENT *event_up = (ALLEGRO_EVENT*)calloc(1, sizeof(ALLEGRO_EVENT)); 51 | 52 | event_down->type = ALLEGRO_EVENT_KEY_DOWN; 53 | event_down->keyboard.display = current_display; 54 | event_down->keyboard.keycode = ALLEGRO_KEY_BACKSPACE; 55 | event_up->type = ALLEGRO_EVENT_KEY_UP; 56 | event_up->keyboard.display = current_display; 57 | event_up->keyboard.keycode = ALLEGRO_KEY_BACKSPACE; 58 | al_emit_user_event(event_source, event_down, NULL); 59 | al_emit_user_event(event_source, event_up, NULL); 60 | 61 | free(event_down); 62 | free(event_up); 63 | } 64 | 65 | - (BOOL)hasText { 66 | return YES; 67 | } 68 | 69 | - (void)insertText:(NSString *)text 70 | { 71 | if (!event_source) { 72 | NSLog(@"insertText(): No event source found, not sending events"); 73 | return; 74 | } 75 | 76 | ALLEGRO_EVENT *event_down = (ALLEGRO_EVENT*)calloc(1, sizeof(ALLEGRO_EVENT)); 77 | ALLEGRO_EVENT *event_up = (ALLEGRO_EVENT*)calloc(1, sizeof(ALLEGRO_EVENT)); 78 | 79 | if([text isEqualToString:@"\n"]) 80 | { 81 | event_down->type = ALLEGRO_EVENT_KEY_DOWN; 82 | event_down->keyboard.display = current_display; 83 | event_down->keyboard.keycode = ALLEGRO_KEY_ENTER; 84 | event_up->type = ALLEGRO_EVENT_KEY_UP; 85 | event_up->keyboard.display = current_display; 86 | event_up->keyboard.keycode = ALLEGRO_KEY_ENTER; 87 | al_emit_user_event(event_source, event_down, NULL); 88 | al_emit_user_event(event_source, event_up, NULL); 89 | [self hide]; 90 | //m_kb->setDonePressed(); 91 | } 92 | else { 93 | event_down->type = ALLEGRO_EVENT_KEY_CHAR; 94 | event_down->keyboard.display = current_display; 95 | event_down->keyboard.unichar = [text characterAtIndex:0]; 96 | // doesn't matter what keycode is, nuklear backend ignores it as long as it 97 | // isn't a special key 98 | event_down->keyboard.keycode = ALLEGRO_KEY_A; 99 | al_emit_user_event(event_source, event_down, NULL); 100 | } 101 | free(event_down); 102 | free(event_up); 103 | } 104 | 105 | -(void)show { 106 | NSLog(@"Should be showing!"); 107 | [self performSelectorOnMainThread:@selector(becomeFirstResponder) withObject:nil waitUntilDone:YES]; 108 | } 109 | -(void)hide { 110 | NSLog(@"Should be hiding!"); 111 | [self performSelectorOnMainThread:@selector(resignFirstResponder) withObject:nil waitUntilDone:YES]; 112 | } 113 | - (void)keyboardDidHide:(NSNotification *)notification { 114 | NSLog(@"keyboardDidHide called"); 115 | } 116 | 117 | -(void)dealloc { 118 | [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil]; 119 | } 120 | @end 121 | -------------------------------------------------------------------------------- /demo/allegro5/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | # TODO: Handle Windows build 11 | #ifeq ($(OS),Windows_NT) 12 | #BIN := $(BIN).exe 13 | #LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32 14 | #else 15 | LIBS = -lallegro -lallegro_main -lallegro_image -lallegro_font \ 16 | -lallegro_ttf -lallegro_primitives -lm 17 | #endif 18 | 19 | $(BIN): 20 | @mkdir -p bin 21 | rm -f bin/$(BIN) $(OBJS) 22 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 23 | -------------------------------------------------------------------------------- /demo/allegro5/Readme.md: -------------------------------------------------------------------------------- 1 | # Allegro v5 nuklear backend 2 | 3 | This backend provides support for [Allegro version 5](https://liballeg.github.io). It works on on all supported platforms with an OpenGL backend, including iOS and Android. 4 | 5 | Touch support is provided by handling the first touch (ignoring any extra simultaneous touches) and emitting nuklear mouse events. nuklear will handle only the first touch like a single left-mouse click. Dragging the touch screen emits mouse-move events. 6 | 7 | ## Compiling 8 | You must link with image, font, ttf, and primitives Allegro addons. See the `Makefile`. 9 | 10 | ## Resolutions 11 | 12 | Like every nuklear backend, handling many different resolutions and resolution densities can be tricky. 14px font on a desktop may be perfect, but extremely small on a retina iPad. I recommend writing a middleware that will detect what kind of screen is being used, and modify the sizes of widgets accordingly. 13 | 14 | ## Soft Keyboard for Touch Screen Devices 15 | 16 | Information on how to implement soft keyboard callbacks for Android can be on the Allegro community wiki: https://wiki.allegro.cc/index.php?title=Running_Allegro_applications_on_Android#Displaying_the_Android_keyboard 17 | 18 | To display a soft keyboard on iOS, you must create a `UIView` subclass that implements the `UIKeyInput` interface. See `KeyboardHandleriOS.h` and `KeyboardHandleriOS.m` Objective-C source code files for an example on how to do this. As the Allegro keyboard driver does not currently listen for iOS events, we use a custom event emitter to emit keyboard events, which is passed in after initialization with `(void)setCustomKeyboardEventSource:(ALLEGRO_EVENT_SOURCE *)ev_src`. This causes normal keyboard events to be emitted and properly caught by the nuklear backend. The provided `main.c` demo file does not implement this, but with the provided source code files it is not difficult to do. See this Allegro community forum thread for more information: https://www.allegro.cc/forums/thread/616672 19 | 20 | To know when nuklear wants to open and close the keyboard, you can check edit widget flags: 21 | 22 | ``` 23 | nk_flags ed_flags = nk_edit_string(ctx, NK_EDIT_FIELD, field_buffer, &field_len, 64, nk_filter_default); 24 | if (ed_flags & NK_EDIT_ACTIVATED) 25 | open_ios_soft_keyboard(); 26 | if (ed_flags & NK_EDIT_DEACTIVATED) 27 | close_ios_soft_keyboard(); 28 | ``` 29 | 30 | ### Manual Soft Keyboard Dismissal 31 | As the user can dismiss a keyboard manually, nuklear will not be aware when this occurs, and the text edit cursor will think the entry field is still active. I recommend catching the dismiss event, then emitting `ALLEGRO_EVENT_TOUCH_BEGIN` and `ALLEGRO_EVENT_TOUCH_END` events in an unused portion of the screen (like the bottom-right corner). This will simulate the user touching outside of the text entry widget, which will make the edit field inactive. 32 | 33 | ### The Keyboard Covers Widgets 34 | 35 | If you have a widget near the bottom of the screen, the keyboard opening woll cover it, and the user won't see what they are entering. One way to handle this is to make all text edit widgets view-only, and when tapped you dynamically create a new widget above the keyboard that receives all the key strokes. When the user dismisses the keyboard, copy the result from the new widget into the existing read-only text view and destroy the dynamic one. -------------------------------------------------------------------------------- /demo/allegro5/main.c: -------------------------------------------------------------------------------- 1 | /* nuklear - 1.32.0 - public domain */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #define WINDOW_WIDTH 1200 15 | #define WINDOW_HEIGHT 800 16 | 17 | #define NK_INCLUDE_FIXED_TYPES 18 | #define NK_INCLUDE_STANDARD_IO 19 | #define NK_INCLUDE_STANDARD_VARARGS 20 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 21 | #define NK_IMPLEMENTATION 22 | #define NK_ALLEGRO5_IMPLEMENTATION 23 | #include "../../nuklear.h" 24 | #include "nuklear_allegro5.h" 25 | 26 | 27 | #define UNUSED(a) (void)a 28 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 29 | #define MAX(a,b) ((a) < (b) ? (b) : (a)) 30 | #define LEN(a) (sizeof(a)/sizeof(a)[0]) 31 | 32 | 33 | /* =============================================================== 34 | * 35 | * EXAMPLE 36 | * 37 | * ===============================================================*/ 38 | /* This are some code examples to provide a small overview of what can be 39 | * done with this library. To try out an example uncomment the defines */ 40 | /*#define INCLUDE_ALL */ 41 | /*#define INCLUDE_STYLE */ 42 | /*#define INCLUDE_CALCULATOR */ 43 | /*#define INCLUDE_CANVAS */ 44 | #define INCLUDE_OVERVIEW 45 | /*#define INCLUDE_CONFIGURATOR */ 46 | /*#define INCLUDE_NODE_EDITOR */ 47 | 48 | #ifdef INCLUDE_ALL 49 | #define INCLUDE_STYLE 50 | #define INCLUDE_CALCULATOR 51 | #define INCLUDE_CANVAS 52 | #define INCLUDE_OVERVIEW 53 | #define INCLUDE_CONFIGURATOR 54 | #define INCLUDE_NODE_EDITOR 55 | #endif 56 | 57 | #ifdef INCLUDE_STYLE 58 | #include "../../demo/common/style.c" 59 | #endif 60 | #ifdef INCLUDE_CALCULATOR 61 | #include "../../demo/common/calculator.c" 62 | #endif 63 | #ifdef INCLUDE_CANVAS 64 | #include "../../demo/common/canvas.c" 65 | #endif 66 | #ifdef INCLUDE_OVERVIEW 67 | #include "../../demo/common/overview.c" 68 | #endif 69 | #ifdef INCLUDE_CONFIGURATOR 70 | #include "../../demo/common/style_configurator.c" 71 | #endif 72 | #ifdef INCLUDE_NODE_EDITOR 73 | #include "../../demo/common/node_editor.c" 74 | #endif 75 | 76 | /* =============================================================== 77 | * 78 | * DEMO 79 | * 80 | * ===============================================================*/ 81 | int main(void) 82 | { 83 | /* Platform */ 84 | ALLEGRO_DISPLAY *display = NULL; 85 | ALLEGRO_EVENT_QUEUE *event_queue = NULL; 86 | NkAllegro5Font *font; 87 | struct nk_context *ctx; 88 | 89 | #ifdef INCLUDE_CONFIGURATOR 90 | static struct nk_color color_table[NK_COLOR_COUNT]; 91 | memcpy(color_table, nk_default_color_style, sizeof(color_table)); 92 | #endif 93 | 94 | if (!al_init()) { 95 | fprintf(stdout, "failed to initialize allegro5!\n"); 96 | exit(1); 97 | } 98 | 99 | al_install_mouse(); 100 | al_set_mouse_wheel_precision(150); 101 | al_install_keyboard(); 102 | 103 | al_set_new_display_flags(ALLEGRO_WINDOWED|ALLEGRO_RESIZABLE|ALLEGRO_OPENGL); 104 | al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); 105 | al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST); 106 | display = al_create_display(WINDOW_WIDTH, WINDOW_HEIGHT); 107 | if (!display) { 108 | fprintf(stdout, "failed to create display!\n"); 109 | exit(1); 110 | } 111 | 112 | event_queue = al_create_event_queue(); 113 | if (!event_queue) { 114 | fprintf(stdout, "failed to create event_queue!\n"); 115 | al_destroy_display(display); 116 | exit(1); 117 | } 118 | 119 | al_register_event_source(event_queue, al_get_display_event_source(display)); 120 | al_register_event_source(event_queue, al_get_mouse_event_source()); 121 | al_register_event_source(event_queue, al_get_keyboard_event_source()); 122 | 123 | font = nk_allegro5_font_create_from_file("../../extra_font/Roboto-Regular.ttf", 12, 0); 124 | 125 | ctx = nk_allegro5_init(font, display, WINDOW_WIDTH, WINDOW_HEIGHT); 126 | 127 | while(1) 128 | { 129 | bool get_event; 130 | ALLEGRO_EVENT ev; 131 | ALLEGRO_TIMEOUT timeout; 132 | al_init_timeout(&timeout, 0.06); 133 | 134 | get_event = al_wait_for_event_until(event_queue, &ev, &timeout); 135 | 136 | if (get_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 137 | break; 138 | } 139 | 140 | /* Very Important: Always do nk_input_begin / nk_input_end even if 141 | there are no events, otherwise internal nuklear state gets messed up */ 142 | nk_input_begin(ctx); 143 | if (get_event) { 144 | while (get_event) { 145 | nk_allegro5_handle_event(&ev); 146 | get_event = al_get_next_event(event_queue, &ev); 147 | } 148 | } 149 | nk_input_end(ctx); 150 | 151 | /* GUI */ 152 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 153 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 154 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 155 | { 156 | enum {EASY, HARD}; 157 | static int op = EASY; 158 | static int property = 20; 159 | 160 | nk_layout_row_static(ctx, 30, 80, 1); 161 | if (nk_button_label(ctx, "button")) 162 | fprintf(stdout, "button pressed\n"); 163 | nk_layout_row_dynamic(ctx, 30, 2); 164 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 165 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 166 | nk_layout_row_dynamic(ctx, 22, 1); 167 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 168 | } 169 | nk_end(ctx); 170 | 171 | /* -------------- EXAMPLES ---------------- */ 172 | #ifdef INCLUDE_CALCULATOR 173 | calculator(ctx); 174 | #endif 175 | #ifdef INCLUDE_CANVAS 176 | canvas(ctx); 177 | #endif 178 | #ifdef INCLUDE_OVERVIEW 179 | overview(ctx); 180 | #endif 181 | #ifdef INCLUDE_CONFIGURATOR 182 | style_configurator(ctx, color_table); 183 | #endif 184 | #ifdef INCLUDE_NODE_EDITOR 185 | node_editor(ctx); 186 | #endif 187 | /* ----------------------------------------- */ 188 | 189 | /* Draw */ 190 | al_clear_to_color(al_map_rgb(19, 43, 81)); 191 | /* IMPORTANT: `nk_allegro5_render` changes the target backbuffer 192 | to the display set at initialization and does not restore it. 193 | Change it if you want to draw somewhere else. */ 194 | nk_allegro5_render(); 195 | al_flip_display(); 196 | } 197 | 198 | nk_allegro5_font_del(font); 199 | nk_allegro5_shutdown(); 200 | al_destroy_display(display); 201 | al_destroy_event_queue(event_queue); 202 | return 0; 203 | } 204 | 205 | -------------------------------------------------------------------------------- /demo/common/calculator.c: -------------------------------------------------------------------------------- 1 | /* nuklear - v1.00 - public domain */ 2 | static void 3 | calculator(struct nk_context *ctx) 4 | { 5 | if (nk_begin(ctx, "Calculator", nk_rect(10, 10, 180, 250), 6 | NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE)) 7 | { 8 | static int set = 0, prev = 0, op = 0; 9 | static const char numbers[] = "789456123"; 10 | static const char ops[] = "+-*/"; 11 | static double a = 0, b = 0; 12 | static double *current = &a; 13 | 14 | size_t i = 0; 15 | int solve = 0; 16 | {int len; char buffer[256]; 17 | nk_layout_row_dynamic(ctx, 35, 1); 18 | len = snprintf(buffer, 256, "%.2f", *current); 19 | nk_edit_string(ctx, NK_EDIT_SIMPLE, buffer, &len, 255, nk_filter_float); 20 | buffer[len] = 0; 21 | *current = atof(buffer);} 22 | 23 | nk_layout_row_dynamic(ctx, 35, 4); 24 | for (i = 0; i < 16; ++i) { 25 | if (i >= 12 && i < 15) { 26 | if (i > 12) continue; 27 | if (nk_button_label(ctx, "C")) { 28 | a = b = op = 0; current = &a; set = 0; 29 | } if (nk_button_label(ctx, "0")) { 30 | *current = *current*10.0f; set = 0; 31 | } if (nk_button_label(ctx, "=")) { 32 | solve = 1; prev = op; op = 0; 33 | } 34 | } else if (((i+1) % 4)) { 35 | if (nk_button_text(ctx, &numbers[(i/4)*3+i%4], 1)) { 36 | *current = *current * 10.0f + numbers[(i/4)*3+i%4] - '0'; 37 | set = 0; 38 | } 39 | } else if (nk_button_text(ctx, &ops[i/4], 1)) { 40 | if (!set) { 41 | if (current != &b) { 42 | current = &b; 43 | } else { 44 | prev = op; 45 | solve = 1; 46 | } 47 | } 48 | op = ops[i/4]; 49 | set = 1; 50 | } 51 | } 52 | if (solve) { 53 | if (prev == '+') a = a + b; 54 | if (prev == '-') a = a - b; 55 | if (prev == '*') a = a * b; 56 | if (prev == '/') a = a / b; 57 | current = &a; 58 | if (set) current = &b; 59 | b = 0; set = 0; 60 | } 61 | } 62 | nk_end(ctx); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /demo/common/canvas.c: -------------------------------------------------------------------------------- 1 | /* nuklear - v1.05 - public domain */ 2 | struct nk_canvas { 3 | struct nk_command_buffer *painter; 4 | struct nk_vec2 item_spacing; 5 | struct nk_vec2 panel_padding; 6 | struct nk_style_item window_background; 7 | }; 8 | 9 | static nk_bool 10 | canvas_begin(struct nk_context *ctx, struct nk_canvas *canvas, nk_flags flags, 11 | int x, int y, int width, int height, struct nk_color background_color) 12 | { 13 | /* save style properties which will be overwritten */ 14 | canvas->panel_padding = ctx->style.window.padding; 15 | canvas->item_spacing = ctx->style.window.spacing; 16 | canvas->window_background = ctx->style.window.fixed_background; 17 | 18 | /* use the complete window space and set background */ 19 | ctx->style.window.spacing = nk_vec2(0,0); 20 | ctx->style.window.padding = nk_vec2(0,0); 21 | ctx->style.window.fixed_background = nk_style_item_color(background_color); 22 | 23 | /* create/update window and set position + size */ 24 | if (!nk_begin(ctx, "Canvas", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR|flags)) 25 | return nk_false; 26 | 27 | /* allocate the complete window space for drawing */ 28 | { 29 | struct nk_rect total_space; 30 | total_space = nk_window_get_content_region(ctx); 31 | nk_layout_row_dynamic(ctx, total_space.h, 1); 32 | nk_widget(&total_space, ctx); 33 | canvas->painter = nk_window_get_canvas(ctx); 34 | } 35 | 36 | return nk_true; 37 | } 38 | 39 | static void 40 | canvas_end(struct nk_context *ctx, struct nk_canvas *canvas) 41 | { 42 | nk_end(ctx); 43 | ctx->style.window.spacing = canvas->panel_padding; 44 | ctx->style.window.padding = canvas->item_spacing; 45 | ctx->style.window.fixed_background = canvas->window_background; 46 | } 47 | 48 | static void 49 | canvas(struct nk_context *ctx) 50 | { 51 | struct nk_canvas canvas; 52 | if (canvas_begin(ctx, &canvas, NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 53 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE, 10, 10, 500, 550, nk_rgb(250,250,250))) 54 | { 55 | float x = canvas.painter->clip.x, y = canvas.painter->clip.y; 56 | 57 | nk_fill_rect(canvas.painter, nk_rect(x + 15, y + 15, 210, 210), 5, nk_rgb(247, 230, 154)); 58 | nk_fill_rect(canvas.painter, nk_rect(x + 20, y + 20, 200, 200), 5, nk_rgb(188, 174, 118)); 59 | /* nk_draw_text(canvas.painter, nk_rect(x + 30, y + 30, 150, 20), "Text to draw", 12, &font->handle, nk_rgb(188,174,118), nk_rgb(0,0,0)); */ 60 | nk_fill_rect(canvas.painter, nk_rect(x + 250, y + 20, 100, 100), 0, nk_rgb(0,0,255)); 61 | nk_fill_circle(canvas.painter, nk_rect(x + 20, y + 250, 100, 100), nk_rgb(255,0,0)); 62 | nk_fill_triangle(canvas.painter, x + 250, y + 250, x + 350, y + 250, x + 300, y + 350, nk_rgb(0,255,0)); 63 | nk_fill_arc(canvas.painter, x + 300, y + 420, 50, 0, 3.141592654f * 3.0f / 4.0f, nk_rgb(255,255,0)); 64 | 65 | { 66 | float points[12]; 67 | points[0] = x + 200; points[1] = y + 250; 68 | points[2] = x + 250; points[3] = y + 350; 69 | points[4] = x + 225; points[5] = y + 350; 70 | points[6] = x + 200; points[7] = y + 300; 71 | points[8] = x + 175; points[9] = y + 350; 72 | points[10] = x + 150; points[11] = y + 350; 73 | nk_fill_polygon(canvas.painter, points, 6, nk_rgb(0,0,0)); 74 | } 75 | 76 | { 77 | float points[12]; 78 | points[0] = x + 200; points[1] = y + 370; 79 | points[2] = x + 250; points[3] = y + 470; 80 | points[4] = x + 225; points[5] = y + 470; 81 | points[6] = x + 200; points[7] = y + 420; 82 | points[8] = x + 175; points[9] = y + 470; 83 | points[10] = x + 150; points[11] = y + 470; 84 | nk_stroke_polygon(canvas.painter, points, 6, 4, nk_rgb(0,0,0)); 85 | } 86 | 87 | { 88 | float points[8]; 89 | points[0] = x + 250; points[1] = y + 200; 90 | points[2] = x + 275; points[3] = y + 220; 91 | points[4] = x + 325; points[5] = y + 170; 92 | points[6] = x + 350; points[7] = y + 200; 93 | nk_stroke_polyline(canvas.painter, points, 4, 2, nk_rgb(255,128,0)); 94 | } 95 | 96 | nk_stroke_line(canvas.painter, x + 15, y + 10, x + 200, y + 10, 2.0f, nk_rgb(189,45,75)); 97 | nk_stroke_rect(canvas.painter, nk_rect(x + 370, y + 20, 100, 100), 10, 3, nk_rgb(0,0,255)); 98 | nk_stroke_curve(canvas.painter, x + 380, y + 200, x + 405, y + 270, x + 455, y + 120, x + 480, y + 200, 2, nk_rgb(0,150,220)); 99 | nk_stroke_circle(canvas.painter, nk_rect(x + 20, y + 370, 100, 100), 5, nk_rgb(0,255,120)); 100 | nk_stroke_triangle(canvas.painter, x + 370, y + 250, x + 470, y + 250, x + 420, y + 350, 6, nk_rgb(255,0,143)); 101 | nk_stroke_arc(canvas.painter, x + 420, y + 420, 50, 0, 3.141592654f * 3.0f / 4.0f, 5, nk_rgb(0,255,255)); 102 | } 103 | canvas_end(ctx, &canvas); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/checked.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/cloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/cloud.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/computer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/computer.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/copy.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/default.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/delete.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/desktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/desktop.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/directory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/directory.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/edit.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/export.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/font.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/home.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/img.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/movie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/movie.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/music.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/music.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/next.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/pause.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/pen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/pen.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/phone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/phone.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/plane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/plane.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/play.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/prev.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/rocket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/rocket.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/settings.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/stop.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/text.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/tools.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/unchecked.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/volume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/volume.png -------------------------------------------------------------------------------- /demo/common/filebrowser/icon/wifi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/demo/common/filebrowser/icon/wifi.png -------------------------------------------------------------------------------- /demo/d3d11/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem This will use VS2015 for compiler 4 | call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 5 | 6 | fxc.exe /nologo /T vs_4_0_level_9_0 /E vs /O3 /Zpc /Ges /Fh nuklear_d3d11_vertex_shader.h /Vn nk_d3d11_vertex_shader /Qstrip_reflect /Qstrip_debug /Qstrip_priv nuklear_d3d11.hlsl 7 | fxc.exe /nologo /T ps_4_0_level_9_0 /E ps /O3 /Zpc /Ges /Fh nuklear_d3d11_pixel_shader.h /Vn nk_d3d11_pixel_shader /Qstrip_reflect /Qstrip_debug /Qstrip_priv nuklear_d3d11.hlsl 8 | 9 | cl /D_CRT_SECURE_NO_DEPRECATE /nologo /W3 /O2 /fp:fast /Gm- /Fedemo.exe main.c user32.lib dxguid.lib d3d11.lib /link /incremental:no 10 | -------------------------------------------------------------------------------- /demo/d3d11/nuklear_d3d11.hlsl: -------------------------------------------------------------------------------- 1 | // 2 | cbuffer buffer0 : register(b0) 3 | { 4 | float4x4 ProjectionMatrix; 5 | }; 6 | 7 | sampler sampler0 : register(s0); 8 | Texture2D texture0 : register(t0); 9 | 10 | struct VS_INPUT 11 | { 12 | float2 pos : POSITION; 13 | float4 col : COLOR0; 14 | float2 uv : TEXCOORD0; 15 | }; 16 | 17 | struct PS_INPUT 18 | { 19 | float4 pos : SV_POSITION; 20 | float4 col : COLOR0; 21 | float2 uv : TEXCOORD0; 22 | }; 23 | 24 | PS_INPUT vs(VS_INPUT input) 25 | { 26 | PS_INPUT output; 27 | output.pos = mul(ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f)); 28 | output.col = input.col; 29 | output.uv = input.uv; 30 | return output; 31 | } 32 | 33 | float4 ps(PS_INPUT input) : SV_Target 34 | { 35 | return input.col * texture0.Sample(sampler0, input.uv); 36 | } 37 | -------------------------------------------------------------------------------- /demo/d3d11/nuklear_d3d11_pixel_shader.h: -------------------------------------------------------------------------------- 1 | #if 0 2 | // 3 | // Generated by Microsoft (R) D3D Shader Disassembler 4 | // 5 | // 6 | // Input signature: 7 | // 8 | // Name Index Mask Register SysValue Format Used 9 | // -------------------- ----- ------ -------- -------- ------- ------ 10 | // SV_POSITION 0 xyzw 0 POS float 11 | // COLOR 0 xyzw 1 NONE float xyzw 12 | // TEXCOORD 0 xy 2 NONE float xy 13 | // 14 | // 15 | // Output signature: 16 | // 17 | // Name Index Mask Register SysValue Format Used 18 | // -------------------- ----- ------ -------- -------- ------- ------ 19 | // SV_Target 0 xyzw 0 TARGET float xyzw 20 | // 21 | // 22 | // Sampler/Resource to DX9 shader sampler mappings: 23 | // 24 | // Target Sampler Source Sampler Source Resource 25 | // -------------- --------------- ---------------- 26 | // s0 s0 t0 27 | // 28 | // 29 | // Level9 shader bytecode: 30 | // 31 | ps_2_0 32 | dcl t0 33 | dcl t1.xy 34 | dcl_2d s0 35 | texld r0, t1, s0 36 | mul r0, r0, t0 37 | mov oC0, r0 38 | 39 | // approximately 3 instruction slots used (1 texture, 2 arithmetic) 40 | // 41 | // Sampler/Resource to DX9 shader sampler mappings: 42 | // 43 | // Target Sampler Source Sampler Source Resource 44 | // -------------- --------------- ---------------- 45 | // s0 s0 t0 46 | // 47 | // 48 | // XNA shader bytecode: 49 | // 50 | ps_2_0 51 | dcl t0 52 | dcl t1.xy 53 | dcl_2d s0 54 | texld r0, r2, s0 55 | mul oC0, r0, r1 56 | 57 | // approximately 2 instruction slots used (1 texture, 1 arithmetic) 58 | ps_4_0 59 | dcl_sampler s0, mode_default 60 | dcl_resource_texture2d (float,float,float,float) t0 61 | dcl_input_ps linear v1.xyzw 62 | dcl_input_ps linear v2.xy 63 | dcl_output o0.xyzw 64 | dcl_temps 1 65 | sample r0.xyzw, v2.xyxx, t0.xyzw, s0 66 | mul o0.xyzw, r0.xyzw, v1.xyzw 67 | ret 68 | // Approximately 0 instruction slots used 69 | #endif 70 | 71 | const BYTE nk_d3d11_pixel_shader[] = 72 | { 73 | 68, 88, 66, 67, 249, 46, 74 | 26, 75, 111, 182, 161, 241, 75 | 199, 179, 191, 89, 44, 229, 76 | 245, 103, 1, 0, 0, 0, 77 | 124, 2, 0, 0, 5, 0, 78 | 0, 0, 52, 0, 0, 0, 79 | 176, 0, 0, 0, 56, 1, 80 | 0, 0, 212, 1, 0, 0, 81 | 72, 2, 0, 0, 88, 78, 82 | 65, 83, 116, 0, 0, 0, 83 | 116, 0, 0, 0, 0, 2, 84 | 255, 255, 76, 0, 0, 0, 85 | 40, 0, 0, 0, 0, 0, 86 | 40, 0, 0, 0, 40, 0, 87 | 0, 0, 40, 0, 1, 0, 88 | 36, 0, 0, 0, 40, 0, 89 | 0, 0, 0, 0, 0, 2, 90 | 255, 255, 31, 0, 0, 2, 91 | 0, 0, 0, 128, 0, 0, 92 | 15, 176, 31, 0, 0, 2, 93 | 0, 0, 0, 128, 1, 0, 94 | 3, 176, 31, 0, 0, 2, 95 | 0, 0, 0, 144, 0, 8, 96 | 15, 160, 66, 0, 0, 3, 97 | 0, 0, 15, 128, 2, 0, 98 | 228, 128, 0, 8, 228, 160, 99 | 5, 0, 0, 3, 0, 8, 100 | 15, 128, 0, 0, 228, 128, 101 | 1, 0, 228, 128, 255, 255, 102 | 0, 0, 65, 111, 110, 57, 103 | 128, 0, 0, 0, 128, 0, 104 | 0, 0, 0, 2, 255, 255, 105 | 88, 0, 0, 0, 40, 0, 106 | 0, 0, 0, 0, 40, 0, 107 | 0, 0, 40, 0, 0, 0, 108 | 40, 0, 1, 0, 36, 0, 109 | 0, 0, 40, 0, 0, 0, 110 | 0, 0, 0, 2, 255, 255, 111 | 31, 0, 0, 2, 0, 0, 112 | 0, 128, 0, 0, 15, 176, 113 | 31, 0, 0, 2, 0, 0, 114 | 0, 128, 1, 0, 3, 176, 115 | 31, 0, 0, 2, 0, 0, 116 | 0, 144, 0, 8, 15, 160, 117 | 66, 0, 0, 3, 0, 0, 118 | 15, 128, 1, 0, 228, 176, 119 | 0, 8, 228, 160, 5, 0, 120 | 0, 3, 0, 0, 15, 128, 121 | 0, 0, 228, 128, 0, 0, 122 | 228, 176, 1, 0, 0, 2, 123 | 0, 8, 15, 128, 0, 0, 124 | 228, 128, 255, 255, 0, 0, 125 | 83, 72, 68, 82, 148, 0, 126 | 0, 0, 64, 0, 0, 0, 127 | 37, 0, 0, 0, 90, 0, 128 | 0, 3, 0, 96, 16, 0, 129 | 0, 0, 0, 0, 88, 24, 130 | 0, 4, 0, 112, 16, 0, 131 | 0, 0, 0, 0, 85, 85, 132 | 0, 0, 98, 16, 0, 3, 133 | 242, 16, 16, 0, 1, 0, 134 | 0, 0, 98, 16, 0, 3, 135 | 50, 16, 16, 0, 2, 0, 136 | 0, 0, 101, 0, 0, 3, 137 | 242, 32, 16, 0, 0, 0, 138 | 0, 0, 104, 0, 0, 2, 139 | 1, 0, 0, 0, 69, 0, 140 | 0, 9, 242, 0, 16, 0, 141 | 0, 0, 0, 0, 70, 16, 142 | 16, 0, 2, 0, 0, 0, 143 | 70, 126, 16, 0, 0, 0, 144 | 0, 0, 0, 96, 16, 0, 145 | 0, 0, 0, 0, 56, 0, 146 | 0, 7, 242, 32, 16, 0, 147 | 0, 0, 0, 0, 70, 14, 148 | 16, 0, 0, 0, 0, 0, 149 | 70, 30, 16, 0, 1, 0, 150 | 0, 0, 62, 0, 0, 1, 151 | 73, 83, 71, 78, 108, 0, 152 | 0, 0, 3, 0, 0, 0, 153 | 8, 0, 0, 0, 80, 0, 154 | 0, 0, 0, 0, 0, 0, 155 | 1, 0, 0, 0, 3, 0, 156 | 0, 0, 0, 0, 0, 0, 157 | 15, 0, 0, 0, 92, 0, 158 | 0, 0, 0, 0, 0, 0, 159 | 0, 0, 0, 0, 3, 0, 160 | 0, 0, 1, 0, 0, 0, 161 | 15, 15, 0, 0, 98, 0, 162 | 0, 0, 0, 0, 0, 0, 163 | 0, 0, 0, 0, 3, 0, 164 | 0, 0, 2, 0, 0, 0, 165 | 3, 3, 0, 0, 83, 86, 166 | 95, 80, 79, 83, 73, 84, 167 | 73, 79, 78, 0, 67, 79, 168 | 76, 79, 82, 0, 84, 69, 169 | 88, 67, 79, 79, 82, 68, 170 | 0, 171, 79, 83, 71, 78, 171 | 44, 0, 0, 0, 1, 0, 172 | 0, 0, 8, 0, 0, 0, 173 | 32, 0, 0, 0, 0, 0, 174 | 0, 0, 0, 0, 0, 0, 175 | 3, 0, 0, 0, 0, 0, 176 | 0, 0, 15, 0, 0, 0, 177 | 83, 86, 95, 84, 97, 114, 178 | 103, 101, 116, 0, 171, 171 179 | }; 180 | -------------------------------------------------------------------------------- /demo/d3d12/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem This will use VS2015 for compiler... if you have vs 2015 and it is installed at this / the default path 4 | call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 5 | 6 | fxc.exe /nologo /T vs_5_1 /E vs /O3 /Zpc /Ges /Fh nuklear_d3d12_vertex_shader.h /Vn nk_d3d12_vertex_shader /Qstrip_reflect /Qstrip_debug /Qstrip_priv nuklear_d3d12.hlsl 7 | fxc.exe /nologo /T ps_5_1 /E ps /O3 /Zpc /Ges /Fh nuklear_d3d12_pixel_shader.h /Vn nk_d3d12_pixel_shader /Qstrip_reflect /Qstrip_debug /Qstrip_priv /enable_unbounded_descriptor_tables nuklear_d3d12.hlsl 8 | 9 | cl /D_CRT_SECURE_NO_DEPRECATE /nologo /W3 /O2 /fp:fast /Gm- /Fedemo.exe main.c user32.lib dxguid.lib dxgi.lib d3d12.lib /link /incremental:no 10 | -------------------------------------------------------------------------------- /demo/d3d12/nuklear_d3d12.hlsl: -------------------------------------------------------------------------------- 1 | #define NK_ROOTSIGNATURE ""\ 2 | "RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT),"\ 3 | "DescriptorTable("\ 4 | "CBV(b0, numDescriptors = 1, flags = DATA_VOLATILE),"\ 5 | "SRV(t0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)"\ 6 | "),"\ 7 | "RootConstants(num32BitConstants = 1, b1),"\ 8 | "StaticSampler(s0, "\ 9 | "filter = FILTER_MIN_MAG_MIP_LINEAR,"\ 10 | "addressU = TEXTURE_ADDRESS_CLAMP,"\ 11 | "addressV = TEXTURE_ADDRESS_CLAMP,"\ 12 | "addressW = TEXTURE_ADDRESS_CLAMP,"\ 13 | "comparisonFunc = COMPARISON_ALWAYS"\ 14 | ")" 15 | 16 | cbuffer buffer0 : register(b0) 17 | { 18 | float4x4 ProjectionMatrix; 19 | }; 20 | static uint texture_index : register(b1); 21 | 22 | sampler sampler0 : register(s0); 23 | Texture2D textures[] : register(t0); 24 | 25 | struct VS_INPUT 26 | { 27 | float2 pos : POSITION; 28 | float4 col : COLOR0; 29 | float2 uv : TEXCOORD0; 30 | }; 31 | 32 | struct PS_INPUT 33 | { 34 | float4 pos : SV_POSITION; 35 | float4 col : COLOR0; 36 | float2 uv : TEXCOORD0; 37 | }; 38 | 39 | [RootSignature(NK_ROOTSIGNATURE)] 40 | PS_INPUT vs(VS_INPUT input) 41 | { 42 | PS_INPUT output; 43 | output.pos = mul(ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f)); 44 | output.col = input.col; 45 | output.uv = input.uv; 46 | return output; 47 | } 48 | 49 | [RootSignature(NK_ROOTSIGNATURE)] 50 | float4 ps(PS_INPUT input) : SV_Target 51 | { 52 | return input.col * textures[texture_index].Sample(sampler0, input.uv); 53 | } 54 | -------------------------------------------------------------------------------- /demo/d3d12/nuklear_d3d12_pixel_shader.h: -------------------------------------------------------------------------------- 1 | #if 0 2 | // 3 | // Generated by Microsoft (R) D3D Shader Disassembler 4 | // 5 | // 6 | // Input signature: 7 | // 8 | // Name Index Mask Register SysValue Format Used 9 | // -------------------- ----- ------ -------- -------- ------- ------ 10 | // SV_POSITION 0 xyzw 0 POS float 11 | // COLOR 0 xyzw 1 NONE float xyzw 12 | // TEXCOORD 0 xy 2 NONE float xy 13 | // 14 | // 15 | // Output signature: 16 | // 17 | // Name Index Mask Register SysValue Format Used 18 | // -------------------- ----- ------ -------- -------- ------- ------ 19 | // SV_Target 0 xyzw 0 TARGET float xyzw 20 | // 21 | ps_5_1 22 | dcl_globalFlags refactoringAllowed 23 | dcl_sampler S0[0:0], mode_default, space=0 24 | dcl_resource_texture2d (float,float,float,float) T0[0:*], space=0 25 | dcl_input_ps linear v1.xyzw 26 | dcl_input_ps linear v2.xy 27 | dcl_output o0.xyzw 28 | dcl_temps 1 29 | sample r0.xyzw, v2.xyxx, T0[0].xyzw, S0[0] 30 | mul o0.xyzw, r0.xyzw, v1.xyzw 31 | ret 32 | // Approximately 0 instruction slots used 33 | #endif 34 | 35 | const BYTE nk_d3d12_pixel_shader[] = 36 | { 37 | 68, 88, 66, 67, 228, 128, 38 | 250, 93, 94, 248, 174, 160, 39 | 102, 133, 107, 228, 84, 49, 40 | 109, 253, 1, 0, 0, 0, 41 | 72, 2, 0, 0, 4, 0, 42 | 0, 0, 48, 0, 0, 0, 43 | 164, 0, 0, 0, 216, 0, 44 | 0, 0, 152, 1, 0, 0, 45 | 73, 83, 71, 78, 108, 0, 46 | 0, 0, 3, 0, 0, 0, 47 | 8, 0, 0, 0, 80, 0, 48 | 0, 0, 0, 0, 0, 0, 49 | 1, 0, 0, 0, 3, 0, 50 | 0, 0, 0, 0, 0, 0, 51 | 15, 0, 0, 0, 92, 0, 52 | 0, 0, 0, 0, 0, 0, 53 | 0, 0, 0, 0, 3, 0, 54 | 0, 0, 1, 0, 0, 0, 55 | 15, 15, 0, 0, 98, 0, 56 | 0, 0, 0, 0, 0, 0, 57 | 0, 0, 0, 0, 3, 0, 58 | 0, 0, 2, 0, 0, 0, 59 | 3, 3, 0, 0, 83, 86, 60 | 95, 80, 79, 83, 73, 84, 61 | 73, 79, 78, 0, 67, 79, 62 | 76, 79, 82, 0, 84, 69, 63 | 88, 67, 79, 79, 82, 68, 64 | 0, 171, 79, 83, 71, 78, 65 | 44, 0, 0, 0, 1, 0, 66 | 0, 0, 8, 0, 0, 0, 67 | 32, 0, 0, 0, 0, 0, 68 | 0, 0, 0, 0, 0, 0, 69 | 3, 0, 0, 0, 0, 0, 70 | 0, 0, 15, 0, 0, 0, 71 | 83, 86, 95, 84, 97, 114, 72 | 103, 101, 116, 0, 171, 171, 73 | 83, 72, 69, 88, 184, 0, 74 | 0, 0, 81, 0, 0, 0, 75 | 46, 0, 0, 0, 106, 8, 76 | 0, 1, 90, 0, 0, 6, 77 | 70, 110, 48, 0, 0, 0, 78 | 0, 0, 0, 0, 0, 0, 79 | 0, 0, 0, 0, 0, 0, 80 | 0, 0, 88, 24, 0, 7, 81 | 70, 126, 48, 0, 0, 0, 82 | 0, 0, 0, 0, 0, 0, 83 | 255, 255, 255, 255, 85, 85, 84 | 0, 0, 0, 0, 0, 0, 85 | 98, 16, 0, 3, 242, 16, 86 | 16, 0, 1, 0, 0, 0, 87 | 98, 16, 0, 3, 50, 16, 88 | 16, 0, 2, 0, 0, 0, 89 | 101, 0, 0, 3, 242, 32, 90 | 16, 0, 0, 0, 0, 0, 91 | 104, 0, 0, 2, 1, 0, 92 | 0, 0, 69, 0, 0, 11, 93 | 242, 0, 16, 0, 0, 0, 94 | 0, 0, 70, 16, 16, 0, 95 | 2, 0, 0, 0, 70, 126, 96 | 32, 0, 0, 0, 0, 0, 97 | 0, 0, 0, 0, 0, 96, 98 | 32, 0, 0, 0, 0, 0, 99 | 0, 0, 0, 0, 56, 0, 100 | 0, 7, 242, 32, 16, 0, 101 | 0, 0, 0, 0, 70, 14, 102 | 16, 0, 0, 0, 0, 0, 103 | 70, 30, 16, 0, 1, 0, 104 | 0, 0, 62, 0, 0, 1, 105 | 82, 84, 83, 48, 168, 0, 106 | 0, 0, 2, 0, 0, 0, 107 | 2, 0, 0, 0, 24, 0, 108 | 0, 0, 1, 0, 0, 0, 109 | 116, 0, 0, 0, 1, 0, 110 | 0, 0, 0, 0, 0, 0, 111 | 0, 0, 0, 0, 48, 0, 112 | 0, 0, 1, 0, 0, 0, 113 | 0, 0, 0, 0, 104, 0, 114 | 0, 0, 2, 0, 0, 0, 115 | 56, 0, 0, 0, 2, 0, 116 | 0, 0, 1, 0, 0, 0, 117 | 0, 0, 0, 0, 0, 0, 118 | 0, 0, 2, 0, 0, 0, 119 | 255, 255, 255, 255, 0, 0, 120 | 0, 0, 255, 255, 255, 255, 121 | 0, 0, 0, 0, 0, 0, 122 | 0, 0, 1, 0, 0, 0, 123 | 255, 255, 255, 255, 1, 0, 124 | 0, 0, 0, 0, 0, 0, 125 | 1, 0, 0, 0, 21, 0, 126 | 0, 0, 3, 0, 0, 0, 127 | 3, 0, 0, 0, 3, 0, 128 | 0, 0, 0, 0, 0, 0, 129 | 16, 0, 0, 0, 8, 0, 130 | 0, 0, 2, 0, 0, 0, 131 | 0, 0, 0, 0, 255, 255, 132 | 127, 127, 0, 0, 0, 0, 133 | 0, 0, 0, 0, 0, 0, 134 | 0, 0 135 | }; 136 | -------------------------------------------------------------------------------- /demo/d3d12/nuklear_d3d12_vertex_shader.h: -------------------------------------------------------------------------------- 1 | #if 0 2 | // 3 | // Generated by Microsoft (R) D3D Shader Disassembler 4 | // 5 | // 6 | // Input signature: 7 | // 8 | // Name Index Mask Register SysValue Format Used 9 | // -------------------- ----- ------ -------- -------- ------- ------ 10 | // POSITION 0 xy 0 NONE float xy 11 | // COLOR 0 xyzw 1 NONE float xyzw 12 | // TEXCOORD 0 xy 2 NONE float xy 13 | // 14 | // 15 | // Output signature: 16 | // 17 | // Name Index Mask Register SysValue Format Used 18 | // -------------------- ----- ------ -------- -------- ------- ------ 19 | // SV_POSITION 0 xyzw 0 POS float xyzw 20 | // COLOR 0 xyzw 1 NONE float xyzw 21 | // TEXCOORD 0 xy 2 NONE float xy 22 | // 23 | vs_5_1 24 | dcl_globalFlags refactoringAllowed 25 | dcl_constantbuffer CB0[0:0][4], immediateIndexed, space=0 26 | dcl_input v0.xy 27 | dcl_input v1.xyzw 28 | dcl_input v2.xy 29 | dcl_output_siv o0.xyzw, position 30 | dcl_output o1.xyzw 31 | dcl_output o2.xy 32 | dcl_temps 1 33 | mul r0.xyzw, v0.yyyy, CB0[0][1].xyzw 34 | mad r0.xyzw, CB0[0][0].xyzw, v0.xxxx, r0.xyzw 35 | add o0.xyzw, r0.xyzw, CB0[0][3].xyzw 36 | mov o1.xyzw, v1.xyzw 37 | mov o2.xy, v2.xyxx 38 | ret 39 | // Approximately 0 instruction slots used 40 | #endif 41 | 42 | const BYTE nk_d3d12_vertex_shader[] = 43 | { 44 | 68, 88, 66, 67, 187, 129, 45 | 163, 57, 169, 94, 219, 158, 46 | 174, 23, 30, 91, 108, 150, 47 | 135, 141, 1, 0, 0, 0, 48 | 232, 2, 0, 0, 4, 0, 49 | 0, 0, 48, 0, 0, 0, 50 | 160, 0, 0, 0, 20, 1, 51 | 0, 0, 56, 2, 0, 0, 52 | 73, 83, 71, 78, 104, 0, 53 | 0, 0, 3, 0, 0, 0, 54 | 8, 0, 0, 0, 80, 0, 55 | 0, 0, 0, 0, 0, 0, 56 | 0, 0, 0, 0, 3, 0, 57 | 0, 0, 0, 0, 0, 0, 58 | 3, 3, 0, 0, 89, 0, 59 | 0, 0, 0, 0, 0, 0, 60 | 0, 0, 0, 0, 3, 0, 61 | 0, 0, 1, 0, 0, 0, 62 | 15, 15, 0, 0, 95, 0, 63 | 0, 0, 0, 0, 0, 0, 64 | 0, 0, 0, 0, 3, 0, 65 | 0, 0, 2, 0, 0, 0, 66 | 3, 3, 0, 0, 80, 79, 67 | 83, 73, 84, 73, 79, 78, 68 | 0, 67, 79, 76, 79, 82, 69 | 0, 84, 69, 88, 67, 79, 70 | 79, 82, 68, 0, 79, 83, 71 | 71, 78, 108, 0, 0, 0, 72 | 3, 0, 0, 0, 8, 0, 73 | 0, 0, 80, 0, 0, 0, 74 | 0, 0, 0, 0, 1, 0, 75 | 0, 0, 3, 0, 0, 0, 76 | 0, 0, 0, 0, 15, 0, 77 | 0, 0, 92, 0, 0, 0, 78 | 0, 0, 0, 0, 0, 0, 79 | 0, 0, 3, 0, 0, 0, 80 | 1, 0, 0, 0, 15, 0, 81 | 0, 0, 98, 0, 0, 0, 82 | 0, 0, 0, 0, 0, 0, 83 | 0, 0, 3, 0, 0, 0, 84 | 2, 0, 0, 0, 3, 12, 85 | 0, 0, 83, 86, 95, 80, 86 | 79, 83, 73, 84, 73, 79, 87 | 78, 0, 67, 79, 76, 79, 88 | 82, 0, 84, 69, 88, 67, 89 | 79, 79, 82, 68, 0, 171, 90 | 83, 72, 69, 88, 28, 1, 91 | 0, 0, 81, 0, 1, 0, 92 | 71, 0, 0, 0, 106, 8, 93 | 0, 1, 89, 0, 0, 7, 94 | 70, 142, 48, 0, 0, 0, 95 | 0, 0, 0, 0, 0, 0, 96 | 0, 0, 0, 0, 4, 0, 97 | 0, 0, 0, 0, 0, 0, 98 | 95, 0, 0, 3, 50, 16, 99 | 16, 0, 0, 0, 0, 0, 100 | 95, 0, 0, 3, 242, 16, 101 | 16, 0, 1, 0, 0, 0, 102 | 95, 0, 0, 3, 50, 16, 103 | 16, 0, 2, 0, 0, 0, 104 | 103, 0, 0, 4, 242, 32, 105 | 16, 0, 0, 0, 0, 0, 106 | 1, 0, 0, 0, 101, 0, 107 | 0, 3, 242, 32, 16, 0, 108 | 1, 0, 0, 0, 101, 0, 109 | 0, 3, 50, 32, 16, 0, 110 | 2, 0, 0, 0, 104, 0, 111 | 0, 2, 1, 0, 0, 0, 112 | 56, 0, 0, 9, 242, 0, 113 | 16, 0, 0, 0, 0, 0, 114 | 86, 21, 16, 0, 0, 0, 115 | 0, 0, 70, 142, 48, 0, 116 | 0, 0, 0, 0, 0, 0, 117 | 0, 0, 1, 0, 0, 0, 118 | 50, 0, 0, 11, 242, 0, 119 | 16, 0, 0, 0, 0, 0, 120 | 70, 142, 48, 0, 0, 0, 121 | 0, 0, 0, 0, 0, 0, 122 | 0, 0, 0, 0, 6, 16, 123 | 16, 0, 0, 0, 0, 0, 124 | 70, 14, 16, 0, 0, 0, 125 | 0, 0, 0, 0, 0, 9, 126 | 242, 32, 16, 0, 0, 0, 127 | 0, 0, 70, 14, 16, 0, 128 | 0, 0, 0, 0, 70, 142, 129 | 48, 0, 0, 0, 0, 0, 130 | 0, 0, 0, 0, 3, 0, 131 | 0, 0, 54, 0, 0, 5, 132 | 242, 32, 16, 0, 1, 0, 133 | 0, 0, 70, 30, 16, 0, 134 | 1, 0, 0, 0, 54, 0, 135 | 0, 5, 50, 32, 16, 0, 136 | 2, 0, 0, 0, 70, 16, 137 | 16, 0, 2, 0, 0, 0, 138 | 62, 0, 0, 1, 82, 84, 139 | 83, 48, 168, 0, 0, 0, 140 | 2, 0, 0, 0, 2, 0, 141 | 0, 0, 24, 0, 0, 0, 142 | 1, 0, 0, 0, 116, 0, 143 | 0, 0, 1, 0, 0, 0, 144 | 0, 0, 0, 0, 0, 0, 145 | 0, 0, 48, 0, 0, 0, 146 | 1, 0, 0, 0, 0, 0, 147 | 0, 0, 104, 0, 0, 0, 148 | 2, 0, 0, 0, 56, 0, 149 | 0, 0, 2, 0, 0, 0, 150 | 1, 0, 0, 0, 0, 0, 151 | 0, 0, 0, 0, 0, 0, 152 | 2, 0, 0, 0, 255, 255, 153 | 255, 255, 0, 0, 0, 0, 154 | 255, 255, 255, 255, 0, 0, 155 | 0, 0, 0, 0, 0, 0, 156 | 1, 0, 0, 0, 255, 255, 157 | 255, 255, 1, 0, 0, 0, 158 | 0, 0, 0, 0, 1, 0, 159 | 0, 0, 21, 0, 0, 0, 160 | 3, 0, 0, 0, 3, 0, 161 | 0, 0, 3, 0, 0, 0, 162 | 0, 0, 0, 0, 16, 0, 163 | 0, 0, 8, 0, 0, 0, 164 | 2, 0, 0, 0, 0, 0, 165 | 0, 0, 255, 255, 127, 127, 166 | 0, 0, 0, 0, 0, 0, 167 | 0, 0, 0, 0, 0, 0 168 | }; 169 | -------------------------------------------------------------------------------- /demo/d3d9/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem This will use VS2015 for compiler 4 | call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 5 | 6 | cl /D_CRT_SECURE_NO_DEPRECATE /nologo /W3 /O2 /fp:fast /Gm- /Fedemo.exe main.c user32.lib d3d9.lib /link /incremental:no 7 | -------------------------------------------------------------------------------- /demo/gdi/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem This will use VS2015 for compiler 4 | call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 5 | 6 | cl /nologo /W3 /O2 /fp:fast /Gm- /Fedemo.exe main.c user32.lib gdi32.lib Msimg32.lib /link /incremental:no 7 | -------------------------------------------------------------------------------- /demo/gdi/main.c: -------------------------------------------------------------------------------- 1 | /* nuklear - 1.32.0 - public domain */ 2 | #define WIN32_LEAN_AND_MEAN 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define WINDOW_WIDTH 800 10 | #define WINDOW_HEIGHT 600 11 | 12 | #define NK_INCLUDE_FIXED_TYPES 13 | #define NK_INCLUDE_STANDARD_IO 14 | #define NK_INCLUDE_STANDARD_VARARGS 15 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 16 | #define NK_IMPLEMENTATION 17 | #define NK_GDI_IMPLEMENTATION 18 | #include "../../nuklear.h" 19 | #include "nuklear_gdi.h" 20 | 21 | /* =============================================================== 22 | * 23 | * EXAMPLE 24 | * 25 | * ===============================================================*/ 26 | /* This are some code examples to provide a small overview of what can be 27 | * done with this library. To try out an example uncomment the defines */ 28 | /*#define INCLUDE_ALL */ 29 | /*#define INCLUDE_STYLE */ 30 | /*#define INCLUDE_CALCULATOR */ 31 | /*#define INCLUDE_CANVAS */ 32 | #define INCLUDE_OVERVIEW 33 | /*#define INCLUDE_CONFIGURATOR */ 34 | /*#define INCLUDE_NODE_EDITOR */ 35 | 36 | #ifdef INCLUDE_ALL 37 | #define INCLUDE_STYLE 38 | #define INCLUDE_CALCULATOR 39 | #define INCLUDE_CANVAS 40 | #define INCLUDE_OVERVIEW 41 | #define INCLUDE_CONFIGURATOR 42 | #define INCLUDE_NODE_EDITOR 43 | #endif 44 | 45 | #ifdef INCLUDE_STYLE 46 | #include "../../demo/common/style.c" 47 | #endif 48 | #ifdef INCLUDE_CALCULATOR 49 | #include "../../demo/common/calculator.c" 50 | #endif 51 | #ifdef INCLUDE_CANVAS 52 | #include "../../demo/common/canvas.c" 53 | #endif 54 | #ifdef INCLUDE_OVERVIEW 55 | #include "../../demo/common/overview.c" 56 | #endif 57 | #ifdef INCLUDE_CONFIGURATOR 58 | #include "../../demo/common/style_configurator.c" 59 | #endif 60 | #ifdef INCLUDE_NODE_EDITOR 61 | #include "../../demo/common/node_editor.c" 62 | #endif 63 | 64 | /* =============================================================== 65 | * 66 | * DEMO 67 | * 68 | * ===============================================================*/ 69 | static LRESULT CALLBACK 70 | WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) 71 | { 72 | switch (msg) 73 | { 74 | case WM_DESTROY: 75 | PostQuitMessage(0); 76 | return 0; 77 | } 78 | 79 | if (nk_gdi_handle_event(wnd, msg, wparam, lparam)) 80 | return 0; 81 | 82 | return DefWindowProcW(wnd, msg, wparam, lparam); 83 | } 84 | 85 | int main(void) 86 | { 87 | GdiFont* font; 88 | struct nk_context *ctx; 89 | 90 | WNDCLASSW wc; 91 | ATOM atom; 92 | RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT }; 93 | DWORD style = WS_OVERLAPPEDWINDOW; 94 | DWORD exstyle = WS_EX_APPWINDOW; 95 | HWND wnd; 96 | HDC dc; 97 | int running = 1; 98 | int needs_refresh = 1; 99 | 100 | #ifdef INCLUDE_CONFIGURATOR 101 | static struct nk_color color_table[NK_COLOR_COUNT]; 102 | memcpy(color_table, nk_default_color_style, sizeof(color_table)); 103 | #endif 104 | 105 | /* Win32 */ 106 | memset(&wc, 0, sizeof(wc)); 107 | wc.style = CS_DBLCLKS; 108 | wc.lpfnWndProc = WindowProc; 109 | wc.hInstance = GetModuleHandleW(0); 110 | wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 111 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 112 | wc.lpszClassName = L"NuklearWindowClass"; 113 | atom = RegisterClassW(&wc); 114 | 115 | AdjustWindowRectEx(&rect, style, FALSE, exstyle); 116 | wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear GDI Demo", 117 | style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 118 | rect.right - rect.left, rect.bottom - rect.top, 119 | NULL, NULL, wc.hInstance, NULL); 120 | dc = GetDC(wnd); 121 | 122 | /* GUI */ 123 | font = nk_gdifont_create("Arial", 14); 124 | ctx = nk_gdi_init(font, dc, WINDOW_WIDTH, WINDOW_HEIGHT); 125 | 126 | while (running) 127 | { 128 | /* Input */ 129 | MSG msg; 130 | nk_input_begin(ctx); 131 | if (needs_refresh == 0) { 132 | if (GetMessageW(&msg, NULL, 0, 0) <= 0) 133 | running = 0; 134 | else { 135 | TranslateMessage(&msg); 136 | DispatchMessageW(&msg); 137 | } 138 | needs_refresh = 1; 139 | } else needs_refresh = 0; 140 | 141 | while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { 142 | if (msg.message == WM_QUIT) 143 | running = 0; 144 | TranslateMessage(&msg); 145 | DispatchMessageW(&msg); 146 | needs_refresh = 1; 147 | } 148 | nk_input_end(ctx); 149 | 150 | /* GUI */ 151 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 152 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 153 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 154 | { 155 | enum {EASY, HARD}; 156 | static int op = EASY; 157 | static int property = 20; 158 | 159 | nk_layout_row_static(ctx, 30, 80, 1); 160 | if (nk_button_label(ctx, "button")) 161 | fprintf(stdout, "button pressed\n"); 162 | nk_layout_row_dynamic(ctx, 30, 2); 163 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 164 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 165 | nk_layout_row_dynamic(ctx, 22, 1); 166 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 167 | } 168 | nk_end(ctx); 169 | 170 | /* -------------- EXAMPLES ---------------- */ 171 | #ifdef INCLUDE_CALCULATOR 172 | calculator(ctx); 173 | #endif 174 | #ifdef INCLUDE_CANVAS 175 | canvas(ctx); 176 | #endif 177 | #ifdef INCLUDE_OVERVIEW 178 | overview(ctx); 179 | #endif 180 | #ifdef INCLUDE_CONFIGURATOR 181 | style_configurator(ctx, color_table); 182 | #endif 183 | #ifdef INCLUDE_NODE_EDITOR 184 | node_editor(ctx); 185 | #endif 186 | /* ----------------------------------------- */ 187 | 188 | /* Draw */ 189 | nk_gdi_render(nk_rgb(30,30,30)); 190 | } 191 | 192 | nk_gdifont_del(font); 193 | ReleaseDC(wnd, dc); 194 | UnregisterClassW(wc.lpszClassName, wc.hInstance); 195 | return 0; 196 | } 197 | 198 | -------------------------------------------------------------------------------- /demo/gdi_native_nuklear/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem This will use VS2015 for compiler 4 | call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 5 | 6 | cl /nologo /W3 /O2 /fp:fast /Gm- /D_CRT_SECURE_NO_DEPRECATE /Fedemo.exe main.c user32.lib gdi32.lib Msimg32.lib /link /incremental:no 7 | -------------------------------------------------------------------------------- /demo/gdi_native_nuklear/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #pragma comment(linker,"\"/manifestdependency:type='win32' \ 4 | name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ 5 | processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 6 | 7 | /* Includes the default nuklear implementation 8 | * Includes the modified GDI backend (No more global state to allow multiple hwnd's) 9 | */ 10 | #define NK_INCLUDE_FIXED_TYPES 11 | #define NK_INCLUDE_STANDARD_IO 12 | #define NK_INCLUDE_STANDARD_VARARGS 13 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 14 | #define NK_IMPLEMENTATION 15 | #define NK_GDI_IMPLEMENTATION 16 | #include "../../nuklear.h" 17 | #include "nuklear_gdi.h" 18 | 19 | /* Include the window framework (the new fancy code of this demo) */ 20 | #define NKGDI_IMPLEMENT_WINDOW 21 | #include "window.h" 22 | 23 | /* This callback will be called when the window is draw 24 | * You will NOT need to call nk_begin(...) and nk_end(...) 25 | * begin and end are handled by the parent code calling this 26 | * callback 27 | */ 28 | int drawCallback(struct nk_context* ctx) 29 | { 30 | /* Code is from ../calculator.c */ 31 | static int set = 0, prev = 0, op = 0; 32 | static const char numbers[] = "789456123"; 33 | static const char ops[] = "+-*/"; 34 | static double a = 0, b = 0; 35 | static double *current = &a; 36 | 37 | size_t i = 0; 38 | int solve = 0; 39 | {int len; char buffer[256]; 40 | nk_layout_row_dynamic(ctx, 35, 1); 41 | len = snprintf(buffer, 256, "%.2f", *current); 42 | nk_edit_string(ctx, NK_EDIT_SIMPLE, buffer, &len, 255, nk_filter_float); 43 | buffer[len] = 0; 44 | *current = atof(buffer);} 45 | 46 | nk_layout_row_dynamic(ctx, 35, 4); 47 | for (i = 0; i < 16; ++i) { 48 | if (i >= 12 && i < 15) { 49 | if (i > 12) continue; 50 | if (nk_button_label(ctx, "C")) { 51 | a = b = op = 0; current = &a; set = 0; 52 | } if (nk_button_label(ctx, "0")) { 53 | *current = *current*10.0f; set = 0; 54 | } if (nk_button_label(ctx, "=")) { 55 | solve = 1; prev = op; op = 0; 56 | } 57 | } else if (((i+1) % 4)) { 58 | if (nk_button_text(ctx, &numbers[(i/4)*3+i%4], 1)) { 59 | *current = *current * 10.0f + numbers[(i/4)*3+i%4] - '0'; 60 | set = 0; 61 | } 62 | } else if (nk_button_text(ctx, &ops[i/4], 1)) { 63 | if (!set) { 64 | if (current != &b) { 65 | current = &b; 66 | } else { 67 | prev = op; 68 | solve = 1; 69 | } 70 | } 71 | op = ops[i/4]; 72 | set = 1; 73 | } 74 | } 75 | if (solve) { 76 | if (prev == '+') a = a + b; 77 | if (prev == '-') a = a - b; 78 | if (prev == '*') a = a * b; 79 | if (prev == '/') a = a / b; 80 | current = &a; 81 | if (set) current = &b; 82 | b = 0; set = 0; 83 | } 84 | return 1; 85 | } 86 | 87 | /* Main entry point - wWinMain used for UNICODE 88 | * (You can also use _tWinMain(...) to automaticaly use the ASCII or WIDE char entry point base on your build) 89 | */ 90 | INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, PWSTR _In_ cmdArgs, INT _In_ cmdShow) 91 | { 92 | /* Call this first to setup all required prerequisites */ 93 | nkgdi_window_init(); 94 | 95 | /* Preparing two window contexts */ 96 | struct nkgdi_window w1, w2; 97 | memset(&w1, 0x0, sizeof(struct nkgdi_window)); 98 | memset(&w2, 0x0, sizeof(struct nkgdi_window)); 99 | 100 | /* Configure and create window 1. 101 | * Note: You can allways change the direct accesible parameters later as well! 102 | */ 103 | w1.allow_sizing = 0; 104 | w1.allow_maximize = 0; 105 | w1.allow_move = 0; 106 | w1.has_titlebar = 0; 107 | w1.cb_on_draw = &drawCallback; 108 | nkgdi_window_create(&w1, 500, 500, "F1", 10, 10); 109 | 110 | /* Configure and create window 2 */ 111 | w2.allow_sizing = 1; 112 | w2.allow_maximize = 1; 113 | w2.allow_move = 1; 114 | w2.has_titlebar = 1; 115 | w2.cb_on_draw = &drawCallback; 116 | nkgdi_window_create(&w2, 500, 500, "F2", 520, 10); 117 | 118 | /* As long as both windows are valid (nkgdi_window_update returning 1) */ 119 | while (nkgdi_window_update(&w1) && nkgdi_window_update(&w2)) Sleep(20); 120 | 121 | /* Destroy both windows context */ 122 | nkgdi_window_destroy(&w1); 123 | nkgdi_window_destroy(&w2); 124 | 125 | /* Call nkgdi_window_shutdown to properly shutdown the gdi window framework */ 126 | nkgdi_window_shutdown(); 127 | return 0; 128 | } 129 | -------------------------------------------------------------------------------- /demo/gdip/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 4 | 5 | cl /nologo /W3 /O2 /fp:fast /Gm- /Fedemo.exe /D_CRT_SECURE_NO_DEPRECATE main.c user32.lib gdiplus.lib shlwapi.lib /link /incremental:no 6 | -------------------------------------------------------------------------------- /demo/gdip/main.c: -------------------------------------------------------------------------------- 1 | /* nuklear - 1.32.0 - public domain */ 2 | #define WIN32_LEAN_AND_MEAN 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define WINDOW_WIDTH 800 10 | #define WINDOW_HEIGHT 600 11 | 12 | #define NK_INCLUDE_FIXED_TYPES 13 | #define NK_INCLUDE_STANDARD_IO 14 | #define NK_INCLUDE_STANDARD_VARARGS 15 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 16 | #define NK_IMPLEMENTATION 17 | #define NK_GDIP_IMPLEMENTATION 18 | #include "../../nuklear.h" 19 | #include "nuklear_gdip.h" 20 | 21 | /* =============================================================== 22 | * 23 | * EXAMPLE 24 | * 25 | * ===============================================================*/ 26 | /* This are some code examples to provide a small overview of what can be 27 | * done with this library. To try out an example uncomment the defines */ 28 | /*#define INCLUDE_ALL */ 29 | /*#define INCLUDE_STYLE */ 30 | /*#define INCLUDE_CALCULATOR */ 31 | /*#define INCLUDE_CANVAS */ 32 | #define INCLUDE_OVERVIEW 33 | /*#define INCLUDE_CONFIGURATOR */ 34 | /*#define INCLUDE_NODE_EDITOR */ 35 | 36 | #ifdef INCLUDE_ALL 37 | #define INCLUDE_STYLE 38 | #define INCLUDE_CALCULATOR 39 | #define INCLUDE_CANVAS 40 | #define INCLUDE_OVERVIEW 41 | #define INCLUDE_CONFIGURATOR 42 | #define INCLUDE_NODE_EDITOR 43 | #endif 44 | 45 | #ifdef INCLUDE_STYLE 46 | #include "../../demo/common/style.c" 47 | #endif 48 | #ifdef INCLUDE_CALCULATOR 49 | #include "../../demo/common/calculator.c" 50 | #endif 51 | #ifdef INCLUDE_CANVAS 52 | #include "../../demo/common/canvas.c" 53 | #endif 54 | #ifdef INCLUDE_OVERVIEW 55 | #include "../../demo/common/overview.c" 56 | #endif 57 | #ifdef INCLUDE_CONFIGURATOR 58 | #include "../../demo/common/style_configurator.c" 59 | #endif 60 | #ifdef INCLUDE_NODE_EDITOR 61 | #include "../../demo/common/node_editor.c" 62 | #endif 63 | 64 | /* =============================================================== 65 | * 66 | * DEMO 67 | * 68 | * ===============================================================*/ 69 | static LRESULT CALLBACK 70 | WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) 71 | { 72 | switch (msg) { 73 | case WM_DESTROY: 74 | PostQuitMessage(0); 75 | return 0; 76 | } 77 | if (nk_gdip_handle_event(wnd, msg, wparam, lparam)) 78 | return 0; 79 | return DefWindowProcW(wnd, msg, wparam, lparam); 80 | } 81 | 82 | int main(void) 83 | { 84 | GdipFont* font; 85 | struct nk_context *ctx; 86 | 87 | WNDCLASSW wc; 88 | RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT }; 89 | DWORD style = WS_OVERLAPPEDWINDOW; 90 | DWORD exstyle = WS_EX_APPWINDOW; 91 | HWND wnd; 92 | int running = 1; 93 | int needs_refresh = 1; 94 | 95 | #ifdef INCLUDE_CONFIGURATOR 96 | static struct nk_color color_table[NK_COLOR_COUNT]; 97 | memcpy(color_table, nk_default_color_style, sizeof(color_table)); 98 | #endif 99 | 100 | /* Win32 */ 101 | memset(&wc, 0, sizeof(wc)); 102 | wc.style = CS_DBLCLKS; 103 | wc.lpfnWndProc = WindowProc; 104 | wc.hInstance = GetModuleHandleW(0); 105 | wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 106 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 107 | wc.lpszClassName = L"NuklearWindowClass"; 108 | RegisterClassW(&wc); 109 | 110 | AdjustWindowRectEx(&rect, style, FALSE, exstyle); 111 | 112 | wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear GDI+ Demo", 113 | style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 114 | rect.right - rect.left, rect.bottom - rect.top, 115 | NULL, NULL, wc.hInstance, NULL); 116 | 117 | /* GUI */ 118 | ctx = nk_gdip_init(wnd, WINDOW_WIDTH, WINDOW_HEIGHT); 119 | font = nk_gdipfont_create("Arial", 12); 120 | nk_gdip_set_font(font); 121 | 122 | while (running) 123 | { 124 | /* Input */ 125 | MSG msg; 126 | nk_input_begin(ctx); 127 | if (needs_refresh == 0) { 128 | if (GetMessageW(&msg, NULL, 0, 0) <= 0) 129 | running = 0; 130 | else { 131 | TranslateMessage(&msg); 132 | DispatchMessageW(&msg); 133 | } 134 | needs_refresh = 1; 135 | } else needs_refresh = 0; 136 | while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { 137 | if (msg.message == WM_QUIT) 138 | running = 0; 139 | TranslateMessage(&msg); 140 | DispatchMessageW(&msg); 141 | needs_refresh = 1; 142 | } 143 | nk_input_end(ctx); 144 | 145 | /* GUI */ 146 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 147 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 148 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 149 | { 150 | enum {EASY, HARD}; 151 | static int op = EASY; 152 | static int property = 20; 153 | 154 | nk_layout_row_static(ctx, 30, 80, 1); 155 | if (nk_button_label(ctx, "button")) 156 | fprintf(stdout, "button pressed\n"); 157 | nk_layout_row_dynamic(ctx, 30, 2); 158 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 159 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 160 | nk_layout_row_dynamic(ctx, 22, 1); 161 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 162 | } 163 | nk_end(ctx); 164 | 165 | /* -------------- EXAMPLES ---------------- */ 166 | #ifdef INCLUDE_CALCULATOR 167 | calculator(ctx); 168 | #endif 169 | #ifdef INCLUDE_CANVAS 170 | canvas(ctx); 171 | #endif 172 | #ifdef INCLUDE_OVERVIEW 173 | overview(ctx); 174 | #endif 175 | #ifdef INCLUDE_CONFIGURATOR 176 | style_configurator(ctx, color_table); 177 | #endif 178 | #ifdef INCLUDE_NODE_EDITOR 179 | node_editor(ctx); 180 | #endif 181 | /* ----------------------------------------- */ 182 | 183 | /* Draw */ 184 | nk_gdip_render(NK_ANTI_ALIASING_ON, nk_rgb(30,30,30)); 185 | } 186 | 187 | nk_gdipfont_del(font); 188 | nk_gdip_shutdown(); 189 | UnregisterClassW(wc.lpszClassName, wc.hInstance); 190 | return 0; 191 | } 192 | -------------------------------------------------------------------------------- /demo/glfw_opengl2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c99 -Wall -Wextra -pedantic 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | ifeq ($(OS),Windows_NT) 11 | BIN := $(BIN).exe 12 | LIBS = -lglfw3 -lopengl32 -lm -lGLU32 13 | else 14 | UNAME_S := $(shell uname -s) 15 | ifeq ($(UNAME_S),Darwin) 16 | LIBS := -lglfw3 -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib 17 | else 18 | LIBS = -lglfw -lGL -lm -lGLU 19 | endif 20 | endif 21 | 22 | $(BIN): 23 | @mkdir -p bin 24 | rm -f bin/$(BIN) $(OBJS) 25 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 26 | -------------------------------------------------------------------------------- /demo/glfw_opengl3/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -g -std=c89 -Wall -Wextra -pedantic 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | ifeq ($(OS),Windows_NT) 11 | BIN := $(BIN).exe 12 | LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32 13 | else 14 | UNAME_S := $(shell uname -s) 15 | GLFW3 := $(shell pkg-config --libs glfw3) 16 | ifeq ($(UNAME_S),Darwin) 17 | LIBS := $(GLFW3) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib 18 | else 19 | LIBS = $(GLFW3) -lGL -lm -lGLU -lGLEW 20 | endif 21 | endif 22 | 23 | $(BIN): 24 | @mkdir -p bin 25 | rm -f bin/$(BIN) $(OBJS) 26 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 27 | -------------------------------------------------------------------------------- /demo/glfw_opengl4/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -g -std=c89 -Wall -Wextra -pedantic 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | ifeq ($(OS),Windows_NT) 11 | BIN := $(BIN).exe 12 | LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32 13 | else 14 | UNAME_S := $(shell uname -s) 15 | GLFW3 := $(shell pkg-config --libs glfw3) 16 | ifeq ($(UNAME_S),Darwin) 17 | LIBS := $(GLFW3) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib 18 | else 19 | LIBS = $(GLFW3) -lGL -lm -lGLU -lGLEW 20 | endif 21 | endif 22 | 23 | $(BIN): 24 | @mkdir -p bin 25 | rm -f bin/$(BIN) $(OBJS) 26 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 27 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | # same as .editorconfig 4 | IndentWidth: 4 5 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/.gitignore: -------------------------------------------------------------------------------- 1 | src/nuklearshaders/*.spv 2 | src/nuklear_glfw_vulkan.h 3 | shaders/*.spv 4 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | ifeq ($(OS),Windows_NT) 11 | BIN := $(BIN).exe 12 | LIBS = -lglfw3 -lvulkan -lm 13 | else 14 | UNAME_S := $(shell uname -s) 15 | GLFW3 := $(shell pkg-config --libs glfw3) 16 | LIBS = $(GLFW3) -lvulkan -lm 17 | endif 18 | 19 | 20 | $(BIN): shaders/demo.vert.spv shaders/demo.frag.spv 21 | @mkdir -p bin 22 | rm -f bin/$(BIN) $(OBJS) 23 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 24 | 25 | shaders/demo.vert.spv: shaders/demo.vert 26 | glslc --target-env=vulkan shaders/demo.vert -o shaders/demo.vert.spv 27 | 28 | shaders/demo.frag.spv: shaders/demo.frag 29 | glslc --target-env=vulkan shaders/demo.frag -o shaders/demo.frag.spv 30 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/README.md: -------------------------------------------------------------------------------- 1 | # nuklear glfw vulkan 2 | 3 | ## Theory of operation 4 | 5 | The nuklear glfw vulkan integration creates an independent graphics pipeline that will render the nuklear UI to separate render targets. 6 | The application is responsible to fully manage these render targets. So it must ensure they are properly sized (and resized when requested). 7 | 8 | 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. 9 | 10 | This is how you can integrate it in your application: 11 | 12 | ``` 13 | /* 14 | Setup: overlay_images have been created and their number match with the number 15 | of the swap_chain_images of your application. The overlay_images in this 16 | example have the same format as your swap_chain images (optional) 17 | */ 18 | struct nk_context *ctx = nk_glfw3_init( 19 | demo.win, demo.device, demo.physical_device, demo.indices.graphics, 20 | demo.overlay_image_views, demo.swap_chain_images_len, 21 | demo.swap_chain_image_format, NK_GLFW3_INSTALL_CALLBACKS, 22 | MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); 23 | [...] 24 | /* 25 | in your draw loop draw you can then render to the overlay image at 26 | `image_index` 27 | your own application can then wait for the semaphore and produce 28 | the swap_chain_image at `image_index` 29 | this should simply sample from the overlay_image (see example) 30 | */ 31 | nk_semaphore semaphore = 32 | nk_glfw3_render(demo.graphics_queue, image_index, 33 | demo.image_available, NK_ANTI_ALIASING_ON); 34 | if (!render(&demo, &bg, nk_semaphore, image_index)) { 35 | fprintf(stderr, "render failed\n"); 36 | return false; 37 | } 38 | ``` 39 | 40 | You must call `nk_glfw3_resize` whenever the size of the overlay_images resize. 41 | 42 | ## Using images 43 | 44 | Images can be used by providing a VkImageView as an nk_image_ptr to nuklear: 45 | 46 | ``` 47 | img = nk_image_ptr(demo.demo_texture_image_view); 48 | ``` 49 | 50 | Note that they must have SHADER_READ_OPTIMAL layout 51 | 52 | It is currently not possible to specify how they are being sampled. The nuklear glfw vulkan integration uses a fixed sampler that does linear filtering. 53 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/shaders/demo.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | layout(binding = 0) uniform sampler2D overlay; 5 | 6 | layout(location = 0) in vec2 inUV; 7 | 8 | layout(location = 0) out vec4 outColor; 9 | 10 | void main() { 11 | outColor = texture(overlay, inUV); 12 | } 13 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/shaders/demo.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | layout (location = 0) out vec2 outUV; 5 | 6 | void main() 7 | { 8 | outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2); 9 | gl_Position = vec4(outUV * 2.0f + -1.0f, 0.0f, 1.0f); 10 | } 11 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/src/Makefile: -------------------------------------------------------------------------------- 1 | create_shader_inlined_header: nuklearshaders/nuklear.vert.spv nuklearshaders/nuklear.frag.spv 2 | 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_glfw_vulkan.in.h > nuklear_glfw_vulkan.h 3 | 4 | nuklearshaders/nuklear.vert.spv: nuklearshaders/nuklear.vert 5 | glslc --target-env=vulkan nuklearshaders/nuklear.vert -o nuklearshaders/nuklear.vert.spv 6 | 7 | nuklearshaders/nuklear.frag.spv: nuklearshaders/nuklear.frag 8 | glslc --target-env=vulkan nuklearshaders/nuklear.frag -o nuklearshaders/nuklear.frag.spv 9 | 10 | clean: 11 | rm nuklearshaders/nuklear.vert.spv nuklearshaders/nuklear.frag.spv nuklear_glfw_vulkan.h 12 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/src/README.md: -------------------------------------------------------------------------------- 1 | Contrary to OpenGL Vulkan needs precompiled shaders in the SPIR-V format which makes it a bit more difficult to inline the shadercode. 2 | 3 | After executing `make` the result should be a self contained `nuklear_glfw_vulkan.h`. Copy the result file to the parent directory and the "release" should be done. 4 | 5 | You will need to have `xxd`, `glslc` and `awk` installed for this. 6 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/src/nuklearshaders/nuklear.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | layout(binding = 0, set = 1) uniform sampler2D currentTexture; 5 | 6 | layout(location = 0) in vec4 fragColor; 7 | layout(location = 1) in vec2 fragUv; 8 | layout(location = 0) out vec4 outColor; 9 | 10 | void main() { 11 | vec4 texColor = texture(currentTexture, fragUv); 12 | outColor = fragColor * texColor; 13 | } 14 | -------------------------------------------------------------------------------- /demo/glfw_vulkan/src/nuklearshaders/nuklear.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | out gl_PerVertex { 5 | vec4 gl_Position; 6 | }; 7 | 8 | layout(binding = 0) uniform UniformBufferObject { 9 | mat4 projection; 10 | } ubo; 11 | 12 | layout(location = 0) in vec2 position; 13 | layout(location = 1) in vec2 uv; 14 | layout(location = 2) in uvec4 color; 15 | layout(location = 0) out vec4 fragColor; 16 | layout(location = 1) out vec2 fragUv; 17 | 18 | void main() { 19 | gl_Position = ubo.projection * vec4(position, 0.0, 1.0); 20 | gl_Position.y = -gl_Position.y; 21 | fragColor = vec4(color[0]/255.0, color[1]/255.0, color[2]/255.0, color[3]/255.0); 22 | fragUv = uv; 23 | } 24 | -------------------------------------------------------------------------------- /demo/rawfb/sdl/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS+=`sdl2-config --cflags --libs` -std=c89 -Wall -Wextra -pedantic -Wno-unused-function -O0 -g -fvisibility=hidden `pkg-config SDL2_ttf --cflags --libs` 2 | 3 | .PHONY: clean 4 | 5 | demo: main.c ../nuklear_rawfb.h 6 | $(CC) -o demo *.c $(CFLAGS) -lrt -lm 7 | 8 | clean: 9 | $(RM) demo 10 | -------------------------------------------------------------------------------- /demo/rawfb/wayland/.gitignore: -------------------------------------------------------------------------------- 1 | xdg-shell.c 2 | xdg-shell.h 3 | -------------------------------------------------------------------------------- /demo/rawfb/wayland/Makefile: -------------------------------------------------------------------------------- 1 | WAYLAND=`pkg-config wayland-client --cflags --libs` 2 | WAYLAND_SCANNER=wayland-scanner 3 | WAYLAND_PROTOCOLS_DIR=/usr/share/wayland-protocols 4 | 5 | CFLAGS+=-std=c99 -Wall -Wextra -pedantic -Wno-unused-function -O3 -fvisibility=hidden 6 | 7 | .PHONY: clean 8 | 9 | demo: main.c xdg-shell.c xdg-shell.h 10 | $(CC) $(CFLAGS) -o demo *.c $(WAYLAND) -lrt -lm 11 | 12 | xdg-shell.c: 13 | $(WAYLAND_SCANNER) code $(WAYLAND_PROTOCOLS_DIR)/stable/xdg-shell/xdg-shell.xml xdg-shell.c 14 | 15 | xdg-shell.h: 16 | $(WAYLAND_SCANNER) client-header $(WAYLAND_PROTOCOLS_DIR)/stable/xdg-shell/xdg-shell.xml xdg-shell.h 17 | 18 | clean: 19 | $(RM) demo xdg-shell.c xdg-shell.h 20 | -------------------------------------------------------------------------------- /demo/rawfb/x11/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | $(BIN): 11 | @mkdir -p bin 12 | rm -f bin/$(BIN) $(OBJS) 13 | $(CC) $(SRC) $(CFLAGS) -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -o bin/$(BIN) -lX11 -lXext -lm 14 | -------------------------------------------------------------------------------- /demo/sdl_opengl2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic -DSDL_DISABLE_IMMINTRIN_H 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | ifeq ($(OS),Windows_NT) 11 | BIN := $(BIN).exe 12 | LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lm -lGLU32 13 | else 14 | UNAME_S := $(shell uname -s) 15 | ifeq ($(UNAME_S),Darwin) 16 | LIBS = -lSDL2 -framework OpenGL -lm 17 | else 18 | LIBS = -lSDL2 -lGL -lm -lGLU 19 | endif 20 | endif 21 | 22 | $(BIN): 23 | @mkdir -p bin 24 | rm -f bin/$(BIN) $(OBJS) 25 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 26 | -------------------------------------------------------------------------------- /demo/sdl_opengl3/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic -DSDL_DISABLE_IMMINTRIN_H 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | ifeq ($(OS),Windows_NT) 11 | BIN := $(BIN).exe 12 | LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lm -lGLU32 -lGLEW32 13 | else 14 | UNAME_S := $(shell uname -s) 15 | ifeq ($(UNAME_S),Darwin) 16 | LIBS = -lSDL2 -framework OpenGL -lm -lGLEW 17 | else 18 | LIBS = -lSDL2 -lGL -lm -lGLU -lGLEW 19 | endif 20 | endif 21 | 22 | $(BIN): 23 | @mkdir -p bin 24 | rm -f bin/$(BIN) $(OBJS) 25 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 26 | -------------------------------------------------------------------------------- /demo/sdl_opengles2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic -DSDL_DISABLE_IMMINTRIN_H 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | UNAME_S := $(shell uname -s) 11 | ifeq ($(UNAME_S),Darwin) 12 | LIBS = -lSDL2 -framework OpenGLES -lm 13 | else 14 | LIBS = -lSDL2 -lGLESv2 -lm 15 | endif 16 | 17 | $(BIN): prepare 18 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 19 | 20 | web: prepare 21 | emcc $(SRC) -Os -s USE_SDL=2 -o bin/index.html 22 | 23 | rpi: prepare 24 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) `PKG_CONFIG_PATH=/opt/vc/lib/pkgconfig/ pkg-config --cflags --libs bcm_host brcmglesv2` `/usr/local/bin/sdl2-config --libs --cflags` 25 | 26 | prepare: 27 | @mkdir -p bin 28 | rm -f bin/$(BIN) $(OBJS) 29 | -------------------------------------------------------------------------------- /demo/sdl_opengles2/Readme.md: -------------------------------------------------------------------------------- 1 | OpenGL ES 2 | ========= 3 | 4 | OpenGL ES (OpenGL for Embedded Systems) it is a subset of OpenGL aimed to be simple and fast. It is designed for embedded systems, so for example, this demo could be a good point to start an Android application. 5 | 6 | 7 | Linux, Mac OS X 8 | --------------- 9 | You can develop under your favorite modern Linux distro. Most of them support Open GL ES out of the box. But remember that implementation could be different and you have to test your application on the end device too. 10 | 11 | Just use `make` to build normal Linux / Mac OS X version. 12 | 13 | 14 | Emscripten 15 | ---------- 16 | Some other demos could be compiled into WebGL too. But the point of this demo is to be compiled without overhead and compatibility mode. 17 | 18 | `make web` to build a web-version using Emscripten. 19 | 20 | 21 | Raspberry Pi 22 | ------------ 23 | 24 | Accelerated Open GL ES2 output supported for Raspberry Pi too. But SDL2 in default Raspbian repositories is not supporting `rpi` video driver by default, so you have to compile SDL2 yourself. 25 | 26 | It is better to compile SDL2 without X11 support (*--disable-video-x11* configure option). Or use `export SDL_VIDEODRIVER=rpi` before each run of the application. 27 | 28 | More info can be found here: https://github.com/vurtun/nuklear/issues/748 29 | 30 | `make rpi` to build the demo on your Raspberry Pi board. 31 | -------------------------------------------------------------------------------- /demo/sdl_renderer/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic -O2 -DSDL_DISABLE_IMMINTRIN_H 6 | CFLAGS += `sdl2-config --cflags` 7 | 8 | SRC = main.c 9 | OBJ = $(SRC:.c=.o) 10 | 11 | ifeq ($(OS),Windows_NT) 12 | #TODO 13 | #BIN := $(BIN).exe 14 | #LIBS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lm -lGLU32 15 | else 16 | UNAME_S := $(shell uname -s) 17 | ifeq ($(UNAME_S),Darwin) 18 | #TODO LIBS = -lSDL2 -framework OpenGL -lm 19 | else 20 | LIBS += -lm -ldl `sdl2-config --libs` 21 | endif 22 | endif 23 | 24 | $(BIN): 25 | @mkdir -p bin 26 | rm -f bin/$(BIN) $(OBJS) 27 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 28 | -------------------------------------------------------------------------------- /demo/sdl_vulkan/.gitignore: -------------------------------------------------------------------------------- 1 | src/nuklearshaders/*.spv 2 | src/nuklear_sdl_vulkan.h 3 | shaders/*.spv 4 | -------------------------------------------------------------------------------- /demo/sdl_vulkan/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic -fsanitize=address -O2 6 | CFLAGS += -DSDL_DISABLE_IMMINTRIN_H 7 | 8 | SRC = main.c 9 | OBJ = $(SRC:.c=.o) 10 | 11 | ifeq ($(OS),Windows_NT) 12 | BIN := $(BIN).exe 13 | LIBS = -lsdl2 -lvulkan -lm 14 | else 15 | UNAME_S := $(shell uname -s) 16 | SDL2 := $(shell pkg-config --libs sdl2) 17 | LIBS = $(SDL2) -lvulkan -lm 18 | endif 19 | 20 | 21 | $(BIN): shaders/demo.vert.spv shaders/demo.frag.spv 22 | @mkdir -p bin 23 | rm -f bin/$(BIN) $(OBJS) 24 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS) 25 | 26 | shaders/demo.vert.spv: shaders/demo.vert 27 | glslc --target-env=vulkan shaders/demo.vert -o shaders/demo.vert.spv 28 | 29 | shaders/demo.frag.spv: shaders/demo.frag 30 | glslc --target-env=vulkan shaders/demo.frag -o shaders/demo.frag.spv 31 | -------------------------------------------------------------------------------- /demo/sdl_vulkan/README.md: -------------------------------------------------------------------------------- 1 | # nuklear sdl vulkan 2 | 3 | ## Theory of operation 4 | 5 | The nuklear SDL vulkan integration creates an independent graphics pipeline that will render the nuklear UI to separate render targets. 6 | The application is responsible to fully manage these render targets. So it must ensure they are properly sized (and resized when requested). 7 | 8 | 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. 9 | 10 | This is how you can integrate it in your application: 11 | 12 | ``` 13 | /* 14 | Setup: overlay_images have been created and their number match with the number 15 | of the swap_chain_images of your application. The overlay_images in this 16 | example have the same format as your swap_chain images (optional) 17 | */ 18 | struct nk_context *ctx = nk_sdl_init( 19 | demo.win, demo.device, demo.physical_device, demo.indices.graphics, 20 | demo.overlay_image_views, demo.swap_chain_images_len, 21 | demo.swap_chain_image_format, 0, 22 | MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); 23 | [...] 24 | /* 25 | in your draw loop draw you can then render to the overlay image at 26 | `image_index` 27 | your own application can then wait for the semaphore and produce 28 | the swap_chain_image at `image_index` 29 | this should simply sample from the overlay_image (see example) 30 | */ 31 | nk_semaphore semaphore = 32 | nk_sdl_render(demo.graphics_queue, image_index, 33 | demo.image_available, NK_ANTI_ALIASING_ON); 34 | if (!render(&demo, &bg, nk_semaphore, image_index)) { 35 | fprintf(stderr, "render failed\n"); 36 | return false; 37 | } 38 | ``` 39 | 40 | You must call `nk_sdl_resize` whenever the size of the overlay_images resize. 41 | 42 | ## Using images 43 | 44 | Images can be used by providing a VkImageView as an nk_image_ptr to nuklear: 45 | 46 | ``` 47 | img = nk_image_ptr(demo.demo_texture_image_view); 48 | ``` 49 | 50 | Note that they must have SHADER_READ_OPTIMAL layout 51 | 52 | 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. 53 | -------------------------------------------------------------------------------- /demo/sdl_vulkan/shaders/demo.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | layout(binding = 0) uniform sampler2D overlay; 5 | 6 | layout(location = 0) in vec2 inUV; 7 | 8 | layout(location = 0) out vec4 outColor; 9 | 10 | void main() { 11 | outColor = texture(overlay, inUV); 12 | } 13 | -------------------------------------------------------------------------------- /demo/sdl_vulkan/shaders/demo.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | layout (location = 0) out vec2 outUV; 5 | 6 | void main() 7 | { 8 | outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2); 9 | gl_Position = vec4(outUV * 2.0f + -1.0f, 0.0f, 1.0f); 10 | } 11 | -------------------------------------------------------------------------------- /demo/sdl_vulkan/src/Makefile: -------------------------------------------------------------------------------- 1 | create_shader_inlined_header: nuklearshaders/nuklear.vert.spv nuklearshaders/nuklear.frag.spv 2 | 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 3 | 4 | nuklearshaders/nuklear.vert.spv: nuklearshaders/nuklear.vert 5 | glslc --target-env=vulkan nuklearshaders/nuklear.vert -o nuklearshaders/nuklear.vert.spv 6 | 7 | nuklearshaders/nuklear.frag.spv: nuklearshaders/nuklear.frag 8 | glslc --target-env=vulkan nuklearshaders/nuklear.frag -o nuklearshaders/nuklear.frag.spv 9 | 10 | clean: 11 | rm nuklearshaders/nuklear.vert.spv nuklearshaders/nuklear.frag.spv nuklear_sdl_vulkan.h 12 | -------------------------------------------------------------------------------- /demo/sdl_vulkan/src/README.md: -------------------------------------------------------------------------------- 1 | Contrary to OpenGL Vulkan needs precompiled shaders in the SPIR-V format which makes it a bit more difficult to inline the shadercode. 2 | 3 | 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. 4 | 5 | You will need to have `xxd`, `glslc` and `awk` installed for this. 6 | -------------------------------------------------------------------------------- /demo/sdl_vulkan/src/nuklearshaders/nuklear.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | layout(binding = 0, set = 1) uniform sampler2D currentTexture; 5 | 6 | layout(location = 0) in vec4 fragColor; 7 | layout(location = 1) in vec2 fragUv; 8 | layout(location = 0) out vec4 outColor; 9 | 10 | void main() { 11 | vec4 texColor = texture(currentTexture, fragUv); 12 | outColor = fragColor * texColor; 13 | } 14 | -------------------------------------------------------------------------------- /demo/sdl_vulkan/src/nuklearshaders/nuklear.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | out gl_PerVertex { 5 | vec4 gl_Position; 6 | }; 7 | 8 | layout(binding = 0) uniform UniformBufferObject { 9 | mat4 projection; 10 | } ubo; 11 | 12 | layout(location = 0) in vec2 position; 13 | layout(location = 1) in vec2 uv; 14 | layout(location = 2) in uvec4 color; 15 | layout(location = 0) out vec4 fragColor; 16 | layout(location = 1) out vec2 fragUv; 17 | 18 | void main() { 19 | gl_Position = ubo.projection * vec4(position, 0.0, 1.0); 20 | gl_Position.y = -gl_Position.y; 21 | fragColor = vec4(color[0]/255.0, color[1]/255.0, color[2]/255.0, color[3]/255.0); 22 | fragUv = uv; 23 | } 24 | -------------------------------------------------------------------------------- /demo/sfml_opengl2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | CC = g++ 3 | BIN = demo 4 | 5 | # Flags 6 | CFLAGS += -s -Wall -Wextra -pedantic 7 | 8 | SRC = main.cpp 9 | OBJ = $(SRC:.cpp=.o) 10 | 11 | ifeq ($(OS),Windows_NT) 12 | # Edit the line below to point to your SFML folder on Windows 13 | SFML_DIR = C:/Users/Ricky/MinGW-Libs/SFML 14 | 15 | BIN := $(BIN).exe 16 | LIBS = -lmingw32 -DSFML_STATIC -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 17 | else 18 | # Edit the line below to point to your SFML folder on Linux/MacOS 19 | SFML_DIR = /home/ricky/Libraries/SFML 20 | 21 | UNAME_S := $(shell uname -s) 22 | ifeq ($(UNAME_S),Darwin) 23 | LIBS = -lsfml-window -lsfml-system -pthread -framework OpenGL 24 | else 25 | LIBS = -DSFML_STATIC -lsfml-window -lsfml-system -pthread -ludev -lGL -lX11 -lXrandr 26 | endif 27 | endif 28 | 29 | SFML_INC = -I $(SFML_DIR)/include 30 | SFML_LIB = -L $(SFML_DIR)/lib 31 | 32 | $(BIN): 33 | $(CC) $(SRC) $(CFLAGS) -o $(BIN) $(SFML_INC) $(SFML_LIB) $(LIBS) 34 | -------------------------------------------------------------------------------- /demo/sfml_opengl2/Readme.md: -------------------------------------------------------------------------------- 1 | # SFML 2.4 nuklear backend 2 | 3 | This backend provides support for [SFML 2.4](http://www.sfml-dev.org). It will work on all platforms supported by SFML. 4 | 5 | ## Compiling 6 | 7 | You have to edit the Makefile provided so that you can build the demo. Edit the SFML_DIR variable to point to your SFML root folder. This will be the folder to which SFML was installed and contains the lib and include folders. 8 | 9 | On Linux there is an extra step. You need to install the udev development files. 10 | -------------------------------------------------------------------------------- /demo/sfml_opengl2/main.cpp: -------------------------------------------------------------------------------- 1 | /* nuklear - v1.32.0 - public domain */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #define NK_INCLUDE_FIXED_TYPES 16 | #define NK_INCLUDE_STANDARD_IO 17 | #define NK_INCLUDE_STANDARD_VARARGS 18 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 19 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 20 | #define NK_INCLUDE_FONT_BAKING 21 | #define NK_INCLUDE_DEFAULT_FONT 22 | #define NK_IMPLEMENTATION 23 | #define NK_SFML_GL2_IMPLEMENTATION 24 | #include "../../nuklear.h" 25 | #include "nuklear_sfml_gl2.h" 26 | 27 | #define WINDOW_WIDTH 1200 28 | #define WINDOW_HEIGHT 800 29 | 30 | /* =============================================================== 31 | * 32 | * EXAMPLE 33 | * 34 | * ===============================================================*/ 35 | /* This are some code examples to provide a small overview of what can be 36 | * done with this library. To try out an example uncomment the defines */ 37 | /*#define INCLUDE_ALL */ 38 | /*#define INCLUDE_STYLE */ 39 | /*#define INCLUDE_CALCULATOR */ 40 | /*#define INCLUDE_CANVAS */ 41 | #define INCLUDE_OVERVIEW 42 | /*#define INCLUDE_CONFIGURATOR */ 43 | /*#define INCLUDE_NODE_EDITOR */ 44 | 45 | #ifdef INCLUDE_ALL 46 | #define INCLUDE_STYLE 47 | #define INCLUDE_CALCULATOR 48 | #define INCLUDE_CANVAS 49 | #define INCLUDE_OVERVIEW 50 | #define INCLUDE_CONFIGURATOR 51 | #define INCLUDE_NODE_EDITOR 52 | #endif 53 | 54 | #ifdef INCLUDE_STYLE 55 | #include "../../demo/common/style.c" 56 | #endif 57 | #ifdef INCLUDE_CALCULATOR 58 | #include "../../demo/common/calculator.c" 59 | #endif 60 | #ifdef INCLUDE_CANVAS 61 | #include "../../demo/common/canvas.c" 62 | #endif 63 | #ifdef INCLUDE_OVERVIEW 64 | #include "../../demo/common/overview.c" 65 | #endif 66 | #ifdef INCLUDE_CONFIGURATOR 67 | #include "../../demo/common/style_configurator.c" 68 | #endif 69 | #ifdef INCLUDE_NODE_EDITOR 70 | #include "../../demo/common/node_editor.c" 71 | #endif 72 | 73 | /* =============================================================== 74 | * 75 | * DEMO 76 | * 77 | * ===============================================================*/ 78 | int main(void) 79 | { 80 | /* Platform */ 81 | sf::ContextSettings settings(24, 8, 4, 2, 2); 82 | sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings); 83 | win.setVerticalSyncEnabled(true); 84 | win.setActive(true); 85 | glViewport(0, 0, win.getSize().x, win.getSize().y); 86 | 87 | /* GUI */ 88 | struct nk_context *ctx; 89 | ctx = nk_sfml_init(&win); 90 | /* Load Fonts: if none of these are loaded a default font will be used */ 91 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 92 | struct nk_font_atlas *atlas; 93 | nk_sfml_font_stash_begin(&atlas); 94 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 95 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ 96 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 97 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 98 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 99 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 100 | nk_sfml_font_stash_end(); 101 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 102 | /*nk_style_set_font(ctx, &droid->handle);*/ 103 | 104 | #ifdef INCLUDE_CONFIGURATOR 105 | static struct nk_color color_table[NK_COLOR_COUNT]; 106 | memcpy(color_table, nk_default_color_style, sizeof(color_table)); 107 | #endif 108 | 109 | struct nk_colorf bg; 110 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 111 | while (win.isOpen()) 112 | { 113 | /* Input */ 114 | sf::Event evt; 115 | nk_input_begin(ctx); 116 | while(win.pollEvent(evt)) { 117 | if(evt.type == sf::Event::Closed) 118 | win.close(); 119 | else if(evt.type == sf::Event::Resized) 120 | glViewport(0, 0, evt.size.width, evt.size.height); 121 | nk_sfml_handle_event(&evt); 122 | } 123 | nk_input_end(ctx); 124 | 125 | /* GUI */ 126 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 127 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 128 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 129 | { 130 | enum {EASY, HARD}; 131 | static int op = EASY; 132 | static int property = 20; 133 | nk_layout_row_static(ctx, 30, 80, 1); 134 | if (nk_button_label(ctx, "button")) 135 | fprintf(stdout, "button pressed\n"); 136 | 137 | nk_layout_row_dynamic(ctx, 30, 2); 138 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 139 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 140 | 141 | nk_layout_row_dynamic(ctx, 25, 1); 142 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 143 | 144 | nk_layout_row_dynamic(ctx, 20, 1); 145 | nk_label(ctx, "background:", NK_TEXT_LEFT); 146 | nk_layout_row_dynamic(ctx, 25, 1); 147 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 148 | nk_layout_row_dynamic(ctx, 120, 1); 149 | bg = nk_color_picker(ctx, bg, NK_RGBA); 150 | nk_layout_row_dynamic(ctx, 25, 1); 151 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 152 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 153 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 154 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 155 | nk_combo_end(ctx); 156 | } 157 | } 158 | nk_end(ctx); 159 | 160 | /* -------------- EXAMPLES ---------------- */ 161 | #ifdef INCLUDE_CALCULATOR 162 | calculator(ctx); 163 | #endif 164 | #ifdef INCLUDE_CANVAS 165 | canvas(ctx); 166 | #endif 167 | #ifdef INCLUDE_OVERVIEW 168 | overview(ctx); 169 | #endif 170 | #ifdef INCLUDE_CONFIGURATOR 171 | style_configurator(ctx, color_table); 172 | #endif 173 | #ifdef INCLUDE_NODE_EDITOR 174 | node_editor(ctx); 175 | #endif 176 | /* ----------------------------------------- */ 177 | 178 | /* Draw */ 179 | win.setActive(true); 180 | glClear(GL_COLOR_BUFFER_BIT); 181 | glClearColor(bg.r, bg.g, bg.b, bg.a); 182 | /* IMPORTANT: `nk_sfml_render` modifies some global OpenGL state 183 | * with blending, scissor, face culling and depth test and defaults everything 184 | * back into a default state. Make sure to either save and restore or 185 | * reset your own state after drawing rendering the UI. */ 186 | nk_sfml_render(NK_ANTI_ALIASING_ON); 187 | win.display(); 188 | } 189 | nk_sfml_shutdown(); 190 | return 0; 191 | } 192 | 193 | -------------------------------------------------------------------------------- /demo/sfml_opengl3/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | CC = g++ 3 | BIN = demo 4 | 5 | # Flags 6 | CFLAGS += -s -Wall -Wextra -pedantic 7 | 8 | SRC = main.cpp 9 | OBJ = $(SRC:.cpp=.o) 10 | 11 | ifeq ($(OS),Windows_NT) 12 | # Edit the line below to point to your SFML/GLAD folder on Windows 13 | SFML_DIR = C:/Users/Ricky/MinGW-Libs/SFML 14 | GLAD_DIR = C:/Users/Ricky/MinGW-Libs/GLAD 15 | 16 | BIN := $(BIN).exe 17 | LIBS = -lmingw32 -DSFML_STATIC -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 18 | else 19 | # Edit the line below to point to your SFML/GLAD folder on Linux/MacOS 20 | SFML_DIR = /home/ricky/Libraries/SFML 21 | GLAD_DIR = /home/ricky/Libraries/GLAD 22 | 23 | UNAME_S := $(shell uname -s) 24 | ifeq ($(UNAME_S),Darwin) 25 | LIBS = -lsfml-window -lsfml-system -pthread -framework OpenGL 26 | else 27 | LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lGL -lX11 -lXrandr 28 | endif 29 | endif 30 | 31 | SFML_INC = -I $(SFML_DIR)/include 32 | SFML_LIB = -L $(SFML_DIR)/lib 33 | GLAD_INC = -I $(GLAD_DIR)/include 34 | GLAD_SRC = $(GLAD_DIR)/src/glad.c 35 | 36 | $(BIN): 37 | $(CC) $(GLAD_SRC) $(SRC) $(CFLAGS) $(GLAD_INC) $(SFML_INC) $(SFML_LIB) $(SFML_EXT) -o $(BIN) $(LIBS) 38 | -------------------------------------------------------------------------------- /demo/sfml_opengl3/main.cpp: -------------------------------------------------------------------------------- 1 | /* nuklear - v1.32.0 - public domain */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #define NK_INCLUDE_FIXED_TYPES 15 | #define NK_INCLUDE_STANDARD_IO 16 | #define NK_INCLUDE_STANDARD_VARARGS 17 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 18 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 19 | #define NK_INCLUDE_FONT_BAKING 20 | #define NK_INCLUDE_DEFAULT_FONT 21 | #define NK_IMPLEMENTATION 22 | #define NK_SFML_GL3_IMPLEMENTATION 23 | #include "../../nuklear.h" 24 | #include "nuklear_sfml_gl3.h" 25 | 26 | #define WINDOW_WIDTH 1200 27 | #define WINDOW_HEIGHT 800 28 | 29 | #define MAX_VERTEX_BUFFER 512 * 1024 30 | #define MAX_ELEMENT_BUFFER 128 * 1024 31 | 32 | /* =============================================================== 33 | * 34 | * EXAMPLE 35 | * 36 | * ===============================================================*/ 37 | /* This are some code examples to provide a small overview of what can be 38 | * done with this library. To try out an example uncomment the defines */ 39 | /*#define INCLUDE_ALL */ 40 | /*#define INCLUDE_STYLE */ 41 | /*#define INCLUDE_CALCULATOR */ 42 | /*#define INCLUDE_CANVAS */ 43 | #define INCLUDE_OVERVIEW 44 | /*#define INCLUDE_CONFIGURATOR */ 45 | /*#define INCLUDE_NODE_EDITOR */ 46 | 47 | #ifdef INCLUDE_ALL 48 | #define INCLUDE_STYLE 49 | #define INCLUDE_CALCULATOR 50 | #define INCLUDE_CANVAS 51 | #define INCLUDE_OVERVIEW 52 | #define INCLUDE_CONFIGURATOR 53 | #define INCLUDE_NODE_EDITOR 54 | #endif 55 | 56 | #ifdef INCLUDE_STYLE 57 | #include "../../demo/common/style.c" 58 | #endif 59 | #ifdef INCLUDE_CALCULATOR 60 | #include "../../demo/common/calculator.c" 61 | #endif 62 | #ifdef INCLUDE_CANVAS 63 | #include "../../demo/common/canvas.c" 64 | #endif 65 | #ifdef INCLUDE_OVERVIEW 66 | #include "../../demo/common/overview.c" 67 | #endif 68 | #ifdef INCLUDE_CONFIGURATOR 69 | #include "../../demo/common/style_configurator.c" 70 | #endif 71 | #ifdef INCLUDE_NODE_EDITOR 72 | #include "../../demo/common/node_editor.c" 73 | #endif 74 | 75 | /* =============================================================== 76 | * 77 | * DEMO 78 | * 79 | * ===============================================================*/ 80 | int main(void) 81 | { 82 | /* Platform */ 83 | sf::ContextSettings settings(24, 8, 4, 3, 3); 84 | sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings); 85 | win.setVerticalSyncEnabled(true); 86 | win.setActive(true); 87 | if(!gladLoadGL()) { /* Load OpenGL extensions */ 88 | printf("Failed to load OpenGL extensions!\n"); 89 | return -1; 90 | } 91 | glViewport(0, 0, win.getSize().x, win.getSize().y); 92 | 93 | /* GUI */ 94 | struct nk_context *ctx; 95 | ctx = nk_sfml_init(&win); 96 | /* Load Fonts: if none of these are loaded a default font will be used */ 97 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 98 | struct nk_font_atlas *atlas; 99 | nk_sfml_font_stash_begin(&atlas); 100 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 101 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ 102 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 103 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 104 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 105 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 106 | nk_sfml_font_stash_end(); 107 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 108 | /*nk_style_set_font(ctx, &droid->handle);*/ 109 | 110 | #ifdef INCLUDE_CONFIGURATOR 111 | static struct nk_color color_table[NK_COLOR_COUNT]; 112 | memcpy(color_table, nk_default_color_style, sizeof(color_table)); 113 | #endif 114 | 115 | struct nk_colorf bg; 116 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 117 | while (win.isOpen()) 118 | { 119 | /* Input */ 120 | sf::Event evt; 121 | nk_input_begin(ctx); 122 | while(win.pollEvent(evt)) { 123 | if(evt.type == sf::Event::Closed) 124 | win.close(); 125 | else if(evt.type == sf::Event::Resized) 126 | glViewport(0, 0, evt.size.width, evt.size.height); 127 | 128 | nk_sfml_handle_event(&evt); 129 | } 130 | nk_input_end(ctx); 131 | 132 | /* GUI */ 133 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 134 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 135 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 136 | { 137 | enum {EASY, HARD}; 138 | static int op = EASY; 139 | static int property = 20; 140 | nk_layout_row_static(ctx, 30, 80, 1); 141 | if (nk_button_label(ctx, "button")) 142 | fprintf(stdout, "button pressed\n"); 143 | 144 | nk_layout_row_dynamic(ctx, 30, 2); 145 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 146 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 147 | 148 | nk_layout_row_dynamic(ctx, 25, 1); 149 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 150 | 151 | nk_layout_row_dynamic(ctx, 20, 1); 152 | nk_label(ctx, "background:", NK_TEXT_LEFT); 153 | nk_layout_row_dynamic(ctx, 25, 1); 154 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 155 | nk_layout_row_dynamic(ctx, 120, 1); 156 | bg = nk_color_picker(ctx, bg, NK_RGBA); 157 | nk_layout_row_dynamic(ctx, 25, 1); 158 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 159 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 160 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 161 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 162 | nk_combo_end(ctx); 163 | } 164 | } 165 | nk_end(ctx); 166 | 167 | /* -------------- EXAMPLES ---------------- */ 168 | #ifdef INCLUDE_CALCULATOR 169 | calculator(ctx); 170 | #endif 171 | #ifdef INCLUDE_CANVAS 172 | canvas(ctx); 173 | #endif 174 | #ifdef INCLUDE_OVERVIEW 175 | overview(ctx); 176 | #endif 177 | #ifdef INCLUDE_CONFIGURATOR 178 | style_configurator(ctx, color_table); 179 | #endif 180 | #ifdef INCLUDE_NODE_EDITOR 181 | node_editor(ctx); 182 | #endif 183 | /* ----------------------------------------- */ 184 | 185 | /* Draw */ 186 | win.setActive(true); 187 | glClear(GL_COLOR_BUFFER_BIT); 188 | glClearColor(bg.r, bg.g, bg.b, bg.a); 189 | /* IMPORTANT: `nk_sfml_render` modifies some global OpenGL state 190 | * with blending, scissor, face culling and depth test and defaults everything 191 | * back into a default state. Make sure to either save and restore or 192 | * reset your own state after drawing rendering the UI. */ 193 | nk_sfml_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); 194 | win.display(); 195 | } 196 | nk_sfml_shutdown(); 197 | return 0; 198 | } 199 | 200 | -------------------------------------------------------------------------------- /demo/x11/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | $(BIN): 11 | @mkdir -p bin 12 | rm -f bin/$(BIN) $(OBJS) 13 | $(CC) $(SRC) $(CFLAGS) -D_POSIX_C_SOURCE=200809L -o bin/$(BIN) -lX11 -lm 14 | -------------------------------------------------------------------------------- /demo/x11/main.c: -------------------------------------------------------------------------------- 1 | /* nuklear - v1.32.0 - public domain */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define NK_INCLUDE_FIXED_TYPES 14 | #define NK_INCLUDE_STANDARD_IO 15 | #define NK_INCLUDE_STANDARD_VARARGS 16 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 17 | #define NK_IMPLEMENTATION 18 | #define NK_XLIB_IMPLEMENTATION 19 | #include "../../nuklear.h" 20 | #include "nuklear_xlib.h" 21 | 22 | #define DTIME 20 23 | #define WINDOW_WIDTH 800 24 | #define WINDOW_HEIGHT 600 25 | 26 | typedef struct XWindow XWindow; 27 | struct XWindow { 28 | Display *dpy; 29 | Window root; 30 | Visual *vis; 31 | Colormap cmap; 32 | XWindowAttributes attr; 33 | XSetWindowAttributes swa; 34 | Window win; 35 | int screen; 36 | XFont *font; 37 | unsigned int width; 38 | unsigned int height; 39 | Atom wm_delete_window; 40 | }; 41 | 42 | static void 43 | die(const char *fmt, ...) 44 | { 45 | va_list ap; 46 | va_start(ap, fmt); 47 | vfprintf(stderr, fmt, ap); 48 | va_end(ap); 49 | fputs("\n", stderr); 50 | exit(EXIT_FAILURE); 51 | } 52 | 53 | static long 54 | timestamp(void) 55 | { 56 | struct timeval tv; 57 | if (gettimeofday(&tv, NULL) < 0) return 0; 58 | return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000); 59 | } 60 | 61 | static void 62 | sleep_for(long t) 63 | { 64 | struct timespec req; 65 | const time_t sec = (int)(t/1000); 66 | const long ms = t - (sec * 1000); 67 | req.tv_sec = sec; 68 | req.tv_nsec = ms * 1000000L; 69 | while(-1 == nanosleep(&req, &req)); 70 | } 71 | 72 | /* =============================================================== 73 | * 74 | * EXAMPLE 75 | * 76 | * ===============================================================*/ 77 | /* This are some code examples to provide a small overview of what can be 78 | * done with this library. To try out an example uncomment the defines */ 79 | /*#define INCLUDE_ALL */ 80 | /*#define INCLUDE_STYLE */ 81 | /*#define INCLUDE_CALCULATOR */ 82 | /*#define INCLUDE_CANVAS */ 83 | #define INCLUDE_OVERVIEW 84 | /*#define INCLUDE_CONFIGURATOR */ 85 | /*#define INCLUDE_NODE_EDITOR */ 86 | 87 | #ifdef INCLUDE_ALL 88 | #define INCLUDE_STYLE 89 | #define INCLUDE_CALCULATOR 90 | #define INCLUDE_CANVAS 91 | #define INCLUDE_OVERVIEW 92 | #define INCLUDE_CONFIGURATOR 93 | #define INCLUDE_NODE_EDITOR 94 | #endif 95 | 96 | #ifdef INCLUDE_STYLE 97 | #include "../../demo/common/style.c" 98 | #endif 99 | #ifdef INCLUDE_CALCULATOR 100 | #include "../../demo/common/calculator.c" 101 | #endif 102 | #ifdef INCLUDE_CANVAS 103 | #include "../../demo/common/canvas.c" 104 | #endif 105 | #ifdef INCLUDE_OVERVIEW 106 | #include "../../demo/common/overview.c" 107 | #endif 108 | #ifdef INCLUDE_CONFIGURATOR 109 | #include "../../demo/common/style_configurator.c" 110 | #endif 111 | #ifdef INCLUDE_NODE_EDITOR 112 | #include "../../demo/common/node_editor.c" 113 | #endif 114 | 115 | /* =============================================================== 116 | * 117 | * DEMO 118 | * 119 | * ===============================================================*/ 120 | int 121 | main(void) 122 | { 123 | long dt; 124 | long started; 125 | int running = 1; 126 | XWindow xw; 127 | struct nk_context *ctx; 128 | 129 | #ifdef INCLUDE_CONFIGURATOR 130 | static struct nk_color color_table[NK_COLOR_COUNT]; 131 | memcpy(color_table, nk_default_color_style, sizeof(color_table)); 132 | #endif 133 | 134 | /* X11 */ 135 | memset(&xw, 0, sizeof xw); 136 | xw.dpy = XOpenDisplay(NULL); 137 | if (!xw.dpy) die("Could not open a display; perhaps $DISPLAY is not set?"); 138 | xw.root = DefaultRootWindow(xw.dpy); 139 | xw.screen = XDefaultScreen(xw.dpy); 140 | xw.vis = XDefaultVisual(xw.dpy, xw.screen); 141 | xw.cmap = XCreateColormap(xw.dpy,xw.root,xw.vis,AllocNone); 142 | 143 | xw.swa.colormap = xw.cmap; 144 | xw.swa.event_mask = 145 | ExposureMask | KeyPressMask | KeyReleaseMask | 146 | ButtonPress | ButtonReleaseMask| ButtonMotionMask | 147 | Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask| 148 | PointerMotionMask | KeymapStateMask; 149 | xw.win = XCreateWindow(xw.dpy, xw.root, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 150 | XDefaultDepth(xw.dpy, xw.screen), InputOutput, 151 | xw.vis, CWEventMask | CWColormap, &xw.swa); 152 | 153 | XStoreName(xw.dpy, xw.win, "X11"); 154 | XMapWindow(xw.dpy, xw.win); 155 | xw.wm_delete_window = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False); 156 | XSetWMProtocols(xw.dpy, xw.win, &xw.wm_delete_window, 1); 157 | XGetWindowAttributes(xw.dpy, xw.win, &xw.attr); 158 | xw.width = (unsigned int)xw.attr.width; 159 | xw.height = (unsigned int)xw.attr.height; 160 | 161 | /* GUI */ 162 | xw.font = nk_xfont_create(xw.dpy, "fixed"); 163 | ctx = nk_xlib_init(xw.font, xw.dpy, xw.screen, xw.win, xw.width, xw.height); 164 | 165 | while (running) 166 | { 167 | /* Input */ 168 | XEvent evt; 169 | started = timestamp(); 170 | nk_input_begin(ctx); 171 | while (XPending(xw.dpy)) { 172 | XNextEvent(xw.dpy, &evt); 173 | if (evt.type == ClientMessage) goto cleanup; 174 | if (XFilterEvent(&evt, xw.win)) continue; 175 | nk_xlib_handle_event(xw.dpy, xw.screen, xw.win, &evt); 176 | } 177 | nk_input_end(ctx); 178 | 179 | /* GUI */ 180 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 181 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 182 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 183 | { 184 | enum {EASY, HARD}; 185 | static int op = EASY; 186 | static int property = 20; 187 | 188 | nk_layout_row_static(ctx, 30, 80, 1); 189 | if (nk_button_label(ctx, "button")) 190 | fprintf(stdout, "button pressed\n"); 191 | nk_layout_row_dynamic(ctx, 30, 2); 192 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 193 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 194 | nk_layout_row_dynamic(ctx, 25, 1); 195 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 196 | } 197 | nk_end(ctx); 198 | if (nk_window_is_hidden(ctx, "Demo")) break; 199 | 200 | /* -------------- EXAMPLES ---------------- */ 201 | #ifdef INCLUDE_CALCULATOR 202 | calculator(ctx); 203 | #endif 204 | #ifdef INCLUDE_CANVAS 205 | canvas(ctx); 206 | #endif 207 | #ifdef INCLUDE_OVERVIEW 208 | overview(ctx); 209 | #endif 210 | #ifdef INCLUDE_CONFIGURATOR 211 | style_configurator(ctx, color_table); 212 | #endif 213 | #ifdef INCLUDE_NODE_EDITOR 214 | node_editor(ctx); 215 | #endif 216 | /* ----------------------------------------- */ 217 | 218 | /* Draw */ 219 | XClearWindow(xw.dpy, xw.win); 220 | nk_xlib_render(xw.win, nk_rgb(30,30,30)); 221 | XFlush(xw.dpy); 222 | 223 | /* Timing */ 224 | dt = timestamp() - started; 225 | if (dt < DTIME) 226 | sleep_for(DTIME - dt); 227 | } 228 | 229 | cleanup: 230 | nk_xfont_del(xw.dpy, xw.font); 231 | nk_xlib_shutdown(); 232 | XUnmapWindow(xw.dpy, xw.win); 233 | XFreeColormap(xw.dpy, xw.cmap); 234 | XDestroyWindow(xw.dpy, xw.win); 235 | XCloseDisplay(xw.dpy); 236 | return 0; 237 | } 238 | 239 | -------------------------------------------------------------------------------- /demo/x11_opengl2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Compiler 5 | CC ?= clang 6 | DCC = gcc 7 | 8 | # Flags 9 | CFLAGS += -std=c89 -Wall -Wextra -pedantic 10 | 11 | SRC = main.c 12 | OBJ = $(SRC:.c=.o) 13 | 14 | # Modes 15 | .PHONY: gcc 16 | gcc: CC ?= gcc 17 | gcc: $(BIN) 18 | 19 | .PHONY: clang 20 | clang: CC ?= clang 21 | clang: $(BIN) 22 | 23 | $(BIN): 24 | @mkdir -p bin 25 | rm -f bin/$(BIN) $(OBJS) 26 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) -lX11 -lm -lGL -lm -lGLU 27 | -------------------------------------------------------------------------------- /demo/x11_opengl3/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Compiler 5 | CC ?= clang 6 | DCC = gcc 7 | 8 | # Flags 9 | CFLAGS += -std=c89 -Wall -Wextra -pedantic 10 | 11 | SRC = main.c 12 | OBJ = $(SRC:.c=.o) 13 | 14 | # Modes 15 | .PHONY: gcc 16 | gcc: CC ?= gcc 17 | gcc: $(BIN) 18 | 19 | .PHONY: clang 20 | clang: CC ?= clang 21 | clang: $(BIN) 22 | 23 | $(BIN): 24 | @mkdir -p bin 25 | rm -f bin/$(BIN) $(OBJS) 26 | $(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) -lX11 -lm -lGL -lm -lGLU 27 | -------------------------------------------------------------------------------- /demo/x11_xft/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -Wall -Wextra -pedantic -Wno-unused-function 6 | 7 | SRC = main.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | LDFLAGS += -lX11 -lm 11 | 12 | CFLAGS += ${shell pkg-config --cflags xft} -DNK_XLIB_USE_XFT 13 | LDFLAGS += ${shell pkg-config --libs xft} 14 | 15 | SRC = ${wildcard *.c} 16 | OBJ = $(SRC:.c=.o) 17 | 18 | $(BIN): 19 | @mkdir -p bin 20 | rm -f bin/$(BIN) $(OBJS) 21 | $(CC) $(SRC) $(CFLAGS) -D_POSIX_C_SOURCE=200809L -o bin/$(BIN) -lX11 ${LDFLAGS} 22 | -------------------------------------------------------------------------------- /demo/x11_xft/main.c: -------------------------------------------------------------------------------- 1 | /* nuklear - v1.32.0 - public domain */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define NK_INCLUDE_FIXED_TYPES 14 | #define NK_INCLUDE_STANDARD_IO 15 | #define NK_INCLUDE_STANDARD_VARARGS 16 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 17 | #define NK_IMPLEMENTATION 18 | #define NK_XLIB_IMPLEMENTATION 19 | #include "../../nuklear.h" 20 | #include "nuklear_xlib.h" 21 | 22 | #define DTIME 20 23 | #define WINDOW_WIDTH 800 24 | #define WINDOW_HEIGHT 600 25 | 26 | typedef struct XWindow XWindow; 27 | struct XWindow { 28 | Display *dpy; 29 | Window root; 30 | Visual *vis; 31 | Colormap cmap; 32 | XWindowAttributes attr; 33 | XSetWindowAttributes swa; 34 | Window win; 35 | int screen; 36 | XFont *font; 37 | unsigned int width; 38 | unsigned int height; 39 | Atom wm_delete_window; 40 | }; 41 | 42 | static void 43 | die(const char *fmt, ...) 44 | { 45 | va_list ap; 46 | va_start(ap, fmt); 47 | vfprintf(stderr, fmt, ap); 48 | va_end(ap); 49 | fputs("\n", stderr); 50 | exit(EXIT_FAILURE); 51 | } 52 | 53 | static long 54 | timestamp(void) 55 | { 56 | struct timeval tv; 57 | if (gettimeofday(&tv, NULL) < 0) return 0; 58 | return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000); 59 | } 60 | 61 | static void 62 | sleep_for(long t) 63 | { 64 | struct timespec req; 65 | const time_t sec = (int)(t/1000); 66 | const long ms = t - (sec * 1000); 67 | req.tv_sec = sec; 68 | req.tv_nsec = ms * 1000000L; 69 | while(-1 == nanosleep(&req, &req)); 70 | } 71 | 72 | /* =============================================================== 73 | * 74 | * EXAMPLE 75 | * 76 | * ===============================================================*/ 77 | /* This are some code examples to provide a small overview of what can be 78 | * done with this library. To try out an example uncomment the defines */ 79 | /*#define INCLUDE_ALL */ 80 | /*#define INCLUDE_STYLE */ 81 | /*#define INCLUDE_CALCULATOR */ 82 | /*#define INCLUDE_CANVAS */ 83 | #define INCLUDE_OVERVIEW 84 | /*#define INCLUDE_CONFIGURATOR */ 85 | /*#define INCLUDE_NODE_EDITOR */ 86 | 87 | #ifdef INCLUDE_ALL 88 | #define INCLUDE_STYLE 89 | #define INCLUDE_CALCULATOR 90 | #define INCLUDE_CANVAS 91 | #define INCLUDE_OVERVIEW 92 | #define INCLUDE_CONFIGURATOR 93 | #define INCLUDE_NODE_EDITOR 94 | #endif 95 | 96 | #ifdef INCLUDE_STYLE 97 | #include "../../demo/common/style.c" 98 | #endif 99 | #ifdef INCLUDE_CALCULATOR 100 | #include "../../demo/common/calculator.c" 101 | #endif 102 | #ifdef INCLUDE_CANVAS 103 | #include "../../demo/common/canvas.c" 104 | #endif 105 | #ifdef INCLUDE_OVERVIEW 106 | #include "../../demo/common/overview.c" 107 | #endif 108 | #ifdef INCLUDE_CONFIGURATOR 109 | #include "../../demo/common/style_configurator.c" 110 | #endif 111 | #ifdef INCLUDE_NODE_EDITOR 112 | #include "../../demo/common/node_editor.c" 113 | #endif 114 | 115 | /* =============================================================== 116 | * 117 | * DEMO 118 | * 119 | * ===============================================================*/ 120 | int 121 | main(void) 122 | { 123 | long dt; 124 | long started; 125 | int running = 1; 126 | XWindow xw; 127 | struct nk_context *ctx; 128 | 129 | #ifdef INCLUDE_CONFIGURATOR 130 | static struct nk_color color_table[NK_COLOR_COUNT]; 131 | memcpy(color_table, nk_default_color_style, sizeof(color_table)); 132 | #endif 133 | 134 | /* X11 */ 135 | memset(&xw, 0, sizeof xw); 136 | xw.dpy = XOpenDisplay(NULL); 137 | if (!xw.dpy) die("Could not open a display; perhaps $DISPLAY is not set?"); 138 | xw.root = DefaultRootWindow(xw.dpy); 139 | xw.screen = XDefaultScreen(xw.dpy); 140 | xw.vis = XDefaultVisual(xw.dpy, xw.screen); 141 | xw.cmap = XCreateColormap(xw.dpy,xw.root,xw.vis,AllocNone); 142 | 143 | xw.swa.colormap = xw.cmap; 144 | xw.swa.event_mask = 145 | ExposureMask | KeyPressMask | KeyReleaseMask | 146 | ButtonPress | ButtonReleaseMask| ButtonMotionMask | 147 | Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask| 148 | PointerMotionMask | KeymapStateMask; 149 | xw.win = XCreateWindow(xw.dpy, xw.root, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 150 | XDefaultDepth(xw.dpy, xw.screen), InputOutput, 151 | xw.vis, CWEventMask | CWColormap, &xw.swa); 152 | 153 | XStoreName(xw.dpy, xw.win, "X11"); 154 | XMapWindow(xw.dpy, xw.win); 155 | xw.wm_delete_window = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False); 156 | XSetWMProtocols(xw.dpy, xw.win, &xw.wm_delete_window, 1); 157 | XGetWindowAttributes(xw.dpy, xw.win, &xw.attr); 158 | xw.width = (unsigned int)xw.attr.width; 159 | xw.height = (unsigned int)xw.attr.height; 160 | 161 | /* GUI */ 162 | xw.font = nk_xfont_create(xw.dpy, "Arial"); 163 | ctx = nk_xlib_init(xw.font, xw.dpy, xw.screen, xw.win, 164 | #ifdef NK_XLIB_USE_XFT 165 | xw.vis, xw.cmap, 166 | #endif 167 | xw.width, xw.height); 168 | 169 | while (running) 170 | { 171 | /* Input */ 172 | XEvent evt; 173 | started = timestamp(); 174 | nk_input_begin(ctx); 175 | while (XPending(xw.dpy)) { 176 | XNextEvent(xw.dpy, &evt); 177 | if (evt.type == ClientMessage) goto cleanup; 178 | if (XFilterEvent(&evt, xw.win)) continue; 179 | nk_xlib_handle_event(xw.dpy, xw.screen, xw.win, &evt); 180 | } 181 | nk_input_end(ctx); 182 | 183 | /* GUI */ 184 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 185 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 186 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 187 | { 188 | enum {EASY, HARD}; 189 | static int op = EASY; 190 | static int property = 20; 191 | 192 | nk_layout_row_static(ctx, 30, 80, 1); 193 | if (nk_button_label(ctx, "button")) 194 | fprintf(stdout, "button pressed\n"); 195 | nk_layout_row_dynamic(ctx, 30, 2); 196 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 197 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 198 | nk_layout_row_dynamic(ctx, 25, 1); 199 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 200 | } 201 | nk_end(ctx); 202 | if (nk_window_is_hidden(ctx, "Demo")) break; 203 | 204 | /* -------------- EXAMPLES ---------------- */ 205 | #ifdef INCLUDE_CALCULATOR 206 | calculator(ctx); 207 | #endif 208 | #ifdef INCLUDE_CANVAS 209 | canvas(ctx); 210 | #endif 211 | #ifdef INCLUDE_OVERVIEW 212 | overview(ctx); 213 | #endif 214 | #ifdef INCLUDE_CONFIGURATOR 215 | style_configurator(ctx, color_table); 216 | #endif 217 | #ifdef INCLUDE_NODE_EDITOR 218 | node_editor(ctx); 219 | #endif 220 | /* ----------------------------------------- */ 221 | 222 | /* Draw */ 223 | XClearWindow(xw.dpy, xw.win); 224 | nk_xlib_render(xw.win, nk_rgb(30,30,30)); 225 | XFlush(xw.dpy); 226 | 227 | /* Timing */ 228 | dt = timestamp() - started; 229 | if (dt < DTIME) 230 | sleep_for(DTIME - dt); 231 | } 232 | 233 | cleanup: 234 | nk_xfont_del(xw.dpy, xw.font); 235 | nk_xlib_shutdown(); 236 | XUnmapWindow(xw.dpy, xw.win); 237 | XFreeColormap(xw.dpy, xw.cmap); 238 | XDestroyWindow(xw.dpy, xw.win); 239 | XCloseDisplay(xw.dpy); 240 | return 0; 241 | } 242 | 243 | -------------------------------------------------------------------------------- /demo/xcb_cairo/Makefile: -------------------------------------------------------------------------------- 1 | # Target 2 | BIN = demo 3 | CFLAGS += -std=c89 -pedantic 4 | LDFLAGS += -lm 5 | SRC = ${wildcard *.c} 6 | OBJ = $(SRC:.c=.o) 7 | 8 | # Freetype 9 | CFLAGS += ${shell pkg-config --cflags freetype2} 10 | LDFLAGS += ${shell pkg-config --libs freetype2} 11 | 12 | # XCB 13 | CFLAGS += ${shell pkg-config --cflags xcb xcb-util xcb-keysyms xkbcommon xkbcommon-x11} 14 | LDFLAGS += ${shell pkg-config --libs xcb xcb-util xcb-keysyms xkbcommon xkbcommon-x11} 15 | 16 | # Cairo 17 | CFLAGS += ${shell pkg-config --cflags cairo} 18 | LDFLAGS += ${shell pkg-config --libs cairo} 19 | 20 | # Rules 21 | $(BIN): 22 | @mkdir -p bin 23 | rm -f bin/$(BIN) $(OBJS) 24 | $(CC) $(SRC) $(CFLAGS) -D_POSIX_C_SOURCE=200809L -o bin/$(BIN) ${LDFLAGS} 25 | -------------------------------------------------------------------------------- /demo/xcb_cairo/main.c: -------------------------------------------------------------------------------- 1 | /* nuklear - v1.32.0 - public domain */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define NK_INCLUDE_FIXED_TYPES 14 | #define NK_INCLUDE_STANDARD_IO 15 | #define NK_INCLUDE_STANDARD_VARARGS 16 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 17 | #define NK_IMPLEMENTATION 18 | #include "../../nuklear.h" 19 | 20 | #define NK_XCB_CAIRO_IMPLEMENTATION 21 | #include "nuklear_xcb.h" 22 | 23 | static void die(const char *fmt, ...) 24 | { 25 | va_list ap; 26 | va_start(ap, fmt); 27 | vfprintf(stderr, fmt, ap); 28 | va_end(ap); 29 | fputs("\n", stderr); 30 | exit(EXIT_FAILURE); 31 | } 32 | 33 | /* =============================================================== 34 | * 35 | * EXAMPLE 36 | * 37 | * ===============================================================*/ 38 | /* This are some code examples to provide a small overview of what can be 39 | * done with this library. To try out an example uncomment the defines */ 40 | 41 | /*#define INCLUDE_ALL */ 42 | /*#define INCLUDE_STYLE */ 43 | /*#define INCLUDE_CALCULATOR */ 44 | #define INCLUDE_OVERVIEW 45 | /*#define INCLUDE_CONFIGURATOR */ 46 | /*#define INCLUDE_NODE_EDITOR */ 47 | /*#define INCLUDE_CANVAS */ 48 | 49 | #ifdef INCLUDE_ALL 50 | #define INCLUDE_STYLE 51 | #define INCLUDE_CALCULATOR 52 | #define INCLUDE_OVERVIEW 53 | #define INCLUDE_NODE_EDITOR 54 | #define INCLUDE_CONFIGURATOR 55 | #define INCLUDE_CANVAS 56 | #endif 57 | 58 | #ifdef INCLUDE_STYLE 59 | #include "../common/style.c" 60 | #endif 61 | #ifdef INCLUDE_CALCULATOR 62 | #include "../common/calculator.c" 63 | #endif 64 | #ifdef INCLUDE_OVERVIEW 65 | #include "../common/overview.c" 66 | #endif 67 | #ifdef INCLUDE_CONFIGURATOR 68 | #include "../../demo/common/style_configurator.c" 69 | #endif 70 | #ifdef INCLUDE_NODE_EDITOR 71 | #include "../common/node_editor.c" 72 | #endif 73 | #ifdef INCLUDE_CANVAS 74 | #include "../common/canvas.c" 75 | #endif 76 | 77 | /* =============================================================== 78 | * 79 | * DEMO 80 | * 81 | * ===============================================================*/ 82 | int 83 | main(void) 84 | { 85 | struct nk_xcb_context *xcb_ctx; 86 | struct nk_color background = nk_rgb(0, 0, 0); 87 | struct nk_cairo_context *cairo_ctx; 88 | struct nk_user_font *font; 89 | struct nk_context* ctx; 90 | int running = 1; 91 | int events; 92 | 93 | #ifdef INCLUDE_CONFIGURATOR 94 | static struct nk_color color_table[NK_COLOR_COUNT]; 95 | memcpy(color_table, nk_default_color_style, sizeof(color_table)); 96 | #endif 97 | 98 | xcb_ctx = nk_xcb_init("Nuklear XCB/Cairo", 20, 20, 600, 800); 99 | cairo_ctx = nk_cairo_init(&background, NULL, 0, nk_xcb_create_cairo_surface(xcb_ctx)); 100 | /*cairo_ctx = nk_cairo_init(&background, "../../extra_font/DroidSans.ttf", 0, nk_xcb_create_surface(xcb_ctx));*/ 101 | font = nk_cairo_default_font(cairo_ctx); 102 | ctx = malloc(sizeof(struct nk_context)); 103 | nk_init_default(ctx, font); 104 | 105 | #ifdef INCLUDE_STYLE 106 | set_style(ctx, THEME_BLACK); 107 | /*nk_style_push_float(ctx, &ctx->style.window.rounding, 20.0f);*/ 108 | /*set_style(ctx, THEME_WHITE);*/ 109 | /*set_style(ctx, THEME_RED);*/ 110 | /*set_style(ctx, THEME_BLUE);*/ 111 | /*set_style(ctx, THEME_DARK);*/ 112 | #endif 113 | 114 | while (running) 115 | { 116 | /* Events */ 117 | events = nk_xcb_handle_event(xcb_ctx, ctx); 118 | if (events & NK_XCB_EVENT_STOP) { 119 | break; 120 | } 121 | if (events & NK_XCB_EVENT_PAINT) { 122 | nk_cairo_damage(cairo_ctx); 123 | } 124 | if (events & NK_XCB_EVENT_RESIZED) { 125 | nk_xcb_resize_cairo_surface(xcb_ctx, nk_cairo_surface(cairo_ctx)); 126 | } 127 | 128 | /* GUI */ 129 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 130 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 131 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 132 | { 133 | enum {EASY, HARD}; 134 | static int op = EASY; 135 | static int property = 20; 136 | 137 | nk_layout_row_static(ctx, 30, 80, 1); 138 | if (nk_button_label(ctx, "button")) 139 | fprintf(stdout, "button pressed\n"); 140 | nk_layout_row_dynamic(ctx, 30, 2); 141 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 142 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 143 | nk_layout_row_dynamic(ctx, 25, 1); 144 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 145 | } 146 | nk_end(ctx); 147 | if (nk_window_is_hidden(ctx, "Demo")) { 148 | break; 149 | } 150 | 151 | /* -------------- EXAMPLES ---------------- */ 152 | #ifdef INCLUDE_CALCULATOR 153 | calculator(ctx); 154 | #endif 155 | #ifdef INCLUDE_OVERVIEW 156 | overview(ctx); 157 | #endif 158 | #ifdef INCLUDE_CONFIGURATOR 159 | style_configurator(ctx, color_table); 160 | #endif 161 | #ifdef INCLUDE_NODE_EDITOR 162 | node_editor(ctx); 163 | #endif 164 | #ifdef INCLUDE_CANVAS 165 | canvas(ctx); 166 | #endif 167 | /* ----------------------------------------- */ 168 | 169 | /* Render */ 170 | nk_cairo_render(cairo_ctx, ctx); 171 | nk_xcb_render(xcb_ctx); 172 | nk_clear(ctx); 173 | } 174 | 175 | nk_free(ctx); 176 | free(ctx); 177 | nk_cairo_free(cairo_ctx); 178 | nk_xcb_free(xcb_ctx); 179 | 180 | return EXIT_SUCCESS; 181 | } 182 | -------------------------------------------------------------------------------- /example/Makefile: -------------------------------------------------------------------------------- 1 | # Flags 2 | CFLAGS += -std=c99 -Wall -Wextra -pedantic -Wno-misleading-indentation -Wno-shift-negative-value 3 | LIBS := 4 | 5 | ifeq ($(OS),Windows_NT) 6 | DEL_BIN = IF EXIST bin DEL /F /Q bin\* 7 | BIN := $(BIN).exe 8 | LIBS := -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32 9 | else 10 | DEL_BIN = rm -rf bin 11 | UNAME_S := $(shell uname -s) 12 | GLFW3 := $(shell pkg-config --libs glfw3) 13 | ifeq ($(UNAME_S),Darwin) 14 | LIBS := $(GLFW3) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib 15 | CFLAGS += -I/usr/local/include 16 | else 17 | LIBS := $(GLFW3) -lGL -lm -lGLU -lGLEW 18 | endif 19 | endif 20 | 21 | all: generate file_browser extended canvas skinning 22 | 23 | generate: clean 24 | ifeq ($(OS),Windows_NT) 25 | @mkdir bin 2> nul || exit 0 26 | else 27 | @mkdir -p bin 28 | endif 29 | 30 | clean: 31 | $(DEL_BIN) 32 | 33 | file_browser: generate 34 | $(CC) $(CFLAGS) -o bin/file_browser file_browser.c $(LIBS) 35 | 36 | extended: generate 37 | $(CC) $(CFLAGS) -o bin/extended extended.c $(LIBS) 38 | 39 | canvas: generate 40 | $(CC) $(CFLAGS) -o bin/canvas canvas.c $(LIBS) 41 | 42 | skinning: generate 43 | $(CC) $(CFLAGS) -o bin/skinning skinning.c $(LIBS) 44 | 45 | -------------------------------------------------------------------------------- /example/icon/checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/checked.png -------------------------------------------------------------------------------- /example/icon/cloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/cloud.png -------------------------------------------------------------------------------- /example/icon/computer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/computer.png -------------------------------------------------------------------------------- /example/icon/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/copy.png -------------------------------------------------------------------------------- /example/icon/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/default.png -------------------------------------------------------------------------------- /example/icon/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/delete.png -------------------------------------------------------------------------------- /example/icon/desktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/desktop.png -------------------------------------------------------------------------------- /example/icon/directory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/directory.png -------------------------------------------------------------------------------- /example/icon/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/edit.png -------------------------------------------------------------------------------- /example/icon/export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/export.png -------------------------------------------------------------------------------- /example/icon/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/font.png -------------------------------------------------------------------------------- /example/icon/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/home.png -------------------------------------------------------------------------------- /example/icon/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/img.png -------------------------------------------------------------------------------- /example/icon/movie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/movie.png -------------------------------------------------------------------------------- /example/icon/music.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/music.png -------------------------------------------------------------------------------- /example/icon/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/next.png -------------------------------------------------------------------------------- /example/icon/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/pause.png -------------------------------------------------------------------------------- /example/icon/pen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/pen.png -------------------------------------------------------------------------------- /example/icon/phone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/phone.png -------------------------------------------------------------------------------- /example/icon/plane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/plane.png -------------------------------------------------------------------------------- /example/icon/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/play.png -------------------------------------------------------------------------------- /example/icon/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/prev.png -------------------------------------------------------------------------------- /example/icon/rocket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/rocket.png -------------------------------------------------------------------------------- /example/icon/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/settings.png -------------------------------------------------------------------------------- /example/icon/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/stop.png -------------------------------------------------------------------------------- /example/icon/text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/text.png -------------------------------------------------------------------------------- /example/icon/tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/tools.png -------------------------------------------------------------------------------- /example/icon/unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/unchecked.png -------------------------------------------------------------------------------- /example/icon/volume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/volume.png -------------------------------------------------------------------------------- /example/icon/wifi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/icon/wifi.png -------------------------------------------------------------------------------- /example/images/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/images/image1.png -------------------------------------------------------------------------------- /example/images/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/images/image2.png -------------------------------------------------------------------------------- /example/images/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/images/image3.png -------------------------------------------------------------------------------- /example/images/image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/images/image4.png -------------------------------------------------------------------------------- /example/images/image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/images/image5.png -------------------------------------------------------------------------------- /example/images/image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/images/image6.png -------------------------------------------------------------------------------- /example/images/image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/images/image7.png -------------------------------------------------------------------------------- /example/images/image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/images/image8.png -------------------------------------------------------------------------------- /example/images/image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/images/image9.png -------------------------------------------------------------------------------- /example/skins/gwen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/example/skins/gwen.png -------------------------------------------------------------------------------- /extra_font/Cousine-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/Cousine-Regular.ttf -------------------------------------------------------------------------------- /extra_font/DroidSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/DroidSans.ttf -------------------------------------------------------------------------------- /extra_font/Karla-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/Karla-Regular.ttf -------------------------------------------------------------------------------- /extra_font/ProggyClean.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/ProggyClean.ttf -------------------------------------------------------------------------------- /extra_font/ProggyTiny.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/ProggyTiny.ttf -------------------------------------------------------------------------------- /extra_font/Raleway-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/Raleway-Bold.ttf -------------------------------------------------------------------------------- /extra_font/Roboto-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/Roboto-Bold.ttf -------------------------------------------------------------------------------- /extra_font/Roboto-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/Roboto-Light.ttf -------------------------------------------------------------------------------- /extra_font/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/Roboto-Regular.ttf -------------------------------------------------------------------------------- /extra_font/kenvector_future.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/kenvector_future.ttf -------------------------------------------------------------------------------- /extra_font/kenvector_future_thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/171090c8e21584330207544dbde5e7c1ec581135/extra_font/kenvector_future_thin.ttf -------------------------------------------------------------------------------- /src/CREDITS: -------------------------------------------------------------------------------- 1 | /// ## Gallery 2 | /// ![Figure [blue]: Feature overview with blue color styling](https://cloud.githubusercontent.com/assets/8057201/13538240/acd96876-e249-11e5-9547-5ac0b19667a0.png) 3 | /// ![Figure [red]: Feature overview with red color styling](https://cloud.githubusercontent.com/assets/8057201/13538243/b04acd4c-e249-11e5-8fd2-ad7744a5b446.png) 4 | /// ![Figure [widgets]: Widget overview](https://cloud.githubusercontent.com/assets/8057201/11282359/3325e3c6-8eff-11e5-86cb-cf02b0596087.png) 5 | /// ![Figure [blackwhite]: Black and white](https://cloud.githubusercontent.com/assets/8057201/11033668/59ab5d04-86e5-11e5-8091-c56f16411565.png) 6 | /// ![Figure [filexp]: File explorer](https://cloud.githubusercontent.com/assets/8057201/10718115/02a9ba08-7b6b-11e5-950f-adacdd637739.png) 7 | /// ![Figure [opengl]: OpenGL Editor](https://cloud.githubusercontent.com/assets/8057201/12779619/2a20d72c-ca69-11e5-95fe-4edecf820d5c.png) 8 | /// ![Figure [nodedit]: Node Editor](https://cloud.githubusercontent.com/assets/8057201/9976995/e81ac04a-5ef7-11e5-872b-acd54fbeee03.gif) 9 | /// ![Figure [skinning]: Using skinning in Nuklear](https://cloud.githubusercontent.com/assets/8057201/15991632/76494854-30b8-11e6-9555-a69840d0d50b.png) 10 | /// ![Figure [bf]: Heavy modified version](https://cloud.githubusercontent.com/assets/8057201/14902576/339926a8-0d9c-11e6-9fee-a8b73af04473.png) 11 | /// 12 | /// ## Credits 13 | /// Developed by Micha Mettke and every direct or indirect github contributor.

14 | /// 15 | /// Embeds [stb_texedit](https://github.com/nothings/stb/blob/master/stb_textedit.h), [stb_truetype](https://github.com/nothings/stb/blob/master/stb_truetype.h) and [stb_rectpack](https://github.com/nothings/stb/blob/master/stb_rect_pack.h) by Sean Barret (public domain)
16 | /// Uses [stddoc.c](https://github.com/r-lyeh/stddoc.c) from r-lyeh@github.com for documentation generation

17 | /// Embeds ProggyClean.ttf font by Tristan Grimmer (MIT license).
18 | /// 19 | /// Big thank you to Omar Cornut (ocornut@github) for his [imgui library](https://github.com/ocornut/imgui) and 20 | /// giving me the inspiration for this library, Casey Muratori for handmade hero 21 | /// and his original immediate mode graphical user interface idea and Sean 22 | /// Barret for his amazing single header libraries which restored my faith 23 | /// in libraries and brought me to create some of my own. Finally Apoorva Joshi 24 | /// for his single header file packer. 25 | -------------------------------------------------------------------------------- /src/LICENSE: -------------------------------------------------------------------------------- 1 | /// ## License 2 | /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none 3 | /// ------------------------------------------------------------------------------ 4 | /// This software is available under 2 licenses -- choose whichever you prefer. 5 | /// ------------------------------------------------------------------------------ 6 | /// ALTERNATIVE A - MIT License 7 | /// Copyright (c) 2016-2018 Micha Mettke 8 | /// Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | /// this software and associated documentation files (the "Software"), to deal in 10 | /// the Software without restriction, including without limitation the rights to 11 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 | /// of the Software, and to permit persons to whom the Software is furnished to do 13 | /// so, subject to the following conditions: 14 | /// The above copyright notice and this permission notice shall be included in all 15 | /// copies or substantial portions of the Software. 16 | /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | /// SOFTWARE. 23 | /// ------------------------------------------------------------------------------ 24 | /// ALTERNATIVE B - Public Domain (www.unlicense.org) 25 | /// This is free and unencumbered software released into the public domain. 26 | /// Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 27 | /// software, either in source code form or as a compiled binary, for any purpose, 28 | /// commercial or non-commercial, and by any means. 29 | /// In jurisdictions that recognize copyright laws, the author or authors of this 30 | /// software dedicate any and all copyright interest in the software to the public 31 | /// domain. We make this dedication for the benefit of the public at large and to 32 | /// the detriment of our heirs and successors. We intend this dedication to be an 33 | /// overt act of relinquishment in perpetuity of all present and future rights to 34 | /// this software under copyright law. 35 | /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | /// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 39 | /// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 40 | /// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 41 | /// ------------------------------------------------------------------------------ 42 | /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 43 | 44 | -------------------------------------------------------------------------------- /src/Readme.md: -------------------------------------------------------------------------------- 1 | File Packer: 2 | ------------ 3 | - On Linux/Mac just run ./paq.sh > ../nuklear.h 4 | - On Windows just run paq.bat 5 | -------------------------------------------------------------------------------- /src/build.py: -------------------------------------------------------------------------------- 1 | 2 | import fnmatch 3 | import os.path 4 | import sys 5 | import re 6 | 7 | def print_help(): 8 | print( 9 | """usage: python single_header_packer.py --macro [--intro ] --extern --pub --priv1 --priv2 [--outro ] 10 | 11 | where can be a comma-separated list of files. e.g. --priv *.c,inc/*.h 12 | or a space separated list encapsulated in quotes. e.g. --priv1 "file.c file2.c file3.c" 13 | 14 | The 'extern' files are placed between 'priv1' and 'priv2'. 15 | 16 | The resulting code is packed as follows: 17 | 18 | /* 19 | [intro file contents] 20 | */ 21 | 22 | #ifndef _SINGLE_HEADER 23 | #define _SINGLE_HEADER 24 | [public header file contents] 25 | #endif /* _SINGLE_HEADER */ 26 | 27 | #ifdef _IMPLEMENTATION 28 | [private header and source file contents] 29 | #endif /* _IMPLEMENTATION */ 30 | 31 | /* 32 | [outro file contents] 33 | */""") 34 | 35 | def parse_files(arg): 36 | files = [] 37 | paths = re.split(r'[,\s]', arg) 38 | 39 | for path in paths: 40 | if "*" in path: 41 | # Wildcard 42 | d = os.path.dirname(path) 43 | if d == "": d = "." 44 | if d == " ": continue 45 | if not os.path.exists(d): 46 | print(d + " does not exist.") 47 | exit() 48 | 49 | wildcard = os.path.basename(path) 50 | unsorted = [] 51 | for file in os.listdir(d): 52 | if fnmatch.fnmatch(file, wildcard): 53 | unsorted.append(os.path.join(d, file)) 54 | unsorted.sort() 55 | files.extend(unsorted) 56 | 57 | else: 58 | # Regular file 59 | if not os.path.exists(path): 60 | print(path + " does not exist.") 61 | exit() 62 | elif os.path.isdir(path): 63 | print(path + " is a directory. Expected a file name.") 64 | exit() 65 | else: 66 | files.append(path) 67 | 68 | return files; 69 | 70 | def omit_includes(str, files): 71 | for file in files: 72 | fname = os.path.basename(file) 73 | if ".h" in file: 74 | str = str.replace("#include \"" + fname + "\"", ""); 75 | str = str.replace("#include <" + fname + ">", ""); 76 | return str 77 | 78 | def fix_comments(str): 79 | return re.sub(r"//(.*)(\n|$)", "/* \\1 */\\2", str) 80 | 81 | # Main start 82 | # ========== 83 | 84 | if len(sys.argv) < 2: 85 | print_help() 86 | exit() 87 | 88 | intro_files = [] 89 | pub_files = [] 90 | priv_files1 = [] 91 | outro_files2 = [] 92 | extern_files = [] 93 | cur_arg = 1 94 | macro = "" 95 | 96 | # Parse args 97 | # ---------- 98 | while cur_arg < len(sys.argv): 99 | if sys.argv[cur_arg] == "--help": 100 | print_help() 101 | exit() 102 | elif sys.argv[cur_arg] == "--macro": 103 | cur_arg += 1 104 | macro = sys.argv[cur_arg] 105 | elif sys.argv[cur_arg] == "--intro": 106 | cur_arg += 1 107 | intro_files = parse_files(sys.argv[cur_arg]) 108 | elif sys.argv[cur_arg] == "--pub": 109 | cur_arg += 1 110 | pub_files = parse_files(sys.argv[cur_arg]) 111 | elif sys.argv[cur_arg] == "--priv1": 112 | cur_arg += 1 113 | priv_files1 = parse_files(sys.argv[cur_arg]) 114 | elif sys.argv[cur_arg] == "--priv2": 115 | cur_arg += 1 116 | priv_files2 = parse_files(sys.argv[cur_arg]) 117 | elif sys.argv[cur_arg] == "--extern": 118 | cur_arg += 1 119 | extern_files = parse_files(sys.argv[cur_arg]) 120 | elif sys.argv[cur_arg] == "--outro": 121 | cur_arg += 1 122 | outro_files = parse_files(sys.argv[cur_arg]) 123 | else: 124 | print("Unknown argument " + sys.argv[cur_arg]) 125 | 126 | cur_arg += 1 127 | 128 | if macro == "": 129 | print("Option --macro is mandatory") 130 | exit() 131 | 132 | # Print concatenated output 133 | # ------------------------- 134 | print("/*") 135 | for f in intro_files: 136 | sys.stdout.write(open(f, 'r').read()) 137 | print("*/") 138 | 139 | # print("\n#ifndef " + macro + "_SINGLE_HEADER"); 140 | # print("#define " + macro + "_SINGLE_HEADER"); 141 | print("#ifndef NK_SINGLE_FILE"); 142 | print(" #define NK_SINGLE_FILE"); 143 | print("#endif"); 144 | print(""); 145 | 146 | for f in pub_files: 147 | sys.stdout.write(open(f, 'r').read()) 148 | # print("#endif /* " + macro + "_SINGLE_HEADER */"); 149 | 150 | print("\n#ifdef " + macro + "_IMPLEMENTATION"); 151 | print(""); 152 | 153 | for f in priv_files1: 154 | print(omit_includes(open(f, 'r').read(), 155 | pub_files + priv_files1 + priv_files2 + extern_files)) 156 | for f in extern_files: 157 | print(fix_comments(open(f, 'r').read())) 158 | 159 | for f in priv_files2: 160 | print(omit_includes(open(f, 'r').read(), 161 | pub_files + priv_files1 + priv_files2 + extern_files)) 162 | 163 | print("#endif /* " + macro + "_IMPLEMENTATION */"); 164 | 165 | print("\n/*") 166 | for f in outro_files: 167 | sys.stdout.write(open(f, 'r').read()) 168 | print("*/\n") 169 | 170 | -------------------------------------------------------------------------------- /src/nuklear_9slice.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* =============================================================== 5 | * 6 | * 9-SLICE 7 | * 8 | * ===============================================================*/ 9 | NK_API struct nk_nine_slice 10 | nk_sub9slice_ptr(void *ptr, nk_ushort w, nk_ushort h, struct nk_rect rgn, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) 11 | { 12 | struct nk_nine_slice s; 13 | struct nk_image *i = &s.img; 14 | nk_zero(&s, sizeof(s)); 15 | i->handle.ptr = ptr; 16 | i->w = w; i->h = h; 17 | i->region[0] = (nk_ushort)rgn.x; 18 | i->region[1] = (nk_ushort)rgn.y; 19 | i->region[2] = (nk_ushort)rgn.w; 20 | i->region[3] = (nk_ushort)rgn.h; 21 | s.l = l; s.t = t; s.r = r; s.b = b; 22 | return s; 23 | } 24 | NK_API struct nk_nine_slice 25 | nk_sub9slice_id(int id, nk_ushort w, nk_ushort h, struct nk_rect rgn, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) 26 | { 27 | struct nk_nine_slice s; 28 | struct nk_image *i = &s.img; 29 | nk_zero(&s, sizeof(s)); 30 | i->handle.id = id; 31 | i->w = w; i->h = h; 32 | i->region[0] = (nk_ushort)rgn.x; 33 | i->region[1] = (nk_ushort)rgn.y; 34 | i->region[2] = (nk_ushort)rgn.w; 35 | i->region[3] = (nk_ushort)rgn.h; 36 | s.l = l; s.t = t; s.r = r; s.b = b; 37 | return s; 38 | } 39 | NK_API struct nk_nine_slice 40 | nk_sub9slice_handle(nk_handle handle, nk_ushort w, nk_ushort h, struct nk_rect rgn, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) 41 | { 42 | struct nk_nine_slice s; 43 | struct nk_image *i = &s.img; 44 | nk_zero(&s, sizeof(s)); 45 | i->handle = handle; 46 | i->w = w; i->h = h; 47 | i->region[0] = (nk_ushort)rgn.x; 48 | i->region[1] = (nk_ushort)rgn.y; 49 | i->region[2] = (nk_ushort)rgn.w; 50 | i->region[3] = (nk_ushort)rgn.h; 51 | s.l = l; s.t = t; s.r = r; s.b = b; 52 | return s; 53 | } 54 | NK_API struct nk_nine_slice 55 | nk_nine_slice_handle(nk_handle handle, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) 56 | { 57 | struct nk_nine_slice s; 58 | struct nk_image *i = &s.img; 59 | nk_zero(&s, sizeof(s)); 60 | i->handle = handle; 61 | i->w = 0; i->h = 0; 62 | i->region[0] = 0; 63 | i->region[1] = 0; 64 | i->region[2] = 0; 65 | i->region[3] = 0; 66 | s.l = l; s.t = t; s.r = r; s.b = b; 67 | return s; 68 | } 69 | NK_API struct nk_nine_slice 70 | nk_nine_slice_ptr(void *ptr, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) 71 | { 72 | struct nk_nine_slice s; 73 | struct nk_image *i = &s.img; 74 | nk_zero(&s, sizeof(s)); 75 | NK_ASSERT(ptr); 76 | i->handle.ptr = ptr; 77 | i->w = 0; i->h = 0; 78 | i->region[0] = 0; 79 | i->region[1] = 0; 80 | i->region[2] = 0; 81 | i->region[3] = 0; 82 | s.l = l; s.t = t; s.r = r; s.b = b; 83 | return s; 84 | } 85 | NK_API struct nk_nine_slice 86 | nk_nine_slice_id(int id, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) 87 | { 88 | struct nk_nine_slice s; 89 | struct nk_image *i = &s.img; 90 | nk_zero(&s, sizeof(s)); 91 | i->handle.id = id; 92 | i->w = 0; i->h = 0; 93 | i->region[0] = 0; 94 | i->region[1] = 0; 95 | i->region[2] = 0; 96 | i->region[3] = 0; 97 | s.l = l; s.t = t; s.r = r; s.b = b; 98 | return s; 99 | } 100 | NK_API int 101 | nk_nine_slice_is_sub9slice(const struct nk_nine_slice* slice) 102 | { 103 | NK_ASSERT(slice); 104 | return !(slice->img.w == 0 && slice->img.h == 0); 105 | } 106 | 107 | -------------------------------------------------------------------------------- /src/nuklear_color_picker.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* ============================================================== 5 | * 6 | * COLOR PICKER 7 | * 8 | * ===============================================================*/ 9 | NK_LIB nk_bool 10 | nk_color_picker_behavior(nk_flags *state, 11 | const struct nk_rect *bounds, const struct nk_rect *matrix, 12 | const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, 13 | struct nk_colorf *color, const struct nk_input *in) 14 | { 15 | float hsva[4]; 16 | nk_bool value_changed = 0; 17 | nk_bool hsv_changed = 0; 18 | 19 | NK_ASSERT(state); 20 | NK_ASSERT(matrix); 21 | NK_ASSERT(hue_bar); 22 | NK_ASSERT(color); 23 | 24 | /* color matrix */ 25 | nk_colorf_hsva_fv(hsva, *color); 26 | if (nk_button_behavior(state, *matrix, in, NK_BUTTON_REPEATER)) { 27 | hsva[1] = NK_SATURATE((in->mouse.pos.x - matrix->x) / (matrix->w-1)); 28 | hsva[2] = 1.0f - NK_SATURATE((in->mouse.pos.y - matrix->y) / (matrix->h-1)); 29 | value_changed = hsv_changed = 1; 30 | } 31 | /* hue bar */ 32 | if (nk_button_behavior(state, *hue_bar, in, NK_BUTTON_REPEATER)) { 33 | hsva[0] = NK_SATURATE((in->mouse.pos.y - hue_bar->y) / (hue_bar->h-1)); 34 | value_changed = hsv_changed = 1; 35 | } 36 | /* alpha bar */ 37 | if (alpha_bar) { 38 | if (nk_button_behavior(state, *alpha_bar, in, NK_BUTTON_REPEATER)) { 39 | hsva[3] = 1.0f - NK_SATURATE((in->mouse.pos.y - alpha_bar->y) / (alpha_bar->h-1)); 40 | value_changed = 1; 41 | } 42 | } 43 | nk_widget_state_reset(state); 44 | if (hsv_changed) { 45 | *color = nk_hsva_colorfv(hsva); 46 | *state = NK_WIDGET_STATE_ACTIVE; 47 | } 48 | if (value_changed) { 49 | color->a = hsva[3]; 50 | *state = NK_WIDGET_STATE_ACTIVE; 51 | } 52 | /* set color picker widget state */ 53 | if (nk_input_is_mouse_hovering_rect(in, *bounds)) 54 | *state = NK_WIDGET_STATE_HOVERED; 55 | if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, *bounds)) 56 | *state |= NK_WIDGET_STATE_ENTERED; 57 | else if (nk_input_is_mouse_prev_hovering_rect(in, *bounds)) 58 | *state |= NK_WIDGET_STATE_LEFT; 59 | return value_changed; 60 | } 61 | NK_LIB void 62 | nk_draw_color_picker(struct nk_command_buffer *o, const struct nk_rect *matrix, 63 | const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, 64 | struct nk_colorf col) 65 | { 66 | NK_STORAGE const struct nk_color black = {0,0,0,255}; 67 | NK_STORAGE const struct nk_color white = {255, 255, 255, 255}; 68 | NK_STORAGE const struct nk_color black_trans = {0,0,0,0}; 69 | 70 | const float crosshair_size = 7.0f; 71 | struct nk_color temp; 72 | float hsva[4]; 73 | float line_y; 74 | int i; 75 | 76 | NK_ASSERT(o); 77 | NK_ASSERT(matrix); 78 | NK_ASSERT(hue_bar); 79 | 80 | /* draw hue bar */ 81 | nk_colorf_hsva_fv(hsva, col); 82 | for (i = 0; i < 6; ++i) { 83 | NK_GLOBAL const struct nk_color hue_colors[] = { 84 | {255, 0, 0, 255}, {255,255,0,255}, {0,255,0,255}, {0, 255,255,255}, 85 | {0,0,255,255}, {255, 0, 255, 255}, {255, 0, 0, 255} 86 | }; 87 | nk_fill_rect_multi_color(o, 88 | nk_rect(hue_bar->x, hue_bar->y + (float)i * (hue_bar->h/6.0f) + 0.5f, 89 | hue_bar->w, (hue_bar->h/6.0f) + 0.5f), hue_colors[i], hue_colors[i], 90 | hue_colors[i+1], hue_colors[i+1]); 91 | } 92 | line_y = (float)(int)(hue_bar->y + hsva[0] * matrix->h + 0.5f); 93 | nk_stroke_line(o, hue_bar->x-1, line_y, hue_bar->x + hue_bar->w + 2, 94 | line_y, 1, nk_rgb(255,255,255)); 95 | 96 | /* draw alpha bar */ 97 | if (alpha_bar) { 98 | float alpha = NK_SATURATE(col.a); 99 | line_y = (float)(int)(alpha_bar->y + (1.0f - alpha) * matrix->h + 0.5f); 100 | 101 | nk_fill_rect_multi_color(o, *alpha_bar, white, white, black, black); 102 | nk_stroke_line(o, alpha_bar->x-1, line_y, alpha_bar->x + alpha_bar->w + 2, 103 | line_y, 1, nk_rgb(255,255,255)); 104 | } 105 | 106 | /* draw color matrix */ 107 | temp = nk_hsv_f(hsva[0], 1.0f, 1.0f); 108 | nk_fill_rect_multi_color(o, *matrix, white, temp, temp, white); 109 | nk_fill_rect_multi_color(o, *matrix, black_trans, black_trans, black, black); 110 | 111 | /* draw cross-hair */ 112 | {struct nk_vec2 p; float S = hsva[1]; float V = hsva[2]; 113 | p.x = (float)(int)(matrix->x + S * matrix->w); 114 | p.y = (float)(int)(matrix->y + (1.0f - V) * matrix->h); 115 | nk_stroke_line(o, p.x - crosshair_size, p.y, p.x-2, p.y, 1.0f, white); 116 | nk_stroke_line(o, p.x + crosshair_size + 1, p.y, p.x+3, p.y, 1.0f, white); 117 | nk_stroke_line(o, p.x, p.y + crosshair_size + 1, p.x, p.y+3, 1.0f, white); 118 | nk_stroke_line(o, p.x, p.y - crosshair_size, p.x, p.y-2, 1.0f, white);} 119 | } 120 | NK_LIB nk_bool 121 | nk_do_color_picker(nk_flags *state, 122 | struct nk_command_buffer *out, struct nk_colorf *col, 123 | enum nk_color_format fmt, struct nk_rect bounds, 124 | struct nk_vec2 padding, const struct nk_input *in, 125 | const struct nk_user_font *font) 126 | { 127 | int ret = 0; 128 | struct nk_rect matrix; 129 | struct nk_rect hue_bar; 130 | struct nk_rect alpha_bar; 131 | float bar_w; 132 | 133 | NK_ASSERT(out); 134 | NK_ASSERT(col); 135 | NK_ASSERT(state); 136 | NK_ASSERT(font); 137 | if (!out || !col || !state || !font) 138 | return ret; 139 | 140 | bar_w = font->height; 141 | bounds.x += padding.x; 142 | bounds.y += padding.x; 143 | bounds.w -= 2 * padding.x; 144 | bounds.h -= 2 * padding.y; 145 | 146 | matrix.x = bounds.x; 147 | matrix.y = bounds.y; 148 | matrix.h = bounds.h; 149 | matrix.w = bounds.w - (3 * padding.x + 2 * bar_w); 150 | 151 | hue_bar.w = bar_w; 152 | hue_bar.y = bounds.y; 153 | hue_bar.h = matrix.h; 154 | hue_bar.x = matrix.x + matrix.w + padding.x; 155 | 156 | alpha_bar.x = hue_bar.x + hue_bar.w + padding.x; 157 | alpha_bar.y = bounds.y; 158 | alpha_bar.w = bar_w; 159 | alpha_bar.h = matrix.h; 160 | 161 | ret = nk_color_picker_behavior(state, &bounds, &matrix, &hue_bar, 162 | (fmt == NK_RGBA) ? &alpha_bar:0, col, in); 163 | nk_draw_color_picker(out, &matrix, &hue_bar, (fmt == NK_RGBA) ? &alpha_bar:0, *col); 164 | return ret; 165 | } 166 | NK_API nk_bool 167 | nk_color_pick(struct nk_context * ctx, struct nk_colorf *color, 168 | enum nk_color_format fmt) 169 | { 170 | struct nk_window *win; 171 | struct nk_panel *layout; 172 | const struct nk_style *config; 173 | const struct nk_input *in; 174 | 175 | enum nk_widget_layout_states state; 176 | struct nk_rect bounds; 177 | 178 | NK_ASSERT(ctx); 179 | NK_ASSERT(color); 180 | NK_ASSERT(ctx->current); 181 | NK_ASSERT(ctx->current->layout); 182 | if (!ctx || !ctx->current || !ctx->current->layout || !color) 183 | return 0; 184 | 185 | win = ctx->current; 186 | config = &ctx->style; 187 | layout = win->layout; 188 | state = nk_widget(&bounds, ctx); 189 | if (!state) return 0; 190 | in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; 191 | return nk_do_color_picker(&ctx->last_widget_state, &win->buffer, color, fmt, bounds, 192 | nk_vec2(0,0), in, config->font); 193 | } 194 | NK_API struct nk_colorf 195 | nk_color_picker(struct nk_context *ctx, struct nk_colorf color, 196 | enum nk_color_format fmt) 197 | { 198 | nk_color_pick(ctx, &color, fmt); 199 | return color; 200 | } 201 | 202 | -------------------------------------------------------------------------------- /src/nuklear_image.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* =============================================================== 5 | * 6 | * IMAGE 7 | * 8 | * ===============================================================*/ 9 | NK_API nk_handle 10 | nk_handle_ptr(void *ptr) 11 | { 12 | nk_handle handle = {0}; 13 | handle.ptr = ptr; 14 | return handle; 15 | } 16 | NK_API nk_handle 17 | nk_handle_id(int id) 18 | { 19 | nk_handle handle; 20 | nk_zero_struct(handle); 21 | handle.id = id; 22 | return handle; 23 | } 24 | NK_API struct nk_image 25 | nk_subimage_ptr(void *ptr, nk_ushort w, nk_ushort h, struct nk_rect r) 26 | { 27 | struct nk_image s; 28 | nk_zero(&s, sizeof(s)); 29 | s.handle.ptr = ptr; 30 | s.w = w; s.h = h; 31 | s.region[0] = (nk_ushort)r.x; 32 | s.region[1] = (nk_ushort)r.y; 33 | s.region[2] = (nk_ushort)r.w; 34 | s.region[3] = (nk_ushort)r.h; 35 | return s; 36 | } 37 | NK_API struct nk_image 38 | nk_subimage_id(int id, nk_ushort w, nk_ushort h, struct nk_rect r) 39 | { 40 | struct nk_image s; 41 | nk_zero(&s, sizeof(s)); 42 | s.handle.id = id; 43 | s.w = w; s.h = h; 44 | s.region[0] = (nk_ushort)r.x; 45 | s.region[1] = (nk_ushort)r.y; 46 | s.region[2] = (nk_ushort)r.w; 47 | s.region[3] = (nk_ushort)r.h; 48 | return s; 49 | } 50 | NK_API struct nk_image 51 | nk_subimage_handle(nk_handle handle, nk_ushort w, nk_ushort h, struct nk_rect r) 52 | { 53 | struct nk_image s; 54 | nk_zero(&s, sizeof(s)); 55 | s.handle = handle; 56 | s.w = w; s.h = h; 57 | s.region[0] = (nk_ushort)r.x; 58 | s.region[1] = (nk_ushort)r.y; 59 | s.region[2] = (nk_ushort)r.w; 60 | s.region[3] = (nk_ushort)r.h; 61 | return s; 62 | } 63 | NK_API struct nk_image 64 | nk_image_handle(nk_handle handle) 65 | { 66 | struct nk_image s; 67 | nk_zero(&s, sizeof(s)); 68 | s.handle = handle; 69 | s.w = 0; s.h = 0; 70 | s.region[0] = 0; 71 | s.region[1] = 0; 72 | s.region[2] = 0; 73 | s.region[3] = 0; 74 | return s; 75 | } 76 | NK_API struct nk_image 77 | nk_image_ptr(void *ptr) 78 | { 79 | struct nk_image s; 80 | nk_zero(&s, sizeof(s)); 81 | NK_ASSERT(ptr); 82 | s.handle.ptr = ptr; 83 | s.w = 0; s.h = 0; 84 | s.region[0] = 0; 85 | s.region[1] = 0; 86 | s.region[2] = 0; 87 | s.region[3] = 0; 88 | return s; 89 | } 90 | NK_API struct nk_image 91 | nk_image_id(int id) 92 | { 93 | struct nk_image s; 94 | nk_zero(&s, sizeof(s)); 95 | s.handle.id = id; 96 | s.w = 0; s.h = 0; 97 | s.region[0] = 0; 98 | s.region[1] = 0; 99 | s.region[2] = 0; 100 | s.region[3] = 0; 101 | return s; 102 | } 103 | NK_API nk_bool 104 | nk_image_is_subimage(const struct nk_image* img) 105 | { 106 | NK_ASSERT(img); 107 | return !(img->w == 0 && img->h == 0); 108 | } 109 | NK_API void 110 | nk_image(struct nk_context *ctx, struct nk_image img) 111 | { 112 | struct nk_window *win; 113 | struct nk_rect bounds; 114 | 115 | NK_ASSERT(ctx); 116 | NK_ASSERT(ctx->current); 117 | NK_ASSERT(ctx->current->layout); 118 | if (!ctx || !ctx->current || !ctx->current->layout) return; 119 | 120 | win = ctx->current; 121 | if (!nk_widget(&bounds, ctx)) return; 122 | nk_draw_image(&win->buffer, bounds, &img, nk_white); 123 | } 124 | NK_API void 125 | nk_image_color(struct nk_context *ctx, struct nk_image img, struct nk_color col) 126 | { 127 | struct nk_window *win; 128 | struct nk_rect bounds; 129 | 130 | NK_ASSERT(ctx); 131 | NK_ASSERT(ctx->current); 132 | NK_ASSERT(ctx->current->layout); 133 | if (!ctx || !ctx->current || !ctx->current->layout) return; 134 | 135 | win = ctx->current; 136 | if (!nk_widget(&bounds, ctx)) return; 137 | nk_draw_image(&win->buffer, bounds, &img, col); 138 | } 139 | 140 | -------------------------------------------------------------------------------- /src/nuklear_list_view.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* =============================================================== 5 | * 6 | * LIST VIEW 7 | * 8 | * ===============================================================*/ 9 | NK_API nk_bool 10 | nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view, 11 | const char *title, nk_flags flags, int row_height, int row_count) 12 | { 13 | int title_len; 14 | nk_hash title_hash; 15 | nk_uint *x_offset; 16 | nk_uint *y_offset; 17 | 18 | int result; 19 | struct nk_window *win; 20 | struct nk_panel *layout; 21 | const struct nk_style *style; 22 | struct nk_vec2 item_spacing; 23 | 24 | NK_ASSERT(ctx); 25 | NK_ASSERT(view); 26 | NK_ASSERT(title); 27 | if (!ctx || !view || !title) return 0; 28 | 29 | win = ctx->current; 30 | style = &ctx->style; 31 | item_spacing = style->window.spacing; 32 | row_height += NK_MAX(0, (int)item_spacing.y); 33 | 34 | /* find persistent list view scrollbar offset */ 35 | title_len = (int)nk_strlen(title); 36 | title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_GROUP); 37 | x_offset = nk_find_value(win, title_hash); 38 | if (!x_offset) { 39 | x_offset = nk_add_value(ctx, win, title_hash, 0); 40 | y_offset = nk_add_value(ctx, win, title_hash+1, 0); 41 | 42 | NK_ASSERT(x_offset); 43 | NK_ASSERT(y_offset); 44 | if (!x_offset || !y_offset) return 0; 45 | *x_offset = *y_offset = 0; 46 | } else y_offset = nk_find_value(win, title_hash+1); 47 | view->scroll_value = *y_offset; 48 | view->scroll_pointer = y_offset; 49 | 50 | *y_offset = 0; 51 | result = nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags); 52 | win = ctx->current; 53 | layout = win->layout; 54 | 55 | view->total_height = row_height * NK_MAX(row_count,1); 56 | view->begin = (int)NK_MAX(((float)view->scroll_value / (float)row_height), 0.0f); 57 | view->count = (int)NK_MAX(nk_iceilf((layout->clip.h)/(float)row_height),0); 58 | view->count = NK_MIN(view->count, row_count - view->begin); 59 | view->end = view->begin + view->count; 60 | view->ctx = ctx; 61 | return result; 62 | } 63 | NK_API void 64 | nk_list_view_end(struct nk_list_view *view) 65 | { 66 | struct nk_context *ctx; 67 | struct nk_window *win; 68 | struct nk_panel *layout; 69 | 70 | NK_ASSERT(view); 71 | NK_ASSERT(view->ctx); 72 | NK_ASSERT(view->scroll_pointer); 73 | if (!view || !view->ctx) return; 74 | 75 | ctx = view->ctx; 76 | win = ctx->current; 77 | layout = win->layout; 78 | layout->at_y = layout->bounds.y + (float)view->total_height; 79 | *view->scroll_pointer = *view->scroll_pointer + view->scroll_value; 80 | nk_group_end(view->ctx); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /src/nuklear_page_element.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* =============================================================== 5 | * 6 | * PAGE ELEMENT 7 | * 8 | * ===============================================================*/ 9 | NK_LIB struct nk_page_element* 10 | nk_create_page_element(struct nk_context *ctx) 11 | { 12 | struct nk_page_element *elem; 13 | if (ctx->freelist) { 14 | /* unlink page element from free list */ 15 | elem = ctx->freelist; 16 | ctx->freelist = elem->next; 17 | } else if (ctx->use_pool) { 18 | /* allocate page element from memory pool */ 19 | elem = nk_pool_alloc(&ctx->pool); 20 | NK_ASSERT(elem); 21 | if (!elem) return 0; 22 | } else { 23 | /* allocate new page element from back of fixed size memory buffer */ 24 | NK_STORAGE const nk_size size = sizeof(struct nk_page_element); 25 | NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_page_element); 26 | elem = (struct nk_page_element*)nk_buffer_alloc(&ctx->memory, NK_BUFFER_BACK, size, align); 27 | NK_ASSERT(elem); 28 | if (!elem) return 0; 29 | } 30 | nk_zero_struct(*elem); 31 | elem->next = 0; 32 | elem->prev = 0; 33 | return elem; 34 | } 35 | NK_LIB void 36 | nk_link_page_element_into_freelist(struct nk_context *ctx, 37 | struct nk_page_element *elem) 38 | { 39 | /* link table into freelist */ 40 | if (!ctx->freelist) { 41 | ctx->freelist = elem; 42 | } else { 43 | elem->next = ctx->freelist; 44 | ctx->freelist = elem; 45 | } 46 | } 47 | NK_LIB void 48 | nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem) 49 | { 50 | /* we have a pool so just add to free list */ 51 | if (ctx->use_pool) { 52 | nk_link_page_element_into_freelist(ctx, elem); 53 | return; 54 | } 55 | /* if possible remove last element from back of fixed memory buffer */ 56 | {void *elem_end = (void*)(elem + 1); 57 | void *buffer_end = (nk_byte*)ctx->memory.memory.ptr + ctx->memory.size; 58 | if (elem_end == buffer_end) 59 | ctx->memory.size -= sizeof(struct nk_page_element); 60 | else nk_link_page_element_into_freelist(ctx, elem);} 61 | } 62 | 63 | -------------------------------------------------------------------------------- /src/nuklear_pool.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* =============================================================== 5 | * 6 | * POOL 7 | * 8 | * ===============================================================*/ 9 | NK_LIB void 10 | nk_pool_init(struct nk_pool *pool, const struct nk_allocator *alloc, 11 | unsigned int capacity) 12 | { 13 | NK_ASSERT(capacity >= 1); 14 | nk_zero(pool, sizeof(*pool)); 15 | pool->alloc = *alloc; 16 | pool->capacity = capacity; 17 | pool->type = NK_BUFFER_DYNAMIC; 18 | pool->pages = 0; 19 | } 20 | NK_LIB void 21 | nk_pool_free(struct nk_pool *pool) 22 | { 23 | struct nk_page *iter; 24 | if (!pool) return; 25 | iter = pool->pages; 26 | if (pool->type == NK_BUFFER_FIXED) return; 27 | while (iter) { 28 | struct nk_page *next = iter->next; 29 | pool->alloc.free(pool->alloc.userdata, iter); 30 | iter = next; 31 | } 32 | } 33 | NK_LIB void 34 | nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size) 35 | { 36 | nk_zero(pool, sizeof(*pool)); 37 | NK_ASSERT(size >= sizeof(struct nk_page)); 38 | if (size < sizeof(struct nk_page)) return; 39 | /* first nk_page_element is embedded in nk_page, additional elements follow in adjacent space */ 40 | pool->capacity = (unsigned)(1 + (size - sizeof(struct nk_page)) / sizeof(struct nk_page_element)); 41 | pool->pages = (struct nk_page*)memory; 42 | pool->type = NK_BUFFER_FIXED; 43 | pool->size = size; 44 | } 45 | NK_LIB struct nk_page_element* 46 | nk_pool_alloc(struct nk_pool *pool) 47 | { 48 | if (!pool->pages || pool->pages->size >= pool->capacity) { 49 | /* allocate new page */ 50 | struct nk_page *page; 51 | if (pool->type == NK_BUFFER_FIXED) { 52 | NK_ASSERT(pool->pages); 53 | if (!pool->pages) return 0; 54 | NK_ASSERT(pool->pages->size < pool->capacity); 55 | return 0; 56 | } else { 57 | nk_size size = sizeof(struct nk_page); 58 | size += (pool->capacity - 1) * sizeof(struct nk_page_element); 59 | page = (struct nk_page*)pool->alloc.alloc(pool->alloc.userdata,0, size); 60 | page->next = pool->pages; 61 | pool->pages = page; 62 | page->size = 0; 63 | } 64 | } return &pool->pages->win[pool->pages->size++]; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/nuklear_progress.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* =============================================================== 5 | * 6 | * PROGRESS 7 | * 8 | * ===============================================================*/ 9 | NK_LIB nk_size 10 | nk_progress_behavior(nk_flags *state, struct nk_input *in, 11 | struct nk_rect r, struct nk_rect cursor, nk_size max, nk_size value, nk_bool modifiable) 12 | { 13 | int left_mouse_down = 0; 14 | int left_mouse_click_in_cursor = 0; 15 | 16 | nk_widget_state_reset(state); 17 | if (!in || !modifiable) return value; 18 | left_mouse_down = in && in->mouse.buttons[NK_BUTTON_LEFT].down; 19 | left_mouse_click_in_cursor = in && nk_input_has_mouse_click_down_in_rect(in, 20 | NK_BUTTON_LEFT, cursor, nk_true); 21 | if (nk_input_is_mouse_hovering_rect(in, r)) 22 | *state = NK_WIDGET_STATE_HOVERED; 23 | 24 | if (in && left_mouse_down && left_mouse_click_in_cursor) { 25 | if (left_mouse_down && left_mouse_click_in_cursor) { 26 | float ratio = NK_MAX(0, (float)(in->mouse.pos.x - cursor.x)) / (float)cursor.w; 27 | value = (nk_size)NK_CLAMP(0, (float)max * ratio, (float)max); 28 | in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = cursor.x + cursor.w/2.0f; 29 | *state |= NK_WIDGET_STATE_ACTIVE; 30 | } 31 | } 32 | /* set progressbar widget state */ 33 | if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, r)) 34 | *state |= NK_WIDGET_STATE_ENTERED; 35 | else if (nk_input_is_mouse_prev_hovering_rect(in, r)) 36 | *state |= NK_WIDGET_STATE_LEFT; 37 | return value; 38 | } 39 | NK_LIB void 40 | nk_draw_progress(struct nk_command_buffer *out, nk_flags state, 41 | const struct nk_style_progress *style, const struct nk_rect *bounds, 42 | const struct nk_rect *scursor, nk_size value, nk_size max) 43 | { 44 | const struct nk_style_item *background; 45 | const struct nk_style_item *cursor; 46 | 47 | NK_UNUSED(max); 48 | NK_UNUSED(value); 49 | 50 | /* select correct colors/images to draw */ 51 | if (state & NK_WIDGET_STATE_ACTIVED) { 52 | background = &style->active; 53 | cursor = &style->cursor_active; 54 | } else if (state & NK_WIDGET_STATE_HOVER){ 55 | background = &style->hover; 56 | cursor = &style->cursor_hover; 57 | } else { 58 | background = &style->normal; 59 | cursor = &style->cursor_normal; 60 | } 61 | 62 | /* draw background */ 63 | switch(background->type) { 64 | case NK_STYLE_ITEM_IMAGE: 65 | nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor)); 66 | break; 67 | case NK_STYLE_ITEM_NINE_SLICE: 68 | nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor)); 69 | break; 70 | case NK_STYLE_ITEM_COLOR: 71 | nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor)); 72 | nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); 73 | break; 74 | } 75 | 76 | /* draw cursor */ 77 | switch(cursor->type) { 78 | case NK_STYLE_ITEM_IMAGE: 79 | nk_draw_image(out, *scursor, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor)); 80 | break; 81 | case NK_STYLE_ITEM_NINE_SLICE: 82 | nk_draw_nine_slice(out, *scursor, &cursor->data.slice, nk_rgb_factor(nk_white, style->color_factor)); 83 | break; 84 | case NK_STYLE_ITEM_COLOR: 85 | nk_fill_rect(out, *scursor, style->rounding, nk_rgb_factor(cursor->data.color, style->color_factor)); 86 | nk_stroke_rect(out, *scursor, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor)); 87 | break; 88 | } 89 | } 90 | NK_LIB nk_size 91 | nk_do_progress(nk_flags *state, 92 | struct nk_command_buffer *out, struct nk_rect bounds, 93 | nk_size value, nk_size max, nk_bool modifiable, 94 | const struct nk_style_progress *style, struct nk_input *in) 95 | { 96 | float prog_scale; 97 | nk_size prog_value; 98 | struct nk_rect cursor; 99 | 100 | NK_ASSERT(style); 101 | NK_ASSERT(out); 102 | if (!out || !style) return 0; 103 | 104 | /* calculate progressbar cursor */ 105 | cursor.w = NK_MAX(bounds.w, 2 * style->padding.x + 2 * style->border); 106 | cursor.h = NK_MAX(bounds.h, 2 * style->padding.y + 2 * style->border); 107 | cursor = nk_pad_rect(bounds, nk_vec2(style->padding.x + style->border, style->padding.y + style->border)); 108 | prog_scale = (float)value / (float)max; 109 | 110 | /* update progressbar */ 111 | prog_value = NK_MIN(value, max); 112 | prog_value = nk_progress_behavior(state, in, bounds, cursor,max, prog_value, modifiable); 113 | cursor.w = cursor.w * prog_scale; 114 | 115 | /* draw progressbar */ 116 | if (style->draw_begin) style->draw_begin(out, style->userdata); 117 | nk_draw_progress(out, *state, style, &bounds, &cursor, value, max); 118 | if (style->draw_end) style->draw_end(out, style->userdata); 119 | return prog_value; 120 | } 121 | NK_API nk_bool 122 | nk_progress(struct nk_context *ctx, nk_size *cur, nk_size max, nk_bool is_modifyable) 123 | { 124 | struct nk_window *win; 125 | struct nk_panel *layout; 126 | const struct nk_style *style; 127 | struct nk_input *in; 128 | 129 | struct nk_rect bounds; 130 | enum nk_widget_layout_states state; 131 | nk_size old_value; 132 | 133 | NK_ASSERT(ctx); 134 | NK_ASSERT(cur); 135 | NK_ASSERT(ctx->current); 136 | NK_ASSERT(ctx->current->layout); 137 | if (!ctx || !ctx->current || !ctx->current->layout || !cur) 138 | return 0; 139 | 140 | win = ctx->current; 141 | style = &ctx->style; 142 | layout = win->layout; 143 | state = nk_widget(&bounds, ctx); 144 | if (!state) return 0; 145 | 146 | in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; 147 | old_value = *cur; 148 | *cur = nk_do_progress(&ctx->last_widget_state, &win->buffer, bounds, 149 | *cur, max, is_modifyable, &style->progress, in); 150 | return (*cur != old_value); 151 | } 152 | NK_API nk_size 153 | nk_prog(struct nk_context *ctx, nk_size cur, nk_size max, nk_bool modifyable) 154 | { 155 | nk_progress(ctx, &cur, max, modifyable); 156 | return cur; 157 | } 158 | 159 | -------------------------------------------------------------------------------- /src/nuklear_table.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* =============================================================== 5 | * 6 | * TABLE 7 | * 8 | * ===============================================================*/ 9 | NK_LIB struct nk_table* 10 | nk_create_table(struct nk_context *ctx) 11 | { 12 | struct nk_page_element *elem; 13 | elem = nk_create_page_element(ctx); 14 | if (!elem) return 0; 15 | nk_zero_struct(*elem); 16 | return &elem->data.tbl; 17 | } 18 | NK_LIB void 19 | nk_free_table(struct nk_context *ctx, struct nk_table *tbl) 20 | { 21 | union nk_page_data *pd = NK_CONTAINER_OF(tbl, union nk_page_data, tbl); 22 | struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data); 23 | nk_free_page_element(ctx, pe); 24 | } 25 | NK_LIB void 26 | nk_push_table(struct nk_window *win, struct nk_table *tbl) 27 | { 28 | if (!win->tables) { 29 | win->tables = tbl; 30 | tbl->next = 0; 31 | tbl->prev = 0; 32 | tbl->size = 0; 33 | win->table_count = 1; 34 | return; 35 | } 36 | win->tables->prev = tbl; 37 | tbl->next = win->tables; 38 | tbl->prev = 0; 39 | tbl->size = 0; 40 | win->tables = tbl; 41 | win->table_count++; 42 | } 43 | NK_LIB void 44 | nk_remove_table(struct nk_window *win, struct nk_table *tbl) 45 | { 46 | if (win->tables == tbl) 47 | win->tables = tbl->next; 48 | if (tbl->next) 49 | tbl->next->prev = tbl->prev; 50 | if (tbl->prev) 51 | tbl->prev->next = tbl->next; 52 | tbl->next = 0; 53 | tbl->prev = 0; 54 | } 55 | NK_LIB nk_uint* 56 | nk_add_value(struct nk_context *ctx, struct nk_window *win, 57 | nk_hash name, nk_uint value) 58 | { 59 | NK_ASSERT(ctx); 60 | NK_ASSERT(win); 61 | if (!win || !ctx) return 0; 62 | if (!win->tables || win->tables->size >= NK_VALUE_PAGE_CAPACITY) { 63 | struct nk_table *tbl = nk_create_table(ctx); 64 | NK_ASSERT(tbl); 65 | if (!tbl) return 0; 66 | nk_push_table(win, tbl); 67 | } 68 | win->tables->seq = win->seq; 69 | win->tables->keys[win->tables->size] = name; 70 | win->tables->values[win->tables->size] = value; 71 | return &win->tables->values[win->tables->size++]; 72 | } 73 | NK_LIB nk_uint* 74 | nk_find_value(const struct nk_window *win, nk_hash name) 75 | { 76 | struct nk_table *iter = win->tables; 77 | while (iter) { 78 | unsigned int i = 0; 79 | unsigned int size = iter->size; 80 | for (i = 0; i < size; ++i) { 81 | if (iter->keys[i] == name) { 82 | iter->seq = win->seq; 83 | return &iter->values[i]; 84 | } 85 | } size = NK_VALUE_PAGE_CAPACITY; 86 | iter = iter->next; 87 | } 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /src/nuklear_tooltip.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* =============================================================== 5 | * 6 | * TOOLTIP 7 | * 8 | * ===============================================================*/ 9 | NK_API nk_bool 10 | nk_tooltip_begin(struct nk_context *ctx, float width) 11 | { 12 | int x,y,w,h; 13 | struct nk_window *win; 14 | const struct nk_input *in; 15 | struct nk_rect bounds; 16 | int ret; 17 | 18 | NK_ASSERT(ctx); 19 | NK_ASSERT(ctx->current); 20 | NK_ASSERT(ctx->current->layout); 21 | if (!ctx || !ctx->current || !ctx->current->layout) 22 | return 0; 23 | 24 | /* make sure that no nonblocking popup is currently active */ 25 | win = ctx->current; 26 | in = &ctx->input; 27 | if (win->popup.win && ((int)win->popup.type & (int)NK_PANEL_SET_NONBLOCK)) 28 | return 0; 29 | 30 | w = nk_iceilf(width); 31 | h = nk_iceilf(nk_null_rect.h); 32 | x = nk_ifloorf(in->mouse.pos.x + 1) - (int)win->layout->clip.x; 33 | y = nk_ifloorf(in->mouse.pos.y + 1) - (int)win->layout->clip.y; 34 | 35 | bounds.x = (float)x; 36 | bounds.y = (float)y; 37 | bounds.w = (float)w; 38 | bounds.h = (float)h; 39 | 40 | ret = nk_popup_begin(ctx, NK_POPUP_DYNAMIC, 41 | "__##Tooltip##__", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER, bounds); 42 | if (ret) win->layout->flags &= ~(nk_flags)NK_WINDOW_ROM; 43 | win->popup.type = NK_PANEL_TOOLTIP; 44 | ctx->current->layout->type = NK_PANEL_TOOLTIP; 45 | return ret; 46 | } 47 | 48 | NK_API void 49 | nk_tooltip_end(struct nk_context *ctx) 50 | { 51 | NK_ASSERT(ctx); 52 | NK_ASSERT(ctx->current); 53 | if (!ctx || !ctx->current) return; 54 | ctx->current->seq--; 55 | nk_popup_close(ctx); 56 | nk_popup_end(ctx); 57 | } 58 | NK_API void 59 | nk_tooltip(struct nk_context *ctx, const char *text) 60 | { 61 | const struct nk_style *style; 62 | struct nk_vec2 padding; 63 | 64 | int text_len; 65 | float text_width; 66 | float text_height; 67 | 68 | NK_ASSERT(ctx); 69 | NK_ASSERT(ctx->current); 70 | NK_ASSERT(ctx->current->layout); 71 | NK_ASSERT(text); 72 | if (!ctx || !ctx->current || !ctx->current->layout || !text) 73 | return; 74 | 75 | /* fetch configuration data */ 76 | style = &ctx->style; 77 | padding = style->window.padding; 78 | 79 | /* calculate size of the text and tooltip */ 80 | text_len = nk_strlen(text); 81 | text_width = style->font->width(style->font->userdata, 82 | style->font->height, text, text_len); 83 | text_width += (4 * padding.x); 84 | text_height = (style->font->height + 2 * padding.y); 85 | 86 | /* execute tooltip and fill with text */ 87 | if (nk_tooltip_begin(ctx, (float)text_width)) { 88 | nk_layout_row_dynamic(ctx, (float)text_height, 1); 89 | nk_text(ctx, text, text_len, NK_TEXT_LEFT); 90 | nk_tooltip_end(ctx); 91 | } 92 | } 93 | #ifdef NK_INCLUDE_STANDARD_VARARGS 94 | NK_API void 95 | nk_tooltipf(struct nk_context *ctx, const char *fmt, ...) 96 | { 97 | va_list args; 98 | va_start(args, fmt); 99 | nk_tooltipfv(ctx, fmt, args); 100 | va_end(args); 101 | } 102 | NK_API void 103 | nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) 104 | { 105 | char buf[256]; 106 | nk_strfmt(buf, NK_LEN(buf), fmt, args); 107 | nk_tooltip(ctx, buf); 108 | } 109 | #endif 110 | 111 | 112 | -------------------------------------------------------------------------------- /src/nuklear_utf8.c: -------------------------------------------------------------------------------- 1 | #include "nuklear.h" 2 | #include "nuklear_internal.h" 3 | 4 | /* =============================================================== 5 | * 6 | * UTF-8 7 | * 8 | * ===============================================================*/ 9 | NK_GLOBAL const nk_byte nk_utfbyte[NK_UTF_SIZE+1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; 10 | NK_GLOBAL const nk_byte nk_utfmask[NK_UTF_SIZE+1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; 11 | NK_GLOBAL const nk_uint nk_utfmin[NK_UTF_SIZE+1] = {0, 0, 0x80, 0x800, 0x10000}; 12 | NK_GLOBAL const nk_uint nk_utfmax[NK_UTF_SIZE+1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; 13 | 14 | NK_INTERN int 15 | nk_utf_validate(nk_rune *u, int i) 16 | { 17 | NK_ASSERT(u); 18 | if (!u) return 0; 19 | if (!NK_BETWEEN(*u, nk_utfmin[i], nk_utfmax[i]) || 20 | NK_BETWEEN(*u, 0xD800, 0xDFFF)) 21 | *u = NK_UTF_INVALID; 22 | for (i = 1; *u > nk_utfmax[i]; ++i); 23 | return i; 24 | } 25 | NK_INTERN nk_rune 26 | nk_utf_decode_byte(char c, int *i) 27 | { 28 | NK_ASSERT(i); 29 | if (!i) return 0; 30 | for(*i = 0; *i < (int)NK_LEN(nk_utfmask); ++(*i)) { 31 | if (((nk_byte)c & nk_utfmask[*i]) == nk_utfbyte[*i]) 32 | return (nk_byte)(c & ~nk_utfmask[*i]); 33 | } 34 | return 0; 35 | } 36 | NK_API int 37 | nk_utf_decode(const char *c, nk_rune *u, int clen) 38 | { 39 | int i, j, len, type=0; 40 | nk_rune udecoded; 41 | 42 | NK_ASSERT(c); 43 | NK_ASSERT(u); 44 | 45 | if (!c || !u) return 0; 46 | if (!clen) return 0; 47 | *u = NK_UTF_INVALID; 48 | 49 | udecoded = nk_utf_decode_byte(c[0], &len); 50 | if (!NK_BETWEEN(len, 1, NK_UTF_SIZE)) 51 | return 1; 52 | 53 | for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { 54 | udecoded = (udecoded << 6) | nk_utf_decode_byte(c[i], &type); 55 | if (type != 0) 56 | return j; 57 | } 58 | if (j < len) 59 | return 0; 60 | *u = udecoded; 61 | nk_utf_validate(u, len); 62 | return len; 63 | } 64 | NK_INTERN char 65 | nk_utf_encode_byte(nk_rune u, int i) 66 | { 67 | return (char)((nk_utfbyte[i]) | ((nk_byte)u & ~nk_utfmask[i])); 68 | } 69 | NK_API int 70 | nk_utf_encode(nk_rune u, char *c, int clen) 71 | { 72 | int len, i; 73 | len = nk_utf_validate(&u, 0); 74 | if (clen < len || !len || len > NK_UTF_SIZE) 75 | return 0; 76 | 77 | for (i = len - 1; i != 0; --i) { 78 | c[i] = nk_utf_encode_byte(u, 0); 79 | u >>= 6; 80 | } 81 | c[0] = nk_utf_encode_byte(u, len); 82 | return len; 83 | } 84 | NK_API int 85 | nk_utf_len(const char *str, int len) 86 | { 87 | const char *text; 88 | int glyphs = 0; 89 | int text_len; 90 | int glyph_len; 91 | int src_len = 0; 92 | nk_rune unicode; 93 | 94 | NK_ASSERT(str); 95 | if (!str || !len) return 0; 96 | 97 | text = str; 98 | text_len = len; 99 | glyph_len = nk_utf_decode(text, &unicode, text_len); 100 | while (glyph_len && src_len < len) { 101 | glyphs++; 102 | src_len = src_len + glyph_len; 103 | glyph_len = nk_utf_decode(text + src_len, &unicode, text_len - src_len); 104 | } 105 | return glyphs; 106 | } 107 | NK_API const char* 108 | nk_utf_at(const char *buffer, int length, int index, 109 | nk_rune *unicode, int *len) 110 | { 111 | int i = 0; 112 | int src_len = 0; 113 | int glyph_len = 0; 114 | const char *text; 115 | int text_len; 116 | 117 | NK_ASSERT(buffer); 118 | NK_ASSERT(unicode); 119 | NK_ASSERT(len); 120 | 121 | if (!buffer || !unicode || !len) return 0; 122 | if (index < 0) { 123 | *unicode = NK_UTF_INVALID; 124 | *len = 0; 125 | return 0; 126 | } 127 | 128 | text = buffer; 129 | text_len = length; 130 | glyph_len = nk_utf_decode(text, unicode, text_len); 131 | while (glyph_len) { 132 | if (i == index) { 133 | *len = glyph_len; 134 | break; 135 | } 136 | 137 | i++; 138 | src_len = src_len + glyph_len; 139 | glyph_len = nk_utf_decode(text + src_len, unicode, text_len - src_len); 140 | } 141 | if (i != index) return 0; 142 | return buffer + src_len; 143 | } 144 | 145 | -------------------------------------------------------------------------------- /src/paq.bat: -------------------------------------------------------------------------------- 1 | build.py --macro NK --intro HEADER.md --pub nuklear.h --priv1 nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c --extern stb_rect_pack.h,stb_truetype.h --priv2 nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_9slice.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_knob.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS > ..\nuklear.h 2 | -------------------------------------------------------------------------------- /src/paq.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | python3 build.py --macro NK --intro HEADER.md --pub nuklear.h --priv1 nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c --extern stb_rect_pack.h,stb_truetype.h --priv2 nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_9slice.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_knob.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS > ../nuklear.h 3 | --------------------------------------------------------------------------------