hokusai-zero 0.2.6.pre.android → 0.2.6.pre.pinephone

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/Gemfile.lock +0 -2
  4. data/ast/src/core/input.c +85 -0
  5. data/ast/src/core/input.h +31 -0
  6. data/hokusai.gemspec +1 -2
  7. data/ui/examples/drag.rb +154 -0
  8. data/ui/examples/embedded.rb +59 -0
  9. data/ui/examples/game.rb +143 -0
  10. data/ui/examples/overlay.rb +233 -0
  11. data/ui/examples/provider.rb +56 -0
  12. data/ui/examples/shader/test.rb +145 -0
  13. data/ui/examples/shader.rb +100 -0
  14. data/ui/examples/wiki.rb +82 -0
  15. data/ui/lib/lib_hokusai.rb +22 -1
  16. data/ui/spec/spec_helper.rb +1 -1
  17. data/ui/src/hokusai/assets/arrow-down-line.png +0 -0
  18. data/ui/src/hokusai/assets/arrow-down-wide-line.png +0 -0
  19. data/ui/src/hokusai/automation/server.rb +2 -3
  20. data/ui/src/hokusai/backends/embedded/config.rb +47 -0
  21. data/ui/src/hokusai/backends/embedded/font.rb +112 -0
  22. data/ui/src/hokusai/backends/embedded/keys.rb +124 -0
  23. data/ui/src/hokusai/backends/embedded.rb +564 -0
  24. data/ui/src/hokusai/backends/raylib.rb +80 -5
  25. data/ui/src/hokusai/blocks/color_picker.rb +1080 -0
  26. data/ui/src/hokusai/blocks/shader_begin.rb +22 -0
  27. data/ui/src/hokusai/blocks/shader_end.rb +12 -0
  28. data/ui/src/hokusai/blocks/texture.rb +23 -0
  29. data/ui/src/hokusai/commands/rect.rb +10 -1
  30. data/ui/src/hokusai/commands/shader.rb +33 -0
  31. data/ui/src/hokusai/commands/texture.rb +26 -0
  32. data/ui/src/hokusai/commands.rb +22 -0
  33. data/ui/src/hokusai/event.rb +2 -1
  34. data/ui/src/hokusai/events/embedded.rb +66 -0
  35. data/ui/src/hokusai/painter.rb +22 -0
  36. data/ui/src/hokusai/types.rb +29 -0
  37. data/ui/src/hokusai.rb +4 -9
  38. metadata +24 -22
  39. data/ui/src/hokusai/assets/chevron-down.svg +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce738bae9af93e8117b6a962e52d140c69ca8dacac118b7830819a8e4d1db585
4
- data.tar.gz: 0a0cbb5d8f6fb7a35dbcb619e17d06f5d05788c226480b11d546b3e9de7c8813
3
+ metadata.gz: ff2e748026518a381a084842d38e6499cbc21ba6ae82ef8eecea9fcf1caac01d
4
+ data.tar.gz: b6f6552079320c6345dc2332c1876e4ad4640ae91edd1b80b5886cbb7e5a2a81
5
5
  SHA512:
6
- metadata.gz: 1752951b5745a54239c07c9cb3a0b9569105a0011531174a6bfced4b9062466054b098029a72b7562b3f73a89378e422cd13983ff432b0130bcc1a8bce622e6e
7
- data.tar.gz: cc55da6b2f736f4f637a50115ad294247da5eb5c73fb74785ba2eec790c8476b9aae1d0b97822a65152f27ac924a32fd3a58192594e97b5af9f1bb7479f8db94
6
+ metadata.gz: b4d95dbfd485c9948af925f0d824383198a8676fa87714c1b8937b1c34c22bd0f384c86774a67e44e1e941fcfcad745e7576d287edc23f064022369d5187fad2
7
+ data.tar.gz: 73f8f5e98862ff3c219a61f570298e634a3d4293d619b6c79b557a5f499da96992366eb0f5ecf1f7adc7998f98d83ae54a878ee3445c527d262045cd41305038
data/Gemfile CHANGED
@@ -3,7 +3,6 @@ source "https://www.rubygems.org"
3
3
  gem "ffi", github: "ffi/ffi", submodules: true
4
4
 
5
5
  group :development, :test do
6
- gem "concurrent-ruby", require: "concurrent"
7
6
  gem "memory_profiler", require: false
8
7
  gem "mini_portile2", "~> 2.0.0"
9
8
  gem "raylib-bindings"
data/Gemfile.lock CHANGED
@@ -8,7 +8,6 @@ GIT
8
8
  GEM
9
9
  remote: https://www.rubygems.org/
10
10
  specs:
11
- concurrent-ruby (1.3.5)
12
11
  daemons (1.4.1)
13
12
  diff-lcs (1.6.1)
14
13
  domain_name (0.6.20240107)
@@ -77,7 +76,6 @@ PLATFORMS
77
76
  x86_64-linux
78
77
 
79
78
  DEPENDENCIES
80
- concurrent-ruby
81
79
  ffi!
82
80
  memory_profiler
83
81
  mini_portile2 (~> 2.0.0)
data/ast/src/core/input.c CHANGED
@@ -4,6 +4,84 @@
4
4
  #include "input.h"
5
5
  #include <stdio.h>
6
6
 
7
+ int hoku_input_embedded_init(hoku_input_embedded** embedded)
8
+ {
9
+ hoku_input_embedded* out = malloc(sizeof(hoku_input_embedded));
10
+ if (!out) return -1;
11
+
12
+ out->drag_pos = malloc(sizeof(hoku_vec2));
13
+ if (out->drag_pos == NULL)
14
+ {
15
+ free(out);
16
+ return -1;
17
+ }
18
+
19
+ out->pinch_pos = malloc(sizeof(hoku_vec2));
20
+ if (out->pinch_pos == NULL)
21
+ {
22
+ free(out->drag_pos);
23
+ free(out);
24
+ return -1;
25
+ }
26
+
27
+ out->drag_pos->x = 0.0;
28
+ out->drag_pos->y = 0.0;
29
+ out->pinch_pos->x = 0.0;
30
+ out->pinch_pos->y = 0.0;
31
+ out->hold = false;
32
+ out->drag = false;
33
+ out->pinch = false;
34
+ out->drag_direction = HOKU_DRAG_UP;
35
+ out->pinch_direction = HOKU_PINCH_IN;
36
+ out->hold_duration = 0;
37
+ out->drag_angle = 0.0;
38
+ out->pinch_angle = 0.0;
39
+
40
+ *embedded = out;
41
+ return 0;
42
+ }
43
+
44
+ void hoku_input_embedded_set_hold(hoku_input* input, bool hold, int hold_duration)
45
+ {
46
+ input->embedded->hold = hold;
47
+ input->embedded->hold_duration = hold_duration;
48
+ }
49
+
50
+ void hoku_input_embedded_set_drag(hoku_input* input, bool drag, hoku_drag_direction drag_direction, float drag_x, float drag_y, float drag_angle)
51
+ {
52
+ input->embedded->drag = drag;
53
+ input->embedded->drag_direction = drag_direction;
54
+ input->embedded->drag_pos->x = drag_x;
55
+ input->embedded->drag_pos->y = drag_y;
56
+ input->embedded->drag_angle = drag_angle;
57
+ }
58
+
59
+ void hoku_input_embedded_set_pinch(hoku_input* input, bool pinch, hoku_pinch_direction pinch_direction, float pinch_x, float pinch_y, float pinch_angle)
60
+ {
61
+ input->embedded->pinch = pinch;
62
+ input->embedded->pinch_direction = pinch_direction;
63
+ input->embedded->pinch_pos->x = pinch_x;
64
+ input->embedded->pinch_pos->y = pinch_y;
65
+ input->embedded->pinch_angle = pinch_angle;
66
+ }
67
+
68
+ int hoku_input_attach_embedded(hoku_input* input)
69
+ {
70
+ hoku_input_embedded* embedded;
71
+ if (hoku_input_embedded_init(&embedded) == -1) return -1;
72
+ input->embedded = embedded;
73
+
74
+ return 0;
75
+ }
76
+
77
+ void hoku_input_embedded_free(hoku_input_embedded* embedded)
78
+ {
79
+ free(embedded->drag_pos);
80
+ free(embedded->pinch_pos);
81
+ free(embedded);
82
+ }
83
+
84
+
7
85
  static int hoku_keycodes[HOKU_KEY_MAX] = {
8
86
  0,39,44,45,46,47,48,49,50,51,52,53,54,55,56,57,59,61,65,66,67,68,69,
9
87
  70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,
@@ -273,6 +351,12 @@ void hoku_input_free(hoku_input* input)
273
351
  {
274
352
  hoku_input_keyboard_free(input->keyboard);
275
353
  hoku_input_mouse_free(input->mouse);
354
+
355
+ if (input->embedded)
356
+ {
357
+ hoku_input_embedded_free(input->embedded);
358
+ }
359
+
276
360
  free(input);
277
361
  }
278
362
 
@@ -298,6 +382,7 @@ int hoku_input_init(hoku_input** input)
298
382
  return -1;
299
383
  }
300
384
  init->keyboard = keyboard;
385
+ init->embedded = NULL;
301
386
 
302
387
  *input = init;
303
388
  return 0;
data/ast/src/core/input.h CHANGED
@@ -87,12 +87,43 @@ typedef struct HmlInputKeyboard
87
87
  bool collecting;
88
88
  } hoku_input_keyboard;
89
89
 
90
+ typedef enum HmlDragDirection {
91
+ HOKU_DRAG_UP,
92
+ HOKU_DRAG_DOWN,
93
+ HOKU_DRAG_LEFT,
94
+ HOKU_DRAG_RIGHT
95
+ } hoku_drag_direction;
96
+
97
+ typedef enum HmlPinchDirection {
98
+ HOKU_PINCH_IN,
99
+ HOKU_PINCH_OUT
100
+ } hoku_pinch_direction;
101
+
102
+ typedef struct HmlInputEmbedded
103
+ {
104
+ bool hold;
105
+ int hold_duration;
106
+ bool drag;
107
+ hoku_drag_direction drag_direction;
108
+ hoku_vec2* drag_pos;
109
+ float drag_angle;
110
+ bool pinch;
111
+ hoku_pinch_direction pinch_direction;
112
+ hoku_vec2* pinch_pos;
113
+ float pinch_angle;
114
+ } hoku_input_embedded;
115
+
90
116
  typedef struct HmlInput
91
117
  {
92
118
  hoku_input_keyboard* keyboard;
93
119
  hoku_input_mouse* mouse;
120
+ hoku_input_embedded* embedded;
94
121
  } hoku_input;
95
122
 
123
+ void hoku_input_embedded_set_hold(hoku_input* input, bool hold, int hold_duration);
124
+ void hoku_input_embedded_set_drag(hoku_input* input, bool drag, hoku_drag_direction drag_direction, float drag_x, float drag_y, float drag_angle);
125
+ void hoku_input_embedded_set_pinch(hoku_input* input, bool pinch, hoku_pinch_direction pinch_direction, float pinch_x, float pinch_y, float pinch_angle);
126
+ int hoku_input_attach_embedded(hoku_input* input);
96
127
 
97
128
  int hoku_input_keyboard_init(hoku_input_keyboard** keyboard);
98
129
  int hoku_input_mouse_init(hoku_input_mouse** mouse);
data/hokusai.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'hokusai-zero'
3
- s.version = '0.2.6-android'
3
+ s.version = '0.2.6-pinephone'
4
4
  s.licenses = ['MIT']
5
5
  s.summary = "A Ruby library for writing GUI applications"
6
6
  s.authors = ["skinnyjames"]
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.metadata = { "source_code_uri" => "https://codeberg.org/skinnyjames/hokusai" }
17
17
 
18
18
  s.add_dependency "ffi", "~> 1.16"
19
- s.add_dependency "concurrent-ruby", "~> 1.3.4"
20
19
  s.add_dependency "raylib-bindings", "~> 0.7.9"
21
20
  s.add_dependency "sdl2-bindings", "~> 0.2.3"
22
21
  s.add_dependency "memory_profiler"
@@ -0,0 +1,154 @@
1
+ require_relative "../src/hokusai"
2
+ require_relative "../src/hokusai/backends/raylib"
3
+ require "ostruct"
4
+
5
+ class Item < Hokusai::Block
6
+ style <<~EOF
7
+ [style]
8
+ circleStyle {
9
+ cursor: "pointer";
10
+ }
11
+ EOF
12
+ template <<~EOF
13
+ [template]
14
+ empty {
15
+ ...circleStyle
16
+ :color="color"
17
+ @mousedown="start_drag"
18
+ @mouseup="release_drag"
19
+ @mousemove="emit_drag"
20
+ }
21
+ EOF
22
+
23
+ uses(empty: Hokusai::Blocks::Empty)
24
+
25
+ computed :index
26
+ computed! :pos
27
+ computed! :color
28
+
29
+ attr_accessor :dragging
30
+
31
+ def initialize(**props)
32
+ @dragging = false
33
+
34
+ super
35
+ end
36
+
37
+ def contains(p)
38
+ (((p.x - pos[0]) * (p.x - pos[0]) + (p.y - pos[1]) * (p.y - pos[1])) <= 40 * 40)
39
+ end
40
+
41
+ def start_drag(event)
42
+ if event.left.down && contains(event.pos)
43
+
44
+ self.dragging = true
45
+ node.meta.set_prop(:z, 2)
46
+ node.meta.set_prop(:position, "absolute")
47
+ end
48
+ end
49
+
50
+ def release_drag(event)
51
+ if dragging
52
+ emit("done", index)
53
+ self.dragging = false
54
+
55
+ node.meta.set_prop(:z, nil)
56
+ node.meta.set_prop(:position, nil)
57
+ end
58
+ end
59
+
60
+ def emit_drag(event)
61
+ if dragging && event.left.down
62
+ emit("drag", index, [event.pos.x, event.pos.y])
63
+ elsif dragging
64
+ emit("done", index)
65
+
66
+ self.dragging = false
67
+ node.meta.set_prop(:z, nil)
68
+ node.meta.set_prop(:position, nil)
69
+ end
70
+ end
71
+
72
+ def render(canvas)
73
+ canvas.x = canvas.x + (canvas.width / 2)
74
+ canvas.y = canvas.y + canvas.height / 2
75
+
76
+ circle(pos[0], pos[1], 40) do |command|
77
+ command.color = color
78
+ end
79
+
80
+ yield canvas
81
+ end
82
+ end
83
+
84
+
85
+ class Drag < Hokusai::Block
86
+ template <<~EOF
87
+ [template]
88
+ vblock { background="233,233,233" }
89
+ [for="thing in items"]
90
+ item {
91
+ :z="z(index)"
92
+ :key="key(index, thing)"
93
+ :index="index"
94
+ @drag="update_position"
95
+ @done="update_drag_state"
96
+ :pos="pos(thing)"
97
+ :color="color(thing)"
98
+ }
99
+ EOF
100
+
101
+ uses(
102
+ vblock: Hokusai::Blocks::Vblock,
103
+ item: Item
104
+ )
105
+
106
+ attr_reader :items
107
+
108
+ def z(index)
109
+ items[index].dragging ? 2 : nil
110
+ end
111
+
112
+ def update_drag_state(index)
113
+ items[index].dragging = false
114
+ end
115
+
116
+ def key(index, thing)
117
+ "key-#{index}"
118
+ end
119
+
120
+ def pos(thing)
121
+ thing.position
122
+ end
123
+
124
+ def color(thing)
125
+ thing.color
126
+ end
127
+
128
+ def update_position(index, pos)
129
+ items[index].dragging = true
130
+ items[index].position = pos
131
+ end
132
+
133
+ def initialize(**args)
134
+ @items = [[0, 10, [222,222,0]], [100, 100, [0,222,222]], [300, 300, [0, 222, 0]]].map do |list|
135
+ item = OpenStruct.new
136
+ item.position = [list[0], list[1]]
137
+ item.color = Hokusai::Color.convert(list[2])
138
+ item.dragging = false
139
+ item
140
+ end
141
+
142
+ pp items
143
+
144
+ super
145
+ end
146
+ end
147
+
148
+ Hokusai::Backends::RaylibBackend.run(Drag) do |config|
149
+ config.after_load do
150
+ font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
151
+ Hokusai.fonts.register "inter", font
152
+ Hokusai.fonts.activate "inter"
153
+ end
154
+ end
@@ -0,0 +1,59 @@
1
+ require_relative "../src/hokusai"
2
+ require_relative "../src/hokusai/backends/embedded"
3
+
4
+ class App < Hokusai::Block
5
+ template <<~EOF
6
+ [template]
7
+ button {
8
+ @clicked="clear_text"
9
+ height="30"
10
+ content="clear"
11
+ }
12
+ panel {
13
+ @swipe="handle_swipe"
14
+ @taphold="handle_taphold"
15
+ @pinch="handle_pinch"
16
+ }
17
+ text {
18
+ :content="text"
19
+ :size="15"
20
+ }
21
+ EOF
22
+
23
+ uses(
24
+ button: Hokusai::Blocks::Button,
25
+ panel: Hokusai::Blocks::Panel,
26
+ text: Hokusai::Blocks::Text
27
+ )
28
+
29
+ attr_accessor :text
30
+
31
+ def initialize(**args)
32
+ @text = ""
33
+
34
+ super
35
+ end
36
+
37
+ def clear_text(event)
38
+ self.text = ""
39
+ pp ["clear", text]
40
+ end
41
+
42
+ def handle_pinch(event)
43
+ self.text += "Pinch: #{event.pinch_direction} - #{event.pinch_pos.x}x#{event.pinch_pos.y} (#{event.pinch_angle})\n\n"
44
+ end
45
+
46
+ def handle_swipe(event)
47
+ self.text += "Swipe: #{event.drag_direction} - #{event.drag_pos.x}x#{event.drag_pos.y} (#{event.drag_angle})\n\n"
48
+ end
49
+
50
+ def handle_taphold(event)
51
+ self.text += "Taphold #{event.hold_duration}\n\n"
52
+ end
53
+ end
54
+
55
+ Hokusai::Backends::EmbeddedBackend.run(App) do |config|
56
+ config.after_load do
57
+ Hokusai.maximize_window
58
+ end
59
+ end
@@ -0,0 +1,143 @@
1
+ require_relative "../src/hokusai"
2
+ require_relative "../src/hokusai/backends/raylib"
3
+ require 'ostruct'
4
+
5
+ TILES = [
6
+ ["Power Supply", 500],
7
+ ["Power Distribution", 400],
8
+ ["Farm", 100],
9
+ ["Medicine Production", 50],
10
+ ["Science Research", 400],
11
+ ["Lumberyard", 200],
12
+ ["Art Gallery", 20],
13
+ ["School", 100],
14
+ ["Commercial transportation", 300],
15
+ ["Mechanical Automation", 700],
16
+ ["Tailor shop", 50],
17
+ ["Housing Construction", 200],
18
+ ["Commerical Building Construction", 300],
19
+ ["Restaraunt", 50],
20
+ ["Furniture manufacturing", 200],
21
+ ["Cotton mill", 200],
22
+ ["Metals processing", 400],
23
+ ["Forestry center", 400],
24
+ ["Bar", 50],
25
+ ["Healthcare", 100]
26
+ ]
27
+
28
+
29
+ class Game < Hokusai::Block
30
+ style <<-EOF
31
+ [style]
32
+ bg {
33
+ color: rgb(173, 207, 224);
34
+ width: 100;
35
+ height: 100;
36
+ outline: outline(1.0, 1.0, 1.0, 1.0);
37
+ outline_color: rgb(0, 0, 0);
38
+ }
39
+ board {
40
+ height: 500;
41
+ width: 500;
42
+ }
43
+ height {
44
+ height: 100;
45
+ }
46
+ textPadding {
47
+ padding: padding(10.0, 5.0, 10.0, 10.0);
48
+ }
49
+ EOF
50
+ template <<~EOF
51
+ [template]
52
+ vblock { ...board }
53
+ hblock
54
+ [for="tile in top"]
55
+ rect { :key="top_key(tile)" ...bg }
56
+ text { :content="tile" ...textPadding}
57
+ [for="i in middle"]
58
+ hblock {...height :key="get(i)"}
59
+ rect {...bg}
60
+ text { :key="get(i)" :content="get(i)" ...textPadding }
61
+ empty
62
+ empty
63
+ empty
64
+ rect {...bg }
65
+ text { :key="get_next(i)" :content="get_next(i)" ...textPadding}
66
+ hblock
67
+ [for="tile in bottom"]
68
+ rect { ...bg :key="bottom_key(tile)" }
69
+ text { :key="tile" :content="tile" ...textPadding }
70
+ EOF
71
+
72
+ uses(
73
+ hblock: Hokusai::Blocks::Hblock,
74
+ vblock: Hokusai::Blocks::Vblock,
75
+ text: Hokusai::Blocks::Text,
76
+ empty: Hokusai::Blocks::Empty,
77
+ rect: Hokusai::Blocks::Rect
78
+ )
79
+
80
+ attr_reader :tiles
81
+
82
+ def get(i)
83
+ tiles[i[0]].title
84
+ end
85
+
86
+ def get_next(i)
87
+ tiles[i[1]].title
88
+ end
89
+
90
+ def middle
91
+ (5..10).each_slice(2).to_a
92
+ end
93
+
94
+ def bottom_key(t)
95
+ "bottom-#{t}"
96
+ end
97
+
98
+ def top_key(t)
99
+ "top-#{t}"
100
+ end
101
+
102
+ def top
103
+ tiles.take(5).map(&:title)
104
+ end
105
+
106
+ def bottom
107
+ a = tiles[-5, 5].map(&:title)
108
+ a
109
+ end
110
+
111
+ def after_updated
112
+ @tiles = TILES.map do |(label, cost)|
113
+ os = OpenStruct.new
114
+ os.title = label
115
+ os.cost = cost
116
+ os
117
+ end
118
+ end
119
+
120
+ def initialize(**args)
121
+ @tiles = TILES.map do |(label, cost)|
122
+ os = OpenStruct.new
123
+ os.title = label
124
+ os.cost = cost
125
+ os
126
+ end
127
+
128
+ super
129
+ end
130
+ end
131
+
132
+
133
+ Hokusai::Backends::RaylibBackend.run(Game) do |config|
134
+ config.width = 500
135
+ config.height = 500
136
+
137
+ config.after_load do
138
+ font = Hokusai::Backends::RaylibBackend::Font.from_ext("#{__dir__}/assets/OpenSans-Regular.ttf", 160)
139
+ Hokusai.fonts.register "opensans", font
140
+ Hokusai.fonts.activate "opensans"
141
+ end
142
+ end
143
+