mirror of
https://github.com/Fluffy-Bean/ColouringApp.git
synced 2025-01-28 07:18:23 +00:00
If overridden, don't keep asking, file exists warning on new canvas screen
This commit is contained in:
parent
6b5b6e4dbe
commit
59036706ea
40
canvas.go
40
canvas.go
|
@ -23,6 +23,7 @@ type Canvas struct {
|
||||||
UndoneStrokes []raylib.Texture2D
|
UndoneStrokes []raylib.Texture2D
|
||||||
|
|
||||||
UnsavedChanges bool
|
UnsavedChanges bool
|
||||||
|
EditingFile bool
|
||||||
Refresh bool
|
Refresh bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,30 +111,28 @@ func (c *Canvas) Save(force bool) {
|
||||||
addToast("Please enter a file name!")
|
addToast("Please enter a file name!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// check if file already exists, sorry for lazy
|
// check if file already exists
|
||||||
if _, err := os.Stat(filepath.Join(dirUserData, c.Name+".png")); errors.Is(err, os.ErrNotExist) {
|
if !c.EditingFile {
|
||||||
image := raylib.LoadImageFromTexture(c.Target.Texture)
|
_, err := os.Stat(filepath.Join(dirUserData, c.Name+".png"))
|
||||||
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
raylib.ImageRotate(image, 180)
|
if !force {
|
||||||
raylib.ImageFlipHorizontal(image)
|
|
||||||
|
|
||||||
raylib.ExportImage(*image, filepath.Join(dirUserData, c.Name+".png"))
|
|
||||||
|
|
||||||
addToast("Drawing saved as " + c.Name + ".png")
|
|
||||||
} else if force {
|
|
||||||
image := raylib.LoadImageFromTexture(c.Target.Texture)
|
|
||||||
|
|
||||||
raylib.ImageRotate(image, 180)
|
|
||||||
raylib.ImageFlipHorizontal(image)
|
|
||||||
|
|
||||||
raylib.ExportImage(*image, filepath.Join(dirUserData, c.Name+".png"))
|
|
||||||
|
|
||||||
addToast("Drawing saved as " + c.Name + ".png")
|
|
||||||
} else {
|
|
||||||
applicationState = StateFileExists
|
applicationState = StateFileExists
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
image := raylib.LoadImageFromTexture(c.Target.Texture)
|
||||||
|
|
||||||
|
raylib.ImageRotate(image, 180)
|
||||||
|
raylib.ImageFlipHorizontal(image)
|
||||||
|
|
||||||
|
raylib.ExportImage(*image, filepath.Join(dirUserData, c.Name+".png"))
|
||||||
|
|
||||||
|
addToast("Drawing saved as " + c.Name + ".png")
|
||||||
|
|
||||||
c.UnsavedChanges = false
|
c.UnsavedChanges = false
|
||||||
|
c.EditingFile = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCanvas(name string, size, offset raylib.Vector2, background raylib.Texture2D) *Canvas {
|
func NewCanvas(name string, size, offset raylib.Vector2, background raylib.Texture2D) *Canvas {
|
||||||
|
@ -146,6 +145,7 @@ func NewCanvas(name string, size, offset raylib.Vector2, background raylib.Textu
|
||||||
Strokes: []raylib.Texture2D{},
|
Strokes: []raylib.Texture2D{},
|
||||||
UndoneStrokes: []raylib.Texture2D{},
|
UndoneStrokes: []raylib.Texture2D{},
|
||||||
UnsavedChanges: false,
|
UnsavedChanges: false,
|
||||||
|
EditingFile: false,
|
||||||
Refresh: true,
|
Refresh: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
33
main.go
33
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -13,12 +14,13 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Initialize raylib
|
// Initialize raylib
|
||||||
raylib.SetConfigFlags(raylib.FlagWindowResizable | raylib.FlagMsaa4xHint) // raylib.FlagWindowHighdpi
|
raylib.SetConfigFlags(raylib.FlagWindowResizable) // | raylib.FlagWindowHighdpi | raylib.FlagMsaa4xHint)
|
||||||
raylib.InitWindow(applicationWindowWidth, applicationWindowHeight, applicationTitle)
|
raylib.InitWindow(applicationWindowWidth, applicationWindowHeight, applicationTitle)
|
||||||
raylib.SetWindowMinSize(int(applicationMinWindowWidth), int(applicationMinWindowHeight)) // Set a minimum window size
|
raylib.SetWindowMinSize(int(applicationMinWindowWidth), int(applicationMinWindowHeight))
|
||||||
raylib.SetTargetFPS(int32(raylib.GetMonitorRefreshRate(raylib.GetCurrentMonitor()))) // Match monitor refresh rate
|
//raylib.SetTargetFPS(int32(raylib.GetMonitorRefreshRate(raylib.GetCurrentMonitor())))
|
||||||
raylib.SetExitKey(raylib.KeyNull) // disable exit key
|
raylib.SetTargetFPS(60)
|
||||||
raylib.HideCursor() // Hide cursor
|
raylib.SetExitKey(raylib.KeyNull)
|
||||||
|
raylib.HideCursor()
|
||||||
|
|
||||||
// Make sure both assets and userData directories exist
|
// Make sure both assets and userData directories exist
|
||||||
if _, err := os.Stat(dirAssets); os.IsNotExist(err) {
|
if _, err := os.Stat(dirAssets); os.IsNotExist(err) {
|
||||||
|
@ -205,7 +207,7 @@ func main() {
|
||||||
applicationState = StateHelp
|
applicationState = StateHelp
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawLine(toolBarOffset, 0, toolBarOffset, applicationWindowHeight, raylib.Black)
|
raylib.DrawLine(toolBarOffset+1, 0, toolBarOffset+1, applicationWindowHeight, raylib.Black)
|
||||||
}
|
}
|
||||||
raylib.EndScissorMode()
|
raylib.EndScissorMode()
|
||||||
|
|
||||||
|
@ -231,14 +233,15 @@ func main() {
|
||||||
|
|
||||||
toolPanelColourPicker = gui.ColorPicker(raylib.NewRectangle(float32(toolPanelOffset+10), 45, float32(toolPanelWidth-45), toolPanelColourPickerHeight), "Color", toolPanelColourPicker)
|
toolPanelColourPicker = gui.ColorPicker(raylib.NewRectangle(float32(toolPanelOffset+10), 45, float32(toolPanelWidth-45), toolPanelColourPickerHeight), "Color", toolPanelColourPicker)
|
||||||
|
|
||||||
gui.Label(raylib.NewRectangle(float32(toolPanelOffset+10), 55+toolPanelColourPickerHeight, 60, 20), "Brush Size")
|
gui.Label(raylib.NewRectangle(float32(toolPanelOffset+10), 50+toolPanelColourPickerHeight, 60, 20), "Brush Size")
|
||||||
toolPanelBrushSize = gui.Slider(raylib.NewRectangle(float32(toolPanelOffset+80), 55+toolPanelColourPickerHeight, float32(toolPanelWidth-90), 20), "", "", toolPanelBrushSize, 1, 100)
|
gui.Label(raylib.NewRectangle(float32(toolPanelOffset+10), 60+toolPanelColourPickerHeight, 60, 20), fmt.Sprintf("%d", int(toolPanelBrushSize)))
|
||||||
|
toolPanelBrushSize = gui.Slider(raylib.NewRectangle(float32(toolPanelOffset+80), 55+toolPanelColourPickerHeight, float32(toolPanelWidth-90), 20), "", "", toolPanelBrushSize, 1, 150)
|
||||||
|
|
||||||
gui.Label(raylib.NewRectangle(float32(toolPanelOffset+10), 115+toolPanelColourPickerHeight, 60, 20), "File Name")
|
gui.Label(raylib.NewRectangle(float32(toolPanelOffset+10), 115+toolPanelColourPickerHeight, 60, 20), "File Name")
|
||||||
if gui.TextBox(raylib.NewRectangle(float32(toolPanelOffset+80), 115+toolPanelColourPickerHeight, float32(toolPanelWidth-90), 20), &canvas.Name, 40, isEditingCanvasName) {
|
if gui.TextBox(raylib.NewRectangle(float32(toolPanelOffset+80), 115+toolPanelColourPickerHeight, float32(toolPanelWidth-90), 20), &canvas.Name, 40, isEditingCanvasName) {
|
||||||
isEditingCanvasName = !isEditingCanvasName
|
isEditingCanvasName = !isEditingCanvasName
|
||||||
}
|
}
|
||||||
raylib.DrawLine(toolPanelOffset, 0, toolPanelOffset, applicationWindowHeight, raylib.Black)
|
raylib.DrawLine(toolPanelOffset+1, 0, toolPanelOffset+1, applicationWindowHeight, raylib.Black)
|
||||||
}
|
}
|
||||||
raylib.EndScissorMode()
|
raylib.EndScissorMode()
|
||||||
}
|
}
|
||||||
|
@ -262,7 +265,7 @@ func main() {
|
||||||
case StateFileMenu:
|
case StateFileMenu:
|
||||||
gui.Unlock()
|
gui.Unlock()
|
||||||
raylib.DrawRectangle(0, 0, applicationWindowWidth, applicationWindowHeight, raylib.Fade(raylib.Black, 0.5))
|
raylib.DrawRectangle(0, 0, applicationWindowWidth, applicationWindowHeight, raylib.Fade(raylib.Black, 0.5))
|
||||||
windowPos := raylib.NewRectangle(float32((applicationWindowWidth/2)-200), float32((applicationWindowHeight/2)-200), 400, 400)
|
windowPos := raylib.NewRectangle(float32((applicationWindowWidth/2)-200), float32((applicationWindowHeight/2)-225), 450, 400)
|
||||||
if gui.WindowBox(windowPos, "Open or New File") {
|
if gui.WindowBox(windowPos, "Open or New File") {
|
||||||
applicationState = StateNormal
|
applicationState = StateNormal
|
||||||
}
|
}
|
||||||
|
@ -316,6 +319,12 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(filepath.Join(dirUserData, newCanvasName+".png")); !errors.Is(err, os.ErrNotExist) {
|
||||||
|
warnText := fmt.Sprintf("%s already exists", newCanvasName+".png")
|
||||||
|
raylib.DrawRectangle(int32(windowPos.X+21), int32(windowPos.Y+204), raylib.MeasureText(warnText, 10)+20, 20, raylib.Fade(raylib.Red, 0.2))
|
||||||
|
raylib.DrawText(warnText, int32(windowPos.X+31), int32(windowPos.Y+204+5), 10, raylib.Red)
|
||||||
|
}
|
||||||
|
|
||||||
if gui.Button(raylib.NewRectangle(windowPos.X+windowPos.Width-140, windowPos.Y+204, 120, 20), "Create") {
|
if gui.Button(raylib.NewRectangle(windowPos.X+windowPos.Width-140, windowPos.Y+204, 120, 20), "Create") {
|
||||||
applicationState = StateNewCanvas
|
applicationState = StateNewCanvas
|
||||||
}
|
}
|
||||||
|
@ -425,6 +434,10 @@ func main() {
|
||||||
)
|
)
|
||||||
case toolPen:
|
case toolPen:
|
||||||
raylib.DrawCircleLines(int32(raylib.GetMousePosition().X), int32(raylib.GetMousePosition().Y), toolPanelBrushSize/2, raylib.Black)
|
raylib.DrawCircleLines(int32(raylib.GetMousePosition().X), int32(raylib.GetMousePosition().Y), toolPanelBrushSize/2, raylib.Black)
|
||||||
|
if toolPanelBrushSize > 20 {
|
||||||
|
raylib.DrawCircle(int32(raylib.GetMousePosition().X), int32(raylib.GetMousePosition().Y), 1, raylib.White)
|
||||||
|
raylib.DrawCircleLines(int32(raylib.GetMousePosition().X), int32(raylib.GetMousePosition().Y), 2, raylib.Black)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue