-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMenu.h
145 lines (115 loc) · 4.29 KB
/
Menu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once
/*
MINI VIRTUAL ANALOG SYNTHESIZER
Copyright 2014 Kenneth D. Miller III
Menu Functions
*/
namespace Menu
{
class Menu;
// pages
enum Page
{
PAGE_MAIN,
PAGE_FX,
PAGE_COUNT
};
struct PageInfo
{
Menu * const *menu;
int count;
};
extern PageInfo const page_info[];
extern COORD const page_pos;
// menu attributes
extern WORD const title_attrib[2][3];
extern WORD const item_attrib[3];
// active page
extern Page active_page;
// active menu index
extern int active_menu;
// initialize the menu system
void Init();
// update a property
// sign: direction to change the property (+ or -)
// modifiers: keys that determine speed (tiny, small, normal, large)
// scale: quantizes the property to 1/scale
// step: step size for each speed; scale acts as the denominator
// minimum: smallest value the property can have
// maximum: largest value the property can have
extern void UpdateProperty(float &property, int const sign, DWORD const modifiers, float const scale, float const step[], float const minimum, float const maximum);
extern void UpdateProperty(int &property, int const sign, DWORD const modifiers, int const scale, int const step[], int const minimum, int const maximum);
// update a logarthmic-frequency property
extern float const pitch_step[];
inline void UpdatePitchProperty(float &property, int const sign, DWORD const modifiers, float const minimum, float const maximum)
{
UpdateProperty(property, sign, modifiers, 1200, pitch_step, minimum, maximum);
}
// update a linear percentage property
extern float const percent_step[];
inline void UpdatePercentageProperty(float &property, int const sign, DWORD const modifiers, float const minimum, float const maximum)
{
UpdateProperty(property, sign, modifiers, 256, percent_step, minimum, maximum);
}
// update a linear time property
extern float const time_step[];
inline void UpdateTimeProperty(float &property, int const sign, DWORD const modifiers, float const minimum, float const maximum)
{
UpdateProperty(property, sign, modifiers, 1000, time_step, minimum, maximum);
}
// set the active page
extern void SetActivePage(HANDLE hOut, Page page);
// set the active menu
extern void SetActiveMenu(HANDLE hOut, int menu);
extern void NextMenu(HANDLE hOut);
extern void PrevMenu(HANDLE hOut);
// menu key press handler
extern void Handler(HANDLE hOut, WORD key, DWORD modifiers);
// menu mouse click handler
extern void Click(HANDLE hOut, COORD pos);
// print all menus on the active page
extern void PrintActivePage();
// utility functions for printing menu items
extern void PrintItemFloat(HANDLE hOut, COORD pos, DWORD flags, char const *format, float value);
extern void PrintItemString(HANDLE hOut, COORD pos, DWORD flags, char const *format, char const *value);
extern void PrintItemBool(HANDLE hOut, COORD pos, SHORT width, DWORD flags, char const *format, bool value);
class Menu
{
public:
SMALL_RECT rect; // screen rectangle
int menu; // menu number
const char *name; // menu title
int count; // number of items
int item; // selected item
// constructor
Menu(SMALL_RECT rect, const char *name, int count)
: rect(rect)
, menu(0)
, name(name)
, count(count)
, item(0)
{
}
// print the whole menu
void Print(HANDLE hOut);
// shared key press handler
void Handler(HANDLE hOut, WORD key, DWORD modifiers);
// check if a position is inside the menu
inline bool Inside(COORD pos)
{
return pos.X >= rect.Left && pos.X < rect.Right && pos.Y >= rect.Top && pos.Y < rect.Bottom;
}
// shared mouse click handler
bool Click(HANDLE hOut, COORD pos);
protected:
void PrintMarker(HANDLE hOut, int index, CHAR_INFO left, CHAR_INFO right);
void ShowMarker(HANDLE hOut, int index);
void HideMarker(HANDLE hOut, int index);
// update a single item
virtual void Update(int index, int sign, DWORD modifiers) = 0;
// print a single item
virtual void Print(int index, HANDLE hOut, COORD pos, DWORD flags) = 0;
// utility function for printing title bar with attributes based on enable and flags
void PrintTitle(HANDLE hOut, bool enable, DWORD flags, char const *on_text, char const *off_text);
};
}