From 51ac49771eb437a20adc4f3e9466778ca0d455d8 Mon Sep 17 00:00:00 2001 From: "birbilis@zoomicon.com" Date: Fri, 25 Feb 2022 13:30:45 +0200 Subject: [PATCH] Added btnAddBitmapImageStoryItem to Edit sidebar, Fix show/Hide BitmapImageStoryItem's default Glyph when it gets image content --- App/READCOM.App.Globals.dfm | 51 ++++++++++++++++++ .../READCOM.Views.BitmapImageStoryItem.pas | 21 +++++++- App/Views/READCOM.Views.Main.fmx | 4 ++ App/Views/READCOM.Views.Main.pas | 35 +++++++++---- App/Views/READCOM.Views.Menu.HUD.fmx | 52 ++++++++++++++----- App/Views/READCOM.Views.Menu.HUD.pas | 12 +++-- 6 files changed, 148 insertions(+), 27 deletions(-) diff --git a/App/READCOM.App.Globals.dfm b/App/READCOM.App.Globals.dfm index 004d19a..7a52add 100644 --- a/App/READCOM.App.Globals.dfm +++ b/App/READCOM.App.Globals.dfm @@ -68844,6 +68844,49 @@ object Globals: TGlobals '"/>'#10' '#10' '#10''#10 Opacity = 1.000000000000000000 + end + item + MultiResBitmap = < + item + Size = 30 + end> + IconName = 'FramedPicture' + SVGText = + ''#10' '#10' '#10' ' + + ' '#10' '#10' <' + + 'path fill="#5C9E31" stroke="#5C9E31" stroke-linecap="round" stro' + + 'ke-linejoin="round" stroke-miterlimit="10" stroke-width="2" d="M' + + '50,35c-2.8958-0.8542-6.2795-7.9886-8-8c-4.208-0.0278-6.254,5.836' + + '-11,9c-3,2-3.3745,2.8497-6,4c-2.2824,1-3,3-3.25,3.6406 c-0.3031,' + + '0.7766-1.4751,2.5214-0.9583,3.1094c1.2083,1.375,2.4583,1.5,5,0.7' + + '179c2.147-0.6606,4.9769-4.8074,6.875-6.2179 c2.2708-1.6875,4.645' + + '8-2.5,8.0833-2c2.4795,0.3606,6.66,3.1723,7.8125,3.0625c1.3125-0.' + + '125-1.5937-2.5625-0.5312-4.1875 c1.1327-1.7325,2.9102,0.1529,3.6' + + '354-1.0833C51.9844,36.5,50.632,35.1864,50,35z"/>'#10' '#10' '#10' '#10' '#10' '#10' '#10' '#10' '#10' '#10' '#10' ' + + ''#10''#10 + Opacity = 1.000000000000000000 end> Destination = < item @@ -69030,6 +69073,14 @@ object Globals: TGlobals SourceRect.Bottom = 30.000000000000000000 end> end + item + Layers = < + item + Name = 'FramedPicture' + SourceRect.Right = 30.000000000000000000 + SourceRect.Bottom = 30.000000000000000000 + end> + end item Layers = <> end> diff --git a/App/Views/READCOM.Views.BitmapImageStoryItem.pas b/App/Views/READCOM.Views.BitmapImageStoryItem.pas index a342ef8..1c715e9 100644 --- a/App/Views/READCOM.Views.BitmapImageStoryItem.pas +++ b/App/Views/READCOM.Views.BitmapImageStoryItem.pas @@ -37,7 +37,6 @@ TBitmapImageStoryItem = class(TImageStoryItem, IBitmapImageStoryItem, IImageSt {Clipboard} procedure Paste(const Clipboard: IFMXExtendedClipboardService); overload; override; procedure PasteImage(const BitmapSurface: TBitmapSurface); override; - {Image} function GetImage: TImage; override; procedure SetImage(const Value: TImage); override; @@ -47,6 +46,7 @@ TBitmapImageStoryItem = class(TImageStoryItem, IBitmapImageStoryItem, IImageSt procedure SetEditMode(const Value: Boolean); override; procedure Loaded; override; + procedure UpdateGlyphVisibility; public constructor Create(AOwner: TComponent); override; @@ -97,12 +97,19 @@ constructor TBitmapImageStoryItem.Create(AOwner: TComponent); SendToBack; HitTest := false; end; + + Glyph.Visible := true; +end; + +procedure TBitmapImageStoryItem.UpdateGlyphVisibility; +begin + Glyph.Visible := not Assigned(ImageControl.Bitmap.Image); //hide default Glyph if we have a bitmap image end; procedure TBitmapImageStoryItem.Loaded; begin inherited; - Glyph.Visible := not Assigned(ImageControl.Bitmap.Image); //hide default Glyph if we have a bitmap image + UpdateGlyphVisibility; end; {$endregion} @@ -127,6 +134,10 @@ procedure TBitmapImageStoryItem.Paste(const Clipboard: IFMXExtendedClipboardServ procedure TBitmapImageStoryItem.PasteImage(const BitmapSurface: TBitmapSurface); begin ImageControl.Bitmap.Assign(BitmapSurface); + UpdateGlyphVisibility; + + if FAutoSize then + SetSize(ImageControl.Bitmap.Width, ImageControl.Bitmap.Height); //TODO: probably not needed end; {$endregion} @@ -149,6 +160,8 @@ procedure TBitmapImageStoryItem.Load(const Stream: TStream; const ContentFormat: procedure TBitmapImageStoryItem.LoadBitmap(const Stream: TStream); begin ImageControl.Bitmap.LoadFromStream(Stream); //TODO: does it detect PNG and JPEG automatically? + UpdateGlyphVisibility; + if FAutoSize then SetSize(ImageControl.Bitmap.Width, ImageControl.Bitmap.Height); //TODO: probably not needed end; @@ -167,6 +180,10 @@ function TBitmapImageStoryItem.GetImage: TImage; procedure TBitmapImageStoryItem.SetImage(const Value: TImage); begin ImageControl.Bitmap.Assign(Value.Bitmap); //can't assign TImage directly + UpdateGlyphVisibility; + + if FAutoSize then + SetSize(ImageControl.Bitmap.Width, ImageControl.Bitmap.Height); //TODO: probably not needed end; {$endregion} diff --git a/App/Views/READCOM.Views.Main.fmx b/App/Views/READCOM.Views.Main.fmx index c64cc38..87a9a6a 100644 --- a/App/Views/READCOM.Views.Main.fmx +++ b/App/Views/READCOM.Views.Main.fmx @@ -127,6 +127,10 @@ object MainForm: TMainForm inherited actionHelp: TAction ImageIndex = 16 end + inherited actionAddBitmapImageStoryItem: TAction + OnExecute = HUDactionAddBitmapImageStoryItemExecute + ImageIndex = 23 + end end inherited MultiViewFrameStand: TFrameStand Left = 432 diff --git a/App/Views/READCOM.Views.Main.pas b/App/Views/READCOM.Views.Main.pas index a92439c..e5d4141 100644 --- a/App/Views/READCOM.Views.Main.pas +++ b/App/Views/READCOM.Views.Main.pas @@ -16,7 +16,7 @@ interface FMX.Layouts, READCOM.Views.AudioStoryItem, SubjectStand, - READCOM.App.Globals; + READCOM.App.Globals, System.Actions, FMX.ActnList; type @@ -25,25 +25,28 @@ TMainForm = class(TForm, IStory) ZoomFrame: TZoomFrame; StoryTimer: TTimer; procedure FormCreate(Sender: TObject); - procedure FormSaveState(Sender: TObject); procedure FormDestroy(Sender: TObject); + + procedure FormSaveState(Sender: TObject); + + procedure FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); + procedure HUDactionLoadExecute(Sender: TObject); procedure HUDactionSaveExecute(Sender: TObject); procedure HUDactionNewExecute(Sender: TObject); procedure HUDactionHomeExecute(Sender: TObject); procedure HUDactionPreviousExecute(Sender: TObject); procedure HUDactionNextExecute(Sender: TObject); - procedure FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); + procedure HUDactionAddBitmapImageStoryItemExecute(Sender: TObject); + procedure HUDactionAddTextStoryItemExecute(Sender: TObject); procedure HUDactionDeleteExecute(Sender: TObject); procedure HUDactionCopyExecute(Sender: TObject); procedure HUDactionPasteExecute(Sender: TObject); procedure HUDactionFlipHorizontallyExecute(Sender: TObject); procedure HUDactionFlipVerticallyExecute(Sender: TObject); - procedure HUDactionAddTextStoryItemExecute(Sender: TObject); + procedure FormResize(Sender: TObject); procedure StoryTimerTimer(Sender: TObject); - private - function GetStructureView: TStructureView; protected FTimerStarted: Boolean; @@ -84,8 +87,8 @@ TMainForm = class(TForm, IStory) procedure SetStoryMode(const Value: TStoryMode); {StructureView} + function GetStructureView: TStructureView; procedure StructureViewSelection(Sender: TObject; const Selection: TObject); - property StructureView: TStructureView read GetStructureView stored false; procedure UpdateStructureView; procedure RootStoryItemViewResized(Sender: TObject); @@ -95,7 +98,10 @@ TMainForm = class(TForm, IStory) procedure HUDTargetsVisibleChanged(Sender: TObject; const Value: Boolean); procedure HUDUseStoryTimerChanged(Sender: TObject; const Value: Boolean); + procedure AddChildStoryItem(const TheStoryItemClass: TStoryItemClass; const TheName: String); + public + property StructureView: TStructureView read GetStructureView stored false; procedure ZoomTo(const StoryItem: IStoryItem = nil); //ZoomTo(nil) zooms to all content published @@ -117,7 +123,8 @@ implementation Zoomicon.Helpers.RTL.ClassListHelpers, //for TClassList.Create(TClassArray) Zoomicon.Helpers.FMX.Controls.ControlHelpers, //for TControl.FlipHorizontally, TControl.FlipVertically READCOM.Views.PanelStoryItem, - READCOM.Views.TextStoryItem; //TODO: remove + READCOM.Views.BitmapImageStoryItem, + READCOM.Views.TextStoryItem; {$R *.fmx} @@ -502,15 +509,25 @@ procedure TMainForm.HUDEditModeChanged(Sender: TObject; const Value: Boolean); StoryMode := TStoryMode.InteractiveStoryMode; //TODO: should remember previous mode to restore or make EditMode a separate situation end; +procedure TMainForm.HUDactionAddBitmapImageStoryItemExecute(Sender: TObject); +begin + //HUD.actionAddBitmapImageStoryItemExecute(Sender); + AddChildStoryItem(TBitmapImageStoryItem, 'BitmapImageStoryItem'); +end; + procedure TMainForm.HUDactionAddTextStoryItemExecute(Sender: TObject); begin //HUD.actionAddTextStoryItemExecute(Sender); + AddChildStoryItem(TTextStoryItem, 'TextStoryItem'); +end; +procedure TMainForm.AddChildStoryItem(const TheStoryItemClass: TStoryItemClass; const TheName: String); +begin if not Assigned(ActiveStoryItem) then exit; var OwnerAndParent := ActiveStoryItem.View; - var StoryItem := TTextStoryItem.Create(OwnerAndParent, 'TextStoryItem'); //TODO: should have separate actions for adding such default items (for prototyping) for various StoryItem classes + var StoryItem := TheStoryItemClass.Create(OwnerAndParent, TheName); //TODO: should have separate actions for adding such default items (for prototyping) for various StoryItem classes with StoryItem do begin diff --git a/App/Views/READCOM.Views.Menu.HUD.fmx b/App/Views/READCOM.Views.Menu.HUD.fmx index cbab17c..a3b029f 100644 --- a/App/Views/READCOM.Views.Menu.HUD.fmx +++ b/App/Views/READCOM.Views.Menu.HUD.fmx @@ -267,11 +267,33 @@ object StoryHUD: TStoryHUD Justify = Left JustifyLastLine = Left FlowDirection = LeftToRight + object btnAddBitmapImageStoryItem: TSpeedButton + Action = actionAddBitmapImageStoryItem + Anchors = [akTop, akRight] + Enabled = True + Hint = + 'Add Bitmap Image'#13#13'Adds a BitmapImageStoryItem placeholder into t' + + 'he edited StoryItem' + Images = Globals.SVGIconImageList + ImageIndex = 23 + Margins.Left = 3.000000000000000000 + Margins.Top = 3.000000000000000000 + Margins.Right = 3.000000000000000000 + Margins.Bottom = 6.000000000000000000 + Position.X = 3.000000000000000000 + Position.Y = 3.000000000000000000 + Size.Width = 41.000000000000000000 + Size.Height = 33.000000000000000000 + Size.PlatformDefault = False + StyleLookup = 'actiontoolbutton' + end object btnAddTextStoryItem: TSpeedButton Action = actionAddTextStoryItem Anchors = [akTop, akRight] Enabled = True - Hint = 'Add Text'#13#13'Adds a TextStoryItem child into the edited StoryItem' + Hint = + 'Add Text'#13#13'Adds a TextStoryItem placeholder into the edited Story' + + 'Item' Images = Globals.SVGIconImageList ImageIndex = 21 Margins.Left = 3.000000000000000000 @@ -279,7 +301,7 @@ object StoryHUD: TStoryHUD Margins.Right = 3.000000000000000000 Margins.Bottom = 6.000000000000000000 Position.X = 3.000000000000000000 - Position.Y = 3.000000000000000000 + Position.Y = 45.000000000000000000 Size.Width = 41.000000000000000000 Size.Height = 33.000000000000000000 Size.PlatformDefault = False @@ -289,7 +311,7 @@ object StoryHUD: TStoryHUD Action = actionDelete Anchors = [akTop, akRight] Enabled = True - Hint = 'Delete'#13#13'Removes the edited StoryItem' + Hint = 'Delete'#13#13'Delete the edited StoryItem' Images = Globals.SVGIconImageList ImageIndex = 8 Margins.Left = 3.000000000000000000 @@ -297,7 +319,7 @@ object StoryHUD: TStoryHUD Margins.Right = 3.000000000000000000 Margins.Bottom = 3.000000000000000000 Position.X = 3.000000000000000000 - Position.Y = 45.000000000000000000 + Position.Y = 87.000000000000000000 Size.Width = 41.000000000000000000 Size.Height = 33.000000000000000000 Size.PlatformDefault = False @@ -307,7 +329,7 @@ object StoryHUD: TStoryHUD Action = actionCopy Anchors = [akTop, akRight] Enabled = True - Hint = 'Copy'#13#13'Copies the edited StoryItem to the system clipboard' + Hint = 'Copy'#13#13'Copy the edited StoryItem to the Clipboard' Images = Globals.SVGIconImageList ImageIndex = 17 Margins.Left = 3.000000000000000000 @@ -315,7 +337,7 @@ object StoryHUD: TStoryHUD Margins.Right = 3.000000000000000000 Margins.Bottom = 3.000000000000000000 Position.X = 3.000000000000000000 - Position.Y = 84.000000000000000000 + Position.Y = 126.000000000000000000 Size.Width = 41.000000000000000000 Size.Height = 33.000000000000000000 Size.PlatformDefault = False @@ -326,8 +348,8 @@ object StoryHUD: TStoryHUD Anchors = [akTop, akRight] Enabled = True Hint = - 'Paste'#13#13'Pastes a StoryItem from the system clipboard into the edi' + - 'ted StoryItem as a new child' + 'Paste'#13#13'Paste content from the Clipboard into the edited StoryIte' + + 'm' Images = Globals.SVGIconImageList ImageIndex = 18 Margins.Left = 3.000000000000000000 @@ -335,7 +357,7 @@ object StoryHUD: TStoryHUD Margins.Right = 3.000000000000000000 Margins.Bottom = 6.000000000000000000 Position.X = 3.000000000000000000 - Position.Y = 123.000000000000000000 + Position.Y = 165.000000000000000000 Size.Width = 41.000000000000000000 Size.Height = 33.000000000000000000 Size.PlatformDefault = False @@ -351,7 +373,7 @@ object StoryHUD: TStoryHUD Margins.Right = 3.000000000000000000 Margins.Bottom = 3.000000000000000000 Position.X = 3.000000000000000000 - Position.Y = 165.000000000000000000 + Position.Y = 207.000000000000000000 Size.Width = 41.000000000000000000 Size.Height = 33.000000000000000000 Size.PlatformDefault = False @@ -359,7 +381,7 @@ object StoryHUD: TStoryHUD end object btnFlipVertically: TSpeedButton Anchors = [akTop, akRight] - Hint = 'Flip Vertically'#13#13'Mirrors the edited StoryItem vertically' + Hint = 'Flip Vertically'#13#13'Flips the edited StoryItem vertically' Images = Globals.SVGIconImageList ImageIndex = 20 Margins.Left = 3.000000000000000000 @@ -367,7 +389,7 @@ object StoryHUD: TStoryHUD Margins.Right = 3.000000000000000000 Margins.Bottom = 3.000000000000000000 Position.X = 3.000000000000000000 - Position.Y = 204.000000000000000000 + Position.Y = 246.000000000000000000 Size.Width = 41.000000000000000000 Size.Height = 33.000000000000000000 Size.PlatformDefault = False @@ -487,6 +509,12 @@ object StoryHUD: TStoryHUD OnExecute = actionHelpExecute ImageIndex = 16 end + object actionAddBitmapImageStoryItem: TAction + Category = 'Edit' + Text = 'Add BitmapImageStoryItem' + ImageIndex = 23 + ImageIndex = 23 + end end object MultiViewFrameStand: TFrameStand AnimationShow = 'OnShow*' diff --git a/App/Views/READCOM.Views.Menu.HUD.pas b/App/Views/READCOM.Views.Menu.HUD.pas index e1134c1..628dfe6 100644 --- a/App/Views/READCOM.Views.Menu.HUD.pas +++ b/App/Views/READCOM.Views.Menu.HUD.pas @@ -19,7 +19,6 @@ interface TUseStoryTimerChangedEvent = procedure (Sender: TObject; const Value: Boolean) of object; TStoryHUD = class(TFrame) - btnAddTextStoryItem: TSpeedButton; btnPrevious: TSpeedButton; btnToggleEditMode: TSpeedButton; BtnMenu: TSpeedButton; @@ -52,11 +51,16 @@ TStoryHUD = class(TFrame) btnAbout: TSpeedButton; actionCopy: TAction; actionPaste: TAction; - btnCopy: TSpeedButton; - btnPaste: TSpeedButton; actionDelete: TAction; - btnDelete: TSpeedButton; btnToggleUseStoryTimer: TSpeedButton; + actionAddBitmapImageStoryItem: TAction; + btnAddTextStoryItem: TSpeedButton; + btnCopy: TSpeedButton; + btnDelete: TSpeedButton; + btnFlipHorizontally: TSpeedButton; + btnFlipVertically: TSpeedButton; + btnPaste: TSpeedButton; + btnAddBitmapImageStoryItem: TSpeedButton; procedure actionAboutExecute(Sender: TObject); procedure actionMenuExecute(Sender: TObject); procedure actionHelpExecute(Sender: TObject);