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