make glfw close first

fix other stuff....
This commit is contained in:
lordwelch 2016-02-17 14:55:29 -08:00
parent 0461807287
commit 03e816356c
4 changed files with 113 additions and 49 deletions

View File

@ -2,7 +2,6 @@
package main package main
import ( import (
"fmt"
"math" "math"
"github.com/gographics/imagick/imagick" "github.com/gographics/imagick/imagick"
@ -13,7 +12,7 @@ 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") //fmt.Println("hahahahahah :-P")
origWidth = int(mw.GetImageWidth()) origWidth = int(mw.GetImageWidth())
if (origHeight != newHeight) || (origWidth != newWidth) { if (origHeight != newHeight) || (origWidth != newWidth) {
@ -35,7 +34,7 @@ func resizeImage(mw *imagick.MagickWand, newWidth, newHeight int, keepSpecSize,
center = false center = false
} else { } else {
resmw.NewImage(uint(newWidth), uint(newHeight), imagick.NewPixelWand()) resmw.NewImage(uint(newWidth), uint(newHeight), imagick.NewPixelWand())
fmt.Println(resmw.GetImageHeight(), resmw.GetImageWidth()) //fmt.Println(resmw.GetImageHeight(), resmw.GetImageWidth())
if center { if center {
err = mw.ResizeImage(uint(width), uint(height), imagick.FILTER_LANCZOS, 1) err = mw.ResizeImage(uint(width), uint(height), imagick.FILTER_LANCZOS, 1)
if err != nil { if err != nil {

74
main.go
View File

@ -1,8 +1,6 @@
// PresentationApp project main.go // PresentationApp project main.go
package main package main
import "C"
import ( import (
"fmt" "fmt"
"image" "image"
@ -18,25 +16,26 @@ import (
) )
type cell struct { type cell struct {
text string text string
//img image.Image img image.RGBA
qmlcell qml.Object qmlcell qml.Object
index int index int
} }
type slide []cell type slide []*cell
var ( var (
x, y int x, y int
path string path string
textEdit qml.Object textEdit qml.Object
cellQml qml.Object cellQml qml.Object
window *qml.Window window *qml.Window
win *glfw.Window win *glfw.Window
slides slide slides slide
err error err error
monitors []*glfw.Monitor monitors []*glfw.Monitor
mw1 *imagick.MagickWand projMonitor *glfw.Monitor
tex1 uint32 mw1, mw2 *imagick.MagickWand
tex1 uint32
//drawSlide func() //drawSlide func()
) )
@ -48,6 +47,7 @@ func main() {
} }
defer glfw.Terminate() defer glfw.Terminate()
fmt.Println("test")
} }
@ -88,19 +88,19 @@ func run() error {
setSignals() setSignals()
window.Show() window.Show()
qml.RunMain(func() { qml.RunMain(glInit)
glInit()
})
window.Wait() window.Wait()
mw1.Destroy() //win.Destroy()
mw2.Destroy()
imagick.Terminate()
return nil return nil
} }
func setupScene() { func setupScene() {
gl.ClearColor(0.1, 0.5, 0.9, 0.0) gl.ClearColor(0.1, 0.5, 0.9, 0.0)
mw2 := resizeImage(mw1, x, y, true, true) mw2 = resizeImage(mw1, x, y, true, true)
tex1 = newTexture(*mw2) tex1 = newTexture(*mw2)
@ -172,10 +172,13 @@ func checkMon() {
glfw.WindowHint(glfw.Decorated, glfw.False) glfw.WindowHint(glfw.Decorated, glfw.False)
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")
win, err = glfw.CreateWindow(600, 800, "Cube", nil, nil) x = 800
y = 600
win, err = glfw.CreateWindow(x, y, "Cube", nil, nil)
if err != nil { if err != nil {
panic(err) panic(err)
} }
projMonitor = monitors[0]
} else { } else {
fmt.Printf("You have %d monitors\n", i) fmt.Printf("You have %d monitors\n", i)
x = monitors[1].GetVideoMode().Width x = monitors[1].GetVideoMode().Width
@ -187,6 +190,7 @@ func checkMon() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
projMonitor = monitors[1]
} }
monitorInfo() monitorInfo()
@ -213,7 +217,7 @@ func glInit() {
panic(err) panic(err)
} }
setupScene() setupScene()
win.SetPos(monitors[1].GetPos()) win.SetPos(projMonitor.GetPos())
qml.Func1 = func() int { qml.Func1 = func() int {
if !win.ShouldClose() { if !win.ShouldClose() {
@ -223,7 +227,7 @@ func glInit() {
return 0 return 0
} else { } else {
win.Hide() win.Hide()
win.Destroy()
return 1 return 1
} }
} }
@ -231,16 +235,29 @@ func glInit() {
} }
func setSignals() { func setSignals() {
window.On("closing", func() {
fmt.Println(window.Bool("cls"))
win.Hide()
//win.Destroy()
window.Set("cls", true)
})
textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) { textEdit.ObjectByName("textEdit1").On("focusChanged", func(focus bool) {
var ( var (
str string str string
cel cell cel *cell
) )
if !focus { if !focus {
str = textEdit.ObjectByName("textEdit1").String("text") str = textEdit.ObjectByName("textEdit1").String("text")
cel = slides[textEdit.Int("cell")] cel = slides[textEdit.Int("cell")]
cel.qmlcell.ObjectByName("cellText").Set("text", str) if textEdit.Bool("txt") {
cel.qmlcell.ObjectByName("cellText").Set("text", str)
//fmt.Println("haha.....:-P")
cel.text = str
//fmt.Println("----->"+cel.text, str, textEdit.Int("cell"))
}
} }
}) })
@ -249,6 +266,7 @@ func setSignals() {
func (cl *cell) setSignal() { func (cl *cell) setSignal() {
cl.qmlcell.ObjectByName("cellMouse").On("doubleClicked", func() { cl.qmlcell.ObjectByName("cellMouse").On("doubleClicked", func() {
cellText := cl.qmlcell.ObjectByName("cellText") cellText := cl.qmlcell.ObjectByName("cellText")
textEdit.Set("cell", cl.index) textEdit.Set("cell", cl.index)
textEdit.Set("x", cellText.Int("x")+4) textEdit.Set("x", cellText.Int("x")+4)
textEdit.Set("y", cellText.Int("y")+4) textEdit.Set("y", cellText.Int("y")+4)
@ -258,6 +276,8 @@ func (cl *cell) setSignal() {
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)
textEdit.ObjectByName("textEdit1").Set("text", cl.text)
}) })
} }
@ -273,7 +293,7 @@ func (sl *slide) addCell( /*cl *cell*/ ) {
cl.text = "testing 1... 2... 3..." cl.text = "testing 1... 2... 3..."
cl.qmlcell.ObjectByName("cellText").Set("text", cl.text) cl.qmlcell.ObjectByName("cellText").Set("text", cl.text)
*sl = append(*sl, cl) *sl = append(*sl, &cl)
cl.setSignal() cl.setSignal()

View File

@ -12,7 +12,12 @@ ApplicationWindow {
minimumHeight: 500 minimumHeight: 500
width: 1000 width: 1000
height: 600 height: 600
Screen.objectName: "Screen1" property bool cls: false
//Screen.objectName: "Screen1"
onClosing: if (!cls) {
close.accepted = false
}
AboutDialog { id: aboutDialog } AboutDialog { id: aboutDialog }
Action { Action {
@ -130,23 +135,45 @@ ApplicationWindow {
Rectangle { Rectangle {
id: textEdit id: textEdit
property int cell property int cell
x: 448 x: 232
y: 151 y: 622
objectName: "textEdit" objectName: "textEdit"
width: 200 width: 200
height: 200 height: 200
color: "#ffffff" color: "#ffffff"
visible: false visible: false
Keys.onEscapePressed: { property bool txt: true
x = -100 Keys.onPressed: {
y = -100 if ((event.key == Qt.Key_Return) && (event.modifiers & Qt.ControlModifier)) {
visible = false txt = true
focus = true
enabled = false x = -100
opacity = 0 y = -100
textEdit1.focus = false visible = false
focus = true
enabled = false
opacity = 0
textEdit1.focus = false
event.accepted = true
}
if (event.key == Qt.Key_Escape) {
txt = false
x = -100
y = -100
visible = false
focus = true
enabled = false
opacity = 0
textEdit1.focus = false
event.accepted = true
}
} }
TextArea { TextArea {
id: textEdit1 id: textEdit1
objectName: "textEdit1" objectName: "textEdit1"

View File

@ -6,34 +6,52 @@ Rectangle {
property int index: 0 property int index: 0
width: 100 width: 100
height: 100 height: 100
color: "#00000000" border.width: 2
anchors.right: parent.right anchors.right: parent.right
anchors.left: parent.left anchors.left: parent.left
onFocusChanged: if (focus) {
border.color = "gainsboro"
color = "blue"
}
Text { Text {
id: cellText id: cellText
enabled: true enabled: true
objectName: "cellText" objectName: "cellText"
height: 75
text: "hello this is text\nhaha\nhdsjfklfhaskjd" text: "hello this is text\nhaha\nhdsjfklfhaskjd"
textFormat: Text.AutoText
clip: true clip: true
font.bold: false
anchors.fill: parent
wrapMode: Text.WrapAtWordBoundaryOrAnywhere wrapMode: Text.WrapAtWordBoundaryOrAnywhere
horizontalAlignment: Text.AlignLeft anchors.fill: parent
verticalAlignment: Text.AlignTop
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 0 anchors.rightMargin: 0
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 0 anchors.leftMargin: 0
font.pixelSize: 12 onFocusChanged: if (focus) {
parent.border.color = "gainsboro"
parent.color = "blue"
}
MouseArea { MouseArea {
id: cellMouse id: cellMouse
hoverEnabled: true
enabled: true enabled: true
objectName: "cellMouse" objectName: "cellMouse"
anchors.fill: parent anchors.fill: parent
onFocusChanged: if (focus) {
parent.parent.border.color = "gainsboro"
parent.parent.color = "blue"
}
onClicked: focus = true
onEntered: if (containsMouse) {
parent.parent.border.color = "skyblue"
parent.parent.color = "darkblue"
parent.color = "white"
}
onExited: {
parent.parent.border.color = "white"
parent.parent.color = "white"
parent.color = "black"
}
} }
} }
} }