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.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/ast/src/core/input.c +85 -0
- data/ast/src/core/input.h +31 -0
- data/hokusai.gemspec +1 -2
- data/ui/examples/drag.rb +154 -0
- data/ui/examples/embedded.rb +59 -0
- data/ui/examples/game.rb +143 -0
- data/ui/examples/overlay.rb +233 -0
- data/ui/examples/provider.rb +56 -0
- data/ui/examples/shader/test.rb +145 -0
- data/ui/examples/shader.rb +100 -0
- data/ui/examples/wiki.rb +82 -0
- data/ui/lib/lib_hokusai.rb +22 -1
- 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/automation/server.rb +2 -3
- data/ui/src/hokusai/backends/embedded/config.rb +47 -0
- data/ui/src/hokusai/backends/embedded/font.rb +112 -0
- data/ui/src/hokusai/backends/embedded/keys.rb +124 -0
- data/ui/src/hokusai/backends/embedded.rb +564 -0
- data/ui/src/hokusai/backends/raylib.rb +80 -5
- data/ui/src/hokusai/blocks/color_picker.rb +1080 -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/texture.rb +23 -0
- data/ui/src/hokusai/commands/rect.rb +10 -1
- 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/embedded.rb +66 -0
- data/ui/src/hokusai/painter.rb +22 -0
- data/ui/src/hokusai/types.rb +29 -0
- data/ui/src/hokusai.rb +4 -9
- metadata +24 -22
- data/ui/src/hokusai/assets/chevron-down.svg +0 -1
@@ -0,0 +1,47 @@
|
|
1
|
+
module Hokusai::Backends
|
2
|
+
class EmbeddedBackend::ConfigError < StandardError; end
|
3
|
+
|
4
|
+
class EmbeddedBackend::Config
|
5
|
+
attr_accessor :width, :height, :fps,
|
6
|
+
:title, :config_flags, :window_state_flags,
|
7
|
+
:automation_driver, :background, :after_load_cb,
|
8
|
+
:host, :port, :automated, :on_reload, :event_waiting
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@width = 500
|
12
|
+
@height = 500
|
13
|
+
@fps = 60
|
14
|
+
@title = "(Unknown Title)"
|
15
|
+
@config_flags = Raylib::FLAG_WINDOW_RESIZABLE | Raylib::FLAG_VSYNC_HINT
|
16
|
+
@window_state_flags = Raylib::FLAG_WINDOW_RESIZABLE
|
17
|
+
@automation_driver = nil
|
18
|
+
@background = Raylib::WHITE
|
19
|
+
@after_load_cb = nil
|
20
|
+
@host = "127.0.0.1"
|
21
|
+
@port = 4333
|
22
|
+
@automated = false
|
23
|
+
@on_reload = ->(_){}
|
24
|
+
@event_waiting = false
|
25
|
+
end
|
26
|
+
|
27
|
+
def start_automation_driver
|
28
|
+
raise ConfigError.new("Need a Hokusai::Driver in order to automate") if automation_driver.nil?
|
29
|
+
|
30
|
+
automation_driver.serve(host, port)
|
31
|
+
end
|
32
|
+
|
33
|
+
def automate(host, port)
|
34
|
+
self.host = host
|
35
|
+
self.port = port
|
36
|
+
self.automated = true
|
37
|
+
end
|
38
|
+
|
39
|
+
def after_load(&block)
|
40
|
+
self.after_load_cb = block
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_reload(&block)
|
44
|
+
@on_reload = block
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Hokusai
|
2
|
+
module Backends
|
3
|
+
class EmbeddedBackend
|
4
|
+
class DataForCb < FFI::Struct
|
5
|
+
layout :size, :int,
|
6
|
+
:spacing, :int,
|
7
|
+
:raw, :pointer
|
8
|
+
|
9
|
+
def self.create(size, spacing, raw)
|
10
|
+
obj = new.tap do |instance|
|
11
|
+
instance[:size] = size
|
12
|
+
instance[:spacing] = spacing
|
13
|
+
instance[:raw] = raw
|
14
|
+
end
|
15
|
+
|
16
|
+
yield obj.to_ptr
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
OnWidthCb = Proc.new do |char, ffi_pointer|
|
21
|
+
data = DataForCb.new ffi_pointer
|
22
|
+
|
23
|
+
Raylib.MeasureTextEx(data[:raw], "#{char.chr}", data[:size], data[:spacing]).x + 1.565#@ data[:spacing]
|
24
|
+
end
|
25
|
+
|
26
|
+
class Font < Hokusai::Font
|
27
|
+
attr_reader :raw
|
28
|
+
|
29
|
+
DEFAULT = "–—‘’“”…\r\n\t0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%%^&*(),.?/\"\\[]-_=+|~`{}<>;:'\0"
|
30
|
+
|
31
|
+
def self.default
|
32
|
+
font = Raylib.GetFontDefault
|
33
|
+
Raylib.SetTextureFilter(font.texture, Raylib::TEXTURE_FILTER_BILINEAR)
|
34
|
+
# Raylib.GenTextureMipmaps(font.texture)
|
35
|
+
|
36
|
+
new(font)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.from(file)
|
40
|
+
font = Raylib.LoadFont(file)
|
41
|
+
Raylib.SetTextureFilter(font.texture, Raylib::TEXTURE_FILTER_BILINEAR)
|
42
|
+
# Raylib.GenTextureMipmaps(font.texture)
|
43
|
+
|
44
|
+
new(font)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.from_ext(file, font_size, codepoint_string = DEFAULT)
|
48
|
+
ptr = FFI::MemoryPointer.new :int
|
49
|
+
codepoints = Raylib.LoadCodepoints(codepoint_string, ptr)
|
50
|
+
count = ptr.read_int
|
51
|
+
|
52
|
+
raylib_font = Raylib.LoadFontEx(file, font_size, codepoints, count)
|
53
|
+
# Raylib.GenTextureMipmaps(raylib_font.texture)
|
54
|
+
Raylib.SetTextureFilter(raylib_font.texture, Raylib::TEXTURE_FILTER_BILINEAR)
|
55
|
+
|
56
|
+
font = new(raylib_font)
|
57
|
+
Raylib.UnloadCodepoints(codepoints)
|
58
|
+
|
59
|
+
font
|
60
|
+
end
|
61
|
+
|
62
|
+
def initialize(raw, spacing = 1.0)
|
63
|
+
@raw = raw
|
64
|
+
@spacing = spacing
|
65
|
+
end
|
66
|
+
|
67
|
+
# returns the spacing for this font
|
68
|
+
# based on the text size
|
69
|
+
def spacing
|
70
|
+
ssize = raw.baseSize || 1
|
71
|
+
ssize = 10 if ssize < 10
|
72
|
+
|
73
|
+
(ssize / (raw.baseSize.zero? ? 1 : raw.baseSize)).to_f
|
74
|
+
end
|
75
|
+
|
76
|
+
def measure(string, size)
|
77
|
+
vec = Raylib.MeasureTextEx(raw, string, size, spacing)
|
78
|
+
|
79
|
+
[vec.x, vec.y]
|
80
|
+
end
|
81
|
+
|
82
|
+
def height
|
83
|
+
raw.baseSize
|
84
|
+
end
|
85
|
+
|
86
|
+
def clamp_markdown(text, size, width, initial_offset = 0.0)
|
87
|
+
clamping_pointer = FFI::MemoryPointer.new :pointer
|
88
|
+
RaylibBackend::DataForCb.create(size, spacing, raw) do |ptr|
|
89
|
+
ret = LibHokusai.hoku_text_md_clamp(clamping_pointer, text, width, initial_offset, ptr, RaylibBackend::OnWidthCb)
|
90
|
+
raise Hokusai::Error.new("Clamping failed") unless ret.zero?
|
91
|
+
end
|
92
|
+
|
93
|
+
clamping = LibHokusai::HokuClamping.new(FFI::AutoPointer.new(clamping_pointer.get_pointer(0), LibHokusai.method(:hoku_text_clamping_free)))
|
94
|
+
|
95
|
+
Hokusai::Clamping.new(clamping, markdown: true)
|
96
|
+
end
|
97
|
+
|
98
|
+
def clamp(text, size, width, initial_offset = 0.0)
|
99
|
+
clamping_pointer = FFI::MemoryPointer.new :pointer
|
100
|
+
EmbeddedBackend::DataForCb.create(size, spacing, raw) do |ptr|
|
101
|
+
ret = LibHokusai.hoku_text_clamp(clamping_pointer, text, width, initial_offset, ptr, EmbeddedBackend::OnWidthCb)
|
102
|
+
raise Hokusai::Error.new("Clamping failed") unless ret.zero?
|
103
|
+
end
|
104
|
+
|
105
|
+
clamping = LibHokusai::HokuClamping.new(FFI::AutoPointer.new(clamping_pointer.get_pointer(0), LibHokusai.method(:hoku_text_clamping_free)))
|
106
|
+
|
107
|
+
Hokusai::Clamping.new(clamping)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Hokusai::Backends
|
2
|
+
class EmbeddedBackend
|
3
|
+
Keys = [
|
4
|
+
[:null, Raylib::KEY_NULL],
|
5
|
+
[:left_shift, Raylib::KEY_LEFT_SHIFT],
|
6
|
+
[:left_control, Raylib::KEY_LEFT_CONTROL],
|
7
|
+
[:left_alt, Raylib::KEY_LEFT_ALT],
|
8
|
+
[:left_super, Raylib::KEY_LEFT_SUPER],
|
9
|
+
[:right_shift, Raylib::KEY_RIGHT_SHIFT],
|
10
|
+
[:right_control, Raylib::KEY_RIGHT_CONTROL],
|
11
|
+
[:right_alt, Raylib::KEY_RIGHT_ALT],
|
12
|
+
[:right_super, Raylib::KEY_RIGHT_SUPER],
|
13
|
+
[:apostrophe, Raylib::KEY_APOSTROPHE],
|
14
|
+
[:comma, Raylib::KEY_COMMA],
|
15
|
+
[:minus, Raylib::KEY_MINUS],
|
16
|
+
[:period, Raylib::KEY_PERIOD],
|
17
|
+
[:slash, Raylib::KEY_SLASH],
|
18
|
+
[:zero, Raylib::KEY_ZERO],
|
19
|
+
[:one, Raylib::KEY_ONE],
|
20
|
+
[:two, Raylib::KEY_TWO],
|
21
|
+
[:three, Raylib::KEY_THREE],
|
22
|
+
[:four, Raylib::KEY_FOUR],
|
23
|
+
[:five, Raylib::KEY_FIVE],
|
24
|
+
[:six, Raylib::KEY_SIX],
|
25
|
+
[:seven, Raylib::KEY_SEVEN],
|
26
|
+
[:eight, Raylib::KEY_EIGHT],
|
27
|
+
[:nine, Raylib::KEY_NINE],
|
28
|
+
[:semicolon, Raylib::KEY_SEMICOLON],
|
29
|
+
[:equal, Raylib::KEY_EQUAL],
|
30
|
+
[:a, Raylib::KEY_A],
|
31
|
+
[:b, Raylib::KEY_B],
|
32
|
+
[:c, Raylib::KEY_C],
|
33
|
+
[:d, Raylib::KEY_D],
|
34
|
+
[:e, Raylib::KEY_E],
|
35
|
+
[:f, Raylib::KEY_F],
|
36
|
+
[:g, Raylib::KEY_G],
|
37
|
+
[:h, Raylib::KEY_H],
|
38
|
+
[:i, Raylib::KEY_I],
|
39
|
+
[:j, Raylib::KEY_J],
|
40
|
+
[:k, Raylib::KEY_K],
|
41
|
+
[:l, Raylib::KEY_L],
|
42
|
+
[:m, Raylib::KEY_M],
|
43
|
+
[:n, Raylib::KEY_N],
|
44
|
+
[:o, Raylib::KEY_O],
|
45
|
+
[:p, Raylib::KEY_P],
|
46
|
+
[:q, Raylib::KEY_Q],
|
47
|
+
[:r, Raylib::KEY_R],
|
48
|
+
[:s, Raylib::KEY_S],
|
49
|
+
[:t, Raylib::KEY_T],
|
50
|
+
[:u, Raylib::KEY_U],
|
51
|
+
[:v, Raylib::KEY_V],
|
52
|
+
[:w, Raylib::KEY_W],
|
53
|
+
[:x, Raylib::KEY_X],
|
54
|
+
[:y, Raylib::KEY_Y],
|
55
|
+
[:z, Raylib::KEY_Z],
|
56
|
+
[:left_bracket, Raylib::KEY_LEFT_BRACKET],
|
57
|
+
[:backslash, Raylib::KEY_BACKSLASH],
|
58
|
+
[:right_bracket, Raylib::KEY_RIGHT_BRACKET],
|
59
|
+
[:grave, Raylib::KEY_GRAVE],
|
60
|
+
[:space, Raylib::KEY_SPACE],
|
61
|
+
[:escape, Raylib::KEY_ESCAPE],
|
62
|
+
[:enter, Raylib::KEY_ENTER],
|
63
|
+
[:tab, Raylib::KEY_TAB],
|
64
|
+
[:backspace, Raylib::KEY_BACKSPACE],
|
65
|
+
[:insert, Raylib::KEY_INSERT],
|
66
|
+
[:delete, Raylib::KEY_DELETE],
|
67
|
+
[:right, Raylib::KEY_RIGHT],
|
68
|
+
[:left, Raylib::KEY_LEFT],
|
69
|
+
[:down, Raylib::KEY_DOWN],
|
70
|
+
[:up, Raylib::KEY_UP],
|
71
|
+
[:page_up, Raylib::KEY_PAGE_UP],
|
72
|
+
[:page_down, Raylib::KEY_PAGE_DOWN],
|
73
|
+
[:home, Raylib::KEY_HOME],
|
74
|
+
[:end, Raylib::KEY_END],
|
75
|
+
[:caps_lock, Raylib::KEY_CAPS_LOCK],
|
76
|
+
[:scroll_lock, Raylib::KEY_SCROLL_LOCK],
|
77
|
+
[:num_lock, Raylib::KEY_NUM_LOCK],
|
78
|
+
[:print_screen, Raylib::KEY_PRINT_SCREEN],
|
79
|
+
[:pause, Raylib::KEY_PAUSE],
|
80
|
+
[:f1, Raylib::KEY_F1],
|
81
|
+
[:f2, Raylib::KEY_F2],
|
82
|
+
[:f3, Raylib::KEY_F3],
|
83
|
+
[:f4, Raylib::KEY_F4],
|
84
|
+
[:f5, Raylib::KEY_F5],
|
85
|
+
[:f6, Raylib::KEY_F6],
|
86
|
+
[:f7, Raylib::KEY_F7],
|
87
|
+
[:f8, Raylib::KEY_F8],
|
88
|
+
[:f9, Raylib::KEY_F9],
|
89
|
+
[:f10, Raylib::KEY_F10],
|
90
|
+
[:f11, Raylib::KEY_F11],
|
91
|
+
[:f12, Raylib::KEY_F12],
|
92
|
+
[:left_shift, Raylib::KEY_LEFT_SHIFT],
|
93
|
+
[:left_control, Raylib::KEY_LEFT_CONTROL],
|
94
|
+
[:left_alt, Raylib::KEY_LEFT_ALT],
|
95
|
+
[:left_super, Raylib::KEY_LEFT_SUPER],
|
96
|
+
[:right_shift, Raylib::KEY_RIGHT_SHIFT],
|
97
|
+
[:right_control, Raylib::KEY_RIGHT_CONTROL],
|
98
|
+
[:right_alt, Raylib::KEY_RIGHT_ALT],
|
99
|
+
[:right_super, Raylib::KEY_RIGHT_SUPER],
|
100
|
+
[:kb_menu, Raylib::KEY_KB_MENU],
|
101
|
+
[:kp_0, Raylib::KEY_KP_0],
|
102
|
+
[:kp_1, Raylib::KEY_KP_1],
|
103
|
+
[:kp_2, Raylib::KEY_KP_2],
|
104
|
+
[:kp_3, Raylib::KEY_KP_3],
|
105
|
+
[:kp_4, Raylib::KEY_KP_4],
|
106
|
+
[:kp_5, Raylib::KEY_KP_5],
|
107
|
+
[:kp_6, Raylib::KEY_KP_6],
|
108
|
+
[:kp_7, Raylib::KEY_KP_7],
|
109
|
+
[:kp_8, Raylib::KEY_KP_8],
|
110
|
+
[:kp_9, Raylib::KEY_KP_9],
|
111
|
+
[:kp_decimal, Raylib::KEY_KP_DECIMAL],
|
112
|
+
[:kp_divide, Raylib::KEY_KP_DIVIDE],
|
113
|
+
[:kp_multiply, Raylib::KEY_KP_MULTIPLY],
|
114
|
+
[:kp_subtract, Raylib::KEY_KP_SUBTRACT],
|
115
|
+
[:kp_add, Raylib::KEY_KP_ADD],
|
116
|
+
[:kp_enter, Raylib::KEY_KP_ENTER],
|
117
|
+
[:kp_equal, Raylib::KEY_KP_EQUAL],
|
118
|
+
[:back, Raylib::KEY_BACK],
|
119
|
+
[:menu, Raylib::KEY_MENU],
|
120
|
+
[:volume_up, Raylib::KEY_VOLUME_UP],
|
121
|
+
[:volume_down, Raylib::KEY_VOLUME_DOWN]]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|