diff --git a/src/Tizen.NUI.PenWave/src/public/EventBus.cs b/src/Tizen.NUI.PenWave/src/public/EventBus.cs new file mode 100644 index 00000000000..fb0ca4c0391 --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/EventBus.cs @@ -0,0 +1,41 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using System.Collections.Generic; + +namespace Tizen.NUI.PenWave +{ + public static class EventBus + { + private static readonly Dictionary> events = new(); + + public static void Subscribe(string eventName, Action callback) + { + if (events.ContainsKey(eventName)) + events[eventName] += callback; + else + events[eventName] = callback; + } + + public static void Publish(string eventName, object eventArgs = null) + { + if (events.TryGetValue(eventName, out var action)) + action.Invoke(eventArgs); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/PWCanvasView.cs b/src/Tizen.NUI.PenWave/src/public/PWCanvasView.cs index a5eb141848e..ad14af7aba3 100644 --- a/src/Tizen.NUI.PenWave/src/public/PWCanvasView.cs +++ b/src/Tizen.NUI.PenWave/src/public/PWCanvasView.cs @@ -36,30 +36,25 @@ public class PWCanvasView : DirectRenderingGLView public PWCanvasView() : base(DirectRenderingGLView.ColorFormat.RGBA8888, DirectRenderingGLView.BackendMode.UnsafeDirectRendering) { - pageManager = new PageManager(); renderer = new CanvasRenderer(PWEngine.CreateCanvas(-1, -1)); - uiManager = new CanvasUIManager(this); - ToolManager = new ToolManager(); InitializeCanvas(); } public PWCanvasView(string backgroundPath) : base(DirectRenderingGLView.ColorFormat.RGBA8888, DirectRenderingGLView.BackendMode.UnsafeDirectRendering) { - pageManager = new PageManager(); renderer = new CanvasRenderer(PWEngine.CreateCanvasWithBackgroundImage(backgroundPath)); - uiManager = new CanvasUIManager(this); - ToolManager = new ToolManager(); InitializeCanvas(); } + public static PWCanvasView CreateDefaultCanvas() { var canvasView = new PWCanvasView(); - CanvasTool canvasTool = new CanvasTool(); - PencilTool pencilTool = new PencilTool(); - EraserTool eraserTool = new EraserTool(); - SelectTool selectTool = new SelectTool(); + var canvasTool = ToolFactory.CreateTool(ToolBase.ToolType.Canvas); + var pencilTool = ToolFactory.CreateTool(ToolBase.ToolType.Pencil); + var eraserTool = ToolFactory.CreateTool(ToolBase.ToolType.Eraser); + var selectTool = ToolFactory.CreateTool(ToolBase.ToolType.Select); canvasView.ToolManager.RegisterTool(canvasTool); canvasView.ToolManager.RegisterTool(pencilTool); @@ -71,8 +66,16 @@ public static PWCanvasView CreateDefaultCanvas() return canvasView; } + private void InitializeManager() + { + pageManager = new PageManager(); + uiManager = new CanvasUIManager(this); + ToolManager = new ToolManager(); + } + private void InitializeCanvas() { + InitializeManager(); this.RenderingMode = GLRenderingMode.Continuous; this.RegisterGLCallbacks(renderer.InitializeGL, renderer.RenderFrame, renderer.TerminateGL); this.SetGraphicsConfig(false, false, 0, GLESVersion.Version20); diff --git a/src/Tizen.NUI.PenWave/src/public/PopupManager.cs b/src/Tizen.NUI.PenWave/src/public/PopupManager.cs new file mode 100644 index 00000000000..f57530a55ce --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/PopupManager.cs @@ -0,0 +1,53 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class PopupManager + { + private View popupView; + private View parentView; + + public PopupManager(View parentView) + { + this.parentView = parentView; + } + + public void ShowPopup(View contentView) + { + if (popupView != null) HidePopup(); + + popupView = new View(); + popupView.Add(contentView); + parentView.Add(popupView); + } + + public void HidePopup() + { + if (popupView != null) + { + parentView.Remove(popupView); + popupView = null; + } + } + } + +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Canvas/CanvasTool.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Canvas/CanvasTool.cs index cb0632a0dbb..18ea168029f 100644 --- a/src/Tizen.NUI.PenWave/src/public/Tools/Canvas/CanvasTool.cs +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Canvas/CanvasTool.cs @@ -40,9 +40,12 @@ public class CanvasTool : ToolBase new Color("#090E21"), }; + private Icon palettIcon; + public CanvasTool() { - + palettIcon = new PalettIcon(); + AddIcon(palettIcon); } protected override void StartDrawing(Vector2 position, uint touchTime) @@ -57,31 +60,15 @@ protected override void EndDrawing() { } - protected override void Deactivate() + protected override void OnIconSelected() { - EndDrawing(); - } + var colorIconsView = CreateColorIconsView(); + PopupManager.ShowPopup(colorIconsView); - public override View GetUI() - { - View rootView = new View - { - // Layout = new LinearLayout() - // { - // LinearOrientation = LinearLayout.Orientation.Horizontal, - // }, - Layout = new GridLayout { Columns = 1, RowSpacing = 4 } - }; - var icon = new PalettIcon(); - rootView.Add(icon); - icon.IconSelected += OnIconSelected; - - MakePopup(rootView); - - return rootView; + Tizen.Log.Error("NUI", $"canvasTool Icon\n"); } - private void MakePopup(View rootView) + private View CreateColorIconsView() { var bgImage = new ImageView { @@ -91,34 +78,24 @@ private void MakePopup(View rootView) Layout = new GridLayout { Columns = 1, RowSpacing = 4 } }; AddIconsToView(bgImage, BgColors, color => new BackgroundColorIcon(color)); - rootView.Add(bgImage); + bgImage.Position2D = new Position2D((int)palettIcon.ScreenPosition.X, (int)palettIcon.ScreenPosition.Y + 48); + return bgImage; } private void AddIconsToView(View rootView, IEnumerableitems, Func iconFactory) { var view = new View { - // Layout = new LinearLayout() - // { - // LinearOrientation = LinearLayout.Orientation.Horizontal, - // }, Layout = new GridLayout { Columns = 4, ColumnSpacing = 8, RowSpacing = 8 }, }; foreach (var item in items) { var icon = iconFactory(item); view.Add(icon); - // icon.IconSelected += OnIconSelected; } + rootView.Add(view); } - // protected override void OnIconSelected() - // { - // base.OnIconSelected(); - - - // } - } } diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Eraser/EraserTool.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Eraser/EraserTool.cs index 598906518c7..7c0b0e3b73f 100644 --- a/src/Tizen.NUI.PenWave/src/public/Tools/Eraser/EraserTool.cs +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Eraser/EraserTool.cs @@ -37,7 +37,7 @@ enum Mode public EraserTool() { - + AddIcon(new EraserIcon()); } protected override void StartDrawing(Vector2 position, uint touchTime) @@ -55,24 +55,5 @@ protected override void EndDrawing() PWEngine.StopErasing(); } - protected override void Deactivate() - { - EndDrawing(); - } - - public override View GetUI() - { - View rootView = new View - { - Layout = new LinearLayout() - { - LinearOrientation = LinearLayout.Orientation.Horizontal, - }, - }; - var icon = new EraserIcon(); - rootView.Add(icon); - icon.IconSelected += OnIconSelected; - return rootView; - } } } diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/BrushIcon.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/BrushIcon.cs similarity index 53% rename from src/Tizen.NUI.PenWave/src/public/Tools/Pencil/BrushIcon.cs rename to src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/BrushIcon.cs index dadceddcb45..f3dd33c9068 100644 --- a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/BrushIcon.cs +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/BrushIcon.cs @@ -25,7 +25,8 @@ namespace Tizen.NUI.PenWave { public class BrushIcon : Icon { - private PWEngine.BrushType mBrushType; + private PWEngine.BrushType brushType; + private readonly IBrushStrategy brushStrategy; private static readonly Dictionary IconMap = new Dictionary { @@ -40,52 +41,12 @@ public class BrushIcon : Icon { PWEngine.BrushType.SharpBrush, "icon_sharp_brush" }, }; - private static readonly Dictionary BrushConfigs = new Dictionary - { - { PWEngine.BrushType.Stroke, () => PWEngine.SetStrokeType(0) }, - { PWEngine.BrushType.VarStroke, () => PWEngine.SetStrokeType(6) }, - { PWEngine.BrushType.VarStrokeInc, () => PWEngine.SetStrokeType(7) }, - { PWEngine.BrushType.SprayBrush, () => - { - PWEngine.SetStrokeType(1); - PWEngine.SetBrushTexture(0); - PWEngine.SetBrushDistance(3.0f); - } - }, - { PWEngine.BrushType.DotBrush, () => - { - PWEngine.SetStrokeType(1); - PWEngine.SetBrushTexture(1); - PWEngine.SetBrushDistance(2.0f); - } - }, - { PWEngine.BrushType.DashedLine, () => - { - PWEngine.SetStrokeType(5); - PWEngine.SetDashArray("1 3"); - } - }, - { PWEngine.BrushType.Highlighter, () => - { - PWEngine.SetStrokeType(1); - PWEngine.SetBrushTexture(3); - PWEngine.SetBrushDistance(0.25f); - } - }, - { PWEngine.BrushType.SoftBrush, () => - { - PWEngine.SetStrokeType(1); - PWEngine.SetBrushTexture(4); - PWEngine.SetBrushDistance(1.0f); - } - }, - { PWEngine.BrushType.SharpBrush, () => PWEngine.SetStrokeType(8) }, - }; - private ImageView mImgView; public BrushIcon(PWEngine.BrushType brushType) : base() { - mBrushType = brushType; + brushStrategy = BrushStrategyFactory.GetBrushStrategy(brushType); + + this.brushType = brushType; mImgView = new ImageView(); mImgView.Size2D = new Size2D(48, 48); @@ -101,17 +62,14 @@ private string GetIconUrl(PWEngine.BrushType brushType) } - public PWEngine.BrushType GetBrushType() => mBrushType; + public PWEngine.BrushType GetBrushType() => brushType; public override bool IconClick(object sender, View.TouchEventArgs args) { if (base.IconClick(sender, args)) { - if (BrushConfigs.ContainsKey(GetBrushType())) - { - BrushConfigs[GetBrushType()].Invoke(); - } + brushStrategy.ApplyBrushSettings(); } return true; diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/BrushStrategyFactory.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/BrushStrategyFactory.cs new file mode 100644 index 00000000000..f1585161b7f --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/BrushStrategyFactory.cs @@ -0,0 +1,46 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using System.ComponentModel; +using System.Collections.Generic; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public static class BrushStrategyFactory + { + public static IBrushStrategy GetBrushStrategy(PWEngine.BrushType brushType) + { + return brushType switch + { + PWEngine.BrushType.Stroke => new StrokeBrush(), + PWEngine.BrushType.VarStroke => new VarStrokeBrush(), + PWEngine.BrushType.VarStrokeInc => new VarStrokeIncBrush(), + PWEngine.BrushType.SprayBrush => new SprayBrush(), + PWEngine.BrushType.DotBrush => new DotBrush(), + PWEngine.BrushType.DashedLine => new DashedLineBrush(), + PWEngine.BrushType.Highlighter => new HighlighterBrush(), + PWEngine.BrushType.SoftBrush => new SoftBrush(), + PWEngine.BrushType.SharpBrush => new SharpBrush(), + _ => throw new ArgumentOutOfRangeException(nameof(brushType), brushType, null) + }; + } + + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/DashedLineBrush.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/DashedLineBrush.cs new file mode 100644 index 00000000000..76f91ba1dd7 --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/DashedLineBrush.cs @@ -0,0 +1,31 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class DashedLineBrush : IBrushStrategy + { + public void ApplyBrushSettings() + { + PWEngine.SetStrokeType(5); + PWEngine.SetDashArray("1 3"); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/DotBrush .cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/DotBrush .cs new file mode 100644 index 00000000000..fed8b380b2c --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/DotBrush .cs @@ -0,0 +1,32 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class DotBrush : IBrushStrategy + { + public void ApplyBrushSettings() + { + PWEngine.SetStrokeType(1); + PWEngine.SetBrushTexture(1); + PWEngine.SetBrushDistance(2.0f); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/HighlighterBrush.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/HighlighterBrush.cs new file mode 100644 index 00000000000..252f898c572 --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/HighlighterBrush.cs @@ -0,0 +1,32 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class HighlighterBrush : IBrushStrategy + { + public void ApplyBrushSettings() + { + PWEngine.SetStrokeType(1); + PWEngine.SetBrushTexture(3); + PWEngine.SetBrushDistance(0.25f); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/IBrushStrategy.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/IBrushStrategy.cs new file mode 100644 index 00000000000..ffbd409ce88 --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/IBrushStrategy.cs @@ -0,0 +1,30 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using System.ComponentModel; +using System.Collections.Generic; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public interface IBrushStrategy + { + void ApplyBrushSettings(); + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/SharpBrush.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/SharpBrush.cs new file mode 100644 index 00000000000..02b51316141 --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/SharpBrush.cs @@ -0,0 +1,30 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class SharpBrush : IBrushStrategy + { + public void ApplyBrushSettings() + { + PWEngine.SetStrokeType(8); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/SoftBrush.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/SoftBrush.cs new file mode 100644 index 00000000000..023e8fc72ea --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/SoftBrush.cs @@ -0,0 +1,32 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class SoftBrush : IBrushStrategy + { + public void ApplyBrushSettings() + { + PWEngine.SetStrokeType(1); + PWEngine.SetBrushTexture(4); + PWEngine.SetBrushDistance(1.0f); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/SprayBrush.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/SprayBrush.cs new file mode 100644 index 00000000000..10850a26aa8 --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/SprayBrush.cs @@ -0,0 +1,32 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class SprayBrush : IBrushStrategy + { + public void ApplyBrushSettings() + { + PWEngine.SetStrokeType(1); + PWEngine.SetBrushTexture(0); + PWEngine.SetBrushDistance(3.0f); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/StrokeBrush.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/StrokeBrush.cs new file mode 100644 index 00000000000..8aa16e515c9 --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/StrokeBrush.cs @@ -0,0 +1,30 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class StrokeBrush : IBrushStrategy + { + public void ApplyBrushSettings() + { + PWEngine.SetStrokeType(0); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/VarStrokeBrush.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/VarStrokeBrush.cs new file mode 100644 index 00000000000..5c51222607f --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/VarStrokeBrush.cs @@ -0,0 +1,30 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class VarStrokeBrush : IBrushStrategy + { + public void ApplyBrushSettings() + { + PWEngine.SetStrokeType(6); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/VarStrokeIncBrush.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/VarStrokeIncBrush.cs new file mode 100644 index 00000000000..5d4b2b71784 --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/Brush/VarStrokeIncBrush.cs @@ -0,0 +1,30 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.PenWave +{ + public class VarStrokeIncBrush : IBrushStrategy + { + public void ApplyBrushSettings() + { + PWEngine.SetStrokeType(7); + } + } +} diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/PencilTool.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/PencilTool.cs index 178744d42d5..9fef24d64d0 100644 --- a/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/PencilTool.cs +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Pencil/PencilTool.cs @@ -34,11 +34,22 @@ public class PencilTool : ToolBase public PencilTool() { ink = new PenInk(); + + InitializePencilTool(); } public PencilTool(PenInk penInk) { ink = penInk ?? new PenInk(); + + InitializePencilTool(); + } + + private void InitializePencilTool() + { + AddIcons(ink.BrushTypes, brushType => new BrushIcon(brushType)); + AddIcons(ink.Sizes, size => new SizeIcon(size)); + AddIcons(ink.Colors, color => new ColorIcon(color)); } protected override void StartDrawing(Vector2 position, uint touchTime) @@ -69,44 +80,16 @@ protected override void EndDrawing() mCurrentShapeId = 0; } - protected override void Deactivate() - { - EndDrawing(); - } - - public override View GetUI() - { - View rootView = new View - { - Layout = new LinearLayout() - { - LinearOrientation = LinearLayout.Orientation.Horizontal, - }, - }; - - AddIconsToView(rootView, ink.BrushTypes, brushType => new BrushIcon(brushType)); - AddIconsToView(rootView, ink.Sizes, size => new SizeIcon(size)); - AddIconsToView(rootView, ink.Colors, color => new ColorIcon(color)); - return rootView; - } - private void AddIconsToView(View rootView, IEnumerableitems, Func iconFactory) + private void AddIcons(IEnumerableitems, Func iconFactory) { - var view = new View - { - Layout = new LinearLayout() - { - LinearOrientation = LinearLayout.Orientation.Horizontal, - }, - }; foreach (var item in items) { var icon = iconFactory(item); - view.Add(icon); - icon.IconSelected += OnIconSelected; + AddIcon(icon); } - rootView.Add(view); } + } public enum ErrorShapeAddPointsType diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/Select/SelectTool.cs b/src/Tizen.NUI.PenWave/src/public/Tools/Select/SelectTool.cs index bf07b06f751..8b47ddb284a 100644 --- a/src/Tizen.NUI.PenWave/src/public/Tools/Select/SelectTool.cs +++ b/src/Tizen.NUI.PenWave/src/public/Tools/Select/SelectTool.cs @@ -38,7 +38,7 @@ enum Mode public SelectTool() { - + AddIcon(new SelectIcon()); } protected override void StartDrawing(Vector2 position, uint touchTime) @@ -85,25 +85,10 @@ protected override void EndDrawing() mode = Mode.None; } - protected override void Deactivate() + protected override void OnDeactivate() { mode = Mode.None; - EndDrawing(); - } - - public override View GetUI() - { - View rootView = new View - { - Layout = new LinearLayout() - { - LinearOrientation = LinearLayout.Orientation.Horizontal, - }, - }; - var icon = new SelectIcon(); - rootView.Add(icon); - icon.IconSelected += OnIconSelected; - return rootView; + base.OnDeactivate(); } } } diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/ToolBase.cs b/src/Tizen.NUI.PenWave/src/public/Tools/ToolBase.cs index 9d2239f9e7a..2274baffc20 100644 --- a/src/Tizen.NUI.PenWave/src/public/Tools/ToolBase.cs +++ b/src/Tizen.NUI.PenWave/src/public/Tools/ToolBase.cs @@ -38,30 +38,43 @@ public enum ToolType public abstract ToolBase.ToolType Type { get; } public event Action ToolSelected; - private bool mActivate; - private View mRootView; + protected bool Active {get; private set; } + protected List Icons { get; } = new List(); - public bool Activate + protected PopupManager PopupManager { get; private set; } + + public void SetPopupManager(PopupManager popupManager) { - get => mActivate; - set - { - mActivate = value; - if (!mActivate) - { - Deactivate(); - } - } + PopupManager = popupManager; } - protected virtual void OnIconSelected() + protected virtual void OnIconSelected() => ToolSelected?.Invoke(Type); + + public void Activate() { - ToolSelected?.Invoke(Type); + Active = true; + OnActivated(); + } + + public void Deactivate() + { + Active = false; + OnDeactivate(); + } + + protected virtual void OnActivated() + { + + } + + protected virtual void OnDeactivate() + { + EndDrawing(); } public virtual void HandleInput(Touch touch) { - if (!Activate || touch == null || touch.GetPointCount() == 0) return; + if (!Active || touch == null || touch.GetPointCount() == 0) return; uint pointStateIndex = 0; uint touchTime = touch.GetTime(); @@ -88,11 +101,28 @@ public virtual void HandleInput(Touch touch) } } - public abstract View GetUI(); + public virtual View GetUI() + { + var view = new View + { + Layout = new LinearLayout + { + LinearOrientation = LinearLayout.Orientation.Horizontal, + } + }; + foreach (var icon in Icons) + { + icon.IconSelected += OnIconSelected; + view.Add(icon); + } + return view; + } + + protected void AddIcon(Icon icon) => Icons.Add(icon); protected abstract void StartDrawing(Vector2 position, uint touchTime); protected abstract void ContinueDrawing(Vector2 position, uint touchTime); protected abstract void EndDrawing(); - protected abstract void Deactivate(); + } } \ No newline at end of file diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/ToolFactory.cs b/src/Tizen.NUI.PenWave/src/public/Tools/ToolFactory.cs new file mode 100644 index 00000000000..6a9a21d3953 --- /dev/null +++ b/src/Tizen.NUI.PenWave/src/public/Tools/ToolFactory.cs @@ -0,0 +1,36 @@ +/* + * Copyright(c) 2024 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; + +namespace Tizen.NUI.PenWave +{ + public static class ToolFactory + { + public static ToolBase CreateTool(ToolBase.ToolType toolType) + { + return toolType switch + { + ToolBase.ToolType.Pencil => new PencilTool(), + ToolBase.ToolType.Eraser => new EraserTool(), + ToolBase.ToolType.Select => new SelectTool(), + ToolBase.ToolType.Canvas => new CanvasTool(), + _ => throw new ArgumentException("Unknown ToolType") + }; + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/ToolManager.cs b/src/Tizen.NUI.PenWave/src/public/Tools/ToolManager.cs index 19e69d7027a..713e37ad2d8 100644 --- a/src/Tizen.NUI.PenWave/src/public/Tools/ToolManager.cs +++ b/src/Tizen.NUI.PenWave/src/public/Tools/ToolManager.cs @@ -25,15 +25,10 @@ namespace Tizen.NUI.PenWave { public class ToolManager { - public readonly Dictionary Tools; - private ToolBase mCurrentTool; + public Dictionary Tools { get; } = new(); + private ToolBase currentTool; - public event Action ToolChanged; - - public ToolManager() - { - Tools = new Dictionary(); - } + public ToolManager() {} public void RegisterTool(ToolBase tool) { @@ -55,35 +50,25 @@ public void UnregisterTool(ToolBase tool) public void SelectTool(ToolBase.ToolType toolType) { - - if (mCurrentTool != null) + currentTool?.Deactivate(); + if (Tools.TryGetValue(toolType, out currentTool)) { - if (toolType == GetCurrentToolType()) - { - return; // 선택된 툴이 현재 툴과 같다. 할 거 없다. - } - mCurrentTool.Activate = false; - } - - if (Tools.TryGetValue(toolType, out mCurrentTool)) - { - mCurrentTool.Activate = true; - ToolChanged?.Invoke(toolType); + currentTool.Activate(); + EventBus.Publish("ToolChanged", toolType); } } public void HandleInput(Touch touch) { - mCurrentTool?.HandleInput(touch); + currentTool?.HandleInput(touch); } - public ToolBase.ToolType GetCurrentToolType() => mCurrentTool?.Type ?? ToolBase.ToolType.Pencil; - private void OnToolSelected(ToolBase.ToolType toolType) { Tizen.Log.Info("NUI", $"OnToolSelected {toolType}\n"); SelectTool(toolType); - ToolChanged?.Invoke(toolType); } + + public ToolBase.ToolType GetCurrentToolType() => currentTool?.Type ?? ToolBase.ToolType.Pencil; } } \ No newline at end of file diff --git a/src/Tizen.NUI.PenWave/src/public/Tools/ToolPickerView.cs b/src/Tizen.NUI.PenWave/src/public/Tools/ToolPickerView.cs index bd1ac9d9b53..c08fb450be8 100644 --- a/src/Tizen.NUI.PenWave/src/public/Tools/ToolPickerView.cs +++ b/src/Tizen.NUI.PenWave/src/public/Tools/ToolPickerView.cs @@ -27,12 +27,14 @@ public class ToolPickerView : View { private ToolManager mToolManager; private Dictionary mToolUIs; - // private List mCustomIcons; + private View pickerView; + private View popupView; + private PopupManager popupManager; public ToolPickerView(ToolManager toolManager) { this.mToolManager = toolManager; - toolManager.ToolChanged += OnUpdateUI; + EventBus.Subscribe("ToolChanged", OnToolChanged); mToolUIs = new Dictionary(); InitializeUI(); @@ -40,30 +42,77 @@ public ToolPickerView(ToolManager toolManager) private void InitializeUI() { - CornerRadius = new Vector4(10, 10, 10, 10); - BackgroundImage = FrameworkInformation.ResourcePath + "images/" + "light" + "/menu_bg.png"; - WidthSpecification = LayoutParamPolicies.WrapContent; - HeightSpecification = LayoutParamPolicies.WrapContent; - Layout = new LinearLayout + WidthResizePolicy = ResizePolicyType.FillToParent; + HeightResizePolicy = ResizePolicyType.FillToParent; + + var rootView = new View { - VerticalAlignment = VerticalAlignment.Center, - HorizontalAlignment = HorizontalAlignment.Center + WidthResizePolicy = ResizePolicyType.FillToParent, + HeightResizePolicy = ResizePolicyType.FillToParent, + Layout = new LinearLayout() + { + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Top, + LinearOrientation = LinearLayout.Orientation.Vertical, + } }; + pickerView = new View + { + CornerRadius = new Vector4(10, 10, 10, 10), + BackgroundImage = FrameworkInformation.ResourcePath + "images/" + "light" + "/menu_bg.png", + WidthSpecification = LayoutParamPolicies.WrapContent, + HeightSpecification = LayoutParamPolicies.WrapContent, + Layout = new LinearLayout + { + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Center + }, + }; + + popupView = new View + { + // CornerRadius = new Vector4(10, 10, 10, 10), + // BackgroundImage = FrameworkInformation.ResourcePath + "images/" + "light" + "/menu_bg.png", + WidthSpecification = LayoutParamPolicies.WrapContent, + HeightSpecification = LayoutParamPolicies.WrapContent, + Layout = new LinearLayout + { + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Center + } + }; + + this.popupManager = new PopupManager(popupView); + foreach (var tool in mToolManager.Tools) { + tool.Value.SetPopupManager(popupManager); var toolUI = tool.Value.GetUI(); if (mToolUIs.TryAdd(tool.Key, toolUI)) { - this.Add(toolUI); + pickerView.Add(toolUI); } } + rootView.Add(pickerView); + this.Add(rootView); + this.Add(popupView); } + public void ShowPopup(View contentView) + { + popupManager.ShowPopup(contentView); + } - private void OnUpdateUI(ToolBase.ToolType toolType) + public void HidePopup(View contentView) { + popupManager.HidePopup(); + } + + private void OnToolChanged(object toolType) + { + // object is ToolBase.ToolType } @@ -91,33 +140,5 @@ public void CustomizeToolUI(ToolBase.ToolType toolType, View customUI) this.Add(customUI); } } - - // public void AddCustomToolIcon(View view) - // { - // mRootView.Add(view); - // } - - // public void RemoveCustomToolIcon(View view) - // { - // mRootView.Remove(view); - // } - - // private void UpdateUI() - // { - // foreach (ITool tool in mToolManager.Tools.Values) { - // View toolView = tool.GetUI(); - // if (mToolIcons.TryAdd(tool.Type, toolView)) - // { - // mRootView.Add(toolView); - // } - // } - // } - - // private void OnToolChanged(ToolBase.ToolType toolType, int type) - // { - // // UpdateUI(); - // } - - } -} \ No newline at end of file +}