Skip to content

Commit

Permalink
doc: Improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Sep 30, 2017
1 parent 23123eb commit a7fc463
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 178 deletions.
15 changes: 9 additions & 6 deletions colorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ColorMDim = affine.ColorMDim

// A ColorM represents a matrix to transform coloring when rendering an image.
//
// A ColorM is applied to the source alpha color
// A ColorM is applied to the straight alpha color
// while an Image's pixels' format is alpha premultiplied.
// Before applying a matrix, a color is un-multiplied, and after applying the matrix,
// the color is multiplied again.
Expand Down Expand Up @@ -61,8 +61,9 @@ func (c *ColorM) Translate(r, g, b, a float64) {
}

// RotateHue rotates the hue.
// theta represents rotating angle in radian.
func (c *ColorM) RotateHue(theta float64) {
c.impl.RotateHue(theta)
c.ChangeHSV(theta, 1, 1)
}

// ChangeHSV changes HSV (Hue-Saturation-Value) values.
Expand All @@ -81,13 +82,15 @@ func (c *ColorM) Element(i, j int) float64 {
}

// SetElement sets an element at (i, j).
func (c *ColorM) SetElement(i, j int, value float64) {
c.impl.SetElement(i, j, value)
func (c *ColorM) SetElement(i, j int, element float64) {
c.impl.SetElement(i, j, element)
}

// Monochrome returns a color matrix to make an image monochrome.
// Monochrome is deprecated as of 1.6.0-alpha. Use ChangeHSV(0, 0, 1) instead.
func Monochrome() ColorM {
return ColorM{affine.Monochrome()}
c := ColorM{}
c.ChangeHSV(0, 0, 1)
return c
}

// ScaleColor is deprecated as of 1.2.0-alpha. Use Scale instead.
Expand Down
66 changes: 33 additions & 33 deletions gamepad.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,37 @@ type GamepadButton int

// GamepadButtons
const (
GamepadButton0 = GamepadButton(ui.GamepadButton0)
GamepadButton1 = GamepadButton(ui.GamepadButton1)
GamepadButton2 = GamepadButton(ui.GamepadButton2)
GamepadButton3 = GamepadButton(ui.GamepadButton3)
GamepadButton4 = GamepadButton(ui.GamepadButton4)
GamepadButton5 = GamepadButton(ui.GamepadButton5)
GamepadButton6 = GamepadButton(ui.GamepadButton6)
GamepadButton7 = GamepadButton(ui.GamepadButton7)
GamepadButton8 = GamepadButton(ui.GamepadButton8)
GamepadButton9 = GamepadButton(ui.GamepadButton9)
GamepadButton10 = GamepadButton(ui.GamepadButton10)
GamepadButton11 = GamepadButton(ui.GamepadButton11)
GamepadButton12 = GamepadButton(ui.GamepadButton12)
GamepadButton13 = GamepadButton(ui.GamepadButton13)
GamepadButton14 = GamepadButton(ui.GamepadButton14)
GamepadButton15 = GamepadButton(ui.GamepadButton15)
GamepadButton16 = GamepadButton(ui.GamepadButton16)
GamepadButton17 = GamepadButton(ui.GamepadButton17)
GamepadButton18 = GamepadButton(ui.GamepadButton18)
GamepadButton19 = GamepadButton(ui.GamepadButton19)
GamepadButton20 = GamepadButton(ui.GamepadButton20)
GamepadButton21 = GamepadButton(ui.GamepadButton21)
GamepadButton22 = GamepadButton(ui.GamepadButton22)
GamepadButton23 = GamepadButton(ui.GamepadButton23)
GamepadButton24 = GamepadButton(ui.GamepadButton24)
GamepadButton25 = GamepadButton(ui.GamepadButton25)
GamepadButton26 = GamepadButton(ui.GamepadButton26)
GamepadButton27 = GamepadButton(ui.GamepadButton27)
GamepadButton28 = GamepadButton(ui.GamepadButton28)
GamepadButton29 = GamepadButton(ui.GamepadButton29)
GamepadButton30 = GamepadButton(ui.GamepadButton30)
GamepadButton31 = GamepadButton(ui.GamepadButton31)
GamepadButtonMax = GamepadButton31
GamepadButton0 GamepadButton = GamepadButton(ui.GamepadButton0)
GamepadButton1 GamepadButton = GamepadButton(ui.GamepadButton1)
GamepadButton2 GamepadButton = GamepadButton(ui.GamepadButton2)
GamepadButton3 GamepadButton = GamepadButton(ui.GamepadButton3)
GamepadButton4 GamepadButton = GamepadButton(ui.GamepadButton4)
GamepadButton5 GamepadButton = GamepadButton(ui.GamepadButton5)
GamepadButton6 GamepadButton = GamepadButton(ui.GamepadButton6)
GamepadButton7 GamepadButton = GamepadButton(ui.GamepadButton7)
GamepadButton8 GamepadButton = GamepadButton(ui.GamepadButton8)
GamepadButton9 GamepadButton = GamepadButton(ui.GamepadButton9)
GamepadButton10 GamepadButton = GamepadButton(ui.GamepadButton10)
GamepadButton11 GamepadButton = GamepadButton(ui.GamepadButton11)
GamepadButton12 GamepadButton = GamepadButton(ui.GamepadButton12)
GamepadButton13 GamepadButton = GamepadButton(ui.GamepadButton13)
GamepadButton14 GamepadButton = GamepadButton(ui.GamepadButton14)
GamepadButton15 GamepadButton = GamepadButton(ui.GamepadButton15)
GamepadButton16 GamepadButton = GamepadButton(ui.GamepadButton16)
GamepadButton17 GamepadButton = GamepadButton(ui.GamepadButton17)
GamepadButton18 GamepadButton = GamepadButton(ui.GamepadButton18)
GamepadButton19 GamepadButton = GamepadButton(ui.GamepadButton19)
GamepadButton20 GamepadButton = GamepadButton(ui.GamepadButton20)
GamepadButton21 GamepadButton = GamepadButton(ui.GamepadButton21)
GamepadButton22 GamepadButton = GamepadButton(ui.GamepadButton22)
GamepadButton23 GamepadButton = GamepadButton(ui.GamepadButton23)
GamepadButton24 GamepadButton = GamepadButton(ui.GamepadButton24)
GamepadButton25 GamepadButton = GamepadButton(ui.GamepadButton25)
GamepadButton26 GamepadButton = GamepadButton(ui.GamepadButton26)
GamepadButton27 GamepadButton = GamepadButton(ui.GamepadButton27)
GamepadButton28 GamepadButton = GamepadButton(ui.GamepadButton28)
GamepadButton29 GamepadButton = GamepadButton(ui.GamepadButton29)
GamepadButton30 GamepadButton = GamepadButton(ui.GamepadButton30)
GamepadButton31 GamepadButton = GamepadButton(ui.GamepadButton31)
GamepadButtonMax GamepadButton = GamepadButton31
)
4 changes: 2 additions & 2 deletions genkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ type Key int
// Keys
const (
{{range $index, $name := .KeyNames}}Key{{$name}} = Key(ui.Key{{$name}})
{{end}} KeyMax = Key{{.LastKeyName}}
{{range $index, $name := .KeyNames}}Key{{$name}} Key = Key(ui.Key{{$name}})
{{end}} KeyMax Key = Key{{.LastKeyName}}
)
`

Expand Down
3 changes: 2 additions & 1 deletion geom.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (g *GeoM) Reset() {
}

// Apply pre-multiplies a vector (x, y, 1) by the matrix.
// In other words, Apply calculates GeoM * (x, y, 1).
// In other words, Apply calculates GeoM * (x, y, 1)^T.
// The return value is x and y values of the result vector.
func (g *GeoM) Apply(x, y float64) (x2, y2 float64) {
return g.impl.Apply(x, y)
Expand Down Expand Up @@ -84,6 +84,7 @@ func (g *GeoM) Translate(tx, ty float64) {
}

// Rotate rotates the matrix by theta.
// The unit is radian.
func (g *GeoM) Rotate(theta float64) {
g.impl.Rotate(theta)
}
Expand Down
40 changes: 23 additions & 17 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,11 @@ func (i *Image) Fill(clr color.Color) error {
return nil
}

// DrawImage draws the given image on the receiver image.
// DrawImage draws the given image on the image i.
//
// This method accepts the options.
// The parts of the given image at the parts of the destination.
// After determining parts to draw, this applies the geometry matrix and the color matrix.
// DrawImage accepts the options. For details, see the document of DrawImageOptions.
//
// Here are the default values:
// SourceRect: nil. When SourceRect is nil, the whole source image is used.
// GeoM: Identity matrix
// ColorM: Identity matrix (that changes no colors)
// CompositeMode: CompositeModeSourceOver (regular alpha blending)
// DrawImage determinines the part to draw, then DrawImage applies the geometry matrix and the color matrix.
//
// For drawing, the pixels of the argument image at the time of this call is adopted.
// Even if the argument image is mutated after this call,
Expand Down Expand Up @@ -156,9 +150,11 @@ func (i *Image) ColorModel() color.Model {

// At returns the color of the image at (x, y).
//
// This method loads pixels from GPU to system memory if necessary.
// At loads pixels from GPU to system memory if necessary, which means that At can be slow.
//
// This method can't be called before the main loop (ebiten.Run) starts (as of version 1.4.0-alpha).
// At always returns color.Transparend if the image is disposed.
//
// At can't be called before the main loop (ebiten.Run) starts (as of version 1.4.0-alpha).
func (i *Image) At(x, y int) color.Color {
if i.restorable == nil {
return color.Transparent
Expand All @@ -171,10 +167,9 @@ func (i *Image) At(x, y int) color.Color {
return clr
}

// Dispose disposes the image data. After disposing, the image becomes invalid.
// This is useful to save memory.
// Dispose disposes the image data. After disposing, most of image functions do nothing and returns meaningless values.
//
// The behavior of any functions for a disposed image is undefined.
// Dispose is useful to save memory.
//
// When the image is disposed, Dipose does nothing.
//
Expand Down Expand Up @@ -219,9 +214,20 @@ func (i *Image) ReplacePixels(p []uint8) error {

// A DrawImageOptions represents options to render an image on an image.
type DrawImageOptions struct {
SourceRect *image.Rectangle
GeoM GeoM
ColorM ColorM
// SourceRect is the region of the source image to draw.
// If SourceRect is nil, whole image is used.
SourceRect *image.Rectangle

// GeoM is a geometry matrix to draw.
// The default (zero) value is identify, which draws the image at (0, 0).
GeoM GeoM

// ColorM is a color matrix to draw.
// The default (zero) value is identity, which doesn't change any color.
ColorM ColorM

// CompositeMode is a composite mode to draw.
// The default (zero) value is regular alpha blending.
CompositeMode CompositeMode

// Deprecated (as of 1.5.0-alpha): Use SourceRect instead.
Expand Down
18 changes: 7 additions & 11 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// InputChars represents the environment's locale-dependent translation of keyboard
// input to Unicode characters.
//
// IsKeyPressed is based on a mapping of device codes to input device keys.
// IsKeyPressed is based on a mapping of device (US keyboard) codes to input device keys.
// "Control" and modifier keys should be handled with IsKeyPressed.
//
// This function is concurrent-safe.
Expand Down Expand Up @@ -56,46 +56,42 @@ func IsMouseButtonPressed(mouseButton MouseButton) bool {
return ui.CurrentInput().IsMouseButtonPressed(ui.MouseButton(mouseButton))
}

// GamepadAxisNum returns the number of axes of the gamepad.
// GamepadAxisNum returns the number of axes of the gamepad (id).
//
// This function is concurrent-safe.
//
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
// To use this API, browsers might require rebooting the browser.
func GamepadAxisNum(id int) int {
return ui.CurrentInput().GamepadAxisNum(id)
}

// GamepadAxis returns the float value [-1.0 - 1.0] of the axis.
// GamepadAxis returns the float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis).
//
// This function is concurrent-safe.
//
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
// To use this API, browsers might require rebooting the browser.
func GamepadAxis(id int, axis int) float64 {
return ui.CurrentInput().GamepadAxis(id, axis)
}

// GamepadButtonNum returns the number of the buttons of the gamepad.
// GamepadButtonNum returns the number of the buttons of the given gamepad (id).
//
// This function is concurrent-safe.
//
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
// To use this API, browsers might require rebooting the browser.
func GamepadButtonNum(id int) int {
return ui.CurrentInput().GamepadButtonNum(id)
}

// IsGamepadButtonPressed returns the boolean indicating the buttons is pressed or not.
// IsGamepadButtonPressed returns the boolean indicating the given button of the gamepad (id) is pressed or not.
//
// This function is concurrent-safe.
//
// The key states vary depending on environments.
// The button states vary depending on environments.
// There can be differences even between Chrome and Firefox.
// Don't assume that states of a keys are always same when same buttons are pressed.
// Don't assume that returned values are always same when same buttons are pressed.
//
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
// To use this API, browsers might require rebooting the browser.
func IsGamepadButtonPressed(id int, button GamepadButton) bool {
return ui.CurrentInput().IsGamepadButtonPressed(id, ui.GamepadButton(button))
}
Expand Down
16 changes: 0 additions & 16 deletions internal/affine/colorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ func (c *ColorM) Translate(r, g, b, a float64) {
c.elements = es
}

// RotateHue rotates the hue.
func (c *ColorM) RotateHue(theta float64) {
c.ChangeHSV(theta, 1, 1)
}

var (
// The YCbCr value ranges are:
// Y: [ 0 - 1 ]
Expand Down Expand Up @@ -200,14 +195,3 @@ func (c *ColorM) ChangeHSV(hueTheta float64, saturationScale float64, valueScale
c.Scale(v, s*v, s*v, 1)
c.Concat(&yCbCrToRgb)
}

var monochrome ColorM

func init() {
monochrome.ChangeHSV(0, 0, 1)
}

// Monochrome returns a color matrix to make an image monochrome.
func Monochrome() ColorM {
return monochrome
}
Loading

0 comments on commit a7fc463

Please sign in to comment.