Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1
2
3/*
4 * event.h
5 *
6* Created on: Apr 16, 2022
7 * Author: micahbly
8 */
9
10#ifndef EVENT_H_
11#define EVENT_H_
12
13
14/* about this class: Event Manager
15 *
16 * Provides structures and functions for queueing events
17
18 * NOTE: Event structures and style are largely based on Apple's old (pre-OS X) events.h
19 * I have adapted for Foenix realities, and for my style, and added a couple of conveniences
20 * A couple of conveniences added in style of Amiga Intuition: the window and control are available directly from the event record
21 * There is no expectation that somebody's old mac code would work
22 * however, it should be familiar in feel to anyone who programmed macs before OS X
23
24 *
25 *** things this class needs to be able to do
26 * Provide interrupt handlers that turn mouse and keyboard actions into events
27 * Provide a global event queue that apps can access
28 *
29 *
30 * STRETCH GOALS
31 *
32 *
33 * SUPER STRETCH GOALS
34 *
35 *
36 */
37
38
39/*****************************************************************************/
40/* Includes */
41/*****************************************************************************/
42
43// project includes
44
45
46// C includes
47#include <stdbool.h>
48
49
50// A2560 includes
51#include <mcp/syscalls.h>
52#include "a2560k.h"
53
54
55/*****************************************************************************/
56/* Macro Definitions */
57/*****************************************************************************/
58
59#define EVENT_QUEUE_SIZE 128
60
61
62/*****************************************************************************/
63/* Enumerations */
64/*****************************************************************************/
65
66typedef enum event_kind
67{
68 nullEvent = 0,
69 mouseDown , // left mouse button
70 mouseUp , // left mouse button
71 rMouseDown ,
72 rMouseUp ,
73 mMouseDown , // middle mouse button
74 mMouseUp ,
75 mouseMoved ,
76 keyDown , // key event
77 keyUp , // key event
78 autoKey , // key event
79 windowChanged , // window event
80 updateEvt , // window event
81 activateEvt , // window event
82 inactivateEvt , // window event
83 controlClicked , // window event
84 menuOpened , // menu event
85 menuSelected , // menu event
86 menuCanceled , // menu event
87 diskEvt , // DOS event
88 invalidEvent , // marker for last event type supported
89} event_kind;
90
91
92typedef enum event_mask
93{
94 mouseDownMask = 1 << mouseDown, // mouse button pressed
95 mouseUpMask = 1 << mouseUp, // mouse button released
96 keyDownMask = 1 << keyDown, // key pressed
97 keyUpMask = 1 << keyUp, // key released
98 autoKeyMask = 1 << autoKey, // key repeatedly held down
99 updateMask = 1 << updateEvt, // window needs updating
100 diskEvtMask = 1 << diskEvt, // disk inserted
101 activateEvtMask = 1 << activateEvt, // activate window
102 inactivateEvtMask = 1 << inactivateEvt, // deactivate window
103 rMouseDownMask = 1 << rMouseDown, // right mouse button pressed
104 rMouseUpMask = 1 << rMouseUp, // right mouse button released
105 menuOpenedMask = 1 << menuOpened, // contextual menu opened
106 menuSelectedMask = 1 << menuSelected, // item from the contextual menu selected
107 menuCanceledMask = 1 << menuCanceled, // contextual menu closed without an item being selected
108 controlClickedMask = 1 << controlClicked, // a clickable (2 state) control has been clicked
109 mouseMovedMask = 1 << mouseMoved, // mouse has been moved
110 windowChangedMask = 1 << windowChanged, // a window has changed size and/or position
111 mMouseDownMask = 1 << mMouseDown, // middle mouse button pressed
112 mMouseUpMask = 1 << mMouseUp, // middle mouse button released
113 everyEvent = 0xFFFF // all of the above
114} event_mask;
115
116
117typedef enum event_modifiers
118{
119 noneFlagBit = 0, // no modifier
120 activeFlagBit = 1, // activate? (activateEvt and mouseDown)
121 btnStateBit = 7, // state of button?
122 foenixKeyBit = 8, // foenix key down?
123 shiftKeyBit = 9, // shift key down?
124 alphaLockBit = 10, // alpha lock down?
125 optionKeyBit = 11, // option key down?
126 controlKeyBit = 12, // control key down?
127 rightShiftKeyBit = 13, // right shift key down?
128 rightOptionKeyBit = 14, // right Option key down?
129 rightControlKeyBit = 15 // right Control key down?
130} event_modifiers;
131
132typedef enum event_modifier_flags
133{
134 activeFlag = 1 << activeFlagBit,
135 btnState = 1 << btnStateBit,
136 foenixKey = 1 << foenixKeyBit,
137 shiftKey = 1 << shiftKeyBit,
138 alphaLock = 1 << alphaLockBit,
139 optionKey = 1 << optionKeyBit,
140 controlKey = 1 << controlKeyBit,
141 rightShiftKey = 1 << rightShiftKeyBit,
142 rightOptionKey = 1 << rightOptionKeyBit,
143 rightControlKey = 1 << rightControlKeyBit
144} event_modifier_flags;
145
146
147// TODO: localize this for A2560
148enum
149{
150 kNullCharCode = 0,
151 kHomeCharCode = 1,
152 kEnterCharCode = 3,
153 kEndCharCode = 4,
154 kHelpCharCode = 5,
155 kBellCharCode = 7,
156 kBackspaceCharCode = 8,
157 kTabCharCode = 9,
158 kLineFeedCharCode = 10,
159 kVerticalTabCharCode = 11,
160 kPageUpCharCode = 11,
161 kFormFeedCharCode = 12,
162 kPageDownCharCode = 12,
163 kReturnCharCode = 13,
164 kFunctionKeyCharCode = 16,
165 kEscapeCharCode = 27,
166 kClearCharCode = 27,
167 kLeftArrowCharCode = 28,
168 kRightArrowCharCode = 29,
169 kUpArrowCharCode = 30,
170 kDownArrowCharCode = 31,
171 kDeleteCharCode = 127,
172 kNonBreakingSpaceCharCode = 202
173};
174
175
176
177/*****************************************************************************/
178/* Structs */
179/*****************************************************************************/
180
182// event_modifiers modifiers_; //! set for keyboard and mouse events
183 uint8_t key_;
184 uint8_t char_;
185 uint8_t modifiers_;
186 uint8_t source_;
187};
188
189struct EventMenu {
190 int16_t selection_;
191 int16_t x_;
192 int16_t y_;
193};
194
196 event_modifiers modifiers_;
197 int16_t x_;
198 int16_t y_;
200};
201
203 event_modifiers modifiers_;
204 int16_t x_;
205 int16_t y_;
206 int16_t width_;
207 int16_t height_;
208};
209
211{
212 uint32_t when_;
213 event_kind what_;
214 Window* window_;
216 union {
217 EventKeyboard keyinfo_;
218 EventMouse mouseinfo_;
219 EventWindow windowinfo_;
220 EventMenu menuinfo_;
221 };
222};
223
225{
226 EventRecord* queue_[EVENT_QUEUE_SIZE];
227 uint16_t write_idx_;
228 uint16_t read_idx_;
230};
231
232
233
234
235/*****************************************************************************/
236/* Global Variables */
237/*****************************************************************************/
238
239
240/*****************************************************************************/
241/* Public Function Prototypes */
242/*****************************************************************************/
243
244
245// **** events are pre-created in a fixed size array on system startup (circular buffer)
246// **** as interrupts need to add more events, they take the next slot available in the array
247
248// **** CONSTRUCTOR AND DESTRUCTOR *****
249
250// constructor
253
254// destructor
255// frees all allocated memory associated with the passed object, and the object itself
256bool Event_Destroy(EventRecord** the_event);
257
258
259
260// constructor
263
264// destructor
265// frees all allocated memory associated with the passed object, and the object itself
266bool EventManager_Destroy(EventManager** the_event_manager);
267
268
269
270
271// **** Queue Management functions *****
272
273
277
281
288void EventManager_AddMouseEvent(event_kind the_what);
289
300void EventManager_AddWindowEvent(event_kind the_what, int16_t x, int16_t y, int16_t width, int16_t height, Window* the_window, Control* the_control);
301
310void EventManager_AddMenuEvent(event_kind the_what, int16_t menu_selection,int16_t x, int16_t y, Window* the_window);
311
314
315
316
317
318
319// **** Debug functions *****
320
321void Event_Print(EventRecord* the_event);
322void EventManager_Print(EventManager* the_event_manager);
323
324
325
326#endif /* EVENT_H_ */
327
328
void EventManager_RemoveEventsForWindow(Window *the_window)
Nulls out any events associated with the window pointer passed Call this when a window has been close...
Definition: event.c:322
void EventManager_WaitForEvent(void)
Wait for an event to happen, do system-processing of it, then if appropriate, give the window respons...
Definition: event.c:1151
void EventManager_AddMenuEvent(event_kind the_what, int16_t menu_selection, int16_t x, int16_t y, Window *the_window)
Add a new menu event to the event queue NOTE: this does not actually insert a new record,...
Definition: event.c:521
EventRecord * EventManager_NextEvent(void)
Checks to see if there is an event in the queue returns NULL if no event (not the same as returning a...
Definition: event.c:369
EventRecord * Event_New(void)
Allocate an EventManager object.
Definition: event.c:188
EventManager * EventManager_New(void)
Allocate an EventManager object.
Definition: event.c:236
void EventManager_AddWindowEvent(event_kind the_what, int16_t x, int16_t y, int16_t width, int16_t height, Window *the_window, Control *the_control)
Add a new window event to the event queue NOTE: this does not actually insert a new record,...
Definition: event.c:473
void EventManager_AddMouseEvent(event_kind the_what)
Add a new mouse event to the event queue NOTE: this does not actually insert a new record,...
Definition: event.c:415
This structure describes an instantiated control on a window.
Definition: control.h:130
Definition: event.h:181
uint8_t modifiers_
the character code resulting from the key, after mapping. e.g, 1 may return 49, ALT-1 may return 145,...
Definition: event.h:185
uint8_t source_
bit flags for shift, ctrl, meta, etc.
Definition: event.h:186
uint8_t char_
the key code of the key pushed. eg, KEY_BKSP (0x92), not CH_BKSP (0x08). Most useful for handling act...
Definition: event.h:184
Definition: event.h:225
MouseTracker * mouse_tracker_
index to queue_: where the next event record will be read from
Definition: event.h:229
uint16_t read_idx_
index to queue_: where the next event record will be slotted
Definition: event.h:228
uint16_t write_idx_
circular buffer for the event queue
Definition: event.h:227
Definition: event.h:189
int16_t x_
for menu events: the selected menu item ID
Definition: event.h:191
int16_t y_
for menu events: the global x position of mouse.
Definition: event.h:192
Definition: event.h:195
int16_t x_
set for keyboard and mouse events
Definition: event.h:197
Control * control_
for mouse events: the global y position of mouse.
Definition: event.h:199
int16_t y_
for mouse events: the global x position of mouse.
Definition: event.h:198
Definition: event.h:211
Control * control_
The affected window (if any). May be NULL.
Definition: event.h:215
event_kind what_
ticks
Definition: event.h:213
Definition: event.h:202
int16_t height_
for window events: the new width of the window.
Definition: event.h:207
int16_t x_
set for keyboard and mouse events
Definition: event.h:204
int16_t y_
for window events: the new global x position of the window.
Definition: event.h:205
int16_t width_
for window events: the new global y position of the window.
Definition: event.h:206
Definition: mouse.h:85
Definition: window.h:135