Beispiel #1
0
/* Function: CalculateGeometry
 * ---------------------------
 * This internal helper does all the messy math to work out how to divide up the space
 * within the current graphics window to neatly fit the board, the cubes, and the word lists.
 */
static void CalculateGeometry(int numRows, int numCols)
{	
    double boardSize = min(min(GetWindowWidth()/3, GetWindowHeight() - LABEL_HEIGHT), 2.7);
    gState.cubeSize = min((boardSize-BOARD_BORDER)/numRows, (boardSize-BOARD_BORDER)/numCols);
    gState.board.w = gState.board.h = boardSize;
    gState.board.y = GetWindowHeight() - LABEL_HEIGHT - gState.board.h;
    double leftover = GetWindowWidth() - gState.board.w - 2*INDENT;
    gState.scoreBox[Human].x = INDENT;
    gState.scoreBox[Human].y = gState.scoreBox[Computer].y = gState.board.y + gState.board.h;
    gState.scoreBox[Human].h = gState.scoreBox[Computer].h = LABEL_HEIGHT;
    gState.scoreBox[Human].w = leftover*HUMAN_PERCENTAGE;
    gState.board.x = gState.scoreBox[Human].x + gState.scoreBox[Human].w;
    gState.scoreBox[Computer].x = gState.board.x + gState.board.w + INDENT;
    gState.scoreBox[Computer].w = GetWindowWidth() - gState.scoreBox[Computer].x - INDENT;
    gState.numRows = numRows;
    gState.numCols = numCols;
    SetFont(WORD_FONT);
    SetPointSize(WORD_FONT_SIZE);
    gState.wordColumnWidth = TextStringWidth("mmmmm");	// col size is 5 letters wide
    SetFont(CUBE_FONT);
    // iterate to find largest font that fits within given percentage
    for (gState.cubeFontSize = 8; gState.cubeFontSize < 48; gState.cubeFontSize++) {
	SetPointSize(gState.cubeFontSize);
	if ((TextStringWidth("M") > FONT_PERCENTAGE*gState.cubeSize) || 
	    (GetFontAscent() > FONT_PERCENTAGE*gState.cubeSize)) break;
    }
}
Beispiel #2
0
/* 
 * Function: EraseOldScore
 * ------------------------
 * I used to do this with SetEraseMode, but that left cruft behind, so instead
 * paint an opaque white box over the old score
 */
static void EraseOldScore(playerT playerNum, int value)
{   
    SetFont(SCORE_FONT);
    SetPointSize(SCORE_FONT_SIZE);
    string str = IntegerToString(value);
    FillBox(gState.scoreBox[playerNum].x + gState.scoreBox[playerNum].w - TextStringWidth(str), 
	    gState.scoreBox[playerNum].y + GetFontDescent(),
	    TextStringWidth(str), GetFontAscent(), 1.0, "blue");
}
Beispiel #3
0
/* 
 * Function: DrawCenteredChar
 * --------------------------
 * Used to draw the letters in the center of the cube. 
 * Note that this function centers the char
 * both vertically and horizontally around the point specified.
 */ 
static void DrawCenteredChar(double centerX, double centerY, char ch)
{
    string s(1, ch);
    SetFont(CUBE_FONT);
    SetPointSize(gState.cubeFontSize);
    MovePen(centerX - TextStringWidth(s)/2, centerY - GetFontAscent()/2);
    DrawTextString(s);
}
void DrawButtonText(buttonT & button) {
    SetFont(BUTTON_FONT);
	SetStyle(BUTTON_STYLE);
    SetPointSize(BUTTON_POINT_SIZE);
    MovePen(button.x + (button.width - TextStringWidth(button.name)) / 2,
            button.y + (button.height + GetFontAscent()) / 2);
    DrawTextString(button.name);
}
static void DrawCenteredText(string text, double cx, double cy, string color) {
	double x = cx - TextStringWidth(text)/2;
	double y = cy - GetFontAscent()/2;
	MovePen(x, y);
	string oldColor = GetPenColor();
	SetPenColor(color);
	DrawTextString(text);
	SetPenColor(oldColor);
}
double ComputeButtonWidth(string name) {
	SaveGraphicsState();
    SetFont(BUTTON_FONT);
	SetStyle(BUTTON_STYLE);
    SetPointSize(BUTTON_POINT_SIZE);
	double width = 2 * BUTTON_MARGIN + TextStringWidth(name);
	RestoreGraphicsState();
	if (width < MIN_BUTTON_WIDTH) width = MIN_BUTTON_WIDTH;
	return width;
}
Beispiel #7
0
/* 
 * Function: DrawOneScore
 * ----------------------
 * Draws the specified score for the player according to player enum.
 */
static void DrawOneScore(playerT playerNum, int value)
{   
    SetFont(SCORE_FONT);
    SetPointSize(SCORE_FONT_SIZE);
    SetPenColor("Label Color");
    string str = IntegerToString(value);
    MovePen(gState.scoreBox[playerNum].x + gState.scoreBox[playerNum].w - TextStringWidth(str), 
	    gState.scoreBox[playerNum].y + GetFontDescent() + 0.03); // the 0.03 hack added Sept-2011
    // Using SetEraseMode() to delete old score interfered with the line underneath
    DrawTextString(str);
}