diff --git a/HelpSource/Classes/ScatterView.schelp b/HelpSource/Classes/ScatterView.schelp index a1b08c9..4eb53a3 100644 --- a/HelpSource/Classes/ScatterView.schelp +++ b/HelpSource/Classes/ScatterView.schelp @@ -92,14 +92,10 @@ PRIVATE:: initPlot EXAMPLES:: code:: -// you may want to use Swing or Cocoa -SwingOSC.default.boot -GUI.swing - ( var data = 1000.collect{ [1.0.rand, exprand(0.01, 1)]}; -w = GUI.window.new(bounds: Rect(40, 40, 800, 800)).front; +w = Window.new(bounds: Rect(40, 40, 800, 800)).front; a = ScatterView(w, Rect(10, 10, 760, 760), data, [0,1].asSpec, [0,1].asSpec); a.drawAxis_(true).drawMethod_(\fillOval) .symbolColor_(Color.blue(0.5, 0.5)).symbolSize_(5) @@ -108,10 +104,10 @@ a.drawAxis_(true).drawMethod_(\fillOval) ( var numItems = 630; -w = GUI.window.new(bounds: Rect(40, 40, 800, 150)).front; +w = Window.new(bounds: Rect(40, 40, 800, 150)).front; a = ScatterView(w, Rect(10, 10, 760, 100), {|i| [sin(i/50), sin(0.05*i)]}!numItems, [-1,1].asSpec, [-1,1].asSpec); a.isHighlight = true; -GUI.slider.new(w, Rect(10, 120, 760, 20)).action_{|me| +Slider.new(w, Rect(10, 120, 760, 20)).action_{|me| a.highlightItemRel = me.value; a.refresh; // a.highlightItem = (me.value*numItems).asInteger.min(numItems-1); @@ -176,12 +172,13 @@ w.refresh // use two views stacked ( var numItems = 630; -w = SCWindow.new(bounds: Rect(40, 40, 800, 150)).front; +w = Window.new(bounds: Rect(40, 40, 800, 150)).front; a = ScatterView(w, Rect(10, 10, 760, 100), {|i| [sin(i/50), sin(0.05*i)]}!numItems, [-1,1].asSpec, [-1,1].asSpec); b = ScatterView(w, Rect(10, 10, 760, 100), {|i| [sin(i/21), sin(0.05*i)]}!numItems, [-1,1].asSpec, [-1,1].asSpec); a.background = Color.gray(0, 0); +b.background = Color.clear; a.isHighlight = true; -SCSlider(w, Rect(10, 120, 760, 10)).action_{|me| +Slider(w, Rect(10, 120, 760, 10)).action_{|me| a.highlightItemRel = me.value; w.refresh; //a.highlightItem = (me.value*numItems).asInteger.min(numItems-1); @@ -197,10 +194,10 @@ w.refresh; ( var numItems = 630; -w = SCWindow.new(bounds: Rect(40, 40, 800, 150)).front; +w = Window.new(bounds: Rect(40, 40, 800, 150)).front; a = ScatterView(w, Rect(10, 10, 760, 100), {|i| [sin(i/50), sin(0.05*i)]}!numItems, [-1,1].asSpec, [-1,1].asSpec); a.isHighlight = true; -SCRangeSlider(w, Rect(10, 120, 760, 10)).action_{|me| +RangeSlider(w, Rect(10, 120, 760, 10)).action_{|me| a.highlightRangeRel(me.lo, me.hi); w.refresh; // a.highlightItem = (me.value*numItems).asInteger.min(numItems-1); diff --git a/HelpSource/Classes/ScatterView2.schelp b/HelpSource/Classes/ScatterView2.schelp index 5267130..26f22a1 100644 --- a/HelpSource/Classes/ScatterView2.schelp +++ b/HelpSource/Classes/ScatterView2.schelp @@ -64,7 +64,7 @@ code:: // three dimensional dataset d = ({1.0.rand}!9000).clump(3); -w = SCWindow.new("ScatterView Example"); +w = Window.new("ScatterView Example"); v = ScatterView2(w, Rect(10, 10, 380, 380), d); v.selectionMode = \nextNeighbour; v.background = Color.black; diff --git a/HelpSource/Guides/rewriteString.schelp b/HelpSource/Guides/rewriteString.schelp index 745b88b..b740571 100644 --- a/HelpSource/Guides/rewriteString.schelp +++ b/HelpSource/Guides/rewriteString.schelp @@ -276,7 +276,7 @@ SynthDef("sinegrain", var env; env = EnvGen.kr(Env.perc(0.01, dur, 0.2), doneAction:2); Out.ar(out, SinOsc.ar(freq, 0, env)) -}).memStore; +}).add; ) @@ -445,18 +445,18 @@ k.asStream.rewriteString(c, 6).all.join.postcs; // "bbbbbbab" ( var w, b, u, f, z, level=0; -w = SCWindow("test", Rect(40, 240, 200, 200)).front; +w = Window("test", Rect(40, 240, 200, 200)).front; w.view.decorator = FlowLayout(w.bounds.copy.left_(30).top_(30)); b = { |i| { |j| var c = ({ "abcd".choose } ! 3).join; - SCButton(w, Rect(0,0, 30,25)) + Button(w, Rect(0,0, 30,25)) .states_([[c, Color.black]]) .action_({ f.(c) }) .font_(Font(\Georgia, 11)) } ! 4; w.view.decorator.nextLine } ! 4; w.view.decorator.nextLine; -SCButton(w, Rect(0,0, 30,25)) +Button(w, Rect(0,0, 30,25)) .states_({ |i| [i.asString, Color.black]} ! 16) .action_({ |b| level = b.value }); @@ -474,7 +474,7 @@ SynthDef(\p, { |out = 0, freq=400, amp=0.4, sustain=0.04| SinOsc.ar(freq) * XLine.ar(amp, amp * 0.001, sustain, doneAction: 2) ); -}).memStore; +}).add; ); u = { |str| diff --git a/classes/gui/ScatterView.sc b/classes/gui/ScatterView.sc index ac774a1..3e047e2 100644 --- a/classes/gui/ScatterView.sc +++ b/classes/gui/ScatterView.sc @@ -52,17 +52,17 @@ ScatterView { } initPlot { arg parent, bounds, data, argSpecX, argSpecY; - + var widthSpec, heightSpec, cross; var possibleMethods; - + specX = argSpecX ? [0,1].asSpec; specY = argSpecY ? specX.copy; possibleMethods = [\fillRect, \fillOval, \strokeOval, \strokeRect]; - + this.symbolSize = 1; symbolColor = symbolColor ? Color.black; - + background = Color.white; highlightColor = Color.red; highlightItem = 0; @@ -72,28 +72,27 @@ ScatterView { drawValues = false; xAxisName= "X"; yAxisName= "Y"; - + this.data_(data); - + cross = {|rect, width, color| var dx, dy, extX, extY; dx = rect.left; dy = rect.top; extX = rect.width; extY = rect.height; - GUI.pen.use{ - GUI.pen.color = color; - GUI.pen.translate(dx, dy); - GUI.pen.moveTo((0)@(extY*0.5)); - GUI.pen.lineTo(extX@(extY*0.5)); - GUI.pen.moveTo((extX*0.5)@(0)); - GUI.pen.lineTo((extX*0.5)@(extY)); - GUI.pen.stroke; + Pen.use{ + Pen.color = color; + Pen.translate(dx, dy); + Pen.moveTo((0)@(extY*0.5)); + Pen.lineTo(extX@(extY*0.5)); + Pen.moveTo((extX*0.5)@(0)); + Pen.lineTo((extX*0.5)@(extY)); + Pen.stroke; }; }; - - plot = GUI.userView.new(parent, bounds) - .relativeOrigin_(false) + + plot = UserView.new(parent, bounds) .drawFunc_({|w| var width, height, rect, pad = 10; if (drawAxis) { pad = 60 }; @@ -101,78 +100,70 @@ ScatterView { width = w.bounds.width - pad; height = w.bounds.height - pad; - GUI.pen.use{ + Pen.use{ // clipping into the boundingbox - GUI.pen.moveTo((w.bounds.left)@(w.bounds.top)); - GUI.pen.lineTo(((w.bounds.left)@(w.bounds.top)) - + (w.bounds.width@0)); - GUI.pen.lineTo(((w.bounds.left)@(w.bounds.top)) - + (w.bounds.width@w.bounds.height)); - GUI.pen.lineTo(((w.bounds.left)@(w.bounds.top)) - + (0@w.bounds.height)); - GUI.pen.lineTo((w.bounds.left)@(w.bounds.top)); - GUI.pen.clip; - + Pen.moveTo(0@0); + Pen.lineTo(w.bounds.width@0); + Pen.lineTo(w.bounds.width@w.bounds.height); + Pen.lineTo(0@w.bounds.height); + Pen.lineTo(0@0); + Pen.clip; + // draw Background - GUI.pen.color = background; - GUI.pen.addRect(w.bounds); - GUI.pen.fill; - + Pen.color = background; + Pen.addRect(Rect(0, 0, w.bounds.width, w.bounds.height)); + Pen.fill; + // draw data - GUI.pen.color = symbolColor; + Pen.color = symbolColor; if (possibleMethods.includes(drawMethod), { - GUI.pen.beginPath; + Pen.beginPath; adjustedData.do{|item, i| rect = Rect( ( item[0] * width) - (symbolSize.x/2) + (pad/2), - ((1-item[1]) * height) - (symbolSize.y/2) + (pad/2), + ((1-item[1]) * height) - (symbolSize.y/2) + (pad/2), symbolSize.x, symbolSize.y ); - GUI.pen.perform( + Pen.perform( drawMethod, - (Rect(w.bounds.left, w.bounds.top, 0, 0) + rect) + rect ); } },{ // else draw lines - GUI.pen.width = symbolSize.x; + Pen.width = symbolSize.x; // move to first position; if (adjustedData.notNil) { - GUI.pen.moveTo( + Pen.moveTo( ((adjustedData[0][0] * width) + (pad/2)) @ (((1-adjustedData[0][1]) * height) + (pad/2)) - + - (w.bounds.left@w.bounds.top) ); }; // draw lines adjustedData.do{|item, i| - GUI.pen.lineTo( + Pen.lineTo( ((item[0] * width) + (pad/2)) @ - (((1-item[1]) * height) + (pad/2)) - + - (w.bounds.left@w.bounds.top) + (((1-item[1]) * height) + (pad/2)) ) }; - if(drawMethod == \fill, {GUI.pen.fill},{GUI.pen.stroke}); + if(drawMethod == \fill, {Pen.fill},{Pen.stroke}); }); - + // highlight datapoint if(isHighlight) { highlightItem.do{|item| cross.value((Rect( - (adjustedData[item][0] * width) - - + (adjustedData[item][0] * width) + - (highlightSize.x/2) + (pad/2), - ((1-adjustedData[item][1]) * height) - - - (highlightSize.y/2) - + - (pad/2), - highlightSize.x, highlightSize.y) - + - Rect(w.bounds.left, w.bounds.top, 0, 0)), + ((1-adjustedData[item][1]) * height) + - + (highlightSize.y/2) + + + (pad/2), + highlightSize.x, highlightSize.y) + ), symbolSize, highlightColor ); @@ -180,36 +171,37 @@ ScatterView { }; // draw axis if (drawAxis) { - GUI.pen.moveTo((w.bounds.left+(pad/2))@(w.bounds.top+(pad/2))); - GUI.pen.lineTo((w.bounds.left+(pad/2))@(w.bounds.top+w.bounds.height-(pad/2))); - GUI.pen.lineTo( - (w.bounds.left-(pad/2)+w.bounds.width)@(w.bounds.top+w.bounds.height-(pad/2))); + Pen.fillColor = Color.black; + Pen.moveTo((pad/2)@(pad/2)); + Pen.lineTo((pad/2)@(w.bounds.height-(pad/2))); + Pen.lineTo( + (0-(pad/2)+w.bounds.width)@(w.bounds.height-(pad/2))); specX.minval.round(0.001).asString .drawAtPoint( - (w.bounds.left+(pad/2)+10)@ - (w.bounds.height-(pad/2)+10)); + ((pad/2)+10)@ + (w.bounds.height-(pad/2))); xAxisName .drawAtPoint( - (w.bounds.left+(w.bounds.width/2))@ - (w.bounds.height-(pad/2)+10)); + (w.bounds.width/2)@ + (w.bounds.height-(pad/2))); specX.maxval.round(0.001).asString .drawAtPoint( - (w.bounds.left+10+w.bounds.width-20-(pad/2))@ - (w.bounds.height-(pad/2)+10)); + (10+w.bounds.width-20-(pad/2))@ + (w.bounds.height-(pad/2))); - GUI.pen.rotate(-pi/2); - GUI.pen.translate(w.bounds.height.neg, 0); + Pen.rotate(-pi/2); + Pen.translate(w.bounds.height.neg, 0); specY.minval.round(0.001).asString - .drawAtPoint((pad/2)@(w.bounds.left+(pad/2) -20)); + .drawAtPoint((pad/2)@((pad/2) -20)); yAxisName. - drawAtPoint((w.bounds.height/2)@(w.bounds.left+(pad/2) -20)); + drawAtPoint((w.bounds.height/2)@((pad/2) -20)); specY.maxval.round(0.001).asString - .drawAtPoint((w.bounds.height - (pad/2))@(w.bounds.left+(pad/2) -20)); - GUI.pen.translate(w.bounds.height, 0); - GUI.pen.rotate(pi/2); - GUI.pen.stroke; + .drawAtPoint((w.bounds.height - (pad/2))@((pad/2) -20)); + Pen.translate(w.bounds.height, 0); + Pen.rotate(pi/2); + Pen.stroke; }; // draw values if (drawValues) { @@ -221,7 +213,7 @@ ScatterView { ) } } - }; // end GUI.pen.use + }; // end Pen.use }); } canFocus_ { arg state = false; @@ -243,7 +235,7 @@ ScatterView3d { var rotX, rotY, rotZ; var specX, specY, specZ; var data3d; - + *new {|parent, bounds, data, specX, specY, specZ, rotX = 0, rotY = 0, rotZ = 0| ^super.new.init3d(parent, bounds, data, specX, specY, specZ, rotX, rotY, rotZ); } @@ -268,8 +260,8 @@ ScatterView3d { data_{|data| data3d = data.collect {|item| Matrix.withFlatArray(3, 1, [ - specX.unmap(item[0]), - specY.unmap(item[1]), + specX.unmap(item[0]), + specY.unmap(item[1]), specZ.unmap(item[2]) ] * 2 - 1); }; @@ -296,13 +288,13 @@ ScatterView3d { scatterView.data = this.pr_project; } drawMethod_{|method| - scatterView.drawMethod = method; + scatterView.drawMethod = method; } symbolSize_{|val| - scatterView.symbolSize = val; + scatterView.symbolSize = val; } symbolColor_{|val| - scatterView.symbolColor = val; + scatterView.symbolColor = val; } isHighlight_{|val| scatterView.isHighlight_(val); @@ -320,7 +312,7 @@ ScatterView3d { scatterView.highlightSize_(size); } background_{|val| - scatterView.background = val; + scatterView.background = val; } resize{ ^scatterView.resize @@ -337,13 +329,13 @@ ScatterView3d { cx = cos(rotX); cy = cos(rotY); cz = cos(rotZ); - + projectionMatrix = Matrix.with([ [( (cy * cz) - (sx * sy * sz)), (sz.neg * cx), ((cz * sy) + (sz * sx * cy))], [( (cy * sz) + (cz * sx * sy)), ( cz * cx), ((sz * sy) - (sx * cy * cz))] ]); - - + + ^data3d.collect{|row| (projectionMatrix * row).getCol(0) }; diff --git a/classes/gui/ScatterView2.sc b/classes/gui/ScatterView2.sc index 1486832..3cdd96e 100644 --- a/classes/gui/ScatterView2.sc +++ b/classes/gui/ScatterView2.sc @@ -20,7 +20,7 @@ ScatterView2 { var selectionRect; var <>action; - var <>mouseDownAction, <>mouseUpAction, <>mouseMoveAction, mouseDownAction, <>mouseUpAction, <>mouseMoveAction,