home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / STANDARD / UCROSSH.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  3.3 KB  |  123 lines

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Cross-Hair demo                             }
  4. { Copyright (c) 1995-1996 by David Berneda    }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. unit Ucrossh;
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, StdCtrls, Teengine, Series, ExtCtrls, Chart, Buttons,
  14.   TeeProcs;
  15.  
  16. type
  17.   TCrossHairForm = class(TForm)
  18.     Chart1: TChart;
  19.     LineSeries1: TLineSeries;
  20.     Panel1: TPanel;
  21.     Label1: TLabel;
  22.     BitBtn1: TBitBtn;
  23.     Label2: TLabel;
  24.     CheckBox1: TCheckBox;
  25.     BitBtn2: TBitBtn;
  26.     Memo1: TMemo;
  27.     procedure FormCreate(Sender: TObject);
  28.     procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  29.       Y: Integer);
  30.     procedure LineSeries1AfterDrawValues(Sender: TObject);
  31.     procedure CheckBox1Click(Sender: TObject);
  32.     procedure BitBtn2Click(Sender: TObject);
  33.   private
  34.     { Private declarations }
  35.   public
  36.     { Public declarations }
  37.     OldX,OldY:Longint;
  38.     CrossHairColor:TColor;
  39.     CrossHairStyle:TPenStyle;
  40.   end;
  41.  
  42. implementation
  43.  
  44. {$R *.DFM}
  45. Uses udemutil;
  46.  
  47. procedure TCrossHairForm.FormCreate(Sender: TObject);
  48. begin
  49.   LineSeries1.FillSampleValues(30);  { <-- some random values }
  50.   OldX:=-1;                          { initialize variables }
  51.   CrossHairColor:=clYellow;
  52.   CrossHairStyle:=psSolid;
  53. end;
  54.  
  55. procedure TCrossHairForm.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  56.   Y: Integer);
  57.  
  58.   { This procedure draws the crosshair lines }
  59.   Procedure DrawCross(AX,AY:Integer);
  60.   var tmp:TColor;
  61.   begin
  62.     With Chart1,Canvas do
  63.     begin
  64.       tmp:=Chart1.BackColor;
  65.       if tmp=clTeeColor then tmp:=clBtnFace;
  66.       Pen.Color:=(CrossHairColor xor ColorToRGB(tmp));
  67.  
  68.       Pen.Style:=CrossHairStyle;
  69.       Pen.Mode:=pmXor;
  70.       Pen.Width:=1;
  71.       MoveTo(ax,ChartRect.Top-Height3D);
  72.       LineTo(ax,ChartRect.Bottom-Height3D);
  73.       MoveTo(ChartRect.Left+Width3D,ay);
  74.       LineTo(ChartRect.Right+Width3D,ay);
  75.     end;
  76.   end;
  77.  
  78. Var tmpX,tmpY:Double;
  79. begin
  80.   if (OldX<>-1) then
  81.   begin
  82.     DrawCross(OldX,OldY);  { draw old crosshair }
  83.     OldX:=-1;
  84.   end;
  85.  
  86.   { check if mouse is inside Chart rectangle }
  87.   if PtInRect( Chart1.ChartRect, Point(X-Chart1.Width3D,Y+Chart1.Height3D)  ) then
  88.   begin
  89.     DrawCross(x,y);  { draw crosshair at current position }
  90.     { store old position }
  91.     OldX:=x;
  92.     OldY:=y;
  93.     { set label text }
  94.     With LineSeries1 do
  95.     begin
  96.       GetCursorValues(tmpX,tmpY);  { <-- get values under mouse cursor }
  97.       Label1.Caption:=GetVertAxis.LabelValue(tmpY)+
  98.                       ' '+
  99.                       GetHorizAxis.LabelValue(tmpX);
  100.     end;
  101.   end;
  102. end;
  103.  
  104. procedure TCrossHairForm.LineSeries1AfterDrawValues(Sender: TObject);
  105. begin
  106.   OldX:=-1;  { Reset old mouse position }
  107. end;
  108.  
  109. procedure TCrossHairForm.CheckBox1Click(Sender: TObject);
  110. begin
  111.   if CheckBox1.Checked then Chart1.Cursor:=crCross
  112.                        else Chart1.Cursor:=crDefault;
  113.   Chart1.OriginalCursor:=Chart1.Cursor;
  114. end;
  115.  
  116. procedure TCrossHairForm.BitBtn2Click(Sender: TObject);
  117. begin
  118.   CrossHairColor:=EditColor(Self,CrossHairColor);
  119. end;
  120.  
  121.  
  122. end.
  123.