本文整理汇总了C++中common::Array::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Array::begin方法的具体用法?C++ Array::begin怎么用?C++ Array::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::Array
的用法示例。
在下文中一共展示了Array::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadSharedCastsFrom
void DirectorEngine::loadSharedCastsFrom(Common::String filename) {
Archive *shardcst;
if (getVersion() < 4) {
shardcst = new RIFFArchive();
} else {
shardcst = new RIFXArchive();
}
shardcst->openFile(filename);
Score *castScore = new Score(this);
Common::SeekableSubReadStreamEndian *castStream = shardcst->getResource(MKTAG('V','W','C','R'), 1024);
castScore->loadCastData(*castStream);
*_sharedCasts = castScore->_casts;
Common::Array<uint16> dib = shardcst->getResourceIDList(MKTAG('D','I','B',' '));
if (dib.size() != 0) {
Common::Array<uint16>::iterator iterator;
for (iterator = dib.begin(); iterator != dib.end(); ++iterator) {
debug(3, "Shared DIB %d", *iterator);
_sharedDIB->setVal(*iterator, shardcst->getResource(MKTAG('D','I','B',' '), *iterator));
}
}
Common::Array<uint16> stxt = shardcst->getResourceIDList(MKTAG('S','T','X','T'));
if (stxt.size() != 0) {
Common::Array<uint16>::iterator iterator;
for (iterator = stxt.begin(); iterator != stxt.end(); ++iterator) {
debug(3, "Shared STXT %d", *iterator);
_sharedSTXT->setVal(*iterator, shardcst->getResource(MKTAG('S','T','X','T'), *iterator));
}
}
Common::Array<uint16> bmp = shardcst->getResourceIDList(MKTAG('B','I','T','D'));
if (bmp.size() != 0) {
Common::Array<uint16>::iterator iterator;
for (iterator = bmp.begin(); iterator != bmp.end(); ++iterator) {
_sharedBMP->setVal(*iterator, shardcst->getResource(MKTAG('B','I','T','D'), *iterator));
}
}
Common::Array<uint16> sound = shardcst->getResourceIDList(MKTAG('S','N','D',' '));
if (stxt.size() != 0) {
Common::Array<uint16>::iterator iterator;
for (iterator = sound.begin(); iterator != sound.end(); ++iterator) {
_sharedSound->setVal(*iterator, shardcst->getResource(MKTAG('S','N','D',' '), *iterator));
}
}
}
示例2: loadSharedCastsFrom
void DirectorEngine::loadSharedCastsFrom(Common::String filename) {
Archive *shardcst = createArchive();
debugC(1, kDebugLoading, "Loading Shared cast '%s'", filename.c_str());
shardcst->openFile(filename);
_sharedDIB = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>;
_sharedSTXT = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>;
_sharedSound = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>;
_sharedBMP = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>;
Score *castScore = new Score(this, shardcst);
castScore->loadConfig(*shardcst->getResource(MKTAG('V','W','C','F'), 1024));
castScore->loadCastData(*shardcst->getResource(MKTAG('V','W','C','R'), 1024));
_sharedCasts = &castScore->_casts;
Common::Array<uint16> dib = shardcst->getResourceIDList(MKTAG('D','I','B',' '));
if (dib.size() != 0) {
debugC(3, kDebugLoading, "Loading %d DIBs", dib.size());
for (Common::Array<uint16>::iterator iterator = dib.begin(); iterator != dib.end(); ++iterator) {
debugC(3, kDebugLoading, "Shared DIB %d", *iterator);
_sharedDIB->setVal(*iterator, shardcst->getResource(MKTAG('D','I','B',' '), *iterator));
}
}
Common::Array<uint16> stxt = shardcst->getResourceIDList(MKTAG('S','T','X','T'));
if (stxt.size() != 0) {
debugC(3, kDebugLoading, "Loading %d STXTs", stxt.size());
for (Common::Array<uint16>::iterator iterator = stxt.begin(); iterator != stxt.end(); ++iterator) {
debugC(3, kDebugLoading, "Shared STXT %d", *iterator);
_sharedSTXT->setVal(*iterator, shardcst->getResource(MKTAG('S','T','X','T'), *iterator));
}
}
Common::Array<uint16> bmp = shardcst->getResourceIDList(MKTAG('B','I','T','D'));
if (bmp.size() != 0) {
debugC(3, kDebugLoading, "Loading %d BITDs", bmp.size());
for (Common::Array<uint16>::iterator iterator = bmp.begin(); iterator != bmp.end(); ++iterator) {
_sharedBMP->setVal(*iterator, shardcst->getResource(MKTAG('B','I','T','D'), *iterator));
}
}
Common::Array<uint16> sound = shardcst->getResourceIDList(MKTAG('S','N','D',' '));
if (stxt.size() != 0) {
debugC(3, kDebugLoading, "Loading %d SNDs", sound.size());
for (Common::Array<uint16>::iterator iterator = sound.begin(); iterator != sound.end(); ++iterator) {
_sharedSound->setVal(*iterator, shardcst->getResource(MKTAG('S','N','D',' '), *iterator));
}
}
}
示例3: listSavegames
void listSavegames(Common::Array<SavegameDesc> &saves) {
Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
// Load all saves
Common::StringList saveNames = saveFileMan->listSavefiles(((SciEngine *)g_engine)->getSavegamePattern());
for (Common::StringList::const_iterator iter = saveNames.begin(); iter != saveNames.end(); ++iter) {
Common::String filename = *iter;
Common::SeekableReadStream *in;
if ((in = saveFileMan->openForLoading(filename))) {
SavegameMetadata meta;
if (!get_savegame_metadata(in, &meta)) {
// invalid
delete in;
continue;
}
delete in;
SavegameDesc desc;
desc.id = strtol(filename.end() - 3, NULL, 10);
desc.date = meta.savegame_date;
desc.time = meta.savegame_time;
debug(3, "Savegame in file %s ok, id %d", filename.c_str(), desc.id);
saves.push_back(desc);
}
}
// Sort the list by creation date of the saves
qsort(saves.begin(), saves.size(), sizeof(SavegameDesc), _savegame_index_struct_compare);
}
示例4: getInfo
bool SaveReader::getInfo(Common::SeekableReadStream &stream, SavePartInfo &info) {
// Remeber the stream's starting position to seek back to
uint32 startPos = stream.pos();
// Get parts' basic information
Common::Array<SaveContainer::PartInfo> *partsInfo = getPartsInfo(stream);
// No parts => fail
if (!partsInfo) {
stream.seek(startPos);
return false;
}
bool result = false;
// Iterate over all parts
for (Common::Array<SaveContainer::PartInfo>::iterator it = partsInfo->begin();
it != partsInfo->end(); ++it) {
// Check for the info part
if (it->id == SavePartInfo::kID) {
if (!stream.seek(it->offset))
break;
// Read it
result = info.read(stream);
break;
}
}
stream.seek(startPos);
delete partsInfo;
return result;
}
示例5: TreeNode
Node *Tree::aStarSearch_singlePass() {
float currentT = 0.0;
Node *retNode = NULL;
static int maxTime = 0;
if (_currentChildIndex == 1) {
maxTime = _ai->getPlayerMaxTime();
}
if (_currentChildIndex) {
if (!(_currentMap->size())) {
retNode = _currentNode;
return retNode;
}
_currentNode = _currentMap->front()->node;
_currentMap->erase(_currentMap->begin());
}
if ((_currentNode->getDepth() < _maxDepth) && (Node::getNodeCount() < _maxNodes) && ((!maxTime) || (_ai->getTimerValue(3) < maxTime))) {
// Generate nodes
_currentChildIndex = _currentNode->generateChildren();
if (_currentChildIndex) {
Common::Array<Node *> vChildren = _currentNode->getChildren();
if (!vChildren.size() && !_currentMap->size()) {
_currentChildIndex = 0;
retNode = _currentNode;
}
for (Common::Array<Node *>::iterator i = vChildren.begin(); i != vChildren.end(); i++) {
IContainedObject *pTemp = (*i)->getContainedObject();
currentT = pTemp->calcT();
if (currentT == SUCCESS) {
retNode = *i;
i = vChildren.end() - 1;
} else {
_currentMap->insert(new TreeNode(currentT, (*i)));
}
}
if (!(_currentMap->size()) && (currentT != SUCCESS)) {
assert(_currentNode != NULL);
retNode = _currentNode;
}
}
} else {
retNode = _currentNode;
}
return retNode;
}
示例6: run_gc
void run_gc(EngineState *s) {
SegManager *segMan = s->_segMan;
// Some debug stuff
debugC(kDebugLevelGC, "[GC] Running...");
#ifdef GC_DEBUG_CODE
const char *segnames[SEG_TYPE_MAX + 1];
int segcount[SEG_TYPE_MAX + 1];
memset(segnames, 0, sizeof(segnames));
memset(segcount, 0, sizeof(segcount));
#endif
// Compute the set of all segments references currently in use.
AddrSet *activeRefs = findAllActiveReferences(s);
// Iterate over all segments, and check for each whether it
// contains stuff that can be collected.
const Common::Array<SegmentObj *> &heap = segMan->getSegments();
for (uint seg = 1; seg < heap.size(); seg++) {
SegmentObj *mobj = heap[seg];
if (mobj != NULL) {
#ifdef GC_DEBUG_CODE
const SegmentType type = mobj->getType();
segnames[type] = segmentTypeNames[type];
#endif
// Get a list of all deallocatable objects in this segment,
// then free any which are not referenced from somewhere.
const Common::Array<reg_t> tmp = mobj->listAllDeallocatable(seg);
for (Common::Array<reg_t>::const_iterator it = tmp.begin(); it != tmp.end(); ++it) {
const reg_t addr = *it;
if (!activeRefs->contains(addr)) {
// Not found -> we can free it
mobj->freeAtAddress(segMan, addr);
debugC(kDebugLevelGC, "[GC] Deallocating %04x:%04x", PRINT_REG(addr));
#ifdef GC_DEBUG_CODE
segcount[type]++;
#endif
}
}
}
}
delete activeRefs;
#ifdef GC_DEBUG_CODE
// Output debug summary of garbage collection
debugC(kDebugLevelGC, "[GC] Summary:");
for (int i = 0; i <= SEG_TYPE_MAX; i++)
if (segcount[i])
debugC(kDebugLevelGC, "\t%d\t* %s", segcount[i], segnames[i]);
#endif
}
示例7: Cmd_DumpKnowledge
bool Console::Cmd_DumpKnowledge(int argc, const char **argv) {
Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
Common::Array<Resources::Knowledge *> knowledge = level->listChildrenRecursive<Resources::Knowledge>();
knowledge.insert_at(knowledge.size(), location->listChildrenRecursive<Resources::Knowledge>());
Common::Array<Resources::Knowledge *>::iterator it;
for (it = knowledge.begin(); it != knowledge.end(); ++it) {
(*it)->print();
}
return true;
}
示例8: listSaves
virtual SaveStateList listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::String pattern = Common::String::format("%s??", target);
// Get list of savefiles for target game
Common::StringArray filenames = saveFileMan->listSavefiles(pattern);
Common::Array<int> slots;
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
// Obtain the last 2 digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + file->size() - 2);
// Ensure save slot is within valid range
if (slotNum >= 1 && slotNum <= 10) {
slots.push_back(slotNum);
}
}
// Sort save slot ids
Common::sort<int>(slots.begin(), slots.end());
// Load save index
Common::String fileEpa = Common::String::format("%s.epa", target);
Common::InSaveFile *epa = saveFileMan->openForLoading(fileEpa);
// Get savegame names from index
Common::String saveDesc;
SaveStateList saveList;
int line = 1;
for (uint i = 0; i < slots.size(); i++) {
// ignore lines corresponding to unused saveslots
for (; line < slots[i]; line++)
epa->readLine();
// copy the name in the line corresponding to the save slot and truncate to 22 characters
saveDesc = Common::String(epa->readLine().c_str(), 22);
// handle cases where the save directory and save index are detectably out of sync
if (saveDesc == "*")
saveDesc = "No name specified.";
// increment line number to keep it in sync with slot number
line++;
// Insert savegame name into list
saveList.push_back(SaveStateDescriptor(slots[i], saveDesc));
}
delete epa;
return saveList;
}
示例9: initDijkstraNodes
static void initDijkstraNodes(DijkstraNode::Container &dijkstraNodes, const Region ®ion,
const Vertex &start, const Common::Array<Vertex> &nodes) {
// Allocate sufficient space in the array
dijkstraNodes.resize(nodes.size());
// Initialize all the nodes which are visible from the starting node
DijkstraNode::Iter dijkstraIter = dijkstraNodes.begin();
for (Common::Array<Vertex>::const_iterator nodesIter = nodes.begin();
nodesIter != nodes.end(); nodesIter++, dijkstraIter++) {
(*dijkstraIter).parentIter = dijkstraNodes.end();
if (region.isLineOfSight(*nodesIter, start))(*dijkstraIter).cost = (*nodesIter).distance(start);
}
assert(dijkstraIter == dijkstraNodes.end());
}
示例10: if
BaseSurface *BaseFontTT::renderTextToTexture(const WideString &text, int width, TTextAlign align, int maxHeight, int &textOffset) {
//TextLineList lines;
// TODO: Use WideString-conversion here.
//WrapText(text, width, maxHeight, lines);
Common::Array<Common::String> lines;
_font->wordWrapText(text, width, lines);
while (maxHeight > 0 && lines.size() * _lineHeight > maxHeight) {
lines.pop_back();
}
if (lines.size() == 0) {
return nullptr;
}
Graphics::TextAlign alignment = Graphics::kTextAlignInvalid;
if (align == TAL_LEFT) {
alignment = Graphics::kTextAlignLeft;
} else if (align == TAL_CENTER) {
alignment = Graphics::kTextAlignCenter;
} else if (align == TAL_RIGHT) {
alignment = Graphics::kTextAlignRight;
}
debugC(kWintermuteDebugFont, "%s %d %d %d %d", text.c_str(), RGBCOLGetR(_layers[0]->_color), RGBCOLGetG(_layers[0]->_color), RGBCOLGetB(_layers[0]->_color), RGBCOLGetA(_layers[0]->_color));
// void drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const;
Graphics::Surface *surface = new Graphics::Surface();
if (_deletableFont) { // We actually have a TTF
surface->create((uint16)width, (uint16)(_lineHeight * lines.size()), Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24));
} else { // We are using a fallback, they can't do 32bpp
surface->create((uint16)width, (uint16)(_lineHeight * lines.size()), Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0));
}
uint32 useColor = 0xffffffff;
Common::Array<Common::String>::iterator it;
int heightOffset = 0;
for (it = lines.begin(); it != lines.end(); ++it) {
_font->drawString(surface, *it, 0, heightOffset, width, useColor, alignment);
heightOffset += (int)_lineHeight;
}
BaseSurface *retSurface = _gameRef->_renderer->createSurface();
Graphics::Surface *convertedSurface = surface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24));
retSurface->putSurface(*convertedSurface, true);
convertedSurface->free();
surface->free();
delete surface;
delete convertedSurface;
return retSurface;
// TODO: _isUnderline, _isBold, _isItalic, _isStriked
}
示例11: mmfpOpen
Node *Tree::aStarSearch() {
Common::SortedArray<TreeNode *> mmfpOpen(compareTreeNodes);
Node *currentNode = NULL;
float currentT;
Node *retNode = NULL;
float temp = pBaseNode->getContainedObject()->calcT();
if (static_cast<int>(temp) != SUCCESS) {
mmfpOpen.insert(new TreeNode(pBaseNode->getObjectT(), pBaseNode));
while (mmfpOpen.size() && (retNode == NULL)) {
currentNode = mmfpOpen.front()->node;
mmfpOpen.erase(mmfpOpen.begin());
if ((currentNode->getDepth() < _maxDepth) && (Node::getNodeCount() < _maxNodes)) {
// Generate nodes
Common::Array<Node *> vChildren = currentNode->getChildren();
for (Common::Array<Node *>::iterator i = vChildren.begin(); i != vChildren.end(); i++) {
IContainedObject *pTemp = (*i)->getContainedObject();
currentT = pTemp->calcT();
if (currentT == SUCCESS)
retNode = *i;
else
mmfpOpen.insert(new TreeNode(currentT, (*i)));
}
} else {
retNode = currentNode;
}
}
} else {
retNode = pBaseNode;
}
return retNode;
}
示例12: StaticTextWidget
TestbedOptionsDialog::TestbedOptionsDialog(Common::Array<Testsuite *> &tsList, TestbedConfigManager *tsConfMan) : GUI::Dialog("Browser"), _testbedConfMan(tsConfMan) {
new GUI::StaticTextWidget(this, "Browser.Headline", "Select Testsuites to Execute");
new GUI::StaticTextWidget(this, "Browser.Path", "Use Doubleclick to select/deselect");
// Construct a String Array
Common::Array<Testsuite *>::const_iterator iter;
Common::String description;
uint selected = 0;
for (iter = tsList.begin(); iter != tsList.end(); iter++) {
_testSuiteArray.push_back(*iter);
description = (*iter)->getDescription();
if ((*iter)->isEnabled()) {
_testSuiteDescArray.push_back(description + "(selected)");
selected++;
_colors.push_back(GUI::ThemeEngine::kFontColorNormal);
} else {
_testSuiteDescArray.push_back(description);
_colors.push_back(GUI::ThemeEngine::kFontColorAlternate);
}
}
_testListDisplay = new TestbedListWidget(this, "Browser.List", _testSuiteArray);
_testListDisplay->setNumberingMode(GUI::kListNumberingOff);
_testListDisplay->setList(_testSuiteDescArray, &_colors);
// This list shouldn't be editable
_testListDisplay->setEditable(false);
if (selected > (tsList.size() - selected)) {
_selectButton = new GUI::ButtonWidget(this, "Browser.Up", "Deselect All", 0, kTestbedDeselectAll, 0);
} else {
_selectButton = new GUI::ButtonWidget(this, "Browser.Up", "Select All", 0, kTestbedSelectAll, 0);
}
new GUI::ButtonWidget(this, "Browser.Cancel", "Run tests", 0, GUI::kCloseCmd);
new GUI::ButtonWidget(this, "Browser.Choose", "Exit Testbed", 0, kTestbedQuitCmd);
}
示例13: drawTextWithWordWrapping
//.........这里部分代码省略.........
if (stateChanges & TEXT_CHANGE_HAS_STATE_BOX) {
Common::String temp = Common::String::format("%d", _engine->getScriptManager()->getStateValue(currentState._statebox));
wordWidth += font.getStringWidth(temp);
// If the word causes the line to overflow, render the sentence and start a new line
if (lineWidth + sentenceWidth + wordWidth > dest.w) {
textSurfaces.push_back(TextSurface(font.renderSolidText(currentSentence, textColor), sentencePixelOffset, currentLineNumber));
// Set line width
lineWidths.push_back(lineWidth + sentenceWidth - (numSpaces * spaceWidth));
currentSentence.clear();
sentenceWidth = 0;
// Update the offsets
sentencePixelOffset.x = 0u;
sentencePixelOffset.y += lineHeight;
// Reset the line variables
lineHeight = font.getFontHeight();
lineWidth = 0;
++currentLineNumber;
lineJustifications.push_back(currentState._justification);
}
}
} else {
currentWord += text[i];
wordWidth += font.getCharWidth(text[i]);
if (text[i] == ' ') {
// When we hit the first space, flush the current word to the sentence
if (!currentWord.empty()) {
currentSentence += currentWord;
sentenceWidth += wordWidth;
currentWord.clear();
wordWidth = 0;
}
// We track the number of spaces so we can disregard their width in lineWidth calculations
++numSpaces;
} else {
// If the word causes the line to overflow, render the sentence and start a new line
if (lineWidth + sentenceWidth + wordWidth > dest.w) {
// Only render out content
if (!currentSentence.empty()) {
textSurfaces.push_back(TextSurface(font.renderSolidText(currentSentence, currentState.getTextColor(_engine)), sentencePixelOffset, currentLineNumber));
}
// Set line width
lineWidths.push_back(lineWidth + sentenceWidth - (numSpaces * spaceWidth));
currentSentence.clear();
sentenceWidth = 0;
// Update the offsets
sentencePixelOffset.x = 0u;
sentencePixelOffset.y += lineHeight;
// Reset the line variables
lineHeight = font.getFontHeight();
lineWidth = 0;
++currentLineNumber;
lineJustifications.push_back(currentState._justification);
}
numSpaces = 0u;
}
}
i++;
}
// Render out any remaining words/sentences
if (!currentWord.empty() || !currentSentence.empty()) {
currentSentence += currentWord;
sentenceWidth += wordWidth;
textSurfaces.push_back(TextSurface(font.renderSolidText(currentSentence, currentState.getTextColor(_engine)), sentencePixelOffset, currentLineNumber));
}
lineWidths.push_back(lineWidth + sentenceWidth);
lineJustifications.push_back(currentState._justification);
for (Common::Array<TextSurface>::iterator iter = textSurfaces.begin(); iter != textSurfaces.end(); ++iter) {
Common::Rect empty;
if (lineJustifications[iter->_lineNumber] == TEXT_JUSTIFY_LEFT) {
_engine->getRenderManager()->blitSurfaceToSurface(*iter->_surface, empty, dest, iter->_surfaceOffset.x, iter->_surfaceOffset.y, 0);
} else if (lineJustifications[iter->_lineNumber] == TEXT_JUSTIFY_CENTER) {
_engine->getRenderManager()->blitSurfaceToSurface(*iter->_surface, empty, dest, ((dest.w - lineWidths[iter->_lineNumber]) / 2) + iter->_surfaceOffset.x, iter->_surfaceOffset.y, 0);
} else if (lineJustifications[iter->_lineNumber] == TEXT_JUSTIFY_RIGHT) {
_engine->getRenderManager()->blitSurfaceToSurface(*iter->_surface, empty, dest, dest.w - lineWidths[iter->_lineNumber] + iter->_surfaceOffset.x, iter->_surfaceOffset.y, 0);
}
// Release memory
iter->_surface->free();
delete iter->_surface;
}
}
示例14: if
BaseSurface *BaseFontTT::renderTextToTexture(const WideString &text, int width, TTextAlign align, int maxHeight, int &textOffset) {
//TextLineList lines;
// TODO: Use WideString-conversion here.
//WrapText(text, width, maxHeight, lines);
Common::Array<WideString> lines;
_font->wordWrapText(text, width, lines);
while (maxHeight > 0 && lines.size() * _lineHeight > maxHeight) {
lines.pop_back();
}
if (lines.size() == 0) {
return nullptr;
}
Graphics::TextAlign alignment = Graphics::kTextAlignInvalid;
if (align == TAL_LEFT) {
alignment = Graphics::kTextAlignLeft;
} else if (align == TAL_CENTER) {
alignment = Graphics::kTextAlignCenter;
} else if (align == TAL_RIGHT) {
alignment = Graphics::kTextAlignRight;
}
// TODO: This debug call does not work with WideString because text.c_str() returns an uint32 array.
//debugC(kWintermuteDebugFont, "%s %d %d %d %d", text.c_str(), RGBCOLGetR(_layers[0]->_color), RGBCOLGetG(_layers[0]->_color), RGBCOLGetB(_layers[0]->_color), RGBCOLGetA(_layers[0]->_color));
// void drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const;
Graphics::Surface *surface = new Graphics::Surface();
surface->create((uint16)width, (uint16)(_lineHeight * lines.size()), _gameRef->_renderer->getPixelFormat());
uint32 useColor = 0xffffffff;
Common::Array<WideString>::iterator it;
int heightOffset = 0;
for (it = lines.begin(); it != lines.end(); ++it) {
_font->drawString(surface, *it, 0, heightOffset, width, useColor, alignment);
heightOffset += (int)_lineHeight;
}
BaseSurface *retSurface = _gameRef->_renderer->createSurface();
if (_deletableFont) {
// Reconstruct the alpha channel of the font.
// Since we painted it with color 0xFFFFFFFF onto a black background,
// the alpha channel is gone, but the color value of each pixel corresponds
// to its original alpha value.
Graphics::PixelFormat format = _gameRef->_renderer->getPixelFormat();
uint32 *pixels = (uint32 *)surface->getPixels();
// This is a Surface we created ourselves, so no empty space between rows.
for (int i = 0; i < surface->w * surface->h; ++i) {
uint8 a, r, g, b;
format.colorToRGB(*pixels, r, g, b);
a = r;
*pixels++ = format.ARGBToColor(a, r, g, b);
}
}
retSurface->putSurface(*surface, true);
surface->free();
delete surface;
return retSurface;
// TODO: _isUnderline, _isBold, _isItalic, _isStriked
}
示例15: scCallMethod
//.........这里部分代码省略.........
stack->correctParams(2);
const char *strToFind = stack->pop()->getString();
int index = stack->pop()->getInt();
WideString str;
if (_gameRef->_textEncoding == TEXT_UTF8) {
str = StringUtil::utf8ToWide(_string);
} else {
str = StringUtil::ansiToWide(_string);
}
WideString toFind;
if (_gameRef->_textEncoding == TEXT_UTF8) {
toFind = StringUtil::utf8ToWide(strToFind);
} else {
toFind = StringUtil::ansiToWide(strToFind);
}
int indexOf = StringUtil::indexOf(str, toFind, index);
stack->pushInt(indexOf);
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// Split
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "Split") == 0) {
stack->correctParams(1);
ScValue *val = stack->pop();
char separators[MAX_PATH_LENGTH] = ",";
if (!val->isNULL()) {
strcpy(separators, val->getString());
}
SXArray *array = new SXArray(_gameRef);
if (!array) {
stack->pushNULL();
return STATUS_OK;
}
WideString str;
if (_gameRef->_textEncoding == TEXT_UTF8) {
str = StringUtil::utf8ToWide(_string);
} else {
str = StringUtil::ansiToWide(_string);
}
WideString delims;
if (_gameRef->_textEncoding == TEXT_UTF8) {
delims = StringUtil::utf8ToWide(separators);
} else {
delims = StringUtil::ansiToWide(separators);
}
Common::Array<WideString> parts;
uint32 start = 0;
for(uint32 i = 0; i < str.size() + 1; i++) {
char ch = str.c_str()[i];
if(ch=='\0' || delims.contains(ch))
{
char *part = new char[i - start + 1];
if(i != start) {
Common::strlcpy(part, str.c_str() + start, i - start + 1);
part[i - start] = '\0';
} else {
part[0] = '\0';
}
val = new ScValue(_gameRef, part);
array->push(val);
delete[] part;
delete val;
val = nullptr;
start = i + 1;
}
}
for (Common::Array<WideString>::iterator it = parts.begin(); it != parts.end(); ++it) {
WideString &part = (*it);
if (_gameRef->_textEncoding == TEXT_UTF8) {
val = new ScValue(_gameRef, StringUtil::wideToUtf8(part).c_str());
} else {
val = new ScValue(_gameRef, StringUtil::wideToAnsi(part).c_str());
}
array->push(val);
delete val;
val = nullptr;
}
stack->pushNative(array, false);
return STATUS_OK;
} else {
return STATUS_FAILED;
}
}