added a SetBounds function to replace the SetSize function
This commit is contained in:
parent
447d83e9f0
commit
1cd53a4e6b
6 changed files with 19 additions and 12 deletions
20
canvas.go
20
canvas.go
|
@ -96,12 +96,8 @@ const (
|
||||||
// the origin, since GL uses the bottom left coordinate, the
|
// the origin, since GL uses the bottom left coordinate, the
|
||||||
// coordinates given here also use the bottom left as origin
|
// coordinates given here also use the bottom left as origin
|
||||||
func New(x, y, w, h int) *Canvas {
|
func New(x, y, w, h int) *Canvas {
|
||||||
cv := &Canvas{
|
cv := &Canvas{stateStack: make([]drawState, 0, 20)}
|
||||||
x: x, y: y, w: w, h: h,
|
cv.SetBounds(x, y, w, h)
|
||||||
fx: float64(x), fy: float64(y),
|
|
||||||
fw: float64(w), fh: float64(h),
|
|
||||||
stateStack: make([]drawState, 0, 20),
|
|
||||||
}
|
|
||||||
cv.state.lineWidth = 1
|
cv.state.lineWidth = 1
|
||||||
cv.state.globalAlpha = 1
|
cv.state.globalAlpha = 1
|
||||||
cv.state.fill.color = glColor{a: 1}
|
cv.state.fill.color = glColor{a: 1}
|
||||||
|
@ -112,12 +108,24 @@ func New(x, y, w, h int) *Canvas {
|
||||||
|
|
||||||
// SetSize changes the internal size of the canvas. This would
|
// SetSize changes the internal size of the canvas. This would
|
||||||
// usually be called for example when the window is resized
|
// usually be called for example when the window is resized
|
||||||
|
//
|
||||||
|
// Deprecated: Use SetBounds instead
|
||||||
func (cv *Canvas) SetSize(w, h int) {
|
func (cv *Canvas) SetSize(w, h int) {
|
||||||
cv.w, cv.h = w, h
|
cv.w, cv.h = w, h
|
||||||
cv.fw, cv.fh = float64(w), float64(h)
|
cv.fw, cv.fh = float64(w), float64(h)
|
||||||
activeCanvas = nil
|
activeCanvas = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetBounds updates the bounds of the canvas. This would
|
||||||
|
// usually be called for example when the window is resized
|
||||||
|
func (cv *Canvas) SetBounds(x, y, w, h int) {
|
||||||
|
cv.x, cv.y = x, y
|
||||||
|
cv.w, cv.h = w, h
|
||||||
|
cv.fx, cv.fy = float64(x), float64(y)
|
||||||
|
cv.fw, cv.fh = float64(w), float64(h)
|
||||||
|
activeCanvas = nil
|
||||||
|
}
|
||||||
|
|
||||||
// Width returns the internal width of the canvas
|
// Width returns the internal width of the canvas
|
||||||
func (cv *Canvas) Width() int { return cv.w }
|
func (cv *Canvas) Width() int { return cv.w }
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,7 @@ func OnSurfaceChanged(w, h int) {
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cv = canvas.New(0, 0, 0, 0)
|
cv = canvas.New(0, 0, w, h)
|
||||||
cv.SetSize(w, h)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnDrawFrame() {
|
func OnDrawFrame() {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func main() {
|
||||||
rg.AddColorStop(0.5, "#0000ff")
|
rg.AddColorStop(0.5, "#0000ff")
|
||||||
|
|
||||||
wnd.SizeChange = func(w, h int) {
|
wnd.SizeChange = func(w, h int) {
|
||||||
cv.SetSize(w, h)
|
cv.SetBounds(0, 0, w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
wnd.MainLoop(func() {
|
wnd.MainLoop(func() {
|
||||||
|
|
|
@ -44,7 +44,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wnd.SizeChange = func(w, h int) {
|
wnd.SizeChange = func(w, h int) {
|
||||||
cv.SetSize(w, h)
|
cv.SetBounds(0, 0, w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTime := time.Now()
|
lastTime := time.Now()
|
||||||
|
|
|
@ -60,7 +60,7 @@ func main() {
|
||||||
|
|
||||||
// set canvas size
|
// set canvas size
|
||||||
ww, wh := window.GetSize()
|
ww, wh := window.GetSize()
|
||||||
cv.SetSize(ww, wh)
|
cv.SetBounds(0, 0, ww, wh)
|
||||||
|
|
||||||
// call the run function to do all the drawing
|
// call the run function to do all the drawing
|
||||||
run(cv, float64(ww), float64(wh))
|
run(cv, float64(ww), float64(wh))
|
||||||
|
|
|
@ -101,7 +101,7 @@ func main() {
|
||||||
|
|
||||||
// set canvas size
|
// set canvas size
|
||||||
ww, wh := window.GetSize()
|
ww, wh := window.GetSize()
|
||||||
cv.SetSize(int(ww), int(wh))
|
cv.SetBounds(0, 0, int(ww), int(wh))
|
||||||
|
|
||||||
// call the run function to do all the drawing
|
// call the run function to do all the drawing
|
||||||
run(cv, float64(ww), float64(wh))
|
run(cv, float64(ww), float64(wh))
|
||||||
|
|
Loading…
Reference in a new issue