gui design

E

Edward Gregor

Hi! I hope this is the right place to post,
I considered posting it to comp.programming, but I think
my question is very C specific. But if this is the wrong
place just tell me. thanks!

Im making my own gui, and this is the structure for a window so far:

typedef struct window {
int handle;

int x, y;
int width, height;

char *caption;
short style;

widget *widgets;

int (*proc) (int handle, event *e);

/* prev is above, next is below */
struct window *prev, *next;
} window;

Now to handle drawing, I want to have different backends, for example
curses or SDL. For each of these I have a source file, i.e curses.c and
sdl.c
These files contain specific drawing routines, and these need access to
the window structs for each window. In the curses case, I need to have a
WINDOW struct associated with each window struct, which has the same size
and dimensions, so in order to map these windows, I've made another
mapping struct like:

static struct window_mapping {
window *window;
WINDOW *curses;
#ifdef USE_SHADOW
WINDOW *shadow;
#endif
struct window_mapping *next;
} *wmap_head = NULL;

My first question is: does this seem to be a reasonable design solution?
To have a mapping struct like this, or is there some other solution
that you consider is much better?

And the second question is: If I use this design, which is the best
type of parameter to pass to functions like like draw_window(),
hide_window() in curses.c?

I can think of three ways,
1. They will be passed a window struct, and then extract the curses WINDOW
from each function.
2. They will be passed both a window and a curses WINDOW struct.
3. The mapping struct window_mapping will be passed as an argument, and
the appropiate values can be extracted.

I think 3 seems best, maybe. It seems like it will be easier to add support
for more values of the struct that may be needed. 2 seems bad since I
need to
change each function argument list if I add more stuff.

Thanks

/Edward
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top