Skip to content

Commit

Permalink
PenWave
Browse files Browse the repository at this point in the history
  • Loading branch information
JoogabYun committed Nov 29, 2024
1 parent 15f53d3 commit 8bdfab2
Show file tree
Hide file tree
Showing 19 changed files with 955 additions and 445 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal class CanvasRenderer

// Canvas id.
private uint canvasId;
private PenWave engine;

/// <summary>
/// Constructor. Creates a new instance of CanvasRenderer. This constructor sets the current canvas to the specified canvas id. Also it sets paths to resources and initializes textures.
Expand All @@ -53,26 +54,27 @@ internal class CanvasRenderer
public CanvasRenderer(uint canvasId)
{
this.canvasId = canvasId;
PWEngine.SetCurrentCanvas(canvasId);
PWEngine.SetResourcePath(FrameworkInformation.ResourcePath + "images/");
PWEngine.SetFontPath(FontPath);
PWEngine.SetTexturePaths(TexturePaths, TexturePaths.Length);
engine = PenWave.Instance;
engine.SetCurrentCanvas(canvasId);
engine.SetResourcePath(FrameworkInformation.ResourcePath + "images/");
engine.SetFontPath(FontPath);
engine.SetTexturePaths(TexturePaths, TexturePaths.Length);
}

/// <summary>
/// Initializes OpenGL context. This method must be called before any other methods that require OpenGL context.
/// </summary>
public void InitializeGL()
{
PWEngine.InitializeGL();
engine.InitializeGL();
}

/// <summary>
/// Terminates OpenGL context. This method must be called after all methods that require OpenGL context are finished.
/// </summary>
public void TerminateGL()
{
PWEngine.TerminateGL();
engine.TerminateGL();
}

/// <summary>
Expand All @@ -82,7 +84,7 @@ public void TerminateGL()
/// <returns></returns>
public int RenderFrame(in DirectRenderingGLView.RenderCallbackInput input)
{
return PWEngine.RenderFrameGL();
return engine.RenderFrameGL();
}

/// <summary>
Expand All @@ -92,16 +94,16 @@ public int RenderFrame(in DirectRenderingGLView.RenderCallbackInput input)
/// <param name="height"></param>
public void Resize(int width, int height)
{
PWEngine.UpdateGLWindowSize(width, height);
PWEngine.RenderFullyReDraw();
engine.UpdateGLWindowSize(width, height);
engine.RenderFullyReDraw();
}

/// <summary>
/// Clears the current canvas. All strokes and pictures will be removed.
/// </summary>
public void ClearCanvas()
{
PWEngine.ClearCurrentCanvas();
engine.ClearCurrentCanvas();
}

/// <summary>
Expand All @@ -110,7 +112,7 @@ public void ClearCanvas()
/// <param name="path"></param>
public void AddPicture(string path, Size2D size, Position2D position)
{
PWEngine.AddPicture(path, position.X, position.Y, size.Width, size.Height);
engine.AddPicture(path, position.X, position.Y, size.Width, size.Height);
}

/// <summary>
Expand All @@ -119,7 +121,7 @@ public void AddPicture(string path, Size2D size, Position2D position)
/// <param name="gridType"></param>
public void ToggleGrid(GridDensityType gridType)
{
PWEngine.ToggleGrid((int)gridType);
engine.ToggleGrid((int)gridType);
}

/// <summary>
Expand All @@ -128,7 +130,7 @@ public void ToggleGrid(GridDensityType gridType)
/// <param name="color"></param>
public void SetCanvasColor(Color color)
{
PWEngine.CanvasSetColor(ToHex(color), 1.0f);
engine.CanvasSetColor(ToHex(color), 1.0f);
}

/// <summary>
Expand All @@ -137,7 +139,7 @@ public void SetCanvasColor(Color color)
/// <param name="path"></param>
public void SaveCanvas(string path)
{
PWEngine.SaveCanvas(canvasId, path);
engine.SaveCanvas(canvasId, path);
}

/// <summary>
Expand All @@ -152,10 +154,25 @@ public void LoadCanvas(string path)
}
else
{
PWEngine.LoadCanvas(canvasId, path);
engine.LoadCanvas(canvasId, path);
}
}

/// <summary>
/// Takes screenshot of the current canvas and saves it to the specified path. The area of the screenshot is defined by the coordinates and dimensions. The callback is called when the screenshot is saved. The callback has one parameter which is the path to the saved image. If the path is null, then the screenshot was not saved successfully.
/// </summary>
/// <param name="path"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="callback"></param>
public void TakeScreenShot(string path, int x, int y, int width, int height, PenWave.ThumbnailSavedDelegate callback)
{
engine.TakeScreenshot(canvasId, path, x, y, width, height, callback);
}

// Converts Color to hex string.
private string ToHex(Color color)
{
var red = (uint)(color.R * 255);
Expand Down
Loading

0 comments on commit 8bdfab2

Please sign in to comment.