NAME
FLTK::draw - The FLTK drawing library, used by all widgets to draw themselves
Description
The FLTK drawing library, used by all widgets to draw themselves.
These functions can only be called when FLTK is setup to draw things. This is only true:
Inside the default
Widget::draw()method.Inside the
Symbol::draw()function.After calling
Widget::make_current(), before callingwait()orflush().
Calling the drawing functions at other times produces undefined results, including crashing.
Functions
addarc
FLTK::addarc( $l, $t, $w, $h, $start, $end );-
Add a series of points to the current path on the arc of an ellipse. The ellipse in inscribed in the
l,t,w,hrectangle, and thestartandendangles are measured in degrees counter-clockwise from 3 o'clock, 45 points at the upper-right corner of the rectangle. If end is less than start then it draws the arc in a clockwise direction.Import this function with the
:drawtag.
addchord
FLTK::addchord( $rect, $start, $end );-
Add an isolated circular arc to the path. It is inscribed in the rectangle so if it is stroked with the default line width it exactly fills the rectangle (this is slightly smaller than
addarc()will draw). If the angles are 0 and 360 a closed circle is added.This tries to take advantage of the primitive calls provided by Xlib and GDI32. Limitations are that you can only draw one, a rotated current transform does not work.
Import this function with the
:drawtag.
addcurve
FLTK::addcurve( $x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3 );-
Add a series of points on a Bezier spline to the path. The curve ends (and two of the points) are at
x0,y0andx3,y3. The "handles" are atx1,y1andx2,y2.Import this function with the
:drawtag.
addpie
FLTK::addpie( $rect, $start, $end );-
Add a pie-shaped closed piece to the path, inscribed in the rectangle so if it is stroked with the default line width it exactly fills the rectangle (this is slightly smaller than <
addarc()will draw). If you want a full circle useaddchord().This tries to take advantage of the primitive calls provided by Xlib and GDI32. Limitations are that you can only draw one per path, that rotated coordinates don't work, and doing anything other than
fillpath()will produce unpredictable results.See also
addchord().Import this function with the
:drawtag.
addvertex
FLTK::addvertex( $x, $y );-
Add a single vertex to the current path. (if the path is empty or a
closepath()was done, this is equivalent to a "moveto" in PostScript, otherwise it is equivalent to a "lineto").This integer version is provided by the fltk libs because it is much faster than the floating-point version. FLTK (the module) will "resolve" which one you want to call.
Import this function with the
:drawtag.
addvertices
FLTK::addvertices( @xy1, ..., @xy );-
Add a whole set of vertices to the current path. This is much faster than calling
addvertexonce for each point.Import this function with the
:drawtag.
addvertices_transformed
FLTK::addvertices_transformed( @xy1, ..., @xy );-
Adds a whole set of vertcies that have been produced from values returned by
transform(). This is howcurve()andarc()are implemented.Import this function with the
:drawtag.
clipout
FLTK::clipout( $rectangle );-
Remove
rectanglefrom the current clip region, thus making it a more complex shape. This does not push the stack, it just replaces the top of it.Some graphics backends (OpenGL and Cairo, at least) do not support non-rectangular clip regions. This call does nothing on those.
Import this function with the
:drawtag.
closepath
FLTK::closepath( );-
Similar to drawing another vertex back at the starting point, but fltk knows the path is closed. The next
addvertex()will start a new disconnected part of the shape.It is harmless to call
closepath()several times in a row, or to call it before the first point. Sections with less than 3 points in them will not draw anything when filled.Import this function with the
:drawtag.
column_widths
FLTK::column_widths( $col1, ..., $col );-
Set where
\tcharacters go in label text formatter.Import this function with the
:drawtag. my @widths = FLTK::column_widths( );-
Get where
\tcharacters go in label text formatter.Okay, not really. This is useless. Thank the fltk authors.
Import this function with the
:drawtag.
concat
FLTK::concat( $a, $b, $c, $d, $x, $y );-
Multiply the current transformation by
a b 0 c d 0 x y 1Import this function with the
:drawtag.
drawflags
FLTK::drawflags( $flags );-
Import this function with the
:drawtag. my $flags = FLTK::drawflags( );-
Import this function with the
:drawtag.
drawimage
FLTK::drawimage( $pointer, $type, $rect, $line_delta );-
Draw a image (a rectangle of pixels) stored in your program's memory. The current transformation (scale, rotate) is applied.
pointer-
Points at the first byte of the top-left pixel.
type-
Describes how to interpret the bytes of each pixel.
rect-
The image is put in the top-left corner and the width and height declare how many pixels the image has.
line_delta-
How much to add to
pointerto go 1 pixel down.
By setting
line_deltato larger thandepth($type)*$rect-w()> you can crop a picture out of a larger buffer. You can also set it negative for images that are stored with bottom-to-top in memory, notice that in this casepointerstill points at the top-left pixel, which is at theendof your buffer minus one line_delta.The X version of FLTK will
abort()if the default visual is one it cannot use for images. To avoid this callvisual(fltk::RGB)at the start of your program.Import this function with the
:drawor:imagetags. FLTK::drawimage( $pointer, $type, $rect );-
Same except
$line_deltais set to$rect-w() * depth($type)>, indicating the rows are packed together one after another with no gap.Import this function with the
:drawor:imagetags.
drawline
FLTK::drawline( $x0, $y0, $x1, $y1 );-
Draw a straight line between the two points.
If
line_width()is zero, this tries to draw as though a 1x1 square pen is moved between the first centers of pixels to the lower-right of the start and end points. Thus if$y == $y1this will fill a rectangle with the corners$x,$yand$x1+1,$y+1. This may be 1 wider than you expect, but is necessary for compatability with previous fltk versions (and is due to the original X11 behavior).If
line_width()is not zero then the results depend on the back end. It also may not produce consistent results if the ctm is not an integer translation or if the line is not horizontal or vertical.Import this function with the
:drawtag.
drawpoint
FLTK::drawpoint( $x, $y );-
Draw a dot at the given point. If
line_width()is zero this is the single pixel containing$x,$y, or the one to the lower-right if$xand$ytransform to integers. Ifline_width()is non-zero this is a dot drawn with the current pen and line caps (currently draws nothing in some api's unless theline_stylehasCAP_ROUND).Import this function with the
:drawtag.
drawstyle
my $style = FLTK::drawstyle( );-
Return the last style sent to
drawstyle($style,$flags). Some drawing functions (such as glyphs) look in this for box types. If this has not been called it isWidget::default_style.Import this function with the
:drawtag. FLTK::drawstyle( $style, $flags );-
Draw using this style. Set
drawstyle()to this,drawflags()toflags, callssetcolor()andsetbgcolor()with appropriate colors for this style and the given flags, and callssetfont(). This is called by thedraw()methods on most fltk widgets. The calling Widget picks what flags to pass to the Symbols so that when they call this they get the correct colors for each part of the widget.Flags that are understood:
HIGHLIGHT-
If
highlight_color()is non-zero, set bg tohighlight_color()and fg tohighlight_textcolor(). OUTPUT-
Normally
color(),textcolor(),textfont(), andtextsize()are used. If this flag is setbuttoncolor(),labelcolor(),labelfont(), andlabelsize()are used. Widgets will set this true for any internal buttons, but false for the main area. INACTIVE_R-
Change the fg to a gray color.
It then further modifies fg so that it contrasts with the bg.
Import this function with the
:drawtag.
drawtext
FLTK::drawtext( $text, $rect, $flags );-
This is the fancy string-drawing function that is used to draw all labels in fltk. The string is formatted and aligned inside the passed rectangle. This also:
- Breaks the text into lines at
\ncharacters. Word-wraps (ifflagshasALIGN_WRAPset) so the words fit in the columns. - Looks up
@xyz;sequeces to see if they are a Symbol, if so it prints that symbol instead. This is skipped if the flags hasRAW_LABELset. - Parses
&xcombinations to produce Microsoft style underscores, unlessRAW_LABELflag is set. - Splits it at every
\ttab character and usescolumn_widths()to set each section into a column.
Import this function with the
:drawtag. - Breaks the text into lines at
FLTK::drawtext( $text, $x, $y );-
Draw a string.
Import this function with the
:drawtag. FLTK::drawtext( $text, $x, $y, $length );-
Draw the first
lengthbytes (not characters if utf8 is used) starting at the given position.Import this function with the
:drawtag.
drawtext_transformed
FLTK::drawtext_transformed( $text, $n, $x, $y );-
Draw text starting at a point returned by
transform(). This is needed for complex text layout when the current transform may not match the transform being used by the font.Import this function with the
:drawtag.
fillpath
FLTK::fillpath( );-
Does
closepath()and then fill with the current color, and then clear the path.For portability, you should only draw polygons that appear the same whether "even/odd" or "non-zero" winding rules are used to fill them. This mostly means that holes should be drawn in the opposite direction of the outside.
Warning: result is somewhat different on X and Win32! Use
fillstrokepath()to make matching shapes. In my opinion X is correct, we may change the Win32 version to match in the future, perhaps by making the current pen invisible?Import this function with the
:drawtag.
fillrect
FLTK::fillrect( $x, $y, $w, $h );-
Fill the rectangle with the current color.
Import this function with the
:drawtag. FLTK::fillrect( $rectangle );-
Fill the
rectanglewith the current color.Import this function with the
:drawtag.
fillstrokepath
FLTK::fillstrokepath( $color );-
Does
fill(), then sets the current color to linecolor and doesstrokewith the same closed path, and then clears the path.This seems to produce very similar results on X and Win32. Also it takes advantage of a single GDI32 call that does this and should be faster.
Import this function with the
:drawtag.
getascent
my $distance = FLTK::getascent( );-
Return the distance from the baseline to the top of letters in the current font.
Import this function with the
:drawtag.
getbgcolor
my $color = FLTK::getbgcolor( );-
Returns the last Color passed to
setbgcolor(). To actually draw in the bg color, do this:my $saved = FLTK::getcolor(); FLTK::setcolor(FLTK::getbgcolor()); draw_stuff(); FLTK::setcolor($saved);Import this function with the
:drawtag.
getcolor
my $color = FLTK::getcolor( );-
Returns the last Color passed to
setcolor().Import this function with the
:drawtag.
getdescent
my $distance = FLTK::getdescent( );-
Return the distance from the baseline to the bottom of letters in the current font.
Import this function with the
:drawtag.
getfont
my $font = FLTK::getfont( );-
Returns the font sent to the last
setfont().Import this function with the
:drawtag.
getsize
my $size = FLTK::getsize( );-
Return the size sent to the last
setfont(). You should use this as a minimum line spacing (usingascent()+descent()will produce oddly spaced lines for many fonts).Import this function with the
:drawtag.
getwidth
my $width = FLTK::getwidth( $text );-
Return the width of a UTF-8 string drawn in the font set by the most recent
setfont().Import this function with the
:drawtag. my $width = FLTK::getwidth( $text, $n );-
Return the width of the first
nbytes of this UTF-8 string drawn in the font set by the most recentsetfont().Import this function with the
:drawtag.
intersect_with_clip
my $return = FLTK::intersect_with_clip( $rectangle );-
Intersect a
transform()'d rectangle with the current clip region and change it to the smaller rectangle that surrounds (and probably equals) this intersection area.This can be used by device-specific drawing code to limit complex pixel operations (like drawing images) to the smallest rectangle needed to update the visible area.
Return values:
- 0 if it does not intersect, and W and H are set to zero
- 1 if if the result is equal to the rectangle (i.e. it is entirely inside or equal to the clip region)
- 2 if it is partially clipped
Import this function with the
:drawtag.
line_dashes
my @dashes = FLTK::line_dashes( );-
Return the last value for
$dashessent toline_style($style,$width, $dashes). Note this is only useful for checking if it is NULL or not.Import this function with the
:drawtag.
line_style
FLTK::line_style( $style, $width, $dashes );-
Set how to draw lines (the "pen"). If you change this it is your responsibility to set it back to the default with
line_style(0).styleis a bitmask in which you 'or' the following values (imported withdrawtag). If you don't specify a dash type you will get a solid line. If you don't specify a cap or join type you will get a system-defined default of whatever value is fastest.SOLID-
------- DASH-
- - - - DOT-
········· DASHDOT-
- · - · DASHDOTDOT-
- ·· - ·· CAP_FLATCAP_ROUNDCAP_SQUARE-
extends past end point 1/2 line width
JOIN_MITER-
pointed
JOIN_ROUNDJOIN_BEVEL-
flat
widthis the number of pixels thick to draw the lines. Zero results in the system-defined default, which on both X and Windows is somewhat different and nicer than 1.dashesis a list of dash lengths, measured in pixels, if set then the dash pattern instyleis ignored. The first location is how long to draw a solid portion, the next is how long to draw the gap, then the solid, etc. It is terminated with a zero-length entry. A null pointer or a zero-length array results in a solid line. Odd array sizes are not supported and result in undefined behavior. The dashes array is ignored on Windows 95/98.Import this function with the
:drawtag. my $style = FLTK::line_style( );-
Return the last value sent to
line_style($style,$width,$dashes), indicating the cap and join types and the built-in dash patterns.Import this function with the
:drawtag.
line_width
my $width = FLTK::line_width( );-
Return the last value for
$widthsent toline_style($style,$width, $dashes).Import this function with the
:drawtag.
load_identity
FLTK::load_identity( );-
Replace the current transform with the identity transform, which puts 0,0 in the top-left corner of the window and each unit is 1 pixel in size.
Import this function with the
:drawtag.
measure
my @wh = FLTK::measure( $string, $flags );-
Measure the size of box necessary for
drawtext()to draw the given string inside of it. Theflagsare used to set the alignment, though this should not make a difference except forALIGN_WRAP. To correctly measure wrapwmust be preset to the width you want to wrap at ifALIGN_WRAPis on in the flags!wandhare changed to the size of the resulting box.Import this function with the
:drawtag.
newpath
FLTK::newpath( );-
Clear the current "path". This is normally done by
fillpath()or any other drawing command.Import this function with the
:drawtag.
not_clipped
my $inside = FLTK::not_clipped( $rectangle );-
Returns true if any or all of
rectangleis inside the clip region.Import this function with the
:drawtag.
pop_clip
FLTK::pop_clip( );-
Restore the previous clip region. You must call
pop_clip()exactly once for every time you callpush_clip(). If you return to FLTK with the clip stack not empty unpredictable results occur.Import this function with the
:drawtag.
pop_matrix
FLTK::pop_matrix( );-
Put the transformation back to the way it was before the last
push_matrix(). Calling this without a matching push_matrix will crash!Import this function with the
:gsaveor:drawtags.
push_clip
FLTK::push_clip( $rect );-
Pushes the intersection of the current region and Rectangle
xonto the clip stack.Import this function with the
:drawtag. FLTK::push_clip( $x, $y, $w, $h );-
Same as
push_clip(FLTK::Rectangl->new($x,$y,$r,$h))except faster as it avoids the construction of an intermediate rectangle object.Import this function with the
:drawtag.
push_matrix
FLTK::push_matrix( );-
Save the current transformation on a stack, so you can restore it with
pop_matrix().FLTK provides an arbitrary 2-D affine transformation (rotation, scale, skew, reflections, and translation). This is very similar to PostScript, PDF, SVG, and Cairo.
Due to limited graphics capabilities of some systems, not all drawing functions will be correctly transformed, except by the integer portion of the translation. Don't rely on this as we may be fixing this without notice.
Import this function with the
:gsaveor:drawtags.
push_no_clip
FLTK::push_no_clip( );-
Pushes an empty clip region on the stack so nothing will be clipped. This lets you draw outside the current clip region. This should only be used to temporarily ignore the clip region to draw into an offscreen area.
Import this function with the
:drawtag.
readimage
FLTK::readimage( $pointer, $type, $rect, $line_delta );-
Reads a 2-D image off the current drawing destination. The resulting data can be passed to
drawimage()or the 8-bit pixels examined or stored by your program.The return value is either
pointerorundefif there is some problem (such as an inability to read from the current output surface, or if the rectangle is empty).pointerpoints to the location to store the first byte of the upper-left pixel of the image. The caller must allocate this buffer.typecan beRGBorRGBA(possibly other types will be supported in the future).rectindicates the position on the surface in the current transformation to read from and the width and height of the resulting image. What happens when the current transformation is rotated or scaled is undefined. If the rectangle extends outside the current drawing surface, or into areas obscured by overlapping windows, the result in those areas is undefined.line_deltais how much to add to a pointer to advance from one pixel to the one below it. Any bytes skipped over are left with undefined values in them. Negative values can be used to store the image upside-down, howeverpointershould point to 1 line before the end of the buffer, as it still points to the top-left pixel.
Import this function with the
:drawtag. FLTK::readimage( $pointer, $type, $rect );-
Same except
line_deltais set to$rect-w() * depth($type)>.Import this function with the
:drawtag.
rotate
FLTK::rotate( $d );-
Rotate the current transformation counter-clockwise by
ddegrees (not radians!!). This is done by multiplying the matrix by:cos -sin 0 sin cos 0 0 0 1Import this function with the
:drawtag.
scale
FLTK::scale( $x );-
Scale the current transformation by multiplying it by
x 0 0 0 x 0 0 0 1Import this function with the
:drawtag. FLTK::scale( $x, $y );-
Scale the current transformation by multiplying it by
x 0 0 0 y 0 0 0 1Import this function with the
:drawtag.
setbgcolor
FLTK::setbgcolor( $color );-
Set the "background" color. This is not used by the drawing functions, but many box and image types will refer to it by calling
getbgcolor().Import this function with the
:drawtag.
setcolor
FLTK::setcolor( $color );-
Set the color for all subsequent drawing operations.
See
setcolor_alpha().Import this function with the
:drawtag.
setcolor_alpha
FLTK::setcolor_alpha( $color, $alpha );-
Sets the current rgb and alpha to draw in, on rendering systems that allow it. If alpha is not supported this is the same as
setcolor(). The color you pass should not premultiplied by the alpha value, that would be a different, nyi, call.Import this function with the
:drawtag.
setdrawflags
setfont
FLTK::setfont( $font, $size );-
Set the current font and font scaling so the size is size pixels. The size is unaffected by the current transformation matrix (you may be able to use
transform()to get the size to get a properly scaled font).The size is given in pixels. Many pieces of software express sizes in "points" (for mysterious reasons, since everything else is measured in pixels!). To convert these point sizes to pixel sizes use the following code:
my $monitor = FLTK::Monitor::all(); my $pixels_per_point = $monitor->dpi_y() / 72.0; my $font_pixel_size = $font_point_size * $pixels_per_point;See the FLTK::Font class for a description of what can be passed as a font. For most uses one of the built-in constant fonts like
HELVETICAcan be used.Import this function with the
:drawtag.
strokepath
FLTK::strokepath( );-
Draw a line between all the points in the path (see
line_style()for ways to set the thicknesss and dot pattern ofthe line), then clear the path.Import this function with the
:drawtag.
strokerect
FLTK::strokerect( $x, $y, $w, $h );-
Draw a line inside this bounding box (currently correct only for 0-thickness lines).
Import this function with the
:drawtag. FLTK::strokerect( $rectangle );-
Draw a line i<inside> this bounding box (currently correct only for 0-thickness lines).
Import this function with the
:drawtag.
transform
FLTK::transform( $x, $y );-
Replace
float_xandfloat_ytransformed into device coordinates. Device-specific code can use this to draw things using the fltk transformation matrix. If the backend is Cairo or another API that does transformations, this may returnxandyunchagned.Import this function with the
:drawtag. FLTK::transform( $x, $y );-
Replace
int_xandint_ywith the transformed coordinates, rounded to the nearest integer.Import this function with the
:drawtag. FLTK::transform( $from, $to );-
Transform the rectangle
rect_frominto device coordinates and put it intorect_to. This only works correctly for 90 degree rotations, for other transforms this will produce an axis-aligned rectangle with the same area (this is useful for inscribing circles, and is about the best that can be done for device functions that don't handle rotation.Import this function with the
:drawtag. FLTK::transform( $x, $y, $w, $h );-
Same as
transform(FLTK::Rectangle->new($x,$y,$w,$h), $rect_to)but replacesx, y, w, hwith the transformed rectangle. This may be faster as it avoids the rectangle construction.Import this function with the
:drawtag.
transform_distance
FLTK::transform_distance( $x, $y );-
Replace
xandywith the tranformed coordinates, ignoring translation. This transforms a vector which is measuring a distance between two positions, rather than a position.Import this function with the
:drawtag.
translate
FLTK::translate( $x, $y );-
Translate the current transformation by multiplying it by
1 0 0 0 1 0 x y 1Import this function with the
:drawtag.
Author
Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/
License and Legal
Copyright (C) 2008-2010 by Sanko Robinson <sanko@cpan.org>
This program is free software; you can redistribute it and/or modify it under the terms of The Artistic License 2.0. See the LICENSE file included with this distribution or notes on the Artistic License 2.0 for clarification.
When separated from the distribution, all original POD documentation is covered by the Creative Commons Attribution-Share Alike 3.0 License. See the clarification of the CCA-SA3.0.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 778:
Non-ASCII character seen before =encoding in 'C<·········>'. Assuming UTF-8