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


C++ VideoPtr::ComputeCarretPosition方法代码示例

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


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

示例1: PlaceInput

void GSGUI_STRING_INPUT::PlaceInput(const Vector2& pos, const str_type::string& font, const unsigned int nMaxChars, 
				const float size, const Color& dwColor, VideoPtr video,
				InputPtr input)
{
	const unsigned int time = video->GetElapsedTime();
	if ((time-lastBlink) > blinkTime)
	{
		showingCarret = showingCarret==0 ? 1 : 0;
		lastBlink = video->GetElapsedTime();
	}

	// pick the text cursor position with a mouse click
	if (input->GetLeftClickState() == GSKS_HIT)
	{
		cursor = video->FindClosestCarretPosition(font, ss, pos, input->GetCursorPositionF(video));
	}
	
	// don't let the cursor exceed the text range
	cursor = Min(cursor, static_cast<unsigned int>(ss.length()));

	str_type::char_t lastInput = input->GetLastCharInput();
	if (lastInput != '\0' && ss.length() < nMaxChars)
	{
		if (numbersOnly)
		{
			if ((lastInput < 'a' || lastInput > 'z') &&
				(lastInput < 'A' || lastInput > 'Z'))
			{
				ss.insert(cursor, 1, lastInput);
			}
		}
		else
		{
			ss.insert(cursor, 1, lastInput);
		}
		cursor++;
	}

	if (input->GetKeyState(GSK_BACK) == GSKS_HIT)
	{
		if (cursor > 0)
		{
			ss.erase(cursor-1, 1);
			cursor--;
		}
	}
	
	if (input->GetKeyState(GSK_DELETE) == GSKS_HIT)
	{
		if (cursor < ss.length())
		{
			ss.erase(cursor, 1);
		}
	}
	
	if (input->GetKeyState(GSK_LEFT) == GSKS_HIT)
	{
		if (cursor > 0)
			cursor--;
	}
	if (input->GetKeyState(GSK_RIGHT) == GSKS_HIT)
	{
		cursor = Min(++cursor, static_cast<unsigned int>(ss.length()));
	}
	if (input->GetKeyState(GSK_END) == GSKS_HIT)
	{
		SendCursorToEnd();
	}

	const Vector2 cursorPosition = video->ComputeCarretPosition(font, ss, cursor);
	video->DrawBitmapText(pos, ss, font, dwColor);
	if (showingCarret==1)
		video->DrawRectangle(cursorPosition+pos-Vector2(2,0), Vector2(2,size), gs2d::constant::BLACK, gs2d::constant::BLACK, gs2d::constant::BLACK, gs2d::constant::BLACK, 0.0f);
}
开发者ID:ArthurCalazans,项目名称:ethanon,代码行数:74,代码来源:gsgui.cpp


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