diff --git a/components/lazmapviewer/examples/plugin_demos/legalnotice_demo/unit1.lfm b/components/lazmapviewer/examples/plugin_demos/legalnotice_demo/unit1.lfm index 98b1957c8..348b6fa46 100644 --- a/components/lazmapviewer/examples/plugin_demos/legalnotice_demo/unit1.lfm +++ b/components/lazmapviewer/examples/plugin_demos/legalnotice_demo/unit1.lfm @@ -3,7 +3,7 @@ object Form1: TForm1 Height = 487 Top = 130 Width = 977 - Caption = 'Form1' + Caption = 'Legal Notice Plugin Demo' ClientHeight = 487 ClientWidth = 977 LCLVersion = '4.99.0.0' @@ -93,6 +93,32 @@ object Form1: TForm1 TabOrder = 4 OnChange = CheckBox2Change 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 object Bevel1: TBevel AnchorSideLeft.Control = Owner diff --git a/components/lazmapviewer/examples/plugin_demos/legalnotice_demo/unit1.pas b/components/lazmapviewer/examples/plugin_demos/legalnotice_demo/unit1.pas index 71f9adf53..476897e9b 100644 --- a/components/lazmapviewer/examples/plugin_demos/legalnotice_demo/unit1.pas +++ b/components/lazmapviewer/examples/plugin_demos/legalnotice_demo/unit1.pas @@ -6,7 +6,7 @@ interface uses Classes, SysUtils, Types, - LCLIntf, Forms, Controls, Graphics, ExtCtrls, StdCtrls, Dialogs, + LCLIntf, Forms, Controls, Graphics, ExtCtrls, StdCtrls, Dialogs, Spin, TAGraph, TATools, mvMapViewer, mvPluginCore, mvPlugins; @@ -18,7 +18,9 @@ type CheckBox2: TCheckBox; ComboBox1: TComboBox; Edit1: TEdit; + SpinEdit1: TSpinEdit; Label1: TLabel; + Label2: TLabel; Panel1: TPanel; Panel2: TPanel; Panel3: TPanel; @@ -27,6 +29,7 @@ type procedure CheckBox2Change(Sender: TObject); procedure ComboBox1Change(Sender: TObject); procedure Edit1Change(Sender: TObject); + procedure FloatSpinEdit1Change(Sender: TObject); procedure FormCreate(Sender: TObject); private FMapView1: TMapView; @@ -80,9 +83,9 @@ begin Font.Color := clBlue; BackgroundColor := clWhite; MapView := FMapView1; - //PluginManager := FPluginManager; // why is this necessary? Edit1.Text := LegalNotice; + SpinEdit1.Value := round(Opacity * 100); end; with TLegalNoticePlugin.Create(FPluginManager) do @@ -94,7 +97,6 @@ begin Font.Color := clBlue; BackgroundColor := clWhite; MapView := FMapView2; - PluginManager := FPluginManager; // why is this necessary? end; with TCenterMarkerPlugin.Create(FPluginManager) do @@ -112,6 +114,13 @@ begin (FPluginManager.Item[0] as TLegalNoticePlugin).LegalNotice := Edit1.Text; 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); begin FMapView1.SaveToFile(TPortableNetworkGraphic, 'map1.png'); diff --git a/components/lazmapviewer/source/addons/plugins/mvplugins.pas b/components/lazmapviewer/source/addons/plugins/mvplugins.pas index 942dbdf36..06f5a5764 100644 --- a/components/lazmapviewer/source/addons/plugins/mvplugins.pas +++ b/components/lazmapviewer/source/addons/plugins/mvplugins.pas @@ -52,10 +52,12 @@ type TLegalNoticePlugin = class(TMvMultiMapsPlugin) private const + DEFAULT_LEGALNOTICE_OPACITY = 0.55; DEFAULT_LEGALNOTICE_SPACING = 4; private FLegalNotice: String; FLegalNoticeURL: String; + FOpacity: Single; FPosition: TLegalNoticePosition; FFont: TFont; FSpacing: Integer; @@ -65,6 +67,7 @@ type procedure SetFont(AValue: TFont); procedure SetLegalNotice(AValue: String); procedure SetLegalNoticeURL(AValue: String); + procedure SetOpacity(AValue: Single); procedure SetPosition(AValue: TLegalNoticePosition); procedure SetSpacing(AValue: Integer); protected @@ -86,6 +89,7 @@ type property Font: TFont read FFont write SetFont; property LegalNotice: String read FLegalNotice write SetLegalNotice; 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 Spacing: Integer read FSpacing write SetSpacing default DEFAULT_LEGALNOTICE_SPACING; // inherited properties @@ -126,6 +130,58 @@ type procedure Assign(Source: TPersistent); override; 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 @@ -267,6 +323,7 @@ begin FPosition := lnpBottomRight; FFont := TFont.Create; FFont.OnChange := @Changed; + FOpacity := DEFAULT_LEGALNOTICE_OPACITY; FSpacing := DEFAULT_LEGALNOTICE_SPACING; end; @@ -284,6 +341,7 @@ begin FFont.Assign(TLegalNoticePlugin(Source).Font); FLegalNotice := TLegalNoticePlugin(Source).LegalNotice; FLegalNoticeURL := TLegalNoticePlugin(Source).LegalNoticeURL; + FOpacity := TLegalNoticePlugin(Source).Opacity; FPosition := TLegalNoticePlugin(Source).Position; FSpacing := TLegalNoticePlugin(Source).Spacing; end; @@ -292,26 +350,32 @@ end; procedure TLegalNoticePlugin.AfterDrawObjects(AMapView: TMapView; var Handled: Boolean); var - x,y : Integer; - lSavedFont: TMvFont; + x, y: Integer; lClickableRect: TRect; + lSavedFont: TMvFont; + lSavedOpacity: Single; begin if not Assigned(AMapView) then Exit; Handled := True; - if FBackgroundColor = clNone then - AMapView.DrawingEngine.BrushStyle := bsClear - else begin - AMapView.DrawingEngine.BrushStyle := bsSolid; - AMapView.DrawingEngine.BrushColor := FBackgroundColor; - end; CalcClickableRect(AMapView,lClickableRect); - x := lClickableRect.Left - FSpacing; - y := lClickableRect.Top - FSpacing; + x := lClickableRect.Left; + y := lClickableRect.Top; lSavedFont := AMapView.DrawingEngine.GetFont; + lSavedOpacity := AMapView.DrawingEngine.Opacity; 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.TextOut(x, y, FLegalNotice); finally + AMapView.DrawingEngine.Opacity := lSavedOpacity; AMapView.DrawingEngine.SetFont(lSavedFont); end; end; @@ -339,7 +403,7 @@ begin lnpBottomLeft, lnpBottomRight: y := AMapView.Height - sz.CY - FSpacing; 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)); finally AMapView.DrawingEngine.SetFont(lSavedFont); @@ -401,6 +465,13 @@ begin Update; end; +procedure TLegalNoticePlugin.SetOpacity(AValue: Single); +begin + if FOpacity = AValue then Exit; + FOpacity := AValue; + Update; +end; + procedure TLegalNoticePlugin.SetPosition(AValue: TLegalNoticePosition); begin if FPosition = AValue then Exit; @@ -560,12 +631,80 @@ begin inherited; 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 RegisterPluginClass(TCenterMarkerPlugin, 'Center marker'); RegisterPluginClass(TLegalNoticePlugin, 'Legal notice'); RegisterPluginClass(TLinkedMapsPlugin, 'Linked maps'); RegisterPluginClass(TDraggableMarkerPlugin, 'Draggable marker'); + RegisterPluginClass(TUserDefinedPlugin, 'User-defined'); end.