Examples under Synth:new should not use SynthDef:play to make nodes
[supercollider.git] / SCClassLibrary / QtCollider / QUserView.sc
blobdf8ed8eefdcb202cc0351edf418b638fc3fbc214
1 QUserView : QView {
2   var <drawFunc, <drawingEnabled=true, <background;
4   *qtClass { ^"QcCustomPainted" }
6   *new { arg parent, bounds;
7     var me = super.new(parent, bounds ?? {this.sizeHint} );
8     me.canFocus = true;
9     ^me;
10   }
12   *sizeHint {
13     ^Point(150,150);
14   }
16   drawingEnabled_ { arg boolean;
17     // Allow setting the property apart from the instance variable
18     // to optimize when drawFunc is nil. See drawFunc_ implementation.
19     drawingEnabled = boolean;
20     this.setProperty( \drawingEnabled, boolean );
21   }
23   clearOnRefresh { ^this.getProperty( \clearOnRefresh ); }
24   clearOnRefresh_ { arg boolean; this.setProperty( \clearOnRefresh, boolean ); }
26   clearDrawing { this.invokeMethod( \clear ); }
28   drawFunc_ { arg aFunction;
29     this.setProperty( \drawingEnabled, aFunction.notNil );
30     drawFunc = aFunction;
31   }
33   draw {
34     // NOTE: it is only allowed to call this while a QPaintEvent is being
35     // processed by this QWidget, or an error will be thrown.
36     drawFunc.value(this);
37   }
39   animate_ { arg bool; this.invokeMethod( \animate, bool ); }
41   frameRate_ { arg fps; this.setProperty( \frameRate, fps.asFloat ); }
42   frameRate { ^this.getProperty( \frameRate ); }
44   frame { ^this.getProperty( \frameCount ); }
46   background_ { arg aColor;
47     background = aColor;
48     this.setProperty( \background, aColor, true );
49   }
51   // override QView's action_ to not connect to 'action()' signal
52   action_ { arg func;
53     action = func;
54   }
56   doDrawFunc { drawFunc.value(this) }