home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume2
/
mines.shr
/
tool.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-11-20
|
3KB
|
117 lines
/*
* handle the tool environment
*
* Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
* Stanwood, WA 98282. All rights reserved.
*/
static char copyright[] = "Copyright 1987 Tom Anderson";
#include <stdio.h>
#include <suntool/tool_hs.h>
#include <suntool/panel.h>
#include <suntool/gfxsw.h>
#include <sys/resource.h>
#include <sys/ioctl.h>
#include <strings.h>
#include "mines.h"
struct tool * MinesTool;
char ** ToolAttrs = (char **) NULL;
char * ToolName;
/*
* iconic form of window
*/
unsigned short IconImage[] = {
#include "mines.icon"
};
DEFINE_ICON_FROM_IMAGE(WindowIcon, IconImage);
sigwinched()
{
tool_sigwinch(MinesTool);
}
/*
* parse the tool args.
*/
void
ParseToolArgs(argc, argv)
int *argc;
char **argv;
{
ToolName = argv[0];
(*argc)--;
argv++;
if (tool_parse_all(argc, argv, &ToolAttrs, ToolName) == -1) {
tool_usage(ToolName);
exit(1);
}
(*argc)++;
}
/*
* set up the tool environment
*/
void
InitTool()
{
register unsigned int height;
register struct toolsw * twsp;
if ((MinesTool = tool_make(
WIN_LABEL, ToolName,
WIN_ICON, &WindowIcon,
WIN_ATTR_LIST, ToolAttrs,
WIN_WIDTH, SIDE_SIZE * (SquareWidth-1) + 2 * tool_borderwidth(MinesTool) - 1,
/*
* NOTE: The following line was unnecessary in Sun release 2.2,
* but is necessary in release 3.0. For some unknown reason, the
* call to tool_set_attributes following the call to InitBoardSW
* now fails to uncover the board area that was obscured by the
* default tool height being too small (note that the tool has not
* been installed yet).
*/
WIN_HEIGHT, 2000,
0)) == (struct tool *) NULL)
{
fputs("Can't make tool\n", stderr);
exit(1);
}
tool_free_attribute_list(ToolAttrs);
/* initialize the subwindows */
InitLevelSW();
InitMsgSW();
InitBoardSW();
/*
* add up subwindow heights and force the tool to the resulting size
*/
height = tool_stripeheight(MinesTool) + tool_borderwidth(MinesTool) - tool_subwindowspacing(MinesTool);
for (twsp = MinesTool->tl_sw ; twsp != (struct toolsw *) 0 ; twsp = twsp->ts_next)
height += twsp->ts_height + tool_subwindowspacing(MinesTool);
/*
* NOTE: under 2.2, the above calculation yielded the correct height.
* under 3.0, we need to add a few pixels to make it come out right (the
* reason is not yet known).
*/
height += 2;
tool_set_attributes(MinesTool, WIN_HEIGHT, height, 0);
signal(SIGWINCH, sigwinched);
}
void
RunTool()
{
/*
* NOTE: this is another difference between release 2.2 and 3.0:
* in release 2.2, the SIGWINCH handler would get called once at the
* outset to draw the board area; in release 3.0, this doesn't happen.
*/
DrawBoard();
tool_select(MinesTool, 0);
tool_destroy(MinesTool);
}