Warrior of the Light
21st April 2004 20:04 UTC
Buttons in AVS
It's questionable if this belongs in the presets subforum or in the AVS forum, but I didn't start this thread only about the preset, but more about the functionality.
A lot of people have already worked this out, but here's my way of doing this:
You don't want the button to flip per frame when you hold the mouse button for multiple frames, what would happen if you would simply use button=getkbmouse(3); I solved this by generating a pulse when the mouse-button is pressed.
This pulse normally would only trigger the button for 1 frame. You want it to switch per pulse. Here's how I solved it all (button is reg02).
xm=getkbmouse(1);
ym=getkbmouse(2);
rm=getkbmouse(3);
mc=if(below(xm,-.9)&above(xm,-1)&above(ym,.9)&below(ym,1)&rm,1,0);
mcpulse=if(equal(mcold,mcnew),0,if(equal(mcold,0),1,0));
mcold=var;
var=if(equal(mc,0),mcpulse,1);
mcnew=var;
mcswitch=if(mcpulse,bnot(mcswitch),mcswitch);
reg02=mcswitch;
Example preset is attached (will most likely be in my new pack).
The button appears when you move the mouse over the left and bottom of the preset ( xpos < -0.9 or ypos < 0.9 ) Click it and the preset changes. Also explained in the comment.
UnConeD
22nd April 2004 01:00 UTC
Your method is waaaaaay too complicated (not to mention such a thing has been posted before).
Pulse:
old=new;new=getkbmouse(3);pulse=band(new,bnot(old));
Then just check the x/y coordinates and and with pulse:
if(band(pulse,...), /* do mouse click */ ,0);
S-uper_T-oast
22nd April 2004 03:25 UTC
UnConeD got it.
I am kicking aorund an idea like that for a prest library GUI type fux0red thing, it would be nice if it worked.
Tuggummi
22nd April 2004 07:58 UTC
Yup, i've used UnConeD's method for a while now and im very pleased by it :)
Warrior of the Light
22nd April 2004 10:55 UTC
%@#$!!! just when I think I've worked someting out... :mad:
Nevermind...
By the way, why is band() faster than & ? Aren't funtions slower than operators in this case (pulse) ? :confused:
[edit]
Am I the only one who likes the altered preset or am I the only one? None of my friends seem to like it... :cry:
[/edit]
Tuggummi
22nd April 2004 11:07 UTC
Hmm, doesn't & do something else? The explanation on the help is hard to understand for me tho :confused:
But band would be * too in occasions, band(1,1)=1 and 1*1=1 Just as long as they are numbers and the values are 1 precisely.
Don't know what is the fastest way though :p
[edit]
The altered preset is nicer with low fps, but with high fps it tends to flicker too much.
[/edit]
TomyLobo
22nd April 2004 14:14 UTC
band() is boolean AND
& is bitwise AND
the C representation of band(x, y) should be something like
(((x == 0) || (y==0))? 0 : 1)
x & y is probably
(double)(((int)x)&((int)y))
band() is 2 floating point comparisons and a boolean OR,
whereas & is 3 type conversions and a bitwise AND
guess which one is faster ;)
Warrior of the Light
23rd April 2004 13:51 UTC
I know what they do :hang: i was talking about my case, but this makes it more clear... thanks
DynamicMovement
23rd April 2004 17:11 UTC
UnConeD's method has benefits & disadvantages:
For writing DM it has functionality, but, when I want to code other parts I have same problems.
UnConeD
23rd April 2004 18:22 UTC
Comparing functions with operators in AVS makes no sense: the scripting language is way too high level to be able to decide what goes on on the assembly level.
Get the WA5 SDK and look in the nseel dir, nseel-cfunc.c. Then come back and discuss speed issues :rolleyes: .