Skip to content

Commit

Permalink
PenWave
Browse files Browse the repository at this point in the history
  • Loading branch information
JoogabYun committed Nov 8, 2024
1 parent d1f37de commit b41207f
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 132 deletions.
10 changes: 10 additions & 0 deletions src/Tizen.NUI.PenWave/src/public/CanvasRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,15 @@ public void Resize(int width, int height)
PWEngine.UpdateGLWindowSize(width, height);
PWEngine.RenderFullyReDraw();
}

public void ClearCanvas()
{
PWEngine.ClearCurrentCanvas();
}

public void AddPicture(string path)
{
PWEngine.AddPicture(path);
}
}
}
4 changes: 0 additions & 4 deletions src/Tizen.NUI.PenWave/src/public/CanvasUIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,5 @@ public void UpdateUI()
// 캔버스 상태에 따라 UI 갱신
}

public void ToggleGrid(bool visible)
{
// 그리드 표시/숨기기 처리
}
}
}
13 changes: 10 additions & 3 deletions src/Tizen.NUI.PenWave/src/public/PWCanvasView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class PWCanvasView : DirectRenderingGLView

public ToolManager ToolManager {get; private set;}
public event Action<int> OnPageChanged;
public event Action OnCanvasCleared;

public PWCanvasView() : base(DirectRenderingGLView.ColorFormat.RGBA8888, DirectRenderingGLView.BackendMode.UnsafeDirectRendering)
{
Expand Down Expand Up @@ -99,10 +98,18 @@ public void SetCurrentPage(int pageIndex)

public void ClearCanvas()
{
// 캔버스 클리어 처리
OnCanvasCleared?.Invoke();
renderer.ClearCanvas();
}

public void AddPicture(string path, Size2D size, Position2D position)
{
renderer.AddPicture(path);
}

public void SelectTool(ToolBase.ToolType toolType)
{
ToolManager.SelectTool(toolType);
}

public void HandleInput(Touch touch)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Tizen.NUI.PenWave/src/public/PopupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ public class PopupManager
public PopupManager(View parentView)
{
this.parentView = parentView;
this.parentView.TouchEvent += (s, e) => { return true; }; // To prevent touch event propagation to parent view.
}

public void ShowPopup(View contentView)
public void ShowPopup(View contentView, Position2D position)
{
if (popupView != null) HidePopup();

popupView = new View();
popupView.Add(contentView);
parentView.Position2D = position;
parentView.Add(popupView);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ protected override string GetSelectedImageUrl()
return $"{FrameworkInformation.ResourcePath}images/light/color_icon_selected.png";
}

public override bool OnClickIcon(object sender, View.TouchEventArgs args)
public override bool OnIconClicked(object sender, View.TouchEventArgs args)
{
if (base.OnClickIcon(sender, args))
if (base.OnIconClicked(sender, args))
{
PWEngine.CanvasSetColor(GetColorHex(), 1.0f);
}
Expand Down
29 changes: 14 additions & 15 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/CanvasTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class CanvasTool : ToolBase
{
public override ToolBase.ToolType Type => ToolBase.ToolType.Canvas;

private static readonly string popupBgUrl = $"{FrameworkInformation.ResourcePath}images/light/canvas_popup_bg.png";
private static readonly List<Color> BgColors = new List<Color>
private static readonly string s_popupBgUrl = $"{FrameworkInformation.ResourcePath}images/light/canvas_popup_bg.png";
private static readonly List<Color> s_bgColors = new List<Color>
{
new Color("#FFFEFE"),
new Color("#F0F0F0"),
Expand All @@ -40,47 +40,47 @@ public class CanvasTool : ToolBase
new Color("#090E21"),
};

private Icon palettIcon;
private Icon paletteIcon;
private Icon gridIcon;

public CanvasTool() : base(new CanvasToolActionHandler())
{
palettIcon = new PalettIcon();
AddIcon(palettIcon);
paletteIcon = new PaletteIcon();
AddIcon(paletteIcon);

gridIcon = new GridIcon();
AddIcon(gridIcon);

AddIcon(new UndoIcon());
AddIcon(new RedoIcon());
AddIcon(new ClearIcon());
}

protected override void OnIconSelected(object sender)
{
Tizen.Log.Info("NUI", $"OnIconSelected\n");
if (sender is PalettIcon)
if (sender is PaletteIcon)
{
var colorIconsView = CreateColorIconsView();
PopupManager.ShowPopup(colorIconsView);
CreateColorIconsView();
}
else
{
PopupManager.HidePopup();
}
}

private View CreateColorIconsView()
private void CreateColorIconsView()
{
var bgImage = new ImageView
var view = new ImageView
{
BackgroundImage = popupBgUrl,
BackgroundImage = s_popupBgUrl,
WidthSpecification = LayoutParamPolicies.WrapContent,
HeightSpecification = LayoutParamPolicies.WrapContent,
Layout = new GridLayout { Columns = 1, RowSpacing = 4 }
};
AddIconsToView(bgImage, BgColors, color => new BackgroundColorIcon(color));
bgImage.Position2D = new Position2D((int)palettIcon.ScreenPosition.X, (int)palettIcon.ScreenPosition.Y + 60);
return bgImage;
AddIconsToView(view, s_bgColors, color => new BackgroundColorIcon(color));
Position2D position = new Position2D((int)paletteIcon.ScreenPosition.X, (int)paletteIcon.ScreenPosition.Y + 60);
PopupManager.ShowPopup(view, position);
}

private void AddIconsToView<T>(View rootView, IEnumerable<T>items, Func<T, Icon> iconFactory)
Expand All @@ -93,7 +93,6 @@ private void AddIconsToView<T>(View rootView, IEnumerable<T>items, Func<T, Icon>
{
var icon = iconFactory(item);
view.Add(icon);
// icon.IconSelected += OnIconSelected;
}

rootView.Add(view);
Expand Down
51 changes: 51 additions & 0 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/ClearIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 ClearIcon : Icon
{
public ClearIcon() : base()
{
InitializeIcon();
}

protected override string GetDefaultImageUrl()
{
return $"{FrameworkInformation.ResourcePath}images/light/icon_clear.png";
}

protected override string GetSelectedImageUrl()
{
return $"{FrameworkInformation.ResourcePath}images/light/color_icon_selected.png";
}

public override bool OnIconClicked(object sender, View.TouchEventArgs args)
{
if (base.OnIconClicked(sender, args))
{
Tizen.Log.Info("NUI", $"ClearIcon\n");
PWEngine.ClearCurrentCanvas();
}
return true;
}

}
}
4 changes: 2 additions & 2 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/GridIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ protected override string GetSelectedImageUrl()
return $"{FrameworkInformation.ResourcePath}images/light/color_icon_selected.png";
}

public override bool OnClickIcon(object sender, View.TouchEventArgs args)
public override bool OnIconClicked(object sender, View.TouchEventArgs args)
{
if (base.OnClickIcon(sender, args))
if (base.OnIconClicked(sender, args))
{
Tizen.Log.Info("NUI", $"GridIcon\n");
PWEngine.ToggleGrid((int)GridDensityType.Small);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

namespace Tizen.NUI.PenWave
{
public class PalettIcon : Icon
public class PaletteIcon : Icon
{
public PalettIcon() : base()
public PaletteIcon() : base()
{
InitializeIcon();
}
Expand All @@ -37,11 +37,11 @@ protected override string GetSelectedImageUrl()
return $"{FrameworkInformation.ResourcePath}images/light/color_icon_selected.png";
}

public override bool OnClickIcon(object sender, View.TouchEventArgs args)
public override bool OnIconClicked(object sender, View.TouchEventArgs args)
{
if (base.OnClickIcon(sender, args))
if (base.OnIconClicked(sender, args))
{
Tizen.Log.Info("NUI", $"PalettIcon\n");
Tizen.Log.Info("NUI", $"PaletteIcon\n");
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/RedoIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ protected override string GetSelectedImageUrl()
return $"{FrameworkInformation.ResourcePath}images/light/color_icon_selected.png";
}

public override bool OnClickIcon(object sender, View.TouchEventArgs args)
public override bool OnIconClicked(object sender, View.TouchEventArgs args)
{
if (base.OnClickIcon(sender, args))
if (base.OnIconClicked(sender, args))
{
Tizen.Log.Info("NUI", $"RedoIcon\n");
PWEngine.Redo();
Expand Down
4 changes: 2 additions & 2 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/UndoIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ protected override string GetSelectedImageUrl()
return $"{FrameworkInformation.ResourcePath}images/light/color_icon_selected.png";
}

public override bool OnClickIcon(object sender, View.TouchEventArgs args)
public override bool OnIconClicked(object sender, View.TouchEventArgs args)
{
if (base.OnClickIcon(sender, args))
if (base.OnIconClicked(sender, args))
{
Tizen.Log.Info("NUI", $"UndoIcon\n");
PWEngine.Undo();
Expand Down
4 changes: 2 additions & 2 deletions src/Tizen.NUI.PenWave/src/public/Tools/Eraser/EraserIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ protected override string GetSelectedImageUrl()
return $"{FrameworkInformation.ResourcePath}images/light/color_icon_selected.png";
}

public override bool OnClickIcon(object sender, View.TouchEventArgs args)
public override bool OnIconClicked(object sender, View.TouchEventArgs args)
{
base.OnClickIcon(sender, args);
base.OnIconClicked(sender, args);
return true;
}
}
Expand Down
Loading

0 comments on commit b41207f

Please sign in to comment.