Momentary Buttons and interface builder

steve holmes's picture

I know this has been asked before, but is there a work around for using momentary buttons in Interface builder for use with quartz compostions.

Cheers Steve

franz's picture
Re: Momentary Buttons and interface builder

search field, left of the page: http://kineme.net/Discussion/GeneralDiscussion/NSButtonproblem

http://kineme.net/forum/Discussion/DevelopingCompositions/NSButtonInterf...

or do it programmatically from your AppController object. (doesn't have the overhead of the pulse)

steve holmes's picture
Re: Momentary Buttons and interface builder

Thanks for that I had search for an answer for this one honest! I read both the posts but they both suggest not using momentary buttons. As for a solution through the App controller I will have a look at this, so thanks. Steve

steve holmes's picture
Re: Momentary Buttons and interface builder

Hi Franz I have looked across the web for info on using AppController with momentary buttons, it may well be one of those things that is obvious for programmers (which I am not, if you hadn't guessed) but I can't seem to find any info on this, so I was wondering if you could point me to any examples or a brief explanation.

Thanks again for all the help. Cheers Steve

franz's picture
Re: Momentary Buttons and interface builder

np. Launch Xcode and make a new project using the QCapplication template. In the AppController object (.h and .m file), there's an IBAction method called "change Color to Blue". That method is "applied" through a momentary button. Launch InterfaceBuilder (double click the MainMenu.xib) and look for the "Set preset" button at the right (whose behavior is Momentary push in).

steve holmes's picture
Re: Momentary Buttons and interface builder

Thanks Franz I had see that example and tried to understand how it worked but I was only testing it with Cocoa Simulator which did nothing, after building the application it all becomes clearer thanks for the pointer this should help loads. Cheers Steve

franz's picture
Re: Momentary Buttons and interface builder

IBActions won't work in the simulator, apparently and unfortunately.

steve holmes's picture
Re: Momentary Buttons and interface builder

Okay after 2 days of scratching my head and trawling across the internet for info (most of which has not made sense to me!) I have managed to start to get somewhere.

I have used the following code to allow me to use a series of buttons to recall presets from a multiplexior which is nice and useful.

- (IBAction) changeColorToBlue:(id)sender
{
   switch ( [sender tag] )
   {
      case 1:
         [qcView setValue:[NSNumber numberWithInt:1] forInputKey:@"B3"];
         break;
 
      case 2:
         [qcView setValue:[NSNumber numberWithInt:2] forInputKey:@"B3"];         
         break;
      case 3:
         [qcView setValue:[NSNumber numberWithInt:3] forInputKey:@"B3"];         
         break;
      case 4:
         [qcView setValue:[NSNumber numberWithInt:4] forInputKey:@"B3"];         
         break;
      case 5:
         [qcView setValue:[NSNumber numberWithInt:5] forInputKey:@"B3"];         
         break;
   }

The changecolortoblue is hangover from the xcode example. Using the xcode example I was able to get a momentary switch to turn a sprite on, but unfortunately it stayed on after the button had been pressed so it wasn't a momentary switch. So the question I have is how do I get a bool value only when the button is pressed?

As ever thanks for all the help. Cheers Steve

cwright's picture
Re: Momentary Buttons and interface builder

steve holmes wrote:
I was able to get a momentary switch to turn a sprite on, but unfortunately it stayed on after the button had been pressed so it wasn't a momentary switch. So the question I have is how do I get a bool value only when the button is pressed?

... don't use an ibaction? IBAction is inherently single-shot (i.e. it will fire exactly once when clicked). If you want to use a momentary button's value, use bindings, not actions.

franz's picture
Re: Momentary Buttons and interface builder

if you want to control a multiplexer, why not use a PopDown button , and bind its "selected index" to your multiplexer's index, via simple binding ? It would be much simpler IMHO than using a switch case.

Also, to turn a sprite ON/OFF, a regular button is definitly what you need (ON/OFF behavior ...)

steve holmes's picture
Re: Momentary Buttons and interface builder

Hi Guys thanks for the advice, what I am looking to build is a preset recall program that will recall a series of presets on the press of a button. So I will have 25 buttons that can recall any preset. This is to go with the PTZ camera control I have been working on. So when you press button 1 it goes to position 1. As this is sending a serial command I don't want the button toggled on as I want the user to then be able to fire the next preset.

Hope this make sense and why I want to use momentary buttons. Cheers Steve

gtoledo3's picture
Re: Momentary Buttons and interface builder

Sorry if this drifts OT, but how do you get the behavior of a switch - eg., when I hit it, it triggers, NOT when I let up (ala an OS X button). For anything where you want something to happen in a timed manner, the OS X button behavior is undesirable since the trigger happens on release.

usefuldesign.au's picture
Re: Momentary Buttons and interface builder

steve holmes wrote:
So when you press button 1 it goes to position 1. As this is sending a serial command I don't want the button toggled on as I want the user to then be able to fire the next preset.
This sounds close to the radio button default behaviour. You could have an "Other" button as button 26 to allow for any non-preset occurrences if necessary. Just a suggestion…