mirror of
https://github.com/Fluffy-Bean/ColouringApp.git
synced 2025-05-14 07:32:16 +00:00
Load confirmation
This commit is contained in:
parent
9ed1e192d7
commit
70ec91d5f2
2 changed files with 64 additions and 34 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -12,3 +12,7 @@ userData
|
||||||
ColouringApp
|
ColouringApp
|
||||||
ColouringApp.exe
|
ColouringApp.exe
|
||||||
ColouringApp.zip
|
ColouringApp.zip
|
||||||
|
|
||||||
|
# Screenshots
|
||||||
|
# saved as screenshot0000.png, screenshot0001.png, etc.
|
||||||
|
screenshot*.png
|
||||||
|
|
94
main.go
94
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
gui "github.com/gen2brain/raylib-go/raygui"
|
gui "github.com/gen2brain/raylib-go/raygui"
|
||||||
raylib "github.com/gen2brain/raylib-go/raylib"
|
raylib "github.com/gen2brain/raylib-go/raylib"
|
||||||
|
@ -29,6 +30,7 @@ const (
|
||||||
StateNormal = iota
|
StateNormal = iota
|
||||||
StateDrawing
|
StateDrawing
|
||||||
StateFileMenu
|
StateFileMenu
|
||||||
|
StateNewCanvas
|
||||||
)
|
)
|
||||||
|
|
||||||
var canvas *Canvas
|
var canvas *Canvas
|
||||||
|
@ -48,13 +50,13 @@ 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.FlagWindowHighdpi)
|
raylib.SetConfigFlags(raylib.FlagWindowHighdpi)
|
||||||
// raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||||
|
|
||||||
raylib.InitWindow(WindowWidth, WindowHeight, WindowTitle)
|
raylib.InitWindow(WindowWidth, WindowHeight, WindowTitle)
|
||||||
raylib.SetWindowMinSize(int(WindowMinWidth), int(WindowMinHeight))
|
raylib.SetWindowMinSize(int(WindowMinWidth), int(WindowMinHeight))
|
||||||
raylib.SetTargetFPS(int32(raylib.GetMonitorRefreshRate(raylib.GetCurrentMonitor())))
|
raylib.SetTargetFPS(int32(raylib.GetMonitorRefreshRate(raylib.GetCurrentMonitor())))
|
||||||
// raylib.SetExitKey(0) // disable exit key
|
raylib.SetExitKey(0) // disable exit key
|
||||||
|
|
||||||
// Augh
|
// Augh
|
||||||
var (
|
var (
|
||||||
|
@ -93,6 +95,7 @@ func main() {
|
||||||
newCanvasHeightEditing = false
|
newCanvasHeightEditing = false
|
||||||
|
|
||||||
newCanvasBackgroundColor = raylib.White
|
newCanvasBackgroundColor = raylib.White
|
||||||
|
newCanvasBackgroundImage = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
var userDataProjects []string
|
var userDataProjects []string
|
||||||
|
@ -126,9 +129,30 @@ func main() {
|
||||||
|
|
||||||
// CREATE CANVAS
|
// CREATE CANVAS
|
||||||
if createNewCanvas {
|
if createNewCanvas {
|
||||||
canvasBackground := NewBackground(raylib.NewVector2(float32(newCanvasWidth), float32(newCanvasHeight)), newCanvasBackgroundColor)
|
var canvasBackground raylib.Texture2D
|
||||||
canvas = NewCanvas("NewProject", raylib.NewVector2(float32(newCanvasWidth), float32(newCanvasHeight)), raylib.NewVector2(15, 15), canvasBackground)
|
if newCanvasBackgroundImage != "" {
|
||||||
|
loadedImage := raylib.LoadImage(newCanvasBackgroundImage)
|
||||||
|
{
|
||||||
|
raylib.ImageFlipHorizontal(loadedImage)
|
||||||
|
raylib.ImageRotate(loadedImage, 180)
|
||||||
|
}
|
||||||
|
|
||||||
|
canvasBackground = raylib.LoadTextureFromImage(loadedImage)
|
||||||
|
|
||||||
|
newCanvasWidth = int(loadedImage.Width)
|
||||||
|
newCanvasHeight = int(loadedImage.Height)
|
||||||
|
} else {
|
||||||
|
canvasBackground = NewBackground(raylib.NewVector2(float32(newCanvasWidth), float32(newCanvasHeight)), newCanvasBackgroundColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas = NewCanvas(newProjectName, raylib.NewVector2(float32(newCanvasWidth), float32(newCanvasHeight)), raylib.NewVector2(15, 15), canvasBackground)
|
||||||
|
|
||||||
createNewCanvas = false
|
createNewCanvas = false
|
||||||
|
newProjectName = "NewProject"
|
||||||
|
newCanvasWidth = 700
|
||||||
|
newCanvasHeight = 530
|
||||||
|
newCanvasBackgroundColor = raylib.White
|
||||||
|
newCanvasBackgroundImage = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// INPUT
|
// INPUT
|
||||||
|
@ -139,6 +163,9 @@ func main() {
|
||||||
if raylib.IsKeyPressed(raylib.KeyF8) {
|
if raylib.IsKeyPressed(raylib.KeyF8) {
|
||||||
showDebugStats = !showDebugStats
|
showDebugStats = !showDebugStats
|
||||||
}
|
}
|
||||||
|
if raylib.IsKeyPressed(raylib.KeyF12) {
|
||||||
|
AddToast("Screenshot saved!")
|
||||||
|
}
|
||||||
|
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) && state == StateNormal {
|
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) && state == StateNormal {
|
||||||
if !raylib.CheckCollisionPointRec(raylib.GetMousePosition(), raylib.NewRectangle(float32(WindowWidth-int32(sidePanelWidth)), 0, sidePanelWidth, float32(WindowHeight))) &&
|
if !raylib.CheckCollisionPointRec(raylib.GetMousePosition(), raylib.NewRectangle(float32(WindowWidth-int32(sidePanelWidth)), 0, sidePanelWidth, float32(WindowHeight))) &&
|
||||||
|
@ -183,9 +210,9 @@ func main() {
|
||||||
UpdateToasts()
|
UpdateToasts()
|
||||||
canvas.Update()
|
canvas.Update()
|
||||||
if state != StateNormal {
|
if state != StateNormal {
|
||||||
gui.SetState(gui.STATE_DISABLED)
|
gui.Lock()
|
||||||
} else {
|
} else {
|
||||||
gui.SetState(gui.STATE_NORMAL)
|
gui.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.CheckCollisionPointRec(raylib.GetMousePosition(), raylib.NewRectangle(float32(WindowWidth-int32(sidePanelWidth)), 0, sidePanelWidth, float32(WindowHeight))) {
|
if raylib.CheckCollisionPointRec(raylib.GetMousePosition(), raylib.NewRectangle(float32(WindowWidth-int32(sidePanelWidth)), 0, sidePanelWidth, float32(WindowHeight))) {
|
||||||
|
@ -268,10 +295,11 @@ func main() {
|
||||||
|
|
||||||
switch state {
|
switch state {
|
||||||
case StateFileMenu:
|
case StateFileMenu:
|
||||||
gui.SetState(gui.STATE_NORMAL)
|
windowPos := raylib.NewRectangle(float32((WindowWidth/2)-200), float32((WindowHeight/2)-200), 400, 400)
|
||||||
|
|
||||||
raylib.DrawRectangle(0, 0, WindowWidth, WindowHeight, raylib.Fade(raylib.Black, 0.5))
|
raylib.DrawRectangle(0, 0, WindowWidth, WindowHeight, raylib.Fade(raylib.Black, 0.5))
|
||||||
|
|
||||||
windowPos := raylib.NewRectangle(float32((WindowWidth/2)-200), float32((WindowHeight/2)-200), 400, 400)
|
gui.Unlock()
|
||||||
if gui.WindowBox(windowPos, "Open or New File") {
|
if gui.WindowBox(windowPos, "Open or New File") {
|
||||||
state = StateNormal
|
state = StateNormal
|
||||||
}
|
}
|
||||||
|
@ -327,47 +355,45 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
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") {
|
||||||
state = StateNormal
|
state = StateNewCanvas
|
||||||
createNewCanvas = true
|
|
||||||
AddToast("Created New Canvas")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.GroupBox(raylib.NewRectangle(windowPos.X+11, windowPos.Y+244, windowPos.Width-22, float32(len(userDataProjects)*20)+10), "Open Existing")
|
gui.GroupBox(raylib.NewRectangle(windowPos.X+11, windowPos.Y+244, windowPos.Width-22, float32(len(userDataProjects)*20)+10), "Open Existing")
|
||||||
{
|
{
|
||||||
if gui.Button(raylib.NewRectangle(windowPos.X+21, windowPos.Y+254, windowPos.Width-42, 20), "Maned Wolf") {
|
if gui.Button(raylib.NewRectangle(windowPos.X+21, windowPos.Y+254, windowPos.Width-42, 20), "Maned Wolf") {
|
||||||
loadedImage := raylib.LoadImage(DirAssets + "manedWolf.jpg")
|
newCanvasBackgroundImage = DirAssets + "manedWolf.jpg"
|
||||||
{
|
newProjectName = "ManedWolf"
|
||||||
raylib.ImageFlipHorizontal(loadedImage)
|
state = StateNewCanvas
|
||||||
raylib.ImageRotate(loadedImage, 180)
|
|
||||||
}
|
|
||||||
canvas = NewCanvas("NewProject", raylib.NewVector2(float32(loadedImage.Width), float32(loadedImage.Height)), raylib.NewVector2(15, 15), raylib.LoadTextureFromImage(loadedImage))
|
|
||||||
|
|
||||||
raylib.UnloadImage(loadedImage)
|
|
||||||
state = StateNormal
|
|
||||||
|
|
||||||
AddToast("Loaded Maned Wolf")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(userDataProjects); i++ {
|
for i := 0; i < len(userDataProjects); i++ {
|
||||||
if gui.Button(raylib.NewRectangle(windowPos.X+21, windowPos.Y+274+float32(i*20), windowPos.Width-42, 20), userDataProjects[i]) {
|
if gui.Button(raylib.NewRectangle(windowPos.X+21, windowPos.Y+274+float32(i*20), windowPos.Width-42, 20), userDataProjects[i]) {
|
||||||
loadedImage := raylib.LoadImage(DirUserData + userDataProjects[i])
|
newCanvasBackgroundImage = DirUserData + userDataProjects[i]
|
||||||
{
|
splitName := strings.Split(userDataProjects[i], ".")
|
||||||
raylib.ImageFlipHorizontal(loadedImage)
|
newProjectName = splitName[:len(splitName)-1][0]
|
||||||
raylib.ImageRotate(loadedImage, 180)
|
state = StateNewCanvas
|
||||||
}
|
|
||||||
canvas = NewCanvas("NewProject", raylib.NewVector2(float32(loadedImage.Width), float32(loadedImage.Height)), raylib.NewVector2(15, 15), raylib.LoadTextureFromImage(loadedImage))
|
|
||||||
|
|
||||||
raylib.UnloadImage(loadedImage)
|
|
||||||
state = StateNormal
|
|
||||||
|
|
||||||
AddToast("Loaded " + userDataProjects[i])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndScissorMode()
|
raylib.EndScissorMode()
|
||||||
|
case StateNewCanvas:
|
||||||
|
windowPos := raylib.NewRectangle(float32((WindowWidth/2)-200), float32((WindowHeight/2)-75), 400, 150)
|
||||||
|
|
||||||
|
raylib.DrawRectangle(0, 0, WindowWidth, WindowHeight, raylib.Fade(raylib.Black, 0.5))
|
||||||
|
|
||||||
|
gui.Unlock()
|
||||||
|
choice := gui.MessageBox(windowPos, "New Canvas", "Are you sure you want to create a new canvas?", "No;Yes")
|
||||||
|
|
||||||
|
if choice == 0 || choice == 1 {
|
||||||
|
state = StateNormal
|
||||||
|
createNewCanvas = false
|
||||||
|
} else if choice == 2 {
|
||||||
|
state = StateNormal
|
||||||
|
createNewCanvas = true
|
||||||
|
AddToast("Created New Canvas: " + canvas.Name)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue