Added documentation
This commit is contained in:
		
							parent
							
								
									2986c8fd03
								
							
						
					
					
						commit
						c0d85cda5b
					
				| @ -62,11 +62,14 @@ func (application *Application) SetTitle (title string) (err error) { | |||||||
| 	return  | 	return  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Title returns the application's title. | ||||||
| func (application *Application) Title () (title string) { | func (application *Application) Title () (title string) { | ||||||
| 	title = application.title | 	title = application.title | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetIcon takes in a list of different sizes of an icon, and sets it as the | ||||||
|  | // application's icon. | ||||||
| func (application *Application) SetIcon (sizes []image.Image) (err error) { | func (application *Application) SetIcon (sizes []image.Image) (err error) { | ||||||
| 	application.icons = sizes | 	application.icons = sizes | ||||||
| 	if application.backend != nil { | 	if application.backend != nil { | ||||||
| @ -76,6 +79,8 @@ func (application *Application) SetIcon (sizes []image.Image) (err error) { | |||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Icon returns all available sizes of the application's icon. If there is no | ||||||
|  | // icon, nil is returned. | ||||||
| func (application *Application) Icon () (sizes []image.Image) { | func (application *Application) Icon () (sizes []image.Image) { | ||||||
| 	sizes = application.icons | 	sizes = application.icons | ||||||
| 	return | 	return | ||||||
|  | |||||||
							
								
								
									
										34
									
								
								buffer.go
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								buffer.go
									
									
									
									
									
								
							| @ -1,5 +1,6 @@ | |||||||
| package stone | package stone | ||||||
| 
 | 
 | ||||||
|  | // Color represents all the different colors a cell can be. | ||||||
| type Color uint8 | type Color uint8 | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| @ -9,6 +10,8 @@ const ( | |||||||
| 	ColorApplication Color = 0x3 | 	ColorApplication Color = 0x3 | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | // Style contains styling information about cells. These properties can be or'd | ||||||
|  | // together to combine them. | ||||||
| type Style uint8 | type Style uint8 | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| @ -18,27 +21,33 @@ const ( | |||||||
| 	StyleBoldItalic Style = StyleBold | StyleItalic | 	StyleBoldItalic Style = StyleBold | StyleItalic | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | // Cell is a grid-aligned rune in a buffer with associated styling and color | ||||||
|  | // informaiton. | ||||||
| type Cell struct { | type Cell struct { | ||||||
| 	color   Color | 	color   Color | ||||||
| 	style   Style | 	style   Style | ||||||
| 	content rune | 	content rune | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Color returns the cell's color. | ||||||
| func (cell Cell) Color (color Color) { | func (cell Cell) Color (color Color) { | ||||||
| 	color = cell.color | 	color = cell.color | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Style returns the styling information associated with the cell | ||||||
| func (cell Cell) Style (style Style) { | func (cell Cell) Style (style Style) { | ||||||
| 	style = cell.style | 	style = cell.style | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Rune returns the rune in the cell | ||||||
| func (cell Cell) Rune () (content rune) { | func (cell Cell) Rune () (content rune) { | ||||||
| 	content = cell.content | 	content = cell.content | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Buffer is a basic grid of cells. | ||||||
| type Buffer struct { | type Buffer struct { | ||||||
| 	content []Cell | 	content []Cell | ||||||
| 	width  int | 	width  int | ||||||
| @ -58,12 +67,15 @@ func (buffer *Buffer) isOutOfBounds (x, y int) (outOfBounds bool) { | |||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Size returns the width and height of the buffer. | ||||||
| func (buffer *Buffer) Size () (width, height int) { | func (buffer *Buffer) Size () (width, height int) { | ||||||
| 	width  = buffer.width | 	width  = buffer.width | ||||||
| 	height = buffer.height | 	height = buffer.height | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetSize sets the width and height of the buffer. This clears all data in the | ||||||
|  | // buffer. If the width or height is negative, this method does nothing. | ||||||
| func (buffer *Buffer) SetSize (width, height int) { | func (buffer *Buffer) SetSize (width, height int) { | ||||||
| 	if width < 0 || height < 0 { return } | 	if width < 0 || height < 0 { return } | ||||||
| 	buffer.width   = width | 	buffer.width   = width | ||||||
| @ -71,27 +83,34 @@ func (buffer *Buffer) SetSize (width, height int) { | |||||||
| 	buffer.content = make([]Cell, width * height) | 	buffer.content = make([]Cell, width * height) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Cell returns the cell at the specified x and y coordinates. If the | ||||||
|  | // coordinates are out of bounds, this method will return a blank cell. | ||||||
| func (buffer *Buffer) Cell (x, y int) (cell Cell) { | func (buffer *Buffer) Cell (x, y int) (cell Cell) { | ||||||
| 	if buffer.isOutOfBounds(x, y) { return } | 	if buffer.isOutOfBounds(x, y) { return } | ||||||
| 	cell = buffer.content[x + y * buffer.width] | 	cell = buffer.content[x + y * buffer.width] | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetColor sets the color of the cell at the specified x and y coordinates. | ||||||
| func (buffer *Buffer) SetColor (x, y int, color Color) { | func (buffer *Buffer) SetColor (x, y int, color Color) { | ||||||
| 	if buffer.isOutOfBounds(x, y) { return } | 	if buffer.isOutOfBounds(x, y) { return } | ||||||
| 	buffer.content[x + y * buffer.width].color = color | 	buffer.content[x + y * buffer.width].color = color | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetStyle sets the style of the cell at the specified x and y coordinates. | ||||||
| func (buffer *Buffer) SetStyle (x, y int, style Style) { | func (buffer *Buffer) SetStyle (x, y int, style Style) { | ||||||
| 	if buffer.isOutOfBounds(x, y) { return } | 	if buffer.isOutOfBounds(x, y) { return } | ||||||
| 	buffer.content[x + y * buffer.width].style = style | 	buffer.content[x + y * buffer.width].style = style | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetRune sets the rune of the cell at the specified x and y coordinates. | ||||||
| func (buffer *Buffer) SetRune (x, y int, content rune) { | func (buffer *Buffer) SetRune (x, y int, content rune) { | ||||||
| 	if buffer.isOutOfBounds(x, y) { return } | 	if buffer.isOutOfBounds(x, y) { return } | ||||||
| 	buffer.content[x + y * buffer.width].content = content | 	buffer.content[x + y * buffer.width].content = content | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Write writes data stored in a byte slice to the buffer at the current dot | ||||||
|  | // position. This makes Buffer an io.Writer. | ||||||
| func (buffer *Buffer) Write (bytes []byte) (bytesWritten int, err error) { | func (buffer *Buffer) Write (bytes []byte) (bytesWritten int, err error) { | ||||||
| 	text := string(bytes) | 	text := string(bytes) | ||||||
| 	bytesWritten = len(bytes) | 	bytesWritten = len(bytes) | ||||||
| @ -105,22 +124,30 @@ func (buffer *Buffer) Write (bytes []byte) (bytesWritten int, err error) { | |||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // ResetDot is a convenience method to reset the dot to the buffer origin point | ||||||
|  | // (0, 0). | ||||||
| func (buffer *Buffer) ResetDot () { | func (buffer *Buffer) ResetDot () { | ||||||
| 	buffer.Dot.X = 0 | 	buffer.Dot.X = 0 | ||||||
| 	buffer.Dot.Y = 0 | 	buffer.Dot.Y = 0 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // DamageBuffer is a special buffer that keeps track of damage information. | ||||||
|  | // Cells are dirty by default, are only clean when marked as clean, and become | ||||||
|  | // dirty again when they are altered in some way. | ||||||
| type DamageBuffer struct { | type DamageBuffer struct { | ||||||
| 	Buffer | 	Buffer | ||||||
| 	clean []bool | 	clean []bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetSize sets the width and height of the buffer. This clears all data in the | ||||||
|  | // buffer. If the width or height is negative, this method does nothing. | ||||||
| func (buffer *DamageBuffer) SetSize (width, height int) { | func (buffer *DamageBuffer) SetSize (width, height int) { | ||||||
| 	if width < 0 || height < 0 { return } | 	if width < 0 || height < 0 { return } | ||||||
| 	buffer.Buffer.SetSize(width, height) | 	buffer.Buffer.SetSize(width, height) | ||||||
| 	buffer.clean = make([]bool, width * height) | 	buffer.clean = make([]bool, width * height) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetColor sets the color of the cell at the specified x and y coordinates. | ||||||
| func (buffer *DamageBuffer) SetColor (x, y int, color Color) { | func (buffer *DamageBuffer) SetColor (x, y int, color Color) { | ||||||
| 	if buffer.isOutOfBounds(x, y) { return } | 	if buffer.isOutOfBounds(x, y) { return } | ||||||
| 	index := x + y * buffer.width | 	index := x + y * buffer.width | ||||||
| @ -128,6 +155,7 @@ func (buffer *DamageBuffer) SetColor (x, y int, color Color) { | |||||||
| 	buffer.Buffer.SetColor(x, y, color) | 	buffer.Buffer.SetColor(x, y, color) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetStyle sets the style of the cell at the specified x and y coordinates. | ||||||
| func (buffer *DamageBuffer) SetStyle (x, y int, style Style) { | func (buffer *DamageBuffer) SetStyle (x, y int, style Style) { | ||||||
| 	if buffer.isOutOfBounds(x, y) { return } | 	if buffer.isOutOfBounds(x, y) { return } | ||||||
| 	index := x + y * buffer.width | 	index := x + y * buffer.width | ||||||
| @ -135,6 +163,7 @@ func (buffer *DamageBuffer) SetStyle (x, y int, style Style) { | |||||||
| 	buffer.Buffer.SetStyle(x, y, style) | 	buffer.Buffer.SetStyle(x, y, style) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // SetRune sets the rune of the cell at the specified x and y coordinates. | ||||||
| func (buffer *DamageBuffer) SetRune (x, y int, content rune) { | func (buffer *DamageBuffer) SetRune (x, y int, content rune) { | ||||||
| 	if buffer.isOutOfBounds(x, y) { return } | 	if buffer.isOutOfBounds(x, y) { return } | ||||||
| 	index := x + y * buffer.width | 	index := x + y * buffer.width | ||||||
| @ -142,6 +171,8 @@ func (buffer *DamageBuffer) SetRune (x, y int, content rune) { | |||||||
| 	buffer.Buffer.SetRune(x, y, content) | 	buffer.Buffer.SetRune(x, y, content) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Write writes data stored in a byte slice to the buffer at the current dot | ||||||
|  | // position. This makes DamageBuffer an io.Writer. | ||||||
| func (buffer *DamageBuffer) Write (bytes []byte) (bytesWritten int, err error) { | func (buffer *DamageBuffer) Write (bytes []byte) (bytesWritten int, err error) { | ||||||
| 	text := string(bytes) | 	text := string(bytes) | ||||||
| 	bytesWritten = len(bytes) | 	bytesWritten = len(bytes) | ||||||
| @ -155,12 +186,15 @@ func (buffer *DamageBuffer) Write (bytes []byte) (bytesWritten int, err error) { | |||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Clean returns whether or not the cell at the specified x and y coordinates is | ||||||
|  | // clean. | ||||||
| func (buffer *DamageBuffer) Clean (x, y int) (clean bool) { | func (buffer *DamageBuffer) Clean (x, y int) (clean bool) { | ||||||
| 	if buffer.isOutOfBounds(x, y) { return } | 	if buffer.isOutOfBounds(x, y) { return } | ||||||
| 	clean = buffer.clean[x + y * buffer.width] | 	clean = buffer.clean[x + y * buffer.width] | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // MarkClean marks the cell at the specified x and y coordinates as clean. | ||||||
| func (buffer *DamageBuffer) MarkClean (x, y int) { | func (buffer *DamageBuffer) MarkClean (x, y int) { | ||||||
| 	if buffer.isOutOfBounds(x, y) { return } | 	if buffer.isOutOfBounds(x, y) { return } | ||||||
| 	buffer.clean[x + y * buffer.width] = true | 	buffer.clean[x + y * buffer.width] = true | ||||||
|  | |||||||
							
								
								
									
										15
									
								
								event.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								event.go
									
									
									
									
									
								
							| @ -1,11 +1,26 @@ | |||||||
| package stone | package stone | ||||||
| 
 | 
 | ||||||
|  | // Event can be any event. | ||||||
| type Event interface { } | type Event interface { } | ||||||
| 
 | 
 | ||||||
|  | // EventQuit is sent when the backend shuts down due to a window close, error, | ||||||
|  | // or something else. | ||||||
| type EventQuit struct { } | type EventQuit struct { } | ||||||
|  | 
 | ||||||
|  | // EventPress is sent when a button is pressed, or a key repeat event is | ||||||
|  | // triggered. | ||||||
| type EventPress struct { Button } | type EventPress struct { Button } | ||||||
|  | 
 | ||||||
|  | // Release is sent when a button is released. | ||||||
| type EventRelease struct { Button } | type EventRelease struct { Button } | ||||||
|  | 
 | ||||||
|  | // Resize is sent when the application window is resized by the user. This event | ||||||
|  | // must be handled, as it implies that the buffer has been resized and therefore | ||||||
|  | // cleared. Application.Draw() must be called after this event is recieved. | ||||||
| type EventResize struct { } | type EventResize struct { } | ||||||
|  | 
 | ||||||
|  | // EventMouseMove is sent when the mouse changes position. It contains the X and | ||||||
|  | // Y position of the mouse. | ||||||
| type EventMouseMove struct { | type EventMouseMove struct { | ||||||
| 	X int | 	X int | ||||||
| 	Y int | 	Y int | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								input.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								input.go
									
									
									
									
									
								
							| @ -2,6 +2,7 @@ package stone | |||||||
| 
 | 
 | ||||||
| import "unicode" | import "unicode" | ||||||
| 
 | 
 | ||||||
|  | // Button represents a keyboard or mouse button. | ||||||
| type Button int | type Button int | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| @ -72,6 +73,9 @@ const ( | |||||||
| 	KeyF12 Button = 155 | 	KeyF12 Button = 155 | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | // Printable returns whether or not the character could show up on screen. If | ||||||
|  | // this function returns true, the button can be cast to a rune and used as | ||||||
|  | // such. | ||||||
| func (button Button) Printable () (printable bool) { | func (button Button) Printable () (printable bool) { | ||||||
| 	printable = unicode.IsPrint(rune(button)) | 	printable = unicode.IsPrint(rune(button)) | ||||||
| 	return | 	return | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user