nuklear 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00d829f1e7f4d4d305a18e1d831df3cd95874224581986977a89fd2eb114da0f
4
- data.tar.gz: 45da4ef0e277ca42d642919a06c8086952c695a139b45265df6d5b7ceb4d5aaa
3
+ metadata.gz: 71711825cf0d022f9c47979905f5bf685067e9f2c1fdd8f9755a21142de60c6b
4
+ data.tar.gz: 23eae0b964a56384d2224018b3a5c54414286ee4ddcdab5a64e84db408e0d35e
5
5
  SHA512:
6
- metadata.gz: baa5798e57b4f1765b4e819ee7dac4db9aa40e172f44fd48c74ff6b6942bc8c0d5afdc55cc137aeb400b4c48f51cd5286000b4b849505e11b94f2de2e8e9ec43
7
- data.tar.gz: f37d1e63dcb902f2752c21e37d3ceaebccb0a2b5b9d50d615925049010dc2eedf3c726da9edc0687a63ba9ec651ffcd03cbc052cd0ea16c1b38e28275aa9e777
6
+ metadata.gz: 609432ea3c0dad02a1814ae94c6a42f7b96da73c1b2b8f1934481e22767473bb97723389c7f8dd698c07e2c343715d47be137918b93b4fa3b423b29ff7dd6102
7
+ data.tar.gz: e740ab30d11e8a9fb607342e5c150758510c06ebae411acf2609c7cd82bf4a4c11098c0b2d34d49864212cd637230b644bd9bbeb937f31496f0a105286d87c72
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  *.o
12
12
  *.a
13
13
  mkmf.log
14
+ .DS_Store
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nuklear (0.1.0)
4
+ nuklear (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -18,6 +18,13 @@ This project implements a set of Ruby classes which wrap the Nuklear API. It
18
18
  also provides two sample renderers (OpenGL 2 and OpenGL 4).
19
19
 
20
20
 
21
+ ## Screenshots
22
+
23
+ ![Hello Nuklear](https://github.com/sinisterchipmunk/nuklear-ruby/blob/master/examples/hello_nuklear.png)
24
+
25
+ ![Calculator](https://github.com/sinisterchipmunk/nuklear-ruby/blob/master/examples/calculator.png)
26
+
27
+
21
28
  ## Installation
22
29
 
23
30
  Add this line to your application's Gemfile:
@@ -75,7 +82,7 @@ ctx = Nuklear::Context.new(font)
75
82
  # to actually implement our real renderer on top of. Here, we'll use the
76
83
  # bundled OpenGL 2 renderer.
77
84
  require 'nuklear/nuklear_renderer_opengl2'
78
- ctx.renderer = Nuklear::Renderer::OpenGL2.new(ctx)
85
+ ctx.renderer = Nuklear::Renderer::OpenGL2.new
79
86
  ```
80
87
 
81
88
  ### With DSL
@@ -188,7 +195,7 @@ push git commits and tags, and push the `.gem` file to
188
195
  ## Contributing
189
196
 
190
197
  Bug reports and pull requests are welcome on GitHub at
191
- https://github.com/[USERNAME]/nuklear.
198
+ https://github.com/sinisterchipmunk/nuklear-ruby.
192
199
 
193
200
  ## License
194
201
 
Binary file
Binary file
@@ -56,7 +56,7 @@ ctx = Nuklear::Context.new(font)
56
56
  # renderer the size of the window and the size of the drawing surface, which
57
57
  # aren't always the same thing.
58
58
  require 'nuklear/nuklear_renderer_opengl2'
59
- ctx.renderer = Nuklear::Renderer::OpenGL2.new(ctx)
59
+ ctx.renderer = Nuklear::Renderer::OpenGL2.new
60
60
  ctx.renderer.window_size = window.size
61
61
  ctx.renderer.drawable_size = window.gl_drawable_size
62
62
 
@@ -35,7 +35,7 @@ module Examples
35
35
 
36
36
  def nuklear_context=(ctx)
37
37
  @nuklear_context = ctx
38
- @nuklear_context.renderer = Nuklear::Renderer::OpenGL2.new(@nuklear_context)
38
+ @nuklear_context.renderer = Nuklear::Renderer::OpenGL2.new
39
39
  @nuklear_context.renderer.window_size = @handle.size
40
40
  @nuklear_context.renderer.drawable_size = renderable_size
41
41
  end
@@ -220,6 +220,11 @@ VALUE nkrb_context_ui(VALUE self) {
220
220
  return ui;
221
221
  }
222
222
 
223
+ static VALUE nkrb_context_is_any_item_active(VALUE self) {
224
+ struct nk_context *ctx = nkrb_context_get(self);
225
+ return nk_item_is_any_active(ctx) ? Qtrue : Qfalse;
226
+ }
227
+
223
228
  void nkrb_context_init(void) {
224
229
  cNuklearContext = rb_define_class_under(mNuklear, "Context", rb_cObject);
225
230
  rb_define_alloc_func(cNuklearContext, nkrb_context_alloc);
@@ -228,6 +233,7 @@ void nkrb_context_init(void) {
228
233
  rb_define_method(cNuklearContext, "initialize", nkrb_context_initialize, 1);
229
234
  rb_define_method(cNuklearContext, "tick", nkrb_context_tick, 0);
230
235
  rb_define_method(cNuklearContext, "ui", nkrb_context_ui, 0);
236
+ rb_define_method(cNuklearContext, "any_item_active?", nkrb_context_is_any_item_active, 0);
231
237
 
232
238
  cNuklearContextEventSink = rb_define_class_under(cNuklearContext, "EventSink", rb_cObject);
233
239
  rb_define_method(cNuklearContextEventSink, "initialize", rb_nkrb_event_sink_initialize, 1);
@@ -33,12 +33,12 @@ static enum nk_draw_vertex_layout_format rb2nk_format(VALUE v) {
33
33
  else rb_raise(rb_eArgError, "Invalid vertex layout format name");
34
34
  }
35
35
 
36
- VALUE nkrb_renderer_convert(VALUE self) {
36
+ VALUE nkrb_renderer_convert(VALUE self, VALUE rcontext) {
37
37
  struct nk_context *context = NULL;
38
38
  struct nk_buffer *commands = NULL;
39
39
  struct nk_buffer *vertices = NULL;
40
40
  struct nk_buffer *indices = NULL;
41
- Data_Get_Struct(rb_funcall(self, rb_intern("context"), 0), struct nk_context, context);
41
+ Data_Get_Struct(rcontext, struct nk_context, context);
42
42
  Data_Get_Struct(rb_funcall(self, rb_intern("commands"), 0), struct nk_buffer, commands);
43
43
  Data_Get_Struct(rb_funcall(self, rb_intern("vertices"), 0), struct nk_buffer, vertices);
44
44
  Data_Get_Struct(rb_funcall(self, rb_intern("vertex_indices"), 0), struct nk_buffer, indices);
@@ -77,10 +77,10 @@ VALUE nkrb_renderer_convert(VALUE self) {
77
77
  return self;
78
78
  }
79
79
 
80
- VALUE nkrb_renderer_draw_foreach(VALUE self) {
80
+ VALUE nkrb_renderer_draw_foreach(VALUE self, VALUE rcontext) {
81
81
  struct nk_context *context = NULL;
82
82
  struct nk_buffer *commands = NULL;
83
- Data_Get_Struct(rb_funcall(self, rb_intern("context"), 0), struct nk_context, context);
83
+ Data_Get_Struct(rcontext, struct nk_context, context);
84
84
  Data_Get_Struct(rb_funcall(self, rb_intern("commands"), 0), struct nk_buffer, commands);
85
85
 
86
86
  /* convert from command queue into draw list and draw to screen */
@@ -109,6 +109,6 @@ VALUE nkrb_renderer_draw_foreach(VALUE self) {
109
109
 
110
110
  void nkrb_renderer_init(void) {
111
111
  VALUE cRenderer = rb_define_class_under(mNuklear, "Renderer", rb_cObject);
112
- rb_define_method(cRenderer, "nk_convert", nkrb_renderer_convert, 0);
113
- rb_define_method(cRenderer, "nk_draw_foreach", nkrb_renderer_draw_foreach, 0);
112
+ rb_define_method(cRenderer, "nk_convert", nkrb_renderer_convert, 1);
113
+ rb_define_method(cRenderer, "nk_draw_foreach", nkrb_renderer_draw_foreach, 1);
114
114
  }
@@ -52,17 +52,17 @@ static enum nk_draw_vertex_layout_format rb2nk_format(VALUE v) {
52
52
  else rb_raise(rb_eArgError, "Invalid vertex layout format name");
53
53
  }
54
54
 
55
- VALUE renderer_initialize(VALUE self, VALUE context) {
55
+ VALUE renderer_initialize(VALUE self) {
56
56
  if (!gladLoadGL())
57
57
  rb_raise(rb_eStandardError, "Failed to init GLAD");
58
58
  // printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
59
59
 
60
- rb_call_super(1, &context);
60
+ rb_call_super(0, NULL);
61
61
 
62
62
  return self;
63
63
  }
64
64
 
65
- VALUE renderer_render_gl(VALUE self) {
65
+ VALUE renderer_render_gl(VALUE self, VALUE rcontext) {
66
66
  VALUE window_size = rb_funcall(self, rb_intern("window_size"), 0);
67
67
  VALUE drawable_size = rb_funcall(self, rb_intern("drawable_size"), 0);
68
68
  VALUE window_width = rb_ary_entry(window_size, 0);
@@ -96,7 +96,7 @@ VALUE renderer_render_gl(VALUE self) {
96
96
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
97
97
  glEnableClientState(GL_COLOR_ARRAY);
98
98
 
99
- rb_call_super(0, NULL);
99
+ rb_call_super(1, &rcontext);
100
100
 
101
101
  /* default OpenGL state */
102
102
  glDisableClientState(GL_VERTEX_ARRAY);
@@ -119,8 +119,8 @@ VALUE renderer_render_gl(VALUE self) {
119
119
  return self;
120
120
  }
121
121
 
122
- VALUE renderer_nk_convert_gl(VALUE self) {
123
- VALUE result = rb_call_super(0, NULL);
122
+ VALUE renderer_nk_convert_gl(VALUE self, VALUE rcontext) {
123
+ VALUE result = rb_call_super(1, &rcontext);
124
124
  VALUE rconfig = rb_funcall(self, rb_intern("convert_config"), 0);
125
125
  GLsizei vs = (GLsizei) FIX2INT(rb_hash_aref(rconfig, ID2SYM(rb_intern("vertex_size"))));
126
126
 
@@ -190,8 +190,8 @@ void Init_nuklear_renderer_opengl2(void) {
190
190
  cNuklearRendererOpenGL2 = rb_define_class_under(cNuklearRenderer, "OpenGL2", cNuklearRenderer);
191
191
  cNuklearBuffer = rb_const_get(mNuklear, rb_intern("Buffer"));
192
192
 
193
- rb_define_method(cNuklearRendererOpenGL2, "initialize", renderer_initialize, 1);
194
- rb_define_method(cNuklearRendererOpenGL2, "nk_convert", renderer_nk_convert_gl, 0);
193
+ rb_define_method(cNuklearRendererOpenGL2, "initialize", renderer_initialize, 0);
194
+ rb_define_method(cNuklearRendererOpenGL2, "nk_convert", renderer_nk_convert_gl, 1);
195
195
  rb_define_method(cNuklearRendererOpenGL2, "draw", renderer_draw_gl, 1);
196
- rb_define_method(cNuklearRendererOpenGL2, "render", renderer_render_gl, 0);
196
+ rb_define_method(cNuklearRendererOpenGL2, "render", renderer_render_gl, 1);
197
197
  }
@@ -54,12 +54,12 @@ void nuklear_command_buffer_free(struct nk_buffer *buf) {
54
54
  nk_buffer_free(buf);
55
55
  }
56
56
 
57
- VALUE renderer_initialize(VALUE self, VALUE context) {
57
+ VALUE renderer_initialize(VALUE self) {
58
58
  if (!gladLoadGL())
59
59
  rb_raise(rb_eStandardError, "Failed to init GLAD");
60
60
  // printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
61
61
 
62
- rb_call_super(1, &context);
62
+ rb_call_super(0, NULL);
63
63
 
64
64
  int status;
65
65
  int prog = glCreateProgram();
@@ -124,8 +124,7 @@ VALUE renderer_initialize(VALUE self, VALUE context) {
124
124
  return self;
125
125
  }
126
126
 
127
- VALUE renderer_render_gl(VALUE self) {
128
- struct nk_context *ctx;
127
+ VALUE renderer_render_gl(VALUE self, VALUE rcontext) {
129
128
  struct nk_buffer *cmds;
130
129
  VALUE window_size = rb_funcall(self, rb_intern("window_size"), 0);
131
130
  VALUE drawable_size = rb_funcall(self, rb_intern("drawable_size"), 0);
@@ -144,7 +143,6 @@ VALUE renderer_render_gl(VALUE self) {
144
143
  struct nk_vec2 scale;
145
144
  VALUE context = rb_ivar_get(self, rb_intern("@context"));
146
145
  Data_Get_Struct(rb_ivar_get(context, rb_intern("@null")), struct nk_draw_null_texture, null_tex);
147
- Data_Get_Struct(context, struct nk_context, ctx);
148
146
  Data_Get_Struct(rb_ivar_get(self, rb_intern("@commands")), struct nk_buffer, cmds);
149
147
 
150
148
  GLfloat ortho[4][4] = {
@@ -174,7 +172,7 @@ VALUE renderer_render_gl(VALUE self) {
174
172
  glUniform1i(uniform_tex, 0);
175
173
  glUniformMatrix4fv(uniform_proj, 1, GL_FALSE, &ortho[0][0]);
176
174
 
177
- rb_call_super(0, NULL);
175
+ rb_call_super(1, &rcontext);
178
176
 
179
177
  glUseProgram(0);
180
178
  glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -187,8 +185,8 @@ VALUE renderer_render_gl(VALUE self) {
187
185
  return self;
188
186
  }
189
187
 
190
- VALUE renderer_nk_convert_gl(VALUE self) {
191
- VALUE result = rb_call_super(0, NULL);
188
+ VALUE renderer_nk_convert_gl(VALUE self, VALUE rcontext) {
189
+ VALUE result = rb_call_super(1, &rcontext);
192
190
 
193
191
  struct nk_buffer *vertices = NULL;
194
192
  struct nk_buffer *indices = NULL;
@@ -248,8 +246,8 @@ void Init_nuklear_renderer_opengl4(void) {
248
246
  cNuklearRendererOpenGL4 = rb_define_class_under(cNuklearRenderer, "OpenGL4", cNuklearRenderer);
249
247
  cNuklearBuffer = rb_const_get(mNuklear, rb_intern("Buffer"));
250
248
 
251
- rb_define_method(cNuklearRendererOpenGL4, "initialize", renderer_initialize, 1);
252
- rb_define_method(cNuklearRendererOpenGL4, "nk_convert", renderer_nk_convert_gl, 0);
249
+ rb_define_method(cNuklearRendererOpenGL4, "initialize", renderer_initialize, 0);
250
+ rb_define_method(cNuklearRendererOpenGL4, "nk_convert", renderer_nk_convert_gl, 1);
253
251
  rb_define_method(cNuklearRendererOpenGL4, "draw", renderer_draw_gl, 1);
254
- rb_define_method(cNuklearRendererOpenGL4, "render", renderer_render_gl, 0);
252
+ rb_define_method(cNuklearRendererOpenGL4, "render", renderer_render_gl, 1);
255
253
  }
@@ -31,7 +31,7 @@ module Nuklear
31
31
  # Nuklear frame update process. It should not be called directly.
32
32
  protected def paint
33
33
  run_commands(self)
34
- renderer.render
34
+ renderer.render(self)
35
35
  end
36
36
 
37
37
  # Events (window events, input events, etc) will accumulate over time.
@@ -46,11 +46,10 @@ module Nuklear
46
46
 
47
47
  # For all renderer implementations, override #initialize to set up your
48
48
  # initial state (e.g. compiling shaders) and call `super`.
49
- def initialize(context)
49
+ def initialize
50
50
  @commands = Nuklear::Buffer.new
51
51
  @vertices = Nuklear::Buffer.new
52
52
  @vertex_indices = Nuklear::Buffer.new
53
- @context = context
54
53
  @window_size = [640, 480]
55
54
  @drawable_size = nil
56
55
  @null_texture_handle = 0
@@ -84,9 +83,9 @@ module Nuklear
84
83
  # Called at the start of a render pass. Renderers may wish to override
85
84
  # this method to apply once-per-frame state updates. They should call
86
85
  # `super` when they are ready to proceed.
87
- def render
88
- nk_convert
89
- nk_draw_foreach { |command| draw(command) }
86
+ def render(context)
87
+ nk_convert(context)
88
+ nk_draw_foreach(context) { |command| draw(command) }
90
89
  end
91
90
 
92
91
  # Called for each Nuklear draw command, numerous times per render pass.
@@ -1,3 +1,3 @@
1
1
  module Nuklear
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nuklear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin MacKenzie IV
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-10 00:00:00.000000000 Z
11
+ date: 2022-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,7 +114,9 @@ files:
114
114
  - bin/console
115
115
  - bin/setup
116
116
  - examples/arial.ttf
117
+ - examples/calculator.png
117
118
  - examples/calculator.rb
119
+ - examples/hello_nuklear.png
118
120
  - examples/hello_nuklear.rb
119
121
  - examples/lib/opengl_font.rb
120
122
  - examples/lib/opengl_init.rb