Esempio n. 1
0
boolean TextManip::HandleKey (Event& e) {
    World* world = GetViewer()->GetWorld();
    char c = e.keystring[0];
    boolean manipulating = true;

    switch (c) {
        case '\007':  world->RingBell(1); break;
        case '\001':  BeginningOfLine(); break;
        case '\005':  EndOfLine(); break;
        case '\006':  ForwardCharacter(1); break;
        case '\002':  BackwardCharacter(1); break;
        case '\016':  ForwardLine(1); break;
        case '\020':  BackwardLine(1); break;
        case '\013':  DeleteLine(); break;
        case '\004':  DeleteCharacter(1); break;
        case '\010':  DeleteCharacter(-1); break;
        case '\177':  DeleteCharacter(-1); break;
        case '\011':  InsertCharacter('\t'); break;
        case '\015':  if (_multiline) InsertCharacter('\n'); break;
        case '\033':  manipulating = false; break;
        default:
            if (!iscntrl(c & 0x7f)) {
                InsertCharacter(c);
            }
            break;
    }
    return manipulating;
}
Esempio n. 2
0
void EditableLabel::StartTyping()
{
	for (int i = 0; i < NUMBER_OF_VIRTUAL_KEYS; i++)
	{
		if (s_theInputSystem->WasKeyJustDown(i))
		{
			if (s_theInputSystem->WasKeyJustDown(VK_BACK))
			{
				RemoveLastCharacter();
				return;
			}
			if (s_theInputSystem->IsKeyDown(VK_SHIFT))
			{
				if (i >= 65 && i <= 90)
				{
					InsertCharacter(i);
					return;
				}
				if (i == 57)
				{
					InsertCharacter(i);
					return;
				}
				if (i == 48)
				{
					InsertCharacter(i);
					return;
				}
			}
			if (i == 32)
			{
				InsertCharacter(i);
				return;
			}
			if (i >= 65 && i <= 90)
			{
				InsertCharacter(i + 32);
				return;
			}
			if (i >= 188 && i <= 191)
			{
				InsertCharacter(i - 144);
				return;
			}
			if (i == 186)
			{
				InsertCharacter(59);
				return;
			}
			if (i <= 57 && i >= 48)
			{
				InsertCharacter(i);
				return;
			}

		}
	}
}
Esempio n. 3
0
std::vector<std::string> Permutations(const std::string & str)
{
    
    std::vector<std::string> perms;
    if (str.empty())
    {
        perms.push_back("");
        return perms;
    }
    
    //get the first charcater and the remainder.
    std::string first = str.substr(0,1);
    std::string remainder = str.substr(1);
//    std::cout << "remainder: " << remainder << std::endl;
    std::vector<std::string> words = Permutations(remainder);
    for (auto it = words.begin(); it != words.end(); ++it)
    {
        for (unsigned int i = 0; i <= it->size(); ++i)
        {
            std::string s = InsertCharacter(first, *it, i);
//            std::cout << "push_back: " << s << std::endl;
            perms.push_back(s);
        }
    }
    return perms;
}
Esempio n. 4
0
void MythUITextEdit::InsertText(const QString &text)
{
    if (!m_Text)
        return;

    int i = 0;
    for (; i < text.size(); ++i)
    {
        InsertCharacter(text.data()[i]);
    }

    emit valueChanged();
}
Esempio n. 5
0
static void ExecuteCommand(bufferADT buffer, string line)
{
    int i;

    switch (toupper(line[0])) {
      case 'I': for (i = 1; line[i] != '\0'; i++) {
                    InsertCharacter(buffer, line[i]);
                }
                break;
      case 'D': DeleteCharacter(buffer); break;
      case 'F': MoveCursorForward(buffer); break;
      case 'B': MoveCursorBackward(buffer); break;
      case 'J': MoveCursorToStart(buffer); break;
      case 'E': MoveCursorToEnd(buffer); break;
      case 'H': HelpCommand(); break;
      case 'Q': exit(0);
      default:  printf("Illegal command\n"); break;
    }
}
Esempio n. 6
0
void Fonts::UpdateTextInput(float deltaTime)
{
	deltaTime;
	PrintLogToFile();
	AddHelpText();
	ClearAllText();

	if (m_startType==false)
	{
		return;
	}
	if (s_theInputSystem->WasKeyJustDown(VK_ESCAPE))
	{
		s_text = "";
		m_log[m_log.size() - 1] = s_text;
		m_startType = false;
		m_doShowConsole = false;
		return;
	}
	if (s_theInputSystem->WasKeyJustDown(VK_UP))
	{
		if ((checkLineNum-1)>=0)
		{
			checkLineNum--;		
			
		}
		else
			checkLineNum = m_log.size()-1;
		if (m_log[checkLineNum][0]!='>')
		{
			s_text = ">" + m_log[checkLineNum];
		}
		
		m_log[m_log.size() - 1] = s_text;
	}
	if (s_theInputSystem->WasKeyJustDown(VK_LEFT))
	{
		if (curserPositionInString>0)
		{
			curserPositionInString--;
		}
	}
	if (s_theInputSystem->WasKeyJustDown(VK_RIGHT))
	{
		if (curserPositionInString < s_text.length()-1)
		{
			curserPositionInString++;
		}
	}
	if (s_theInputSystem->WasKeyJustDown(VK_DOWN))
	{
		if ((checkLineNum) < (int)m_log.size() - 1)
		{
			checkLineNum++;			
		}
		else
			checkLineNum = 0;
		if (m_log[checkLineNum][0] != '>')
		{
			s_text = ">" + m_log[checkLineNum];
		}
		m_log[m_log.size() - 1] = s_text;
	}
	if (s_theInputSystem->WasKeyJustDown(VK_BACK))
	{
		//if (s_text.length()>1)
		//{
		//	s_text = s_text.substr(0, s_text.length() - 1);
		//}
		//
		//m_log[m_log.size() - 1] = s_text;
		DeleteCharacter();
	}
	m_log[m_log.size() - 1] = s_text;
	if (s_theInputSystem->WasKeyJustDown(VK_RETURN))
	{
		if (s_text == ">")
		{
			s_text = "";
			m_startType = false;
			return;
		}
		else
		{
			m_log[m_log.size() - 1] = CutDoubleString(s_text,'>','\n');
			RunConsoleFromLine(m_log[m_log.size() - 1].c_str());
			m_log.push_back("");
			s_text = "";
			m_startType = false;
			checkLineNum = m_log.size()-1;
		}
		curserPositionInString = 0;
		return;
	}

	for (int i = 0; i < NUMBER_OF_VIRTUAL_KEYS; i++)
	{
		if (s_theInputSystem->WasKeyJustDown(i))
		{
			if (s_theInputSystem->IsKeyDown(VK_SHIFT))
			{
				if (i>=65 && i<=90)
				{
					//s_text += (char)i;
					//curserPositionInString++;
					InsertCharacter(i);
					return;
				}
				if (i == 57)
				{
					//s_text += 40;  //'('
					//curserPositionInString++;
					InsertCharacter(i);
					return;
				}
				if (i == 48)
				{
					//s_text += 41;  //')'
					//curserPositionInString++;
					InsertCharacter(i);
					return;
				}
			}
			if (i == 32)
			{
				InsertCharacter(i);
			}
			if (i >= 65 && i <= 90)
			{
				InsertCharacter(i+32);
				return;
			}
			if (i>=188 && i<=191)
			{
				InsertCharacter(i-144);
				return;
			}
			if (i == 186)
			{
				InsertCharacter(59);
				return;
			}
			if (i<=57 && i >=48)
			{
				InsertCharacter(i);
			}
			
		}
	}
}
Esempio n. 7
0
bool MythUITextEdit::keyPressEvent(QKeyEvent *e)
{
    m_lastKeyPress.restart();

    QStringList actions;
    bool handled = false;

    handled = GetMythMainWindow()->TranslateKeyPress("Global", e, actions, false);

    if (!handled && InsertCharacter(e->text()))
        handled = true;

    for (int i = 0; i < actions.size() && !handled; i++)
    {

        QString action = actions[i];
        handled = true;

        if (action == "LEFT")
        {
            if (!MoveCursor(MoveLeft))
                handled = false;
        }
        else if (action == "RIGHT")
        {
            if (!MoveCursor(MoveRight))
                handled = false;
        }
        else if (action == "DELETE")
        {
            RemoveCharacter(m_Position+1);
        }
        else if (action == "BACKSPACE")
        {
            RemoveCharacter(m_Position);
        }
        else if (action == "SELECT" && e->key() != Qt::Key_Space
                 && GetMythDB()->GetNumSetting("UseVirtualKeyboard", 1) == 1)
        {
            MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
            MythUIVirtualKeyboard *kb =  new MythUIVirtualKeyboard(popupStack, this);

            if (kb->Create())
            {
                //connect(kb, SIGNAL(keyPress(QString)), SLOT(keyPress(QString)));
                popupStack->AddScreen(kb);
            }
            else
                delete kb;
        }
        else if (action == "CUT")
        {
            CutTextToClipboard();
        }
        else if (action == "COPY")
        {
            CopyTextToClipboard();
        }
        else if (action == "PASTE")
        {
            PasteTextFromClipboard();
        }
        else
            handled = false;
    }

    return handled;
}
Esempio n. 8
0
/*****************************************************************************
 * FUNCTION: WFConsoleProcess
 *
 * RETURNS: None
 *
 * PARAMS:  None
 *
 * NOTES:   State machine called from main loop of app.  Handles serial input.
 *
 *****************************************************************************/
void WFConsoleProcess(void)
{
    //UINT8 *pStart = &(cmdline[0]);
    UINT16  rc;
    INT8  c;
    static INT8 escape_sequence[kWFMaxInputEscapeSequence];
    static INT8 esc_seq_index;

    // if this state machine has been disabled
    if (g_ConsoleContext.bStateMachineLoop == FALSE)
    {
        return;
    }


    // if a command was entered that is application=specific
    if (g_ConsoleContext.appConsoleMsgRx == TRUE)
    {
        return;  // wait until app done before processing further characters
    }

    // if no character(s) received
    if ( (rc = DataRdyUART() ) == 0u )
    {
        return;
    }

    // get the character
    c = (INT8) ReadUART();

    // if this is the very first character received by this state machine
    if (g_ConsoleContext.firstChar == FALSE)
    {
        Output_Monitor_Hdr();
        g_ConsoleContext.firstChar = TRUE;
    }

    switch( GET_RX_STATE() )
    {
        //------------------------------------------
        case kSTWaitForChar:
        //------------------------------------------
            // if a 'normal' printable character
            if (isPrintableCharacter(c))
            {
                InsertCharacter(c);
            }
            // else if Delete key
            else if (c == kWFDelete)
            {
                Delete();
            }
            // else if Backspace key
            else if (c == (INT8)kWFBackspace)
            {
                Backspace();
            }
            // else if Enter key
            else if (c == kWFEnter)
            {
                Enter();
            }
            // else if Escape key
            else if (c == kWFEscape)
            {
                /* zero out escape buffer, init with ESC */
                memset(escape_sequence, 0x00, sizeof(escape_sequence));
                escape_sequence[0] = kWFEscape;
                esc_seq_index = 1;
                SET_RX_STATE(kSTWaitForEscSeqSecondChar);
            }
            // else if Ctrl C
            else if (c == kWFCtrl_C)
            {
               OutputCommandPrompt();
            }
            else {
                // Enter();
            }
            break;

        //------------------------------------------
        case kSTWaitForEscSeqSecondChar:
        //------------------------------------------
            /* if an arrow key, home, or end key (which is all that this state machine handles) */
            if (c == 0x5b)
            {
               escape_sequence[1] = c;
               SET_RX_STATE(kSTWaitForEscSeqThirdChar);
            }
            // else if user pressed escape followed by any printable character
            else if (isPrintableCharacter(c))
            {
                InsertCharacter(c);
                SET_RX_STATE(kSTWaitForChar);
            }
            // start this command line over
            else // anything else
            {
                OutputCommandPrompt();
                SET_RX_STATE(kSTWaitForChar);
            }
            break;

        //------------------------------------------
        case kSTWaitForEscSeqThirdChar:
        //------------------------------------------
            escape_sequence[2] = c;
            ProcessEscapeSequence(escape_sequence);
            SET_RX_STATE(kSTWaitForChar);
            break;


    } // end switch
}
Esempio n. 9
0
bool MythUITextEdit::keyPressEvent(QKeyEvent *event)
{
    m_lastKeyPress.restart();

    QStringList actions;
    bool handled = false;

    handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions,
                                                     false);

    Qt::KeyboardModifiers modifiers = event->modifiers();
    int keynum = event->key();

    if (keynum >= Qt::Key_Shift && keynum <= Qt::Key_CapsLock)
        return false;

    QString character;
    // Compose key handling
    // Enter composition mode
    if ((modifiers & Qt::GroupSwitchModifier) &&
        (keynum >= Qt::Key_Dead_Grave) && (keynum <= Qt::Key_Dead_Horn))
    {
        m_composeKey = keynum;
        handled = true;
    }
    else if (m_composeKey > 0) // 'Compose' the key
    {
        if (gDeadKeyMap.isEmpty())
            LoadDeadKeys(gDeadKeyMap);

        LOG(VB_GUI, LOG_DEBUG, QString("Compose key: %1 Key: %2").arg(QString::number(m_composeKey, 16)).arg(QString::number(keynum, 16)));

        if (gDeadKeyMap.contains(keyCombo(m_composeKey, keynum)))
        {
            int keycode = gDeadKeyMap.value(keyCombo(m_composeKey, keynum));

            //QKeyEvent key(QEvent::KeyPress, keycode, modifiers);
            character = QChar(keycode);

            if (modifiers & Qt::ShiftModifier)
                character = character.toUpper();
            else
                character = character.toLower();
            LOG(VB_GUI, LOG_DEBUG, QString("Found match for dead-key combo - %1").arg(character));
        }
        m_composeKey = 0;
    }

    if (character.isEmpty())
        character = event->text();

    if (!handled && InsertCharacter(character))
        handled = true;

    for (int i = 0; i < actions.size() && !handled; i++)
    {

        QString action = actions[i];
        handled = true;

        if (action == "LEFT")
        {
            MoveCursor(MoveLeft);
        }
        else if (action == "RIGHT")
        {
            MoveCursor(MoveRight);
        }
        else if (action == "UP")
        {
            handled = MoveCursor(MoveUp);
        }
        else if (action == "DOWN")
        {
            handled = MoveCursor(MoveDown);
        }
        else if (action == "PAGEUP")
        {
            handled = MoveCursor(MovePageUp);
        }
        else if (action == "PAGEDOWN")
        {
            handled = MoveCursor(MovePageDown);
        }
        else if (action == "DELETE")
        {
            RemoveCharacter(m_Position + 1);
        }
        else if (action == "BACKSPACE")
        {
            RemoveCharacter(m_Position);
        }
        else if (action == "NEWLINE")
        {
            QString newmessage = m_Message;
            newmessage.insert(m_Position + 1, '\n');
            SetText(newmessage, false);
            MoveCursor(MoveRight);
        }
        else if (action == "SELECT" && keynum != Qt::Key_Space
                 && GetMythDB()->GetNumSetting("UseVirtualKeyboard", 1) == 1)
        {
            MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
            MythUIVirtualKeyboard *kb =  new MythUIVirtualKeyboard(popupStack, this);

            if (kb->Create())
            {
                //connect(kb, SIGNAL(keyPress(QString)), SLOT(keyPress(QString)));
                popupStack->AddScreen(kb);
            }
            else
                delete kb;
        }
        else if (action == "CUT")
        {
            CutTextToClipboard();
        }
        else if (action == "COPY")
        {
            CopyTextToClipboard();
        }
        else if (action == "PASTE")
        {
            PasteTextFromClipboard();
        }
        else
            handled = false;
    }

    return handled;
}
Esempio n. 10
0
void EditCharacters(TCampaignSetting * setting)
{
	int done = 0;
	int c = 0;
	int index = 0;
	int xc = 0, yc = 0;
	TBadGuy scrap;
	int x, y, buttons, tag;

	memset(&scrap, 0, sizeof(scrap));
	SetMouseRects(localClicks);

	while (!done) {
		Display(setting, index, xc, yc);

		do {
			GetEvent(&c, &x, &y, &buttons);
			if (buttons) {
				if (XYToCharacterIndex(x, y, &tag)) {
					if (tag >= 0
					    && tag <
					    setting->characterCount)
						index = tag;
					c = DUMMY;
				} else if (GetMouseRectTag(x, y, &tag)) {
					xc = (tag >> 8);
					yc = (tag & 0xFF);
					AdjustYC(&yc);
					AdjustXC(yc, &xc);
					c = (buttons ==
					     1 ? PAGEUP : PAGEDOWN);
				}
			}
		}
		while (!c);

		switch (c) {
		case HOME:
			if (index > 0)
				index--;
			break;

		case END:
			if (index < setting->characterCount - 1)
				index++;
			break;

		case INSERT:
			InsertCharacter(setting, index, NULL);
			fileChanged = 1;
			break;

		case ALT_X:
			scrap = setting->characters[index];

		case DELETE:
			DeleteCharacter(setting, &index);
			fileChanged = 1;
			break;

		case ALT_C:
			scrap = setting->characters[index];
			break;

		case ALT_V:
			InsertCharacter(setting, index, &scrap);
			fileChanged = 1;
			break;

		case ALT_N:
			InsertCharacter(setting, setting->characterCount,
					NULL);
			index = setting->characterCount - 1;
			fileChanged = 1;
			break;

		case ARROW_UP:
			yc--;
			AdjustYC(&yc);
			AdjustXC(yc, &xc);
			break;

		case ARROW_DOWN:
			yc++;
			AdjustYC(&yc);
			AdjustXC(yc, &xc);
			break;

		case ARROW_LEFT:
			xc--;
			AdjustXC(yc, &xc);
			break;

		case ARROW_RIGHT:
			xc++;
			AdjustXC(yc, &xc);
			break;

		case PAGEUP:
			Change(setting, index, yc, xc, 1);
			fileChanged = 1;
			break;

		case PAGEDOWN:
			Change(setting, index, yc, xc, -1);
			fileChanged = 1;
			break;

		case ESCAPE:
			done = 1;
			break;
		}
	}
}
Esempio n. 11
0
/*****************************************************************************
 * FUNCTION: IperfConsoleProcess
 *
 * RETURNS: None
 *
 * PARAMS:  None
 *
 * NOTES:   State machine called from main loop of app.  Handles serial input.
 *
 *****************************************************************************/
void IperfConsoleProcess(void)
{
    //uint8_t *pStart = &(cmdline[0]);
    int8_t  c;
    static int8_t escape_sequence[kMaxInputEscapeSequence];
    static int8_t esc_seq_index;

    // if this state machine has been disabled
    if (g_ConsoleContext.bStateMachineLoop == false)
    {
        return;
    }


    // if a command was entered that is application=specific
    if (g_ConsoleContext.appConsoleMsgRx == true)
    {
        return;  // wait until app done before processing further characters
    }

    // if no character(s) received
    if (SYS_CONSOLE_DATA_RDY() == 0)
    {
        return;
    }

    // get the character
    c = (int8_t) SYS_CONSOLE_GETC();

    // if this is the very first character received by this state machine
    if (g_ConsoleContext.firstChar == false)
    {
        Output_Monitor_Hdr();
        g_ConsoleContext.firstChar = true;
    }

    switch( GET_RX_STATE() )
    {
        //------------------------------------------
        case kSTWaitForChar:
        //------------------------------------------
            // if a 'normal' printable character
            if (isPrintableCharacter(c))
            {
                InsertCharacter(c);
            }
            // else if Delete key
            else if (c == kDelete)
            {
                Delete();
            }
            // else if Backspace key
            else if (c == (int8_t)kBackspace)
            {
                Backspace();
            }
            // else if Enter key
            else if (c == kEnter)
            {
                Enter();
            }
            // else if Escape key
            else if (c == kEscape)
            {
                /* zero out escape buffer, init with ESC */
                memset(escape_sequence, 0x00, sizeof(escape_sequence));
                escape_sequence[0] = kEscape;
                esc_seq_index = 1;
                SET_RX_STATE(kSTWaitForEscSeqSecondChar);
            }
            // else if Ctrl C
            else if (c == kCtrl_C)
            {
               OutputCommandPrompt();
            }
            else {
                // Enter();
            }
            break;

        //------------------------------------------
        case kSTWaitForEscSeqSecondChar:
        //------------------------------------------
            /* if an arrow key, home, or end key (which is all that this state machine handles) */
            if (c == 0x5b)
            {
               escape_sequence[1] = c;
               SET_RX_STATE(kSTWaitForEscSeqThirdChar);
            }
            // else if user pressed escape followed by any printable character
            else if (isPrintableCharacter(c))
            {
                InsertCharacter(c);
                SET_RX_STATE(kSTWaitForChar);
            }
            // start this command line over
            else // anything else
            {
                OutputCommandPrompt();
                SET_RX_STATE(kSTWaitForChar);
            }
            break;

        //------------------------------------------
        case kSTWaitForEscSeqThirdChar:
        //------------------------------------------
            escape_sequence[2] = c;
            
            if ((c == 0x31) || (c == 0x34))   // home or end key
            {
                SET_RX_STATE(kSTWaitForEscSeqFourthChar);
            }
            else
            {    
                ProcessEscapeSequence(escape_sequence);
                SET_RX_STATE(kSTWaitForChar);
            }    
            break;
            
        //------------------------------------------            
        case kSTWaitForEscSeqFourthChar:
        //------------------------------------------
            ProcessEscapeSequence(escape_sequence);
            SET_RX_STATE(kSTWaitForChar);
            break;
            


    } // end switch
}