@@ -15,44 +15,59 @@ SysStatusComponent::SysStatusComponent()
15
15
LookAndFeelFactory::getInstance ()->getLAFFor (LookAndFeelFactory::SysStatus));
16
16
this ->setMouseCursor (juce::MouseCursor::PointingHandCursor);
17
17
18
- /* * Translate */
19
- this ->nameTrans .insert (std::make_pair (" cpu" , TRANS (" cpu" )));
20
- this ->nameTrans .insert (std::make_pair (" audio" , TRANS (" audio" )));
21
- this ->nameTrans .insert (std::make_pair (" mem" , TRANS (" mem" )));
22
- this ->nameTrans .insert (std::make_pair (" mem-process" , TRANS (" mem-process" )));
18
+ /* * Name */
19
+ this ->watchName [WatchType::CPU] = TRANS (" CPU" );
20
+ this ->watchName [WatchType::Audio] = TRANS (" Audio" );
21
+ this ->watchName [WatchType::Memory] = TRANS (" RAM" );
22
+ this ->watchName [WatchType::ProcessMem] = TRANS (" Process RAM" );
23
+
24
+ /* * Refresh */
25
+ this ->refresh ();
23
26
}
24
27
25
- void SysStatusComponent::update () {
28
+ void SysStatusComponent::refresh () {
26
29
/* * Get Config */
27
30
juce::var& conf = ConfigManager::getInstance ()->get (" sysstat" );
28
31
29
- /* * Check Curve Name And Size */
30
- juce::String curveName = conf[" curve" ].toString ();
32
+ /* * Check Curve Type And Size */
33
+ int curveType{ (int )conf[" curve" ] };
34
+ if (curveType < 0 || curveType >= WatchType::TotalNum) {
35
+ curveType = 0 ;
36
+ }
37
+
31
38
int curveSize = conf[" points" ];
32
- if (curveName != this ->curveName || curveSize != this ->curveData .size ()) {
33
- this ->curveName = curveName ;
39
+ if (curveType != this ->currentCurve || curveSize != this ->curveData .size ()) {
40
+ this ->currentCurve = (WatchType)curveType ;
34
41
this ->clearCurve (curveSize);
35
42
}
36
43
37
- /* * Get Curve Data */
38
- this ->addCurve (this ->getData (curveName));
39
-
40
- /* * Get Watch Name */
44
+ /* * Check Watch List */
41
45
auto watchArray = conf[" watch" ].getArray ();
42
46
for (int i = 0 ; i < watchArray->size (); i++) {
43
- if (i < this ->watchName .size ()) {
44
- this ->watchName [i] = watchArray->getUnchecked (i).toString ();
45
- }
46
- }
47
+ if (i < this ->currentWatchList .size ()) {
48
+ int watchType{ (int )watchArray->getUnchecked (i) };
49
+ if (watchType < 0 || watchType >= WatchType::TotalNum) {
50
+ watchType = 0 ;
51
+ }
47
52
48
- /* * Get Watch Data */
49
- for (int i = 0 ; i < this ->watchName .size (); i++) {
50
- if (i < this ->watchData .size ()) {
51
- this ->watchData [i] = this ->getData (this ->watchName [i]);
53
+ this ->currentWatchList [i] = (WatchType)watchType;
52
54
}
53
55
}
54
56
}
55
57
58
+ void SysStatusComponent::update () {
59
+ static SysStatus::CPUPercTemp cpuTemp;
60
+
61
+ /* * Get Data */
62
+ this ->watchData [WatchType::CPU] = SysStatus::getInstance ()->getCPUUsage (cpuTemp);
63
+ this ->watchData [WatchType::Audio] = quickAPI::getCPUUsage ();
64
+ this ->watchData [WatchType::Memory] = SysStatus::getInstance ()->getMemUsage ();
65
+ this ->watchData [WatchType::ProcessMem] = SysStatus::getInstance ()->getProcMemUsage ();
66
+
67
+ /* * Get Curve Data */
68
+ this ->addCurve (this ->watchData [this ->currentCurve ]);
69
+ }
70
+
56
71
void SysStatusComponent::paint (juce::Graphics& g) {
57
72
auto & laf = this ->getLookAndFeel ();
58
73
auto screenSize = utils::getScreenSize (this );
@@ -88,30 +103,32 @@ void SysStatusComponent::paint(juce::Graphics& g) {
88
103
g.fillAll ();
89
104
90
105
/* * Watch */
91
- for (int i = 0 ; i < this ->watchData . size () && i < this -> watchName .size (); i++) {
106
+ for (int i = 0 ; i < this ->currentWatchList .size (); i++) {
92
107
juce::Rectangle<int > labelRect (
93
108
this ->getWidth () - watchWidth + watchPaddingWidth, i * (watchLabelHeight + watchTextHeight),
94
109
watchWidth - watchPaddingWidth * 2 , watchLabelHeight);
95
110
juce::Rectangle<int > textRect (
96
111
this ->getWidth () - watchWidth + watchPaddingWidth, i * (watchLabelHeight + watchTextHeight) + watchLabelHeight,
97
112
watchWidth - watchPaddingWidth * 2 , watchTextHeight);
98
113
99
- juce::String name = this ->watchName [i];
100
- double value = this ->watchData [i];
114
+ WatchType type = this ->currentWatchList [i];
115
+ juce::String name = this ->watchName [type];
116
+ double value = this ->watchData [type];
101
117
102
118
g.setColour (labelColor);
103
119
g.setFont (labelFont);
104
- g.drawFittedText (this -> nameTrans [ name] , labelRect,
120
+ g.drawFittedText (name, labelRect,
105
121
juce::Justification::centredLeft, 1 , 1 .f );
106
- g.setColour (this ->getAlert (name , value) ? alertColor : textColor);
122
+ g.setColour (this ->getAlert (type , value) ? alertColor : textColor);
107
123
g.setFont (textFont);
108
- g.drawFittedText (this ->getValueText (name , value), textRect,
124
+ g.drawFittedText (this ->getValueText (type , value), textRect,
109
125
juce::Justification::centredRight, 1 , 1 .f );
110
126
}
111
127
112
128
/* * Curve Label */
113
- auto [vMin, vMax] = this ->getRange ();
129
+ auto [vMin, vMax] = this ->getRange (this -> currentCurve );
114
130
int curveWidth = this ->getWidth () - watchWidth;
131
+ auto & curveName = this ->watchName [this ->currentCurve ];
115
132
116
133
juce::Rectangle<int > maxLabelRect (
117
134
curveWidth - curvePaddingWidth - curveLabelWidth, 0 ,
@@ -123,10 +140,10 @@ void SysStatusComponent::paint(juce::Graphics& g) {
123
140
g.setColour (labelColor);
124
141
g.setFont (labelFont);
125
142
g.drawFittedText (
126
- this ->getValueText (this ->curveName , vMax), maxLabelRect,
143
+ this ->getValueText (this ->currentCurve , vMax), maxLabelRect,
127
144
juce::Justification::centredRight, 1 , 1 .f );
128
145
g.drawFittedText (
129
- this ->getValueText (this ->curveName , vMin), minLabelRect,
146
+ this ->getValueText (this ->currentCurve , vMin), minLabelRect,
130
147
juce::Justification::centredRight, 1 , 1 .f );
131
148
132
149
/* * Curve */
@@ -154,13 +171,12 @@ void SysStatusComponent::paint(juce::Graphics& g) {
154
171
curveLabelWidth, watchTextHeight);
155
172
g.setColour (labelColor);
156
173
g.setFont (labelFont);
157
- g.drawFittedText (
158
- this ->nameTrans [this ->curveName ], curveLabelRect,
174
+ g.drawFittedText (curveName, curveLabelRect,
159
175
juce::Justification::centredLeft, 1 , 1 .f );
160
- g.setColour (this ->getAlert (this ->curveName , vTemp) ? alertColor : textColor);
176
+ g.setColour (this ->getAlert (this ->currentCurve , vTemp) ? alertColor : textColor);
161
177
g.setFont (textFont);
162
178
g.drawFittedText (
163
- this ->getValueText (this ->curveName , vTemp), curveTextRect,
179
+ this ->getValueText (this ->currentCurve , vTemp), curveTextRect,
164
180
juce::Justification::centredLeft, 1 , 1 .f );
165
181
}
166
182
@@ -192,21 +208,21 @@ void SysStatusComponent::mouseMove(const juce::MouseEvent& event) {
192
208
193
209
/* * Curve */
194
210
if (event.position .getX () < (this ->getWidth () - watchWidth)) {
195
- juce::String name = this ->curveName ;
196
- this ->setTooltip (this -> nameTrans [name] + " : " +
197
- this ->getValueText (name , this ->getCurve (this ->curveData .size () - 1 )));
211
+ auto & curveName = this ->watchName [ this -> currentCurve ] ;
212
+ this ->setTooltip (curveName + " : " +
213
+ this ->getValueText (this -> currentCurve , this ->getCurve (this ->curveData .size () - 1 )));
198
214
}
199
215
/* * Watch */
200
216
else {
201
217
int index = event.position .getY () / watchHeight;
202
- if (index < 0 || index >= this ->watchName .size ()
203
- || index >= this ->watchData .size ()) {
218
+ if (index < 0 || index >= this ->currentWatchList .size ()) {
204
219
return ;
205
220
}
206
221
207
- juce::String name = this ->watchName [index];
208
- this ->setTooltip (this ->nameTrans [name] + " : " +
209
- this ->getValueText (name, this ->watchData [index]));
222
+ WatchType type = this ->currentWatchList [index];
223
+ juce::String name = this ->watchName [type];
224
+ this ->setTooltip (name + " : " +
225
+ this ->getValueText (type, this ->watchData [type]));
210
226
}
211
227
}
212
228
@@ -240,19 +256,8 @@ double SysStatusComponent::getCurve(int index) {
240
256
return this ->curveData [realIndex];
241
257
}
242
258
243
- double SysStatusComponent::getData (const juce::String& name) const {
244
- static SysStatus::CPUPercTemp cpuTemp;
245
-
246
- if (name == " cpu" ) { return SysStatus::getInstance ()->getCPUUsage (cpuTemp); }
247
- else if (name == " audio" ) { return quickAPI::getCPUUsage (); }
248
- else if (name == " mem" ) { return SysStatus::getInstance ()->getMemUsage (); }
249
- else if (name == " mem-process" ) { return SysStatus::getInstance ()->getProcMemUsage (); }
250
-
251
- return 0 ;
252
- }
253
-
254
- std::tuple<double , double > SysStatusComponent::getRange () const {
255
- if (this ->curveName == " mem-process" ) {
259
+ std::tuple<double , double > SysStatusComponent::getRange (WatchType type) const {
260
+ if (type == WatchType::ProcessMem) {
256
261
double maxT = 0 ;
257
262
for (auto i : this ->curveData ) {
258
263
maxT = std::max (maxT, i);
@@ -264,17 +269,17 @@ std::tuple<double, double> SysStatusComponent::getRange() const {
264
269
}
265
270
266
271
bool SysStatusComponent::getAlert (
267
- const juce::String& name , double value) const {
268
- if (name == " mem-process " ) {
272
+ WatchType type , double value) const {
273
+ if (type == WatchType::ProcessMem ) {
269
274
return false ;
270
275
}
271
276
272
277
return value >= 0.9 ;
273
278
}
274
279
275
280
juce::String SysStatusComponent::getValueText (
276
- const juce::String& name , double value) const {
277
- if (name == " mem-process " ) {
281
+ WatchType type , double value) const {
282
+ if (type == WatchType::ProcessMem ) {
278
283
if (value < (uint64_t )1024 ) {
279
284
return juce::String{ value, 2 , false } + " B" ;
280
285
}
@@ -295,55 +300,41 @@ juce::String SysStatusComponent::getValueText(
295
300
296
301
void SysStatusComponent::showCurveMenu () {
297
302
/* * Show Menu */
298
- auto menu = this ->createMenu (this ->curveName , this -> curveData . size () , true );
303
+ auto menu = this ->createMenu (this ->currentCurve , true );
299
304
int result = menu.show ();
300
305
301
306
/* * Result */
302
307
auto conf = ConfigManager::getInstance ()->get (" sysstat" ).getDynamicObject ();
303
308
if (!conf) { return ; }
304
309
switch (result) {
305
- case 1 :
306
- conf->setProperty (" curve" , " cpu" );
307
- ConfigManager::getInstance ()->saveConfig (" sysstat" );
308
- break ;
309
- case 2 :
310
- conf->setProperty (" curve" , " audio" );
311
- ConfigManager::getInstance ()->saveConfig (" sysstat" );
312
- break ;
313
- case 3 :
314
- conf->setProperty (" curve" , " mem" );
315
- ConfigManager::getInstance ()->saveConfig (" sysstat" );
316
- break ;
317
- case 4 :
318
- conf->setProperty (" curve" , " mem-process" );
310
+ case 110 :
311
+ case 120 :
312
+ case 150 :
313
+ conf->setProperty (" points" , result - 100 );
319
314
ConfigManager::getInstance ()->saveConfig (" sysstat" );
320
315
break ;
321
316
322
- case 101 :
323
- conf->setProperty (" points" , 10 );
324
- ConfigManager::getInstance ()->saveConfig (" sysstat" );
325
- break ;
326
- case 102 :
327
- conf->setProperty (" points" , 20 );
328
- ConfigManager::getInstance ()->saveConfig (" sysstat" );
329
- break ;
330
- case 103 :
331
- conf->setProperty (" points" , 50 );
332
- ConfigManager::getInstance ()->saveConfig (" sysstat" );
317
+ default :
318
+ if (result >= 1 && result <= WatchType::TotalNum) {
319
+ conf->setProperty (" curve" , result - 1 );
320
+ ConfigManager::getInstance ()->saveConfig (" sysstat" );
321
+ }
333
322
break ;
334
323
}
324
+
325
+ /* * Refresh */
326
+ this ->refresh ();
335
327
}
336
328
337
329
void SysStatusComponent::showWatchMenu (int index) {
338
- if (index < 0 || index >= this ->watchName .size ()
339
- || index >= this ->watchData .size ()) { return ; }
330
+ if (index < 0 || index >= this ->currentWatchList .size ()) { return ; }
340
331
341
332
/* * Show Menu */
342
- auto menu = this ->createMenu (this ->watchName [index], 0 , false );
333
+ auto menu = this ->createMenu (this ->currentWatchList [index], false );
343
334
int result = menu.show ();
344
335
345
336
/* * Set Func */
346
- auto setFunc = [index, size = this ->watchName .size ()](const juce::String& name )->bool {
337
+ auto setFunc = [index, size = this ->currentWatchList .size ()](WatchType type )->bool {
347
338
auto conf = ConfigManager::getInstance ()->get (" sysstat" ).getDynamicObject ();
348
339
if (!conf) { return false ; }
349
340
@@ -354,43 +345,34 @@ void SysStatusComponent::showWatchMenu(int index) {
354
345
ptrArray->resize (size);
355
346
}
356
347
357
- ptrArray->set (index, name );
348
+ ptrArray->set (index, ( int )type );
358
349
conf->setProperty (" watch" , juce::var{ *ptrArray });
359
350
ConfigManager::getInstance ()->saveConfig (" sysstat" );
360
351
return true ;
361
352
};
362
353
363
354
/* * Result */
364
- switch (result) {
365
- case 1 :
366
- if (!setFunc (" cpu" )) { return ; }
367
- break ;
368
- case 2 :
369
- if (!setFunc (" audio" )) { return ; }
370
- break ;
371
- case 3 :
372
- if (!setFunc (" mem" )) { return ; }
373
- break ;
374
- case 4 :
375
- if (!setFunc (" mem-process" )) { return ; }
376
- break ;
355
+ if (result >= 1 && result <= WatchType::TotalNum) {
356
+ setFunc ((WatchType)(result - 1 ));
377
357
}
358
+
359
+ /* * Refresh */
360
+ this ->refresh ();
378
361
}
379
362
380
- juce::PopupMenu SysStatusComponent::createMenu (const juce::String& currentName,
381
- int currentPoints, bool isCurve) {
363
+ juce::PopupMenu SysStatusComponent::createMenu (WatchType type, bool isCurve) {
382
364
juce::PopupMenu menu;
383
365
384
- menu.addItem (1 , this ->nameTrans [" cpu" ], true , currentName == " cpu" , nullptr );
385
- menu.addItem (2 , this ->nameTrans [" audio" ], true , currentName == " audio" , nullptr );
386
- menu.addItem (3 , this ->nameTrans [" mem" ], true , currentName == " mem" , nullptr );
387
- menu.addItem (4 , this ->nameTrans [" mem-process" ], true , currentName == " mem-process" , nullptr );
366
+ for (int i = 0 ; i < WatchType::TotalNum; i++) {
367
+ menu.addItem (i + 1 , this ->watchName [i], true , type == i);
368
+ }
388
369
389
370
menu.addSeparator ();
390
371
391
- menu.addItem (101 , " 10" , isCurve, currentPoints == 10 , nullptr );
392
- menu.addItem (102 , " 20" , isCurve, currentPoints == 20 , nullptr );
393
- menu.addItem (103 , " 50" , isCurve, currentPoints == 50 , nullptr );
372
+ int currentPoints = this ->curveData .size ();
373
+ menu.addItem (110 , " 10" , isCurve, currentPoints == 10 );
374
+ menu.addItem (120 , " 20" , isCurve, currentPoints == 20 );
375
+ menu.addItem (150 , " 50" , isCurve, currentPoints == 50 );
394
376
395
377
return menu;
396
378
}
0 commit comments