PDA

View Full Version : I'm an old dog and need new tricks



BloodQuest
05-08-2008, 03:04 PM
Hi guys,

I was saying to someone the other day about how you know you've mastered a language, like French, when you can THINK in it.

Well, I'm never going to be able to think in C...

So, here's the problem I'm stuck on.

I want to be able to configure a button to run a specified command. I've got a callback that looks like this:

static void event_7( LWControl *ctl, char* userdata )
{
static char cmd[ 256 ], arg[ 256 ];
int result;

msg->info( "Command is", userdata );
result = local->evaluate( local->data, userdata );
}

Crashes every time. I've tried all sorts of permutations, but nothing helps.

Any thoughts from anyone who knows what they're doing?

Simon

Lightwolf
05-09-2008, 01:18 AM
Obscure... I gather that msg->info is not NULL and nor is userdata and local?
Try using a fixed command for a start, i.e. local->evaluate(local->data, "AboutOpenGL");

Other than that I'm stumped... have you run this in a debugger to see the variable contents? Where does it crash?

Cheers,
Mike

BloodQuest
05-09-2008, 10:17 AM
Hey Mike,

Sorry, didn't explain very well - the msg->info works and reports the correct info - it's when the evaluate runs that the crash occurs.

I should also explain that the problem is only when using a callback - if I put the same function in the main entry function it works fine.

I have tried using a fixed command - the "about" function - it crashes just the same.

As to debugging, I found info in the SDK on using a debugger with Modeler, but not layout...

Cheers,

Simon

BloodQuest
05-10-2008, 02:25 AM
I've obviously had too many late nights!

The problem with "local" was using a pointer to a structure when what I needed was the struct itself.

As for debugging, well RTFM, eh?

Thanks as always for the help.

I will post the plug-in here once it's done!

Simon

Lightwolf
05-10-2008, 03:38 AM
I've obviously had too many late nights!

The problem with "local" was using a pointer to a structure when what I needed was the struct itself.

As for debugging, well RTFM, eh?

Good to see you got it to work.
Debugging: Which compiler are you using? If you'Re using the MSVC compiler it is dead easy really, build a debug version of the plugin, run Layout, then in the IDE attach the debugger to Layout and then run your plugin.

Cheers,
Mike

BloodQuest
05-10-2008, 11:25 AM
What I meant was that I HAD read the relevant section of the SDK and had got the debug mode working - it is MSVC - and it really helped pin the problem down.

This is why I love these forums!

Simon

Lightwolf
05-10-2008, 01:20 PM
What I meant was that I HAD read the relevant section of the SDK and had got the debug mode working - it is MSVC - and it really helped pin the problem down.

Ah, sorry, I misunderstood...

Good to see you make progress then! :jam:

Cheers,
Mike

BloodQuest
05-11-2008, 12:45 AM
Okay, so I have everything working, except now I want to be able to add keyboard input - so I can have keyboard shortcuts as an alternative to pressing buttons in the panel.

I've looked through the panels section of the SDK docs, which has left me none the wiser. Unfortunately, there's no example that I can find of handling keyboard input.

Am I just stupid or is this really as complicated as it seems?

Simon

Lightwolf
05-11-2008, 05:02 AM
Okay, so I have everything working, except now I want to be able to add keyboard input - so I can have keyboard shortcuts as an alternative to pressing buttons in the panel.

I've looked through the panels section of the SDK docs, which has left me none the wiser. Unfortunately, there's no example that I can find of handling keyboard input.

Am I just stupid or is this really as complicated as it seems?

Simon
Hm, all you really need is to set a callback for LW to call.

Panel Callbacks

The LWPanelFuncs set function allows you to install a number of panel callbacks that LWPanels will call when certain events occur. You aren't required to install any, so only use them if you need them. All panel callbacks receive as their second argument the value you set for PAN_USERDATA.

pankey( panel, userdata, key )
The form for PAN_USERKEYS and PAN_USERKEYUPS. For alphanumeric keys, the key code is just the ASCII code. lwpanel.h defines special codes for other keys. A value of '1' should be returned if the key was processed, or '0' if not.
The difference between PAN_USERKEYS and PAN_USERKEYUPS is that the former triggers when the key is pressed, the later when the key is released by the user.

Afaik there are no macros to simplify this, but panf->set(panelID, PAN_USERKEYS, yourCallbackFunction); ought to do it.

Cheers,
Mike

BloodQuest
05-11-2008, 06:53 PM
Michael - you are awesome! Once again, you've put me on the right track.

Anyway, what started out as something I thought would be trivial turned into a pain in the bum! Here's where I'm at (everything works with the caveats noted below):

http://www.simon-coombs.com/utils/quix/quix.png

The idea was to have a configurable non-modal panel with sets of commands available on the pulldown.
Each set would be accessed via mouse or the keyboard 1 through 0.

There are a few remaining issues:

Firstly, LW insists on passing through keypresses which means layout promptly changes view.

Secondly, if the window loses focus, the keyboard commands no longer work.

Finally, Modeler won't support a non-modal window.

So I find myself wondering whether to carry on, or give it up as a bad idea?

Simon

Lightwolf
05-12-2008, 01:25 AM
...
The idea was to have a configurable non-modal panel with sets of commands available on the pulldown.
Each set would be accessed via mouse or the keyboard 1 through 0.

There are a few remaining issues:

Firstly, LW insists on passing through keypresses which means layout promptly changes view.
...
I think this issue can be stopped, I remember reading about it on the developers mailing list at groups.yahoo.com if I'm not mistaken...
You might want to search the archive there:
http://groups.yahoo.com/group/lw-plugin/

I've actually had something similar in mind some time ago... but automated and based on the frequency of use.

Cheers,
Mike

BloodQuest
05-12-2008, 05:23 PM
Thanks Mike, I'll check that out!

Simon