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

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