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


C++ String::deleteChar方法代码示例

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


在下文中一共展示了String::deleteChar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: themeConfigParseHeader

bool ThemeEngine::themeConfigParseHeader(Common::String header, Common::String &themeName) {
	// Check that header is not corrupted
	if ((byte)header[0] > 127) {
		warning("Corrupted theme header found");
		return false;
	}

	header.trim();

	if (header.empty())
		return false;

	if (header[0] != '[' || header.lastChar() != ']')
		return false;

	header.deleteChar(0);
	header.deleteLastChar();

	Common::StringTokenizer tok(header, ":");

	if (tok.nextToken() != SCUMMVM_THEME_VERSION_STR)
		return false;

	themeName = tok.nextToken();
	Common::String author = tok.nextToken();

	return tok.empty();
}
开发者ID:megaboy,项目名称:scummvm,代码行数:28,代码来源:ThemeEngine.cpp

示例2: translateFileName

Common::String Resource::translateFileName(const Common::String filename) {
	Common::String upperFilename = filename;
	upperFilename.toUppercase();
	Common::String fileNameStrFinal;

	if (upperFilename.hasPrefix("P:") || upperFilename.hasPrefix("F:")) {
		if (_vm->_isHiRes)
			fileNameStrFinal = "SPICT/";
		else
			fileNameStrFinal = "PICT/";

		if (_vm->getPlatform() == Common::kPlatformAmiga) {
			if (upperFilename.hasPrefix("P:")) {
				fileNameStrFinal = "PICT/";
			} else {
				fileNameStrFinal = "LABFONTS/";
				upperFilename += "T";	// all the Amiga fonts have a ".FONT" suffix
			}
		}
	} else if (upperFilename.hasPrefix("LAB:")) {
		// Look inside the game folder
	} else if (upperFilename.hasPrefix("MUSIC:")) {
		fileNameStrFinal = "MUSIC/";
	}

	if (upperFilename.contains(':')) {
		while (upperFilename[0] != ':') {
			upperFilename.deleteChar(0);
		}

		upperFilename.deleteChar(0);
	}

	fileNameStrFinal += upperFilename;

	return fileNameStrFinal;
}
开发者ID:ScummQuest,项目名称:scummvm,代码行数:37,代码来源:resource.cpp

示例3: handle

void ResourceHandler::handle(Client &client) {
	Common::String filename = client.path();
	filename.deleteChar(0);

	// if archive hidden file is requested, ignore
	if (filename.size() && filename[0] == '.')
		return;

	// if file not found, don't set handler either
	Common::SeekableReadStream *file = HandlerUtils::getArchiveFile(filename);
	if (file == nullptr)
		return;

	LocalWebserver::setClientGetHandler(client, file, 200, determineMimeType(filename));
}
开发者ID:Tkachov,项目名称:scummvm,代码行数:15,代码来源:resourcehandler.cpp

示例4: Cmd_PlayText

bool Debugger::Cmd_PlayText(int argc, const char **argv) {
	if (argc != 2) {
		debugPrintf("Usage: %s <text name>\n", argv[0]);
		return true;
	} else {
		Common::String resName = argv[1];
		if (resName.hasPrefix("@"))
			resName.deleteChar(0);

		Common::File f;
		if (f.exists(resName) || f.exists(resName + ".txr")) {
			TextView::execute(_vm, resName);
			return false;
		} else {
			debugPrintf("Could not find resource file\n");
			return true;
		}
	}
}
开发者ID:AReim1982,项目名称:scummvm,代码行数:19,代码来源:debugger.cpp

示例5: themeConfigParseHeader

bool ThemeEngine::themeConfigParseHeader(Common::String header, Common::String &themeName) {
	header.trim();

	if (header.empty())
		return false;

	if (header[0] != '[' || header.lastChar() != ']')
		return false;

	header.deleteChar(0);
	header.deleteLastChar();

	Common::StringTokenizer tok(header, ":");

	if (tok.nextToken() != RESIDUAL_THEME_VERSION_STR)
		return false;

	themeName = tok.nextToken();
	Common::String author = tok.nextToken();

	return tok.empty();
}
开发者ID:Templier,项目名称:residual,代码行数:22,代码来源:ThemeEngine.cpp

示例6: loadSubtitles

void Subtitles::loadSubtitles() {
	File f("special.bin");

	if (!g_vm->_files->_ccNum) {
		// The first subtitle line contains all the text for the Clouds intro. Since ScummVM allows
		// both voice and subtitles at the same time, unlike the original, we need to split up the
		// first subtitle into separate lines to allow them to better interleave with the voice
		Common::String line = f.readString();
		for (;;) {
			const char *lineSep = strstr(line.c_str(), "   ");
			if (!lineSep)
				break;

			_lines.push_back(Common::String(line.c_str(), lineSep));
			line = Common::String(lineSep + 3);
			while (line.hasPrefix(" "))
				line.deleteChar(0);
		}
	}

	while (f.pos() < f.size())
		_lines.push_back(f.readString());
	f.close();
}
开发者ID:BenCastricum,项目名称:scummvm,代码行数:24,代码来源:subtitles.cpp

示例7: readSelectorValue

void GfxControls32::kernelTexteditChange(reg_t controlObject) {
	SciEvent curEvent;
	uint16 maxChars = readSelectorValue(_segMan, controlObject, SELECTOR(max));
	reg_t textReference = readSelector(_segMan, controlObject, SELECTOR(text));
	GfxFont *font = _cache->getFont(readSelectorValue(_segMan, controlObject, SELECTOR(font)));
	Common::String text;
	uint16 textSize;
	bool textChanged = false;
	bool textAddChar = false;
	Common::Rect rect;

	if (textReference.isNull())
		error("kEditControl called on object that doesnt have a text reference");
	text = _segMan->getString(textReference);

	// TODO: Finish this, add a loop etc
	warning("kEditText ('%s')", text.c_str());
	return;

	uint16 cursorPos = 0;
	//uint16 oldCursorPos = cursorPos;

	curEvent = g_sci->getEventManager()->getSciEvent(SCI_EVENT_KEYBOARD);
	if (curEvent.type != SCI_EVENT_NONE) {
		textSize = text.size();

		switch (curEvent.type) {
		case SCI_EVENT_MOUSE_PRESS:
			// TODO: Implement mouse support for cursor change
			break;
		case SCI_EVENT_KEYBOARD:
			switch (curEvent.data) {
			case SCI_KEY_BACKSPACE:
				if (cursorPos > 0) {
					cursorPos--; text.deleteChar(cursorPos);
					textChanged = true;
				}
				break;
			case SCI_KEY_DELETE:
				if (cursorPos < textSize) {
					text.deleteChar(cursorPos);
					textChanged = true;
				}
				break;
			case SCI_KEY_HOME: // HOME
				cursorPos = 0; textChanged = true;
				break;
			case SCI_KEY_END: // END
				cursorPos = textSize; textChanged = true;
				break;
			case SCI_KEY_LEFT: // LEFT
				if (cursorPos > 0) {
					cursorPos--; textChanged = true;
				}
				break;
			case SCI_KEY_RIGHT: // RIGHT
				if (cursorPos + 1 <= textSize) {
					cursorPos++; textChanged = true;
				}
				break;
			case 3:	// returned in SCI1 late and newer when Control - C is pressed
				if (curEvent.modifiers & SCI_KEYMOD_CTRL) {
					// Control-C erases the whole line
					cursorPos = 0; text.clear();
					textChanged = true;
				}
				break;
			default:
				if ((curEvent.modifiers & SCI_KEYMOD_CTRL) && curEvent.data == 99) {
					// Control-C in earlier SCI games (SCI0 - SCI1 middle)
					// Control-C erases the whole line
					cursorPos = 0; text.clear();
					textChanged = true;
				} else if (curEvent.data > 31 && curEvent.data < 256 && textSize < maxChars) {
					// insert pressed character
					textAddChar = true;
					textChanged = true;
				}
				break;
			}
			break;
		}
	}

	if (textChanged) {
		rect = g_sci->_gfxCompare->getNSRect(controlObject);

		if (textAddChar) {
			const char *textPtr = text.c_str();

			// We check if we are really able to add the new char
			uint16 textWidth = 0;
			while (*textPtr)
				textWidth += font->getCharWidth((byte)*textPtr++);
			textWidth += font->getCharWidth(curEvent.data);

			// Does it fit?
			if (textWidth >= rect.width()) {
				return;
			}
//.........这里部分代码省略.........
开发者ID:dividedmind,项目名称:scummvm,代码行数:101,代码来源:controls32.cpp

示例8:

Stxt::Stxt(Common::SeekableSubReadStreamEndian &textStream) {
	// TODO: Side effects on textStream make this a little hard to understand in context?
	uint32 unk1 = textStream.readUint32();
	uint32 strLen = textStream.readUint32();
	uint32 dataLen = textStream.readUint32();
	Common::String text;

	for (uint32 i = 0; i < strLen; i++) {
		byte ch = textStream.readByte();
		if (ch == 0x0d) {
			ch = '\n';
		}
		text += ch;
	}
	debugC(3, kDebugText, "Stxt init: unk1: %d strLen: %d dataLen: %d textlen: %u", unk1, strLen, dataLen, text.size());
	if (strLen < 200)
		debugC(3, kDebugText, "text: '%s'", text.c_str());

	uint16 formattingCount = textStream.readUint16();
	uint32 prevPos = 0;

	while (formattingCount) {
		uint32 formatStartOffset = textStream.readUint32();
		uint16 unk1f = textStream.readUint16();
		uint16 unk2f = textStream.readUint16();

		_fontId = textStream.readUint16();
		_textSlant = textStream.readByte();
		byte unk3f = textStream.readByte();
		_fontSize = textStream.readUint16();

		_palinfo1 = textStream.readUint16();
		_palinfo2 = textStream.readUint16();
		_palinfo3 = textStream.readUint16();

		debugC(3, kDebugText, "Stxt init: formattingCount: %u, formatStartOffset: %d, unk1: %d unk2: %d, fontId: %d, textSlant: %d",
			   formattingCount, formatStartOffset, unk1f, unk2f, _fontId, _textSlant);

		debugC(3, kDebugText, "        unk3: %d, fontSize: %d, p0: %x p1: %x p2: %x", unk3f, _fontSize, _palinfo1, _palinfo2, _palinfo3);

		assert(prevPos <= formatStartOffset);  // If this is triggered, we have to implement sorting

		while (prevPos != formatStartOffset) {
			char f = text.firstChar();
			_ftext += text.firstChar();
			text.deleteChar(0);

			if (f == '\001')    // Insert two \001s as a replacement
				_ftext += '\001';

			prevPos++;

			debugCN(4, kDebugText, "%c", f);
		}

		debugCN(4, kDebugText, "*");

		_ftext += Common::String::format("\001\015%c%c%c%c%c%c%c%c%c%c%c%c",
										 (_fontId >> 8) & 0xff, _fontId & 0xff,
										 _textSlant & 0xff, unk3f & 0xff,
										 (_fontSize >> 8) & 0xff, _fontSize & 0xff,
										 (_palinfo1 >> 8) & 0xff, _palinfo1 & 0xff,
										 (_palinfo2 >> 8) & 0xff, _palinfo2 & 0xff,
										 (_palinfo3 >> 8) & 0xff, _palinfo3 & 0xff);

		formattingCount--;
	}

	debugC(4, kDebugText, "%s", text.c_str());
	_ftext += text;
}
开发者ID:DrItanium,项目名称:scummvm,代码行数:71,代码来源:stxt.cpp

示例9: createBitmap


//.........这里部分代码省略.........
	int maxLineWidth = 0;
	for (int i = 0; i < (int)msg.size(); i++) {
		lineWidth += MAX(_font->getCharWidth(msg[i]), _font->getCharDataWidth(msg[i]));
		if (lineWidth > maxWidth) {
			if (message.contains(' ')) {
				while (msg[i] != ' ' && i > 0) {
					lineWidth -= MAX(_font->getCharWidth(msg[i]), _font->getCharDataWidth(msg[i]));
					message.deleteLastChar();
					--i;
				} 
			} else if (msg[i] != ' ') { // if it is a unique word
				int dashWidth = MAX(_font->getCharWidth('-'), _font->getCharDataWidth('-'));
				while (lineWidth + dashWidth > maxWidth) {
					lineWidth -= MAX(_font->getCharWidth(msg[i]), _font->getCharDataWidth(msg[i]));
					message.deleteLastChar();
					--i;
				}
				message += '-';
 			}
			message += '\n';
			_numberLines++;

			if (lineWidth > maxLineWidth) {
				maxLineWidth = lineWidth;
			}
			lineWidth = 0;

			continue; // don't add the space back
		}

		if (lineWidth > maxLineWidth)
			maxLineWidth = lineWidth;

		message += msg[i];
	}

	// If the text object is a speech subtitle, the y parameter is the
	// coordinate of the bottom of the text block (instead of the top). It means
	// that every extra line pushes the previous lines up, instead of being
	// printed further down the screen.
	const int SCREEN_TOP_MARGIN = 16;
	if (_isSpeech) {
		_y -= _numberLines * _font->getHeight();
		if (_y < SCREEN_TOP_MARGIN) {
			_y = SCREEN_TOP_MARGIN;
		}
	}

	_textObjectHandle = (GfxBase::TextObjectHandle **)malloc(sizeof(long) * _numberLines);
	_bitmapWidthPtr = new int[_numberLines];

	for (int j = 0; j < _numberLines; j++) {
		int nextLinePos, cutLen;
		const char *pos = strchr(message.c_str(), '\n');
		if (pos) {
			nextLinePos = pos - message.c_str();
			cutLen = nextLinePos + 1;
		} else {
			nextLinePos = message.size();
			cutLen = nextLinePos;
		}
		Common::String currentLine(message.c_str(), message.c_str() + nextLinePos);

		_bitmapWidthPtr[j] = 0;
		for (unsigned int i = 0; i < currentLine.size(); ++i) {
			_bitmapWidthPtr[j] += MAX(_font->getCharWidth(currentLine[i]), _font->getCharDataWidth(currentLine[i]));
		}

		_textBitmap = new uint8[_font->getHeight() * (_bitmapWidthPtr[j] + 1)];
		memset(_textBitmap, 0, _font->getHeight() * (_bitmapWidthPtr[j] + 1));

		// Fill bitmap
		int startOffset = 0;
		for (unsigned int d = 0; d < currentLine.size(); d++) {
			int ch = currentLine[d];
			int8 startingLine = _font->getCharStartingLine(ch) + _font->getBaseOffsetY();
			int32 charDataWidth = _font->getCharDataWidth(ch);
			int32 charWidth = _font->getCharWidth(ch);
			int8 startingCol = _font->getCharStartingCol(ch);
			for (int line = 0; line < _font->getCharDataHeight(ch); line++) {
				int offset = startOffset + ((_bitmapWidthPtr[j] + 1) * (line + startingLine));
				for (int r = 0; r < charDataWidth; r++) {
					const byte pixel = *(_font->getCharData(ch) + r + (charDataWidth * line));
					byte *dst = _textBitmap + offset + startingCol + r;
					if (*dst == 0 && pixel != 0)
						_textBitmap[offset + startingCol + r] = pixel;
				}
				if (line + startingLine >= _font->getHeight())
					break;
			}
			startOffset += charWidth;
		}

		_textObjectHandle[j] = g_driver->createTextBitmap(_textBitmap, _bitmapWidthPtr[j] + 1, _font->getHeight(), _fgColor);
		delete[] _textBitmap;
		for (int count = 0; count < cutLen; count++)
			message.deleteChar(0);
	}
	_created = true;
}
开发者ID:jvprat,项目名称:residual,代码行数:101,代码来源:textobject.cpp

示例10: show

void EndCredits::show() {
	_vm->_mouse->disable();
	_vm->_mixer->stopAll();
	_vm->_ambientSounds->removeAllNonLoopingSounds(true);
	_vm->_ambientSounds->removeAllLoopingSounds(4);
	_vm->_audioSpeech->stopSpeech();

	_vm->_music->play(_vm->_gameInfo->getMusicTrack(17), 100, 0, 2, -1, 0, 3);

	Font *fontBig = new Font(_vm);
	fontBig->open("TAHOMA24.FON", 640, 480, -1, 0, 0);
	fontBig->setSpacing(1, 0);

	Font *fontSmall = new Font(_vm);
	fontSmall->open("TAHOMA18.FON", 640, 480, -1, 0, 0);
	fontSmall->setSpacing(1, 0);

	TextResource *textResource = new TextResource(_vm);
	textResource->open("ENDCRED");

	int textCount = textResource->getCount();
	int *textPositions = (int *)malloc(textCount * sizeof(int));
	int y = 452;
	bool small = false;

	for (int i = 0; i < textCount; i++) {
		Common::String s = textResource->getText(i);
		if (s.hasPrefix("^")) {
			if (!small) {
				y += 28;
			}
			small = false;
		} else {
			if (small) {
				y += 24;
			} else {
				y += 28;
			}
			small = true;
		}
		if (s.hasPrefix("^")) {
			textPositions[i] = y;
		} else {
			textPositions[i] = y + 2;
		}
	}

	_vm->_vqaIsPlaying = true;
	_vm->_vqaStopIsRequested = false;

	double position = 0.0;
	uint32 timeLast = _vm->getTotalPlayTime(); // Original game is using system timer

	while (!_vm->_vqaStopIsRequested && !_vm->shouldQuit()) {
		if (position >= textPositions[textCount - 1]) {
			break;
		}

		//soundSystem::tick(SoundSystem);
		_vm->handleEvents();

		if (!_vm->_gameIsRunning) {
			timeLast = _vm->getTotalPlayTime(); // Original game is using system timer

			continue;
		}

		uint32 timeNow = _vm->getTotalPlayTime(); // Original game is using system timer
		position += (double)(timeNow - timeLast) * 0.05f;
		timeLast = timeNow;

		_vm->_surfaceFront.fillRect(Common::Rect(640, 480), 0);

		for (int i = 0; i < textCount; i++) {
			Common::String s = textResource->getText(i);
			Font *font;
			int height;

			if (s.hasPrefix("^")) {
				font = fontBig;
				height = 28;
				s.deleteChar(0);
			} else {
				font = fontSmall;
				height = 24;
			}

			y = textPositions[i] - (int)position;

			if (y < 452 && y + height > 28) {
				int x;

				if (font == fontBig) {
					x = 280;
				} else {
					x = 270 - font->getTextWidth(s);
				}

				font->draw(s, _vm->_surfaceFront, x, y);
			}
//.........这里部分代码省略.........
开发者ID:Templier,项目名称:scummvm,代码行数:101,代码来源:end_credits.cpp

示例11: readSelectorValue

void GfxControls16::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
	uint16 cursorPos = readSelectorValue(_segMan, controlObject, SELECTOR(cursor));
	uint16 maxChars = readSelectorValue(_segMan, controlObject, SELECTOR(max));
	reg_t textReference = readSelector(_segMan, controlObject, SELECTOR(text));
	Common::String text;
	uint16 textSize, eventType, eventKey = 0, modifiers = 0;
	bool textChanged = false;
	bool textAddChar = false;
	Common::Rect rect;

	if (textReference.isNull())
		error("kEditControl called on object that doesnt have a text reference");
	text = _segMan->getString(textReference);

	uint16 oldCursorPos = cursorPos;

	if (!eventObject.isNull()) {
		textSize = text.size();
		eventType = readSelectorValue(_segMan, eventObject, SELECTOR(type));

		switch (eventType) {
		case SCI_EVENT_MOUSE_PRESS:
			// TODO: Implement mouse support for cursor change
			break;
		case SCI_EVENT_KEYBOARD:
			eventKey = readSelectorValue(_segMan, eventObject, SELECTOR(message));
			modifiers = readSelectorValue(_segMan, eventObject, SELECTOR(modifiers));
			switch (eventKey) {
			case SCI_KEY_BACKSPACE:
				if (cursorPos > 0) {
					cursorPos--; text.deleteChar(cursorPos);
					textChanged = true;
				}
				break;
			case SCI_KEY_DELETE:
				if (cursorPos < textSize) {
					text.deleteChar(cursorPos);
					textChanged = true;
				}
				break;
			case SCI_KEY_HOME: // HOME
				cursorPos = 0; textChanged = true;
				break;
			case SCI_KEY_END: // END
				cursorPos = textSize; textChanged = true;
				break;
			case SCI_KEY_LEFT: // LEFT
				if (cursorPos > 0) {
					cursorPos--; textChanged = true;
				}
				break;
			case SCI_KEY_RIGHT: // RIGHT
				if (cursorPos + 1 <= textSize) {
					cursorPos++; textChanged = true;
				}
				break;
			case 3:	// returned in SCI1 late and newer when Control - C is pressed
				if (modifiers & SCI_KEYMOD_CTRL) {
					// Control-C erases the whole line
					cursorPos = 0; text.clear();
					textChanged = true;
				}
				break;
			default:
				if ((modifiers & SCI_KEYMOD_CTRL) && eventKey == 99) {
					// Control-C in earlier SCI games (SCI0 - SCI1 middle)
					// Control-C erases the whole line
					cursorPos = 0; text.clear();
					textChanged = true;
				} else if (eventKey > 31 && eventKey < 256 && textSize < maxChars) {
					// insert pressed character
					textAddChar = true;
					textChanged = true;
				}
				break;
			}
			break;
		}
	}

	if (g_sci->getVocabulary() && !textChanged && oldCursorPos != cursorPos) {
		assert(!textAddChar);
		textChanged = g_sci->getVocabulary()->checkAltInput(text, cursorPos);
	}

	if (textChanged) {
		GuiResourceId oldFontId = _text16->GetFontId();
		GuiResourceId fontId = readSelectorValue(_segMan, controlObject, SELECTOR(font));
		rect = g_sci->_gfxCompare->getNSRect(controlObject);

		_text16->SetFont(fontId);
		if (textAddChar) {

			const char *textPtr = text.c_str();

			// We check if we are really able to add the new char
			uint16 textWidth = 0;
			while (*textPtr)
				textWidth += _text16->_font->getCharWidth((byte)*textPtr++);
			textWidth += _text16->_font->getCharWidth(eventKey);
//.........这里部分代码省略.........
开发者ID:pdpdds,项目名称:scummvm,代码行数:101,代码来源:controls16.cpp

示例12: createCommandsMenu

void Menu::createCommandsMenu(MenuItem *menu) {
	Common::String string(_gui->_engine->_world->_commandsMenu);

	Common::String item;

	for (uint i = 0; i < string.size(); i++) {
		while(i < string.size() && string[i] != ';') // Read token
			item += string[i++];

		if (item == "(-") {
			menu->subitems.push_back(new MenuSubItem(NULL, 0));
		} else {
			bool enabled = true;
			int style = 0;
			char shortcut = 0;
			const char *shortPtr = strrchr(item.c_str(), '/');
			if (shortPtr != NULL) {
				if (strlen(shortPtr) >= 2) {
					shortcut = shortPtr[1];
					item.deleteChar(shortPtr - item.c_str());
					item.deleteChar(shortPtr - item.c_str());
				} else {
					error("Unexpected shortcut: '%s', item '%s' in menu '%s'", shortPtr, item.c_str(), string.c_str());
				}
			}

			while (item.size() >= 2 && item[item.size() - 2] == '<') {
				char c = item.lastChar();
				if (c == 'B') {
					style |= kFontStyleBold;
				} else if (c == 'I') {
					style |= kFontStyleItalic;
				} else if (c == 'U') {
					style |= kFontStyleUnderline;
				} else if (c == 'O') {
					style |= kFontStyleOutline;
				} else if (c == 'S') {
					style |= kFontStyleShadow;
				} else if (c == 'C') {
					style |= kFontStyleCondensed;
				} else if (c == 'E') {
					style |= kFontStyleExtended;
				}
				item.deleteLastChar();
				item.deleteLastChar();
			}

			Common::String tmpitem(item);
			tmpitem.trim();
			if (tmpitem[0] == '(') {
				enabled = false;

				for (uint j = 0; j < item.size(); j++)
					if (item[j] == '(') {
						item.deleteChar(j);
						break;
					}
			}

			menu->subitems.push_back(new MenuSubItem(item.c_str(), kMenuActionCommand, style, shortcut, enabled));
		}

		item.clear();
	}
}
开发者ID:Deledrius,项目名称:scummvm,代码行数:65,代码来源:menu.cpp

示例13: getFilename

bool WidgetFiles::getFilename() {
	Events &events = *_vm->_events;
	TattooScene &scene = *(TattooScene *)_vm->_scene;
	Screen &screen = *_vm->_screen;
	Talk &talk = *_vm->_talk;
	int index = 0;
	int done = 0;
	bool blinkFlag = false;
	int blinkCountdown = 0;
	int cursorColor = 192;
	byte color, textColor;
	bool insert = true;

	assert(_selector != -1);
	Common::Point pt(_surface.stringWidth("00.") + _surface.widestChar() + 5,
		_surface.fontHeight() + 14 + (_selector - _savegameIndex) * (_surface.fontHeight() + 1));

	Common::String numStr = Common::String::format("%d.", _selector + 1);
	_surface.writeString(numStr, Common::Point(_surface.widestChar(), pt.y), COMMAND_HIGHLIGHTED);

	Common::String filename = _savegames[_selector];

	if (isSlotEmpty(_selector)) {
		index = 0;
		_surface.fillRect(Common::Rect(pt.x, pt.y, _bounds.right - BUTTON_SIZE - 9, pt.y + _surface.fontHeight() - 1), TRANSPARENCY);
		filename = "";
	} else {
		index = filename.size();
		_surface.writeString(filename, pt, COMMAND_HIGHLIGHTED);
		pt.x = _surface.stringWidth("00.") + _surface.stringWidth(filename) + _surface.widestChar() + 5;
	}

	do {
		scene.doBgAnim();

		if (talk._talkToAbort)
			return false;

		char currentChar = (index == (int)filename.size()) ? ' ' : filename[index];
		Common::String charString = Common::String::format("%c", currentChar);
		int width = screen.charWidth(currentChar);

		// Wait for keypress
		while (!events.kbHit()) {
			events.pollEventsAndWait();
			events.setButtonState();

			scene.doBgAnim();

			if (talk._talkToAbort)
				return false;

			if (--blinkCountdown <= 0) {
				blinkCountdown = 3;
				blinkFlag = !blinkFlag;
				if (blinkFlag) {
					textColor = 236;
					color = cursorColor;
				} else {
					textColor = COMMAND_HIGHLIGHTED;
					color = TRANSPARENCY;
				}

				_surface.fillRect(Common::Rect(pt.x, pt.y, pt.x + width, pt.y + _surface.fontHeight()), color);
				if (currentChar != ' ')
					_surface.writeString(charString, pt, textColor);
			}
			if (_vm->shouldQuit())
				return false;
		}

		Common::KeyState keyState = events.getKey();
		if (keyState.keycode == Common::KEYCODE_BACKSPACE && index > 0) {
			pt.x -= _surface.charWidth(filename[index - 1]);
			--index;

			if (insert) {
				filename.deleteChar(index);
			} else {
				filename.setChar(' ', index);
			}

			_surface.fillRect(Common::Rect(pt.x, pt.y, _surface.width() - BUTTON_SIZE - 9, pt.y + _surface.fontHeight() - 1), TRANSPARENCY);
			_surface.writeString(filename.c_str() + index, pt, COMMAND_HIGHLIGHTED);

		} else if ((keyState.keycode == Common::KEYCODE_LEFT && index > 0)
				|| (keyState.keycode == Common::KEYCODE_RIGHT && index < 49 && pt.x < (_bounds.right - BUTTON_SIZE - 20))
				|| (keyState.keycode == Common::KEYCODE_HOME && index > 0)
				|| (keyState.keycode == Common::KEYCODE_END)) {
			_surface.fillRect(Common::Rect(pt.x, pt.y, pt.x + width, pt.y + _surface.fontHeight()), TRANSPARENCY);
			if (currentChar)
				_surface.writeString(charString, pt, COMMAND_HIGHLIGHTED);

			switch (keyState.keycode) {
			case Common::KEYCODE_LEFT:
				pt.x -= _surface.charWidth(filename[index - 1]);
				--index;
				break;

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

示例14: setupText


//.........这里部分代码省略.........
			_x = SCREEN_MARGIN;
		} else if (SCREEN_WIDTH - _x < SCREEN_MARGIN) {
			_x = SCREEN_WIDTH - SCREEN_MARGIN;
		}
	}

	// The maximum width for any line of text is determined by the justification
	// mode. Note that there are no left/right margins -- this is consistent
	// with GrimE.
	int maxWidth = 0;
	if (_justify == CENTER) {
		maxWidth = 2 * MIN(_x, SCREEN_WIDTH - _x);
	} else if (_justify == LJUSTIFY) {
		maxWidth = SCREEN_WIDTH - _x;
	} else if (_justify == RJUSTIFY) {
		maxWidth = _x;
	}

	// We break the message to lines not longer than maxWidth
	Common::String currLine;
	_numberLines = 1;
	int lineWidth = 0;
	int maxLineWidth = 0;
	for (uint i = 0; i < msg.size(); i++) {
		lineWidth += MAX(_font->getCharWidth(msg[i]), _font->getCharDataWidth(msg[i]));
		if (lineWidth > maxWidth) {
			bool wordSplit = false;
			if (currLine.contains(' ')) {
				while (msg[i] != ' ' && i > 0) {
					lineWidth -= MAX(_font->getCharWidth(msg[i]), _font->getCharDataWidth(msg[i]));
					message.deleteLastChar();
					--i;
				}
			} else if (msg[i] != ' ') { // if it is a unique word
				int dashWidth = MAX(_font->getCharWidth('-'), _font->getCharDataWidth('-'));
				while (lineWidth + dashWidth > maxWidth) {
					lineWidth -= MAX(_font->getCharWidth(msg[i]), _font->getCharDataWidth(msg[i]));
					message.deleteLastChar();
					--i;
				}
				message += '-';
				wordSplit = true;
 			}
			message += '\n';
			currLine.clear();
			_numberLines++;

			if (lineWidth > maxLineWidth) {
				maxLineWidth = lineWidth;
			}
			lineWidth = 0;

			if (wordSplit) {
				lineWidth += MAX(_font->getCharWidth(msg[i]), _font->getCharDataWidth(msg[i]));
			} else {
				continue; // don't add the space back
			}
		}

		if (lineWidth > maxLineWidth)
			maxLineWidth = lineWidth;

		message += msg[i];
		currLine += msg[i];
	}

	// If the text object is a speech subtitle, the y parameter is the
	// coordinate of the bottom of the text block (instead of the top). It means
	// that every extra line pushes the previous lines up, instead of being
	// printed further down the screen.
	const int SCREEN_TOP_MARGIN = 16;
	if (_isSpeech) {
		_y -= _numberLines * _font->getHeight();
		if (_y < SCREEN_TOP_MARGIN) {
			_y = SCREEN_TOP_MARGIN;
		}
	}

	_lines = new Common::String[_numberLines];

	for (int j = 0; j < _numberLines; j++) {
		int nextLinePos, cutLen;
		const char *breakPos = strchr(message.c_str(), '\n');
		if (breakPos) {
			nextLinePos = breakPos - message.c_str();
			cutLen = nextLinePos + 1;
		} else {
			nextLinePos = message.size();
			cutLen = nextLinePos;
		}
		Common::String currentLine(message.c_str(), message.c_str() + nextLinePos);
		_lines[j] = currentLine;
		int width = _font->getStringLength(currentLine);
		if (width > _maxLineWidth)
			_maxLineWidth = width;
		for (int count = 0; count < cutLen; count++)
			message.deleteChar(0);
	}
	_elapsedTime = 0;
}
开发者ID:digitall,项目名称:residual,代码行数:101,代码来源:textobject.cpp

示例15: switchPage

/**
 * Loads and draws the chosen page of the help.
 * @remarks Originally called 'getme'
 */
void Help::switchPage(byte which) {
	// Help icons are 80x20.

	_highlightWas = 177; // Forget where the highlight was.

	Common::File file;

	if (!file.open("help.avd"))
		error("AVALANCHE: Help: File not found: help.avd");

	file.seek(which * 2);
	uint16 offset = file.readUint16LE();
	file.seek(offset);

	Common::String title = getLine(file);

	_vm->_graphics->drawFilledRectangle(Common::Rect(0, 0, 640, 200), kColorBlue);
	_vm->_graphics->drawFilledRectangle(Common::Rect(8, 40, 450, 200), kColorWhite);

	byte index = file.readByte();
	_vm->_graphics->helpDrawButton(-177, index);

	// Plot the title:
	_vm->_graphics->drawNormalText(title, _vm->_font, 8, 629 - 8 * title.size(), 26, kColorBlack);
	_vm->_graphics->drawNormalText(title, _vm->_font, 8, 630 - 8 * title.size(), 25, kColorCyan);

	_vm->_graphics->helpDrawBigText("help!", 549, 1, kColorBlack);
	_vm->_graphics->helpDrawBigText("help!", 550, 0, kColorCyan);

	byte y = 0;
	do {
		Common::String line = getLine(file);
		if (!line.empty()) {
			if (line.compareTo(Common::String('!')) == 0)  // End of the help text is signalled with a '!'.
				break;
			if (line[0] == '\\') {
				line.deleteChar(0);
				_vm->_graphics->drawNormalText(line, _vm->_font, 8, 16, 41 + y * 10, kColorRed);
			}
			else
				_vm->_graphics->drawNormalText(line, _vm->_font, 8, 16, 41 + y * 10, kColorBlack);
		}
		y++;
	} while (true);

	// We are now at the end of the text. Next we must read the icons:
	y = 0;
	_buttonNum = 0;
	while (!file.eos()) {
		int trigger = file.readByte();

		if (trigger == 177)
			break;
		switch (trigger) {
		case 254: // Escape
			trigger = 27;
			break;
		case 214: // PageUp
			trigger = 280;
			break;
		case 216: // PageDown
			trigger = 281;
			break;
		default: // A - Z
			// The characters are stored in the file in uppercase, but we need the lowercase versions for KeyCode:
			trigger = tolower(trigger);
			break;
		}

		_buttons[y]._trigger = Common::KeyCode(trigger);
		index = file.readByte();
		if (_buttons[y]._trigger != Common::KEYCODE_INVALID)
			_vm->_graphics->helpDrawButton(13 + (y + 1) * 27, index);
		_buttons[y]._whither = file.readByte(); // This is the position to jump to.

		Common::String text = "";
		switch (_buttons[y]._trigger) {
		case Common::KEYCODE_ESCAPE:
			text = Common::String("Esc");
			break;
		case Common::KEYCODE_PAGEUP:
			text = Common::String(24);
			break;
		case Common::KEYCODE_PAGEDOWN:
			text = Common::String(25);
			break;
		default:
			text = Common::String(toupper(_buttons[y]._trigger));
			break;
		}

		_vm->_graphics->helpDrawBigText(text, 589 - (text.size() * 8), 18 + (y + 1) * 27, kColorBlack);
		_vm->_graphics->helpDrawBigText(text, 590 - (text.size() * 8), 17 + (y + 1) * 27, kColorCyan);

		y++;
		_buttonNum++;
//.........这里部分代码省略.........
开发者ID:andrew889,项目名称:scummvm,代码行数:101,代码来源:help.cpp


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