2016-01-11 09:10:52 -08:00
|
|
|
// PresentationApp project main.go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-02-09 21:55:57 -08:00
|
|
|
"image"
|
2016-01-21 10:11:16 -08:00
|
|
|
"log"
|
2016-01-14 15:30:14 -08:00
|
|
|
"os"
|
2016-01-14 18:42:52 -08:00
|
|
|
"path/filepath"
|
2016-03-11 14:30:04 -08:00
|
|
|
"runtime/debug"
|
2016-03-21 22:03:46 -07:00
|
|
|
"strconv"
|
2016-03-23 19:52:46 -07:00
|
|
|
"strings"
|
2016-01-14 15:30:14 -08:00
|
|
|
|
2016-01-29 20:05:16 -08:00
|
|
|
"github.com/go-gl/gl/v2.1/gl"
|
2016-01-21 10:11:16 -08:00
|
|
|
"github.com/go-gl/glfw/v3.1/glfw"
|
2016-01-14 15:30:14 -08:00
|
|
|
"github.com/kardianos/osext"
|
2016-01-25 17:27:00 -08:00
|
|
|
"github.com/lordwelch/qml"
|
2016-03-11 14:30:04 -08:00
|
|
|
"gopkg.in/gographics/imagick.v2/imagick"
|
2016-01-11 09:10:52 -08:00
|
|
|
)
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//lazy wanted a toggle function
|
2016-03-21 08:49:06 -07:00
|
|
|
type Bool bool
|
|
|
|
|
2016-01-14 22:25:53 -08:00
|
|
|
type cell struct {
|
2016-02-17 14:55:29 -08:00
|
|
|
text string
|
2016-03-11 14:30:04 -08:00
|
|
|
img *imagick.MagickWand
|
2016-03-07 08:54:14 -08:00
|
|
|
qmlimg qml.Object
|
2016-01-14 22:25:53 -08:00
|
|
|
qmlcell qml.Object
|
|
|
|
index int
|
|
|
|
}
|
2016-02-17 14:55:29 -08:00
|
|
|
type slide []*cell
|
2016-01-14 22:25:53 -08:00
|
|
|
|
2016-01-14 18:42:52 -08:00
|
|
|
var (
|
2016-03-23 19:52:46 -07:00
|
|
|
//displayed width/height the focused and the cell that was last right clicked
|
|
|
|
monWidth, monHeight, selCell, rhtClkCell int
|
|
|
|
path string
|
|
|
|
qimg qml.Object //file for the image object
|
|
|
|
textEdit qml.Object
|
|
|
|
cellQml qml.Object //file for the cell object
|
|
|
|
window *qml.Window //QML
|
|
|
|
win *glfw.Window //GLFW
|
|
|
|
slides slide
|
|
|
|
err error
|
|
|
|
monitors []*glfw.Monitor
|
|
|
|
projMonitor *glfw.Monitor
|
|
|
|
tex1 *uint32 //identifier for opengl texture
|
|
|
|
texDel, quickEdit Bool = false, false //if texture should be deleted
|
2016-01-14 18:42:52 -08:00
|
|
|
)
|
|
|
|
|
2016-01-11 09:10:52 -08:00
|
|
|
func main() {
|
2016-03-23 19:52:46 -07:00
|
|
|
selCell = 0
|
2016-01-21 10:11:16 -08:00
|
|
|
|
2016-02-01 17:04:11 -08:00
|
|
|
if err = qml.Run(run); err != nil {
|
2016-01-14 15:30:14 -08:00
|
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-01-21 10:11:16 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-14 15:30:14 -08:00
|
|
|
func run() error {
|
2016-02-03 16:14:11 -08:00
|
|
|
var mainQml qml.Object
|
2016-02-09 21:55:57 -08:00
|
|
|
imagick.Initialize()
|
2016-03-11 09:56:45 -08:00
|
|
|
|
2016-01-14 15:30:14 -08:00
|
|
|
engine := qml.NewEngine()
|
2016-03-07 08:54:14 -08:00
|
|
|
engine.AddImageProvider("images", imgProvider)
|
2016-03-23 19:52:46 -07:00
|
|
|
//path for qml files TODO: change to somewhere else
|
2016-01-19 21:12:11 -08:00
|
|
|
path, err = osext.ExecutableFolder()
|
2016-01-14 18:42:52 -08:00
|
|
|
path = filepath.Clean(path + "/../src/github.com/lordwelch/PresentationApp/")
|
2016-01-25 17:27:00 -08:00
|
|
|
|
2016-02-01 17:04:11 -08:00
|
|
|
mainQml, err = engine.LoadFile(path + "/main.qml")
|
2016-01-21 10:11:16 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-01-29 20:05:16 -08:00
|
|
|
}
|
2016-01-21 10:11:16 -08:00
|
|
|
|
2016-01-20 18:18:43 -08:00
|
|
|
cellQml, err = engine.LoadFile(path + "/qml/cell.qml")
|
2016-01-14 15:30:14 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:54:14 -08:00
|
|
|
qimg, err = engine.LoadFile(path + "/qml/img.qml")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-01-14 22:25:53 -08:00
|
|
|
window = mainQml.CreateWindow(nil)
|
2016-01-29 20:05:16 -08:00
|
|
|
|
2016-01-20 18:18:43 -08:00
|
|
|
textEdit = window.ObjectByName("textEdit")
|
2016-01-19 21:12:11 -08:00
|
|
|
slides.addCell()
|
2016-03-24 09:16:15 -07:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//signals for whole qml
|
2016-02-01 17:04:11 -08:00
|
|
|
setSignals()
|
2016-03-24 09:16:15 -07:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//image is ready for imageprovider
|
2016-03-11 09:56:45 -08:00
|
|
|
imgready = true
|
2016-01-25 17:27:00 -08:00
|
|
|
|
2016-01-14 15:30:14 -08:00
|
|
|
window.Show()
|
2016-02-17 14:55:29 -08:00
|
|
|
qml.RunMain(glInit)
|
2016-02-01 17:04:11 -08:00
|
|
|
|
2016-01-14 15:30:14 -08:00
|
|
|
window.Wait()
|
2016-02-19 08:46:03 -08:00
|
|
|
|
2016-02-17 14:55:29 -08:00
|
|
|
imagick.Terminate()
|
2016-01-14 15:30:14 -08:00
|
|
|
return nil
|
2016-01-11 09:10:52 -08:00
|
|
|
}
|
2016-01-14 22:25:53 -08:00
|
|
|
|
2016-02-09 21:55:57 -08:00
|
|
|
func setupScene() {
|
|
|
|
|
2016-03-15 10:21:59 -07:00
|
|
|
gl.ClearColor(0, 0, 0, 0)
|
2016-03-15 11:02:58 -07:00
|
|
|
if texDel {
|
2016-03-21 08:49:06 -07:00
|
|
|
gl.DeleteTextures(1, tex1)
|
2016-03-15 11:02:58 -07:00
|
|
|
}
|
2016-03-23 19:52:46 -07:00
|
|
|
tex1 = newTexture(*slides[selCell].getImage(monWidth, monHeight))
|
2016-02-09 21:55:57 -08:00
|
|
|
|
|
|
|
gl.MatrixMode(gl.PROJECTION)
|
|
|
|
gl.LoadIdentity()
|
|
|
|
gl.Ortho(-1, 1, -1, 1, 1.0, 10.0)
|
|
|
|
gl.MatrixMode(gl.MODELVIEW)
|
|
|
|
gl.LoadIdentity()
|
2016-03-15 11:02:58 -07:00
|
|
|
texDel = true
|
2016-03-11 09:56:45 -08:00
|
|
|
|
2016-02-09 21:55:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func drawSlide() {
|
|
|
|
gl.Clear(gl.COLOR_BUFFER_BIT)
|
|
|
|
|
|
|
|
gl.MatrixMode(gl.MODELVIEW)
|
|
|
|
gl.LoadIdentity()
|
|
|
|
gl.Translatef(0, 0, -3.0)
|
|
|
|
|
|
|
|
gl.Begin(gl.QUADS)
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//top left
|
2016-02-09 21:55:57 -08:00
|
|
|
gl.TexCoord2f(0, 0)
|
|
|
|
gl.Vertex3f(-1, 1, 0)
|
2016-03-23 19:52:46 -07:00
|
|
|
//top right
|
2016-02-09 21:55:57 -08:00
|
|
|
gl.TexCoord2f(1, 0)
|
|
|
|
gl.Vertex3f(1, 1, 0)
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//bottom right
|
2016-02-09 21:55:57 -08:00
|
|
|
gl.TexCoord2f(1, 1)
|
|
|
|
gl.Vertex3f(1, -1, 0)
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//bottom left
|
2016-02-09 21:55:57 -08:00
|
|
|
gl.TexCoord2f(0, 1)
|
|
|
|
gl.Vertex3f(-1, -1, 0)
|
|
|
|
|
|
|
|
gl.End()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-21 08:49:06 -07:00
|
|
|
func newTexture(rgba image.RGBA) *uint32 {
|
2016-02-09 21:55:57 -08:00
|
|
|
var texture1 uint32
|
|
|
|
gl.Enable(gl.TEXTURE_2D)
|
|
|
|
gl.GenTextures(1, &texture1)
|
|
|
|
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
|
|
|
|
gl.TexImage2D(
|
|
|
|
gl.TEXTURE_2D,
|
|
|
|
0,
|
|
|
|
gl.RGBA,
|
|
|
|
int32(rgba.Rect.Size().X),
|
|
|
|
int32(rgba.Rect.Size().Y),
|
|
|
|
0,
|
|
|
|
gl.RGBA,
|
|
|
|
gl.UNSIGNED_BYTE,
|
|
|
|
gl.Ptr(rgba.Pix))
|
|
|
|
|
2016-03-21 08:49:06 -07:00
|
|
|
return &texture1
|
2016-03-11 09:56:45 -08:00
|
|
|
|
2016-02-09 21:55:57 -08:00
|
|
|
}
|
|
|
|
|
2016-01-21 10:11:16 -08:00
|
|
|
func checkMon() {
|
|
|
|
monitors = glfw.GetMonitors()
|
2016-02-09 21:55:57 -08:00
|
|
|
glfw.WindowHint(glfw.ContextVersionMajor, 2)
|
|
|
|
glfw.WindowHint(glfw.ContextVersionMinor, 1)
|
|
|
|
glfw.WindowHint(glfw.AutoIconify, glfw.False)
|
|
|
|
glfw.WindowHint(glfw.Decorated, glfw.False)
|
2016-03-07 08:54:14 -08:00
|
|
|
|
2016-01-21 10:11:16 -08:00
|
|
|
if i := len(monitors); i < 2 {
|
|
|
|
fmt.Println("You only have 1 monitor!!!!!!!!!!! :-P")
|
2016-03-23 19:52:46 -07:00
|
|
|
monWidth = 800
|
|
|
|
monHeight = 600
|
2016-03-07 08:54:14 -08:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil)
|
2016-02-09 21:55:57 -08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2016-02-17 14:55:29 -08:00
|
|
|
projMonitor = monitors[0]
|
2016-01-21 10:11:16 -08:00
|
|
|
} else {
|
|
|
|
fmt.Printf("You have %d monitors\n", i)
|
2016-03-23 19:52:46 -07:00
|
|
|
monWidth = monitors[1].GetVideoMode().Width
|
|
|
|
monHeight = monitors[1].GetVideoMode().Height
|
|
|
|
win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil)
|
2016-02-09 21:55:57 -08:00
|
|
|
fmt.Println(win.GetPos())
|
|
|
|
win.SetPos(monitors[1].GetPos())
|
2016-03-23 19:52:46 -07:00
|
|
|
fmt.Println(monWidth, monHeight)
|
2016-02-09 21:55:57 -08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2016-02-17 14:55:29 -08:00
|
|
|
projMonitor = monitors[1]
|
2016-03-07 08:54:14 -08:00
|
|
|
|
2016-01-21 10:11:16 -08:00
|
|
|
}
|
|
|
|
monitorInfo()
|
2016-02-01 17:04:11 -08:00
|
|
|
|
2016-01-21 10:11:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func monitorInfo() {
|
|
|
|
for _, mon := range monitors {
|
|
|
|
fmt.Printf("monitor name: %s\n", mon.GetName())
|
|
|
|
i, t := mon.GetPos()
|
|
|
|
fmt.Printf("position X: %d Y: %d\n", i, t)
|
2016-03-11 09:56:45 -08:00
|
|
|
|
2016-01-21 10:11:16 -08:00
|
|
|
}
|
2016-02-01 17:04:11 -08:00
|
|
|
|
2016-01-21 10:11:16 -08:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:04:11 -08:00
|
|
|
func glInit() {
|
|
|
|
if err = glfw.Init(); err != nil {
|
|
|
|
log.Fatalln("failed to initialize glfw:", err)
|
|
|
|
}
|
|
|
|
checkMon()
|
|
|
|
|
|
|
|
win.MakeContextCurrent()
|
|
|
|
|
|
|
|
if err := gl.Init(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2016-03-16 10:23:15 -07:00
|
|
|
|
2016-02-17 14:55:29 -08:00
|
|
|
win.SetPos(projMonitor.GetPos())
|
2016-03-16 10:23:15 -07:00
|
|
|
setupScene()
|
2016-02-01 17:04:11 -08:00
|
|
|
|
|
|
|
qml.Func1 = func() int {
|
|
|
|
if !win.ShouldClose() {
|
2016-03-08 10:40:29 -08:00
|
|
|
glfw.PollEvents()
|
2016-02-01 17:04:11 -08:00
|
|
|
drawSlide()
|
|
|
|
win.SwapBuffers()
|
|
|
|
return 0
|
2016-03-11 09:56:45 -08:00
|
|
|
|
2016-02-01 17:04:11 -08:00
|
|
|
} else {
|
|
|
|
win.Hide()
|
2016-03-16 10:23:15 -07:00
|
|
|
//win.Destroy()
|
|
|
|
glfw.Terminate()
|
2016-02-01 17:04:11 -08:00
|
|
|
return 1
|
2016-03-11 09:56:45 -08:00
|
|
|
|
2016-02-01 17:04:11 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//setSignals() for non dynamic elements
|
2016-02-01 17:04:11 -08:00
|
|
|
func setSignals() {
|
2016-03-23 19:52:46 -07:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
2016-02-18 15:12:22 -08:00
|
|
|
window.ObjectByName("btnAdd").On("clicked", func() {
|
|
|
|
slides.addCell()
|
|
|
|
})
|
|
|
|
|
2016-03-11 14:30:04 -08:00
|
|
|
window.ObjectByName("btnRem").On("clicked", func() {
|
|
|
|
slides[len(slides)-1].remove()
|
|
|
|
})
|
|
|
|
|
|
|
|
window.ObjectByName("btnMem").On("clicked", func() {
|
2016-03-23 19:52:46 -07:00
|
|
|
//run GC
|
2016-03-11 14:30:04 -08:00
|
|
|
debug.FreeOSMemory()
|
|
|
|
})
|
|
|
|
|
2016-02-17 14:55:29 -08:00
|
|
|
window.On("closing", func() {
|
2016-03-23 19:52:46 -07:00
|
|
|
//close glfw first
|
2016-03-18 10:21:14 -07:00
|
|
|
if false == window.Property("cls") {
|
|
|
|
win.SetShouldClose(true)
|
|
|
|
window.Set("cls", true)
|
|
|
|
}
|
2016-02-17 14:55:29 -08:00
|
|
|
|
|
|
|
})
|
2016-02-18 15:12:22 -08:00
|
|
|
|
2016-03-21 08:49:06 -07:00
|
|
|
window.ObjectByName("mnuEdit").On("triggered", func() {
|
|
|
|
(&quickEdit).Toggle()
|
|
|
|
})
|
|
|
|
|
2016-02-01 17:04:11 -08:00
|
|
|
textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) {
|
|
|
|
var (
|
2016-02-03 16:14:11 -08:00
|
|
|
str string
|
2016-02-17 14:55:29 -08:00
|
|
|
cel *cell
|
2016-02-01 17:04:11 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
if !focus {
|
2016-03-23 19:52:46 -07:00
|
|
|
//set text back to the cell
|
2016-02-01 17:04:11 -08:00
|
|
|
str = textEdit.ObjectByName("textEdit1").String("text")
|
|
|
|
cel = slides[textEdit.Int("cell")]
|
2016-02-17 14:55:29 -08:00
|
|
|
if textEdit.Bool("txt") {
|
|
|
|
cel.qmlcell.ObjectByName("cellText").Set("text", str)
|
|
|
|
cel.text = str
|
|
|
|
}
|
2016-02-01 17:04:11 -08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//getImage() from imagick to image.RGBA
|
|
|
|
func (cl cell) getImage(width, height int) (img *image.RGBA) {
|
2016-03-11 14:30:04 -08:00
|
|
|
mw := cl.img.GetImage()
|
2016-03-23 19:52:46 -07:00
|
|
|
if (width == 0) || (height == 0) {
|
|
|
|
width = int(mw.GetImageWidth())
|
|
|
|
height = int(mw.GetImageHeight())
|
2016-03-07 08:54:14 -08:00
|
|
|
}
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
mw = resizeImage(mw, width, height, true, true)
|
|
|
|
img = image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
|
2016-03-07 08:54:14 -08:00
|
|
|
if img.Stride != img.Rect.Size().X*4 {
|
|
|
|
panic("unsupported stride")
|
|
|
|
}
|
2016-03-15 10:21:59 -07:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
Tpix, _ := mw.ExportImagePixels(0, 0, uint(width), uint(height), "RGBA", imagick.PIXEL_CHAR)
|
2016-03-07 08:54:14 -08:00
|
|
|
img.Pix = Tpix.([]uint8)
|
2016-03-15 10:21:59 -07:00
|
|
|
mw.Destroy()
|
2016-03-07 08:54:14 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//signals for the cell and image in qml
|
2016-02-01 17:04:11 -08:00
|
|
|
func (cl *cell) setSignal() {
|
2016-03-21 08:49:06 -07:00
|
|
|
cl.qmlcell.ObjectByName("cellMouse").On("clicked", func(musEvent qml.Object) {
|
|
|
|
btn := musEvent.Property("button")
|
2016-03-23 19:52:46 -07:00
|
|
|
//right click
|
2016-03-21 08:49:06 -07:00
|
|
|
if btn == 2 {
|
2016-03-23 19:52:46 -07:00
|
|
|
//context menu
|
2016-03-21 10:22:52 -07:00
|
|
|
window.ObjectByName("mnuCtx").Call("popup")
|
|
|
|
rhtClkCell = cl.index
|
2016-03-21 08:49:06 -07:00
|
|
|
} else {
|
2016-03-23 19:52:46 -07:00
|
|
|
//left click
|
|
|
|
//select and update image preview for cell
|
|
|
|
selCell = cl.qmlcell.Int("index")
|
2016-03-21 08:49:06 -07:00
|
|
|
cl.qmlcell.ObjectByName("cellMouse").Set("focus", true)
|
|
|
|
setupScene()
|
|
|
|
}
|
2016-03-23 19:52:46 -07:00
|
|
|
//update image preview
|
2016-03-21 22:03:46 -07:00
|
|
|
cl.clearcache()
|
2016-03-16 10:23:15 -07:00
|
|
|
})
|
|
|
|
|
2016-03-17 09:41:21 -07:00
|
|
|
cl.qmlcell.ObjectByName("cellMouse").On("focusChanged", func(focus bool) {
|
|
|
|
if focus {
|
|
|
|
cl.qmlcell.ObjectByName("cellMouse").Call("selected")
|
|
|
|
} else {
|
|
|
|
cl.qmlcell.ObjectByName("cellMouse").Call("notSelected")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-01-19 21:12:11 -08:00
|
|
|
cl.qmlcell.ObjectByName("cellMouse").On("doubleClicked", func() {
|
2016-03-21 08:49:06 -07:00
|
|
|
if quickEdit {
|
2016-03-23 19:52:46 -07:00
|
|
|
//cover the cell with the text edit
|
2016-03-21 08:49:06 -07:00
|
|
|
textEdit.Set("cell", cl.index)
|
|
|
|
textEdit.Set("x", cl.qmlcell.Int("x"))
|
|
|
|
textEdit.Set("y", cl.qmlcell.Int("y"))
|
|
|
|
textEdit.Set("height", cl.qmlcell.Int("height"))
|
|
|
|
textEdit.Set("z", 100)
|
|
|
|
textEdit.Set("visible", true)
|
|
|
|
textEdit.ObjectByName("textEdit1").Set("focus", true)
|
|
|
|
textEdit.Set("enabled", true)
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//set the text
|
2016-03-21 08:49:06 -07:00
|
|
|
textEdit.ObjectByName("textEdit1").Set("text", cl.text)
|
|
|
|
}
|
2016-01-20 18:18:43 -08:00
|
|
|
})
|
2016-02-01 17:04:11 -08:00
|
|
|
|
2016-01-19 21:12:11 -08:00
|
|
|
}
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//clear cache dosen't actually clear the cache
|
|
|
|
//just gives a new source so that the cache isn't used
|
2016-03-21 22:03:46 -07:00
|
|
|
func (cl *cell) clearcache() {
|
|
|
|
str := cl.qmlimg.String("source")
|
|
|
|
//fmt.Println("source (click): ", str)
|
|
|
|
i := strings.Index(str, `;`)
|
|
|
|
str1 := str[:i]
|
|
|
|
//fmt.Println("ext (click): ", str1)
|
|
|
|
i1, _ := strconv.Atoi(str[i+1:])
|
|
|
|
str = str1 + `;` + strconv.Itoa(i1+1)
|
|
|
|
//fmt.Println("new source (click): ", str)
|
|
|
|
cl.qmlimg.Set("source", str)
|
|
|
|
}
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//Adds a new cell
|
2016-01-15 15:18:02 -08:00
|
|
|
func (sl *slide) addCell( /*cl *cell*/ ) {
|
|
|
|
var cl cell
|
2016-03-23 19:52:46 -07:00
|
|
|
//gets the length so that the index is valid
|
2016-03-07 08:54:14 -08:00
|
|
|
cl.index = len(*sl)
|
2016-03-23 19:52:46 -07:00
|
|
|
|
|
|
|
//increase count on parent QML element
|
2016-03-08 10:23:04 -08:00
|
|
|
window.ObjectByName("gridRect").Set("count", window.ObjectByName("gridRect").Int("count")+1)
|
2016-01-14 22:25:53 -08:00
|
|
|
cl.qmlcell = cellQml.Create(nil)
|
2016-03-07 08:54:14 -08:00
|
|
|
cl.qmlcell.Set("objectName", fmt.Sprintf("cellRect%d", len(*sl)))
|
2016-01-19 21:12:11 -08:00
|
|
|
cl.qmlcell.Set("parent", window.ObjectByName("data1"))
|
2016-03-07 08:54:14 -08:00
|
|
|
cl.qmlcell.Set("index", cl.index)
|
2016-01-19 21:12:11 -08:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//load image
|
2016-03-11 14:30:04 -08:00
|
|
|
cl.img = imagick.NewMagickWand()
|
|
|
|
cl.img.ReadImage("logo:")
|
2016-01-21 10:11:16 -08:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//give QML the text
|
2016-01-19 21:12:11 -08:00
|
|
|
cl.qmlcell.ObjectByName("cellText").Set("text", cl.text)
|
2016-03-23 19:52:46 -07:00
|
|
|
|
|
|
|
//keep the pointer/dereference (i'm not sure which it is)
|
|
|
|
//problems occur otherwise
|
2016-02-17 14:55:29 -08:00
|
|
|
*sl = append(*sl, &cl)
|
2016-02-01 17:04:11 -08:00
|
|
|
cl.setSignal()
|
2016-01-19 21:12:11 -08:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//seperate image object in QML
|
2016-03-07 08:54:14 -08:00
|
|
|
cl.qmlimg = qimg.Create(nil)
|
2016-03-21 22:03:46 -07:00
|
|
|
fmt.Println("index", cl.index)
|
|
|
|
fmt.Printf("objectName: %s\n", fmt.Sprintf("cellImg%d", cl.index))
|
2016-03-07 08:54:14 -08:00
|
|
|
cl.qmlimg.Set("objectName", fmt.Sprintf("cellImg%d", cl.index))
|
2016-03-21 22:03:46 -07:00
|
|
|
cl.qmlimg.Set("source", fmt.Sprintf("image://images/%d"+`;`+"0", cl.index))
|
|
|
|
fmt.Println("source: ", cl.qmlimg.String("source"))
|
2016-03-07 08:54:14 -08:00
|
|
|
cl.qmlimg.Set("parent", window.ObjectByName("data2"))
|
|
|
|
cl.qmlimg.Set("index", cl.index)
|
|
|
|
|
2016-01-19 21:12:11 -08:00
|
|
|
}
|
2016-01-14 22:25:53 -08:00
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//remove() should destroy everything
|
2016-03-11 14:30:04 -08:00
|
|
|
func (cl *cell) remove() {
|
|
|
|
cl.text = ""
|
|
|
|
cl.qmlimg.Destroy()
|
|
|
|
cl.qmlcell.Destroy()
|
2016-03-15 10:21:59 -07:00
|
|
|
cl.img.Destroy()
|
2016-03-11 14:30:04 -08:00
|
|
|
window.ObjectByName("gridRect").Set("count", window.ObjectByName("gridRect").Int("count")-1)
|
|
|
|
slides.remove(cl.index)
|
|
|
|
cl.index = -1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//(slide) remove copied from gist on github
|
2016-03-11 14:30:04 -08:00
|
|
|
func (sl *slide) remove(i int) {
|
|
|
|
*sl, (*sl)[len((*sl))-1] = append((*sl)[:i], (*sl)[i+1:]...), nil
|
|
|
|
}
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//lazy wanted a toggle func
|
2016-03-21 08:49:06 -07:00
|
|
|
func (bl *Bool) Toggle() {
|
|
|
|
if *bl == false {
|
|
|
|
*bl = true
|
|
|
|
} else {
|
|
|
|
*bl = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 19:52:46 -07:00
|
|
|
//not really needed
|
2016-01-19 21:12:11 -08:00
|
|
|
func (cl cell) String() string {
|
2016-01-21 10:11:16 -08:00
|
|
|
return fmt.Sprintf("Index: %d \nText: %s\n", cl.index, cl.text)
|
2016-01-14 22:25:53 -08:00
|
|
|
}
|