mirror of
https://github.com/Fluffy-Bean/ColouringApp.git
synced 2024-12-28 01:56:07 +00:00
OMG I CAN CREATE NEW PROJECTSSSSSSS
This commit is contained in:
parent
a0fd1d41a3
commit
1dd1460199
15
canvas.go
15
canvas.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
raylib "github.com/gen2brain/raylib-go/raylib"
|
raylib "github.com/gen2brain/raylib-go/raylib"
|
||||||
|
@ -26,7 +27,7 @@ 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.DrawTexturePro(
|
raylib.DrawTexturePro(
|
||||||
c.Background,
|
c.Background,
|
||||||
raylib.NewRectangle(0, 0, c.Size.X, -c.Size.Y),
|
raylib.NewRectangle(0, 0, c.Size.X, -c.Size.Y),
|
||||||
|
@ -125,3 +126,15 @@ func NewCanvas(name string, size, offset raylib.Vector2, background raylib.Textu
|
||||||
Refresh: true,
|
Refresh: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewBackground(size raylib.Vector2, color raylib.Color) raylib.Texture2D {
|
||||||
|
texture := raylib.LoadRenderTexture(int32(size.X), int32(size.Y))
|
||||||
|
|
||||||
|
fmt.Println(size)
|
||||||
|
|
||||||
|
raylib.BeginTextureMode(texture)
|
||||||
|
raylib.DrawRectangle(0, 0, int32(size.X), int32(size.Y), color)
|
||||||
|
raylib.EndTextureMode()
|
||||||
|
|
||||||
|
return texture.Texture
|
||||||
|
}
|
||||||
|
|
103
main.go
103
main.go
|
@ -2,10 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
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"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -64,7 +64,6 @@ 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)
|
||||||
|
@ -80,14 +79,20 @@ func main() {
|
||||||
showDebugStats = false
|
showDebugStats = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// init canvas
|
var (
|
||||||
canvasBackground := raylib.LoadRenderTexture(700, 530)
|
createNewCanvas = true
|
||||||
{
|
|
||||||
raylib.BeginTextureMode(canvasBackground)
|
newProjectName = "NewProject"
|
||||||
raylib.ClearBackground(raylib.White)
|
newProjectNameEditing = false
|
||||||
raylib.EndTextureMode()
|
|
||||||
}
|
newCanvasWidth = 700
|
||||||
canvas = NewCanvas("NewProject", raylib.NewVector2(700, 530), raylib.NewVector2(15, 15), canvasBackground.Texture)
|
newCanvasWidthEditing = false
|
||||||
|
|
||||||
|
newCanvasHeight = 530
|
||||||
|
newCanvasHeightEditing = false
|
||||||
|
|
||||||
|
newCanvasBackgroundColor = raylib.White
|
||||||
|
)
|
||||||
|
|
||||||
// LOOP
|
// LOOP
|
||||||
for !appShouldQuit {
|
for !appShouldQuit {
|
||||||
|
@ -98,6 +103,13 @@ func main() {
|
||||||
sidePanelRelativeX = WindowWidth - int32(sidePanelWidth)
|
sidePanelRelativeX = WindowWidth - int32(sidePanelWidth)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CREATE CANVAS
|
||||||
|
if createNewCanvas {
|
||||||
|
canvasBackground := NewBackground(raylib.NewVector2(float32(newCanvasWidth), float32(newCanvasHeight)), newCanvasBackgroundColor)
|
||||||
|
canvas = NewCanvas("NewProject", raylib.NewVector2(float32(newCanvasWidth), float32(newCanvasHeight)), raylib.NewVector2(15, 15), canvasBackground)
|
||||||
|
createNewCanvas = false
|
||||||
|
}
|
||||||
|
|
||||||
// INPUT
|
// INPUT
|
||||||
{
|
{
|
||||||
if raylib.IsKeyPressed(raylib.KeyF7) {
|
if raylib.IsKeyPressed(raylib.KeyF7) {
|
||||||
|
@ -160,12 +172,6 @@ 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
|
||||||
|
@ -244,27 +250,68 @@ func main() {
|
||||||
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))
|
||||||
|
|
||||||
windowPos := raylib.NewRectangle(float32((WindowWidth/2)-200), float32((WindowHeight/2)-100), 400, 200)
|
windowPos := raylib.NewRectangle(float32((WindowWidth/2)-200), float32((WindowHeight/2)-200), 400, 400)
|
||||||
if gui.WindowBox(windowPos, "Open or New File") {
|
if gui.WindowBox(windowPos, "Open or New File") {
|
||||||
state = StateNormal
|
state = StateNormal
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magic numbers
|
// Magic numbers
|
||||||
raylib.BeginScissorMode(int32(windowPos.X)+1, int32(windowPos.Y)+24, int32(windowPos.Width)-2, int32(windowPos.Height)-25)
|
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
|
gui.GroupBox(raylib.NewRectangle(windowPos.X+11, windowPos.Y+34, windowPos.Width-22, 40), "Open Existing")
|
||||||
canvas = NewCanvas("NewProject", raylib.NewVector2(float32(loadedImage.Width), float32(loadedImage.Height)), raylib.NewVector2(15, 15), raylib.LoadTextureFromImage(loadedImage))
|
{
|
||||||
|
if gui.Button(raylib.NewRectangle(windowPos.X+21, windowPos.Y+44, 120, 20), "Maned Wolf") {
|
||||||
|
loadedImage := raylib.LoadImage(DirAssets + "manedWolf.jpg")
|
||||||
|
{
|
||||||
|
raylib.ImageFlipHorizontal(loadedImage)
|
||||||
|
raylib.ImageRotate(loadedImage, 180)
|
||||||
|
}
|
||||||
|
canvas = NewCanvas("NewProject", raylib.NewVector2(float32(loadedImage.Width), float32(loadedImage.Height)), raylib.NewVector2(15, 15), raylib.LoadTextureFromImage(loadedImage))
|
||||||
|
|
||||||
// SAVE MEMORY
|
raylib.UnloadImage(loadedImage)
|
||||||
raylib.UnloadImage(loadedImage)
|
state = StateNormal
|
||||||
|
|
||||||
// Aurghhhhh
|
AddToast("Loaded Maned Wolf")
|
||||||
state = StateNormal
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gui.GroupBox(raylib.NewRectangle(windowPos.X+11, windowPos.Y+84, windowPos.Width-22, 200), "Create New")
|
||||||
|
{
|
||||||
|
gui.Label(raylib.NewRectangle(windowPos.X+21, windowPos.Y+94, 100, 20), "File Name")
|
||||||
|
if gui.TextBox(raylib.NewRectangle(windowPos.X+131, windowPos.Y+94, windowPos.Width-152, 20), &newProjectName, 40, newProjectNameEditing) {
|
||||||
|
newProjectNameEditing = !newProjectNameEditing
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.Label(raylib.NewRectangle(windowPos.X+21, windowPos.Y+124, 100, 20), "Canvas Size")
|
||||||
|
{
|
||||||
|
var err error
|
||||||
|
|
||||||
|
lastWidth := newCanvasWidth
|
||||||
|
width := fmt.Sprintf("%d", newCanvasWidth)
|
||||||
|
if gui.TextBox(raylib.NewRectangle(windowPos.X+131, windowPos.Y+124, windowPos.Width-152, 20), &width, 40, newCanvasWidthEditing) {
|
||||||
|
newCanvasWidthEditing = !newCanvasWidthEditing
|
||||||
|
}
|
||||||
|
if newCanvasWidth, err = strconv.Atoi(width); err != nil {
|
||||||
|
newCanvasWidth = lastWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
lastHeight := newCanvasHeight
|
||||||
|
height := fmt.Sprintf("%d", newCanvasHeight)
|
||||||
|
if gui.TextBox(raylib.NewRectangle(windowPos.X+131, windowPos.Y+154, windowPos.Width-152, 20), &height, 40, newCanvasHeightEditing) {
|
||||||
|
newCanvasHeightEditing = !newCanvasHeightEditing
|
||||||
|
}
|
||||||
|
if newCanvasHeight, err = strconv.Atoi(height); err != nil {
|
||||||
|
newCanvasHeight = lastHeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if gui.Button(raylib.NewRectangle(windowPos.X+21, windowPos.Y+184, 120, 20), "Create") {
|
||||||
|
state = StateNormal
|
||||||
|
createNewCanvas = true
|
||||||
|
AddToast("Created New Canvas")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
raylib.EndScissorMode()
|
raylib.EndScissorMode()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue