hokusai-zero 0.2.6 → 0.2.7

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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/Gemfile.lock +0 -2
  4. data/README.md +1 -1
  5. data/ast/src/core/ast.c +3 -11
  6. data/ast/src/core/hml.c +212 -40
  7. data/ast/src/core/hml.h +1 -0
  8. data/ast/src/core/input.h +0 -1
  9. data/ast/src/core/log.c +87 -0
  10. data/ast/src/core/log.h +41 -0
  11. data/ast/src/core/util.c +23 -23
  12. data/ast/src/core/util.h +7 -7
  13. data/ast/test/parser.c +1 -0
  14. data/ext/extconf.rb +6 -6
  15. data/hokusai.gemspec +1 -2
  16. data/ui/examples/drag.rb +154 -0
  17. data/ui/examples/embedded.rb +58 -0
  18. data/ui/examples/forum/file.rb +1 -1
  19. data/ui/examples/forum/post.rb +0 -1
  20. data/ui/examples/forum.rb +7 -7
  21. data/ui/examples/game.rb +143 -0
  22. data/ui/examples/keyboard.rb +47 -0
  23. data/ui/examples/overlay.rb +233 -0
  24. data/ui/examples/provider.rb +56 -0
  25. data/ui/examples/shader/test.rb +155 -0
  26. data/ui/examples/shader.rb +100 -0
  27. data/ui/examples/spreadsheet.rb +12 -11
  28. data/ui/examples/wiki.rb +82 -0
  29. data/ui/lib/lib_hokusai.rb +43 -24
  30. data/ui/spec/hokusai/e2e/keyboard_spec.rb +52 -0
  31. data/ui/spec/spec_helper.rb +1 -1
  32. data/ui/src/hokusai/assets/arrow-down-line.png +0 -0
  33. data/ui/src/hokusai/assets/arrow-down-wide-line.png +0 -0
  34. data/ui/src/hokusai/assets/icons/outline/arrow-big-up.svg +19 -0
  35. data/ui/src/hokusai/assets/icons/outline/backspace.svg +20 -0
  36. data/ui/src/hokusai/automation/driver_commands/base.rb +2 -8
  37. data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +3 -6
  38. data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +12 -5
  39. data/ui/src/hokusai/automation/server.rb +2 -3
  40. data/ui/src/hokusai/backends/raylib/config.rb +2 -1
  41. data/ui/src/hokusai/backends/raylib/font.rb +24 -3
  42. data/ui/src/hokusai/backends/raylib.rb +167 -36
  43. data/ui/src/hokusai/backends/sdl2/config.rb +9 -6
  44. data/ui/src/hokusai/backends/sdl2/font.rb +3 -1
  45. data/ui/src/hokusai/backends/sdl2.rb +188 -93
  46. data/ui/src/hokusai/blocks/color_picker.rb +1080 -0
  47. data/ui/src/hokusai/blocks/input.rb +2 -2
  48. data/ui/src/hokusai/blocks/keyboard.rb +249 -0
  49. data/ui/src/hokusai/blocks/shader_begin.rb +22 -0
  50. data/ui/src/hokusai/blocks/shader_end.rb +12 -0
  51. data/ui/src/hokusai/blocks/slider.rb +139 -0
  52. data/ui/src/hokusai/blocks/texture.rb +23 -0
  53. data/ui/src/hokusai/commands/rect.rb +12 -3
  54. data/ui/src/hokusai/commands/shader.rb +33 -0
  55. data/ui/src/hokusai/commands/texture.rb +26 -0
  56. data/ui/src/hokusai/commands.rb +22 -0
  57. data/ui/src/hokusai/event.rb +2 -1
  58. data/ui/src/hokusai/events/keyboard.rb +11 -18
  59. data/ui/src/hokusai/events/mouse.rb +10 -8
  60. data/ui/src/hokusai/events/touch.rb +62 -0
  61. data/ui/src/hokusai/meta.rb +9 -4
  62. data/ui/src/hokusai/mounting/loop_entry.rb +1 -1
  63. data/ui/src/hokusai/mounting/update_entry.rb +7 -6
  64. data/ui/src/hokusai/painter.rb +31 -8
  65. data/ui/src/hokusai/types/display.rb +151 -0
  66. data/ui/src/hokusai/types/keyboard.rb +168 -0
  67. data/ui/src/hokusai/types/mouse.rb +36 -0
  68. data/ui/src/hokusai/types/primitives.rb +56 -0
  69. data/ui/src/hokusai/types/touch.rb +181 -0
  70. data/ui/src/hokusai/types.rb +20 -244
  71. data/ui/src/hokusai/util/wrap_stream.rb +193 -0
  72. data/ui/src/hokusai.rb +61 -35
  73. data/xmake.lua +2 -1
  74. metadata +34 -22
  75. data/ui/src/hokusai/assets/chevron-down.svg +0 -1
@@ -122,23 +122,7 @@ module LibHokusai
122
122
  :next_child, HmlAst.ptr
123
123
  end
124
124
 
125
-
126
- # fun hashmap_iter(map : Hashmap, i : LibC::SizeT*, item : Void**) : Bool
127
- # ast methods
128
- attach_function :hoku_ast_prop_init, [:pointer, :string], :int
129
- attach_function :hoku_ast_class_list_includes, [:pointer, :string], :int
130
- attach_function :hoku_ast_get_prop, [HmlAst.by_ref, HmlAstProp.by_ref], HmlAstProp.by_ref
131
- attach_function :hoku_ast_get_event, [:pointer, :pointer], HmlAstEvent.by_ref
132
- attach_function :hashmap_iter, [:hashmap, :pointer, :pointer], :bool
133
- attach_function :hashmap_count, [:hashmap], :int
134
- attach_function :hoku_ast_free, [:pointer], :void
135
- attach_function :hoku_errored_ast, [HmlAst.by_ref], HmlAst.by_ref
136
- attach_function :hoku_ast_from_template, [:pointer, :string, :string], :int
137
- attach_function :hoku_style_from_template, [:pointer, :string], :int
138
- attach_function :hoku_style_free, [:pointer], :void
139
- attach_function :hoku_dump, [:pointer, :int], :void
140
-
141
- enum :hml_input_key, [
125
+ HOKUSAI_KEYS = [
142
126
  :null, :apostrophe, :comma, :minus,
143
127
  :period, :slash, :zero, :one, :two,
144
128
  :three, :four, :five, :six, :seven,
@@ -162,6 +146,41 @@ module LibHokusai
162
146
  :max
163
147
  ]
164
148
 
149
+ def self.set_log_level(symbol)
150
+ case symbol
151
+ when :fine
152
+ LibHokusai.f_logger_set_level(1 | 2 | 4 | 8 | 16)
153
+ when :debug
154
+ LibHokusai.f_logger_set_level(1 | 2 | 4 | 8)
155
+ when :info
156
+ LibHokusai.f_logger_set_level(1 | 2 | 4)
157
+ when :warn
158
+ LibHokusai.f_logger_set_level(1 | 2)
159
+ when :error
160
+ LibHokusai.f_logger_set_level(1)
161
+ end
162
+ end
163
+
164
+ enum :log_level, [:error, 1, :warn, 2, :info, 4, :debug, 8, :fine, 16]
165
+
166
+ # fun hashmap_iter(map : Hashmap, i : LibC::SizeT*, item : Void**) : Bool
167
+ # ast methods
168
+ attach_function :f_logger_set_level, [:log_level], :void
169
+ attach_function :hoku_ast_prop_init, [:pointer, :string], :int
170
+ attach_function :hoku_ast_class_list_includes, [:pointer, :string], :int
171
+ attach_function :hoku_ast_get_prop, [HmlAst.by_ref, HmlAstProp.by_ref], HmlAstProp.by_ref
172
+ attach_function :hoku_ast_get_event, [:pointer, :pointer], HmlAstEvent.by_ref
173
+ attach_function :hashmap_iter, [:hashmap, :pointer, :pointer], :bool
174
+ attach_function :hashmap_count, [:hashmap], :int
175
+ attach_function :hoku_ast_free, [:pointer], :void
176
+ attach_function :hoku_errored_ast, [HmlAst.by_ref], HmlAst.by_ref
177
+ attach_function :hoku_ast_from_template, [:pointer, :string, :string], :int
178
+ attach_function :hoku_style_from_template, [:pointer, :string], :int
179
+ attach_function :hoku_style_free, [:pointer], :void
180
+ attach_function :hoku_dump, [:pointer, :int], :void
181
+
182
+ enum :hml_input_key, HOKUSAI_KEYS
183
+
165
184
  enum :hml_input_select_type, [
166
185
  :ACTIVE, 0x01,
167
186
  :FROZEN, 0x02,
@@ -352,16 +371,16 @@ module LibHokusai
352
371
 
353
372
  attach_function :hoku_selection_init, [:pointer], :int
354
373
  attach_function :hoku_selection_selected, [HokuSelection.by_ref, :float, :float, :float, :float], :bool
355
- attach_function :hoku_selection_cursor_set, [HokuSelection.by_ref, HokuCursorPosition.by_value], :int
374
+ attach_function :hoku_selection_cursor_set, [HokuSelection.by_ref, HokuCursorPosition.by_ref], :int
356
375
  attach_function :hoku_selection_cursor_free, [HokuSelection.by_ref], :void
357
376
  attach_function :hoku_selection_free, [HokuSelection.by_ref], :void
358
377
 
359
- attach_function :hoku_rect_includes_y, [HmlRect.by_value, :float], :bool
360
- attach_function :hoku_rect_includes_x, [HmlRect.by_value, :float], :bool
361
- attach_function :hoku_rect_x_left, [HmlRect.by_value, :int], :float
362
- attach_function :hoku_rect_x_right, [HmlRect.by_value, :int], :float
363
- attach_function :hoku_rect_y_up, [HmlRect.by_value, :int], :float
364
- attach_function :hoku_rect_y_down, [HmlRect.by_value, :int], :float
378
+ attach_function :hoku_rect_includes_y, [HmlRect.by_ref, :float], :bool
379
+ attach_function :hoku_rect_includes_x, [HmlRect.by_ref, :float], :bool
380
+ attach_function :hoku_rect_x_left, [HmlRect.by_ref, :int], :float
381
+ attach_function :hoku_rect_x_right, [HmlRect.by_ref, :int], :float
382
+ attach_function :hoku_rect_y_up, [HmlRect.by_ref, :int], :float
383
+ attach_function :hoku_rect_y_down, [HmlRect.by_ref, :int], :float
365
384
 
366
385
  class HokuChar < FFI::Struct
367
386
  layout :offset, :int,
@@ -0,0 +1,52 @@
1
+ # describe Hokusai::Automation::Client do
2
+ # let(:keyboard) do
3
+ # klass = Class.new(Hokusai::Block) do
4
+ # template <<~EOF
5
+ # [template]
6
+ # vblock
7
+ # text#display {
8
+ # @keypress="update_content"
9
+ # :content="content" size="90"
10
+ # }
11
+ # keyboard{ :automatic="true" }
12
+ # EOF
13
+
14
+ # uses(
15
+ # text: Hokusai::Blocks::Text,
16
+ # keyboard: Hokusai::Blocks::Keyboard
17
+ # )
18
+
19
+ # attr_accessor :content
20
+
21
+ # def update_content(event)
22
+ # self.content << event.char
23
+ # end
24
+
25
+ # def initialize(**args)
26
+ # @content = ""
27
+
28
+ # super(**args)
29
+ # end
30
+ # end
31
+
32
+ # klass
33
+ # end
34
+
35
+ # def click_key(client, key)
36
+ # client.block("keyboard.#{key}").click
37
+ # end
38
+
39
+ # it "client works" do
40
+ # with_app(keyboard) do |client, app|
41
+ # display = client.block("#display")
42
+
43
+ # expect(display.prop("content")).to eq("")
44
+
45
+ # "hello world".split("").each do |key|
46
+ # click_key(client, key)
47
+ # end
48
+
49
+ # expect(display.prop("content")).to eq("hello world")
50
+ # end
51
+ # end
52
+ # end
@@ -44,7 +44,7 @@ def with_app(app, &block)
44
44
  client = nil
45
45
  error = nil
46
46
 
47
- Hokusai::ThreadPool.post do
47
+ Thread.new do
48
48
  client = Hokusai::Automation::Client.start
49
49
 
50
50
  yield client
@@ -0,0 +1,19 @@
1
+ <!--
2
+ tags: [direction, north]
3
+ category: Arrows
4
+ version: "1.37"
5
+ unicode: "eddd"
6
+ -->
7
+ <svg
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ width="24"
10
+ height="24"
11
+ viewBox="0 0 24 24"
12
+ fill="none"
13
+ stroke="white"
14
+ stroke-width="2"
15
+ stroke-linecap="round"
16
+ stroke-linejoin="round"
17
+ >
18
+ <path d="M9 20v-8h-3.586a1 1 0 0 1 -.707 -1.707l6.586 -6.586a1 1 0 0 1 1.414 0l6.586 6.586a1 1 0 0 1 -.707 1.707h-3.586v8a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z" />
19
+ </svg>
@@ -0,0 +1,20 @@
1
+ <!--
2
+ category: Text
3
+ tags: [delete, remove, eliminate]
4
+ version: "1.0"
5
+ unicode: "ea2d"
6
+ -->
7
+ <svg
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ width="24"
10
+ height="24"
11
+ viewBox="0 0 24 24"
12
+ fill="none"
13
+ stroke="white"
14
+ stroke-width="2"
15
+ stroke-linecap="round"
16
+ stroke-linejoin="round"
17
+ >
18
+ <path d="M20 6a1 1 0 0 1 1 1v10a1 1 0 0 1 -1 1h-11l-5 -5a1.5 1.5 0 0 1 0 -2l5 -5z" />
19
+ <path d="M12 10l4 4m0 -4l-4 4" />
20
+ </svg>
@@ -65,14 +65,8 @@ module Hokusai::Automation
65
65
  end
66
66
 
67
67
  def mouse_move(x, y, input)
68
- LibHokusai.hoku_input_set_mouse_position(input, vec2(x, y))
69
- end
70
-
71
- private
72
-
73
- # Returns an HmlVec2 from {x,y}
74
- def vec2(x, y)
75
- LibHokusai::HmlVec2.create(x, y)
68
+ input.mouse.pos.x = x
69
+ input.mouse.pos.y = y
76
70
  end
77
71
  end
78
72
  end
@@ -33,21 +33,18 @@ module Hokusai::Automation
33
33
  decode_key = keys.shift
34
34
 
35
35
  mouse_center(canvas, input)
36
- state = LibHokusai::HmlInputMouseButton.create(clicked: true)
37
- LibHokusai.hoku_input_mouse_set_button(input, state, 0)
36
+ input.mouse.left.clicked = true
38
37
 
39
38
  begin
40
39
  key_results = to_hml_keygroup(decode_key)
41
40
 
42
- LibHokusai.hoku_input_keyboard_start(input)
41
+ input.keyboard.reset
43
42
 
44
43
  key_results.each do |key|
45
44
  Log.info { "populating #{key}"}
46
45
 
47
- LibHokusai.hoku_input_keyboard_set_key(input, key, true)
46
+ input.keyboard.set(key, true)
48
47
  end
49
-
50
- LibHokusai.hoku_input_keyboard_stop(input)
51
48
  rescue Automation::Error => ex
52
49
  keys.clear
53
50
  self.exeception = ex
@@ -2,9 +2,9 @@ module Hokusai::Automation
2
2
  module DriverCommands
3
3
  module MouseMethods
4
4
  def trigger_mouse(input, **args)
5
- state = LibHokusai::HmlInputMouseButton.create(**args)
6
-
7
- LibHokusai.hoku_input_mouse_set_button(input, state, button)
5
+ args.each do |which, bool|
6
+ input.mouse.left.send("#{which}=", bool)
7
+ end
8
8
  end
9
9
  end
10
10
 
@@ -27,6 +27,14 @@ module Hokusai::Automation
27
27
  state[:button]
28
28
  end
29
29
 
30
+ def button_symbol
31
+ {
32
+ 0 => :left,
33
+ 1 => :middle,
34
+ 2 => :right
35
+ }[button]
36
+ end
37
+
30
38
  def on_complete
31
39
  return value if done?
32
40
 
@@ -65,7 +73,6 @@ module Hokusai::Automation
65
73
  class TriggerMouseClick < TriggerMouseBase
66
74
  def execute(blocks, canvas, input)
67
75
  if matches_blocks(blocks)
68
-
69
76
  mouse_center(canvas, input)
70
77
  trigger_mouse(input, clicked: true)
71
78
 
@@ -202,8 +209,8 @@ module Hokusai::Automation
202
209
  def execute(blocks, canvas, input)
203
210
  if matches_block(blocks[0])
204
211
  mouse_center(canvas, input)
205
- LibHokusai.hoku_input_mouse_set_scroll(input, scroll_amount)
206
212
 
213
+ input.mouse.scroll = scroll_amount
207
214
 
208
215
  done!
209
216
  end
@@ -99,15 +99,14 @@ module Hokusai
99
99
  app = App.new(driver)
100
100
 
101
101
  @socket = Thin::Server.new(*args, app)
102
- Hokusai::ThreadPool.post do
102
+
103
+ Thread.new do
103
104
  @socket.start
104
105
  end
105
106
  end
106
107
 
107
108
  def self.stop
108
109
  @socket.stop
109
-
110
- Hokusai::ThreadPool.prune_pool
111
110
  end
112
111
  end
113
112
  end
@@ -5,7 +5,7 @@ module Hokusai::Backends
5
5
  attr_accessor :width, :height, :fps,
6
6
  :title, :config_flags, :window_state_flags,
7
7
  :automation_driver, :background, :after_load_cb,
8
- :host, :port, :automated, :on_reload, :event_waiting
8
+ :host, :port, :automated, :on_reload, :event_waiting, :touch
9
9
 
10
10
  def initialize
11
11
  @width = 500
@@ -22,6 +22,7 @@ module Hokusai::Backends
22
22
  @automated = false
23
23
  @on_reload = ->(_){}
24
24
  @event_waiting = false
25
+ @touch = false
25
26
  end
26
27
 
27
28
  def start_automation_driver
@@ -24,7 +24,7 @@ module Hokusai
24
24
  end
25
25
 
26
26
  class Font < Hokusai::Font
27
- attr_reader :raw
27
+ attr_reader :raw, :sdf
28
28
 
29
29
  DEFAULT = "–—‘’“”…\r\n\t0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%%^&*(),.?/\"\\[]-_=+|~`{}<>;:'\0"
30
30
 
@@ -51,7 +51,7 @@ module Hokusai
51
51
 
52
52
  raylib_font = Raylib.LoadFontEx(file, font_size, codepoints, count)
53
53
  Raylib.GenTextureMipmaps(raylib_font.texture)
54
- Raylib.SetTextureFilter(raylib_font.texture, Raylib::TEXTURE_FILTER_BILINEAR)
54
+ Raylib.SetTextureFilter(raylib_font.texture, Raylib::TEXTURE_FILTER_POINT)
55
55
 
56
56
  font = new(raylib_font)
57
57
  Raylib.UnloadCodepoints(codepoints)
@@ -59,9 +59,30 @@ module Hokusai
59
59
  font
60
60
  end
61
61
 
62
- def initialize(raw, spacing = 1.0)
62
+ def self.sdf(file, size)
63
+ ptr = FFI::MemoryPointer.new(:int)
64
+ data = Raylib.LoadFileData(file, ptr)
65
+ font = Raylib::Font.new
66
+ font.baseSize = size
67
+ font.glyphCount = 95
68
+
69
+ font.glyphs = Raylib.LoadFontData(data, ptr.read_int, size, nil, 0, Raylib::FONT_SDF)
70
+ buf = FFI::MemoryPointer.new(:pointer, 1)
71
+ atlas = Raylib.GenImageFontAtlas(font.glyphs, buf, 95, size, 4, 0)
72
+ font.recs = buf.read_pointer
73
+ font.texture = Raylib.LoadTextureFromImage(atlas)
74
+ Raylib.UnloadImage(atlas)
75
+ Raylib.UnloadFileData(data)
76
+ buf.free
77
+ ptr.free
78
+
79
+ new(font, sdf: true)
80
+ end
81
+
82
+ def initialize(raw, spacing = 1.0, sdf: false)
63
83
  @raw = raw
64
84
  @spacing = spacing
85
+ @sdf = sdf
65
86
  end
66
87
 
67
88
  # returns the spacing for this font