home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qube / win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-07  |  1.9 KB  |  100 lines

  1. /***
  2. ****  QuBE --- Windowing routines for graphics display, if possible.
  3. ****
  4. ****  Definitely needs work; better support of, well, everything.
  5. ***/
  6.  
  7. #include "qube.h"
  8.  
  9. #ifdef QUBE_MSDOS
  10. #include "svgagrph.h"
  11. #include "svgamous.h"
  12. #include "f14nsans.h"
  13. #include "keyboard.h"
  14. #endif
  15. #ifdef QUBE_UNIX
  16. #include "xgfx.h"
  17. #endif
  18.  
  19. struct WinTag {
  20.     struct WinTag *child, *parent;
  21.     int x, y, width, height;
  22.     void (*doevent)(int event, int window);
  23.     int windnum;
  24. };
  25. typedef struct WinTag Win;
  26.  
  27. void InitWindow(void);
  28. int OpenWindow(int x, y, width, height, void (*doevent)(int event, int window));
  29. int CloseWindow(int window);
  30. void WindPaint(int color, int window);
  31. void TotalRepaint(void);
  32.  
  33. static void RootUpdate(int event, int window);
  34.  
  35. Win RootWin = { NULL, NULL, 0, 0, 640, 480, RootUpdate, 0 };
  36. Win *LastWin = &RootWin;
  37.  
  38. static Win *hashtable[128];
  39.  
  40. static void RootUpdate(int event, int window)
  41. {
  42. }
  43.  
  44. void InitWindow(void)
  45. {
  46.     int i;
  47.  
  48.     for (i = 0; i < 128; i++)
  49.         hashtable[i] = NULL;
  50.  
  51.     hashtable[0] = &RootWin;
  52.  
  53.     Repaint(0, 0, 639, 479);
  54. }
  55.  
  56. int OpenWindow(int x, y, width, height, void (*doevent)(int event, int window))
  57. {
  58.     int w, wp;
  59.  
  60.     for (w = 0; w < 128 && hashtable[w] == NULL; w++);
  61.  
  62.     hashtable[w] = wp = Qmalloc(sizeof(Win));
  63.  
  64.     wp->x = x;
  65.     wp->y = y;
  66.     wp->width = width;
  67.         wp->height = height;
  68.     wp->doevent = doevent;
  69.     wp->parent = LastWin;
  70.     LastWin->child = wp;
  71.         LastWin = wp;
  72.     wp->child = NULL;
  73.  
  74.     Repaint(x, y, x+width-1, y+height-1);
  75.  
  76.     return(w);
  77. }
  78.  
  79. int CloseWindow(int window)
  80. {
  81.     Win *wp = hashtable[window];
  82.  
  83.     hashtable[window] = NULL;
  84.     wp->parent->child = wp->child;
  85.     if (wp->child != NULL)
  86.         wp->child->parent = wp->parent;
  87.     else
  88.         LastWin = wp->parent;
  89.  
  90.     Repaint(wp->x, wp->y, wp->x + wp->width - 1, wp->y + wp->height - 1);
  91.  
  92.     Qfree(wp);
  93. }
  94.  
  95. void Repaint(int x1, y1, x2, y2)
  96. {
  97.     Area *canvas = MakeUnion(&RootWindow, x1, y1, x2, y2);
  98.  
  99. }
  100.