add some documentation
This commit is contained in:
parent
c351d10cb9
commit
f0c49df67b
@ -12,7 +12,6 @@ func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize,
|
|||||||
width, height, origHeight, origWidth int
|
width, height, origHeight, origWidth int
|
||||||
)
|
)
|
||||||
origHeight = int(mw.GetImageHeight())
|
origHeight = int(mw.GetImageHeight())
|
||||||
//fmt.Println("hahahahahah :-P")
|
|
||||||
origWidth = int(mw.GetImageWidth())
|
origWidth = int(mw.GetImageWidth())
|
||||||
|
|
||||||
if (origHeight != newHeight) || (origWidth != newWidth) {
|
if (origHeight != newHeight) || (origWidth != newWidth) {
|
||||||
|
129
main.go
129
main.go
@ -8,9 +8,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/go-gl/gl/v2.1/gl"
|
"github.com/go-gl/gl/v2.1/gl"
|
||||||
"github.com/go-gl/glfw/v3.1/glfw"
|
"github.com/go-gl/glfw/v3.1/glfw"
|
||||||
@ -19,6 +18,7 @@ import (
|
|||||||
"gopkg.in/gographics/imagick.v2/imagick"
|
"gopkg.in/gographics/imagick.v2/imagick"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//lazy wanted a toggle function
|
||||||
type Bool bool
|
type Bool bool
|
||||||
|
|
||||||
type cell struct {
|
type cell struct {
|
||||||
@ -31,23 +31,24 @@ type cell struct {
|
|||||||
type slide []*cell
|
type slide []*cell
|
||||||
|
|
||||||
var (
|
var (
|
||||||
x0, y0, selSlide, rhtClkCell int
|
//displayed width/height the focused and the cell that was last right clicked
|
||||||
path string
|
monWidth, monHeight, selCell, rhtClkCell int
|
||||||
qimg qml.Object
|
path string
|
||||||
textEdit qml.Object
|
qimg qml.Object //file for the image object
|
||||||
cellQml qml.Object
|
textEdit qml.Object
|
||||||
window *qml.Window
|
cellQml qml.Object //file for the cell object
|
||||||
win *glfw.Window
|
window *qml.Window //QML
|
||||||
slides slide
|
win *glfw.Window //GLFW
|
||||||
err error
|
slides slide
|
||||||
monitors []*glfw.Monitor
|
err error
|
||||||
projMonitor *glfw.Monitor
|
monitors []*glfw.Monitor
|
||||||
tex1 *uint32
|
projMonitor *glfw.Monitor
|
||||||
texDel, quickEdit Bool = false, false
|
tex1 *uint32 //identifier for opengl texture
|
||||||
|
texDel, quickEdit Bool = false, false //if texture should be deleted
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
selSlide = 0
|
selCell = 0
|
||||||
|
|
||||||
if err = qml.Run(run); err != nil {
|
if err = qml.Run(run); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
@ -62,7 +63,7 @@ func run() error {
|
|||||||
|
|
||||||
engine := qml.NewEngine()
|
engine := qml.NewEngine()
|
||||||
engine.AddImageProvider("images", imgProvider)
|
engine.AddImageProvider("images", imgProvider)
|
||||||
|
//path for qml files TODO: change to somewhere else
|
||||||
path, err = osext.ExecutableFolder()
|
path, err = osext.ExecutableFolder()
|
||||||
path = filepath.Clean(path + "/../src/github.com/lordwelch/PresentationApp/")
|
path = filepath.Clean(path + "/../src/github.com/lordwelch/PresentationApp/")
|
||||||
|
|
||||||
@ -85,7 +86,9 @@ func run() error {
|
|||||||
|
|
||||||
textEdit = window.ObjectByName("textEdit")
|
textEdit = window.ObjectByName("textEdit")
|
||||||
slides.addCell()
|
slides.addCell()
|
||||||
|
//signals for whole qml
|
||||||
setSignals()
|
setSignals()
|
||||||
|
//image is ready for imageprovider
|
||||||
imgready = true
|
imgready = true
|
||||||
|
|
||||||
window.Show()
|
window.Show()
|
||||||
@ -103,7 +106,7 @@ func setupScene() {
|
|||||||
if texDel {
|
if texDel {
|
||||||
gl.DeleteTextures(1, tex1)
|
gl.DeleteTextures(1, tex1)
|
||||||
}
|
}
|
||||||
tex1 = newTexture(*slides[selSlide].getImage(x0, y0))
|
tex1 = newTexture(*slides[selCell].getImage(monWidth, monHeight))
|
||||||
|
|
||||||
gl.MatrixMode(gl.PROJECTION)
|
gl.MatrixMode(gl.PROJECTION)
|
||||||
gl.LoadIdentity()
|
gl.LoadIdentity()
|
||||||
@ -123,15 +126,18 @@ func drawSlide() {
|
|||||||
|
|
||||||
gl.Begin(gl.QUADS)
|
gl.Begin(gl.QUADS)
|
||||||
|
|
||||||
|
//top left
|
||||||
gl.TexCoord2f(0, 0)
|
gl.TexCoord2f(0, 0)
|
||||||
gl.Vertex3f(-1, 1, 0)
|
gl.Vertex3f(-1, 1, 0)
|
||||||
|
//top right
|
||||||
gl.TexCoord2f(1, 0)
|
gl.TexCoord2f(1, 0)
|
||||||
gl.Vertex3f(1, 1, 0)
|
gl.Vertex3f(1, 1, 0)
|
||||||
|
|
||||||
|
//bottom right
|
||||||
gl.TexCoord2f(1, 1)
|
gl.TexCoord2f(1, 1)
|
||||||
gl.Vertex3f(1, -1, 0)
|
gl.Vertex3f(1, -1, 0)
|
||||||
|
|
||||||
|
//bottom left
|
||||||
gl.TexCoord2f(0, 1)
|
gl.TexCoord2f(0, 1)
|
||||||
gl.Vertex3f(-1, -1, 0)
|
gl.Vertex3f(-1, -1, 0)
|
||||||
|
|
||||||
@ -168,22 +174,22 @@ func checkMon() {
|
|||||||
|
|
||||||
if i := len(monitors); i < 2 {
|
if i := len(monitors); i < 2 {
|
||||||
fmt.Println("You only have 1 monitor!!!!!!!!!!! :-P")
|
fmt.Println("You only have 1 monitor!!!!!!!!!!! :-P")
|
||||||
x0 = 800
|
monWidth = 800
|
||||||
y0 = 600
|
monHeight = 600
|
||||||
|
|
||||||
win, err = glfw.CreateWindow(x0, y0, "Cube", nil, nil)
|
win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
projMonitor = monitors[0]
|
projMonitor = monitors[0]
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("You have %d monitors\n", i)
|
fmt.Printf("You have %d monitors\n", i)
|
||||||
x0 = monitors[1].GetVideoMode().Width
|
monWidth = monitors[1].GetVideoMode().Width
|
||||||
y0 = monitors[1].GetVideoMode().Height
|
monHeight = monitors[1].GetVideoMode().Height
|
||||||
win, err = glfw.CreateWindow(x0, y0, "Cube", nil, nil)
|
win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil)
|
||||||
fmt.Println(win.GetPos())
|
fmt.Println(win.GetPos())
|
||||||
win.SetPos(monitors[1].GetPos())
|
win.SetPos(monitors[1].GetPos())
|
||||||
fmt.Println(x0, y0)
|
fmt.Println(monWidth, monHeight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -236,7 +242,20 @@ func glInit() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//setSignals() for non dynamic elements
|
||||||
func setSignals() {
|
func setSignals() {
|
||||||
|
window.ObjectByName("imgpicker").On("accepted", func() {
|
||||||
|
//delete file:// from url
|
||||||
|
url := filepath.Clean(strings.Replace(window.ObjectByName("imgpicker").String("fileUrl"), "file:", "", 1))
|
||||||
|
|
||||||
|
//replace new image
|
||||||
|
slides[rhtClkCell].img.Clear()
|
||||||
|
slides[rhtClkCell].img.ReadImage(url)
|
||||||
|
setupScene()
|
||||||
|
//update image preview
|
||||||
|
slides[rhtClkCell].clearcache()
|
||||||
|
})
|
||||||
|
|
||||||
window.ObjectByName("btnAdd").On("clicked", func() {
|
window.ObjectByName("btnAdd").On("clicked", func() {
|
||||||
slides.addCell()
|
slides.addCell()
|
||||||
})
|
})
|
||||||
@ -246,10 +265,12 @@ func setSignals() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
window.ObjectByName("btnMem").On("clicked", func() {
|
window.ObjectByName("btnMem").On("clicked", func() {
|
||||||
|
//run GC
|
||||||
debug.FreeOSMemory()
|
debug.FreeOSMemory()
|
||||||
})
|
})
|
||||||
|
|
||||||
window.On("closing", func() {
|
window.On("closing", func() {
|
||||||
|
//close glfw first
|
||||||
if false == window.Property("cls") {
|
if false == window.Property("cls") {
|
||||||
win.SetShouldClose(true)
|
win.SetShouldClose(true)
|
||||||
window.Set("cls", true)
|
window.Set("cls", true)
|
||||||
@ -268,7 +289,7 @@ func setSignals() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if !focus {
|
if !focus {
|
||||||
|
//set text back to the cell
|
||||||
str = textEdit.ObjectByName("textEdit1").String("text")
|
str = textEdit.ObjectByName("textEdit1").String("text")
|
||||||
cel = slides[textEdit.Int("cell")]
|
cel = slides[textEdit.Int("cell")]
|
||||||
if textEdit.Bool("txt") {
|
if textEdit.Bool("txt") {
|
||||||
@ -280,36 +301,43 @@ func setSignals() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cl cell) getImage(x, y int) (img *image.RGBA) {
|
//getImage() from imagick to image.RGBA
|
||||||
|
func (cl cell) getImage(width, height int) (img *image.RGBA) {
|
||||||
mw := cl.img.GetImage()
|
mw := cl.img.GetImage()
|
||||||
if (x == 0) || (y == 0) {
|
if (width == 0) || (height == 0) {
|
||||||
x = int(mw.GetImageWidth())
|
width = int(mw.GetImageWidth())
|
||||||
y = int(mw.GetImageHeight())
|
height = int(mw.GetImageHeight())
|
||||||
}
|
}
|
||||||
|
|
||||||
mw = resizeImage(mw, x, y, true, true)
|
mw = resizeImage(mw, width, height, true, true)
|
||||||
img = image.NewRGBA(image.Rect(0, 0, int(x), int(y)))
|
img = image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
|
||||||
if img.Stride != img.Rect.Size().X*4 {
|
if img.Stride != img.Rect.Size().X*4 {
|
||||||
panic("unsupported stride")
|
panic("unsupported stride")
|
||||||
}
|
}
|
||||||
|
|
||||||
Tpix, _ := mw.ExportImagePixels(0, 0, uint(x), uint(y), "RGBA", imagick.PIXEL_CHAR)
|
Tpix, _ := mw.ExportImagePixels(0, 0, uint(width), uint(height), "RGBA", imagick.PIXEL_CHAR)
|
||||||
img.Pix = Tpix.([]uint8)
|
img.Pix = Tpix.([]uint8)
|
||||||
mw.Destroy()
|
mw.Destroy()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//signals for the cell and image in qml
|
||||||
func (cl *cell) setSignal() {
|
func (cl *cell) setSignal() {
|
||||||
cl.qmlcell.ObjectByName("cellMouse").On("clicked", func(musEvent qml.Object) {
|
cl.qmlcell.ObjectByName("cellMouse").On("clicked", func(musEvent qml.Object) {
|
||||||
btn := musEvent.Property("button")
|
btn := musEvent.Property("button")
|
||||||
|
//right click
|
||||||
if btn == 2 {
|
if btn == 2 {
|
||||||
|
//context menu
|
||||||
window.ObjectByName("mnuCtx").Call("popup")
|
window.ObjectByName("mnuCtx").Call("popup")
|
||||||
rhtClkCell = cl.index
|
rhtClkCell = cl.index
|
||||||
} else {
|
} else {
|
||||||
selSlide = cl.qmlcell.Int("index")
|
//left click
|
||||||
|
//select and update image preview for cell
|
||||||
|
selCell = cl.qmlcell.Int("index")
|
||||||
cl.qmlcell.ObjectByName("cellMouse").Set("focus", true)
|
cl.qmlcell.ObjectByName("cellMouse").Set("focus", true)
|
||||||
setupScene()
|
setupScene()
|
||||||
}
|
}
|
||||||
|
//update image preview
|
||||||
cl.clearcache()
|
cl.clearcache()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -321,34 +349,27 @@ func (cl *cell) setSignal() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
window.ObjectByName("imgpicker").On("accepted", func() {
|
|
||||||
//url := window.Call("getFileDialogUrl")
|
|
||||||
url := filepath.Clean(strings.Replace(window.ObjectByName("imgpicker").String("fileUrl"), "file:", "", 1))
|
|
||||||
|
|
||||||
slides[rhtClkCell].img.Clear()
|
|
||||||
slides[rhtClkCell].img.ReadImage(url)
|
|
||||||
setupScene()
|
|
||||||
cl.clearcache()
|
|
||||||
})
|
|
||||||
|
|
||||||
cl.qmlcell.ObjectByName("cellMouse").On("doubleClicked", func() {
|
cl.qmlcell.ObjectByName("cellMouse").On("doubleClicked", func() {
|
||||||
if quickEdit {
|
if quickEdit {
|
||||||
|
//cover the cell with the text edit
|
||||||
textEdit.Set("cell", cl.index)
|
textEdit.Set("cell", cl.index)
|
||||||
textEdit.Set("x", cl.qmlcell.Int("x"))
|
textEdit.Set("x", cl.qmlcell.Int("x"))
|
||||||
textEdit.Set("y", cl.qmlcell.Int("y"))
|
textEdit.Set("y", cl.qmlcell.Int("y"))
|
||||||
textEdit.Set("height", cl.qmlcell.Int("height"))
|
textEdit.Set("height", cl.qmlcell.Int("height"))
|
||||||
textEdit.Set("z", 100)
|
textEdit.Set("z", 100)
|
||||||
textEdit.Set("opacity", 100)
|
|
||||||
textEdit.Set("visible", true)
|
textEdit.Set("visible", true)
|
||||||
textEdit.ObjectByName("textEdit1").Set("focus", true)
|
textEdit.ObjectByName("textEdit1").Set("focus", true)
|
||||||
textEdit.Set("enabled", true)
|
textEdit.Set("enabled", true)
|
||||||
|
|
||||||
|
//set the text
|
||||||
textEdit.ObjectByName("textEdit1").Set("text", cl.text)
|
textEdit.ObjectByName("textEdit1").Set("text", cl.text)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//clear cache dosen't actually clear the cache
|
||||||
|
//just gives a new source so that the cache isn't used
|
||||||
func (cl *cell) clearcache() {
|
func (cl *cell) clearcache() {
|
||||||
str := cl.qmlimg.String("source")
|
str := cl.qmlimg.String("source")
|
||||||
//fmt.Println("source (click): ", str)
|
//fmt.Println("source (click): ", str)
|
||||||
@ -361,24 +382,32 @@ func (cl *cell) clearcache() {
|
|||||||
cl.qmlimg.Set("source", str)
|
cl.qmlimg.Set("source", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Adds a new cell
|
||||||
func (sl *slide) addCell( /*cl *cell*/ ) {
|
func (sl *slide) addCell( /*cl *cell*/ ) {
|
||||||
var cl cell
|
var cl cell
|
||||||
|
//gets the length so that the index is valid
|
||||||
cl.index = len(*sl)
|
cl.index = len(*sl)
|
||||||
|
|
||||||
|
//increase count on parent QML element
|
||||||
window.ObjectByName("gridRect").Set("count", window.ObjectByName("gridRect").Int("count")+1)
|
window.ObjectByName("gridRect").Set("count", window.ObjectByName("gridRect").Int("count")+1)
|
||||||
cl.qmlcell = cellQml.Create(nil)
|
cl.qmlcell = cellQml.Create(nil)
|
||||||
cl.qmlcell.Set("objectName", fmt.Sprintf("cellRect%d", len(*sl)))
|
cl.qmlcell.Set("objectName", fmt.Sprintf("cellRect%d", len(*sl)))
|
||||||
cl.qmlcell.Set("parent", window.ObjectByName("data1"))
|
cl.qmlcell.Set("parent", window.ObjectByName("data1"))
|
||||||
cl.qmlcell.Set("index", cl.index)
|
cl.qmlcell.Set("index", cl.index)
|
||||||
|
|
||||||
|
//load image
|
||||||
cl.img = imagick.NewMagickWand()
|
cl.img = imagick.NewMagickWand()
|
||||||
cl.img.ReadImage("logo:")
|
cl.img.ReadImage("logo:")
|
||||||
|
|
||||||
cl.text = "testing 1... 2... 3..."
|
//give QML the text
|
||||||
cl.qmlcell.ObjectByName("cellText").Set("text", cl.text)
|
cl.qmlcell.ObjectByName("cellText").Set("text", cl.text)
|
||||||
|
|
||||||
|
//keep the pointer/dereference (i'm not sure which it is)
|
||||||
|
//problems occur otherwise
|
||||||
*sl = append(*sl, &cl)
|
*sl = append(*sl, &cl)
|
||||||
cl.setSignal()
|
cl.setSignal()
|
||||||
|
|
||||||
|
//seperate image object in QML
|
||||||
cl.qmlimg = qimg.Create(nil)
|
cl.qmlimg = qimg.Create(nil)
|
||||||
fmt.Println("index", cl.index)
|
fmt.Println("index", cl.index)
|
||||||
fmt.Printf("objectName: %s\n", fmt.Sprintf("cellImg%d", cl.index))
|
fmt.Printf("objectName: %s\n", fmt.Sprintf("cellImg%d", cl.index))
|
||||||
@ -390,6 +419,7 @@ func (sl *slide) addCell( /*cl *cell*/ ) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//remove() should destroy everything
|
||||||
func (cl *cell) remove() {
|
func (cl *cell) remove() {
|
||||||
cl.text = ""
|
cl.text = ""
|
||||||
cl.qmlimg.Destroy()
|
cl.qmlimg.Destroy()
|
||||||
@ -401,10 +431,12 @@ func (cl *cell) remove() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//(slide) remove copied from gist on github
|
||||||
func (sl *slide) remove(i int) {
|
func (sl *slide) remove(i int) {
|
||||||
*sl, (*sl)[len((*sl))-1] = append((*sl)[:i], (*sl)[i+1:]...), nil
|
*sl, (*sl)[len((*sl))-1] = append((*sl)[:i], (*sl)[i+1:]...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//lazy wanted a toggle func
|
||||||
func (bl *Bool) Toggle() {
|
func (bl *Bool) Toggle() {
|
||||||
if *bl == false {
|
if *bl == false {
|
||||||
*bl = true
|
*bl = true
|
||||||
@ -413,6 +445,7 @@ func (bl *Bool) Toggle() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//not really needed
|
||||||
func (cl cell) String() string {
|
func (cl cell) String() string {
|
||||||
return fmt.Sprintf("Index: %d \nText: %s\n", cl.index, cl.text)
|
return fmt.Sprintf("Index: %d \nText: %s\n", cl.index, cl.text)
|
||||||
}
|
}
|
||||||
|
2
main.qml
2
main.qml
@ -3,7 +3,7 @@ import QtQuick.Dialogs 1.2
|
|||||||
import QtQuick.Controls 1.3
|
import QtQuick.Controls 1.3
|
||||||
import QtQuick.Window 2.0
|
import QtQuick.Window 2.0
|
||||||
import "qml"
|
import "qml"
|
||||||
import QtQuick.Layouts 1.2
|
import QtQuick.Layouts 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
id: applicationWindow1
|
id: applicationWindow1
|
||||||
|
7
xml.go
7
xml.go
@ -1,3 +1,5 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
type _ struct {
|
type _ struct {
|
||||||
Song struct {
|
Song struct {
|
||||||
Version string `xml:"version,attr"`
|
Version string `xml:"version,attr"`
|
||||||
@ -45,14 +47,13 @@ type _ struct {
|
|||||||
|
|
||||||
Verse []struct {
|
Verse []struct {
|
||||||
Lang string `xml:"lang,attr,omitempty"`
|
Lang string `xml:"lang,attr,omitempty"`
|
||||||
transliteration string `xml:"translit,attr,omitempty"`
|
Transliteration string `xml:"translit,attr,omitempty"`
|
||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
Lines []struct {
|
Lines []struct {
|
||||||
Part string `xml"part,attr"`
|
Part string `xml:"part,attr"`
|
||||||
Value string `xml:",innerxml"`
|
Value string `xml:",innerxml"`
|
||||||
} `xml:"lines"`
|
} `xml:"lines"`
|
||||||
Comments []string `xml:"comments,omitempty"`
|
Comments []string `xml:"comments,omitempty"`
|
||||||
} `xml:"lyrics>verse"`
|
} `xml:"lyrics>verse"`
|
||||||
} `xml:"song"`
|
} `xml:"song"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user