> Is it better to create wrappers for all of the base struct functions which will be used by the child struct
Wrappers IMO. That way if anything internally changes then the user is really none-the-wiser.
Printable View
> Is it better to create wrappers for all of the base struct functions which will be used by the child struct
Wrappers IMO. That way if anything internally changes then the user is really none-the-wiser.
Thanks zacs7. Definitely makes sense.
I also noticed you're using glut, which is mostly dead. You may want to look into gflw.
I use it, and it is VERY nice.
Thanks for the link. I'll see if I can get it to load up on my system and give it a spin....
It'll probably mean you'll have to program your own fonts though :-). No more using the glut ones!
If you still want bitmap fonts, perhaps use http://www.angelcode.com/products/bmfont/ . Of course this is all work in the opposite direction of what you're trying to get done really... :p
officedog is resourceful and already has a wonky home-made bitmap alphabet! So assuming glfw can withstand a few officedog characters and an officedog rectangle, all should be well. However we'll investigate angelfonts, just in case. Thanks for all these links, really helpful.
The direction is evolving as these posts go by. We've decided to go back to the drawing board, re-engineer the structs, wrap all functions and develop a programme which will bake the GUI. Shouldn't take more than a couple of days.
I am trying to build a screen manager now. It will detect which object the user clicked with the mouse and work out which function to call. I've returned to C_ntua's earlier post (page 1, no.14) on this. Just wondering whether I'm getting the ideas right.
Here's what I have so far:
Included in the struct for each GUI object is another struct called "objectScreenData". The purpose is to serve as a set of data for use by the screen manager - to check which object has been clicked on and know where to go to call the relevant function.
Here's the struct
Each time an object is drawn or redrawn, it sends a pointer to this information to the ScreenManager struct. Here's the screen manager:Code:typedef struct objectScreenData {
ScreenBounds objectBounds;
ScreenBounds resizeBounds;
ScreenBounds textBounds;
int type;
int tag;
char name[20];
void * address; //stores address of struct - key issue. Intend to put a cast on it with
// relevant struct when function is called.
}ObjectScreenData;
This is the add function for the screen manager:Code:typedef struct screenManager {
ObjectScreenData * objects[20];
int nObjects;
int selectedObject;
//Function pointers
void (*init)(struct screenManager *sm);
void (*destroy)(struct screenManager **sm);
int (*add)(struct screenManager *sm, ObjectScreenData *obj);
void (*checkWhichObject)(struct screenManager *sm, int x, int y);
int (*checkWhichFunction)(struct screenManager *sm, int x, int y);
void (*callFunction)(struct screenManager *sm, int tag);
}ScreenManager;
And this is the checkWhichObject function. Still work n progress - it's a bit of a building site at the moment, but just to give an idea of where it is (or isn't?) going.Code:int screenManagerAdd(ScreenManager *sm, ObjectScreenData *obj) {
if (sm->nObjects < 19) {
if ((obj->tag) < 0)
{
printf("\n\n+++ Adding %s to screen manager database", obj->name);
sm->objects[sm->nObjects] = obj;
sm->nObjects += 1;
obj->tag = sm->nObjects;
printf("\nObject added, tag = %d", obj->tag);
return sm->nObjects;
}
else{
printf("\nObject >>%s, ID = %d already registered", obj->name, obj->tag);
return obj->tag;
}
}
else{
printf("\nObject: %s could not be added to the Screen Manager", obj->name);
return -1;
}
}
Comments are very welcome. The general question is - am I on the right lines, are there any glaring errors in the way I'm doing this?Code:void screenManagerCheckWhichObject(ScreenManager *sm, int x, int y) {
for (int i = 0; i < sm->nObjects; i++) {
//get the objects screen boundaries
int minX = (sm->objects[i])->objectBounds.minX;
int minY = (sm->objects[i])->objectBounds.minY;
int maxX = (sm->objects[i])->objectBounds.maxX;
int maxY = (sm->objects[i])->objectBounds.maxY;
if ( x> minX && x < maxX && y > minY && y < maxY) {
sm->selectedObject = i;
printf("\nObject ID = %d, name = %s", i, (sm->objects[i])->name);
sm->checkWhichFunction(sm, x, y);
}
}
}