Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
mouse.h
Go to the documentation of this file.
1
2
3/*
4 * mouse.h
5 *
6 * Created on: May 1, 2022
7 * Author: micahbly
8 */
9
10#ifndef MOUSE_H_
11#define MOUSE_H_
12
13
14
15/* about this class: MouseTracker
16 *
17 * This tracks mouse positions and button actions to make it easier to see if double-click has happened, and to easily see if a given icon is under the mouse pointer
18 *
19 *** things this class needs to be able to do
20 * Track X, Y at last mouse click
21 * Track time of last mouse click, and determine if a double-click happened
22 * Track a mouse mode, which includes icon selected, drag mode, lasso mode, etc.
23 * Determine if a given coordinate pair is within the defined zone around the mouse pointer
24 *
25 *** things objects of this class have
26 *
27 *
28 */
29
30
31/*****************************************************************************/
32/* Includes */
33/*****************************************************************************/
34
35
36// project includes
37//#include "control.h"
38
39// C includes
40#include <stdbool.h>
41
42// A2560 includes
43// #include <mcp/syscalls.h>
44#include "a2560k.h"
45
46
47/*****************************************************************************/
48/* Macro Definitions */
49/*****************************************************************************/
50
51#define MOUSE_POINTER_RADIUS 2 // number of pixels up/down/left/right from mouse pointer that will be included in selection. might need to be 0
52#define MOUSE_MOVEMENT_THRESHOLD 4 // number of pixels away from the mouse-down point that mouse must before before lasso starts drawing or drag mode begins
53#define MOUSE_DOUBLE_CLICK_TICKS 30 // maximum number of ticks between first and second click for a double-click event to be registered
54
55
56/*****************************************************************************/
57/* Enumerations */
58/*****************************************************************************/
59
60// covers what action mode the mouse is in after a mouse down event: either dragging one or more icons, or selecting via lasso, or neither
61typedef enum MouseMode
62{
63 mouseFree = 0,
64 mouseSelect = 1, // user has clicked on icon(s), but not moved mouse enough to start drag
65 mouseDoubleclick = 2,
66 mouseDrag = 3, // user clicked on icon(s) and moved mouse enough to start drag mode
67 mouseLasso = 4, // nothing under cursor, button down, ready to start drawing a lasso
68 mouseLassoInProgress = 5, // user has moved mouse from origin point with mouse down, lasso is actively being drawn
69 mouseDownOnControl = 6, // mouse was clicked within bounds of a control. Mouse button is not released.
70 mouseDragTitle = 7,
71 mouseMenuOpen = 8, // right click opened a menu, and menu has not been closed yet.
72 mouseResizeUp = 9,
73 mouseResizeRight = 10,
74 mouseResizeDown = 11,
75 mouseResizeLeft = 12,
76 mouseResizeDownRight = 13,
77} MouseMode;
78
79
80/*****************************************************************************/
81/* Structs */
82/*****************************************************************************/
83
85{
86 Window* clicked_window_; // window the mouse was in when clicked. Not updated during a move or mouse up.
87 int16_t clicked_x_;
88 int16_t clicked_y_;
89 int16_t x_;
90 int16_t y_;
91 MouseMode mode_;
92 uint32_t clicked_ticks;
93 Rectangle selection_area_; // a box around the pointer (if not lasso), or the lasso box, used to detect icon selection and drag-mode start
94 Rectangle movement_area_; // a box between the last clicked and current location
95};
96
97
98/*****************************************************************************/
99/* Global Variables */
100/*****************************************************************************/
101
102
103/*****************************************************************************/
104/* Public Function Prototypes */
105/*****************************************************************************/
106
107// **** CONSTRUCTOR AND DESTRUCTOR *****
108
109
110// constructor
111// allocates space for the object
112MouseTracker* Mouse_New(void);
113
114// destructor
115void Mouse_Destroy(MouseTracker** the_mouse);
116
117
118// **** SETTERS *****
119
120
121// sets the mouse mode (select, doubleclick, drag, lasso, etc.)
122void Mouse_SetMode(MouseTracker* the_mouse, MouseMode the_mode);
123
124// sets the current x, y coord
125void Mouse_SetXY(MouseTracker* the_mouse, int16_t x, int16_t y);
126
127// sets the current x, y coord. If button_down is true, it also sets button down coord to passed coord.
128// Note: regardless of the value of the_window, clicked_window_ will only be updated if button_down is true.
129// Window should only be set when calling AcceptUpdate on a mouse down (click)
130void Mouse_AcceptUpdate(MouseTracker* the_mouse, Window* the_window, int16_t x, int16_t y, bool button_down);
131
132// updates the selection rectangle
133void Mouse_UpdateSelectionRectangle(MouseTracker* the_mouse, int16_t x_scrolled, int16_t y_scrolled);
134
135// clears the target window, panel, and folder
136// void Mouse_ClearTarget(MouseTracker* the_mouse);
137
138// sets the source window, panel, and folder
139// void Mouse_SetSource(MouseTracker* the_mouse, WB2KWindow* the_surface, WB2KViewPanel* the_panel, WB2KFolderObject* the_folder);
140
141// resets the mode, coordinates, time
142void Mouse_Clear(MouseTracker* the_mouse);
143
144
145// **** GETTERS *****
146
147// Get the mouse mode
148MouseMode Mouse_GetMode(MouseTracker* the_mouse);
149
150// Get the x coord
151int16_t Mouse_GetX(MouseTracker* the_mouse);
152
153// Get the y coord
154int16_t Mouse_GetY(MouseTracker* the_mouse);
155
156// Get the window the mouse was clicked on
157Window* Mouse_GetClickedWindow(MouseTracker* the_mouse);
158
159// Get the last clicked x coord
160int16_t Mouse_GetClickedX(MouseTracker* the_mouse);
161
162// Get the last clicked y coord
163int16_t Mouse_GetClickedY(MouseTracker* the_mouse);
164
165// get the horizontal delta between current and last clicked position
166int16_t Mouse_GetXDelta(MouseTracker* the_mouse);
167
168// get the vertical delta between current and last clicked position
169int16_t Mouse_GetYDelta(MouseTracker* the_mouse);
170
171
172
173// **** OTHER FUNCTIONS *****
174
175// check for a double click, assuming it just happened. Returns true if timer says it was double click. If not double click, resets the button down time to now.
176bool Mouse_WasDoubleClick(MouseTracker* the_mouse);
177
178// detect an overlap (selection) between the current selection area of the mouse, and the passed rectangle
179bool Mouse_DetectOverlap(MouseTracker* the_mouse, Rectangle the_other_object);
180
181// detect whether mouse pointer is far enough away from last click spot to engage lasso mode
182bool Mouse_MovedEnoughForLassoStart(MouseTracker* the_mouse);
183
184// detect whether mouse pointer is far enough away from last click spot to engage drag mode
185bool Mouse_MovedEnoughForDragStart(MouseTracker* the_mouse);
186
187// draw a rectangle in the rastport passed, using the mouse coordinates. If doUnDraw is TRUE, try to undraw it (unimplemented TODO)
188void Mouse_DrawSelectionBox(MouseTracker* the_mouse);
189
190
191
192// **** Debug functions *****
193
194void Mouse_Print(MouseTracker* the_mouse);
195
196
197
198
199#endif /* MOUSE_H_ */
Definition: mouse.h:85
Definition: a2560k.h:1369
Definition: window.h:135