[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
GL3.2 for AIX: Graphics Library (GL) Technical Reference

vlsi.c Example C Language Program

/*
vlsi.c
A simple vlsi graphical editor.  RIGHTMOUSE clears the screen.
LEFTMOUSE picks the current color from one of 4 in the bottom
left-hand corner, and draws the rectangles.  To draw, hold down
LEFTMOUSE on the point where you want one of the four
corners of the rectangle to be, and then move the mouse to the
opposite corner of the rectangle you want to specify, BEFORE you
let go of the LEFTMOUSE.
*/
#include <gl/gl.h>
#include <gl/device.h>
main()
{
  register i;
  Device dummy, xend, yend, xstart, ystart, type;
  short wm;
  prefposition(0, XMAXSCREEN-50, 0, YMAXSCREEN-50);
  winopen("vlsi");
  save_cmap();
  mapcolor(0, 255, 255, 255);    /* WHITE */
  mapcolor(1, 0, 0, 255);        /* BLUE */
  mapcolor(2, 0, 255, 0);        /* RED */
  mapcolor(3, 0, 150, 255);      /* PURPLE */
  mapcolor(4, 255, 0, 0);        /* GREEN */
  mapcolor(5, 150, 0, 255);      /* LIGHT BLUE */
  mapcolor(6, 255, 255, 0);      /* YELLOW */
  mapcolor(7, 150, 100, 0);      /* BROWN */
  for (i = 8; i < 24; i++)
    mapcolor(i, 0, 0, 0);        /* BLACK */
  for (i = 24; i < 32; i++)
    mapcolor(i, 255, 255, 255);  /* WHITE */
  qdevice(LEFTMOUSE);
  tie(LEFTMOUSE, MOUSEX, MOUSEY);
  qdevice(MIDDLEMOUSE);
  tie(MIDDLEMOUSE, MOUSEX, MOUSEY);
  qdevice(RIGHTMOUSE);
  qdevice(KEYBD);
  setcursor(0, 16, 16);
  restart();
  while (TRUE)
    switch (type = qread(&dummy)) {
    case KEYBD:
      restore_cmap();
      greset();
      gexit();
      exit(0);
    case RIGHTMOUSE:
      qread(&dummy);
      restart();
      break;
    case MIDDLEMOUSE:
    case LEFTMOUSE:
      qread(&xstart);
      qread(&ystart);
      if (xstart < 60) {
        if (10 <= xstart && xstart <= 50) {
          if (10 <= ystart && ystart <= 50)
            wm = 1;
          else if (60 <= ystart && ystart <= 100)
            wm = 2;
          else if (110 <= ystart && ystart <= 150)
            wm = 4;
          else if (160 <= ystart && ystart <= 200)
            wm = 8;
          writemask(wm);
          qread(&dummy);
          qread(&dummy);
          qread(&dummy);
        }
      }
      else {
        qread(&dummy);
        qread(&xend);
        qread(&yend);
        if (xend > 60) {
          if (type == LEFTMOUSE)
            color(31);           /* draw */
          else
            color(0);            /* erase */
          rectfi(xstart, ystart, xend, yend);
        }
      }
    }
}
restart()
{
  writemask(0xfff);
  color(0);
  clear();
  color(1);
  rectfi(10, 10, 50, 50);
  color(2);
  rectfi(10, 60, 50, 100);
  color(4);
  rectfi(10, 110, 50, 150);
  color(8);
  rectfi(10, 160, 50, 200);
  move2i(60, 0);
  draw2i(60, 767);
  color(31);
  writemask(0);
}
/*This saves the colormap*/
#define lo_end 0
#define hi_end 255
short *CarrayR, *CarrayG, *CarrayB;
save_cmap()
{
  CarrayR = calloc (lo_end+hi_end,sizeof(short));
  CarrayG = calloc (lo_end+hi_end,sizeof(short));
  CarrayB = calloc (lo_end+hi_end,sizeof(short));
  getmcolors ((Int16 const)lo_end,(Int16 const)hi_end,
     CarrayR, CarrayG, CarrayB);
}
/*This restores the colormap*/
restore_cmap()
{
  mapcolors ((Int16 const)lo_end,(Int16 const)hi_end,
     CarrayR, CarrayG, CarrayB);
}
/*
  Changes:
    -  Added the restoring of the colormap
*/

Related Information

The greset subroutine , tie subroutine , writemask subroutine .


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]