TAChart: Add mouse events demo

git-svn-id: trunk@20118 -
This commit is contained in:
ask 2009-05-22 05:34:25 +00:00
parent 1b34be4add
commit c6677a7a40
6 changed files with 251 additions and 0 deletions

5
.gitattributes vendored
View File

@ -1539,6 +1539,11 @@ components/tachart/demo/basic/demo.lpr svneol=native#text/plain
components/tachart/demo/basic/unit1.lfm svneol=native#text/plain
components/tachart/demo/basic/unit1.lrs svneol=native#text/plain
components/tachart/demo/basic/unit1.pas svneol=native#text/plain
components/tachart/demo/dragdrop/dragdropdemo.lpi svneol=native#text/plain
components/tachart/demo/dragdrop/dragdropdemo.lpr svneol=native#text/plain
components/tachart/demo/dragdrop/main.lfm svneol=native#text/plain
components/tachart/demo/dragdrop/main.lrs svneol=native#text/plain
components/tachart/demo/dragdrop/main.pas svneol=native#text/pascal
components/tachart/demo/extent/extentdemo.lpi svneol=native#text/plain
components/tachart/demo/extent/extentdemo.lpr svneol=native#text/plain
components/tachart/demo/extent/main.lfm svneol=native#text/plain

View File

@ -0,0 +1,72 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="\"/>
<Version Value="7"/>
<General>
<Flags>
<SaveClosedFiles Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<TargetFileExt Value=".exe"/>
<Title Value="Chart mouse events demo"/>
<UseXPManifest Value="True"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
</VersionInfo>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="TAChartLazarusPkg"/>
<MinVersion Major="1" Valid="True"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="dragdropdemo.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="dragdropdemo"/>
</Unit0>
<Unit1>
<Filename Value="main.pas"/>
<ComponentName Value="Form1"/>
<IsPartOfProject Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Main"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="8"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)\"/>
</SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</CONFIG>

View File

@ -0,0 +1,21 @@
program dragdropdemo;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Main, TAChartLazarusPkg
{ you can add units after this };
{$IFDEF WINDOWS}{$R dragdropdemo.rc}{$ENDIF}
begin
Application.Title := 'Chart mouse events demo';
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@ -0,0 +1,43 @@
object Form1: TForm1
Left = 318
Height = 300
Top = 151
Width = 400
Caption = 'Form1'
ClientHeight = 300
ClientWidth = 400
OnCreate = FormCreate
LCLVersion = '0.9.27'
object Chart1: TChart
Left = 0
Height = 300
Top = 0
Width = 400
BottomAxis.Grid.Style = psDot
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
LeftAxis.Grid.Style = psDot
LeftAxis.Title.Angle = 90
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'You can drag data points'
'while holding Shift key'
)
Title.Visible = True
Align = alClient
DoubleBuffered = True
ParentColor = False
OnMouseDown = Chart1MouseDown
OnMouseMove = Chart1MouseMove
OnMouseUp = Chart1MouseUp
object Chart1LineSeries1: TLineSeries
Pointer.Brush.Color = clPurple
Pointer.HorizSize = 6
Pointer.Style = psDiamond
Pointer.VertSize = 6
SeriesColor = clBlack
ShowPoints = True
end
end
end

View File

@ -0,0 +1,18 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'>'#1#6'Height'#3','#1#3'Top'#3#151#0#5'Wi'
+'dth'#3#144#1#7'Caption'#6#5'Form1'#12'ClientHeight'#3','#1#11'ClientWidth'#3
+#144#1#8'OnCreate'#7#10'FormCreate'#10'LCLVersion'#6#6'0.9.27'#0#6'TChart'#6
+'Chart1'#4'Left'#2#0#6'Height'#3','#1#3'Top'#2#0#5'Width'#3#144#1#21'BottomA'
+'xis.Grid.Style'#7#5'psDot'#16'Foot.Brush.Color'#7#9'clBtnFace'#15'Foot.Font'
+'.Color'#7#6'clBlue'#19'LeftAxis.Grid.Style'#7#5'psDot'#20'LeftAxis.Title.An'
+'gle'#2'Z'#17'Title.Brush.Color'#7#9'clBtnFace'#16'Title.Font.Color'#7#6'clB'
+'lue'#18'Title.Text.Strings'#1#6#24'You can drag data points'#6#23'while hol'
+'ding Shift key'#0#13'Title.Visible'#9#5'Align'#7#8'alClient'#14'DoubleBuffe'
+'red'#9#11'ParentColor'#8#11'OnMouseDown'#7#15'Chart1MouseDown'#11'OnMouseMo'
+'ve'#7#15'Chart1MouseMove'#9'OnMouseUp'#7#13'Chart1MouseUp'#0#11'TLineSeries'
+#17'Chart1LineSeries1'#19'Pointer.Brush.Color'#7#8'clPurple'#17'Pointer.Hori'
+'zSize'#2#6#13'Pointer.Style'#7#9'psDiamond'#16'Pointer.VertSize'#2#6#11'Ser'
+'iesColor'#7#7'clBlack'#10'ShowPoints'#9#0#0#0#0
]);

View File

@ -0,0 +1,92 @@
unit Main;
{$mode objfpc}{$H+}
interface
uses
Classes, ExtCtrls, SysUtils, FileUtil, LResources, Forms, Controls, Graphics,
Dialogs, TAGraph, TASeries;
type
{ TForm1 }
TForm1 = class(TForm)
Chart1: TChart;
Chart1LineSeries1: TLineSeries;
procedure Chart1MouseDown(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure Chart1MouseMove(
Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Chart1MouseUp(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
FDragIndex: Integer;
end;
var
Form1: TForm1;
implementation
uses
TAChartUtils;
type
TLineSeriesAccess = class(TLineSeries);
{ TForm1 }
procedure TForm1.Chart1MouseDown(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
pt, img: TPoint;
val: TDoublePoint;
begin
Unused(Button);
pt := Point(X, Y);
if
(Shift = [ssShift, ssLeft]) and
TLineSeriesAccess(Chart1LineSeries1).GetNearestPoint(
@PointDist, pt, FDragIndex, img, val) and
(PointDist(pt, img) <= Sqr(Chart1LineSeries1.Pointer.HorizSize))
then
else
FDragIndex := -1;
end;
procedure TForm1.Chart1MouseMove(
Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
Unused(Shift);
Unused(X, Y);
if FDragIndex < 0 then exit;
Chart1LineSeries1.SetXValue(FDragIndex, Chart1.XImageToGraph(X));
Chart1LineSeries1.SetYValue(FDragIndex, Chart1.YImageToGraph(Y));
end;
procedure TForm1.Chart1MouseUp(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Unused(Button, Shift);
Unused(X, Y);
FDragIndex := -1;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
RandSeed := 675402;
for i := 1 to 10 do
Chart1LineSeries1.AddXY(i, Random(20) - 10);
FDragIndex := -1;
end;
initialization
{$I main.lrs}
end.