KUIML
Blue Cat's User Interface Programming Language
CANVAS (Experimental)

Description

The CANVAS element lets you draw your own shapes using the Kt::Graphics scripting API.

Inherited Attributes

See the Widgets element.

Specific Attributes

Name Value Type Default Value Description Comment V. Exp.

render_script

script

empty

inline script that draws onto the current Graphics context.

Experimental. You can access the current graphics context object in the script using the Kt::Graphics::GetCurrentContext() function.

2.6

No

requires

list of ';' separated identifiers or wildcards

Empty.

List of objects expected by the script.

Forces the KUIML engine to expose the listed objects to the scripting engine. for example: 'my_object.*;my_string'

2.0

No

script_handles_opacity

boolean

false

if true, the render script should handle the opacity of the widget.

2.6

No

Examples

ref_widget_canvas_element_example1.png

Skin file:

<?xml version="1.0" encoding="utf-8" ?>
<SKIN author="Blue Cat Audio" name="2D Canvas Script" background_color="#000000" margin="2">
<!-- Includes -->
<SCRIPT src="demoCanvas.cxx"/>

<!-- The Canvas -->
<CANVAS id="shapes" requires="shapes.width;shapes.height" render_script="renderShapes(this.width,this.height)" width="300" height="300" opacity=".8"/>
</SKIN>

Render script file (demoCanvas.cxx):

void renderShapes(double w,double h)
{
if(@ctx!=null)
{
double r=.5;
double g=1;
double b=1;
// setup transforms
double lineW=3*2/sqrt(w*w+h*h);
// draw lines and outer circle
ctx.transform.Scale(w/2,h/2);
ctx.transform.Translate(1,1);
ctx.settings.lineWidth=lineW;
ctx.source.SetRGBA(r,g,b,1);
ctx.path.Clear();
ctx.path.MoveTo(-.7,-.7);
ctx.path.LineTo(.7,.7);
ctx.path.MoveTo(.7,-.7);
ctx.path.LineTo(-.7,.7);
ctx.path.MoveTo(-1,0);
ctx.path.LineTo(1,0);
ctx.path.NewSubPath();
ctx.path.Arc(0,0,1-lineW/2,0,360);
ctx.StrokePath();
// draw gradient
Kt::Graphics::GradientDrawPattern@ gradient=ctx.patterns.NewRadialGradient(0,0,0,0,0,1);
gradient.AddColorStopRGBA(0,r,g,b,0);
gradient.AddColorStopRGBA(1,r,g,b,.3);
gradient.SelectAsSource();
ctx.FillPath();
ctx.path.MoveTo(0,0);
ctx.transform.Scale(.05,.05);
ctx.path.Clear();
Kt::Graphics::DrawPattern@ rgba=ctx.patterns.NewRGBA(1,1,1,.8);
ctx.font.SelectFontFace("Georgia");
ctx.font.SetFontSize(9);
ctx.path.Text("ABC");
ctx.FillPath();
}
}