本文整理汇总了Golang中exp/draw.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: flushFunc
func flushFunc(ctxt draw.Context) func(r draw.Rectangle) {
if fctxt, ok := ctxt.(RectFlusherContext); ok {
return func(r draw.Rectangle) {
fctxt.FlushImageRect(r)
}
}
return func(_ draw.Rectangle) {
ctxt.FlushImage()
}
}
示例2: Init
func (m *SpacewarPDP1) Init(ctxt draw.Context) {
m.ctxt = ctxt
m.kc = ctxt.KeyboardChan()
m.screen = ctxt.Screen()
m.dx = m.screen.Width()
m.dy = m.screen.Height()
m.colorModel = m.screen.ColorModel()
m.pix = make([][]uint8, m.dy)
for i := range m.pix {
m.pix[i] = make([]uint8, m.dx)
}
m.cmap = make([]image.Color, 256)
for i := range m.cmap {
var r, g, b uint8
r = uint8(min(0, 255))
g = uint8(min(i*2, 255))
b = uint8(min(0, 255))
m.cmap[i] = m.colorModel.Convert(image.RGBAColor{r, g, b, 0xff})
}
}
示例3: Play
func Play(pp []Piece, ctxt draw.Context) {
display = ctxt
screen = ctxt.Screen()
screenr = draw.Rect(0, 0, screen.Width(), screen.Height())
pieces = pp
N = len(pieces[0].d)
initPieces()
rand.Seed(int32(time.Nanoseconds() % (1e9 - 1)))
whitemask = draw.White.SetAlpha(0x7F)
tsleep = 50
timerc = time.Tick(int64(tsleep/2) * 1e6)
suspc = make(chan bool)
mousec = make(chan draw.Mouse)
resizec = ctxt.ResizeChan()
kbdc = make(chan int)
go quitter(ctxt.QuitChan())
go suspproc()
points = 0
redraw(false)
play()
}
示例4: draw
func (inpMazeCell *SMazeCell) draw(inContext draw.Context, inSquareSize int)
{
vl_screen := inContext.Screen();
upXLeft, upYLeft := 100, 100;
squareSize := inSquareSize;
fullCell := draw.Rect(upXLeft, upYLeft, squareSize + upXLeft, squareSize + upYLeft);
draw.Draw(vl_screen, fullCell, draw.Black, nil, draw.ZP);
// inset set the color of the inside
draw.Draw(vl_screen, fullCell.Inset(1), draw.White, nil, draw.ZP);
//hide a wall with a rectangle... POOR SOLUTION !!
if inpMazeCell.northOpen
{
// up wall
hiderup := draw.Rect(upXLeft, upYLeft,
upXLeft + squareSize, upYLeft + 1);
draw.Draw(vl_screen, hiderup, draw.White, nil, draw.ZP);
}
else
{
// do not hide
}
if inpMazeCell.westOpen
{
// right wall
hiderright := draw.Rect(upXLeft + squareSize - 1, upYLeft,
upXLeft + squareSize, upYLeft + squareSize);
draw.Draw(vl_screen, hiderright, draw.White, nil, draw.ZP);
}
else
{
// do not hide
}
if inpMazeCell.southOpen
{
// down wall
hiderdown := draw.Rect(upXLeft, upYLeft + squareSize - 1,
upXLeft + squareSize, upYLeft + squareSize);
draw.Draw(vl_screen, hiderdown, draw.White, nil, draw.ZP);
}
else
{
// do not hide
}
if inpMazeCell.eastOpen
{
// left wall
hiderleft := draw.Rect(upXLeft, upYLeft,
upXLeft + 1, upYLeft + squareSize);
draw.Draw(vl_screen, hiderleft, draw.White, nil, draw.ZP);
}
else
{
// do not hide
}
}
示例5: app
func app(inContext draw.Context)
{
vl_screen := inContext.Screen();
screenr := draw.Rect(0, 0, vl_screen.Width(), vl_screen.Height());
draw.Draw(vl_screen, screenr, draw.White, nil, draw.ZP);
squareSize := 30;
var cell *SMazeCell = new(SMazeCell);
cell.draw(inContext, squareSize);
inContext.FlushImage();
fmt.Printf("Press the any key to exit.\n");
for
{
select
{
case r := <- inContext.KeyboardChan():
switch r
{
case 'q', 'Q', 0x04, 0x7F, 32 :
fmt.Printf("Exiting because of keyboard event %d\n", r);
os.Exit(0);
default :
fmt.Printf("Exiting because of keyboard event %d\n", r);
}
case <- inContext.MouseChan():
// No-op.
case <- inContext.ResizeChan():
// No-op.
case <- inContext.QuitChan():
fmt.Printf("Exiting because of QuitChan\n");
return;
}
}
}