LazMapViewer: New class TMvMultiMapsDrawPlugin combining TMvMultiMapsPlugin and TMvDrawPlugin used for the LegalNotice-Plugin.
Added published Property DragMouseButton in the TDraggableMarkerPlugin to allow dragging with specific MouseButtons. Contributed by Ekkehard Domning. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9550 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
0b8056db78
commit
8457b3b34a
@ -12,7 +12,6 @@
|
||||
<XPManifest>
|
||||
<DpiAware Value="True"/>
|
||||
</XPManifest>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
|
@ -45,7 +45,7 @@ type
|
||||
|
||||
TLegalNoticePosition = (lnpTopLeft, lnpTopRight, lnpBottomLeft, lnpBottomRight);
|
||||
|
||||
TLegalNoticePlugin = class(TMvMultiMapsPlugin)
|
||||
TLegalNoticePlugin = class(TMvMultiMapsDrawPlugin)
|
||||
private
|
||||
const
|
||||
DEFAULT_LEGALNOTICE_OPACITY = 0.55;
|
||||
@ -55,13 +55,11 @@ type
|
||||
FLegalNoticeURL: String;
|
||||
FBackgroundOpacity: Single;
|
||||
FPosition: TLegalNoticePosition;
|
||||
FFont: TFont;
|
||||
FSpacing: Integer;
|
||||
FBackgroundColor: TColor;
|
||||
private
|
||||
procedure SetBackgroundColor(AValue: TColor);
|
||||
procedure SetBackgroundOpacity(AValue: Single);
|
||||
procedure SetFont(AValue: TFont);
|
||||
procedure SetLegalNotice(AValue: String);
|
||||
procedure SetLegalNoticeURL(AValue: String);
|
||||
procedure SetPosition(AValue: TLegalNoticePosition);
|
||||
@ -83,12 +81,12 @@ type
|
||||
published
|
||||
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor default clNone;
|
||||
property BackgroundOpacity: Single read FBackgroundOpacity write SetBackgroundOpacity default DEFAULT_LEGALNOTICE_OPACITY; // 0..1
|
||||
property Font: TFont read FFont write SetFont;
|
||||
property LegalNotice: String read FLegalNotice write SetLegalNotice;
|
||||
property LegalNoticeURL: String read FLegalNoticeURL write SetLegalNoticeURL;
|
||||
property Position: TLegalNoticePosition read FPosition write SetPosition default lnpBottomRight;
|
||||
property Spacing: Integer read FSpacing write SetSpacing default DEFAULT_LEGALNOTICE_SPACING;
|
||||
// inherited properties
|
||||
property Font;
|
||||
property MapView;
|
||||
end;
|
||||
|
||||
@ -101,7 +99,7 @@ type
|
||||
{ TDraggableMarkerData }
|
||||
PDraggableMarkerData = ^TDraggableMarkerData;
|
||||
TDraggableMarkerData = record
|
||||
FDraggableMarker : TGPSPoint;
|
||||
FDraggedMarker : TGPSPoint;
|
||||
FOrgPosition : TRealPoint;
|
||||
end;
|
||||
|
||||
@ -109,7 +107,10 @@ type
|
||||
private
|
||||
FDraggableMarkerCanMoveEvent : TDraggableMarkerCanMoveEvent;
|
||||
FDraggableMarkerMovedEvent : TDraggableMarkerMovedEvent;
|
||||
FDragMouseButton: TMouseButton;
|
||||
function GetFirstMarkerAtMousePos(const AMapView: TMapView; const AX, AY : Integer) : TGPSPoint;
|
||||
function GetDraggedMarker(AMapView : TMapView) : TGPSPoint;
|
||||
function GetOrgPosition(AMapView : TMapView): TRealPoint;
|
||||
protected
|
||||
procedure MouseDown(AMapView: TMapView; {%H-}Button: TMouseButton; {%H-}Shift: TShiftState;
|
||||
X, Y: Integer; var Handled: Boolean); override;
|
||||
@ -120,9 +121,10 @@ type
|
||||
published
|
||||
property DraggableMarkerCanMoveEvent : TDraggableMarkerCanMoveEvent read FDraggableMarkerCanMoveEvent write FDraggableMarkerCanMoveEvent;
|
||||
property DraggableMarkerMovedEvent : TDraggableMarkerMovedEvent read FDraggableMarkerMovedEvent write FDraggableMarkerMovedEvent;
|
||||
property DragMouseButton : TMouseButton read FDragMouseButton write FDragMouseButton default mbLeft;
|
||||
public
|
||||
// property DraggableMarker : TGPSPoint read FDraggableMarker;
|
||||
// property OrgPosition : TRealPoint read FOrgPosition;
|
||||
property DraggedMarker[AMapView : TMapView] : TGPSPoint read GetDraggedMarker;
|
||||
property OrgPosition[AMapView : TMapView] : TRealPoint read GetOrgPosition;
|
||||
procedure Assign(Source: TPersistent); override;
|
||||
end;
|
||||
|
||||
@ -319,24 +321,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
(*
|
||||
procedure TLinkedMapsPlugin.ZoomChanging(AMapView: TMapView;
|
||||
var NewZoom, Handled: Boolean);
|
||||
var
|
||||
i: integer;
|
||||
map: TMapView;
|
||||
begin
|
||||
if FLocked > 0 then
|
||||
exit;
|
||||
inc(FLocked);
|
||||
try
|
||||
for i := = to PluginManager.MapList.Count-1 do
|
||||
begin
|
||||
map := TMapView(PluginManager.MapList[i]);
|
||||
if AMapView <> map then
|
||||
map.ZoomChanging(NewZoom, Allow);
|
||||
*)
|
||||
|
||||
|
||||
{ TLegalNoticePlugin }
|
||||
|
||||
@ -344,16 +328,13 @@ constructor TLegalNoticePlugin.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FBackgroundColor := clNone;
|
||||
FPosition := lnpBottomRight;
|
||||
FFont := TFont.Create;
|
||||
FFont.OnChange := @Changed;
|
||||
FBackgroundOpacity := DEFAULT_LEGALNOTICE_OPACITY;
|
||||
FPosition := lnpBottomRight;
|
||||
FSpacing := DEFAULT_LEGALNOTICE_SPACING;
|
||||
end;
|
||||
|
||||
destructor TLegalNoticePlugin.Destroy;
|
||||
begin
|
||||
FFont.Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
@ -363,7 +344,6 @@ begin
|
||||
begin
|
||||
FBackgroundColor := TLegalNoticePlugin(Source).BackgroundColor;
|
||||
FBackgroundOpacity := TLegalNoticePlugin(Source).BackgroundOpacity;
|
||||
FFont.Assign(TLegalNoticePlugin(Source).Font);
|
||||
FLegalNotice := TLegalNoticePlugin(Source).LegalNotice;
|
||||
FLegalNoticeURL := TLegalNoticePlugin(Source).LegalNoticeURL;
|
||||
FPosition := TLegalNoticePlugin(Source).Position;
|
||||
@ -396,7 +376,7 @@ begin
|
||||
AMapView.DrawingEngine.FillRect(Left, Top, Right, Bottom);
|
||||
end;
|
||||
AMapView.DrawingEngine.BrushStyle := bsClear;
|
||||
AMapView.DrawingEngine.SetFont(FFont.Name, FFont.Size, FFont.Style, FFont.Color);
|
||||
AMapView.DrawingEngine.SetFont(Font.Name, Font.Size, Font.Style, Font.Color);
|
||||
AMapView.DrawingEngine.TextOut(x, y, FLegalNotice);
|
||||
finally
|
||||
AMapView.DrawingEngine.Opacity := lSavedOpacity;
|
||||
@ -413,7 +393,7 @@ var
|
||||
begin
|
||||
lSavedFont := AMapView.DrawingEngine.GetFont;
|
||||
try
|
||||
AMapView.DrawingEngine.SetFont(FFont.Name, FFont.Size, FFont.Style, FFont.Color);
|
||||
AMapView.DrawingEngine.SetFont(Font.Name, Font.Size, Font.Style, Font.Color);
|
||||
sz := AMapView.DrawingEngine.TextExtent(FLegalNotice);
|
||||
case FPosition of
|
||||
lnpTopLeft, lnpBottomLeft:
|
||||
@ -478,12 +458,12 @@ begin
|
||||
if PtInRect(lClickableRect, Point(X, Y)) and (not AMapView.Engine.InDrag) and
|
||||
(FLegalNoticeURL <> '') then
|
||||
begin
|
||||
FFont.Style := [fsUnderline];
|
||||
Font.Style := [fsUnderline];
|
||||
AMapView.Cursor := crHandPoint;
|
||||
Handled := true;
|
||||
end else
|
||||
begin
|
||||
FFont.Style := [];
|
||||
Font.Style := [];
|
||||
if not Handled then
|
||||
AMapView.Cursor := crDefault;
|
||||
end;
|
||||
@ -525,12 +505,6 @@ begin
|
||||
Update;
|
||||
end;
|
||||
|
||||
procedure TLegalNoticePlugin.SetFont(AValue: TFont);
|
||||
begin
|
||||
FFont.Assign(AValue);
|
||||
Update;
|
||||
end;
|
||||
|
||||
procedure TLegalNoticePlugin.SetSpacing(AValue: Integer);
|
||||
begin
|
||||
if FSpacing = AValue then Exit;
|
||||
@ -579,17 +553,40 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TDraggableMarkerPlugin.GetDraggedMarker(AMapView: TMapView): TGPSPoint;
|
||||
var
|
||||
lDraggableMarkerData : TDraggableMarkerData;
|
||||
cnt : Integer;
|
||||
begin
|
||||
Result := Nil;
|
||||
cnt := GetMapViewData(AMapView,lDraggableMarkerData,SizeOf(lDraggableMarkerData));
|
||||
if (cnt >= SizeOf(lDraggableMarkerData)) then
|
||||
Result := lDraggableMarkerData.FDraggedMarker;
|
||||
end;
|
||||
|
||||
function TDraggableMarkerPlugin.GetOrgPosition(AMapView : TMapView): TRealPoint;
|
||||
var
|
||||
lDraggableMarkerData : TDraggableMarkerData;
|
||||
cnt : Integer;
|
||||
begin
|
||||
Result.InitXY(0.0,0.0);
|
||||
cnt := GetMapViewData(AMapView,lDraggableMarkerData,SizeOf(lDraggableMarkerData));
|
||||
if (cnt >= SizeOf(lDraggableMarkerData)) then
|
||||
Result := lDraggableMarkerData.FOrgPosition;
|
||||
end;
|
||||
|
||||
procedure TDraggableMarkerPlugin.MouseDown(AMapView: TMapView; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer; var Handled: Boolean);
|
||||
var
|
||||
lDraggableMarkerData : TDraggableMarkerData;
|
||||
begin
|
||||
if Handled then Exit;
|
||||
lDraggableMarkerData.FDraggableMarker := GetFirstMarkerAtMousePos(AMapView,X,Y);
|
||||
if Assigned(lDraggableMarkerData.FDraggableMarker) then
|
||||
if FDragMouseButton <> Button then Exit;
|
||||
lDraggableMarkerData.FDraggedMarker := GetFirstMarkerAtMousePos(AMapView,X,Y);
|
||||
if Assigned(lDraggableMarkerData.FDraggedMarker) then
|
||||
begin
|
||||
lDraggableMarkerData.FOrgPosition.Lon:= lDraggableMarkerData.FDraggableMarker.Lon;
|
||||
lDraggableMarkerData.FOrgPosition.Lat:= lDraggableMarkerData.FDraggableMarker.Lat;
|
||||
lDraggableMarkerData.FOrgPosition.Lon:= lDraggableMarkerData.FDraggedMarker.Lon;
|
||||
lDraggableMarkerData.FOrgPosition.Lat:= lDraggableMarkerData.FDraggedMarker.Lat;
|
||||
SetMapViewData(AMapView,lDraggableMarkerData,SizeOf(lDraggableMarkerData));
|
||||
Handled := True;
|
||||
end;
|
||||
@ -607,14 +604,14 @@ var
|
||||
begin
|
||||
cnt := GetMapViewData(AMapView,lDraggableMarkerData,SizeOf(lDraggableMarkerData));
|
||||
if (cnt >= SizeOf(lDraggableMarkerData)) and
|
||||
Assigned(lDraggableMarkerData.FDraggableMarker) then
|
||||
Assigned(lDraggableMarkerData.FDraggedMarker) then
|
||||
begin
|
||||
pt.X := X;
|
||||
pt.Y := Y;
|
||||
rpt := AMapView.ScreenToLatLon(pt);
|
||||
ele := lDraggableMarkerData.FDraggableMarker.Elevation;
|
||||
dt := lDraggableMarkerData.FDraggableMarker.DateTime;
|
||||
lDraggableMarkerData.FDraggableMarker.MoveTo(rpt.Lon, rpt.Lat,ele,dt);
|
||||
ele := lDraggableMarkerData.FDraggedMarker.Elevation;
|
||||
dt := lDraggableMarkerData.FDraggedMarker.DateTime;
|
||||
lDraggableMarkerData.FDraggedMarker.MoveTo(rpt.Lon, rpt.Lat,ele,dt);
|
||||
AMapView.Invalidate;
|
||||
Handled := True; // Prevent the dragging of the map!!
|
||||
end
|
||||
@ -628,7 +625,6 @@ begin
|
||||
else if not Handled then
|
||||
AMapView.Cursor := crDefault;
|
||||
end
|
||||
|
||||
end;
|
||||
|
||||
procedure TDraggableMarkerPlugin.MouseUp(AMapView: TMapView; Button: TMouseButton;
|
||||
@ -636,13 +632,14 @@ procedure TDraggableMarkerPlugin.MouseUp(AMapView: TMapView; Button: TMouseButto
|
||||
var
|
||||
lpDraggableMarkerData : PDraggableMarkerData;
|
||||
begin
|
||||
if FDragMouseButton <> Button then Exit;
|
||||
lpDraggableMarkerData := MapViewDataPtr[AMapView];
|
||||
if Assigned(lpDraggableMarkerData) and Assigned(lpDraggableMarkerData^.FDraggableMarker) then
|
||||
if Assigned(lpDraggableMarkerData) and Assigned(lpDraggableMarkerData^.FDraggedMarker) then
|
||||
begin
|
||||
if Assigned(FDraggableMarkerMovedEvent) then
|
||||
FDraggableMarkerMovedEvent(Self,lpDraggableMarkerData^.FDraggableMarker,lpDraggableMarkerData^.FOrgPosition);
|
||||
FDraggableMarkerMovedEvent(Self,lpDraggableMarkerData^.FDraggedMarker,lpDraggableMarkerData^.FOrgPosition);
|
||||
Handled := True;
|
||||
lpDraggableMarkerData^.FDraggableMarker := Nil;
|
||||
lpDraggableMarkerData^.FDraggedMarker := Nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -652,10 +649,12 @@ begin
|
||||
begin
|
||||
FDraggableMarkerCanMoveEvent := TDraggableMarkerPlugin(Source).DraggableMarkerCanMoveEvent;
|
||||
FDraggableMarkerMovedEvent := TDraggableMarkerPlugin(Source).DraggableMarkerMovedEvent;
|
||||
FDragMouseButton := TDraggableMarkerPlugin(Source).DragMouseButton;
|
||||
end;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
||||
{ TMvCustomPlugin }
|
||||
|
||||
procedure TUserDefinedPlugin.AfterDrawObjects(AMapView: TMapView;
|
||||
|
@ -160,6 +160,36 @@ type
|
||||
property Enabled;
|
||||
end;
|
||||
|
||||
{ TMvMultiMapsDrawPlugin }
|
||||
|
||||
TMvMultiMapsDrawPlugin = class(TMvMultiMapsPlugin)
|
||||
private
|
||||
const
|
||||
DEFAULT_OPACITY = 0.55;
|
||||
DEFAULT_BACKGROUND_COLOR = clWhite;
|
||||
private
|
||||
FBackgroundColor: TColor;
|
||||
FBackgroundOpacity: Single;
|
||||
FFont: TFont;
|
||||
FPen: TPen;
|
||||
function IsOpacityStored: Boolean;
|
||||
procedure SetBackgroundColor(AValue: TColor);
|
||||
procedure SetBackgroundOpacity(AValue: Single);
|
||||
procedure SetFont(AValue: TFont);
|
||||
procedure SetPen(AValue: TPen);
|
||||
protected
|
||||
procedure Changed(Sender: TObject);
|
||||
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor default DEFAULT_BACKGROUND_COLOR;
|
||||
property BackgroundOpacity: Single read FBackgroundOpacity write SetBackgroundOpacity stored IsOpacityStored;
|
||||
property Font: TFont read FFont write SetFont;
|
||||
property Pen: TPen read FPen write SetPen;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure Assign(ASource: TPersistent); override;
|
||||
end;
|
||||
|
||||
|
||||
TMvCustomPluginClass = class of TMvCustomPlugin;
|
||||
|
||||
TMvPluginList = class(TMvIndexedComponentList)
|
||||
@ -682,6 +712,92 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
{ TMvMultiMapsDrawPlugin }
|
||||
|
||||
constructor TMvMultiMapsDrawPlugin.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FBackgroundColor := DEFAULT_BACKGROUND_COLOR;
|
||||
FBackgroundOpacity := DEFAULT_OPACITY;
|
||||
FFont := TFont.Create;
|
||||
FFont.OnChange := @Changed;
|
||||
FPen := TPen.Create;
|
||||
FPen.OnChange := @Changed;
|
||||
end;
|
||||
|
||||
destructor TMvMultiMapsDrawPlugin.Destroy;
|
||||
begin
|
||||
FFont.Free;
|
||||
FPen.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TMvMultiMapsDrawPlugin.Assign(ASource: TPersistent);
|
||||
begin
|
||||
if ASource is TMvDrawPlugin then
|
||||
begin
|
||||
FBackgroundColor := TMvDrawPlugin(ASource).BackgroundColor;
|
||||
FBackgroundOpacity := TMvDrawPlugin(ASource).BackgroundOpacity;
|
||||
FFont.Assign(TMvDrawPlugin(ASource).Font);
|
||||
FPen.Assign(TMvDrawPlugin(ASource).Pen);
|
||||
end;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TMvMultiMapsDrawPlugin.Changed(Sender: TObject);
|
||||
begin
|
||||
Update;
|
||||
end;
|
||||
|
||||
function TMvMultiMapsDrawPlugin.IsOpacityStored: Boolean;
|
||||
begin
|
||||
Result := FBackgroundOpacity <> DEFAULT_OPACITY;
|
||||
end;
|
||||
|
||||
procedure TMvMultiMapsDrawPlugin.SetBackgroundColor(AValue: TColor);
|
||||
begin
|
||||
if FBackgroundColor <> AValue then
|
||||
begin
|
||||
FBackgroundColor := AValue;
|
||||
Update;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMvMultiMapsDrawPlugin.SetBackgroundOpacity(AValue: Single);
|
||||
begin
|
||||
if FBackgroundOpacity <> AValue then
|
||||
begin
|
||||
FBackgroundOpacity := AValue;
|
||||
Update;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMvMultiMapsDrawPlugin.SetFont(AValue: TFont);
|
||||
begin
|
||||
if (AValue = nil) then
|
||||
exit;
|
||||
if (AValue.Name = FFont.Name) and (AValue.Size = FFont.Size) and
|
||||
(AValue.Style = FFont.Style) and (AValue.Color = FFont.Color)
|
||||
then
|
||||
exit;
|
||||
FFont.Assign(AValue);
|
||||
Changed(Self);
|
||||
end;
|
||||
|
||||
procedure TMvMultiMapsDrawPlugin.SetPen(AValue: TPen);
|
||||
begin
|
||||
if (AValue = nil) then
|
||||
exit;
|
||||
if (AValue.Color = FPen.Color) and (AValue.Width = FPen.Width) and
|
||||
(AValue.Style = FPen.Style) and (AValue.Mode = FPen.Mode) and
|
||||
(AValue.JoinStyle = FPen.JoinStyle) and (AValue.EndCap = FPen.EndCap)
|
||||
then
|
||||
exit;
|
||||
FPen.Assign(AValue);
|
||||
Changed(Self);
|
||||
end;
|
||||
|
||||
|
||||
{ TMvPluginList }
|
||||
|
||||
function TMvPluginList.GetItem(AIndex: Integer): TMvCustomPlugin;
|
||||
|
Loading…
Reference in New Issue
Block a user