Esempio n. 1
0
    /*
     * Creates all cubes in position, including a blank letter centered in
     * the middle of each cube.  Initially the cubes are not highlighted.
     */
    static void setupLetterCubes() {
        double lineWidth = 2;
        double cubeSize = gState.cubeSize - lineWidth;
        double cubeY = gState.board.y + BOARD_BORDER/2;
        for (int row = 0; row < gState.rowCount; row++) {
            double cubeX = gState.board.x + BOARD_BORDER/2;
            for (int col = 0; col < gState.columnCount; col++) {
                // display the letter cubes as rounded rectangles
                double cubeRoundRadius = gState.cubeSize/5;
                GRoundRect* rect = new GRoundRect(cubeX, cubeY, cubeSize,
                                                  cubeSize, cubeRoundRadius * 2);
                rect->setLineWidth(lineWidth);
                rect->setColor("Black");
                rect->setFilled(true);
                rect->setFillColor(DIE_COLOR);
                gwp->add(rect);
                letterCubes[row][col].rect = rect;

                // draw the letter on the cube
                GLabel* label = new GLabel("M");   // start as "M" for getWidth
                label->setFont(CUBE_FONT + "-" + integerToString(int(gState.fontSize)));
                label->setColor(LETTER_COLOR);
                label->setLocation(cubeX + gState.cubeSize/2 - label->getWidth()/2,
                                   cubeY + gState.cubeSize/2 + 0.4 * gState.fontSize);
                label->setLabel(" ");
                gwp->add(label);
                letterCubes[row][col].label = label;
                cubeX += (int) cubeSize + lineWidth;
            }
            cubeY += (int) cubeSize + lineWidth;
        }
    }
Esempio n. 2
0
    void labelCube(int row, int col, char letter, bool highlighted) {
        ensureInitialized();
        if (row < 0 || row >= gState.rowCount || col < 0 || col >= gState.columnCount) {
            error(string("labelCube called with invalid row, col arguments.  Must be between (0, 0) and (")
                  + integerToString(gState.rowCount) + ", " + integerToString(gState.columnCount) + ")");
        }
        if (!isalpha(letter) && letter != ' ') {
            error(string("labelCube called with non-alphabetic character: '") + letter);
        }

        setHighlighted(row, col, highlighted);

        GLabel* label = letterCubes[row][col].label;
        label->setLabel(string(1, letter));
        if (isalpha(letter)) {
            label->setLocation(
                    letterCubes[row][col].rect->getX() + gState.cubeSize/2 - 0.45 * label->getWidth(),
                    letterCubes[row][col].rect->getY() + gState.cubeSize/2 + 0.36 * gState.fontSize);
        }
    }