normalized most of lines to <=100 chars

This commit is contained in:
faiface 2016-12-30 17:43:26 +01:00
parent fefa184652
commit 9096277914
8 changed files with 106 additions and 82 deletions

View File

@ -9,7 +9,8 @@ type NRGBA struct {
R, G, B, A float64
}
// Add adds color d to color c component-wise and returns the result (the components are not clamped).
// Add adds color d to color c component-wise and returns the result (the components are not
// clamped).
func (c NRGBA) Add(d NRGBA) NRGBA {
return NRGBA{
R: c.R + d.R,
@ -19,7 +20,8 @@ func (c NRGBA) Add(d NRGBA) NRGBA {
}
}
// Sub subtracts color d from color c component-wise and returns the result (the components are not clamped).
// Sub subtracts color d from color c component-wise and returns the result (the components
// are not clamped).
func (c NRGBA) Sub(d NRGBA) NRGBA {
return NRGBA{
R: c.R - d.R,
@ -39,7 +41,8 @@ func (c NRGBA) Mul(d NRGBA) NRGBA {
}
}
// Scaled multiplies each component of color c by scale and returns the result (the components are not clamped).
// Scaled multiplies each component of color c by scale and returns the result (the components
// are not clamped).
func (c NRGBA) Scaled(scale float64) NRGBA {
return NRGBA{
R: c.R * scale,

View File

@ -6,10 +6,10 @@ import (
"math/cmplx"
)
// Vec is a 2d vector type. It is unusually implemented as complex128 for convenience. Since Go does
// not allow operator overloading, implementing vector as a struct leads to a bunch of methods for
// addition, subtraction and multiplication of vectors. With complex128, much of this functionality
// is given through operators.
// Vec is a 2d vector type. It is unusually implemented as complex128 for convenience. Since
// Go does not allow operator overloading, implementing vector as a struct leads to a bunch of
// methods for addition, subtraction and multiplication of vectors. With complex128, much of
// this functionality is given through operators.
//
// Create vectors with the V constructor:
//
@ -27,7 +27,7 @@ import (
// u := pixel.V(2, 3)
// v := pixel.V(8, 1)
// if u.X() < 0 {
// fmt.Println("this won't happen")
// fmt.Println("this won't happen")
// }
// x := u.Unit().Dot(v.Unit())
type Vec complex128
@ -97,7 +97,8 @@ func (u Vec) Cross(v Vec) float64 {
return u.X()*v.Y() - v.X()*u.Y()
}
// Rect is a 2d rectangle aligned with the axis of the coordinate system. It has a position and a size.
// Rect is a 2d rectangle aligned with the axis of the coordinate system. It has a position
// and a size.
//
// You can manipulate the position and the size using the usual vector operations.
type Rect struct {

View File

@ -11,8 +11,9 @@ import (
// Drawer is anything that can be drawn. It's by no means a drawer inside your table.
//
// Drawer consists of a single methods: Draw. Draw methods takes any number of Transform arguments. It applies these
// transforms in the reverse order and finally draws something transformed by these transforms.
// Drawer consists of a single methods: Draw. Draw methods takes any number of Transform
// arguments. It applies these transforms in the reverse order and finally draws something
// transformed by these transforms.
//
// Example:
//
@ -24,21 +25,23 @@ type Drawer interface {
Draw(t ...Transform)
}
// Group is used to effeciently handle a collection of objects with a common parent. Usually many objects share a parent,
// using a group can significantly increase performance in these cases.
// Group is used to effeciently handle a collection of objects with a common parent. Usually many
// objects share a parent, using a group can significantly increase performance in these cases.
//
// To use a group, first, create a group and as it's parent use the common parent of the collection of objects:
// To use a group, first, create a group and as it's parent use the common parent of the
// collection of objects:
//
// group := pixel.NewGroup(commonParent)
//
// Then, when creating the objects, use the group as their parent, instead of the original common parent, but, don't forget
// to put everything into a With block, like this:
// Then, when creating the objects, use the group as their parent, instead of the original
// common parent, but, don't forget to put everything into a With block, like this:
//
// group.With(func() {
// object := newArbitratyObject(group, ...) // group is the parent of the object
// })
//
// When dealing with objects associated with a group, it's always necessary to wrap that into a With block:
// When dealing with objects associated with a group, it's always necessary to wrap that into
// a With block:
//
// group.With(func() {
// for _, obj := range objectsWithCommonParent {
@ -74,10 +77,11 @@ func (g *Group) Do(sub func(pixelgl.Context)) {
// Shape is a general drawable shape constructed from vertices.
//
// Vertices are specified in the vertex array of a shape. A shape can have a picture, a color (mask) and a static
// transform.
// Vertices are specified in the vertex array of a shape. A shape can have a picture, a color
// (mask) and a static transform.
//
// Usually you use this type only indirectly throught other specific shapes (sprites, polygons, ...) embedding it.
// Usually you use this type only indirectly throught other specific shapes (sprites, polygons,
// ...) embedding it.
type Shape struct {
parent pixelgl.Doer
picture *Picture
@ -155,10 +159,11 @@ func (s *Shape) Draw(t ...Transform) {
})
}
// MultiShape is a shape composed of several other shapes. These shapes cannot be modifies after combined into a multishape.
// MultiShape is a shape composed of several other shapes. These shapes cannot be modifies
// after combined into a multishape.
//
// Using a multishape can greatly increase drawing performance. However, it's only usable when the relative transformations
// of the shapes don't change (e.g. static blocks in a level).
// Using a multishape can greatly increase drawing performance. However, it's only usable when
// the relative transformations of the shapes don't change (e.g. static blocks in a level).
//
// All shapes in a multishape must share the same texture (or use no texture).
type MultiShape struct {
@ -234,18 +239,19 @@ func NewMultiShape(parent pixelgl.Doer, shapes ...*Shape) *MultiShape {
return &MultiShape{NewShape(parent, picture, color.White, Position(0), va)}
}
// Sprite is a picture that can be drawn on the screen. Optionally it can be color masked or tranformed.
// Sprite is a picture that can be drawn on the screen. Optionally it can be color masked
// or tranformed.
//
// Usually, you only transform objects when you're drawing them (by passing transforms to the Draw method).
// With sprites however, it can be useful to also transform them "statically". For example, sprites are
// anchor by their bottom-left corner by default. Setting a transform can change this anchored to the center,
// or wherever you want.
// Usually, you only transform objects when you're drawing them (by passing transforms to the
// Draw method). With sprites however, it can be useful to also transform them "statically". For
// example, sprites are anchor by their bottom-left corner by default. Setting a transform can
// change this anchored to the center, or wherever you want.
type Sprite struct {
*Shape
}
// NewSprite creates a new sprite with the supplied picture. The sprite's size is the size of the supplied picture.
// If you want to change the sprite's size, change it's transform.
// NewSprite creates a new sprite with the supplied picture. The sprite's size is the size of
// the supplied picture. If you want to change the sprite's size, change it's transform.
func NewSprite(parent pixelgl.Doer, picture *Picture) *Sprite {
var va *pixelgl.VertexArray
@ -290,8 +296,8 @@ type LineColor struct {
width float64
}
// NewLineColor creates a new line shape between points A and B filled with a single color. Parent is an object
// that this shape belongs to, such as a window, or a graphics effect.
// NewLineColor creates a new line shape between points A and B filled with a single color. Parent
// is an object that this shape belongs to, such as a window, or a graphics effect.
func NewLineColor(parent pixelgl.Doer, c color.Color, a, b Vec, width float64) *LineColor {
var va *pixelgl.VertexArray
@ -371,8 +377,8 @@ type PolygonColor struct {
points []Vec
}
// NewPolygonColor creates a new polygon shape filled with a single color. Parent is an object that this shape belongs to,
// such as a window, or a graphics effect.
// NewPolygonColor creates a new polygon shape filled with a single color. Parent is an object
// that this shape belongs to, such as a window, or a graphics effect.
func NewPolygonColor(parent pixelgl.Doer, c color.Color, points ...Vec) *PolygonColor {
var va *pixelgl.VertexArray
@ -436,9 +442,10 @@ type EllipseColor struct {
fill float64
}
// NewEllipseColor creates a new ellipse shape filled with a single color. Parent is an object that this shape belongs to,
// such as a window, or a graphics effect. Fill should be a number between 0 and 1 which specifies how much of the ellipse will
// be filled (from the outside). The value of 1 means that the whole ellipse is filled. The value of 0 means that none of the
// NewEllipseColor creates a new ellipse shape filled with a single color. Parent is an object
// that this shape belongs to, such as a window, or a graphics effect. Fill should be a number
// between 0 and 1 which specifies how much of the ellipse will be filled (from the outside). The
// value of 1 means that the whole ellipse is filled. The value of 0 means that none of the
// ellipse is filled (which makes the ellipse invisible).
func NewEllipseColor(parent pixelgl.Doer, c color.Color, radius Vec, fill float64) *EllipseColor {
var va *pixelgl.VertexArray

View File

@ -224,6 +224,7 @@ func (w *Window) updateInput() {
glfw.PollEvents()
})
// cache current state to temp (so that if there are callbacks outside this function, everything works)
// cache current state to temp (so that if there are callbacks outside this function,
// everything works)
w.tempInp = w.currInp
}

View File

@ -10,8 +10,9 @@ import (
// Picture is a raster picture. It is usually used with sprites.
//
// A picture is created from an image.Image, that can be either loaded from a file, or generated. After the creation
// a picture can be sliced (slicing creates a "sub-picture" from a picture) into smaller pictures.
// A picture is created from an image.Image, that can be either loaded from a file, or
// generated. After the creation a picture can be sliced (slicing creates a "sub-picture"
// from a picture) into smaller pictures.
type Picture struct {
texture *pixelgl.Texture
bounds Rect
@ -47,11 +48,11 @@ func (p *Picture) Texture() *pixelgl.Texture {
return p.texture
}
// Slice returns a picture within the supplied rectangle of the original picture. The original and the sliced picture
// share the same texture.
// Slice returns a picture within the supplied rectangle of the original picture. The original
// and the sliced picture share the same texture.
//
// For example, suppose we have a 100x200 pixels picture. If we slice it with rectangle (50, 100, 50, 100), we get
// the upper-right quadrant of the original picture.
// For example, suppose we have a 100x200 pixels picture. If we slice it with rectangle (50,
// 100, 50, 100), we get the upper-right quadrant of the original picture.
func (p *Picture) Slice(slice Rect) *Picture {
return &Picture{
texture: p.texture,
@ -61,7 +62,8 @@ func (p *Picture) Slice(slice Rect) *Picture {
// Bounds returns the bounding rectangle of this picture relative to the most original picture.
//
// If the original picture gets sliced with the return value of this method, this picture will be obtained.
// If the original picture gets sliced with the return value of this method, this picture will
// be obtained.
func (p *Picture) Bounds() Rect {
return p.bounds
}

13
run.go
View File

@ -5,10 +5,12 @@ import (
"github.com/go-gl/glfw/v3.2/glfw"
)
// Run is essentialy the "main" function of Pixel. It exists mainly due to the technical limitations of OpenGL and operating systems,
// in short, all graphics and window manipulating calls must be done from the main thread. Run makes this possible.
// Run is essentialy the "main" function of Pixel. It exists mainly due to the technical
// limitations of OpenGL and operating systems, in short, all graphics and window manipulating
// calls must be done from the main thread. Run makes this possible.
//
// Call this function from the main function of your application. This is necessary, so that Run runs on the main thread.
// Call this function from the main function of your application. This is necessary, so that
// Run runs on the main thread.
//
// func run() {
// window := pixel.NewWindow(...)
@ -21,8 +23,9 @@ import (
// pixel.Run(run)
// }
//
// You can spawn any number of goroutines from you run function and interact with Pixel concurrently.
// The only condition is that the Run function must be called from your main function.
// You can spawn any number of goroutines from you run function and interact with Pixel
// concurrently. The only condition is that the Run function must be called from your main
// function.
func Run(run func()) {
defer glfw.Terminate()
pixelgl.Run(run)

View File

@ -2,16 +2,16 @@ package pixel
import "github.com/go-gl/mathgl/mgl32"
// Transform holds space transformation information. Concretely, a transformation is specified by position,
// anchor, scale and rotation.
// Transform holds space transformation information. Concretely, a transformation is specified
// by position, anchor, scale and rotation.
//
// All points are first rotated around the anchor. Then they are multiplied by the scale. If the
// scale factor is 2, the object becomes 2x bigger. Finally, all points are moved, so that the original
// anchor is located precisely at the position.
// All points are first rotated around the anchor. Then they are multiplied by the scale. If
// the scale factor is 2, the object becomes 2x bigger. Finally, all points are moved, so that
// the original anchor is located precisely at the position.
//
// Create a Transform object with the Position function. This sets the position variable, which is the
// most important. Then use methods, like Scale and Rotate to change scale, rotation and achor. The order
// in which you apply these methods is irrelevant.
// Create a Transform object with the Position function. This sets the position variable,
// which is the most important. Then use methods, like Scale and Rotate to change scale,
// rotation and achor. The order in which you apply these methods is irrelevant.
//
// pixel.Position(pixel.V(100, 100)).Rotate(math.Pi / 3).Scale(1.5)
type Transform struct {
@ -19,7 +19,8 @@ type Transform struct {
rot float64
}
// Position creates a Transformation object with specified position. Anchor is (0, 0), rotation is 0 and scale is 1.
// Position creates a Transformation object with specified position. Anchor is (0, 0), rotation
// is 0 and scale is 1.
func Position(position Vec) Transform {
return Transform{
pos: position,
@ -73,17 +74,18 @@ func (t Transform) MoveAnchor(delta Vec) Transform {
// Scale scales the transform by the supplied factor.
//
// Note, that subsequent calls to this method accumulate the final scale factor. Scaling two times by 2 is equivalent
// to scaling once by 4.
// Note, that subsequent calls to this method accumulate the final scale factor. Scaling two
// times by 2 is equivalent to scaling once by 4.
func (t Transform) Scale(scale float64) Transform {
t.sca = t.sca.Scaled(scale)
return t
}
// ScaleXY scales the transform by the supplied X and Y factor. Note, that scale is applied before rotation.
// ScaleXY scales the transform by the supplied X and Y factor. Note, that scale is applied
// before rotation.
//
// Note, that subsequent calls to this method accumulate the final scale factor. Scaling two times by 2 is equivalent
// to scaling once by 4.
// Note, that subsequent calls to this method accumulate the final scale factor. Scaling two
// times by 2 is equivalent to scaling once by 4.
func (t Transform) ScaleXY(scale Vec) Transform {
t.sca = V(t.sca.X()*scale.X(), t.sca.Y()*scale.Y())
return t
@ -91,8 +93,8 @@ func (t Transform) ScaleXY(scale Vec) Transform {
// Rotate rotates the transform by the supplied angle in radians.
//
// Note, that subsequent calls to this method accumulate the final rotation. Rotating two times by Pi/2 is
// equivalent to rotating once by Pi.
// Note, that subsequent calls to this method accumulate the final rotation. Rotating two times
// by Pi/2 is equivalent to rotating once by Pi.
func (t Transform) Rotate(angle float64) Transform {
t.rot += angle
return t
@ -134,8 +136,8 @@ func (t Transform) InvMat() mgl32.Mat3 {
return mat
}
// Camera is a convenience function, that returns a Transform that acts like a camera.
// Center is the position in the world coordinates, that will be projected onto the center of the screen.
// Camera is a convenience function, that returns a Transform that acts like a camera. Center is
// the position in the world coordinates, that will be projected onto the center of the screen.
// One unit in world coordinates will be projected onto zoom pixels.
//
// It is possible to apply additional rotations, scales and moves to the returned transform.

View File

@ -14,8 +14,8 @@ import (
)
// WindowConfig is convenience structure for specifying all possible properties of a window.
// Properties are chosen in such a way, that you usually only need to set a few of them - defaults
// (zeros) should usually be sensible.
// Properties are chosen in such a way, that you usually only need to set a few of them -
// defaults (zeros) should usually be sensible.
//
// Note that you always need to set the width and the height of a window.
type WindowConfig struct {
@ -28,7 +28,8 @@ type WindowConfig struct {
// Height of a window in pixels.
Height float64
// If set to nil, a window will be windowed. Otherwise it will be fullscreen on the specified monitor.
// If set to nil, a window will be windowed. Otherwise it will be fullscreen on the
// specified monitor.
Fullscreen *Monitor
// Whether a window is resizable.
@ -46,11 +47,12 @@ type WindowConfig struct {
// Whether a window is maximized.
Maximized bool
// VSync (vertical synchronization) synchronizes window's framerate with the framerate of the monitor.
// VSync (vertical synchronization) synchronizes window's framerate with the framerate
// of the monitor.
VSync bool
// Number of samples for multi-sample anti-aliasing (edge-smoothing).
// Usual values are 0, 2, 4, 8 (powers of 2 and not much more than this).
// Number of samples for multi-sample anti-aliasing (edge-smoothing). Usual values
// are 0, 2, 4, 8 (powers of 2 and not much more than this).
MSAASamples int
}
@ -183,8 +185,8 @@ func (w *Window) DefaultShader() *pixelgl.Shader {
// SetClosed sets the closed flag of a window.
//
// This is usefull when overriding the user's attempt to close a window, or just to close a window
// from within a program.
// This is usefull when overriding the user's attempt to close a window, or just to close a
// window from within a program.
func (w *Window) SetClosed(closed bool) {
pixelgl.Do(func() {
w.window.SetShouldClose(closed)
@ -207,8 +209,8 @@ func (w *Window) SetTitle(title string) {
})
}
// SetSize resizes a window to the specified size in pixels.
// In case of a fullscreen window, it changes the resolution of that window.
// SetSize resizes a window to the specified size in pixels. In case of a fullscreen window,
// it changes the resolution of that window.
func (w *Window) SetSize(width, height float64) {
pixelgl.Do(func() {
w.window.SetSize(int(width), int(height))
@ -239,10 +241,12 @@ func (w *Window) Hide() {
})
}
// SetFullscreen sets a window fullscreen on a given monitor. If the monitor is nil, the window will be resored to windowed instead.
// SetFullscreen sets a window fullscreen on a given monitor. If the monitor is nil, the window
// will be resored to windowed instead.
//
// Note, that there is nothing about the resolution of the fullscreen window. The window is automatically set to the monitor's
// resolution. If you want a different resolution, you need to set it manually with SetSize method.
// Note, that there is nothing about the resolution of the fullscreen window. The window is
// automatically set to the monitor's resolution. If you want a different resolution, you need
// to set it manually with SetSize method.
func (w *Window) SetFullscreen(monitor *Monitor) {
if w.Monitor() != monitor {
if monitor == nil {
@ -281,7 +285,8 @@ func (w *Window) IsFullscreen() bool {
return w.Monitor() != nil
}
// Monitor returns a monitor a fullscreen window is on. If the window is not fullscreen, this function returns nil.
// Monitor returns a monitor a fullscreen window is on. If the window is not fullscreen, this
// function returns nil.
func (w *Window) Monitor() *Monitor {
monitor := pixelgl.DoVal(func() interface{} {
return w.window.GetMonitor()