Compare commits

..

6 Commits

Author SHA1 Message Date
Jeff Carr 3d46cf352a remove for now 2025-03-05 03:47:40 -06:00
Jeff Carr 113154e858 fix typos 2025-02-21 10:21:32 -06:00
Jeff Carr 9e177d2636 fixed for new 'tree' package 2025-02-14 18:20:30 -06:00
Jeff Carr 2b8673e04c ignore all *.so files 2025-01-07 17:44:05 -06:00
Jeff Carr bdfdf5b2c3 standard build rules 2024-12-06 01:52:16 -06:00
Jeff Carr 3b22b50a2b using resources so it might run as a plugin 2024-12-05 18:49:47 -06:00
12 changed files with 178 additions and 81 deletions

2
.gitignore vendored
View File

@ -2,4 +2,4 @@
go.mod go.mod
go.sum go.sum
pixelgl pixelgl
pixelgl.so *.so

View File

@ -1,11 +1,22 @@
all: plugin VERSION = $(shell git describe --tags)
ldd pixelgl.so BUILDTIME = $(shell date +%Y.%m.%d)
all: clean goimports plugin
#ldd pixelgl.so
deps:
sudo apt install libxxf86vm-dev libxxf86vm1
plugin: plugin:
go build -v -x -buildmode=plugin -o pixelgl.so LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/ GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so
install: install:
go build -v -x -buildmode=plugin -o pixelgl.so rm -f pixelgo.so
go build -v -x -buildmode=plugin -o ~/go/lib/pixelgl-${VERSION}.so
cd ~/go/lib && ln -f -s pixelgl-${VERSION}.so pixelgl.so
clean:
rm -f pixelgl pixelgl.so
full-plugin: full-plugin:
GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so
@ -14,7 +25,8 @@ full-install:
GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so
standalone: standalone:
go build -v -x GO111MODULE=off go build -v -x
./pixelgl
check-git-clean: check-git-clean:
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1) @git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)

View File

@ -7,12 +7,13 @@ package main
*/ */
import ( import (
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
) )
func Add(n *tree.Node) { func newAdd(n *tree.Node) {
log.Log(INFO, "Add() END =", n.WidgetType, n.String()) log.Log(INFO, "Add() END =", n.WidgetType, n.String())
if n == nil { if n == nil {
log.Warn("Tree Error: Add() sent n == nil") log.Warn("Tree Error: Add() sent n == nil")
@ -58,7 +59,7 @@ func newaction(n *tree.Node, atype widget.ActionType) {
// w.disableColor() // w.disableColor()
case widget.Delete: case widget.Delete:
log.Info("newaction() DeleteNode()") log.Info("newaction() DeleteNode()")
n.DeleteNode() // n.DeleteNode()
case widget.ToolkitClose: case widget.ToolkitClose:
log.Info("newaction() toolkit closed. are the channels cleand up?") log.Info("newaction() toolkit closed. are the channels cleand up?")
return return
@ -68,15 +69,15 @@ func newaction(n *tree.Node, atype widget.ActionType) {
log.Log(INFO, "newaction() END", atype, n.String()) log.Log(INFO, "newaction() END", atype, n.String())
} }
func SetTitle(n *tree.Node, s string) { func setTitle(n *tree.Node, s string) {
SetText(n, s) setText(n, s)
} }
func SetLabel(n *tree.Node, s string) { func setLabel(n *tree.Node, s string) {
SetText(n, s) setText(n, s)
} }
func SetText(n *tree.Node, s string) { func setText(n *tree.Node, s string) {
if n == nil { if n == nil {
log.Warn("Tree Error: Add() sent n == nil") log.Warn("Tree Error: Add() sent n == nil")
return return
@ -90,7 +91,7 @@ func SetText(n *tree.Node, s string) {
log.Info("SetText()", n.WidgetType, n.String()) log.Info("SetText()", n.WidgetType, n.String())
} }
func AddText(n *tree.Node, s string) { func addText(n *tree.Node, s string) {
if n == nil { if n == nil {
log.Warn("Tree Error: Add() sent n == nil") log.Warn("Tree Error: Add() sent n == nil")
return return
@ -103,3 +104,23 @@ func AddText(n *tree.Node, s string) {
// w := n.TK.(*guiWidget) // w := n.TK.(*guiWidget)
// w.AddText(s) // w.AddText(s)
} }
func enableWidget(n *tree.Node) {
log.Info("do enable() here")
}
func disableWidget(n *tree.Node) {
log.Info("do enable() here")
}
func setChecked(n *tree.Node, b bool) {
log.Info("do enable() here")
}
func showTable(n *guipb.Table) {
log.Info("do enable() here")
}
func toolkitClose() {
log.Info("do enable() here")
}

51
main.go
View File

@ -9,10 +9,11 @@ package main
import ( import (
"embed" "embed"
"io/fs"
"os"
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree"
"github.com/faiface/pixel/pixelgl" "github.com/faiface/pixel/pixelgl"
// "github.com/gookit/config" // "github.com/gookit/config"
@ -22,16 +23,23 @@ import (
var VERSION string var VERSION string
var BUILDTIME string var BUILDTIME string
//go:embed *.glsl var PLUGIN string = "pixelgl"
var glFile embed.FS
//go:embed resources/*
var resources embed.FS
var pp *arg.Parser var pp *arg.Parser
func init() { // the glsl file
var glslFile string
func initPlugin() {
pp = arg.MustParse(&argv) pp = arg.MustParse(&argv)
log.Log(INFO, "Init()") log.Log(INFO, "Init()")
me.myTree = tree.New() me.myTree = initTree()
/*
me.myTree.PluginName = "nocui" me.myTree.PluginName = "nocui"
// me.myTree.ActionFromChannel = doAction // me.myTree.ActionFromChannel = doAction
@ -41,6 +49,7 @@ func init() {
me.myTree.SetLabel = SetLabel me.myTree.SetLabel = SetLabel
me.myTree.SetText = SetText me.myTree.SetText = SetText
me.myTree.AddText = AddText me.myTree.AddText = AddText
*/
me.exit = false me.exit = false
@ -50,6 +59,7 @@ func init() {
go simpleStdin() go simpleStdin()
glslFile = loadGLSL(argv.Filename)
// I think this doesn't work as a goroutine because // I think this doesn't work as a goroutine because
// opengl closes. This plugin probably has to wait // opengl closes. This plugin probably has to wait
// until there is some sort of protobuf + socket interface // until there is some sort of protobuf + socket interface
@ -66,3 +76,34 @@ func main() {
// parseConfig() // parseConfig()
pixelgl.Run(run) pixelgl.Run(run)
} }
// LoadFileToString loads the contents of a file into a string
func loadGLSL(filename string) string {
var err error
var data []byte
//
data, err = os.ReadFile(filename)
if err == nil {
log.Println("found embedded file:", filename)
return string(data)
}
data, err = fs.ReadFile(resources, filename)
if len(data) == 0 {
log.Info("still could not find file", filename, err)
} else {
return string(data)
}
filename = "resources/seascape.glsl"
log.Println("did not find embedded file:", filename, err)
data, err = fs.ReadFile(resources, filename)
if len(data) == 0 {
log.Info("still could not find file", filename)
os.Exit(-1)
}
// return a string of the data to feed into
// canvas.SetFragmentShader(file)
return string(data)
}

View File

@ -1,12 +1,8 @@
package main package main
import ( import (
"io/fs"
"io/ioutil"
"github.com/faiface/pixel" "github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl" "github.com/faiface/pixel/pixelgl"
"go.wit.com/log"
) )
// Pixel Shader utility functions // Pixel Shader utility functions
@ -44,20 +40,3 @@ func CenterWindow(win *pixelgl.Window) {
), ),
) )
} }
// LoadFileToString loads the contents of a file into a string
func LoadFileToString(filename string) (string, error) {
embedf, err1 := fs.ReadFile(glFile, filename)
if err1 == nil {
log.Println("found embedded file:", filename)
return string(embedf), nil
} else {
log.Println("did not find embedded file:", filename)
log.Println("err", err1)
}
b, err := ioutil.ReadFile("/tmp/" + filename)
if err != nil {
return "", err
}
return string(b), nil
}

View File

@ -32,12 +32,6 @@ func run() {
// I am putting all shader example initializing stuff here for // I am putting all shader example initializing stuff here for
// easier reference to those learning to use this functionality // easier reference to those learning to use this functionality
fragSource, err := LoadFileToString(argv.Filename)
if err != nil {
panic(err)
}
var uMouse mgl32.Vec4 var uMouse mgl32.Vec4
var uTime float32 var uTime float32
var glDrift float32 = argv.GLdrift var glDrift float32 = argv.GLdrift
@ -52,7 +46,7 @@ func run() {
"uDrift", &glDrift, "uDrift", &glDrift,
) )
canvas.SetFragmentShader(fragSource) canvas.SetFragmentShader(glslFile)
start := time.Now() start := time.Now()

View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"sync"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
) )
@ -13,8 +15,8 @@ type guiWidget struct {
val map[string]int val map[string]int
} }
// It's probably a terrible idea to call this 'me' var initOnce sync.Once // run initPlugin() only once
var me toolkitConfig var me toolkitConfig // It's probably a terrible idea to call this 'me'
type toolkitConfig struct { type toolkitConfig struct {
treeRoot *tree.Node // the base of the binary tree. it should have id == 0 treeRoot *tree.Node // the base of the binary tree. it should have id == 0

24
tree.go
View File

@ -1,24 +0,0 @@
package main
/*
This is reference code for toolkit developers
*/
import (
"go.wit.com/widget"
)
// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from
// other goroutines. This is due to the nature of how
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
//
// this sets the channel to send user events back from the plugin
func Callback(guiCallback chan widget.Action) {
me.myTree.Callback(guiCallback)
}
func PluginChannel() chan widget.Action {
return me.myTree.PluginChannel()
}

72
treeInit.go Normal file
View File

@ -0,0 +1,72 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
/*
DO NOT EDIT THIS FILE
this file is the same for every GUI toolkit plugin
when you are making a new GUI toolkit plugin for
a specific toolkit, you just need to define these
functions.
for example, in the "gocui" toolkit, the functions
below are what triggers the "gocui" GO package
to draw labels, buttons, windows, etc
If you are starting out trying to make a new GUI toolkit,
all you have to do is copy this file over. Then
work on making these functions. addWidget(), setText(), etc.
That's it!
*/
package main
/*
This is reference code for toolkit developers
This is how information is passed in GO back to the application
via the GO 'plugin' concept
TODO: switch this to protocol buffers
*/
import (
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from
// other goroutines. This is due to the nature of how
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
//
// this sets the channel to send user events back from the plugin
func Callback(guiCallback chan widget.Action) {
me.myTree.Callback(guiCallback)
}
func PluginChannel() chan widget.Action {
initOnce.Do(initPlugin)
return me.myTree.PluginChannel()
}
func initTree() *tree.TreeInfo {
t := tree.New()
t.PluginName = PLUGIN
t.Add = newAdd
t.SetTitle = setTitle
t.SetLabel = setLabel
t.SetText = setText
t.AddText = addText
t.Enable = enableWidget
t.Disable = disableWidget
t.SetChecked = setChecked
t.ToolkitClose = toolkitClose
t.ShowTable = showTable
return t
}