Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGSpeedo.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id: TGSpeedo.cxx
2// Author: Bertrand Bellenot 26/10/06
3
4/*************************************************************************
5 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13/** \class TGSpeedo
14 \ingroup guiwidgets
15
16TGSpeedo is a widget looking like a speedometer, with a needle,
17a counter and a small odometer window.
18
19Three thresholds are configurable, with their glowing color
20A peak mark can be enabled, allowing to keep track of the highest
21value displayed. The mark can be reset by right-clicking on the
22widget.
23
24Two signals are available:
25 - OdoClicked(): when user click on the small odometer window
26 - LedClicked(): when user click on the small led near the counter
27
28*/
29
30
31#include "TSystem.h"
32#include "TGResourcePool.h"
33#include "TImage.h"
34#include "TMath.h"
35#include "TVirtualX.h"
36#include "snprintf.h"
37
38#include "TGSpeedo.h"
39#include <numeric>
40
41
43
44////////////////////////////////////////////////////////////////////////////////
45/// TGSpeedo widget constructor.
46
48 : TGFrame(p, 1, 1), TGWidget (id), fImage(0), fImage2(0), fBase(0)
49{
50 fAngleMin = -133.5;
51 fAngleMax = 133.5;
52 fAngle = -133.5;
53 fScaleMin = 0.0;
54 fScaleMax = 100.0;
55 fValue = 0.0;
56 fCounter = 0;
59 fPeakVal = 0.0;
60 fMeanVal = 0.0;
62 fThreshold[0] = fThreshold[1] = fThreshold[2] = 0.0;
67 fPicName = "speedo.gif";
69 if (!fImage || !fImage->IsValid())
70 Error("TGSpeedo::Build", "%s not found", fPicName.Data());
71 fBufferCount = 0;
72 fBufferSize = 0;
73 Build();
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// TGSpeedo widget constructor.
79
81 const char *lbl1, const char *lbl2, const char *dsp1,
82 const char *dsp2, int id)
83 : TGFrame(p, 1, 1), TGWidget (id), fImage(0), fImage2(0), fBase(0)
84{
85 fAngleMin = -133.5;
86 fAngleMax = 133.5;
87 fAngle = -133.5;
88 fScaleMin = smin;
89 fScaleMax = smax;
90 fValue = smin;
91 fCounter = 0;
92 fLabel1 = lbl1;
93 fLabel2 = lbl2;
94 fDisplay1 = dsp1;
95 fDisplay2 = dsp2;
98 fPeakVal = 0.0;
99 fMeanVal = 0.0;
101 fThreshold[0] = fThreshold[1] = fThreshold[2] = 0.0;
106 fPicName = "speedo.gif";
108 if (!fImage || !fImage->IsValid())
109 Error("TGSpeedo::Build", "%s not found", fPicName.Data());
110 fBufferCount = 0;
111 fBufferSize = 0;
112 Build();
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Build TGSpeedo widget.
118
120{
121 TString sc;
122 Float_t step, mark[5];
123 TString ar = "arialbd.ttf";
124 Int_t i, nexe, offset;
125
126 const TGFont *counterFont = fClient->GetFont("-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
127 if (!counterFont) return;
128 fCounterFS = counterFont->GetFontStruct();
129
130 const TGFont *textFont = fClient->GetFont("-*-helvetica-bold-r-*-*-8-*-*-*-*-*-*-*");
131 if (!textFont) return;
132 fTextFS = textFont->GetFontStruct();
133
134 const TGFont *labelFont = fClient->GetFont("-*-helvetica-bold-r-*-*-14-*-*-*-*-*-*-*");
135 if (!labelFont) return;
136 FontStruct_t labelFS = labelFont->GetFontStruct();
137
138 if (fImage && fImage->IsValid()) {
141 // center of the image
142 Float_t xc = (Float_t)(fBase ? (fBase->GetWidth() + 1) / 2 : 96.0);
143 Float_t yc = (Float_t)(fBase ? (fBase->GetHeight() + 1) / 2 : 96.0);
144
145 // compute scale ticks steps
146 step = (fScaleMax - fScaleMin) / 4.0;
147 mark[0] = fScaleMin;
148 mark[4] = fScaleMax;
149 for (i=1; i<4; i++) {
150 mark[i] = mark[i-1] + step;
151 }
152 // format tick labels
153 if (fScaleMax >= 1000.0) {
154 nexe = 0;
155 while (1) {
156 nexe++;
157 for (i=0; i<5; i++) {
158 mark[i] /= 10.0;
159 }
160 // coverity[loop_condition]: ignore - false positive
161 if (mark[4] < 1000.0) break;
162 }
163 // draw multiplier
164 fImage->DrawText((Int_t)xc - 11, (Int_t)yc + 15, "x10", 12, "#ffffff", ar);
165 sc.Form("%d", nexe);
166 fImage->DrawText((Int_t)xc + 11, (Int_t)yc + 13, sc.Data(), 10, "#ffffff", ar);
167 }
168 else if (fScaleMax < 100.0) {
169 nexe = 0;
170 while (1) {
171 nexe--;
172 for (i=0; i<5; i++) {
173 mark[i] *= 10.0;
174 }
175 // coverity[loop_condition]: ignore - false positive
176 if (mark[4] > 99.9 ) break;
177 }
178 // draw multiplier
179 fImage->DrawText((Int_t)xc - 11, (Int_t)yc + 15, "x10", 12, "#ffffff", ar);
180 sc.Form("%d", nexe);
181 fImage->DrawText((Int_t)xc + 11, (Int_t)yc + 13, sc.Data(), 10, "#ffffff", ar);
182 }
183 // Format and draw scale tickmarks
184 sc.Form("%d",(Int_t)mark[0]);
185 fImage->DrawText((Int_t)xc - 51, (Int_t)yc + 30, sc.Data(), 14, "#ffffff", ar);
186 sc.Form("%d",(Int_t)mark[1]);
187 fImage->DrawText((Int_t)xc - 59, (Int_t)yc - 29, sc.Data(), 14, "#ffffff", ar);
188 sc.Form("%d",(Int_t)mark[2]);
189 offset = gVirtualX->TextWidth(labelFS, sc.Data(), sc.Length()) / 2;
190 fImage->DrawText((Int_t)xc - offset, (Int_t)yc - 65, sc.Data(), 14, "#ffffff", ar);
191 sc.Form("%d",(Int_t)mark[3]);
192 offset = 60 - gVirtualX->TextWidth(labelFS, sc.Data(), sc.Length());
193 fImage->DrawText((Int_t)xc + offset, (Int_t)yc - 29, sc.Data(), 14, "#ffffff", ar);
194 sc.Form("%d",(Int_t)mark[4]);
195 offset = 52 - gVirtualX->TextWidth(labelFS, sc.Data(), sc.Length());
196 fImage->DrawText((Int_t)xc + offset, (Int_t)yc + 30, sc.Data(), 14, "#ffffff", ar);
197 // draw main label (two lines)
198 fImage->DrawText((Int_t)xc + 13, (Int_t)yc - 17, fLabel1.Data(), 14, "#ffffff", ar);
199 fImage->DrawText((Int_t)xc + 13, (Int_t)yc - 4, fLabel2.Data(), 12, "#ffffff", ar);
200 if (fBase)
201 gVirtualX->ShapeCombineMask(fId, 0, 0, fBase->GetMask());
202 }
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// TGSpeedo widget Destructor.
207
209{
210 if (fImage && fImage->IsValid())
211 delete fImage;
212 if (fImage2 && fImage2->IsValid())
213 delete fImage2;
214 if (fBase)
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Return default dimension of the widget.
220
222{
223 if (fBase)
225 return TGDimension(100, 100);
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Compute and return the mean of the circular buffer content.
230
232{
233 if ((fBufferSize == 0) || (fBuffer.size() == 0))
234 return fMeanVal;
235 return std::accumulate(fBuffer.begin(), fBuffer.end(), 0.0f) / fBuffer.size();
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Make speedo glowing.
240
242{
243 static EGlowColor act_col = kNoglow;
244 TImage *glowImage = 0;
245
246 if (col == act_col)
247 return;
248
249 if (fImage && fImage->IsValid())
250 delete fImage;
251
252 switch (col) {
253 case kNoglow:
254 break;
255 case kGreen:
256 glowImage = TImage::Open("glow_green.png");
257 if (!glowImage || !glowImage->IsValid()) {
258 Error("TGSpeedo::Glow", "glow_green.png not found");
259 glowImage = 0;
260 }
261 break;
262 case kOrange:
263 glowImage = TImage::Open("glow_orange.png");
264 if (!glowImage || !glowImage->IsValid()) {
265 Error("TGSpeedo::Glow", "glow_orange.png not found");
266 glowImage = 0;
267 }
268 break;
269 case kRed:
270 glowImage = TImage::Open("glow_red.png");
271 if (!glowImage || !glowImage->IsValid()) {
272 Error("TGSpeedo::Glow", "glow_red.png not found");
273 glowImage = 0;
274 }
275 break;
276 }
278 if (fImage && fImage->IsValid() && glowImage && glowImage->IsValid()) {
279 fImage->Merge(glowImage);
280 delete glowImage;
281 }
282 act_col = col;
283 Build();
284 DrawText();
285}
286
287////////////////////////////////////////////////////////////////////////////////
288/// Handle mouse button event.
289
291{
292 if (fBase) {
293 int xc = (fBase->GetWidth() + 1) / 2;
294 int yc = (fBase->GetHeight() + 1) / 2;
295 if (event->fType == kButtonRelease && event->fCode == kButton1) {
296 // check if in the selector area
297 if ((event->fX > (xc - 26)) && (event->fX < (xc + 26)) &&
298 (event->fY < (yc + 50)) && (event->fY > (yc + 28))) {
299 OdoClicked();
300 }
301 // check if in the led area
302 else if ((event->fX > (xc + 30)) && (event->fX < (xc + 40)) &&
303 (event->fY > (yc + 57)) && (event->fY < (yc + 67))) {
304 LedClicked();
305 }
306 }
307 if (event->fType == kButtonRelease && event->fCode == kButton3) {
308 ResetPeakVal();
309 }
310 }
311 return kTRUE;
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// Change the circular buffer size (used for the automatic mean calculation).
316/// SetMeanValue is ignored if SetBufferSize is called with a greater-than-zero
317/// argument. The mean value is then automatically calculated by using the sum
318/// of values contained in the buffer divided by their count.
319/// To disable automatic mean calculation, simply call SetBufferSize with a zero
320/// argument
321
323{
324 if (size < 0) size = 0;
326 fBuffer.clear();
327 fBuffer.reserve(fBufferSize);
328 fBufferCount = 0;
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Set actual value of odo meter.
333
335{
336 // avoid useless redraw
337 if (val == fCounter)
338 return;
339 fCounter = val;
340 DrawText();
341 DrawNeedle();
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Set small display text (two lines).
346
347void TGSpeedo::SetDisplayText(const char *text1, const char *text2)
348{
349 if (!(fDisplay1.CompareTo(text1)) &&
350 !(fDisplay2.CompareTo(text2)))
351 return;
352 fDisplay1 = text1;
353 fDisplay2 = text2;
354 DrawText();
355 DrawNeedle();
356}
357
358////////////////////////////////////////////////////////////////////////////////
359/// Set main label text (two lines).
360
361void TGSpeedo::SetLabelText(const char *text1, const char *text2)
362{
363 if (fImage && fImage->IsValid())
364 delete fImage;
365 fLabel1 = text1;
366 fLabel2 = text2;
368 if (!fImage || !fImage->IsValid())
369 Error("TGSpeedo::Build", "%s not found", fPicName.Data());
370 Build();
371 DrawText();
372}
373
374////////////////////////////////////////////////////////////////////////////////
375/// Set min and max scale values.
376
378{
379 if (fImage && fImage->IsValid())
380 delete fImage;
381 fScaleMin = min;
382 fScaleMax = max;
384 if (!fImage || !fImage->IsValid())
385 Error("TGSpeedo::Build", "%s not found", fPicName.Data());
386 Build();
387 DrawText();
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Set actual scale (needle position) value.
392
394{
395 // avoid useless redraw
396 if (val == fValue)
397 return;
398
399 fValue = val;
400 if (fValue > fScaleMax)
402 else if (fValue < fScaleMin)
404
405 if (fThresholdActive) {
406 if (fValue < fThreshold[0])
407 Glow(kNoglow);
408 if (fValue >= fThreshold[0] && fValue < fThreshold[1])
410 if (fValue >= fThreshold[1] && fValue < fThreshold[2])
412 if (fValue >= fThreshold[2])
414 }
415 if (fValue > fPeakVal)
417
418 if (fBufferSize > 0) {
419 if ((Int_t)fBuffer.size() < (fBufferCount + 1))
420 fBuffer.push_back(fValue);
421 else
423 ++fBufferCount;
425 fBufferCount = 0;
426 }
427
429 (fAngleMax - fAngleMin)));
430
431 if (fAngle > fAngleMax)
433 else if (fAngle < fAngleMin)
435 DrawNeedle();
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// Set actual scale (needle position) value.
440
442{
443 Float_t i;
444 Float_t old_val = fValue;
445 Float_t step, new_val = val;
446 // avoid useless redraw
447 if (val == fValue)
448 return;
449
450 if ((damping > 0) || (gVirtualX->InheritsFrom("TGX11")))
451 step = 2.0;
452 else
453 step = 0.15;
454
455 Float_t diff_angle = fAngleMax - fAngleMin;
456 Float_t diff_scale = fScaleMax - fScaleMin;
457 Float_t diff_ratio = diff_scale / diff_angle;
458 Float_t old_angle = fAngleMin + (old_val / diff_ratio);
459 Float_t new_angle = fAngleMin + (new_val / diff_ratio);
460
461 if (new_angle > old_angle) {
462 for (i=old_angle; i<new_angle; i+=step) {
463 new_val = (i - fAngleMin) * diff_ratio;
464 SetScaleValue(new_val);
465 if (damping > 0)
466 gSystem->Sleep(damping);
467 }
468 }
469 if (new_angle < old_angle) {
470 for (i=old_angle; i>new_angle; i-=step) {
471 new_val = (i - fAngleMin) * diff_ratio;
472 SetScaleValue(new_val);
473 if (damping > 0)
474 gSystem->Sleep(damping);
475 }
476 }
477 // Last step
478 SetScaleValue(val);
479}
480
481////////////////////////////////////////////////////////////////////////////////
482/// Increment/decrement scale (needle position) of "step" value.
483
485{
486 SetScaleValue(fValue + step);
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// Translate distance from center and angle to xy coordinates.
491
493{
494 Float_t xc = (Float_t)(fBase ? (fBase->GetWidth() + 1) / 2 : 96.0);
495 Float_t yc = (Float_t)(fBase ? (fBase->GetHeight() + 1) / 2 : 96.0);
496 *x = (Int_t)(xc + val * sin(angle * TMath::Pi() / 180) + 0.5);
497 *y = (Int_t)(yc - val * cos(angle * TMath::Pi() / 180) + 0.5);
498}
499
500////////////////////////////////////////////////////////////////////////////////
501/// Draw needle in speedo widget.
502
504{
505 Int_t xch0, xch1, ych0, ych1;
506 Int_t xpk0, ypk0, xpk1, ypk1;
507 Int_t xmn0, ymn0, xmn1, ymn1;
509 (fAngleMax - fAngleMin));
510
511 // compute x/y position of the needle
512 Translate(9.0, fAngle, &xch0, &ych0);
513 Translate(73.0, fAngle, &xch1, &ych1);
514
515 // compute x/y position of the peak mark
517 (fAngleMax - fAngleMin)));
518 Translate(80.0, angle, &xpk0, &ypk0);
519 Translate(67.0, angle, &xpk1, &ypk1);
520
521 fMeanVal = GetMean();
522
523 // compute x/y position of the mean mark
525 (fAngleMax - fAngleMin)));
526 Translate(80.0, angle, &xmn0, &ymn0);
527 Translate(70.0, angle, &xmn1, &ymn1);
528
529 if (fImage2 && fImage2->IsValid()) {
530 // First clone original image.
531 TImage *img = (TImage*)fImage2->Clone("img");
532 if (!img || !img->IsValid()) return;
533 if (fPeakMark) {
534 img->DrawLine(xpk0, ypk0, xpk1, ypk1, "#00ff00", 3);
535 img->DrawLine(xpk0, ypk0, xpk1, ypk1, "#ffffff", 1);
536 }
537 if (fMeanMark) {
538 img->DrawLine(xmn0, ymn0, xmn1, ymn1, "#ffff00", 3);
539 img->DrawLine(xmn0, ymn0, xmn1, ymn1, "#ff0000", 1);
540 }
541 // draw line (used to render the needle) directly on the image
542 img->DrawLine(xch0, ych0, xch1, ych1, "#ff0000", 2);
543 // finally paint image to the widget
544 img->PaintImage(fId, 0, 0, 0, 0, 0, 0, "opaque");
545 // and finally, to avoid memory leaks
546 delete img;
547 }
548 gVirtualX->Update();
549}
550
551////////////////////////////////////////////////////////////////////////////////
552/// Draw text in speedo widget.
553
555{
556 char sval[80];
557 char dsval[80];
558 Int_t strSize;
559
560 // center of the image
561 Float_t xc = fBase ? (fBase->GetWidth() + 1) / 2 : 96.0;
562 Float_t yc = fBase ? (fBase->GetHeight() + 1) / 2 : 96.0;
563
564 if (fImage && fImage->IsValid()) {
565 // First clone original image.
566 if (fImage2 && fImage2->IsValid())
567 delete fImage2;
568 fImage2 = (TImage*)fImage->Clone("fImage2");
569 if (!fImage2 || !fImage2->IsValid()) return;
570 TString ar = "arialbd.ttf";
571 // format counter value
572 Int_t nexe = 0;
573 Int_t ww = fCounter;
574 if (fCounter >= 10000) {
575 while (1) {
576 nexe++;
577 ww /= 10;
578 if (nexe%3 == 0 && ww < 10000) break;
579 }
580 fImage2->DrawText((Int_t)xc - 9, (Int_t)yc + 72, "x10", 10, "#ffffff", ar);
581 snprintf(sval, 80, "%d", nexe);
582 fImage2->DrawText((Int_t)xc + 9, (Int_t)yc + 69, sval, 8, "#ffffff", ar);
583 }
584 snprintf(sval, 80, "%04d", (int)ww);
585 snprintf(dsval, 80, "%c %c %c %c", sval[0], sval[1], sval[2], sval[3]);
586 // draw text in the counter
587 if (gVirtualX->InheritsFrom("TGX11")) {
588 // as there is a small difference between Windows and Linux...
589 fImage2->DrawText((Int_t)xc - 18, (Int_t)yc + 55, dsval, 12, "#ffffff", ar);
590 }
591 else {
592 fImage2->DrawText((Int_t)xc - 16, (Int_t)yc + 56, dsval, 12, "#ffffff", ar);
593 }
594 // compute the size of the string to draw in the small display box
595 // first line
596 strSize = gVirtualX->TextWidth(fTextFS, fDisplay1.Data(), fDisplay1.Length()) - 6;
597 // draw text directly on the imaget_t)yc + 29, fDispla
598 fImage2->DrawText((Int_t)xc - (strSize / 2), (Int_t)yc + 29, fDisplay1.Data(), 8, "#ffffff", ar);
599 // second line
600 strSize = gVirtualX->TextWidth(fTextFS, fDisplay2.Data(), fDisplay2.Length()) - 6;
601 fImage2->DrawText((Int_t)xc - (strSize / 2), (Int_t)yc + 38, fDisplay2.Data(), 8, "#ffffff", ar);
602 }
603}
604
605////////////////////////////////////////////////////////////////////////////////
606/// Redraw speedo widget.
607
609{
610 char sval[80];
611 char dsval[80];
612 Int_t strSize;
613 Int_t xch0, xch1, ych0, ych1;
614 Int_t xpk0, ypk0, xpk1, ypk1;
615 Int_t xmn0, ymn0, xmn1, ymn1;
616 static Bool_t first = kTRUE;
617 if (first) {
619 first = kFALSE;
620 }
622 (fAngleMax - fAngleMin));
623
624 // center of the image
625 Float_t xc = fBase ? (fBase->GetWidth() + 1) / 2 : 96.0;
626 Float_t yc = fBase ? (fBase->GetHeight() + 1) / 2 : 96.0;
627
628 // compute x/y position of the needle
629 Translate(9.0, fAngle, &xch0, &ych0);
630 Translate(73.0, fAngle, &xch1, &ych1);
631
632 // compute x/y position of the peak mark
634 (fAngleMax - fAngleMin)));
635 Translate(80.0, angle, &xpk0, &ypk0);
636 Translate(67.0, angle, &xpk1, &ypk1);
637
638 // compute x/y position of the peak mark
640 (fAngleMax - fAngleMin)));
641 Translate(80.0, angle, &xmn0, &ymn0);
642 Translate(70.0, angle, &xmn1, &ymn1);
643
644 if (fImage && fImage->IsValid()) {
645 // First clone original image.
646 if (fImage2 && fImage2->IsValid())
647 delete fImage2;
648 fImage2 = (TImage*)fImage->Clone("fImage2");
649 if (!fImage2 || !fImage2->IsValid()) return;
650 TString ar = "arialbd.ttf";
651 // format counter value
652 Int_t nexe = 0;
653 Int_t ww = fCounter;
654 if (fCounter >= 10000) {
655 while (1) {
656 nexe++;
657 ww /= 10;
658 if (nexe%3 == 0 && ww < 10000) break;
659 }
660 fImage2->DrawText((Int_t)xc - 9, (Int_t)yc + 72, "x10", 10, "#ffffff", ar);
661 snprintf(sval, 80, "%d", nexe);
662 fImage2->DrawText((Int_t)xc + 9, (Int_t)yc + 69, sval, 8, "#ffffff", ar);
663 }
664 snprintf(sval, 80, "%04d", (int)ww);
665 snprintf(dsval, 80, "%c %c %c %c", sval[0], sval[1], sval[2], sval[3]);
666 // draw text in the counter
667 if (gVirtualX->InheritsFrom("TGX11")) {
668 // as there is a small difference between Windows and Linux...
669 fImage2->DrawText((Int_t)xc - 18, (Int_t)yc + 55, dsval, 12, "#ffffff", ar);
670 }
671 else {
672 fImage2->DrawText((Int_t)xc - 16, (Int_t)yc + 56, dsval, 12, "#ffffff", ar);
673 }
674 // compute the size of the string to draw in the small display box
675 // first line
676 strSize = gVirtualX->TextWidth(fTextFS, fDisplay1.Data(), fDisplay1.Length()) - 6;
677 // draw text directly on the imaget_t)yc + 29, fDispla
678 fImage2->DrawText((Int_t)xc - (strSize / 2), (Int_t)yc + 29, fDisplay1.Data(), 8, "#ffffff", ar);
679 // second line
680 strSize = gVirtualX->TextWidth(fTextFS, fDisplay2.Data(), fDisplay2.Length()) - 6;
681 fImage2->DrawText((Int_t)xc - (strSize / 2), (Int_t)yc + 38, fDisplay2.Data(), 8, "#ffffff", ar);
682 TImage *img = (TImage*)fImage2->Clone("img");
683 if (!img || !img->IsValid()) return;
684 if (fPeakMark) {
685 img->DrawLine(xpk0, ypk0, xpk1, ypk1, "#00ff00", 3);
686 img->DrawLine(xpk0, ypk0, xpk1, ypk1, "#ffffff", 1);
687 }
688 if (fMeanMark) {
689 img->DrawLine(xmn0, ymn0, xmn1, ymn1, "#ffff00", 3);
690 img->DrawLine(xmn0, ymn0, xmn1, ymn1, "#ff0000", 1);
691 }
692 // draw line (used to render the needle) directly on the image
693 img->DrawLine(xch0, ych0, xch1, ych1, "#ff0000", 2);
694 // finally paint image to the widget
695 img->PaintImage(fId, 0, 0, 0, 0, 0, 0, "opaque");
696 // and finally, to avoid memory leaks
697 delete img;
698 }
699}
@ kButtonRelease
Definition GuiTypes.h:60
const Mask_t kButtonPressMask
Definition GuiTypes.h:161
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:162
@ kButton3
Definition GuiTypes.h:214
@ kButton1
Definition GuiTypes.h:214
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:382
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint angle
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
#define gVirtualX
Definition TVirtualX.h:337
#define snprintf
Definition civetweb.c:1540
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get a font from the font pool.
Definition TGClient.cxx:357
TGPicturePool * GetPicturePool() const
Definition TGClient.h:126
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition TGClient.cxx:317
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
FontStruct_t GetFontStruct() const
Definition TGFont.h:184
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:339
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:430
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition TGPicture.cxx:83
Pixmap_t GetMask() const
Definition TGPicture.h:55
UInt_t GetHeight() const
Definition TGPicture.h:53
UInt_t GetWidth() const
Definition TGPicture.h:52
TGSpeedo is a widget looking like a speedometer, with a needle, a counter and a small odometer window...
Definition TGSpeedo.h:22
const TGPicture * fBase
picture used as background
Definition TGSpeedo.h:30
Int_t fBufferSize
circular buffer size
Definition TGSpeedo.h:48
void SetOdoValue(Int_t val)
Set actual value of odo meter.
Definition TGSpeedo.cxx:334
void ResetPeakVal()
Definition TGSpeedo.h:95
Float_t GetMean()
Compute and return the mean of the circular buffer content.
Definition TGSpeedo.cxx:231
Bool_t HandleButton(Event_t *event) override
Handle mouse button event.
Definition TGSpeedo.cxx:290
TString fLabel1
main label (first line)
Definition TGSpeedo.h:34
void StepScale(Float_t step)
Increment/decrement scale (needle position) of "step" value.
Definition TGSpeedo.cxx:484
FontStruct_t fTextFS
Definition TGSpeedo.h:31
EGlowColor fThresholdColor[3]
glowing threshold colors
Definition TGSpeedo.h:44
void SetDisplayText(const char *text1, const char *text2="")
Set small display text (two lines).
Definition TGSpeedo.cxx:347
Float_t fAngleMin
Definition TGSpeedo.h:41
TString fDisplay1
first line in the small display
Definition TGSpeedo.h:36
Float_t fScaleMin
Definition TGSpeedo.h:42
@ kOrange
Definition TGSpeedo.h:25
@ kNoglow
Definition TGSpeedo.h:25
~TGSpeedo() override
TGSpeedo widget Destructor.
Definition TGSpeedo.cxx:208
Float_t fAngle
Definition TGSpeedo.h:38
void Glow(EGlowColor col=kGreen)
Make speedo glowing.
Definition TGSpeedo.cxx:241
void SetMinMaxScale(Float_t min, Float_t max)
Set min and max scale values.
Definition TGSpeedo.cxx:377
Float_t fMeanVal
mean value mark
Definition TGSpeedo.h:40
TGSpeedo(const TGWindow *p=nullptr, int id=-1)
TGSpeedo widget constructor.
Definition TGSpeedo.cxx:47
Int_t fCounter
small odo meter (4 digits)
Definition TGSpeedo.h:32
TImage * fImage
image used as background
Definition TGSpeedo.h:28
void OdoClicked()
Definition TGSpeedo.h:99
void SetBufferSize(Int_t size)
Change the circular buffer size (used for the automatic mean calculation).
Definition TGSpeedo.cxx:322
FontStruct_t fCounterFS
font structures for text rendering
Definition TGSpeedo.h:31
void DrawText()
Draw text in speedo widget.
Definition TGSpeedo.cxx:554
TString fDisplay2
second line in the small display
Definition TGSpeedo.h:37
Float_t fScaleMax
needle min and max scale
Definition TGSpeedo.h:42
Float_t fPeakVal
maximum peak mark
Definition TGSpeedo.h:39
Int_t fBufferCount
circular buffer count
Definition TGSpeedo.h:49
TString fPicName
name of picture used as background
Definition TGSpeedo.h:33
Bool_t fThresholdActive
kTRUE if glowing thresholds are active
Definition TGSpeedo.h:45
void Translate(Float_t val, Float_t angle, Int_t *x, Int_t *y)
Translate distance from center and angle to xy coordinates.
Definition TGSpeedo.cxx:492
Float_t fThreshold[3]
glowing thresholds
Definition TGSpeedo.h:43
void SetLabelText(const char *text1, const char *text2="")
Set main label text (two lines).
Definition TGSpeedo.cxx:361
TImage * fImage2
intermediate image used as background
Definition TGSpeedo.h:29
void SetScaleValue(Float_t val)
Set actual scale (needle position) value.
Definition TGSpeedo.cxx:393
Bool_t fMeanMark
kTRUE if mean mark is active
Definition TGSpeedo.h:47
std::vector< Float_t > fBuffer
circular buffer for mean calculation
Definition TGSpeedo.h:50
TString fLabel2
main label (second line)
Definition TGSpeedo.h:35
Float_t fAngleMax
needle min and max angle
Definition TGSpeedo.h:41
TGDimension GetDefaultSize() const override
Return default dimension of the widget.
Definition TGSpeedo.cxx:221
void LedClicked()
Definition TGSpeedo.h:100
void Build()
Build TGSpeedo widget.
Definition TGSpeedo.cxx:119
void DoRedraw() override
Redraw speedo widget.
Definition TGSpeedo.cxx:608
void DrawNeedle()
Draw needle in speedo widget.
Definition TGSpeedo.cxx:503
Bool_t fPeakMark
kTRUE if peak mark is active
Definition TGSpeedo.h:46
Float_t fValue
needle angle and corresponding value
Definition TGSpeedo.h:38
The widget base class.
Definition TGWidget.h:43
ROOT GUI Window base class.
Definition TGWindow.h:23
An abstract interface to image processing library.
Definition TImage.h:29
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:118
virtual void DrawText(Int_t=0, Int_t=0, const char *="", Int_t=12, const char *=nullptr, const char *="fixed", EText3DType=TImage::kPlain, const char *=nullptr, Float_t=0)
Definition TImage.h:200
virtual void DrawLine(UInt_t, UInt_t, UInt_t, UInt_t, const char *="#000000", UInt_t=1)
Definition TImage.h:184
virtual Bool_t IsValid() const
Definition TImage.h:230
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition TImage.h:172
virtual Pixmap_t GetPixmap()
Definition TImage.h:235
virtual void PaintImage(Drawable_t, Int_t, Int_t, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0, Option_t *="")
Definition TImage.h:243
TObject * Clone(const char *) const override
Make a clone of an object using the Streamer facility.
Definition TImage.h:111
virtual Pixmap_t GetMask()
Definition TImage.h:236
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1005
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:457
const char * Data() const
Definition TString.h:376
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:934
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:437
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
constexpr Double_t Pi()
Definition TMath.h:37
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:178
Int_t fX
Definition GuiTypes.h:178
UInt_t fCode
key or button code
Definition GuiTypes.h:180