home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / Chip_2002-05_cd1.bin / chplus / cpp / 5 / Komponety.exe / perfgrap.h < prev    next >
C/C++ Source or Header  |  1998-02-09  |  4KB  |  150 lines

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1998 Borland International Inc.  All Rights Reserved.
  4. //---------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #ifndef PerfGraphH
  7. #define PerfGraphH
  8. //---------------------------------------------------------------------------
  9. #include <SysUtils.hpp>
  10. #include <Controls.hpp>
  11. #include <Classes.hpp>
  12. #include <Forms.hpp>
  13. //---------------------------------------------------------------------------
  14. enum TGraphKind { pgBar, pgLine };
  15.  
  16. class PACKAGE TPerformanceGraph : public TGraphicControl
  17. {
  18. private:
  19.     TGraphKind FKind;
  20.     TColor FForeColor;
  21.     TColor FBackColor;
  22.     Longint FGridSize;
  23.     Longint FStepSize;
  24.     Longint FScale;
  25.     Longint FGradient;
  26.     Boolean FGridlines;
  27.     Longint FPenWidth;
  28.     TNotifyEvent FOnScaleChange;
  29.  
  30.     void __fastcall SetGraphKind(TGraphKind Value);
  31.     void __fastcall SetForeColor(TColor Value);
  32.     void __fastcall SetBackColor(TColor Value);
  33.     void __fastcall SetGridSize(Longint Value);
  34.     void __fastcall SetStepSize(Longint Value);
  35.     void __fastcall SetScale(Longint Value);
  36.     void __fastcall SetGradient(Longint Value);
  37.     void __fastcall SetGridlines(Boolean Value);
  38.     void __fastcall SetPenWidth(Longint Value);
  39.  
  40. private:
  41.     TRect LayoutRect;
  42.     TRect SourceRect;
  43.     TRect DestRect;
  44.     TRect OpenBand;
  45.     Longint Hidden;
  46.     Graphics::TBitmap *SaveArea;
  47.     Boolean Occupied;
  48.  
  49.     void __fastcall Initialize(Longint Index);
  50.     void __fastcall PaintBar(TColor color, Longint base, Longint amount);
  51.     void __fastcall PaintLine(TColor color, Longint lastAmount,
  52.         Longint amount);
  53.  
  54. #define MAXLINES 16
  55.  
  56.     struct TDataPoints
  57.     {
  58.         Longint    used;
  59.         TColor    color[MAXLINES];
  60.         Longint    value[MAXLINES];
  61.     };
  62.  
  63.     TDataPoints    *History;
  64.     Longint        Allocated;
  65.     int            BeginY, CurrentY;
  66.  
  67. #define LIST_END -1
  68.  
  69.     int __fastcall CountY() {
  70.         return Allocated - 1;
  71.     }
  72.  
  73.     int __fastcall FirstY() {
  74.         return BeginY;
  75.     }
  76.     
  77.     int __fastcall NextY(int Y) {
  78.         Y++;
  79.         if    (Y == Allocated)
  80.             Y = 0;
  81.         if    (Y == BeginY)
  82.             return -1;
  83.         return Y;
  84.     }
  85.     
  86.     int __fastcall LastY(int Y) {
  87.         if    (Y == 0)
  88.             return Allocated - 1;
  89.         return Y - 1;
  90.     }
  91.  
  92.     int __fastcall ShiftY() {
  93.         Longint nextY = CurrentY;
  94.         nextY++;
  95.         if    (nextY == Allocated)
  96.             nextY = 0;
  97.  
  98.         History[nextY].used = 0;
  99.         BeginY = nextY + 1;
  100.         if    (BeginY == Allocated)
  101.             BeginY = 0;
  102.  
  103.         CurrentY = nextY;
  104.     }
  105.  
  106. protected:
  107.     virtual void __fastcall Paint(void);
  108.     void __fastcall ScrollGraph();
  109.     void __fastcall DisplayPoints(Longint Index);
  110.     void __fastcall ReallocHistory();
  111.     void __fastcall Replay(void);
  112.  
  113.     Longint __fastcall GetBandCount() {
  114.         return Width / StepSize;
  115.     }
  116.     __property Longint Bands = {read=GetBandCount};
  117.  
  118.     Longint __fastcall RoundUp(Longint Value, Longint Increment) {
  119.         if    (Increment && Value % Increment)
  120.             return ((Value / Increment) + 1) * Increment;
  121.         return Value;
  122.     }
  123.  
  124. public:
  125.     __fastcall TPerformanceGraph(TComponent* Owner);
  126.     virtual __fastcall ~TPerformanceGraph();
  127.  
  128.     void __fastcall DataPoint(TColor color, Longint value);
  129.     void __fastcall Update();
  130.  
  131. __published:
  132.     __property Align ;
  133.     __property Enabled ;
  134.     __property TGraphKind Kind = {read=FKind, write=SetGraphKind, default=1};
  135.     __property TColor ForeColor = {read=FForeColor, write=SetForeColor, default=clGreen};
  136.     __property TColor BackColor = {read=FBackColor, write=SetBackColor, default=clBlack};
  137.     __property ParentShowHint ;
  138.     __property Longint GridSize = {read=FGridSize, write=SetGridSize, default=15};
  139.     __property Longint StepSize = {read=FStepSize, write=SetStepSize, default=3};
  140.     __property Longint Scale = {read=FScale, write=SetScale, default=1000};
  141.     __property Longint Gradient = {read=FGradient, write=SetGradient, default=1000};
  142.     __property Boolean Gridlines = {read=FGridlines, write=SetGridlines, default=true};
  143.     __property Longint PenWidth = {read=FPenWidth, write=SetPenWidth, default=2};
  144.     __property TNotifyEvent OnScaleChange = {read=FOnScaleChange, write=FOnScaleChange};
  145.     __property ShowHint ;
  146.     __property Visible ;
  147. };
  148. //---------------------------------------------------------------------------
  149. #endif
  150.