make a cell init func. image now displays text
This commit is contained in:
parent
3c608d3d46
commit
47d2c22b0e
36
imagick.go
36
imagick.go
@ -3,8 +3,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -79,6 +79,10 @@ func (cl *cell) getImage(width, height int) (img *image.RGBA) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mw = resizeImage(mw, width, height, true, true)
|
mw = resizeImage(mw, width, height, true, true)
|
||||||
|
mw1 := cl.imgtext(width, height)
|
||||||
|
mw.CompositeImage(mw1, imagick.COMPOSITE_OP_OVER, 0, 0)
|
||||||
|
mw1.Destroy()
|
||||||
|
|
||||||
img = image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
|
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")
|
||||||
@ -91,9 +95,9 @@ func (cl *cell) getImage(width, height int) (img *image.RGBA) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adding text to image copied from example
|
// adding text to image copied from example
|
||||||
func (cl *cell) imgtext(x, y int) {
|
func (cl *cell) imgtext(width, height int) *imagick.MagickWand {
|
||||||
mw := imagick.NewMagickWand()
|
mw := imagick.NewMagickWand()
|
||||||
defer mw.Destroy()
|
//defer mw.Destroy()
|
||||||
dw := imagick.NewDrawingWand()
|
dw := imagick.NewDrawingWand()
|
||||||
defer dw.Destroy()
|
defer dw.Destroy()
|
||||||
pw := imagick.NewPixelWand()
|
pw := imagick.NewPixelWand()
|
||||||
@ -101,30 +105,35 @@ func (cl *cell) imgtext(x, y int) {
|
|||||||
pw.SetColor("none")
|
pw.SetColor("none")
|
||||||
|
|
||||||
// Create a new transparent image
|
// Create a new transparent image
|
||||||
mw.NewImage(0, 0, pw)
|
mw.NewImage(uint(width), uint(height), pw)
|
||||||
|
|
||||||
// Set up a 72 point white font
|
// Set up a 72 point white font
|
||||||
pw.SetColor(font.textColor)
|
r, g, b, _ := cl.font.color.RGBA()
|
||||||
|
pw.SetColor(fmt.Sprintf("rgb(%d,%d,%d)", r, g, b))
|
||||||
dw.SetFillColor(pw)
|
dw.SetFillColor(pw)
|
||||||
dw.SetFont(font.name)
|
dw.SetFont(cl.font.name)
|
||||||
dw.SetFontSize(font.size)
|
dw.SetFontSize(cl.font.size)
|
||||||
|
|
||||||
|
otlne := "none"
|
||||||
// Add a black outline to the text
|
// Add a black outline to the text
|
||||||
pw.SetColor(font.OutlineColor)
|
r, g, b, _ = cl.font.outlineColor.RGBA()
|
||||||
|
if cl.font.outline {
|
||||||
|
otlne = fmt.Sprintf("rgb(%d,%d,%d)", r, g, b)
|
||||||
|
}
|
||||||
|
|
||||||
|
pw.SetColor(otlne)
|
||||||
dw.SetStrokeColor(pw)
|
dw.SetStrokeColor(pw)
|
||||||
|
dw.SetStrokeWidth(cl.font.outlineSize)
|
||||||
|
|
||||||
// Turn antialias on - not sure this makes a difference
|
// Turn antialias on - not sure this makes a difference
|
||||||
dw.SetTextAntialias(true)
|
//dw.SetTextAntialias(true)
|
||||||
|
|
||||||
// Now draw the text
|
// Now draw the text
|
||||||
dw.Annotation(25, 65, cl.text)
|
dw.Annotation(cl.font.x, cl.font.y, cl.text)
|
||||||
|
|
||||||
// Draw the image on to the mw
|
// Draw the image on to the mw
|
||||||
mw.DrawImage(dw)
|
mw.DrawImage(dw)
|
||||||
|
|
||||||
// Trim the image down to include only the text
|
|
||||||
mw.TrimImage(0)
|
|
||||||
|
|
||||||
// equivalent to the command line +repage
|
// equivalent to the command line +repage
|
||||||
mw.ResetImagePage("")
|
mw.ResetImagePage("")
|
||||||
|
|
||||||
@ -141,6 +150,7 @@ func (cl *cell) imgtext(x, y int) {
|
|||||||
// Composite the text on top of the shadow
|
// Composite the text on top of the shadow
|
||||||
mw.CompositeImage(cw, imagick.COMPOSITE_OP_OVER, 5, 5)
|
mw.CompositeImage(cw, imagick.COMPOSITE_OP_OVER, 5, 5)
|
||||||
cw.Destroy()
|
cw.Destroy()
|
||||||
|
return mw
|
||||||
}
|
}
|
||||||
|
|
||||||
func findfonts() {
|
func findfonts() {
|
||||||
|
35
main.go
35
main.go
@ -24,10 +24,10 @@ type cell struct {
|
|||||||
index int
|
index int
|
||||||
font struct {
|
font struct {
|
||||||
name string
|
name string
|
||||||
size int
|
outlineSize, size, x, y float64
|
||||||
color color.RGBA
|
color color.RGBA
|
||||||
outline float32
|
|
||||||
outlineColor color.RGBA
|
outlineColor color.RGBA
|
||||||
|
outline Bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type slide []*cell
|
type slide []*cell
|
||||||
@ -52,6 +52,7 @@ func main() {
|
|||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
imagick.Initialize()
|
imagick.Initialize()
|
||||||
|
findfonts()
|
||||||
|
|
||||||
engine = qml.NewEngine()
|
engine = qml.NewEngine()
|
||||||
engine.AddImageProvider("images", imgProvider)
|
engine.AddImageProvider("images", imgProvider)
|
||||||
@ -104,6 +105,7 @@ func run() error {
|
|||||||
//Adds a new cell
|
//Adds a new cell
|
||||||
func (sl *slide) add( /*cl *cell*/ ) {
|
func (sl *slide) add( /*cl *cell*/ ) {
|
||||||
var cl cell
|
var cl cell
|
||||||
|
cl.Init()
|
||||||
//gets the length so that the index is valid
|
//gets the length so that the index is valid
|
||||||
cl.index = len(*sl)
|
cl.index = len(*sl)
|
||||||
|
|
||||||
@ -114,19 +116,11 @@ func (sl *slide) add( /*cl *cell*/ ) {
|
|||||||
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.ReadImage("logo:")
|
|
||||||
|
|
||||||
//give QML the text
|
|
||||||
cl.qmlcell.ObjectByName("cellText").Set("text", cl.text)
|
|
||||||
|
|
||||||
//keep the pointer/dereference (i'm not sure which it is)
|
//keep the pointer/dereference (i'm not sure which it is)
|
||||||
//problems occur otherwise
|
//problems occur otherwise
|
||||||
*sl = append(*sl, &cl)
|
*sl = append(*sl, &cl)
|
||||||
|
|
||||||
//seperate image object in QML
|
//seperate image object in QML
|
||||||
cl.qmlimg = qimg.Create(engine.Context())
|
|
||||||
cl.qmlimg.Set("objectName", fmt.Sprintf("cellImg%d", cl.index))
|
cl.qmlimg.Set("objectName", fmt.Sprintf("cellImg%d", cl.index))
|
||||||
cl.qmlimg.Set("source", fmt.Sprintf("image://images/%d"+`;`+"0", cl.index))
|
cl.qmlimg.Set("source", fmt.Sprintf("image://images/%d"+`;`+"0", cl.index))
|
||||||
cl.qmlimg.Set("parent", window.ObjectByName("data2"))
|
cl.qmlimg.Set("parent", window.ObjectByName("data2"))
|
||||||
@ -135,6 +129,27 @@ func (sl *slide) add( /*cl *cell*/ ) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cl *cell) Init() {
|
||||||
|
cl.text = "Testing 1... 2... 3... :-P"
|
||||||
|
cl.index = -1
|
||||||
|
cl.font.color, cl.font.outlineColor = color.RGBA{0, 0, 0, 1}, color.RGBA{1, 1, 1, 1}
|
||||||
|
cl.font.name = fontlst[1]
|
||||||
|
cl.font.outline = false
|
||||||
|
cl.font.outlineSize = 1
|
||||||
|
cl.font.size = 35
|
||||||
|
cl.font.x, cl.font.y = 10, 30
|
||||||
|
|
||||||
|
cl.qmlcell = cellQml.Create(engine.Context())
|
||||||
|
cl.qmlimg = qimg.Create(engine.Context())
|
||||||
|
|
||||||
|
//load image
|
||||||
|
cl.img = imagick.NewMagickWand()
|
||||||
|
cl.img.ReadImage("logo:")
|
||||||
|
|
||||||
|
//give QML the text
|
||||||
|
cl.qmlcell.ObjectByName("cellText").Set("text", cl.text)
|
||||||
|
}
|
||||||
|
|
||||||
//(cell) remove() should destroy everything for this cell
|
//(cell) remove() should destroy everything for this cell
|
||||||
func (cl *cell) remove() {
|
func (cl *cell) remove() {
|
||||||
cl.text = ""
|
cl.text = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user