Skip to content

Commit

Permalink
PenWave CodeClean
Browse files Browse the repository at this point in the history
  • Loading branch information
JoogabYun committed Dec 19, 2024
1 parent 50846c3 commit 710cd53
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 51 deletions.
68 changes: 34 additions & 34 deletions src/Tizen.NUI.PenWave/src/public/Picker/PenWaveToolPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ namespace Tizen.NUI.PenWave
[EditorBrowsable(EditorBrowsableState.Never)]
public class PenWaveToolPicker : View
{
private static readonly string ResourcePath = FrameworkInformation.ResourcePath + "images/light/";
private static readonly string s_resourcePath = FrameworkInformation.ResourcePath + "images/light/";

// the icons for different brush types
private static readonly Dictionary<BrushType, string> BrushIconMap = new Dictionary<BrushType, string>
private static readonly Dictionary<BrushType, string> s_brushIconMap = new Dictionary<BrushType, string>
{
{ BrushType.Stroke, "icon_pencil.png" },
{ BrushType.VarStroke, "icon_varstroke_dec.png" },
Expand All @@ -46,29 +46,29 @@ public class PenWaveToolPicker : View
};

// the color palette for brushes
private static readonly List<Color> BrushColorMap = new List<Color>
private static readonly List<Color> s_brushColorMap = new List<Color>
{
new Color("#F7B32C"), new Color("#FD5703"), new Color("#DA1727"),
new Color("#FF00A8"), new Color("#74BFB8"), new Color("#4087C5"),
new Color("#070044"), new Color("#0E0E0E")
};

// the icons for different eraser types
private static readonly Dictionary<EraserType, string> EraserIconMap = new Dictionary<EraserType, string>
private static readonly Dictionary<EraserType, string> s_eraserIconMap = new Dictionary<EraserType, string>
{
{ EraserType.Partial, "icon_eraser.png" },
{ EraserType.Full, "icon_full_eraser.png" },
};

// the color palette for canvas background color
private static readonly List<Color> CanvasColor = new List<Color>
private static readonly List<Color> s_canvasColor = new List<Color>
{
new Color("#F0F0F0"), new Color("#B7B7B7"), new Color("#E3F2FF"),
new Color("#202022"), new Color("#515151"), new Color("#17234D"),
};

// the icons for different grid density types
private static readonly Dictionary<GridDensityType, string> GridIconMap = new Dictionary<GridDensityType, string>
private static readonly Dictionary<GridDensityType, string> s_gridIconMap = new Dictionary<GridDensityType, string>
{
{ GridDensityType.Small, "icon_small_grid_density.png" },
{ GridDensityType.Medium, "icon_medium_grid_density.png" },
Expand Down Expand Up @@ -139,7 +139,7 @@ private void InitializeUI()
LinearOrientation = LinearLayout.Orientation.Vertical,
};

// Picker View 구성
// Picker View
pickerView = new View
{
CornerRadius = new Vector4(10, 10, 10, 10),
Expand All @@ -152,11 +152,11 @@ private void InitializeUI()
HorizontalAlignment = HorizontalAlignment.Center,
CellPadding = new Size2D(5, 5),
},
BackgroundImage = ResourcePath + "menu_bg.png",
BackgroundImage = s_resourcePath + "menu_bg.png",
};
pickerView.TouchEvent += (s, e) => { return true; }; // Prevent touch events from propagating to the canvas view

// Popup View 구성
// Popup View
popupView = new View
{
WidthSpecification = LayoutParamPolicies.WrapContent,
Expand All @@ -168,7 +168,7 @@ private void InitializeUI()
LinearOrientation = LinearLayout.Orientation.Vertical,
CellPadding = new Size2D(5, 5),
},
BackgroundImage = ResourcePath + "picker_popup_bg.png",
BackgroundImage = s_resourcePath + "picker_popup_bg.png",
Padding = new Extents(20, 20, 20, 20),
};
popupView.Hide();
Expand All @@ -183,33 +183,33 @@ private void InitializeUI()
// Initialize the canvas tools and their corresponding buttons.
private void InitializeCanvasTools()
{
var backgroundColorButton = CreateToolButton(ResourcePath + "icon_color_palette.png", () =>
var backgroundColorButton = CreateToolButton(s_resourcePath + "icon_color_palette.png", () =>
{
ShowPaletteSetting();
});
pickerView.Add(backgroundColorButton);

var gridButton = CreateToolButton(ResourcePath + "icon_medium_grid_density.png", () =>
var gridButton = CreateToolButton(s_resourcePath + "icon_medium_grid_density.png", () =>
{
ShowGridSetting();
});
pickerView.Add(gridButton);

undoButton = CreateToolButton(ResourcePath + "icon_undo.png", () =>
undoButton = CreateToolButton(s_resourcePath + "icon_undo.png", () =>
{
canvasView.Undo();
UpdateUI();
});
pickerView.Add(undoButton);

redoButton = CreateToolButton(ResourcePath + "icon_redo.png", () =>
redoButton = CreateToolButton(s_resourcePath + "icon_redo.png", () =>
{
canvasView.Redo();
UpdateUI();
});
pickerView.Add(redoButton);

var clearButton = CreateToolButton(ResourcePath + "icon_clear.png", () =>
var clearButton = CreateToolButton(s_resourcePath + "icon_clear.png", () =>
{
canvasView.ClearCanvas();
UpdateUI();
Expand All @@ -235,13 +235,13 @@ private void ShowPaletteSetting()
}
};

foreach (var color in CanvasColor)
foreach (var color in s_canvasColor)
{
var button = new ImageView
{
Size2D = new Size2D(48, 48),
Color = color,
ResourceUrl = ResourcePath + "/color_icon_base.png",
ResourceUrl = s_resourcePath + "/color_icon_base.png",
};
button.TouchEvent += (s, e) =>
{
Expand Down Expand Up @@ -276,9 +276,9 @@ private void ShowGridSetting()
}
};

foreach (var icon in GridIconMap)
foreach (var icon in s_gridIconMap)
{
var button = CreateToolButton(ResourcePath + icon.Value, () =>
var button = CreateToolButton(s_resourcePath + icon.Value, () =>
{
canvasView.ToggleGrid(icon.Key);
});
Expand Down Expand Up @@ -311,7 +311,7 @@ private void AddTool(ToolBase tool, string icon)
{
tools[tool.GetType()] = tool;

var toolButton = CreateToolButton(ResourcePath + icon, () =>
var toolButton = CreateToolButton(s_resourcePath + icon, () =>
{
SetTool(tool);
});
Expand Down Expand Up @@ -387,9 +387,9 @@ private void AddBrushPicker(PencilTool pencilTool)
}
};

foreach (var icon in BrushIconMap)
foreach (var icon in s_brushIconMap)
{
var button = CreateToolButton(ResourcePath + icon.Value, () =>
var button = CreateToolButton(s_resourcePath + icon.Value, () =>
{
pencilTool.Brush = icon.Key;
pencilTool.Activate();
Expand All @@ -414,13 +414,13 @@ private void AddColorPicker(PencilTool pencilTool)
}
};

foreach (var color in BrushColorMap)
foreach (var color in s_brushColorMap)
{
var button = new ImageView
{
Size2D = new Size2D(48, 48),
Color = color,
ResourceUrl = ResourcePath + "/color_icon_base.png",
ResourceUrl = s_resourcePath + "/color_icon_base.png",
};
button.TouchEvent += (s, e) =>
{
Expand Down Expand Up @@ -490,9 +490,9 @@ private void AddEraserTypePicker(EraserTool eraserTool)
}
};

foreach (var icon in EraserIconMap)
foreach (var icon in s_eraserIconMap)
{
var button = CreateToolButton(ResourcePath + icon.Value, () =>
var button = CreateToolButton(s_resourcePath + icon.Value, () =>
{
eraserTool.Eraser = eraserTool.Eraser == EraserType.Partial
? EraserType.Full
Expand All @@ -519,7 +519,7 @@ private void AddSelectionTypePicker(SelectionTool selectionTool)
var types = Enum.GetValues(typeof(SelectionType));
foreach (SelectionType type in types)
{
var button = CreateToolButton(ResourcePath + $"icon_{type.ToString().ToLower()}.png", () =>
var button = CreateToolButton(s_resourcePath + $"icon_{type.ToString().ToLower()}.png", () =>
{
selectionTool.Selection = type;
});
Expand All @@ -544,7 +544,7 @@ private void AddRulerTypePicker(RulerTool rulerTool)
var types = Enum.GetValues(typeof(RulerType));
foreach (RulerType type in types)
{
var button = CreateToolButton(ResourcePath + $"icon_{type.ToString().ToLower()}.png", () =>
var button = CreateToolButton(s_resourcePath + $"icon_{type.ToString().ToLower()}.png", () =>
{
rulerTool.Ruler = type;
});
Expand All @@ -557,8 +557,8 @@ private void AddRulerTypePicker(RulerTool rulerTool)
/// <summary>
/// Add a button to the picker view with the given icon path and click action.
/// </summary>
/// <param name="iconPath"></param>
/// <param name="OnClick"></param>
/// <param name="iconPath">The icon image path</param>
/// <param name="OnClick">The action</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public void AddButtonToPickerView(string iconPath, Action OnClick)
{
Expand All @@ -573,7 +573,7 @@ public void AddButtonToPickerView(string iconPath, Action OnClick)
/// <summary>
/// Add a button to the picker view with the given view.
/// </summary>
/// <param name="view"></param>
/// <param name="view">The view</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public void AddViewToPickerView(View view)
{
Expand All @@ -583,8 +583,8 @@ public void AddViewToPickerView(View view)
/// <summary>
/// Add a button to the popup view with the given icon path and click action.
/// </summary>
/// <param name="iconPath"></param>
/// <param name="OnClick"></param>
/// <param name="iconPath">The icon image path</param>
/// <param name="OnClick">The action</param>
public void AddButtonToPopupView(string iconPath, Action OnClick)
{
var button = CreateToolButton(iconPath, OnClick);
Expand All @@ -594,7 +594,7 @@ public void AddButtonToPopupView(string iconPath, Action OnClick)
/// <summary>
/// Sets a button to the popup view with the given view
/// </summary>
/// <param name="view"></param>
/// <param name="view">The view</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetViewToPopupView(View view)
{
Expand Down
36 changes: 23 additions & 13 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/CanvasTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
using System.ComponentModel;
using System.Collections.Generic;
using Tizen.NUI;
using Tizen.NUI.BaseComponents;

namespace Tizen.NUI.PenWave
{
/// <summary>
/// The CanvasTool class provides a tool that allows the user to move the canvas around.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class CanvasTool : ToolBase
{
private float mInitialTouchX;
private float mInitialTouchY;
private bool mIsCanvasMoving = false;
private float initialTouchX;
private float initialTouchY;
private bool isCanvasMoving = false;
private PenWaveCanvas canvasView;

[EditorBrowsable(EditorBrowsableState.Never)]
Expand Down Expand Up @@ -57,6 +59,7 @@ public override void Deactivate()
/// <summary>
/// Handles input from the user.
/// </summary>
/// <param name="touch">The touch event.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool HandleInput(Touch touch)
{
Expand All @@ -74,7 +77,7 @@ public override bool HandleInput(Touch touch)
Vector2 position = touchPositionList[(int)pointStateIndex];
if (touch.GetMouseButton(0) == MouseButton.Secondary)
{
mIsCanvasMoving = true;
isCanvasMoving = true;
}
switch (touch.GetState(pointStateIndex))
{
Expand All @@ -89,36 +92,43 @@ public override bool HandleInput(Touch touch)
EndDrawing();
break;
}
return mIsCanvasMoving;
return isCanvasMoving;
}

// Start drawing when the first touch down event occurs.
private void StartDrawing(float positionX, float positionY, uint touchTime)
{
if (mIsCanvasMoving)
if (isCanvasMoving)
{
mInitialTouchX = positionX;
mInitialTouchY = positionY;
initialTouchX = positionX;
initialTouchY = positionY;
canvasView.MoveBegin();
}
}

// Continue drawing the touch motion events occur.
private void ContinueDrawing(float positionX, float positionY, uint touchTime)
{
if (mIsCanvasMoving)
if (isCanvasMoving)
{
canvasView.MoveUpdate((int)(positionX - mInitialTouchX), (int)(positionY - mInitialTouchY));
canvasView.MoveUpdate((int)(positionX - initialTouchX), (int)(positionY - initialTouchY));
}
}

// End drawing when the last touch up event occurs.
private void EndDrawing()
{
if (mIsCanvasMoving)
if (isCanvasMoving)
{
canvasView.MoveEnd();
mIsCanvasMoving = false;
isCanvasMoving = false;
}
}

/// <summary>
/// Handles input from the user.
/// </summary>
/// <param name="wheel">The wheel event.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool HandleInput(Wheel wheel)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Tizen.NUI.PenWave/src/public/Tools/Eraser/EraserTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
*
*/

using System;
using System.ComponentModel;
using System.Collections.Generic;
using Tizen.NUI;
using Tizen.NUI.BaseComponents;

namespace Tizen.NUI.PenWave
{
Expand Down
6 changes: 5 additions & 1 deletion src/Tizen.NUI.PenWave/src/public/Tools/Toolbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ public abstract class ToolBase
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract bool HandleInput(Touch touch);

/// <summary>
/// Handles input events such as wheel events and updates the state of the tool accordingly.
/// </summary>
/// <param name="wheel">The wheel event data.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract bool HandleInput(Wheel touch);
public abstract bool HandleInput(Wheel wheel);

/// <summary>
/// Activates the tool, making it ready to receive input and perform its functionality.
Expand Down

0 comments on commit 710cd53

Please sign in to comment.