home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl\vcl.h>
- #pragma hdrstop
-
- #include "frmprint.h"
- #include "math.h"
- #include "vcl\printers.hpp"
- //---------------------------------------------------------------------------
- #pragma link "RChart"
- #pragma link "NumLab"
- #pragma resource "*.dfm"
- TForm1 *Form1;
- int PrintPosX; // position of printout
- int PrintPosY;
- double PrintScaleF; // scaling factor of printout
- int xpRes, ypRes; // printer resolution
- int xpSize, ypSize; // printer paper size
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormActivate(TObject *Sender)
- {
- int i;
-
- RChart1->ClearGraf();
- RChart1->MoveTo (0,0);
- for (i=1; i<=200; i++)
- RChart1->DrawTo (i, (1-exp(i*0.005))*sin(0.2*i)*sin(0.33*i));
- RChart1->ShowGraf();
- PrintPosX = 100;
- PrintPosY = 100;
- PrintScaleF = 1.0;
- NLbScaleF->Value = 1.0;
- SBScalF->Position = 0;
- xpRes = GetDeviceCaps (Printer()->Handle, LOGPIXELSX);
- ypRes = GetDeviceCaps (Printer()->Handle, LOGPIXELSY);
- xpSize = GetDeviceCaps (Printer()->Handle, HORZSIZE);
- ypSize = GetDeviceCaps (Printer()->Handle, VERTSIZE);
- RChart2->SetRange (0, ypSize/25.4*ypRes, xpSize/25.4*xpRes, 0);
- ShowPageRect();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::ShowPageRect()
- {
- RChart2->ClearGraf();
- RChart2->FillColor = clRed;
- RChart2->DataColor = clRed;
- RChart2->Rectangle (PrintPosX, PrintPosY,
- PrintPosX+PrintScaleF*xpRes/Screen->PixelsPerInch*RChart1->Width,
- PrintPosY+PrintScaleF*ypRes/Screen->PixelsPerInch*RChart1->Height);
- RChart2->DataColor = clWhite;
- RChart2->Text ((2*PrintPosX+PrintScaleF*xpRes/Screen->PixelsPerInch*RChart1->Width)/2,
- (2*PrintPosY+PrintScaleF*ypRes/Screen->PixelsPerInch*RChart1->Height)/2,
- ceil(8*PrintScaleF), "Chart");
- RChart2->ShowGraf();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- char astr[20];
- int x1, y1;
-
- if (PrintDialog1->Execute())
- {
- Printer()->BeginDoc();
- sprintf (astr, "%1.2f", PrintScaleF);
- Printer()->Canvas->TextOut (100,40,"Position of image: x="+
- IntToStr(PrintPosX)+" y="+IntToStr(PrintPosY)+
- " Scaling factor: "+astr);
- x1 = PrintPosX; // copy position into dummy vars in order NOT to change PrintPosX/Y}
- y1 = PrintPosY;
- RChart1->CopyToOpenPrinter (x1,y1, PrintScaleF, ! CBColor->Checked);
- Printer()->Canvas->TextOut (300,y1+20,"This line is just below the printed image");
- Printer()->EndDoc();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::RChart2MouseMoveInChart(TObject *Sender, bool InChart,
- TShiftState Shift, double rMousePosX, double rMousePosY)
- {
- NLbPosX->Empty = !InChart;
- NLbPosY->Empty = !InChart;
- NLbPosX->Value = rMousePosX;
- NLbPosY->Value = rMousePosY;
- if (Shift.Contains (ssLeft))
- {
- PrintPosX = ceil(RChart2->MousePosX);
- PrintPosY = ceil(RChart2->MousePosY);
- ShowPageRect();
- };
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::SBScalFChange(TObject *Sender)
- {
- PrintScaleF = 1.0+(0.01*SBScalF->Position);
- NLbScaleF->Value = PrintScaleF;
- ShowPageRect();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::RChart2Click(TObject *Sender)
- {
- PrintPosX = ceil(RChart2->MousePosX);
- PrintPosY = ceil(RChart2->MousePosY);
- ShowPageRect();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X,
- int Y)
- {
- Screen->Cursor = crDefault;
- NLbPosX->Empty = true;
- NLbPosY->Empty = true;
- }
- //---------------------------------------------------------------------------