Annotation of 43BSDReno/games/chess/Xchess/popup.c, revision 1.1

1.1     ! root        1: 
        !             2: /* This file contains code for X-CHESS.
        !             3:    Copyright (C) 1986 Free Software Foundation, Inc.
        !             4: 
        !             5: This file is part of X-CHESS.
        !             6: 
        !             7: X-CHESS is distributed in the hope that it will be useful,
        !             8: but WITHOUT ANY WARRANTY.  No author or distributor
        !             9: accepts responsibility to anyone for the consequences of using it
        !            10: or for whether it serves any particular purpose or works at all,
        !            11: unless he says so in writing.  Refer to the X-CHESS General Public
        !            12: License for full details.
        !            13: 
        !            14: Everyone is granted permission to copy, modify and redistribute
        !            15: X-CHESS, but only under the conditions described in the
        !            16: X-CHESS General Public License.   A copy of this license is
        !            17: supposed to have been given to you along with X-CHESS so you
        !            18: can know your rights and responsibilities.  It should be in a
        !            19: file named COPYING.  Among other things, the copyright notice
        !            20: and this notice must be preserved on all copies.  */
        !            21: 
        !            22: 
        !            23: /* RCS Info: $Revision: 1.2 $ on $Date: 86/11/26 12:10:38 $
        !            24:  *           $Source: /users/faustus/xchess/RCS/popup.c,v $
        !            25:  * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group 
        !            26:  *      [email protected], ucbvax!faustus
        !            27:  * Permission is granted to modify and re-distribute this code in any manner
        !            28:  * as long as this notice is preserved.  All standard disclaimers apply.
        !            29:  *
        !            30:  * A simple pop-up menu system.
        !            31:  */
        !            32: 
        !            33: #include "xchess.h"
        !            34: 
        !            35: /* Open a small window with some text in it and two buttons -- yes and no.
        !            36:  * Use black and white pixel, and the medium font.
        !            37:  */
        !            38: 
        !            39: bool
        !            40: pop_question(win, text)
        !            41:        windata *win;
        !            42:        char *text;
        !            43: {
        !            44:        char *s, *t;
        !            45:        int nlines = 1, ncols = 0, i = 0, j;
        !            46:        int x, y;
        !            47:        Window w;
        !            48:        bool ch;
        !            49:        XEvent ev;
        !            50: 
        !            51:        for (s = text; *s; s++) {
        !            52:                if ((*s == '\n') && s[1])
        !            53:                        nlines++;
        !            54:                if ((*s == '\n') || !s[1]) {
        !            55:                        if (i > ncols)
        !            56:                                ncols = i;
        !            57:                        i = 0;
        !            58:                } else
        !            59:                        i++;
        !            60:        }
        !            61: 
        !            62:        if (ncols < 12)
        !            63:                ncols = 12;
        !            64:        nlines += 4;
        !            65:        ncols += 4;
        !            66: 
        !            67:        x = (BASE_WIDTH - ncols * win->medium->max_bounds.width) / 2;
        !            68:        y = (BASE_HEIGHT - nlines * win->medium->max_bounds.ascent) / 2;
        !            69: 
        !            70:        w = XCreateSimpleWindow(win->display, win->basewin,
        !            71:                                x, y, ncols * win->medium->max_bounds.width,
        !            72:                                nlines * win->medium->ascent,
        !            73:                                BORDER_WIDTH, win->border.pixel,
        !            74:                                win->textback.pixel);
        !            75:        XMapRaised(win->display, w);
        !            76:        XSetFont(win->display, DefaultGC(win->display, 0),
        !            77:                 win->medium->fid);
        !            78:        
        !            79:        for (i = 0, s = text; i < nlines - 4; i++) {
        !            80:                for (t = s, j = 0; *t && (*t != '\n'); t++, j++)
        !            81:                        ;
        !            82:                XDrawString(win->display, w, DefaultGC(win->display, 0),
        !            83:                            (ncols - j) / 2 * win->medium->max_bounds.width,
        !            84:                            (i + 1) * win->medium->ascent,
        !            85:                            s, j);
        !            86:                s = t + 1;
        !            87:        }
        !            88:        XDrawString(win->display, w, DefaultGC(win->display, 0),
        !            89:                    (ncols - 8) * win->medium->max_bounds.width / 4,
        !            90:                    (nlines - 2) * win->medium->ascent,
        !            91:                    "YES", 3);
        !            92:        XDrawString(win->display, w, DefaultGC(win->display, 0),
        !            93:                    (ncols - 4) * win->medium->max_bounds.width * 3 / 4,
        !            94:                    (nlines - 2) * win->medium->ascent,
        !            95:                    "NO", 2);
        !            96: 
        !            97:        XSync(win->display, 0);
        !            98:        XSelectInput(win->display, w, ButtonPressMask);
        !            99:        XWindowEvent(win->display, w, ButtonPressMask, &ev);
        !           100:        x = ev.xkey.x;
        !           101:        y = ev.xkey.y;
        !           102: 
        !           103:        if (x > ncols * win->medium->max_bounds.width / 2)
        !           104:                ch = false;
        !           105:        else
        !           106:                ch = true;
        !           107: 
        !           108:        XDestroyWindow(win->display, w);
        !           109:        XSync(win->display, 0);
        !           110:        return (ch);
        !           111: }
        !           112: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.