home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / PIES.CPP < prev    next >
C/C++ Source or Header  |  1997-01-16  |  3KB  |  112 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. #include <Windows.hpp>
  12. #include "pies.h"
  13.  
  14. //---------------------------------------------------------------------------
  15. __fastcall TAngles::TAngles(void) : TPersistent() { }
  16. __fastcall TAngles::~TAngles(void) { }
  17.  
  18. void __fastcall TAngles::Assign(TPersistent* Value)
  19. {
  20.   StartAngle = dynamic_cast<TAngles*>(Value)->StartAngle;
  21.   EndAngle = dynamic_cast<TAngles*>(Value)->EndAngle;
  22. }
  23.  
  24. void __fastcall TAngles::SetStart(int Value)
  25. {
  26.   if (Value != FStartAngle){
  27.     FStartAngle = Value;
  28.     Changed();
  29.   }
  30. }
  31.  
  32. void __fastcall TAngles::SetEnd(int Value)
  33. {
  34.   if (Value != FEndAngle){
  35.     FEndAngle = Value;
  36.     Changed();
  37.   }
  38. }
  39.  
  40. void __fastcall TAngles::Changed()
  41. {
  42.   if (FOnChange != NULL)
  43.     FOnChange(this);
  44. }
  45.  
  46. __fastcall TPie::TPie(TComponent* AOwner): TGraphicControl(AOwner)
  47. {
  48.   Width = 100;
  49.   Height = 100;
  50.   FPen = new TPen();
  51.   FPen->OnChange = StyleChanged;
  52.   FBrush = new TBrush();
  53.   FBrush->OnChange = StyleChanged;
  54.   FAngles = new TAngles();
  55.   FAngles->OnChange = StyleChanged;
  56.   FAngles->StartAngle = 180;
  57.   FAngles->EndAngle = 90;
  58. }
  59.  
  60. __fastcall TPie::~TPie(void) { }
  61.  
  62. void __fastcall TPie::StyleChanged(TObject* /*Sender*/)
  63. {
  64.   Invalidate();
  65. }
  66.  
  67. void __fastcall TPie::SetBrush(TBrush* Value)
  68. {
  69.   FBrush->Assign(Value);
  70. }
  71.  
  72. void __fastcall TPie::SetPen(TPen* Value)
  73. {
  74.   FPen->Assign(Value);
  75. }
  76.  
  77. void __fastcall TPie::SetAngles(TAngles* Value)
  78. {
  79.   FAngles->Assign(Value);
  80.   Invalidate();
  81. }
  82.  
  83. void __fastcall TPie::Paint()
  84. {
  85.   int StartA, EndA;
  86.   int midX, midY, stX, stY, endX, endY;
  87.   float sX, sY, eX, eY;
  88.  
  89.   StartA = FAngles->StartAngle;
  90.   EndA = FAngles->EndAngle;
  91.   midX =  Width/2;
  92.   midY = Height/2;
  93.  
  94.   sX = cos((StartA / 180.0) * PI);
  95.   sY = sin((StartA / 180.0) * PI);
  96.   eX = cos((EndA / 180.0) * PI);
  97.   eY = sin((EndA / 180.0) * PI);
  98.  
  99.   stX = floor(sX * 100);
  100.   stY = floor(sY * 100);
  101.   endX = ceil(eX * 100);
  102.   endY = ceil(eY * 100);
  103.  
  104.   Canvas->Pen = FPen;
  105.   Canvas->Brush = FBrush;
  106.   Canvas->Pie(0,0,
  107.               Width,Height,
  108.               midX + stX, midY - stY,
  109.               midX + endX, midY - endY);
  110. }
  111.  
  112.