/* 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; } }
/* * 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); }
/* * 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"); }
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); }
void DrawPathfinderNode(pointT center, string color, string label) { MovePen(center.x + NODE_RADIUS, center.y); SetPenColor(color); StartFilledRegion(1.0); DrawArc(NODE_RADIUS, 0, 360); EndFilledRegion(); if (!label.empty()) { MovePen(center.x + NODE_RADIUS + 2, center.y + 0.4 * GetFontAscent()); SetFont("Helvetica"); SetPointSize(FONT_SIZE); DrawTextString(label); } }
void CPDF_VariableText::Initialize() { if (!m_bInitial) { CPVT_SectionInfo secinfo; CPVT_WordPlace place; place.nSecIndex = 0; AddSection(place, secinfo); CPVT_LineInfo lineinfo; lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize()); lineinfo.fLineDescent = GetFontDescent(GetDefaultFontIndex(), GetFontSize()); AddLine(place, lineinfo); if (CSection* pSection = m_SectionArray.GetAt(0)) pSection->ResetLinePlace(); m_bInitial = TRUE; } }
void CPDF_VariableText::Initialize() { if (!m_bInitial) { CPVT_SectionInfo secinfo; if (m_bRichText) { secinfo.pSecProps = new CPVT_SecProps(0.0f, 0.0f, 0); secinfo.pWordProps = new CPVT_WordProps( GetDefaultFontIndex(), kDefaultFontSize, 0, ScriptType::Normal, 0); } CPVT_WordPlace place; place.nSecIndex = 0; AddSection(place, secinfo); CPVT_LineInfo lineinfo; lineinfo.fLineAscent = GetFontAscent(GetDefaultFontIndex(), GetFontSize()); lineinfo.fLineDescent = GetFontDescent(GetDefaultFontIndex(), GetFontSize()); AddLine(place, lineinfo); if (CSection* pSection = m_SectionArray.GetAt(0)) pSection->ResetLinePlace(); m_bInitial = TRUE; } }
FX_FLOAT CPDF_VariableText::GetWordAscent(const CPVT_WordInfo& WordInfo, FX_BOOL bFactFontSize) { return GetFontAscent(GetWordFontIndex(WordInfo), GetWordFontSize(WordInfo, bFactFontSize)); }
FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) { return m_bRichText && SecInfo.pWordProps ? GetFontAscent(SecInfo.pWordProps->nFontIndex, SecInfo.pWordProps->fFontSize) : GetFontAscent(GetDefaultFontIndex(), GetFontSize()); }
FX_FLOAT CPDF_VariableText::GetLineAscent(const CPVT_SectionInfo& SecInfo) { return GetFontAscent(GetDefaultFontIndex(), GetFontSize()); }