-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenDrawing.cpp
235 lines (184 loc) · 6.25 KB
/
ScreenDrawing.cpp
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "Screen.h"
void Screen::Draw()
{
SortPrinters();
//Clear Pads
clear();
wclear(TopPad);
wclear(Pad);
//Top Text Panel
wattrset(TopPad, A_BOLD | COLOR_PAIR(0b111010));
waddstr(TopPad, " Name ");
if (SortOrder == 0) { waddch(TopPad, ACS_UARROW); } else { waddch(TopPad, ' '); }
waddstr(TopPad, " Status ");
if (SortOrder == 1) { waddch(TopPad, ACS_UARROW); } else { waddch(TopPad, ' '); }
FillLine(TopPad, ' ');
wattrset(TopPad, COLOR_PAIR(NORMAL));
//Do drawing for printer grid
UpdatePrinterColumns();
int printerPos = 0;
for (int i = 0; i < (int)PrinterList.size(); i++)
{
//wattrset(Pad, COLOR_PAIR(GREY));
//Border(Pad, 0, printerPos-1, PrinterWidth+1, printerPos+PrinterHeight);
//wattrset(Pad, COLOR_PAIR(NORMAL));
mvderwin(PrinterList[i]->Pad, printerPos, 0);
PrinterList[i]->Mutex->lock();
PrinterList[i]->Draw(this);
PrinterList[i]->Mutex->unlock();
//wborder(PrinterList[i].Pad, '1','2','3','4','5','6','7','8');
printerPos+=(PrinterList[i]->Expanded ? PrinterHeight : 1) + 1;
//if (PrinterList[i].Expanded) { exit(0); }
if (i != (int)PrinterList.size() - 1)
{
wmove(Pad, printerPos - 1, 0);
whline(Pad, ACS_HLINE, getmaxx(Pad));
}
}
//Bottom Text Panel
wattrset(stdscr, COLOR_PAIR(0b111100));
wmove(stdscr, Height-1, 0);
waddstr(stdscr, "Auto Scroll:");
if (AutoScroll) { wattrset(stdscr, A_BOLD | COLOR_PAIR(0b010100)); waddstr(stdscr, "ON "); }
else { wattrset(stdscr, A_BOLD | COLOR_PAIR(0b001100)); waddstr(stdscr, "OFF"); }
wattrset(stdscr, COLOR_PAIR(0b111100));
if (RefreshingPrinters) { waddstr(stdscr, " Refreshing Printers "); }
else { waddstr(stdscr, " "); }
{
int NumPapers = 0;
for (int i = 0; i < (int)PrinterList.size(); i++)
{
for (int j = 0; j < (int)PrinterList[i]->TrayList.size(); j++)
{
if (PrinterList[i]->TrayList[j].Status == "Low" || PrinterList[i]->TrayList[j].Status == "Empty")
{
NumPapers++;
}
}
}
waddstr(stdscr, "Estimated Papers Needed:");
if (NumPapers > 0) { wattrset(stdscr, A_BOLD | COLOR_PAIR(0b001100)); }
waddstr(stdscr, std::to_string(NumPapers).c_str());
}
wattrset(stdscr, COLOR_PAIR(0b111100));
FillLine(stdscr, ' ');
wmove(stdscr, Height-1, Width - 31);
waddstr(stdscr, "Press H or I for Help and Info");
wattrset(stdscr, COLOR_PAIR(NORMAL));
if (Popup)
{
DrawInfoMenu();
}
if (AutoScroll)
{
if (AutoScrollDelay++ >= 10)
{
int maxY = 0;
GetPrinterDisplayHeight(&maxY);
if (ScrollY + Height - 2 >= maxY)
{
ScrollY = 0;
}
else
{
ScrollY += MIN((int)(Height * 0.75), maxY-(ScrollY+Height-2));
}
AutoScrollDelay = 0;
}
}
else
{
AutoScrollDelay = 0;
}
//Scroll Bar
{
int maxY = 0;
GetPrinterDisplayHeight(&maxY);
int screenMin = ScrollY;
int screenMax = ScrollY + Height-2;
int barMin = (Height-2)*screenMin/MAX(maxY, Height-2);
int barMax = (Height-2)*screenMax/MAX(maxY, Height-2);
wmove(stdscr, 1, Width-1);
wvline(stdscr, ACS_VLINE, Height-2);
wmove(stdscr, barMin + 1, Width-1);
wattrset(stdscr, COLOR_PAIR(0b111111));
wvline(stdscr, ACS_CKBOARD, barMax - barMin);
wattrset(stdscr, COLOR_PAIR(0b111111));
}
//Refresh display elements
wnoutrefresh(stdscr);
//touchwin(Pad);
pnoutrefresh(Pad, ScrollY, ScrollX, 1, 0, Height-2, Width-2);
pnoutrefresh(TopPad, 0, ScrollX,0,0,1,Width-1);
if (Popup) { wnoutrefresh(PopupBorder); wnoutrefresh(Popup); }
//Draw update to screen. Doing this after reduces screen flicker
doupdate();
}
void Screen::DrawInfoMenu()
{
wclear(PopupBorder);
wclear(Popup);
wattrset(PopupBorder, A_BOLD | COLOR_PAIR(0b111111));
wborder(PopupBorder, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER);
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
wmove(Popup, 0, getmaxx(Popup)/2-2);
waddstr(Popup, "Info");
FillLine(Popup, ' ');
FillLine(Popup, ACS_HLINE);
//wmove(Popup, 1, 2);
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "Created By: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Conner Tenn"); FillLine(Popup, ' ');
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "Source Code availaible at:"); FillLine(Popup, ' ');
wattrset(Popup, A_BOLD | COLOR_PAIR(0b110000));
waddstr(Popup, "https://github.com/ConnerTenn/IT_Printer_Status"); FillLine(Popup, ' ');
wmove(Popup, 7, 0);
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
wmove(Popup, 7, getmaxx(Popup)/2-5);
waddstr(Popup, "Help Menu");
FillLine(Popup, ' ');
FillLine(Popup, ACS_HLINE);
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "The printer file stores all the printers that will be accessed by the program.\nThe config file contains various settings for the program operation.\n\n");
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "Key Bindings:"); FillLine(Popup, ' ');
waddstr(Popup, "A: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Toggle Auto Scroll\n");
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "R: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Reload Printers From File and Reload\n");
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "S: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Toggle Sort Order\n");
#ifdef WINDOWS
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "M: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Maximize Screen Size\n");
#endif
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "E: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Expand/Contract All\n");
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "Enter: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Expand/Contract Selected Printer\n");
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "Arrow Keys: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Move Cursor and Scroll Left/Right\n");
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "Escape: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Close Program\n");
wattrset(Popup, A_BOLD | COLOR_PAIR(NORMAL));
waddstr(Popup, "H/I: ");
wattrset(Popup, COLOR_PAIR(NORMAL));
waddstr(Popup, "Toggle Help and Info Menu\n");
}