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.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/README.md +1 -1
- data/ast/src/core/ast.c +3 -11
- data/ast/src/core/hml.c +212 -40
- data/ast/src/core/hml.h +1 -0
- data/ast/src/core/input.h +0 -1
- data/ast/src/core/log.c +87 -0
- data/ast/src/core/log.h +41 -0
- data/ast/src/core/util.c +23 -23
- data/ast/src/core/util.h +7 -7
- data/ast/test/parser.c +1 -0
- data/ext/extconf.rb +6 -6
- data/hokusai.gemspec +1 -2
- data/ui/examples/drag.rb +154 -0
- data/ui/examples/embedded.rb +58 -0
- data/ui/examples/forum/file.rb +1 -1
- data/ui/examples/forum/post.rb +0 -1
- data/ui/examples/forum.rb +7 -7
- data/ui/examples/game.rb +143 -0
- data/ui/examples/keyboard.rb +47 -0
- data/ui/examples/overlay.rb +233 -0
- data/ui/examples/provider.rb +56 -0
- data/ui/examples/shader/test.rb +155 -0
- data/ui/examples/shader.rb +100 -0
- data/ui/examples/spreadsheet.rb +12 -11
- data/ui/examples/wiki.rb +82 -0
- data/ui/lib/lib_hokusai.rb +43 -24
- data/ui/spec/hokusai/e2e/keyboard_spec.rb +52 -0
- data/ui/spec/spec_helper.rb +1 -1
- data/ui/src/hokusai/assets/arrow-down-line.png +0 -0
- data/ui/src/hokusai/assets/arrow-down-wide-line.png +0 -0
- data/ui/src/hokusai/assets/icons/outline/arrow-big-up.svg +19 -0
- data/ui/src/hokusai/assets/icons/outline/backspace.svg +20 -0
- data/ui/src/hokusai/automation/driver_commands/base.rb +2 -8
- data/ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb +3 -6
- data/ui/src/hokusai/automation/driver_commands/trigger_mouse.rb +12 -5
- data/ui/src/hokusai/automation/server.rb +2 -3
- data/ui/src/hokusai/backends/raylib/config.rb +2 -1
- data/ui/src/hokusai/backends/raylib/font.rb +24 -3
- data/ui/src/hokusai/backends/raylib.rb +167 -36
- data/ui/src/hokusai/backends/sdl2/config.rb +9 -6
- data/ui/src/hokusai/backends/sdl2/font.rb +3 -1
- data/ui/src/hokusai/backends/sdl2.rb +188 -93
- data/ui/src/hokusai/blocks/color_picker.rb +1080 -0
- data/ui/src/hokusai/blocks/input.rb +2 -2
- data/ui/src/hokusai/blocks/keyboard.rb +249 -0
- data/ui/src/hokusai/blocks/shader_begin.rb +22 -0
- data/ui/src/hokusai/blocks/shader_end.rb +12 -0
- data/ui/src/hokusai/blocks/slider.rb +139 -0
- data/ui/src/hokusai/blocks/texture.rb +23 -0
- data/ui/src/hokusai/commands/rect.rb +12 -3
- data/ui/src/hokusai/commands/shader.rb +33 -0
- data/ui/src/hokusai/commands/texture.rb +26 -0
- data/ui/src/hokusai/commands.rb +22 -0
- data/ui/src/hokusai/event.rb +2 -1
- data/ui/src/hokusai/events/keyboard.rb +11 -18
- data/ui/src/hokusai/events/mouse.rb +10 -8
- data/ui/src/hokusai/events/touch.rb +62 -0
- data/ui/src/hokusai/meta.rb +9 -4
- data/ui/src/hokusai/mounting/loop_entry.rb +1 -1
- data/ui/src/hokusai/mounting/update_entry.rb +7 -6
- data/ui/src/hokusai/painter.rb +31 -8
- data/ui/src/hokusai/types/display.rb +151 -0
- data/ui/src/hokusai/types/keyboard.rb +168 -0
- data/ui/src/hokusai/types/mouse.rb +36 -0
- data/ui/src/hokusai/types/primitives.rb +56 -0
- data/ui/src/hokusai/types/touch.rb +181 -0
- data/ui/src/hokusai/types.rb +20 -244
- data/ui/src/hokusai/util/wrap_stream.rb +193 -0
- data/ui/src/hokusai.rb +61 -35
- data/xmake.lua +2 -1
- metadata +34 -22
- data/ui/src/hokusai/assets/chevron-down.svg +0 -1
@@ -0,0 +1,233 @@
|
|
1
|
+
require_relative "../src/hokusai"
|
2
|
+
require_relative "../src/hokusai/backends/raylib"
|
3
|
+
|
4
|
+
class DropdownItem < Hokusai::Block
|
5
|
+
style <<~EOF
|
6
|
+
[style]
|
7
|
+
textStyle {
|
8
|
+
padding: padding(5.0, 5.0, 5.0, 5.0);
|
9
|
+
size: 23;
|
10
|
+
color: rgb(255,255,255);
|
11
|
+
cursor: "pointer";
|
12
|
+
}
|
13
|
+
EOF
|
14
|
+
|
15
|
+
template <<~EOF
|
16
|
+
[template]
|
17
|
+
text#second {
|
18
|
+
:content="content"
|
19
|
+
...textStyle
|
20
|
+
@click="emit_option"
|
21
|
+
@height_updated="udpate_height"
|
22
|
+
}
|
23
|
+
EOF
|
24
|
+
|
25
|
+
uses(text: Hokusai::Blocks::Text)
|
26
|
+
|
27
|
+
computed! :content
|
28
|
+
computed! :index
|
29
|
+
|
30
|
+
def udpate_height(height)
|
31
|
+
node.portal.meta.set_prop(:height, height)
|
32
|
+
emit("height", height, index)
|
33
|
+
end
|
34
|
+
|
35
|
+
def emit_option(e)
|
36
|
+
emit("option", content)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Dropdown < Hokusai::Block
|
41
|
+
style <<-EOF
|
42
|
+
[style]
|
43
|
+
panelStyle {
|
44
|
+
z: 1;
|
45
|
+
width: 200;
|
46
|
+
height: 300;
|
47
|
+
background: rgb(67, 64, 92);
|
48
|
+
}
|
49
|
+
|
50
|
+
labelStyle {
|
51
|
+
size: 22;
|
52
|
+
content: "Please choose your fruit?";
|
53
|
+
}
|
54
|
+
EOF
|
55
|
+
|
56
|
+
template <<~EOF
|
57
|
+
[template]
|
58
|
+
vblock { @click="toggle_dropdown" height="70"}
|
59
|
+
label { ...labelStyle }
|
60
|
+
label { :content="selected" size="25" }
|
61
|
+
[if="toggled"]
|
62
|
+
panel#first { ...panelStyle @click="stop"}
|
63
|
+
[for="option in options"]
|
64
|
+
item {
|
65
|
+
:height="get_height(index)"
|
66
|
+
:content="option"
|
67
|
+
:key="index"
|
68
|
+
:index="index"
|
69
|
+
@option="select"
|
70
|
+
@height="update_height"
|
71
|
+
}
|
72
|
+
EOF
|
73
|
+
|
74
|
+
uses(label: Hokusai::Blocks::Label, vblock: Hokusai::Blocks::Vblock, item: DropdownItem, panel: Hokusai::Blocks::Panel)
|
75
|
+
|
76
|
+
attr_reader :toggled
|
77
|
+
|
78
|
+
computed! :options
|
79
|
+
|
80
|
+
def list_height
|
81
|
+
@heights ||= {}
|
82
|
+
@heights.values.reduce(&:+) || 0.0
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_height(index)
|
86
|
+
@heights ||= {}
|
87
|
+
@heights[index] || 0.0
|
88
|
+
end
|
89
|
+
|
90
|
+
def update_height(height, index)
|
91
|
+
@heights ||= {}
|
92
|
+
@heights[index] = height
|
93
|
+
end
|
94
|
+
|
95
|
+
def stop(e)
|
96
|
+
end
|
97
|
+
|
98
|
+
def toggle_dropdown(_)
|
99
|
+
@toggled = !@toggled
|
100
|
+
end
|
101
|
+
|
102
|
+
def select(option)
|
103
|
+
@selected = option
|
104
|
+
@toggled = false
|
105
|
+
end
|
106
|
+
|
107
|
+
# def options
|
108
|
+
# %w[apple pear mango pineapple orange pear bananana kiwi grapes melon lemon lime]
|
109
|
+
# end
|
110
|
+
|
111
|
+
def selected
|
112
|
+
@selected || options.first
|
113
|
+
end
|
114
|
+
|
115
|
+
def initialize(**args)
|
116
|
+
@toggled = true
|
117
|
+
|
118
|
+
super
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class Modal < Hokusai::Block
|
123
|
+
template <<~EOF
|
124
|
+
[template]
|
125
|
+
hblock#top
|
126
|
+
empty
|
127
|
+
empty#topempty
|
128
|
+
text { @click="emit_close" content="X" size="40" color="255,255,255}
|
129
|
+
hblock#middle { height="300"}
|
130
|
+
slot
|
131
|
+
hblock#last
|
132
|
+
empty#lastempty
|
133
|
+
EOF
|
134
|
+
|
135
|
+
uses(vblock: Hokusai::Blocks::Vblock, empty: Hokusai::Blocks::Empty, hblock: Hokusai::Blocks::Hblock, text: Hokusai::Blocks::Label)
|
136
|
+
|
137
|
+
computed :color, default: [0, 0, 0, 200], convert: Hokusai::Color
|
138
|
+
|
139
|
+
def emit_close(event)
|
140
|
+
emit("close")
|
141
|
+
|
142
|
+
event.stop
|
143
|
+
end
|
144
|
+
|
145
|
+
def render(canvas)
|
146
|
+
draw do
|
147
|
+
rect(canvas.x, canvas.y, canvas.width, canvas.height) do |command|
|
148
|
+
command.color = color
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
yield canvas
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class Thing < Hokusai::Block
|
157
|
+
style <<~EOF
|
158
|
+
[style]
|
159
|
+
textStyle {
|
160
|
+
size: 30;
|
161
|
+
color: rgb(0, 0, 0);
|
162
|
+
content: "Hello modal!";
|
163
|
+
}
|
164
|
+
|
165
|
+
otherText {
|
166
|
+
size: 25;
|
167
|
+
content: "Hello World";
|
168
|
+
}
|
169
|
+
contentStyle {
|
170
|
+
height: 300.0;
|
171
|
+
width: 300.0;
|
172
|
+
background: rgb(255, 255, 255, 255);
|
173
|
+
}
|
174
|
+
backgroundStyle {
|
175
|
+
background: rgb(43, 151, 117);
|
176
|
+
}
|
177
|
+
modalStyle {
|
178
|
+
z: 1;
|
179
|
+
position: "absolute";
|
180
|
+
}
|
181
|
+
EOF
|
182
|
+
|
183
|
+
template <<~EOF
|
184
|
+
[template]
|
185
|
+
vblock#topnot
|
186
|
+
hblock#not{ ...backgroundStyle }
|
187
|
+
text#not { ...otherText @click="open_modal" }
|
188
|
+
dropdown { :options="outer_options" }
|
189
|
+
hblock { background="233,0,0" }
|
190
|
+
text#second { content="Second" }
|
191
|
+
modal {
|
192
|
+
@close="close"
|
193
|
+
:active="modal_open"
|
194
|
+
}
|
195
|
+
vblock { ...contentStyle }
|
196
|
+
dropdown { :options="inner_options" }
|
197
|
+
color_picker
|
198
|
+
text#last { size="30" content="last"}
|
199
|
+
EOF
|
200
|
+
|
201
|
+
attr_reader :modal_open
|
202
|
+
|
203
|
+
def log(event)
|
204
|
+
pp ["clicked!"]
|
205
|
+
end
|
206
|
+
|
207
|
+
def outer_options
|
208
|
+
%w[sam betty fred candace justin lucy annabelle nick janessa sean]
|
209
|
+
end
|
210
|
+
|
211
|
+
def inner_options
|
212
|
+
%w[apple pear mango pineapple orange pear bananana kiwi grapes melon lemon lime]
|
213
|
+
end
|
214
|
+
|
215
|
+
def open_modal(event)
|
216
|
+
@modal_open = true
|
217
|
+
end
|
218
|
+
|
219
|
+
def close
|
220
|
+
@modal_open = false
|
221
|
+
end
|
222
|
+
|
223
|
+
uses(
|
224
|
+
color_picker: Hokusai::Blocks::ColorPicker, modal: Hokusai::Blocks::Modal, dropdown: Hokusai::Blocks::Dropdown, vblock: Hokusai::Blocks::Vblock, text: Hokusai::Blocks::Text,empty: Hokusai::Blocks::Empty, hblock: Hokusai::Blocks::Hblock)
|
225
|
+
end
|
226
|
+
|
227
|
+
Hokusai::Backends::RaylibBackend.run(Thing) do |config|
|
228
|
+
config.after_load do
|
229
|
+
font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
|
230
|
+
Hokusai.fonts.register "inter", font
|
231
|
+
Hokusai.fonts.activate "inter"
|
232
|
+
end
|
233
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "../src/hokusai"
|
2
|
+
require_relative "../src/hokusai/backends/raylib"
|
3
|
+
|
4
|
+
class Child < Hokusai::Block
|
5
|
+
template <<~EOF
|
6
|
+
[template]
|
7
|
+
text { :content="get_content" @selected="handle_selected" @height_updated="update_height"}
|
8
|
+
EOF
|
9
|
+
|
10
|
+
uses(
|
11
|
+
vblock: Hokusai::Blocks::Vblock,
|
12
|
+
text: Hokusai::Blocks::Text,
|
13
|
+
input: Hokusai::Blocks::Input
|
14
|
+
)
|
15
|
+
|
16
|
+
def update_height(height)
|
17
|
+
node.meta.set_prop(:height, height)
|
18
|
+
end
|
19
|
+
|
20
|
+
def handle_selected(start, stop)
|
21
|
+
pp [start, stop]
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_content
|
25
|
+
@file ||= File.read(__FILE__)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class ProviderExample < Hokusai::Block
|
30
|
+
template <<~EOF
|
31
|
+
[template]
|
32
|
+
selectable
|
33
|
+
panel
|
34
|
+
text { :content="get_content" }
|
35
|
+
EOF
|
36
|
+
|
37
|
+
uses(
|
38
|
+
vblock: Hokusai::Blocks::Vblock,
|
39
|
+
selectable: Hokusai::Blocks::Selectable,
|
40
|
+
panel: Hokusai::Blocks::Panel,
|
41
|
+
child: Child,
|
42
|
+
text: Hokusai::Blocks::Text
|
43
|
+
)
|
44
|
+
|
45
|
+
def get_content
|
46
|
+
@file ||= File.read(__FILE__)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
Hokusai::Backends::RaylibBackend.run(ProviderExample) do |config|
|
52
|
+
config.width = 500
|
53
|
+
config.height = 500
|
54
|
+
config.title = "Provider application"
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require_relative "../../src/hokusai"
|
2
|
+
require_relative "../../src/hokusai/backends/raylib"
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
class ShaderWrapper < Hokusai::Block
|
6
|
+
template <<~EOF
|
7
|
+
[template]
|
8
|
+
shader_begin {
|
9
|
+
@mousemove="update_value"
|
10
|
+
:vertex_shader="vertex_shader"
|
11
|
+
:uniforms="uniforms"
|
12
|
+
}
|
13
|
+
slot
|
14
|
+
shader_end
|
15
|
+
EOF
|
16
|
+
|
17
|
+
uses(
|
18
|
+
shader_begin: Hokusai::Blocks::ShaderBegin,
|
19
|
+
shader_end: Hokusai::Blocks::ShaderEnd,
|
20
|
+
texture: Hokusai::Blocks::Texture
|
21
|
+
)
|
22
|
+
|
23
|
+
def update_value(event)
|
24
|
+
@pos = (event.pos.x + event.pos.y) / 1000
|
25
|
+
end
|
26
|
+
|
27
|
+
def uniforms
|
28
|
+
return unless @start && @pos
|
29
|
+
done = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
30
|
+
elapsed = (done - @start).round(3)
|
31
|
+
|
32
|
+
{
|
33
|
+
millis: [elapsed / 2, Hokusai::SHADER_UNIFORM_FLOAT]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_mounted
|
38
|
+
@start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
39
|
+
end
|
40
|
+
|
41
|
+
def fragment_shader
|
42
|
+
<<-EOF
|
43
|
+
#version 330
|
44
|
+
in vec4 fragColor;
|
45
|
+
out vec4 finalColor;
|
46
|
+
|
47
|
+
void main() {
|
48
|
+
finalColor = fragColor; //vec4(0., 1., 0., 1.);
|
49
|
+
}
|
50
|
+
EOF
|
51
|
+
end
|
52
|
+
|
53
|
+
def vertex_shader
|
54
|
+
<<-EOF
|
55
|
+
#version 330
|
56
|
+
in vec3 vertexPosition;
|
57
|
+
in vec2 vertexTexCoord;
|
58
|
+
in vec4 vertexColor;
|
59
|
+
|
60
|
+
uniform mat4 mvp;
|
61
|
+
uniform float millis;
|
62
|
+
|
63
|
+
out vec2 fragTexCoord;
|
64
|
+
out vec4 fragColor;
|
65
|
+
|
66
|
+
void main() {
|
67
|
+
fragTexCoord = vertexTexCoord;
|
68
|
+
fragColor = vertexColor;
|
69
|
+
vec4 position = mvp * vec4(vertexPosition, 1.);
|
70
|
+
|
71
|
+
position.x += sin(millis + position.y * 8) / 8;
|
72
|
+
gl_Position = position;
|
73
|
+
}
|
74
|
+
EOF
|
75
|
+
end
|
76
|
+
|
77
|
+
def render(canvas)
|
78
|
+
canvas.vertical = true
|
79
|
+
@x = canvas.x
|
80
|
+
|
81
|
+
yield canvas
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class ShaderTest < Hokusai::Block
|
86
|
+
style <<~EOF
|
87
|
+
[style]
|
88
|
+
circleStyle {
|
89
|
+
color: rgb(47, 112, 106);
|
90
|
+
}
|
91
|
+
|
92
|
+
textStyle {
|
93
|
+
content: "Whoa, coool dude.";
|
94
|
+
size: 15.0;
|
95
|
+
}
|
96
|
+
EOF
|
97
|
+
|
98
|
+
template <<~EOF
|
99
|
+
[template]
|
100
|
+
vblock
|
101
|
+
[if="pickered"]
|
102
|
+
picker
|
103
|
+
[else]
|
104
|
+
vblock
|
105
|
+
hblock { @click="set_pickered" }
|
106
|
+
empty
|
107
|
+
hblock
|
108
|
+
hblock
|
109
|
+
empty
|
110
|
+
hblock
|
111
|
+
wrapper
|
112
|
+
image { :source="addy_png" :width="500" :height="400" }
|
113
|
+
text { ...textStyle }
|
114
|
+
circle {
|
115
|
+
:radius="50.0"
|
116
|
+
...circleStyle
|
117
|
+
}
|
118
|
+
hblock
|
119
|
+
empty
|
120
|
+
hblock
|
121
|
+
empty
|
122
|
+
EOF
|
123
|
+
|
124
|
+
uses(
|
125
|
+
wrapper: ShaderWrapper,
|
126
|
+
picker: Hokusai::Blocks::ColorPicker,
|
127
|
+
image: Hokusai::Blocks::Image,
|
128
|
+
text: Hokusai::Blocks::Text,
|
129
|
+
circle: Hokusai::Blocks::Circle,
|
130
|
+
vblock: Hokusai::Blocks::Vblock,
|
131
|
+
hblock: Hokusai::Blocks::Hblock,
|
132
|
+
empty: Hokusai::Blocks::Empty
|
133
|
+
)
|
134
|
+
|
135
|
+
attr_accessor :pickered
|
136
|
+
|
137
|
+
def set_pickered(event)
|
138
|
+
self.pickered = true
|
139
|
+
end
|
140
|
+
|
141
|
+
def addy_png
|
142
|
+
"#{__dir__}/../assets/addy.png"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
Hokusai::Backends::RaylibBackend.run(ShaderTest) do |config|
|
148
|
+
config.width = 900
|
149
|
+
config.height = 800
|
150
|
+
config.after_load do
|
151
|
+
font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
|
152
|
+
Hokusai.fonts.register "inter", font
|
153
|
+
Hokusai.fonts.activate "inter"
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require_relative "../src/hokusai"
|
2
|
+
require_relative "../src/hokusai/backends/raylib"
|
3
|
+
|
4
|
+
class ShaderExample < Hokusai::Block
|
5
|
+
style <<~EOF
|
6
|
+
[style]
|
7
|
+
textureThing {
|
8
|
+
width: 500;
|
9
|
+
height: 900;
|
10
|
+
scale: 100.0;
|
11
|
+
}
|
12
|
+
EOF
|
13
|
+
|
14
|
+
template <<~EOF
|
15
|
+
[template]
|
16
|
+
colorpicker
|
17
|
+
shader_begin {
|
18
|
+
@mousemove="change_rotation"
|
19
|
+
@click="switch_color"
|
20
|
+
:fragment_shader="fragment_shader"
|
21
|
+
:uniforms="uniforms"
|
22
|
+
}
|
23
|
+
texture {
|
24
|
+
...textureThing
|
25
|
+
:rotation="rotate"
|
26
|
+
}
|
27
|
+
shader_end
|
28
|
+
EOF
|
29
|
+
|
30
|
+
uses(
|
31
|
+
colorpicker: Hokusai::Blocks::ColorPicker,
|
32
|
+
shader_begin: Hokusai::Blocks::ShaderBegin,
|
33
|
+
shader_end: Hokusai::Blocks::ShaderEnd,
|
34
|
+
texture: Hokusai::Blocks::Texture,
|
35
|
+
rect: Hokusai::Blocks::Rect,
|
36
|
+
vblock: Hokusai::Blocks::Vblock
|
37
|
+
)
|
38
|
+
|
39
|
+
attr_reader :rotate
|
40
|
+
|
41
|
+
def initialize(**args)
|
42
|
+
@color = [1.0, 0.0, 0.0, 1.0]
|
43
|
+
@position = [0.0, 100.0, 0.0, 1.0]
|
44
|
+
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
def change_rotation(event)
|
49
|
+
@rotate = event.delta[:y]
|
50
|
+
end
|
51
|
+
|
52
|
+
def switch_color(event)
|
53
|
+
@color = [
|
54
|
+
[0.3, 0.3, 0.3, 1.0],
|
55
|
+
[0.0, 1.0, 0.0, 1.0],
|
56
|
+
[0.0, 0.0, 1.0, 1.0]
|
57
|
+
].sample
|
58
|
+
end
|
59
|
+
|
60
|
+
# def move_mouse(event)
|
61
|
+
# @position[0] = [0.0, 0.3, 0.6, 0.9, 1.0].sample
|
62
|
+
# end
|
63
|
+
|
64
|
+
def vertex_shader
|
65
|
+
<<-EOF
|
66
|
+
#version 330 core
|
67
|
+
|
68
|
+
uniform vec4 position;
|
69
|
+
|
70
|
+
void main() {
|
71
|
+
gl_Position = position;
|
72
|
+
}
|
73
|
+
EOF
|
74
|
+
end
|
75
|
+
|
76
|
+
def fragment_shader
|
77
|
+
<<-EOF
|
78
|
+
#version 330 core
|
79
|
+
|
80
|
+
in vec4 position;
|
81
|
+
out vec4 FragColor;
|
82
|
+
|
83
|
+
uniform vec4 color;
|
84
|
+
|
85
|
+
void main() {
|
86
|
+
FragColor = color;
|
87
|
+
}
|
88
|
+
EOF
|
89
|
+
end
|
90
|
+
|
91
|
+
def uniforms
|
92
|
+
[
|
93
|
+
["color", @color, Hokusai::SHADER_UNIFORM_VEC4]
|
94
|
+
]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
Hokusai::Backends::RaylibBackend.run(ShaderExample) do |config|
|
99
|
+
config.background = Raylib::BLUE
|
100
|
+
end
|
data/ui/examples/spreadsheet.rb
CHANGED
@@ -119,22 +119,23 @@ module Demos
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
Hokusai::Backends::
|
123
|
-
config.after_load do
|
124
|
-
|
125
|
-
|
126
|
-
|
122
|
+
Hokusai::Backends::SDLBackend.run(Demos::Spreadsheet::App) do |config|
|
123
|
+
# config.after_load do
|
124
|
+
# font = Hokusai::Backends::RaylibBackend::Font.from("#{__dir__}/assets/Inter-Regular.ttf")
|
125
|
+
# Hokusai.fonts.register "inter", font
|
126
|
+
# Hokusai.fonts.activate "inter"
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
end
|
128
|
+
# font = Hokusai::Backends::RaylibBackend::Font.from_ext("#{__dir__}/assets/Delius-Regular.ttf", 160)
|
129
|
+
# Hokusai.fonts.register "dohyeon", font
|
130
|
+
# end
|
131
131
|
|
132
132
|
config.fps = 60
|
133
133
|
config.width = 800
|
134
134
|
config.height = 500
|
135
135
|
config.title = "Spreadsheet application"
|
136
136
|
|
137
|
-
|
138
|
-
config.
|
139
|
-
config.
|
137
|
+
|
138
|
+
# config.config_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_VSYNC_HINT | Raylib::FLAG_WINDOW_TRANSPARENT
|
139
|
+
# config.window_state_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_WINDOW_UNDECORATED | Raylib::FLAG_WINDOW_TRANSPARENT
|
140
|
+
# config.background = Raylib::BLANK
|
140
141
|
end
|
data/ui/examples/wiki.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require "wikipedia"
|
2
|
+
require_relative "../src/hokusai"
|
3
|
+
require_relative "../src/hokusai/backends/raylib"
|
4
|
+
|
5
|
+
module Wiki
|
6
|
+
class Widget < Hokusai::Block
|
7
|
+
style <<-EOF
|
8
|
+
[style]
|
9
|
+
wikiStyle {
|
10
|
+
color: rgb(49, 49, 49);
|
11
|
+
size: 20;
|
12
|
+
markdown: true;
|
13
|
+
padding: padding(5.0, 10.0, 5.0, 10.0);
|
14
|
+
}
|
15
|
+
search {
|
16
|
+
height: 45;
|
17
|
+
background: rgb(239, 243, 255);
|
18
|
+
}
|
19
|
+
EOF
|
20
|
+
template <<-EOF
|
21
|
+
[template]
|
22
|
+
selectable
|
23
|
+
vblock
|
24
|
+
vblock {
|
25
|
+
...search
|
26
|
+
}
|
27
|
+
label {
|
28
|
+
content="Search by Term"
|
29
|
+
}
|
30
|
+
input {
|
31
|
+
size="25"
|
32
|
+
@change="update_term"
|
33
|
+
}
|
34
|
+
[if="summary"]
|
35
|
+
panel
|
36
|
+
text {
|
37
|
+
@selected="handle_selected"
|
38
|
+
:content="summary"
|
39
|
+
...wikiStyle
|
40
|
+
}
|
41
|
+
EOF
|
42
|
+
|
43
|
+
uses(
|
44
|
+
selectable: Hokusai::Blocks::Selectable,
|
45
|
+
vblock: Hokusai::Blocks::Vblock,
|
46
|
+
text: Hokusai::Blocks::Text,
|
47
|
+
label: Hokusai::Blocks::Label,
|
48
|
+
input: Hokusai::Blocks::Input,
|
49
|
+
panel: Hokusai::Blocks::Panel,
|
50
|
+
)
|
51
|
+
|
52
|
+
attr_reader :summary
|
53
|
+
|
54
|
+
def update_term(term)
|
55
|
+
page = Wikipedia.find(term)
|
56
|
+
|
57
|
+
@summary = <<~EOF
|
58
|
+
**[#{term}](#{page.fullurl})**
|
59
|
+
|
60
|
+
#{page.summary}
|
61
|
+
EOF
|
62
|
+
|
63
|
+
@summary
|
64
|
+
end
|
65
|
+
|
66
|
+
def handle_selected(start, stop)
|
67
|
+
pp [start, stop]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Hokusai::Backends::RaylibBackend.run(Wiki::Widget) do |config|
|
73
|
+
config.after_load do
|
74
|
+
font = Hokusai::Backends::RaylibBackend::Font.from_ext("#{__dir__}/assets/Inter-Regular.ttf", 160)
|
75
|
+
Hokusai.fonts.register "inter", font
|
76
|
+
Hokusai.fonts.activate "inter"
|
77
|
+
end
|
78
|
+
|
79
|
+
config.width = 500
|
80
|
+
config.height = 500
|
81
|
+
config.title = "Wiki Widget"
|
82
|
+
end
|