Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
menu.h
Go to the documentation of this file.
1
2
3/*
4 * menu.h
5 *
6 * Created on: May 12, 2022
7 * Author: micahbly
8 */
9
10#ifndef MENU_H_
11#define MENU_H_
12
13
14/* about this class
15 *
16 * code to manage all aspects of menus
17 *
18 * Will be used for:
19 *
20 *
21 *** things a list needs to be able to do
22 * create/build menus at app startup
23 * determine which menu item has been selected by the user
24 * execute or route actions for each menu item
25 *
26 *
27*/
28
29
30/*****************************************************************************/
31/* Includes */
32/*****************************************************************************/
33
34#include "a2560k.h"
35#include "event.h"
36
37
38
39/*****************************************************************************/
40/* Macro Definitions */
41/*****************************************************************************/
42
43#define MENU_MAX_ITEMS 30
44#define MENU_MAX_WIDTH 300
45#define MENU_MAX_HEIGHT 350
46#define MENU_MARGIN 5
47#define MENU_TEXT_PADDING 2
48#define MENU_SHORTCUT_SPACE 40
49
50#define MENU_ID_NO_PARENT -1
51#define MENU_ID_DIVIDER -2
52#define MENU_ID_NO_SELECTION -3
53#define MENU_NOTHING_HIGHLIGHTED -1
54
55#define MENU_PARAM_SHOW_HIGHLIGHTED true
56#define MENU_PARAM_SHOW_NORMAL false
57
58/*****************************************************************************/
59/* Enumerations */
60/*****************************************************************************/
61
62typedef enum menu_item_type
63{
64 menuItem = 0,
65 menuSubmenu = 1,
66 menuDivider = 2,
67} menu_item_type;
68
69// typedef enum menu_level
70// {
71// menu_no_menu = -1,
72// menu_level_0 = 0,
73// menu_level_1 = 1,
74// menu_level_2 = 2,
75// menu_level_3 = 3,
76// } menu_level;
77
78// typedef enum menu_modifiers
79// {
80// foenixKeyBit = 1, // foenix key down?
81// shiftKeyBit = 2, // shift key down?
82// optionKeyBit = 3, // option key down?
83// controlKeyBit = 4, // control key down?
84// } menu_modifiers;
85//
86// typedef enum menu_modifier_flags
87// {
88// foenixKey = 1 << foenixKeyBit,
89// shiftKey = 1 << shiftKeyBit,
90// optionKey = 1 << optionKeyBit,
91// controlKey = 1 << controlKeyBit,
92// } menu_modifier_flags;
93
94/*****************************************************************************/
95/* Structs */
96/*****************************************************************************/
97
98
100{
101 int16_t id_;
102 char* text_;
103 event_modifier_flags modifiers_;
104 unsigned char shortcut_;
105 menu_item_type type_;
107};
108
110{
111 int16_t id_;
112 char* title_;
113 struct MenuItem* item_[MENU_MAX_ITEMS];
114 int16_t num_menu_items_;
115 bool is_submenu_; // if this menu group is a submenu, it will get a < back item at the top of the menu.
116 int16_t parent_id_;
117};
118
119struct Menu
120{
121 Bitmap* bitmap_; // bitmap in standard memory, to hold the rendered menu. Will be blitted to the screen.
122 int16_t pen_x_; // Local H position relative to the overall_rect_, of the "pen", for drawing functions
123 int16_t pen_y_; // Local V position relative to the overall_rect_, of the "pen", for drawing functions
124 uint8_t pen_color_; // Color index of the "pen", for drawing functions
125 Font* pen_font_; // Font to be used by the "pen", for drawing functions
126 Rectangle overall_rect_; // the local rect describing the total area of the menu
127 Rectangle global_rect_; // the global rect describing the total area of the menu
128 int16_t x_; // current global horizontal coordinate
129 int16_t y_; // current global vertical coordinate
130 int16_t width_; // current width of menu
131 int16_t height_; // current height of menu
132 int16_t inner_width_; // space available inside the menu, accounting for margin thicknesses
133 int16_t inner_height_; // space available inside the menu, accounting for margin thicknesses
134 Rectangle clip_rect_[2]; // one or more clipping rects; determines which parts of menu need to be re-blitted to the screen
135 int16_t clip_count_; // number of clip rects the menu is currently tracking
136 MenuGroup* menu_group_; // pointer to the menu group currently being displayed
137 bool invalidated_; // if true, the menu needs to be completely re-rendered on the next render pass
138 bool visible_; // is the menu active/visible, or not?
139 int16_t current_selection_; // index to menu_group_->item_[]. Updated during mouse move. Indicates which one of the rows is currently highlighted, if any. -1 if none.
140};
141
142
143/*****************************************************************************/
144/* Public Function Prototypes */
145/*****************************************************************************/
146
147// constructor
150Menu* Menu_New(void);
151
152// destructor
154void Menu_Destroy(Menu** the_menu);
155
156
159void Menu_Render(Menu* the_menu);
160
167void Menu_Open(Menu* the_menu, MenuGroup* the_menu_group, int16_t x, int16_t y);
168
172void Menu_CancelOpen(Menu* the_menu);
173
176void Menu_Hide(Menu* the_menu);
177
182void Menu_SetVisible(Menu* the_menu, bool is_visible);
183
184
190int16_t Menu_AcceptClick(Menu* the_menu, int16_t x, int16_t y);
191
196void Menu_AcceptMouseMove(Menu* the_menu, int16_t x, int16_t y);
197
203bool Menu_SetFont(Menu* the_menu, Font* the_font);
204
205
206#endif /* MENU_H_ */
bool Menu_SetFont(Menu *the_menu, Font *the_font)
Set the font used for drawing menu text This also sets the font of the menu's bitmap.
Definition: menu.c:872
void Menu_Destroy(Menu **the_menu)
Definition: menu.c:535
void Menu_Render(Menu *the_menu)
Renders the menu and blits entire menu or required cliprects to the screen.
Definition: menu.c:563
int16_t Menu_AcceptClick(Menu *the_menu, int16_t x, int16_t y)
Accept a right or left mouse click while a menu is open, identify which, if any, menu item should be ...
Definition: menu.c:756
Menu * Menu_New(void)
Creates a new Menu object, allocating space from the heap return Returns a complete Menu object with ...
Definition: menu.c:477
void Menu_SetVisible(Menu *the_menu, bool is_visible)
Set the menu's visibility flag.
Definition: menu.c:733
void Menu_CancelOpen(Menu *the_menu)
Cancels the opening of a menu before it is shown NOTE: this sets mouse mode back to mouseFree.
Definition: menu.c:673
void Menu_Hide(Menu *the_menu)
Hides the menu by damaging and distributing damage rects to all other windows, and re-rendering scree...
Definition: menu.c:696
void Menu_AcceptMouseMove(Menu *the_menu, int16_t x, int16_t y)
Accept a new mouse x/y while a menu is open, identify which, if any, menu item should be shown as sel...
Definition: menu.c:806
void Menu_Open(Menu *the_menu, MenuGroup *the_menu_group, int16_t x, int16_t y)
Replaces current menu_group_ reference with a new one, calculates widths, rects, and renders the menu...
Definition: menu.c:607
Definition: bitmap.h:97
This Font object is essentially the Mac "fontRecord" struct, with added pointers for the data tables.
Definition: font.h:71
Definition: menu.h:110
bool is_submenu_
of the total possible menu items defined by MENU_MAX_ITEMS, for this menu, how many are currently use...
Definition: menu.h:115
struct MenuItem * item_[MENU_MAX_ITEMS]
displayed at top of menu panel, and in the 'back' part of a child menu
Definition: menu.h:113
Definition: menu.h:120
Definition: menu.h:100
menu_item_type type_
the shortcut key. Must be typeable or user won't be able to use it.
Definition: menu.h:105
unsigned char shortcut_
none, or some/all of (foenixKey|shiftKey|optionKey|controlKey)
Definition: menu.h:104
Rectangle selection_rect_
the type of menu object: a submenu, a menu item, or a divider
Definition: menu.h:106
event_modifier_flags modifiers_
the label/text of the menu item
Definition: menu.h:103
Definition: a2560k.h:1369