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