hokusai-zero 0.2.6.pre.pinephone6 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +2 -0
  4. data/README.md +1 -1
  5. data/ast/src/core/input.h +1 -0
  6. data/ast/src/core/util.c +23 -23
  7. data/ast/src/core/util.h +7 -7
  8. data/ext/extconf.rb +3 -3
  9. data/hokusai.gemspec +2 -1
  10. data/ui/examples/counter.rb +1 -2
  11. data/ui/examples/forum/file.rb +1 -1
  12. data/ui/examples/forum/post.rb +1 -0
  13. data/ui/examples/forum.rb +7 -7
  14. data/ui/examples/spreadsheet.rb +0 -1
  15. data/ui/examples/tic_tac_toe.rb +6 -6
  16. data/ui/lib/lib_hokusai.rb +24 -25
  17. data/ui/spec/spec_helper.rb +1 -1
  18. data/ui/src/hokusai/assets/chevron-down.svg +1 -0
  19. data/ui/src/hokusai/automation/driver_commands/base.rb +8 -2
  20. data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +6 -3
  21. data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +5 -12
  22. data/ui/src/hokusai/automation/server.rb +3 -2
  23. data/ui/src/hokusai/backends/raylib/config.rb +1 -2
  24. data/ui/src/hokusai/backends/raylib/font.rb +3 -24
  25. data/ui/src/hokusai/backends/raylib.rb +36 -167
  26. data/ui/src/hokusai/backends/sdl2/config.rb +6 -9
  27. data/ui/src/hokusai/backends/sdl2/font.rb +1 -3
  28. data/ui/src/hokusai/backends/sdl2.rb +93 -188
  29. data/ui/src/hokusai/blocks/input.rb +2 -2
  30. data/ui/src/hokusai/commands/rect.rb +3 -12
  31. data/ui/src/hokusai/commands.rb +0 -22
  32. data/ui/src/hokusai/event.rb +1 -2
  33. data/ui/src/hokusai/events/keyboard.rb +18 -11
  34. data/ui/src/hokusai/events/mouse.rb +8 -10
  35. data/ui/src/hokusai/mounting/loop_entry.rb +1 -1
  36. data/ui/src/hokusai/painter.rb +8 -31
  37. data/ui/src/hokusai/types.rb +244 -20
  38. data/ui/src/hokusai.rb +35 -61
  39. data/xmake.lua +1 -1
  40. metadata +22 -32
  41. data/ui/examples/drag.rb +0 -154
  42. data/ui/examples/embedded.rb +0 -58
  43. data/ui/examples/game.rb +0 -143
  44. data/ui/examples/keyboard.rb +0 -47
  45. data/ui/examples/overlay.rb +0 -233
  46. data/ui/examples/provider.rb +0 -56
  47. data/ui/examples/shader/test.rb +0 -155
  48. data/ui/examples/shader.rb +0 -100
  49. data/ui/examples/wiki.rb +0 -82
  50. data/ui/spec/hokusai/e2e/keyboard_spec.rb +0 -52
  51. data/ui/src/hokusai/assets/arrow-down-line.png +0 -0
  52. data/ui/src/hokusai/assets/arrow-down-wide-line.png +0 -0
  53. data/ui/src/hokusai/assets/icons/outline/arrow-big-up.svg +0 -19
  54. data/ui/src/hokusai/assets/icons/outline/backspace.svg +0 -20
  55. data/ui/src/hokusai/blocks/color_picker.rb +0 -1080
  56. data/ui/src/hokusai/blocks/keyboard.rb +0 -249
  57. data/ui/src/hokusai/blocks/shader_begin.rb +0 -22
  58. data/ui/src/hokusai/blocks/shader_end.rb +0 -12
  59. data/ui/src/hokusai/blocks/slider.rb +0 -139
  60. data/ui/src/hokusai/blocks/texture.rb +0 -23
  61. data/ui/src/hokusai/commands/shader.rb +0 -33
  62. data/ui/src/hokusai/commands/texture.rb +0 -26
  63. data/ui/src/hokusai/events/touch.rb +0 -62
  64. data/ui/src/hokusai/types/display.rb +0 -151
  65. data/ui/src/hokusai/types/keyboard.rb +0 -168
  66. data/ui/src/hokusai/types/mouse.rb +0 -36
  67. data/ui/src/hokusai/types/primitives.rb +0 -56
  68. data/ui/src/hokusai/types/touch.rb +0 -181
  69. data/ui/src/hokusai/util/wrap_stream.rb +0 -193
@@ -16,7 +16,8 @@ module Hokusai::Backends
16
16
  yield(config)
17
17
  end
18
18
 
19
- backend.run(app)
19
+ block = app.mount
20
+ backend.run(block)
20
21
  end
21
22
 
22
23
  def self.cursors
@@ -29,17 +30,6 @@ module Hokusai::Backends
29
30
  }
30
31
  end
31
32
 
32
- def hml_vec2(x, y)
33
- if @hml_vec2.nil?
34
- @hml_vec2 = LibHokusai::HmlVec2.create(x, y)
35
- else
36
- @hml_vec2[:x] = x
37
- @hml_vec2[:y] = y
38
- end
39
-
40
- @hml_vec2
41
- end
42
-
43
33
  def self.stopped
44
34
  @stopped ||= false
45
35
  end
@@ -66,19 +56,7 @@ module Hokusai::Backends
66
56
  yield @config
67
57
  end
68
58
 
69
- def get_size(window)
70
- w = FFI::MemoryPointer.new :int
71
- h = FFI::MemoryPointer.new :int
72
-
73
- SDL.GL_GetDrawableSize(window, w, h)
74
-
75
- res = { width: w.read_int, height: h.read_int }
76
- w.free
77
- h.free
78
- res
79
- end
80
-
81
- def run(app)
59
+ def run(block)
82
60
  resize = true
83
61
  self.render_width = config.width
84
62
  self.render_height = config.height
@@ -102,7 +80,6 @@ module Hokusai::Backends
102
80
  image_libpath: "#{SDL_PATH}/libSDL2_image.so"
103
81
  )
104
82
  end
105
-
106
83
  SDL.Init(config.init_flags)
107
84
  SDL.TTF_Init
108
85
 
@@ -110,77 +87,46 @@ module Hokusai::Backends
110
87
  SDL.SetWindowPosition(window, SDL::WINDOWPOS_CENTERED_MASK, SDL::WINDOWPOS_CENTERED_MASK)
111
88
  renderer = SDL.CreateRenderer(window, -1, SDL::RENDERER_TARGETTEXTURE | SDL::RENDERER_ACCELERATED)
112
89
 
113
- size = get_size(window)
114
- SDL.RenderSetScale(renderer, size[:width] / render_width, size[:height] / render_height);
115
-
116
90
  Hokusai.fonts.register "default", SDLBackend::Font.from("#{__dir__}/sdl2/Monaco.ttf", 121)
117
91
  Hokusai.fonts.activate "default"
118
92
  config.after_load_cb&.call
119
93
 
120
94
  register_command_handlers(renderer, window)
121
- block = app.mount
122
95
  # MemoryProfiler.start if ENV["PROFILE"]
123
96
 
124
- input = Hokusai::Input.new
125
-
126
- if config.touch
127
- input.support_touch!
128
- end
129
-
97
+ ptr = FFI::MemoryPointer.new :pointer
98
+ LibHokusai.hoku_input_init(ptr)
99
+ raw = LibHokusai::HmlInput.new(ptr.get_pointer(0))
100
+ input = Hokusai::Input.new(raw)
130
101
  canvas = Hokusai::Canvas.new(render_width.to_f, render_height.to_f)
131
102
  event = SDL::Event.new
132
103
 
133
104
  loop do
134
- if SDL.PollEvent(event)
135
- self.class.stopped = true if event[:common][:type] == SDL::QUIT || self.class.stopped
136
-
137
- process_input(input, event)
138
- if config.touch
139
- if input.touch.touching?
140
- token = input.touch.token
141
-
142
- input.mouse.pos.x = token[:x]
143
- input.mouse.pos.y = token[:y]
144
- end
145
-
146
- # translate taps to clicks
147
- if input.touch.tapped?
148
- input.mouse.left.clicked = true
149
- input.mouse.left.down = true
150
- input.mouse.left.released = false
151
- input.mouse.left.up = false
152
- else
153
- input.mouse.left.clicked = true
154
- input.mouse.left.down = true
155
- input.mouse.left.released = false
156
- input.mouse.left.up = false
157
- end
158
- end
105
+ SDL.WaitEvent(event)
106
+ break if event[:common][:type] == SDL::QUIT || self.class.stopped
107
+ if process_input(input, event)
108
+ # since we are using wait event, we need to process the render twice
109
+ # once to capture all events, and once after updating block state.
110
+ SDL.SetRenderDrawBlendMode(renderer, SDL::BLENDMODE_NONE)
111
+ SDL.SetRenderDrawColor(renderer, config.background[:r], config.background[:g], config.background[:b], config.background[:a])
112
+ SDL.RenderClear(renderer)
113
+ canvas.reset(nil, nil, render_width.to_f, render_height.to_f)
114
+ painter = Hokusai::Painter.new(block, input)
115
+ painter.render(canvas, resize)
116
+ block.update
117
+ SDL.RenderPresent(renderer)
118
+
119
+ SDL.SetRenderDrawBlendMode(renderer, SDL::BLENDMODE_NONE)
120
+ SDL.SetRenderDrawColor(renderer, config.background[:r], config.background[:g], config.background[:b], config.background[:a])
121
+ SDL.RenderClear(renderer)
122
+ canvas.reset(nil, nil, render_width.to_f, render_height.to_f)
123
+ painter = Hokusai::Painter.new(block, input)
124
+ painter.render(canvas, resize, capture: false)
125
+ SDL.RenderPresent(renderer)
159
126
  end
160
-
161
- break if self.class.stopped
162
- # since we are using wait event, we need to process the render twice
163
- # once to capture all events, and once after updating block state.
164
- SDL.SetRenderDrawBlendMode(renderer, SDL::BLENDMODE_BLEND)
165
- SDL.SetRenderDrawColor(renderer, config.background[:r], config.background[:g], config.background[:b], config.background[:a])
166
- SDL.RenderClear(renderer)
167
- canvas.reset(0.0, 0.0, render_width.to_f, render_height.to_f)
168
- painter = Hokusai::Painter.new(block, input)
169
- painter.render(canvas, resize)
170
-
171
- SDL.RenderPresent(renderer)
172
- block.update
173
-
174
- # SDL.SetRenderDrawBlendMode(renderer, SDL::BLENDMODE_NONE)
175
- # SDL.SetRenderDrawColor(renderer, config.background[:r], config.background[:g], config.background[:b], config.background[:a])
176
- # SDL.RenderClear(renderer)
177
- # canvas.reset(nil, nil, render_width.to_f, render_height.to_f)
178
- # painter = Hokusai::Painter.new(block, input)
179
- # painter.render(canvas, resize, capture: false)
180
- # SDL.RenderPresent(renderer)
181
- SDL.Delay(10)
182
127
  end
183
128
 
129
+ LibHokusai.hoku_input_free(input.raw)
184
130
  if ENV["PROFILE"]
185
131
  # report = MemoryProfiler.stop
186
132
  # report.pretty_print
@@ -211,76 +157,52 @@ module Hokusai::Backends
211
157
  end
212
158
 
213
159
  def reset_keys(input)
214
- if !input.keyboard_override
215
- input.keyboard.reset
216
-
217
- Modifiers.each do |(sdlk, hkey)|
218
- input.keyboard.set(hkey, false)
219
- end
160
+ LibHokusai.hoku_input_keyboard_start(input.raw)
161
+ Modifiers.each do |(sdlk, hkey)|
162
+ LibHokusai.hoku_input_keyboard_set_key(input.raw, hkey, false)
163
+ end
220
164
 
221
- Keys.values.each do |hkey|
222
- input.keyboard.set(hkey, false)
223
- end
165
+ Keys.values.each do |hkey|
166
+ LibHokusai.hoku_input_keyboard_set_key(input.raw, hkey, false)
224
167
  end
168
+
169
+ LibHokusai.hoku_input_keyboard_stop(input.raw)
225
170
  end
226
171
 
227
172
  def process_input(input, event)
228
173
  reset_keys(input)
229
174
 
230
- t = event[:common][:type]
231
- if config.touch && t != SDL::FINGERDOWN && t != SDL::WINDOWEVENT && t != SDL::FINGERUP && t != SDL::FINGERMOTION && t != SDL::MOUSEMOTION && t != SDL::POLLSENTINEL
232
- input.touch.clear
233
- end
234
-
235
175
  case event[:common][:type]
236
- when SDL::FINGERDOWN
237
- x = event[:tfinger][:x] * render_width
238
- y = event[:tfinger][:y] * render_height
239
-
240
- input.touch.record(0, x, y)
241
- return true
242
- when SDL::FINGERUP
243
- input.touch.clear
244
- return true
245
- when SDL::FINGERMOTION
246
- x = event[:tfinger][:x] * render_width
247
- y = event[:tfinger][:y] * render_height
248
-
249
- input.touch.record(0, x, y)
250
- return true
251
176
  when SDL::KEYDOWN
252
- if !input.keyboard_override
253
- modifier = event[:key][:keysym][:mod]
254
- code = event[:key][:keysym][:sym]
255
- hkey = Keys[code]
256
-
257
- input.keyboard.reset
258
-
259
- Modifiers.each do |(sdlk, hkey)|
260
- if modifier & sdlk == sdlk
261
- input.keyboard.set(hkey, true)
262
- end
177
+ modifier = event[:key][:keysym][:mod]
178
+ code = event[:key][:keysym][:sym]
179
+ hkey = Keys[code]
180
+
181
+ LibHokusai.hoku_input_keyboard_start(input.raw)
182
+ Modifiers.each do |(sdlk, hkey)|
183
+ if modifier & sdlk == sdlk
184
+ LibHokusai.hoku_input_keyboard_set_key(input.raw, hkey, true)
263
185
  end
264
-
265
- input.keyboard.set(hkey, true) unless hkey.nil?
266
186
  end
267
187
 
188
+ LibHokusai.hoku_input_keyboard_set_key(input.raw, hkey, true) unless hkey.nil?
189
+ LibHokusai.hoku_input_keyboard_stop(input.raw)
190
+
268
191
  return true
269
192
  when SDL::KEYUP
270
- if !input.keyboard_override
271
- modifier = event[:key][:keysym][:mod]
272
- code = event[:key][:keysym][:sym]
273
- hkey = Keys[code]
274
- input.keyboard.reset
275
-
276
- Modifiers.each do |(sdlk, hkey)|
277
- if modifier & sdlk == sdlk
278
- input.keyboard.set(hkey, false)
279
- end
193
+ modifier = event[:key][:keysym][:mod]
194
+ code = event[:key][:keysym][:sym]
195
+ hkey = Keys[code]
196
+
197
+ LibHokusai.hoku_input_keyboard_start(input.raw)
198
+ Modifiers.each do |(sdlk, hkey)|
199
+ if modifier & sdlk == sdlk
200
+ LibHokusai.hoku_input_keyboard_set_key(input.raw, hkey, false)
280
201
  end
281
-
282
- input.keyboard.set(hkey, false) unless hkey.nil?
283
202
  end
203
+
204
+ LibHokusai.hoku_input_keyboard_set_key(input.raw, hkey, false) unless hkey.nil?
205
+ LibHokusai.hoku_input_keyboard_stop(input.raw)
284
206
  return true
285
207
  when SDL::WINDOWEVENT
286
208
  if event[:window][:event] == SDL::WINDOWEVENT_RESIZED
@@ -301,65 +223,54 @@ module Hokusai::Backends
301
223
 
302
224
  return true
303
225
  when SDL::MOUSEMOTION
304
- if input.mouse.delta.y > 0
305
- input.mouse.delta.y = 0.0
306
- input.mouse.scroll_delta = 0.0
307
- input.mouse.scroll = event[:motion][:y]
226
+ if input.raw[:mouse][:delta][:y] > 0
227
+ # LibHokusai.hoku_input_mouse_set_scroll(input.raw, 0.0)
228
+ input.raw[:mouse][:delta][:y] = 0.0
229
+ input.raw[:mouse][:scroll_delta] = 0.0
230
+ input.raw[:mouse][:scroll] = event[:motion][:y]
308
231
  end
309
232
 
310
- input.mouse.pos.x = event[:motion][:x]
311
- input.mouse.pos.y = event[:motion][:y]
233
+ # pp ["set mouse", Time.now.strftime("%H:%M:%S %L")]
234
+ hoku_mouse_pos = LibHokusai::HmlVec2.create(event[:motion][:x], event[:motion][:y])
235
+ LibHokusai.hoku_input_set_mouse_position(input.raw, hoku_mouse_pos)
312
236
 
313
237
  # clear any click events
314
238
  [[:left, 0], [:right, 2], [:middle, 1]].each do |(btn, i)|
315
- input.mouse.send(btn).clicked = false
239
+ button = input.raw[:mouse][btn]
240
+ button[:clicked] = false
241
+ LibHokusai.hoku_input_mouse_set_button(input.raw, button, i)
316
242
  end
317
243
 
318
244
  return true
319
245
  when SDL::MOUSEWHEEL
320
- input.mouse.scroll = event[:wheel][:preciseY]
321
- input.mouse.delta.y = event[:wheel][:preciseY]
246
+ LibHokusai.hoku_input_mouse_set_scroll(input.raw, event[:wheel][:preciseY])
247
+ input.raw[:mouse][:delta][:y] = event[:wheel][:preciseY]
322
248
 
323
249
  # clear any click events
324
250
  [[:left, 0], [:right, 2], [:middle, 1]].each do |(btn, i)|
325
- input.mouse.send(btn).clicked = false
251
+ button = input.raw[:mouse][btn]
252
+ button[:clicked] = false
253
+ LibHokusai.hoku_input_mouse_set_button(input.raw, button, i)
326
254
  end
327
-
328
255
  return true
329
256
  when SDL::MOUSEBUTTONDOWN
330
257
  clicked = event[:button][:clicks] > 0
331
- btn = {
332
- 0 => :left,
333
- 1 => :middle,
334
- 2 => :right
335
- }[event[:button][:which]]
336
-
337
- input.mouse.send(btn).clicked = clicked
338
- input.mouse.send(btn).down = true
339
- input.mouse.send(btn).up = false
340
- input.mouse.scroll = 0.0
341
- input.mouse.delta.y = 0.0
258
+ button = mouse_button(down: true, clicked: clicked)
259
+
260
+ # LibHokusai.hoku_input_mouse_set_scroll(input.raw, 0.0)
261
+ # input.raw[:mouse][:delta][:y] = 0.0
342
262
 
263
+ LibHokusai.hoku_input_mouse_set_button(input.raw, button, event[:button][:which])
343
264
  return true
344
265
  when SDL::MOUSEBUTTONUP
345
- btn = {
346
- 0 => :left,
347
- 1 => :middle,
348
- 2 => :right
349
- }[event[:button][:which]]
350
-
351
- input.mouse.send(btn).up = true
352
- input.mouse.send(btn).down = false
353
- input.mouse.scroll = 0.0
354
- input.mouse.delta.y = 0.0
355
- return true
356
- when SDL::TEXTINPUT
266
+ button = mouse_button(up: true)
267
+ #
268
+ # LibHokusai.hoku_input_mouse_set_scroll(input.raw, 0.0)
269
+ # input.raw[:mouse][:delta][:y] = 0.0
357
270
 
271
+ LibHokusai.hoku_input_mouse_set_button(input.raw, button, event[:button][:which])
358
272
  return true
359
- when SDL::TEXTEDITING
360
- # start = event[:edit][:start]
361
- # len = event[:edit][:length]
362
- # text = event[:edit][:text]
273
+ when SDL::TEXTINPUT
363
274
  return false
364
275
  else
365
276
  false
@@ -499,21 +410,16 @@ module Hokusai::Backends
499
410
  self.class.images[command.source]
500
411
  else
501
412
  file = File.read(command.source)
502
- SDL.SetHint(SDL::HINT_RENDER_SCALE_QUALITY, "0");
503
- texture = SDL.IMG_LoadTexture(renderer, command.source)
504
- if texture.null?
413
+
414
+ rw = SDL.RWFromConstMem(file, file.size)
415
+ surface_ptr = SDL.IMG_Load_RW(rw, 1)
416
+ if surface_ptr.null?
505
417
  raise Hokusai::Error.new("Can't load Image: #{SDL.GetError.read_string}")
506
418
  end
507
419
 
508
- # rw = SDL.RWFromConstMem(file, file.size)
509
- # surface_ptr = SDL.IMG_LoadSVG_RW(rw)
510
- # if surface_ptr.null?
511
- # raise Hokusai::Error.new("Can't load Image: #{SDL.GetError.read_string}")
512
- # end
513
-
514
- # texture = SDL.CreateTextureFromSurface(renderer, surface_ptr)
420
+ texture = SDL.CreateTextureFromSurface(renderer, surface_ptr)
515
421
  self.class.images[command.source] = texture
516
- # SDL.FreeSurface(surface_ptr)
422
+ SDL.FreeSurface(surface_ptr)
517
423
  texture
518
424
  end
519
425
  end
@@ -525,7 +431,6 @@ module Hokusai::Backends
525
431
 
526
432
  Hokusai::Commands::Rect.on_draw do |command|
527
433
  next unless inside_scissor(command.x, command.y, command.height)
528
- next if command.color.a == 0
529
434
  # draw background first
530
435
  x, y, w, h = [command.x, command.y, command.width, command.height]
531
436
 
@@ -601,6 +506,7 @@ module Hokusai::Backends
601
506
  rounding = command.rounding
602
507
 
603
508
  if command.rounding > 0
509
+ pp command.color
604
510
  SDL.roundedBoxRGBA(renderer, x, y, x + w, y + h, (command.rounding).ceil.to_i, command.color.r, command.color.g, command.color.b, command.color.a)
605
511
  else
606
512
  rect = SDL::Rect.new
@@ -609,7 +515,6 @@ module Hokusai::Backends
609
515
  rect[:w] = w
610
516
  rect[:h] = h
611
517
 
612
- SDL.SetRenderDrawBlendMode(renderer, SDL::BLENDMODE_BLEND)
613
518
  SDL.SetRenderDrawColor(renderer, command.color.r, command.color.g, command.color.b, command.color.a)
614
519
  SDL.RenderFillRect(renderer, rect)
615
520
  end
@@ -87,7 +87,7 @@ class Hokusai::Blocks::Input < Hokusai::Block
87
87
  end
88
88
 
89
89
  def dynamic_keypress_handle(event)
90
- return unless node.meta.focused || event.input.keyboard_override
90
+ return unless node.meta.focused
91
91
  case event
92
92
  when proc(&:ctrl), proc(&:super)
93
93
  if event.char == "z"
@@ -154,7 +154,7 @@ class Hokusai::Blocks::Input < Hokusai::Block
154
154
  self.buffer_offset = offset
155
155
  end
156
156
 
157
- self.buffer += event.char unless event.char.nil?
157
+ self.buffer += event.char
158
158
  end
159
159
  end
160
160
 
@@ -2,7 +2,7 @@ module Hokusai
2
2
  class Commands::Rect < Commands::Base
3
3
  attr_reader :x, :y, :width, :height,
4
4
  :rounding, :color, :outline,
5
- :outline_color, :padding, :gradient
5
+ :outline_color, :padding
6
6
 
7
7
  def initialize(x, y, width, height)
8
8
  @x = x.to_f
@@ -11,10 +11,9 @@ module Hokusai
11
11
  @height = height.to_f
12
12
  @outline = Outline.default
13
13
  @rounding = 0.0
14
- @color = Color.new(255, 255, 255, 0)
15
- @outline_color = Color.new(0, 0, 0, 0)
14
+ @color = Color.new(0, 0, 0, 0)
15
+ @outline_color = Color.new(0, 0, 0, 255)
16
16
  @padding = Padding.new(0.0, 0.0, 0.0, 0.0)
17
- @gradient = nil
18
17
  end
19
18
 
20
19
  def hash
@@ -45,14 +44,6 @@ module Hokusai
45
44
  height
46
45
  end
47
46
 
48
- def gradient=(colors)
49
- unless colors.is_a?(Array) && colors.size == 4 && colors.all? { |color| color.is_a?(Hokusai::Color) }
50
- raise Hokusai::Error.new("Gradient must be an array of 4 Hokuai::Color")
51
- end
52
-
53
- @gradient = colors
54
- end
55
-
56
47
  # Sets padding for the rectangle
57
48
  # `value` is an array with padding declarations
58
49
  # at [top, right, bottom, left]
@@ -4,8 +4,6 @@ require_relative "./commands/image"
4
4
  require_relative "./commands/rect"
5
5
  require_relative "./commands/scissor"
6
6
  require_relative "./commands/text"
7
- require_relative "./commands/shader"
8
- require_relative "./commands/texture"
9
7
 
10
8
  module Hokusai
11
9
  # A proxy class for invoking various UI commands
@@ -83,26 +81,6 @@ module Hokusai
83
81
  queue << Commands::ScissorEnd.new
84
82
  end
85
83
 
86
- def shader_begin
87
- command = Commands::ShaderBegin.new
88
-
89
- yield command
90
-
91
- queue << command
92
- end
93
-
94
- def shader_end
95
- queue << Commands::ShaderEnd.new
96
- end
97
-
98
- def texture(x, y, w, h)
99
- command = Commands::Texture.new(x, y, w, h)
100
-
101
- yield command
102
-
103
- queue << command
104
- end
105
-
106
84
  # Draws text
107
85
  #
108
86
  # @param [String] the text content
@@ -65,5 +65,4 @@ module Hokusai
65
65
  end
66
66
 
67
67
  require_relative './events/keyboard'
68
- require_relative './events/mouse'
69
- require_relative './events/touch'
68
+ require_relative './events/mouse'
@@ -1,11 +1,10 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Hokusai
4
2
  class KeyboardEvent < Event
5
3
  extend Forwardable
6
4
 
7
5
  def_delegators :@keyboard, :shift, :super, :ctrl,
8
- :alt, :pressed, :released, :char, :code
6
+ :alt, :pressed, :pressed_len, :released,
7
+ :released_len
9
8
 
10
9
  attr_reader :input
11
10
 
@@ -36,40 +35,48 @@ module Hokusai
36
35
  class KeyUpEvent < KeyboardEvent
37
36
  name "keyup"
38
37
 
38
+ def keyboard_key
39
+ input.raw[:keyboard][:released]
40
+ end
41
+
39
42
  def key
40
- released[0]&.[](:symbol)
43
+ keyboard_key[:key][:key]
41
44
  end
42
45
 
43
46
  def code
44
- released[0]&.[](:code)
47
+ keyboard_key[:char_code]
45
48
  end
46
49
 
47
50
  def char
48
- released[0]&.[](:char)
51
+ code.chr
49
52
  end
50
53
 
51
54
  def capture(block, _)
52
- captures << block if matches(block) && released.size > 0
55
+ captures << block if matches(block) && released_len > 0
53
56
  end
54
57
  end
55
58
 
56
59
  class KeyPressEvent < KeyboardEvent
57
60
  name "keypress"
58
61
 
62
+ def keyboard_key
63
+ input.raw[:keyboard][:pressed]
64
+ end
65
+
59
66
  def key
60
- pressed[0]&.[](:symbol)
67
+ keyboard_key[:key][:key]
61
68
  end
62
69
 
63
70
  def code
64
- pressed[0]&.[](:code)
71
+ keyboard_key[:char_code]
65
72
  end
66
73
 
67
74
  def char
68
- pressed[0]&.[](:char)
75
+ code.chr
69
76
  end
70
77
 
71
78
  def capture(block, _)
72
- return unless matches(block) && pressed.size > 0
79
+ return unless matches(block) && pressed_len > 0
73
80
 
74
81
  captures << block
75
82
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Hokusai
4
2
  class MouseEvent < Event
5
3
  extend Forwardable
@@ -69,7 +67,7 @@ module Hokusai
69
67
  protected
70
68
 
71
69
  def hovered(canvas)
72
- input.hovered?(canvas)
70
+ LibHokusai.hoku_input_is_hovered(input.raw, canvas.to_hoku_rect)
73
71
  end
74
72
  end
75
73
 
@@ -87,19 +85,19 @@ module Hokusai
87
85
  name "click"
88
86
 
89
87
  def capture(block, canvas)
90
- if left.clicked && clicked(canvas)
88
+ if left[:clicked] && clicked(canvas)
91
89
  block.node.meta.focus
92
90
 
93
91
  if matches(block)
94
92
  captures << block
95
93
  end
96
- elsif left.clicked
94
+ elsif left[:clicked]
97
95
  block.node.meta.blur
98
96
  end
99
97
  end
100
98
 
101
99
  def clicked(canvas)
102
- left.clicked && input.hovered?(canvas)
100
+ LibHokusai.hoku_input_is_clicked(input.raw, canvas.to_hoku_rect)
103
101
  end
104
102
  end
105
103
 
@@ -107,7 +105,7 @@ module Hokusai
107
105
  name "mouseup"
108
106
 
109
107
  def capture(block, _)
110
- if left.up && matches(block)
108
+ if left[:up] && matches(block)
111
109
  captures << block
112
110
  end
113
111
  end
@@ -117,7 +115,7 @@ module Hokusai
117
115
  name "mousedown"
118
116
 
119
117
  def capture(block, _)
120
- if left.down && matches(block)
118
+ if left[:down] && matches(block)
121
119
  captures << block
122
120
  end
123
121
  end
@@ -170,13 +168,13 @@ module Hokusai
170
168
  def capture(block, canvas)
171
169
  captures << block if matches(block)
172
170
 
173
- if left.clicked && !clicked(canvas)
171
+ if left[:clicked] && !clicked(canvas)
174
172
  block.node.meta.blur
175
173
  end
176
174
  end
177
175
 
178
176
  def clicked(canvas)
179
- left.clicked && input.hovered?(canvas)
177
+ LibHokusai.hoku_input_is_clicked(input.raw, canvas.to_hoku_rect)
180
178
  end
181
179
  end
182
180
  end
@@ -65,7 +65,7 @@ module Hokusai
65
65
 
66
66
  portal = Node.new(ast)
67
67
  node = child_block_class.compile(ast.type, portal)
68
- child_block = child_block_class.new(node: node, providers: mount_providers)
68
+ child_block = child_block_class.new(node: node)
69
69
  child_block.node.add_styles(target.class)
70
70
  child_block.node.add_props_from_block(target, context: ctx)
71
71
  child_block.node.meta.set_prop(ast.loop.var.to_sym, value)