├── .gitmodules ├── doc ├── build.sh ├── Makefile └── stddoc.c ├── example ├── icon │ ├── copy.png │ ├── edit.png │ ├── font.png │ ├── home.png │ ├── img.png │ ├── next.png │ ├── pen.png │ ├── play.png │ ├── prev.png │ ├── stop.png │ ├── text.png │ ├── wifi.png │ ├── checked.png │ ├── cloud.png │ ├── default.png │ ├── delete.png │ ├── desktop.png │ ├── export.png │ ├── movie.png │ ├── music.png │ ├── pause.png │ ├── phone.png │ ├── plane.png │ ├── rocket.png │ ├── tools.png │ ├── volume.png │ ├── computer.png │ ├── directory.png │ ├── settings.png │ └── unchecked.png ├── skins │ └── gwen.png ├── images │ ├── image1.png │ ├── image2.png │ ├── image3.png │ ├── image4.png │ ├── image5.png │ ├── image6.png │ ├── image7.png │ ├── image8.png │ └── image9.png └── Makefile ├── extra_font ├── DroidSans.ttf ├── ProggyClean.ttf ├── ProggyTiny.ttf ├── Roboto-Bold.ttf ├── Karla-Regular.ttf ├── Raleway-Bold.ttf ├── Roboto-Light.ttf ├── Roboto-Regular.ttf ├── Cousine-Regular.ttf ├── kenvector_future.ttf └── kenvector_future_thin.ttf ├── .gitattributes ├── .gitignore ├── package.json ├── demo ├── gdi │ ├── build.bat │ └── main.c ├── gdip │ ├── build.bat │ └── main.c ├── allegro5 │ ├── KeyboardHandleriOS.h │ ├── Makefile │ ├── Readme.md │ ├── KeyboardHandleriOS.m │ └── main.c ├── d3d9 │ ├── build.bat │ └── main.c ├── x11 │ ├── Makefile │ └── main.c ├── x11_rawfb │ ├── Makefile │ ├── main.c │ └── nuklear_xlib.h ├── x11_opengl2 │ └── Makefile ├── x11_opengl3 │ ├── Makefile │ └── main.c ├── sfml_opengl2 │ ├── Readme.md │ ├── Makefile │ └── main.cpp ├── sdl_opengles2 │ ├── Makefile │ └── main.c ├── sdl_opengl2 │ ├── Makefile │ ├── main.c │ └── nuklear_sdl_gl2.h ├── sdl_opengl3 │ ├── Makefile │ └── main.c ├── glfw_opengl2 │ ├── Makefile │ └── main.c ├── d3d11 │ ├── build.bat │ ├── nuklear_d3d11.hlsl │ ├── nuklear_d3d11_pixel_shader.h │ ├── main.c │ └── nuklear_d3d11_vertex_shader.h ├── glfw_opengl3 │ ├── Makefile │ └── main.c ├── sfml_opengl3 │ ├── Makefile │ └── main.cpp ├── calculator.c └── style.c ├── .travis.yml └── Readme.md /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cat ../nuklear.h|./doc > nuklear.html 3 | 4 | 5 | -------------------------------------------------------------------------------- /example/icon/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/copy.png -------------------------------------------------------------------------------- /example/icon/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/edit.png -------------------------------------------------------------------------------- /example/icon/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/font.png -------------------------------------------------------------------------------- /example/icon/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/home.png -------------------------------------------------------------------------------- /example/icon/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/img.png -------------------------------------------------------------------------------- /example/icon/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/next.png -------------------------------------------------------------------------------- /example/icon/pen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/pen.png -------------------------------------------------------------------------------- /example/icon/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/play.png -------------------------------------------------------------------------------- /example/icon/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/prev.png -------------------------------------------------------------------------------- /example/icon/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/stop.png -------------------------------------------------------------------------------- /example/icon/text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/text.png -------------------------------------------------------------------------------- /example/icon/wifi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/wifi.png -------------------------------------------------------------------------------- /example/icon/checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/checked.png -------------------------------------------------------------------------------- /example/icon/cloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/cloud.png -------------------------------------------------------------------------------- /example/icon/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/default.png -------------------------------------------------------------------------------- /example/icon/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/delete.png -------------------------------------------------------------------------------- /example/icon/desktop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/desktop.png -------------------------------------------------------------------------------- /example/icon/export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/export.png -------------------------------------------------------------------------------- /example/icon/movie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/movie.png -------------------------------------------------------------------------------- /example/icon/music.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/music.png -------------------------------------------------------------------------------- /example/icon/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/pause.png -------------------------------------------------------------------------------- /example/icon/phone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/phone.png -------------------------------------------------------------------------------- /example/icon/plane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/plane.png -------------------------------------------------------------------------------- /example/icon/rocket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/rocket.png -------------------------------------------------------------------------------- /example/icon/tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/tools.png -------------------------------------------------------------------------------- /example/icon/volume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/volume.png -------------------------------------------------------------------------------- /example/skins/gwen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/skins/gwen.png -------------------------------------------------------------------------------- /extra_font/DroidSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/DroidSans.ttf -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Github language settings 2 | *.h linguist-language=c 3 | *.c linguist-language=c 4 | -------------------------------------------------------------------------------- /example/icon/computer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/computer.png -------------------------------------------------------------------------------- /example/icon/directory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/directory.png -------------------------------------------------------------------------------- /example/icon/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/settings.png -------------------------------------------------------------------------------- /example/icon/unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/icon/unchecked.png -------------------------------------------------------------------------------- /example/images/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/images/image1.png -------------------------------------------------------------------------------- /example/images/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/images/image2.png -------------------------------------------------------------------------------- /example/images/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/images/image3.png -------------------------------------------------------------------------------- /example/images/image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/images/image4.png -------------------------------------------------------------------------------- /example/images/image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/images/image5.png -------------------------------------------------------------------------------- /example/images/image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/images/image6.png -------------------------------------------------------------------------------- /example/images/image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/images/image7.png -------------------------------------------------------------------------------- /example/images/image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/images/image8.png -------------------------------------------------------------------------------- /example/images/image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/example/images/image9.png -------------------------------------------------------------------------------- /extra_font/ProggyClean.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/ProggyClean.ttf -------------------------------------------------------------------------------- /extra_font/ProggyTiny.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/ProggyTiny.ttf -------------------------------------------------------------------------------- /extra_font/Roboto-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/Roboto-Bold.ttf -------------------------------------------------------------------------------- /extra_font/Karla-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/Karla-Regular.ttf -------------------------------------------------------------------------------- /extra_font/Raleway-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/Raleway-Bold.ttf -------------------------------------------------------------------------------- /extra_font/Roboto-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/Roboto-Light.ttf -------------------------------------------------------------------------------- /extra_font/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/Roboto-Regular.ttf -------------------------------------------------------------------------------- /extra_font/Cousine-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/Cousine-Regular.ttf -------------------------------------------------------------------------------- /extra_font/kenvector_future.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/kenvector_future.ttf -------------------------------------------------------------------------------- /extra_font/kenvector_future_thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/nuklear/master/extra_font/kenvector_future_thin.ttf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | demo/*/*.exe 2 | demo/*/*.obj 3 | demo/*/bin/* 4 | example/bin/* 5 | docs/xml 6 | docs/build 7 | docs/src 8 | *.tmp 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nuklear", 3 | "version": "1.0.0", 4 | "repo": "vurtun/nuklear", 5 | "description": "A small ANSI C gui toolkit", 6 | "keywords": ["gl", "ui", "toolkit"], 7 | "src": ["nuklear.h"] 8 | } 9 | -------------------------------------------------------------------------------- /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 /link /incremental:no 7 | -------------------------------------------------------------------------------- /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/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/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/x11/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = zahnrad 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -pedantic -O2 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_rawfb/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = zahnrad 3 | 4 | # Flags 5 | CFLAGS += -std=c89 -pedantic -O2 -Wunused -DRAWFB_XRGB_8888 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 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = doc 3 | 4 | # Flags 5 | CFLAGS += -std=c99 -pedantic -O2 6 | 7 | SRC = stddoc.c 8 | OBJ = $(SRC:.c=.o) 9 | 10 | ifeq ($(OS),Windows_NT) 11 | BIN := $(BIN).exe 12 | LIBS = 13 | else 14 | UNAME_S := $(shell uname -s) 15 | ifeq ($(UNAME_S),Darwin) 16 | LIBS = 17 | else 18 | LIBS = 19 | endif 20 | endif 21 | 22 | $(BIN): 23 | rm -f $(BIN) $(OBJS) 24 | $(CC) $(SRC) $(CFLAGS) -o $(BIN) 25 | -------------------------------------------------------------------------------- /demo/x11_opengl2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Compiler 5 | CC = clang 6 | DCC = gcc 7 | 8 | # Flags 9 | CFLAGS += -std=c99 -pedantic -O2 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=c99 -pedantic -O2 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 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | os: 4 | - linux 5 | 6 | compiler: 7 | - gcc 8 | - clang 9 | 10 | before_install: 11 | - if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:pyglfw/pyglfw && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libglew-dev; fi 12 | 13 | script: 14 | - make -C demo/glfw_opengl3 CFLAGS="-Wall -DINCLUDE_ALL" 15 | - make -C demo/glfw_opengl2 16 | - make -C example 17 | -------------------------------------------------------------------------------- /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 the udev development files. 10 | -------------------------------------------------------------------------------- /demo/sdl_opengles2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c99 -pedantic -O2 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 | prepare: 24 | @mkdir -p bin 25 | rm -f bin/$(BIN) $(OBJS) 26 | -------------------------------------------------------------------------------- /demo/allegro5/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c99 -pedantic -O2 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/sdl_opengl2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c99 -pedantic -O2 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=c99 -pedantic -O2 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/glfw_opengl2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c99 -pedantic -O2 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/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/glfw_opengl3/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | BIN = demo 3 | 4 | # Flags 5 | CFLAGS += -std=c99 -pedantic -O2 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/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/sfml_opengl2/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | CC = g++ 3 | BIN = demo 4 | 5 | # Flags 6 | CFLAGS += -s -O2 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-s -lsfml-system-s -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 | -------------------------------------------------------------------------------- /example/Makefile: -------------------------------------------------------------------------------- 1 | # Flags 2 | CFLAGS += -std=c99 -pedantic -O2 3 | LIBS := 4 | 5 | ifeq ($(OS),Windows_NT) 6 | BIN := $(BIN).exe 7 | LIBS := -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32 8 | else 9 | UNAME_S := $(shell uname -s) 10 | GLFW3 := $(shell pkg-config --libs glfw3) 11 | ifeq ($(UNAME_S),Darwin) 12 | LIBS := $(GLFW3) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib 13 | CFLAGS += -I/usr/local/include 14 | else 15 | LIBS := $(GLFW3) -lGL -lm -lGLU -lGLEW 16 | endif 17 | endif 18 | 19 | all: generate file_browser extended canvas skinning 20 | 21 | generate: clean 22 | ifeq ($(OS),Windows_NT) 23 | @mkdir bin 2> nul || exit 0 24 | else 25 | @mkdir -p bin 26 | endif 27 | 28 | clean: 29 | @rm -rf bin 30 | 31 | file_browser: generate 32 | $(CC) $(CFLAGS) -o bin/file_browser file_browser.c $(LIBS) 33 | 34 | extended: generate 35 | $(CC) $(CFLAGS) -o bin/extended extended.c $(LIBS) 36 | 37 | canvas: generate 38 | $(CC) $(CFLAGS) -o bin/canvas canvas.c $(LIBS) 39 | 40 | skinning: generate 41 | $(CC) $(CFLAGS) -o bin/skinning skinning.c $(LIBS) 42 | 43 | -------------------------------------------------------------------------------- /demo/sfml_opengl3/Makefile: -------------------------------------------------------------------------------- 1 | # Install 2 | CC = g++ 3 | BIN = demo 4 | 5 | # Flags 6 | CFLAGS += -s -O2 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/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/allegro5/Readme.md: -------------------------------------------------------------------------------- 1 | # Allegro v5 nuklear backend 2 | 3 | This backend provides support for [Allegro version 5](http://liballeg.org/). 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/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 | -------------------------------------------------------------------------------- /doc/stddoc.c: -------------------------------------------------------------------------------- 1 | /// ## About 2 | /// - _stddoc.c_ is a tiny documentation generator for 60 programming languages. 3 | /// - This page sample was auto-generated from the code comments found in `stddoc.c` file. 4 | /// 5 | /// ## How does it work? 6 | /// - Markdeep code comments are extracted from stdin and printed into stdout as a HTML file. 7 | /// 8 | /// ## Supported languages 9 | /// - `/// Three slashes comment` [ActionScript, AngelScript, C (C99), C#, C++, ChaiScript, D, 10 | /// GameMonkey, GML, Go, Java, JavaScript, JetScript, jtc, Jx9, Kotlin, Neko, Object Pascal (Delphi), 11 | /// Objective-C, Pawn, PHP, QuakeC, Rust, SASS, Scala, Squirrel, Swift, Vala, Wren, Xojo]. 12 | /// - `--- Three dashes comment` [Ada, AppleScript, Eiffel, Euphoria, Haskell, Lua, Occam, 13 | /// PL/SQL, PSL, SGML, SPARK, SQL, Terra, TSQL, VHDL]. 14 | /// - `### Three hashes comment` [AWK, Bash, Bourne shell, C shell, Cobra, Maple, Maple, 15 | /// Perl, Perl6, PowerShell, Python, R, Ruby, Seed7, Tcl]. 16 | /// 17 | /// ## Usage 18 | /// - `stddoc < source.code > documentation.html` 19 | /// 20 | /// ## Changelog 21 | /// 2018/01/07 22 | /// : Initial version (_v1.0.0_) 23 | /// 24 | /// ## License 25 | /// - rlyeh, unlicensed (~public domain). 26 | 27 | #include 28 | 29 | int main() { 30 | printf("%s\n", ""); 31 | printf("%s\n", ""); 32 | 33 | for( int fsm_S = 0, fsm_D = 0, fsm_H = 0; !feof(stdin); ) { 34 | int chr = getc(stdin); 35 | if( fsm_S > 3 || fsm_D > 3 || fsm_H > 3 ) { 36 | putc(chr, stdout); 37 | if( chr != '\r' && chr != '\n' ) continue; 38 | } 39 | /**/ if( fsm_S <= 2 && chr == '/' && !fsm_D && !fsm_H ) fsm_S++; 40 | else if( fsm_S == 3 && chr == ' ' && !fsm_D && !fsm_H ) fsm_S++; 41 | else if( fsm_D <= 2 && chr == '-' && !fsm_S && !fsm_H ) fsm_D++; 42 | else if( fsm_D == 3 && chr == ' ' && !fsm_S && !fsm_H ) fsm_D++; 43 | else if( fsm_H <= 2 && chr == '#' && !fsm_S && !fsm_D ) fsm_H++; 44 | else if( fsm_H == 3 && chr == ' ' && !fsm_S && !fsm_D ) fsm_H++; 45 | else fsm_S = fsm_D = fsm_H = 0; 46 | } 47 | 48 | printf("%s\n", ""); 49 | printf("%s\n", ""); 50 | } 51 | 52 | /// 53 | /// ## **Example page!** 54 | /// 55 | /// Imaginary documentation page. Here would be some introduction text. 56 | /// 57 | /// The table of contents that Markdeep produces is stuffed on the right side, 58 | /// if the browser window is wide enough. Otherwise it is hidden. 59 | /// 60 | /// ### Basic Markdeep 61 | /// 62 | /// Regular styling like **bold**, _italics_, ~~strikethrough~~, `inline code`, etc. Lists as: 63 | /// 64 | /// * A 65 | /// * Bullet 66 | /// * List 67 | /// 68 | /// And: 69 | /// 70 | /// 1. A 71 | /// 1. Numbered 72 | /// 1. List! 73 | /// 74 | /// Symbol substitutions: a 45-degree turn; som x -> y arrows; some whoa ==> fancy <==> arrows. 75 | /// 76 | /// Is this a definition list? 77 | /// : Looks like one to me 78 | /// Is that right? 79 | /// : Possibly! 80 | /// 81 | /// And a code listing: 82 | /// 83 | /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 84 | /// int main() 85 | /// { 86 | /// return 1; 87 | /// } 88 | /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 89 | /// 90 | /// 91 | /// ### Tables 92 | /// 93 | /// Thing Name | Description |Notes 94 | /// ------------------------|--------------------|----- 95 | /// Yes | Yup! | 96 | /// No | Nope :( | 97 | /// FileNotFound | Doesn't find files | Pass `-sFIND_FILE=maybe` to maybe find them 98 | /// 99 | /// 100 | /// ### Diagrams 101 | /// 102 | /// ******************************************* Here's a text to the right of the diagram, 103 | /// * +-----------------+ .-. * ain't that fancy. Pretty fancy indeed, I 104 | /// * |\ | .-+ | * must say! Markdeep diagrams are generally 105 | /// * | \ A-B *---+--> .--+ '--. * enclosed into a rectangle full made of `*` 106 | /// * | \ | | Cloud! | * symbols; and are "drawn" using ASCII-art 107 | /// * +---+-------------+ '-------------' * style, with `- | + / \ * o` etc. 108 | /// ******************************************* Suh-weet! 109 | /// 110 | /// Another random diagram, just because: 111 | /// 112 | /// ******************** 113 | /// * +-+-+-+-*-o * 114 | /// * / / ^ / * 115 | /// * / v / / * 116 | /// * +-+-+-+ * 117 | /// ******************** 118 | /// 119 | /// ### Special notes 120 | /// 121 | /// !!! Note 122 | /// Hey I'm a note. Don't mind me, I'm just sitting here. 123 | /// 124 | /// !!! WARNING 125 | /// I'm a warning, perhaps. *Something might happen!* 126 | /// 127 | /// !!! Error: Never Pass `nullptr` to a Shader 128 | /// Invoking a shader with a null argument can seg fault. 129 | /// This is a multi-line admonition. 130 | /// 131 | /// Seriously, don't call shaders like that. 132 | /// 133 | /// ### Embedding HTML 134 | /// 135 | ///
136 | /// This is an embedded html node by the way!
137 | /// 
138 | /// 139 | /// ## Credits 140 | /// - API doc style created by [Aras Pranckevičius](https://github.com/aras-p) 141 | /// - Markdeep by [Morgan McGuire](https://casual-effects.com/markdeep/). 142 | -------------------------------------------------------------------------------- /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_OVERVIEW */ 32 | /*#define INCLUDE_NODE_EDITOR */ 33 | 34 | #ifdef INCLUDE_ALL 35 | #define INCLUDE_STYLE 36 | #define INCLUDE_CALCULATOR 37 | #define INCLUDE_OVERVIEW 38 | #define INCLUDE_NODE_EDITOR 39 | #endif 40 | 41 | #ifdef INCLUDE_STYLE 42 | #include "../style.c" 43 | #endif 44 | #ifdef INCLUDE_CALCULATOR 45 | #include "../calculator.c" 46 | #endif 47 | #ifdef INCLUDE_OVERVIEW 48 | #include "../overview.c" 49 | #endif 50 | #ifdef INCLUDE_NODE_EDITOR 51 | #include "../node_editor.c" 52 | #endif 53 | 54 | /* =============================================================== 55 | * 56 | * DEMO 57 | * 58 | * ===============================================================*/ 59 | static LRESULT CALLBACK 60 | WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) 61 | { 62 | switch (msg) { 63 | case WM_DESTROY: 64 | PostQuitMessage(0); 65 | return 0; 66 | } 67 | if (nk_gdip_handle_event(wnd, msg, wparam, lparam)) 68 | return 0; 69 | return DefWindowProcW(wnd, msg, wparam, lparam); 70 | } 71 | 72 | int main(void) 73 | { 74 | GdipFont* font; 75 | struct nk_context *ctx; 76 | 77 | WNDCLASSW wc; 78 | RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT }; 79 | DWORD style = WS_OVERLAPPEDWINDOW; 80 | DWORD exstyle = WS_EX_APPWINDOW; 81 | HWND wnd; 82 | int running = 1; 83 | int needs_refresh = 1; 84 | 85 | /* Win32 */ 86 | memset(&wc, 0, sizeof(wc)); 87 | wc.style = CS_DBLCLKS; 88 | wc.lpfnWndProc = WindowProc; 89 | wc.hInstance = GetModuleHandleW(0); 90 | wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 91 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 92 | wc.lpszClassName = L"NuklearWindowClass"; 93 | RegisterClassW(&wc); 94 | 95 | AdjustWindowRectEx(&rect, style, FALSE, exstyle); 96 | 97 | wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo", 98 | style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 99 | rect.right - rect.left, rect.bottom - rect.top, 100 | NULL, NULL, wc.hInstance, NULL); 101 | 102 | /* GUI */ 103 | ctx = nk_gdip_init(wnd, WINDOW_WIDTH, WINDOW_HEIGHT); 104 | font = nk_gdipfont_create("Arial", 12); 105 | nk_gdip_set_font(font); 106 | 107 | /* style.c */ 108 | #ifdef INCLUDE_STYLE 109 | /*set_style(ctx, THEME_WHITE);*/ 110 | /*set_style(ctx, THEME_RED);*/ 111 | /*set_style(ctx, THEME_BLUE);*/ 112 | /*set_style(ctx, THEME_DARK);*/ 113 | #endif 114 | 115 | while (running) 116 | { 117 | /* Input */ 118 | MSG msg; 119 | nk_input_begin(ctx); 120 | if (needs_refresh == 0) { 121 | if (GetMessageW(&msg, NULL, 0, 0) <= 0) 122 | running = 0; 123 | else { 124 | TranslateMessage(&msg); 125 | DispatchMessageW(&msg); 126 | } 127 | needs_refresh = 1; 128 | } else needs_refresh = 0; 129 | while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { 130 | if (msg.message == WM_QUIT) 131 | running = 0; 132 | TranslateMessage(&msg); 133 | DispatchMessageW(&msg); 134 | needs_refresh = 1; 135 | } 136 | nk_input_end(ctx); 137 | 138 | /* GUI */ 139 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 140 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 141 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 142 | { 143 | enum {EASY, HARD}; 144 | static int op = EASY; 145 | static int property = 20; 146 | 147 | nk_layout_row_static(ctx, 30, 80, 1); 148 | if (nk_button_label(ctx, "button")) 149 | fprintf(stdout, "button pressed\n"); 150 | nk_layout_row_dynamic(ctx, 30, 2); 151 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 152 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 153 | nk_layout_row_dynamic(ctx, 22, 1); 154 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 155 | } 156 | nk_end(ctx); 157 | 158 | /* -------------- EXAMPLES ---------------- */ 159 | #ifdef INCLUDE_CALCULATOR 160 | calculator(ctx); 161 | #endif 162 | #ifdef INCLUDE_OVERVIEW 163 | overview(ctx); 164 | #endif 165 | #ifdef INCLUDE_NODE_EDITOR 166 | node_editor(ctx); 167 | #endif 168 | /* ----------------------------------------- */ 169 | 170 | /* Draw */ 171 | nk_gdip_render(NK_ANTI_ALIASING_ON, nk_rgb(30,30,30)); 172 | } 173 | 174 | nk_gdipfont_del(font); 175 | nk_gdip_shutdown(); 176 | UnregisterClassW(wc.lpszClassName, wc.hInstance); 177 | return 0; 178 | } 179 | -------------------------------------------------------------------------------- /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_OVERVIEW */ 32 | /*#define INCLUDE_NODE_EDITOR */ 33 | 34 | #ifdef INCLUDE_ALL 35 | #define INCLUDE_STYLE 36 | #define INCLUDE_CALCULATOR 37 | #define INCLUDE_OVERVIEW 38 | #define INCLUDE_NODE_EDITOR 39 | #endif 40 | 41 | #ifdef INCLUDE_STYLE 42 | #include "../style.c" 43 | #endif 44 | #ifdef INCLUDE_CALCULATOR 45 | #include "../calculator.c" 46 | #endif 47 | #ifdef INCLUDE_OVERVIEW 48 | #include "../overview.c" 49 | #endif 50 | #ifdef INCLUDE_NODE_EDITOR 51 | #include "../node_editor.c" 52 | #endif 53 | 54 | /* =============================================================== 55 | * 56 | * DEMO 57 | * 58 | * ===============================================================*/ 59 | static LRESULT CALLBACK 60 | WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) 61 | { 62 | switch (msg) 63 | { 64 | case WM_DESTROY: 65 | PostQuitMessage(0); 66 | return 0; 67 | } 68 | 69 | if (nk_gdi_handle_event(wnd, msg, wparam, lparam)) 70 | return 0; 71 | 72 | return DefWindowProcW(wnd, msg, wparam, lparam); 73 | } 74 | 75 | int main(void) 76 | { 77 | GdiFont* font; 78 | struct nk_context *ctx; 79 | 80 | WNDCLASSW wc; 81 | ATOM atom; 82 | RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT }; 83 | DWORD style = WS_OVERLAPPEDWINDOW; 84 | DWORD exstyle = WS_EX_APPWINDOW; 85 | HWND wnd; 86 | HDC dc; 87 | int running = 1; 88 | int needs_refresh = 1; 89 | 90 | /* Win32 */ 91 | memset(&wc, 0, sizeof(wc)); 92 | wc.style = CS_DBLCLKS; 93 | wc.lpfnWndProc = WindowProc; 94 | wc.hInstance = GetModuleHandleW(0); 95 | wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 96 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 97 | wc.lpszClassName = L"NuklearWindowClass"; 98 | atom = RegisterClassW(&wc); 99 | 100 | AdjustWindowRectEx(&rect, style, FALSE, exstyle); 101 | wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo", 102 | style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 103 | rect.right - rect.left, rect.bottom - rect.top, 104 | NULL, NULL, wc.hInstance, NULL); 105 | dc = GetDC(wnd); 106 | 107 | /* GUI */ 108 | font = nk_gdifont_create("Arial", 14); 109 | ctx = nk_gdi_init(font, dc, WINDOW_WIDTH, WINDOW_HEIGHT); 110 | 111 | /* style.c */ 112 | #ifdef INCLUDE_STYLE 113 | /*set_style(ctx, THEME_WHITE);*/ 114 | /*set_style(ctx, THEME_RED);*/ 115 | /*set_style(ctx, THEME_BLUE);*/ 116 | /*set_style(ctx, THEME_DARK);*/ 117 | #endif 118 | 119 | while (running) 120 | { 121 | /* Input */ 122 | MSG msg; 123 | nk_input_begin(ctx); 124 | if (needs_refresh == 0) { 125 | if (GetMessageW(&msg, NULL, 0, 0) <= 0) 126 | running = 0; 127 | else { 128 | TranslateMessage(&msg); 129 | DispatchMessageW(&msg); 130 | } 131 | needs_refresh = 1; 132 | } else needs_refresh = 0; 133 | 134 | while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { 135 | if (msg.message == WM_QUIT) 136 | running = 0; 137 | TranslateMessage(&msg); 138 | DispatchMessageW(&msg); 139 | needs_refresh = 1; 140 | } 141 | nk_input_end(ctx); 142 | 143 | /* GUI */ 144 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 145 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 146 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 147 | { 148 | enum {EASY, HARD}; 149 | static int op = EASY; 150 | static int property = 20; 151 | 152 | nk_layout_row_static(ctx, 30, 80, 1); 153 | if (nk_button_label(ctx, "button")) 154 | fprintf(stdout, "button pressed\n"); 155 | nk_layout_row_dynamic(ctx, 30, 2); 156 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 157 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 158 | nk_layout_row_dynamic(ctx, 22, 1); 159 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 160 | } 161 | nk_end(ctx); 162 | 163 | /* -------------- EXAMPLES ---------------- */ 164 | #ifdef INCLUDE_CALCULATOR 165 | calculator(ctx); 166 | #endif 167 | #ifdef INCLUDE_OVERVIEW 168 | overview(ctx); 169 | #endif 170 | #ifdef INCLUDE_NODE_EDITOR 171 | node_editor(ctx); 172 | #endif 173 | /* ----------------------------------------- */ 174 | 175 | /* Draw */ 176 | nk_gdi_render(nk_rgb(30,30,30)); 177 | } 178 | 179 | nk_gdifont_del(font); 180 | ReleaseDC(wnd, dc); 181 | UnregisterClassW(wc.lpszClassName, wc.hInstance); 182 | return 0; 183 | } 184 | 185 | -------------------------------------------------------------------------------- /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 | #include 12 | 13 | #include 14 | 15 | #define WINDOW_WIDTH 1200 16 | #define WINDOW_HEIGHT 800 17 | 18 | #define NK_INCLUDE_FIXED_TYPES 19 | #define NK_INCLUDE_STANDARD_IO 20 | #define NK_INCLUDE_STANDARD_VARARGS 21 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 22 | #define NK_IMPLEMENTATION 23 | #define NK_ALLEGRO5_IMPLEMENTATION 24 | #include "../../nuklear.h" 25 | #include "nuklear_allegro5.h" 26 | 27 | 28 | #define UNUSED(a) (void)a 29 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 30 | #define MAX(a,b) ((a) < (b) ? (b) : (a)) 31 | #define LEN(a) (sizeof(a)/sizeof(a)[0]) 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 include 40 | * and the corresponding function. */ 41 | /*#include "../style.c"*/ 42 | /*#include "../calculator.c"*/ 43 | #include "../overview.c" 44 | /*#include "../node_editor.c"*/ 45 | 46 | /* =============================================================== 47 | * 48 | * DEMO 49 | * 50 | * ===============================================================*/ 51 | static void error_callback(int e, const char *d) 52 | {printf("Error %d: %s\n", e, d);} 53 | 54 | int main(void) 55 | { 56 | /* Platform */ 57 | ALLEGRO_DISPLAY *display = NULL; 58 | ALLEGRO_EVENT_QUEUE *event_queue = NULL; 59 | 60 | if (!al_init()) { 61 | fprintf(stdout, "failed to initialize allegro5!\n"); 62 | exit(1); 63 | } 64 | 65 | al_install_mouse(); 66 | al_set_mouse_wheel_precision(150); 67 | al_install_keyboard(); 68 | 69 | al_set_new_display_flags(ALLEGRO_WINDOWED|ALLEGRO_RESIZABLE|ALLEGRO_OPENGL); 70 | al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); 71 | al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST); 72 | display = al_create_display(WINDOW_WIDTH, WINDOW_HEIGHT); 73 | if (!display) { 74 | fprintf(stdout, "failed to create display!\n"); 75 | exit(1); 76 | } 77 | 78 | event_queue = al_create_event_queue(); 79 | if (!event_queue) { 80 | fprintf(stdout, "failed to create event_queue!\n"); 81 | al_destroy_display(display); 82 | exit(1); 83 | } 84 | 85 | al_register_event_source(event_queue, al_get_display_event_source(display)); 86 | al_register_event_source(event_queue, al_get_mouse_event_source()); 87 | al_register_event_source(event_queue, al_get_keyboard_event_source()); 88 | 89 | NkAllegro5Font *font; 90 | font = nk_allegro5_font_create_from_file("../../../extra_font/Roboto-Regular.ttf", 12, 0); 91 | struct nk_context *ctx; 92 | 93 | ctx = nk_allegro5_init(font, display, WINDOW_WIDTH, WINDOW_HEIGHT); 94 | 95 | /* style.c */ 96 | /*set_style(ctx, THEME_WHITE);*/ 97 | /*set_style(ctx, THEME_RED);*/ 98 | /*set_style(ctx, THEME_BLUE);*/ 99 | /*set_style(ctx, THEME_DARK);*/ 100 | 101 | while(1) 102 | { 103 | ALLEGRO_EVENT ev; 104 | ALLEGRO_TIMEOUT timeout; 105 | al_init_timeout(&timeout, 0.06); 106 | 107 | bool get_event = al_wait_for_event_until(event_queue, &ev, &timeout); 108 | 109 | if (get_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 110 | break; 111 | } 112 | 113 | /* Very Important: Always do nk_input_begin / nk_input_end even if 114 | there are no events, otherwise internal nuklear state gets messed up */ 115 | nk_input_begin(ctx); 116 | if (get_event) { 117 | while (get_event) { 118 | nk_allegro5_handle_event(&ev); 119 | get_event = al_get_next_event(event_queue, &ev); 120 | } 121 | } 122 | nk_input_end(ctx); 123 | 124 | /* GUI */ 125 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 126 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 127 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 128 | { 129 | enum {EASY, HARD}; 130 | static int op = EASY; 131 | static int property = 20; 132 | 133 | nk_layout_row_static(ctx, 30, 80, 1); 134 | if (nk_button_label(ctx, "button")) 135 | fprintf(stdout, "button pressed\n"); 136 | nk_layout_row_dynamic(ctx, 30, 2); 137 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 138 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 139 | nk_layout_row_dynamic(ctx, 22, 1); 140 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 141 | } 142 | nk_end(ctx); 143 | 144 | /* -------------- EXAMPLES ---------------- */ 145 | /*calculator(ctx);*/ 146 | overview(ctx); 147 | /*node_editor(ctx);*/ 148 | /* ----------------------------------------- */ 149 | 150 | /* Draw */ 151 | al_clear_to_color(al_map_rgb(19, 43, 81)); 152 | /* IMPORTANT: `nk_allegro5_render` changes the target backbuffer 153 | to the display set at initialization and does not restore it. 154 | Change it if you want to draw somewhere else. */ 155 | nk_allegro5_render(); 156 | al_flip_display(); 157 | } 158 | 159 | nk_allegro5_font_del(font); 160 | nk_allegro5_shutdown(); 161 | al_destroy_display(display); 162 | al_destroy_event_queue(event_queue); 163 | return 0; 164 | } 165 | 166 | -------------------------------------------------------------------------------- /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/glfw_opengl2/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 | #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_GLFW_GL2_IMPLEMENTATION 24 | #include "../../nuklear.h" 25 | #include "nuklear_glfw_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_OVERVIEW */ 41 | /*#define INCLUDE_NODE_EDITOR */ 42 | 43 | #ifdef INCLUDE_ALL 44 | #define INCLUDE_STYLE 45 | #define INCLUDE_CALCULATOR 46 | #define INCLUDE_OVERVIEW 47 | #define INCLUDE_NODE_EDITOR 48 | #endif 49 | 50 | #ifdef INCLUDE_STYLE 51 | #include "../style.c" 52 | #endif 53 | #ifdef INCLUDE_CALCULATOR 54 | #include "../calculator.c" 55 | #endif 56 | #ifdef INCLUDE_OVERVIEW 57 | #include "../overview.c" 58 | #endif 59 | #ifdef INCLUDE_NODE_EDITOR 60 | #include "../node_editor.c" 61 | #endif 62 | 63 | /* =============================================================== 64 | * 65 | * DEMO 66 | * 67 | * ===============================================================*/ 68 | static void error_callback(int e, const char *d) 69 | {printf("Error %d: %s\n", e, d);} 70 | 71 | int main(void) 72 | { 73 | /* Platform */ 74 | static GLFWwindow *win; 75 | int width = 0, height = 0; 76 | struct nk_context *ctx; 77 | struct nk_colorf bg; 78 | 79 | /* GLFW */ 80 | glfwSetErrorCallback(error_callback); 81 | if (!glfwInit()) { 82 | fprintf(stdout, "[GFLW] failed to init!\n"); 83 | exit(1); 84 | } 85 | win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL); 86 | glfwMakeContextCurrent(win); 87 | glfwGetWindowSize(win, &width, &height); 88 | 89 | /* GUI */ 90 | ctx = nk_glfw3_init(win, NK_GLFW3_INSTALL_CALLBACKS); 91 | /* Load Fonts: if none of these are loaded a default font will be used */ 92 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 93 | {struct nk_font_atlas *atlas; 94 | nk_glfw3_font_stash_begin(&atlas); 95 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 96 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ 97 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 98 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 99 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 100 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 101 | nk_glfw3_font_stash_end(); 102 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 103 | /*nk_style_set_font(ctx, &droid->handle);*/} 104 | 105 | #ifdef INCLUDE_STYLE 106 | /*set_style(ctx, THEME_WHITE);*/ 107 | /*set_style(ctx, THEME_RED);*/ 108 | /*set_style(ctx, THEME_BLUE);*/ 109 | /*set_style(ctx, THEME_DARK);*/ 110 | #endif 111 | 112 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 113 | while (!glfwWindowShouldClose(win)) 114 | { 115 | /* Input */ 116 | glfwPollEvents(); 117 | nk_glfw3_new_frame(); 118 | 119 | /* GUI */ 120 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 121 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 122 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 123 | { 124 | enum {EASY, HARD}; 125 | static int op = EASY; 126 | static int property = 20; 127 | nk_layout_row_static(ctx, 30, 80, 1); 128 | if (nk_button_label(ctx, "button")) 129 | fprintf(stdout, "button pressed\n"); 130 | 131 | nk_layout_row_dynamic(ctx, 30, 2); 132 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 133 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 134 | 135 | nk_layout_row_dynamic(ctx, 25, 1); 136 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 137 | 138 | nk_layout_row_dynamic(ctx, 20, 1); 139 | nk_label(ctx, "background:", NK_TEXT_LEFT); 140 | nk_layout_row_dynamic(ctx, 25, 1); 141 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 142 | nk_layout_row_dynamic(ctx, 120, 1); 143 | bg = nk_color_picker(ctx, bg, NK_RGBA); 144 | nk_layout_row_dynamic(ctx, 25, 1); 145 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 146 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 147 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 148 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 149 | nk_combo_end(ctx); 150 | } 151 | } 152 | nk_end(ctx); 153 | 154 | /* -------------- EXAMPLES ---------------- */ 155 | #ifdef INCLUDE_CALCULATOR 156 | calculator(ctx); 157 | #endif 158 | #ifdef INCLUDE_OVERVIEW 159 | overview(ctx); 160 | #endif 161 | #ifdef INCLUDE_NODE_EDITOR 162 | node_editor(ctx); 163 | #endif 164 | /* ----------------------------------------- */ 165 | 166 | /* Draw */ 167 | glfwGetWindowSize(win, &width, &height); 168 | glViewport(0, 0, width, height); 169 | glClear(GL_COLOR_BUFFER_BIT); 170 | glClearColor(bg.r, bg.g, bg.b, bg.a); 171 | /* IMPORTANT: `nk_glfw_render` modifies some global OpenGL state 172 | * with blending, scissor, face culling and depth test and defaults everything 173 | * back into a default state. Make sure to either save and restore or 174 | * reset your own state after drawing rendering the UI. */ 175 | nk_glfw3_render(NK_ANTI_ALIASING_ON); 176 | glfwSwapBuffers(win); 177 | } 178 | nk_glfw3_shutdown(); 179 | glfwTerminate(); 180 | return 0; 181 | } 182 | 183 | -------------------------------------------------------------------------------- /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 | #include 12 | 13 | #include 14 | #include 15 | 16 | #define NK_INCLUDE_FIXED_TYPES 17 | #define NK_INCLUDE_STANDARD_IO 18 | #define NK_INCLUDE_STANDARD_VARARGS 19 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 20 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 21 | #define NK_INCLUDE_FONT_BAKING 22 | #define NK_INCLUDE_DEFAULT_FONT 23 | #define NK_IMPLEMENTATION 24 | #define NK_SFML_GL2_IMPLEMENTATION 25 | #include "../../nuklear.h" 26 | #include "nuklear_sfml_gl2.h" 27 | 28 | #define WINDOW_WIDTH 1200 29 | #define WINDOW_HEIGHT 800 30 | 31 | /* =============================================================== 32 | * 33 | * EXAMPLE 34 | * 35 | * ===============================================================*/ 36 | /* This are some code examples to provide a small overview of what can be 37 | * done with this library. To try out an example uncomment the defines */ 38 | /*#define INCLUDE_ALL */ 39 | /*#define INCLUDE_STYLE */ 40 | /*#define INCLUDE_CALCULATOR */ 41 | /*#define INCLUDE_OVERVIEW */ 42 | /*#define INCLUDE_NODE_EDITOR */ 43 | 44 | #ifdef INCLUDE_ALL 45 | #define INCLUDE_STYLE 46 | #define INCLUDE_CALCULATOR 47 | #define INCLUDE_OVERVIEW 48 | #define INCLUDE_NODE_EDITOR 49 | #endif 50 | 51 | #ifdef INCLUDE_STYLE 52 | #include "../style.c" 53 | #endif 54 | #ifdef INCLUDE_CALCULATOR 55 | #include "../calculator.c" 56 | #endif 57 | #ifdef INCLUDE_OVERVIEW 58 | #include "../overview.c" 59 | #endif 60 | #ifdef INCLUDE_NODE_EDITOR 61 | #include "../node_editor.c" 62 | #endif 63 | 64 | /* =============================================================== 65 | * 66 | * DEMO 67 | * 68 | * ===============================================================*/ 69 | int main(void) 70 | { 71 | /* Platform */ 72 | sf::ContextSettings settings(24, 8, 4, 2, 2); 73 | sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings); 74 | win.setVerticalSyncEnabled(true); 75 | win.setActive(true); 76 | glViewport(0, 0, win.getSize().x, win.getSize().y); 77 | 78 | /* GUI */ 79 | struct nk_context *ctx; 80 | ctx = nk_sfml_init(&win); 81 | /* Load Fonts: if none of these are loaded a default font will be used */ 82 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 83 | struct nk_font_atlas *atlas; 84 | nk_sfml_font_stash_begin(&atlas); 85 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 86 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ 87 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 88 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 89 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 90 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 91 | nk_sfml_font_stash_end(); 92 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 93 | /*nk_style_set_font(ctx, &droid->handle);*/ 94 | 95 | /* style.c */ 96 | #ifdef INCLUDE_STYLE 97 | /*set_style(ctx, THEME_WHITE);*/ 98 | /*set_style(ctx, THEME_RED);*/ 99 | /*set_style(ctx, THEME_BLUE);*/ 100 | /*set_style(ctx, THEME_DARK);*/ 101 | #endif 102 | 103 | struct nk_colorf bg; 104 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 105 | while (win.isOpen()) 106 | { 107 | /* Input */ 108 | sf::Event evt; 109 | nk_input_begin(ctx); 110 | while(win.pollEvent(evt)) { 111 | if(evt.type == sf::Event::Closed) 112 | win.close(); 113 | else if(evt.type == sf::Event::Resized) 114 | glViewport(0, 0, evt.size.width, evt.size.height); 115 | nk_sfml_handle_event(&evt); 116 | } 117 | nk_input_end(ctx); 118 | 119 | /* GUI */ 120 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 121 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 122 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 123 | { 124 | enum {EASY, HARD}; 125 | static int op = EASY; 126 | static int property = 20; 127 | nk_layout_row_static(ctx, 30, 80, 1); 128 | if (nk_button_label(ctx, "button")) 129 | fprintf(stdout, "button pressed\n"); 130 | 131 | nk_layout_row_dynamic(ctx, 30, 2); 132 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 133 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 134 | 135 | nk_layout_row_dynamic(ctx, 25, 1); 136 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 137 | 138 | nk_layout_row_dynamic(ctx, 20, 1); 139 | nk_label(ctx, "background:", NK_TEXT_LEFT); 140 | nk_layout_row_dynamic(ctx, 25, 1); 141 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 142 | nk_layout_row_dynamic(ctx, 120, 1); 143 | bg = nk_color_picker(ctx, bg, NK_RGBA); 144 | nk_layout_row_dynamic(ctx, 25, 1); 145 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 146 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 147 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 148 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 149 | nk_combo_end(ctx); 150 | } 151 | } 152 | nk_end(ctx); 153 | 154 | /* -------------- EXAMPLES ---------------- */ 155 | #ifdef INCLUDE_CALCULATOR 156 | calculator(ctx); 157 | #endif 158 | #ifdef INCLUDE_OVERVIEW 159 | overview(ctx); 160 | #endif 161 | #ifdef INCLUDE_NODE_EDITOR 162 | node_editor(ctx); 163 | #endif 164 | /* ----------------------------------------- */ 165 | 166 | /* Draw */ 167 | win.setActive(true); 168 | nk_color_fv(bg, background); 169 | glClear(GL_COLOR_BUFFER_BIT); 170 | glClearColor(bg.r, bg.g, bg.b, bg.a); 171 | /* IMPORTANT: `nk_sfml_render` modifies some global OpenGL state 172 | * with blending, scissor, face culling and depth test and defaults everything 173 | * back into a default state. Make sure to either save and restore or 174 | * reset your own state after drawing rendering the UI. */ 175 | nk_sfml_render(NK_ANTI_ALIASING_ON); 176 | win.display(); 177 | } 178 | nk_sfml_shutdown(); 179 | return 0; 180 | } 181 | 182 | -------------------------------------------------------------------------------- /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_OVERVIEW */ 83 | /*#define INCLUDE_NODE_EDITOR */ 84 | 85 | #ifdef INCLUDE_ALL 86 | #define INCLUDE_STYLE 87 | #define INCLUDE_CALCULATOR 88 | #define INCLUDE_OVERVIEW 89 | #define INCLUDE_NODE_EDITOR 90 | #endif 91 | 92 | #ifdef INCLUDE_STYLE 93 | #include "../style.c" 94 | #endif 95 | #ifdef INCLUDE_CALCULATOR 96 | #include "../calculator.c" 97 | #endif 98 | #ifdef INCLUDE_OVERVIEW 99 | #include "../overview.c" 100 | #endif 101 | #ifdef INCLUDE_NODE_EDITOR 102 | #include "../node_editor.c" 103 | #endif 104 | 105 | /* =============================================================== 106 | * 107 | * DEMO 108 | * 109 | * ===============================================================*/ 110 | int 111 | main(void) 112 | { 113 | long dt; 114 | long started; 115 | int running = 1; 116 | XWindow xw; 117 | struct nk_context *ctx; 118 | 119 | /* X11 */ 120 | memset(&xw, 0, sizeof xw); 121 | xw.dpy = XOpenDisplay(NULL); 122 | if (!xw.dpy) die("Could not open a display; perhaps $DISPLAY is not set?"); 123 | xw.root = DefaultRootWindow(xw.dpy); 124 | xw.screen = XDefaultScreen(xw.dpy); 125 | xw.vis = XDefaultVisual(xw.dpy, xw.screen); 126 | xw.cmap = XCreateColormap(xw.dpy,xw.root,xw.vis,AllocNone); 127 | 128 | xw.swa.colormap = xw.cmap; 129 | xw.swa.event_mask = 130 | ExposureMask | KeyPressMask | KeyReleaseMask | 131 | ButtonPress | ButtonReleaseMask| ButtonMotionMask | 132 | Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask| 133 | PointerMotionMask | KeymapStateMask; 134 | xw.win = XCreateWindow(xw.dpy, xw.root, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 135 | XDefaultDepth(xw.dpy, xw.screen), InputOutput, 136 | xw.vis, CWEventMask | CWColormap, &xw.swa); 137 | 138 | XStoreName(xw.dpy, xw.win, "X11"); 139 | XMapWindow(xw.dpy, xw.win); 140 | xw.wm_delete_window = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False); 141 | XSetWMProtocols(xw.dpy, xw.win, &xw.wm_delete_window, 1); 142 | XGetWindowAttributes(xw.dpy, xw.win, &xw.attr); 143 | xw.width = (unsigned int)xw.attr.width; 144 | xw.height = (unsigned int)xw.attr.height; 145 | 146 | /* GUI */ 147 | xw.font = nk_xfont_create(xw.dpy, "fixed"); 148 | ctx = nk_xlib_init(xw.font, xw.dpy, xw.screen, xw.win, xw.width, xw.height); 149 | 150 | #ifdef INCLUDE_STYLE 151 | /*set_style(ctx, THEME_WHITE);*/ 152 | /*set_style(ctx, THEME_RED);*/ 153 | /*set_style(ctx, THEME_BLUE);*/ 154 | /*set_style(ctx, THEME_DARK);*/ 155 | #endif 156 | 157 | while (running) 158 | { 159 | /* Input */ 160 | XEvent evt; 161 | started = timestamp(); 162 | nk_input_begin(ctx); 163 | while (XPending(xw.dpy)) { 164 | XNextEvent(xw.dpy, &evt); 165 | if (evt.type == ClientMessage) goto cleanup; 166 | if (XFilterEvent(&evt, xw.win)) continue; 167 | nk_xlib_handle_event(xw.dpy, xw.screen, xw.win, &evt); 168 | } 169 | nk_input_end(ctx); 170 | 171 | /* GUI */ 172 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 173 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 174 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 175 | { 176 | enum {EASY, HARD}; 177 | static int op = EASY; 178 | static int property = 20; 179 | 180 | nk_layout_row_static(ctx, 30, 80, 1); 181 | if (nk_button_label(ctx, "button")) 182 | fprintf(stdout, "button pressed\n"); 183 | nk_layout_row_dynamic(ctx, 30, 2); 184 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 185 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 186 | nk_layout_row_dynamic(ctx, 25, 1); 187 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 188 | } 189 | nk_end(ctx); 190 | if (nk_window_is_hidden(ctx, "Demo")) break; 191 | 192 | /* -------------- EXAMPLES ---------------- */ 193 | #ifdef INCLUDE_CALCULATOR 194 | calculator(ctx); 195 | #endif 196 | #ifdef INCLUDE_OVERVIEW 197 | overview(ctx); 198 | #endif 199 | #ifdef INCLUDE_NODE_EDITOR 200 | node_editor(ctx); 201 | #endif 202 | /* ----------------------------------------- */ 203 | 204 | /* Draw */ 205 | XClearWindow(xw.dpy, xw.win); 206 | nk_xlib_render(xw.win, nk_rgb(30,30,30)); 207 | XFlush(xw.dpy); 208 | 209 | /* Timing */ 210 | dt = timestamp() - started; 211 | if (dt < DTIME) 212 | sleep_for(DTIME - dt); 213 | } 214 | 215 | cleanup: 216 | nk_xfont_del(xw.dpy, xw.font); 217 | nk_xlib_shutdown(); 218 | XUnmapWindow(xw.dpy, xw.win); 219 | XFreeColormap(xw.dpy, xw.cmap); 220 | XDestroyWindow(xw.dpy, xw.win); 221 | XCloseDisplay(xw.dpy); 222 | return 0; 223 | } 224 | 225 | -------------------------------------------------------------------------------- /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 | #include 12 | 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_GL3_IMPLEMENTATION 24 | #include "../../nuklear.h" 25 | #include "nuklear_sfml_gl3.h" 26 | 27 | #define WINDOW_WIDTH 1200 28 | #define WINDOW_HEIGHT 800 29 | 30 | #define MAX_VERTEX_BUFFER 512 * 1024 31 | #define MAX_ELEMENT_BUFFER 128 * 1024 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_OVERVIEW */ 44 | /*#define INCLUDE_NODE_EDITOR */ 45 | 46 | #ifdef INCLUDE_ALL 47 | #define INCLUDE_STYLE 48 | #define INCLUDE_CALCULATOR 49 | #define INCLUDE_OVERVIEW 50 | #define INCLUDE_NODE_EDITOR 51 | #endif 52 | 53 | #ifdef INCLUDE_STYLE 54 | #include "../style.c" 55 | #endif 56 | #ifdef INCLUDE_CALCULATOR 57 | #include "../calculator.c" 58 | #endif 59 | #ifdef INCLUDE_OVERVIEW 60 | #include "../overview.c" 61 | #endif 62 | #ifdef INCLUDE_NODE_EDITOR 63 | #include "../node_editor.c" 64 | #endif 65 | 66 | /* =============================================================== 67 | * 68 | * DEMO 69 | * 70 | * ===============================================================*/ 71 | int main(void) 72 | { 73 | /* Platform */ 74 | sf::ContextSettings settings(24, 8, 4, 3, 3); 75 | sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings); 76 | win.setVerticalSyncEnabled(true); 77 | win.setActive(true); 78 | if(!gladLoadGL()) { /* Load OpenGL extensions */ 79 | printf("Failed to load OpenGL extensions!\n"); 80 | return -1; 81 | } 82 | glViewport(0, 0, win.getSize().x, win.getSize().y); 83 | 84 | /* GUI */ 85 | struct nk_context *ctx; 86 | ctx = nk_sfml_init(&win); 87 | /* Load Fonts: if none of these are loaded a default font will be used */ 88 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 89 | struct nk_font_atlas *atlas; 90 | nk_sfml_font_stash_begin(&atlas); 91 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 92 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ 93 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 94 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 95 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 96 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 97 | nk_sfml_font_stash_end(); 98 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 99 | /*nk_style_set_font(ctx, &droid->handle);*/ 100 | 101 | /* style.c */ 102 | #ifdef INCLUDE_STYLE 103 | /*set_style(ctx, THEME_WHITE);*/ 104 | /*set_style(ctx, THEME_RED);*/ 105 | /*set_style(ctx, THEME_BLUE);*/ 106 | /*set_style(ctx, THEME_DARK);*/ 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 | 122 | nk_sfml_handle_event(&evt); 123 | } 124 | nk_input_end(ctx); 125 | 126 | /* GUI */ 127 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 128 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 129 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 130 | { 131 | enum {EASY, HARD}; 132 | static int op = EASY; 133 | static int property = 20; 134 | nk_layout_row_static(ctx, 30, 80, 1); 135 | if (nk_button_label(ctx, "button")) 136 | fprintf(stdout, "button pressed\n"); 137 | 138 | nk_layout_row_dynamic(ctx, 30, 2); 139 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 140 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 141 | 142 | nk_layout_row_dynamic(ctx, 25, 1); 143 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 144 | 145 | nk_layout_row_dynamic(ctx, 20, 1); 146 | nk_label(ctx, "background:", NK_TEXT_LEFT); 147 | nk_layout_row_dynamic(ctx, 25, 1); 148 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 149 | nk_layout_row_dynamic(ctx, 120, 1); 150 | bg = nk_color_picker(ctx, bg, NK_RGBA); 151 | nk_layout_row_dynamic(ctx, 25, 1); 152 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 153 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 154 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 155 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 156 | nk_combo_end(ctx); 157 | } 158 | } 159 | nk_end(ctx); 160 | 161 | /* -------------- EXAMPLES ---------------- */ 162 | #ifdef INCLUDE_CALCULATOR 163 | calculator(ctx); 164 | #endif 165 | #ifdef INCLUDE_OVERVIEW 166 | overview(ctx); 167 | #endif 168 | #ifdef INCLUDE_NODE_EDITOR 169 | node_editor(ctx); 170 | #endif 171 | /* ----------------------------------------- */ 172 | 173 | /* Draw */ 174 | float bg[4]; 175 | win.setActive(true); 176 | nk_color_fv(bg, background); 177 | glClear(GL_COLOR_BUFFER_BIT); 178 | glClearColor(bg.r, bg.g, bg.b, bg.a); 179 | /* IMPORTANT: `nk_sfml_render` modifies some global OpenGL state 180 | * with blending, scissor, face culling and depth test and defaults everything 181 | * back into a default state. Make sure to either save and restore or 182 | * reset your own state after drawing rendering the UI. */ 183 | nk_sfml_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); 184 | win.display(); 185 | } 186 | nk_sfml_shutdown(); 187 | return 0; 188 | } 189 | 190 | -------------------------------------------------------------------------------- /demo/sdl_opengles2/main.c: -------------------------------------------------------------------------------- 1 | /* nuklear - 1.40.8 - 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_INCLUDE_VERTEX_BUFFER_OUTPUT 18 | #define NK_INCLUDE_FONT_BAKING 19 | #define NK_INCLUDE_DEFAULT_FONT 20 | #define NK_IMPLEMENTATION 21 | #define NK_SDL_GLES2_IMPLEMENTATION 22 | #include "../../nuklear.h" 23 | #include "nuklear_sdl_gles2.h" 24 | 25 | #define WINDOW_WIDTH 800 26 | #define WINDOW_HEIGHT 600 27 | 28 | #define MAX_VERTEX_MEMORY 512 * 1024 29 | #define MAX_ELEMENT_MEMORY 128 * 1024 30 | 31 | #define UNUSED(a) (void)a 32 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 33 | #define MAX(a,b) ((a) < (b) ? (b) : (a)) 34 | #define LEN(a) (sizeof(a)/sizeof(a)[0]) 35 | 36 | /* =============================================================== 37 | * 38 | * EXAMPLE 39 | * 40 | * ===============================================================*/ 41 | /* This are some code examples to provide a small overview of what can be 42 | * done with this library. To try out an example uncomment the include 43 | * and the corresponding function. */ 44 | /*#include "../style.c"*/ 45 | /*#include "../calculator.c"*/ 46 | /*#include "../overview.c"*/ 47 | /*#include "../node_editor.c"*/ 48 | 49 | /* =============================================================== 50 | * 51 | * DEMO 52 | * 53 | * ===============================================================*/ 54 | 55 | 56 | /* Platform */ 57 | SDL_Window *win; 58 | int running = nk_true; 59 | 60 | static void 61 | MainLoop(void* loopArg){ 62 | struct nk_context *ctx = (struct nk_context *)loopArg; 63 | 64 | /* Input */ 65 | SDL_Event evt; 66 | nk_input_begin(ctx); 67 | while (SDL_PollEvent(&evt)) { 68 | if (evt.type == SDL_QUIT) running = nk_false; 69 | nk_sdl_handle_event(&evt); 70 | } 71 | nk_input_end(ctx); 72 | 73 | 74 | /* GUI */ 75 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 76 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 77 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 78 | { 79 | nk_menubar_begin(ctx); 80 | nk_layout_row_begin(ctx, NK_STATIC, 25, 2); 81 | nk_layout_row_push(ctx, 45); 82 | if (nk_menu_begin_label(ctx, "FILE", NK_TEXT_LEFT, nk_vec2(120, 200))) { 83 | nk_layout_row_dynamic(ctx, 30, 1); 84 | nk_menu_item_label(ctx, "OPEN", NK_TEXT_LEFT); 85 | nk_menu_item_label(ctx, "CLOSE", NK_TEXT_LEFT); 86 | nk_menu_end(ctx); 87 | } 88 | nk_layout_row_push(ctx, 45); 89 | if (nk_menu_begin_label(ctx, "EDIT", NK_TEXT_LEFT, nk_vec2(120, 200))) { 90 | nk_layout_row_dynamic(ctx, 30, 1); 91 | nk_menu_item_label(ctx, "COPY", NK_TEXT_LEFT); 92 | nk_menu_item_label(ctx, "CUT", NK_TEXT_LEFT); 93 | nk_menu_item_label(ctx, "PASTE", NK_TEXT_LEFT); 94 | nk_menu_end(ctx); 95 | } 96 | nk_layout_row_end(ctx); 97 | nk_menubar_end(ctx); 98 | 99 | enum {EASY, HARD}; 100 | static int op = EASY; 101 | static int property = 20; 102 | nk_layout_row_static(ctx, 30, 80, 1); 103 | if (nk_button_label(ctx, "button")) 104 | fprintf(stdout, "button pressed\n"); 105 | nk_layout_row_dynamic(ctx, 30, 2); 106 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 107 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 108 | nk_layout_row_dynamic(ctx, 25, 1); 109 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 110 | } 111 | nk_end(ctx); 112 | 113 | /* -------------- EXAMPLES ---------------- */ 114 | /*calculator(ctx);*/ 115 | /*overview(ctx);*/ 116 | /*node_editor(ctx);*/ 117 | /* ----------------------------------------- */ 118 | 119 | /* Draw */ 120 | {float bg[4]; 121 | int win_width, win_height; 122 | nk_color_fv(bg, nk_rgb(28,48,62)); 123 | SDL_GetWindowSize(win, &win_width, &win_height); 124 | glViewport(0, 0, win_width, win_height); 125 | glClear(GL_COLOR_BUFFER_BIT); 126 | glClearColor(bg[0], bg[1], bg[2], bg[3]); 127 | /* IMPORTANT: `nk_sdl_render` modifies some global OpenGL state 128 | * with blending, scissor, face culling, depth test and viewport and 129 | * defaults everything back into a default state. 130 | * Make sure to either a.) save and restore or b.) reset your own state after 131 | * rendering the UI. */ 132 | nk_sdl_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_MEMORY, MAX_ELEMENT_MEMORY); 133 | SDL_GL_SwapWindow(win);} 134 | } 135 | 136 | int main(int argc, char* argv[]) 137 | { 138 | /* GUI */ 139 | struct nk_context *ctx; 140 | SDL_GLContext glContext; 141 | /* SDL setup */ 142 | SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0"); 143 | /*SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS); // - do NOT init SDL on GL ES 2 */ 144 | SDL_GL_SetAttribute (SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); 145 | SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); 146 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); 147 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); 148 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 149 | win = SDL_CreateWindow("Demo", 150 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 151 | WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI); 152 | glContext = SDL_GL_CreateContext(win); 153 | 154 | /* OpenGL setup */ 155 | glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); 156 | 157 | ctx = nk_sdl_init(win); 158 | /* Load Fonts: if none of these are loaded a default font will be used */ 159 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 160 | {struct nk_font_atlas *atlas; 161 | nk_sdl_font_stash_begin(&atlas); 162 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 163 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, 0);*/ 164 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 165 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 166 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 167 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 168 | nk_sdl_font_stash_end(); 169 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 170 | /*nk_style_set_font(ctx, &roboto->handle)*/;} 171 | 172 | /* style.c */ 173 | /*set_style(ctx, THEME_WHITE);*/ 174 | /*set_style(ctx, THEME_RED);*/ 175 | /*set_style(ctx, THEME_BLUE);*/ 176 | /*set_style(ctx, THEME_DARK);*/ 177 | 178 | #if defined(__EMSCRIPTEN__) 179 | #include 180 | emscripten_set_main_loop_arg(MainLoop, (void*)ctx, 0, nk_true); 181 | #else 182 | while (running) MainLoop((void*)ctx); 183 | #endif 184 | 185 | nk_sdl_shutdown(); 186 | SDL_GL_DeleteContext(glContext); 187 | SDL_DestroyWindow(win); 188 | SDL_Quit(); 189 | return 0; 190 | } 191 | 192 | -------------------------------------------------------------------------------- /demo/sdl_opengl2/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 | #include 12 | 13 | #include 14 | #include 15 | 16 | #define NK_INCLUDE_FIXED_TYPES 17 | #define NK_INCLUDE_STANDARD_IO 18 | #define NK_INCLUDE_STANDARD_VARARGS 19 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 20 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 21 | #define NK_INCLUDE_FONT_BAKING 22 | #define NK_INCLUDE_DEFAULT_FONT 23 | #define NK_IMPLEMENTATION 24 | #define NK_SDL_GL2_IMPLEMENTATION 25 | #include "../../nuklear.h" 26 | #include "nuklear_sdl_gl2.h" 27 | 28 | #define WINDOW_WIDTH 1200 29 | #define WINDOW_HEIGHT 800 30 | 31 | /* =============================================================== 32 | * 33 | * EXAMPLE 34 | * 35 | * ===============================================================*/ 36 | /* This are some code examples to provide a small overview of what can be 37 | * done with this library. To try out an example uncomment the defines */ 38 | /*#define INCLUDE_ALL */ 39 | /*#define INCLUDE_STYLE */ 40 | /*#define INCLUDE_CALCULATOR */ 41 | /*#define INCLUDE_OVERVIEW */ 42 | /*#define INCLUDE_NODE_EDITOR */ 43 | 44 | #ifdef INCLUDE_ALL 45 | #define INCLUDE_STYLE 46 | #define INCLUDE_CALCULATOR 47 | #define INCLUDE_OVERVIEW 48 | #define INCLUDE_NODE_EDITOR 49 | #endif 50 | 51 | #ifdef INCLUDE_STYLE 52 | #include "../style.c" 53 | #endif 54 | #ifdef INCLUDE_CALCULATOR 55 | #include "../calculator.c" 56 | #endif 57 | #ifdef INCLUDE_OVERVIEW 58 | #include "../overview.c" 59 | #endif 60 | #ifdef INCLUDE_NODE_EDITOR 61 | #include "../node_editor.c" 62 | #endif 63 | 64 | /* =============================================================== 65 | * 66 | * DEMO 67 | * 68 | * ===============================================================*/ 69 | int 70 | main(void) 71 | { 72 | /* Platform */ 73 | SDL_Window *win; 74 | SDL_GLContext glContext; 75 | int win_width, win_height; 76 | int running = 1; 77 | 78 | /* GUI */ 79 | struct nk_context *ctx; 80 | struct nk_colorf bg; 81 | 82 | /* SDL setup */ 83 | SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0"); 84 | SDL_Init(SDL_INIT_VIDEO); 85 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 86 | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); 87 | SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); 88 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); 89 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); 90 | win = SDL_CreateWindow("Demo", 91 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 92 | WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI); 93 | glContext = SDL_GL_CreateContext(win); 94 | SDL_GetWindowSize(win, &win_width, &win_height); 95 | 96 | /* GUI */ 97 | ctx = nk_sdl_init(win); 98 | /* Load Fonts: if none of these are loaded a default font will be used */ 99 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 100 | {struct nk_font_atlas *atlas; 101 | nk_sdl_font_stash_begin(&atlas); 102 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 103 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, 0);*/ 104 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 105 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 106 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 107 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 108 | nk_sdl_font_stash_end(); 109 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 110 | /*nk_style_set_font(ctx, &roboto->handle)*/;} 111 | 112 | #ifdef INCLUDE_STYLE 113 | /*set_style(ctx, THEME_WHITE);*/ 114 | /*set_style(ctx, THEME_RED);*/ 115 | /*set_style(ctx, THEME_BLUE);*/ 116 | /*set_style(ctx, THEME_DARK);*/ 117 | #endif 118 | 119 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 120 | while (running) 121 | { 122 | /* Input */ 123 | SDL_Event evt; 124 | nk_input_begin(ctx); 125 | while (SDL_PollEvent(&evt)) { 126 | if (evt.type == SDL_QUIT) goto cleanup; 127 | nk_sdl_handle_event(&evt); 128 | } 129 | nk_input_end(ctx); 130 | 131 | /* GUI */ 132 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 133 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 134 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 135 | { 136 | enum {EASY, HARD}; 137 | static int op = EASY; 138 | static int property = 20; 139 | 140 | nk_layout_row_static(ctx, 30, 80, 1); 141 | if (nk_button_label(ctx, "button")) 142 | fprintf(stdout, "button pressed\n"); 143 | nk_layout_row_dynamic(ctx, 30, 2); 144 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 145 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 146 | nk_layout_row_dynamic(ctx, 25, 1); 147 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 148 | 149 | nk_layout_row_dynamic(ctx, 20, 1); 150 | nk_label(ctx, "background:", NK_TEXT_LEFT); 151 | nk_layout_row_dynamic(ctx, 25, 1); 152 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 153 | nk_layout_row_dynamic(ctx, 120, 1); 154 | bg = nk_color_picker(ctx, bg, NK_RGBA); 155 | nk_layout_row_dynamic(ctx, 25, 1); 156 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 157 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 158 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 159 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 160 | nk_combo_end(ctx); 161 | } 162 | } 163 | nk_end(ctx); 164 | 165 | /* -------------- EXAMPLES ---------------- */ 166 | #ifdef INCLUDE_CALCULATOR 167 | calculator(ctx); 168 | #endif 169 | #ifdef INCLUDE_OVERVIEW 170 | overview(ctx); 171 | #endif 172 | #ifdef INCLUDE_NODE_EDITOR 173 | node_editor(ctx); 174 | #endif 175 | /* ----------------------------------------- */ 176 | 177 | /* Draw */ 178 | SDL_GetWindowSize(win, &win_width, &win_height); 179 | glViewport(0, 0, win_width, win_height); 180 | glClear(GL_COLOR_BUFFER_BIT); 181 | glClearColor(bg.r, bg.g, bg.b, bg.a); 182 | /* IMPORTANT: `nk_sdl_render` modifies some global OpenGL state 183 | * with blending, scissor, face culling, depth test and viewport and 184 | * defaults everything back into a default state. 185 | * Make sure to either a.) save and restore or b.) reset your own state after 186 | * rendering the UI. */ 187 | nk_sdl_render(NK_ANTI_ALIASING_ON); 188 | SDL_GL_SwapWindow(win); 189 | } 190 | 191 | cleanup: 192 | nk_sdl_shutdown(); 193 | SDL_GL_DeleteContext(glContext); 194 | SDL_DestroyWindow(win); 195 | SDL_Quit(); 196 | return 0; 197 | } 198 | 199 | -------------------------------------------------------------------------------- /demo/glfw_opengl3/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 | #include 12 | 13 | #include 14 | #include 15 | 16 | #define NK_INCLUDE_FIXED_TYPES 17 | #define NK_INCLUDE_STANDARD_IO 18 | #define NK_INCLUDE_STANDARD_VARARGS 19 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 20 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 21 | #define NK_INCLUDE_FONT_BAKING 22 | #define NK_INCLUDE_DEFAULT_FONT 23 | #define NK_IMPLEMENTATION 24 | #define NK_GLFW_GL3_IMPLEMENTATION 25 | #include "../../nuklear.h" 26 | #include "nuklear_glfw_gl3.h" 27 | 28 | #define WINDOW_WIDTH 1200 29 | #define WINDOW_HEIGHT 800 30 | 31 | #define MAX_VERTEX_BUFFER 512 * 1024 32 | #define MAX_ELEMENT_BUFFER 128 * 1024 33 | 34 | /* =============================================================== 35 | * 36 | * EXAMPLE 37 | * 38 | * ===============================================================*/ 39 | /* This are some code examples to provide a small overview of what can be 40 | * done with this library. To try out an example uncomment the defines */ 41 | /*#define INCLUDE_ALL */ 42 | /*#define INCLUDE_STYLE */ 43 | /*#define INCLUDE_CALCULATOR */ 44 | /*#define INCLUDE_OVERVIEW */ 45 | /*#define INCLUDE_NODE_EDITOR */ 46 | 47 | #ifdef INCLUDE_ALL 48 | #define INCLUDE_STYLE 49 | #define INCLUDE_CALCULATOR 50 | #define INCLUDE_OVERVIEW 51 | #define INCLUDE_NODE_EDITOR 52 | #endif 53 | 54 | #ifdef INCLUDE_STYLE 55 | #include "../style.c" 56 | #endif 57 | #ifdef INCLUDE_CALCULATOR 58 | #include "../calculator.c" 59 | #endif 60 | #ifdef INCLUDE_OVERVIEW 61 | #include "../overview.c" 62 | #endif 63 | #ifdef INCLUDE_NODE_EDITOR 64 | #include "../node_editor.c" 65 | #endif 66 | 67 | /* =============================================================== 68 | * 69 | * DEMO 70 | * 71 | * ===============================================================*/ 72 | static void error_callback(int e, const char *d) 73 | {printf("Error %d: %s\n", e, d);} 74 | 75 | int main(void) 76 | { 77 | /* Platform */ 78 | static GLFWwindow *win; 79 | int width = 0, height = 0; 80 | struct nk_context *ctx; 81 | struct nk_colorf bg; 82 | 83 | /* GLFW */ 84 | glfwSetErrorCallback(error_callback); 85 | if (!glfwInit()) { 86 | fprintf(stdout, "[GFLW] failed to init!\n"); 87 | exit(1); 88 | } 89 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 90 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 91 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 92 | #ifdef __APPLE__ 93 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 94 | #endif 95 | win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL); 96 | glfwMakeContextCurrent(win); 97 | glfwGetWindowSize(win, &width, &height); 98 | 99 | /* OpenGL */ 100 | glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); 101 | glewExperimental = 1; 102 | if (glewInit() != GLEW_OK) { 103 | fprintf(stderr, "Failed to setup GLEW\n"); 104 | exit(1); 105 | } 106 | 107 | ctx = nk_glfw3_init(win, NK_GLFW3_INSTALL_CALLBACKS); 108 | /* Load Fonts: if none of these are loaded a default font will be used */ 109 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 110 | {struct nk_font_atlas *atlas; 111 | nk_glfw3_font_stash_begin(&atlas); 112 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 113 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ 114 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 115 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 116 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 117 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 118 | nk_glfw3_font_stash_end(); 119 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 120 | /*nk_style_set_font(ctx, &droid->handle);*/} 121 | 122 | #ifdef INCLUDE_STYLE 123 | /*set_style(ctx, THEME_WHITE);*/ 124 | /*set_style(ctx, THEME_RED);*/ 125 | /*set_style(ctx, THEME_BLUE);*/ 126 | /*set_style(ctx, THEME_DARK);*/ 127 | #endif 128 | 129 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 130 | while (!glfwWindowShouldClose(win)) 131 | { 132 | /* Input */ 133 | glfwPollEvents(); 134 | nk_glfw3_new_frame(); 135 | 136 | /* GUI */ 137 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 138 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 139 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 140 | { 141 | enum {EASY, HARD}; 142 | static int op = EASY; 143 | static int property = 20; 144 | nk_layout_row_static(ctx, 30, 80, 1); 145 | if (nk_button_label(ctx, "button")) 146 | fprintf(stdout, "button pressed\n"); 147 | 148 | nk_layout_row_dynamic(ctx, 30, 2); 149 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 150 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 151 | 152 | nk_layout_row_dynamic(ctx, 25, 1); 153 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 154 | 155 | nk_layout_row_dynamic(ctx, 20, 1); 156 | nk_label(ctx, "background:", NK_TEXT_LEFT); 157 | nk_layout_row_dynamic(ctx, 25, 1); 158 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 159 | nk_layout_row_dynamic(ctx, 120, 1); 160 | bg = nk_color_picker(ctx, bg, NK_RGBA); 161 | nk_layout_row_dynamic(ctx, 25, 1); 162 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 163 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 164 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 165 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 166 | nk_combo_end(ctx); 167 | } 168 | } 169 | nk_end(ctx); 170 | 171 | /* -------------- EXAMPLES ---------------- */ 172 | #ifdef INCLUDE_CALCULATOR 173 | calculator(ctx); 174 | #endif 175 | #ifdef INCLUDE_OVERVIEW 176 | overview(ctx); 177 | #endif 178 | #ifdef INCLUDE_NODE_EDITOR 179 | node_editor(ctx); 180 | #endif 181 | /* ----------------------------------------- */ 182 | 183 | /* Draw */ 184 | glfwGetWindowSize(win, &width, &height); 185 | glViewport(0, 0, width, height); 186 | glClear(GL_COLOR_BUFFER_BIT); 187 | glClearColor(bg.r, bg.g, bg.b, bg.a); 188 | /* IMPORTANT: `nk_glfw_render` modifies some global OpenGL state 189 | * with blending, scissor, face culling, depth test and viewport and 190 | * defaults everything back into a default state. 191 | * Make sure to either a.) save and restore or b.) reset your own state after 192 | * rendering the UI. */ 193 | nk_glfw3_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); 194 | glfwSwapBuffers(win); 195 | } 196 | nk_glfw3_shutdown(); 197 | glfwTerminate(); 198 | return 0; 199 | } 200 | 201 | -------------------------------------------------------------------------------- /demo/sdl_opengl3/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 | #include 12 | 13 | #include 14 | #include 15 | #include 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_INCLUDE_VERTEX_BUFFER_OUTPUT 22 | #define NK_INCLUDE_FONT_BAKING 23 | #define NK_INCLUDE_DEFAULT_FONT 24 | #define NK_IMPLEMENTATION 25 | #define NK_SDL_GL3_IMPLEMENTATION 26 | #include "../../nuklear.h" 27 | #include "nuklear_sdl_gl3.h" 28 | 29 | #define WINDOW_WIDTH 1200 30 | #define WINDOW_HEIGHT 800 31 | 32 | #define MAX_VERTEX_MEMORY 512 * 1024 33 | #define MAX_ELEMENT_MEMORY 128 * 1024 34 | 35 | /* =============================================================== 36 | * 37 | * EXAMPLE 38 | * 39 | * ===============================================================*/ 40 | /* This are some code examples to provide a small overview of what can be 41 | * done with this library. To try out an example uncomment the defines */ 42 | /*#define INCLUDE_ALL */ 43 | /*#define INCLUDE_STYLE */ 44 | /*#define INCLUDE_CALCULATOR */ 45 | /*#define INCLUDE_OVERVIEW */ 46 | /*#define INCLUDE_NODE_EDITOR */ 47 | 48 | #ifdef INCLUDE_ALL 49 | #define INCLUDE_STYLE 50 | #define INCLUDE_CALCULATOR 51 | #define INCLUDE_OVERVIEW 52 | #define INCLUDE_NODE_EDITOR 53 | #endif 54 | 55 | #ifdef INCLUDE_STYLE 56 | #include "../style.c" 57 | #endif 58 | #ifdef INCLUDE_CALCULATOR 59 | #include "../calculator.c" 60 | #endif 61 | #ifdef INCLUDE_OVERVIEW 62 | #include "../overview.c" 63 | #endif 64 | #ifdef INCLUDE_NODE_EDITOR 65 | #include "../node_editor.c" 66 | #endif 67 | 68 | /* =============================================================== 69 | * 70 | * DEMO 71 | * 72 | * ===============================================================*/ 73 | int main(void) 74 | { 75 | /* Platform */ 76 | SDL_Window *win; 77 | SDL_GLContext glContext; 78 | int win_width, win_height; 79 | int running = 1; 80 | 81 | /* GUI */ 82 | struct nk_context *ctx; 83 | struct nk_colorf bg; 84 | 85 | /* SDL setup */ 86 | SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0"); 87 | SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS); 88 | SDL_GL_SetAttribute (SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); 89 | SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); 90 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); 91 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); 92 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 93 | win = SDL_CreateWindow("Demo", 94 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 95 | WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI); 96 | glContext = SDL_GL_CreateContext(win); 97 | SDL_GetWindowSize(win, &win_width, &win_height); 98 | 99 | /* OpenGL setup */ 100 | glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); 101 | glewExperimental = 1; 102 | if (glewInit() != GLEW_OK) { 103 | fprintf(stderr, "Failed to setup GLEW\n"); 104 | exit(1); 105 | } 106 | 107 | ctx = nk_sdl_init(win); 108 | /* Load Fonts: if none of these are loaded a default font will be used */ 109 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 110 | {struct nk_font_atlas *atlas; 111 | nk_sdl_font_stash_begin(&atlas); 112 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 113 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, 0);*/ 114 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 115 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 116 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 117 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 118 | nk_sdl_font_stash_end(); 119 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 120 | /*nk_style_set_font(ctx, &roboto->handle);*/} 121 | 122 | /* style.c */ 123 | #ifdef INCLUDE_STYLE 124 | /*set_style(ctx, THEME_WHITE);*/ 125 | /*set_style(ctx, THEME_RED);*/ 126 | /*set_style(ctx, THEME_BLUE);*/ 127 | /*set_style(ctx, THEME_DARK);*/ 128 | #endif 129 | 130 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 131 | while (running) 132 | { 133 | /* Input */ 134 | SDL_Event evt; 135 | nk_input_begin(ctx); 136 | while (SDL_PollEvent(&evt)) { 137 | if (evt.type == SDL_QUIT) goto cleanup; 138 | nk_sdl_handle_event(&evt); 139 | } nk_input_end(ctx); 140 | 141 | /* GUI */ 142 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 143 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 144 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 145 | { 146 | enum {EASY, HARD}; 147 | static int op = EASY; 148 | static int property = 20; 149 | 150 | nk_layout_row_static(ctx, 30, 80, 1); 151 | if (nk_button_label(ctx, "button")) 152 | printf("button pressed!\n"); 153 | nk_layout_row_dynamic(ctx, 30, 2); 154 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 155 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 156 | nk_layout_row_dynamic(ctx, 22, 1); 157 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 158 | 159 | nk_layout_row_dynamic(ctx, 20, 1); 160 | nk_label(ctx, "background:", NK_TEXT_LEFT); 161 | nk_layout_row_dynamic(ctx, 25, 1); 162 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 163 | nk_layout_row_dynamic(ctx, 120, 1); 164 | bg = nk_color_picker(ctx, bg, NK_RGBA); 165 | nk_layout_row_dynamic(ctx, 25, 1); 166 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 167 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 168 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 169 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 170 | nk_combo_end(ctx); 171 | } 172 | } 173 | nk_end(ctx); 174 | 175 | /* -------------- EXAMPLES ---------------- */ 176 | #ifdef INCLUDE_CALCULATOR 177 | calculator(ctx); 178 | #endif 179 | #ifdef INCLUDE_OVERVIEW 180 | overview(ctx); 181 | #endif 182 | #ifdef INCLUDE_NODE_EDITOR 183 | node_editor(ctx); 184 | #endif 185 | /* ----------------------------------------- */ 186 | 187 | /* Draw */ 188 | SDL_GetWindowSize(win, &win_width, &win_height); 189 | glViewport(0, 0, win_width, win_height); 190 | glClear(GL_COLOR_BUFFER_BIT); 191 | glClearColor(bg.r, bg.g, bg.b, bg.a); 192 | /* IMPORTANT: `nk_sdl_render` modifies some global OpenGL state 193 | * with blending, scissor, face culling, depth test and viewport and 194 | * defaults everything back into a default state. 195 | * Make sure to either a.) save and restore or b.) reset your own state after 196 | * rendering the UI. */ 197 | nk_sdl_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_MEMORY, MAX_ELEMENT_MEMORY); 198 | SDL_GL_SwapWindow(win); 199 | } 200 | 201 | cleanup: 202 | nk_sdl_shutdown(); 203 | SDL_GL_DeleteContext(glContext); 204 | SDL_DestroyWindow(win); 205 | SDL_Quit(); 206 | return 0; 207 | } 208 | 209 | -------------------------------------------------------------------------------- /demo/style.c: -------------------------------------------------------------------------------- 1 | enum theme {THEME_BLACK, THEME_WHITE, THEME_RED, THEME_BLUE, THEME_DARK}; 2 | 3 | static void 4 | set_style(struct nk_context *ctx, enum theme theme) 5 | { 6 | struct nk_color table[NK_COLOR_COUNT]; 7 | if (theme == THEME_WHITE) { 8 | table[NK_COLOR_TEXT] = nk_rgba(70, 70, 70, 255); 9 | table[NK_COLOR_WINDOW] = nk_rgba(175, 175, 175, 255); 10 | table[NK_COLOR_HEADER] = nk_rgba(175, 175, 175, 255); 11 | table[NK_COLOR_BORDER] = nk_rgba(0, 0, 0, 255); 12 | table[NK_COLOR_BUTTON] = nk_rgba(185, 185, 185, 255); 13 | table[NK_COLOR_BUTTON_HOVER] = nk_rgba(170, 170, 170, 255); 14 | table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(160, 160, 160, 255); 15 | table[NK_COLOR_TOGGLE] = nk_rgba(150, 150, 150, 255); 16 | table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(120, 120, 120, 255); 17 | table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(175, 175, 175, 255); 18 | table[NK_COLOR_SELECT] = nk_rgba(190, 190, 190, 255); 19 | table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(175, 175, 175, 255); 20 | table[NK_COLOR_SLIDER] = nk_rgba(190, 190, 190, 255); 21 | table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(80, 80, 80, 255); 22 | table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(70, 70, 70, 255); 23 | table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(60, 60, 60, 255); 24 | table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255); 25 | table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255); 26 | table[NK_COLOR_EDIT_CURSOR] = nk_rgba(0, 0, 0, 255); 27 | table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255); 28 | table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255); 29 | table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255); 30 | table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); 31 | table[NK_COLOR_SCROLLBAR] = nk_rgba(180, 180, 180, 255); 32 | table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(140, 140, 140, 255); 33 | table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255); 34 | table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255); 35 | table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255); 36 | nk_style_from_table(ctx, table); 37 | } else if (theme == THEME_RED) { 38 | table[NK_COLOR_TEXT] = nk_rgba(190, 190, 190, 255); 39 | table[NK_COLOR_WINDOW] = nk_rgba(30, 33, 40, 215); 40 | table[NK_COLOR_HEADER] = nk_rgba(181, 45, 69, 220); 41 | table[NK_COLOR_BORDER] = nk_rgba(51, 55, 67, 255); 42 | table[NK_COLOR_BUTTON] = nk_rgba(181, 45, 69, 255); 43 | table[NK_COLOR_BUTTON_HOVER] = nk_rgba(190, 50, 70, 255); 44 | table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(195, 55, 75, 255); 45 | table[NK_COLOR_TOGGLE] = nk_rgba(51, 55, 67, 255); 46 | table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 60, 60, 255); 47 | table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(181, 45, 69, 255); 48 | table[NK_COLOR_SELECT] = nk_rgba(51, 55, 67, 255); 49 | table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(181, 45, 69, 255); 50 | table[NK_COLOR_SLIDER] = nk_rgba(51, 55, 67, 255); 51 | table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(181, 45, 69, 255); 52 | table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(186, 50, 74, 255); 53 | table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(191, 55, 79, 255); 54 | table[NK_COLOR_PROPERTY] = nk_rgba(51, 55, 67, 255); 55 | table[NK_COLOR_EDIT] = nk_rgba(51, 55, 67, 225); 56 | table[NK_COLOR_EDIT_CURSOR] = nk_rgba(190, 190, 190, 255); 57 | table[NK_COLOR_COMBO] = nk_rgba(51, 55, 67, 255); 58 | table[NK_COLOR_CHART] = nk_rgba(51, 55, 67, 255); 59 | table[NK_COLOR_CHART_COLOR] = nk_rgba(170, 40, 60, 255); 60 | table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); 61 | table[NK_COLOR_SCROLLBAR] = nk_rgba(30, 33, 40, 255); 62 | table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); 63 | table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); 64 | table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); 65 | table[NK_COLOR_TAB_HEADER] = nk_rgba(181, 45, 69, 220); 66 | nk_style_from_table(ctx, table); 67 | } else if (theme == THEME_BLUE) { 68 | table[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255); 69 | table[NK_COLOR_WINDOW] = nk_rgba(202, 212, 214, 215); 70 | table[NK_COLOR_HEADER] = nk_rgba(137, 182, 224, 220); 71 | table[NK_COLOR_BORDER] = nk_rgba(140, 159, 173, 255); 72 | table[NK_COLOR_BUTTON] = nk_rgba(137, 182, 224, 255); 73 | table[NK_COLOR_BUTTON_HOVER] = nk_rgba(142, 187, 229, 255); 74 | table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(147, 192, 234, 255); 75 | table[NK_COLOR_TOGGLE] = nk_rgba(177, 210, 210, 255); 76 | table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(182, 215, 215, 255); 77 | table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(137, 182, 224, 255); 78 | table[NK_COLOR_SELECT] = nk_rgba(177, 210, 210, 255); 79 | table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(137, 182, 224, 255); 80 | table[NK_COLOR_SLIDER] = nk_rgba(177, 210, 210, 255); 81 | table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(137, 182, 224, 245); 82 | table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(142, 188, 229, 255); 83 | table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(147, 193, 234, 255); 84 | table[NK_COLOR_PROPERTY] = nk_rgba(210, 210, 210, 255); 85 | table[NK_COLOR_EDIT] = nk_rgba(210, 210, 210, 225); 86 | table[NK_COLOR_EDIT_CURSOR] = nk_rgba(20, 20, 20, 255); 87 | table[NK_COLOR_COMBO] = nk_rgba(210, 210, 210, 255); 88 | table[NK_COLOR_CHART] = nk_rgba(210, 210, 210, 255); 89 | table[NK_COLOR_CHART_COLOR] = nk_rgba(137, 182, 224, 255); 90 | table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); 91 | table[NK_COLOR_SCROLLBAR] = nk_rgba(190, 200, 200, 255); 92 | table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); 93 | table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); 94 | table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); 95 | table[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255); 96 | nk_style_from_table(ctx, table); 97 | } else if (theme == THEME_DARK) { 98 | table[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255); 99 | table[NK_COLOR_WINDOW] = nk_rgba(57, 67, 71, 215); 100 | table[NK_COLOR_HEADER] = nk_rgba(51, 51, 56, 220); 101 | table[NK_COLOR_BORDER] = nk_rgba(46, 46, 46, 255); 102 | table[NK_COLOR_BUTTON] = nk_rgba(48, 83, 111, 255); 103 | table[NK_COLOR_BUTTON_HOVER] = nk_rgba(58, 93, 121, 255); 104 | table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(63, 98, 126, 255); 105 | table[NK_COLOR_TOGGLE] = nk_rgba(50, 58, 61, 255); 106 | table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 53, 56, 255); 107 | table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(48, 83, 111, 255); 108 | table[NK_COLOR_SELECT] = nk_rgba(57, 67, 61, 255); 109 | table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(48, 83, 111, 255); 110 | table[NK_COLOR_SLIDER] = nk_rgba(50, 58, 61, 255); 111 | table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(48, 83, 111, 245); 112 | table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); 113 | table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); 114 | table[NK_COLOR_PROPERTY] = nk_rgba(50, 58, 61, 255); 115 | table[NK_COLOR_EDIT] = nk_rgba(50, 58, 61, 225); 116 | table[NK_COLOR_EDIT_CURSOR] = nk_rgba(210, 210, 210, 255); 117 | table[NK_COLOR_COMBO] = nk_rgba(50, 58, 61, 255); 118 | table[NK_COLOR_CHART] = nk_rgba(50, 58, 61, 255); 119 | table[NK_COLOR_CHART_COLOR] = nk_rgba(48, 83, 111, 255); 120 | table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255); 121 | table[NK_COLOR_SCROLLBAR] = nk_rgba(50, 58, 61, 255); 122 | table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(48, 83, 111, 255); 123 | table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); 124 | table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); 125 | table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255); 126 | nk_style_from_table(ctx, table); 127 | } else { 128 | nk_style_default(ctx); 129 | } 130 | } 131 | 132 | 133 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Nuklear 2 | 3 | [![Build Status](https://travis-ci.org/vurtun/nuklear.svg)](https://travis-ci.org/vurtun/nuklear) 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 and input handling but instead provides a very modular 9 | library approach by using simple input state for input and draw 10 | 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 only focuses 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 memory control if needed or 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://rawgit.com/vurtun/nuklear/master/doc/nuklear.html) 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 to define 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 languges created by other authors. 96 | I cannot atest for their quality since I am not necessarily proficient in either 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 | - [Golang](https://github.com/golang-ui/nuklear) by golang-ui@github.com 101 | - [Rust](https://github.com/snuk182/nuklear-rust) by snuk182@github.com 102 | - [Chicken](https://github.com/wasamasa/nuklear) by wasamasa@github.com 103 | - [Nim](https://github.com/zacharycarter/nuklear-nim) by zacharycarter@github.com 104 | - [Lua/Löve2d](https://github.com/keharriso/love-nuklear) by Kevin Harrison 105 | - [Python](https://github.com/billsix/pyNuklear) by William Emerison Six 106 | - [CSharp/.NET](https://github.com/cartman300/NuklearDotNet) by cartman300@github.com 107 | 108 | ## Credits 109 | Developed by Micha Mettke and every direct or indirect contributor to the GitHub. 110 | 111 | 112 | Embeds `stb_texedit`, `stb_truetype` and `stb_rectpack` by Sean Barrett (public domain) 113 | Embeds `ProggyClean.ttf` font by Tristan Grimmer (MIT license). 114 | 115 | 116 | Big thank you to Omar Cornut (ocornut@github) for his [imgui](https://github.com/ocornut/imgui) library and 117 | giving me the inspiration for this library, Casey Muratori for handmade hero 118 | and his original immediate mode graphical user interface idea and Sean 119 | Barrett for his amazing single header [libraries](https://github.com/nothings/stb) which restored my faith 120 | in libraries and brought me to create some of my own. 121 | 122 | ## License 123 | ``` 124 | ------------------------------------------------------------------------------ 125 | This software is available under 2 licenses -- choose whichever you prefer. 126 | ------------------------------------------------------------------------------ 127 | ALTERNATIVE A - MIT License 128 | Copyright (c) 2017 Micha Mettke 129 | Permission is hereby granted, free of charge, to any person obtaining a copy of 130 | this software and associated documentation files (the "Software"), to deal in 131 | the Software without restriction, including without limitation the rights to 132 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 133 | of the Software, and to permit persons to whom the Software is furnished to do 134 | so, subject to the following conditions: 135 | The above copyright notice and this permission notice shall be included in all 136 | copies or substantial portions of the Software. 137 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 138 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 139 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 140 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 141 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 142 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 143 | SOFTWARE. 144 | ------------------------------------------------------------------------------ 145 | ALTERNATIVE B - Public Domain (www.unlicense.org) 146 | This is free and unencumbered software released into the public domain. 147 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 148 | software, either in source code form or as a compiled binary, for any purpose, 149 | commercial or non-commercial, and by any means. 150 | In jurisdictions that recognize copyright laws, the author or authors of this 151 | software dedicate any and all copyright interest in the software to the public 152 | domain. We make this dedication for the benefit of the public at large and to 153 | the detriment of our heirs and successors. We intend this dedication to be an 154 | overt act of relinquishment in perpetuity of all present and future rights to 155 | this software under copyright law. 156 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 157 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 158 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 159 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 160 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 161 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 162 | ----------------------------------------------------------------------------- 163 | ``` 164 | -------------------------------------------------------------------------------- /demo/x11_rawfb/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2016-2017 Patrick Rudolph 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | 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 | * Based on x11/main.c. 25 | * 26 | */ 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #define RAWFB_RGBX_8888 39 | #define NK_INCLUDE_FIXED_TYPES 40 | #define NK_INCLUDE_STANDARD_IO 41 | #define NK_INCLUDE_STANDARD_VARARGS 42 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 43 | #define NK_IMPLEMENTATION 44 | #define NK_XLIBSHM_IMPLEMENTATION 45 | #define NK_RAWFB_IMPLEMENTATION 46 | #define NK_INCLUDE_FONT_BAKING 47 | #define NK_INCLUDE_DEFAULT_FONT 48 | #define NK_INCLUDE_SOFTWARE_FONT 49 | 50 | #include "../../nuklear.h" 51 | #include "nuklear_rawfb.h" 52 | #include "nuklear_xlib.h" 53 | 54 | #define DTIME 20 55 | #define WINDOW_WIDTH 800 56 | #define WINDOW_HEIGHT 600 57 | 58 | #define UNUSED(a) (void)a 59 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 60 | #define MAX(a,b) ((a) < (b) ? (b) : (a)) 61 | #define LEN(a) (sizeof(a)/sizeof(a)[0]) 62 | 63 | typedef struct XWindow XWindow; 64 | struct XWindow { 65 | Display *dpy; 66 | Window root; 67 | Visual *vis; 68 | Colormap cmap; 69 | XWindowAttributes attr; 70 | XSetWindowAttributes swa; 71 | Window win; 72 | int screen; 73 | unsigned int width; 74 | unsigned int height; 75 | }; 76 | 77 | static void 78 | die(const char *fmt, ...) 79 | { 80 | va_list ap; 81 | va_start(ap, fmt); 82 | vfprintf(stderr, fmt, ap); 83 | va_end(ap); 84 | fputs("\n", stderr); 85 | exit(EXIT_FAILURE); 86 | } 87 | 88 | static long 89 | timestamp(void) 90 | { 91 | struct timeval tv; 92 | if (gettimeofday(&tv, NULL) < 0) return 0; 93 | return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000); 94 | } 95 | 96 | static void 97 | sleep_for(long t) 98 | { 99 | struct timespec req; 100 | const time_t sec = (int)(t/1000); 101 | const long ms = t - (sec * 1000); 102 | req.tv_sec = sec; 103 | req.tv_nsec = ms * 1000000L; 104 | while(-1 == nanosleep(&req, &req)); 105 | } 106 | 107 | /* =============================================================== 108 | * 109 | * EXAMPLE 110 | * 111 | * ===============================================================*/ 112 | /* This are some code examples to provide a small overview of what can be 113 | * done with this library. To try out an example uncomment the defines */ 114 | /*#define INCLUDE_ALL */ 115 | /*#define INCLUDE_STYLE */ 116 | /*#define INCLUDE_CALCULATOR */ 117 | /*#define INCLUDE_OVERVIEW */ 118 | /*#define INCLUDE_NODE_EDITOR */ 119 | 120 | #ifdef INCLUDE_ALL 121 | #define INCLUDE_STYLE 122 | #define INCLUDE_CALCULATOR 123 | #define INCLUDE_OVERVIEW 124 | #define INCLUDE_NODE_EDITOR 125 | #endif 126 | 127 | #ifdef INCLUDE_STYLE 128 | #include "../style.c" 129 | #endif 130 | #ifdef INCLUDE_CALCULATOR 131 | #include "../calculator.c" 132 | #endif 133 | #ifdef INCLUDE_OVERVIEW 134 | #include "../overview.c" 135 | #endif 136 | #ifdef INCLUDE_NODE_EDITOR 137 | #include "../node_editor.c" 138 | #endif 139 | 140 | /* =============================================================== 141 | * 142 | * DEMO 143 | * 144 | * ===============================================================*/ 145 | int 146 | main(void) 147 | { 148 | long dt; 149 | long started; 150 | int running = 1; 151 | int status; 152 | XWindow xw; 153 | struct rawfb_context *rawfb; 154 | void *fb = NULL; 155 | unsigned char tex_scratch[512 * 512]; 156 | 157 | /* X11 */ 158 | memset(&xw, 0, sizeof xw); 159 | xw.dpy = XOpenDisplay(NULL); 160 | if (!xw.dpy) die("Could not open a display; perhaps $DISPLAY is not set?"); 161 | 162 | xw.root = DefaultRootWindow(xw.dpy); 163 | xw.screen = XDefaultScreen(xw.dpy); 164 | xw.vis = XDefaultVisual(xw.dpy, xw.screen); 165 | xw.cmap = XCreateColormap(xw.dpy,xw.root,xw.vis,AllocNone); 166 | xw.swa.colormap = xw.cmap; 167 | xw.swa.event_mask = 168 | ExposureMask | KeyPressMask | KeyReleaseMask | 169 | ButtonPress | ButtonReleaseMask| ButtonMotionMask | 170 | Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask| 171 | PointerMotionMask | KeymapStateMask | EnterWindowMask | LeaveWindowMask; 172 | xw.win = XCreateWindow(xw.dpy, xw.root, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 173 | XDefaultDepth(xw.dpy, xw.screen), InputOutput, 174 | xw.vis, CWEventMask | CWColormap, &xw.swa); 175 | 176 | XStoreName(xw.dpy, xw.win, "X11"); 177 | XMapWindow(xw.dpy, xw.win); 178 | XGetWindowAttributes(xw.dpy, xw.win, &xw.attr); 179 | xw.width = (unsigned int)xw.attr.width; 180 | xw.height = (unsigned int)xw.attr.height; 181 | 182 | /* Framebuffer emulator */ 183 | status = nk_xlib_init(xw.dpy, xw.vis, xw.screen, xw.win, xw.width, xw.height, &fb); 184 | if (!status || !fb) 185 | return 0; 186 | 187 | /* GUI */ 188 | rawfb = nk_rawfb_init(fb, tex_scratch, xw.width, xw.height, xw.width * 4); 189 | if (!rawfb) running = 0; 190 | 191 | #ifdef INCLUDE_STYLE 192 | /*set_style(ctx, THEME_WHITE);*/ 193 | /*set_style(ctx, THEME_RED);*/ 194 | /*set_style(ctx, THEME_BLUE);*/ 195 | /*set_style(ctx, THEME_DARK);*/ 196 | #endif 197 | 198 | while (running) { 199 | /* Input */ 200 | XEvent evt; 201 | started = timestamp(); 202 | nk_input_begin(&rawfb->ctx); 203 | while (XCheckWindowEvent(xw.dpy, xw.win, xw.swa.event_mask, &evt)) { 204 | if (XFilterEvent(&evt, xw.win)) continue; 205 | nk_xlib_handle_event(xw.dpy, xw.screen, xw.win, &evt, rawfb); 206 | } 207 | nk_input_end(&rawfb->ctx); 208 | 209 | /* GUI */ 210 | if (nk_begin(&rawfb->ctx, "Demo", nk_rect(50, 50, 200, 200), 211 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE| 212 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { 213 | enum {EASY, HARD}; 214 | static int op = EASY; 215 | static int property = 20; 216 | 217 | nk_layout_row_static(&rawfb->ctx, 30, 80, 1); 218 | if (nk_button_label(&rawfb->ctx, "button")) 219 | fprintf(stdout, "button pressed\n"); 220 | nk_layout_row_dynamic(&rawfb->ctx, 30, 2); 221 | if (nk_option_label(&rawfb->ctx, "easy", op == EASY)) op = EASY; 222 | if (nk_option_label(&rawfb->ctx, "hard", op == HARD)) op = HARD; 223 | nk_layout_row_dynamic(&rawfb->ctx, 25, 1); 224 | nk_property_int(&rawfb->ctx, "Compression:", 0, &property, 100, 10, 1); 225 | } 226 | nk_end(&rawfb->ctx); 227 | if (nk_window_is_closed(&rawfb->ctx, "Demo")) break; 228 | 229 | /* -------------- EXAMPLES ---------------- */ 230 | #ifdef INCLUDE_CALCULATOR 231 | calculator(ctx); 232 | #endif 233 | #ifdef INCLUDE_OVERVIEW 234 | overview(ctx); 235 | #endif 236 | #ifdef INCLUDE_NODE_EDITOR 237 | node_editor(ctx); 238 | #endif 239 | /* ----------------------------------------- */ 240 | 241 | /* Draw framebuffer */ 242 | nk_rawfb_render(rawfb, nk_rgb(30,30,30), 1); 243 | 244 | /* Emulate framebuffer */ 245 | XClearWindow(xw.dpy, xw.win); 246 | nk_xlib_render(xw.win); 247 | XFlush(xw.dpy); 248 | 249 | /* Timing */ 250 | dt = timestamp() - started; 251 | if (dt < DTIME) 252 | sleep_for(DTIME - dt); 253 | } 254 | 255 | nk_rawfb_shutdown(rawfb); 256 | nk_xlib_shutdown(); 257 | XUnmapWindow(xw.dpy, xw.win); 258 | XFreeColormap(xw.dpy, xw.cmap); 259 | XDestroyWindow(xw.dpy, xw.win); 260 | XCloseDisplay(xw.dpy); 261 | return 0; 262 | } 263 | 264 | -------------------------------------------------------------------------------- /demo/d3d11/main.c: -------------------------------------------------------------------------------- 1 | /* nuklear - 1.32.0 - public domain */ 2 | #define COBJMACROS 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define WINDOW_WIDTH 800 12 | #define WINDOW_HEIGHT 600 13 | 14 | #define MAX_VERTEX_BUFFER 512 * 1024 15 | #define MAX_INDEX_BUFFER 128 * 1024 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_INCLUDE_VERTEX_BUFFER_OUTPUT 22 | #define NK_INCLUDE_FONT_BAKING 23 | #define NK_INCLUDE_DEFAULT_FONT 24 | #define NK_IMPLEMENTATION 25 | #define NK_D3D11_IMPLEMENTATION 26 | #include "../../nuklear.h" 27 | #include "nuklear_d3d11.h" 28 | 29 | /* =============================================================== 30 | * 31 | * EXAMPLE 32 | * 33 | * ===============================================================*/ 34 | /* This are some code examples to provide a small overview of what can be 35 | * done with this library. To try out an example uncomment the defines */ 36 | /*#define INCLUDE_ALL */ 37 | /*#define INCLUDE_STYLE */ 38 | /*#define INCLUDE_CALCULATOR */ 39 | /*#define INCLUDE_OVERVIEW */ 40 | /*#define INCLUDE_NODE_EDITOR */ 41 | 42 | #ifdef INCLUDE_ALL 43 | #define INCLUDE_STYLE 44 | #define INCLUDE_CALCULATOR 45 | #define INCLUDE_OVERVIEW 46 | #define INCLUDE_NODE_EDITOR 47 | #endif 48 | 49 | #ifdef INCLUDE_STYLE 50 | #include "../style.c" 51 | #endif 52 | #ifdef INCLUDE_CALCULATOR 53 | #include "../calculator.c" 54 | #endif 55 | #ifdef INCLUDE_OVERVIEW 56 | #include "../overview.c" 57 | #endif 58 | #ifdef INCLUDE_NODE_EDITOR 59 | #include "../node_editor.c" 60 | #endif 61 | 62 | /* =============================================================== 63 | * 64 | * DEMO 65 | * 66 | * ===============================================================*/ 67 | static IDXGISwapChain *swap_chain; 68 | static ID3D11Device *device; 69 | static ID3D11DeviceContext *context; 70 | static ID3D11RenderTargetView* rt_view; 71 | 72 | static void 73 | set_swap_chain_size(int width, int height) 74 | { 75 | ID3D11Texture2D *back_buffer; 76 | D3D11_RENDER_TARGET_VIEW_DESC desc; 77 | HRESULT hr; 78 | 79 | if (rt_view) 80 | ID3D11RenderTargetView_Release(rt_view); 81 | 82 | ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, NULL); 83 | 84 | hr = IDXGISwapChain_ResizeBuffers(swap_chain, 0, width, height, DXGI_FORMAT_UNKNOWN, 0); 85 | if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET || hr == DXGI_ERROR_DRIVER_INTERNAL_ERROR) 86 | { 87 | /* to recover from this, you'll need to recreate device and all the resources */ 88 | MessageBoxW(NULL, L"DXGI device is removed or reset!", L"Error", 0); 89 | exit(0); 90 | } 91 | assert(SUCCEEDED(hr)); 92 | 93 | memset(&desc, 0, sizeof(desc)); 94 | desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 95 | desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; 96 | 97 | hr = IDXGISwapChain_GetBuffer(swap_chain, 0, &IID_ID3D11Texture2D, &back_buffer); 98 | assert(SUCCEEDED(hr)); 99 | 100 | hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)back_buffer, &desc, &rt_view); 101 | assert(SUCCEEDED(hr)); 102 | 103 | ID3D11Texture2D_Release(back_buffer); 104 | } 105 | 106 | static LRESULT CALLBACK 107 | WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) 108 | { 109 | switch (msg) 110 | { 111 | case WM_DESTROY: 112 | PostQuitMessage(0); 113 | return 0; 114 | 115 | case WM_SIZE: 116 | if (swap_chain) 117 | { 118 | int width = LOWORD(lparam); 119 | int height = HIWORD(lparam); 120 | set_swap_chain_size(width, height); 121 | nk_d3d11_resize(context, width, height); 122 | } 123 | break; 124 | } 125 | 126 | if (nk_d3d11_handle_event(wnd, msg, wparam, lparam)) 127 | return 0; 128 | 129 | return DefWindowProcW(wnd, msg, wparam, lparam); 130 | } 131 | 132 | int main(void) 133 | { 134 | struct nk_context *ctx; 135 | struct nk_colorf bg; 136 | 137 | WNDCLASSW wc; 138 | RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT }; 139 | DWORD style = WS_OVERLAPPEDWINDOW; 140 | DWORD exstyle = WS_EX_APPWINDOW; 141 | HWND wnd; 142 | int running = 1; 143 | HRESULT hr; 144 | D3D_FEATURE_LEVEL feature_level; 145 | DXGI_SWAP_CHAIN_DESC swap_chain_desc; 146 | 147 | /* Win32 */ 148 | memset(&wc, 0, sizeof(wc)); 149 | wc.style = CS_DBLCLKS; 150 | wc.lpfnWndProc = WindowProc; 151 | wc.hInstance = GetModuleHandleW(0); 152 | wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 153 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 154 | wc.lpszClassName = L"NuklearWindowClass"; 155 | RegisterClassW(&wc); 156 | 157 | AdjustWindowRectEx(&rect, style, FALSE, exstyle); 158 | 159 | wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo", 160 | style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 161 | rect.right - rect.left, rect.bottom - rect.top, 162 | NULL, NULL, wc.hInstance, NULL); 163 | 164 | /* D3D11 setup */ 165 | memset(&swap_chain_desc, 0, sizeof(swap_chain_desc)); 166 | swap_chain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 167 | swap_chain_desc.BufferDesc.RefreshRate.Numerator = 60; 168 | swap_chain_desc.BufferDesc.RefreshRate.Denominator = 1; 169 | swap_chain_desc.SampleDesc.Count = 1; 170 | swap_chain_desc.SampleDesc.Quality = 0; 171 | swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 172 | swap_chain_desc.BufferCount = 1; 173 | swap_chain_desc.OutputWindow = wnd; 174 | swap_chain_desc.Windowed = TRUE; 175 | swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; 176 | swap_chain_desc.Flags = 0; 177 | if (FAILED(D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, 178 | NULL, 0, NULL, 0, D3D11_SDK_VERSION, &swap_chain_desc, 179 | &swap_chain, &device, &feature_level, &context))) 180 | { 181 | /* if hardware device fails, then try WARP high-performance 182 | software rasterizer, this is useful for RDP sessions */ 183 | hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_WARP, 184 | NULL, 0, NULL, 0, D3D11_SDK_VERSION, &swap_chain_desc, 185 | &swap_chain, &device, &feature_level, &context); 186 | assert(SUCCEEDED(hr)); 187 | } 188 | set_swap_chain_size(WINDOW_WIDTH, WINDOW_HEIGHT); 189 | 190 | /* GUI */ 191 | ctx = nk_d3d11_init(device, WINDOW_WIDTH, WINDOW_HEIGHT, MAX_VERTEX_BUFFER, MAX_INDEX_BUFFER); 192 | /* Load Fonts: if none of these are loaded a default font will be used */ 193 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 194 | {struct nk_font_atlas *atlas; 195 | nk_d3d11_font_stash_begin(&atlas); 196 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../extra_font/DroidSans.ttf", 14, 0);*/ 197 | /*struct nk_font *robot = nk_font_atlas_add_from_file(atlas, "../../extra_font/Roboto-Regular.ttf", 14, 0);*/ 198 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 199 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../extra_font/ProggyClean.ttf", 12, 0);*/ 200 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../extra_font/ProggyTiny.ttf", 10, 0);*/ 201 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 202 | nk_d3d11_font_stash_end(); 203 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 204 | /*nk_style_set_font(ctx, &droid->handle)*/;} 205 | 206 | /* style.c */ 207 | #ifdef INCLUDE_STYLE 208 | /*set_style(ctx, THEME_WHITE);*/ 209 | /*set_style(ctx, THEME_RED);*/ 210 | /*set_style(ctx, THEME_BLUE);*/ 211 | /*set_style(ctx, THEME_DARK);*/ 212 | #endif 213 | 214 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 215 | while (running) 216 | { 217 | /* Input */ 218 | MSG msg; 219 | nk_input_begin(ctx); 220 | while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) 221 | { 222 | if (msg.message == WM_QUIT) 223 | running = 0; 224 | TranslateMessage(&msg); 225 | DispatchMessageW(&msg); 226 | } 227 | nk_input_end(ctx); 228 | 229 | /* GUI */ 230 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 231 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 232 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 233 | { 234 | enum {EASY, HARD}; 235 | static int op = EASY; 236 | static int property = 20; 237 | 238 | nk_layout_row_static(ctx, 30, 80, 1); 239 | if (nk_button_label(ctx, "button")) 240 | fprintf(stdout, "button pressed\n"); 241 | nk_layout_row_dynamic(ctx, 30, 2); 242 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 243 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 244 | nk_layout_row_dynamic(ctx, 22, 1); 245 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 246 | 247 | nk_layout_row_dynamic(ctx, 20, 1); 248 | nk_label(ctx, "background:", NK_TEXT_LEFT); 249 | nk_layout_row_dynamic(ctx, 25, 1); 250 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 251 | nk_layout_row_dynamic(ctx, 120, 1); 252 | bg = nk_color_picker(ctx, bg, NK_RGBA); 253 | nk_layout_row_dynamic(ctx, 25, 1); 254 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 255 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 256 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 257 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 258 | nk_combo_end(ctx); 259 | } 260 | } 261 | nk_end(ctx); 262 | 263 | /* -------------- EXAMPLES ---------------- */ 264 | #ifdef INCLUDE_CALCULATOR 265 | calculator(ctx); 266 | #endif 267 | #ifdef INCLUDE_OVERVIEW 268 | overview(ctx); 269 | #endif 270 | #ifdef INCLUDE_NODE_EDITOR 271 | node_editor(ctx); 272 | #endif 273 | /* ----------------------------------------- */ 274 | 275 | /* Draw */ 276 | ID3D11DeviceContext_ClearRenderTargetView(context, rt_view, &bg.r); 277 | ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rt_view, NULL); 278 | nk_d3d11_render(context, NK_ANTI_ALIASING_ON); 279 | hr = IDXGISwapChain_Present(swap_chain, 1, 0); 280 | if (hr == DXGI_ERROR_DEVICE_RESET || hr == DXGI_ERROR_DEVICE_REMOVED) { 281 | /* to recover from this, you'll need to recreate device and all the resources */ 282 | MessageBoxW(NULL, L"D3D11 device is lost or removed!", L"Error", 0); 283 | break; 284 | } else if (hr == DXGI_STATUS_OCCLUDED) { 285 | /* window is not visible, so vsync won't work. Let's sleep a bit to reduce CPU usage */ 286 | Sleep(10); 287 | } 288 | assert(SUCCEEDED(hr)); 289 | } 290 | 291 | ID3D11DeviceContext_ClearState(context); 292 | nk_d3d11_shutdown(); 293 | ID3D11ShaderResourceView_Release(rt_view); 294 | ID3D11DeviceContext_Release(context); 295 | ID3D11Device_Release(device); 296 | IDXGISwapChain_Release(swap_chain); 297 | UnregisterClassW(wc.lpszClassName, wc.hInstance); 298 | return 0; 299 | } 300 | -------------------------------------------------------------------------------- /demo/x11_rawfb/nuklear_xlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2016-2017 Patrick Rudolph 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | 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 | * Based on x11/nuklear_xlib.h. 25 | */ 26 | /* 27 | * ============================================================== 28 | * 29 | * API 30 | * 31 | * =============================================================== 32 | */ 33 | #ifndef NK_XLIBSHM_H_ 34 | #define NK_XLIBSHM_H_ 35 | 36 | #include 37 | 38 | NK_API int nk_xlib_init(Display *dpy, Visual *vis, int screen, Window root, unsigned int w, unsigned int h, void **fb); 39 | NK_API int nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt, struct rawfb_context *rawfb); 40 | NK_API void nk_xlib_render(Drawable screen); 41 | NK_API void nk_xlib_shutdown(void); 42 | 43 | #endif 44 | /* 45 | * ============================================================== 46 | * 47 | * IMPLEMENTATION 48 | * 49 | * =============================================================== 50 | */ 51 | #ifdef NK_XLIBSHM_IMPLEMENTATION 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | 60 | static struct { 61 | struct nk_context ctx; 62 | struct XSurface *surf; 63 | Cursor cursor; 64 | Display *dpy; 65 | Window root; 66 | XImage *ximg; 67 | XShmSegmentInfo xsi; 68 | char fallback; 69 | GC gc; 70 | } xlib; 71 | 72 | NK_API int 73 | nk_xlib_init(Display *dpy, Visual *vis, int screen, Window root, 74 | unsigned int w, unsigned int h, void **fb) 75 | { 76 | unsigned int depth = XDefaultDepth(dpy, screen); 77 | xlib.dpy = dpy; 78 | xlib.root = root; 79 | 80 | if (!setlocale(LC_ALL,"")) return 0; 81 | if (!XSupportsLocale()) return 0; 82 | if (!XSetLocaleModifiers("@im=none")) return 0; 83 | 84 | /* create invisible cursor */ 85 | {static XColor dummy; char data[1] = {0}; 86 | Pixmap blank = XCreateBitmapFromData(dpy, root, data, 1, 1); 87 | if (blank == None) return 0; 88 | xlib.cursor = XCreatePixmapCursor(dpy, blank, blank, &dummy, &dummy, 0, 0); 89 | XFreePixmap(dpy, blank);} 90 | 91 | xlib.fallback = False; 92 | do {/* Initialize shared memory according to: 93 | * https://www.x.org/archive/X11R7.5/doc/Xext/mit-shm.html */ 94 | int status; 95 | if (!XShmQueryExtension(dpy)) { 96 | printf("No XShm Extension available.\n"); 97 | xlib.fallback = True; 98 | break; 99 | } 100 | xlib.ximg = XShmCreateImage(dpy, vis, depth, ZPixmap, NULL, &xlib.xsi, w, h); 101 | if (!xlib.ximg) { 102 | xlib.fallback = True; 103 | break; 104 | } 105 | xlib.xsi.shmid = shmget(IPC_PRIVATE, xlib.ximg->bytes_per_line * xlib.ximg->height, IPC_CREAT | 0777); 106 | if (xlib.xsi.shmid < 0) { 107 | XDestroyImage(xlib.ximg); 108 | xlib.fallback = True; 109 | break; 110 | } 111 | xlib.xsi.shmaddr = xlib.ximg->data = shmat(xlib.xsi.shmid, NULL, 0); 112 | if ((size_t)xlib.xsi.shmaddr < 0) { 113 | XDestroyImage(xlib.ximg); 114 | xlib.fallback = True; 115 | break; 116 | } 117 | xlib.xsi.readOnly = False; 118 | status = XShmAttach(dpy, &xlib.xsi); 119 | if (!status) { 120 | shmdt(xlib.xsi.shmaddr); 121 | XDestroyImage(xlib.ximg); 122 | xlib.fallback = True; 123 | break; 124 | } XSync(dpy, False); 125 | shmctl(xlib.xsi.shmid, IPC_RMID, NULL); 126 | } while(0); 127 | 128 | if (xlib.fallback) { 129 | xlib.ximg = XCreateImage(dpy, vis, depth, ZPixmap, 0, NULL, w, h, 32, 0); 130 | if (!xlib.ximg) return 0; 131 | xlib.ximg->data = malloc(h * xlib.ximg->bytes_per_line); 132 | if (!xlib.ximg->data) 133 | return 0; 134 | } 135 | xlib.gc = XDefaultGC(dpy, screen); 136 | *fb = xlib.ximg->data; 137 | return 1; 138 | } 139 | 140 | NK_API int 141 | nk_xlib_handle_event(Display *dpy, int screen, Window win, XEvent *evt, struct rawfb_context *rawfb) 142 | { 143 | /* optional grabbing behavior */ 144 | if (rawfb->ctx.input.mouse.grab) { 145 | /* XDefineCursor(xlib.dpy, xlib.root, xlib.cursor); */ 146 | rawfb->ctx.input.mouse.grab = 0; 147 | } else if (rawfb->ctx.input.mouse.ungrab) { 148 | XWarpPointer(xlib.dpy, None, xlib.root, 0, 0, 0, 0, 149 | (int)rawfb->ctx.input.mouse.prev.x, (int)rawfb->ctx.input.mouse.prev.y); 150 | /* XUndefineCursor(xlib.dpy, xlib.root); */ 151 | rawfb->ctx.input.mouse.ungrab = 0; 152 | } 153 | 154 | if (evt->type == KeyPress || evt->type == KeyRelease) 155 | { 156 | /* Key handler */ 157 | int ret, down = (evt->type == KeyPress); 158 | KeySym *code = XGetKeyboardMapping(xlib.dpy, (KeyCode)evt->xkey.keycode, 1, &ret); 159 | if (*code == XK_Shift_L || *code == XK_Shift_R) nk_input_key(&rawfb->ctx, NK_KEY_SHIFT, down); 160 | else if (*code == XK_Delete) nk_input_key(&rawfb->ctx, NK_KEY_DEL, down); 161 | else if (*code == XK_Return) nk_input_key(&rawfb->ctx, NK_KEY_ENTER, down); 162 | else if (*code == XK_Tab) nk_input_key(&rawfb->ctx, NK_KEY_TAB, down); 163 | else if (*code == XK_Left) nk_input_key(&rawfb->ctx, NK_KEY_LEFT, down); 164 | else if (*code == XK_Right) nk_input_key(&rawfb->ctx, NK_KEY_RIGHT, down); 165 | else if (*code == XK_Up) nk_input_key(&rawfb->ctx, NK_KEY_UP, down); 166 | else if (*code == XK_Down) nk_input_key(&rawfb->ctx, NK_KEY_DOWN, down); 167 | else if (*code == XK_BackSpace) nk_input_key(&rawfb->ctx, NK_KEY_BACKSPACE, down); 168 | else if (*code == XK_Escape) nk_input_key(&rawfb->ctx, NK_KEY_TEXT_RESET_MODE, down); 169 | else if (*code == XK_Page_Up) nk_input_key(&rawfb->ctx, NK_KEY_SCROLL_UP, down); 170 | else if (*code == XK_Page_Down) nk_input_key(&rawfb->ctx, NK_KEY_SCROLL_DOWN, down); 171 | else if (*code == XK_Home) { 172 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_START, down); 173 | nk_input_key(&rawfb->ctx, NK_KEY_SCROLL_START, down); 174 | } else if (*code == XK_End) { 175 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_END, down); 176 | nk_input_key(&rawfb->ctx, NK_KEY_SCROLL_END, down); 177 | } else { 178 | if (*code == 'c' && (evt->xkey.state & ControlMask)) 179 | nk_input_key(&rawfb->ctx, NK_KEY_COPY, down); 180 | else if (*code == 'v' && (evt->xkey.state & ControlMask)) 181 | nk_input_key(&rawfb->ctx, NK_KEY_PASTE, down); 182 | else if (*code == 'x' && (evt->xkey.state & ControlMask)) 183 | nk_input_key(&rawfb->ctx, NK_KEY_CUT, down); 184 | else if (*code == 'z' && (evt->xkey.state & ControlMask)) 185 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_UNDO, down); 186 | else if (*code == 'r' && (evt->xkey.state & ControlMask)) 187 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_REDO, down); 188 | else if (*code == XK_Left && (evt->xkey.state & ControlMask)) 189 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_WORD_LEFT, down); 190 | else if (*code == XK_Right && (evt->xkey.state & ControlMask)) 191 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_WORD_RIGHT, down); 192 | else if (*code == 'b' && (evt->xkey.state & ControlMask)) 193 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_LINE_START, down); 194 | else if (*code == 'e' && (evt->xkey.state & ControlMask)) 195 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_LINE_END, down); 196 | else { 197 | if (*code == 'i') 198 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_INSERT_MODE, down); 199 | else if (*code == 'r') 200 | nk_input_key(&rawfb->ctx, NK_KEY_TEXT_REPLACE_MODE, down); 201 | if (down) { 202 | char buf[32]; 203 | KeySym keysym = 0; 204 | if (XLookupString((XKeyEvent*)evt, buf, 32, &keysym, NULL) != NoSymbol) 205 | nk_input_glyph(&rawfb->ctx, buf); 206 | } 207 | } 208 | } XFree(code); 209 | return 1; 210 | } else if (evt->type == ButtonPress || evt->type == ButtonRelease) { 211 | /* Button handler */ 212 | int down = (evt->type == ButtonPress); 213 | const int x = evt->xbutton.x, y = evt->xbutton.y; 214 | if (evt->xbutton.button == Button1) 215 | nk_input_button(&rawfb->ctx, NK_BUTTON_LEFT, x, y, down); 216 | if (evt->xbutton.button == Button2) 217 | nk_input_button(&rawfb->ctx, NK_BUTTON_MIDDLE, x, y, down); 218 | else if (evt->xbutton.button == Button3) 219 | nk_input_button(&rawfb->ctx, NK_BUTTON_RIGHT, x, y, down); 220 | else if (evt->xbutton.button == Button4) 221 | nk_input_scroll(&rawfb->ctx, nk_vec2(0, 1.0f)); 222 | else if (evt->xbutton.button == Button5) 223 | nk_input_scroll(&rawfb->ctx, nk_vec2(0, -1.0f)); 224 | else return 0; 225 | return 1; 226 | } else if (evt->type == MotionNotify) { 227 | /* Mouse motion handler */ 228 | const int x = evt->xmotion.x, y = evt->xmotion.y; 229 | nk_input_motion(&rawfb->ctx, x, y); 230 | if (rawfb->ctx.input.mouse.grabbed) { 231 | rawfb->ctx.input.mouse.pos.x = rawfb->ctx.input.mouse.prev.x; 232 | rawfb->ctx.input.mouse.pos.y = rawfb->ctx.input.mouse.prev.y; 233 | XWarpPointer(xlib.dpy, None, xlib.root, 0, 0, 0, 0, (int)rawfb->ctx.input.mouse.pos.x, (int)rawfb->ctx.input.mouse.pos.y); 234 | } return 1; 235 | } else if (evt->type == Expose || evt->type == ConfigureNotify) { 236 | /* Window resize handler */ 237 | void *fb; 238 | unsigned int width, height; 239 | XWindowAttributes attr; 240 | XGetWindowAttributes(dpy, win, &attr); 241 | 242 | width = (unsigned int)attr.width; 243 | height = (unsigned int)attr.height; 244 | 245 | nk_xlib_shutdown(); 246 | nk_xlib_init(dpy, XDefaultVisual(dpy, screen), screen, win, width, height, &fb); 247 | nk_rawfb_resize_fb(rawfb, fb, width, height, width * 4); 248 | } else if (evt->type == KeymapNotify) { 249 | XRefreshKeyboardMapping(&evt->xmapping); 250 | return 1; 251 | } else if (evt->type == LeaveNotify) { 252 | XUndefineCursor(xlib.dpy, xlib.root); 253 | } else if (evt->type == EnterNotify) { 254 | XDefineCursor(xlib.dpy, xlib.root, xlib.cursor); 255 | } return 0; 256 | } 257 | 258 | NK_API void 259 | nk_xlib_shutdown(void) 260 | { 261 | XFreeCursor(xlib.dpy, xlib.cursor); 262 | if (xlib.fallback) { 263 | free(xlib.ximg->data); 264 | XDestroyImage(xlib.ximg); 265 | } else { 266 | XShmDetach(xlib.dpy, &xlib.xsi); 267 | XDestroyImage(xlib.ximg); 268 | shmdt(xlib.xsi.shmaddr); 269 | shmctl(xlib.xsi.shmid, IPC_RMID, NULL); 270 | } nk_memset(&xlib, 0, sizeof(xlib)); 271 | } 272 | 273 | NK_API void 274 | nk_xlib_render(Drawable screen) 275 | { 276 | if (xlib.fallback) 277 | XPutImage(xlib.dpy, screen, xlib.gc, xlib.ximg, 278 | 0, 0, 0, 0, xlib.ximg->width, xlib.ximg->height); 279 | else XShmPutImage(xlib.dpy, screen, xlib.gc, xlib.ximg, 280 | 0, 0, 0, 0, xlib.ximg->width, xlib.ximg->height, False); 281 | } 282 | #endif 283 | 284 | -------------------------------------------------------------------------------- /demo/d3d9/main.c: -------------------------------------------------------------------------------- 1 | /* nuklear - 1.32.0 - public domain */ 2 | #define COBJMACROS 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define WINDOW_WIDTH 800 12 | #define WINDOW_HEIGHT 600 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_D3D9_IMPLEMENTATION 23 | #include "../../nuklear.h" 24 | #include "nuklear_d3d9.h" 25 | 26 | /* =============================================================== 27 | * 28 | * EXAMPLE 29 | * 30 | * ===============================================================*/ 31 | /* This are some code examples to provide a small overview of what can be 32 | * done with this library. To try out an example uncomment the defines */ 33 | /*#define INCLUDE_ALL */ 34 | /*#define INCLUDE_STYLE */ 35 | /*#define INCLUDE_CALCULATOR */ 36 | /*#define INCLUDE_OVERVIEW */ 37 | /*#define INCLUDE_NODE_EDITOR */ 38 | 39 | #ifdef INCLUDE_ALL 40 | #define INCLUDE_STYLE 41 | #define INCLUDE_CALCULATOR 42 | #define INCLUDE_OVERVIEW 43 | #define INCLUDE_NODE_EDITOR 44 | #endif 45 | 46 | #ifdef INCLUDE_STYLE 47 | #include "../style.c" 48 | #endif 49 | #ifdef INCLUDE_CALCULATOR 50 | #include "../calculator.c" 51 | #endif 52 | #ifdef INCLUDE_OVERVIEW 53 | #include "../overview.c" 54 | #endif 55 | #ifdef INCLUDE_NODE_EDITOR 56 | #include "../node_editor.c" 57 | #endif 58 | 59 | /* =============================================================== 60 | * 61 | * DEMO 62 | * 63 | * ===============================================================*/ 64 | static IDirect3DDevice9 *device; 65 | static IDirect3DDevice9Ex *deviceEx; 66 | static D3DPRESENT_PARAMETERS present; 67 | 68 | static LRESULT CALLBACK 69 | WindowProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam) 70 | { 71 | switch (msg) 72 | { 73 | case WM_DESTROY: 74 | PostQuitMessage(0); 75 | return 0; 76 | 77 | case WM_SIZE: 78 | if (device) 79 | { 80 | UINT width = LOWORD(lparam); 81 | UINT height = HIWORD(lparam); 82 | if (width != 0 && height != 0 && 83 | (width != present.BackBufferWidth || height != present.BackBufferHeight)) 84 | { 85 | nk_d3d9_release(); 86 | present.BackBufferWidth = width; 87 | present.BackBufferHeight = height; 88 | HRESULT hr = IDirect3DDevice9_Reset(device, &present); 89 | NK_ASSERT(SUCCEEDED(hr)); 90 | nk_d3d9_resize(width, height); 91 | } 92 | } 93 | break; 94 | } 95 | 96 | if (nk_d3d9_handle_event(wnd, msg, wparam, lparam)) 97 | return 0; 98 | 99 | return DefWindowProcW(wnd, msg, wparam, lparam); 100 | } 101 | 102 | static void create_d3d9_device(HWND wnd) 103 | { 104 | HRESULT hr; 105 | 106 | present.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; 107 | present.BackBufferWidth = WINDOW_WIDTH; 108 | present.BackBufferHeight = WINDOW_HEIGHT; 109 | present.BackBufferFormat = D3DFMT_X8R8G8B8; 110 | present.BackBufferCount = 1; 111 | present.MultiSampleType = D3DMULTISAMPLE_NONE; 112 | present.SwapEffect = D3DSWAPEFFECT_DISCARD; 113 | present.hDeviceWindow = wnd; 114 | present.EnableAutoDepthStencil = TRUE; 115 | present.AutoDepthStencilFormat = D3DFMT_D24S8; 116 | present.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; 117 | present.Windowed = TRUE; 118 | 119 | {/* first try to create Direct3D9Ex device if possible (on Windows 7+) */ 120 | typedef HRESULT WINAPI Direct3DCreate9ExPtr(UINT, IDirect3D9Ex**); 121 | Direct3DCreate9ExPtr *Direct3DCreate9Ex = (void *)GetProcAddress(GetModuleHandleA("d3d9.dll"), "Direct3DCreate9Ex"); 122 | if (Direct3DCreate9Ex) { 123 | IDirect3D9Ex *d3d9ex; 124 | if (SUCCEEDED(Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex))) { 125 | hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, 126 | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE | D3DCREATE_FPU_PRESERVE, 127 | &present, NULL, &deviceEx); 128 | if (SUCCEEDED(hr)) { 129 | device = (IDirect3DDevice9 *)deviceEx; 130 | } else { 131 | /* hardware vertex processing not supported, no big deal 132 | retry with software vertex processing */ 133 | hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, 134 | D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE | D3DCREATE_FPU_PRESERVE, 135 | &present, NULL, &deviceEx); 136 | if (SUCCEEDED(hr)) { 137 | device = (IDirect3DDevice9 *)deviceEx; 138 | } 139 | } 140 | IDirect3D9Ex_Release(d3d9ex); 141 | } 142 | } 143 | } 144 | 145 | if (!device) { 146 | /* otherwise do regular D3D9 setup */ 147 | IDirect3D9 *d3d9 = Direct3DCreate9(D3D_SDK_VERSION); 148 | 149 | hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, 150 | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE | D3DCREATE_FPU_PRESERVE, 151 | &present, &device); 152 | if (FAILED(hr)) { 153 | /* hardware vertex processing not supported, no big deal 154 | retry with software vertex processing */ 155 | hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, 156 | D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE | D3DCREATE_FPU_PRESERVE, 157 | &present, &device); 158 | NK_ASSERT(SUCCEEDED(hr)); 159 | } 160 | IDirect3D9_Release(d3d9); 161 | } 162 | } 163 | 164 | int main(void) 165 | { 166 | struct nk_context *ctx; 167 | struct nk_colorf bg; 168 | 169 | WNDCLASSW wc; 170 | RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT }; 171 | DWORD style = WS_OVERLAPPEDWINDOW; 172 | DWORD exstyle = WS_EX_APPWINDOW; 173 | HWND wnd; 174 | int running = 1; 175 | 176 | /* Win32 */ 177 | memset(&wc, 0, sizeof(wc)); 178 | wc.style = CS_DBLCLKS; 179 | wc.lpfnWndProc = WindowProc; 180 | wc.hInstance = GetModuleHandleW(0); 181 | wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 182 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 183 | wc.lpszClassName = L"NuklearWindowClass"; 184 | RegisterClassW(&wc); 185 | 186 | AdjustWindowRectEx(&rect, style, FALSE, exstyle); 187 | 188 | wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"Nuklear Demo", 189 | style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 190 | rect.right - rect.left, rect.bottom - rect.top, 191 | NULL, NULL, wc.hInstance, NULL); 192 | 193 | create_d3d9_device(wnd); 194 | 195 | /* GUI */ 196 | ctx = nk_d3d9_init(device, WINDOW_WIDTH, WINDOW_HEIGHT); 197 | /* Load Fonts: if none of these are loaded a default font will be used */ 198 | /* Load Cursor: if you uncomment cursor loading please hide the cursor */ 199 | {struct nk_font_atlas *atlas; 200 | nk_d3d9_font_stash_begin(&atlas); 201 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../extra_font/DroidSans.ttf", 14, 0);*/ 202 | /*struct nk_font *robot = nk_font_atlas_add_from_file(atlas, "../../extra_font/Roboto-Regular.ttf", 14, 0);*/ 203 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 204 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../extra_font/ProggyClean.ttf", 12, 0);*/ 205 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../extra_font/ProggyTiny.ttf", 10, 0);*/ 206 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 207 | nk_d3d9_font_stash_end(); 208 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 209 | /*nk_style_set_font(ctx, &droid->handle)*/;} 210 | 211 | /* style.c */ 212 | #ifdef INCLUDE_STYLE 213 | /*set_style(ctx, THEME_WHITE);*/ 214 | /*set_style(ctx, THEME_RED);*/ 215 | /*set_style(ctx, THEME_BLUE);*/ 216 | /*set_style(ctx, THEME_DARK);*/ 217 | #endif 218 | 219 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 220 | while (running) 221 | { 222 | /* Input */ 223 | MSG msg; 224 | nk_input_begin(ctx); 225 | while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { 226 | if (msg.message == WM_QUIT) 227 | running = 0; 228 | TranslateMessage(&msg); 229 | DispatchMessageW(&msg); 230 | } 231 | nk_input_end(ctx); 232 | 233 | /* GUI */ 234 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 235 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 236 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 237 | { 238 | enum {EASY, HARD}; 239 | static int op = EASY; 240 | static int property = 20; 241 | 242 | nk_layout_row_static(ctx, 30, 80, 1); 243 | if (nk_button_label(ctx, "button")) 244 | fprintf(stdout, "button pressed\n"); 245 | nk_layout_row_dynamic(ctx, 30, 2); 246 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 247 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 248 | nk_layout_row_dynamic(ctx, 22, 1); 249 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 250 | 251 | nk_layout_row_dynamic(ctx, 20, 1); 252 | nk_label(ctx, "background:", NK_TEXT_LEFT); 253 | nk_layout_row_dynamic(ctx, 25, 1); 254 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 255 | nk_layout_row_dynamic(ctx, 120, 1); 256 | bg = nk_color_picker(ctx, bg, NK_RGBA); 257 | nk_layout_row_dynamic(ctx, 25, 1); 258 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 259 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 260 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 261 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 262 | nk_combo_end(ctx); 263 | } 264 | } 265 | nk_end(ctx); 266 | 267 | /* -------------- EXAMPLES ---------------- */ 268 | #ifdef INCLUDE_CALCULATOR 269 | calculator(ctx); 270 | #endif 271 | #ifdef INCLUDE_OVERVIEW 272 | overview(ctx); 273 | #endif 274 | #ifdef INCLUDE_NODE_EDITOR 275 | node_editor(ctx); 276 | #endif 277 | /* ----------------------------------------- */ 278 | 279 | /* Draw */ 280 | { 281 | HRESULT hr; 282 | hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 283 | D3DCOLOR_COLORVALUE(bg.a, bg.r, bg.g, bg.b), 0.0f, 0); 284 | NK_ASSERT(SUCCEEDED(hr)); 285 | 286 | hr = IDirect3DDevice9_BeginScene(device); 287 | NK_ASSERT(SUCCEEDED(hr)); 288 | nk_d3d9_render(NK_ANTI_ALIASING_ON); 289 | hr = IDirect3DDevice9_EndScene(device); 290 | NK_ASSERT(SUCCEEDED(hr)); 291 | 292 | if (deviceEx) { 293 | hr = IDirect3DDevice9Ex_PresentEx(deviceEx, NULL, NULL, NULL, NULL, 0); 294 | } else { 295 | hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); 296 | } 297 | if (hr == D3DERR_DEVICELOST || hr == D3DERR_DEVICEHUNG || hr == D3DERR_DEVICEREMOVED) { 298 | /* to recover from this, you'll need to recreate device and all the resources */ 299 | MessageBoxW(NULL, L"D3D9 device is lost or removed!", L"Error", 0); 300 | break; 301 | } else if (hr == S_PRESENT_OCCLUDED) { 302 | /* window is not visible, so vsync won't work. Let's sleep a bit to reduce CPU usage */ 303 | Sleep(10); 304 | } 305 | NK_ASSERT(SUCCEEDED(hr)); 306 | } 307 | } 308 | nk_d3d9_shutdown(); 309 | if (deviceEx)IDirect3DDevice9Ex_Release(deviceEx); 310 | else IDirect3DDevice9_Release(device); 311 | UnregisterClassW(wc.lpszClassName, wc.hInstance); 312 | return 0; 313 | } 314 | -------------------------------------------------------------------------------- /demo/d3d11/nuklear_d3d11_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 | // 24 | // Constant buffer to DX9 shader constant mappings: 25 | // 26 | // Target Reg Buffer Start Reg # of Regs Data Conversion 27 | // ---------- ------- --------- --------- ---------------------- 28 | // c1 cb0 0 4 ( FLT, FLT, FLT, FLT) 29 | // 30 | // 31 | // Runtime generated constant mappings: 32 | // 33 | // Target Reg Constant Description 34 | // ---------- -------------------------------------------------- 35 | // c0 Vertex Shader position offset 36 | // 37 | // 38 | // Level9 shader bytecode: 39 | // 40 | vs_2_0 41 | def c5, 0, 1, 0, 0 42 | dcl_texcoord v0 43 | dcl_texcoord1 v1 44 | dcl_texcoord2 v2 45 | mul r0, v0.x, c1 46 | mad r0, c2, v0.y, r0 47 | mov r1.xy, c5 48 | mad r0, c3, r1.x, r0 49 | mad r0, c4, r1.y, r0 50 | mul r1.xy, r0.w, c0 51 | add oPos.xy, r0, r1 52 | mov oPos.zw, r0 53 | mov oT0, v1 54 | mov oT1.xy, v2 55 | 56 | // approximately 10 instruction slots used 57 | // 58 | // Constant buffer to DX9 shader constant mappings: 59 | // 60 | // Target Reg Buffer Start Reg # of Regs Data Conversion 61 | // ---------- ------- --------- --------- ---------------------- 62 | // c0 cb0 0 4 ( FLT, FLT, FLT, FLT) 63 | // 64 | // 65 | // XNA Prepass shader bytecode: 66 | // 67 | vs_2_0 68 | def c4, 0, 1, 0, 0 69 | dcl_texcoord v0 70 | mul r1, r0.x, c0 71 | mad r0, c1, r0.y, r1 72 | mov r1.xy, c4 73 | mad r0, c2, r1.x, r0 74 | mad r0, c3, r1.y, r0 75 | mov oPos, r0 76 | 77 | // approximately 6 instruction slots used 78 | // 79 | // Constant buffer to DX9 shader constant mappings: 80 | // 81 | // Target Reg Buffer Start Reg # of Regs Data Conversion 82 | // ---------- ------- --------- --------- ---------------------- 83 | // c0 cb0 0 4 ( FLT, FLT, FLT, FLT) 84 | // 85 | // 86 | // XNA shader bytecode: 87 | // 88 | vs_2_0 89 | def c4, 0, 1, 0, 0 90 | dcl_texcoord v0 91 | dcl_texcoord1 v1 92 | dcl_texcoord2 v2 93 | mov oT0, r1 94 | mov oT1.xy, r2 95 | mul r1, r0.x, c0 96 | mad r0, c1, r0.y, r1 97 | mov r1.xy, c4 98 | mad r0, c2, r1.x, r0 99 | mad r0, c3, r1.y, r0 100 | mov oPos, r0 101 | 102 | // approximately 8 instruction slots used 103 | vs_4_0 104 | dcl_constantbuffer cb0[4], immediateIndexed 105 | dcl_input v0.xy 106 | dcl_input v1.xyzw 107 | dcl_input v2.xy 108 | dcl_output_siv o0.xyzw, position 109 | dcl_output o1.xyzw 110 | dcl_output o2.xy 111 | dcl_temps 1 112 | mul r0.xyzw, v0.xxxx, cb0[0].xyzw 113 | mad r0.xyzw, cb0[1].xyzw, v0.yyyy, r0.xyzw 114 | mad r0.xyzw, cb0[2].xyzw, l(0.000000, 0.000000, 0.000000, 0.000000), r0.xyzw 115 | mad o0.xyzw, cb0[3].xyzw, l(1.000000, 1.000000, 1.000000, 1.000000), r0.xyzw 116 | mov o1.xyzw, v1.xyzw 117 | mov o2.xy, v2.xyxx 118 | ret 119 | // Approximately 0 instruction slots used 120 | #endif 121 | 122 | const BYTE nk_d3d11_vertex_shader[] = 123 | { 124 | 68, 88, 66, 67, 215, 245, 125 | 86, 155, 188, 117, 37, 118, 126 | 193, 207, 209, 90, 160, 153, 127 | 246, 188, 1, 0, 0, 0, 128 | 72, 5, 0, 0, 6, 0, 129 | 0, 0, 56, 0, 0, 0, 130 | 48, 1, 0, 0, 248, 1, 131 | 0, 0, 20, 3, 0, 0, 132 | 100, 4, 0, 0, 212, 4, 133 | 0, 0, 88, 78, 65, 83, 134 | 240, 0, 0, 0, 240, 0, 135 | 0, 0, 0, 2, 254, 255, 136 | 192, 0, 0, 0, 48, 0, 137 | 0, 0, 1, 0, 36, 0, 138 | 0, 0, 48, 0, 0, 0, 139 | 48, 0, 0, 0, 36, 0, 140 | 0, 0, 48, 0, 0, 0, 141 | 0, 0, 4, 0, 0, 0, 142 | 0, 0, 0, 0, 0, 2, 143 | 254, 255, 81, 0, 0, 5, 144 | 4, 0, 15, 160, 0, 0, 145 | 0, 0, 0, 0, 128, 63, 146 | 0, 0, 0, 0, 0, 0, 147 | 0, 0, 31, 0, 0, 2, 148 | 5, 0, 0, 128, 0, 0, 149 | 15, 144, 31, 0, 0, 2, 150 | 5, 0, 1, 128, 1, 0, 151 | 15, 144, 31, 0, 0, 2, 152 | 5, 0, 2, 128, 2, 0, 153 | 15, 144, 1, 0, 0, 2, 154 | 0, 0, 15, 224, 1, 0, 155 | 228, 128, 1, 0, 0, 2, 156 | 1, 0, 3, 224, 2, 0, 157 | 228, 128, 5, 0, 0, 3, 158 | 1, 0, 15, 128, 0, 0, 159 | 0, 128, 0, 0, 228, 160, 160 | 4, 0, 0, 4, 0, 0, 161 | 15, 128, 1, 0, 228, 160, 162 | 0, 0, 85, 128, 1, 0, 163 | 228, 128, 1, 0, 0, 2, 164 | 1, 0, 3, 128, 4, 0, 165 | 228, 160, 4, 0, 0, 4, 166 | 0, 0, 15, 128, 2, 0, 167 | 228, 160, 1, 0, 0, 128, 168 | 0, 0, 228, 128, 4, 0, 169 | 0, 4, 0, 0, 15, 128, 170 | 3, 0, 228, 160, 1, 0, 171 | 85, 128, 0, 0, 228, 128, 172 | 1, 0, 0, 2, 0, 0, 173 | 15, 192, 0, 0, 228, 128, 174 | 255, 255, 0, 0, 88, 78, 175 | 65, 80, 192, 0, 0, 0, 176 | 192, 0, 0, 0, 0, 2, 177 | 254, 255, 144, 0, 0, 0, 178 | 48, 0, 0, 0, 1, 0, 179 | 36, 0, 0, 0, 48, 0, 180 | 0, 0, 48, 0, 0, 0, 181 | 36, 0, 0, 0, 48, 0, 182 | 0, 0, 0, 0, 4, 0, 183 | 0, 0, 0, 0, 0, 0, 184 | 0, 2, 254, 255, 81, 0, 185 | 0, 5, 4, 0, 15, 160, 186 | 0, 0, 0, 0, 0, 0, 187 | 128, 63, 0, 0, 0, 0, 188 | 0, 0, 0, 0, 31, 0, 189 | 0, 2, 5, 0, 0, 128, 190 | 0, 0, 15, 144, 5, 0, 191 | 0, 3, 1, 0, 15, 128, 192 | 0, 0, 0, 128, 0, 0, 193 | 228, 160, 4, 0, 0, 4, 194 | 0, 0, 15, 128, 1, 0, 195 | 228, 160, 0, 0, 85, 128, 196 | 1, 0, 228, 128, 1, 0, 197 | 0, 2, 1, 0, 3, 128, 198 | 4, 0, 228, 160, 4, 0, 199 | 0, 4, 0, 0, 15, 128, 200 | 2, 0, 228, 160, 1, 0, 201 | 0, 128, 0, 0, 228, 128, 202 | 4, 0, 0, 4, 0, 0, 203 | 15, 128, 3, 0, 228, 160, 204 | 1, 0, 85, 128, 0, 0, 205 | 228, 128, 1, 0, 0, 2, 206 | 0, 0, 15, 192, 0, 0, 207 | 228, 128, 255, 255, 0, 0, 208 | 65, 111, 110, 57, 20, 1, 209 | 0, 0, 20, 1, 0, 0, 210 | 0, 2, 254, 255, 224, 0, 211 | 0, 0, 52, 0, 0, 0, 212 | 1, 0, 36, 0, 0, 0, 213 | 48, 0, 0, 0, 48, 0, 214 | 0, 0, 36, 0, 1, 0, 215 | 48, 0, 0, 0, 0, 0, 216 | 4, 0, 1, 0, 0, 0, 217 | 0, 0, 0, 0, 0, 0, 218 | 0, 2, 254, 255, 81, 0, 219 | 0, 5, 5, 0, 15, 160, 220 | 0, 0, 0, 0, 0, 0, 221 | 128, 63, 0, 0, 0, 0, 222 | 0, 0, 0, 0, 31, 0, 223 | 0, 2, 5, 0, 0, 128, 224 | 0, 0, 15, 144, 31, 0, 225 | 0, 2, 5, 0, 1, 128, 226 | 1, 0, 15, 144, 31, 0, 227 | 0, 2, 5, 0, 2, 128, 228 | 2, 0, 15, 144, 5, 0, 229 | 0, 3, 0, 0, 15, 128, 230 | 0, 0, 0, 144, 1, 0, 231 | 228, 160, 4, 0, 0, 4, 232 | 0, 0, 15, 128, 2, 0, 233 | 228, 160, 0, 0, 85, 144, 234 | 0, 0, 228, 128, 1, 0, 235 | 0, 2, 1, 0, 3, 128, 236 | 5, 0, 228, 160, 4, 0, 237 | 0, 4, 0, 0, 15, 128, 238 | 3, 0, 228, 160, 1, 0, 239 | 0, 128, 0, 0, 228, 128, 240 | 4, 0, 0, 4, 0, 0, 241 | 15, 128, 4, 0, 228, 160, 242 | 1, 0, 85, 128, 0, 0, 243 | 228, 128, 5, 0, 0, 3, 244 | 1, 0, 3, 128, 0, 0, 245 | 255, 128, 0, 0, 228, 160, 246 | 2, 0, 0, 3, 0, 0, 247 | 3, 192, 0, 0, 228, 128, 248 | 1, 0, 228, 128, 1, 0, 249 | 0, 2, 0, 0, 12, 192, 250 | 0, 0, 228, 128, 1, 0, 251 | 0, 2, 0, 0, 15, 224, 252 | 1, 0, 228, 144, 1, 0, 253 | 0, 2, 1, 0, 3, 224, 254 | 2, 0, 228, 144, 255, 255, 255 | 0, 0, 83, 72, 68, 82, 256 | 72, 1, 0, 0, 64, 0, 257 | 1, 0, 82, 0, 0, 0, 258 | 89, 0, 0, 4, 70, 142, 259 | 32, 0, 0, 0, 0, 0, 260 | 4, 0, 0, 0, 95, 0, 261 | 0, 3, 50, 16, 16, 0, 262 | 0, 0, 0, 0, 95, 0, 263 | 0, 3, 242, 16, 16, 0, 264 | 1, 0, 0, 0, 95, 0, 265 | 0, 3, 50, 16, 16, 0, 266 | 2, 0, 0, 0, 103, 0, 267 | 0, 4, 242, 32, 16, 0, 268 | 0, 0, 0, 0, 1, 0, 269 | 0, 0, 101, 0, 0, 3, 270 | 242, 32, 16, 0, 1, 0, 271 | 0, 0, 101, 0, 0, 3, 272 | 50, 32, 16, 0, 2, 0, 273 | 0, 0, 104, 0, 0, 2, 274 | 1, 0, 0, 0, 56, 0, 275 | 0, 8, 242, 0, 16, 0, 276 | 0, 0, 0, 0, 6, 16, 277 | 16, 0, 0, 0, 0, 0, 278 | 70, 142, 32, 0, 0, 0, 279 | 0, 0, 0, 0, 0, 0, 280 | 50, 0, 0, 10, 242, 0, 281 | 16, 0, 0, 0, 0, 0, 282 | 70, 142, 32, 0, 0, 0, 283 | 0, 0, 1, 0, 0, 0, 284 | 86, 21, 16, 0, 0, 0, 285 | 0, 0, 70, 14, 16, 0, 286 | 0, 0, 0, 0, 50, 0, 287 | 0, 13, 242, 0, 16, 0, 288 | 0, 0, 0, 0, 70, 142, 289 | 32, 0, 0, 0, 0, 0, 290 | 2, 0, 0, 0, 2, 64, 291 | 0, 0, 0, 0, 0, 0, 292 | 0, 0, 0, 0, 0, 0, 293 | 0, 0, 0, 0, 0, 0, 294 | 70, 14, 16, 0, 0, 0, 295 | 0, 0, 50, 0, 0, 13, 296 | 242, 32, 16, 0, 0, 0, 297 | 0, 0, 70, 142, 32, 0, 298 | 0, 0, 0, 0, 3, 0, 299 | 0, 0, 2, 64, 0, 0, 300 | 0, 0, 128, 63, 0, 0, 301 | 128, 63, 0, 0, 128, 63, 302 | 0, 0, 128, 63, 70, 14, 303 | 16, 0, 0, 0, 0, 0, 304 | 54, 0, 0, 5, 242, 32, 305 | 16, 0, 1, 0, 0, 0, 306 | 70, 30, 16, 0, 1, 0, 307 | 0, 0, 54, 0, 0, 5, 308 | 50, 32, 16, 0, 2, 0, 309 | 0, 0, 70, 16, 16, 0, 310 | 2, 0, 0, 0, 62, 0, 311 | 0, 1, 73, 83, 71, 78, 312 | 104, 0, 0, 0, 3, 0, 313 | 0, 0, 8, 0, 0, 0, 314 | 80, 0, 0, 0, 0, 0, 315 | 0, 0, 0, 0, 0, 0, 316 | 3, 0, 0, 0, 0, 0, 317 | 0, 0, 3, 3, 0, 0, 318 | 89, 0, 0, 0, 0, 0, 319 | 0, 0, 0, 0, 0, 0, 320 | 3, 0, 0, 0, 1, 0, 321 | 0, 0, 15, 15, 0, 0, 322 | 95, 0, 0, 0, 0, 0, 323 | 0, 0, 0, 0, 0, 0, 324 | 3, 0, 0, 0, 2, 0, 325 | 0, 0, 3, 3, 0, 0, 326 | 80, 79, 83, 73, 84, 73, 327 | 79, 78, 0, 67, 79, 76, 328 | 79, 82, 0, 84, 69, 88, 329 | 67, 79, 79, 82, 68, 0, 330 | 79, 83, 71, 78, 108, 0, 331 | 0, 0, 3, 0, 0, 0, 332 | 8, 0, 0, 0, 80, 0, 333 | 0, 0, 0, 0, 0, 0, 334 | 1, 0, 0, 0, 3, 0, 335 | 0, 0, 0, 0, 0, 0, 336 | 15, 0, 0, 0, 92, 0, 337 | 0, 0, 0, 0, 0, 0, 338 | 0, 0, 0, 0, 3, 0, 339 | 0, 0, 1, 0, 0, 0, 340 | 15, 0, 0, 0, 98, 0, 341 | 0, 0, 0, 0, 0, 0, 342 | 0, 0, 0, 0, 3, 0, 343 | 0, 0, 2, 0, 0, 0, 344 | 3, 12, 0, 0, 83, 86, 345 | 95, 80, 79, 83, 73, 84, 346 | 73, 79, 78, 0, 67, 79, 347 | 76, 79, 82, 0, 84, 69, 348 | 88, 67, 79, 79, 82, 68, 349 | 0, 171 350 | }; 351 | -------------------------------------------------------------------------------- /demo/sdl_opengl2/nuklear_sdl_gl2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Nuklear - 1.32.0 - public domain 3 | * no warrenty implied; use at your own risk. 4 | * authored from 2015-2017 by Micha Mettke 5 | */ 6 | /* 7 | * ============================================================== 8 | * 9 | * API 10 | * 11 | * =============================================================== 12 | */ 13 | #ifndef NK_SDL_GL2_H_ 14 | #define NK_SDL_GL2_H_ 15 | 16 | #include 17 | NK_API struct nk_context* nk_sdl_init(SDL_Window *win); 18 | NK_API void nk_sdl_font_stash_begin(struct nk_font_atlas **atlas); 19 | NK_API void nk_sdl_font_stash_end(void); 20 | NK_API int nk_sdl_handle_event(SDL_Event *evt); 21 | NK_API void nk_sdl_render(enum nk_anti_aliasing); 22 | NK_API void nk_sdl_shutdown(void); 23 | 24 | #endif 25 | /* 26 | * ============================================================== 27 | * 28 | * IMPLEMENTATION 29 | * 30 | * =============================================================== 31 | */ 32 | #ifdef NK_SDL_GL2_IMPLEMENTATION 33 | 34 | struct nk_sdl_device { 35 | struct nk_buffer cmds; 36 | struct nk_draw_null_texture null; 37 | GLuint font_tex; 38 | }; 39 | 40 | struct nk_sdl_vertex { 41 | float position[2]; 42 | float uv[2]; 43 | nk_byte col[4]; 44 | }; 45 | 46 | static struct nk_sdl { 47 | SDL_Window *win; 48 | struct nk_sdl_device ogl; 49 | struct nk_context ctx; 50 | struct nk_font_atlas atlas; 51 | } sdl; 52 | 53 | NK_INTERN void 54 | nk_sdl_device_upload_atlas(const void *image, int width, int height) 55 | { 56 | struct nk_sdl_device *dev = &sdl.ogl; 57 | glGenTextures(1, &dev->font_tex); 58 | glBindTexture(GL_TEXTURE_2D, dev->font_tex); 59 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 60 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 61 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, 62 | GL_RGBA, GL_UNSIGNED_BYTE, image); 63 | } 64 | 65 | NK_API void 66 | nk_sdl_render(enum nk_anti_aliasing AA) 67 | { 68 | /* setup global state */ 69 | struct nk_sdl_device *dev = &sdl.ogl; 70 | int width, height; 71 | int display_width, display_height; 72 | struct nk_vec2 scale; 73 | 74 | SDL_GetWindowSize(sdl.win, &width, &height); 75 | SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height); 76 | scale.x = (float)display_width/(float)width; 77 | scale.y = (float)display_height/(float)height; 78 | 79 | glPushAttrib(GL_ENABLE_BIT|GL_COLOR_BUFFER_BIT|GL_TRANSFORM_BIT); 80 | glDisable(GL_CULL_FACE); 81 | glDisable(GL_DEPTH_TEST); 82 | glEnable(GL_SCISSOR_TEST); 83 | glEnable(GL_BLEND); 84 | glEnable(GL_TEXTURE_2D); 85 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 86 | 87 | /* setup viewport/project */ 88 | glViewport(0,0,(GLsizei)display_width,(GLsizei)display_height); 89 | glMatrixMode(GL_PROJECTION); 90 | glPushMatrix(); 91 | glLoadIdentity(); 92 | glOrtho(0.0f, width, height, 0.0f, -1.0f, 1.0f); 93 | glMatrixMode(GL_MODELVIEW); 94 | glPushMatrix(); 95 | glLoadIdentity(); 96 | 97 | glEnableClientState(GL_VERTEX_ARRAY); 98 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); 99 | glEnableClientState(GL_COLOR_ARRAY); 100 | { 101 | GLsizei vs = sizeof(struct nk_sdl_vertex); 102 | size_t vp = offsetof(struct nk_sdl_vertex, position); 103 | size_t vt = offsetof(struct nk_sdl_vertex, uv); 104 | size_t vc = offsetof(struct nk_sdl_vertex, col); 105 | 106 | /* convert from command queue into draw list and draw to screen */ 107 | const struct nk_draw_command *cmd; 108 | const nk_draw_index *offset = NULL; 109 | struct nk_buffer vbuf, ebuf; 110 | 111 | /* fill converting configuration */ 112 | struct nk_convert_config config; 113 | static const struct nk_draw_vertex_layout_element vertex_layout[] = { 114 | {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_sdl_vertex, position)}, 115 | {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_sdl_vertex, uv)}, 116 | {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_sdl_vertex, col)}, 117 | {NK_VERTEX_LAYOUT_END} 118 | }; 119 | NK_MEMSET(&config, 0, sizeof(config)); 120 | config.vertex_layout = vertex_layout; 121 | config.vertex_size = sizeof(struct nk_sdl_vertex); 122 | config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex); 123 | config.null = dev->null; 124 | config.circle_segment_count = 22; 125 | config.curve_segment_count = 22; 126 | config.arc_segment_count = 22; 127 | config.global_alpha = 1.0f; 128 | config.shape_AA = AA; 129 | config.line_AA = AA; 130 | 131 | /* convert shapes into vertexes */ 132 | nk_buffer_init_default(&vbuf); 133 | nk_buffer_init_default(&ebuf); 134 | nk_convert(&sdl.ctx, &dev->cmds, &vbuf, &ebuf, &config); 135 | 136 | /* setup vertex buffer pointer */ 137 | {const void *vertices = nk_buffer_memory_const(&vbuf); 138 | glVertexPointer(2, GL_FLOAT, vs, (const void*)((const nk_byte*)vertices + vp)); 139 | glTexCoordPointer(2, GL_FLOAT, vs, (const void*)((const nk_byte*)vertices + vt)); 140 | glColorPointer(4, GL_UNSIGNED_BYTE, vs, (const void*)((const nk_byte*)vertices + vc));} 141 | 142 | /* iterate over and execute each draw command */ 143 | offset = (const nk_draw_index*)nk_buffer_memory_const(&ebuf); 144 | nk_draw_foreach(cmd, &sdl.ctx, &dev->cmds) 145 | { 146 | if (!cmd->elem_count) continue; 147 | glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id); 148 | glScissor( 149 | (GLint)(cmd->clip_rect.x * scale.x), 150 | (GLint)((height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * scale.y), 151 | (GLint)(cmd->clip_rect.w * scale.x), 152 | (GLint)(cmd->clip_rect.h * scale.y)); 153 | glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset); 154 | offset += cmd->elem_count; 155 | } 156 | nk_clear(&sdl.ctx); 157 | nk_buffer_free(&vbuf); 158 | nk_buffer_free(&ebuf); 159 | } 160 | 161 | /* default OpenGL state */ 162 | glDisableClientState(GL_VERTEX_ARRAY); 163 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); 164 | glDisableClientState(GL_COLOR_ARRAY); 165 | 166 | glDisable(GL_CULL_FACE); 167 | glDisable(GL_DEPTH_TEST); 168 | glDisable(GL_SCISSOR_TEST); 169 | glDisable(GL_BLEND); 170 | glDisable(GL_TEXTURE_2D); 171 | 172 | glBindTexture(GL_TEXTURE_2D, 0); 173 | glMatrixMode(GL_MODELVIEW); 174 | glPopMatrix(); 175 | glMatrixMode(GL_PROJECTION); 176 | glPopMatrix(); 177 | glPopAttrib(); 178 | } 179 | 180 | static void 181 | nk_sdl_clipbard_paste(nk_handle usr, struct nk_text_edit *edit) 182 | { 183 | const char *text = SDL_GetClipboardText(); 184 | if (text) nk_textedit_paste(edit, text, nk_strlen(text)); 185 | (void)usr; 186 | } 187 | 188 | static void 189 | nk_sdl_clipbard_copy(nk_handle usr, const char *text, int len) 190 | { 191 | char *str = 0; 192 | (void)usr; 193 | if (!len) return; 194 | str = (char*)malloc((size_t)len+1); 195 | if (!str) return; 196 | memcpy(str, text, (size_t)len); 197 | str[len] = '\0'; 198 | SDL_SetClipboardText(str); 199 | free(str); 200 | } 201 | 202 | NK_API struct nk_context* 203 | nk_sdl_init(SDL_Window *win) 204 | { 205 | sdl.win = win; 206 | nk_init_default(&sdl.ctx, 0); 207 | sdl.ctx.clip.copy = nk_sdl_clipbard_copy; 208 | sdl.ctx.clip.paste = nk_sdl_clipbard_paste; 209 | sdl.ctx.clip.userdata = nk_handle_ptr(0); 210 | nk_buffer_init_default(&sdl.ogl.cmds); 211 | return &sdl.ctx; 212 | } 213 | 214 | NK_API void 215 | nk_sdl_font_stash_begin(struct nk_font_atlas **atlas) 216 | { 217 | nk_font_atlas_init_default(&sdl.atlas); 218 | nk_font_atlas_begin(&sdl.atlas); 219 | *atlas = &sdl.atlas; 220 | } 221 | 222 | NK_API void 223 | nk_sdl_font_stash_end(void) 224 | { 225 | const void *image; int w, h; 226 | image = nk_font_atlas_bake(&sdl.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); 227 | nk_sdl_device_upload_atlas(image, w, h); 228 | nk_font_atlas_end(&sdl.atlas, nk_handle_id((int)sdl.ogl.font_tex), &sdl.ogl.null); 229 | if (sdl.atlas.default_font) 230 | nk_style_set_font(&sdl.ctx, &sdl.atlas.default_font->handle); 231 | } 232 | 233 | NK_API int 234 | nk_sdl_handle_event(SDL_Event *evt) 235 | { 236 | struct nk_context *ctx = &sdl.ctx; 237 | 238 | /* optional grabbing behavior */ 239 | if (ctx->input.mouse.grab) { 240 | SDL_SetRelativeMouseMode(SDL_TRUE); 241 | ctx->input.mouse.grab = 0; 242 | } else if (ctx->input.mouse.ungrab) { 243 | int x = (int)ctx->input.mouse.prev.x, y = (int)ctx->input.mouse.prev.y; 244 | SDL_SetRelativeMouseMode(SDL_FALSE); 245 | SDL_WarpMouseInWindow(sdl.win, x, y); 246 | ctx->input.mouse.ungrab = 0; 247 | } 248 | if (evt->type == SDL_KEYUP || evt->type == SDL_KEYDOWN) { 249 | /* key events */ 250 | int down = evt->type == SDL_KEYDOWN; 251 | const Uint8* state = SDL_GetKeyboardState(0); 252 | SDL_Keycode sym = evt->key.keysym.sym; 253 | if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT) 254 | nk_input_key(ctx, NK_KEY_SHIFT, down); 255 | else if (sym == SDLK_DELETE) 256 | nk_input_key(ctx, NK_KEY_DEL, down); 257 | else if (sym == SDLK_RETURN) 258 | nk_input_key(ctx, NK_KEY_ENTER, down); 259 | else if (sym == SDLK_TAB) 260 | nk_input_key(ctx, NK_KEY_TAB, down); 261 | else if (sym == SDLK_BACKSPACE) 262 | nk_input_key(ctx, NK_KEY_BACKSPACE, down); 263 | else if (sym == SDLK_HOME) { 264 | nk_input_key(ctx, NK_KEY_TEXT_START, down); 265 | nk_input_key(ctx, NK_KEY_SCROLL_START, down); 266 | } else if (sym == SDLK_END) { 267 | nk_input_key(ctx, NK_KEY_TEXT_END, down); 268 | nk_input_key(ctx, NK_KEY_SCROLL_END, down); 269 | } else if (sym == SDLK_PAGEDOWN) { 270 | nk_input_key(ctx, NK_KEY_SCROLL_DOWN, down); 271 | } else if (sym == SDLK_PAGEUP) { 272 | nk_input_key(ctx, NK_KEY_SCROLL_UP, down); 273 | } else if (sym == SDLK_z) 274 | nk_input_key(ctx, NK_KEY_TEXT_UNDO, down && state[SDL_SCANCODE_LCTRL]); 275 | else if (sym == SDLK_r) 276 | nk_input_key(ctx, NK_KEY_TEXT_REDO, down && state[SDL_SCANCODE_LCTRL]); 277 | else if (sym == SDLK_c) 278 | nk_input_key(ctx, NK_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]); 279 | else if (sym == SDLK_v) 280 | nk_input_key(ctx, NK_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]); 281 | else if (sym == SDLK_x) 282 | nk_input_key(ctx, NK_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]); 283 | else if (sym == SDLK_b) 284 | nk_input_key(ctx, NK_KEY_TEXT_LINE_START, down && state[SDL_SCANCODE_LCTRL]); 285 | else if (sym == SDLK_e) 286 | nk_input_key(ctx, NK_KEY_TEXT_LINE_END, down && state[SDL_SCANCODE_LCTRL]); 287 | else if (sym == SDLK_UP) 288 | nk_input_key(ctx, NK_KEY_UP, down); 289 | else if (sym == SDLK_DOWN) 290 | nk_input_key(ctx, NK_KEY_DOWN, down); 291 | else if (sym == SDLK_LEFT) { 292 | if (state[SDL_SCANCODE_LCTRL]) 293 | nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, down); 294 | else nk_input_key(ctx, NK_KEY_LEFT, down); 295 | } else if (sym == SDLK_RIGHT) { 296 | if (state[SDL_SCANCODE_LCTRL]) 297 | nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, down); 298 | else nk_input_key(ctx, NK_KEY_RIGHT, down); 299 | } else return 0; 300 | return 1; 301 | } else if (evt->type == SDL_MOUSEBUTTONDOWN || evt->type == SDL_MOUSEBUTTONUP) { 302 | /* mouse button */ 303 | int down = evt->type == SDL_MOUSEBUTTONDOWN; 304 | const int x = evt->button.x, y = evt->button.y; 305 | if (evt->button.button == SDL_BUTTON_LEFT) { 306 | if (evt->button.clicks > 1) 307 | nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, down); 308 | nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down); 309 | } else if (evt->button.button == SDL_BUTTON_MIDDLE) 310 | nk_input_button(ctx, NK_BUTTON_MIDDLE, x, y, down); 311 | else if (evt->button.button == SDL_BUTTON_RIGHT) 312 | nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, down); 313 | else return 0; 314 | return 1; 315 | } else if (evt->type == SDL_MOUSEMOTION) { 316 | /* mouse motion */ 317 | if (ctx->input.mouse.grabbed) { 318 | int x = (int)ctx->input.mouse.prev.x, y = (int)ctx->input.mouse.prev.y; 319 | nk_input_motion(ctx, x + evt->motion.xrel, y + evt->motion.yrel); 320 | } else nk_input_motion(ctx, evt->motion.x, evt->motion.y); 321 | return 1; 322 | } else if (evt->type == SDL_TEXTINPUT) { 323 | /* text input */ 324 | nk_glyph glyph; 325 | memcpy(glyph, evt->text.text, NK_UTF_SIZE); 326 | nk_input_glyph(ctx, glyph); 327 | return 1; 328 | } else if (evt->type == SDL_MOUSEWHEEL) { 329 | /* mouse wheel */ 330 | nk_input_scroll(ctx,nk_vec2((float)evt->wheel.x,(float)evt->wheel.y)); 331 | return 1; 332 | } 333 | return 0; 334 | } 335 | 336 | NK_API 337 | void nk_sdl_shutdown(void) 338 | { 339 | struct nk_sdl_device *dev = &sdl.ogl; 340 | nk_font_atlas_clear(&sdl.atlas); 341 | nk_free(&sdl.ctx); 342 | glDeleteTextures(1, &dev->font_tex); 343 | nk_buffer_free(&dev->cmds); 344 | memset(&sdl, 0, sizeof(sdl)); 345 | } 346 | 347 | #endif 348 | -------------------------------------------------------------------------------- /demo/x11_opengl3/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_INCLUDE_VERTEX_BUFFER_OUTPUT 18 | #define NK_INCLUDE_FONT_BAKING 19 | #define NK_INCLUDE_DEFAULT_FONT 20 | #define NK_IMPLEMENTATION 21 | #define NK_XLIB_GL3_IMPLEMENTATION 22 | #define NK_XLIB_LOAD_OPENGL_EXTENSIONS 23 | #include "../../nuklear.h" 24 | #include "nuklear_xlib_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_OVERVIEW */ 43 | /*#define INCLUDE_NODE_EDITOR */ 44 | 45 | #ifdef INCLUDE_ALL 46 | #define INCLUDE_STYLE 47 | #define INCLUDE_CALCULATOR 48 | #define INCLUDE_OVERVIEW 49 | #define INCLUDE_NODE_EDITOR 50 | #endif 51 | 52 | #ifdef INCLUDE_STYLE 53 | #include "../style.c" 54 | #endif 55 | #ifdef INCLUDE_CALCULATOR 56 | #include "../calculator.c" 57 | #endif 58 | #ifdef INCLUDE_OVERVIEW 59 | #include "../overview.c" 60 | #endif 61 | #ifdef INCLUDE_NODE_EDITOR 62 | #include "../node_editor.c" 63 | #endif 64 | 65 | /* =============================================================== 66 | * 67 | * DEMO 68 | * 69 | * ===============================================================*/ 70 | struct XWindow { 71 | Display *dpy; 72 | Window win; 73 | XVisualInfo *vis; 74 | Colormap cmap; 75 | XSetWindowAttributes swa; 76 | XWindowAttributes attr; 77 | GLXFBConfig fbc; 78 | Atom wm_delete_window; 79 | int width, height; 80 | }; 81 | static int gl_err = nk_false; 82 | static int gl_error_handler(Display *dpy, XErrorEvent *ev) 83 | {NK_UNUSED(dpy); NK_UNUSED(ev); gl_err = nk_true;return 0;} 84 | 85 | static void 86 | die(const char *fmt, ...) 87 | { 88 | va_list ap; 89 | va_start(ap, fmt); 90 | vfprintf(stderr, fmt, ap); 91 | va_end(ap); 92 | fputs("\n", stderr); 93 | exit(EXIT_FAILURE); 94 | } 95 | 96 | static int 97 | has_extension(const char *string, const char *ext) 98 | { 99 | const char *start, *where, *term; 100 | where = strchr(ext, ' '); 101 | if (where || *ext == '\0') 102 | return nk_false; 103 | 104 | for (start = string;;) { 105 | where = strstr((const char*)start, ext); 106 | if (!where) break; 107 | term = where + strlen(ext); 108 | if (where == start || *(where - 1) == ' ') { 109 | if (*term == ' ' || *term == '\0') 110 | return nk_true; 111 | } 112 | start = term; 113 | } 114 | return nk_false; 115 | } 116 | 117 | int main(void) 118 | { 119 | /* Platform */ 120 | int running = 1; 121 | struct XWindow win; 122 | GLXContext glContext; 123 | struct nk_context *ctx; 124 | struct nk_colorf bg; 125 | 126 | memset(&win, 0, sizeof(win)); 127 | win.dpy = XOpenDisplay(NULL); 128 | if (!win.dpy) die("Failed to open X display\n"); 129 | { 130 | /* check glx version */ 131 | int glx_major, glx_minor; 132 | if (!glXQueryVersion(win.dpy, &glx_major, &glx_minor)) 133 | die("[X11]: Error: Failed to query OpenGL version\n"); 134 | if ((glx_major == 1 && glx_minor < 3) || (glx_major < 1)) 135 | die("[X11]: Error: Invalid GLX version!\n"); 136 | } 137 | { 138 | /* find and pick matching framebuffer visual */ 139 | int fb_count; 140 | static GLint attr[] = { 141 | GLX_X_RENDERABLE, True, 142 | GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 143 | GLX_RENDER_TYPE, GLX_RGBA_BIT, 144 | GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, 145 | GLX_RED_SIZE, 8, 146 | GLX_GREEN_SIZE, 8, 147 | GLX_BLUE_SIZE, 8, 148 | GLX_ALPHA_SIZE, 8, 149 | GLX_DEPTH_SIZE, 24, 150 | GLX_STENCIL_SIZE, 8, 151 | GLX_DOUBLEBUFFER, True, 152 | None 153 | }; 154 | GLXFBConfig *fbc; 155 | fbc = glXChooseFBConfig(win.dpy, DefaultScreen(win.dpy), attr, &fb_count); 156 | if (!fbc) die("[X11]: Error: failed to retrieve framebuffer configuration\n"); 157 | { 158 | /* pick framebuffer with most samples per pixel */ 159 | int i; 160 | int fb_best = -1, best_num_samples = -1; 161 | for (i = 0; i < fb_count; ++i) { 162 | XVisualInfo *vi = glXGetVisualFromFBConfig(win.dpy, fbc[i]); 163 | if (vi) { 164 | int sample_buffer, samples; 165 | glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLE_BUFFERS, &sample_buffer); 166 | glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLES, &samples); 167 | if ((fb_best < 0) || (sample_buffer && samples > best_num_samples)) 168 | fb_best = i, best_num_samples = samples; 169 | } 170 | } 171 | win.fbc = fbc[fb_best]; 172 | XFree(fbc); 173 | win.vis = glXGetVisualFromFBConfig(win.dpy, win.fbc); 174 | } 175 | } 176 | { 177 | /* create window */ 178 | win.cmap = XCreateColormap(win.dpy, RootWindow(win.dpy, win.vis->screen), win.vis->visual, AllocNone); 179 | win.swa.colormap = win.cmap; 180 | win.swa.background_pixmap = None; 181 | win.swa.border_pixel = 0; 182 | win.swa.event_mask = 183 | ExposureMask | KeyPressMask | KeyReleaseMask | 184 | ButtonPress | ButtonReleaseMask| ButtonMotionMask | 185 | Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask| 186 | PointerMotionMask| StructureNotifyMask; 187 | win.win = XCreateWindow(win.dpy, RootWindow(win.dpy, win.vis->screen), 0, 0, 188 | WINDOW_WIDTH, WINDOW_HEIGHT, 0, win.vis->depth, InputOutput, 189 | win.vis->visual, CWBorderPixel|CWColormap|CWEventMask, &win.swa); 190 | if (!win.win) die("[X11]: Failed to create window\n"); 191 | XFree(win.vis); 192 | XStoreName(win.dpy, win.win, "Demo"); 193 | XMapWindow(win.dpy, win.win); 194 | win.wm_delete_window = XInternAtom(win.dpy, "WM_DELETE_WINDOW", False); 195 | XSetWMProtocols(win.dpy, win.win, &win.wm_delete_window, 1); 196 | } 197 | { 198 | /* create opengl context */ 199 | typedef GLXContext(*glxCreateContext)(Display*, GLXFBConfig, GLXContext, Bool, const int*); 200 | int(*old_handler)(Display*, XErrorEvent*) = XSetErrorHandler(gl_error_handler); 201 | const char *extensions_str = glXQueryExtensionsString(win.dpy, DefaultScreen(win.dpy)); 202 | glxCreateContext create_context = (glxCreateContext) 203 | glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB"); 204 | 205 | gl_err = nk_false; 206 | if (!has_extension(extensions_str, "GLX_ARB_create_context") || !create_context) { 207 | fprintf(stdout, "[X11]: glXCreateContextAttribARB() not found...\n"); 208 | fprintf(stdout, "[X11]: ... using old-style GLX context\n"); 209 | glContext = glXCreateNewContext(win.dpy, win.fbc, GLX_RGBA_TYPE, 0, True); 210 | } else { 211 | GLint attr[] = { 212 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, 213 | GLX_CONTEXT_MINOR_VERSION_ARB, 0, 214 | None 215 | }; 216 | glContext = create_context(win.dpy, win.fbc, 0, True, attr); 217 | XSync(win.dpy, False); 218 | if (gl_err || !glContext) { 219 | /* Could not create GL 3.0 context. Fallback to old 2.x context. 220 | * If a version below 3.0 is requested, implementations will 221 | * return the newest context version compatible with OpenGL 222 | * version less than version 3.0.*/ 223 | attr[1] = 1; attr[3] = 0; 224 | gl_err = nk_false; 225 | fprintf(stdout, "[X11] Failed to create OpenGL 3.0 context\n"); 226 | fprintf(stdout, "[X11] ... using old-style GLX context!\n"); 227 | glContext = create_context(win.dpy, win.fbc, 0, True, attr); 228 | } 229 | } 230 | XSync(win.dpy, False); 231 | XSetErrorHandler(old_handler); 232 | if (gl_err || !glContext) 233 | die("[X11]: Failed to create an OpenGL context\n"); 234 | glXMakeCurrent(win.dpy, win.win, glContext); 235 | } 236 | 237 | ctx = nk_x11_init(win.dpy, win.win); 238 | /* Load Fonts: if none of these are loaded a default font will be used */ 239 | {struct nk_font_atlas *atlas; 240 | nk_x11_font_stash_begin(&atlas); 241 | /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ 242 | /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ 243 | /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ 244 | /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ 245 | /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ 246 | /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ 247 | nk_x11_font_stash_end(); 248 | /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ 249 | /*nk_style_set_font(ctx, &droid->handle);*/} 250 | 251 | #ifdef INCLUDE_STYLE 252 | /*set_style(ctx, THEME_WHITE);*/ 253 | /*set_style(ctx, THEME_RED);*/ 254 | /*set_style(ctx, THEME_BLUE);*/ 255 | /*set_style(ctx, THEME_DARK);*/ 256 | #endif 257 | 258 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 259 | while (running) 260 | { 261 | /* Input */ 262 | XEvent evt; 263 | nk_input_begin(ctx); 264 | while (XPending(win.dpy)) { 265 | XNextEvent(win.dpy, &evt); 266 | if (evt.type == ClientMessage) goto cleanup; 267 | if (XFilterEvent(&evt, win.win)) continue; 268 | nk_x11_handle_event(&evt); 269 | } 270 | nk_input_end(ctx); 271 | 272 | /* GUI */ 273 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), 274 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 275 | NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 276 | { 277 | enum {EASY, HARD}; 278 | static int op = EASY; 279 | static int property = 20; 280 | 281 | nk_layout_row_static(ctx, 30, 80, 1); 282 | if (nk_button_label(ctx, "button")) 283 | fprintf(stdout, "button pressed\n"); 284 | nk_layout_row_dynamic(ctx, 30, 2); 285 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 286 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 287 | nk_layout_row_dynamic(ctx, 25, 1); 288 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 289 | 290 | nk_layout_row_dynamic(ctx, 20, 1); 291 | nk_label(ctx, "background:", NK_TEXT_LEFT); 292 | nk_layout_row_dynamic(ctx, 25, 1); 293 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 294 | nk_layout_row_dynamic(ctx, 120, 1); 295 | bg = nk_color_picker(ctx, bg, NK_RGBA); 296 | nk_layout_row_dynamic(ctx, 25, 1); 297 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 298 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 299 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 300 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 301 | nk_combo_end(ctx); 302 | } 303 | } 304 | nk_end(ctx); 305 | 306 | /* -------------- EXAMPLES ---------------- */ 307 | #ifdef INCLUDE_CALCULATOR 308 | calculator(ctx); 309 | #endif 310 | #ifdef INCLUDE_OVERVIEW 311 | overview(ctx); 312 | #endif 313 | #ifdef INCLUDE_NODE_EDITOR 314 | node_editor(ctx); 315 | #endif 316 | /* ----------------------------------------- */ 317 | 318 | /* Draw */ 319 | XGetWindowAttributes(win.dpy, win.win, &win.attr); 320 | glViewport(0, 0, win.width, win.height); 321 | glClear(GL_COLOR_BUFFER_BIT); 322 | glClearColor(bg.r, bg.g, bg.b, bg.a); 323 | /* IMPORTANT: `nk_x11_render` modifies some global OpenGL state 324 | * with blending, scissor, face culling, depth test and viewport and 325 | * defaults everything back into a default state. 326 | * Make sure to either a.) save and restore or b.) reset your own state after 327 | * rendering the UI. */ 328 | nk_x11_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); 329 | glXSwapBuffers(win.dpy, win.win); 330 | } 331 | 332 | cleanup: 333 | nk_x11_shutdown(); 334 | glXMakeCurrent(win.dpy, 0, 0); 335 | glXDestroyContext(win.dpy, glContext); 336 | XUnmapWindow(win.dpy, win.win); 337 | XFreeColormap(win.dpy, win.cmap); 338 | XDestroyWindow(win.dpy, win.win); 339 | XCloseDisplay(win.dpy); 340 | return 0; 341 | 342 | } 343 | --------------------------------------------------------------------------------