PDA

View Full Version : Connecting data from WPOPUP_CTL to variable



Red_Oddity
02-19-2008, 09:38 AM
I have the following piece of code, using LWPanels to create my interface, but i was wondering if i need to write a setevent routine for every interface item, i seriously doubt it, but i have a really hard time finding some usefull examples in the SDK samples that deal with multiple interface items that actually do more than just being an example interface that does nothing.




static void handle_preset( LWControl *ectl, colorSpaceInst *inst )
{
GET_INT( ectl, inst->colorSpaceFrom );
}

static void create_controls( colorSpaceInst *inst )
{


ctl[ 0 ] = WPOPUP_CTL( panf, panel, "From", preset, 150 );
ctl[ 1 ] = WPOPUP_CTL( panf, panel, "To", preset, 150 );
ctl[ 2 ] = BOOL_CTL( panf, panel, "Remove Gamma");

SET_INT( ctl[ 0 ], inst->colorSpaceFrom );
SET_INT( ctl[ 1 ], inst->colorSpaceTo );
SET_INT( ctl[ 2 ], inst->to_from );

CON_SETEVENT( ctl[ 0 ], handle_preset, inst );

}

Lightwolf
02-19-2008, 11:32 AM
You can let them all use the same callback.
Then use the LWControl *ectl to differentiate between the called control.
If your control array ctl[] is a part of your colorSpaceInst you can easily compare them.

i.e.



if (ectl == inst->ctl[0]) {
// handle colorSpaceFrom
}
else if...

Cheers,
Mike

Red_Oddity
02-19-2008, 12:04 PM
Aaah...i was so close...thanks Mike

Red_Oddity
02-19-2008, 12:17 PM
I did have to make ctl part of colorSpaceInst, is this the normal/best way to do it? Or are there other ways, or does it come down to personal preference?

Just wondering, as this is different to what is done in most SDK samples

Lightwolf
02-19-2008, 12:21 PM
I did have to make ctl part of colorSpaceInst, is this the normal/best way to do it?
Yup, best way. Basically colorSpaceInst should be used for all things unique to an instance of your plugin.
Think of it this way... if you had your plugin run twice, which items would need to be unique to each of them. The controls would be one of those items.

Cheers,
Mike

Red_Oddity
02-19-2008, 02:33 PM
Ah, yes, that does make sense, you learn something new everyday.

Thanks again Mike.

Lightwolf
02-19-2008, 02:34 PM
Ah, yes, that does make sense, you learn something new everyday.
Wouldn't life be boring otherwise? :D

Thanks again Mike.
You're welcome.

Happy hacking & cheers,
Mike