INVISIBLE_PARAM_KNOB
Active invisible element that let the user change the value of a prameter by dragging the mouse or clicking on specific keys. For more information, see User Experience. This widget is similar to the IMAGE_PARAM_KNOB element, except that it does not display anything.
Attributes brief detailed show all inherited
Examples
If we compare this to INVISIBLE_PARAM_SLIDER we can see they are very similar in mouse behaviour. Difference is that slider also changes to the click position, and knob changes only when dragged.
Let's try with the similar simple example as in INVISIBLE_PARAM_SLIDER.
- <!-- create demo param -->
- <PARAM id="demo_param" min="0" max="1" default="0.5" value_format="0.3" />
- <!-- an area of a widget to see -->
- <WIDGET background_color="#EEEEEE" layout_type="layer_stack">
- <!-- "thumb" rectangle -->
- <WIDGET id="v_thumb" background_color="#DD0000" width="100%" height="10" v_align="top" />
- <!-- move thumb position according to param value -->
- <PARAM_LINK from="demo_param" to="v_thumb.v_offset" formula="100-10-x*(100-10)" /> <!-- widget height minus thumb height -->
- <!-- the control that handles mouse and keyboard-->
- <INVISIBLE_PARAM_KNOB param_id="demo_param" cursor="system::hand" width="100" height="100" />
- </WIDGET>
- <!-- text value of a param -->
- <PARAM_TEXT_CONTROL param_id="demo_param" />

Let's replace "slider" graphics with a proper "knob" graphics. To draw a knob we can use CANVAS.
- <!-- create demo param -->
- <PARAM id="demo_param" min="-50" max="50" default="0" value_format="0.1" />
- <!-- an area of a widget to see -->
- <WIDGET background_color="#EEEEEE" layout_type="layer_stack">
- <!-- the canvas element, where all the drawing happens -->
- <CANVAS id="demo_canvas" width="100%" height="100%" render_script="renderKnob(this.width, this.height, demo_inv_knob.value);" requires="demo_canvas.width;demo_canvas.height;demo_inv_knob.value" />
- <!-- redraw canvas on param changes -->
- <ACTION_TRIGGER event_id="demo_param.value_changed" script="demo_canvas.Invalidate()" requires="demo_canvas.Invalidate" />
- <!-- the control that handles mouse and keyboard-->
- <INVISIBLE_PARAM_KNOB id="demo_inv_knob" param_id="demo_param" cursor="system::hand" width="100" height="100" />
- </WIDGET>
- <!-- text value of a param -->
- <PARAM_TEXT_CONTROL param_id="demo_param" />
- <!-- script to draw on canvas -->
- <SCRIPT script="
- void renderKnob(double w, double h, double nvalue){
- /* get graphics object */
- auto ctx=Kt::Graphics::GetCurrentContext();
- /* scale to virtual coordinates from -1 to 1 */
- ctx.transform.Scale(w/2,h/2);
- ctx.transform.Translate(1,1);
- /* add a circle */
- ctx.path.Clear();
- ctx.source.SetRGBA(0.3, 0.8, 1, 0.2); /* r,g,b, alpha */
- ctx.path.Arc(0, 0, 0.9, 0, 360); /* add a circle with radius 0.9 */
- ctx.FillPath();
- /* draw circle border */
- ctx.source.SetRGBA(0, 0, 0.2, 0.5);
- ctx.settings.set_lineWidth(0.02);
- ctx.StrokePath();
- /* calculate coordinates for the marker */
- double angle_start = -135, angle_end = 135;
- double angle_width = (angle_end-angle_start);
- double angle_center = 90 - (angle_start+angle_end)/2;
- double adeg = (angle_center - (nvalue-0.5)*angle_width);
- double arad = adeg*pi/180;
- double si = sin(arad), co = cos(arad);
- double marker_start = 0.7, marker_end = 0.35, marker_width=0.2;
- double dxme = co*marker_end;
- double dyme = -si*marker_end;
- double dxms = co*marker_start;
- double dyms = -si*marker_start;
- double mdeg = 270-adeg;
- /* draw a marker */
- ctx.path.Clear();
- ctx.path.Arc(dxms, dyms, marker_width*0.5, mdeg, mdeg+180);
- ctx.path.Arc(dxme, dyme, marker_width*0.5, mdeg+180, mdeg+360);
- ctx.source.SetRGBA(0, 0.3, 0.3, 0.8);
- ctx.FillPath();
- /* write text with normalized value */
- ctx.font.SetFontSize(0.27);
- ctx.source.SetRGBA(0, 0, 0, 0.7);
- string s = (""+nvalue).substr(0,3);
- ctx.path.MoveTo(- ctx.font.GetTextSize(s).x/2, 0.7);
- ctx.WriteText(s);
- }" />

This is a very rough demo of what can be done with CANVAS. Take a look at Simple knobs article to see more demos.
Ready-to-use knobs
Here are some demo knobs created inside LM Skin using CANVAS and INVISIBLE_PARAM_KNOB. You can easily change the size, colors and other parameters without touching Gimp or Photoshop. Open LM Skin -> Skin Scanner to observe them and LM Skin -> Controls customizer to adapt them to your needs.

Take a look at INVISIBLE_PARAM_SLIDER and IMAGE_PARAM_KNOB.
Comments
Please, authorize to view and post comments.