Documentation
¶
Overview ¶
Package canvas contains the logic to draw the game.
Index ¶
- type Canvas
- func (c Canvas) DesiredWidth() int
- func (c *Canvas) InitDom(ctx context.Context, wg *sync.WaitGroup)
- func (c Canvas) NumCols() int
- func (c Canvas) NumRows() int
- func (c Canvas) ParentDivOffsetWidth() int
- func (c *Canvas) Redraw()
- func (c *Canvas) SetGameStatus(s game.Status)
- func (c *Canvas) SetTileLength(tileLength int)
- func (c *Canvas) StartSwap()
- func (c Canvas) TileLength() int
- func (c *Canvas) UpdateSize(width int)
- type Config
- type Context
- type DOM
- type Log
- type Socket
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
type Canvas struct {
Socket Socket
MainColor string
DragColor string
TileColor string
ErrorColor string
// contains filtered or unexported fields
}
Canvas is the object which draws the game.
func (Canvas) DesiredWidth ¶ added in v1.2.0
DesiredWidth is width the canvas needs to safely draw the board. Uses the TileLength, numCols, and badding
func (*Canvas) InitDom ¶
InitDom registers canvas dom functions by adding an event listeners to the canvas element.
func (Canvas) ParentDivOffsetWidth ¶
ParentDivOffsetWidth is the offsetWidth of the parent div.
func (*Canvas) SetGameStatus ¶
SetGameStatus sets the gameStatus for the canvas. The canvas is redrawn afterwards to clean up drawing artifacts
func (*Canvas) SetTileLength ¶
SetTileLength sets the drawing size of the tiles length/height.
func (Canvas) TileLength ¶
TileLength is the drawing size of the tiles length/height.
func (*Canvas) UpdateSize ¶
UpdateSize sets the draw properties of the canvas for it's current size in the window.
type Config ¶
type Config struct {
TileLength int
MainColor string
DragColor string
TileColor string
ErrorColor string
}
Config contains the parameters to create a Canvas.
type Context ¶
type Context interface {
SetFont(name string)
SetLineWidth(width float64)
SetFillColor(name string)
SetStrokeColor(name string)
FillText(text string, x, y int)
ClearRect(x, y, width, height int)
FillRect(x, y, width, height int)
StrokeRect(x, y, width, height int)
}
Context handles the drawing of the canvas.
type DOM ¶ added in v1.2.0
type DOM interface {
QuerySelector(query string) js.Value
SetChecked(query string, checked bool)
NewJsEventFunc(fn func(event js.Value)) js.Func
ReleaseJsFuncsOnDone(ctx context.Context, wg *sync.WaitGroup, jsFuncs map[string]js.Func)
}
DOM interacts with the page.