Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Start tool tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
aplerdal committed Apr 28, 2024
1 parent d25fea1 commit e26c807
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
41 changes: 41 additions & 0 deletions AdvancedEdit/UI/Tools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using ImGuiNET;
using AdvancedEdit.Types;
using System.Numerics;

namespace AdvancedEdit.UI;
class ToolManager{

int tileSize = 16;
Vector2I mapSize;
bool dragged = false;
Vector2 lastPos;

Tool activeTool;
int selectedTile;
int[,] selectedArea;
int[,] previewIndicies;
Vector2 contentPosition = new Vector2(0,0);
public ToolManager(){

selectedTile = 0;
selectedArea = new int[0,0];
}
public void ClickEvent(int x, int y, ref byte[,] indicies){

}
public void MouseUpEvent(int x, int y, ref byte[,] indicies){

}
public void DrawToolPreview(){

}
}
public enum Tool{
Pencil,
Line,
Curve,
Rectangle,
FilledRectangle,
Oval,
Bucket,
}
7 changes: 5 additions & 2 deletions AdvancedEdit/UI/TrackPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ class TrackPanel
bool dragged = false;
Vector2 lastPos;
Vector2 contentPosition = new Vector2(0,0);

ToolManager toolManager = new ToolManager();
public TrackPanel()
{

}
/// <summary>
/// Gets the tile position in indicies at the given absolute position. Must be called from inside the UI rendering sequence of the TilePanel
Expand All @@ -54,7 +55,6 @@ public void SetTile(int selectedTile, Vector2 position)
}
public void Draw(IntPtr[] tileTextures, byte[,] indicies, ref byte selectedTile)
{
//TODO Fix memory leak
Vector2 newContentPos = contentPosition;
ImGui.Begin("TilePanel",ImGuiWindowFlags.NoScrollWithMouse | ImGuiWindowFlags.NoScrollbar);
mapSize = new Vector2I(indicies.GetLength(0), indicies.GetLength(1));
Expand All @@ -66,11 +66,14 @@ public void Draw(IntPtr[] tileTextures, byte[,] indicies, ref byte selectedTile)
{
ImGui.SetCursorPos(new(x*tileSize+contentPosition.X,y*tileSize+contentPosition.Y));
ImGui.Image(tileTextures[indicies[y,x]], new System.Numerics.Vector2(tileSize, tileSize));
if (previewIndicies[y,x]!=-1) toolManager.DrawToolPreview(x,y);
if (ImGui.IsItemHovered())
{
if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
{
indicies[y, x] = selectedTile;
} else {

}
}
if (ImGui.IsMouseDown(ImGuiMouseButton.Middle))
Expand Down

0 comments on commit e26c807

Please sign in to comment.