.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Tickit::RenderBuffer 3pm" .TH Tickit::RenderBuffer 3pm "2023-02-06" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" "Tickit::RenderBuffer" \- efficiently render text and line\-drawing .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package Tickit::Widget::Something; \& ... \& \& sub render_to_rb \& { \& my $self = shift; \& my ( $rb, $rect ) = @_; \& \& $rb\->eraserect( $rect ); \& $rb\->text_at( 2, 2, "Hello, world!", $self\->pen ); \& } .Ve .PP .PP .Vb 2 \& $win\->set_on_expose( sub { \& my ( $win, $rb, $rect ) = @_; \& \& $rb\->eraserect( $rect ); \& $rb\->text_at( 2, 2, "Hello, world!" ); \& }); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Provides a buffer of pending rendering operations to apply to the terminal. The buffer is modified by rendering operations performed by widgets or other code, and flushed to the terminal when complete. .PP This provides the following advantages: .IP "\(bu" 2 Changes can be made in any order, and will be flushed in top-to-bottom, left-to-right order, minimising cursor movements. .IP "\(bu" 2 Buffered content can be overwritten or partly erased once stored, simplifying some styles of drawing operation. Large areas can be erased, and then redrawn with text or lines, without causing a double-drawing flicker on the output terminal. .IP "\(bu" 2 The buffer supports line-drawing, complete with merging of line segments that meet in a character cell. Boxes, grids, and other shapes can be easily formed by drawing separate line segments, and the \f(CW\*(C`RenderBuffer\*(C'\fR will handle the corners and other junctions formed. .IP "\(bu" 2 A single buffer can be passed around all of the windows or widgets to properly combine line segments and layering effects, making it possible to create many kinds of sub-divided or layered output. .PP Drawing methods come in two forms; absolute, and cursor-relative: .IP "\(bu" 2 Absolute methods, identified by their name having a suffixed \f(CW\*(C`_at\*(C'\fR, operate on a position within the buffer specified by their argument. .IP "\(bu" 2 Cursor-relative methods, identified by their lack of \f(CW\*(C`_at\*(C'\fR suffix, operate at and update the position of the \*(L"virtual cursor\*(R". This is a position within the buffer that can be set using the \f(CW\*(C`goto\*(C'\fR method. The position of the virtual cursor is not affected by the absolute-position methods. .SS "State Stack" .IX Subsection "State Stack" The \f(CW\*(C`RenderBuffer\*(C'\fR stores a stack of saved state. The state of the buffer can be stored using the \f(CW\*(C`save\*(C'\fR method, so that changes can be made, before finally restoring back to that state using \f(CW\*(C`restore\*(C'\fR. The following items of state are saved: .IP "\(bu" 2 The virtual cursor position .IP "\(bu" 2 The clipping rectangle .IP "\(bu" 2 The render pen .IP "\(bu" 2 The translation offset .IP "\(bu" 2 The set of masked regions .PP When the state is saved to the stack, the render pen is remembered and merged with any pen set using the \f(CW\*(C`setpen\*(C'\fR method. .PP The queued content to render is not part of the state stack. It is intended that the state stack be used to implement recursive delegation of drawing operations down a tree of code, allowing child contexts to be created by saving state and modifying it, to later restore it again afterwards. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .SS "new" .IX Subsection "new" .Vb 1 \& $rb = Tickit::RenderBuffer\->new( %args ) .Ve .PP Returns a new instance of a \f(CW\*(C`Tickit::RenderBuffer\*(C'\fR. .PP Takes the following named arguments: .IP "lines => \s-1INT\s0" 8 .IX Item "lines => INT" .PD 0 .IP "cols => \s-1INT\s0" 8 .IX Item "cols => INT" .PD The size of the buffer area. .SH "METHODS" .IX Header "METHODS" .SS "lines" .IX Subsection "lines" .SS "cols" .IX Subsection "cols" .Vb 1 \& $lines = $rb\->lines \& \& $cols = $rb\->cols .Ve .PP Returns the size of the buffer area .SS "line" .IX Subsection "line" .SS "col" .IX Subsection "col" .Vb 1 \& $line = $rb\->line \& \& $col = $rb\->col .Ve .PP Returns the current position of the virtual cursor, or \f(CW\*(C`undef\*(C'\fR if it is not set. .SS "save" .IX Subsection "save" .Vb 1 \& $rb\->save .Ve .PP Pushes a new state-saving context to the stack, which can later be returned to by the \f(CW\*(C`restore\*(C'\fR method. .SS "savepen" .IX Subsection "savepen" .Vb 1 \& $rb\->savepen .Ve .PP Pushes a new state-saving context to the stack that only stores the pen. This can later be returned to by the \f(CW\*(C`restore\*(C'\fR method, but will only restore the pen. Other attributes such as the virtual cursor position will be unaffected. .PP This may be more efficient for rendering runs of text in a different pen, than multiple calls to \f(CW\*(C`text\*(C'\fR or \f(CW\*(C`erase\*(C'\fR using the same pen. For a single call it is better just to pass a different pen directly. .SS "restore" .IX Subsection "restore" .Vb 1 \& $rb\->restore .Ve .PP Pops and restores a saved state previously created with \f(CW\*(C`save\*(C'\fR. .SS "clip" .IX Subsection "clip" .Vb 1 \& $rb\->clip( $rect ) .Ve .PP Restricts the clipping rectangle of drawing operations to be no further than the limits of the given rectangle. This will apply to subsequent rendering operations but does not affect existing content, nor the actual rendering to the terminal. .PP Clipping rectangles cumulative; each call further restricts the drawing region. To revert back to a larger drawing area, use the \f(CW\*(C`save\*(C'\fR and \&\f(CW\*(C`restore\*(C'\fR stack. .SS "mask" .IX Subsection "mask" .Vb 1 \& $rb\->mask( $rect ) .Ve .PP Masks off the given area against any further changes. This will apply to subsequent rendering operations but does not affect the existing content, nor the actual rendering to the terminal. .PP Areas within the clipping region may be arbitrarily masked. Masks are scoped to the depth of the stack they are applied at; once the \f(CW\*(C`restore\*(C'\fR method is invoked, any masks applied since its corresponding \f(CW\*(C`save\*(C'\fR will be removed. .SS "translate" .IX Subsection "translate" .Vb 1 \& $rb\->translate( $downward, $rightward ) .Ve .PP Applies a translation to the coordinate system used by \f(CW\*(C`goto\*(C'\fR and the absolute-position methods \f(CW*_at\fR. After this call, all positions used will be offset by the given amount. .SS "reset" .IX Subsection "reset" .Vb 1 \& $rb\->reset .Ve .PP Removes any pending changes and reverts the \f(CW\*(C`RenderBuffer\*(C'\fR to its default empty state. Undefines the virtual cursor position, resets the clipping rectangle, and clears the stack of saved state. .SS "clear" .IX Subsection "clear" .Vb 1 \& $rb\->clear( $pen ) .Ve .PP Resets every cell in the buffer to an erased state. A shortcut to calling \f(CW\*(C`erase_at\*(C'\fR for every line. .SS "goto" .IX Subsection "goto" .Vb 1 \& $rb\->goto( $line, $col ) .Ve .PP Sets the position of the virtual cursor. .SS "setpen" .IX Subsection "setpen" .Vb 1 \& $rb\->setpen( $pen ) .Ve .PP Sets the rendering pen to use for drawing operations. If a pen is set then a \&\f(CW$pen\fR argument is optional to any of the drawing methods. If a pen argument is supplied as well as having a stored pen, then the attributes are merged, with the directly-applied pen taking precedence. .PP Successive calls to this method will replace the active pen used, but if there is a saved state on the stack it will be merged with the rendering pen of the most recent saved state. .PP This method may be preferable to passing pens into multiple \f(CW\*(C`text\*(C'\fR or \&\f(CW\*(C`erase\*(C'\fR calls as it may be more efficient than merging the same pen on every call. If the original pen is still required afterwards, the \f(CW\*(C`savepen\*(C'\fR / \&\f(CW\*(C`restore\*(C'\fR pair may be useful. .SS "skip_at" .IX Subsection "skip_at" .Vb 1 \& $rb\->skip_at( $line, $col, $len ) .Ve .PP Sets the range of cells given to a skipped state. No content will be drawn here, nor will any content existing on the terminal be erased. .PP Initially, or after calling \f(CW\*(C`reset\*(C'\fR, all cells are set to this state. .SS "skip" .IX Subsection "skip" .Vb 1 \& $rb\->skip( $len ) .Ve .PP Sets the range of cells at the virtual cursor position to a skipped state, and updates the position. .SS "skip_to" .IX Subsection "skip_to" .Vb 1 \& $rb\->skip_to( $col ) .Ve .PP Sets the range of cells from the virtual cursor position until before the given column to a skipped state, and updates the position to the column. .PP If the position is already past this column then the cursor is moved backwards and no buffer changes are made. .SS "skiprect" .IX Subsection "skiprect" .Vb 1 \& $rb\->skiprect( $rect ) .Ve .PP Sets the range of cells given by the rectangle to skipped state. .SS "text_at" .IX Subsection "text_at" .Vb 1 \& $cols = $rb\->text_at( $line, $col, $text, $pen ) .Ve .PP Sets the range of cells starting at the given position, to render the given text in the given pen. .PP Returns the number of columns wide the actual \f(CW$text\fR is (which may be more than was actually printed). .SS "text" .IX Subsection "text" .Vb 1 \& $cols = $rb\->text( $text, $pen ) .Ve .PP Sets the range of cells at the virtual cursor position to render the given text in the given pen, and updates the position. .PP Returns the number of columns wide the actual \f(CW$text\fR is (which may be more than was actually printed). .SS "erase_at" .IX Subsection "erase_at" .Vb 1 \& $rb\->erase_at( $line, $col, $len, $pen ) .Ve .PP Sets the range of cells given to erase with the given pen. .SS "erase" .IX Subsection "erase" .Vb 1 \& $rb\->erase( $len, $pen ) .Ve .PP Sets the range of cells at the virtual cursor position to erase with the given pen, and updates the position. .SS "erase_to" .IX Subsection "erase_to" .Vb 1 \& $rb\->erase_to( $col, $pen ) .Ve .PP Sets the range of cells from the virtual cursor position until before the given column to erase with the given pen, and updates the position to the column. .PP If the position is already past this column then the cursor is moved backwards and no buffer changes are made. .SS "eraserect" .IX Subsection "eraserect" .Vb 1 \& $rb\->eraserect( $rect, $pen ) .Ve .PP Sets the range of cells given by the rectangle to erase with the given pen. .SH "LINE DRAWING" .IX Header "LINE DRAWING" The \f(CW\*(C`RenderBuffer\*(C'\fR supports storing line-drawing characters in cells, and can merge line segments where they meet, attempting to draw the correct character for the segments that meet in each cell. .PP There are three exported constants giving supported styles of line drawing: .IP "\(bu" 4 \&\s-1LINE_SINGLE\s0 .Sp A single, thin line .IP "\(bu" 4 \&\s-1LINE_DOUBLE\s0 .Sp A pair of double, thin lines .IP "\(bu" 4 \&\s-1LINE_THICK\s0 .Sp A single, thick line .PP Note that linedrawing is performed by Unicode characters, and not every possible combination of line segments of differing styles meeting in a cell is supported by Unicode. The following sets of styles may be relied upon: .IP "\(bu" 4 Any possible combination of only \f(CW\*(C`SINGLE\*(C'\fR segments, \f(CW\*(C`THICK\*(C'\fR segments, or both. .IP "\(bu" 4 Any combination of only \f(CW\*(C`DOUBLE\*(C'\fR segments, except cells that only have one of the four borders occupied. .IP "\(bu" 4 Any combination of \f(CW\*(C`SINGLE\*(C'\fR and \f(CW\*(C`DOUBLE\*(C'\fR segments except where the style changes between \f(CW\*(C`SINGLE\*(C'\fR to \f(CW\*(C`DOUBLE\*(C'\fR on a vertical or horizontal run. .PP Other combinations are not directly supported (i.e. any combination of \&\f(CW\*(C`DOUBLE\*(C'\fR and \f(CW\*(C`THICK\*(C'\fR in the same cell, or any attempt to change from \&\f(CW\*(C`SINGLE\*(C'\fR to \f(CW\*(C`DOUBLE\*(C'\fR in either the vertical or horizontal direction). To handle these cases, a cell may be rendered with a substitution character which replaces a \f(CW\*(C`DOUBLE\*(C'\fR or \f(CW\*(C`THICK\*(C'\fR segment with a \f(CW\*(C`SINGLE\*(C'\fR one within that cell. The effect will be the overall shape of the line is retained, but close to the edge or corner it will have the wrong segment type. .PP Conceptually, every cell involved in line drawing has a potential line segment type at each of its four borders to its neighbours. Horizontal lines are drawn though the vertical centre of each cell, and vertical lines are drawn through the horizontal centre. .PP There is a choice of how to handle the ends of line segments, as to whether the segment should go to the centre of each cell, or should continue through the entire body of the cell and stop at the boundary. By default line segments will start and end at the centre of the cells, so that horizontal and vertical lines meeting in a cell will form a neat corner. When drawing isolated lines such as horizontal or vertical rules, it is preferable that the line go right through the cells at the start and end. To control this behaviour, the \&\f(CW$caps\fR bitmask is used. \f(CW\*(C`CAP_START\*(C'\fR and \f(CW\*(C`CAP_END\*(C'\fR state that the line should consume the whole of the start or end cell, respectively; \f(CW\*(C`CAP_BOTH\*(C'\fR is a convenient shortcut specifying both behaviours. .PP A rectangle may be formed by combining two \f(CW\*(C`hline_at\*(C'\fR and two \f(CW\*(C`vline_at\*(C'\fR calls, without end caps: .PP .Vb 4 \& $rb\->hline_at( $top, $left, $right, $style, $pen ); \& $rb\->hline_at( $bottom, $left, $right, $style, $pen ); \& $rb\->vline_at( $top, $bottom, $left, $style, $pen ); \& $rb\->vline_at( $top, $bottom, $right, $style, $pen ); .Ve .SS "hline_at" .IX Subsection "hline_at" .Vb 1 \& $rb\->hline_at( $line, $startcol, $endcol, $style, $pen, $caps ) .Ve .PP Draws a horizontal line between the given columns (both are inclusive), in the given line style, with the given pen. .SS "vline_at" .IX Subsection "vline_at" .Vb 1 \& $rb\->vline_at( $startline, $endline, $col, $style, $pen, $caps ) .Ve .PP Draws a vertical line between the centres of the given lines (both are inclusive), in the given line style, with the given pen. .SS "linebox_at" .IX Subsection "linebox_at" .Vb 1 \& $rb\->linebox_at( $startline, $endline, $startcol, $endcol, $style, $pen ) .Ve .PP A convenient shortcut to calling two \f(CW\*(C`hline_at\*(C'\fR and two \f(CW\*(C`vline_at\*(C'\fR in order to draw a rectangular box. .SS "char_at" .IX Subsection "char_at" .Vb 1 \& $rb\->char_at( $line, $col, $codepoint, $pen ) .Ve .PP Sets the given cell to render the given Unicode character (as given by codepoint number, not character string) in the given pen. .SS "char" .IX Subsection "char" .Vb 1 \& $rb\->char( $codepoint, $pen ) .Ve .PP Sets the cell at the virtual cursor position to render the given Unicode character (as given by codepoint number, not character string) in the given pen, and updates the position. .PP While this is also achieveable by the \f(CW\*(C`text\*(C'\fR and \f(CW\*(C`text_at\*(C'\fR methods, these methods are implemented without storing a text segment, so can be more efficient than many single-column wide \f(CW\*(C`text_at\*(C'\fR calls. .SS "copyrect" .IX Subsection "copyrect" .SS "moverect" .IX Subsection "moverect" .Vb 1 \& $rb\->copyrect( $dest, $src ) \& \& $rb\->moverect( $dest, $src ) .Ve .PP Copies (or moves) buffered content from one rectangular region to another. The two regions may overlap. .PP The move operation is identical to the copy operation followed by setting the vacated areas of the source rectangle not covered by the destination to skipping state. .SS "get_cell" .IX Subsection "get_cell" .Vb 1 \& $cell = $rb\->get_cell( $line, $col ) .Ve .PP Returns a structure containing the content stored in the given cell. The \&\f(CW$cell\fR structure responds to the following methods: .ie n .IP "$cell\->char" 4 .el .IP "\f(CW$cell\fR\->char" 4 .IX Item "$cell->char" On a skipped cell, returns \f(CW\*(C`undef\*(C'\fR. On a text or char cell, returns the unicode codepoint number. On a line or erased cell, returns 0. .ie n .IP "$cell\->linemask" 4 .el .IP "\f(CW$cell\fR\->linemask" 4 .IX Item "$cell->linemask" On a line cell, returns a representation of the line segments in the cell. This is a sub-structure with four fields; \f(CW\*(C`north\*(C'\fR, \f(CW\*(C`south\*(C'\fR, \f(CW\*(C`east\*(C'\fR, \f(CW\*(C`west\*(C'\fR to represent the four cell borders; the value of each is either zero, or one of the \f(CW\*(C`LINE_\*(C'\fR constants. .Sp On any other kind of cell, returns \f(CW\*(C`undef\*(C'\fR. .ie n .IP "$cell\->pen" 4 .el .IP "\f(CW$cell\fR\->pen" 4 .IX Item "$cell->pen" Returns the \f(CW\*(C`Tickit::Pen\*(C'\fR for non-skipped cells, or \f(CW\*(C`undef\*(C'\fR for skipped cells. .SS "flush_to_term" .IX Subsection "flush_to_term" .Vb 1 \& $rb\->flush_to_term( $term ) .Ve .PP Renders the stored content to the given Tickit::Term. After this, the buffer will be cleared and reset back to initial state. .SH "AUTHOR" .IX Header "AUTHOR" Paul Evans