richb@sunaus.oz (Rich Burridge) (12/10/90)
------CUT HERE------ patch3 - part5 ------CUT HERE------ ------- boardstuff.c ------- *** /tmp/da07561 Sun Dec 9 15:11:31 1990 --- boardstuff.c Sat Dec 8 19:46:17 1990 *************** *** 27,37 **** #include "color.h" #include "extern.h" #include <ctype.h> - #ifdef SYSV - #include <sys/times.h> - #else - #include <sys/time.h> - #endif /*SYSV*/ #ifdef X11 #include <X11/Xos.h> --- 27,32 ---- *************** *** 182,188 **** taken = formfliplist(move, player) ; update_board_image(player) ; ! SPRINTF(line, "%s took %d %s", (player == BLACK) ? "Black" : "White", taken, (taken == 1) ? "stone" : "stones") ; message(PANEL_MES, line) ; } --- 177,189 ---- taken = formfliplist(move, player) ; update_board_image(player) ; ! if (DO_LAST == FALSE && DO_NUMBER == FALSE) ! SPRINTF(line, "%s moved at <%c-%c> and took %d %s", ! (player == BLACK) ? "Black" : "White", ! (move % 8) + 'a', (move >> 3) + '1', ! taken, (taken == 1) ? "stone" : "stones") ; ! else ! SPRINTF(line, "%s took %d %s", (player == BLACK) ? "Black" : "White", taken, (taken == 1) ? "stone" : "stones") ; message(PANEL_MES, line) ; } *************** *** 205,214 **** { switch (piece) { ! case BLACK : draw_stencil(x, y, PSIZE, PSIZE, op, C_BLACK, P_BLACK, P_BLACK) ; break ; ! case WHITE : draw_stencil(x, y, PSIZE, PSIZE, op, C_BLACK, P_BLACK, P_WHITE) ; } } --- 206,215 ---- { switch (piece) { ! case BLACK : draw_stencil(W_MAIN, x, y, PSIZE, PSIZE, op, C_BLACK, P_BLACK, P_BLACK) ; break ; ! case WHITE : draw_stencil(W_MAIN, x, y, PSIZE, PSIZE, op, C_BLACK, P_BLACK, P_WHITE) ; } } *************** *** 215,228 **** void ! draw_rect(x1, y1, x2, y2, op, color) int x1, y1, x2, y2, color ; enum optype op ; { ! draw_line(x1, y1, x2, y1, op, color) ; ! draw_line(x1, y1, x1, y2, op, color) ; ! draw_line(x2, y1, x2, y2, op, color) ; ! draw_line(x1, y2, x2, y2, op, color) ; } --- 216,230 ---- void ! draw_rect(wtype, x1, y1, x2, y2, op, color) ! enum win_type wtype ; int x1, y1, x2, y2, color ; enum optype op ; { ! draw_line(wtype, x1, y1, x2, y1, op, color) ; ! draw_line(wtype, x1, y1, x1, y2, op, color) ; ! draw_line(wtype, x2, y1, x2, y2, op, color) ; ! draw_line(wtype, x1, y2, x2, y2, op, color) ; } *************** *** 238,245 **** x = (move & 7) * CELL_SIZE + BBORDER ; y = (move >> 3) * CELL_SIZE + BBORDER ; ! draw_rect(x + offset, CY + y + offset, ! x + CELL_SIZE - offset, CY + y + CELL_SIZE - offset, RSRC, color) ; } --- 240,248 ---- x = (move & 7) * CELL_SIZE + BBORDER ; y = (move >> 3) * CELL_SIZE + BBORDER ; ! draw_rect(W_MAIN, x + offset, CY + y + offset, ! x + CELL_SIZE - offset, CY + y + CELL_SIZE - offset, ! RSRC, color) ; } *************** *** 385,390 **** --- 388,395 ---- if (legal(move, next_player, &board) == FALSE) return(0) ; (void) formfliplist(move, next_player) ; batch(IS_ON) ; + if (DO_LAST) show_last(last_move, IS_OFF) ; + if (DO_NUMBER) show_number(last_move, 59 - board.moves_left, IS_OFF) ; FOR_BOARD(i) if (board.square[i] != old_board.square[i]) { *************** *** 391,396 **** --- 396,404 ---- get_xy(i, &x, &y) ; draw_piece(next_player, x, CY+y, RSRC) ; } + if (DO_LAST) show_last(move, IS_ON) ; + if (DO_NUMBER) show_number(move, 60 - board.moves_left, IS_ON) ; + last_move = move ; batch(IS_OFF) ; return(1) ; } *************** *** 465,473 **** int player, move ; long note ; { ! SPRINTF(line, "%s: <%c-%c> eval : %ld", (player == BLACK) ? "Black" : "White", ! (move & 7) + 'a', (move >> 3) + '1', note) ; message(EVAL_MES, line) ; } --- 473,481 ---- int player, move ; long note ; { ! SPRINTF(line, "%s: <%c-%c> eval : %ld depth: %d", (player == BLACK) ? "Black" : "White", ! (move & 7) + 'a', (move >> 3) + '1', note, profmax) ; message(EVAL_MES, line) ; } *************** *** 519,525 **** if (iscolor[d]) { get_xy(i, &x, &y) ; ! draw_stencil(x, CY+y, PSIZE, PSIZE, RSRC, C_BLACK, P_WHITE, P_WHITE) ; } else --- 527,533 ---- if (iscolor[d]) { get_xy(i, &x, &y) ; ! draw_stencil(W_MAIN, x, CY+y, PSIZE, PSIZE, RSRC, C_BLACK, P_WHITE, P_WHITE) ; } else *************** *** 526,533 **** { x = BBORDER + ((i & 7) + 1) * CELL_SIZE - CELL_SIZE / 2 ; y = BBORDER + ((i >> 3) + 1) * CELL_SIZE - CELL_SIZE / 2 ; ! draw_line(x-5, CY+y, x+5, CY+y, RSRC, C_BLACK) ; ! draw_line(x, CY+y+5, x, CY+y-5, RSRC, C_BLACK) ; } } } --- 534,541 ---- { x = BBORDER + ((i & 7) + 1) * CELL_SIZE - CELL_SIZE / 2 ; y = BBORDER + ((i >> 3) + 1) * CELL_SIZE - CELL_SIZE / 2 ; ! draw_line(W_MAIN, x-5, CY+y, x+5, CY+y, RSRC, C_BLACK) ; ! draw_line(W_MAIN, x, CY+y+5, x, CY+y-5, RSRC, C_BLACK) ; } } } *************** *** 540,546 **** x = (i & 7) * CELL_SIZE + BBORDER + 1 ; y = (i >> 3) * CELL_SIZE + BBORDER + 1 ; color = (iscolor[d]) ? C_LBROWN : C_WHITE ; ! color_area(x, CY + y, CELL_SIZE - 2, CELL_SIZE - 2, color) ; } } batch(IS_OFF) ; --- 548,554 ---- x = (i & 7) * CELL_SIZE + BBORDER + 1 ; y = (i >> 3) * CELL_SIZE + BBORDER + 1 ; color = (iscolor[d]) ? C_LBROWN : C_WHITE ; ! color_area(W_MAIN, x, CY + y, CELL_SIZE - 2, CELL_SIZE - 2, color) ; } } batch(IS_OFF) ; *************** *** 554,565 **** long note ; { batch(IS_ON) ; ! if (move == -1 || do_bestmove == FALSE) return ; if (best_cmove != -1) ! draw_square(best_cmove, IS_OFF, 2) ; best_cmove = move ; draw_square(best_cmove, IS_ON, 2) ; ! if (show_notes) set_eval(next_player, move, note) ; batch(IS_OFF) ; } --- 562,578 ---- long note ; { batch(IS_ON) ; ! if (move == -1 || DO_BESTMOVE == FALSE) return ; if (best_cmove != -1) ! { ! draw_square(best_cmove, IS_OFF, 2) ; ! if (DO_NUMBER) show_number(best_cmove, cmove_depth, IS_OFF) ; ! } best_cmove = move ; + cmove_depth = profmax ; draw_square(best_cmove, IS_ON, 2) ; ! if (DO_NUMBER) show_number(best_cmove, cmove_depth, IS_ON) ; ! if (SHOW_NOTES) set_eval(next_player, move, note) ; batch(IS_OFF) ; } *************** *** 569,603 **** int move ; enum bltype state ; { ! if (move == -1 || do_last == FALSE) return ; ! draw_square(move, state, 2) ; } void ! show_number(move, state) ! int move ; enum bltype state ; { char num[3] ; ! int color, strw, val, x, y ; ! if (move == -1 || do_number == FALSE) return ; ! if (board.square[move] == BLACK) color = (state == IS_ON) ? C_WHITE : C_BLACK ; else if (board.square[move] == WHITE) color = (state == IS_ON) ? C_BLACK : C_WHITE ; x = (move & 7) * CELL_SIZE + BBORDER + PIECE_MARGIN ; y = (move >> 3) * CELL_SIZE + BBORDER + PIECE_MARGIN ; - val = 60 - board.moves_left ; - if (state == IS_OFF) val-- ; SPRINTF(num, "%2d", val) ; strw = get_strwidth(NFONT, num) ; x = x + ((2 * PIECE_RAD) - strw) / 2 ; y = y + CY + nfont_height + ((2 * PIECE_RAD) - nfont_height) / 2 ; ! draw_text(x, y, NFONT, color, num) ; } --- 582,621 ---- int move ; enum bltype state ; { ! if (move == -1) return ; ! if (board.moves_left < 60) draw_square(move, state, 2) ; } void ! show_number(move, val, state) ! int move, val ; enum bltype state ; { char num[3] ; ! int color, strw, x, y ; ! if (move == -1) return ; ! ! if (board.square[move] == BLACK) color = (state == IS_ON) ? C_WHITE : C_BLACK ; else if (board.square[move] == WHITE) color = (state == IS_ON) ? C_BLACK : C_WHITE ; + else if (iscolor[(int) cur_dpyno]) + color = (state == IS_ON) ? C_BLACK : C_LBROWN ; + else + color = (state == IS_ON) ? C_BLACK : C_WHITE ; + x = (move & 7) * CELL_SIZE + BBORDER + PIECE_MARGIN ; y = (move >> 3) * CELL_SIZE + BBORDER + PIECE_MARGIN ; SPRINTF(num, "%2d", val) ; strw = get_strwidth(NFONT, num) ; x = x + ((2 * PIECE_RAD) - strw) / 2 ; + if (val < 10) x -= 3 ; y = y + CY + nfont_height + ((2 * PIECE_RAD) - nfont_height) / 2 ; ! draw_text(W_MAIN, x, y, NFONT, color, num) ; } *************** *** 611,620 **** rop = RCLR ; color = (iscolor[(int) cur_dpyno]) ? C_LBROWN : C_WHITE ; if (iscolor[(int) cur_dpyno]) rop = RSRC ; ! draw_line(suggest_x-5, CY+suggest_y-5, ! suggest_x+5, CY+suggest_y+5, rop, color) ; ! draw_line(suggest_x-5, CY+suggest_y+5, ! suggest_x+5, CY+suggest_y-5, rop, color) ; suggestion = -1 ; } } --- 629,638 ---- rop = RCLR ; color = (iscolor[(int) cur_dpyno]) ? C_LBROWN : C_WHITE ; if (iscolor[(int) cur_dpyno]) rop = RSRC ; ! draw_line(W_MAIN, suggest_x-5, CY+suggest_y-5, ! suggest_x+5, CY+suggest_y+5, rop, color) ; ! draw_line(W_MAIN, suggest_x-5, CY+suggest_y+5, ! suggest_x+5, CY+suggest_y-5, rop, color) ; suggestion = -1 ; } } *************** *** 626,635 **** { int flips, i, piece, total_flips, x, y ; ! total_flips = (quickgame == TRUE) ? 2 : 4 ; show_all(IS_OFF) ; ! show_last(last_move, IS_OFF) ; ! show_number(last_move, IS_OFF) ; show_suggestion() ; for (flips = 0; flips < total_flips; flips++) { --- 644,653 ---- { int flips, i, piece, total_flips, x, y ; ! total_flips = (QUICKGAME == TRUE) ? 2 : 4 ; show_all(IS_OFF) ; ! if (DO_LAST) show_last(last_move, IS_OFF) ; ! if (DO_NUMBER) show_number(last_move, 59 - board.moves_left, IS_OFF) ; show_suggestion() ; for (flips = 0; flips < total_flips; flips++) { *************** *** 648,660 **** batch(IS_OFF) ; PAUSE ; } ! show_last(move, IS_ON) ; ! show_number(move, IS_ON) ; last_move = move ; set_score() ; set_turn(OPPONENT(player)) ; message(TURN_MES, line) ; ! if (show_notes) if ((player == BLACK && items[(int) BLACK_PLAYS].value == COMPUTER) || (player == WHITE && items[(int) WHITE_PLAYS].value == COMPUTER)) set_eval(player, move, note) ; --- 666,678 ---- batch(IS_OFF) ; PAUSE ; } ! if (DO_LAST) show_last(move, IS_ON) ; ! if (DO_NUMBER) show_number(move, 60 - board.moves_left, IS_ON) ; last_move = move ; set_score() ; set_turn(OPPONENT(player)) ; message(TURN_MES, line) ; ! if (SHOW_NOTES) if ((player == BLACK && items[(int) BLACK_PLAYS].value == COMPUTER) || (player == WHITE && items[(int) WHITE_PLAYS].value == COMPUTER)) set_eval(player, move, note) ; ------- events.c ------- *** /tmp/da07564 Sun Dec 9 15:11:32 1990 --- events.c Sun Dec 9 14:09:16 1990 *************** *** 36,41 **** --- 36,42 ---- n = (int) item ; if (items[n].x == -1) return ; + if (items[n].wtype != curwin) return ; if ((curx > items[n].x) && (curx < (items[n].x + items[n].width)) && (cury > items[n].y) && (cury < (items[n].y + items[n].height))) { *************** *** 42,92 **** down = nextc ; itemno = n ; but_inverted = itemno ; ! draw_button((enum panel_type) itemno, C_LGREY, BUT_INVERT) ; } } void check_cycle_down(item) enum panel_type item ; { ! int ix, n, reply ; n = (int) item ; ! ix = items[n].x + (3 * BWIDTH) + (2 * BGAP) - CWIDTH ; ! if ((curx > ix) && (curx < (ix + (items[n].width / 2))) && ! (cury > items[n].y) && (cury < (items[n].y + items[n].height)) && nextc != RIGHT_DOWN) { direction = INCREMENT ; down = nextc ; itemno = n ; ! draw_cycle((enum panel_type) n, C_LGREY, CY_LINVERT) ; } ! else if ((curx > ix) && (curx < (ix + items[n].width)) && ! (cury > items[n].y) && (cury < (items[n].y + items[n].height)) && nextc != RIGHT_DOWN) { direction = DECREMENT ; down = nextc ; itemno = n ; ! draw_cycle((enum panel_type) n, C_LGREY, CY_RINVERT) ; } - else if ((curx > ix) && (curx < (ix + items[n].width)) && - (cury > items[n].y) && (cury < (items[n].y + items[n].height))) - { - direction = NONE ; - down = RIGHT_DOWN ; - itemno = n ; - reply = do_menu((enum panel_type) itemno) ; - if (reply) - { - nextc = RIGHT_UP ; - handle_item(reply - 1) ; - draw_cycle((enum panel_type) itemno, C_LGREY, CY_NORMAL) ; - } - } } --- 43,97 ---- down = nextc ; itemno = n ; but_inverted = itemno ; ! draw_button(W_MAIN, (enum panel_type) itemno, C_LGREY, BUT_INVERT) ; } } void + check_choice_down(item) + enum panel_type item ; + { + int n ; + + n = (int) item ; + if (items[n].wtype != curwin) return ; + if ((curx > items[n].x) && (curx < (items[n].x + items[n].width)) && + (cury > items[n].y) && (cury < (items[n].y + items[n].height))) + { + down = nextc ; + itemno = n ; + } + } + + + void check_cycle_down(item) enum panel_type item ; { ! int ix, n ; n = (int) item ; ! if (items[n].wtype != curwin) return ; ! ix = items[n].x + 40 ; ! if ((curx > ix) && (curx < (ix + (CWIDTH / 2))) && ! (cury > items[n].y) && (cury < (items[n].y + CHEIGHT)) && nextc != RIGHT_DOWN) { direction = INCREMENT ; down = nextc ; itemno = n ; ! draw_cycle(curwin, (enum panel_type) n, C_LGREY, CY_LINVERT) ; } ! else if ((curx > ix) && (curx < (ix + CWIDTH)) && ! (cury > items[n].y) && (cury < (items[n].y + CHEIGHT)) && nextc != RIGHT_DOWN) { direction = DECREMENT ; down = nextc ; itemno = n ; ! draw_cycle(curwin, (enum panel_type) n, C_LGREY, CY_RINVERT) ; } } *************** *** 100,108 **** { case P_BUTTON : check_button_down((enum panel_type) n) ; break ; case P_CYCLE : check_cycle_down((enum panel_type) n) ; break ; ! case P_MESSAGE : /* do nothing. */ ; } } --- 105,116 ---- { case P_BUTTON : check_button_down((enum panel_type) n) ; break ; + case P_CHOICE : check_choice_down((enum panel_type) n) ; + break ; case P_CYCLE : check_cycle_down((enum panel_type) n) ; break ; ! case P_MESSAGE : break ; /* Do nothing. */ ! case P_TOGGLE : check_toggle_down((enum panel_type) n) ; } } *************** *** 110,115 **** --- 118,126 ---- void check_item_up() { + int color, d ; + + d = (int) cur_dpyno ; if ((nextc == LEFT_UP && down == LEFT_DOWN) || (nextc == MIDDLE_UP && down == MIDDLE_DOWN) || (nextc == RIGHT_UP && down == RIGHT_DOWN)) *************** *** 116,130 **** { if (items[itemno].type == P_BUTTON && but_inverted == -1) return ; handle_item(items[itemno].value) ; ! if (items[itemno].type == P_BUTTON && items[itemno].x != -1) ! draw_button((enum panel_type) itemno, C_LGREY, BUT_NORMAL) ; ! else if (items[itemno].type == P_CYCLE) ! draw_cycle((enum panel_type) itemno, C_LGREY, CY_NORMAL) ; } } void do_action() { int cx, cy, thismove ; --- 127,174 ---- { if (items[itemno].type == P_BUTTON && but_inverted == -1) return ; handle_item(items[itemno].value) ; ! ! switch (items[itemno].type) ! { ! case P_BUTTON : if (items[itemno].x != -1) ! draw_button(items[itemno].wtype, ! (enum panel_type) itemno, ! C_LGREY, BUT_NORMAL) ; ! break ; ! case P_CHOICE : color = (iscolor[d]) ? C_BEIGE : C_WHITE ; ! draw_choice(items[itemno].wtype, ! (enum panel_type) itemno, color) ; ! break ; ! case P_CYCLE : draw_cycle(items[itemno].wtype, ! (enum panel_type) itemno, ! C_LGREY, CY_NORMAL) ; ! break ; ! case P_TOGGLE : color = (iscolor[d]) ? C_BEIGE : C_WHITE ; ! draw_toggle(items[itemno].wtype, ! (enum panel_type) itemno, color) ; ! } } } void + check_toggle_down(item) + enum panel_type item ; + { + int n ; + + n = (int) item ; + if (items[n].wtype != curwin) return ; + if ((curx > items[n].x) && (curx < (items[n].x + items[n].width)) && + (cury > items[n].y) && (cury < (items[n].y + items[n].height))) + { + down = nextc ; + itemno = n ; + } + } + + + void do_action() { int cx, cy, thismove ; *************** *** 131,137 **** switch (nextc) { ! case MOUSE_MOVING : if (animation == TRUE) draw_piece(next_player, piece_x, piece_y, RINV) ; piece_x = curx - PIECE_RAD ; piece_y = cury - PIECE_RAD ; --- 175,181 ---- switch (nextc) { ! case MOUSE_MOVING : if (ANIMATION == TRUE) draw_piece(next_player, piece_x, piece_y, RINV) ; piece_x = curx - PIECE_RAD ; piece_y = cury - PIECE_RAD ; *************** *** 149,155 **** draw_outline(last_outline, IS_ON) ; } ! if (animation == TRUE) draw_piece(next_player, piece_x, piece_y, RINV) ; break ; --- 193,199 ---- draw_outline(last_outline, IS_ON) ; } ! if (ANIMATION == TRUE) draw_piece(next_player, piece_x, piece_y, RINV) ; break ; *************** *** 157,163 **** case EXIT_WINDOW : set_cursor(CANVASCUR) ; draw_outline(last_outline, IS_OFF) ; last_outline = -1 ; ! if (animation == TRUE) draw_piece(next_player, piece_x, piece_y, RINV) ; cmode = (enum cantype) ((int) cmode - 1) ; break ; --- 201,207 ---- case EXIT_WINDOW : set_cursor(CANVASCUR) ; draw_outline(last_outline, IS_OFF) ; last_outline = -1 ; ! if (ANIMATION == TRUE) draw_piece(next_player, piece_x, piece_y, RINV) ; cmode = (enum cantype) ((int) cmode - 1) ; break ; *************** *** 178,189 **** enum panel_type item ; int ch ; { ! int val ; if (!validkey) { validkey = cur_ch ; ! message(PANEL_MES, items[(int) item].text) ; } else { --- 222,236 ---- enum panel_type item ; int ch ; { ! int color, d, maxw, val ; + d = (int) cur_dpyno ; + color = (iscolor[d]) ? C_BEIGE : C_WHITE ; if (!validkey) { validkey = cur_ch ; ! if (item == OPT_EVAL) message(PANEL_MES, "Notes?") ; ! else message(PANEL_MES, items[(int) item].label) ; } else { *************** *** 190,232 **** val = -1 ; switch (item) { ! case BLACK_PLAYS : ! case WHITE_PLAYS : if (item == BLACK_PLAYS) curx = 0 ; ! else curx = BBORDER + (3*(BWIDTH+BGAP)) ; ! switch (ch) { ! case 'c' : ! case 'C' : val = 1 ; ! items[(int) item].value = val ; ! set_cycle(item, ! player_values[val]) ; break ; ! case 'h' : ! case 'H' : val = 0 ; ! items[(int) item].value = val ; ! set_cycle(item, ! player_values[val]) ; break ; default : return ; } ! case DIFFICULTY : if (ch >= '1' && ch <= '9') val = ch - '1' ; ! items[(int) item].value = val ; ! set_cycle(item, diff_values[val]) ; ! break ; ! case NOTES : switch (ch) { case 'n' : case 'N' : val = 0 ; - items[(int) item].value = val ; - set_cycle(item, notes_values[val]) ; break ; case 'y' : case 'Y' : val = 1 ; - items[(int) item].value = val ; - set_cycle(item, notes_values[val]) ; break ; default : return ; } } if (val != -1) { --- 237,282 ---- val = -1 ; switch (item) { ! case COMP_CHOICE : switch (ch) { ! case 'a' : /* All (both). */ ! case 'A' : val = CP_BOTH ; break ; ! case 'b' : /* Black. */ ! case 'B' : val = CP_BLACK ; break ; + case 'n' : /* Neither. */ + case 'N' : val = CP_NEITHER ; + break ; + case 'w' : /* White. */ + case 'W' : val = CP_WHITE ; + break ; default : return ; } ! maxw = items[(int) item].width / ! items[(int) item].nopts ; ! curx = items[(int) item].x + (maxw * val) ; ! itemno = (int) item ; ! items[(int) item].value = val ; ! draw_choice(W_PROPS, item, color) ; ! break ; ! case DIFF_CHOICE : if (ch >= '1' && ch <= '9') val = ch - '1' ; ! items[(int) item].value = val ; ! draw_choice(W_PROPS, item, color) ; ! break ; ! case OPT_EVAL : color = (iscolor[d]) ? C_BEIGE : C_WHITE ; ! switch (ch) { case 'n' : case 'N' : val = 0 ; break ; case 'y' : case 'Y' : val = 1 ; break ; default : return ; } + items[(int) item].value = val ; + draw_toggle(W_PROPS, OPT_EVAL, color) ; } if (val != -1) { *************** *** 274,280 **** set_cursor(NOCURSOR) ; piece_x = curx - PIECE_RAD ; piece_y = cury - PIECE_RAD ; ! if (animation == TRUE) draw_piece(next_player, piece_x, piece_y, RINV) ; cmode = (enum cantype) ((int) cmode + 1) ; --- 324,330 ---- set_cursor(NOCURSOR) ; piece_x = curx - PIECE_RAD ; piece_y = cury - PIECE_RAD ; ! if (ANIMATION == TRUE) draw_piece(next_player, piece_x, piece_y, RINV) ; cmode = (enum cantype) ((int) cmode + 1) ; *************** *** 292,305 **** process_event() ; if (nextc == FRAME_REPAINT) init_canvas() ; else if (nextc == KEYBOARD) handle_key() ; else if (nextc == EXIT_WINDOW && but_inverted != -1) { ! draw_button((enum panel_type) but_inverted, C_LGREY, BUT_NORMAL) ; but_inverted = -1 ; down = 0 ; } ! else if (cury > (CY + BBORDER)) handle_board_event() ; else if (nextc == LEFT_UP || nextc == MIDDLE_UP || nextc == RIGHT_UP) check_item_up() ; else if (nextc == LEFT_DOWN || nextc == MIDDLE_DOWN || nextc == RIGHT_DOWN) --- 342,356 ---- process_event() ; if (nextc == FRAME_REPAINT) init_canvas() ; + else if (nextc == PROPS_REPAINT) paint_prop_sheet() ; else if (nextc == KEYBOARD) handle_key() ; else if (nextc == EXIT_WINDOW && but_inverted != -1) { ! draw_button(W_MAIN, (enum panel_type) but_inverted, C_LGREY, BUT_NORMAL) ; but_inverted = -1 ; down = 0 ; } ! else if (curwin == W_MAIN && cury > (CY + BBORDER)) handle_board_event() ; else if (nextc == LEFT_UP || nextc == MIDDLE_UP || nextc == RIGHT_UP) check_item_up() ; else if (nextc == LEFT_DOWN || nextc == MIDDLE_DOWN || nextc == RIGHT_DOWN) *************** *** 337,350 **** } switch (cur_ch) { ! case 'B' : do_cycle_key(BLACK_PLAYS, nextc) ; /* Cycle items. */ break ; ! case 'D' : do_cycle_key(DIFFICULTY, nextc) ; break ; ! case 'N' : do_cycle_key(NOTES, nextc) ; break ; - case 'W' : do_cycle_key(WHITE_PLAYS, nextc) ; - break ; case 'M' : show_all_moves() ; /* Button items. */ break ; --- 388,399 ---- } switch (cur_ch) { ! case 'C' : do_cycle_key(COMP_CHOICE, nextc) ; /* Cycle items. */ break ; ! case 'D' : do_cycle_key(DIFF_CHOICE, nextc) ; break ; ! case 'N' : do_cycle_key(OPT_EVAL, nextc) ; break ; case 'M' : show_all_moves() ; /* Button items. */ break ; *************** *** 359,364 **** --- 408,415 ---- case 's' : suggest() ; break ; case 'u' : undo() ; + break ; + case 'p' : do_props() ; break ; case 'q' : destroy_frame() ; ------- items.c ------- *** /tmp/da07567 Sun Dec 9 15:11:33 1990 --- items.c Sun Dec 9 13:53:06 1990 *************** *** 27,41 **** #include "color.h" #include "extern.h" - #ifdef SYSV - #include "string.h" - #else - #include <strings.h> - #endif /*SYSV*/ - void ! draw_button(item, color, image) /* Draw a panel button. */ enum panel_type item ; int color ; enum image_type image ; --- 27,36 ---- #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 ; *************** *** 47,102 **** y = items[(int) item].y ; if (iscolor[(int) cur_dpyno]) { ! draw_stencil(x, y, BWIDTH, BHEIGHT, RSRC, color, BUT_STENCIL, BUT_STENCIL) ; ! draw_image(x, y, BWIDTH, BHEIGHT, image) ; } ! else draw_stencil(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_BLACK ; x += ((BWIDTH - get_strwidth(NFONT, label)) / 2) ; y += (nfont_height + (BHEIGHT - nfont_height) / 2) - 5 ; ! draw_text(x, y, NFONT, color, label) ; } void ! draw_cycle(item, color, image) enum panel_type item ; int color ; enum image_type image ; { int x, y ; ! x = items[(int) item].x + (3 * BWIDTH) + (2 * BGAP) - CWIDTH ; y = items[(int) item].y ; if (iscolor[(int) cur_dpyno]) { ! draw_stencil(x, y, CWIDTH, CHEIGHT, RSRC, color, CY_STENCIL, CY_STENCIL) ; ! draw_image(x, y, CWIDTH, CHEIGHT, image) ; } ! else draw_stencil(x, y, CWIDTH, CHEIGHT, RSRC, C_WHITE, CY_STENCIL, image) ; } void ! draw_cycle_item(item, choices, color, image) /* Display cycle panel item. */ enum panel_type item ; - char *choices[] ; int color ; enum image_type image ; { ! char *label ; ! int n, x, y ; ! n = (int) item ; ! label = items[n].text ; ! x = items[n].x ; ! y = items[n].y ; ! draw_text(x, y + bfont_height, BFONT, C_BLACK, label) ; ! set_cycle(item, choices[items[n].value]) ; ! draw_cycle(item, color, image) ; } --- 42,154 ---- y = items[(int) item].y ; if (iscolor[(int) cur_dpyno]) { ! 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_BLACK ; x += ((BWIDTH - get_strwidth(NFONT, label)) / 2) ; y += (nfont_height + (BHEIGHT - nfont_height) / 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, val, width, x, xoff, y ; + + if (strlen(items[(int) item].label)) + draw_text(items[(int) item].wtype, + items[(int) item].lx, items[(int) item].ly + bfont_height, + BFONT, C_BLACK, 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 = nfont_height * 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 + nfont_height + (nfont_height / 2), NFONT, C_BLACK, str) ; + } + + val = items[(int) item].value ; + draw_rect(wtype, + x + (val * maxw) + 1, y + 1, + x + ((val + 1) * maxw) - 1, y + height - 1, RSRC, C_BLACK) ; + } + + + void + draw_cycle(wtype, item, color, image) + enum win_type wtype ; + enum panel_type item ; + int color ; enum image_type image ; { int x, y ; ! x = items[(int) item].x + 40 ; y = items[(int) item].y ; if (iscolor[(int) cur_dpyno]) { ! 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] ; ! if (strlen(items[(int) item].label)) ! draw_text(items[(int) item].wtype, ! items[(int) item].lx, items[(int) item].ly + bfont_height, ! BFONT, C_BLACK, items[(int) item].label) ; ! ! SPRINTF(val, "%d", items[(int) item].value) ; ! set_cycle(wtype, item, val) ; ! draw_cycle(wtype, item, color, image) ; } *************** *** 106,121 **** { int y ; ! color_area(tx + 1, ty + 1, tw - 2, th - 2, C_WHITE) ; y = ty + (nfont_height + (th - nfont_height) / 2) - 5 ; ! draw_text(tx + 5, y, NFONT, C_BLACK, str) ; ! draw_line(tx + 5 + get_strwidth(NFONT, str), y + 5, ! tx + 5 + get_strwidth(NFONT, str), y + 5 - nfont_height, ! RSRC, C_BLACK) ; } void draw_textfield() { int x1, y1 ; --- 158,209 ---- { int y ; ! color_area(W_MAIN, tx + 1, ty + 1, tw - 2, th - 2, C_WHITE) ; y = ty + (nfont_height + (th - nfont_height) / 2) - 5 ; ! draw_text(W_MAIN, tx + 5, y, NFONT, C_BLACK, str) ; ! draw_line(W_MAIN, tx + 5 + get_strwidth(NFONT, str), y + 5, ! tx + 5 + get_strwidth(NFONT, str), y + 5 - nfont_height, ! RSRC, C_BLACK) ; } void + draw_toggle(wtype, item, color) + enum win_type wtype ; + enum panel_type item ; + int color ; + { + enum image_type image ; + int x, y ; + + if (strlen(items[(int) item].label)) + draw_text(items[(int) item].wtype, + items[(int) item].lx, items[(int) item].ly + bfont_height, + BFONT, C_BLACK, 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[(int) cur_dpyno]) + { + 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 + nfont_height, + NFONT, C_BLACK, items[(int) item].text) ; + } + + + void draw_textfield() { int x1, y1 ; *************** *** 123,132 **** lsval = (curx < (BBORDER + (2*(BWIDTH+BGAP)))) ? 'l' : 's' ; x1 = BBORDER + BWIDTH + (BGAP / 2) ; y1 = BBORDER + BHEIGHT + (BGAP / 2) ; ! color_area(x1, y1, 4 * (BWIDTH + BGAP), BHEIGHT + BGAP, C_WHITE) ; ! draw_rect(x1, y1, x1 + (4 * (BWIDTH + BGAP)) - 1, ! y1 + BHEIGHT + BGAP - 1, RSRC, C_BLACK) ; ! draw_text(BBORDER + BWIDTH + BGAP, BBORDER + BHEIGHT + BGAP + (nfont_height + (BHEIGHT - nfont_height) / 2) - 5, BFONT, C_BLACK, "File:") ; tx = BBORDER + BWIDTH + BGAP + (BWIDTH / 2) + 10 ; --- 211,220 ---- lsval = (curx < (BBORDER + (2*(BWIDTH+BGAP)))) ? 'l' : 's' ; x1 = BBORDER + BWIDTH + (BGAP / 2) ; y1 = BBORDER + BHEIGHT + (BGAP / 2) ; ! color_area(W_MAIN, x1, y1, 4 * (BWIDTH + BGAP), BHEIGHT + BGAP, C_WHITE) ; ! draw_rect(W_MAIN, x1, y1, x1 + (4 * (BWIDTH + BGAP)) - 1, ! y1 + BHEIGHT + BGAP - 1, RSRC, C_BLACK) ; ! draw_text(W_MAIN, BBORDER + BWIDTH + BGAP, BBORDER + BHEIGHT + BGAP + (nfont_height + (BHEIGHT - nfont_height) / 2) - 5, BFONT, C_BLACK, "File:") ; tx = BBORDER + BWIDTH + BGAP + (BWIDTH / 2) + 10 ; *************** *** 133,145 **** ty = BBORDER + BHEIGHT + BGAP ; tw = (BWIDTH / 2) - 10 + (2 * (BWIDTH + BGAP)) ; th = BHEIGHT ; ! draw_rect(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(CANCEL_BUT, C_LGREY, BUT_NORMAL) ; } --- 221,233 ---- ty = BBORDER + BHEIGHT + BGAP ; tw = (BWIDTH / 2) - 10 + (2 * (BWIDTH + BGAP)) ; th = BHEIGHT ; ! draw_rect(W_MAIN, 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_MAIN, CANCEL_BUT, C_LGREY, BUT_NORMAL) ; } *************** *** 175,192 **** void ! make_message(item) /* Display a message panel. */ enum panel_type item ; { char *message ; int x, y ; message = items[(int) item].text ; x = items[(int) item].x ; y = items[(int) item].y ; color = (iscolor[(int) cur_dpyno]) ? C_BEIGE : C_WHITE ; ! color_area(x, y, TOTAL_WIDTH, 15, color) ; ! draw_text(x, y+nfont_height, NFONT, C_BLACK, message) ; } --- 263,286 ---- void ! make_message(wtype, item) /* Display a message panel. */ ! enum win_type wtype ; enum panel_type item ; { char *message ; int x, y ; + if (strlen(items[(int) item].label)) + draw_text(items[(int) item].wtype, + items[(int) item].lx, items[(int) item].ly + bfont_height, + BFONT, C_BLACK, items[(int) item].label) ; + message = items[(int) item].text ; x = items[(int) item].x ; y = items[(int) item].y ; color = (iscolor[(int) cur_dpyno]) ? C_BEIGE : C_WHITE ; ! color_area(wtype, x, y, TOTAL_WIDTH, 15, color) ; ! draw_text(wtype, x, y + nfont_height, NFONT, C_BLACK, message) ; } *************** *** 193,217 **** void make_panel() { ! draw_button(LOAD_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(NEW_GAME_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(SAVE_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(SHOW_ALL_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(SUGGEST_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(UNDO_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(DONE_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(QUIT_BUT, C_LGREY, BUT_NORMAL) ; ! draw_cycle_item(BLACK_PLAYS, player_values, C_LGREY, CY_NORMAL) ; ! draw_cycle_item(WHITE_PLAYS, player_values, C_LGREY, CY_NORMAL) ; ! draw_cycle_item(DIFFICULTY, diff_values, C_LGREY, CY_NORMAL) ; ! draw_cycle_item(NOTES, notes_values, C_LGREY, CY_NORMAL) ; ! ! make_message(PANEL_MES) ; ! make_message(EVAL_MES) ; ! make_message(SCORE_MES) ; ! make_message(TURN_MES) ; } --- 287,308 ---- void make_panel() { ! draw_button(W_MAIN, LOAD_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(W_MAIN, MOVES_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(W_MAIN, NEW_GAME_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(W_MAIN, SAVE_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(W_MAIN, SUGGEST_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(W_MAIN, UNDO_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(W_MAIN, PROPS_BUT, C_LGREY, BUT_NORMAL) ; ! draw_button(W_MAIN, QUIT_BUT, C_LGREY, BUT_NORMAL) ; ! make_message(W_MAIN, BLACK_PLAYS) ; ! make_message(W_MAIN, WHITE_PLAYS) ; ! make_message(W_MAIN, PANEL_MES) ; ! make_message(W_MAIN, EVAL_MES) ; ! make_message(W_MAIN, SCORE_MES) ; ! make_message(W_MAIN, TURN_MES) ; } *************** *** 224,237 **** n = (int) mtype ; color = (iscolor[(int) cur_dpyno]) ? C_BEIGE : C_WHITE ; ! color_area(items[n].x, items[n].y, get_strwidth(NFONT, items[n].text), nfont_height + 5, color) ; ! draw_text(items[n].x, items[n].y + nfont_height, NFONT, C_BLACK, str) ; STRCPY(items[n].text, str) ; } void remove_textfield() { int x1, y1 ; --- 315,353 ---- n = (int) mtype ; color = (iscolor[(int) cur_dpyno]) ? C_BEIGE : C_WHITE ; ! color_area(W_MAIN, items[n].x, items[n].y, get_strwidth(NFONT, items[n].text), nfont_height + 5, color) ; ! draw_text(W_MAIN, items[n].x, items[n].y + nfont_height, ! NFONT, C_BLACK, str) ; STRCPY(items[n].text, str) ; } void + paint_prop_sheet() + { + int color, d ; + + d = (int) cur_dpyno ; + color = (iscolor[d]) ? C_BEIGE : C_WHITE ; + color_area(W_PROPS, 0, 0, PROPS_WIDTH, PROPS_HEIGHT, color) ; + + color = (iscolor[d]) ? C_BEIGE : C_WHITE ; + draw_choice(W_PROPS, COMP_CHOICE, color) ; + draw_choice(W_PROPS, DIFF_CHOICE, color) ; + + draw_cycle_item(W_PROPS, MAX_DEPTH, C_LGREY, 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) ; + } + + + void remove_textfield() { int x1, y1 ; *************** *** 238,244 **** x1 = BBORDER + BWIDTH + (BGAP / 2) ; y1 = BBORDER + BHEIGHT + (BGAP / 2) ; ! color_area(x1, y1, 4 * (BWIDTH + BGAP), BHEIGHT + BGAP, (iscolor[(int) cur_dpyno]) ? C_BEIGE : C_WHITE) ; tinput = 0 ; items[(int) CANCEL_BUT].x = -1 ; --- 354,360 ---- x1 = BBORDER + BWIDTH + (BGAP / 2) ; y1 = BBORDER + BHEIGHT + (BGAP / 2) ; ! color_area(W_MAIN, x1, y1, 4 * (BWIDTH + BGAP), BHEIGHT + BGAP, (iscolor[(int) cur_dpyno]) ? C_BEIGE : C_WHITE) ; tinput = 0 ; items[(int) CANCEL_BUT].x = -1 ; *************** *** 247,267 **** void ! set_cycle(mtype, str) ! enum panel_type mtype ; char *str ; { - int n, width, x ; - - n = (int) mtype ; color = (iscolor[(int) cur_dpyno]) ? C_BEIGE : C_WHITE ; ! width = (3 * BWIDTH) + (2 * BGAP) - ! get_strwidth(BFONT, items[n].text) - CWIDTH ; ! x = items[n].x + get_strwidth(BFONT, items[n].text) ; ! color_area(x, items[n].y, width, items[n].height, color) ; ! ! width = get_strwidth(NFONT, str) ; ! x = items[n].x + (3 * BWIDTH) + (2 * BGAP) - CWIDTH - width ; ! draw_text(x - 5, items[n].y + nfont_height, NFONT, C_BLACK, str) ; } --- 363,379 ---- void ! set_cycle(wtype, item, str) ! enum win_type wtype ; ! enum panel_type item ; char *str ; { color = (iscolor[(int) cur_dpyno]) ? C_BEIGE : C_WHITE ; ! color_area(wtype, items[(int) item].x, items[(int) item].y, ! items[(int) item].width, CHEIGHT, color) ; ! draw_text(wtype, items[(int) item].x, items[(int) item].y + nfont_height, ! NFONT, C_BLACK, str) ; ! STRCPY(items[(int) item].text, str) ; ! items[(int) item].width = get_strwidth(NFONT, str) ; }