Skip to content

Commit

Permalink
CanvasBackground
Browse files Browse the repository at this point in the history
  • Loading branch information
JoogabYun committed Nov 1, 2024
1 parent 08b1de7 commit 68c4f60
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Tizen.NUI.PenWave/src/public/PWCanvasView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public static PWCanvasView CreateDefaultCanvas()
{
var canvasView = new PWCanvasView();

CanvasTool canvasTool = new CanvasTool();
PencilTool pencilTool = new PencilTool();
EraserTool eraserTool = new EraserTool();
SelectTool selectTool = new SelectTool();

canvasView.ToolManager.RegisterTool(canvasTool);
canvasView.ToolManager.RegisterTool(pencilTool);
canvasView.ToolManager.RegisterTool(eraserTool);
canvasView.ToolManager.RegisterTool(selectTool);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 BackgroundColorIcon : Icon
{
private readonly string mColorHex;
private readonly Color mColor;

public BackgroundColorIcon(Tizen.NUI.Color color) : base()
{
mColorHex = ToHex(color);
mColor = color;

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

InitializeIcon(url, mColor);
}

public override bool IconClick(object sender, View.TouchEventArgs args)
{
if (base.IconClick(sender, args))
{
PWEngine.CanvasSetColor(GetColorHex(), 1.0f);
}
return true;
}

private string ToHex(Color color)
{
var red = (uint)(color.R * 255);
var green = (uint)(color.G * 255);
var blue = (uint)(color.B * 255);
return $"#{red:X2}{green:X2}{blue:X2}";
}

public string GetColorHex() => mColorHex;
}
}
124 changes: 124 additions & 0 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/CanvasTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* 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 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>
{
new Color("#FFFEFE"),
new Color("#F0F0F0"),
new Color("#B7B7B7"),
new Color("#E3F2FF"),
new Color("#202022"),
new Color("#515151"),
new Color("#17234D"),
new Color("#090E21"),
};

public CanvasTool()
{

}

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

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

protected override void EndDrawing()
{
}

protected override void Deactivate()
{
EndDrawing();
}

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;
}

private void MakePopup(View rootView)
{
var bgImage = new ImageView
{
BackgroundImage = popupBgUrl,
WidthSpecification = LayoutParamPolicies.WrapContent,
HeightSpecification = LayoutParamPolicies.WrapContent,
Layout = new GridLayout { Columns = 1, RowSpacing = 4 }
};
AddIconsToView(bgImage, BgColors, color => new BackgroundColorIcon(color));
rootView.Add(bgImage);
}

private void AddIconsToView<T>(View rootView, IEnumerable<T>items, Func<T, Icon> 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();


// }

}
}
48 changes: 48 additions & 0 deletions src/Tizen.NUI.PenWave/src/public/Tools/Canvas/PalettIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 PalettIcon : Icon
{
private static readonly string url = $"{FrameworkInformation.ResourcePath}images/light/icon_color_palette.png";

private ImageView bgImage;

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

public override bool IconClick(object sender, View.TouchEventArgs args)
{
if (base.IconClick(sender, args))
{
Tizen.Log.Error("NUI", $"PalettIcon show\n");
// 캔버스 색상 팝업
}
return true;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SelectIcon : Icon
public SelectIcon() : base()
{

string url = $"{FrameworkInformation.ResourcePath}images/light/icon_select.png";
string url = $"{FrameworkInformation.ResourcePath}images/light/icon_select_area.png";

InitializeIcon(url, new Color("#17234d"));
}
Expand Down
3 changes: 2 additions & 1 deletion src/Tizen.NUI.PenWave/src/public/Tools/ToolBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum ToolType
Eraser,
Select,
Scale,
Canvas,
}

public abstract ToolBase.ToolType Type { get; }
Expand All @@ -53,7 +54,7 @@ public bool Activate
}
}

protected void OnIconSelected()
protected virtual void OnIconSelected()
{
ToolSelected?.Invoke(Type);
}
Expand Down
1 change: 1 addition & 0 deletions src/Tizen.NUI.PenWave/src/public/Tools/ToolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void OnToolSelected(ToolBase.ToolType toolType)
{
Tizen.Log.Info("NUI", $"OnToolSelected {toolType}\n");
SelectTool(toolType);
ToolChanged?.Invoke(toolType);
}
}
}
7 changes: 7 additions & 0 deletions src/Tizen.NUI.PenWave/src/public/Tools/ToolPickerView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ToolPickerView : View
public ToolPickerView(ToolManager toolManager)
{
this.mToolManager = toolManager;
toolManager.ToolChanged += OnUpdateUI;
mToolUIs = new Dictionary<ToolBase.ToolType, View>();

InitializeUI();
Expand Down Expand Up @@ -60,6 +61,12 @@ private void InitializeUI()
}


private void OnUpdateUI(ToolBase.ToolType toolType)
{

}


public void ShowTool(ToolBase.ToolType type)
{
if (mToolUIs.TryGetValue(type, out var toolView))
Expand Down

0 comments on commit 68c4f60

Please sign in to comment.