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

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff2e748026518a381a084842d38e6499cbc21ba6ae82ef8eecea9fcf1caac01d
4
- data.tar.gz: b6f6552079320c6345dc2332c1876e4ad4640ae91edd1b80b5886cbb7e5a2a81
3
+ metadata.gz: e6b346169398fdc8ace4e949627b34928b44230de71c120dc1b7ec2e3cb377c5
4
+ data.tar.gz: 444a5c3581cc74ca1537f2682cd0a1fd3859164f92a773af738a3fea434d579f
5
5
  SHA512:
6
- metadata.gz: b4d95dbfd485c9948af925f0d824383198a8676fa87714c1b8937b1c34c22bd0f384c86774a67e44e1e941fcfcad745e7576d287edc23f064022369d5187fad2
7
- data.tar.gz: 73f8f5e98862ff3c219a61f570298e634a3d4293d619b6c79b557a5f499da96992366eb0f5ecf1f7adc7998f98d83ae54a878ee3445c527d262045cd41305038
6
+ metadata.gz: a9e491ff21f1ed5532ae4b265c2084f3599a1c242f68cd14974d9ccd2f0b9cc8d39897ff38795183460641aea0b62984fcf3cdcaea1432bc076b0bf4844e12c7
7
+ data.tar.gz: 80a602eff3310633a24f4edc99b7191d2d367a1a826e0f591ac4bece88119088551566cf82779f138f757c5fcd8c651efae8be1188b0c77c2131725aa016de87
data/ast/src/core/input.c CHANGED
@@ -4,83 +4,133 @@
4
4
  #include "input.h"
5
5
  #include <stdio.h>
6
6
 
7
- int hoku_input_embedded_init(hoku_input_embedded** embedded)
7
+ #define NANO_TO_MILLISECONDS 1000000
8
+
9
+ int hoku_input_touch_init(hoku_input_touch** embedded, int max_touch_positions)
8
10
  {
9
- hoku_input_embedded* out = malloc(sizeof(hoku_input_embedded));
11
+ hoku_input_touch* out = malloc(sizeof(hoku_input_touch));
10
12
  if (!out) return -1;
11
13
 
12
- out->drag_pos = malloc(sizeof(hoku_vec2));
13
- if (out->drag_pos == NULL)
14
- {
15
- free(out);
16
- return -1;
17
- }
14
+ out->last_touch_positions = malloc(sizeof(hoku_dvec2*) * max_touch_positions);
15
+ if (out->last_touch_positions == NULL) return -1;
16
+
17
+ out->touch_positions = malloc(sizeof(hoku_dvec2*) * max_touch_positions);
18
+ if (out->touch_positions == NULL) return -1;
18
19
 
19
- out->pinch_pos = malloc(sizeof(hoku_vec2));
20
- if (out->pinch_pos == NULL)
20
+ for (int i=0; i < max_touch_positions; i++)
21
21
  {
22
- free(out->drag_pos);
23
- free(out);
24
- return -1;
22
+ out->last_touch_positions[i] = malloc(sizeof(hoku_dvec2));
23
+ if (out->last_touch_positions[i] == NULL) return -1;
24
+ out->last_touch_positions[i]->x = -1.0;
25
+ out->last_touch_positions[i]->y = -1.0;
26
+
27
+
28
+ out->touch_positions[i] = malloc(sizeof(hoku_dvec2));
29
+ if (out->touch_positions[i] == NULL) return -1;
30
+ out->touch_positions[i]->x = -1.0;
31
+ out->touch_positions[i]->y = -1.0;
25
32
  }
26
33
 
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;
34
+ out->touch_len = max_touch_positions;
35
+ out->touch_count = 0;
36
+ out->touching_now = false;
37
+ out->timer = 0;
39
38
 
40
39
  *embedded = out;
41
40
  return 0;
42
41
  }
43
42
 
44
- void hoku_input_embedded_set_hold(hoku_input* input, bool hold, int hold_duration)
43
+ long hoku_input_touch_duration(hoku_input* input)
45
44
  {
46
- input->embedded->hold = hold;
47
- input->embedded->hold_duration = hold_duration;
45
+ return input->touch->timer * NANO_TO_MILLISECONDS;
48
46
  }
49
47
 
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)
48
+ bool hoku_input_touch_tapped(hoku_input* input)
51
49
  {
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;
50
+ if (input->touch->touching_now == false && input->touch->last_touch_positions[0] != NULL) return true;
51
+
52
+ return false;
57
53
  }
58
54
 
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)
55
+ bool hoku_input_touch_swiped(hoku_input* input, float threshold)
60
56
  {
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;
57
+ if (input->touch->touching_now == false)
58
+ {
59
+ hoku_dvec2* last = input->touch->last_touch_positions[0];
60
+ hoku_dvec2* now = input->touch->touch_positions[0];
61
+
62
+ if (last->x == -1.0 || last->y == -1.0) return false;
63
+ if (last == NULL || now == NULL) return false;
64
+
65
+ return (abs((int)(now->x - last->x)) >= threshold || abs((int)(now->y - last->y)) >= threshold);
66
+ }
67
+
68
+ return false;
69
+ }
70
+
71
+ bool hoku_input_touch_pinched(hoku_input* input)
72
+ {
73
+ return false;
66
74
  }
67
75
 
68
- int hoku_input_attach_embedded(hoku_input* input)
76
+ bool hoku_input_touch_longtapped(hoku_input* input, int threshold)
69
77
  {
70
- hoku_input_embedded* embedded;
71
- if (hoku_input_embedded_init(&embedded) == -1) return -1;
72
- input->embedded = embedded;
78
+ if (input->touch->touching_now && input->touch->timer > 0l)
79
+ {
80
+ hoku_dvec2* last = input->touch->last_touch_positions[0];
81
+ hoku_dvec2* now = input->touch->touch_positions[0];
82
+
83
+ return (abs((int)(now->x - last->x)) < threshold && abs((int)(now->y - last->y)) < threshold);
84
+ }
85
+
86
+ return false;
87
+ }
88
+
89
+ void hoku_input_clear_touch(hoku_input* input, int index)
90
+ {
91
+ input->touch->touching_now = false;
92
+ input->touch->timer = 0l;
93
+ }
94
+
95
+ int hoku_input_record_touch(hoku_input* input, int index, float x, float y)
96
+ {
97
+ struct timespec start;
98
+ if (clock_gettime(CLOCK_MONOTONIC, &start) == -1) return -1;
99
+
100
+ if (!(input->touch->touching_now))
101
+ {
102
+ input->touch->last_touch_positions[index]->x = input->touch->touch_positions[index]->x;
103
+ input->touch->last_touch_positions[index]->y = input->touch->touch_positions[index]->y;
104
+
105
+ input->touch->timer = start.tv_nsec;
106
+ }
107
+ else
108
+ {
109
+ input->touch->timer = start.tv_nsec - input->touch->timer;
110
+ }
111
+
112
+ input->touch->touch_positions[index]->x = x;
113
+ input->touch->touch_positions[index]->y = y;
114
+ input->touch->touching_now = true;
73
115
 
74
116
  return 0;
75
117
  }
76
118
 
77
- void hoku_input_embedded_free(hoku_input_embedded* embedded)
119
+ int hoku_input_attach_touch(hoku_input* input, int max_touch_count)
78
120
  {
79
- free(embedded->drag_pos);
80
- free(embedded->pinch_pos);
81
- free(embedded);
121
+ hoku_input_touch* touch;
122
+ if (hoku_input_touch_init(&touch, max_touch_count) == -1) return -1;
123
+ input->touch = touch;
124
+
125
+ return 0;
82
126
  }
83
127
 
128
+ void hoku_input_touch_free(hoku_input_touch* embedded)
129
+ {
130
+ free(embedded->touch_positions);
131
+ free(embedded->last_touch_positions);
132
+ free(embedded);
133
+ }
84
134
 
85
135
  static int hoku_keycodes[HOKU_KEY_MAX] = {
86
136
  0,39,44,45,46,47,48,49,50,51,52,53,54,55,56,57,59,61,65,66,67,68,69,
@@ -352,9 +402,9 @@ void hoku_input_free(hoku_input* input)
352
402
  hoku_input_keyboard_free(input->keyboard);
353
403
  hoku_input_mouse_free(input->mouse);
354
404
 
355
- if (input->embedded)
405
+ if (input->touch)
356
406
  {
357
- hoku_input_embedded_free(input->embedded);
407
+ hoku_input_touch_free(input->touch);
358
408
  }
359
409
 
360
410
  free(input);
@@ -382,7 +432,7 @@ int hoku_input_init(hoku_input** input)
382
432
  return -1;
383
433
  }
384
434
  init->keyboard = keyboard;
385
- init->embedded = NULL;
435
+ init->touch = NULL;
386
436
 
387
437
  *input = init;
388
438
  return 0;
data/ast/src/core/input.h CHANGED
@@ -4,6 +4,7 @@
4
4
  #include "common.h"
5
5
  #include <stdbool.h>
6
6
  #include <stdlib.h>
7
+ #include <time.h>
7
8
 
8
9
  typedef struct HmlInputMouseButton
9
10
  {
@@ -99,31 +100,31 @@ typedef enum HmlPinchDirection {
99
100
  HOKU_PINCH_OUT
100
101
  } hoku_pinch_direction;
101
102
 
102
- typedef struct HmlInputEmbedded
103
+ typedef struct HmlInputTouch
103
104
  {
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;
105
+ int touch_len;
106
+ int touch_count;
107
+ bool touching_now;
108
+ long timer;
109
+ hoku_dvec2** last_touch_positions;
110
+ hoku_dvec2** touch_positions;
111
+ } hoku_input_touch;
115
112
 
116
113
  typedef struct HmlInput
117
114
  {
118
115
  hoku_input_keyboard* keyboard;
119
116
  hoku_input_mouse* mouse;
120
- hoku_input_embedded* embedded;
117
+ hoku_input_touch* touch;
121
118
  } hoku_input;
122
119
 
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);
120
+
121
+ long hoku_input_touch_duration(hoku_input* input);
122
+ bool hoku_input_touch_tapped(hoku_input* input);
123
+ bool hoku_input_touch_swiped(hoku_input* input, float threshold);
124
+ bool hoku_input_touch_longtapped(hoku_input* input, int threshold);
125
+ void hoku_input_clear_touch(hoku_input* input, int index);
126
+ int hoku_input_record_touch(hoku_input* input, int index, float x, float y);
127
+ int hoku_input_attach_touch(hoku_input* input, int max_touch_count);
127
128
 
128
129
  int hoku_input_keyboard_init(hoku_input_keyboard** keyboard);
129
130
  int hoku_input_mouse_init(hoku_input_mouse** mouse);
data/ast/test/hokusai.c CHANGED
@@ -1,6 +1,7 @@
1
1
  #include "greatest.h"
2
2
  #include "parser.c"
3
3
  #include "text.c"
4
+ #include "input.c"
4
5
 
5
6
  GREATEST_MAIN_DEFS();
6
7
 
@@ -9,6 +10,7 @@ int main(int argc, char** argv) {
9
10
 
10
11
  RUN_SUITE(hoku_parser_suite);
11
12
  RUN_SUITE(hoku_text_suite);
13
+ RUN_SUITE(hoku_input_suite);
12
14
 
13
15
  GREATEST_MAIN_END();
14
16
  }
data/ast/test/input.c ADDED
@@ -0,0 +1,44 @@
1
+ #include "../src/core/input.c"
2
+ #include<unistd.h>
3
+
4
+ TEST test_hoku_input_touch_basic()
5
+ {
6
+ hoku_input* input;
7
+ int ret = hoku_input_init(&input);
8
+ ASSERT_EQ_FMT(ret, 0, "%d");
9
+
10
+ ret = hoku_input_attach_touch(input, 2);
11
+ ASSERT_EQ_FMT(ret, 0, "%d");
12
+
13
+ hoku_input_record_touch(input, 0, 1.0, 2.0);
14
+ hoku_input_clear_touch(input, 0);
15
+
16
+ bool tapped = hoku_input_touch_tapped(input);
17
+ bool swiped = hoku_input_touch_swiped(input, 4);
18
+
19
+ ASSERT_EQ_FMT(1, tapped, "%d");
20
+ ASSERT_EQ_FMT(0, swiped, "%d");
21
+
22
+ hoku_input_record_touch(input, 0, 1.0, 2.0);
23
+ usleep(1000);
24
+ hoku_input_record_touch(input, 0, 3.0, 1.0);
25
+
26
+ bool longtapped = hoku_input_touch_longtapped(input, 4);
27
+
28
+ hoku_input_clear_touch(input, 0);
29
+ swiped = hoku_input_touch_swiped(input, 1.0);
30
+
31
+ ASSERT_EQ_FMT(1, longtapped, "%d");
32
+ ASSERT_EQ_FMT(1, swiped, "%d");
33
+ // ASSERT_EQ_FMT(pinched, 0, "%d");
34
+
35
+ hoku_input_free(input);
36
+
37
+ PASS();
38
+ }
39
+
40
+
41
+ SUITE(hoku_input_suite)
42
+ {
43
+ RUN_TEST(test_hoku_input_touch_basic);
44
+ }
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-pinephone'
3
+ s.version = '0.2.6-pinephone2'
4
4
  s.licenses = ['MIT']
5
5
  s.summary = "A Ruby library for writing GUI applications"
6
6
  s.authors = ["skinnyjames"]
@@ -36,7 +36,6 @@ class App < Hokusai::Block
36
36
 
37
37
  def clear_text(event)
38
38
  self.text = ""
39
- pp ["clear", text]
40
39
  end
41
40
 
42
41
  def handle_pinch(event)
@@ -245,20 +245,13 @@ module LibHokusai
245
245
  :collecting, :bool
246
246
  end
247
247
 
248
- enum :hml_drag_direction, [:up, :down, :left, :right]
249
- enum :hml_pinch_direction, [:in, :out]
250
-
251
- class HmlInputEmbedded < FFI::Struct
252
- layout :hold, :bool,
253
- :hold_duration, :int,
254
- :drag, :bool,
255
- :drag_direction, :hml_drag_direction,
256
- :drag_pos, HmlVec2.ptr,
257
- :drag_angle, :float,
258
- :pinch, :bool,
259
- :pinch_direction, :hml_pinch_direction,
260
- :pinch_pos, HmlVec2.ptr,
261
- :pinch_angle, :float
248
+ class HmlInputTouch < FFI::Struct
249
+ layout :touch_len, :int,
250
+ :touch_count, :int,
251
+ :touching_now, :bool,
252
+ :timer, :long,
253
+ :last_touch_positions, :pointer,
254
+ :touch_positions, :pointer
262
255
  end
263
256
 
264
257
  class HmlInputMouseButton < FFI::Struct
@@ -310,7 +303,7 @@ module LibHokusai
310
303
  class HmlInput < FFI::Struct
311
304
  layout :keyboard, HmlInputKeyboard.ptr,
312
305
  :mouse, HmlInputMouse.ptr,
313
- :embedded, HmlInputEmbedded.ptr
306
+ :touch, HmlInputTouch.ptr
314
307
  end
315
308
 
316
309
  def LibHokusai.const_missing( sym )
@@ -325,10 +318,15 @@ module LibHokusai
325
318
  attach_function :hoku_input_set_mouse_position, [HmlInput.by_ref, HmlVec2.by_ref], :void
326
319
  attach_function :hoku_input_mouse_set_scroll, [HmlInput.by_ref, :float], :void
327
320
  attach_function :hoku_input_mouse_set_button, [HmlInput.by_ref, HmlInputMouseButton.by_ref, :int], :void
328
- attach_function :hoku_input_embedded_set_hold, [HmlInput.by_ref, :bool, :int], :void
329
- attach_function :hoku_input_embedded_set_drag, [HmlInput.by_ref, :bool, :hml_drag_direction, :float, :float, :float], :void
330
- attach_function :hoku_input_embedded_set_pinch, [HmlInput.by_ref, :bool, :hml_pinch_direction, :float, :float, :float], :void
331
- attach_function :hoku_input_attach_embedded, [HmlInput.by_ref], :int
321
+ # touch functions
322
+ attach_function :hoku_input_attach_touch, [HmlInput.by_ref, :int], :int
323
+ attach_function :hoku_input_record_touch, [HmlInput.by_ref, :int, :float, :float], :int
324
+ attach_function :hoku_input_clear_touch, [HmlInput.by_ref, :int], :void
325
+
326
+ attach_function :hoku_input_touch_duration, [HmlInput.by_ref], :long
327
+ attach_function :hoku_input_touch_tapped, [HmlInput.by_ref], :bool
328
+ attach_function :hoku_input_touch_swiped, [HmlInput.by_ref], :bool
329
+ attach_function :hoku_input_touch_longtapped, [HmlInput.by_ref], :bool
332
330
 
333
331
  attach_function :hoku_input_is_clicked, [HmlInput.by_ref, HmlRect.by_ref], :bool
334
332
  attach_function :hoku_input_is_hovered, [HmlInput.by_ref, HmlRect.by_ref], :bool
@@ -5,7 +5,7 @@ module Hokusai::Backends
5
5
  attr_accessor :width, :height, :fps,
6
6
  :title, :config_flags, :window_state_flags,
7
7
  :automation_driver, :background, :after_load_cb,
8
- :host, :port, :automated, :on_reload, :event_waiting
8
+ :host, :port, :automated, :on_reload, :event_waiting, :max_touch_count
9
9
 
10
10
  def initialize
11
11
  @width = 500
@@ -22,6 +22,7 @@ module Hokusai::Backends
22
22
  @automated = false
23
23
  @on_reload = ->(_){}
24
24
  @event_waiting = false
25
+ @max_touch_count = 2
25
26
  end
26
27
 
27
28
  def start_automation_driver
@@ -18,7 +18,8 @@ module Hokusai::Backends
18
18
  end
19
19
  end
20
20
 
21
- attr_reader :config, :last_touch
21
+ attr_reader :config
22
+ attr_accessor :last_touch, :last_gesture, :touches, :stuff
22
23
 
23
24
  def self.icons
24
25
  @icons ||= {}
@@ -113,56 +114,28 @@ module Hokusai::Backends
113
114
  end
114
115
 
115
116
  def process_input(input)
116
- raylib_mouse_pos = Raylib.GetMousePosition
117
- raylib_mouse_delta = Raylib.GetMouseDelta
118
- LibHokusai.hoku_input_set_mouse_position(input.raw, hml_vec2(raylib_mouse_pos.x, raylib_mouse_pos.y))
117
+ self.touches = Raylib.GetTouchPointCount
118
+ if touches > 0
119
+ touches.times do |i|
120
+ vec = Raylib.GetTouchPosition
119
121
 
120
- input.raw[:mouse][:delta][:x] = raylib_mouse_delta.x
121
- input.raw[:mouse][:delta][:y] = raylib_mouse_delta.y
122
-
123
- if Raylib.GetTouchPointCount > 0
124
- self.last_touch = Raylib.GetTouchPosition(0)
125
-
126
- button = mouse_button(clicked: false, down: true, released: false, up: false)
127
- LibHokusai.hoku_input_mouse_set_button(input.raw, button, 0)
122
+ if LibHokusai.hoku_input_record_touch(input.raw, i, vec.x, vec.y) == -1
123
+ raise Hokusai::Error.new("Could not record touch")
124
+ end
125
+ end
128
126
  else
129
- if last_touch
130
- button = mouse_button(clicked: true, down: false, released: true, up: true)
131
- LibHokusai.hoku_input_mouse_set_button(input.raw, button, 0)
127
+ config.max_touch_count.times do |i|
128
+ LibHokusai.hoku_input_clear_touch(input.raw, i)
132
129
  end
133
130
  end
134
131
 
135
- LibHokusai.hoku_input_embedded_set_drag(input.raw, false, :up, 0.0, 0.0, 0.0)
136
- LibHokusai.hoku_input_embedded_set_hold(input.raw, false, 0)
137
- LibHokusai.hoku_input_embedded_set_pinch(input.raw, false, :in, 0.0, 0.0, 0.0)
138
-
139
- gesture = Raylib.GetGestureDetected
140
- case gesture
141
- when Raylib::GESTURE_NONE
142
- # nothing yet
143
- when Raylib::GESTURE_DOUBLETAP
144
- # nothing yet
145
- when Raylib::GESTURE_HOLD
146
- LibHokusai.hoku_input_embedded_set_hold(input.raw, true, Raylib.GetGestureHoldDuration)
147
- when Raylib::GESTURE_DRAG
148
- # nothing yet
149
- when Raylib::GESTURE_SWIPE_DOWN
150
- pos = Raylb.GetGestureDragVector
151
- LibHokusai.hoku_input_embedded_set_drag(input.raw, true, :down, pos.x, pos.y, Raylb.GetGestureDragAngle)
152
- when Raylib::GESTURE_SWIPE_UP
153
- pos = Raylb.GetGestureDragVector
154
- LibHokusai.hoku_input_embedded_set_drag(input.raw, true, :up, pos.x, pos.y, Raylb.GetGestureDragAngle)
155
- when Raylib::GESTURE_SWIPE_LEFT
156
- pos = Raylb.GetGestureDragVector
157
- LibHokusai.hoku_input_embedded_set_drag(input.raw, true, :left, pos.x, pos.y, Raylb.GetGestureDragAngle)
158
- when Raylib::GESTURE_SWIPE_RIGHT
159
- pos = Raylb.GetGestureDragVector
160
- LibHokusai.hoku_input_embedded_set_drag(input.raw, true, :right, pos.x, pos.y, Raylb.GetGestureDragAngle)
161
- when Raylib::GESTURE_PINCH_IN
162
- pos = Raylib.GetGesturePinchVector
163
- LibHokusai.hoku_input_embedded_set_pinch(input.raw, true, :in, pos.x, pos.y, Raylb.GetGesturePinchAngle)
164
- when Raylib::GESTURE_PINCH_OUT
165
- LibHokusai.hoku_input_embedded_set_pinch(input.raw, true, :out, pos.x, pos.y, Raylb.GetGesturePinchAngle)
132
+ # translate taps to clicks
133
+ if input.touch.tapped?
134
+ button = mouse_button(clicked: true, down: true, released: false, up: false)
135
+ LibHokusai.hoku_input_mouse_set_button(input.raw, button, 0)
136
+ else
137
+ button = mouse_button(clicked: false, down: false, released: true, up: true)
138
+ LibHokusai.hoku_input_mouse_set_button(input.raw, button, 0)
166
139
  end
167
140
  end
168
141
 
@@ -190,7 +163,7 @@ module Hokusai::Backends
190
163
  ptr = FFI::MemoryPointer.new :pointer
191
164
  LibHokusai.hoku_input_init(ptr)
192
165
  raw = LibHokusai::HmlInput.new(ptr.get_pointer(0))
193
- LibHokusai.hoku_input_attach_embedded(raw)
166
+ LibHokusai.hoku_input_attach_touch(raw, config.max_touch_count)
194
167
 
195
168
  input = Hokusai::Input.new(raw)
196
169
  ptr.free
@@ -268,6 +241,9 @@ module Hokusai::Backends
268
241
 
269
242
  painter.render(canvas, resize)
270
243
 
244
+ Raylib.DrawText("Touches: #{touches}", 10, 10, 14, color(Hokusai::Color.new(244,22,22)));
245
+ Raylib.DrawText("Stuff: #{stuff}", 10, 24, 14, color(Hokusai::Color.new(244,22,22))) if stuff
246
+
271
247
  Raylib.DrawFPS(10, 10) if ENV["PROFILE"] || ENV["FPS"]
272
248
  Raylib.EndDrawing
273
249
 
@@ -66,4 +66,4 @@ end
66
66
 
67
67
  require_relative './events/keyboard'
68
68
  require_relative './events/mouse'
69
- require_relative './events/embedded'
69
+ require_relative './events/touch'
@@ -1,17 +1,17 @@
1
1
  module Hokusai
2
- class EmbeddedEvent < Event
2
+ class TouchEvent < Event
3
3
  extend Forwardable
4
4
 
5
- def_delegators :@embedded, :hold, :hold_duration, :drag, :drag_direction,
6
- :drag_pos, :drag_angle, :pinch,
7
- :pinch_direction, :pinch_pos, :pinch_angle
5
+ def_delegators :@touch, :tapped?, :swiped?, :longtapped?, :touching?,
6
+ :duration, :direction, :angle, :position, :last_position,
7
+ :touch_len, :touch_count, :timer
8
8
 
9
9
  attr_reader :input
10
10
 
11
11
  def initialize(input, state)
12
12
  @input = input
13
13
  @state = state
14
- @embedded = input.embedded
14
+ @touch = input.touch
15
15
  end
16
16
 
17
17
  def hovered(canvas)
@@ -28,37 +28,37 @@ module Hokusai
28
28
  end
29
29
  end
30
30
 
31
- class TapHoldEvent < EmbeddedEvent
31
+ class TapHoldEvent < TouchEvent
32
32
  name "taphold"
33
33
 
34
34
  def capture(block, canvas)
35
- if hold && hovered(canvas)
35
+ if longtapped? && hovered(canvas)
36
36
  block.node.meta.focus
37
37
 
38
38
  if matches(block)
39
39
  captures << block
40
40
  end
41
- elsif hold
41
+ elsif touching?
42
42
  block.node.meta.blur
43
43
  end
44
44
  end
45
45
  end
46
46
 
47
- class PinchEvent < EmbeddedEvent
47
+ class PinchEvent < TouchEvent
48
48
  name "pinch"
49
49
 
50
50
  def capture(block, canvas)
51
- if pinch && matches(block)
51
+ if false && matches(block)
52
52
  captures << block
53
53
  end
54
54
  end
55
55
  end
56
56
 
57
- class SwipeEvent < EmbeddedEvent
57
+ class SwipeEvent < TouchEvent
58
58
  name "swipe"
59
59
 
60
60
  def capture(block, canvas)
61
- if drag && matches(block)
61
+ if swiped? && matches(block)
62
62
  captures << block
63
63
  end
64
64
  end
@@ -46,10 +46,10 @@ module Hokusai
46
46
  keypress: KeyPressEvent.new(input, state)
47
47
  }
48
48
 
49
- add_embedded_events(events, input, state) unless input.embedded.nil?
49
+ add_touch_events(events, input, state) unless input.touch.nil?
50
50
  end
51
51
 
52
- def add_embedded_events(events, input, state)
52
+ def add_touch_events(events, input, state)
53
53
  events.merge!({
54
54
  taphold: TapHoldEvent.new(input, state),
55
55
  pinch: PinchEvent.new(input, state),
@@ -181,7 +181,7 @@ module Hokusai
181
181
  events[:mousedown].bubble
182
182
  events[:mouseup].bubble
183
183
 
184
- unless input.embedded.nil?
184
+ unless input.touch.nil?
185
185
  events[:taphold].bubble
186
186
  events[:pinch].bubble
187
187
  events[:swipe].bubble
@@ -282,7 +282,7 @@ module Hokusai
282
282
  events[:keypress].capture(block, canvas)
283
283
  end
284
284
 
285
- unless input.embedded.nil?
285
+ unless input.touch.nil?
286
286
  events[:taphold].capture(block, canvas)
287
287
  events[:pinch].capture(block, canvas)
288
288
  events[:swipe].capture(block, canvas)
@@ -240,23 +240,83 @@ module Hokusai
240
240
  end
241
241
  end
242
242
 
243
- class Embedded
243
+ class Touch
244
244
  attr_reader :raw
245
-
245
+
246
246
  [
247
- :hold, :hold_duration, :drag, :drag_direction,
248
- :drag_pos, :drag_angle, :pinch,
249
- :pinch_direction, :pinch_pos, :pinch_angle
247
+ :touch_len, :touch_count, :touching_now, :timer,
250
248
  ].each do |key|
251
249
  define_method(key) do
252
- raw[key]
250
+ raw[:touch][key]
253
251
  end
252
+ end
253
+
254
+ def swiped?
255
+ LibHokusai.hoku_input_touch_swiped(raw)
256
+ end
257
+
258
+ def longtapped?
259
+ LibHokusai.hoku_input_touch_longtapped(raw)
260
+ end
261
+
262
+ # return [Intger] duration in milliseconds
263
+ def duration
264
+ LibHokusai.hoku_input_touch_duration(raw)
265
+ end
266
+
267
+ def touching?
268
+ touching_now
269
+ end
270
+
271
+ def tapped?
272
+ LibHokusai.hoku_input_touch_tapped(raw)
273
+ end
274
+
275
+ def position(index=0)
276
+ touches[index]
277
+ end
254
278
 
255
- define_method("#{key}=") do |val|
256
- raw[key] = val
279
+ def last_position(index=0)
280
+ last_touches[index]
281
+ end
282
+
283
+ def angle(index = 0)
284
+ return nil unless swiped?
285
+
286
+ pos = position(index)
287
+ lpos = last_position(index)
288
+
289
+ x = position.x - last_position.x
290
+ y = position.y - last_position.y
291
+
292
+ (Math.atan2(x, y) * (180 / Math::PI)).round(0).to_i
293
+ end
294
+
295
+ def direction(index=0)
296
+ return nil unless swiped?
297
+
298
+ pos = position(index)
299
+ lpos = last_position(index)
300
+
301
+ x = position.x - last_position.x
302
+ y = position.y - last_position.y
303
+
304
+ if x.abs > y.abs
305
+ # swiping left/right
306
+ position.x > last_position.x ? :right : :left
307
+ else
308
+ # swiping up/down
309
+ position.y > last_position.y ? :up : :down
257
310
  end
258
311
  end
259
312
 
313
+ def last_touches
314
+ @raw[:last_touch_positions].read_array_of_type(LibHokusai::HmlDoubleVec2, :read_pointer, touch_len)
315
+ end
316
+
317
+ def touches
318
+ @raw[:touch_positions].read_array_of_type(LibHokusai::HmlDoubleVec2, :read_pointer, touch_len)
319
+ end
260
320
 
261
321
  def initialize(raw)
262
322
  @raw = raw
@@ -274,10 +334,10 @@ module Hokusai
274
334
  @raw = raw
275
335
  end
276
336
 
277
- def embedded
278
- return nil if @raw[:embedded].null?
337
+ def touch
338
+ return nil if @raw[:touch].null?
279
339
 
280
- Embedded.new(@raw[:embedded])
340
+ Touch.new(@raw)
281
341
  end
282
342
 
283
343
  def keyboard
data/xmake.lua CHANGED
@@ -159,7 +159,7 @@ target("test-ast")
159
159
  )
160
160
  -- add_cflags("-Wall -Werror")
161
161
  after_build(function(target)
162
- os.exec("./%s -t markdown", target:targetfile())
162
+ os.exec("./%s -t input", target:targetfile())
163
163
  -- os.exec("leaks -atExit -- %s", target:targetfile())
164
164
  end)
165
165
  target_end()
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.pinephone
4
+ version: 0.2.6.pre.pinephone2
5
5
  platform: ruby
6
6
  authors:
7
7
  - skinnyjames
@@ -114,6 +114,7 @@ files:
114
114
  - ast/test/fixtures/test.ui
115
115
  - ast/test/greatest.h
116
116
  - ast/test/hokusai.c
117
+ - ast/test/input.c
117
118
  - ast/test/parser.c
118
119
  - ast/test/text.c
119
120
  - docs.sh
@@ -276,9 +277,9 @@ files:
276
277
  - ui/src/hokusai/diff.rb
277
278
  - ui/src/hokusai/error.rb
278
279
  - ui/src/hokusai/event.rb
279
- - ui/src/hokusai/events/embedded.rb
280
280
  - ui/src/hokusai/events/keyboard.rb
281
281
  - ui/src/hokusai/events/mouse.rb
282
+ - ui/src/hokusai/events/touch.rb
282
283
  - ui/src/hokusai/font.rb
283
284
  - ui/src/hokusai/meta.rb
284
285
  - ui/src/hokusai/mounting/loop_entry.rb