-
Notifications
You must be signed in to change notification settings - Fork 0
/
picview.c
executable file
·172 lines (147 loc) · 3.39 KB
/
picview.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
/* Sarien - A Sierra AGI resource interpreter engine
* Copyright (C) 1999-2001 Stuart George and Claudio Matsuoka
*
* $Id: picview.c,v 1.19 2002/11/12 11:28:41 cmatsuoka Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; see docs/COPYING for further details.
*/
#include <stdio.h>
#include <string.h>
#ifndef PALMOS
#include <ctype.h>
#endif
#include "sarien.h"
#ifdef OPT_PICTURE_VIEWER
#include "agi.h"
#include "graphics.h"
#include "keyboard.h"
#include "console.h"
#include "text.h"
static int picviewer_get_key ()
{
int key;
/* clear key queue */
while (keypress ()) { get_key (); }
_D (_D_WARN "waiting...");
while (42) {
poll_timer ();
key = do_poll_keyboard ();
if (key) break;
}
return key;
}
static void screen_dump ()
{
FILE *f;
f = fopen ("screen.raw", "wb");
fwrite (game.sbuf, _HEIGHT, _WIDTH, f);
fclose (f);
}
int view_pictures ()
{
int ec = err_OK;
char x[64];
int i, pic = 0, dir = 1;
game.line_min_print = 1;
for (i = 0; ec == err_OK; i = 1) {
while (game.dir_pic[pic].offset == _EMPTY) {
pic += dir;
if (pic < 0)
pic = MAX_DIRS - 1;
if (pic > MAX_DIRS - 1) {
pic = 0;
if (i == 0) { /* no pics? */
ec = 1;
fprintf (stderr, "No pictures found\n");
goto end_view;
}
}
}
_D ("picture = %d", pic);
if ((ec = agi_load_resource (rPICTURE, pic)) != err_OK) {
_D (_D_CRIT "Whoops. bad pic %d", pic);
ec = err_OK;
pic += dir;
goto next_pic;
}
print_text ("[drawing]", 0, 16, 0, strlen (x) + 1, 0, 15);
/* decodes the raw data to useable form */
decode_picture (pic, TRUE);
show_pic ();
put_screen ();
update_statusline:
#ifdef USE_HIRES
sprintf (x, "Picture:%3i Hi-res: %3s",
pic, opt.hires ? " on" : "off");
#else
sprintf (x, "Picture:%3i Hi-res: N/A", pic);
#endif
print_text (x, 0, 0, 0, strlen (x) + 1, 0, 15);
sprintf (x, "H:Hi-res P:Vis/Prio +:Next -:Prev");
print_text (x, 0, 0, 23, strlen (x) + 1, 15, 0);
sprintf (x, "R:Redraw D:Screen dump Q:Quit");
print_text (x, 0, 0, 24, strlen (x) + 1, 15, 0);
while (42) {
decode_picture (pic, TRUE);
switch (picviewer_get_key()) {
case 'q':
goto end_view;
#ifdef USE_HIRES
#ifdef USE_MOUSE
case BUTTON_RIGHT:
#endif
case 'h':
opt.hires = !opt.hires;
show_pic ();
put_screen ();
goto update_statusline;
#endif
case 'p':
debug.priority = !debug.priority;
show_pic ();
put_screen ();
break;
case 'd':
/*opt.showscreendraw = !opt.showscreendraw;*/
screen_dump();
goto update_statusline;
case 'r':
goto next_pic;
#ifdef USE_MOUSE
case BUTTON_LEFT:
if (mouse.x < GFX_WIDTH / 2)
goto previous_pic;
#endif
/* fall through */
case '+':
_D ("next pic");
if (pic < MAX_DIRS - 1)
pic++;
else
pic = 0;
dir = 1;
goto next_pic;
case '-':
previous_pic:
_D ("previous pic");
if (pic > 0)
pic--;
else
pic = MAX_DIRS - 1;
i = 0;
dir = -1;
goto next_pic;
}
}
next_pic:
agi_unload_resource (rPICTURE, pic);
}
end_view:
return ec;
}
#else
/* to make Watcom 7 happy */
void picview_stub(){}
#endif /* OPT_PICTURE_VIEWER */