1+ #pragma once
2+
3+ #include " stdint.h"
4+
5+ #include < functional>
6+
7+ namespace zest {
8+
9+ struct Screen {
10+ /* * Vertical height taken up by the user program in pixels. */
11+ static constexpr int16_t HEADER_HEIGHT = 32 ;
12+ /* * The width of the screen in pixels. */
13+ static constexpr int16_t WIDTH = 480 ;
14+ /* * The height of the screen in pixels, excludes the header. */
15+ static constexpr int16_t HEIGHT = 240 ;
16+ /* * The framerate of the Brain is 60fps. */
17+ static constexpr int16_t FRAMERATE = 60 ;
18+
19+ /* * A touch event on the screen. */
20+ struct TouchEvent {
21+ enum class State {
22+ /* * The screen has been released. */
23+ Release,
24+ /* * The screen has been touched. */
25+ Press,
26+ /* * The screen has been touched and is still being held. */
27+ Held
28+ };
29+
30+ /* * The y coordinate of the touch. */
31+ State state;
32+ /* * The x coordinate of the touch. */
33+ int16_t x;
34+ /* * The y coordinate of the touch. */
35+ int16_t y;
36+
37+ // TODO: Determine when it starts counting
38+ /* * The number of times the screen has been pressed. */
39+ int32_t pressCount;
40+ /* * The number of times the screen has been released. */
41+ int32_t releaseCount;
42+ };
43+
44+ /* *
45+ * @brief Gets the most recent touch event.
46+ *
47+ * TODO: Determine the starting return value (Before the screen is touched).
48+ *
49+ * @return The most recent touch event.
50+ */
51+ static TouchEvent get_last_touch ();
52+
53+ /* *
54+ * @brief Subscribes the listener to be called when the screen begins to be pressed.
55+ *
56+ * Spawn a new task to check for events if it is not already running.
57+ * All listeners are called from this task.
58+ *
59+ * @warning If you have multiple listeners, avoid using delays, which can delay other callbacks
60+ * from being called, and result in lost information.
61+ * For this reason, it is recommended library developers use get_last_touch() instead of this
62+ * function.
63+ *
64+ * @param listener_cb The function to call when the screen is pressed.
65+ */
66+ static void on_pressed (std::function<void (const TouchEvent&)> listener_cb);
67+
68+ /* *
69+ * @brief Subscribes the listener to be called when the screen begins to be released.
70+ *
71+ * Spawn a new task to check for events if it is not already running.
72+ * All listeners are called from this task.
73+ *
74+ * @warning If you have multiple listeners, avoid using delays, which can delay other callbacks
75+ * from being called, and result in lost information.
76+ * For this reason, it is recommended library developers use get_last_touch() instead of this
77+ * function.
78+ *
79+ * @param listener_cb The function to call when the screen is pressed.
80+ */
81+ static void on_released (std::function<void (const TouchEvent&)> listener_cb);
82+
83+ // TODO: Should there be a on_held() function?
84+
85+ static void set_render_mode ();
86+ static void get_render_mode ();
87+ static void render ();
88+ static void scroll ();
89+ static void scroll_region ();
90+
91+ // TODO: Should these be a single function? see:
92+ // https://docs.rs/vexide/latest/vexide/devices/display/struct.Display.html#method.fill
93+ static void draw_rect ();
94+ static void draw_circle ();
95+ static void draw_line ();
96+ static void draw_pixel ();
97+
98+ static void fill_rect ();
99+ static void fill_circle ();
100+
101+ // Should likely use a text object, like vexide does:
102+ // https://docs.rs/vexide/latest/vexide/devices/display/struct.Text.html
103+ static void draw_text ();
104+
105+ static void clear (auto color /* = TODO*/ );
106+
107+ static void draw_buffer ();
108+ };
109+
110+ } // namespace zest
0 commit comments