2014-12-09 15:16:04 +01:00
|
|
|
/*
|
|
|
|
Copyright 2014 Hajime Hoshi
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
package ebiten
|
2014-12-08 17:08:47 +01:00
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
type syncGraphicsContext struct {
|
2014-12-14 10:57:29 +01:00
|
|
|
ui *ui
|
2014-12-08 17:08:47 +01:00
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
var _ GraphicsContext = new(syncGraphicsContext)
|
2014-12-08 17:08:47 +01:00
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
func (c *syncGraphicsContext) Clear() {
|
2014-12-14 10:57:29 +01:00
|
|
|
c.ui.use(func() {
|
|
|
|
c.ui.graphicsContext.Clear()
|
2014-12-08 17:08:47 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
func (c *syncGraphicsContext) Fill(r, g, b uint8) {
|
2014-12-14 10:57:29 +01:00
|
|
|
c.ui.use(func() {
|
|
|
|
c.ui.graphicsContext.Fill(r, g, b)
|
2014-12-08 17:08:47 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
func (c *syncGraphicsContext) Texture(id TextureID) (d Drawer) {
|
2014-12-14 10:57:29 +01:00
|
|
|
c.ui.use(func() {
|
2014-12-08 17:08:47 +01:00
|
|
|
d = &drawer{
|
2014-12-14 10:57:29 +01:00
|
|
|
ui: c.ui,
|
|
|
|
innerDrawer: c.ui.graphicsContext.Texture(id),
|
2014-12-08 17:08:47 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
func (c *syncGraphicsContext) RenderTarget(id RenderTargetID) (d Drawer) {
|
2014-12-14 10:57:29 +01:00
|
|
|
c.ui.use(func() {
|
2014-12-08 17:08:47 +01:00
|
|
|
d = &drawer{
|
2014-12-14 10:57:29 +01:00
|
|
|
ui: c.ui,
|
|
|
|
innerDrawer: c.ui.graphicsContext.RenderTarget(id),
|
2014-12-08 17:08:47 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
func (c *syncGraphicsContext) PopRenderTarget() {
|
2014-12-14 10:57:29 +01:00
|
|
|
c.ui.use(func() {
|
|
|
|
c.ui.graphicsContext.PopRenderTarget()
|
2014-12-08 17:08:47 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
func (c *syncGraphicsContext) PushRenderTarget(id RenderTargetID) {
|
2014-12-14 10:57:29 +01:00
|
|
|
c.ui.use(func() {
|
|
|
|
c.ui.graphicsContext.PushRenderTarget(id)
|
2014-12-08 17:08:47 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type drawer struct {
|
2014-12-14 10:57:29 +01:00
|
|
|
ui *ui
|
2014-12-14 08:53:32 +01:00
|
|
|
innerDrawer Drawer
|
2014-12-08 17:08:47 +01:00
|
|
|
}
|
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
var _ Drawer = new(drawer)
|
2014-12-08 17:08:47 +01:00
|
|
|
|
2014-12-14 08:53:32 +01:00
|
|
|
func (d *drawer) Draw(parts []TexturePart, geo GeometryMatrix, color ColorMatrix) {
|
2014-12-14 10:57:29 +01:00
|
|
|
d.ui.use(func() {
|
2014-12-08 17:08:47 +01:00
|
|
|
d.innerDrawer.Draw(parts, geo, color)
|
|
|
|
})
|
|
|
|
}
|