1 /*
2 * xvinfo.c - 'Info' box handling functions
3 *
4 * callable functions:
5 *
6 * CreateInfo(geom) - creates the infoW window. Doesn't map it.
7 * InfoBox(vis) - random processing based on value of 'vis'
8 * maps/unmaps window, etc.
9 * RedrawInfo(x,y,w,h) - called by 'expose' events
10 * SetInfoMode(mode) - changes amount of info Info window shows
11 * SetISTR(st, fmt, args) - sprintf's into ISTR #st. Redraws it in window
12 * char *GetISTR(st) - returns pointer to ISTR #st, or NULL if st bogus
13 */
14
15 #include "copyright.h"
16
17 #define NEEDSARGS
18
19 #include "xv.h"
20
21 #include "bits/penn"
22 #include "bits/pennnet"
23
24
25 #define INFOWIDE 500 /* (fixed) size of info window */
26 #define INFOHIGH 270
27
28 /* max length of an Info String */
29 #define ISTRLEN 256
30
31 /* baseline of top line of text */
32 #define TOPBASE (36 + penn_height/2 + 4 + 8 + ASCENT)
33 #define STLEFT 100 /* left edge of strings */
34
35 static Pixmap pnetPix, pennPix;
36 static char istrs[NISTR][ISTRLEN];
37
38 static void drawStrings PARM((void));
39 static void drawFieldName PARM((int));
40 static void redrawString PARM((int));
41
42
43
44 /***************************************************/
CreateInfo(geom)45 void CreateInfo(geom)
46 const char *geom;
47 {
48 infoW = CreateWindow("xv info", "XVinfo", geom, INFOWIDE, INFOHIGH,
49 infofg, infobg, 0);
50 if (!infoW) FatalError("can't create info window!");
51
52 pennPix = XCreatePixmapFromBitmapData(theDisp, infoW,
53 (char *) penn_bits, penn_width, penn_height, infofg, infobg, dispDEEP);
54
55 pnetPix = XCreatePixmapFromBitmapData(theDisp,infoW,
56 (char *) pennnet_bits, pennnet_width, pennnet_height,
57 infofg, infobg, dispDEEP);
58 }
59
60
61 /***************************************************/
InfoBox(vis)62 void InfoBox(vis)
63 int vis;
64 {
65 if (vis) XMapRaised(theDisp, infoW);
66 else XUnmapWindow(theDisp, infoW);
67
68 infoUp = vis;
69 }
70
71
72 /***************************************************/
RedrawInfo(x,y,w,h)73 void RedrawInfo(x,y,w,h)
74 int x,y,w,h;
75 {
76 int i;
77
78 XSetForeground(theDisp, theGC, infofg);
79 XSetBackground(theDisp, theGC, infobg);
80
81 /* draw the two icons */
82 XCopyArea(theDisp, pennPix, infoW, theGC, 0, 0, penn_width, penn_height,
83 36 - penn_width/2, 36 - penn_height/2);
84 XCopyArea(theDisp, pnetPix, infoW, theGC, 0, 0, pennnet_width,
85 pennnet_height, INFOWIDE - 36 - pennnet_width/2,
86 36 - pennnet_height/2);
87
88 /* draw the credits */
89 snprintf(dummystr, sizeof(dummystr), "XV - %s", REVDATE);
90 CenterString(infoW, INFOWIDE/2, 36-LINEHIGH, dummystr);
91 CenterString(infoW, INFOWIDE/2, 36,
92 "by John Bradley (bradley@dccs.upenn.edu)");
93 CenterString(infoW, INFOWIDE/2, 36+LINEHIGH,
94 "Copyright 1994, John Bradley - All Rights Reserved");
95
96
97 /* draw the dividing lines */
98 i = 36 + penn_height/2 + 4;
99
100 XDrawLine(theDisp, infoW, theGC, 0, i, INFOWIDE, i);
101 XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-22, INFOWIDE, INFOHIGH-22);
102 XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-42, INFOWIDE, INFOHIGH-42);
103
104 if (ctrlColor) {
105 XSetForeground(theDisp, theGC, locol);
106 XDrawLine(theDisp, infoW, theGC, 0, i+1, INFOWIDE, i+1);
107 XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-21, INFOWIDE, INFOHIGH-21);
108 XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-41, INFOWIDE, INFOHIGH-41);
109 }
110
111 if (ctrlColor) XSetForeground(theDisp, theGC, hicol);
112 XDrawLine(theDisp, infoW, theGC, 0, i+2, INFOWIDE, i+2);
113 XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-20, INFOWIDE, INFOHIGH-20);
114 XDrawLine(theDisp, infoW, theGC, 0, INFOHIGH-40, INFOWIDE, INFOHIGH-40);
115
116 drawStrings();
117 }
118
119
120 /***************************************************/
drawStrings()121 static void drawStrings()
122 {
123 int i;
124 for (i=0; i<7; i++) drawFieldName(i); /* draw the field titles */
125 for (i=0; i<NISTR; i++) redrawString(i); /* draw the field values */
126 XFlush(theDisp);
127 }
128
129
130 /***************************************************/
drawFieldName(fnum)131 static void drawFieldName(fnum)
132 int fnum;
133 {
134 static const char *fname[7] = { "Filename:", "Format:", "Resolution:",
135 "Cropping:", "Expansion:", "Selection:", "Colors:" };
136
137 XSetForeground(theDisp, theGC, infofg);
138 XSetBackground(theDisp, theGC, infobg);
139
140 if (infoMode == INF_NONE || infoMode == INF_STR) return;
141 if (infoMode == INF_PART && fnum>=3) return;
142
143 XDrawString(theDisp, infoW, theGC, 10, TOPBASE + fnum*LINEHIGH,
144 fname[fnum], (int) strlen(fname[fnum]));
145 }
146
147
148 /***************************************************/
redrawString(st)149 static void redrawString(st)
150 int st;
151 {
152 /* erase area of string, and draw it with new contents */
153
154 if (infoMode == INF_NONE) return;
155 if (infoMode == INF_STR && st > ISTR_WARNING) return;
156 if (infoMode == INF_PART && st > ISTR_RES) return;
157
158
159 if (st == ISTR_INFO) {
160 XSetForeground(theDisp, theGC, infobg);
161 XFillRectangle(theDisp, infoW, theGC, 0, INFOHIGH-39, INFOWIDE, 17);
162 XSetForeground(theDisp, theGC, infofg);
163 CenterString(infoW, INFOWIDE/2, INFOHIGH-31, istrs[st]);
164 }
165 else if (st == ISTR_WARNING) {
166 XSetForeground(theDisp, theGC, infobg);
167 XFillRectangle(theDisp, infoW, theGC, 0, INFOHIGH-19, INFOWIDE, 17);
168 XSetForeground(theDisp, theGC, infofg);
169 CenterString(infoW, INFOWIDE/2, INFOHIGH-10, istrs[st]);
170 }
171 else {
172 XSetForeground(theDisp, theGC, infobg);
173 XFillRectangle(theDisp, infoW, theGC,
174 STLEFT, TOPBASE - ASCENT + (st-ISTR_FILENAME)*LINEHIGH,
175 (u_int) INFOWIDE-STLEFT, (u_int) LINEHIGH);
176 XSetForeground(theDisp, theGC, infofg);
177 XDrawString(theDisp, infoW, theGC, STLEFT,
178 TOPBASE + (st-ISTR_FILENAME)*LINEHIGH, istrs[st],
179 (int) strlen(istrs[st]));
180 }
181 }
182
183
184
185 /***************************************************/
SetInfoMode(mode)186 void SetInfoMode(mode)
187 int mode;
188 {
189 int y1, y2;
190
191 infoMode = mode;
192 if (infoUp) { /* only do this if window is mapped */
193 y1 = TOPBASE - ASCENT;
194 y2 = INFOHIGH-43;
195
196 XSetForeground(theDisp, theGC, infobg);
197
198 XFillRectangle(theDisp,infoW,theGC,0,y1,
199 (u_int) INFOWIDE, (u_int) y2-y1);
200 XFillRectangle(theDisp,infoW,theGC,0,INFOHIGH-39,
201 (u_int) INFOWIDE, (u_int) 17);
202 XFillRectangle(theDisp,infoW,theGC,0,INFOHIGH-19,
203 (u_int) INFOWIDE, (u_int) 17);
204
205 drawStrings();
206 }
207 }
208
209
210 /***************************************************/
211 /* SetISTR( ISTR, format, arg1, arg2, ...) */
212
213 #if defined(__STDC__) && !defined(NOSTDHDRS)
SetISTR(int stnum,...)214 void SetISTR(int stnum, ...)
215 {
216 va_list args;
217 char *fmt;
218
219 va_start(args, stnum);
220 #else
221 /*VARARGS0*/
222 void SetISTR(va_alist)
223 va_dcl
224 {
225 va_list args;
226 char *fmt;
227 int stnum;
228
229 va_start(args);
230
231 stnum = va_arg(args, int);
232 #endif
233
234 if (stnum>=0 && stnum < NISTR) {
235 fmt = va_arg(args, char *);
236 if (fmt) vsnprintf(istrs[stnum], sizeof(istrs[stnum]), fmt, args);
237 else istrs[stnum][0] = '\0';
238 }
239 va_end(args);
240
241 if (stnum == ISTR_COLOR) {
242 snprintf(istrs[ISTR_INFO], sizeof(istrs[ISTR_INFO]), "%s %s %s",
243 formatStr, (picType==PIC8) ? "8-bit mode." : "24-bit mode.",
244 istrs[ISTR_COLOR]);
245 }
246
247 if (infoUp) {
248 redrawString(stnum);
249 if (stnum == ISTR_COLOR) redrawString(ISTR_INFO);
250 XFlush(theDisp);
251 }
252
253 if (ctrlUp && (stnum == ISTR_INFO || stnum == ISTR_WARNING ||
254 stnum == ISTR_COLOR)) {
255 DrawCtrlStr();
256 XFlush(theDisp);
257 }
258
259 if (anyBrowUp && (stnum == ISTR_WARNING || stnum == ISTR_INFO)
260 && strlen(istrs[stnum])) {
261 SetBrowStr(istrs[stnum]);
262 XFlush(theDisp);
263 }
264
265 if (stnum == ISTR_WARNING && !ctrlUp && !infoUp && !anyBrowUp &&
266 strlen(istrs[stnum])) {
267 OpenAlert(istrs[stnum]);
268 sleep(1); /* was 3, but _really_ slow for TIFFs with unknown tags... */
269 CloseAlert();
270 }
271 }
272
273
274 /***************************************************/
275 char *GetISTR(stnum)
276 int stnum;
277 {
278 /* returns pointer to ISTR string */
279 if (stnum < 0 || stnum>=NISTR) return(NULL);
280 return (istrs[stnum]);
281 }
282
283
284