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