anjin
June 7, 2011, 5:55pm
1
I’m having a small problem with define_key. I would like define key to access the below function. However, when ever I build I get this error:
‘keyObject::key_down’: function call missing argument list; use ‘&keyObject::key_down’ to create a pointer to member
define key call (KEY is a string variable):
window->get_panda_framework()->define_key(KEY, KEY, key_down, NULL);
function definition:
void keyObject::key_down(const Event * theEvent, void * data)
{ value++; }
heek
June 7, 2011, 6:32pm
2
Something that’s common to happen when programming these methods is to forget to make it static . So, the declaration should be:
static void key_down(const Event * theEvent, void * data);
And in the cxx you can just let it the same.
anjin
June 7, 2011, 7:20pm
3
Does anyone know how to use non-static functions with define_key?
heek
June 7, 2011, 7:36pm
4
Instead of passing a NULL as the last parameter you pass a pointer to the object…
window->get_panda_framework()->define_key(KEY, KEY, key_down, this);
and then:
void keyObject::key_down(const Event * theEvent, void * data){
MyClass me = (MyClass*)data;
me->value++;
}
or you can do something like this, and implement your stuff on the second method:
static void key_down(const Event*, void* data){ ((MyClass*)data)->key_down(); }
void key_down(){
// My Stuff;
}
anjin
June 11, 2011, 7:05am
5
Thankyou very much. I feel a little stupid now, but thankyou.
anjin
June 11, 2011, 7:53am
6
well, now I need to create buttons dynamically. Is there a way to do this?
I have messed around with PGButton_notify, but I have no idea how such an object tells when a button is clicked.
drwr
June 11, 2011, 5:13pm
7
Your OP was talking about handling keyboard button events. Are you still referring to keyboard buttons when you talk about creating buttons dynamically, or are you now talking about onscreen GUI button elements? The PGButton class is for the purpose of creating an onscreen GUI button, and it works by generating an event when the button is clicked with the mouse.
But if you’re talking about creating keyboard buttons dynamically, what precisely do you mean?
David
anjin
June 11, 2011, 8:29pm
8
Actually I’m refering to the GUI. I guess I should start a new thread.