home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 March / Chip_1999-03_cd.bin / zkuste / delphi / D / MATEM.ARJ / RCHART.ZIP / exmpl-8 / cpp1 / frmprint.cpp next >
Encoding:
C/C++ Source or Header  |  1997-08-24  |  4.3 KB  |  122 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "frmprint.h"
  6. #include "math.h"
  7. #include "vcl\printers.hpp"
  8. //---------------------------------------------------------------------------
  9. #pragma link "RChart"
  10. #pragma link "NumLab"
  11. #pragma resource "*.dfm"
  12. TForm1 *Form1;
  13. int PrintPosX;                         // position of printout
  14. int PrintPosY;
  15. double PrintScaleF;                    // scaling factor of printout
  16. int xpRes, ypRes;                      // printer resolution
  17. int xpSize, ypSize;                    // printer paper size
  18. //---------------------------------------------------------------------------
  19. __fastcall TForm1::TForm1(TComponent* Owner)
  20.     : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TForm1::Button1Click(TObject *Sender)
  25. {
  26. Close();
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TForm1::FormActivate(TObject *Sender)
  30. {
  31. int i;
  32.  
  33. RChart1->ClearGraf();
  34. RChart1->MoveTo (0,0);
  35. for (i=1; i<=200; i++)
  36.   RChart1->DrawTo (i, (1-exp(i*0.005))*sin(0.2*i)*sin(0.33*i));
  37. RChart1->ShowGraf();
  38. PrintPosX = 100;
  39. PrintPosY = 100;
  40. PrintScaleF = 1.0;
  41. NLbScaleF->Value = 1.0;
  42. SBScalF->Position = 0;
  43. xpRes = GetDeviceCaps (Printer()->Handle, LOGPIXELSX);
  44. ypRes = GetDeviceCaps (Printer()->Handle, LOGPIXELSY);
  45. xpSize = GetDeviceCaps (Printer()->Handle, HORZSIZE);
  46. ypSize = GetDeviceCaps (Printer()->Handle, VERTSIZE);
  47. RChart2->SetRange (0, ypSize/25.4*ypRes, xpSize/25.4*xpRes, 0);
  48. ShowPageRect();
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TForm1::ShowPageRect()
  52. {
  53. RChart2->ClearGraf();
  54. RChart2->FillColor = clRed;
  55. RChart2->DataColor = clRed;
  56. RChart2->Rectangle (PrintPosX, PrintPosY,
  57.                    PrintPosX+PrintScaleF*xpRes/Screen->PixelsPerInch*RChart1->Width,
  58.                    PrintPosY+PrintScaleF*ypRes/Screen->PixelsPerInch*RChart1->Height);
  59. RChart2->DataColor = clWhite;
  60. RChart2->Text ((2*PrintPosX+PrintScaleF*xpRes/Screen->PixelsPerInch*RChart1->Width)/2,
  61.               (2*PrintPosY+PrintScaleF*ypRes/Screen->PixelsPerInch*RChart1->Height)/2,
  62.               ceil(8*PrintScaleF), "Chart");
  63. RChart2->ShowGraf();
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TForm1::Button2Click(TObject *Sender)
  67. {
  68. char astr[20];
  69. int x1, y1;
  70.  
  71. if (PrintDialog1->Execute())
  72.   {
  73.   Printer()->BeginDoc();
  74.   sprintf (astr, "%1.2f", PrintScaleF);
  75.   Printer()->Canvas->TextOut (100,40,"Position of image: x="+
  76.                           IntToStr(PrintPosX)+"  y="+IntToStr(PrintPosY)+
  77.                           "    Scaling factor: "+astr);
  78.   x1 = PrintPosX;  //  copy position into dummy vars in order NOT to change PrintPosX/Y}
  79.   y1 = PrintPosY;
  80.   RChart1->CopyToOpenPrinter (x1,y1, PrintScaleF, ! CBColor->Checked);
  81.   Printer()->Canvas->TextOut (300,y1+20,"This line is just below the printed image");
  82.   Printer()->EndDoc();
  83.   }
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TForm1::RChart2MouseMoveInChart(TObject *Sender, bool InChart,
  87.     TShiftState Shift, double rMousePosX, double rMousePosY)
  88. {
  89. NLbPosX->Empty = !InChart;
  90. NLbPosY->Empty = !InChart;
  91. NLbPosX->Value = rMousePosX;
  92. NLbPosY->Value = rMousePosY;
  93. if (Shift.Contains (ssLeft))
  94.   {
  95.   PrintPosX = ceil(RChart2->MousePosX);
  96.   PrintPosY = ceil(RChart2->MousePosY);
  97.   ShowPageRect();
  98.   };
  99. }
  100. //---------------------------------------------------------------------------
  101. void __fastcall TForm1::SBScalFChange(TObject *Sender)
  102. {
  103. PrintScaleF = 1.0+(0.01*SBScalF->Position);
  104. NLbScaleF->Value = PrintScaleF;
  105. ShowPageRect();
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TForm1::RChart2Click(TObject *Sender)
  109. {
  110. PrintPosX = ceil(RChart2->MousePosX);
  111. PrintPosY = ceil(RChart2->MousePosY);
  112. ShowPageRect();
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X,
  116.     int Y)
  117. {
  118. Screen->Cursor = crDefault;
  119. NLbPosX->Empty = true;
  120. NLbPosY->Empty = true;
  121. }
  122. //---------------------------------------------------------------------------