updated to raylib

This commit is contained in:
partisan 2024-12-20 18:58:53 +01:00
parent f82fa6ef37
commit 84fe6fe9eb
18 changed files with 1065 additions and 1130 deletions

373
main.go
View file

@ -1,233 +1,140 @@
package main
import (
"fmt"
"image"
_ "image/jpeg"
"os"
"path/filepath"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.New()
ApplyTheme(a) // Apply the theme here
w := a.NewWindow("Fyne Installer")
// Load Image
imagePath := "test.jpg"
file, err := os.Open(imagePath)
if err != nil {
dialog.ShowError(fmt.Errorf("failed to load image: %w", err), w)
return
}
defer file.Close()
img, _, err := image.Decode(file)
if err != nil {
dialog.ShowError(fmt.Errorf("failed to decode image: %w", err), w)
return
}
logo := canvas.NewImageFromImage(img)
logo.FillMode = canvas.ImageFillContain
logo.SetMinSize(fyne.NewSize(300, 300)) // Set a minimum size for the image
// Step 1: Language Selection
languageLabel := widget.NewLabelWithStyle("Select the setup language:", fyne.TextAlignLeading, fyne.TextStyle{})
languageSelect := widget.NewSelect([]string{
"English (United States)",
"Deutsch (Deutschland)",
"Italiano (Italia)",
"日本語 (日本)",
"Español (España)",
"Français (France)",
"Nederlands (Nederland)",
"中文(简体) (中国)",
}, func(value string) {
fmt.Println("Selected language:", value)
})
languageSelect.SetSelected("English (United States)")
// Navigation Buttons
nextButton := widget.NewButtonWithIcon("Next", theme.NavigateNextIcon(), func() {
w.SetContent(step2(a, w))
})
cancelButton := widget.NewButtonWithIcon("Cancel", theme.CancelIcon(), func() {
a.Quit()
})
// Step 1 Layout
step1Content := container.NewVBox(
widget.NewLabelWithStyle("Welcome to the Fyne Installer", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
widget.NewLabelWithStyle("Please select the setup language and click 'Next'", fyne.TextAlignLeading, fyne.TextStyle{}),
languageLabel,
languageSelect,
layout.NewSpacer(),
container.NewHBox(layout.NewSpacer(), nextButton, cancelButton),
)
// Main Layout
mainLayout := container.NewBorder(nil, nil, logo, nil, step1Content)
w.SetContent(mainLayout)
w.Resize(fyne.NewSize(800, 400))
w.CenterOnScreen()
w.ShowAndRun()
}
func step2(a fyne.App, w fyne.Window) fyne.CanvasObject {
// Load Image
imagePath := "test2.jpg"
file, err := os.Open(imagePath)
if err != nil {
dialog.ShowError(fmt.Errorf("failed to load image: %w", err), w)
return nil
}
defer file.Close()
img, _, err := image.Decode(file)
if err != nil {
dialog.ShowError(fmt.Errorf("failed to decode image: %w", err), w)
return nil
}
logo := canvas.NewImageFromImage(img)
logo.FillMode = canvas.ImageFillContain
logo.SetMinSize(fyne.NewSize(300, 300)) // Set a minimum size for the image
// Step 2: Installation Path Selection
info := widget.NewLabelWithStyle("Please select the installation path and click 'Install'", fyne.TextAlignLeading, fyne.TextStyle{})
pathEntry := widget.NewEntry()
pathEntry.SetPlaceHolder("Select installation path...")
selectPath := widget.NewButtonWithIcon("Browse", theme.FolderOpenIcon(), func() {
dialog.ShowFolderOpen(func(uri fyne.ListableURI, err error) {
if err != nil {
dialog.ShowError(err, w)
return
}
if uri != nil {
pathEntry.SetText(uri.Path())
}
}, w)
})
progressBar := widget.NewProgressBar()
progressBar.Hide()
installButton := widget.NewButtonWithIcon("Install", theme.ConfirmIcon(), func() {
installPath := pathEntry.Text
if installPath == "" {
dialog.ShowError(fmt.Errorf("please select an installation path"), w)
return
}
progressBar.Show()
progressBar.SetValue(0)
go installApplication(installPath, progressBar)
})
backButton := widget.NewButtonWithIcon("Back", theme.NavigateBackIcon(), func() {
w.SetContent(step1(a, w))
})
cancelButton := widget.NewButtonWithIcon("Cancel", theme.CancelIcon(), func() {
a.Quit()
})
// Step 2 Layout
step2Content := container.NewVBox(
widget.NewLabelWithStyle("Installation Setup", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
info,
container.NewHBox(pathEntry, selectPath),
progressBar,
layout.NewSpacer(),
container.NewHBox(layout.NewSpacer(), backButton, installButton, cancelButton),
)
return container.NewBorder(nil, nil, logo, nil, step2Content)
}
func step1(a fyne.App, w fyne.Window) fyne.CanvasObject {
// Load Image
imagePath := "test2.jpg"
file, err := os.Open(imagePath)
if err != nil {
dialog.ShowError(fmt.Errorf("failed to load image: %w", err), w)
return nil
}
defer file.Close()
img, _, err := image.Decode(file)
if err != nil {
dialog.ShowError(fmt.Errorf("failed to decode image: %w", err), w)
return nil
}
logo := canvas.NewImageFromImage(img)
logo.FillMode = canvas.ImageFillContain
logo.SetMinSize(fyne.NewSize(300, 300)) // Set a minimum size for the image
// Step 1: Language Selection
languageLabel := widget.NewLabelWithStyle("Select the setup language:", fyne.TextAlignLeading, fyne.TextStyle{})
languageSelect := widget.NewSelect([]string{
"English (United States)",
"Deutsch (Deutschland)",
"Italiano (Italia)",
"日本語 (日本)",
"Español (España)",
"Français (France)",
"Nederlands (Nederland)",
"中文(简体) (中国)",
}, func(value string) {
fmt.Println("Selected language:", value)
})
languageSelect.SetSelected("English (United States)")
// Navigation Buttons
nextButton := widget.NewButtonWithIcon("Next", theme.NavigateNextIcon(), func() {
w.SetContent(step2(a, w))
})
cancelButton := widget.NewButtonWithIcon("Cancel", theme.CancelIcon(), func() {
a.Quit()
})
// Step 1 Layout
step1Content := container.NewVBox(
widget.NewLabelWithStyle("Welcome to the Fyne Installer", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
widget.NewLabelWithStyle("Please select the setup language and click 'Next'", fyne.TextAlignLeading, fyne.TextStyle{}),
languageLabel,
languageSelect,
layout.NewSpacer(),
container.NewHBox(layout.NewSpacer(), nextButton, cancelButton),
)
return container.NewBorder(nil, nil, logo, nil, step1Content)
}
func installApplication(path string, progressBar *widget.ProgressBar) {
// Simulate installation process
for i := 0; i <= 10; i++ {
progressBar.SetValue(float64(i) / 10)
// Simulate time-consuming installation step
time.Sleep(500 * time.Millisecond)
}
// Create a file to simulate an installation
file, err := os.Create(filepath.Join(path, "installed.txt"))
if err != nil {
dialog.ShowError(err, fyne.CurrentApp().Driver().AllWindows()[0])
return
}
defer file.Close()
file.WriteString("Installation complete!")
progressBar.SetValue(1)
dialog.ShowInformation("Installation Complete", "The application was successfully installed.", fyne.CurrentApp().Driver().AllWindows()[0])
}
package main
import (
"fmt"
"os"
rl "github.com/gen2brain/raylib-go/raylib"
)
var transition = NewTransitionManager()
var currentStep = 0
var targetStep = 0
var useDefault = false
var step1DefaultRect rl.Rectangle
var step1CustomRect rl.Rectangle
func main() {
monitor := rl.GetCurrentMonitor()
screenW := rl.GetMonitorWidth(monitor)
screenH := rl.GetMonitorHeight(monitor)
rl.InitWindow(int32(screenW), int32(screenH), "Spitfire Browser Installer")
rl.SetWindowState(rl.FlagFullscreenMode)
defer rl.CloseWindow()
rl.SetTargetFPS(60)
InitBackground(rl.GetScreenWidth(), rl.GetScreenHeight())
targetStep = 0
for !rl.WindowShouldClose() {
screenW = rl.GetScreenWidth()
screenH = rl.GetScreenHeight()
mousePos := rl.GetMousePosition()
buttonW := 100
buttonH := 30
prevX := int32(50)
prevY := int32(screenH - 50)
nextX := int32(screenW - 150)
nextY := prevY
oldAlpha, oldScale, oldOffsetX, newAlpha, newScale, newOffsetX := transition.Update()
if !transition.IsActive() && currentStep != targetStep {
currentStep = targetStep
}
if !transition.IsActive() && rl.IsMouseButtonPressed(rl.MouseLeftButton) {
handleInput(mousePos, screenW, screenH, buttonW, buttonH, prevX, prevY, nextX, nextY)
}
UpdateBackground(screenW, screenH)
rl.BeginDrawing()
DrawBackground(screenW, screenH)
drawHeader(screenW)
oldStep := currentStep
newStep := currentStep
if transition.IsActive() {
oldStep = transition.oldStep
newStep = transition.newStep
}
phase := transition.GetPhase()
if transition.IsActive() {
if phase == TransitionOutFadeScale {
drawStep(oldStep, screenW, screenH, mousePos, oldAlpha, oldScale, oldOffsetX)
} else {
drawStep(oldStep, screenW, screenH, mousePos, oldAlpha, oldScale, oldOffsetX)
drawStep(newStep, screenW, screenH, mousePos, newAlpha, newScale, newOffsetX)
}
} else {
drawStep(currentStep, screenW, screenH, mousePos, 1.0, 1.0, 0.0)
}
if !transition.IsActive() {
if currentStep > 0 && currentStep < 3 {
drawButton("Previous", prevX, prevY, int32(buttonW), int32(buttonH), mousePos)
}
if currentStep == 1 {
drawButton("Next", nextX, nextY, int32(buttonW), int32(buttonH), mousePos)
} else if currentStep == 2 {
drawButton("Finish", nextX, nextY, int32(buttonW), int32(buttonH), mousePos)
}
}
rl.EndDrawing()
}
}
func startTransition(from, to int) {
targetStep = to
transition.Start(from, to)
}
func handleInput(mousePos rl.Vector2, screenW, screenH, buttonW, buttonH int, prevX, prevY, nextX, nextY int32) {
if currentStep == 0 {
if overRect(mousePos, step1DefaultRect) {
fmt.Println("Installation complete with default settings.")
os.Exit(0)
}
if overRect(mousePos, step1CustomRect) {
useDefault = false
startTransition(currentStep, 1)
}
} else if currentStep == 1 {
if overButton(mousePos, nextX, nextY, int32(buttonW), int32(buttonH)) {
startTransition(currentStep, 2)
}
if overButton(mousePos, int32(prevX), int32(prevY), int32(buttonW), int32(buttonH)) {
startTransition(currentStep, 0)
}
selectColor(mousePos)
selectContrastIcon(mousePos)
selectTheme(mousePos)
} else if currentStep == 2 {
if overButton(mousePos, nextX, nextY, int32(buttonW), int32(buttonH)) {
fmt.Printf("Installation complete:\nDefault: %v\nColor: %s\nTheme: %s\nLayout: %s\n",
useDefault, selectedColor, selectedTheme, selectedLayout)
os.Exit(0)
}
if overButton(mousePos, int32(prevX), int32(prevY), int32(buttonW), int32(buttonH)) {
startTransition(currentStep, 1)
}
selectLayoutOption(mousePos)
}
}
func drawHeader(screenW int) {
title := "Spitfire Browser Installer"
titleFontSize := int32(30)
titleWidth := rl.MeasureText(title, titleFontSize)
rl.DrawText(title, (int32(screenW)-titleWidth)/2, 20, titleFontSize, rl.RayWhite)
rl.DrawLine(50, 60, int32(screenW)-50, 60, rl.Fade(rl.White, 0.5))
}