VideoChip

**VideoChip** is a module in *Retro Gadgets*. It controls Screens and ScreenButtons to display graphics on them, likely using SpriteSheets.

## Sizes

There are three different VideoChip sizes, but currently their behavior is identical.

## Properties

**Mode** VideoChipMode
The buffering mode for this VideoChip. Defaults to DoubleBuffer.

read only
**Width** number
Width in pixels of the rendering buffer. The area takes into account all the displays connected to this VideoChip.

read only
**Height** number
Height in pixels of the rendering buffer. The area takes into account all the displays connected to this VideoChip.

## Methods

**Clear**( color color )
Clears all the render area with the specified color

**SetPixel**( position vec2, color color )
Returns an InputSource axis for a given axis.

**DrawPointGrid**( gridOffset vec2, dotsDistance number, color color )
Draws a dotted grid on the entire display area, with an offset. The dotsDistance parameter express the distance in pixels, on both axis, between dots.

**DrawLine**( start vec2, end vec2, color color )
Draws a line from position start to position end, using the specified color

**DrawCircle**( position vec2, radius number, color color )
Draws an empty circle at the specified position, with the specified radius, in the specified color.

**FillCircle**( position vec2, radius number, color color )
Draws a filled circle at the specified position, with the specified radius, in the specified color.

**DrawRect**( position1 vec2, position2 vec2, color color )
Draws an empty rect from position1 to position2, in the specified color.

**FillRect**( position1 vec2, position2 vec2, color color )
Draws a filled rect from position1 to position2, in the specified color.

**DrawTriangle**( position1 vec2, position2 vec2, position3 vec3, color color )
Draws an empty triangle with vertexes in position1, position2, and position3, in the specified color.

**FillTriangle**( position1 vec2, position2 vec2, position3 vec3, color color )
Draws a filled triangle with vertexes in position1, position2, and position3, in the specified color.

**DrawSprite**( position vec2, spriteSheet SpriteSheet, spriteX number, spriteY number, tintColor color, backgroundColor color )
Draws a specific sprite frame from the spriteSheet.

* Position is the on-screen sprite desired position starting from the top left corner,
* spriteSheet is the SpriteSheet asset containing the sprite frame to draw,
* spriteX and spriteY are the coordinates to identify the desired sprite frame starting from the, top left corner, expressed in grid units.
	+ spriteX=0 and spriteY=0 are the coordinates of the first sprite, top left.
* tintColor is the color multiplier used to draw the sprite frame. Color(255,255,255) or color.white will leave the sprite frame unaffected.
* backgroundColor is the color used to replace the transparent areas of the spriteFrame. Using ColorRGBA(0,0,0,0) or color.clear will leave the transparency as it is.

**DrawCustomSprite**( position vec2, spriteSheet SpriteSheet, spriteOffset vec2, spriteSize vec2, tintColor color, backgroundColor color )
Draw a portion of a SpriteSheet (defined by spriteOffset, spriteSize) without taking into account of the grid.

**DrawText**( fontSprite vec2, spriteSheet SpriteSheet, text string, tintColor color, backgroundColor color )
Draw a portion of a SpriteSheet (defined by spriteOffset, spriteSize) without taking into account of the grid.

**RasterSprite**( position1 vec2, position2 vec2, position3 vec2, position4 vec2, spriteSheet SpriteSheet, spriteX number, spriteY number, tintColor color, backgroundColor color )
Draws a specific sprite frame from the spriteSheet mapping it on a quad identified by position1, position2, position3, position4

**DrawCustomSprite**( position1 vec2, position2 vec2, position3 vec2, position4 vec2, spriteSheet SpriteSheet, spriteOffset vec2, spriteSize vec2, tintColor color, backgroundColor color )
Draws a portion of a SpriteSheet (defined by spriteOffset, spriteSize) without taking into account of the grid mapping it on a quad identified by position1, position2, position3, position4.

**DrawRenderBuffer**( position vec2, renderBuffer RenderBuffer, width number, height number )
Draws a render buffer (supposedly coming from Webcam component) at the desired position, width and height.

**SetPixelData**( pixelData PixelData )
Apply pixelData content to VideoChip's video buffer, width and height must have the same value as VideoChip's.

**BlitPixelData**( position vec2, pixelData PixelData )
Draw a pixelData content to VideoChip's video buffer at the offset of position. This way PixelData width and height don't need to match the VideoChip's.

## Buffering modes

There are two valid values for a VideoChipMode:

* SingleBuffer
* DoubleBuffer

Double buffering means the video chip will flip between two buffers instead of constantly refreshing the same one. This is a technique to prevent image tearing, since with two buffers you don't see the current active one being drawn to. In practice, use whichever mode seems to work best in a given gadget.