// @(#)root/gui:$Id: TGSpeedo.h
// Author: Bertrand Bellenot   26/10/06

/*************************************************************************
 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGSpeedo
#define ROOT_TGSpeedo

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGSpeedo                                                             //
//                                                                      //
// TGSpeedo is a widget looking like a speedometer, with a needle,      //
// a counter and a small odometer window.                               //
//                                                                      //
// Three thresholds are configurable, with their glowing color          //
// A peak mark can be enabled, allowing to keep track of the highest    //
// value displayed. The mark can be reset by right-clicking on the      //
// widget.                                                              //
// Two signals are available:                                           //
//    OdoClicked(): when user click on the small odometer window        //
//    LedClicked(): when user click on the small led near the counter   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGFrame
#include "TGFrame.h"
#endif
#ifndef ROOT_TGWidget
#include "TGWidget.h"
#endif
#ifndef ROOT_TGPicture
#include "TGPicture.h"
#endif
#ifndef ROOT_TImage
#include "TImage.h"
#endif


class TGSpeedo : public TGFrame, public TGWidget {

public:
   enum EGlowColor { kNoglow, kGreen, kOrange, kRed };

protected:
   TImage          *fImage;               // image used as background
   TImage          *fImage2;              // intermediate image used as background
   const TGPicture *fBase;                // picture used as background
   FontStruct_t     fTextFS, fCounterFS;  // font structures for text rendering
   Int_t            fCounter;             // small odo meter (4 digits)
   TString          fPicName;             // name of picture used as background
   TString          fLabel1;              // main label (first line)
   TString          fLabel2;              // main label (second line)
   TString          fDisplay1;            // first line in the small display
   TString          fDisplay2;            // second line in the small display
   Float_t          fAngle, fValue;       // needle angle and corresponding value
   Float_t          fPeakVal;             // maximum peak mark
   Float_t          fMeanVal;             // mean value mark
   Float_t          fAngleMin, fAngleMax; // needle min and max angle
   Float_t          fScaleMin, fScaleMax; // needle min and max scale
   Float_t          fThreshold[3];        // glowing thresholds
   EGlowColor       fThresholdColor[3];   // glowing threshold colors
   Bool_t           fThresholdActive;     // kTRUE if glowing threhsholds are active
   Bool_t           fPeakMark;            // kTRUE if peak mark is active
   Bool_t           fMeanMark;            // kTRUE if mean mark is active

   virtual void     DoRedraw();
           void     DrawNeedle();
           void     DrawText();
           void     Translate(Float_t val, Float_t angle, Int_t *x, Int_t *y);

public:
   TGSpeedo(const TGWindow *p = 0, int id = -1);
   TGSpeedo(const TGWindow *p, Float_t smin, Float_t smax,
            const char *lbl1 = "", const char *lbl2 = "",
            const char *dsp1 = "", const char *dsp2 = "", int id = -1);
   virtual ~TGSpeedo();

   virtual TGDimension  GetDefaultSize() const;
   virtual Bool_t       HandleButton(Event_t *event);

   const TGPicture     *GetPicture() const { return fBase; }
   TImage              *GetImage() const { return fImage; }
   Float_t              GetPeakVal() const { return fPeakVal; }
   Float_t              GetScaleMin() const { return fScaleMin; }
   Float_t              GetScaleMax() const { return fScaleMax; }
   Bool_t               IsThresholdActive() { return fThresholdActive; }

   void Build();
   void Glow(EGlowColor col = kGreen);
   void StepScale(Float_t step);
   void SetScaleValue(Float_t val);
   void SetScaleValue(Float_t val, Int_t damping);
   void SetOdoValue(Int_t val);
   void SetDisplayText(const char *text1, const char *text2 = "");
   void SetLabelText(const char *text1, const char *text2 = "");
   void SetMinMaxScale(Float_t min, Float_t max);
   void SetThresholds(Float_t th1 = 0.0, Float_t th2 = 0.0, Float_t th3 = 0.0)
             { fThreshold[0] = th1; fThreshold[1] = th2; fThreshold[2] = th3; }
   void SetThresholdColors(EGlowColor col1, EGlowColor col2, EGlowColor col3)
             { fThresholdColor[0] = col1; fThresholdColor[1] = col2; fThresholdColor[2] = col3; }
   void EnableThreshold() { fThresholdActive = kTRUE; }
   void DisableThreshold() { fThresholdActive = kFALSE; Glow(kNoglow); fClient->NeedRedraw(this);}
   void EnablePeakMark() { fPeakMark = kTRUE; }
   void DisablePeakMark() { fPeakMark = kFALSE; }
   void EnableMeanMark() { fMeanMark = kTRUE; }
   void DisableMeanMark() { fMeanMark = kFALSE; }
   void ResetPeakVal() { fPeakVal = fValue; fClient->NeedRedraw(this); }
   void SetMeanValue(Float_t mean) { fMeanVal = mean; fClient->NeedRedraw(this); }

   void OdoClicked() { Emit("OdoClicked()"); }   // *SIGNAL*
   void LedClicked() { Emit("LedClicked()"); }   // *SIGNAL*

   ClassDef(TGSpeedo,0)  // Base class for analog meter widget
};

#endif
 TGSpeedo.h:1
 TGSpeedo.h:2
 TGSpeedo.h:3
 TGSpeedo.h:4
 TGSpeedo.h:5
 TGSpeedo.h:6
 TGSpeedo.h:7
 TGSpeedo.h:8
 TGSpeedo.h:9
 TGSpeedo.h:10
 TGSpeedo.h:11
 TGSpeedo.h:12
 TGSpeedo.h:13
 TGSpeedo.h:14
 TGSpeedo.h:15
 TGSpeedo.h:16
 TGSpeedo.h:17
 TGSpeedo.h:18
 TGSpeedo.h:19
 TGSpeedo.h:20
 TGSpeedo.h:21
 TGSpeedo.h:22
 TGSpeedo.h:23
 TGSpeedo.h:24
 TGSpeedo.h:25
 TGSpeedo.h:26
 TGSpeedo.h:27
 TGSpeedo.h:28
 TGSpeedo.h:29
 TGSpeedo.h:30
 TGSpeedo.h:31
 TGSpeedo.h:32
 TGSpeedo.h:33
 TGSpeedo.h:34
 TGSpeedo.h:35
 TGSpeedo.h:36
 TGSpeedo.h:37
 TGSpeedo.h:38
 TGSpeedo.h:39
 TGSpeedo.h:40
 TGSpeedo.h:41
 TGSpeedo.h:42
 TGSpeedo.h:43
 TGSpeedo.h:44
 TGSpeedo.h:45
 TGSpeedo.h:46
 TGSpeedo.h:47
 TGSpeedo.h:48
 TGSpeedo.h:49
 TGSpeedo.h:50
 TGSpeedo.h:51
 TGSpeedo.h:52
 TGSpeedo.h:53
 TGSpeedo.h:54
 TGSpeedo.h:55
 TGSpeedo.h:56
 TGSpeedo.h:57
 TGSpeedo.h:58
 TGSpeedo.h:59
 TGSpeedo.h:60
 TGSpeedo.h:61
 TGSpeedo.h:62
 TGSpeedo.h:63
 TGSpeedo.h:64
 TGSpeedo.h:65
 TGSpeedo.h:66
 TGSpeedo.h:67
 TGSpeedo.h:68
 TGSpeedo.h:69
 TGSpeedo.h:70
 TGSpeedo.h:71
 TGSpeedo.h:72
 TGSpeedo.h:73
 TGSpeedo.h:74
 TGSpeedo.h:75
 TGSpeedo.h:76
 TGSpeedo.h:77
 TGSpeedo.h:78
 TGSpeedo.h:79
 TGSpeedo.h:80
 TGSpeedo.h:81
 TGSpeedo.h:82
 TGSpeedo.h:83
 TGSpeedo.h:84
 TGSpeedo.h:85
 TGSpeedo.h:86
 TGSpeedo.h:87
 TGSpeedo.h:88
 TGSpeedo.h:89
 TGSpeedo.h:90
 TGSpeedo.h:91
 TGSpeedo.h:92
 TGSpeedo.h:93
 TGSpeedo.h:94
 TGSpeedo.h:95
 TGSpeedo.h:96
 TGSpeedo.h:97
 TGSpeedo.h:98
 TGSpeedo.h:99
 TGSpeedo.h:100
 TGSpeedo.h:101
 TGSpeedo.h:102
 TGSpeedo.h:103
 TGSpeedo.h:104
 TGSpeedo.h:105
 TGSpeedo.h:106
 TGSpeedo.h:107
 TGSpeedo.h:108
 TGSpeedo.h:109
 TGSpeedo.h:110
 TGSpeedo.h:111
 TGSpeedo.h:112
 TGSpeedo.h:113
 TGSpeedo.h:114
 TGSpeedo.h:115
 TGSpeedo.h:116
 TGSpeedo.h:117
 TGSpeedo.h:118
 TGSpeedo.h:119
 TGSpeedo.h:120
 TGSpeedo.h:121
 TGSpeedo.h:122
 TGSpeedo.h:123