|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T b
Length: 5429 (0x1535) Types: TextFile Names: »boardsw.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/Sun/Mines/boardsw.c«
/* * handle the board subwindow * * 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 <sunwindow/win_cursor.h> #include <sys/resource.h> #include <sys/ioctl.h> #include <strings.h> #include "mines.h" /* * cross-hairs cursor */ static short CrosshairsImage[] = { #include "crosshairs.cursor" }; DEFINE_CURSOR_FROM_IMAGE(CrosshairsCursor, 8, 8, PIX_SRC^PIX_DST, CrosshairsImage); /* * square pixrects */ unsigned short WhiteSquareImage[] = { #include "whiteSquare.icon" }; mpr_static(WhiteSquarePR, 64, 64, 1, WhiteSquareImage); unsigned short BlackSquareImage[] = { #include "blackSquare.icon" }; mpr_static(BlackSquarePR, 64, 64, 1, BlackSquareImage); unsigned short PlayerSquareImage[] = { #include "playerSquare.icon" }; mpr_static(PlayerSquarePR, 64, 64, 1, PlayerSquareImage); unsigned short MineSquareImage[] = { #include "mineSquare.icon" }; mpr_static(MineSquarePR, 64, 64, 1, MineSquareImage); unsigned short SafeSquareImage[] = { #include "safeSquare.icon" }; mpr_static(SafeSquarePR, 64, 64, 1, SafeSquareImage); /* board subwindow handles */ struct toolsw * BoardSW; struct gfxsubwindow * Board; /* square sizes */ int SquareWidth = 32, SquareHeight = 32; /* icon offsets */ struct pr_pos IconOffset = { 32, 32 }; /* * board sigwinch handler */ /*ARGSUSED*/ boardSigwinch(sw) caddr_t sw; { gfxsw_interpretesigwinch(Board); gfxsw_handlesigwinch(Board); if (Board->gfx_flags & GFX_RESTART) { Board->gfx_flags &= ~ GFX_RESTART; DrawBoard(); } } /* * map a mouse coordinate to a board coordinate */ void mapMouseToBoard(mlocp, blocp) struct pr_pos * mlocp; BoardCoordinate * blocp; { blocp->x = mlocp->x / (SquareWidth-1); blocp->y = mlocp->y / (SquareHeight-1); } /* * map a board coordinate to a mouse coordinate */ void mapBoardToMouse(blocp, mlocp) BoardCoordinate * blocp; struct pr_pos * mlocp; { mlocp->x = blocp->x * (SquareWidth-1) - 1; mlocp->y = blocp->y * (SquareHeight-1) - 1; } /* * board select() handler */ /*ARGSUSED*/ boardSelected(nullsw, ibits, obits, ebits, timer) caddr_t * nullsw; int * ibits, * obits, * ebits; struct timeval ** timer; { struct inputevent ie; struct pr_pos mloc; BoardCoordinate bloc; /* * read the input event */ if (input_readevent(BoardSW->ts_windowfd, &ie) == -1) { perror("input failed"); abort(); } if (win_inputposevent(&ie)) { switch(ie.ie_code) { /* * if it is an attempt to move */ case MS_LEFT: mloc.x = ie.ie_locx; mloc.y = ie.ie_locy; mapMouseToBoard(&mloc, &bloc); DoMove(&bloc); break; /* * else if he is toggling a square's unsafe marking */ case MS_MIDDLE: mloc.x = ie.ie_locx; mloc.y = ie.ie_locy; mapMouseToBoard(&mloc, &bloc); MarkSquare(&bloc, FALSE); break; /* * else if he is toggling a square's safe marking */ case MS_RIGHT: mloc.x = ie.ie_locx; mloc.y = ie.ie_locy; mapMouseToBoard(&mloc, &bloc); MarkSquare(&bloc, TRUE); break; } } * ibits = * obits = * ebits = 0; } /* * initialize the board subwindow */ void InitBoardSW() { struct inputmask mask; register unsigned int i; /* * initialize the subwindow */ if ((BoardSW = gfxsw_createtoolsubwindow(MinesTool, "", TOOL_SWEXTENDTOEDGE, /* playing surface + victim area */ (SquareHeight-1) * SIDE_SIZE, NULL)) == NULL) { fprintf(stderr, "Can't create board subwindow\n"); exit(1); } Board = (struct gfxsubwindow *) BoardSW->ts_data; gfxsw_getretained(Board); BoardSW->ts_io.tio_handlesigwinch = boardSigwinch; BoardSW->ts_io.tio_selected = boardSelected; input_imnull(&mask); win_setinputcodebit(&mask, MS_LEFT); win_setinputcodebit(&mask, MS_MIDDLE); win_setinputcodebit(&mask, MS_RIGHT); win_setinputcodebit(&mask, LOC_MOVEWHILEBUTDOWN); win_setinputcodebit(&mask, LOC_WINEXIT); mask.im_flags |= IM_NEGEVENT; win_setinputmask(BoardSW->ts_windowfd, &mask, NULL, WIN_NULLLINK); win_setcursor(BoardSW->ts_windowfd, &CrosshairsCursor); } /* * draw a square */ void DrawSquare(bloc) BoardCoordinate * bloc; { struct pr_pos mloc; struct pixrect * pr; Square * sqp = GetSquare(bloc); /* determine which pixrect to paint the square with */ if (sqp->occupied) pr = &PlayerSquarePR; else if (sqp->traversed) pr = &BlackSquarePR; else if ( ! GameOver && sqp->unsafe || GameOver && sqp->mined) pr = &MineSquarePR; else if ( ! GameOver && sqp->safe) pr = &SafeSquarePR; else pr = &WhiteSquarePR; /* paint the square */ mapBoardToMouse(bloc, &mloc); pw_rop(Board->gfx_pixwin, mloc.x, mloc.y, SquareWidth, SquareHeight, PIX_SRC, pr, IconOffset.x, IconOffset.y); } /* * draw the playing surface and victim area */ void DrawBoard() { BoardCoordinate bloc; /* clear the board area */ pw_rop(Board->gfx_pixwin, 0, 0, Board->gfx_rect.r_width, Board->gfx_rect.r_height, PIX_CLR, (struct pixrect *) 0, 0, 0); /* draw the playing area */ for (bloc.x = 0 ; bloc.x < SIDE_SIZE ; bloc.x++) { for (bloc.y = 0 ; bloc.y < SIDE_SIZE ; bloc.y++) { DrawSquare(&bloc); } } }