Tickit::RenderContext - efficiently render text and linedrawing on Tickit windows
Tickit::RenderContext
package Tickit::Widget::Something; ... sub render { my $self = shift; my $win = $self->window or return; my $rc = Tickit::RenderContext->new( lines => $win->lines, cols => $win->cols, ); $rc->text_at( 2, 2, "Hello, world!", $self->pen ); $rc->render_to_window( $win ); }
Provides a buffer of pending rendering operations to apply to a Window. The buffer is modified by rendering operations performed by the widget, and flushed to the widget's window when complete.
This provides the following advantages:
Changes can be made in any order, and will be flushed in top-to-bottom, left-to-right order, minimising cursor movements.
Buffered content can be overwritten or partly erased once stored, simplifying some styles of drawing operation.
The buffer supports line-drawing, complete with merging of line segments that meet in a character cell.
This code is still in the experiment stage. At some future point it may be merged into the main Tickit distribution, and reimplemented in efficient XS or C code.
Returns a new instance of a Tickit::RenderContext.
Takes the following named arguments:
The size of the buffer area.
Returns the size of the buffer area
Removes any pending changes and reverts the render context to its default empty state.
A shortcut to calling erase_at for every line.
erase_at
Sets the range of cells given to a skipped state. No content will be drawn here, nor will any content existing on the window be erased.
Initially, or after calling reset, all cells are set to this state.
reset
Sets the range of cells starting at the given position, to render the given text in the given pen.
Sets the range of cells given to erase with the given pen.
Draws a horizontal line between the given columns (both are inclusive), in the given line style, with the given pen.
$style should be one of three exported constants:
$style
LINE_SINGLE
A single, thin line
LINE_DOUBLE
A pair of double, thin lines
LINE_THICK
A single, thick line
Draws a vertical line between the given lines (both are inclusive), in the given line style, with the given pen. $style is as for hline.
hline
Renders the stored content to the given Tickit::Window. After this, the context will be cleared and reset back to initial state.
As this code is still experimental, there are many planned features it currently lacks:
A char_at method to store a single Unicode character more effiicently than a 1-column text cell. This may be useful for drawing characters such as arrows and tick-marks.
char_at
A virtual cursor position and pen state, to allow drawing in a position-relative rather than absolute style.
Clipping rectangle to support partial window updates
Hole regions, to directly support shadows made by floating windows
Child contexts, to support cascading render/expose logic down a window tree
Direct rendering to a Tickit::Term instead of a Window.
Paul Evans <leonerd@leonerd.org.uk>
To install Tickit::RenderContext, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tickit::RenderContext
CPAN shell
perl -MCPAN -e shell install Tickit::RenderContext
For more information on module installation, please visit the detailed CPAN module installation guide.