Skip to content

Commit

Permalink
Add ToolActionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
JoogabYun committed Nov 7, 2024
1 parent 7fd221c commit 18762e7
Show file tree
Hide file tree
Showing 21 changed files with 549 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ public BackgroundColorIcon(Tizen.NUI.Color color) : base()
mColorHex = ToHex(color);
mColor = color;

string url = $"{FrameworkInformation.ResourcePath}images/light/color_icon_base.png";
InitializeIcon(mColor);
}

InitializeIcon(url, mColor);
protected override string GetDefaultImageUrl()
{
return $"{FrameworkInformation.ResourcePath}images/light/color_icon_base.png";
}

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

public override bool IconClick(object sender, View.TouchEventArgs args)
Expand Down
16 changes: 2 additions & 14 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/CanvasTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CanvasTool : ToolBase
private Icon palettIcon;
private Icon gridIcon;

public CanvasTool()
public CanvasTool() : base(new CanvasToolActionHandler())
{
palettIcon = new PalettIcon();
AddIcon(palettIcon);
Expand All @@ -52,18 +52,6 @@ public CanvasTool()
AddIcon(gridIcon);
}

protected override void StartDrawing(Vector2 position, uint touchTime)
{
}

protected override void ContinueDrawing(Vector2 position, uint touchTime)
{
}

protected override void EndDrawing()
{
}

protected override void OnIconSelected(object sender)
{
Tizen.Log.Info("NUI", $"OnIconSelected\n");
Expand Down Expand Up @@ -98,7 +86,7 @@ private void AddIconsToView<T>(View rootView, IEnumerable<T>items, Func<T, Icon>
{
var icon = iconFactory(item);
view.Add(icon);
// icon.IconSelected +=(s) => PopupManager.HidePopup();
// icon.IconSelected += OnIconSelected;
}

rootView.Add(view);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 class CanvasToolActionHandler : IToolActionHandler
{
public void Activate()
{
}

public void Deactivate()
{
}

public void HandleInput(Touch touch)
{
}
}
}


12 changes: 11 additions & 1 deletion src/Tizen.NUI.PenWave/src/public/Tools/Canvas/GridIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ public enum GridDensityType

public GridIcon() : base()
{
InitializeIcon(url, new Color("#17234d"));
InitializeIcon(new Color("#17234d"));
}

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

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

public override bool IconClick(object sender, View.TouchEventArgs args)
Expand Down
14 changes: 11 additions & 3 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/PalettIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ namespace Tizen.NUI.PenWave
{
public class PalettIcon : Icon
{
private static readonly string url = $"{FrameworkInformation.ResourcePath}images/light/icon_color_palette.png";

public PalettIcon() : base()
{
InitializeIcon(url, new Color("#17234d"));
InitializeIcon(new Color("#17234d"));
}

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

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

public override bool IconClick(object sender, View.TouchEventArgs args)
Expand Down
11 changes: 9 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 @@ -27,10 +27,17 @@ public class EraserIcon : Icon
{
public EraserIcon() : base()
{
InitializeIcon(new Color("#17234d"));
}

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

InitializeIcon(url, new Color("#17234d"));
protected override string GetSelectedImageUrl()
{
return $"{FrameworkInformation.ResourcePath}images/light/color_icon_selected.png";
}

public override bool IconClick(object sender, View.TouchEventArgs args)
Expand Down
26 changes: 1 addition & 25 deletions src/Tizen.NUI.PenWave/src/public/Tools/Eraser/EraserTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,11 @@ namespace Tizen.NUI.PenWave
{
public class EraserTool : ToolBase
{
enum Mode
{
Partial,
Full
}

public override ToolBase.ToolType Type => ToolBase.ToolType.Eraser;
private float radiusEraser = 48; // 지우개 사이즈 설정 가능해야 함
private Mode mode = Mode.Partial;

public EraserTool()
public EraserTool() : base(new EraserToolActionHandler())
{
AddIcon(new EraserIcon());
}

protected override void StartDrawing(Vector2 position, uint touchTime)
{
PWEngine.EraseShape((int)position.X, (int)position.Y, radiusEraser, (mode == Mode.Partial));
}

protected override void ContinueDrawing(Vector2 position, uint touchTime)
{
PWEngine.EraseShape((int)position.X, (int)position.Y, radiusEraser, (mode == Mode.Partial));
}

protected override void EndDrawing()
{
PWEngine.StopErasing();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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 class EraserToolActionHandler : IToolActionHandler
{
enum Mode
{
Partial,
Full
}

private Mode mode = Mode.Partial;
private float radiusEraser = 48; // 지우개 사이즈 설정 가능해야 함

public void Activate()
{
}

public void Deactivate()
{
EndDrawing();
}

public void HandleInput(Touch touch)
{
if (touch == null || touch.GetPointCount() == 0) return;

uint pointStateIndex = 0;
uint touchTime = touch.GetTime();

List<Vector2> touchPositionList = new List<Vector2>();
for (uint i = 0; i < touch.GetPointCount(); ++i)
{
touchPositionList.Add(touch.GetLocalPosition(i));
}

Vector2 position = touchPositionList[(int)pointStateIndex];
switch (touch.GetState(pointStateIndex))
{
case PointStateType.Down:
StartDrawing(position, touchTime);
break;
case PointStateType.Motion:
ContinueDrawing(position, touchTime);
break;
case PointStateType.Up:
case PointStateType.Leave:
EndDrawing();
break;
}
}

private void StartDrawing(Vector2 position, uint touchTime)
{
PWEngine.EraseShape((int)position.X, (int)position.Y, radiusEraser, (mode == Mode.Partial));
}

private void ContinueDrawing(Vector2 position, uint touchTime)
{
PWEngine.EraseShape((int)position.X, (int)position.Y, radiusEraser, (mode == Mode.Partial));
}

private void EndDrawing()
{
PWEngine.StopErasing();
}

}
}


34 changes: 34 additions & 0 deletions src/Tizen.NUI.PenWave/src/public/Tools/IToolActionHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 IToolActionHandler
{
void HandleInput(Touch touch);
void Activate();
void Deactivate();
}
}


Loading

0 comments on commit 18762e7

Please sign in to comment.