nuklear 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.
@@ -2,14 +2,18 @@ module Nuklear
2
2
  module UI
3
3
  class EditString < Nuklear::UI::Base
4
4
  attr_accessor :flags, :max_length, :filter, :text
5
+ attr_reader :text_was
5
6
 
6
- def initialize(text: "", flags: 0, max_length: 255, filter: nil, enabled: true)
7
+ def initialize(text: "", flags: :simple, max_length: 255, filter: nil,
8
+ enabled: true, &on_change)
7
9
  super enabled: enabled
8
10
  @text = text
9
11
  @flags = Nuklear.parse_flags :edit, flags
10
12
  @max_length = max_length
11
13
  @filter = filter
12
14
  @demand_focus = false
15
+ @text_was = text.dup
16
+ on(:change, &on_change) if block_given?
13
17
  end
14
18
 
15
19
  def demand_focus?
@@ -42,6 +46,11 @@ module Nuklear
42
46
  trigger(:committed) if (result & Nuklear::NK_EDIT_COMMITED) > 0
43
47
  trigger(:active) if (result & Nuklear::NK_EDIT_ACTIVE) > 0
44
48
  trigger(:inactive) if (result & Nuklear::NK_EDIT_INACTIVE) > 0
49
+ if @text != @text_was
50
+ trigger :change
51
+ @text_was.clear
52
+ @text_was.concat @text
53
+ end
45
54
  end
46
55
  end
47
56
  end
@@ -1,3 +1,3 @@
1
1
  module Nuklear
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.3"
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.3
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-12 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