Module wonderful.buffer
Display buffers and buffer view.
See also:
Classes and inheritance
Buffer | A non-renderable buffer. |
Framebuffer | A flushable buffer. |
BufferView | A view on some rectangular area within a buffer |
Class Buffer
Buffer:__new__(args) | Construct a new buffer. |
Buffer:inRange(x, y) | Check if a cell belongs to the buffer. |
Buffer:alphaBlend(color1, color2, alpha) | Perform alpha blending of two colors. |
Buffer:_set(x, y, fg, bg, alpha, char) | Set a cell. |
Buffer:set(x0, y0, fg, bg, alpha, line[, vertical=false]) | Set a line of characters. |
Buffer:_get(x, y) | Retrieve a cell from the storage. |
Buffer:get(x, y) | Retrieve a cell from the storage. |
Buffer:intersection(x0, y0, w, h) | Get an intersection of the buffer and a given sub-box. |
Buffer:_fill(x0, y0, x1, y1, fg, bg, alpha, char) | Fill an area with a given cell. |
Buffer:fill(x0, y0, w, h, fg, bg, alpha, char) | Fill an area with a given cell. |
Buffer:clear() | Reset all cells to default. |
Buffer:view(x, y, w, h, sx, sy, sw, sh) | Create a buffer view. |
Buffer:copyFrom(src[, sx[, sy[, sw[, sh]]]], dx, dy) | Copy an area from a buffer and paste it onto self. |
Buffer:clone([x0=1][, y0=1], w, h) | Create a new buffer, and copy an area from self onto it. |
Class Framebuffer
Framebuffer:__new__(args) | Construct a new framebuffer. |
Framebuffer:writeInstruction(itype, x, y, color, text) | Write a render instruction. |
Framebuffer:compileInstructions(force) | Compile GPU instructions to render the changes onto a GPU. |
Framebuffer:flush(sx, sy, gpu[, force]) | Flush a buffer onto a GPU. |
Class BufferView
BufferView:__new__(buf, coordBox, restrictBox, debug) | Construct a view. |
BufferView:absCoords(x, y) | Convert view-relative coordinates to buffer-relative coordinates. |
BufferView:relCoords(x, y) | Convert buffer-relative coordinates to view-relative coordinates. |
BufferView:inRange(x, y) | Check if a cell at given buffer-relative coordinates belongs to the view. |
BufferView:_set(x, y, fg, bg, alpha, char) | Proxy _set to the buffer. |
BufferView:_fill(x0, y0, x1, y1, fg, bg, alpha, char) | Proxy _fill to the buffer. |
BufferView:_get(x, y) | Proxy _get to the buffer. |
BufferView:intersection(x0, y0, w, h) | Proxy intersection to the buffer. |
BufferView:view(x, y, w, h, sx, sy, sw, sh) | Create a view relative to the view. |
Classes and inheritance
- Buffer
- A non-renderable buffer.
- Framebuffer
-
A flushable buffer.
Parent classes:
- BufferView
-
A view on some rectangular area within a buffer
Parent classes:
Class Buffer
- Buffer:__new__(args)
-
Construct a new buffer.
The debug mode introduces a few sanity checks. They allow to notice the potential bugs and errors, but also slow down the program significantly.
Parameters:
- args a keyword argument table
- w int a width of buffer
- h int a height of buffer
- depth int a color depth
- debug boolean whether the debug mode should be set
- defaultFg int the default foreground color (default 0xffffff)
- defaultBg int the default background color (default 0x000000)
- args a keyword argument table
- Buffer:inRange(x, y)
-
Check if a cell belongs to the buffer.
Parameters:
- x int a row number
- y int a row number
Returns:
-
boolean
- Buffer:alphaBlend(color1, color2, alpha)
-
Perform alpha blending of two colors.
Parameters:
- color1 int the first color
- color2 int the second color
- alpha number an opacity (an alpha value ∈ [0; 1])
Returns:
-
int
the result of alpha blending
- Buffer:_set(x, y, fg, bg, alpha, char)
-
Set a cell.
This is an internal method that does not perform sanity checks. Futhermore, unlike set, this method only sets a single cell per call.
Parameters:
- x int a column number
- y int a row number
- fg int a foreground color
- bg int a background color
- alpha number an opacity (an alpha value ∈ [0; 1])
- char string a character
See also:
- Buffer:set(x0, y0, fg, bg, alpha, line[, vertical=false])
-
Set a line of characters.
Parameters:
- x0 int a column number
- y0 int a row number
- fg optional int a foreground color
- bg optional int a background color
- alpha number an opacity (an alpha value ∈ [0; 1])
- line optional string a text line
- vertical boolean if true, set a vertical line (default false)
See also:
- Buffer:_get(x, y)
-
Retrieve a cell from the storage.
This is an internal method that does not perform sanity checks. Futhermore, unlike get, this method returns a packed color instead of foreground and background.
Parameters:
- x int a column number
- y int a row number
Returns:
- string a cell's character
- int a cell's packed and deflated color
See also:
- Buffer:get(x, y)
-
Retrieve a cell from the storage.
Parameters:
- x int a column number
- y int a row number
Returns:
- string a cell's character
- int a cell's foreground color
- int a cell's background color
See also:
- Buffer:intersection(x0, y0, w, h)
-
Get an intersection of the buffer and a given sub-box.
Parameters:
- x0 int a top-left cell column number
- y0 int a top-left cell row number
- w int a width of sub-box
- h int a height of sub-box
Returns:
- int an intersection's top-left cell column number
- int an intersection's top-left cell row number
- int an intersection's bottom-right cell column number
- int an intersection's bottom-right cell row number
Or
-
nil
the intersection is empty
- Buffer:_fill(x0, y0, x1, y1, fg, bg, alpha, char)
-
Fill an area with a given cell.
This is an internal method that does not perform sanity checks.
Parameters:
- x0 int a top-left cell column number
- y0 int a top-left cell row number
- x1 int a bottom-right cell column number
- y1 int a bottom-right cell row number
- fg optional int a foreground color
- bg optional int a background color
- alpha number an opacity (an alpha value ∈ [0; 1])
- char optional string a character
See also:
- Buffer:fill(x0, y0, w, h, fg, bg, alpha, char)
-
Fill an area with a given cell.
This method performs sanity checks, which may decrease perfomance significantly if used too often.
Parameters:
- x0 int a top-left cell column number
- y0 int a top-left cell row number
- w int an area width
- h int an area width
- fg optional int a foreground color
- bg optional int a background color
- alpha number an opacity (an alpha value ∈ [0; 1])
- char optional string a character
See also:
- Buffer:clear()
- Reset all cells to default.
- Buffer:view(x, y, w, h, sx, sy, sw, sh)
-
Create a buffer view.
Parameters:
- x number a coordinate box's top-left cell column number
- y number a coordinate box's top-left cell row number
- w number a coordinate box's width
- h number a coordinate box's height
- sx number a restricting box's top-left cell column number
- sy number a restricting box's top-left cell row number
- sw number a restricting box's width
- sh number a restricting box's height
Returns:
- Buffer:copyFrom(src[, sx[, sy[, sw[, sh]]]], dx, dy)
-
Copy an area from a buffer and paste it onto self.
If the source area are omitted, the whole source buffer is copied.
Parameters:
- src the source buffer to copy from
- sx int the area's top-left cell column number (optional)
- sy int the area's top-left cell row number (optional)
- sw int the area width (optional)
- sh int the area height (optional)
- dx int the column at which to paste the area's top-left cell
- dy int the row at which to paste the area's top-left cell
- Buffer:clone([x0=1][, y0=1], w, h)
-
Create a new buffer, and copy an area from self onto it.
Parameters:
- x0 int the source area's top-left block column number (default 1)
- y0 int the source area's top-left block row number (default 1)
- w int the source area width
- h int the source area height
Returns:
-
Buffer
the cloned buffer
Or
-
nil
width or height is less than 1
Class Framebuffer
- Framebuffer:__new__(args)
-
Construct a new framebuffer.
Parameters:
- args a keyword argument table
- w int a width of buffer
- h int a height of buffer
- depth int a color depth
- debug boolean whether the debug mode should be set
- args a keyword argument table
- Framebuffer:writeInstruction(itype, x, y, color, text)
-
Write a render instruction.
Used by flush when compiling render instructions.
Parameters:
- itype
one of
InstructionTypes
variants - x int a 0-based column number
- y int a 0-based row number
- color
int
a packed color (
(fg << 24) | bg
) - text string a char for fills, or a line for sets
- itype
one of
- Framebuffer:compileInstructions(force)
-
Compile GPU instructions to render the changes onto a GPU.
Used by flush.
Parameters:
- force boolean whether to do force-redraw
- Framebuffer:flush(sx, sy, gpu[, force])
-
Flush a buffer onto a GPU.
The 4th argument, force, controls whether the buffer should also flush the cells unchanged since the last flush.
Parameters:
- sx int a top-left cell column number to draw buffer at
- sy int a top-left cell row number to draw buffer at
- gpu table GPU component proxy
- force boolean whether to do force-redraw (optional)
Class BufferView
- BufferView:__new__(buf, coordBox, restrictBox, debug)
-
Construct a view.
This method should not be used directly.
Parameters:
- buf
- coordBox
- restrictBox
- debug
See also:
- BufferView:absCoords(x, y)
-
Convert view-relative coordinates to buffer-relative coordinates.
Parameters:
- x int a view-relative cell column number
- y int a view-relative cell row number
Returns:
- int a buffer-relative cell column number
- int a buffer-relative cell row number
- BufferView:relCoords(x, y)
-
Convert buffer-relative coordinates to view-relative coordinates.
Parameters:
- x int a buffer-relative cell column number
- y int a buffer-relative cell row number
Returns:
- int x a view-relative cell column number
- int y a view-relative cell row number
- BufferView:inRange(x, y)
-
Check if a cell at given buffer-relative coordinates belongs to the view.
Parameters:
- x int a view-relative cell column number
- y int a view-relative cell row number
- BufferView:_set(x, y, fg, bg, alpha, char)
-
Proxy _set to the buffer.
Parameters:
- x int a view-relative cell column number
- y int a view-relative cell row number
- fg optional int a foreground color
- bg optional int a background color
- alpha number an opacity (an alpha value ∈ [0; 1])
- char optional string a character
See also:
- BufferView:_fill(x0, y0, x1, y1, fg, bg, alpha, char)
-
Proxy _fill to the buffer.
Parameters:
- x0 int a view-relative top-left cell column number
- y0 int a view-relative top-left cell row number
- x1 int a view-relative bottom-right cell column number
- y1 int a view-relative bottom-right cell row number
- fg optional int a foreground color
- bg optional int a background color
- alpha number an opacity (an alpha value ∈ [0; 1])
- char optional string a character
See also:
- BufferView:_get(x, y)
-
Proxy _get to the buffer.
Parameters:
- x int a view-relative cell column number
- y int a view-relative cell row number
Returns:
- string a cell's character
- int a cell's packed and deflated color
See also:
- BufferView:intersection(x0, y0, w, h)
-
Proxy intersection to the buffer.
Parameters:
- x0 int a view-relative top-left cell column number
- y0 int a view-relative top-left cell row number
- w int a sub-box width
- h int a sub-box height
Returns:
- int a buffer-relative intersection's top-left cell column number
- int a buffer-relative intersection's top-left cell row number
- int a buffer-relative intersection's bottom-right cell column number
- int a buffer-relative intersection's bottom-right cell row number
Or
-
nil
the intersection is empty
See also:
- BufferView:view(x, y, w, h, sx, sy, sw, sh)
-
Create a view relative to the view.
The child view is bounded by the parent view's restricting box.
All coordinates are relative to the parent view's coordinate box.
The child view will point to the buffer directly.
Parameters:
- x int a coordinate box's top-left cell column number
- y int a coordinate box's top-left cell row number
- w int a coordinate box's width
- h int a cooridnate box's height
- sx int a restricting box's top-left cell column number
- sy int a restricting box's top-left cell row number
- sw int a restricting box's width
- sh int a restricting box's height
Returns:
See also: