ColouringApp/main.go

439 lines
17 KiB
Go
Raw Normal View History

2024-01-08 13:29:40 +00:00
package main
import (
2024-01-25 15:57:10 +00:00
"fmt"
2024-01-26 14:41:09 +00:00
"os"
2024-01-29 12:27:28 +00:00
"path/filepath"
2024-01-26 14:41:09 +00:00
"strconv"
2024-01-29 10:39:59 +00:00
"strings"
gui "github.com/gen2brain/raylib-go/raygui"
raylib "github.com/gen2brain/raylib-go/raylib"
2024-01-08 13:29:40 +00:00
)
2024-01-29 11:14:24 +00:00
func main() {
2024-01-29 12:27:28 +00:00
// Initialize raylib
2024-02-09 17:03:32 +00:00
raylib.SetConfigFlags(raylib.FlagWindowResizable | raylib.FlagMsaa4xHint) // raylib.FlagWindowHighdpi
2024-01-29 11:14:24 +00:00
raylib.InitWindow(applicationWindowWidth, applicationWindowHeight, applicationTitle)
2024-01-29 12:27:28 +00:00
raylib.SetWindowMinSize(int(applicationMinWindowWidth), int(applicationMinWindowHeight)) // Set a minimum window size
raylib.SetTargetFPS(int32(raylib.GetMonitorRefreshRate(raylib.GetCurrentMonitor()))) // Match monitor refresh rate
raylib.SetExitKey(raylib.KeyNull) // disable exit key
2024-02-09 14:16:18 +00:00
raylib.HideCursor() // Hide cursor
2024-01-26 14:41:09 +00:00
// Make sure both assets and userData directories exist
if _, err := os.Stat(dirAssets); os.IsNotExist(err) {
2024-01-29 11:14:24 +00:00
panic("Assets directory not found")
}
if _, err := os.Stat(dirUserData); os.IsNotExist(err) {
if err := os.Mkdir(dirUserData, 0755); err != nil {
2024-01-29 11:14:24 +00:00
panic("Could not create userData directory")
}
}
2024-01-26 00:55:21 +00:00
// Load all user data projects
2024-01-28 21:29:00 +00:00
var userDataProjects []string
if files, err := os.ReadDir(dirUserData); err == nil {
2024-01-28 21:29:00 +00:00
for _, file := range files {
if strings.HasSuffix(file.Name(), ".png") {
2024-01-28 21:29:00 +00:00
userDataProjects = append(userDataProjects, file.Name())
}
}
}
// LOOP
2024-01-29 11:14:24 +00:00
for !applicationShouldQuit {
// Update default loop values
2024-01-29 12:27:28 +00:00
if raylib.WindowShouldClose() {
2024-01-29 12:53:12 +00:00
applicationState = StateWindowWantsToDie
2024-01-29 12:27:28 +00:00
}
2024-02-09 17:03:32 +00:00
applicationWindowWidth = int32(raylib.GetScreenWidth())
applicationWindowHeight = int32(raylib.GetScreenHeight())
toolBarOffset = applicationWindowWidth - toolBarWidth
toolPanelOffset = applicationWindowWidth - toolPanelWidth - toolBarWidth
2024-01-25 15:57:10 +00:00
// Create new canvas if needed
2024-01-29 11:14:24 +00:00
if shouldCreateNewCanvas {
2024-01-29 10:39:59 +00:00
var canvasBackground raylib.Texture2D
2024-01-29 11:14:24 +00:00
if newCanvasImagePath != "" {
canvasBackground = NewBackgroundImage(newCanvasImagePath)
newCanvasWidth = int(canvasBackground.Width)
newCanvasHeight = int(canvasBackground.Height)
2024-01-29 10:39:59 +00:00
} else {
canvasBackground = NewBackgroundColour(raylib.NewVector2(float32(newCanvasWidth), float32(newCanvasHeight)), newCanvasColor)
2024-01-29 10:39:59 +00:00
}
2024-01-29 11:14:24 +00:00
canvas = NewCanvas(newCanvasName, raylib.NewVector2(float32(newCanvasWidth), float32(newCanvasHeight)), raylib.NewVector2(15, 15), canvasBackground)
2024-01-29 10:39:59 +00:00
// Reset all values
2024-01-29 11:14:24 +00:00
shouldCreateNewCanvas = false
newCanvasName = defaultProjectName
newCanvasWidth = defaultProjectWidth
newCanvasHeight = defaultProjectHeight
newCanvasColor = raylib.White
newCanvasImagePath = ""
2024-01-26 14:41:09 +00:00
}
2024-01-25 15:57:10 +00:00
// INPUT
{
2024-02-09 14:16:18 +00:00
if applicationState == StateNormal {
if raylib.IsKeyPressed(raylib.KeyF1) {
2024-02-09 17:03:32 +00:00
newStrokeType = toolPointer
2024-02-09 14:16:18 +00:00
addToast("Tool: None")
}
if raylib.IsKeyPressed(raylib.KeyF2) {
newStrokeType = toolPen
addToast("Tool: Pen")
}
}
2024-01-26 11:29:29 +00:00
if raylib.IsKeyPressed(raylib.KeyF7) {
2024-02-09 14:16:18 +00:00
addToast("This is a test toast")
2024-01-26 11:29:29 +00:00
}
2024-01-26 00:55:21 +00:00
if raylib.IsKeyPressed(raylib.KeyF8) {
2024-01-29 11:14:24 +00:00
applicationShowDebugValues = !applicationShowDebugValues
2024-01-26 00:55:21 +00:00
}
2024-01-29 10:39:59 +00:00
if raylib.IsKeyPressed(raylib.KeyF12) {
2024-02-09 14:16:18 +00:00
addToast("Screenshot saved!")
2024-01-29 10:39:59 +00:00
}
2024-01-26 00:55:21 +00:00
2024-02-09 14:16:18 +00:00
switch newStrokeType {
case toolPen:
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) && applicationState == StateNormal {
2024-02-09 17:03:32 +00:00
if (!raylib.CheckCollisionPointRec(raylib.GetMousePosition(), raylib.NewRectangle(float32(toolPanelOffset), 0, float32(toolPanelWidth+toolBarWidth), float32(applicationWindowHeight))) || !toolBarShowPanel) &&
2024-02-09 14:16:18 +00:00
raylib.CheckCollisionPointRec(raylib.GetMousePosition(), raylib.NewRectangle(10, 10, canvas.Size.X, canvas.Size.Y)) {
applicationState = StateDrawing
newPenStroke = penTool{
Size: toolPanelBrushSize,
Color: toolPanelColourPicker,
}
2024-01-25 15:57:10 +00:00
}
}
2024-02-09 14:16:18 +00:00
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) && applicationState == StateDrawing {
if len(newPenStroke.Points) <= 1 {
newPenStroke.Points = append(newPenStroke.Points, raylib.GetMousePosition())
} else if raylib.Vector2Distance(newPenStroke.Points[len(newPenStroke.Points)-1], raylib.GetMousePosition()) > float32(newStrokeSafeZone) {
newPenStroke.Points = append(newPenStroke.Points, raylib.GetMousePosition())
}
}
2024-02-09 14:16:18 +00:00
if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) && newPenStroke.Points != nil {
canvas.AddStroke(newPenStroke.Render())
newPenStroke = penTool{}
applicationState = StateNormal
}
2024-02-09 17:03:32 +00:00
case toolPointer:
2024-02-09 14:16:18 +00:00
fallthrough
default:
// yyeeeeet
2024-01-25 15:57:10 +00:00
}
if raylib.IsKeyDown(raylib.KeyLeftControl) && raylib.IsKeyDown(raylib.KeyLeftShift) && raylib.IsKeyPressed(raylib.KeyZ) {
2024-01-25 20:02:20 +00:00
canvas.Redo()
2024-01-25 15:57:10 +00:00
} else if raylib.IsKeyDown(raylib.KeyLeftControl) && raylib.IsKeyPressed(raylib.KeyZ) {
2024-01-25 20:02:20 +00:00
canvas.Undo()
2024-01-25 15:57:10 +00:00
} else if raylib.IsKeyDown(raylib.KeyLeftControl) && raylib.IsKeyPressed(raylib.KeyS) {
2024-02-09 17:03:32 +00:00
canvas.Save(false)
2024-01-25 15:57:10 +00:00
}
}
// UPDATE
{
2024-02-09 14:16:18 +00:00
applicationRuntime += 1
2024-01-29 11:14:24 +00:00
if applicationState != StateNormal {
2024-01-29 10:39:59 +00:00
gui.Lock()
2024-01-25 15:57:10 +00:00
} else {
2024-01-29 10:39:59 +00:00
gui.Unlock()
2024-01-25 15:57:10 +00:00
}
2024-02-09 14:16:18 +00:00
canvas.Update()
updateToasts()
2024-01-25 15:57:10 +00:00
}
// DRAW
raylib.BeginDrawing()
{
raylib.ClearBackground(raylib.White)
2024-01-29 11:14:24 +00:00
gui.Grid(raylib.NewRectangle(0, 0, float32(applicationWindowWidth), float32(applicationWindowHeight)), "", 30, 1, &raylib.Vector2{})
2024-01-25 15:57:10 +00:00
// Canvas
2024-01-25 15:57:10 +00:00
{
2024-01-25 20:02:20 +00:00
raylib.DrawRectangle(int32(canvas.Offset.X)+10, int32(canvas.Offset.Y)+10, int32(canvas.Size.X), int32(canvas.Size.Y), raylib.Fade(raylib.Black, 0.3))
canvas.Draw()
2024-01-25 15:57:10 +00:00
2024-01-25 20:02:20 +00:00
raylib.BeginScissorMode(int32(canvas.Offset.X), int32(canvas.Offset.Y), int32(canvas.Size.X), int32(canvas.Size.Y))
2024-01-29 11:14:24 +00:00
newPenStroke.Draw()
2024-01-25 20:02:20 +00:00
raylib.EndScissorMode()
2024-01-25 15:57:10 +00:00
raylib.DrawRectangleLines(int32(canvas.Offset.X), int32(canvas.Offset.Y), int32(canvas.Size.X), int32(canvas.Size.Y), raylib.DarkGray)
2024-01-25 15:57:10 +00:00
}
// Tool Panel
2024-02-09 17:03:32 +00:00
raylib.BeginScissorMode(toolBarOffset, 0, toolBarWidth, applicationWindowHeight)
2024-01-25 15:57:10 +00:00
{
2024-02-09 17:03:32 +00:00
raylib.DrawRectangle(toolBarOffset, 0, toolBarWidth, applicationWindowHeight, raylib.Fade(raylib.White, 0.9))
// Top
if gui.Button(raylib.NewRectangle(float32(toolBarOffset+10), 10, 25, 25), gui.IconText(gui.ICON_BURGER_MENU, "")) {
toolBarShowPanel = !toolBarShowPanel
}
2024-01-25 15:57:10 +00:00
2024-02-09 17:03:32 +00:00
if newStrokeType == toolPointer {
gui.SetState(gui.STATE_PRESSED)
2024-01-25 15:57:10 +00:00
}
2024-02-09 17:03:32 +00:00
if gui.Button(raylib.NewRectangle(float32(toolBarOffset+10), 45, 25, 25), gui.IconText(gui.ICON_CURSOR_CLASSIC, "")) {
newStrokeType = toolPointer
addToast("Tool: Pointer")
2024-01-25 15:57:10 +00:00
}
2024-02-09 17:03:32 +00:00
gui.SetState(gui.STATE_NORMAL)
2024-01-25 15:57:10 +00:00
2024-02-09 17:03:32 +00:00
if newStrokeType == toolPen {
gui.SetState(gui.STATE_PRESSED)
}
if gui.Button(raylib.NewRectangle(float32(toolBarOffset+10), 80, 25, 25), gui.IconText(gui.ICON_PENCIL, "")) {
newStrokeType = toolPen
addToast("Tool: Pen")
2024-01-25 15:57:10 +00:00
}
2024-02-09 17:03:32 +00:00
gui.SetState(gui.STATE_NORMAL)
// Bottom
if gui.Button(raylib.NewRectangle(float32(toolBarOffset+10), float32(applicationWindowHeight-35), 25, 25), gui.IconText(gui.ICON_INFO, "")) {
applicationState = StateHelp
2024-01-25 15:57:10 +00:00
}
2024-02-09 17:03:32 +00:00
raylib.DrawLine(toolBarOffset, 0, toolBarOffset, applicationWindowHeight, raylib.Black)
}
raylib.EndScissorMode()
// Tool Panel
if toolBarShowPanel {
raylib.BeginScissorMode(toolPanelOffset, 0, toolPanelWidth, applicationWindowHeight)
{
raylib.DrawRectangle(toolPanelOffset, 0, toolPanelWidth, applicationWindowHeight, raylib.Fade(raylib.White, 0.9))
if gui.Button(raylib.NewRectangle(float32(toolPanelOffset+10), 10, 25, 25), gui.IconText(gui.ICON_FOLDER_OPEN, "")) {
applicationState = StateFileMenu
}
if gui.Button(raylib.NewRectangle(float32(toolPanelOffset+20+25), 10, 25, 25), gui.IconText(gui.ICON_FOLDER_SAVE, "")) {
canvas.Save(false)
}
if gui.Button(raylib.NewRectangle(float32(applicationWindowWidth-70-toolBarWidth), 10, 25, 25), gui.IconText(gui.ICON_UNDO, "")) {
canvas.Undo()
}
if gui.Button(raylib.NewRectangle(float32(applicationWindowWidth-35-toolBarWidth), 10, 25, 25), gui.IconText(gui.ICON_REDO, "")) {
canvas.Redo()
}
toolPanelColourPicker = gui.ColorPicker(raylib.NewRectangle(float32(toolPanelOffset+10), 45, float32(toolPanelWidth-45), toolPanelColourPickerHeight), "Color", toolPanelColourPicker)
2024-01-25 15:57:10 +00:00
2024-02-09 17:03:32 +00:00
gui.Label(raylib.NewRectangle(float32(toolPanelOffset+10), 55+toolPanelColourPickerHeight, 60, 20), "Brush Size")
toolPanelBrushSize = gui.Slider(raylib.NewRectangle(float32(toolPanelOffset+80), 55+toolPanelColourPickerHeight, float32(toolPanelWidth-90), 20), "", "", toolPanelBrushSize, 1, 100)
2024-01-25 15:57:10 +00:00
2024-02-09 17:03:32 +00:00
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) {
isEditingCanvasName = !isEditingCanvasName
}
raylib.DrawLine(toolPanelOffset, 0, toolPanelOffset, applicationWindowHeight, raylib.Black)
2024-01-25 15:57:10 +00:00
}
2024-02-09 17:03:32 +00:00
raylib.EndScissorMode()
2024-01-25 15:57:10 +00:00
}
// Debug Values
2024-01-29 11:14:24 +00:00
if applicationShowDebugValues {
2024-01-25 15:57:10 +00:00
var text string
2024-01-29 11:14:24 +00:00
text = fmt.Sprintf("Strokes: %d | Points: %d", len(canvas.Strokes), len(newPenStroke.Points))
gui.StatusBar(raylib.NewRectangle(0, float32(applicationWindowHeight-20), 150, 20), text)
2024-01-25 15:57:10 +00:00
2024-01-25 20:02:20 +00:00
text = fmt.Sprintf("Canvas Size: %dx%d", int32(canvas.Size.X), int32(canvas.Size.Y))
2024-01-29 11:14:24 +00:00
gui.StatusBar(raylib.NewRectangle(150, float32(applicationWindowHeight-20), 150, 20), text)
2024-01-26 00:55:21 +00:00
text = fmt.Sprintf("FPS: %d | DT: %f", raylib.GetFPS(), raylib.GetFrameTime())
2024-01-29 11:14:24 +00:00
gui.StatusBar(raylib.NewRectangle(300, float32(applicationWindowHeight-20), 170, 20), text)
2024-01-25 15:57:10 +00:00
}
// Menus
2024-01-29 11:14:24 +00:00
switch applicationState {
2024-01-25 15:57:10 +00:00
case StateFileMenu:
2024-01-29 10:39:59 +00:00
gui.Unlock()
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)
2024-01-26 11:29:29 +00:00
if gui.WindowBox(windowPos, "Open or New File") {
2024-01-29 11:14:24 +00:00
applicationState = StateNormal
2024-01-26 11:29:29 +00:00
}
// Magic numbers
raylib.BeginScissorMode(int32(windowPos.X)+1, int32(windowPos.Y)+24, int32(windowPos.Width)-2, int32(windowPos.Height)-25)
2024-01-26 18:12:48 +00:00
gui.GroupBox(raylib.NewRectangle(windowPos.X+11, windowPos.Y+34, windowPos.Width-22, 200), "Create New")
2024-01-26 14:41:09 +00:00
{
2024-01-26 18:12:48 +00:00
var err error
2024-01-26 11:29:29 +00:00
2024-01-26 18:12:48 +00:00
gui.Label(raylib.NewRectangle(windowPos.X+21, windowPos.Y+44, 100, 20), "File Name")
2024-01-29 11:14:24 +00:00
if gui.TextBox(raylib.NewRectangle(windowPos.X+131, windowPos.Y+44, windowPos.Width-152, 20), &newCanvasName, 40, isEditingNewCanvasName) {
isEditingNewCanvasName = !isEditingNewCanvasName
2024-01-26 18:12:48 +00:00
}
2024-01-26 11:29:29 +00:00
2024-01-26 18:12:48 +00:00
gui.Label(raylib.NewRectangle(windowPos.X+21, windowPos.Y+74, 100, 20), "Canvas Width")
width := fmt.Sprintf("%d", newCanvasWidth)
2024-01-29 12:27:28 +00:00
lastWidth := newCanvasWidth
2024-01-29 11:14:24 +00:00
if gui.TextBox(raylib.NewRectangle(windowPos.X+131, windowPos.Y+74, windowPos.Width-152, 20), &width, 6, isEditingNewCanvasWidth) {
isEditingNewCanvasWidth = !isEditingNewCanvasWidth
2024-01-26 18:12:48 +00:00
}
if newCanvasWidth, err = strconv.Atoi(width); err != nil {
newCanvasWidth = lastWidth
2024-01-26 14:41:09 +00:00
}
2024-01-26 18:12:48 +00:00
gui.Label(raylib.NewRectangle(windowPos.X+21, windowPos.Y+104, 100, 20), "Canvas Height")
height := fmt.Sprintf("%d", newCanvasHeight)
2024-01-29 12:27:28 +00:00
lastHeight := newCanvasHeight
2024-01-29 11:14:24 +00:00
if gui.TextBox(raylib.NewRectangle(windowPos.X+131, windowPos.Y+104, windowPos.Width-152, 20), &height, 6, isEditingNewCanvasHeight) {
isEditingNewCanvasHeight = !isEditingNewCanvasHeight
2024-01-26 18:12:48 +00:00
}
if newCanvasHeight, err = strconv.Atoi(height); err != nil {
newCanvasHeight = lastHeight
2024-01-26 14:41:09 +00:00
}
2024-01-26 18:12:48 +00:00
colors := []raylib.Color{raylib.Red, raylib.Orange, raylib.Yellow, raylib.Green, raylib.Blue, raylib.Purple, raylib.Pink, raylib.Brown, raylib.Black, raylib.White}
for i := 0; i < len(colors); i++ {
posX := windowPos.X + 21 + ((float32(i) * 26) + float32(i)*11)
posY := windowPos.Y + 149
2024-01-26 14:41:09 +00:00
2024-01-26 18:12:48 +00:00
if gui.Button(raylib.NewRectangle(posX, posY, 26, 26), "") {
2024-01-29 11:14:24 +00:00
newCanvasColor = colors[i]
2024-01-26 14:41:09 +00:00
}
2024-01-29 11:14:24 +00:00
if newCanvasColor == colors[i] {
2024-01-26 18:12:48 +00:00
raylib.DrawRectangle(int32(posX)-4, int32(posY)-4, 26+8, 26+8, raylib.Fade(raylib.Black, 0.2))
raylib.DrawRectangle(int32(posX), int32(posY), 26, 26, colors[i])
} else {
raylib.DrawRectangle(int32(posX), int32(posY), 26, 26, colors[i])
raylib.DrawRectangleLines(int32(posX), int32(posY), 26, 26, raylib.Black)
2024-01-26 14:41:09 +00:00
}
}
2024-01-26 18:12:48 +00:00
if gui.Button(raylib.NewRectangle(windowPos.X+windowPos.Width-140, windowPos.Y+204, 120, 20), "Create") {
2024-01-29 11:14:24 +00:00
applicationState = StateNewCanvas
2024-01-26 14:41:09 +00:00
}
}
2024-01-28 21:29:00 +00:00
gui.GroupBox(raylib.NewRectangle(windowPos.X+11, windowPos.Y+244, windowPos.Width-22, float32(len(userDataProjects)*20)+10), "Open Existing")
2024-01-26 18:12:48 +00:00
{
if gui.Button(raylib.NewRectangle(windowPos.X+21, windowPos.Y+254, windowPos.Width-42, 20), "Maned Wolf") {
2024-01-29 12:27:28 +00:00
newCanvasImagePath = filepath.Join(dirAssets, "manedWolf.jpg")
2024-01-29 11:14:24 +00:00
newCanvasName = "ManedWolf"
applicationState = StateNewCanvas
2024-01-26 18:12:48 +00:00
}
2024-01-28 21:29:00 +00:00
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]) {
2024-01-29 12:27:28 +00:00
newCanvasImagePath = filepath.Join(dirAssets, userDataProjects[i])
2024-01-29 10:39:59 +00:00
splitName := strings.Split(userDataProjects[i], ".")
2024-01-29 12:27:28 +00:00
newCanvasName = filepath.Base(splitName[0])
2024-01-29 11:14:24 +00:00
applicationState = StateNewCanvas
2024-01-28 21:29:00 +00:00
}
}
2024-01-26 18:12:48 +00:00
}
2024-01-26 11:29:29 +00:00
raylib.EndScissorMode()
2024-01-29 10:39:59 +00:00
case StateNewCanvas:
2024-01-29 12:27:28 +00:00
if !canvas.UnsavedChanges {
applicationState = StateNormal
shouldCreateNewCanvas = true
2024-02-09 14:16:18 +00:00
addToast("Created New Canvas: " + canvas.Name)
2024-01-29 12:27:28 +00:00
break
}
2024-01-29 10:39:59 +00:00
gui.Unlock()
raylib.DrawRectangle(0, 0, applicationWindowWidth, applicationWindowHeight, raylib.Fade(raylib.Black, 0.5))
windowPos := raylib.NewRectangle(float32((applicationWindowWidth/2)-200), float32((applicationWindowHeight/2)-75), 400, 150)
2024-01-29 10:39:59 +00:00
choice := gui.MessageBox(windowPos, "New Canvas", "Are you sure you want to create a new canvas?", "No;Yes")
if choice == 0 || choice == 1 {
2024-01-29 11:14:24 +00:00
applicationState = StateNormal
shouldCreateNewCanvas = false
2024-01-29 10:39:59 +00:00
} else if choice == 2 {
2024-01-29 11:14:24 +00:00
applicationState = StateNormal
shouldCreateNewCanvas = true
2024-02-09 14:16:18 +00:00
addToast("Created New Canvas: " + canvas.Name)
2024-01-29 10:39:59 +00:00
}
2024-02-09 17:03:32 +00:00
case StateHelp:
gui.Unlock()
raylib.DrawRectangle(0, 0, applicationWindowWidth, applicationWindowHeight, raylib.Fade(raylib.Black, 0.5))
windowPos := raylib.NewRectangle(float32((applicationWindowWidth/2)-200), float32((applicationWindowHeight/2)-75), 400, 150)
choice := gui.MessageBox(windowPos, "Help", fmt.Sprintf("ColouringApp %s", Version), "Close")
if choice == 0 || choice == 1 {
applicationState = StateNormal
}
case StateFileExists:
gui.Unlock()
raylib.DrawRectangle(0, 0, applicationWindowWidth, applicationWindowHeight, raylib.Fade(raylib.Black, 0.5))
windowPos := raylib.NewRectangle(float32((applicationWindowWidth/2)-200), float32((applicationWindowHeight/2)-75), 400, 150)
choice := gui.MessageBox(windowPos, "File Exists", "File already exists, are you sure you want to save?", "No;Yes")
if choice == 0 || choice == 1 {
applicationState = StateNormal
} else if choice == 2 {
canvas.Save(true)
applicationState = StateNormal
}
2024-01-29 12:27:28 +00:00
case StateWindowWantsToDie:
2024-01-29 12:53:12 +00:00
if !canvas.UnsavedChanges {
applicationShouldQuit = true
break
}
if !canvas.UnsavedChanges {
applicationState = StateNormal
shouldCreateNewCanvas = true
2024-02-09 14:16:18 +00:00
addToast("Created New Canvas: " + canvas.Name)
2024-01-29 12:53:12 +00:00
break
}
2024-01-29 12:27:28 +00:00
gui.Unlock()
raylib.DrawRectangle(0, 0, applicationWindowWidth, applicationWindowHeight, raylib.Fade(raylib.Black, 0.5))
windowPos := raylib.NewRectangle(float32((applicationWindowWidth/2)-200), float32((applicationWindowHeight/2)-75), 400, 150)
choice := gui.MessageBox(windowPos, "Unsaved Changes", "You have unsaved changes, are you sure you want to exit?", "No;Yes")
if choice == 0 || choice == 1 {
applicationState = StateNormal
} else if choice == 2 {
applicationShouldQuit = true
}
default:
2024-01-25 15:57:10 +00:00
}
2024-02-09 14:16:18 +00:00
// Cursor
2024-02-09 17:03:32 +00:00
if raylib.IsCursorOnScreen() {
switch newStrokeType {
case toolPointer:
// Points have to be provided in counter-clockwise order for some reason ??!?!??!?!?
raylib.DrawTriangle(
raylib.NewVector2(raylib.GetMousePosition().X+2, raylib.GetMousePosition().Y+14),
raylib.NewVector2(raylib.GetMousePosition().X+10, raylib.GetMousePosition().Y+10),
raylib.NewVector2(raylib.GetMousePosition().X, raylib.GetMousePosition().Y),
raylib.White,
)
// Here they don't!
raylib.DrawTriangleLines(
raylib.NewVector2(raylib.GetMousePosition().X, raylib.GetMousePosition().Y),
raylib.NewVector2(raylib.GetMousePosition().X+10, raylib.GetMousePosition().Y+10),
raylib.NewVector2(raylib.GetMousePosition().X+2, raylib.GetMousePosition().Y+14),
raylib.Black,
)
case toolPen:
raylib.DrawCircleLines(int32(raylib.GetMousePosition().X), int32(raylib.GetMousePosition().Y), toolPanelBrushSize/2, raylib.Black)
}
2024-02-09 14:16:18 +00:00
}
drawToasts()
2024-01-08 13:29:40 +00:00
}
2024-01-25 15:57:10 +00:00
raylib.EndDrawing()
2024-01-08 13:29:40 +00:00
}
// GOODBYE
raylib.CloseWindow()
2024-01-08 13:29:40 +00:00
}