[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] drawOnRefresh?





i do it with some sort of flag inside the drawfunc. say it's flagged for clear, i then draw a rectangle filling the screen with or without alpha. works fine but maybe there are other ways too.

Hmm. Not sure if I understand.

I've got a SCUserView with a drawFunction. I only want it to draw when I tell it to.

I then update the SCWindow and other Views constantly. When that happens, the SCUserView drawing disappears. (that is if I have a draw flag that says false unless I want it to draw) So it needs to draw on every window update using lots of CPU
cycles for nothing.

If there was a .drawOnRefresh_(false) that would just keep the drawing from the last
window update without redrawing it, it would save processing.

(but thinking about it, this might not be how things work, perhaps it's not possible to "leave" or "freeze" a view in the window and update everything else??)

Maybe I'm just misunderstanding the workings of SCUserView drawing???

thor


(
var func, views, counter= 0;

func = {
	if(counter>0, {
		//clear+fadeout - or in your case just don't draw anything
		Pen.fillColor_(Color.grey(1, 0.07));
		Pen.fillRect(Rect(0, 0, w.bounds.width, w.bounds.height));
	}, {
		//draw only when counter= 0
		Pen.use{
			10.do{
				Color.red(rrand(0.0, 1), rrand(0.0, 0.5)).set;
Pen.addArc((400.exprand(2))@(100.rand), rrand(10, 100), 2pi.rand, pi);
				Pen.perform([\stroke, \fill].choose);
			}
		}
	})
};

w = SCWindow.new("DrawFunc Examples").front;
w.view.background_(Color.white);
views = {|i|
v = SCUserView(w, Rect(20+(i*120), 100, 100, 100)).relativeOrigin_ (true);
	v.drawFunc = func;
	v.clearOnRefresh_(false)
} ! 3;
Routine({
	inf.do{
		w.refresh;
		0.1.wait;
		counter= counter-1%20;
	}
}).play(AppClock);
)




Am 17.12.2007 um 17:57 schrieb thor:



Hi

Is it possible to add .drawOnRefresh_ to SCUserView?

I'd like to draw once and then disable SCUserView's draw functionality until I tell it to draw again. (other views are being updated which forces
SCUserView to draw repeatedly).

The following code from the example works, but it's kind of ugly to have to repeatedly set the drawFunc to nil and then back to the intended drawFunc
when needed.

And I'm not sure if clearOnRefresh saves any CPU...

t

prevent redrawing:

(
var func, views;

func = {|me|
	Pen.use{
		10.do{
			Color.red(rrand(0.0, 1), rrand(0.0, 0.5)).set;
Pen.addArc((400.exprand(2))@(100.rand), rrand(10, 100), 2pi.rand, pi);
			Pen.perform([\stroke, \fill].choose);
		}
	}
};

w = SCWindow.new("DrawFunc Examples").front;
w.view.background_(Color.white);
views = {|i|
v = SCUserView(w, Rect(20+(i*120), 100, 100, 100)).relativeOrigin_ (true);
	v.drawFunc = func;
} ! 3;
w.refresh;
{views.do{|v| v.clearOnRefresh_(false);v.drawFunc = nil}}.defer(0.4);
)


  #|
     fredrikolofsson.com     klippav.org     musicalfieldsforever.com
  |#

_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users