home *** CD-ROM | disk | FTP | other *** search
- /*LINTLIBRARY*/
-
- /* @(#)items.c 1.20 91/11/13
- *
- * Procedures for manipulating the reve game panel items.
- *
- * Copyright (C) 1990, 1991 - Rich Burridge & Yves Gallot.
- * All rights reserved.
- *
- * Permission is granted to copy this source, for redistribution
- * in source form only, provided the news headers in "substantially
- * unaltered format" are retained, the introductory messages are not
- * removed, and no monies are exchanged.
- *
- * Permission is also granted to copy this source, without the
- * news headers, for the purposes of making an executable copy by
- * means of compilation, provided that such copy will not be used
- * for the purposes of competition in any othello tournaments, without
- * prior permission from the authors.
- *
- * No responsibility is taken for any errors on inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file), then an attempt will be made to fix them.
- */
-
- #include "reve.h"
- #include "color.h"
- #include "extern.h"
-
-
- void
- draw_button(wtype, item, color, image) /* Draw a panel button. */
- enum win_type wtype ;
- enum panel_type item ;
- int color ;
- enum image_type image ;
- {
- char *label ;
- int x, y ;
-
- if (gtype == GXVIEW) return ;
- x = items[(int) item].x ;
- y = items[(int) item].y ;
- if (x == -1 && y == -1) return ;
- if (iscolor)
- {
- draw_stencil(wtype, x, y, BWIDTH, BHEIGHT, RSRC, color,
- BUT_STENCIL, BUT_STENCIL) ;
- draw_image(wtype, x, y, BWIDTH, BHEIGHT, image) ;
- }
- else draw_stencil(wtype, x, y, BWIDTH, BHEIGHT, RSRC, C_WHITE,
- BUT_STENCIL, image) ;
- label = items[(int) item].text ;
- if (image == BUT_INVERT) color = C_WHITE ;
- else color = C_TEXT ;
- x += ((BWIDTH - get_strwidth(NFONT, label)) / 2) ;
- y += (font_heights[(int) NFONT] +
- (BHEIGHT - font_heights[(int) NFONT]) / 2) - 5 ;
- draw_text(wtype, x, y, NFONT, color, label) ;
- }
-
-
- void
- draw_choice(wtype, item, color)
- enum win_type wtype ;
- enum panel_type item ;
- int color ;
- {
- char *str ;
- int height, i, maxw, tcol, val, width, x, xoff, y ;
-
- if (gtype == GXVIEW) return ;
- tcol = B_COLOR(C_TEXT) ;
- if (strlen(items[(int) item].label))
- draw_text(items[(int) item].wtype,
- items[(int) item].lx,
- items[(int) item].ly + font_heights[(int) BFONT],
- BFONT, tcol, items[(int) item].label) ;
-
- maxw = 0 ;
- for (i = 0; i < items[(int) item].nopts; i++)
- {
- str = items[(int) item].options[i] ;
- if ((val = get_strwidth(NFONT, str)) > maxw) maxw = val ;
- }
-
- maxw += CHOICEGAP ;
- x = items[(int) item].x ;
- y = items[(int) item].y ;
- height = font_heights[(int) NFONT] * 2 ;
- width = items[(int) item].nopts * maxw ;
- color_area(wtype, x, y, width, height, color) ;
- draw_rect(wtype, x, y, x + width, y + height, RSRC, C_BLACK) ;
-
- items[(int) item].width = width ;
- items[(int) item].height = height ;
-
- for (i = 1; i < items[(int) item].nopts; i++)
- draw_line(W_PROPS, x + (i * maxw), y,
- x + (i * maxw), y + height, RSRC, C_BLACK) ;
-
- for (i = 0; i < items[(int) item].nopts; i++)
- {
- str = items[(int) item].options[i] ;
- val = get_strwidth(NFONT, str) ;
- xoff = (maxw - val) / 2 ;
- draw_text(items[(int) item].wtype,
- x + (i * maxw) + xoff,
- y + font_heights[(int) NFONT] +
- (font_heights[(int) NFONT] / 2), NFONT, tcol, str) ;
- }
-
- val = items[(int) item].value ;
- if (val < 0 || val >= items[(int) item].nopts) return ;
- draw_rect(wtype,
- x + (val * maxw) + 1, y + 1,
- x + ((val + 1) * maxw) - 1, y + height - 1, RSRC, C_BLACK) ;
- }
-
-
- void
- draw_clock(wtype, item, state)
- enum win_type wtype ;
- enum panel_type item ;
- int state ;
- {
- char *label ;
- int color, h, w, x, y ;
-
- #ifdef XVIEW
- xv_clock(item) ;
- return ;
- #else
- if (state) color = B_COLOR(C_TEXT) ;
- else color = W_COLOR(C_PANEL) ;
- if (strlen(items[(int) item].label))
- draw_text(items[(int) item].wtype,
- items[(int) item].lx,
- items[(int) item].ly + font_heights[(int) NFONT],
- NFONT, color, items[(int) item].label) ;
-
- x = items[(int) item].x ;
- y = items[(int) item].y - 10 ;
- w = CLWIDTH ;
- h = CLHEIGHT ;
- color_area(W_PANEL, x + 1, y + 1, w - 2, h - 2, W_COLOR(C_PANEL)) ;
- if (state) color = C_BLACK ;
- else color = W_COLOR(C_PANEL) ;
- draw_rect(W_PANEL, x, y, x + w, y + h, RSRC, color) ;
-
- label = items[(int) item].text ;
- color = C_TEXT ;
- x += ((CLWIDTH - get_strwidth(NFONT, label)) / 2) ;
- y += (font_heights[(int) NFONT] +
- (CLHEIGHT - font_heights[(int) NFONT]) / 2) ;
- if (state) draw_text(wtype, x, y, NFONT, color, label) ;
- #endif /*XVIEW*/
- }
-
-
- void
- draw_cycle(wtype, item, color, image)
- enum win_type wtype ;
- enum panel_type item ;
- int color ;
- enum image_type image ;
- {
- int x, y ;
-
- if (gtype == GXVIEW) return ;
- x = items[(int) item].x + 40 ;
- y = items[(int) item].y ;
- if (iscolor)
- {
- draw_stencil(wtype, x, y, CWIDTH, CHEIGHT, RSRC, color,
- CY_STENCIL, CY_STENCIL) ;
- draw_image(wtype, x, y, CWIDTH, CHEIGHT, image) ;
- }
- else draw_stencil(wtype, x, y, CWIDTH, CHEIGHT, RSRC, C_WHITE,
- CY_STENCIL, image) ;
- }
-
-
- void
- draw_cycle_item(wtype, item, color, image)
- enum win_type wtype ;
- enum panel_type item ;
- int color ;
- enum image_type image ;
- {
- char val[4] ;
- int tcol ;
-
- tcol = B_COLOR(C_TEXT) ;
- if (strlen(items[(int) item].label))
- draw_text(items[(int) item].wtype,
- items[(int) item].lx,
- items[(int) item].ly + font_heights[(int) BFONT],
- BFONT, tcol, items[(int) item].label) ;
-
- if (item == MAX_DEPTH && !items[(int) item].value) STRCPY(val, "off") ;
- else SPRINTF(val, "%d", items[(int) item].value) ;
- set_cycle(wtype, item, val) ;
- draw_cycle(wtype, item, color, image) ;
- }
-
-
- void
- draw_filename(str) /* Output filename in text field. */
- char *str ;
- {
- int y ;
-
- color_area(W_PANEL, tx + 1, ty + 1, tw - 2, th - 2, W_COLOR(C_PANEL)) ;
- y = ty + (font_heights[(int) NFONT] +
- (th - font_heights[(int) NFONT]) / 2) - 5 ;
- draw_text(W_PANEL, tx + 5, y, NFONT, B_COLOR(C_TEXT), str) ;
- draw_line(W_PANEL, tx + 5 + get_strwidth(NFONT, str), y + 5,
- tx + 5 + get_strwidth(NFONT, str),
- y + 5 - font_heights[(int) NFONT], RSRC, C_BLACK) ;
- }
-
-
- void
- draw_textfield()
- {
- int x1, y1 ;
-
- if (gtype == GXVIEW) return ;
- lsval = (cury < (BBORDER + (1*(BHEIGHT+BGAP)))) ? 'l' : 's' ;
- x1 = BBORDER + BWIDTH + (BGAP / 2) ;
- y1 = BBORDER + BHEIGHT + (BGAP / 2) ;
- color_area(W_PANEL, x1, y1,
- 4 * (BWIDTH + BGAP), BHEIGHT + BGAP, W_COLOR(C_PANEL)) ;
- draw_rect(W_PANEL, x1, y1, x1 + (4 * (BWIDTH + BGAP)) - 1,
- y1 + BHEIGHT + BGAP - 1, RSRC, C_BLACK) ;
- draw_text(W_PANEL, BBORDER + BWIDTH + BGAP, BBORDER + BHEIGHT + BGAP +
- (font_heights[(int) NFONT] +
- (BHEIGHT - font_heights[(int) NFONT]) / 2) - 5,
- BFONT, B_COLOR(C_TEXT), "File:") ;
- tx = BBORDER + BWIDTH + BGAP + (BWIDTH / 2) + 10 ;
- ty = BBORDER + BHEIGHT + BGAP ;
- tw = (BWIDTH / 2) - 10 + (2 * (BWIDTH + BGAP)) ;
- th = BHEIGHT ;
- draw_rect(W_PANEL, tx, ty, tx + tw, ty + th, RSRC, C_BLACK) ;
- draw_filename(gamefile) ;
-
- tinput = 1 ;
- items[(int) CANCEL_BUT].x = BBORDER + (4*(BWIDTH+BGAP)) ;
- items[(int) CANCEL_BUT].y = BBORDER + (1*(BHEIGHT+BGAP)) ;
- draw_button(W_PANEL, CANCEL_BUT, C_ITEMS, BUT_NORMAL) ;
- }
-
-
- void
- draw_toggle(wtype, item, color)
- enum win_type wtype ;
- enum panel_type item ;
- int color ;
- {
- enum image_type image ;
- int tcol, x, y ;
-
- if (gtype == GXVIEW) return ;
- tcol = B_COLOR(C_TEXT) ;
- if (strlen(items[(int) item].label))
- draw_text(items[(int) item].wtype,
- items[(int) item].lx,
- items[(int) item].ly + font_heights[(int) BFONT],
- BFONT, tcol, items[(int) item].label) ;
-
- if (items[(int) item].value) image = TOGGLE_ON ;
- else image = TOGGLE_OFF ;
-
- x = items[(int) item].x ;
- y = items[(int) item].y ;
- if (iscolor)
- {
- draw_stencil(wtype, x, y, TICKWIDTH, TICKHEIGHT, RSRC, color,
- CY_STENCIL, CY_STENCIL) ;
- draw_image(wtype, x, y, TICKWIDTH, TICKHEIGHT, image) ;
- }
- else draw_stencil(wtype, x, y, TICKWIDTH, TICKHEIGHT, RSRC, C_WHITE,
- CY_STENCIL, image) ;
-
- if (strlen(items[(int) item].text))
- draw_text(items[(int) item].wtype,
- items[(int) item].x + TICKWIDTH + 10,
- items[(int) item].y + font_heights[(int) NFONT],
- NFONT, tcol, items[(int) item].text) ;
- }
-
-
- void
- get_filename() /* Extract next character for load/save filename. */
- {
- char c, dummy[MAXLINE] ;
- int finished, len, nochars ;
-
- if (gtype == GXVIEW) return ;
- finished = 0 ;
- c = cur_ch ;
- if (c == ESCAPE)
- {
- remove_textfield() ;
- return ;
- }
- len = strlen(gamefile) ;
- if (c == BACKSPACE || c == DEL) gamefile[len-1] = '\0' ;
- else if (c == RETURN || c == LINEFEED) finished = 1 ;
- else if (c >= 32) STRNCAT(gamefile, &c, 1) ;
- len = strlen(gamefile) ;
- nochars = (len <= 20) ? len : 20 ;
- STRNCPY(dummy, &gamefile[len - nochars], nochars) ;
- dummy[nochars] = '\0' ;
- draw_filename(dummy) ;
-
- if (finished)
- {
- if (lsval == 'l') load_game() ;
- else if (lsval == 's') save_game() ;
- remove_textfield() ;
- }
- }
-
-
- void
- load_and_move()
- {
- if (loadgame)
- {
- loadgame = 0 ;
- load_game() ;
- }
-
- if (first_move)
- {
- first_move = 0 ;
- next_player = BLACK ;
- opponent_move(next_player) ;
- }
- }
-
-
- void
- make_message(wtype, item) /* Display a message panel. */
- enum win_type wtype ;
- enum panel_type item ;
- {
- char *message ;
- int x, y ;
-
- if (gtype == GXVIEW) return ;
- if (strlen(items[(int) item].label))
- draw_text(items[(int) item].wtype,
- items[(int) item].lx,
- items[(int) item].ly + font_heights[(int) BFONT],
- BFONT, B_COLOR(C_TEXT), items[(int) item].label) ;
-
- message = items[(int) item].text ;
- x = items[(int) item].x ;
- y = items[(int) item].y ;
- color_area(wtype, x, y, PANEL_WIDTH, 15, W_COLOR(C_PANEL)) ;
- draw_text(wtype, x, y + font_heights[(int) NFONT], NFONT,
- B_COLOR(C_TEXT), message) ;
- }
-
-
- void
- message(mtype, str)
- enum panel_type mtype ;
- char *str ;
- {
- int n ;
-
- if (str == NULL) return ;
- if (!started && mtype == PANEL_MES)
- FPRINTF(stderr, "%s: %s\n", progname, str) ;
-
- #ifdef XVIEW
- xv_message(mtype, str) ;
- return ;
- #else
- n = (int) mtype ;
- color_area(W_PANEL, items[n].x, items[n].y,
- get_strwidth(NFONT, items[n].text),
- font_heights[(int) NFONT] + 5, W_COLOR(C_PANEL)) ;
- draw_text(W_PANEL, items[n].x, items[n].y + font_heights[(int) NFONT],
- NFONT, B_COLOR(C_TEXT), str) ;
- STRCPY(items[n].text, str) ;
- #endif /*XVIEW*/
- }
-
-
- void
- paint_all()
- {
- paint_board() ;
- paint_panel() ;
- if (help_showing) set_frame(W_HELP, help_showing) ;
- if (props_showing) set_frame(W_PROPS, props_showing) ;
- load_and_move() ;
- }
-
-
- void
- paint_board()
- {
- char s1[2], sa[2] ;
- int adjust, d, i, n, x, y ;
-
- color_area(W_BOARD, 0, 0, board_width, board_height, C_WHITE) ;
- if (iscolor)
- {
- color_area(W_BOARD, 0, 0, board_width, board_height, C_BORDER) ;
- color_area(W_BOARD, bborder, bborder, BOARD_SIZE * cell_width,
- BOARD_SIZE * cell_height, C_SQUARE) ;
- }
-
- batch(IS_ON) ;
- for (n = 0; n <= BOARD_SIZE; n++)
- {
- color = B_COLOR(C_GRID) ;
- if (n == 0 || n == BOARD_SIZE) color = C_BLACK ;
- if (color == C_GRID) adjust = 1 ;
- else adjust = 0 ;
- draw_line(W_BOARD, (n * cell_width) + bborder, /* Vertical. */
- bborder + adjust, (n * cell_width) + bborder,
- bborder + (BOARD_SIZE * cell_height) - adjust, RSRC, color) ;
- draw_line(W_BOARD, bborder + adjust, /* Horizontal. */
- bborder + (n * cell_height),
- bborder + (BOARD_SIZE * cell_width) - adjust,
- bborder + (n * cell_height), RSRC, color) ;
- }
- batch(IS_OFF) ;
- batch(IS_ON) ;
- for (i = 0; i < BOARD_SIZE; i++)
- {
- color = (iscolor) ? C_WHITE : C_BLACK ;
- SPRINTF(s1, "%c", 'a' + i) ;
- draw_text(W_BOARD, bborder + (i * cell_width) + (cell_width / 2) - 2,
- bborder - 4, GFONT, color, s1) ;
- draw_text(W_BOARD, bborder + (i * cell_width) + (cell_width / 2) - 2,
- (2 * bborder) + (BOARD_SIZE * cell_height) - 2,
- GFONT, color, s1) ;
- SPRINTF(sa, "%c", '1' + i) ;
- draw_text(W_BOARD, bborder / 2 - 2,
- bborder + (i * cell_height) + (cell_height / 2) + 2,
- GFONT, color, sa) ;
- draw_text(W_BOARD, bborder + (BOARD_SIZE * cell_width) + (bborder/2) - 2,
- bborder + (i * cell_height) + (cell_height / 2) + 2,
- GFONT, color, sa) ;
- }
- batch(IS_OFF) ;
- batch(IS_ON) ;
- FOR_BOARD(i)
- if (board.square[i])
- {
- get_xy(i, &x, &y) ;
- draw_piece(board.square[i], x, y, RSRC) ;
- }
- if (DO_LAST) show_last(last_move, IS_ON) ;
- if (DO_NUMBER) show_number(last_move, 60 - board.moves_left, IS_ON) ;
-
- if (show_moves || (invalid == TRUE && SHOW_LEGAL)) show_all(IS_ON) ;
- if (suggestion != -1) draw_symbol(S_SUGGEST, suggestion, IS_ON) ;
- batch(IS_OFF) ;
- }
-
-
- void
- paint_help()
- {
- if (gtype == GXVIEW) return ;
- if (hfp == NULL) return ;
- color_area(W_HELP, 0, 0,
- help_width, (2 * CGAP) + CHEIGHT, W_COLOR(C_PANEL)) ;
- draw_cycle_item(W_HELP, HELP_PAGE, C_ITEMS, CY_NORMAL) ;
- draw_line(W_HELP, 0, (2 * CGAP) + CHEIGHT,
- help_width, (2 * CGAP) + CHEIGHT, RSRC, C_BLACK) ;
- paint_help_text() ;
- }
-
-
- void
- paint_help_text()
- {
- char buf[MAXLINE] ;
- int i, y ;
-
- if (gtype == GXVIEW) return ;
- color_area(W_HELP, 0, (2 * CGAP) + CHEIGHT + 1, help_width,
- ((font_heights[(int) HFONT] + 1) * HELP_ROWS) + (2 * CGAP) - 1,
- W_COLOR(C_PANEL)) ;
- FSEEK(hfp, help_offsets[items[(int) HELP_PAGE].value], 0) ;
- for (i = 0; i < HELP_ROWS; i++)
- {
- if (fgets(buf, MAXLINE, hfp) == NULL) return ;
- y = (3 * CGAP) + CHEIGHT + ((i + 1) * (font_heights[(int) HFONT] + 1)) ;
- draw_text(W_HELP, CGAP, y, HFONT, B_COLOR(C_TEXT), buf) ;
- }
- }
-
-
- void
- paint_panel()
- {
- char mes[MAXLINE] ;
-
- if (iscolor)
- color_area(W_PANEL, 0, 0, PANEL_WIDTH, PANEL_HEIGHT, C_PANEL) ;
-
- draw_button(W_PANEL, LOAD_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, MOVES_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, NEW_GAME_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, HELP_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, REDO_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, PROPS_BUT, C_ITEMS, BUT_NORMAL) ;
-
- draw_button(W_PANEL, SAVE_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, SUGGEST_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, PRINT_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, STOP_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, UNDO_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, QUIT_BUT, C_ITEMS, BUT_NORMAL) ;
-
- make_message(W_PANEL, BLACK_PLAYS) ;
- make_message(W_PANEL, WHITE_PLAYS) ;
-
- draw_clock(W_PANEL, BLACK_CLOCK, DO_CLOCK) ;
- draw_clock(W_PANEL, WHITE_CLOCK, DO_CLOCK) ;
-
- make_message(W_PANEL, PANEL_MES) ;
- make_message(W_PANEL, EVAL_MES) ;
- make_message(W_PANEL, SCORE_MES) ;
- make_message(W_PANEL, TURN_MES) ;
-
- if (tinput) draw_textfield() ;
- set_score() ;
- SPRINTF(mes, "%s to move.",
- (next_player == BLACK) ? bstone_name : wstone_name) ;
- message(TURN_MES, mes) ;
- }
-
-
- void
- paint_prop_sheet()
- {
- int color ;
-
- if (gtype == GXVIEW) return ;
- color = W_COLOR(C_PANEL) ;
- color_area(W_PROPS, 0, 0, PROPS_WIDTH, PROPS_HEIGHT, color) ;
-
- draw_choice(W_PROPS, COMP_CHOICE, color) ;
- draw_choice(W_PROPS, DIFF_CHOICE, color) ;
-
- draw_cycle_item(W_PROPS, MAX_DEPTH, C_ITEMS, CY_NORMAL) ;
-
- draw_toggle(W_PROPS, OPT_ANIM, color) ;
- draw_toggle(W_PROPS, OPT_BEST, color) ;
- draw_toggle(W_PROPS, OPT_LAST, color) ;
- draw_toggle(W_PROPS, OPT_EVAL, color) ;
- draw_toggle(W_PROPS, OPT_NUM, color) ;
- draw_toggle(W_PROPS, OPT_FLIP, color) ;
- draw_toggle(W_PROPS, OPT_MOVE, color) ;
- draw_toggle(W_PROPS, OPT_CLK, color) ;
- }
-
-
- void
- remove_textfield()
- {
- int x1, y1 ;
-
- if (gtype == GXVIEW) return ;
- x1 = BBORDER + BWIDTH + (BGAP / 2) ;
- y1 = BBORDER + BHEIGHT + (BGAP / 2) ;
- color_area(W_PANEL, x1, y1, 4 * (BWIDTH + BGAP), BHEIGHT + BGAP,
- W_COLOR(C_PANEL)) ;
- tinput = 0 ;
- items[(int) CANCEL_BUT].x = -1 ;
- items[(int) CANCEL_BUT].y = -1 ;
-
- draw_button(W_PANEL, SUGGEST_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, PRINT_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, STOP_BUT, C_ITEMS, BUT_NORMAL) ;
- draw_button(W_PANEL, UNDO_BUT, C_ITEMS, BUT_NORMAL) ;
- }
-
-
- void
- set_cycle(wtype, item, str)
- enum win_type wtype ;
- enum panel_type item ;
- char *str ;
- {
- if (gtype == GXVIEW) return ;
- color_area(wtype, items[(int) item].x, items[(int) item].y,
- items[(int) item].width, CHEIGHT, W_COLOR(C_PANEL)) ;
- draw_text(wtype, items[(int) item].x,
- items[(int) item].y + font_heights[(int) NFONT],
- NFONT, B_COLOR(C_TEXT), str) ;
- STRCPY(items[(int) item].text, str) ;
- items[(int) item].width = get_strwidth(NFONT, str) ;
- }
-