LazMapViewer: Some renaming in the grid plugin unit.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9528 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-12-13 21:52:22 +00:00
parent e9817f4048
commit 6304b7d15b
6 changed files with 119 additions and 144 deletions

View File

@ -10,8 +10,7 @@ uses
athreads,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, lazcontrols, main
{ you can add units after this };
Forms, main;
{$R *.res}

View File

@ -106,7 +106,7 @@ object Form1: TForm1
'10°'
'5°'
'2°'
'1"'
'1°'
'30'''
'20'''
'10'''

View File

@ -7,7 +7,7 @@ interface
uses
Classes, ComCtrls, DividerBevel, ExtCtrls, Spin, StdCtrls, SysUtils,
Forms, Controls, Graphics, Dialogs, //LazLogger,
mvMapViewer, mvTypes, mvEngine, mvPluginCore, mvGridPlugin;
mvMapViewer, mvTypes, mvEngine, mvPluginCore, mvMapGridPlugin;
type
TForm1 = class(TForm)
@ -47,7 +47,8 @@ type
procedure seLabelDistanceChange(Sender: TObject);
procedure tbOpacityChange(Sender: TObject);
private
procedure AddPointOfInterest(X, Y: Integer);
FMapGridPlugin: TMapGridPlugin;
procedure AddOrDeletePointOfInterest(X, Y: Integer);
public
@ -64,16 +65,15 @@ procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
MapView.Zoom := 5;
with TGridPlugin.Create(PluginManager) do
begin
clbBackgroundColor.ButtonColor := ColorToRGB(BackgroundColor);
clbPenColor.ButtonColor := ColorToRGB(Pen.Color);
clbLabelTextColor.ButtonColor := ColorToRGB(Font.Color);
tbOpacity.Position := round(Opacity * 100);
end;
FMapGridPlugin := TMapGridPlugin.Create(PluginManager);
clbBackgroundColor.ButtonColor := ColorToRGB(FMapGridPlugin.BackgroundColor);
clbPenColor.ButtonColor := ColorToRGB(FMapGridPlugin.Pen.Color);
clbLabelTextColor.ButtonColor := ColorToRGB(FMapGridPlugin.Font.Color);
tbOpacity.Position := round(FMapGridPlugin.BackgroundOpacity * 100);
end;
procedure TForm1.AddPointOfInterest(X, Y: Integer);
procedure TForm1.AddOrDeletePointOfInterest(X, Y: Integer);
const
DELTA = 4;
var
@ -120,22 +120,22 @@ end;
procedure TForm1.cbEnabledChange(Sender: TObject);
begin
(PluginManager.PluginList[0] as TGridPlugin).Enabled := cbEnabled.Checked;
FMapGridPlugin.Enabled := cbEnabled.Checked;
end;
procedure TForm1.clbBackgroundColorColorChanged(Sender: TObject);
begin
(PluginManager.PluginList[0] as TGridPlugin).BackgroundColor := clbBackgroundColor.ButtonColor;
FMapGridPlugin.BackgroundColor := clbBackgroundColor.ButtonColor;
end;
procedure TForm1.clbLabelTextColorColorChanged(Sender: TObject);
begin
(PluginManager.PluginList[0] as TGridPlugin).Font.Color := clbLabelTextColor.ButtonColor;
FMapGridPlugin.Font.Color := clbLabelTextColor.ButtonColor;
end;
procedure TForm1.clbPenColorColorChanged(Sender: TObject);
begin
(PluginManager.PluginList[0] as TGridPlugin).Pen.Color := clbPenColor.ButtonColor;
FMapGridPlugin.Pen.Color := clbPenColor.ButtonColor;
end;
procedure TForm1.cmbIncrementChange(Sender: TObject);
@ -145,7 +145,7 @@ var
p: Integer;
begin
if cmbIncrement.ItemIndex <= 0 then
(PluginManager.PluginList[0] as TGridPlugin).Increment := 0
FMapGridPlugin.Increment := 0
else
begin
s := cmbIncrement.Items[cmbIncrement.ItemIndex];
@ -167,51 +167,51 @@ begin
end;
end;
s := copy(s, 1, p-1);
(PluginManager.PluginList[0] as TGridPlugin).Increment := StrToInt(s) * multiplier;
FMapGridPlugin.Increment := StrToInt(s) * multiplier;
end;
end;
procedure TForm1.LabelPositionChange(Sender: TObject);
begin
with (PluginManager.PluginList[0] as TGridPlugin).GridLabels do
with FMapGridPlugin do
begin
if cbLeft.Checked then
Position := Position + [glpLeft]
LabelPositions := LabelPositions + [glpLeft]
else
Position := Position - [glpLeft];
LabelPositions := LabelPositions - [glpLeft];
if cbTop.Checked then
Position := Position + [glpTop]
LabelPositions := LabelPositions + [glpTop]
else
Position := Position - [glpTop];
LabelPositions := LabelPositions - [glpTop];
if cbRight.Checked then
Position := Position + [glpRight]
LabelPositions := LabelPositions + [glpRight]
else
Position := Position - [glpRight];
LabelPositions := LabelPositions - [glpRight];
if cbBottom.Checked then
Position := Position + [glpBottom]
LabelPositions := LabelPositions + [glpBottom]
else
Position := Position - [glpBottom];
LabelPositions := LabelPositions - [glpBottom];
end;
end;
procedure TForm1.MapViewMouseUp(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
begin
if Button = mbRight then
AddPointOfInterest(X, Y);
if (Button = mbRight) and (Shift = []) then
AddOrDeletePointOfInterest(X, Y);
end;
procedure TForm1.seLabelDistanceChange(Sender: TObject);
begin
(PluginManager.PluginList[0] as TGridPlugin).GridLabels.Distance := seLabelDistance.Value;
FMapGridPlugin.LabelDistance := seLabelDistance.Value;
end;
procedure TForm1.tbOpacityChange(Sender: TObject);
begin
(PluginManager.PluginList[0] as TGridPlugin).Opacity := tbOpacity.Position / 100;
FMapGridPlugin.BackgroundOpacity := tbOpacity.Position / 100;
end;
end.

View File

@ -145,8 +145,8 @@ FPC 3.2.0 or newer required."/>
<UnitName Value="uInactivityAlarmTimer"/>
</Item30>
<Item31>
<Filename Value="source/addons/plugins/grids/mvgridplugin.pas"/>
<UnitName Value="mvGridPlugin"/>
<Filename Value="source/addons/plugins/grids/mvmapgridplugin.pas"/>
<UnitName Value="mvMapGridPlugin"/>
</Item31>
<Item32>
<Filename Value="source/addons/plugins/scale/mvmapscaleplugin.pas"/>

View File

@ -14,7 +14,7 @@ uses
mvDLEWin, mvMapViewerPropEdits, mvLayersPropEditForm, mvGeoMath,
mvMapViewerPathEditForm, mvMapViewerPathEditDsgForm, mvDLECache,
mvPluginEditors, mvClassRegistration, mvPluginCore, mvPlugins,
mvspreadmarker_plugin, uInactivityAlarmTimer, mvGridPlugin,
mvspreadmarker_plugin, uInactivityAlarmTimer, mvMapGridPlugin,
mvMapScalePlugin, LazarusPackageIntf;
implementation

View File

@ -1,6 +1,6 @@
{ TGridPlugin - draws a grid of constant longitudes and constant latitudes}
{ TMapGridPlugin - draws a grid of constant longitudes and constant latitudes}
unit mvGridPlugin;
unit mvMapGridPlugin;
{$mode objfpc}{$H+}
@ -12,48 +12,37 @@ uses
mvMapViewer, mvDrawingEngine, mvPluginCore, mvGeoMath, mvTypes;
type
TGridPlugin = class;
TMvGridLabelPosition = (glpLeft, glpTop, glpRight, glpBottom);
TMvGridLabelPositions = set of TMvGridLabelPosition;
TMapGridPlugin = class;
TMapGridLabelPosition = (glpLeft, glpTop, glpRight, glpBottom);
TMapGridLabelPositions = set of TMapGridLabelPosition;
TMvGridLabels = class(TPersistent)
private
FPlugin: TGridPlugin;
FPosition: TMvGridLabelPositions;
FDistance: Integer;
procedure SetDistance(AValue: Integer);
procedure SetPosition(AValue: TMvGridLabelpositions);
protected
procedure Update;
public
constructor Create(AOwner: TGridPlugin);
published
property Distance: Integer read FDistance write SetDistance default 0;
property Position: TMvGridLabelPositions read FPosition write SetPosition default [glpLeft, glpTop];
end;
TGridPlugin = class(TMvPlugin)
TMapGridPlugin = class(TMvPlugin)
private
const
DEFAULT_LABEL_POSITIONS = [glpLeft, glpTop];
DEFAULT_MAX_DISTANCE = 200;
DEFAULT_MIN_DISTANCE = 80;
DEFAULT_OPACITY = 0.55;
type
TGridCoordType = (gctLatitude, gctLongitude);
private
FBackgroundColor: TColor;
FBackgroundOpacity: Single;
FFont: TFont;
FIncrement: Double;
FOpacity: Single;
FPen: TPen;
FGridLabels: TMvGridLabels;
FLabelDistance: Integer;
FLabelPositions: TMapGridLabelPositions;
FMaxDistance: Integer;
FMinDistance: Integer;
procedure SetBackgroundColor(AValue: TColor);
procedure SetBackgroundOpacity(AValue: Single);
procedure SetFont(AValue: TFont);
procedure SetIncrement(AValue: Double);
procedure SetLabelDistance(AValue: Integer);
procedure SetLabelPositions(AValue: TMapGridLabelPositions);
procedure SetMaxDistance(AValue: Integer);
procedure SetMinDistance(AValue: Integer);
procedure SetOpacity(AValue: Single);
procedure SetPen(AValue: TPen);
private
procedure Changed(Sender: TObject);
@ -71,12 +60,13 @@ type
destructor Destroy; override;
published
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor default clWhite;
property BackgroundOpacity: Single read FBackgroundOpacity write SetBackgroundOpacity;
property Font: TFont read FFont write SetFont;
property GridLabels: TMvGridLabels read FGridLabels write FGridLabels;
property Increment: Double read FIncrement write SetIncrement; // 0 = automatic increment detection
property LabelDistance: Integer read FLabelDistance write SetLabelDistance default 0;
property LabelPositions: TMapGridLabelPositions read FLabelPositions write SetLabelPositions default DEFAULT_LABEL_POSITIONS;
property MaxDistance: Integer read FMaxDistance write SetMaxDistance default DEFAULT_MAX_DISTANCE;
property MinDistance: Integer read FMinDistance write SetMinDistance default DEFAULT_MIN_DISTANCE;
property Opacity: Single read FOpacity write SetOpacity;
property Pen: TPen read FPen write SetPen;
end;
@ -85,64 +75,31 @@ implementation
uses
Types;
{ TMvGridLabels }
constructor TMvGridLabels.Create(AOwner: TGridPlugin);
begin
inherited Create;
FPlugin := AOwner;
FPosition := [glpLeft, glpTop];
end;
{ TMapGridPlugin }
procedure TMvGridLabels.SetDistance(AValue: Integer);
begin
if FDistance <> AValue then
begin
FDistance := AValue;
FPlugin.Update;
end;
end;
procedure TMvGridLabels.SetPosition(AValue: TMvGridLabelPositions);
begin
if FPosition <> AValue then
begin
FPosition := AValue;
Update;
end;
end;
procedure TMvGridLabels.Update;
begin
FPlugin.Update;
end;
{ TGridPlugin }
constructor TGridPlugin.Create(AOwner: TComponent);
constructor TMapGridPlugin.Create(AOwner: TComponent);
begin
inherited;
FBackgroundColor := clWhite;
FOpacity := 0.55;
FBackgroundOpacity := DEFAULT_OPACITY;
FFont := TFont.Create;
FFont.OnChange := @Changed;
FPen := TPen.Create;
FPen.OnChange := @Changed;
FGridLabels := TMvGridLabels.Create(Self);
FMaxDistance := DEFAULT_MAX_DISTANCE;
FMinDistance := DEFAULT_MIN_DISTANCE;
FLabelPositions := DEFAULT_LABEL_POSITIONS;
end;
destructor TGridPlugin.Destroy;
destructor TMapGridPlugin.Destroy;
begin
FGridLabels.Free;
FPen.Free;
FFont.Free;
inherited;
end;
procedure TGridPlugin.BeforeDrawObjects(AMapView: TMapView; var Handled: Boolean);
procedure TMapGridPlugin.BeforeDrawObjects(AMapView: TMapView; var Handled: Boolean);
var
area: TRealArea;
coordType: TGridCoordType;
@ -184,7 +141,7 @@ end;
{ Calculates the increment of the grid lines. Since, due to the projection, the
latitude lines have a non-constant spacing, their increment is taken from
the equator value, i.e. is assumed to be equal to the longitude lines spacing. }
function TGridPlugin.CalcIncrement(AMapView: TMapView; Area: TRealArea): Double;
function TMapGridPlugin.CalcIncrement(AMapView: TMapView; Area: TRealArea): Double;
type
TIncrement = (deg180, deg90, deg45, deg30, deg10, deg5, deg2, deg1,
min30, min20, min10, min5, min2, min1,
@ -218,7 +175,7 @@ end;
{ Calculates the corner coordinates (in degrees) for the displayed map.
The longitude values are expanded such that they increase monotonously
from left to right. }
function TGridPlugin.CalcVisibleArea(AMapView: TMapView): TRealArea;
function TMapGridPlugin.CalcVisibleArea(AMapView: TMapView): TRealArea;
var
worldWidth: Integer;
numWorlds: Integer;
@ -234,18 +191,18 @@ begin
end;
end;
procedure TGridPlugin.Changed(Sender: TObject);
procedure TMapGridPlugin.Changed(Sender: TObject);
begin
Update;
end;
procedure TGridPlugin.DrawGridLine(ADrawingEngine: TMvCustomDrawingEngine;
procedure TMapGridPlugin.DrawGridLine(ADrawingEngine: TMvCustomDrawingEngine;
AValue: Double; P1, P2: TPoint; AMapRect: TRect);
var
s: String;
txtSize: TSize;
txtRect: array[TMvGridLabelPosition] of TRect;
glp: TMvGridLabelPosition;
txtRect: array[TMapGridLabelPosition] of TRect;
glp: TMapGridLabelPosition;
coordType: TGridCoordType;
begin
if P1.Y = P2.Y then
@ -269,36 +226,36 @@ begin
case coordType of
gctLatitude:
begin
if (glpLeft in FGridLabels.Position) and InRange(P1.X, AMapRect.Left, AMapRect.Right) then
if (glpLeft in FLabelPositions) and InRange(P1.X, AMapRect.Left, AMapRect.Right) then
begin
txtRect[glpLeft] := Rect(0, 0, txtSize.CX, txtSize.CY);
OffsetRect(txtRect[glpLeft], P1.X + FGridLabels.Distance, P1.Y - txtSize.CY div 2);
OffsetRect(txtRect[glpLeft], P1.X + FLabelDistance, P1.Y - txtSize.CY div 2);
end else
txtRect[glpLeft] := Rect(AMapRect.Left, P1.Y, AMapRect.Left, P1.Y);
if (glpRight in FGridLabels.Position) and InRange(P1.X, AMapRect.Left, AMapRect.Right) then
if (glpRight in FLabelPositions) and InRange(P1.X, AMapRect.Left, AMapRect.Right) then
begin
txtRect[glpRight] := Rect(0, 0, txtSize.CX, txtSize.CY);
OffsetRect(txtRect[glpRight], P2.X - txtSize.CX - FGridLabels.Distance, P1.Y - txtSize.CY div 2);
OffsetRect(txtRect[glpRight], P2.X - txtSize.CX - FLabelDistance, P1.Y - txtSize.CY div 2);
end else
txtRect[glpRight] := Rect(AMapRect.Right, P1.Y, AMapRect.Right, P1.Y);
end;
gctLongitude:
begin
if (glpTop in FGridLabels.Position) then
if (glpTop in FLabelPositions) then
begin
txtRect[glpTop] := Rect(0, 0, txtSize.CX, txtSize.CY);
OffsetRect(txtRect[glpTop], P1.X - txtSize.CX div 2, P1.Y + FGridlabels.Distance);
OffsetRect(txtRect[glpTop], P1.X - txtSize.CX div 2, P1.Y + FLabelDistance);
end else
txtRect[glpTop] := Rect(P1.X, AMapRect.Top, P1.X, AMapRect.Top);
if (glpBottom in FGridLabels.Position) then
if (glpBottom in FLabelPositions) then
begin
txtRect[glpBottom] := Rect(0, 0, txtSize.CX, txtSize.CY);
OffsetRect(txtRect[glpBottom], P1.X - txtSize.CX div 2, P2.Y - txtSize.CY - FGridLabels.Distance);
OffsetRect(txtRect[glpBottom], P1.X - txtSize.CX div 2, P2.Y - txtSize.CY - FLabelDistance);
end else
txtRect[glpBottom] := Rect(P1.X, AMapRect.Bottom, P1.X, AMapRect.Bottom);
end;
end;
for glp in TMvGridLabelPositions do
for glp in TMapGridLabelPositions do
begin
if txtRect[glp].Top < AMapRect.Top then OffsetRect(txtRect[glp], 0, AMapRect.Top - txtRect[glp].Top);
if txtRect[glp].Bottom > AMapRect.Bottom then OffsetRect(txtRect[glp], 0, AMapRect.Bottom - txtRect[glp].Bottom);
@ -316,24 +273,24 @@ begin
// Draw (semi-transparent) background
if FBackgroundColor <> clNone then
begin
ADrawingEngine.Opacity := FOpacity;
ADrawingEngine.Opacity := FBackgroundOpacity;
ADrawingEngine.BrushStyle := bsSolid;
case coordType of
gctLatitude:
begin
if (glpLeft in FGridLabels.Position) then
if (glpLeft in FLabelPositions) then
with txtRect[glpLeft] do
ADrawingEngine.FillRect(Left, Top, Right, Bottom);
if (glpRight in FGridLabels.Position) then
if (glpRight in FLabelPositions) then
with txtRect[glpRight] do
ADrawingEngine.FillRect(Left, Top, Right, Bottom);
end;
gctLongitude:
begin
if (glpTop in FGridLabels.Position) then
if (glpTop in FLabelPositions) then
with txtRect[glpTop] do
ADrawingEngine.FillRect(Left, top, Right, Bottom);
if (glpBottom in FGridLabels.Position) then
if (glpBottom in FLabelPositions) then
with txtRect[glpBottom] do
ADrawingEngine.FillRect(Left, Top, Right, Bottom);
end;
@ -346,18 +303,18 @@ begin
case coordType of
gctLatitude:
begin
if glpLeft in FGridlabels.Position then
if glpLeft in FLabelPositions then
with txtRect[glpLeft] do
ADrawingEngine.TextOut(Left, Top, s);
if glpRight in FGridLabels.Position then
if glpRight in FLabelPositions then
with txtRect[glpRight] do
ADrawingEngine.TextOut(Left, Top, s);
end;
gctLongitude:
begin
if glpTop in FGridLabels.Position then
if glpTop in FLabelPositions then
with txtRect[glpTop] do ADrawingEngine.TextOut(Left, Top, s);
if glpBottom in FGridLabels.Position then
if glpBottom in FLabelPositions then
with txtRect[glpBottom] do ADrawingEngine.TextOut(Left, Top, s);
end;
end;
@ -367,7 +324,7 @@ end;
* Area - Area covered by the map, in (monotonous) degrees
* AMapRect - dto., in pixels.
* AIncrement - distance between grid lines, in degrees. }
procedure TGridPlugin.DrawHorGridLines(AMapView: TMapView; Area: TRealArea;
procedure TMapGridPlugin.DrawHorGridLines(AMapView: TMapView; Area: TRealArea;
AMapRect: TRect; AIncrement: Double);
var
rP1, rP2: TRealPoint; // Top and bottom points of each gridline, in degrees
@ -414,7 +371,7 @@ end;
* Area - Area covered by the map, in (monotonous) degrees
* AMapRect - dto., in pixels.
* AIncrement - distance between grid lines, in degrees. }
procedure TGridPlugin.DrawVertGridlines(AMapView: TMapView; Area: TRealArea;
procedure TMapGridPlugin.DrawVertGridlines(AMapView: TMapView; Area: TRealArea;
AMapRect: TRect; AIncrement: Double);
var
rP1, rP2: TRealPoint; // top and bottom points of each gridline, in degrees
@ -463,7 +420,7 @@ begin
end;
end;
function TGridPlugin.GetLatLonAsString(AValue: Double; ACoordType: TGridCoordType): String;
function TMapGridPlugin.GetLatLonAsString(AValue: Double; ACoordType: TGridCoordType): String;
var
degs, mins, secs: Double;
secsZero: Boolean;
@ -495,7 +452,7 @@ begin
end;
end;
procedure TGridPlugin.SetBackgroundColor(AValue: TColor);
procedure TMapGridPlugin.SetBackgroundColor(AValue: TColor);
begin
if FBackgroundColor <> AValue then
begin
@ -504,13 +461,22 @@ begin
end;
end;
procedure TGridPlugin.SetFont(AValue: TFont);
procedure TMapGridPlugin.SetBackgroundOpacity(AValue: Single);
begin
if FBackgroundOpacity <> AValue then
begin
FBackgroundOpacity := AValue;
Update;
end;
end;
procedure TMapGridPlugin.SetFont(AValue: TFont);
begin
FFont := AValue;
Update;
end;
procedure TGridPlugin.SetIncrement(AValue: Double);
procedure TMapGridPlugin.SetIncrement(AValue: Double);
begin
if FIncrement <> AValue then
begin
@ -519,7 +485,25 @@ begin
end;
end;
procedure TGridPlugin.SetMaxDistance(AValue: Integer);
procedure TMapGridPlugin.SetLabelDistance(AValue: Integer);
begin
if FLabelDistance <> AValue then
begin
FLabelDistance := AValue;
Update;
end;
end;
procedure TMapGridPlugin.SetLabelPositions(AValue: TMapGridLabelPositions);
begin
if FLabelPositions <> AValue then
begin
FLabelPositions := AValue;
Update;
end;
end;
procedure TMapGridPlugin.SetMaxDistance(AValue: Integer);
begin
if FMaxDistance <> AValue then
begin
@ -528,7 +512,7 @@ begin
end;
end;
procedure TGridPlugin.SetMinDistance(AValue: Integer);
procedure TMapGridPlugin.SetMinDistance(AValue: Integer);
begin
if FMinDistance <> AValue then
begin
@ -537,23 +521,15 @@ begin
end;
end;
procedure TGridPlugin.SetOpacity(AValue: Single);
begin
if FOpacity <> AValue then
begin
FOpacity := AValue;
Update;
end;
end;
procedure TGridPlugin.SetPen(AValue: TPen);
procedure TMapGridPlugin.SetPen(AValue: TPen);
begin
FPen.Assign(AValue);
Update;
end;
initialization
RegisterPluginClass(TGridPlugin, 'Degrees grid');
RegisterPluginClass(TMapGridPlugin, 'Map grid');
end.