mirror of
https://github.com/Fluffy-Bean/ColouringApp.git
synced 2025-01-14 17:35:12 +00:00
File loading!??!?!?!??!
This commit is contained in:
parent
f2d2a539ea
commit
df80318d3f
BIN
assets/manedWolf.jpg
Normal file
BIN
assets/manedWolf.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 111 KiB |
26
canvas.go
26
canvas.go
|
@ -12,7 +12,8 @@ type Canvas struct {
|
||||||
Size raylib.Vector2
|
Size raylib.Vector2
|
||||||
Offset raylib.Vector2
|
Offset raylib.Vector2
|
||||||
|
|
||||||
Target raylib.RenderTexture2D
|
Target raylib.RenderTexture2D
|
||||||
|
Background raylib.Texture2D
|
||||||
|
|
||||||
Strokes []raylib.Texture2D
|
Strokes []raylib.Texture2D
|
||||||
UndoneStrokes []raylib.Texture2D
|
UndoneStrokes []raylib.Texture2D
|
||||||
|
@ -25,7 +26,16 @@ func (c *Canvas) Update() {
|
||||||
c.Target = raylib.LoadRenderTexture(int32(c.Size.X), int32(c.Size.Y))
|
c.Target = raylib.LoadRenderTexture(int32(c.Size.X), int32(c.Size.Y))
|
||||||
|
|
||||||
raylib.BeginTextureMode(c.Target)
|
raylib.BeginTextureMode(c.Target)
|
||||||
raylib.ClearBackground(raylib.White)
|
//raylib.ClearBackground(raylib.White)
|
||||||
|
raylib.DrawTexturePro(
|
||||||
|
c.Background,
|
||||||
|
raylib.NewRectangle(0, 0, c.Size.X, -c.Size.Y),
|
||||||
|
raylib.NewRectangle(0, 0, c.Size.X, c.Size.Y),
|
||||||
|
raylib.Vector2Zero(),
|
||||||
|
0,
|
||||||
|
raylib.White,
|
||||||
|
)
|
||||||
|
|
||||||
for _, stroke := range c.Strokes {
|
for _, stroke := range c.Strokes {
|
||||||
raylib.DrawTexturePro(
|
raylib.DrawTexturePro(
|
||||||
stroke,
|
stroke,
|
||||||
|
@ -44,7 +54,14 @@ func (c *Canvas) Update() {
|
||||||
|
|
||||||
func (c *Canvas) AddStroke(stroke raylib.Texture2D) {
|
func (c *Canvas) AddStroke(stroke raylib.Texture2D) {
|
||||||
c.Strokes = append(c.Strokes, stroke)
|
c.Strokes = append(c.Strokes, stroke)
|
||||||
c.UndoneStrokes = []raylib.Texture2D{}
|
|
||||||
|
if len(c.UndoneStrokes) > 0 {
|
||||||
|
for i := range c.UndoneStrokes {
|
||||||
|
raylib.UnloadTexture(c.UndoneStrokes[i])
|
||||||
|
}
|
||||||
|
c.UndoneStrokes = []raylib.Texture2D{}
|
||||||
|
}
|
||||||
|
|
||||||
c.Refresh = true
|
c.Refresh = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,12 +113,13 @@ func (c *Canvas) Save() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCanvas(name string, size, offset raylib.Vector2) *Canvas {
|
func NewCanvas(name string, size, offset raylib.Vector2, background raylib.Texture2D) *Canvas {
|
||||||
return &Canvas{
|
return &Canvas{
|
||||||
Name: name,
|
Name: name,
|
||||||
Size: size,
|
Size: size,
|
||||||
Offset: offset,
|
Offset: offset,
|
||||||
Target: raylib.LoadRenderTexture(int32(size.X), int32(size.Y)),
|
Target: raylib.LoadRenderTexture(int32(size.X), int32(size.Y)),
|
||||||
|
Background: background,
|
||||||
Strokes: []raylib.Texture2D{},
|
Strokes: []raylib.Texture2D{},
|
||||||
UndoneStrokes: []raylib.Texture2D{},
|
UndoneStrokes: []raylib.Texture2D{},
|
||||||
Refresh: true,
|
Refresh: true,
|
||||||
|
|
59
main.go
59
main.go
|
@ -49,9 +49,10 @@ func main() {
|
||||||
checkDirs() // Make sure all the directories exist
|
checkDirs() // Make sure all the directories exist
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagWindowResizable)
|
raylib.SetConfigFlags(raylib.FlagWindowResizable)
|
||||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
|
||||||
//raylib.SetTraceLogLevel(raylib.LogTrace)
|
//raylib.SetTraceLogLevel(raylib.LogTrace)
|
||||||
//raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
//raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||||
|
//raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||||
|
//raylib.SetConfigFlags(raylib.FlagFullscreenMode)
|
||||||
|
|
||||||
raylib.InitWindow(WindowWidth, WindowHeight, WindowTitle)
|
raylib.InitWindow(WindowWidth, WindowHeight, WindowTitle)
|
||||||
raylib.SetWindowMinSize(int(WindowMinWidth), int(WindowMinHeight))
|
raylib.SetWindowMinSize(int(WindowMinWidth), int(WindowMinHeight))
|
||||||
|
@ -65,6 +66,7 @@ func main() {
|
||||||
|
|
||||||
sidePanelWidth = float32(350)
|
sidePanelWidth = float32(350)
|
||||||
sidePanelRelativeX = WindowWidth - int32(sidePanelWidth)
|
sidePanelRelativeX = WindowWidth - int32(sidePanelWidth)
|
||||||
|
//sidePanelPos = sidePanelRelativeX
|
||||||
|
|
||||||
colourPickerVal = raylib.Orange
|
colourPickerVal = raylib.Orange
|
||||||
colourPickerHeight = float32(250)
|
colourPickerHeight = float32(250)
|
||||||
|
@ -81,7 +83,13 @@ func main() {
|
||||||
)
|
)
|
||||||
|
|
||||||
// init canvas
|
// init canvas
|
||||||
canvas = NewCanvas("NewProject", raylib.NewVector2(700, 530), raylib.NewVector2(15, 15))
|
canvasBackground := raylib.LoadRenderTexture(700, 530)
|
||||||
|
{
|
||||||
|
raylib.BeginTextureMode(canvasBackground)
|
||||||
|
raylib.ClearBackground(raylib.White)
|
||||||
|
raylib.EndTextureMode()
|
||||||
|
}
|
||||||
|
canvas = NewCanvas("NewProject", raylib.NewVector2(700, 530), raylib.NewVector2(15, 15), canvasBackground.Texture)
|
||||||
|
|
||||||
// LOOP
|
// LOOP
|
||||||
for !appShouldQuit {
|
for !appShouldQuit {
|
||||||
|
@ -94,6 +102,9 @@ func main() {
|
||||||
|
|
||||||
// INPUT
|
// INPUT
|
||||||
{
|
{
|
||||||
|
if raylib.IsKeyPressed(raylib.KeyF7) {
|
||||||
|
AddToast("This is a test toast")
|
||||||
|
}
|
||||||
if raylib.IsKeyPressed(raylib.KeyF8) {
|
if raylib.IsKeyPressed(raylib.KeyF8) {
|
||||||
showDebugStats = !showDebugStats
|
showDebugStats = !showDebugStats
|
||||||
}
|
}
|
||||||
|
@ -151,6 +162,12 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
showCursor = true
|
showCursor = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if state == StateDrawing {
|
||||||
|
// sidePanelPos = int32(raylib.Lerp(float32(sidePanelPos), float32(WindowWidth), 0.5))
|
||||||
|
//} else {
|
||||||
|
// sidePanelPos = int32(raylib.Lerp(float32(sidePanelPos), float32(sidePanelRelativeX), 0.5))
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DRAW
|
// DRAW
|
||||||
|
@ -173,17 +190,12 @@ func main() {
|
||||||
}
|
}
|
||||||
raylib.EndMode2D()
|
raylib.EndMode2D()
|
||||||
|
|
||||||
// Cursor
|
|
||||||
if showCursor {
|
|
||||||
raylib.DrawCircleLines(int32(raylib.GetMousePosition().X), int32(raylib.GetMousePosition().Y), brushSize/2, raylib.Black)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UI stuff
|
// UI stuff
|
||||||
raylib.BeginScissorMode(sidePanelRelativeX, 0, int32(sidePanelWidth), WindowHeight)
|
raylib.BeginScissorMode(sidePanelRelativeX, 0, int32(sidePanelWidth), WindowHeight)
|
||||||
{
|
{
|
||||||
raylib.DrawRectangle(sidePanelRelativeX, 0, int32(sidePanelWidth), WindowHeight, raylib.Fade(raylib.White, 0.7))
|
raylib.DrawRectangle(sidePanelRelativeX, 0, int32(sidePanelWidth), WindowHeight, raylib.Fade(raylib.White, 0.7))
|
||||||
|
|
||||||
if gui.Button(raylib.NewRectangle(float32(sidePanelRelativeX+10), 10, 25, 25), gui.IconText(gui.ICON_CROSS, "")) {
|
if gui.Button(raylib.NewRectangle(float32(sidePanelRelativeX+10), 10, 25, 25), gui.IconText(gui.ICON_FOLDER_OPEN, "")) {
|
||||||
state = StateFileMenu
|
state = StateFileMenu
|
||||||
}
|
}
|
||||||
if gui.Button(raylib.NewRectangle(float32(sidePanelRelativeX+20+25), 10, 25, 25), gui.IconText(gui.ICON_FOLDER_SAVE, "")) {
|
if gui.Button(raylib.NewRectangle(float32(sidePanelRelativeX+20+25), 10, 25, 25), gui.IconText(gui.ICON_FOLDER_SAVE, "")) {
|
||||||
|
@ -206,9 +218,9 @@ func main() {
|
||||||
if gui.TextBox(raylib.NewRectangle(float32(sidePanelRelativeX+80), 115+colourPickerHeight, sidePanelWidth-90, 20), &canvas.Name, 40, fileNameEditing) {
|
if gui.TextBox(raylib.NewRectangle(float32(sidePanelRelativeX+80), 115+colourPickerHeight, sidePanelWidth-90, 20), &canvas.Name, 40, fileNameEditing) {
|
||||||
fileNameEditing = !fileNameEditing
|
fileNameEditing = !fileNameEditing
|
||||||
}
|
}
|
||||||
|
raylib.DrawRectangleLines(sidePanelRelativeX, 0, int32(sidePanelWidth), WindowHeight, raylib.Gray)
|
||||||
}
|
}
|
||||||
raylib.EndScissorMode()
|
raylib.EndScissorMode()
|
||||||
raylib.DrawRectangleLines(sidePanelRelativeX, 0, int32(sidePanelWidth), WindowHeight, raylib.Gray)
|
|
||||||
|
|
||||||
// Info
|
// Info
|
||||||
if showDebugStats {
|
if showDebugStats {
|
||||||
|
@ -224,14 +236,39 @@ func main() {
|
||||||
gui.StatusBar(raylib.NewRectangle(300, float32(WindowHeight-20), 170, 20), text)
|
gui.StatusBar(raylib.NewRectangle(300, float32(WindowHeight-20), 170, 20), text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cursor
|
||||||
|
if showCursor {
|
||||||
|
}
|
||||||
|
raylib.DrawCircleLines(int32(raylib.GetMousePosition().X), int32(raylib.GetMousePosition().Y), brushSize/2, raylib.Black)
|
||||||
|
|
||||||
switch state {
|
switch state {
|
||||||
case StateFileMenu:
|
case StateFileMenu:
|
||||||
gui.SetState(gui.STATE_NORMAL)
|
gui.SetState(gui.STATE_NORMAL)
|
||||||
raylib.DrawRectangle(0, 0, WindowWidth, WindowHeight, raylib.Fade(raylib.Black, 0.5))
|
raylib.DrawRectangle(0, 0, WindowWidth, WindowHeight, raylib.Fade(raylib.Black, 0.5))
|
||||||
choice := gui.MessageBox(raylib.NewRectangle(float32(WindowWidth/2-200), float32(WindowHeight/2-100), 400, 200), "File", "This is a message box", "Ok")
|
|
||||||
if choice == 0 || choice == 1 {
|
windowPos := raylib.NewRectangle(float32((WindowWidth/2)-200), float32((WindowHeight/2)-100), 400, 200)
|
||||||
|
if gui.WindowBox(windowPos, "Open or New File") {
|
||||||
state = StateNormal
|
state = StateNormal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Magic numbers
|
||||||
|
raylib.BeginScissorMode(int32(windowPos.X)+1, int32(windowPos.Y)+24, int32(windowPos.Width)-2, int32(windowPos.Height)-25)
|
||||||
|
if gui.Button(raylib.NewRectangle(float32((WindowWidth/2)-190), float32((WindowHeight/2)-80), 180, 20), "New File") {
|
||||||
|
loadedImage := raylib.LoadImage(DirAssets + "manedWolf.jpg")
|
||||||
|
raylib.ImageFlipHorizontal(loadedImage)
|
||||||
|
raylib.ImageRotate(loadedImage, 180)
|
||||||
|
|
||||||
|
// Create New Canvas with the loaded image as the background
|
||||||
|
canvas = NewCanvas("NewProject", raylib.NewVector2(float32(loadedImage.Width), float32(loadedImage.Height)), raylib.NewVector2(15, 15), raylib.LoadTextureFromImage(loadedImage))
|
||||||
|
|
||||||
|
// SAVE MEMORY
|
||||||
|
raylib.UnloadImage(loadedImage)
|
||||||
|
|
||||||
|
// Aurghhhhh
|
||||||
|
state = StateNormal
|
||||||
|
}
|
||||||
|
raylib.EndScissorMode()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue