gg icon indicating copy to clipboard operation
gg copied to clipboard

Context SetTransform / GetTransform / ApplyTransform

Open bit101 opened this issue 3 years ago • 0 comments

The Context struct has a matrix property and various methods to manipulate that matrix. But although you can create a new Matrix, there is no way to apply a matrix to the context in one shot. Other packages I've used in the past have had one method such as SetTransform which replaces the current transform matrix with a new matrix, and ApplyTransform which applies a full matrix as an additional transform to the current matrix. As well as a method to get the current transform.

I believe this would be as simple as:

func (dc *Context) SetTransform(matrix gg.Matrix) {
	dc.matrix = matrix
}

func (dc *Context) ApplyTransform(matrix gg.Matrix) {
	dc.matrix = dc.matrix.Multiply(matrix)
}

func (dc *Context) GetTransform() gg.Matrix {
        return dc.matrix
}

Though I might have gotten the order reversed in the second one.

The Get and Set methods would be the most useful and if you had those, you could roll your own Apply method.

bit101 avatar Jul 13 '22 21:07 bit101