painter class

# painter class This class provide a painter to paint line and shapes.
Inherits
object widget
Description
With this class you can draw many graphics objects from simple lines to complex shapes like pies and chords. It can also draw aligned text and pixmaps. Normally, it draws in a "natural" coordinate system, but it can also do view and world transformation. The class need to be implemented into a $paintEvent();
Functions
`$drawLine(<x1:integer>,<y1_integer>,<x2:integer>,<y2:integer>)`
Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2).
`$begin(<paint_device:object>)`
Begins painting the paint device <paint_device>: the parameter MUST be a widget or a pixmap. Warning: A paint device can only be painted by one painter at a time.
`$beginPdf(<file_name:string>)`
Begins painting on a file using the pdf format. At present the pdf support is in experimental state.
`$end()`
Ends painting. Any resources used while painting are released.
`$setPen(<rgb or hsv array value or [<red>,<green>,<blue>][<hue>,<saturation>,<value>],[system color:RGB or HSV)`
The pen defines the lines or text, color. You can set it with Red,Green,Blue, or H,S,V value All parameters are in integer form.
`$setPen(<rgb or hsv array value or [<red>,<green>,<blue>][<hue>,<saturation>,<value>],[opacity],[system color:RGB or HSV])`
The pen defines the lines or text, color. You can set it with Red,Green,Blue, or H,S,V value All parameters are in integer form. The HSV system, like RGB, has three components: * H, for hue, is either 0-359 if the color is chromatic (not gray), or meaningless if it is gray. It represents degrees on the color wheel familiar to most people. Red is 0 (degrees), green is 120 and blue is 240. * S, for saturation, is 0-255, and the bigger it is, the stronger the color is. Grayish colors have saturation near 0; very strong colors have saturation near 255. * V, for value, is 0-255 and represents lightness or brightness of the color. 0 is black; 255 is as far from black as possible. Examples: RED is H=0, S=255, V=255. Light RED could have H about 0, S about 50-100, and S=255. ES: $setPen(00,00,00) for black; Default color mode is RGB;
`$setBrush(<rgb or hsv array value or [<red>,<green>,<blue>][<hue>,<saturation>,<value>],[system color:RGB or HSV)`
Sets the painter's brush to have the specified color. Example: class (wdg,widget) { paintevent() { %b=$new(painter) %b->$setBackgroundMode(Opaque) %b->$setBrush(0,250,250) %b->$begin($$) %b->$drawEllipse(50,50,100,50) } } %aa=$new(wdg) %aa->$show()
`$drawRect(<x:integer>,<y:integer>,<w:unsigned integer>,<h:unsigned integer>)`
Draws a rectangle with upper left corner at (x, y) and with width w and height h.
`$drawRoundRect(<start_angle:integer>,<angle_length:integer>,<width:unsigned integer>,<height:unsigned integer>,<xr:integer>,<y:integer>)`
Draws a rectangle with rounded corners at (x, y), with width w and height h.[rb] The xCor and yCor arguments specify how rounded the corners should be (range is 0->99).
`$drawPie(<x:integer>,<y:integer>,<w:unsigned integer>,<h:unsigned integer>,<angle:integer>,<alen:integer>)`
Draws a pie defined by the rectangle (x, y, w, h), the start angle a and the arc length alen. The angles <angle> and <alen> are 1/16th of a degree, i.e. a full circle equals 5760 (16*360).
`$drawArc(<x:integer>,<y:integer>,<w:unsigned integer>,<h:unsigned integer>,<angle:integer>,<alen:integer>)`
Draws an arc defined by the rectangle (x, y, w, h), the start angle a and the arc length alen. The angles <angle> and <alen> are 1/16th of a degree, i.e. a full circle equals 5760 (16*360).
`$drawPoint(<x:integer>,<y:integer>)`
Draws a point at x and y coordinates.
`$drawEllipse(<x:integer>,<y:integer>,<sizew:unsigned integer>,<sizeh:unsigned integer>)`
Draws an ellipse with center at (x + w/2, y + h/2) and size (w, h).
`$drawChord(<x:integer>,<y:integer>,<w:unsigned integer>,<h:unsigned integer>,<angle:integer>,<alen:integer>)`
Draws a chord defined by the rectangle (x, y, w, h), the start angle a and the arc length alen. The angles <angle> and <alen> are 1/16th of a degree, i.e. a full circle equals 5760 (16*360).
`$drawText(<x:integer>,<y:integer>,<width:unsigned integer>,<height:unsigned integer>,<text:string>[,<flag:string>[,<flag:string>[,...]]])`
Draws the given <text> within the rectangle specified by <x>,<y> <width> and <height>. The <flag> parameters may be:
     Left
     Top
     Right
     Bottom
     HCenter
     VCenter
     Center
     TextSingleLine
     TextExpandTabs
     TextShowMnemonic
     TextWordWrap
     TextIncludeTrailingSpaces
`$drawPixmap(<x:integer>,<y:integer>,<pixmap:hobject>,<sx:integer>,<sy:integer>,<ex:integer>,<ey:integer>)`
Draws a pixmap at x,y coordinates
`$setFont(<family:string>,<size:integer>[,<style:enum>,<style:enum>,..])`
Set the font's family, size and style, valid flag for style are:
     italic
     bold
     underline
     overline
     strikeout
     fixedpitch
`$setFontSize(<size:unsigned integer>)`
Set the current painter font's size.
`<integer>$fontAscent()`
Return the distance from the baseline to the highest position characters extend to.
`<integer>$fontDescent()`
Return the distance from the baseline to the lowest point characters extend to.
`<integer>$fontMetricsWidth(<text:string>)`
Returns the font metrics width for the painter's current font.
`<integer>$fontMetricsHeight()`
Returns the font metrics height for the painter's current font.
`$rotate(<angle:real>,[<axis:string>])`
Rotates the coordinate system a degrees counterclockwise by the given angle about the optional parameter <axis>. Valid values for axis are: ZAxis, XAxis, YAxis. Optional parameter <axis>
`$translate(<dx:real>,<dy:real>)`
Translates the coordinate system by <dx>, <dy>.
`$shear(<dh:real>,<dv:real>)`
Shears the coordinate system by <dh>, <dv>.
`$scale(<dh:real>,<dw:real>)`
Scales the coordinate system by <dh>, <dv>.
`$setBackgroundMode(<bgMode:enum>)`
Sets the background mode of the painter to <bgMode>: valid values are: - Transparent (that is the default value); - Opaque.
`$setOpacity(<opacity_factor:real>)`
Sets the painter opacity that affects all painter operations (drawpixmap, drawtext...). Valid values range are from 0 (total transparency) to 1 (total opacity) You must invoke the $begin before using it.
`$setTextAntialiasing(<boolean>)`
Enable/disable antialias in text if possible. You must call the $begin before using it.
`$setAntialiasing(<boolean>)`
Enable/disable antialias in edges of primitives if possible. You must call the $begin before using it.
`$setSmoothPixmapTransform(<boolean>)`
Enable/disable smooth bilinear pixmap transformation algorithm (such as bilinear). You must call the $begin before using it. Example: class (hello,widget) { constructor() { $$->%sintbl[]= $array( 0, 38, 71, 92, 100, 92, 71, 38,0, -38, -71, -92, -100, -92, -71, -38); $$->%index=0 $$->$starttimer( 30 ); $$->$resize(800,600 ); $$->%string=$0 $$->%waitfor=1; $$->%nextanim=0 #zoom and rotation anim $$->%Zoomindex=11 $$->%degree=0 $$->%Noanim=0 $$->%scrollright=-450 #anim effect init $$->%xoffset=4 $$->%yoffset=3 $$->%xstart=270 $$->%ystart=200 $$->%b=0 $$->%yoffs=400 #parallax parameter $$->%Off=400 $$->%roll=1 } timerevent() { $$->%b = $(($$->%b + 1) & 15); if ($$->%nextanim == 1) $$->$repaint(1); $$->$repaint(0); } drawAnim() { %P->$setFont(32,"times",bold); %w=$(%P->$fontMetricsWidth($$->%string[$$->%index]) + 20); %h=$(%P->$fontMetricsHeight * 2); %pmx = $(($$->$width/2) -%w/2); %pmy = $(($$->$height()/2) - %h/2); %x = 10; %y= $((%h/2) + $$->$fontDescent()); %i=0 while ( $str.mid("Grifisx/Noldor",%i,1) != "") { %i16 = $(($$->%b+%i) & 15); %char=$str.mid("Grifisx/Noldor",%i,1) %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) ); %P->$drawText( $(%x+$$->%xstart),$($$->%ystart+%y-$$->%sintbl[%i16]*%h/800),%char,1,Auto); %x += %P->$fontMetricsWidth(%char); %i++; } } matrixeffect() { if (($$->%Zoomindex == 99) && ($$->%degree==360)) return %P->$drawPixmap($(400-32),$(300-32),"kvirc.png",0,0,-1,-1) %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex) if ($$->%Zoomindex != 99) $$->%Zoomindex++; %P->$rotate($$->%degree) %P->$translate(400,300) %P->$drawPixmap(-32,-32,"kvirc.png",0,0,-1,-1) %P->$setFont(28,"times",bold); %P->$reset() if ($$->%scrollright >= 550) return %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex) %P->$translate(400,350) %P->$drawText($$->%scrollright,10,"Another cool class brought to you by...",-1,Auto) $$->%scrollright += 3; %P->$reset() } nextanim() { %p=$new(painter) %p->$setBackgroundMode(Opaque) %p->$setBrush($rand(255),$rand(255),$rand(255)) %p->$begin($$) %rand=$rand(5) %p->$drawrect($rand(800),$rand(400),120,200) %p->$drawArc($rand(800),$rand(400),120,200,20,$(16*20)) %p->$drawPie($rand(800),$rand(400),120,200,20,$(16*20)) %p->$drawChord($rand(800),$rand(400),120,200,20,$(16*20)) %p->$drawEllipse($rand(800),$rand(400),100,30) %p->$end() delete %p } paintEvent() { if ($$->%nextanim ==1) return $$->$nextanim() # pixmap creation: every effect will be painted on it then copied on widget %pixmap=$new(pixmap) %pixmap->$resize($$->$width(),$$->$height()) # painter creation %P=$new(painter); %P->$begin(%pixmap); $$->$drawanim $$->$matrixeffect %i=0 while (%i != 100) { %i16 = $(($$->%b+%i) & 15); %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) ); %P->$drawpoint($rand(800),$rand(600)) %i++ } # sets the animations order to manage the parallax effect %P->$end objects.bitBlt $$ 0 0 %pixmap delete %pixmap delete %P if (%Pauseflag == 1) return # manage the animations parameters if (($$->%Off<=60) && ($$->%roll<182)) $$->%roll += 2; if ($$->%roll>182) $$->%waitfor=0 if ($$->%Noanim != 1) $$->%degree += 16; if ($$->%degree >= 360) { $$->%degree=0; if ($$->%Zoomindex == 99) $$->%Noanim=1 } if ($$->%Noanim != 1) return #sinusoid animation if (($$->%xstart <1) && ($$->%xoffset == -4)) $$->%xoffset=4; if (($$->%xstart >$($$->$width()-%P->$fontMetricsWidth("Grifisx/Noldor"))) && ($$->%xoffset == 4)) $$->%xoffset=-4; if (($$->%ystart <1) && ($$->%yoffset == -3)) $$->%yoffset=3; if (($$->%ystart >$($$->$height()-60)) && ($$->%yoffset == 3)) $$->%yoffset=-3; $$->%xstart += $$->%xoffset; $$->%ystart += $$->%yoffset; } } %Hello=$new(hello) %Hello->$setWindowTitle("Painter effects" ); %Hello->$setFont(28,"times",bold); %Btn=$new(button,%Hello) %Btn->$setmaximumwidth(80) %Btn->$setmaximumheight(30) %Btn->$setFont(8,"times",bold); %Btn->$settext(Next) privateimpl(%Btn,mousepressevent) { if ($$->$parent->%nextanim==0) { $$->$parent->%nextanim=1 $$->$settext(Prev) } else { $$->$parent->%nextanim=0 $$->$settext(Next) } } %lay=$new(layout,%Hello) %lay->$addwidget(%Btn,4,0) %Hello->$setBackgroundColor("000000"); %Hello->$setmaximumwidth(800) %Hello->$setminimumwidth(780) %Hello->$setmaximumheight(600) %Hello->$setminimumheight(600) %Hello->$move(10,10) %Hello->$show();

Index, Object Classes

KVIrc 4.2.0.6190 Documentation
Generated by builduser at Thu May 25 04:22:50 2017