void CMapGridPainter::AddRegion (const CVector &vCenter, Metric rWidth, Metric rHeight) // AddRegion // // Adds a rectangular region to paint. We combine this appropriately with any // previously added regions. { int x, y; Metric rHalfWidth = 0.5 * rWidth; Metric rHalfHeight = 0.5 * rHeight; int xFrom = (int)floor((vCenter.GetX() - rHalfWidth) / GRID_SIZE); int xTo = (int)floor((vCenter.GetX() + rHalfWidth) / GRID_SIZE); int yFrom = (int)floor((vCenter.GetY() - rHalfHeight) / GRID_SIZE); int yTo = (int)floor((vCenter.GetY() + rHalfHeight) / GRID_SIZE); // Null case if (xFrom == xTo || yFrom == yTo) return; // Start with vertical lines TArray<SLine> NewLines; for (x = xFrom; x <= xTo; x++) { SLine *pNewLine = NewLines.Insert(); pNewLine->xyKey = x; pNewLine->xyFrom = yFrom; pNewLine->xyTo = yTo; } AddLines(NewLines, &m_VertLines); // Add horizontal lines NewLines.DeleteAll(); for (y = yFrom; y <= yTo; y++) { SLine *pNewLine = NewLines.Insert(); pNewLine->xyKey = y; pNewLine->xyFrom = xFrom; pNewLine->xyTo = xTo; } AddLines(NewLines, &m_HorzLines); m_bRecalcNeeded = true; }
void CEnergyFieldList::GetList (TArray<CEnergyField *> &List) // GetList // // Returns all the fields in an array { List.DeleteAll(); CEnergyField *pField = m_pFirst; while (pField) { if (!pField->IsDestroyed()) List.Insert(pField); pField = pField->GetNext(); } }
void CTextBlock::Format (const SBlockFormatDesc &BlockFormat) // Format // // Format the text for the given width { int i; m_Formatted.DeleteAll(); // Keep looping until we've formatted all spans. STextSpan *pSpan = (m_Text.GetCount() > 0 ? &m_Text[0] : NULL); STextSpan *pSpanEnd = (pSpan ? pSpan + m_Text.GetCount() : NULL); TArray<STextSpan> Line; STextSpan LeftOver; int y = 0; while (pSpan) { // Add what we've got to the line if (!pSpan->sText.IsBlank()) Line.Insert(*pSpan); // If we've hit the end of the line, then we output everything we've // got in the line to the formatted buffer. if (pSpan->bEoP || (pSpan + 1) == pSpanEnd) { // Compute metrics for each span and the line as a whole. int cyLineAscent = 0; int cxLine = 0; int cyLine = 0; for (i = 0; i < Line.GetCount(); i++) { // Compute the max ascent of the line. int cyAscent = Line[i].Format.pFont->GetAscent(); if (cyAscent > cyLineAscent) cyLineAscent = cyAscent; // Compute the width of each span, the total width of the line // and the max height of the line. int cyHeight; Line[i].cx = Line[i].Format.pFont->MeasureText(Line[i].sText, &cyHeight); cxLine += Line[i].cx; if (cyHeight > cyLine) cyLine = cyHeight; } // Compute to horz position of the line (based on block alignment) int x; if (BlockFormat.iHorzAlign == alignRight && BlockFormat.cxWidth != -1) x = BlockFormat.cxWidth - cxLine; else if (BlockFormat.iHorzAlign == alignCenter && BlockFormat.cxWidth != -1) x = (BlockFormat.cxWidth - cxLine) / 2; else x = 0; // Format all the spans for this line for (i = 0; i < Line.GetCount(); i++) { SFormattedTextSpan *pFormatted = m_Formatted.Insert(); pFormatted->sText = Line[i].sText; pFormatted->Format = Line[i].Format; pFormatted->x = x; pFormatted->y = y + (cyLineAscent - Line[i].Format.pFont->GetAscent()); pFormatted->cx = Line[i].cx; pFormatted->cy = Line[i].Format.pFont->GetHeight(); // Advance the line width x += Line[i].cx; } // Advance the line y += cyLine; Line.DeleteAll(); } // Next pSpan++; if (pSpan >= pSpanEnd) pSpan = NULL; } }
void CIntGraph::GenerateRandomConnections (DWORD dwStartNode, int iMinConnections, int iMaxConnections) // GenerateRandomConnections // // Generate random connection across all nodes. { int i, j; // We start by making sure every node is connected with one other node. // We keep track of the nodes that are connected and those that are not. TArray<int> Connected; TArray<int> NotConnected; // All the nodes are part of the not-connected group // (except for the start node) for (i = 0; i < m_Nodes.GetCount(); i++) if (i != dwStartNode && !NodeIsFree(GetNode(i))) NotConnected.Insert(i); Connected.Insert((int)dwStartNode); // Loop until all nodes are connected while (NotConnected.GetCount() > 0) { // Look for the shortest, non-overlapping distance // between a node in the connected list and a node in the // not-connected list. int iBestDist2 = MAX_DIST2; int iBestFrom = -1; int iBestTo = -1; for (i = 0; i < Connected.GetCount(); i++) { int iFrom = i; SNode *pFrom = GetNode(Connected[iFrom]); for (j = 0; j < NotConnected.GetCount(); j++) { int iTo = j; SNode *pTo = GetNode(NotConnected[iTo]); int xDist = pTo->x - pFrom->x; int yDist = pTo->y - pFrom->y; int iDist2 = xDist * xDist + yDist * yDist; if (iDist2 < iBestDist2 && !IsCrossingConnection(Connected[iFrom], NotConnected[iTo])) { iBestDist2 = iDist2; iBestFrom = iFrom; iBestTo = iTo; } } } // If we found a best distance, connect the two nodes if (iBestFrom != -1) { Connect(Connected[iBestFrom], NotConnected[iBestTo]); Connected.Insert(NotConnected[iBestTo]); NotConnected.Delete(iBestTo); } // If we did not find the best distance, then it means that we could not // connect without overlapping. In that case, just connect all the unconnected else { for (i = 0; i < NotConnected.GetCount(); i++) Connect(Connected[0], NotConnected[i]); NotConnected.DeleteAll(); } } }
void CTranscendenceWnd::CreateCreditsAnimation (IAnimatron **retpAnimatron) // CreateCreditsAnimation // // Creates full end credits { int i; CAniSequencer *pSeq = new CAniSequencer; int iTime = 0; // Figure out the position int xMidCenter = m_rcIntroMain.left + RectWidth(m_rcIntroMain) / 2; int yMidCenter = m_rcIntroMain.bottom - RectHeight(m_rcIntroMain) / 3; IAnimatron *pAnimation; // Create credits TArray<CString> Names; Names.Insert(CONSTLIT("George Moromisato")); m_UIRes.CreateMediumCredit(CONSTLIT("designed & created by"), Names, xMidCenter, yMidCenter, 150, &pAnimation); pSeq->AddTrack(pAnimation, iTime); iTime += 150; Names.DeleteAll(); Names.Insert(CONSTLIT("Michael Tangent")); m_UIRes.CreateMediumCredit(CONSTLIT("music by"), Names, xMidCenter, yMidCenter, 150, &pAnimation); pSeq->AddTrack(pAnimation, iTime); iTime += 150; // More programming Names.DeleteAll(); for (i = 0; i < ADDITIONAL_PROGRAMMING_COUNT; i++) Names.Insert(CString(ADDITIONAL_PROGRAMMING[i])); m_UIRes.CreateMediumCredit(CONSTLIT("additional programming by"), Names, xMidCenter, yMidCenter, 150, &pAnimation); pSeq->AddTrack(pAnimation, iTime); iTime += ADDITIONAL_PROGRAMMING_COUNT * 150; // Special thanks Names.DeleteAll(); for (i = 0; i < SPECIAL_THANKS_COUNT; i++) Names.Insert(CString(SPECIAL_THANKS[i])); m_UIRes.CreateMediumCredit(CONSTLIT("special thanks to"), Names, xMidCenter, yMidCenter, 150, &pAnimation); pSeq->AddTrack(pAnimation, iTime); iTime += SPECIAL_THANKS_COUNT * 150; // Thanks to int yStart = m_rcIntroMain.top; int yEnd = m_rcIntroMain.bottom - m_Fonts.Header.GetHeight(); CreateLongCreditsAnimation(xMidCenter + RectWidth(m_rcIntroMain) / 6, yStart, yEnd - yStart, &pAnimation); pSeq->AddTrack(pAnimation, iTime); iTime += pAnimation->GetDuration(); // Done *retpAnimatron = pSeq; }
bool CCSVParser::ParseRow (TArray<CString> &Row, CString *retsError) // ParseRow // // Parses a row { enum EStates { stateStart, stateSingleQuote, stateDoubleQuote, stateInPlainValue, stateEndOfValue, stateCR, stateLF, }; Row.DeleteAll(); // Parse the BOM, if any if (m_iFormat == formatUnknown) m_iFormat = ParseBOM(); // Keep reading until we hit the end of the line. EStates iState = stateStart; CBuffer Value; while (true) { switch (iState) { case stateStart: { switch (GetCurChar()) { case '\0': return true; case ' ': case '\t': break; case ',': Row.Insert(NULL_STR); break; case '\r': iState = stateCR; break; case '\n': iState = stateLF; break; case '\'': iState = stateSingleQuote; break; case '\"': iState = stateDoubleQuote; break; default: Value.WriteChar(GetCurChar()); iState = stateInPlainValue; break; } break; } case stateSingleQuote: { switch (GetCurChar()) { case '\0': Row.Insert(CString(Value.GetPointer(), Value.GetLength())); return true; case '\'': Row.Insert(CString(Value.GetPointer(), Value.GetLength())); Value.SetLength(0); iState = stateEndOfValue; break; default: Value.WriteChar(GetCurChar()); break; } break; } case stateDoubleQuote: { switch (GetCurChar()) { case '\0': Row.Insert(CString(Value.GetPointer(), Value.GetLength())); return true; case '\"': Row.Insert(CString(Value.GetPointer(), Value.GetLength())); Value.SetLength(0); iState = stateEndOfValue; break; default: Value.WriteChar(GetCurChar()); break; } break; } case stateEndOfValue: { switch (GetCurChar()) { case '\0': return true; case ' ': case '\t': break; case ',': iState = stateStart; break; case '\r': iState = stateCR; break; case '\n': iState = stateLF; break; default: break; } break; } case stateInPlainValue: { switch (GetCurChar()) { case '\0': Row.Insert(CString(Value.GetPointer(), Value.GetLength())); return true; case ',': Row.Insert(CString(Value.GetPointer(), Value.GetLength())); Value.SetLength(0); iState = stateStart; break; case '\r': Row.Insert(CString(Value.GetPointer(), Value.GetLength())); Value.SetLength(0); iState = stateCR; break; case '\n': Row.Insert(CString(Value.GetPointer(), Value.GetLength())); Value.SetLength(0); iState = stateLF; break; default: Value.WriteChar(GetCurChar()); break; } break; } case stateCR: { switch (GetCurChar()) { case '\0': return true; case '\n': GetNextChar(); return true; default: break; } break; } case stateLF: { switch (GetCurChar()) { case '\0': return true; case '\r': GetNextChar(); return true; default: return true; } break; } } GetNextChar(); } }