当前位置: 首页>>代码示例>>C++>>正文


C++ Array::end方法代码示例

本文整理汇总了C++中common::Array::end方法的典型用法代码示例。如果您正苦于以下问题:C++ Array::end方法的具体用法?C++ Array::end怎么用?C++ Array::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common::Array的用法示例。


在下文中一共展示了Array::end方法的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));
		}
	}
}
开发者ID:iskrich,项目名称:director,代码行数:55,代码来源:director.cpp

示例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));
		}
	}
}
开发者ID:RobLoach,项目名称:scummvm,代码行数:55,代码来源:archive.cpp

示例3: 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;
}
开发者ID:m-kiewitz,项目名称:scummvm,代码行数:55,代码来源:ai_tree.cpp

示例4: duplicateTree

void Tree::duplicateTree(Node *sourceNode, Node *destNode) {
    Common::Array<Node *> vUnvisited = sourceNode->getChildren();

    while (vUnvisited.size()) {
        Node *newNode = new Node(*(vUnvisited.end()));
        newNode->setParent(destNode);
        (destNode->getChildren()).push_back(newNode);
        duplicateTree(*(vUnvisited.end()), newNode);
        vUnvisited.pop_back();
    }
}
开发者ID:m-kiewitz,项目名称:scummvm,代码行数:11,代码来源:ai_tree.cpp

示例5: 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;
}
开发者ID:St0rmcrow,项目名称:scummvm,代码行数:34,代码来源:savefile.cpp

示例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
}
开发者ID:86400,项目名称:scummvm,代码行数:55,代码来源:gc.cpp

示例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;
}
开发者ID:Botje,项目名称:residualvm,代码行数:11,代码来源:console.cpp

示例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;
    }
开发者ID:Coworker,项目名称:scummvm,代码行数:51,代码来源:detection.cpp

示例9: initDijkstraNodes

static void initDijkstraNodes(DijkstraNode::Container &dijkstraNodes, const Region &region,
                              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());
}
开发者ID:dergunov,项目名称:scummvm,代码行数:14,代码来源:walkregion.cpp

示例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
}
开发者ID:CatalystG,项目名称:scummvm,代码行数:49,代码来源:base_font_truetype.cpp

示例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;
}
开发者ID:m-kiewitz,项目名称:scummvm,代码行数:40,代码来源:ai_tree.cpp

示例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);
}
开发者ID:MaddTheSane,项目名称:scummvm,代码行数:38,代码来源:config.cpp

示例13: drawTextWithWordWrapping

void TextRenderer::drawTextWithWordWrapping(const Common::String &text, Graphics::Surface &dest) {
	Common::Array<TextSurface> textSurfaces;
	Common::Array<uint> lineWidths;
	Common::Array<TextJustification> lineJustifications;

	// Create the initial text state
	TextStyleState currentState;

	// Create an empty font and bind it to the state
	StyledTTFont font(_engine);
	currentState.updateFontWithTextState(font);

	Common::String currentSentence; // Not a true 'grammatical' sentence. Rather, it's just a collection of words
	Common::String currentWord;
	int sentenceWidth = 0;
	int wordWidth = 0;
	int lineWidth = 0;
	int lineHeight = font.getFontHeight();

	uint currentLineNumber = 0u;

	uint numSpaces = 0u;
	int spaceWidth = 0;

	// The pixel offset to the currentSentence
	Common::Point sentencePixelOffset;

	uint i = 0u;
	uint stringlen = text.size();

	while (i < stringlen) {
		if (text[i] == '<') {
			// Flush the currentWord to the currentSentence
			currentSentence += currentWord;
			sentenceWidth += wordWidth;

			// Reset the word variables
			currentWord.clear();
			wordWidth = 0;

			// Parse the style tag
			uint startTextPosition = i;
			while (i < stringlen && text[i] != '>') {
				++i;
			}
			uint endTextPosition = i;

			uint32 textColor = currentState.getTextColor(_engine);

			uint stateChanges = 0u;
			if ((endTextPosition - startTextPosition - 1) > 0) {
				stateChanges = currentState.parseStyle(Common::String(text.c_str() + startTextPosition + 1), endTextPosition - startTextPosition - 1);
			}

			if (stateChanges & (TEXT_CHANGE_FONT_TYPE | TEXT_CHANGE_FONT_STYLE)) {
				// Use the last state to render out the current sentence
				// Styles apply to the text 'after' them
				if (!currentSentence.empty()) {
					textSurfaces.push_back(TextSurface(font.renderSolidText(currentSentence, textColor), sentencePixelOffset, currentLineNumber));

					lineWidth += sentenceWidth;
					sentencePixelOffset.x += sentenceWidth;

					// Reset the sentence variables
					currentSentence.clear();
					sentenceWidth = 0;
				}

				// Update the current state with the style information
				currentState.updateFontWithTextState(font);

				lineHeight = MAX(lineHeight, font.getFontHeight());
				spaceWidth = font.getCharWidth(' ');
			}
			if (stateChanges & TEXT_CHANGE_NEWLINE) {
				// If the current sentence has content, render it out
				if (!currentSentence.empty()) {
					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);
			}
			if (stateChanges & TEXT_CHANGE_HAS_STATE_BOX) {
				Common::String temp = Common::String::format("%d", _engine->getScriptManager()->getStateValue(currentState._statebox));
				wordWidth += font.getStringWidth(temp);

//.........这里部分代码省略.........
开发者ID:86400,项目名称:scummvm,代码行数:101,代码来源:text.cpp

示例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
}
开发者ID:AReim1982,项目名称:scummvm,代码行数:63,代码来源:base_font_truetype.cpp

示例15: scCallMethod

bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) {
	//////////////////////////////////////////////////////////////////////////
	// Substring
	//////////////////////////////////////////////////////////////////////////
	if (strcmp(name, "Substring") == 0) {
		stack->correctParams(2);
		int start = stack->pop()->getInt();
		int end   = stack->pop()->getInt();

		if (end < start) {
			BaseUtils::swap(&start, &end);
		}

		//try {
		WideString str;
		if (_gameRef->_textEncoding == TEXT_UTF8) {
			str = StringUtil::utf8ToWide(_string);
		} else {
			str = StringUtil::ansiToWide(_string);
		}

		//WideString subStr = str.substr(start, end - start + 1);
		WideString subStr(str.c_str() + start, end - start + 1);

		if (_gameRef->_textEncoding == TEXT_UTF8) {
			stack->pushString(StringUtil::wideToUtf8(subStr).c_str());
		} else {
			stack->pushString(StringUtil::wideToAnsi(subStr).c_str());
		}
		//  } catch (std::exception &) {
		//      stack->pushNULL();
		//  }

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Substr
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Substr") == 0) {
		stack->correctParams(2);
		int start = stack->pop()->getInt();

		ScValue *val = stack->pop();
		int len = val->getInt();

		if (!val->isNULL() && len <= 0) {
			stack->pushString("");
			return STATUS_OK;
		}

		if (val->isNULL()) {
			len = strlen(_string) - start;
		}

//		try {
		WideString str;
		if (_gameRef->_textEncoding == TEXT_UTF8) {
			str = StringUtil::utf8ToWide(_string);
		} else {
			str = StringUtil::ansiToWide(_string);
		}

//			WideString subStr = str.substr(start, len);
		WideString subStr(str.c_str() + start, len);

		if (_gameRef->_textEncoding == TEXT_UTF8) {
			stack->pushString(StringUtil::wideToUtf8(subStr).c_str());
		} else {
			stack->pushString(StringUtil::wideToAnsi(subStr).c_str());
		}
//		} catch (std::exception &) {
//			stack->pushNULL();
//		}

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// ToUpperCase
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "ToUpperCase") == 0) {
		stack->correctParams(0);

		WideString str;
		if (_gameRef->_textEncoding == TEXT_UTF8) {
			str = StringUtil::utf8ToWide(_string);
		} else {
			str = StringUtil::ansiToWide(_string);
		}

		str.toUppercase();

		if (_gameRef->_textEncoding == TEXT_UTF8) {
			stack->pushString(StringUtil::wideToUtf8(str).c_str());
		} else {
			stack->pushString(StringUtil::wideToAnsi(str).c_str());
		}

		return STATUS_OK;
//.........这里部分代码省略.........
开发者ID:CatalystG,项目名称:scummvm,代码行数:101,代码来源:script_ext_string.cpp


注:本文中的common::Array::end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。