Ejemplo n.º 1
0
void CAbstractLabel::SetText(const char* pText, bool Localize)
{
	if(pText)
	{
		str_copy(m_aText, pText, sizeof(m_aText));
		m_Localize = Localize;
	}
	else
		m_aText[0] = 0;
	
	OnTextUpdated();
}
Ejemplo n.º 2
0
/// Begins input! >)
void UIInput::BeginInput()
{
	inputActive = true;
	// Set active state if not done so already.
	this->AddState(UIState::ACTIVE);
	editText = text;
	caretPosition = editText.Length();
	editText.caretPosition = caretPosition;
	// sends message to update the ui with new caret and stuff.
	OnTextUpdated();
	previousText = editText;
	InputMan.DisableKeyBindings();
}
Ejemplo n.º 3
0
/// Halts input and removes Active state.
void UIInput::StopInput()
{
	if (inputActive)
	{
		inputActive = false;
		/// Remove caret
		editText.caretPosition = -1;
		OnTextUpdated();
		// o.o
		UIElement::RemoveState(UIState::ACTIVE);
		InputMan.EnableKeyBindings();
	}
}
Ejemplo n.º 4
0
/// For handling text-input
void UIInput::OnBackspace()
{
	// Delete selection if any
	bool deletedAnything = editText.DeleteSelection();
	/// If anything was deleted, don't take any more.. yet!
    if (caretPosition > 0 && !deletedAnything)
	{
        --caretPosition;	// Move back caret
        // ...and move back the rest one step
		String first = editText.Part(0, caretPosition);
		String second = editText.Part(caretPosition+1);
		editText = first + second;
		// Update the text to render.
		editText.caretPosition = caretPosition;
    }
	OnTextUpdated();
} 
Ejemplo n.º 5
0
void CAbstractTextEdit::OnInputEvent()
{
	m_Composing = false;
	if(m_Focus)
	{
		const char* m_pEditedText = Input()->GetEditedText();
		if(m_pEditedText && str_length(m_pEditedText))
		{
			m_ComposingTextCache.SetText(m_pEditedText);
			m_Composing = true;
		}
		
		if(Input()->KeyIsPressed(KEY_RETURN) || Input()->KeyIsPressed(KEY_KP_ENTER))
		{
			if(m_Changes)
			{
				SaveFromTextBuffer();
				m_Changes = false;
			}
		}
		else if(m_TextCursor.m_TextIter >= 0)
		{
			int TextIter = m_TextCursor.m_TextIter;
			bool Changes = false;
			for(int i = 0; i < Input()->NumEvents(); i++)
			{
				int Len = str_length(m_aText);
				int NumChars = Len;
				if(CLineInput::Manipulate(Input()->GetEvent(i), m_aText, sizeof(m_aText), sizeof(m_aText), &Len, &TextIter, &NumChars))
					Changes = true;
			}
			
			if(Changes)
			{
				OnTextUpdated();
				m_TextCursor = TextRenderer()->GetTextCursorFromTextIter(&m_TextCache, GetTextPosition(), TextIter);
				m_Changes = true;
			}
		}
	}
}
Ejemplo n.º 6
0
/// Used for getting text. This will be local translated language key codes?
int UIInput::OnChar(int asciiCode)
{
	bool isActive = (state & UIState::ACTIVE);
	assert(inputActive == isActive);
	if (!this->inputActive)
		return 0;
	/// Make sure the buffer period has passed ^^
/*	clock_t currentTime = clock();
	if (currentTime < textInputStartTime + 10)	/// 100 ms delay before input can be done o-o
		return;
*/

	// NOTE: Caret is visualized as being right behind the new letter, or right after the letter being added.
	// So caret 3 in the word Ashwood would be:  Ash|wood
	// Backspace
	if (asciiCode == 0x08){
	    OnBackspace();
		return 0;
	}
	/// If control is held, only evaluate it as a special command.
	if (InputMan.KeyPressed(KEY::CTRL))
	{
		switch(asciiCode)
		{
			/// Generated by CTRL+A on windows.. o.O "Start of heading"
			case 1:
			{
				std::cout<<"ERKA:REKA";
				// Select all text! o.o
				editText.SelectAll();
				OnTextUpdated();
				break;
			}
			case 'A':
			case 'a':
			{
				std::cout<<"ERKA:REKA";
				break;
			}
		}
		return 0;
	}
	// Escape, cancel input
	else if (asciiCode == 0x1B)
	{
		// And restore old string!
		editText = previousText;
		StopInput();
		return 0;
	}
	else {
		#define _DEBUG_ASCII
		/// Ignore crap letters
		switch(asciiCode){
			case 0:
			case 4:		// End of transmission, not the same as ETB
			case 13:	// Vertical tab, whatever that is
			case 19:	// XOFF, with XON is TERM=18 flow control
			case 22:	// Synchrous idle, CTRL+V, dunno..
				#ifdef _DEBUG_ASCII
		//		std::cout<<"\nSkipping crap letters.. :3";
				#endif
				return 0;
			default:
				#ifdef _DEBUG_ASCII
		//		std::cout<<"\nAsciiCode: "<<(int)asciiCode<<" "<<(unsigned char)asciiCode;
				#endif
				break;
		}
		/// Accept only alpha-numeric + other accepted signs implemented in Expression 
		bool ok = false;
		if (mathematicalExpressionsOnly)
		{
			if (isalnum(asciiCode))
				ok = true;
			switch(asciiCode)
			{
				case '.':
				case ',':
				case '(':
				case ')':
				case '*':
				case '+':
				case '-':
				case '/':
				case '%':
				case '^':
					ok = true;
					break;
			}
		}
		/// If only accept numbers, skip all except a few ascii..
		else if (numbersOnly)
		{
			if (isdigit(asciiCode))
				ok = true;
			switch(asciiCode)
			{
				case '.':
				case '-':
					ok = true;
					break;
			}
		}
		/// No limit defined? Then automatically accept all characters.
		else 
		{
			ok = true;
		}
		if (!ok)
			return 0;
		/// If any text is selected, remove it and start inserting characters where it was.
		if (editText.DeleteSelection())
			caretPosition = editText.caretPosition;

		String firstHalf = editText.Part(0, caretPosition);
		String secondHalf = editText.Part(caretPosition);
		editText = firstHalf + (char)asciiCode + secondHalf;
		// inputBuffers[selectedInputBuffer][caretPosition] = asciiCode;
		++caretPosition;
		editText.caretPosition = caretPosition;
		OnTextUpdated();
	}
	return 0;
}
Ejemplo n.º 7
0
/// Used by input-captuing elements. Should not be called for any base UI elements(?)
int UIInput::OnKeyDown(int keyCode, bool downBefore)
{
	bool isActive = (state & UIState::ACTIVE);
	assert(inputActive == isActive);
	if (!inputActive)
		return 0;

	int oldCaretPosition = editText.caretPosition;

	bool moveCommand = false;
	switch(keyCode)
	{
		case KEY::BACKSPACE: {
	#ifndef WINDOWS
			// Double trigger at the moment..
			OnBackspace();
	#endif
			break;
		}
		case KEY::ESCAPE:
		{
			std::cout<<"\nCanceling input.";
			editText = previousText;
			// Make inactive.
			StopInput();
			break;
		}
		case KEY::ENTER: {
			// Don't evaluate Enter and certain other keys if they were down before
			if (downBefore)
				return 0;
			StopInput();
			// Activate the messages this element had, if any. If using as a compound e.g. inside a StringInput, then this onTrigger may be omitted.
			if (onTrigger.Length())
				MesMan.QueueMessages(onTrigger, this);
			else 
			{
				
			}
			/// Notify of the update to self and then parents, so that extra actions may be taken.
			this->OnInputUpdated(this);
			break;
		}
		// Delete
		case KEY::DELETE_KEY:
		{
			// Delete selection if any
			if (editText.DeleteSelection())
			{
				caretPosition = editText.caretPosition;
				break;
			}
			String left = editText.Part(0, caretPosition);
			String right = editText.Part(caretPosition+1);
			editText = left + right;
			// Update the text to render.
			editText.caretPosition = caretPosition;
			break;
		}
		case KEY::END:
			caretPosition = editText.Length();
			editText.caretPosition = caretPosition;
			moveCommand = true;
			break;
		case KEY::HOME:
			caretPosition = 0;
			editText.caretPosition = caretPosition;
			moveCommand = true;
			break;
		case KEY::UP: 
		{
			parent->OnKeyDown(keyCode, downBefore);
			break;
		}
		case KEY::DOWN: 
		{
			parent->OnKeyDown(keyCode, downBefore);
			break;
		}
		case KEY::LEFT:
			if (caretPosition > 0)
			{
				if (InputMan.KeyPressed(KEY::CTRL))
				{
					caretPosition = editText.CaretPositionAtPreviousWord();
				}
				else {
					--caretPosition;
				}
				// Update the text to render.
				editText.caretPosition = caretPosition;
			}
			moveCommand = true;
			break;
		case KEY::RIGHT:
			if (caretPosition < editText.Length())
			{
				if (InputMan.KeyPressed(KEY::CTRL))
				{
					caretPosition = editText.CaretPositionAtNextWord();
				}
				else {
					++caretPosition;
				}
				// Update the text to render.
				editText.caretPosition = caretPosition;
			}
			moveCommand = true;
			break;
	}

	// If was trying to move.. 
	if (moveCommand /*&& oldCaretPosition != editText.caretPosition*/)
	{
		if (!InputMan.KeyPressed(KEY::SHIFT))
		{
			// Reset the "previous caret"!
			editText.previousCaretPosition = -1;
		}
		// But if shift is pressed, and the previous caret is -1, then set it!
		else if (editText.previousCaretPosition == -1)
		{
			editText.previousCaretPosition = oldCaretPosition;
		}
	}

	OnTextUpdated();

	// Return from here no matter what now, since we don't want any hot-key
	// whatsoever to be triggered while entering any input!
	return 0;
}
Ejemplo n.º 8
0
void CAbstractIntegerEdit::CEntry::CopyToTextBuffer()
{
	str_format(m_aText, sizeof(m_aText), "%d", m_pIntegerEdit->GetValue());
	OnTextUpdated();
}