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

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1998 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  "pies.h"
  12. #include <Windows.hpp>
  13. #pragma package(smart_init)
  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.   delete FPen;
  63.   delete FBrush;
  64.   delete FAngles;
  65. }
  66.  
  67. void __fastcall TPie::StyleChanged(TObject* /*Sender*/)
  68. {
  69.   Invalidate();
  70. }
  71.  
  72. void __fastcall TPie::SetBrush(TBrush* Value)
  73. {
  74.   FBrush->Assign(Value);
  75. }
  76.  
  77. void __fastcall TPie::SetPen(TPen* Value)
  78. {
  79.   FPen->Assign(Value);
  80. }
  81.  
  82. void __fastcall TPie::SetAngles(TAngles* Value)
  83. {
  84.   FAngles->Assign(Value);
  85.   Invalidate();
  86. }
  87.  
  88. void __fastcall TPie::Paint()
  89. {
  90.   int StartA, EndA;
  91.   int midX, midY, stX, stY, endX, endY;
  92.   float sX, sY, eX, eY;
  93.  
  94.   StartA = FAngles->StartAngle;
  95.   EndA = FAngles->EndAngle;
  96.   midX =  Width/2;
  97.   midY = Height/2;
  98.  
  99.   sX = cos((StartA / 180.0) * PI);
  100.   sY = sin((StartA / 180.0) * PI);
  101.   eX = cos((EndA / 180.0) * PI);
  102.   eY = sin((EndA / 180.0) * PI);
  103.  
  104.   stX = floor(sX * 100);
  105.   stY = floor(sY * 100);
  106.   endX = ceil(eX * 100);
  107.   endY = ceil(eY * 100);
  108.  
  109.   Canvas->Pen = FPen;
  110.   Canvas->Brush = FBrush;
  111.   Canvas->Pie(0,0,
  112.               Width,Height,
  113.               midX + stX, midY - stY,
  114.               midX + endX, midY - endY);
  115. }
  116.  
  117.