home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / PIES.CPP < prev    next >
C/C++ Source or Header  |  1997-02-14  |  3KB  |  121 lines

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1997 Borland International Inc.  All Rights Reserved.
  4. //---------------------------------------------------------------------------
  5. // pies.cpp
  6. // This file is #included in PIEREG.CPP which #includes PIEREG.H which
  7. // in turn #includes PIES.H.  Hence #including PIES.H here is redundant with
  8. // no ramifications (there are sentries in the header file) but has been done
  9. // just to clarify that the function and class implementations in this file are
  10. // prototyped in PIES.H
  11. #if !defined (REGISTER_ALL_CONTROLS)
  12.   #include  "pies.h"
  13. #else
  14.   #include "source\pies.h"
  15. #endif
  16. #include <Windows.hpp>
  17.  
  18. //---------------------------------------------------------------------------
  19. __fastcall TAngles::TAngles(void) : TPersistent() { }
  20. __fastcall TAngles::~TAngles(void) { }
  21.  
  22. void __fastcall TAngles::Assign(TPersistent* Value)
  23. {
  24.   StartAngle = dynamic_cast<TAngles*>(Value)->StartAngle;
  25.   EndAngle = dynamic_cast<TAngles*>(Value)->EndAngle;
  26. }
  27.  
  28. void __fastcall TAngles::SetStart(int Value)
  29. {
  30.   if (Value != FStartAngle){
  31.     FStartAngle = Value;
  32.     Changed();
  33.   }
  34. }
  35.  
  36. void __fastcall TAngles::SetEnd(int Value)
  37. {
  38.   if (Value != FEndAngle){
  39.     FEndAngle = Value;
  40.     Changed();
  41.   }
  42. }
  43.  
  44. void __fastcall TAngles::Changed()
  45. {
  46.   if (FOnChange != NULL)
  47.     FOnChange(this);
  48. }
  49.  
  50. __fastcall TPie::TPie(TComponent* AOwner): TGraphicControl(AOwner)
  51. {
  52.   Width = 100;
  53.   Height = 100;
  54.   FPen = new TPen();
  55.   FPen->OnChange = StyleChanged;
  56.   FBrush = new TBrush();
  57.   FBrush->OnChange = StyleChanged;
  58.   FAngles = new TAngles();
  59.   FAngles->OnChange = StyleChanged;
  60.   FAngles->StartAngle = 180;
  61.   FAngles->EndAngle = 90;
  62. }
  63.  
  64. __fastcall TPie::~TPie(void) 
  65. {
  66.   delete FPen;
  67.   delete FBrush;
  68.   delete FAngles;
  69. }
  70.  
  71. void __fastcall TPie::StyleChanged(TObject* /*Sender*/)
  72. {
  73.   Invalidate();
  74. }
  75.  
  76. void __fastcall TPie::SetBrush(TBrush* Value)
  77. {
  78.   FBrush->Assign(Value);
  79. }
  80.  
  81. void __fastcall TPie::SetPen(TPen* Value)
  82. {
  83.   FPen->Assign(Value);
  84. }
  85.  
  86. void __fastcall TPie::SetAngles(TAngles* Value)
  87. {
  88.   FAngles->Assign(Value);
  89.   Invalidate();
  90. }
  91.  
  92. void __fastcall TPie::Paint()
  93. {
  94.   int StartA, EndA;
  95.   int midX, midY, stX, stY, endX, endY;
  96.   float sX, sY, eX, eY;
  97.  
  98.   StartA = FAngles->StartAngle;
  99.   EndA = FAngles->EndAngle;
  100.   midX =  Width/2;
  101.   midY = Height/2;
  102.  
  103.   sX = cos((StartA / 180.0) * PI);
  104.   sY = sin((StartA / 180.0) * PI);
  105.   eX = cos((EndA / 180.0) * PI);
  106.   eY = sin((EndA / 180.0) * PI);
  107.  
  108.   stX = floor(sX * 100);
  109.   stY = floor(sY * 100);
  110.   endX = ceil(eX * 100);
  111.   endY = ceil(eY * 100);
  112.  
  113.   Canvas->Pen = FPen;
  114.   Canvas->Brush = FBrush;
  115.   Canvas->Pie(0,0,
  116.               Width,Height,
  117.               midX + stX, midY - stY,
  118.               midX + endX, midY - endY);
  119. }
  120.  
  121.