2017-05-23 16:40:02 -04:00
|
|
|
#ifndef GRAPHICSOBJECT_H
|
|
|
|
#define GRAPHICSOBJECT_H
|
|
|
|
|
|
|
|
class GraphicsObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// 2nd arg: pointer to callback function that takes a reference to an int as an argument
|
|
|
|
GraphicsObject(int set_x)
|
|
|
|
{
|
|
|
|
x = set_x;
|
|
|
|
user_data = NULL;
|
|
|
|
callback = NULL; // function pointer
|
|
|
|
}
|
|
|
|
GraphicsObject(void (*set_callback)(int&, void*), void *set_user_data)
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
user_data = set_user_data;
|
|
|
|
callback = set_callback; // function pointer
|
|
|
|
}
|
|
|
|
int X()
|
|
|
|
{
|
|
|
|
// If you are SUPPOSED to callback, ...
|
|
|
|
if(callback)
|
|
|
|
// ... do so to ask for the new X value
|
|
|
|
callback(x, user_data);
|
|
|
|
return x; // either this was just set by callback, or it was always set by constructor.
|
|
|
|
}
|
2017-05-23 17:04:35 -04:00
|
|
|
private:
|
2017-05-23 16:40:02 -04:00
|
|
|
int x;
|
|
|
|
void *user_data;
|
|
|
|
void (*callback)(int&, void*);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|