added a SetBounds function to replace the SetSize function

This commit is contained in:
Thomas Friedel 2018-05-28 16:04:13 +02:00
parent 447d83e9f0
commit 1cd53a4e6b
6 changed files with 19 additions and 12 deletions

View file

@ -96,12 +96,8 @@ const (
// the origin, since GL uses the bottom left coordinate, the
// coordinates given here also use the bottom left as origin
func New(x, y, w, h int) *Canvas {
cv := &Canvas{
x: x, y: y, w: w, h: h,
fx: float64(x), fy: float64(y),
fw: float64(w), fh: float64(h),
stateStack: make([]drawState, 0, 20),
}
cv := &Canvas{stateStack: make([]drawState, 0, 20)}
cv.SetBounds(x, y, w, h)
cv.state.lineWidth = 1
cv.state.globalAlpha = 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
// usually be called for example when the window is resized
//
// Deprecated: Use SetBounds instead
func (cv *Canvas) SetSize(w, h int) {
cv.w, cv.h = w, h
cv.fw, cv.fh = float64(w), float64(h)
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
func (cv *Canvas) Width() int { return cv.w }

View file

@ -24,8 +24,7 @@ func OnSurfaceChanged(w, h int) {
time.Sleep(100 * time.Millisecond)
panic(err)
}
cv = canvas.New(0, 0, 0, 0)
cv.SetSize(w, h)
cv = canvas.New(0, 0, w, h)
}
func OnDrawFrame() {

View file

@ -28,7 +28,7 @@ func main() {
rg.AddColorStop(0.5, "#0000ff")
wnd.SizeChange = func(w, h int) {
cv.SetSize(w, h)
cv.SetBounds(0, 0, w, h)
}
wnd.MainLoop(func() {

View file

@ -44,7 +44,7 @@ func main() {
}
}
wnd.SizeChange = func(w, h int) {
cv.SetSize(w, h)
cv.SetBounds(0, 0, w, h)
}
lastTime := time.Now()

View file

@ -60,7 +60,7 @@ func main() {
// set canvas size
ww, wh := window.GetSize()
cv.SetSize(ww, wh)
cv.SetBounds(0, 0, ww, wh)
// call the run function to do all the drawing
run(cv, float64(ww), float64(wh))

View file

@ -101,7 +101,7 @@ func main() {
// set canvas size
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
run(cv, float64(ww), float64(wh))