LazMapViewer: Add new property TLegalNoticePlugin.Opacity. Update demo.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9517 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-12-09 17:30:50 +00:00
parent 58a4ae4f18
commit baf28e29fb
3 changed files with 189 additions and 15 deletions

View File

@ -3,7 +3,7 @@ object Form1: TForm1
Height = 487 Height = 487
Top = 130 Top = 130
Width = 977 Width = 977
Caption = 'Form1' Caption = 'Legal Notice Plugin Demo'
ClientHeight = 487 ClientHeight = 487
ClientWidth = 977 ClientWidth = 977
LCLVersion = '4.99.0.0' LCLVersion = '4.99.0.0'
@ -93,6 +93,32 @@ object Form1: TForm1
TabOrder = 4 TabOrder = 4
OnChange = CheckBox2Change OnChange = CheckBox2Change
end end
object Label2: TLabel
AnchorSideTop.Control = CheckBox1
AnchorSideTop.Side = asrCenter
Left = 387
Height = 15
Top = 38
Width = 124
Caption = 'Legal note opacity: (%):'
end
object SpinEdit1: TSpinEdit
AnchorSideLeft.Control = Label2
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrCenter
Left = 519
Height = 23
Top = 34
Width = 69
Alignment = taRightJustify
BorderSpacing.Left = 8
Increment = 5
MaxValue = 100
TabOrder = 5
Value = 50
OnChange = FloatSpinEdit1Change
end
end end
object Bevel1: TBevel object Bevel1: TBevel
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, Types, Classes, SysUtils, Types,
LCLIntf, Forms, Controls, Graphics, ExtCtrls, StdCtrls, Dialogs, LCLIntf, Forms, Controls, Graphics, ExtCtrls, StdCtrls, Dialogs, Spin,
TAGraph, TATools, TAGraph, TATools,
mvMapViewer, mvPluginCore, mvPlugins; mvMapViewer, mvPluginCore, mvPlugins;
@ -18,7 +18,9 @@ type
CheckBox2: TCheckBox; CheckBox2: TCheckBox;
ComboBox1: TComboBox; ComboBox1: TComboBox;
Edit1: TEdit; Edit1: TEdit;
SpinEdit1: TSpinEdit;
Label1: TLabel; Label1: TLabel;
Label2: TLabel;
Panel1: TPanel; Panel1: TPanel;
Panel2: TPanel; Panel2: TPanel;
Panel3: TPanel; Panel3: TPanel;
@ -27,6 +29,7 @@ type
procedure CheckBox2Change(Sender: TObject); procedure CheckBox2Change(Sender: TObject);
procedure ComboBox1Change(Sender: TObject); procedure ComboBox1Change(Sender: TObject);
procedure Edit1Change(Sender: TObject); procedure Edit1Change(Sender: TObject);
procedure FloatSpinEdit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
private private
FMapView1: TMapView; FMapView1: TMapView;
@ -80,9 +83,9 @@ begin
Font.Color := clBlue; Font.Color := clBlue;
BackgroundColor := clWhite; BackgroundColor := clWhite;
MapView := FMapView1; MapView := FMapView1;
//PluginManager := FPluginManager; // why is this necessary?
Edit1.Text := LegalNotice; Edit1.Text := LegalNotice;
SpinEdit1.Value := round(Opacity * 100);
end; end;
with TLegalNoticePlugin.Create(FPluginManager) do with TLegalNoticePlugin.Create(FPluginManager) do
@ -94,7 +97,6 @@ begin
Font.Color := clBlue; Font.Color := clBlue;
BackgroundColor := clWhite; BackgroundColor := clWhite;
MapView := FMapView2; MapView := FMapView2;
PluginManager := FPluginManager; // why is this necessary?
end; end;
with TCenterMarkerPlugin.Create(FPluginManager) do with TCenterMarkerPlugin.Create(FPluginManager) do
@ -112,6 +114,13 @@ begin
(FPluginManager.Item[0] as TLegalNoticePlugin).LegalNotice := Edit1.Text; (FPluginManager.Item[0] as TLegalNoticePlugin).LegalNotice := Edit1.Text;
end; end;
procedure TForm1.FloatSpinEdit1Change(Sender: TObject);
begin
(FPluginManager.Item[0] as TLegalNoticePlugin).Opacity := SpinEdit1.Value / 100;
if FPluginManager.PluginList.Count > 1 then
(FPluginManager.Item[1] as TLegalNoticePlugin).Opacity := SpinEdit1.Value / 100;
end;
procedure TForm1.Button1Click(Sender: TObject); procedure TForm1.Button1Click(Sender: TObject);
begin begin
FMapView1.SaveToFile(TPortableNetworkGraphic, 'map1.png'); FMapView1.SaveToFile(TPortableNetworkGraphic, 'map1.png');

View File

@ -52,10 +52,12 @@ type
TLegalNoticePlugin = class(TMvMultiMapsPlugin) TLegalNoticePlugin = class(TMvMultiMapsPlugin)
private private
const const
DEFAULT_LEGALNOTICE_OPACITY = 0.55;
DEFAULT_LEGALNOTICE_SPACING = 4; DEFAULT_LEGALNOTICE_SPACING = 4;
private private
FLegalNotice: String; FLegalNotice: String;
FLegalNoticeURL: String; FLegalNoticeURL: String;
FOpacity: Single;
FPosition: TLegalNoticePosition; FPosition: TLegalNoticePosition;
FFont: TFont; FFont: TFont;
FSpacing: Integer; FSpacing: Integer;
@ -65,6 +67,7 @@ type
procedure SetFont(AValue: TFont); procedure SetFont(AValue: TFont);
procedure SetLegalNotice(AValue: String); procedure SetLegalNotice(AValue: String);
procedure SetLegalNoticeURL(AValue: String); procedure SetLegalNoticeURL(AValue: String);
procedure SetOpacity(AValue: Single);
procedure SetPosition(AValue: TLegalNoticePosition); procedure SetPosition(AValue: TLegalNoticePosition);
procedure SetSpacing(AValue: Integer); procedure SetSpacing(AValue: Integer);
protected protected
@ -86,6 +89,7 @@ type
property Font: TFont read FFont write SetFont; property Font: TFont read FFont write SetFont;
property LegalNotice: String read FLegalNotice write SetLegalNotice; property LegalNotice: String read FLegalNotice write SetLegalNotice;
property LegalNoticeURL: String read FLegalNoticeURL write SetLegalNoticeURL; property LegalNoticeURL: String read FLegalNoticeURL write SetLegalNoticeURL;
property Opacity: Single read FOpacity write SetOpacity default DEFAULT_LEGALNOTICE_OPACITY;
property Position: TLegalNoticePosition read FPosition write SetPosition default lnpBottomRight; property Position: TLegalNoticePosition read FPosition write SetPosition default lnpBottomRight;
property Spacing: Integer read FSpacing write SetSpacing default DEFAULT_LEGALNOTICE_SPACING; property Spacing: Integer read FSpacing write SetSpacing default DEFAULT_LEGALNOTICE_SPACING;
// inherited properties // inherited properties
@ -126,6 +130,58 @@ type
procedure Assign(Source: TPersistent); override; procedure Assign(Source: TPersistent); override;
end; end;
type
TMvPluginNotifyEvent = procedure (Sender : TObject; AMapView: TMapView; var Handled: Boolean) of Object;
TMvPluginMouseEvent = procedure (Sender : TObject; AMapView: TMapView; Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer; var Handled: Boolean) of Object;
TMvPluginMouseMoveEvent = procedure (Sender : TObject; AMapView: TMapView; AShift: TShiftState;
X,Y: Integer; var Handled: Boolean) of Object;
{ TUserDefinedPlugin }
TUserDefinedPlugin = class(TMvCustomPlugin)
private
FAfterDrawObjectsEvent : TMvPluginNotifyEvent;
FAfterPaintEvent : TMvPluginNotifyEvent;
FBeforeDrawObjectsEvent : TMvPluginNotifyEvent;
FCenterMoveEvent : TMvPluginNotifyEvent;
FMouseDownEvent : TMvPluginMouseEvent;
FMouseEnterEvent : TMvPluginNotifyEvent;
FMouseLeaveEvent : TMvPluginNotifyEvent;
FMouseMoveEvent : TMvPluginMouseMoveEvent;
FMouseUpEvent : TMvPluginMouseEvent;
FZoomChangeEvent : TMvPluginNotifyEvent;
protected
procedure AfterDrawObjects(AMapView: TMapView; var Handled: Boolean); override;
procedure AfterPaint(AMapView: TMapView; var Handled: Boolean); override;
procedure BeforeDrawObjects(AMapView: TMapView; var Handled: Boolean); override;
procedure CenterMove(AMapView: TMapView; var Handled: Boolean); override;
procedure MouseDown(AMapView: TMapView; Button: TMouseButton; Shift: TShiftState;
X, Y: Integer; var Handled: Boolean); override;
procedure MouseEnter(AMapView: TMapView; var Handled: Boolean); override;
procedure MouseLeave(AMapView: TMapView; var Handled: Boolean); override;
procedure MouseMove(AMapView: TMapView; AShift: TShiftState; X,Y: Integer;
var Handled: Boolean); override;
procedure MouseUp(AMapView: TMapView; Button: TMouseButton; Shift: TShiftState;
X, Y: Integer; var Handled: Boolean); override;
procedure ZoomChange(AMapView: TMapView; var Handled: Boolean); override;
public
published
property OnAfterDrawObjects : TMvPluginNotifyEvent read FAfterDrawObjectsEvent write FAfterDrawObjectsEvent;
property OnAfterPaint : TMvPluginNotifyEvent read FAfterPaintEvent write FAfterPaintEvent;
property OnBeforeDrawObjects : TMvPluginNotifyEvent read FBeforeDrawObjectsEvent write FBeforeDrawObjectsEvent;
property OnCenterMove : TMvPluginNotifyEvent read FCenterMoveEvent write FCenterMoveEvent;
property OnMouseDown : TMvPluginMouseEvent read FMouseDownEvent write FMouseDownEvent;
property OnMouseEnter : TMvPluginNotifyEvent read FMouseEnterEvent write FMouseEnterEvent;
property OnMouseLeave : TMvPluginNotifyEvent read FMouseLeaveEvent write FMouseLeaveEvent;
property OnMouseMove : TMvPluginMouseMoveEvent read FMouseMoveEvent write FMouseMoveEvent;
property OnMouseUp : TMvPluginMouseEvent read FMouseUpEvent write FMouseUpEvent;
property OnZoomChange : TMvPluginNotifyEvent read FZoomChangeEvent write FZoomChangeEvent;
// inherited
property Enabled;
property MapView;
end;
implementation implementation
@ -267,6 +323,7 @@ begin
FPosition := lnpBottomRight; FPosition := lnpBottomRight;
FFont := TFont.Create; FFont := TFont.Create;
FFont.OnChange := @Changed; FFont.OnChange := @Changed;
FOpacity := DEFAULT_LEGALNOTICE_OPACITY;
FSpacing := DEFAULT_LEGALNOTICE_SPACING; FSpacing := DEFAULT_LEGALNOTICE_SPACING;
end; end;
@ -284,6 +341,7 @@ begin
FFont.Assign(TLegalNoticePlugin(Source).Font); FFont.Assign(TLegalNoticePlugin(Source).Font);
FLegalNotice := TLegalNoticePlugin(Source).LegalNotice; FLegalNotice := TLegalNoticePlugin(Source).LegalNotice;
FLegalNoticeURL := TLegalNoticePlugin(Source).LegalNoticeURL; FLegalNoticeURL := TLegalNoticePlugin(Source).LegalNoticeURL;
FOpacity := TLegalNoticePlugin(Source).Opacity;
FPosition := TLegalNoticePlugin(Source).Position; FPosition := TLegalNoticePlugin(Source).Position;
FSpacing := TLegalNoticePlugin(Source).Spacing; FSpacing := TLegalNoticePlugin(Source).Spacing;
end; end;
@ -292,26 +350,32 @@ end;
procedure TLegalNoticePlugin.AfterDrawObjects(AMapView: TMapView; var Handled: Boolean); procedure TLegalNoticePlugin.AfterDrawObjects(AMapView: TMapView; var Handled: Boolean);
var var
x,y : Integer; x, y: Integer;
lSavedFont: TMvFont;
lClickableRect: TRect; lClickableRect: TRect;
lSavedFont: TMvFont;
lSavedOpacity: Single;
begin begin
if not Assigned(AMapView) then Exit; if not Assigned(AMapView) then Exit;
Handled := True; Handled := True;
if FBackgroundColor = clNone then
AMapView.DrawingEngine.BrushStyle := bsClear
else begin
AMapView.DrawingEngine.BrushStyle := bsSolid;
AMapView.DrawingEngine.BrushColor := FBackgroundColor;
end;
CalcClickableRect(AMapView,lClickableRect); CalcClickableRect(AMapView,lClickableRect);
x := lClickableRect.Left - FSpacing; x := lClickableRect.Left;
y := lClickableRect.Top - FSpacing; y := lClickableRect.Top;
lSavedFont := AMapView.DrawingEngine.GetFont; lSavedFont := AMapView.DrawingEngine.GetFont;
lSavedOpacity := AMapView.DrawingEngine.Opacity;
try try
if FBackgroundColor <> clNone then
begin
AMapView.DrawingEngine.Opacity := FOpacity;
AMapView.DrawingEngine.BrushStyle := bsSolid;
AMapView.DrawingEngine.BrushColor := ColorToRGB(FBackgroundColor);
with lClickableRect do
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(FFont.Name, FFont.Size, FFont.Style, FFont.Color);
AMapView.DrawingEngine.TextOut(x, y, FLegalNotice); AMapView.DrawingEngine.TextOut(x, y, FLegalNotice);
finally finally
AMapView.DrawingEngine.Opacity := lSavedOpacity;
AMapView.DrawingEngine.SetFont(lSavedFont); AMapView.DrawingEngine.SetFont(lSavedFont);
end; end;
end; end;
@ -339,7 +403,7 @@ begin
lnpBottomLeft, lnpBottomRight: lnpBottomLeft, lnpBottomRight:
y := AMapView.Height - sz.CY - FSpacing; y := AMapView.Height - sz.CY - FSpacing;
end; end;
AClickableRect := Rect(x + FSpacing, y + FSpacing, x + sz.CX, y + sz.CY); AClickableRect := Rect(x, y, x + sz.CX, y + sz.CY);
SetMapViewData(AMapView,AClickableRect,SizeOf(AClickableRect)); SetMapViewData(AMapView,AClickableRect,SizeOf(AClickableRect));
finally finally
AMapView.DrawingEngine.SetFont(lSavedFont); AMapView.DrawingEngine.SetFont(lSavedFont);
@ -401,6 +465,13 @@ begin
Update; Update;
end; end;
procedure TLegalNoticePlugin.SetOpacity(AValue: Single);
begin
if FOpacity = AValue then Exit;
FOpacity := AValue;
Update;
end;
procedure TLegalNoticePlugin.SetPosition(AValue: TLegalNoticePosition); procedure TLegalNoticePlugin.SetPosition(AValue: TLegalNoticePosition);
begin begin
if FPosition = AValue then Exit; if FPosition = AValue then Exit;
@ -560,12 +631,80 @@ begin
inherited; inherited;
end; end;
{ TMvCustomPlugin }
procedure TUserDefinedPlugin.AfterDrawObjects(AMapView: TMapView;
var Handled: Boolean);
begin
if Assigned(FAfterDrawObjectsEvent) then
FAfterDrawObjectsEvent(Self, AMapView, Handled);
end;
procedure TUserDefinedPlugin.AfterPaint(AMapView: TMapView; var Handled: Boolean);
begin
if Assigned(FAfterPaintEvent) then
FAfterPaintEvent(Self, AMapView, Handled);
end;
procedure TUserDefinedPlugin.BeforeDrawObjects(AMapView: TMapView;
var Handled: Boolean);
begin
if Assigned(FBeforeDrawObjectsEvent) then
FBeforeDrawObjectsEvent(Self, AMapView, Handled);
end;
procedure TUserDefinedPlugin.CenterMove(AMapView: TMapView; var Handled: Boolean);
begin
if Assigned(FCenterMoveEvent) then
FCenterMoveEvent(Self, AMapView, Handled);
end;
procedure TUserDefinedPlugin.MouseDown(AMapView: TMapView; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer; var Handled: Boolean);
begin
if Assigned(FMouseDownEvent) then
FMouseDownEvent(Self,AMapView, Button, Shift, X,Y, Handled);
end;
procedure TUserDefinedPlugin.MouseEnter(AMapView: TMapView; var Handled: Boolean);
begin
if Assigned(FMouseEnterEvent) then
FMouseEnterEvent(Self, AMapView, Handled);
end;
procedure TUserDefinedPlugin.MouseLeave(AMapView: TMapView; var Handled: Boolean);
begin
if Assigned(FMouseLeaveEvent) then
FMouseLeaveEvent(Self, AMapView, Handled);
end;
procedure TUserDefinedPlugin.MouseMove(AMapView: TMapView; AShift: TShiftState; X,
Y: Integer; var Handled: Boolean);
begin
if Assigned(FMouseMoveEvent) then
FMouseMoveEvent(Self,AMapView, AShift, X, Y, Handled);
end;
procedure TUserDefinedPlugin.MouseUp(AMapView: TMapView; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer; var Handled: Boolean);
begin
if Assigned(FMouseUpEvent) then
FMouseUpEvent(Self, AMapView, Button, Shift, X, Y, Handled);
end;
procedure TUserDefinedPlugin.ZoomChange(AMapView: TMapView; var Handled: Boolean);
begin
if Assigned(FZoomChangeEvent) then
FZoomChangeEvent(Self, AMapView, Handled);
end;
initialization initialization
RegisterPluginClass(TCenterMarkerPlugin, 'Center marker'); RegisterPluginClass(TCenterMarkerPlugin, 'Center marker');
RegisterPluginClass(TLegalNoticePlugin, 'Legal notice'); RegisterPluginClass(TLegalNoticePlugin, 'Legal notice');
RegisterPluginClass(TLinkedMapsPlugin, 'Linked maps'); RegisterPluginClass(TLinkedMapsPlugin, 'Linked maps');
RegisterPluginClass(TDraggableMarkerPlugin, 'Draggable marker'); RegisterPluginClass(TDraggableMarkerPlugin, 'Draggable marker');
RegisterPluginClass(TUserDefinedPlugin, 'User-defined');
end. end.