Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pixel
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nproject
pixel
Commits
30681534
Commit
30681534
authored
8 years ago
by
faiface
Browse files
Options
Downloads
Patches
Plain Diff
add Canvas.SetComposeMethod
parent
c1d00085
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pixelgl/canvas.go
+36
-1
36 additions, 1 deletion
pixelgl/canvas.go
with
36 additions
and
1 deletion
pixelgl/canvas.go
+
36
−
1
View file @
30681534
...
...
@@ -19,11 +19,14 @@ type Canvas struct {
gf
*
GLFrame
shader
*
glhf
.
Shader
cmp
pixel
.
ComposeMethod
mat
mgl32
.
Mat3
col
mgl32
.
Vec4
smooth
bool
}
var
_
pixel
.
ComposeTarget
=
(
*
Canvas
)(
nil
)
// NewCanvas creates a new empty, fully transparent Canvas with given bounds. If the smooth flag is
// set, then stretched Pictures will be smoothed and will not be drawn pixely onto this Canvas.
func
NewCanvas
(
bounds
pixel
.
Rect
,
smooth
bool
)
*
Canvas
{
...
...
@@ -107,6 +110,12 @@ func (c *Canvas) SetColorMask(col color.Color) {
}
}
// SetComposeMethod sets a Porter-Duff composition method to be used in the following draws onto
// this Canvas.
func
(
c
*
Canvas
)
SetComposeMethod
(
cmp
pixel
.
ComposeMethod
)
{
c
.
cmp
=
cmp
}
// SetBounds resizes the Canvas to the new bounds. Old content will be preserved.
func
(
c
*
Canvas
)
SetBounds
(
bounds
pixel
.
Rect
)
{
c
.
gf
.
SetBounds
(
bounds
)
...
...
@@ -135,6 +144,32 @@ func (c *Canvas) setGlhfBounds() {
glhf
.
Bounds
(
bx
,
by
,
bw
,
bh
)
}
// must be manually called inside mainthread
func
(
c
*
Canvas
)
setBlendFunc
()
{
switch
c
.
cmp
{
case
pixel
.
ComposeOver
:
glhf
.
BlendFunc
(
glhf
.
One
,
glhf
.
OneMinusSrcAlpha
)
case
pixel
.
ComposeIn
:
glhf
.
BlendFunc
(
glhf
.
DstAlpha
,
glhf
.
Zero
)
case
pixel
.
ComposeOut
:
glhf
.
BlendFunc
(
glhf
.
OneMinusDstAlpha
,
glhf
.
Zero
)
case
pixel
.
ComposeAtop
:
glhf
.
BlendFunc
(
glhf
.
DstAlpha
,
glhf
.
OneMinusSrcAlpha
)
case
pixel
.
ComposeDstOver
:
glhf
.
BlendFunc
(
glhf
.
OneMinusDstAlpha
,
glhf
.
One
)
case
pixel
.
ComposeDstIn
:
glhf
.
BlendFunc
(
glhf
.
Zero
,
glhf
.
SrcAlpha
)
case
pixel
.
ComposeDstOut
:
glhf
.
BlendFunc
(
glhf
.
Zero
,
glhf
.
OneMinusSrcAlpha
)
case
pixel
.
ComposeDstAtop
:
glhf
.
BlendFunc
(
glhf
.
OneMinusDstAlpha
,
glhf
.
SrcAlpha
)
case
pixel
.
ComposeXor
:
glhf
.
BlendFunc
(
glhf
.
OneMinusDstAlpha
,
glhf
.
OneMinusSrcAlpha
)
default
:
panic
(
errors
.
New
(
"Canvas: invalid compose method"
))
}
}
// Clear fills the whole Canvas with a single color.
func
(
c
*
Canvas
)
Clear
(
color
color
.
Color
)
{
c
.
gf
.
Dirty
()
...
...
@@ -188,7 +223,7 @@ func (ct *canvasTriangles) draw(tex *glhf.Texture, bounds pixel.Rect) {
mainthread
.
CallNonBlock
(
func
()
{
ct
.
dst
.
setGlhfBounds
()
glhf
.
BlendFunc
(
glhf
.
One
,
glhf
.
OneMinusSrcAlpha
)
ct
.
dst
.
setBlendFunc
(
)
frame
:=
ct
.
dst
.
gf
.
Frame
()
shader
:=
ct
.
dst
.
shader
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment