home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / wm_demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-25  |  3.4 KB  |  156 lines

  1. /* wm_demo.c (emx+gcc) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <sys/winmgr.h>
  7.  
  8. #define FALSE 0
  9. #define TRUE  1
  10.  
  11. static wm_handle w1;
  12. static wm_handle w2;
  13. static wm_handle w3;
  14. static int bw;
  15.  
  16.  
  17. static void demo_1 (void)
  18. {
  19.   int i, x, y;
  20.  
  21.   x = 0; y = 0;
  22.   w1 = wm_create (x, y, x+22, y+2, 2,
  23.                   bw ? BW_NORMAL : F_RED|B_BLACK,
  24.                   bw ? BW_NORMAL : F_GREEN|B_BLACK);
  25.   if (w1 != NULL)
  26.     {
  27.       wm_puts_at (w1, 2, 1, "Window manager demo");
  28.       wm_open (w1);
  29.       for (i = 0; i < 10; ++i)
  30.         {
  31.           _sleep2 (60);
  32.           x += 2; y += 1;
  33.           wm_move (w1, x, y);
  34.         }
  35.       sleep (2);
  36.     }
  37. }
  38.  
  39.  
  40. static void demo_2 (void)
  41. {
  42.   int i, j, x, y, sd[2];
  43.   int a1, a2, a3, a4;
  44.   char *title = " A Window Title! ";
  45.   char tmp[100];
  46.   char *backgnd = "B a c k g r o u n d - ";
  47.  
  48.   x = 8; y = 1;
  49.   if (bw)
  50.     {
  51.       a1 = BW_NORMAL;
  52.       a2 = BW_REVERSE;
  53.       a3 = BW_NORMAL|INTENSITY;
  54.       a4 = BW_REVERSE;
  55.     }
  56.   else 
  57.     {
  58.       a1 = F_WHITE|INTENSITY|B_BLUE;
  59.       a2 = F_YELLOW|INTENSITY|B_RED;
  60.       a3 = F_RED|INTENSITY|B_BLUE;
  61.       a4 = F_WHITE|INTENSITY|B_GREEN;
  62.     }
  63.   w2 = wm_create (x, y, x+25, y+9, 1, a1, a1);
  64.   if (w2 != NULL)
  65.     {
  66.       wm_down (w2);
  67.       wm_open (w2);
  68.       for (i = 0; i < 22; ++i)
  69.         {
  70.           _sleep2 (100);
  71.           if (i < 11)
  72.             x += 2;
  73.           else
  74.             y += 1;
  75.           wm_move (w2, x, y);
  76.           wm_gotoxy (w1, 9, 0);
  77.           wm_printf (w1, "(%d,%d)", x, y);
  78.           wm_gotoxy (w2, 0, 0);
  79.           wm_printf (w2, "(%d,%d)", x, y);
  80.         }
  81.       wm_clr_eol (w1, 9, 0);
  82.       for (i = 1; i <= 200; ++i)
  83.         wm_printf (w2, "Window manager demo %-4d ", i);
  84.       for (i = 0; i < 8; ++i)
  85.         {
  86.           wm_attrib_all (w2, a2);
  87.           _sleep2 (150);
  88.           wm_attrib_all (w2, a1);
  89.           _sleep2 (150);
  90.           if (i == 4)
  91.             wm_top (w2);
  92.         }
  93.       j = strlen (title);
  94.       for (i = 0; i <= j; ++i)
  95.         {
  96.           memcpy (tmp, title, i);
  97.           tmp[i] = 0;
  98.           wm_border (w2, 1, a1, tmp, 1, a3);
  99.           _sleep2 (80);
  100.         }
  101.       wm_clear (w2);
  102.       wm_gotoxy (w2, 4, 1); wm_puts (w2, "Title with");
  103.       wm_getxy (w2, &x, &y);
  104.       wm_gotoxy (w2, 4, 2); wm_puts (w2, "vertical bars\n");
  105.       sleep (2);
  106.       wm_border (w2, 1, a1, title, 0, a3);
  107.       wm_attrib (w2, a2);
  108.       wm_puts_at (w2, x, y, "out");
  109.       wm_attrib (w2, a1);
  110.       sleep (2);
  111.       _scrsize (sd);
  112.       x = sd[0]; y = sd[1];
  113.       w3 = wm_create (0, 0, x-1, y-1, 0, 0, a4);
  114.       if (w3 != NULL)
  115.         {
  116.           wm_bottom (w3);
  117.           for (i = 0; i < (x*y)/strlen (backgnd); ++i)
  118.             wm_puts (w3, backgnd);
  119.           wm_putc (w3, ' ');
  120.           wm_open (w3);
  121.           sleep (1);
  122.           wm_attrib (w3, BW_NORMAL);
  123.           wm_clear (w3);
  124.           sleep (1);
  125.           wm_close (w3);
  126.           sleep (1);
  127.         }
  128.     }
  129. }
  130.  
  131.  
  132. int main (int argc, char *argv[])
  133. {
  134.   int i;
  135.  
  136.   bw = FALSE;
  137.   for (i = 1; i < argc; ++i)
  138.     if (strcmp (argv[i], "-b") == 0)
  139.       bw = TRUE;
  140.     else
  141.       {
  142.         fprintf (stderr, "Usage: wm_demo [-b]\n");
  143.         return (1);
  144.       }
  145.   if (!wm_init (20))
  146.     {
  147.       fprintf (stderr, "wm_demo: wm_init() failed\n");
  148.       return (1);
  149.     }
  150.   demo_1 ();
  151.   demo_2 ();
  152.   wm_close_all ();
  153.   wm_exit ();
  154.   return (0);
  155. }
  156.