Compare commits
4 Commits
9dc929f545
...
9214f70b61
Author | SHA1 | Date | |
---|---|---|---|
9214f70b61 | |||
36ac66b644 | |||
c13db1217d | |||
c0124bf232 |
12
box.go
12
box.go
@ -339,10 +339,14 @@ func (this *box) Draw (can canvas.Canvas) {
|
|||||||
// centered texture
|
// centered texture
|
||||||
if this.textureMode == textureModeCenter {
|
if this.textureMode == textureModeCenter {
|
||||||
textureBounds := this.texture.Bounds()
|
textureBounds := this.texture.Bounds()
|
||||||
textureOrigin := image.Pt (
|
textureOrigin :=
|
||||||
textureBounds.Dx() / -2,
|
bounds.Min.
|
||||||
textureBounds.Dy() / -2).
|
Add(image.Pt (
|
||||||
Add(bounds.Min)
|
bounds.Dx() / 2,
|
||||||
|
bounds.Dy() / 2)).
|
||||||
|
Sub(image.Pt (
|
||||||
|
textureBounds.Dx() / 2,
|
||||||
|
textureBounds.Dy() / 2))
|
||||||
|
|
||||||
pen.Fill(color.Transparent)
|
pen.Fill(color.Transparent)
|
||||||
pen.Texture(this.texture)
|
pen.Texture(this.texture)
|
||||||
|
18
examples/blank/main.go
Normal file
18
examples/blank/main.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "image"
|
||||||
|
import "git.tebibyte.media/tomo/x"
|
||||||
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
|
|
||||||
|
func main () {
|
||||||
|
tomo.Register(0, x.NewBackend)
|
||||||
|
err := tomo.Run(run)
|
||||||
|
if err != nil { panic(err) }
|
||||||
|
}
|
||||||
|
|
||||||
|
func run () {
|
||||||
|
window, err := tomo.NewWindow(image.Rect(0, 0, 200, 300))
|
||||||
|
if err != nil { panic(err) }
|
||||||
|
window.OnClose(tomo.Stop)
|
||||||
|
window.SetVisible(true)
|
||||||
|
}
|
29
examples/text/main.go
Normal file
29
examples/text/main.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "image"
|
||||||
|
import "image/color"
|
||||||
|
import "git.tebibyte.media/tomo/x"
|
||||||
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
|
import "golang.org/x/image/font/basicfont"
|
||||||
|
|
||||||
|
func main () {
|
||||||
|
tomo.Register(0, x.NewBackend)
|
||||||
|
err := tomo.Run(run)
|
||||||
|
if err != nil { panic(err) }
|
||||||
|
}
|
||||||
|
|
||||||
|
func run () {
|
||||||
|
window, err := tomo.NewWindow(image.Rectangle { })
|
||||||
|
if err != nil { panic(err) }
|
||||||
|
|
||||||
|
text := tomo.NewTextBox()
|
||||||
|
text.SetText("hello, world!")
|
||||||
|
text.SetTextColor(color.White)
|
||||||
|
text.SetColor(color.Black)
|
||||||
|
text.SetFace(basicfont.Face7x13)
|
||||||
|
text.SetPadding(tomo.I(8))
|
||||||
|
window.SetRoot(text)
|
||||||
|
|
||||||
|
window.OnClose(tomo.Stop)
|
||||||
|
window.SetVisible(true)
|
||||||
|
}
|
83
examples/texture/main.go
Normal file
83
examples/texture/main.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
import "image"
|
||||||
|
import "math/rand"
|
||||||
|
import "image/color"
|
||||||
|
import "git.tebibyte.media/tomo/x"
|
||||||
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
|
|
||||||
|
func main () {
|
||||||
|
tomo.Register(0, x.NewBackend)
|
||||||
|
err := tomo.Run(run)
|
||||||
|
if err != nil { panic(err) }
|
||||||
|
}
|
||||||
|
|
||||||
|
func run () {
|
||||||
|
window, err := tomo.NewWindow(image.Rect(0, 0, 256, 256))
|
||||||
|
if err != nil { panic(err) }
|
||||||
|
|
||||||
|
texture := tomo.NewTexture(coolTexture())
|
||||||
|
|
||||||
|
box := tomo.NewBox()
|
||||||
|
box.SetColor(color.Black)
|
||||||
|
box.SetTextureCenter(texture)
|
||||||
|
box.SetBorder (
|
||||||
|
tomo.Border {
|
||||||
|
Color: [4] color.Color {
|
||||||
|
color.Black, color.Black,
|
||||||
|
color.Black, color.Black },
|
||||||
|
Width: tomo.I(2),
|
||||||
|
},
|
||||||
|
tomo.Border {
|
||||||
|
Color: [4] color.Color {
|
||||||
|
color.White, color.White,
|
||||||
|
color.White, color.White },
|
||||||
|
Width: tomo.I(2),
|
||||||
|
})
|
||||||
|
|
||||||
|
window.SetRoot(box)
|
||||||
|
window.OnClose(tomo.Stop)
|
||||||
|
window.SetVisible(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func coolTexture () image.Image {
|
||||||
|
// this picture IS COOL because i spent AN HOUR on it when i could have
|
||||||
|
// been FIXING BUGS!
|
||||||
|
speedX := 0.015
|
||||||
|
speedY := 0.035
|
||||||
|
bitmap := image.NewRGBA (image.Rect(0, 0, 200, 200))
|
||||||
|
for y := bitmap.Bounds().Min.Y; y < bitmap.Bounds().Max.Y; y++ {
|
||||||
|
for x := bitmap.Bounds().Min.X; x < bitmap.Bounds().Max.X; x++ {
|
||||||
|
value := ((
|
||||||
|
math.Sin(float64(y) * speedY) +
|
||||||
|
math.Cos(float64(x) * speedX)) + 2) / 4
|
||||||
|
value *= 0.7
|
||||||
|
|
||||||
|
r := value * 0.7 + 0.3
|
||||||
|
g := math.Sin(value * 7) * 0.7
|
||||||
|
b := (1 - value) * 0.7
|
||||||
|
|
||||||
|
noise := math.Mod(rand.Float64(), 1)
|
||||||
|
noise = math.Pow(noise, 2) + noise * 0.5
|
||||||
|
noise *= 0.05
|
||||||
|
|
||||||
|
channel := func (f float64) uint8 {
|
||||||
|
contrast := 1.4
|
||||||
|
f = f * (contrast) - ((contrast - 1) / 2)
|
||||||
|
|
||||||
|
if f < 0 { f = 0 }
|
||||||
|
if f > 1 { f = 1 }
|
||||||
|
|
||||||
|
return uint8(f * 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
bitmap.Set(x, y, color.RGBA {
|
||||||
|
R: channel(r + noise),
|
||||||
|
G: channel(g + noise),
|
||||||
|
B: channel(b + noise),
|
||||||
|
A: 255,
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
return bitmap
|
||||||
|
}
|
@ -241,7 +241,9 @@ func (window *window) afterEvent () {
|
|||||||
// set child bounds
|
// set child bounds
|
||||||
childBounds := window.metrics.bounds
|
childBounds := window.metrics.bounds
|
||||||
childBounds = childBounds.Sub(childBounds.Min)
|
childBounds = childBounds.Sub(childBounds.Min)
|
||||||
window.root.SetBounds(childBounds)
|
if window.root != nil {
|
||||||
|
window.root.SetBounds(childBounds)
|
||||||
|
}
|
||||||
|
|
||||||
// full relayout/redraw
|
// full relayout/redraw
|
||||||
if window.root != nil {
|
if window.root != nil {
|
||||||
|
Reference in New Issue
Block a user