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

[sc-users] UI menu?



hi Wouter, 
this works pretty well for me
started it last nite :)
just bits and bobs left i think
what do you think ?



_______________________________________________________________ 
What is the largest island in the Mediterranean Sea? 

postmaster.co.uk
http://www.postmaster.co.uk/cgi-bin/meme/quiz.pl?id=182
{\rtf1\mac\ansicpg10000\cocoartf102
{\fonttbl\f0\fnil\fcharset77 Monaco;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;\red191\green0\blue0;\red0\green0\blue191;
\red0\green115\blue0;\red96\green96\blue96;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f0\fs18 \cf2 \
\cf3 /* \
//change to SCRangeSlider so as not to break:\
\
*paletteExample \{ arg parent, bounds;\
		var v;\
		v = this.new(parent, bounds);\
		v.lo = 0.2;\
		v.hi = 0.7;\
		^v //// added\
	\}\
	\
\
//might want to add this to SCStaticText\
\
*paletteExample \{ arg parent, bounds;\
		var v;\
		v = this.new(parent, bounds);\
		v.string = "The lazy brown fox";\
		v.backColor=Color.green; ////added\
		^v\
	\}\
	\
////sms sept 05\
\
readme:\
press delete with selected views to delete them\
press c with selected views to clone them\
toggle a View in the pallette and select an area to drop a new one in\
detoggle any selected View in the pallette to go back into selection / resize mode\
click inside any side of a View bounds to resize it in that direction\
on / off is for quantize grid\
the number box is integer for grid step pixels\
*/\cf2 \
\
\
(\
	\cf4 var\cf2  tabW=400,tabH=400;\
	\
	\cf4 var\cf2  w,w2,t,views,selectionRect,indentX,indentY;\
	\cf4 var\cf2  selectedViews,multipleDragBy,currentlyDragging;\
	\
	\cf4 var\cf2  gridStep=1,gridNB;\
	\
	\cf4 var\cf2  viewList,insertView,insertButtons,makeTablet;\
	\cf4 var\cf2  mouseDownAction,mouseUpAction,action,keyDownAction;\
	\
	\cf4 var\cf2  clickIsInView,checkResize,resizeMargin=4,resizing;\
	\
	viewList = [\
		\cf4 SCButton\cf2 ,\
		\cf4 SCStaticText\cf2 ,\
		\cf4 SCNumberBox\cf2 ,\
		\cf4 SCSlider\cf2 ,\
		\cf4 SCRangeSlider\cf2 ,\
		\cf4 SCMultiSliderView\cf2 ,\
		\cf4 SCPopUpMenu\cf2 ,\
		\cf4 SC2DTabletSlider\cf2 ,\
		\cf4 SC2DSlider\cf2 ,\
		\cf4 SCTabletView\cf2 ,\
		\cf4 SCEnvelopeView\cf2 ,\
		\cf4 SCDragBoth\cf2 ,\
		\cf4 SCDragSink\cf2 ,\
		\cf4 SCDragSource\cf2 \
		\cf3 //SCTextView		// doesn't behave\cf2 \
		\cf3 //SCMovieView		// doesn't behave\cf2 \
	];\
	\
	clickIsInView = \{ \cf4 |x,y|\cf2 \
		\cf4 var\cf2  p = x@y,i=0,view,index;\
		while (\{ index.isNil and: (i<views.size) \},\{\
			view = views[i];\
			if(view.bounds.containsPoint(p),\
				\{ index=i \}, \{ i=i+1 \})\
		\});\
		index\
	\};\
	\
	checkResize = \{ \cf4 |r,x,y|\cf2 \
		resizing=case (\
			\{ x.inclusivelyBetween( r.left, r.left+resizeMargin ) \},				\cf5 \\l\cf2 , \cf3 // extend left\cf2 \
			\{ x.inclusivelyBetween( r.right-resizeMargin, r.right ) \},\
				\cf5 \\r\cf2 , \cf3 // extend right\cf2 \
			\{ y.inclusivelyBetween( r.top, r.top+resizeMargin ) \}, \
				\cf5 \\u\cf2 , \cf3 // extend up\cf2 \
			\{ y.inclusivelyBetween( r.bottom-resizeMargin, r.bottom ) \},\
				\cf5 \\d\cf2  \cf3 // extend down\cf2 \
		)\
	\};\
	\
	mouseDownAction = \{ \cf4 |v,x,y|\cf2 \
		\cf4 var\cf2  index,view,j=4;\
		index = clickIsInView.(x,y);\
		currentlyDragging = index.notNil;\
		if(currentlyDragging,\{\
			view = views[index];\
			indentX=x-view.bounds.left;\
			indentY=y-view.bounds.top;\
			if( (selectedViews.size>1) and: \{ selectedViews.includes(view) \},\{\
				\cf3 // move around a lot by dragging this one\cf2 \
				multipleDragBy = view\
			\},\{\
				\cf3 // switch selection to this one and move it\cf2 \
				multipleDragBy = \cf4 nil\cf2 ;\
				selectedViews=[view];\
				checkResize.(view.bounds,x,y)\
			\})	\
		\},\{\
			\cf3 //start selection\cf2 \
			selectedViews=[];\
			if(insertView.notNil,\{\
				x=x.round(gridStep).max(gridStep);\
				y=y.round(gridStep).max(gridStep);\
				j=gridStep\
			\});\
			selectionRect = \cf4 Rect\cf2 (x,y,j,j);\
			\
		\});\
		w.refresh\
	\};\
	\
	mouseUpAction = \{ \cf4 |v,x,y|\cf2 \
		\cf4 var\cf2  view;\
		if(selectionRect.notNil,\{\
			if(insertView.notNil,\{\
				view=insertView.paletteExample(w,selectionRect);\
				views=views.grow(1).add(view);\
				selectedViews=[view];\
				t.remove; makeTablet.value\
				\
			\});\
			selectionRect=\cf4 nil\cf2 ;\
			w.refresh\
		\})\
	\};\
	\
	keyDownAction = \{ \cf4 |v,c,m,u|\cf2 \
		\cf4 var\cf2  newViews;\
		case (\
		\{u==127\}, \{ \cf3 // delete\cf2 \
			if(selectedViews.isEmpty.not,\{\
				selectedViews.do(\{ \cf4 |v|\cf2 \
					views.remove(v.remove);\
				\});\
				selectedViews=[];\
				w.refresh\
			\})\
		\},\
		\{(c==$c) or: (c==$C)\},\{ \cf3 // clone\cf2 \
			if(selectedViews.isEmpty.not,\{\
				newViews=selectedViews.collect(\{ \cf4 |v|\cf2 \
					v.class.paletteExample(w,v.bounds.moveBy(40,40))\
				\});\
				views=views++newViews;\
				selectedViews=newViews;\
				t.remove; makeTablet.value;\
				w.refresh\
			\})\
		\})\
	\};\
	\
	action = \{ \cf4 |v,x,y|\cf2 \
		\cf4 var\cf2  ix,iy,l,t,view,b,d;\
		if(currentlyDragging,\{\
			if(multipleDragBy.notNil,\{\
				\cf3 //dragging 0 or more\cf2 \
				l = multipleDragBy.bounds.left+indentX;\
				t = multipleDragBy.bounds.top+indentY;\
				l = x - l;\
				t = y - t;\
				selectedViews.do(\{ \cf4 |v|\cf2 \
					\cf4 var\cf2  b=v.bounds.moveBy(l,t);\
					b.left=round(b.left,gridStep);\
					b.top=round(b.top,gridStep);\
					v.bounds=b\
				\})\
			\},\{\
				\cf3 //dragging one\cf2 \
				view=selectedViews[0];\
				b=view.bounds;\
				if(resizing.isNil,\{\
					view.bounds=b.moveTo(\
						round(x-indentX,gridStep),\
						round(y-indentY,gridStep)\
					)\
				\},\{\
					switch (resizing,\
						\cf5 \\l\cf2 , \{ d=b.left; x=round(x,gridStep);\
							view.bounds=b.left_(x).width_((d-x+b.width).max(gridStep))\
						\},\
						\cf5 \\r\cf2 , \{ \
							view.bounds=b.width_(round(x-b.left,gridStep).max(gridStep))\
						\},\
						\
						\cf5 \\u\cf2 , \{ d=b.top; y=round(y,gridStep);\
							view.bounds=b.top_(y).height_((d-y+b.height).max(gridStep))\
						\},\
						\cf5 \\d\cf2 , \{\
							view.bounds=b.height_(round(y-b.top,gridStep).max(gridStep))\
						\})\
				\})\
			\})\
			\
		\},\{\
			\cf3 //extending selection\cf2 \
			ix=selectionRect.bounds.left;\
			iy=selectionRect.bounds.top;\
			ix=x-ix;\
			iy=y-iy;\
			if(insertView.notNil,\{\
				ix=ix.round(gridStep).max(gridStep);\
				iy=iy.round(gridStep).max(gridStep)\
			\});\
			selectionRect=selectionRect.resizeTo(ix,iy);\
			if(insertView.isNil,\{\
				selectedViews=views.select(\{ \cf4 |v|\cf2 \
					selectionRect.intersects(v.bounds)\
				\})\
			\});\
			w.refresh\
		\})\
	\};\
	\
	makeTablet = \{\
		\cf4 var\cf2  b=w.view.bounds;\
		t = \cf4 SCTabletView\cf2 (w,\cf4 Rect\cf2 (0,0,b.width,b.height));\
		t.resize_(5).mouseDownAction_(mouseDownAction)\
			.mouseUpAction_(mouseUpAction).action_(action)\
			.keyDownAction_(keyDownAction)\
	\};\
	\
	\
	w = \cf4 SCWindow\cf2 (\cf6 "Panel"\cf2 ,\cf4 Rect\cf2 (100,100,tabW,tabH)).front;\
	w.onClose=\{ w2.prClose \};\
	\
	w2 = \cf4 SCWindow\cf2 (\cf6 ""\cf2 ,\cf4 Rect\cf2 (50,50,100,viewList.size*25+60),resizable:\cf4 false\cf2 ).front;\
	w2.onClose=\{ w.prClose \};\
	\
	\cf4 SCButton\cf2 (w2,\cf4 Rect\cf2 (5,5,40,20)).states_([[\cf6 "off"\cf2 ],[\cf6 "on"\cf2 ]])\
		.value_(1).action=\{ \cf4 |v|\cf2  \
			switch ( v.value,\
				0, \{ gridStep=gridNB.value \},\
				1, \{ gridStep=1 \});\
		\
		w.refresh\
	\};\
	\
	insertButtons=viewList.collect(\{ \cf4 |c,i|\cf2  \cf4 var\cf2  s=c.asString;\
		\cf4 SCButton\cf2 (w2,\cf4 Rect\cf2 (5,i*25+55,90,20)).states_\
			([[s,\cf4 Color\cf2 .black,\cf4 Color\cf2 .grey(0.9)],[s,\cf4 Color\cf2 .white,\cf4 Color\cf2 .blue]])\
			.font_(\cf4 Font\cf2 (\cf6 "Helvetica"\cf2 ,9)).action=\{ \cf4 |v|\cf2 \
			if(v.value==0,\{\
				insertView=\cf4 nil\cf2 \
			\},\{\
				insertButtons.reject(\{ \cf4 |b|\cf2  b===v \}).do(\{ \cf4 |b|\cf2  b.value=0 \});\
				insertView=c\
			\})\
		\}\
	\});\
	\
	gridNB=\cf4 SCNumberBox\cf2 (w2,\cf4 Rect\cf2 (50,5,40,20)).value_(10)\
		.align_(\cf5 \\center\cf2 ).action=\{ \cf4 |v|\cf2 \
			v.value=v.value.clip(4,50).asInt;\
			if(gridStep>1,\
				\{ gridStep=v.value; w.refresh \})	\
	\};\
	\
	\cf4 SCButton\cf2 (w2,\cf4 Rect\cf2 (5,30,90,20)).states_([[\cf6 ">> CODE"\cf2 ]])\
		.action=\{\
			(\cf6 "w=SCWindow(\\"\cf2 panel\\\cf6 ","\cf2 ++ w.bounds.asCompileString++\cf6 ").front;"\cf2 ).postln;\
			views.do(\{ \cf4 |v|\cf2  (v.class.asString++\cf6 "(w,"\cf2 \
				++v.bounds.asCompileString++\cf6 ");"\cf2 ).postln \})\
	\};\
	\
	w.drawHook = \{\
		\cf4 var\cf2  gridDivisions;\
		if(gridStep>1,\{\
			tabH = w.view.bounds.height;\
			tabW = w.view.bounds.width;\
			\cf4 Color\cf2 .yellow(1,0.4).set;\
			gridDivisions = tabH / gridStep;\
			(gridDivisions-1).do(\{ \cf4 |i|\cf2  i=i+1*gridStep;\
				\cf4 Pen\cf2 .moveTo(0@i).lineTo(tabW@i).stroke;\
			\});\
			gridDivisions = tabW / gridStep;\
			(gridDivisions-1).do(\{ \cf4 |i|\cf2  i=i+1*gridStep;\
				\cf4 Pen\cf2 .moveTo(i@0).lineTo(i@tabH).stroke;\
			\})\
		\});\
		\cf4 Color\cf2 .blue.set;\
		selectedViews.do(\{ \cf4 |v|\cf2 \
			\cf4 Pen\cf2 .strokeRect(v.bounds)\
		\});\
		if(selectionRect.notNil,\{\
			\cf4 Pen\cf2 .strokeRect(selectionRect)\
		\});\
	\};\
	\
	views = \cf4 Array\cf2 .new;\
		\
	makeTablet.value;\
	\
	selectedViews=\cf4 Array\cf2 .new;\
)\
}