Logo ROOT   6.08/07
Reference Guide
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 "TGClient.h"
37 #include "TGResourcePool.h"
38 #include "TImage.h"
39 #include "TEnv.h"
40 #include "TMath.h"
41 
42 #include "TGSpeedo.h"
43 
44 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// TGSpeedo widget constructor.
49 
50 TGSpeedo::TGSpeedo(const TGWindow *p, int id)
51  : TGFrame(p, 1, 1), TGWidget (id), fImage(0), fImage2(0), fBase(0)
52 {
53  fAngleMin = -133.5;
54  fAngleMax = 133.5;
55  fAngle = -133.5;
56  fScaleMin = 0.0;
57  fScaleMax = 100.0;
58  fValue = 0.0;
59  fCounter = 0;
60  fPeakMark = kFALSE;
61  fMeanMark = kFALSE;
62  fPeakVal = 0.0;
63  fMeanVal = 0.0;
64  fTextFS = fCounterFS = kNone;
65  fThreshold[0] = fThreshold[1] = fThreshold[2] = 0.0;
66  fThresholdColor[0] = kGreen;
67  fThresholdColor[1] = kOrange;
68  fThresholdColor[2] = kRed;
69  fThresholdActive = kFALSE;
70  fPicName = "speedo.gif";
71  fImage = TImage::Open(fPicName);
72  if (!fImage || !fImage->IsValid())
73  Error("TGSpeedo::Build", "%s not found", fPicName.Data());
74  Build();
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// TGSpeedo widget constructor.
80 
82  const char *lbl1, const char *lbl2, const char *dsp1,
83  const char *dsp2, int id)
84  : TGFrame(p, 1, 1), TGWidget (id), fImage(0), fImage2(0), fBase(0)
85 {
86  fAngleMin = -133.5;
87  fAngleMax = 133.5;
88  fAngle = -133.5;
89  fScaleMin = smin;
90  fScaleMax = smax;
91  fValue = smin;
92  fCounter = 0;
93  fLabel1 = lbl1;
94  fLabel2 = lbl2;
95  fDisplay1 = dsp1;
96  fDisplay2 = dsp2;
97  fPeakMark = kFALSE;
98  fMeanMark = kFALSE;
99  fPeakVal = 0.0;
100  fMeanVal = 0.0;
102  fThreshold[0] = fThreshold[1] = fThreshold[2] = 0.0;
103  fThresholdColor[0] = kGreen;
105  fThresholdColor[2] = kRed;
107  fPicName = "speedo.gif";
109  if (!fImage || !fImage->IsValid())
110  Error("TGSpeedo::Build", "%s not found", fPicName.Data());
111  Build();
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Build TGSpeedo widget.
117 
119 {
120  TString sc;
121  Float_t step, mark[5];
122  TString fp = gEnv->GetValue("Root.TTFontPath", "");
123  TString ar = fp + "/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()) {
140  fImage->GetPixmap(), fImage->GetMask());
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)
224  return TGDimension(fBase->GetWidth(), fBase->GetHeight());
225  return TGDimension(100, 100);
226 }
227 
228 ////////////////////////////////////////////////////////////////////////////////
229 /// Make speedo glowing.
230 
232 {
233  static EGlowColor act_col = kNoglow;
234  TImage *glowImage = 0;
235 
236  if (col == act_col)
237  return;
238 
239  if (fImage && fImage->IsValid())
240  delete fImage;
241 
242  switch (col) {
243  case kNoglow:
244  break;
245  case kGreen:
246  glowImage = TImage::Open("glow_green.png");
247  if (!glowImage || !glowImage->IsValid()) {
248  Error("TGSpeedo::Glow", "glow_green.png not found");
249  glowImage = 0;
250  }
251  break;
252  case kOrange:
253  glowImage = TImage::Open("glow_orange.png");
254  if (!glowImage || !glowImage->IsValid()) {
255  Error("TGSpeedo::Glow", "glow_orange.png not found");
256  glowImage = 0;
257  }
258  break;
259  case kRed:
260  glowImage = TImage::Open("glow_red.png");
261  if (!glowImage || !glowImage->IsValid()) {
262  Error("TGSpeedo::Glow", "glow_red.png not found");
263  glowImage = 0;
264  }
265  break;
266  }
268  if (fImage && fImage->IsValid() && glowImage && glowImage->IsValid()) {
269  fImage->Merge(glowImage);
270  delete glowImage;
271  }
272  act_col = col;
273  Build();
274  DrawText();
275 }
276 
277 ////////////////////////////////////////////////////////////////////////////////
278 /// Handle mouse button event.
279 
281 {
282  if (fBase) {
283  int xc = (fBase->GetWidth() + 1) / 2;
284  int yc = (fBase->GetHeight() + 1) / 2;
285  if (event->fType == kButtonRelease && event->fCode == kButton1) {
286  // check if in the selector area
287  if ((event->fX > (xc - 26)) && (event->fX < (xc + 26)) &&
288  (event->fY < (yc + 50)) && (event->fY > (yc + 28))) {
289  OdoClicked();
290  }
291  // check if in the led area
292  else if ((event->fX > (xc + 30)) && (event->fX < (xc + 40)) &&
293  (event->fY > (yc + 57)) && (event->fY < (yc + 67))) {
294  LedClicked();
295  }
296  }
297  if (event->fType == kButtonRelease && event->fCode == kButton3) {
298  ResetPeakVal();
299  }
300  }
301  return kTRUE;
302 }
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 /// Set actual value of odo meter.
306 
308 {
309  // avoid useless redraw
310  if (val == fCounter)
311  return;
312  fCounter = val;
313  DrawText();
314  DrawNeedle();
315 }
316 
317 ////////////////////////////////////////////////////////////////////////////////
318 /// Set small display text (two lines).
319 
320 void TGSpeedo::SetDisplayText(const char *text1, const char *text2)
321 {
322  if (!(fDisplay1.CompareTo(text1)) &&
323  !(fDisplay2.CompareTo(text2)))
324  return;
325  fDisplay1 = text1;
326  fDisplay2 = text2;
327  DrawText();
328  DrawNeedle();
329 }
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 /// Set main label text (two lines).
333 
334 void TGSpeedo::SetLabelText(const char *text1, const char *text2)
335 {
336  if (fImage && fImage->IsValid())
337  delete fImage;
338  fLabel1 = text1;
339  fLabel2 = text2;
341  if (!fImage || !fImage->IsValid())
342  Error("TGSpeedo::Build", "%s not found", fPicName.Data());
343  Build();
344  DrawText();
345 }
346 
347 ////////////////////////////////////////////////////////////////////////////////
348 /// Set min and max scale values.
349 
351 {
352  if (fImage && fImage->IsValid())
353  delete fImage;
354  fScaleMin = min;
355  fScaleMax = max;
357  if (!fImage || !fImage->IsValid())
358  Error("TGSpeedo::Build", "%s not found", fPicName.Data());
359  Build();
360  DrawText();
361 }
362 
363 ////////////////////////////////////////////////////////////////////////////////
364 /// Set actual scale (needle position) value.
365 
367 {
368  // avoid useless redraw
369  if (val == fValue)
370  return;
371 
372  fValue = val;
373  if (fValue > fScaleMax)
374  fValue = fScaleMax;
375  else if (fValue < fScaleMin)
376  fValue = fScaleMin;
377 
378  if (fThresholdActive) {
379  if (fValue < fThreshold[0])
380  Glow(kNoglow);
381  if (fValue >= fThreshold[0] && fValue < fThreshold[1])
382  Glow(fThresholdColor[0]);
383  if (fValue >= fThreshold[1] && fValue < fThreshold[2])
384  Glow(fThresholdColor[1]);
385  if (fValue >= fThreshold[2])
386  Glow(fThresholdColor[2]);
387  }
388  if (fValue > fPeakVal)
389  fPeakVal = fValue;
390 
392  (fAngleMax - fAngleMin)));
393 
394  if (fAngle > fAngleMax)
395  fAngle = fAngleMax;
396  else if (fAngle < fAngleMin)
397  fAngle = fAngleMin;
398  DrawNeedle();
399 }
400 
401 ////////////////////////////////////////////////////////////////////////////////
402 /// Set actual scale (needle position) value.
403 
405 {
406  Float_t i;
407  Float_t old_val = fValue;
408  Float_t step, new_val = val;
409  // avoid useless redraw
410  if (val == fValue)
411  return;
412 
413  if ((damping > 0) || (gVirtualX->InheritsFrom("TGX11")))
414  step = 2.0;
415  else
416  step = 0.15;
417 
418  Float_t diff_angle = fAngleMax - fAngleMin;
419  Float_t diff_scale = fScaleMax - fScaleMin;
420  Float_t diff_ratio = diff_scale / diff_angle;
421  Float_t old_angle = fAngleMin + (old_val / diff_ratio);
422  Float_t new_angle = fAngleMin + (new_val / diff_ratio);
423 
424  if (new_angle > old_angle) {
425  for (i=old_angle; i<new_angle; i+=step) {
426  new_val = (i - fAngleMin) * diff_ratio;
427  SetScaleValue(new_val);
428  if (damping > 0)
429  gSystem->Sleep(damping);
430  }
431  }
432  if (new_angle < old_angle) {
433  for (i=old_angle; i>new_angle; i-=step) {
434  new_val = (i - fAngleMin) * diff_ratio;
435  SetScaleValue(new_val);
436  if (damping > 0)
437  gSystem->Sleep(damping);
438  }
439  }
440  // Last step
441  SetScaleValue(val);
442 }
443 
444 ////////////////////////////////////////////////////////////////////////////////
445 /// Increment/decrement scale (needle position) of "step" value.
446 
448 {
449  SetScaleValue(fValue + step);
450 }
451 
452 ////////////////////////////////////////////////////////////////////////////////
453 /// Translate distance from center and angle to xy coordinates.
454 
456 {
457  Float_t xc = (Float_t)(fBase ? (fBase->GetWidth() + 1) / 2 : 96.0);
458  Float_t yc = (Float_t)(fBase ? (fBase->GetHeight() + 1) / 2 : 96.0);
459  *x = (Int_t)(xc + val * sin(angle * TMath::Pi() / 180) + 0.5);
460  *y = (Int_t)(yc - val * cos(angle * TMath::Pi() / 180) + 0.5);
461 }
462 
463 ////////////////////////////////////////////////////////////////////////////////
464 /// Draw needle in speedo widget.
465 
467 {
468  Int_t xch0, xch1, ych0, ych1;
469  Int_t xpk0, ypk0, xpk1, ypk1;
470  Int_t xmn0, ymn0, xmn1, ymn1;
471  fValue = (fAngle - fAngleMin) * ((fScaleMax - fScaleMin) /
472  (fAngleMax - fAngleMin));
473 
474  // compute x/y position of the needle
475  Translate(9.0, fAngle, &xch0, &ych0);
476  Translate(73.0, fAngle, &xch1, &ych1);
477 
478  // compute x/y position of the peak mark
479  Float_t angle = fAngleMin + (fPeakVal / ((fScaleMax - fScaleMin) /
480  (fAngleMax - fAngleMin)));
481  Translate(80.0, angle, &xpk0, &ypk0);
482  Translate(67.0, angle, &xpk1, &ypk1);
483 
484  // compute x/y position of the peak mark
485  angle = fAngleMin + (fMeanVal / ((fScaleMax - fScaleMin) /
486  (fAngleMax - fAngleMin)));
487  Translate(80.0, angle, &xmn0, &ymn0);
488  Translate(70.0, angle, &xmn1, &ymn1);
489 
490  if (fImage2 && fImage2->IsValid()) {
491  // First clone original image.
492  TImage *img = (TImage*)fImage2->Clone("img");
493  if (!img || !img->IsValid()) return;
494  if (fPeakMark) {
495  img->DrawLine(xpk0, ypk0, xpk1, ypk1, "#00ff00", 3);
496  img->DrawLine(xpk0, ypk0, xpk1, ypk1, "#ffffff", 1);
497  }
498  if (fMeanMark) {
499  img->DrawLine(xmn0, ymn0, xmn1, ymn1, "#ffff00", 3);
500  img->DrawLine(xmn0, ymn0, xmn1, ymn1, "#ff0000", 1);
501  }
502  // draw line (used to render the needle) directly on the image
503  img->DrawLine(xch0, ych0, xch1, ych1, "#ff0000", 2);
504  // finally paint image to the widget
505  img->PaintImage(fId, 0, 0, 0, 0, 0, 0, "opaque");
506  // and finally, to avoid memory leaks
507  delete img;
508  }
509  gVirtualX->Update();
510 }
511 
512 ////////////////////////////////////////////////////////////////////////////////
513 /// Draw text in speedo widget.
514 
516 {
517  char sval[80];
518  char dsval[80];
519  Int_t strSize;
520 
521  // center of the image
522  Float_t xc = fBase ? (fBase->GetWidth() + 1) / 2 : 96.0;
523  Float_t yc = fBase ? (fBase->GetHeight() + 1) / 2 : 96.0;
524 
525  if (fImage && fImage->IsValid()) {
526  // First clone original image.
527  if (fImage2 && fImage2->IsValid())
528  delete fImage2;
529  fImage2 = (TImage*)fImage->Clone("fImage2");
530  if (!fImage2 || !fImage2->IsValid()) return;
531  TString fp = gEnv->GetValue("Root.TTFontPath", "");
532  TString ar = fp + "/arialbd.ttf";
533  // format counter value
534  Int_t nexe = 0;
535  Int_t ww = fCounter;
536  if (fCounter >= 10000) {
537  while (1) {
538  nexe++;
539  ww /= 10;
540  if (nexe%3 == 0 && ww < 10000) break;
541  }
542  fImage2->DrawText((Int_t)xc - 9, (Int_t)yc + 72, "x10", 10, "#ffffff", ar);
543  snprintf(sval, 80, "%d", nexe);
544  fImage2->DrawText((Int_t)xc + 9, (Int_t)yc + 69, sval, 8, "#ffffff", ar);
545  }
546  snprintf(sval, 80, "%04d", (int)ww);
547  snprintf(dsval, 80, "%c %c %c %c", sval[0], sval[1], sval[2], sval[3]);
548  // draw text in the counter
549  if (gVirtualX->InheritsFrom("TGX11")) {
550  // as there is a small difference between Windows and Linux...
551  fImage2->DrawText((Int_t)xc - 18, (Int_t)yc + 55, dsval, 12, "#ffffff", ar);
552  }
553  else {
554  fImage2->DrawText((Int_t)xc - 16, (Int_t)yc + 56, dsval, 12, "#ffffff", ar);
555  }
556  // compute the size of the string to draw in the small display box
557  // first line
558  strSize = gVirtualX->TextWidth(fTextFS, fDisplay1.Data(), fDisplay1.Length()) - 6;
559  // draw text directly on the imaget_t)yc + 29, fDispla
560  fImage2->DrawText((Int_t)xc - (strSize / 2), (Int_t)yc + 29, fDisplay1.Data(), 8, "#ffffff", ar);
561  // second line
562  strSize = gVirtualX->TextWidth(fTextFS, fDisplay2.Data(), fDisplay2.Length()) - 6;
563  fImage2->DrawText((Int_t)xc - (strSize / 2), (Int_t)yc + 38, fDisplay2.Data(), 8, "#ffffff", ar);
564  }
565 }
566 
567 ////////////////////////////////////////////////////////////////////////////////
568 /// Redraw speedo widget.
569 
571 {
572  char sval[80];
573  char dsval[80];
574  Int_t strSize;
575  Int_t xch0, xch1, ych0, ych1;
576  Int_t xpk0, ypk0, xpk1, ypk1;
577  Int_t xmn0, ymn0, xmn1, ymn1;
578  static Bool_t first = kTRUE;
579  if (first) {
581  first = kFALSE;
582  }
583  fValue = (fAngle - fAngleMin) * ((fScaleMax - fScaleMin) /
584  (fAngleMax - fAngleMin));
585 
586  // center of the image
587  Float_t xc = fBase ? (fBase->GetWidth() + 1) / 2 : 96.0;
588  Float_t yc = fBase ? (fBase->GetHeight() + 1) / 2 : 96.0;
589 
590  // compute x/y position of the needle
591  Translate(9.0, fAngle, &xch0, &ych0);
592  Translate(73.0, fAngle, &xch1, &ych1);
593 
594  // compute x/y position of the peak mark
595  Float_t angle = fAngleMin + (fPeakVal / ((fScaleMax - fScaleMin) /
596  (fAngleMax - fAngleMin)));
597  Translate(80.0, angle, &xpk0, &ypk0);
598  Translate(67.0, angle, &xpk1, &ypk1);
599 
600  // compute x/y position of the peak mark
601  angle = fAngleMin + (fMeanVal / ((fScaleMax - fScaleMin) /
602  (fAngleMax - fAngleMin)));
603  Translate(80.0, angle, &xmn0, &ymn0);
604  Translate(70.0, angle, &xmn1, &ymn1);
605 
606  if (fImage && fImage->IsValid()) {
607  // First clone original image.
608  if (fImage2 && fImage2->IsValid())
609  delete fImage2;
610  fImage2 = (TImage*)fImage->Clone("fImage2");
611  if (!fImage2 || !fImage2->IsValid()) return;
612  TString fp = gEnv->GetValue("Root.TTFontPath", "");
613  TString ar = fp + "/arialbd.ttf";
614  // format counter value
615  Int_t nexe = 0;
616  Int_t ww = fCounter;
617  if (fCounter >= 10000) {
618  while (1) {
619  nexe++;
620  ww /= 10;
621  if (nexe%3 == 0 && ww < 10000) break;
622  }
623  fImage2->DrawText((Int_t)xc - 9, (Int_t)yc + 72, "x10", 10, "#ffffff", ar);
624  snprintf(sval, 80, "%d", nexe);
625  fImage2->DrawText((Int_t)xc + 9, (Int_t)yc + 69, sval, 8, "#ffffff", ar);
626  }
627  snprintf(sval, 80, "%04d", (int)ww);
628  snprintf(dsval, 80, "%c %c %c %c", sval[0], sval[1], sval[2], sval[3]);
629  // draw text in the counter
630  if (gVirtualX->InheritsFrom("TGX11")) {
631  // as there is a small difference between Windows and Linux...
632  fImage2->DrawText((Int_t)xc - 18, (Int_t)yc + 55, dsval, 12, "#ffffff", ar);
633  }
634  else {
635  fImage2->DrawText((Int_t)xc - 16, (Int_t)yc + 56, dsval, 12, "#ffffff", ar);
636  }
637  // compute the size of the string to draw in the small display box
638  // first line
639  strSize = gVirtualX->TextWidth(fTextFS, fDisplay1.Data(), fDisplay1.Length()) - 6;
640  // draw text directly on the imaget_t)yc + 29, fDispla
641  fImage2->DrawText((Int_t)xc - (strSize / 2), (Int_t)yc + 29, fDisplay1.Data(), 8, "#ffffff", ar);
642  // second line
643  strSize = gVirtualX->TextWidth(fTextFS, fDisplay2.Data(), fDisplay2.Length()) - 6;
644  fImage2->DrawText((Int_t)xc - (strSize / 2), (Int_t)yc + 38, fDisplay2.Data(), 8, "#ffffff", ar);
645  TImage *img = (TImage*)fImage2->Clone("img");
646  if (!img || !img->IsValid()) return;
647  if (fPeakMark) {
648  img->DrawLine(xpk0, ypk0, xpk1, ypk1, "#00ff00", 3);
649  img->DrawLine(xpk0, ypk0, xpk1, ypk1, "#ffffff", 1);
650  }
651  if (fMeanMark) {
652  img->DrawLine(xmn0, ymn0, xmn1, ymn1, "#ffff00", 3);
653  img->DrawLine(xmn0, ymn0, xmn1, ymn1, "#ff0000", 1);
654  }
655  // draw line (used to render the needle) directly on the image
656  img->DrawLine(xch0, ych0, xch1, ych1, "#ff0000", 2);
657  // finally paint image to the widget
658  img->PaintImage(fId, 0, 0, 0, 0, 0, 0, "opaque");
659  // and finally, to avoid memory leaks
660  delete img;
661  }
662 }
Bool_t fThresholdActive
Definition: TGSpeedo.h:69
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:929
Handle_t FontStruct_t
Definition: GuiTypes.h:40
Int_t fCounter
Definition: TGSpeedo.h:56
float Float_t
Definition: RtypesCore.h:53
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:321
Definition: Rtypes.h:61
TString fDisplay2
Definition: TGSpeedo.h:61
virtual Bool_t IsValid() const
Definition: TImage.h:238
void SetDisplayText(const char *text1, const char *text2="")
Set small display text (two lines).
Definition: TGSpeedo.cxx:320
#define mark(osub)
Definition: triangle.c:1206
void DrawNeedle()
Draw needle in speedo widget.
Definition: TGSpeedo.cxx:466
void StepScale(Float_t step)
Increment/decrement scale (needle position) of "step" value.
Definition: TGSpeedo.cxx:447
Int_t fY
Definition: GuiTypes.h:179
void DrawText()
Draw text in speedo widget.
Definition: TGSpeedo.cxx:515
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
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:455
const Bool_t kFALSE
Definition: Rtypes.h:92
An abstract interface to image processing library.
Definition: TImage.h:37
Definition: Rtypes.h:61
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:180
UInt_t GetHeight() const
Definition: TGPicture.h:74
double cos(double)
virtual Pixmap_t GetPixmap()
Definition: TImage.h:243
Float_t fAngle
Definition: TGSpeedo.h:62
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:412
void SetMinMaxScale(Float_t min, Float_t max)
Set min and max scale values.
Definition: TGSpeedo.cxx:350
Double_t x[n]
Definition: legend1.C:17
Float_t fValue
Definition: TGSpeedo.h:62
TGPicturePool * GetPicturePool() const
Definition: TGClient.h:143
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:442
TString fPicName
Definition: TGSpeedo.h:57
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:306
TGSpeedo(const TGWindow *p=0, int id=-1)
TGSpeedo widget constructor.
Definition: TGSpeedo.cxx:50
TImage * fImage2
Definition: TGSpeedo.h:53
EGlowColor
Definition: TGSpeedo.h:49
virtual TGDimension GetDefaultSize() const
Return default dimension of the widget.
Definition: TGSpeedo.cxx:221
double sin(double)
void SetOdoValue(Int_t val)
Set actual value of odo meter.
Definition: TGSpeedo.cxx:307
void Error(const char *location, const char *msgfmt,...)
Float_t fMeanVal
Definition: TGSpeedo.h:64
void LedClicked()
Definition: TGSpeedo.h:118
TImage * fImage
Definition: TGSpeedo.h:52
Float_t fAngleMax
Definition: TGSpeedo.h:65
const Mask_t kButtonPressMask
Definition: GuiTypes.h:162
void ResetPeakVal()
Definition: TGSpeedo.h:114
FontStruct_t fTextFS
Definition: TGSpeedo.h:55
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:251
void SetScaleValue(Float_t val)
Set actual scale (needle position) value.
Definition: TGSpeedo.cxx:366
Bool_t fPeakMark
Definition: TGSpeedo.h:70
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
EGEventType fType
Definition: GuiTypes.h:176
PyObject * fValue
void Glow(EGlowColor col=kGreen)
Make speedo glowing.
Definition: TGSpeedo.cxx:231
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:496
TString fLabel2
Definition: TGSpeedo.h:59
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2322
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
void SetLabelText(const char *text1, const char *text2="")
Set main label text (two lines).
Definition: TGSpeedo.cxx:334
const Handle_t kNone
Definition: GuiTypes.h:89
Ssiz_t Length() const
Definition: TString.h:390
virtual TObject * Clone(const char *) const
Make a clone of an object using the Streamer facility.
Definition: TImage.h:119
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:79
virtual ~TGSpeedo()
TGSpeedo widget Destructor.
Definition: TGSpeedo.cxx:208
FontStruct_t fCounterFS
Definition: TGSpeedo.h:55
TString fDisplay1
Definition: TGSpeedo.h:60
#define gVirtualX
Definition: TVirtualX.h:362
Double_t Pi()
Definition: TMath.h:44
void Build()
Build TGSpeedo widget.
Definition: TGSpeedo.cxx:118
Float_t fScaleMin
Definition: TGSpeedo.h:66
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:208
Float_t fScaleMax
Definition: TGSpeedo.h:66
#define ClassImp(name)
Definition: Rtypes.h:279
virtual Pixmap_t GetMask()
Definition: TImage.h:244
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:163
UInt_t fCode
Definition: GuiTypes.h:181
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
Definition: TGFont.h:155
FontStruct_t GetFontStruct() const
Definition: TGFont.h:199
Double_t y[n]
Definition: legend1.C:17
UInt_t GetWidth() const
Definition: TGPicture.h:73
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:386
Handle_t fId
Definition: TGObject.h:40
virtual void DrawLine(UInt_t, UInt_t, UInt_t, UInt_t, const char *="#000000", UInt_t=1)
Definition: TImage.h:192
Bool_t fMeanMark
Definition: TGSpeedo.h:71
Float_t fAngleMin
Definition: TGSpeedo.h:65
EGlowColor fThresholdColor[3]
Definition: TGSpeedo.h:68
TGClient * fClient
Definition: TGObject.h:41
Float_t fPeakVal
Definition: TGSpeedo.h:63
Pixmap_t GetMask() const
Definition: TGPicture.h:76
#define snprintf
Definition: civetweb.c:822
TString fLabel1
Definition: TGSpeedo.h:58
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:110
const TGPicture * fBase
Definition: TGSpeedo.h:54
Definition: first.py:1
void OdoClicked()
Definition: TGSpeedo.h:117
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t fX
Definition: GuiTypes.h:179
Definition: Rtypes.h:62
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
Definition: TGSpeedo.cxx:280
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get a font from the font pool.
Definition: TGClient.cxx:346
virtual void DoRedraw()
Redraw speedo widget.
Definition: TGSpeedo.cxx:570
Float_t fThreshold[3]
Definition: TGSpeedo.h:67
const char * Data() const
Definition: TString.h:349