Commit 59557e9a authored by Hanspeter Portner's avatar Hanspeter Portner

Squashed 'nuklear/' changes from 407126c..e8761c7

e8761c7 fix NK_COMMAND_ARC/NK_COMMAND_ARC_FILLED.
524c27e omk: don't clear draw_list.
0c78704 omk: fix lexer code to work with utf8.
5e70ec4 add support for syntax highlighting
76a1791 Merge pull request #538 from metiscus/master
0fca7e2 Adds protection of the texture matrix stack which allows the user to use sf::Sprites with this code unmodified otherwise
9e0ed88 Merge pull request #523 from nuklear-ui/docs
056af25 Merge pull request #534 from DeXP/gles2
a75bfcc Merge pull request #535 from siro20/nuklear_softrast
3705464 demo/x11_rawfb: Change license to MIT
e57e014 Emscripten support
24a7536 Merge branch 'siro20-nuklear_softrast'
e5850a0 Fixed style issues in software renderer
5d72fe5 Merge branch 'nuklear_softrast' of https://github.com/siro20/nuklear into siro20-nuklear_softrast
2eb72b2 Add software rasterizer library and demo.
ed57400 Merge pull request #529 from DeXP/gdip-fonts
49c3bcd nk_ prefix
e24b8ca Merge pull request #526 from RomanAkberov/master
a5f171a Merge branch 'DeXP--gles2'
af216a1 Merge branch 'gles2' of https://github.com/DeXP/nuklear into DeXP--gles2
c582959 Merge pull request #527 from DeXP/gdip
02e6a81 GDI+ multiple fonts support
a019772 Revert X11 changes
cc85565 Open GL ES 2 demo
49f6b11 Revert X11 changes
ecee581 Revert X11 changes
d0ed8bc GDI+ nk_gdip_fill_rect background fix
31c88a8 Use correct style for progressbar cursor.
0b95e3e Fixed #525 by updating canvas example
3444d8a Bump docs submodule revision
981d542 Add doc scripts and sphinx configuration update
075e3fd Add .readthedocs.yml config for installing breathe dependency
9d2fe7c Add doxygen, sphinx docs setup
815b5e1 Merge pull request #521 from valera-rozuvan/patch-3
55206c7 Add comment to closing #endif statement
48f659a Merge pull request #497 from jwdeitch/master
46cd4e0 Merge pull request #520 from valera-rozuvan/patch-2
3757f56 Remove unused line of code
8f9ead7 Merge pull request #519 from valera-rozuvan/patch-2
1b1b04f Fix comment for closing #endif
9059628 Fixed #517 second attempt
b774329 Fixed #516 nk_edit_buffer and nk_edit_focus
43b41f9 Fixed window closing behavior
3b5123f Fixed #517 --!!BREAKING CHANGE!!--
708a7eb Xlib: remove text BG rectangle
0c2a725 Merge pull request #512 from DeXP/master
f72dd62 Optional stb_image defines
31674e4 Fixed #503 background window flag
5de84dc Fix stb_image path
5fc8a25 stb_image with bit transparency
f994b15 Merge branch 'master' of git://github.com/vurtun/nuklear
67b26f9 Merge pull request #510 from lieff/master
039afa8 fix asan error (out-of-scope variable access)
afa76f5 Fixed #502 nk_item_is_any_active for hidden window
7c089a5 Fixed #503 NK_WINDOW_BACKGROUND flag behavior
a2472f8 Fixed #501 incorrect documentation for nk_input_scroll
d7f757b Merge pull request #499 from reujab/master
4a82680 corrected line count
1aebb41 Merge pull request #495 from cascade256/master
fcbbc4a Merge branch 'stillwarter-master'
e454fcf nk_iceilf now returns correct value when x >= 0
52f24d4 fix compiling error on OSX
2a406ca Merge pull request #496 from ettoretorti/master
2a30c4f Fix typos in comments
f7137ec Fix GLFW double clicking
b73e3c7 Merge branch 'ettoretorti-master'
bee9037 Converted C++ comments to C89 and added reference
4ba164c Merge branch 'master' of https://github.com/ettoretorti/nuklear into ettoretorti-master
1da1997 Merge branch 'Np3w-master'
f4171e8 Optimize arc drawing for fewer sin/cos calls
2f56f8b More code style
7abda44 Fix code style
4920522 Make nk_window_is_hovered care about NK_WINDOW_HIDDEN flag
468065b Merge pull request #486 from nsawa/fix_gcc_warning_unused_variable
9eed01d Fix gcc warning 'unused variable'.
ebee716 Fixed #485 widget is hovered/clicked outside window
9a9f4f0 Fixed #479 drawing bug for lines/rectangles
6326b5d Fixed #406 bug causing infinite loop
8e48b99 Fixed #477 segfault on full table
900bca9 Removed unneeded semicolon in C++ NK_ALIGNOF version
83636d4 Fixed #472 with draw lines smaller/equal zero
fad605e Merge branch 'master' of https://github.com/vurtun/gui
170fbf2 Merge pull request #468 from nsawa/fix_warning_in_nk_layout_reset_min_row_height
1c3bc4b Merge pull request #468 from nsawa/fix_warning_in_nk_layout_reset_min_row_height
0f4225a In revision 4741669, gcc 2.7.2 generates a warning in the function nk_layout_reset_min_row_height(): warning: unused variable `font'
4741669 Finished documentation for layouting
ef78999 Fixed documentation for last change
14e0847 Made last auto layout change non-breaking
3c6d32d Fixed tree visual bug caused by min layout height
ecd1691 Merge branch 'master' of https://github.com/vurtun/gui
e13aae2 BREAKING: Auto row height derived from font height
0dbe53a Merge pull request #466 from wheybags/newline_fix
1a73739 Merge pull request #465 from wheybags/chart_fix
9fc0efe fix accidental windows newlines
8d8c392 fix nk_plot functions triggering assert when drawing offscreen
5c7194c Merge pull request #462 from wheybags/nk_textedit_init_fix
d59c879 Zero nk_text_edit structs before initialising in nk_textedit_init_*
5c0ef78 Fixed #458 property behavior bug
a79a083 Added additional layouting utility function
27603d5 Merge pull request #449 from Fra-Ktus/master
3b8d66a Merge pull request #450 from Fra-Ktus/gdi_nk_image
d3a6dc0 Merge branch 'master' of https://github.com/vurtun/gui
26cd843 Fixed #453 return flag for dynamic command buffer
9575b93 Merge pull request #452 from mmozeiko/master
e14dd1c Demo using Direct3D 9 for rendering
9c3ab8e implemented nk_create_image and nk_delete_image
042cd07 implemented nk_create_image and nk_delete_image
3debbd2 allowing touch event to work on iOS and Android
6ac034c Merge pull request #447 from tst2005/patch-1
dff18eb add Lua/Love2d binding to the list
b10ca1d Merge pull request #444 from godlikepanos/master
200017d Make the font ptr const in nk_style_push_font
530266b Merge branch 'master' of https://github.com/vurtun/gui
7bd4679 Fixed #442 Activation of partially visible widgets
c47696e Merge pull request #441 from wheybags/patch-1
aa6bd5a remove typoed/duplicated function declaration
af50d84 Merge branch 'master' of https://github.com/vurtun/gui
d4f5181 Fixed #439 missing zeroing in nk_font_atlas_cleanup
2d80ca8 Merge pull request #436 from mmozeiko/master
edac63b double click support in demo code for Windows platforms
d9a57d4 Fixed panel scaling to behave like windows native
70d9de1 Fixed scrollbar drawing bug if not enough space
9ed3eee Fixed scaler dragging behavior #432
1f8f92e Merge pull request #431 from McNopper/master_norbert_warning_fix
621e233 Removed compiler GCC warning.
9dc7323 Added platform double click support #412
e888338 Introduce define for software fonts
012170b Added additional batch of documentation
8559aeb Fixed key repeat #416 in `nk_input_key`
4c39852 Fixed #405 and added property select and clipboard
43a4f3e Fixed `nk_edit_flags` sequence
945dc5a Fixed #403 with another floating pointer error
d68a9cf Added first batch of documentation
1995518 Added additional input window flags #399
e4c800a Merge pull request #398 from rokups/fix/nk_convert-graceful-failure
89e6ed6 fixed #395 heap corruption in `nk_buffer`
bbb8190 Removed two asserts in order to allow nk_convert() to gracefully fail when buffers do not provide enough space.
7d5648d Added result flags to `nk_convert`
5cf6f20 Removed wrong `nk_window_is_closed` in demos
0d010a3 Merge pull request #393 from nsawa/fix_gcc_warning_in_nk_end
b3963bf Fix gcc warning in nk_end().
274d9c4 Merge branch 'master' of https://github.com/vurtun/gui
67f266a Fixed #388 crashing hidden window on popup click
58b7faf Merge pull request #389 from rokups/fixes
13d9eb4 Merge pull request #391 from cxong/master
9b9f88e Remove redundant assign
80db75a Fix using uninitialized variable as condition.
25e6ba2 Fix examples to use nk_vec2 in nk_input_scroll() calls.
204e2bd Merge pull request #382 from nsawa/fix_warning_unused_variable
b24329d fix: warning unused variable in nk_finish()
1a87c13 Fixed multiline commment in commented out code
2a0942f Fixed #378 popup blocking `NK_WINDOW_BACKGROUND` windows
944af0e Fixed windows closing behavior
45af48a Added horizontal scrolling requested in #377
23eea23 Added horizontal scrolling
a979372 Fixed #375 long window title drawing bug
8594d48 Merge branch 'shyhisi-mater'
6bb0089 Fixed PR styling issues
e7ae9bf Merge branch 'master' of https://github.com/skyhisi/nuklear into shyhisi-mater
46e55e1 Merge pull request #373 from RUSshy/patch-1
86d4c22 Made properties static or they can't be changed
0073110 Xlib: Add font stack push function and copy/paste support
e77b723 Removed unused defines and parameters
99ea7c4 Fixed const warnings
2f63716 Merge pull request #369 from cxong/patch-5
2e4db87 Remove const cast of endptr in nk_strto* functions
436bbcd Merge branch 'ricanteja-master'
7c7e15e Fixed some styling issues in sfml demos
220c314 Merge branch 'master' of https://github.com/ricanteja/nuklear into ricanteja-master
93193e4 Merge pull request #366 from cxong/patch-1
7134bf7 Fix unary operator clang warning
e6a6fe5 fixed #363 wrong example in documentation
d5ea545 Hopefully fixed #362 text input filtering
284772c fixed #361 group closable window flag
3d77394 Forgot to edit link to point to SFML webpage and not Allegro..
1574367 Makefiles done.
c6bfe1c Finally! I fixed that bug that I had. sf::Mouse::setPosition was setting the position of the cursor to desktop coordinates not window coordinates.
63e98d9 Almost ready for merge. Need to fix bug with mouse movement. Need to implement clipboard support. Lastly need to write ReadMe on instructions for building.
443a058 Merge branch 'ClassJG-master'
e5c1cf9 Cleaned up custom draw commands to better fit
4c25cd3 Added a new command type: NK_COMMAND_CUSTOM
064e31f Added assert to prevent group with closable flag
e7d02b4 Updated Readme
5007519 Dumped the pure SFML folder. Got it working enough to realize that it just ran too slow to continue wasting time on it. SFML creates a OpenGL context anyway so users can drop in the nk_sfml_gl2.h and not need anything else. I'll have to add this in the readme. Tried to make my code as similar to other demos for sake of consistency.
4ed15f5 Fixed Readme layouting
82b8ac0 Merge branch 'embox-master'
eaf104d Merge branch 'master' of https://github.com/embox/nuklear into embox-master
5f78107 Added nim language bindings to Readme
67aaa11 Return global clipping back
73b0b94 Added OpenGL3 for SFML and also working on "pure" SFML renderer.
aac2d71 Make NK_API 'static inline' for NK_PRIVATE version
2babe51 Fixed the clipping glitch (bug that caused the window borders and backgrounds to not be rendered). Fixed text input bug that could cause the program to crash.
cd0969c Merge pull request #341 from mmozeiko/master
aa3ffd6 GDI+ simplified image loading, added error checking and image freeing
2d1ea95 Adding SFML backends for Nuklear. Working on porting over the OpenGL 2 renderer from the GLFW and SDL examples. Still some rendering bugs I would like some help on.
7483f7c Fix panel clipping
6fa8424 Make NK_API 'static inline' for NK_PRIVATE version
d536d4e Merge pull request #337 from DeXP/master
35e8558 GDI+ split rendering GUI and clear surface
2df399e Merge pull request #336 from DeXP/master
4442697 GDI+ set text color only once
5d98939 GDI+ text transparent background fix
020acd4 Merge pull request #335 from DeXP/master
9cd5d03 Remove warning "unsigned only in ISO C90"
ef2dcd3 Added function to remove edit focus #321
3123ba0 Merge pull request #330 from DeXP/master
f5447a8 Fixed typo _WIN64 instead of __WIN64
6b27c20 Fixed #331 with graceful x11 window closing
16c2ddd Fix typo
7d52c0d Remove warning: 'nk_to_upper' defined but not used
2e9c4ee Merge pull request #329 from DeXP/master
4a3573b Merge branch 'master' of git://github.com/vurtun/nuklear
36c6054 Remove unused panel warnings
431e675 Merge pull request #327 from DeXP/master
6f8fe8d Fixed input capture from hidden or closed windows
bd44f4f Removed temporary file
8892727 Fixed slider behavior and drawing
8033c40 Added loading TTF font from file
b544d61 Merge pull request #324 from DeXP/master
4d957de Define IStream interface
5011a36 Updated CHANGELOG format and versioning
34d0fcd Merged #198 with bottom-left corner scaler
be7ac9b Updated Makefile as of #256
aa1f516 Added row template layout example to demo/overview
13c785d Fixed #322 C89 compiler error
f2ea71a Merge branch 'master' of https://github.com/vurtun/gui
da347ee Added additional layouting method
14f107b Merge pull request #318 from DeXP/master
24f4e3f GDI+ load font from memory added
7ab7327 nk_gdip_fill_rect filled pies fix
24c756c Merge pull request #315 from seibelj/allegro5_impl
5ad1978 Merge pull request #316 from DeXP/master
7dbd9f9 PR fixes. Removed all keyboard callback code as it can be accomplished with nk_edit flags
e6798bc Removed keyboard callbacks because they are unnecessary
5aedddd Added GDI+ images support
840f539 Added OLE32 to dependencies list
bc6c9c7 Added readme and keyboard handler example files
6d5fba0 Removed display checkers because they appear not to work for custom events. Also fixed up whitespace and changed a variable name from nil to none because of objective-c conflicting
1cf83d2 Improved soft keyboard support
bde7c3c Fix for multitouch causing issues
4e3689a Merge branch 'master' into allegro5_impl
58afd4f Fixed typo inside GLFW demo #311
a9330ad Fixed closing window bug of minimized windows #291
64102b5 Fixed missing Readme newline
12515ca nk_gdip_fill_rect coordinates fix
780d88f Set window bounds in nk_begin when the window isn't user-resizable
16c084c fixed relative path of demo fonts in d3d11 sample
73e5801 Fixes for touch events
63e2cba initial touch support
011187b Merge pull request #313 from inolen/master
baa8ad8 build fix for gcc
e63ae83 Extended 16-bit scrollbar offsets to 32-bit #312
eb58042 Merge branch 'master' into allegro5_impl
533d5d2 Much progress on allegro5 impl. Also added SELCT_ALL command
a835309 Fixed typo inside GLFW demo #311
020a562 Fixed closing window bug of minimized windows #291
a4010b1 Fixed missing Readme newline
21f406f Merge pull request #306 from juliuszint/master
55485f6 Merge pull request #309 from inolen/master
4adc5c0 Merge pull request #310 from DeXP/master
e2c4855 Added initial work for allegro5 backend
d6ac1e4 nk_gdip_fill_rect coordinates fix
76ebc40 Set window bounds in nk_begin when the window isn't user-resizable
1383490 fixed relative path of demo fonts in d3d11 sample
9b7a280 Removed osx travis because it sucks
0273b7c Added chicken binding reference
3a7486c Extended assert explanation #301
REVERT: 407126c fix NK_COMMAND_ARC/NK_COMMAND_ARC_FILLED.
REVERT: 12257a48 omk: don't clear draw_list.
REVERT: c9303e8a omk: fix group border.
REVERT: 928cd5f2 omk: fix lost scrollbar state in nk_edit_buffer.
REVERT: 3074c95b omk: fix lexer code to work with utf8.
REVERT: 08924f1b add support for syntax highlighting

git-subtree-dir: nuklear
git-subtree-split: e8761c79c5b213af87f53d7dafe37a54b5fc3277
parent 55f05217
demo/*/*.exe
demo/*/*.obj
docs/xml
docs/build
docs/src
*.tmp
[submodule "docs/build/html"]
path = docs/build/html
url = https://github.com/nuklear-ui/nuklear-ui.github.io
conda:
file: docs/environment.yml
......@@ -2,7 +2,6 @@ language: c
os:
- linux
- osx
compiler:
- gcc
......@@ -10,7 +9,7 @@ compiler:
before_install:
- if [ $TRAVIS_OS_NAME == linux ]; then sudo add-apt-repository -y ppa:pyglfw/pyglfw && sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libglew-dev; fi
- if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install glfw3 && brew install glew; fi
script:
- make -C demo/glfw_opengl3
- make -C demo/glfw_opengl2
This diff is collapsed.
# Nuklear
[![Build Status](https://travis-ci.org/vurtun/nuklear.svg)](https://travis-ci.org/vurtun/nuklear)
# Nuklear
This is a minimal state immediate mode graphical user interface toolkit
written in ANSI C and licensed under public domain. It was designed as a simple
embeddable user interface for application and does not have any dependencies,
......@@ -11,10 +12,11 @@ layered library that tries to abstract over a number of platform and
render backends it only focuses on the actual UI.
## Features
- Immediate mode graphical user interface toolkit
- Single header library
- Written in C89 (ANSI C)
- Small codebase (~15kLOC)
- Small codebase (~18kLOC)
- Focus on portability, efficiency and simplicity
- No dependencies (not even the standard library if not wanted)
- Fully skinnable and customizable
......@@ -25,6 +27,7 @@ render backends it only focuses on the actual UI.
- Optional font baker and vertex buffer output
## Building
This library is self contained in one single header file and can be used either
in header only mode or in implementation mode. The header only mode is used
by default when included and allows including this header in other headers
......@@ -40,6 +43,7 @@ IMPORTANT: Every time you include "nuklear.h" you have to define the same option
This is very important not doing it either leads to compiler errors or even worse stack corruptions.
## Gallery
![screenshot](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif)
![screen](https://cloud.githubusercontent.com/assets/8057201/13538240/acd96876-e249-11e5-9547-5ac0b19667a0.png)
![screen2](https://cloud.githubusercontent.com/assets/8057201/13538243/b04acd4c-e249-11e5-8fd2-ad7744a5b446.png)
......@@ -48,15 +52,16 @@ This is very important not doing it either leads to compiler errors or even wors
![gamepad](https://cloud.githubusercontent.com/assets/8057201/14902576/339926a8-0d9c-11e6-9fee-a8b73af04473.png)
## Example
```c
/* init gui state */
struct nk_context ctx;
nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
enum {EASY, HARD};
int op = EASY;
float value = 0.6f;
int i = 20;
static int op = EASY;
static float value = 0.6f;
static int i = 20;
if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
......@@ -85,12 +90,19 @@ nk_end(&ctx);
```
![example](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png)
## Bindings:
Java: https://github.com/glegris/nuklear4j
Golang: https://github.com/golang-ui/nuklear
Rust: https://github.com/snuk182/nuklear-rust
## Bindings
There are a number of nuklear bindings for different languges created by other authors.
I cannot atest for their quality since I am not necessarily proficient in either of these
languages. Furthermore there are no guarantee that all bindings will always be kept up to date:
## Credits:
- [Java](https://github.com/glegris/nuklear4j) by Guillaume Legris
- [Golang](https://github.com/golang-ui/nuklear) by golang-ui@github.com
- [Rust](https://github.com/snuk182/nuklear-rust) by snuk182@github.com
- [Chicken](https://github.com/wasamasa/nuklear) by wasamasa@github.comx
- [Nim](https://github.com/zacharycarter/nuklear-nim) by zacharycarter@github.com
- [Lua/Löve2d](https://github.com/keharriso/love-nuklear) by Kevin Harrison
## Credits
Developed by Micha Mettke and every direct or indirect contributor to the GitHub.
......@@ -104,7 +116,8 @@ and his original immediate mode graphical user interface idea and Sean
Barret for his amazing single header [libraries](https://github.com/nothings/stb) which restored my faith
in libraries and brought me to create some of my own.
## License:
## License
This software is dual-licensed to the public domain and under the following
license: you are granted a perpetual, irrevocable license to copy, modify,
publish and distribute this file as you see fit.
......
#import <UIKit/UIKit.h>
#include <allegro5/allegro.h>
@interface KeyboardHandleriOS : UIView <UIKeyInput>
-(void)setCustomKeyboardEventSource:(ALLEGRO_EVENT_SOURCE*)ev_src;
-(void)show;
-(void)hide;
@end
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "KeyboardHandleriOS.h"
#include <allegro5/allegro.h>
#include <allegro5/allegro_iphone_objc.h>
@interface KeyboardHandleriOS()
{
ALLEGRO_EVENT_SOURCE *event_source;
ALLEGRO_DISPLAY *current_display;
}
@end
@implementation KeyboardHandleriOS
- (id)init {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
self = [self initWithFrame:CGRectMake(-100, -100, 0, 0)];
event_source = NULL;
current_display = al_get_current_display();
UIView* v = al_iphone_get_view(current_display);
[v addSubview:self];
return self;
}
- (void)setCustomKeyboardEventSource:(ALLEGRO_EVENT_SOURCE *)ev_src {
event_source = ev_src;
}
- (UIKeyboardType) keyboardType
{
return UIKeyboardTypeASCIICapable;
}
- (UITextAutocorrectionType) autocorrectionType
{
return UITextAutocorrectionTypeNo;
}
-(BOOL)canBecomeFirstResponder {
return YES;
}
- (void)deleteBackward {
if (!event_source) {
NSLog(@"deleteBackward(): No event source found, not sending events");
return;
}
ALLEGRO_EVENT *event_down = (ALLEGRO_EVENT*)calloc(1, sizeof(ALLEGRO_EVENT));
ALLEGRO_EVENT *event_up = (ALLEGRO_EVENT*)calloc(1, sizeof(ALLEGRO_EVENT));
event_down->type = ALLEGRO_EVENT_KEY_DOWN;
event_down->keyboard.display = current_display;
event_down->keyboard.keycode = ALLEGRO_KEY_BACKSPACE;
event_up->type = ALLEGRO_EVENT_KEY_UP;
event_up->keyboard.display = current_display;
event_up->keyboard.keycode = ALLEGRO_KEY_BACKSPACE;
al_emit_user_event(event_source, event_down, NULL);
al_emit_user_event(event_source, event_up, NULL);
free(event_down);
free(event_up);
}
- (BOOL)hasText {
return YES;
}
- (void)insertText:(NSString *)text
{
if (!event_source) {
NSLog(@"insertText(): No event source found, not sending events");
return;
}
ALLEGRO_EVENT *event_down = (ALLEGRO_EVENT*)calloc(1, sizeof(ALLEGRO_EVENT));
ALLEGRO_EVENT *event_up = (ALLEGRO_EVENT*)calloc(1, sizeof(ALLEGRO_EVENT));
if([text isEqualToString:@"\n"])
{
event_down->type = ALLEGRO_EVENT_KEY_DOWN;
event_down->keyboard.display = current_display;
event_down->keyboard.keycode = ALLEGRO_KEY_ENTER;
event_up->type = ALLEGRO_EVENT_KEY_UP;
event_up->keyboard.display = current_display;
event_up->keyboard.keycode = ALLEGRO_KEY_ENTER;
al_emit_user_event(event_source, event_down, NULL);
al_emit_user_event(event_source, event_up, NULL);
[self hide];
//m_kb->setDonePressed();
}
else {
event_down->type = ALLEGRO_EVENT_KEY_CHAR;
event_down->keyboard.display = current_display;
event_down->keyboard.unichar = [text characterAtIndex:0];
// doesn't matter what keycode is, nuklear backend ignores it as long as it
// isn't a special key
event_down->keyboard.keycode = ALLEGRO_KEY_A;
al_emit_user_event(event_source, event_down, NULL);
}
free(event_down);
free(event_up);
}
-(void)show {
NSLog(@"Should be showing!");
[self performSelectorOnMainThread:@selector(becomeFirstResponder) withObject:nil waitUntilDone:YES];
}
-(void)hide {
NSLog(@"Should be hiding!");
[self performSelectorOnMainThread:@selector(resignFirstResponder) withObject:nil waitUntilDone:YES];
}
- (void)keyboardDidHide:(NSNotification *)notification {
NSLog(@"keyboardDidHide called");
}
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
}
@end
# Install
BIN = demo
# Flags
CFLAGS = -std=c99 -pedantic -O2
SRC = main.c
OBJ = $(SRC:.c=.o)
# TODO: Handle Windows build
#ifeq ($(OS),Windows_NT)
#BIN := $(BIN).exe
#LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32
#else
LIBS = -lallegro -lallegro_main -lallegro_image -lallegro_font \
-lallegro_ttf -lallegro_primitives -lm
#endif
$(BIN):
@mkdir -p bin
rm -f bin/$(BIN) $(OBJS)
$(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS)
# Allegro v5 nuklear backend
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.
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.
## Compiling
You must link with image, font, ttf, and primitives Allegro addons. See the `Makefile`.
## Resolutions
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.
## Soft Keyboard for Touch Screen Devices
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
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
To know when nuklear wants to open and close the keyboard, you can check edit widget flags:
```
nk_flags ed_flags = nk_edit_string(ctx, NK_EDIT_FIELD, field_buffer, &field_len, 64, nk_filter_default);
if (ed_flags & NK_EDIT_ACTIVATED)
open_ios_soft_keyboard();
if (ed_flags & NK_EDIT_DEACTIVATED)
close_ios_soft_keyboard();
```
### Manual Soft Keyboard Dismissal
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.
### The Keyboard Covers Widgets
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.
\ No newline at end of file
/* nuklear - 1.32.0 - public domain */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <math.h>
#include <limits.h>
#include <time.h>
#include <allegro5/allegro.h>
#define WINDOW_WIDTH 1200
#define WINDOW_HEIGHT 800
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_IMPLEMENTATION
#define NK_ALLEGRO5_IMPLEMENTATION
#include "../../nuklear.h"
#include "nuklear_allegro5.h"
#define UNUSED(a) (void)a
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) < (b) ? (b) : (a))
#define LEN(a) (sizeof(a)/sizeof(a)[0])
/* ===============================================================
*
* EXAMPLE
*
* ===============================================================*/
/* This are some code examples to provide a small overview of what can be
* done with this library. To try out an example uncomment the include
* and the corresponding function. */
/*#include "../style.c"*/
/*#include "../calculator.c"*/
#include "../overview.c"
/*#include "../node_editor.c"*/
/* ===============================================================
*
* DEMO
*
* ===============================================================*/
static void error_callback(int e, const char *d)
{printf("Error %d: %s\n", e, d);}
int main(void)
{
/* Platform */
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
if (!al_init()) {
fprintf(stdout, "failed to initialize allegro5!\n");
exit(1);
}
al_install_mouse();
al_set_mouse_wheel_precision(150);
al_install_keyboard();
al_set_new_display_flags(ALLEGRO_WINDOWED|ALLEGRO_RESIZABLE|ALLEGRO_OPENGL);
al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);
display = al_create_display(WINDOW_WIDTH, WINDOW_HEIGHT);
if (!display) {
fprintf(stdout, "failed to create display!\n");
exit(1);
}
event_queue = al_create_event_queue();
if (!event_queue) {
fprintf(stdout, "failed to create event_queue!\n");
al_destroy_display(display);
exit(1);
}
al_register_event_source(event_queue, al_get_display_event_source(display));
al_register_event_source(event_queue, al_get_mouse_event_source());
al_register_event_source(event_queue, al_get_keyboard_event_source());
NkAllegro5Font *font;
font = nk_allegro5_font_create_from_file("../../../extra_font/Roboto-Regular.ttf", 12, 0);
struct nk_context *ctx;
ctx = nk_allegro5_init(font, display, WINDOW_WIDTH, WINDOW_HEIGHT);
/* style.c */
/*set_style(ctx, THEME_WHITE);*/
/*set_style(ctx, THEME_RED);*/
/*set_style(ctx, THEME_BLUE);*/
/*set_style(ctx, THEME_DARK);*/
while(1)
{
ALLEGRO_EVENT ev;
ALLEGRO_TIMEOUT timeout;
al_init_timeout(&timeout, 0.06);
bool get_event = al_wait_for_event_until(event_queue, &ev, &timeout);
if (get_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
break;
}
/* Very Important: Always do nk_input_begin / nk_input_end even if
there are no events, otherwise internal nuklear state gets messed up */
nk_input_begin(ctx);
if (get_event) {
while (get_event) {
nk_allegro5_handle_event(&ev);
get_event = al_get_next_event(event_queue, &ev);
}
}
nk_input_end(ctx);
/* GUI */
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
enum {EASY, HARD};
static int op = EASY;
static int property = 20;
nk_layout_row_static(ctx, 30, 80, 1);
if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");
nk_layout_row_dynamic(ctx, 30, 2);
if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
nk_layout_row_dynamic(ctx, 22, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
}
nk_end(ctx);
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
overview(ctx);
/*node_editor(ctx);*/
/* ----------------------------------------- */
/* Draw */
al_clear_to_color(al_map_rgb(19, 43, 81));
/* IMPORTANT: `nk_allegro5_render` changes the target backbuffer
to the display set at initialization and does not restore it.
Change it if you want to draw somewhere else. */
nk_allegro5_render();
al_flip_display();
}
nk_allegro5_font_del(font);
nk_allegro5_shutdown();
al_destroy_display(display);
al_destroy_event_queue(event_queue);
return 0;
}
This diff is collapsed.
/* nuklear - v1.17 - public domain */
/* nuklear - 1.32.0 - public domain */
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
......@@ -131,6 +131,7 @@ int main(void)
/* Win32 */
memset(&wc, 0, sizeof(wc));
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = WindowProc;
wc.hInstance = GetModuleHandleW(0);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
......@@ -177,12 +178,12 @@ int main(void)
/* Load Cursor: if you uncomment cursor loading please hide the cursor */
{struct nk_font_atlas *atlas;
nk_d3d11_font_stash_begin(&atlas);
/*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/
/*struct nk_font *robot = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Robot-Regular.ttf", 14, 0);*/
/*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/
/*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/
/*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/
/*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/
/*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../extra_font/DroidSans.ttf", 14, 0);*/
/*struct nk_font *robot = nk_font_atlas_add_from_file(atlas, "../../extra_font/Roboto-Regular.ttf", 14, 0);*/
/*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../extra_font/kenvector_future_thin.ttf", 13, 0);*/
/*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../extra_font/ProggyClean.ttf", 12, 0);*/
/*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../extra_font/ProggyTiny.ttf", 10, 0);*/
/*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../extra_font/Cousine-Regular.ttf", 13, 0);*/
nk_d3d11_font_stash_end();
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle)*/;}
......@@ -241,7 +242,6 @@ int main(void)
}
}
nk_end(ctx);
if (nk_window_is_closed(ctx, "Demo")) break;
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
......
/*
* Nuklear - v1.17 - public domain
* Nuklear - 1.32.0 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
......@@ -316,6 +316,7 @@ nk_d3d11_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 1;
case WM_LBUTTONUP:
nk_input_button(&d3d11.ctx, NK_BUTTON_DOUBLE, (short)LOWORD(lparam), (short)HIWORD(lparam), 0);
nk_input_button(&d3d11.ctx, NK_BUTTON_LEFT, (short)LOWORD(lparam), (short)HIWORD(lparam), 0);
ReleaseCapture();
return 1;
......@@ -341,12 +342,16 @@ nk_d3d11_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 1;
case WM_MOUSEWHEEL:
nk_input_scroll(&d3d11.ctx, (float)(short)HIWORD(wparam) / WHEEL_DELTA);
nk_input_scroll(&d3d11.ctx, nk_vec2(0,(float)(short)HIWORD(wparam) / WHEEL_DELTA));
return 1;
case WM_MOUSEMOVE:
nk_input_motion(&d3d11.ctx, (short)LOWORD(lparam), (short)HIWORD(lparam));
return 1;
case WM_LBUTTONDBLCLK:
nk_input_button(&d3d11.ctx, NK_BUTTON_DOUBLE, (short)LOWORD(lparam), (short)HIWORD(lparam), 1);
return 1;
}
return 0;
......
@echo off
rem This will use VS2015 for compiler
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
cl /D_CRT_SECURE_NO_DEPRECATE /nologo /W3 /O2 /fp:fast /Gm- /Fedemo.exe main.c user32.lib d3d9.lib /link /incremental:no
This diff is collapsed.
This diff is collapsed.
/* nuklear - v1.17 - public domain */
/* nuklear - 1.32.0 - public domain */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
......@@ -74,6 +74,7 @@ int main(void)
/* Win32 */
memset(&wc, 0, sizeof(wc));
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = WindowProc;
wc.hInstance = GetModuleHandleW(0);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
......@@ -141,7 +142,6 @@ int main(void)
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
}
nk_end(ctx);
if (nk_window_is_closed(ctx, "Demo")) break;
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
......
/*
* Nuklear - v1.17 - public domain
* Nuklear - 1.32.0 - public domain
* no warrenty implied; use at your own risk.
* authored from 2015-2016 by Micha Mettke
*/
......@@ -57,6 +57,78 @@ static struct {
struct nk_context ctx;
} gdi;
static void
nk_create_image(struct nk_image * image, const char * frame_buffer, const int width, const int height)
{
if (image && frame_buffer && (width > 0) && (height > 0))
{
image->w = width;
image->h = height;
image->region[0] = 0;
image->region[1] = 0;
image->region[2] = width;
image->region[3] = height;
INT row = ((width * 3 + 3) & ~3);
BITMAPINFO bi = { 0 };
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = width;
bi.bmiHeader.biHeight = height;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = row * height;
LPBYTE lpBuf, pb = NULL;
HBITMAP hbm = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**)&lpBuf, NULL, 0);
pb = lpBuf + row * height;
unsigned char * src = (unsigned char *)frame_buffer;
for (int v = 0; v<height; v++)
{
pb -= row;
for (int i = 0; i < row; i += 3)
{
pb[i + 0] = src[0];
pb[i + 1] = src[1];
pb[i + 2] = src[2];
src += 3;
}
}
SetDIBits(NULL, hbm, 0, height, lpBuf, &bi, DIB_RGB_COLORS);
image->handle.ptr = hbm;
}
}
static void
nk_delete_image(struct nk_image * image)
{
if (image && image->handle.id != 0)
{
HBITMAP hbm = image->handle.ptr;
DeleteObject(hbm);
memset(image, 0, sizeof(struct nk_image));
}
}
static void
nk_gdi_draw_image(short x, short y, unsigned short w, unsigned short h,
struct nk_image img, struct nk_color col)
{
HBITMAP hbm = img.handle.ptr;
HDC hDCBits;
BITMAP bitmap;
if (!gdi.memory_dc || !hbm)
return;
hDCBits = CreateCompatibleDC(gdi.memory_dc);
GetObject(hbm, sizeof(BITMAP), (LPSTR)&bitmap);
SelectObject(hDCBits, hbm);
StretchBlt(gdi.memory_dc, x, y, w, h, hDCBits, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
DeleteDC(hDCBits);
}
static COLORREF
convert_color(struct nk_color c)
{
......@@ -627,6 +699,7 @@ nk_gdi_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 1;
case WM_LBUTTONUP:
nk_input_button(&gdi.ctx, NK_BUTTON_DOUBLE, (short)LOWORD(lparam), (short)HIWORD(lparam), 0);
nk_input_button(&gdi.ctx, NK_BUTTON_LEFT, (short)LOWORD(lparam), (short)HIWORD(lparam), 0);
ReleaseCapture();
return 1;
......@@ -652,12 +725,16 @@ nk_gdi_handle_event(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 1;
case WM_MOUSEWHEEL:
nk_input_scroll(&gdi.ctx, (float)(short)HIWORD(wparam) / WHEEL_DELTA);
nk_input_scroll(&gdi.ctx, nk_vec2(0,(float)(short)HIWORD(wparam) / WHEEL_DELTA));
return 1;
case WM_MOUSEMOVE:
nk_input_motion(&gdi.ctx, (short)LOWORD(lparam), (short)HIWORD(lparam));
return 1;
case WM_LBUTTONDBLCLK:
nk_input_button(&gdi.ctx, NK_BUTTON_DOUBLE, (short)LOWORD