nuklear 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE.txt +21 -0
- data/README.md +196 -0
- data/Rakefile +26 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/arial.ttf +0 -0
- data/examples/calculator.rb +102 -0
- data/examples/hello_nuklear.rb +182 -0
- data/examples/lib/opengl_font.rb +32 -0
- data/examples/lib/opengl_init.rb +4 -0
- data/examples/lib/sdl2_init.rb +6 -0
- data/examples/lib/sdl2_input.rb +81 -0
- data/examples/lib/window.rb +47 -0
- data/ext/freetype/extconf.rb +26 -0
- data/ext/nuklear/extconf.rb +14 -0
- data/ext/nuklear/nkrb.c +79 -0
- data/ext/nuklear/nkrb.h +89 -0
- data/ext/nuklear/nkrb_buffer.c +80 -0
- data/ext/nuklear/nkrb_context.c +241 -0
- data/ext/nuklear/nkrb_font.c +80 -0
- data/ext/nuklear/nkrb_renderer.c +114 -0
- data/ext/nuklear/nkrb_style.c +61 -0
- data/ext/nuklear/nkrb_style_color.c +126 -0
- data/ext/nuklear/nkrb_style_image.c +32 -0
- data/ext/nuklear/nkrb_ui.c +32 -0
- data/ext/nuklear/nkrb_ui_builder.c +29 -0
- data/ext/nuklear/nkrb_ui_button.c +55 -0
- data/ext/nuklear/nkrb_ui_color_picker.c +20 -0
- data/ext/nuklear/nkrb_ui_combo.c +73 -0
- data/ext/nuklear/nkrb_ui_container.c +7 -0
- data/ext/nuklear/nkrb_ui_edit_string.c +38 -0
- data/ext/nuklear/nkrb_ui_group.c +27 -0
- data/ext/nuklear/nkrb_ui_label.c +30 -0
- data/ext/nuklear/nkrb_ui_layout.c +125 -0
- data/ext/nuklear/nkrb_ui_menu.c +49 -0
- data/ext/nuklear/nkrb_ui_menu_item.c +30 -0
- data/ext/nuklear/nkrb_ui_menubar.c +18 -0
- data/ext/nuklear/nkrb_ui_popup.c +24 -0
- data/ext/nuklear/nkrb_ui_progress.c +19 -0
- data/ext/nuklear/nkrb_ui_property.c +20 -0
- data/ext/nuklear/nkrb_ui_selectables.c +53 -0
- data/ext/nuklear/nkrb_ui_slider.c +19 -0
- data/ext/nuklear/nkrb_ui_tree.c +29 -0
- data/ext/nuklear/nkrb_ui_widget.c +7 -0
- data/ext/nuklear/nkrb_ui_window.c +43 -0
- data/ext/nuklear/nuklear.h +23378 -0
- data/ext/nuklear_renderer_opengl2/KHR/khrplatform.h +285 -0
- data/ext/nuklear_renderer_opengl2/extconf.rb +13 -0
- data/ext/nuklear_renderer_opengl2/glad.c +1432 -0
- data/ext/nuklear_renderer_opengl2/glad.h +2747 -0
- data/ext/nuklear_renderer_opengl2/nuklear_renderer_opengl2.c +197 -0
- data/ext/nuklear_renderer_opengl4/KHR/khrplatform.h +285 -0
- data/ext/nuklear_renderer_opengl4/extconf.rb +13 -0
- data/ext/nuklear_renderer_opengl4/glad.c +1782 -0
- data/ext/nuklear_renderer_opengl4/glad.h +3687 -0
- data/ext/nuklear_renderer_opengl4/nuklear_renderer_opengl4.c +255 -0
- data/lib/nuklear/context.rb +49 -0
- data/lib/nuklear/dsl.rb +46 -0
- data/lib/nuklear/event_buffer.rb +23 -0
- data/lib/nuklear/renderer/opengl24.rb +13 -0
- data/lib/nuklear/renderer.rb +108 -0
- data/lib/nuklear/style/color.rb +24 -0
- data/lib/nuklear/style/image.rb +9 -0
- data/lib/nuklear/style.rb +8 -0
- data/lib/nuklear/test_case.rb +30 -0
- data/lib/nuklear/ui/base.rb +34 -0
- data/lib/nuklear/ui/button.rb +77 -0
- data/lib/nuklear/ui/checkbox.rb +39 -0
- data/lib/nuklear/ui/col.rb +21 -0
- data/lib/nuklear/ui/color_picker.rb +31 -0
- data/lib/nuklear/ui/combo_box.rb +42 -0
- data/lib/nuklear/ui/container.rb +80 -0
- data/lib/nuklear/ui/edit_string.rb +48 -0
- data/lib/nuklear/ui/enableable.rb +29 -0
- data/lib/nuklear/ui/events.rb +23 -0
- data/lib/nuklear/ui/group.rb +31 -0
- data/lib/nuklear/ui/label.rb +21 -0
- data/lib/nuklear/ui/menu.rb +43 -0
- data/lib/nuklear/ui/menu_bar.rb +19 -0
- data/lib/nuklear/ui/menu_item.rb +34 -0
- data/lib/nuklear/ui/option.rb +17 -0
- data/lib/nuklear/ui/option_group.rb +22 -0
- data/lib/nuklear/ui/popup.rb +37 -0
- data/lib/nuklear/ui/progress.rb +33 -0
- data/lib/nuklear/ui/property.rb +28 -0
- data/lib/nuklear/ui/row.rb +28 -0
- data/lib/nuklear/ui/select_list.rb +31 -0
- data/lib/nuklear/ui/selectable.rb +21 -0
- data/lib/nuklear/ui/slider.rb +26 -0
- data/lib/nuklear/ui/text_align.rb +14 -0
- data/lib/nuklear/ui/tree.rb +62 -0
- data/lib/nuklear/ui/window.rb +175 -0
- data/lib/nuklear/ui.rb +33 -0
- data/lib/nuklear/version.rb +3 -0
- data/lib/nuklear.rb +26 -0
- data/nuklear.gemspec +41 -0
- metadata +233 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_group(VALUE self, VALUE rcontext, VALUE rtitle, VALUE rflags, VALUE rscroll_x, VALUE rscroll_y) {
|
4
|
+
struct nk_context *context = nkrb_context_get(rcontext);
|
5
|
+
const char *title = StringValueCStr(rtitle);
|
6
|
+
int flags = FIX2INT(rflags);
|
7
|
+
unsigned int scroll_x = (unsigned int) FIX2INT(rscroll_x);
|
8
|
+
unsigned int scroll_y = (unsigned int) FIX2INT(rscroll_y);
|
9
|
+
int result = nk_group_scrolled_offset_begin(context, &scroll_x, &scroll_y, title, flags);
|
10
|
+
|
11
|
+
if (result) {
|
12
|
+
if (rb_block_given_p()) {
|
13
|
+
instance_eval_block(self);
|
14
|
+
}
|
15
|
+
nk_group_end(context);
|
16
|
+
VALUE scroll = rb_ary_new();
|
17
|
+
rb_ary_push(scroll, INT2FIX(scroll_x));
|
18
|
+
rb_ary_push(scroll, INT2FIX(scroll_y));
|
19
|
+
return scroll;
|
20
|
+
}
|
21
|
+
|
22
|
+
return Qnil;
|
23
|
+
}
|
24
|
+
|
25
|
+
void nkrb_ui_group_init(void) {
|
26
|
+
rb_define_method(mNuklearUIContainer, "ui_group", nkrb_ui_group, 5);
|
27
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_label(VALUE self, VALUE rcontext, VALUE text, VALUE rcolor, VALUE rwrap, VALUE ralign) {
|
4
|
+
struct nk_context *context = nkrb_context_get(rcontext);
|
5
|
+
int align = FIX2INT(ralign);
|
6
|
+
|
7
|
+
if (RTEST(rwrap)) {
|
8
|
+
if (NIL_P(rcolor)) {
|
9
|
+
nk_text_wrap(context, StringValuePtr(text), (int) RSTRING_LEN(text));
|
10
|
+
} else {
|
11
|
+
struct nk_color color;
|
12
|
+
ASSIGN_STYLE_AS_COLOR(color, nkrb_style_item(rcolor));
|
13
|
+
nk_text_wrap_colored(context, StringValuePtr(text), (int) RSTRING_LEN(text), color);
|
14
|
+
}
|
15
|
+
} else {
|
16
|
+
if (NIL_P(rcolor)) {
|
17
|
+
nk_text(context, StringValuePtr(text), (int) RSTRING_LEN(text), align);
|
18
|
+
} else {
|
19
|
+
struct nk_color color;
|
20
|
+
ASSIGN_STYLE_AS_COLOR(color, nkrb_style_item(rcolor));
|
21
|
+
nk_text_colored(context, StringValuePtr(text), (int) RSTRING_LEN(text), align, color);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
return Qnil;
|
26
|
+
}
|
27
|
+
|
28
|
+
void nkrb_ui_label_init(void) {
|
29
|
+
rb_define_method(mNuklearUIContainer, "ui_label", nkrb_ui_label, 5);
|
30
|
+
}
|
@@ -0,0 +1,125 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_layout_row(VALUE self, VALUE rcontext, VALUE rformat, VALUE rheight, VALUE rratios) {
|
4
|
+
struct nk_context *ctx = nkrb_context_get(rcontext);
|
5
|
+
enum nk_layout_format fmt = NK_DYNAMIC;
|
6
|
+
if (SYM2ID(rformat) == rb_intern("static")) fmt = NK_STATIC;
|
7
|
+
float height = (float) NUM2DBL(rheight);
|
8
|
+
int len = (int) RARRAY_LEN(rratios);
|
9
|
+
float *ratios = malloc(len * sizeof(float));
|
10
|
+
int i;
|
11
|
+
for (i = 0; i < len; i++) {
|
12
|
+
ratios[i] = (float) NUM2DBL(rb_ary_entry(rratios, i));
|
13
|
+
}
|
14
|
+
nk_layout_row(ctx, fmt, height, len, ratios);
|
15
|
+
free(ratios);
|
16
|
+
return Qnil;
|
17
|
+
}
|
18
|
+
|
19
|
+
VALUE nkrb_ui_layout_row_dynamic(VALUE self, VALUE context, VALUE height, VALUE ncols) {
|
20
|
+
nk_layout_row_dynamic(nkrb_context_get(context), (float) NUM2DBL(height), FIX2INT(ncols));
|
21
|
+
return Qtrue;
|
22
|
+
}
|
23
|
+
|
24
|
+
VALUE nkrb_ui_layout_row_static(VALUE self, VALUE context, VALUE height, VALUE col_width, VALUE ncols) {
|
25
|
+
nk_layout_row_static(nkrb_context_get(context), (float) NUM2DBL(height), FIX2INT(col_width), FIX2INT(ncols));
|
26
|
+
return Qtrue;
|
27
|
+
}
|
28
|
+
|
29
|
+
VALUE nkrb_ui_layout_row_begin(VALUE self, VALUE context, VALUE format, VALUE row_height, VALUE ncols) {
|
30
|
+
struct nk_context *ctx = nkrb_context_get(context);
|
31
|
+
enum nk_layout_format fmt = NK_DYNAMIC;
|
32
|
+
if (SYM2ID(format) == rb_intern("static")) fmt = NK_STATIC;
|
33
|
+
nk_layout_row_begin(ctx, fmt, (float) NUM2DBL(row_height), FIX2INT(ncols));
|
34
|
+
if (rb_block_given_p()) {
|
35
|
+
instance_eval_block(Qtrue);
|
36
|
+
}
|
37
|
+
nk_layout_row_end(ctx);
|
38
|
+
return Qnil;
|
39
|
+
}
|
40
|
+
|
41
|
+
VALUE nkrb_ui_layout_row_push(VALUE self, VALUE context, VALUE value) {
|
42
|
+
nk_layout_row_push(nkrb_context_get(context), (float) NUM2DBL(value));
|
43
|
+
return Qtrue;
|
44
|
+
}
|
45
|
+
|
46
|
+
VALUE nkrb_ui_layout_row_template_begin(VALUE self, VALUE context, VALUE height) {
|
47
|
+
nk_layout_row_template_begin(nkrb_context_get(context), (float) NUM2DBL(height));
|
48
|
+
return Qnil;
|
49
|
+
}
|
50
|
+
|
51
|
+
VALUE nkrb_ui_layout_row_template_push_dynamic(VALUE self, VALUE context) {
|
52
|
+
nk_layout_row_template_push_dynamic(nkrb_context_get(context));
|
53
|
+
return Qnil;
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE nkrb_ui_layout_row_template_push_variable(VALUE self, VALUE context, VALUE min_width) {
|
57
|
+
nk_layout_row_template_push_variable(nkrb_context_get(context), (float) NUM2DBL(min_width));
|
58
|
+
return Qnil;
|
59
|
+
}
|
60
|
+
|
61
|
+
VALUE nkrb_ui_layout_row_template_push_static(VALUE self, VALUE context, VALUE width) {
|
62
|
+
nk_layout_row_template_push_static(nkrb_context_get(context), (float) NUM2DBL(width));
|
63
|
+
return Qnil;
|
64
|
+
}
|
65
|
+
|
66
|
+
VALUE nkrb_ui_layout_row_template_end(VALUE self, VALUE context) {
|
67
|
+
nk_layout_row_template_end(nkrb_context_get(context));
|
68
|
+
return Qnil;
|
69
|
+
}
|
70
|
+
|
71
|
+
VALUE nkrb_ui_layout_space_begin(VALUE self, VALUE context, VALUE format, VALUE height, VALUE widget_count) {
|
72
|
+
enum nk_layout_format fmt = NK_DYNAMIC;
|
73
|
+
if (SYM2ID(format) == rb_intern("static")) fmt = NK_STATIC;
|
74
|
+
nk_layout_space_begin(nkrb_context_get(context), fmt, (float) NUM2DBL(height), FIX2INT(widget_count));
|
75
|
+
return Qnil;
|
76
|
+
}
|
77
|
+
|
78
|
+
VALUE nkrb_ui_layout_space_push(VALUE self, VALUE context, VALUE rbounds) {
|
79
|
+
VALUE left = rb_hash_aref(rbounds, ID2SYM(rb_intern("left")));
|
80
|
+
VALUE top = rb_hash_aref(rbounds, ID2SYM(rb_intern("top")));
|
81
|
+
VALUE width = rb_hash_aref(rbounds, ID2SYM(rb_intern("width")));
|
82
|
+
VALUE height = rb_hash_aref(rbounds, ID2SYM(rb_intern("height")));
|
83
|
+
if (NIL_P(left)) rb_raise(rb_eArgError, ":left option is required");
|
84
|
+
if (NIL_P(top)) rb_raise(rb_eArgError, ":top option is required");
|
85
|
+
if (NIL_P(width)) rb_raise(rb_eArgError, ":width option is required");
|
86
|
+
if (NIL_P(height)) rb_raise(rb_eArgError, ":height option is required");
|
87
|
+
float x = (float) NUM2DBL(left);
|
88
|
+
float y = (float) NUM2DBL(top);
|
89
|
+
float w = (float) NUM2DBL(width);
|
90
|
+
float h = (float) NUM2DBL(height);
|
91
|
+
nk_layout_space_push(nkrb_context_get(context), nk_rect(x, y, w, h));
|
92
|
+
return Qnil;
|
93
|
+
}
|
94
|
+
|
95
|
+
VALUE nkrb_ui_layout_space_end(VALUE self, VALUE context) {
|
96
|
+
nk_layout_space_end(nkrb_context_get(context));
|
97
|
+
return Qnil;
|
98
|
+
}
|
99
|
+
|
100
|
+
VALUE nkrb_ui_layout_widget_bounds(VALUE self, VALUE context) {
|
101
|
+
struct nk_rect bounds = nk_layout_widget_bounds(nkrb_context_get(context));
|
102
|
+
VALUE ret = rb_hash_new();
|
103
|
+
rb_hash_aset(ret, ID2SYM(rb_intern("left")), bounds.x);
|
104
|
+
rb_hash_aset(ret, ID2SYM(rb_intern("top")), bounds.y);
|
105
|
+
rb_hash_aset(ret, ID2SYM(rb_intern("width")), bounds.w);
|
106
|
+
rb_hash_aset(ret, ID2SYM(rb_intern("height")), bounds.h);
|
107
|
+
return Qnil;
|
108
|
+
}
|
109
|
+
|
110
|
+
void nkrb_ui_layout_init(void) {
|
111
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row", nkrb_ui_layout_row, 4);
|
112
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row_dynamic", nkrb_ui_layout_row_dynamic, 3);
|
113
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row_static", nkrb_ui_layout_row_static, 4);
|
114
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row_begin", nkrb_ui_layout_row_begin, 4);
|
115
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row_push", nkrb_ui_layout_row_push, 2);
|
116
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row_template_begin", nkrb_ui_layout_row_template_begin, 2);
|
117
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row_template_dynamic", nkrb_ui_layout_row_template_push_dynamic, 1);
|
118
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row_template_variable", nkrb_ui_layout_row_template_push_variable, 2);
|
119
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row_template_static", nkrb_ui_layout_row_template_push_static, 2);
|
120
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_row_template_end", nkrb_ui_layout_row_template_end, 1);
|
121
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_space_begin", nkrb_ui_layout_space_begin, 4);
|
122
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_space_push", nkrb_ui_layout_space_push, 2);
|
123
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_space_end", nkrb_ui_layout_space_end, 1);
|
124
|
+
rb_define_method(mNuklearUIContainer, "ui_layout_widget_bounds", nkrb_ui_layout_widget_bounds, 1);
|
125
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_menu(VALUE self, VALUE rcontext, VALUE roptions) {
|
4
|
+
struct nk_context *context = nkrb_context_get(rcontext);
|
5
|
+
|
6
|
+
VALUE rtitle = rb_hash_aref(roptions, ID2SYM(rb_intern("title")));
|
7
|
+
VALUE rimage = rb_hash_aref(roptions, ID2SYM(rb_intern("image")));
|
8
|
+
VALUE rsymbol = rb_hash_aref(roptions, ID2SYM(rb_intern("symbol")));
|
9
|
+
nk_flags align = FIX2INT(rb_hash_aref(roptions, ID2SYM(rb_intern("align"))));
|
10
|
+
float width = (float) NUM2DBL(rb_hash_aref(roptions, ID2SYM(rb_intern("width"))));
|
11
|
+
float height = (float) NUM2DBL(rb_hash_aref(roptions, ID2SYM(rb_intern("height"))));
|
12
|
+
struct nk_vec2 size = nk_vec2(width, height);
|
13
|
+
VALUE rid = rb_hash_aref(roptions, ID2SYM(rb_intern("id")));
|
14
|
+
|
15
|
+
enum nk_symbol_type symbol = NK_SYMBOL_NONE;
|
16
|
+
SET_RSYMBOL(symbol, rsymbol);
|
17
|
+
|
18
|
+
int result = 0;
|
19
|
+
if (!NIL_P(rimage)) {
|
20
|
+
struct nk_image img;
|
21
|
+
ASSIGN_STYLE_AS_IMAGE(img, nkrb_style_item(rimage))
|
22
|
+
if (!NIL_P(rtitle)) {
|
23
|
+
result = nk_menu_begin_image_text(context, RSTRING_PTR(rtitle), (int) RSTRING_LEN(rtitle), align, img, size);
|
24
|
+
} else {
|
25
|
+
rid = rb_funcall(rid, rb_intern("to_s"), 0);
|
26
|
+
result = nk_menu_begin_image(context, StringValueCStr(rid), img, size);
|
27
|
+
}
|
28
|
+
} else if (!NIL_P(rtitle)) {
|
29
|
+
result = nk_menu_begin_symbol_text(context, RSTRING_PTR(rtitle), (int) RSTRING_LEN(rtitle), align, symbol, size);
|
30
|
+
} else {
|
31
|
+
rid = rb_funcall(rid, rb_intern("to_s"), 0);
|
32
|
+
result = nk_menu_begin_symbol(context, StringValueCStr(rid), symbol, size);
|
33
|
+
}
|
34
|
+
|
35
|
+
if (result) {
|
36
|
+
if (rb_block_given_p()) {
|
37
|
+
rb_yield(Qtrue);
|
38
|
+
}
|
39
|
+
nk_menu_end(context);
|
40
|
+
} else {
|
41
|
+
return Qfalse;
|
42
|
+
}
|
43
|
+
|
44
|
+
return Qnil;
|
45
|
+
}
|
46
|
+
|
47
|
+
void nkrb_ui_menu_init(void) {
|
48
|
+
rb_define_method(mNuklearUIContainer, "ui_menu", nkrb_ui_menu, 2);
|
49
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_menu_item(VALUE self, VALUE rcontext, VALUE roptions) {
|
4
|
+
struct nk_context *context = nkrb_context_get(rcontext);
|
5
|
+
|
6
|
+
VALUE rtitle = rb_funcall(rb_hash_aref(roptions, ID2SYM(rb_intern("title"))), rb_intern("to_s"), 0);
|
7
|
+
VALUE rimage = rb_hash_aref(roptions, ID2SYM(rb_intern("image")));
|
8
|
+
VALUE rsymbol = rb_hash_aref(roptions, ID2SYM(rb_intern("symbol")));
|
9
|
+
nk_flags align = FIX2INT(rb_hash_aref(roptions, ID2SYM(rb_intern("align"))));
|
10
|
+
|
11
|
+
enum nk_symbol_type symbol = NK_SYMBOL_NONE;
|
12
|
+
SET_RSYMBOL(symbol, rsymbol);
|
13
|
+
|
14
|
+
int result = 0;
|
15
|
+
if (!NIL_P(rimage)) {
|
16
|
+
struct nk_image img;
|
17
|
+
ASSIGN_STYLE_AS_IMAGE(img, nkrb_style_item(rimage))
|
18
|
+
result = nk_menu_item_image_text(context, img, RSTRING_PTR(rtitle), (int) RSTRING_LEN(rtitle), align);
|
19
|
+
} else if (!NIL_P(rsymbol)) {
|
20
|
+
result = nk_menu_item_symbol_text(context, symbol, RSTRING_PTR(rtitle), (int) RSTRING_LEN(rtitle), align);
|
21
|
+
} else {
|
22
|
+
result = nk_menu_item_text(context, RSTRING_PTR(rtitle), (int) RSTRING_LEN(rtitle), align);
|
23
|
+
}
|
24
|
+
|
25
|
+
return result ? ID2SYM(rb_intern("clicked")) : Qnil;
|
26
|
+
}
|
27
|
+
|
28
|
+
void nkrb_ui_menu_item_init(void) {
|
29
|
+
rb_define_method(mNuklearUIContainer, "ui_menu_item", nkrb_ui_menu_item, 2);
|
30
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_menubar(VALUE self, VALUE rcontext) {
|
4
|
+
struct nk_context *context = nkrb_context_get(rcontext);
|
5
|
+
|
6
|
+
nk_menubar_begin(context);
|
7
|
+
|
8
|
+
if (rb_block_given_p()) {
|
9
|
+
rb_yield(Qtrue);
|
10
|
+
}
|
11
|
+
|
12
|
+
nk_menubar_end(context);
|
13
|
+
return Qnil;
|
14
|
+
}
|
15
|
+
|
16
|
+
void nkrb_ui_menubar_init(void) {
|
17
|
+
rb_define_method(mNuklearUIContainer, "ui_menubar", nkrb_ui_menubar, 1);
|
18
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_popup(VALUE self, VALUE context, VALUE rtype, VALUE rtitle, VALUE rflags, VALUE left, VALUE top, VALUE width, VALUE height) {
|
4
|
+
struct nk_context *ctx = nkrb_context_get(context);
|
5
|
+
const char *title = StringValueCStr(rtitle);
|
6
|
+
int type = FIX2INT(rtype);
|
7
|
+
int flags = FIX2INT(rflags);
|
8
|
+
float x = (float) NUM2DBL(left);
|
9
|
+
float y = (float) NUM2DBL(top);
|
10
|
+
float w = (float) NUM2DBL(width);
|
11
|
+
float h = (float) NUM2DBL(height);
|
12
|
+
if (nk_popup_begin(ctx, type, title, flags, nk_rect(x, y, w, h))) {
|
13
|
+
if (rb_block_given_p()) {
|
14
|
+
instance_eval_block(ID2SYM(rb_intern("visible")));
|
15
|
+
}
|
16
|
+
nk_popup_end(ctx);
|
17
|
+
return Qnil;
|
18
|
+
}
|
19
|
+
return ID2SYM(rb_intern("hidden"));
|
20
|
+
}
|
21
|
+
|
22
|
+
void nkrb_ui_popup_init(void) {
|
23
|
+
rb_define_method(mNuklearUIContainer, "ui_popup", nkrb_ui_popup, 8);
|
24
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_progress(VALUE self, VALUE context, VALUE rcurrent, VALUE rmax, VALUE rmodifiable) {
|
4
|
+
struct nk_context *ctx = nkrb_context_get(context);
|
5
|
+
nk_size current = (nk_size) NUM2LL(rcurrent);
|
6
|
+
nk_size max = (nk_size) NUM2LL(rmax);
|
7
|
+
int modifiable = nk_false;
|
8
|
+
if (RTEST(rmodifiable)) modifiable = nk_true;
|
9
|
+
|
10
|
+
if (nk_progress(ctx, ¤t, max, modifiable)) {
|
11
|
+
return LL2NUM(current);
|
12
|
+
}
|
13
|
+
|
14
|
+
return Qnil;
|
15
|
+
}
|
16
|
+
|
17
|
+
void nkrb_ui_progress_init(void) {
|
18
|
+
rb_define_method(mNuklearUIContainer, "ui_progress", nkrb_ui_progress, 4);
|
19
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_property(VALUE self, VALUE context, VALUE rid, VALUE rmin, VALUE rcurrent, VALUE rmax, VALUE rstep, VALUE rinc_per_pixel) {
|
4
|
+
struct nk_context *ctx = nkrb_context_get(context);
|
5
|
+
float min = (float) NUM2DBL(rmin);
|
6
|
+
float current = (float) NUM2DBL(rcurrent);
|
7
|
+
float max = (float) NUM2DBL(rmax);
|
8
|
+
float step = (float) NUM2DBL(rstep);
|
9
|
+
float inc_pp = (float) NUM2DBL(rinc_per_pixel);
|
10
|
+
float prev = current;
|
11
|
+
rid = rb_funcall(rid, rb_intern("to_s"), 0);
|
12
|
+
|
13
|
+
nk_property_float(ctx, StringValueCStr(rid), min, ¤t, max, step, inc_pp);
|
14
|
+
if (current != prev) return DBL2NUM(current);
|
15
|
+
return Qnil;
|
16
|
+
}
|
17
|
+
|
18
|
+
void nkrb_ui_property_init(void) {
|
19
|
+
rb_define_method(mNuklearUIContainer, "ui_property", nkrb_ui_property, 7);
|
20
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_checkbox(VALUE self, VALUE rcontext, VALUE rtext, VALUE ris_checked) {
|
4
|
+
struct nk_context *context = nkrb_context_get(rcontext);
|
5
|
+
const char *text = StringValueCStr(rtext);
|
6
|
+
int is_checked = RTEST(ris_checked) ? 1 : 0;
|
7
|
+
if (nk_checkbox_label(context, text, &is_checked)) {
|
8
|
+
return is_checked ? Qtrue : Qfalse;
|
9
|
+
}
|
10
|
+
return Qnil;
|
11
|
+
}
|
12
|
+
|
13
|
+
VALUE nkrb_ui_option(VALUE self, VALUE rcontext, VALUE rtext, VALUE ris_checked) {
|
14
|
+
struct nk_context *context = nkrb_context_get(rcontext);
|
15
|
+
const char *text = StringValueCStr(rtext);
|
16
|
+
int is_checked = RTEST(ris_checked) ? 1 : 0;
|
17
|
+
if (nk_option_label(context, text, is_checked)) {
|
18
|
+
return Qtrue;
|
19
|
+
} else {
|
20
|
+
return Qfalse;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
VALUE nkrb_ui_selectable(VALUE self, VALUE rcontext, VALUE rimage, VALUE rtext, VALUE rselected, VALUE ralign) {
|
25
|
+
struct nk_context *context = nkrb_context_get(rcontext);
|
26
|
+
int align = FIX2INT(ralign);
|
27
|
+
int selected = RTEST(rselected) ? 1 : 0;
|
28
|
+
int result;
|
29
|
+
if (NIL_P(rtext)) return Qnil;
|
30
|
+
|
31
|
+
const char *text = StringValuePtr(rtext);
|
32
|
+
int len = (int) RSTRING_LEN(rtext);
|
33
|
+
|
34
|
+
if (NIL_P(rimage))
|
35
|
+
result = nk_selectable_text(context, text, len, align, &selected);
|
36
|
+
else {
|
37
|
+
struct nk_image img;
|
38
|
+
ASSIGN_STYLE_AS_IMAGE(img, nkrb_style_item(rimage))
|
39
|
+
result = nk_selectable_image_text(context, img, text, len, align, &selected);
|
40
|
+
}
|
41
|
+
|
42
|
+
if (result) {
|
43
|
+
return selected ? Qtrue : Qfalse;
|
44
|
+
}
|
45
|
+
|
46
|
+
return Qnil;
|
47
|
+
}
|
48
|
+
|
49
|
+
void nkrb_ui_checkbox_init(void) {
|
50
|
+
rb_define_method(mNuklearUIContainer, "ui_checkbox", nkrb_ui_checkbox, 3);
|
51
|
+
rb_define_method(mNuklearUIContainer, "ui_option", nkrb_ui_option, 3);
|
52
|
+
rb_define_method(mNuklearUIContainer, "ui_selectable", nkrb_ui_selectable, 5);
|
53
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_slider(VALUE self, VALUE context, VALUE rcurrent, VALUE rmin, VALUE rmax, VALUE rstep) {
|
4
|
+
struct nk_context *ctx = nkrb_context_get(context);
|
5
|
+
float current = (float) NUM2DBL(rcurrent);
|
6
|
+
float minimum = (float) NUM2DBL(rmin);
|
7
|
+
float maximum = (float) NUM2DBL(rmax);
|
8
|
+
float step = (float) NUM2DBL(rstep);
|
9
|
+
|
10
|
+
if (nk_slider_float(ctx, minimum, ¤t, maximum, step)) {
|
11
|
+
return DBL2NUM(current);
|
12
|
+
}
|
13
|
+
|
14
|
+
return Qnil;
|
15
|
+
}
|
16
|
+
|
17
|
+
void nkrb_ui_slider_init(void) {
|
18
|
+
rb_define_method(mNuklearUIContainer, "ui_slider", nkrb_ui_slider, 5);
|
19
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_tree(VALUE self, VALUE rcontext, VALUE rtree_type, VALUE rimage, VALUE rtitle, VALUE rcurrent_state) {
|
4
|
+
struct nk_context *context = nkrb_context_get(rcontext);
|
5
|
+
enum nk_tree_type tree_type = FIX2INT(rtree_type);
|
6
|
+
enum nk_collapse_states current_state = FIX2INT(rcurrent_state);
|
7
|
+
const char *title = StringValueCStr(rtitle);
|
8
|
+
int result;
|
9
|
+
if (!NIL_P(rimage)) {
|
10
|
+
struct nk_image image;
|
11
|
+
ASSIGN_STYLE_AS_IMAGE(image, nkrb_style_item(rimage));
|
12
|
+
result = nk_tree_state_image_push(context, tree_type, image, title, ¤t_state);
|
13
|
+
} else {
|
14
|
+
result = nk_tree_state_push(context, tree_type, title, ¤t_state);
|
15
|
+
}
|
16
|
+
|
17
|
+
if (rb_block_given_p()) {
|
18
|
+
rb_yield(INT2FIX(current_state));
|
19
|
+
}
|
20
|
+
|
21
|
+
if (result)
|
22
|
+
nk_tree_state_pop(context);
|
23
|
+
|
24
|
+
return Qnil;
|
25
|
+
}
|
26
|
+
|
27
|
+
void nkrb_ui_tree_init(void) {
|
28
|
+
rb_define_method(mNuklearUIContainer, "ui_tree", nkrb_ui_tree, 5);
|
29
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#include "nkrb.h"
|
2
|
+
|
3
|
+
VALUE nkrb_ui_window(VALUE self, VALUE context, VALUE rid, VALUE rtitle, VALUE rflags, VALUE left, VALUE top, VALUE width, VALUE height) {
|
4
|
+
struct nk_context *ctx = nkrb_context_get(context);
|
5
|
+
const char *id = StringValueCStr(rid);
|
6
|
+
const char *title = StringValueCStr(rtitle);
|
7
|
+
int flags = FIX2INT(rflags);
|
8
|
+
float x = (float) NUM2DBL(left);
|
9
|
+
float y = (float) NUM2DBL(top);
|
10
|
+
float w = (float) NUM2DBL(width);
|
11
|
+
float h = (float) NUM2DBL(height);
|
12
|
+
if (nk_begin_titled(ctx, id, title, nk_rect(x, y, w, h), flags)) {
|
13
|
+
VALUE result = rb_ary_new();
|
14
|
+
struct nk_rect bounds = nk_window_get_bounds(ctx);
|
15
|
+
struct nk_rect content_region = nk_window_get_content_region(ctx);
|
16
|
+
rb_ary_push(result, DBL2NUM(bounds.x));
|
17
|
+
rb_ary_push(result, DBL2NUM(bounds.y));
|
18
|
+
rb_ary_push(result, DBL2NUM(bounds.w));
|
19
|
+
rb_ary_push(result, DBL2NUM(bounds.h));
|
20
|
+
rb_ary_push(result, DBL2NUM(content_region.x));
|
21
|
+
rb_ary_push(result, DBL2NUM(content_region.y));
|
22
|
+
rb_ary_push(result, DBL2NUM(content_region.w));
|
23
|
+
rb_ary_push(result, DBL2NUM(content_region.h));
|
24
|
+
|
25
|
+
if (rb_block_given_p()) {
|
26
|
+
rb_yield(result);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
nk_end(ctx);
|
30
|
+
return Qnil;
|
31
|
+
}
|
32
|
+
|
33
|
+
VALUE nkrb_ui_window_close(VALUE self, VALUE context, VALUE rid) {
|
34
|
+
struct nk_context *ctx = nkrb_context_get(context);
|
35
|
+
const char *id = StringValueCStr(rid);
|
36
|
+
nk_window_close(ctx, id);
|
37
|
+
return Qnil;
|
38
|
+
}
|
39
|
+
|
40
|
+
void nkrb_ui_window_init(void) {
|
41
|
+
rb_define_method(mNuklearUIContainer, "ui_window", nkrb_ui_window, 8);
|
42
|
+
rb_define_method(mNuklearUIContainer, "ui_window_close", nkrb_ui_window_close, 2);
|
43
|
+
}
|