// title: Chopsticks GUI // author: ludions // description: // A GUI example of nesting Views and multiplying widgets, including mouse actions and Pen drawing for each of the views. Thanks to hjh for spotting an early bug on sc-users. Add your own sound... // code: ( var numX=12, numY=8, width, height, margin; w = Window.new("CompositeView", Window.availableBounds).front; width = (Window.availableBounds.width/numX).floor; height = (Window.availableBounds.height/numY).floor; margin = (width + height)/20; w.addFlowLayout(0@0, 0@0); t = Array.fill(numX * numY, { arg i; var u, n, col, moveTo, lineTo, toggle; col = Color.rand; toggle = i%2; n = CompositeView.new(w, Rect(0, 0, width, height)) .background_(col); u=UserView(n, Rect(margin, margin, width-(margin*2), height-(margin*2))); // OK u.background_(col); u.drawFunc={|uview| if(toggle.asBoolean, { moveTo = 0@uview.bounds.height.rand; lineTo = uview.bounds.width@uview.bounds.height.rand; }, { moveTo = uview.bounds.width.rand@uview.bounds.height; lineTo = uview.bounds.width.rand@0; }); Pen.moveTo(moveTo); Pen.lineTo(lineTo); Pen.stroke; }; u.mouseDownAction={|view| col = Color.rand; u.background_(col); n.background_(col); toggle = (toggle - 1).abs; }; u.animate_(true); }); w.front; )