hokusai-zero 0.2.6.pre.pinephone5 → 0.2.6.pre.pinephone6
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/hokusai.gemspec +1 -1
- data/ui/examples/counter.rb +2 -1
- data/ui/examples/spreadsheet.rb +11 -11
- data/ui/examples/tic_tac_toe.rb +6 -6
- 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/backends/raylib/font.rb +24 -3
- data/ui/src/hokusai/backends/raylib.rb +42 -15
- data/ui/src/hokusai/backends/sdl2.rb +55 -59
- data/ui/src/hokusai/blocks/input.rb +1 -1
- data/ui/src/hokusai/events/keyboard.rb +9 -18
- data/ui/src/hokusai/painter.rb +1 -6
- data/ui/src/hokusai/types/keyboard.rb +168 -0
- data/ui/src/hokusai/types.rb +3 -29
- data/ui/src/hokusai/util/wrap_stream.rb +0 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fadc5b1cf6e75bc57d76dcca297a97521e64a744858ef0cafbf53e2e7d259373
|
4
|
+
data.tar.gz: 010f5c1f195932e39b8f5061cbab13bc55ce88485bec86dadb6a5ec0754feb2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e0bdc4ecaa1609324e3ca7a2ba3dadd7ca9ef145ee67c49d66a9fc8c76b5971f1d61f14f806124c7e0c5564a0420af50619dd44da64828a8e041ed47cf35a6d
|
7
|
+
data.tar.gz: 63f2644bd086280547eea3497df85f274e9dd6304314de84c77839eb4bbd49b903506afb87aae47a230e2861cb80201e1c296c864869b8fbf4a5dca0999c3abc
|
data/hokusai.gemspec
CHANGED
data/ui/examples/counter.rb
CHANGED
@@ -122,11 +122,12 @@ Hokusai::Backends::RaylibBackend.run(Demos::Counter) do |config|
|
|
122
122
|
# end
|
123
123
|
|
124
124
|
config.after_load do
|
125
|
-
font = Hokusai::Backends::RaylibBackend::Font.
|
125
|
+
font = Hokusai::Backends::RaylibBackend::Font.sdf("#{__dir__}/assets/OpenSans-Regular.ttf", 260)
|
126
126
|
Hokusai.fonts.register "opensans", font
|
127
127
|
Hokusai.fonts.activate "opensans"
|
128
128
|
end
|
129
129
|
|
130
|
+
config.fps = 40
|
130
131
|
config.width = 500
|
131
132
|
config.height = 500
|
132
133
|
config.title = "Counter application"
|
data/ui/examples/spreadsheet.rb
CHANGED
@@ -119,15 +119,15 @@ module Demos
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
Hokusai::Backends::
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
122
|
+
Hokusai::Backends::RaylibBackend.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
|
-
|
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
|
@@ -135,7 +135,7 @@ Hokusai::Backends::SDLBackend.run(Demos::Spreadsheet::App) do |config|
|
|
135
135
|
config.title = "Spreadsheet application"
|
136
136
|
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
141
141
|
end
|
data/ui/examples/tic_tac_toe.rb
CHANGED
@@ -240,9 +240,9 @@ module Demos
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
end
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
243
|
+
|
244
|
+
Hokusai::Backends::RaylibBackend.run(Demos::TicTacToe::App) do |config|
|
245
|
+
config.width = 500
|
246
|
+
config.height = 500
|
247
|
+
config.title = "Tic Tac Trollio"
|
248
|
+
end
|
@@ -65,14 +65,8 @@ module Hokusai::Automation
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def mouse_move(x, y, input)
|
68
|
-
|
69
|
-
|
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
|
-
|
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
|
-
|
41
|
+
input.keyboard.reset
|
43
42
|
|
44
43
|
key_results.each do |key|
|
45
44
|
Log.info { "populating #{key}"}
|
46
45
|
|
47
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
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
|
@@ -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::
|
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
|
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
|
@@ -5,6 +5,34 @@ require 'memory_profiler'
|
|
5
5
|
|
6
6
|
module Hokusai::Backends
|
7
7
|
class RaylibBackend
|
8
|
+
|
9
|
+
SDF_SHADER = <<~EOF
|
10
|
+
#version 100
|
11
|
+
|
12
|
+
precision mediump float;
|
13
|
+
|
14
|
+
// Input vertex attributes (from vertex shader)
|
15
|
+
varying vec2 fragTexCoord;
|
16
|
+
varying vec4 fragColor;
|
17
|
+
|
18
|
+
// Input uniform values
|
19
|
+
uniform sampler2D texture0;
|
20
|
+
uniform vec4 colDiffuse;
|
21
|
+
|
22
|
+
// NOTE: Add your custom variables here
|
23
|
+
const float smoothing = 1.0/16.0;
|
24
|
+
|
25
|
+
void main()
|
26
|
+
{
|
27
|
+
// Texel color fetching from texture sampler
|
28
|
+
// NOTE: Calculate alpha using signed distance field (SDF)
|
29
|
+
float distance = texture2D(texture0, fragTexCoord).a;
|
30
|
+
float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
|
31
|
+
|
32
|
+
// Calculate final fragment color
|
33
|
+
gl_FragColor = vec4(fragColor.rgb, fragColor.a*alpha);
|
34
|
+
}
|
35
|
+
EOF
|
8
36
|
|
9
37
|
RAYLIB_PATH = ENV["RAYLIB_PATH"] || begin
|
10
38
|
path = "#{__dir__}/../../../../vendor/lib"
|
@@ -168,13 +196,11 @@ module Hokusai::Backends
|
|
168
196
|
end
|
169
197
|
|
170
198
|
if !input.keyboard_override
|
171
|
-
|
199
|
+
input.keyboard.reset
|
172
200
|
|
173
201
|
Keys.each do |(hoku_key, raylib_key)|
|
174
|
-
|
202
|
+
input.keyboard.set(hoku_key, Raylib.IsKeyDown(raylib_key))
|
175
203
|
end
|
176
|
-
|
177
|
-
LibHokusai.hoku_input_keyboard_stop(input.raw)
|
178
204
|
end
|
179
205
|
end
|
180
206
|
|
@@ -198,11 +224,7 @@ module Hokusai::Backends
|
|
198
224
|
|
199
225
|
register_command_handlers
|
200
226
|
|
201
|
-
|
202
|
-
LibHokusai.hoku_input_init(ptr)
|
203
|
-
raw = LibHokusai::HmlInput.new(ptr.get_pointer(0))
|
204
|
-
input = Hokusai::Input.new(raw)
|
205
|
-
ptr.free
|
227
|
+
input = Hokusai::Input.new
|
206
228
|
input.support_touch! if config.touch
|
207
229
|
|
208
230
|
Raylib.SetConfigFlags(config.config_flags)
|
@@ -296,8 +318,6 @@ module Hokusai::Backends
|
|
296
318
|
Raylib.UnloadShader(shader)
|
297
319
|
end
|
298
320
|
|
299
|
-
LibHokusai.hoku_input_free(input.raw)
|
300
|
-
|
301
321
|
if ENV["PROFILE"]
|
302
322
|
report = MemoryProfiler.stop
|
303
323
|
report.pretty_print(scale_bytes: true)
|
@@ -487,9 +507,9 @@ module Hokusai::Backends
|
|
487
507
|
next unless inside_scissor(command.x, command.y, command.size)
|
488
508
|
|
489
509
|
active_name = Hokusai.fonts.active_font_name
|
490
|
-
|
510
|
+
font_name = command.font.nil? ? active_name : command.font
|
491
511
|
|
492
|
-
Hokusai.fonts.activate
|
512
|
+
Hokusai.fonts.activate font_name
|
493
513
|
font = Hokusai.fonts.active
|
494
514
|
|
495
515
|
c = color(command.color)
|
@@ -497,9 +517,16 @@ module Hokusai::Backends
|
|
497
517
|
y = command.y + command.padding.t
|
498
518
|
|
499
519
|
if fnt = font
|
500
|
-
|
520
|
+
if fnt.sdf
|
521
|
+
self.class.shaders["font-sdf-#{font_name}"] ||= Raylib.LoadShaderFromMemory(nil, SDF_SHADER)
|
522
|
+
Raylib.BeginShaderMode(self.class.shaders["font-sdf-#{font_name}"])
|
523
|
+
end
|
524
|
+
|
501
525
|
Raylib.DrawTextEx(fnt.raw, command.content.to_s, vec2(x, y), command.size, fnt.spacing, c)
|
502
|
-
|
526
|
+
|
527
|
+
if fnt.sdf
|
528
|
+
Raylib.EndShaderMode
|
529
|
+
end
|
503
530
|
else
|
504
531
|
Raylib.DrawText(command.content, x, y, command.size, c)
|
505
532
|
end
|
@@ -121,10 +121,7 @@ module Hokusai::Backends
|
|
121
121
|
block = app.mount
|
122
122
|
# MemoryProfiler.start if ENV["PROFILE"]
|
123
123
|
|
124
|
-
|
125
|
-
LibHokusai.hoku_input_init(ptr)
|
126
|
-
raw = LibHokusai::HmlInput.new(ptr.get_pointer(0))
|
127
|
-
input = Hokusai::Input.new(raw)
|
124
|
+
input = Hokusai::Input.new
|
128
125
|
|
129
126
|
if config.touch
|
130
127
|
input.support_touch!
|
@@ -142,16 +139,21 @@ module Hokusai::Backends
|
|
142
139
|
if input.touch.touching?
|
143
140
|
token = input.touch.token
|
144
141
|
|
145
|
-
|
142
|
+
input.mouse.pos.x = token[:x]
|
143
|
+
input.mouse.pos.y = token[:y]
|
146
144
|
end
|
147
145
|
|
148
146
|
# translate taps to clicks
|
149
147
|
if input.touch.tapped?
|
150
|
-
|
151
|
-
|
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
152
|
else
|
153
|
-
|
154
|
-
|
153
|
+
input.mouse.left.clicked = true
|
154
|
+
input.mouse.left.down = true
|
155
|
+
input.mouse.left.released = false
|
156
|
+
input.mouse.left.up = false
|
155
157
|
end
|
156
158
|
end
|
157
159
|
end
|
@@ -179,7 +181,6 @@ module Hokusai::Backends
|
|
179
181
|
SDL.Delay(10)
|
180
182
|
end
|
181
183
|
|
182
|
-
LibHokusai.hoku_input_free(input.raw)
|
183
184
|
if ENV["PROFILE"]
|
184
185
|
# report = MemoryProfiler.stop
|
185
186
|
# report.pretty_print
|
@@ -211,16 +212,15 @@ module Hokusai::Backends
|
|
211
212
|
|
212
213
|
def reset_keys(input)
|
213
214
|
if !input.keyboard_override
|
214
|
-
|
215
|
-
|
216
|
-
|
215
|
+
input.keyboard.reset
|
216
|
+
|
217
|
+
Modifiers.each do |(sdlk, hkey)|
|
218
|
+
input.keyboard.set(hkey, false)
|
217
219
|
end
|
218
220
|
|
219
221
|
Keys.values.each do |hkey|
|
220
|
-
|
222
|
+
input.keyboard.set(hkey, false)
|
221
223
|
end
|
222
|
-
|
223
|
-
LibHokusai.hoku_input_keyboard_stop(input.raw)
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
@@ -254,15 +254,15 @@ module Hokusai::Backends
|
|
254
254
|
code = event[:key][:keysym][:sym]
|
255
255
|
hkey = Keys[code]
|
256
256
|
|
257
|
-
|
257
|
+
input.keyboard.reset
|
258
|
+
|
258
259
|
Modifiers.each do |(sdlk, hkey)|
|
259
260
|
if modifier & sdlk == sdlk
|
260
|
-
|
261
|
+
input.keyboard.set(hkey, true)
|
261
262
|
end
|
262
263
|
end
|
263
264
|
|
264
|
-
|
265
|
-
LibHokusai.hoku_input_keyboard_stop(input.raw)
|
265
|
+
input.keyboard.set(hkey, true) unless hkey.nil?
|
266
266
|
end
|
267
267
|
|
268
268
|
return true
|
@@ -271,16 +271,15 @@ module Hokusai::Backends
|
|
271
271
|
modifier = event[:key][:keysym][:mod]
|
272
272
|
code = event[:key][:keysym][:sym]
|
273
273
|
hkey = Keys[code]
|
274
|
+
input.keyboard.reset
|
274
275
|
|
275
|
-
LibHokusai.hoku_input_keyboard_start(input.raw)
|
276
276
|
Modifiers.each do |(sdlk, hkey)|
|
277
277
|
if modifier & sdlk == sdlk
|
278
|
-
|
278
|
+
input.keyboard.set(hkey, false)
|
279
279
|
end
|
280
280
|
end
|
281
281
|
|
282
|
-
|
283
|
-
LibHokusai.hoku_input_keyboard_stop(input.raw)
|
282
|
+
input.keyboard.set(hkey, false) unless hkey.nil?
|
284
283
|
end
|
285
284
|
return true
|
286
285
|
when SDL::WINDOWEVENT
|
@@ -302,62 +301,59 @@ module Hokusai::Backends
|
|
302
301
|
|
303
302
|
return true
|
304
303
|
when SDL::MOUSEMOTION
|
305
|
-
if input.
|
306
|
-
|
307
|
-
input.
|
308
|
-
input.
|
309
|
-
input.raw[:mouse][:scroll] = event[:motion][:y]
|
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]
|
310
308
|
end
|
311
309
|
|
312
|
-
|
313
|
-
|
314
|
-
LibHokusai.hoku_input_set_mouse_position(input.raw, hoku_mouse_pos)
|
310
|
+
input.mouse.pos.x = event[:motion][:x]
|
311
|
+
input.mouse.pos.y = event[:motion][:y]
|
315
312
|
|
316
313
|
# clear any click events
|
317
314
|
[[:left, 0], [:right, 2], [:middle, 1]].each do |(btn, i)|
|
318
|
-
|
319
|
-
button[:clicked] = false
|
320
|
-
LibHokusai.hoku_input_mouse_set_button(input.raw, button, i)
|
315
|
+
input.mouse.send(btn).clicked = false
|
321
316
|
end
|
322
317
|
|
323
318
|
return true
|
324
319
|
when SDL::MOUSEWHEEL
|
325
|
-
|
326
|
-
input.
|
320
|
+
input.mouse.scroll = event[:wheel][:preciseY]
|
321
|
+
input.mouse.delta.y = event[:wheel][:preciseY]
|
327
322
|
|
328
323
|
# clear any click events
|
329
324
|
[[:left, 0], [:right, 2], [:middle, 1]].each do |(btn, i)|
|
330
|
-
|
331
|
-
button[:clicked] = false
|
332
|
-
LibHokusai.hoku_input_mouse_set_button(input.raw, button, i)
|
325
|
+
input.mouse.send(btn).clicked = false
|
333
326
|
end
|
327
|
+
|
334
328
|
return true
|
335
329
|
when SDL::MOUSEBUTTONDOWN
|
336
330
|
clicked = event[:button][:clicks] > 0
|
337
|
-
|
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
|
338
342
|
|
339
|
-
LibHokusai.hoku_input_mouse_set_scroll(input.raw, 0.0)
|
340
|
-
input.raw[:mouse][:delta][:y] = 0.0
|
341
|
-
|
342
|
-
LibHokusai.hoku_input_mouse_set_button(input.raw, button, event[:button][:which])
|
343
343
|
return true
|
344
344
|
when SDL::MOUSEBUTTONUP
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
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
|
351
355
|
return true
|
352
356
|
when SDL::TEXTINPUT
|
353
|
-
char = event[:text][:text].to_s
|
354
|
-
LibHokusai.hoku_input_keyboard_start(input.raw)
|
355
|
-
|
356
|
-
Modifiers.each do |(sdlk, hkey)|
|
357
|
-
LibHokusai.hoku_input_keyboard_set_key(input.raw, hkey, false)
|
358
|
-
end
|
359
|
-
LibHokusai.hoku_input_keyboard_set_key(input.raw, char.to_sym, true)
|
360
|
-
LibHokusai.hoku_input_keyboard_stop(input.raw)
|
361
357
|
|
362
358
|
return true
|
363
359
|
when SDL::TEXTEDITING
|
@@ -5,8 +5,7 @@ module Hokusai
|
|
5
5
|
extend Forwardable
|
6
6
|
|
7
7
|
def_delegators :@keyboard, :shift, :super, :ctrl,
|
8
|
-
:alt, :pressed, :
|
9
|
-
:released_len
|
8
|
+
:alt, :pressed, :released, :char, :code
|
10
9
|
|
11
10
|
attr_reader :input
|
12
11
|
|
@@ -37,48 +36,40 @@ module Hokusai
|
|
37
36
|
class KeyUpEvent < KeyboardEvent
|
38
37
|
name "keyup"
|
39
38
|
|
40
|
-
def keyboard_key
|
41
|
-
input.raw[:keyboard][:released]
|
42
|
-
end
|
43
|
-
|
44
39
|
def key
|
45
|
-
|
40
|
+
released[0]&.[](:symbol)
|
46
41
|
end
|
47
42
|
|
48
43
|
def code
|
49
|
-
|
44
|
+
released[0]&.[](:code)
|
50
45
|
end
|
51
46
|
|
52
47
|
def char
|
53
|
-
|
48
|
+
released[0]&.[](:char)
|
54
49
|
end
|
55
50
|
|
56
51
|
def capture(block, _)
|
57
|
-
captures << block if matches(block) &&
|
52
|
+
captures << block if matches(block) && released.size > 0
|
58
53
|
end
|
59
54
|
end
|
60
55
|
|
61
56
|
class KeyPressEvent < KeyboardEvent
|
62
57
|
name "keypress"
|
63
58
|
|
64
|
-
def keyboard_key
|
65
|
-
input.raw[:keyboard][:pressed]
|
66
|
-
end
|
67
|
-
|
68
59
|
def key
|
69
|
-
|
60
|
+
pressed[0]&.[](:symbol)
|
70
61
|
end
|
71
62
|
|
72
63
|
def code
|
73
|
-
|
64
|
+
pressed[0]&.[](:code)
|
74
65
|
end
|
75
66
|
|
76
67
|
def char
|
77
|
-
|
68
|
+
pressed[0]&.[](:char)
|
78
69
|
end
|
79
70
|
|
80
71
|
def capture(block, _)
|
81
|
-
return unless matches(block) &&
|
72
|
+
return unless matches(block) && pressed.size > 0
|
82
73
|
|
83
74
|
captures << block
|
84
75
|
end
|
data/ui/src/hokusai/painter.rb
CHANGED
@@ -127,7 +127,7 @@ module Hokusai
|
|
127
127
|
|
128
128
|
canvas.reset(entry.x, entry.y, entry.w, entry.h)
|
129
129
|
|
130
|
-
before_render&.call([group.block, group.parent], canvas, input
|
130
|
+
before_render&.call([group.block, group.parent], canvas, input)
|
131
131
|
|
132
132
|
if capture
|
133
133
|
capture_events(group.block, canvas, hovered: hovered)
|
@@ -267,11 +267,6 @@ module Hokusai
|
|
267
267
|
return
|
268
268
|
end
|
269
269
|
|
270
|
-
|
271
|
-
|
272
|
-
# rect = canvas.to_hoku_rect
|
273
|
-
# block_is_hovered = LibHokusai.hoku_input_is_hovered(input.raw, rect)
|
274
|
-
|
275
270
|
if input.hovered?(canvas)
|
276
271
|
events[:hover].capture(block, canvas)
|
277
272
|
events[:click].capture(block, canvas)
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hokusai
|
4
|
+
KEY_CODES = {
|
5
|
+
null: 0, apostrophe: 39, comma: 44, minus: 45, period: 46,
|
6
|
+
slash: 47, zero: 48, one: 49, two: 50, three: 51, four: 52,
|
7
|
+
five: 53, six: 54, seven: 55, eight: 56, nine: 57, semicolon: 59,
|
8
|
+
equal: 61, a: 65, b: 66, c: 67, d: 68, e: 69, f: 70, g: 71, h: 72,
|
9
|
+
i: 73, j: 74, k: 75, l: 76, m: 77, n: 78, o: 79, p: 80, q: 81, r: 82,
|
10
|
+
s: 83, t: 84, u: 85, v: 86, w: 87, x: 88, y: 89, z: 90, left_bracket: 91,
|
11
|
+
backslash: 92, right_bracket: 93, grave: 96, space: 32, escape: 256,
|
12
|
+
enter: 257, tab: 258, backspace: 259, insert: 260, delete: 261, right: 262,
|
13
|
+
left: 263, down: 264, up: 265, page_up: 266, page_down: 267, home: 268, end: 269,
|
14
|
+
caps_lock: 280, scroll_lock: 281, num_lock: 282, print_screen: 283, pause: 284,
|
15
|
+
f1: 290, f2: 291, f3: 292, f4: 293, f5: 294, f6: 295, f7: 296, f8: 297,
|
16
|
+
f9: 298, f10: 299, f11: 300, f12: 301, left_shift: 340, left_control: 341,
|
17
|
+
left_alt: 342, left_super: 343, right_shift: 344, right_control: 345, right_alt: 346,
|
18
|
+
right_super: 347, kb_menu: 348, kp_0: 320, kp_1: 321, kp_2: 322, kp_3: 323,
|
19
|
+
kp_4: 324, kp_5: 325, kp_6: 326, kp_7: 327, kp_8: 328, kp_9: 329, kp_decimal: 330,
|
20
|
+
kp_divide: 331, kp_multiply: 332, kp_subtract: 333, kp_add: 334, kp_enter: 335,
|
21
|
+
kp_equal: 336, back: 4, menu: 5, volume_up: 24, volume_down: 25
|
22
|
+
}
|
23
|
+
|
24
|
+
class Keyboard
|
25
|
+
attr_accessor :shift, :control, :super, :alt
|
26
|
+
attr_reader :keys, :pressed, :released
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@shift = false
|
30
|
+
@control = false
|
31
|
+
@super = false
|
32
|
+
@alt = false
|
33
|
+
|
34
|
+
@keys = {}
|
35
|
+
@pressed = []
|
36
|
+
@released = []
|
37
|
+
|
38
|
+
# populate the key states
|
39
|
+
KEY_CODES.each do |symbol, code|
|
40
|
+
@keys[symbol] = { code: code, symbol: symbol, up: false, down: false, pressed: false, released: false }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def code
|
45
|
+
pressed[0]&.[](:code)
|
46
|
+
end
|
47
|
+
|
48
|
+
def char
|
49
|
+
pressed[0]&.[](:char)
|
50
|
+
end
|
51
|
+
|
52
|
+
def ctrl
|
53
|
+
@control
|
54
|
+
end
|
55
|
+
|
56
|
+
def reset
|
57
|
+
@pressed.clear
|
58
|
+
@released.clear
|
59
|
+
|
60
|
+
@shift = false
|
61
|
+
@control = false
|
62
|
+
@super = false
|
63
|
+
@alt = false
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def key_is_letter?(symbol)
|
68
|
+
symbol == :a || symbol == :b || symbol == :c || symbol == :d ||
|
69
|
+
symbol == :e || symbol == :f || symbol == :g || symbol == :h ||
|
70
|
+
symbol == :i || symbol == :j || symbol == :k || symbol == :l ||
|
71
|
+
symbol == :m || symbol == :n || symbol == :o || symbol == :p ||
|
72
|
+
symbol == :q || symbol == :r || symbol == :s || symbol == :t ||
|
73
|
+
symbol == :u || symbol == :v || symbol == :w || symbol == :x ||
|
74
|
+
symbol == :y || symbol == :z
|
75
|
+
end
|
76
|
+
|
77
|
+
def char_code_from_key(key, shift)
|
78
|
+
code = keys[key][:code]
|
79
|
+
|
80
|
+
if !shift && key_is_letter?(key)
|
81
|
+
code += 32
|
82
|
+
elsif shift && key == :apostrophe
|
83
|
+
code = 34
|
84
|
+
elsif shift && key == :comma
|
85
|
+
code = 60
|
86
|
+
elsif shift && key == :minus
|
87
|
+
code = 95
|
88
|
+
elsif shift && key == :period
|
89
|
+
code = 62
|
90
|
+
elsif shift && key == :slash
|
91
|
+
code = 63
|
92
|
+
elsif shift && key == :zero
|
93
|
+
code = 41
|
94
|
+
elsif shift && key == :one
|
95
|
+
code = 33
|
96
|
+
elsif shift && key == :two
|
97
|
+
code = 64
|
98
|
+
elsif shift && key == :three
|
99
|
+
code = 35
|
100
|
+
elsif shift && key == :four
|
101
|
+
code = 36
|
102
|
+
elsif shift && key == :five
|
103
|
+
code = 37
|
104
|
+
elsif shift && key == :six
|
105
|
+
code = 94
|
106
|
+
elsif shift && key == :seven
|
107
|
+
code = 38
|
108
|
+
elsif shift && key == :eight
|
109
|
+
code = 42
|
110
|
+
elsif shift && key == :nine
|
111
|
+
code = 40
|
112
|
+
elsif shift && key == :semicolon
|
113
|
+
code = 58
|
114
|
+
elsif shift && key == :equal
|
115
|
+
code = 43
|
116
|
+
elsif shift && key == :left_bracket
|
117
|
+
code = 123
|
118
|
+
elsif shift && key == :backslash
|
119
|
+
code = 124
|
120
|
+
elsif shift && key == :right_bracket
|
121
|
+
code = 125
|
122
|
+
elsif shift && key == :grave
|
123
|
+
code = 126
|
124
|
+
end
|
125
|
+
|
126
|
+
return code if code <= 256
|
127
|
+
end
|
128
|
+
|
129
|
+
def set(key, down)
|
130
|
+
if down
|
131
|
+
case key
|
132
|
+
when :left_shift, :right_shift
|
133
|
+
@shift = true
|
134
|
+
when :left_control, :right_control
|
135
|
+
@control = true
|
136
|
+
when :left_super, :right_super
|
137
|
+
@super = true
|
138
|
+
when :left_alt, :right_alt
|
139
|
+
@alt = true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
if down && keys[key][:up]
|
144
|
+
keys[key][:pressed] = true
|
145
|
+
keys[key][:released]= false
|
146
|
+
|
147
|
+
nkey = keys[key].dup
|
148
|
+
nkey.merge!({ char: char_code_from_key(key, shift)&.chr })
|
149
|
+
|
150
|
+
pressed << nkey
|
151
|
+
elsif !down && keys[key][:down]
|
152
|
+
keys[key][:pressed] = false
|
153
|
+
keys[key][:released] = true
|
154
|
+
|
155
|
+
nkey = keys[key].dup
|
156
|
+
nkey.merge!({ char: char_code_from_key(key, shift)&.chr })
|
157
|
+
|
158
|
+
released << nkey
|
159
|
+
else
|
160
|
+
keys[key][:pressed] = false
|
161
|
+
keys[key][:released] = false
|
162
|
+
end
|
163
|
+
|
164
|
+
keys[key][:down] = down
|
165
|
+
keys[key][:up] = !down
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/ui/src/hokusai/types.rb
CHANGED
@@ -4,34 +4,9 @@ require_relative "./types/primitives"
|
|
4
4
|
require_relative "./types/display"
|
5
5
|
require_relative "./types/touch"
|
6
6
|
require_relative "./types/mouse"
|
7
|
+
require_relative "./types/keyboard"
|
7
8
|
|
8
9
|
module Hokusai
|
9
|
-
class Keyboard
|
10
|
-
attr_reader :raw
|
11
|
-
|
12
|
-
[
|
13
|
-
:shift, :super, :ctrl,
|
14
|
-
:alt, :pressed, :pressed_len, :released,
|
15
|
-
:released_len
|
16
|
-
].each do |name|
|
17
|
-
define_method(name) do
|
18
|
-
raw[name]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def keyboard_key
|
23
|
-
pressed.read_array_of_type(TYPE_UINT8, :read_uint8, pressed_len).first
|
24
|
-
end
|
25
|
-
|
26
|
-
def key
|
27
|
-
keyboard_key[:key][:key]
|
28
|
-
end
|
29
|
-
|
30
|
-
def initialize(raw)
|
31
|
-
@raw = raw
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
10
|
class Input
|
36
11
|
attr_accessor :keyboard_override
|
37
12
|
attr_reader :raw, :touch
|
@@ -40,8 +15,7 @@ module Hokusai
|
|
40
15
|
[self.class, mouse.pos.x, mouse.pos.y, mouse.scroll, mouse.left.clicked, mouse.left.down, mouse.left.up].hash
|
41
16
|
end
|
42
17
|
|
43
|
-
def initialize
|
44
|
-
@raw = raw
|
18
|
+
def initialize
|
45
19
|
@touch = nil
|
46
20
|
@keyboard_override = false
|
47
21
|
end
|
@@ -53,7 +27,7 @@ module Hokusai
|
|
53
27
|
end
|
54
28
|
|
55
29
|
def keyboard
|
56
|
-
Keyboard.new
|
30
|
+
@keyboard ||= Keyboard.new
|
57
31
|
end
|
58
32
|
|
59
33
|
def mouse
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hokusai-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.6.pre.
|
4
|
+
version: 0.2.6.pre.pinephone6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- skinnyjames
|
@@ -293,6 +293,7 @@ files:
|
|
293
293
|
- ui/src/hokusai/style.rb
|
294
294
|
- ui/src/hokusai/types.rb
|
295
295
|
- ui/src/hokusai/types/display.rb
|
296
|
+
- ui/src/hokusai/types/keyboard.rb
|
296
297
|
- ui/src/hokusai/types/mouse.rb
|
297
298
|
- ui/src/hokusai/types/primitives.rb
|
298
299
|
- ui/src/hokusai/types/touch.rb
|