Sg2.9
Problems with slider and func...
Recent RSS
Problems with slider and function call (e.g. scaling)
From:  Axel
Date:  2. October 2010, 02:21

Hi,

in the onChange-part of a slider i want to call a function, let's say scaleShapes(value).

i would do it this way:

(...)
onChange: function(value) { scaleShapes(value) }

(...)

(scaleShape simply calls the scale-method of different Paths passing the value)

but i can't see any change on the shapes i can see in the document.

But, as soon as, i click cancel or ok, scaleShapes is called with the value of the last change.

Is this issue known? Is there a way to get this working?

Axel

Re: Problems with slider and function call (e.g. scaling)
From:  Axel
Date:  2. October 2010, 12:19

ah ok, thanks, so the things is:

i click on the document and create some shapes.
after i have drawn some shapes i would like to scale them.
As i dont know what the right value is (aesthetically), i would like a ui element, that allows me to change the scaling value and shows me result of the scaling.
if i think i found the right value, save it .

What can you advise in order to realize this?

best regards,
Axel

Re: Problems with slider and function call (e.g. scaling)
Date:  2. October 2010, 12:31

Well I would advise to use the Palette - how about something like this:

tool.minDistance = 30;

var lastScale = 1;

var values = {
	scaling: 1
}

var components = {
	scaling: {
		type: 'slider',
		label: 'scaling size',
		value: 1,
		range:[0.05, 4],
		enabled: true,
		onChange: function(value) {
			rescaleTriangles(value);
		}
	}
}

function rescaleTriangles(scale) {
	for(var i = 0; i < shapes.length; i++) {
		var shape = shapes[i];
		shape.scale((1 / lastScale) * scale);
	}
	lastScale = scale;
}

function onMouseDown(event) {
	// empty the shapes array again,
	// this stops scaling items created in the last drag
	shapes = [];
}

function onMouseDrag(event) {
	var path = new Path.Circle(event.point, 10);
	// scale the path to the current scale setting:
	path.scale(values.scaling);
	shapes.push(path);
}

var palette = new Palette('Scaler', components, values);
Re: Problems with slider and function call (e.g. scaling)
From:  Axel
Date:  2. October 2010, 12:53

i got to try it later, but thanks a lot!

Re: Problems with slider and function call (e.g. scaling)
From:  Axel
Date:  2. October 2010, 17:34

works fine

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Crumpler 23.07.10