gui design



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
.



Relevant Pages

  • Re: gui design
    ... and this is the structure for a window so far: ... int handle; ... struct window *prev, *next; ... curses or SDL. ...
    (comp.unix.programmer)
  • GUI design
    ... and this is the structure for a window so far: ... int handle; ... struct window *prev, *next; ... curses or SDL. ...
    (comp.programming)
  • gui design
    ... and this is the structure for a window so far: ... int handle; ... struct window *prev, *next; ... curses or SDL. ...
    (comp.unix.programmer)
  • Re: Using record extension for keylogging
    ... In my OpenNexX window system but has worked ... not capable of reading the input for a specific client. ... The server-side window struct is like this: ... unsigned int flags; ...
    (comp.windows.x)
  • [RFC PATCH 4/5] hvc_console: Add tty window resizing
    ... window dimensions (struct winsize) for a specified hvc console. ... The function stores the new window size and schedules a function ...
    (Linux-Kernel)