hokusai-zero 0.2.6.pre.pinephone4 → 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 +64 -42
- 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 +11 -18
- data/ui/src/hokusai/events/mouse.rb +10 -8
- data/ui/src/hokusai/events/touch.rb +2 -0
- data/ui/src/hokusai/painter.rb +4 -7
- 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 +11 -434
- data/ui/src/hokusai/util/wrap_stream.rb +0 -4
- metadata +6 -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"
|
@@ -116,11 +144,12 @@ module Hokusai::Backends
|
|
116
144
|
if !config.touch
|
117
145
|
raylib_mouse_pos = Raylib.GetMousePosition
|
118
146
|
raylib_mouse_delta = Raylib.GetMouseDelta
|
119
|
-
LibHokusai.hoku_input_mouse_set_scroll(input.raw, Raylib.GetMouseWheelMove)
|
120
|
-
LibHokusai.hoku_input_set_mouse_position(input.raw, hml_vec2(raylib_mouse_pos.x, raylib_mouse_pos.y))
|
121
147
|
|
122
|
-
input.
|
123
|
-
input.
|
148
|
+
input.mouse.pos.x = raylib_mouse_pos.x
|
149
|
+
input.mouse.pos.y = raylib_mouse_pos.y
|
150
|
+
input.mouse.delta.x = raylib_mouse_delta.x
|
151
|
+
input.mouse.delta.y = raylib_mouse_delta.y
|
152
|
+
input.mouse.scroll = Raylib.GetMouseWheelMove
|
124
153
|
end
|
125
154
|
|
126
155
|
if config.touch
|
@@ -134,14 +163,13 @@ module Hokusai::Backends
|
|
134
163
|
input.touch.clear
|
135
164
|
end
|
136
165
|
else
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
button =
|
144
|
-
LibHokusai.hoku_input_mouse_set_button(input.raw, button, button_id)
|
166
|
+
{left: 0, middle: 1, right: 2}.each do |key, button_id|
|
167
|
+
|
168
|
+
button = input.mouse.public_send(key)
|
169
|
+
button.clicked = Raylib.IsMouseButtonPressed(button_id)
|
170
|
+
button.down = Raylib.IsMouseButtonDown(button_id)
|
171
|
+
button.released = Raylib.IsMouseButtonReleased(button_id)
|
172
|
+
button.up = Raylib.IsMouseButtonUp(button_id)
|
145
173
|
end
|
146
174
|
end
|
147
175
|
|
@@ -149,27 +177,30 @@ module Hokusai::Backends
|
|
149
177
|
if input.touch.touching?
|
150
178
|
token = input.touch.token
|
151
179
|
|
152
|
-
|
180
|
+
input.mouse.pos.x = token[:x]
|
181
|
+
input.mouse.pos.y = token[:y]
|
153
182
|
end
|
154
183
|
|
155
184
|
# translate taps to clicks
|
156
185
|
if input.touch.tapped?
|
157
|
-
|
158
|
-
|
186
|
+
input.mouse.left.clicked = true
|
187
|
+
input.mouse.left.down = true
|
188
|
+
input.mouse.left.released = false
|
189
|
+
input.mouse.left.up = false
|
159
190
|
else
|
160
|
-
|
161
|
-
|
191
|
+
input.mouse.left.clicked = true
|
192
|
+
input.mouse.left.down = true
|
193
|
+
input.mouse.left.released = false
|
194
|
+
input.mouse.left.up = false
|
162
195
|
end
|
163
196
|
end
|
164
197
|
|
165
198
|
if !input.keyboard_override
|
166
|
-
|
199
|
+
input.keyboard.reset
|
167
200
|
|
168
201
|
Keys.each do |(hoku_key, raylib_key)|
|
169
|
-
|
202
|
+
input.keyboard.set(hoku_key, Raylib.IsKeyDown(raylib_key))
|
170
203
|
end
|
171
|
-
|
172
|
-
LibHokusai.hoku_input_keyboard_stop(input.raw)
|
173
204
|
end
|
174
205
|
end
|
175
206
|
|
@@ -193,11 +224,7 @@ module Hokusai::Backends
|
|
193
224
|
|
194
225
|
register_command_handlers
|
195
226
|
|
196
|
-
|
197
|
-
LibHokusai.hoku_input_init(ptr)
|
198
|
-
raw = LibHokusai::HmlInput.new(ptr.get_pointer(0))
|
199
|
-
input = Hokusai::Input.new(raw)
|
200
|
-
ptr.free
|
227
|
+
input = Hokusai::Input.new
|
201
228
|
input.support_touch! if config.touch
|
202
229
|
|
203
230
|
Raylib.SetConfigFlags(config.config_flags)
|
@@ -276,8 +303,6 @@ module Hokusai::Backends
|
|
276
303
|
Raylib.DrawFPS(10, 10) if ENV["PROFILE"] || ENV["FPS"]
|
277
304
|
Raylib.EndDrawing
|
278
305
|
|
279
|
-
GC.start
|
280
|
-
|
281
306
|
break if self.class.stopped?
|
282
307
|
end
|
283
308
|
|
@@ -293,8 +318,6 @@ module Hokusai::Backends
|
|
293
318
|
Raylib.UnloadShader(shader)
|
294
319
|
end
|
295
320
|
|
296
|
-
LibHokusai.hoku_input_free(input.raw)
|
297
|
-
|
298
321
|
if ENV["PROFILE"]
|
299
322
|
report = MemoryProfiler.stop
|
300
323
|
report.pretty_print(scale_bytes: true)
|
@@ -383,14 +406,6 @@ module Hokusai::Backends
|
|
383
406
|
Raylib.MinimizeWindow
|
384
407
|
end
|
385
408
|
|
386
|
-
# Hokusai.on_set_shader_value do |location, value, type|
|
387
|
-
# Raylib.SetShaderValue(@shader, location, value, type)
|
388
|
-
# end
|
389
|
-
|
390
|
-
# Hokusai.on_shader_location do |name|
|
391
|
-
# Raylib.GetShaderLocation(@shader, name)
|
392
|
-
# end
|
393
|
-
|
394
409
|
Hokusai.on_renderable do |canvas|
|
395
410
|
inside_scissor(canvas.x, canvas.y, canvas.height)
|
396
411
|
end
|
@@ -492,9 +507,9 @@ module Hokusai::Backends
|
|
492
507
|
next unless inside_scissor(command.x, command.y, command.size)
|
493
508
|
|
494
509
|
active_name = Hokusai.fonts.active_font_name
|
495
|
-
|
510
|
+
font_name = command.font.nil? ? active_name : command.font
|
496
511
|
|
497
|
-
Hokusai.fonts.activate
|
512
|
+
Hokusai.fonts.activate font_name
|
498
513
|
font = Hokusai.fonts.active
|
499
514
|
|
500
515
|
c = color(command.color)
|
@@ -502,9 +517,16 @@ module Hokusai::Backends
|
|
502
517
|
y = command.y + command.padding.t
|
503
518
|
|
504
519
|
if fnt = font
|
505
|
-
|
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
|
+
|
506
525
|
Raylib.DrawTextEx(fnt.raw, command.content.to_s, vec2(x, y), command.size, fnt.spacing, c)
|
507
|
-
|
526
|
+
|
527
|
+
if fnt.sdf
|
528
|
+
Raylib.EndShaderMode
|
529
|
+
end
|
508
530
|
else
|
509
531
|
Raylib.DrawText(command.content, x, y, command.size, c)
|
510
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
|