home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / os2 / hpgl312.zip / TO_SUNVW.C < prev    next >
C/C++ Source or Header  |  1993-04-18  |  5KB  |  212 lines

  1. /*
  2.    Copyright (c) 1991, 1992 Heinz W. Werntges.  All rights reserved.
  3.    Distributed by Free Software Foundation, Inc.
  4.  
  5. This file is part of HP2xx.
  6.  
  7. HP2xx is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  9. to anyone for the consequences of using it or for whether it serves any
  10. particular purpose or works at all, unless he says so in writing.  Refer
  11. to the GNU General Public License, Version 2 or later, for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. HP2xx, but only under the conditions described in the GNU General Public
  15. License.  A copy of this license is supposed to have been
  16. given to you along with HP2xx so you can know your rights and
  17. responsibilities.  It should be in a file named COPYING.  Among other
  18. things, the copyright notice and this notice must be preserved on all
  19. copies.
  20.  
  21. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  22. */
  23.  
  24. /**
  25.  ** to_sunview.c: Sunview previewer for hp2xx
  26.  **
  27.  ** 92/01/28  V 1.00a HWW  Derived from project njm
  28.  ** 92/05/19  V 1.00b HWW  Abort if color mode
  29.  ** 92/05/25  V 1.10a HWW  Colors supported
  30.  ** 93/01/06  V 1.10b HWW  "xx" added in front of color names
  31.  **
  32.  ** NOTE:     Sunview itself is a dying standard (to be replaced by OpenLook
  33.  **           and/or X11). Therefore, I won't continue to maintain this file.
  34.  **           In hp2xx's next release this file will appear in ../extras.
  35.  **           Please use to_x11.c for future previewing on Suns.
  36.  **/
  37.  
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <suntool/sunview.h>
  41. #include <suntool/canvas.h>
  42. #include <suntool/alert.h>
  43. #include <ctype.h>
  44. #include "bresnham.h"
  45. #include "hp2xx.h"
  46.  
  47.  
  48. #define    CMS_SIZE    16
  49. #define    BLACK        0
  50. #define    GRAY        1
  51. #define    RED        2
  52. #define    GREEN        3
  53. #define    BLUE        4
  54. #define    CYAN        5
  55. #define    MAGENTA        6
  56. #define    YELLOW        7
  57. #define    LIGHTGRAY    8
  58. #define    LIGHTRED    10
  59. #define    LIGHTGREEN    11
  60. #define    LIGHTBLUE    12
  61. #define    LIGHTCYAN    13
  62. #define    LIGHTMAGENTA    14
  63. #define    WHITE        15
  64.  
  65. #define    DestX        320
  66. #define    DestY        30
  67.  
  68.  
  69. static Frame    frame;
  70. static Canvas    canvas;
  71.  
  72. static    Pixwin    *pw;
  73. static    int    my_op;
  74.  
  75.  
  76.  
  77.  
  78. void    setcolor (col)
  79. int    col;
  80. {
  81.   if (col == BLACK)
  82.     my_op = PIX_COLOR (col) | PIX_CLR;
  83.   else
  84.     my_op = PIX_COLOR (col) | (PIX_SRC ^ PIX_DST);
  85. }
  86.  
  87.  
  88. #if 0
  89. void    PointW (x0, y0, color)
  90. double x0, y0;
  91. int color;
  92. {
  93.   pw_put (pw, TransX (x0), TransY (y0), color);
  94. }
  95.  
  96.  
  97. void    FillBoxW ( x0,  y0,  x1,  y1)
  98. double x0, y0, x1, y1;
  99. {
  100. int    i0,i1, j0,j1;
  101.  
  102.   i0 = TransX (x0);    i1 = TransX (x1);
  103.   j0 = TransY (y0);    j1 = TransY (y1);
  104.   pw_rop (pw, i0,j1, i1-i0, j0-j1, my_op, NULL, 0, 0);
  105. }
  106. #endif
  107.  
  108.  
  109. void    Init_SunView (int xoff, int yoff, int width, int height)
  110. {
  111. char    st1 [100];
  112. Rect    r;
  113. u_char    red[CMS_SIZE], green[CMS_SIZE], blue[CMS_SIZE];
  114.  
  115.     sprintf ((char *) st1, "hp2xx Sunview previewer");
  116.     frame = window_create(NULL, FRAME,
  117.             WIN_X,        xoff,
  118.             WIN_Y,        yoff,
  119.             WIN_ERROR_MSG,    "Cannot create frame",
  120.             FRAME_LABEL,    st1,
  121.             0);
  122.  
  123.     canvas = window_create(frame, CANVAS,
  124.             WIN_WIDTH,    width,
  125.             WIN_HEIGHT,    height,
  126.             0);
  127.     pw = canvas_pixwin(canvas);
  128.     window_fit (frame);
  129.  
  130.     /* Init. color map    */
  131.  
  132.     red[BLACK] = 0;        green[BLACK] = 0;    blue[BLACK] = 0;
  133.     red[GRAY] = 100;    green[GRAY] = 100;    blue[GRAY] = 100;
  134.     red[RED] = 128;        green[RED] = 0;        blue[RED] = 0;
  135.     red[GREEN]= 0;        green[GREEN]= 128;    blue[GREEN]= 0;
  136.     red[BLUE] = 0;        green[BLUE] = 0;    blue[BLUE] = 128;
  137.     red[CYAN] = 0;        green[CYAN] = 128;    blue[CYAN] = 128;
  138.     red[MAGENTA] = 128;    green[MAGENTA] = 0;    blue[MAGENTA] = 128;
  139.     red[YELLOW] = 255;    green[YELLOW] = 255;    blue[YELLOW] = 0;
  140.     red[LIGHTGRAY] = 200;    green[LIGHTGRAY] = 200;    blue[LIGHTGRAY] = 200;
  141.     red[LIGHTRED] = 255;    green[LIGHTRED] = 0;    blue[LIGHTRED] = 0;
  142.     red[LIGHTGREEN]= 0;    green[LIGHTGREEN]= 255;    blue[LIGHTGREEN]= 0;
  143.     red[LIGHTBLUE] = 0;    green[LIGHTBLUE] = 0;    blue[LIGHTBLUE] = 255;
  144.     red[LIGHTCYAN] = 0;    green[LIGHTCYAN] = 255;    blue[LIGHTCYAN] = 255;
  145.     red[LIGHTMAGENTA]=255;    green[LIGHTMAGENTA]=0;    blue[LIGHTMAGENTA] = 255;
  146.     red[WHITE] = 255;    green[WHITE] = 255;    blue[WHITE] = 255;
  147.  
  148.     pw_setcmsname (pw, "MyColorMap");
  149.     pw_putcolormap(pw, 0, CMS_SIZE, red, green, blue);
  150.     pw_get_region_rect (pw,&r);
  151. }
  152.  
  153.  
  154.  
  155. #if 0
  156. int    user_alert (msg)
  157. char    *msg;
  158. {
  159. int    result;
  160.  
  161.   result = alert_prompt (frame, (Event *)NULL,
  162.         ALERT_MESSAGE_STRINGS, "ERROR: ", msg,
  163.         0,
  164.         ALERT_BUTTON_YES, "Please acknowledge",
  165.         0);
  166.   return (result);
  167. }
  168. #endif
  169.  
  170.  
  171.  
  172.  
  173. void    PicBuf_to_Sunview (PicBuf *picbuf, PAR *p)
  174. {
  175. int    row_c, byte_c, bit, x, xoff, y, yoff;
  176. RowBuf    *row;
  177.  
  178.  
  179.   xoff = p->xoff * p->dpi_x / 25.4;
  180.   yoff = p->yoff * p->dpi_y / 25.4;
  181.   if (!p->quiet)
  182.   {
  183.     fprintf(stderr,
  184.         "\nStarting preview. Use menu bar to quit!\n");
  185.   }
  186.   Init_SunView (xoff, yoff, picbuf->nc, picbuf->nr);
  187.   pw_writebackground (pw, 0, 0, picbuf->nc, picbuf->nr, PIX_CLR);
  188.   setcolor (WHITE);
  189.  
  190.   /* Backward since highest index is lowest line on screen! */
  191.   for (row_c=0, y=picbuf->nr-1; row_c < picbuf->nr; row_c++, y--)
  192.   {
  193.     row = get_RowBuf (picbuf, row_c);
  194.     for (x=0; x < picbuf->nc; x++)
  195.     {
  196.         switch (index_from_RowBuf(row, x, picbuf))
  197.         {
  198.         case xxBackground:break;
  199.         case xxForeground:pw_put (pw, x, y, WHITE);    break;
  200.         case xxRed:    pw_put (pw, x, y, LIGHTRED);    break;
  201.         case xxGreen:    pw_put (pw, x, y, LIGHTGREEN);    break;
  202.         case xxBlue:    pw_put (pw, x, y, LIGHTBLUE);    break;
  203.         case xxCyan:    pw_put (pw, x, y, LIGHTCYAN);    break;
  204.         case xxMagenta:    pw_put (pw, x, y, LIGHTMAGENTA);break;
  205.         case xxYellow:    pw_put (pw, x, y, YELLOW);    break;
  206.         }
  207.     }
  208.   }
  209.   window_main_loop (frame);
  210. }
  211.  
  212.