コード例 #1
0
ファイル: ltguieditctrl.cpp プロジェクト: Arc0re/lithtech
// Handles a key press
bool CLTGUIEditCtrl::HandleChar(wchar_t c)
{
    if (CLTGUICtrl::HandleChar(c)) return true;
    if (c < ' ') return false;

	if (m_pFn)
	{
		c = (*m_pFn)(c,m_nCaretPos);
		if (!c)
			return LTFALSE;
	}

	switch	(m_eInputMode)
	{
	case kInputAlphaNumeric:
		if (!isalnum(c)) return false;
		break;
	case kInputAlphaOnly:
		if (!isalpha(c)) return false;
		break;
	case kInputNumberOnly:
		if (!isdigit(c)) return false;
		break;
	case kInputFileFriendly:
		if (!IsFileFriendly(c,(m_nCaretPos == 0))) return false;
		break;
	};


	AddCharacter(c);
    return true;
}
コード例 #2
0
ファイル: ltguieditctrl.cpp プロジェクト: emoose/lithtech
// Handles a key press
LTBOOL CLTGUIEditCtrl::HandleChar(unsigned char c)
{
    if (CLTGUICtrl::HandleChar(c)) return LTTRUE;
    if (c < ' ') return LTFALSE;

	switch	(m_eInputMode)
	{
	case kInputAlphaNumeric:
		if (!isalnum(c)) return LTFALSE;
		break;
	case kInputAlphaOnly:
		if (!isalpha(c)) return LTFALSE;
		break;
	case kInputNumberOnly:
		if (!isdigit(c)) return LTFALSE;
		break;
	case kInputFileFriendly:
		if (!IsFileFriendly(c,(m_nCaretPos == 0))) return LTFALSE;
		break;

	// Special case disallowing % and \ from a string. Used so the entire codebase doesn't need to be changed
	// for playernames and teams 
	case kInputSprintfFriendly:
		if ( c == 37 || c == 92 )
			  return LTFALSE;
		break;

	};


	AddCharacter(c);
    return LTTRUE;
}
コード例 #3
0
ファイル: World.cpp プロジェクト: MagneticHourglass/hdt-pe
void CWorld::ScanCell()
{
	auto player = DYNAMIC_CAST( LookupFormByID(0x14), TESForm, TESObjectREFR );
	if(!player) goto FAILED;
	auto cell = player->parentCell;
	if(!cell) goto FAILED;
	
	m_pWorld->markForWrite();
	if(m_pCell != cell)
	{
		LogInfo("Cell changed...");
		m_characters.clear();
		m_pCell = cell;

		for(auto& i : m_systems)
		{
			i.second->RemoveFromWorld();
			i.second->AddToWorld(m_pWorld);
		}
	}
	else
	{
		for(auto i=m_characters.begin(); i!=m_characters.end();)
		{
			auto form = i->first;
			auto object = (TESObjectREFR*)LookupFormByID(form);
			if(object->parentCell != cell)
			{
				LogInfo("%08x no longer in cell, release it", form);
				m_characters.erase(i++);
			}
			else if(!i->second->CreateIfValid())
			{
				LogInfo("%08x now invalid, release it", form);
				m_characters.erase(i++);
			}
			else (i++)->second->AddToWorld(m_pWorld);
		}

		for(int i=0; i<cell->objectList.count; ++i)
		{
			auto object = cell->objectList.arr.entries[i];
			if(DYNAMIC_CAST(object, TESObjectREFR, Actor))
				AddCharacter(object->formID);
		}
	}

	m_pWorld->unmarkForWrite();
	return;

FAILED:
	
	m_pWorld->markForWrite();
	m_characters.clear();
	m_pCell = 0;
	m_pWorld->unmarkForWrite();
}
コード例 #4
0
ファイル: PARSER.C プロジェクト: dougc333/stanford
CharSetT *BuildPrintableCharSet(void) {
  int i;
  CharSetT *cs = CreateCharSet();

  for (i = 0; i < 256; i++) {
    if (isprint(i))
      AddCharacter(i, cs);
  }
  return cs;
}
コード例 #5
0
ファイル: PARSER.C プロジェクト: dougc333/stanford
void AddCharacterRange(int a, int b, CharSetT *cs) {
  int i;

  if (a < 0 || b < 0 || a > 255 || b > 255 || a > b) {
#if ERR_MESG
    fprintf(stderr, "AddCharacterRange: invalid arguments");
#endif
    return;
  }
  for (i = a; i <= b; i++)
    AddCharacter(i, cs);
}
コード例 #6
0
static int TXT_InputBoxKeyPress(TXT_UNCAST_ARG(inputbox), int key)
{
    TXT_CAST_ARG(txt_inputbox_t, inputbox);
    unsigned int c;

    if (!inputbox->editing)
    {
        if (key == KEY_ABUTTON)
        {
            StartEditing(inputbox);
            return 1;
        }

        // Backspace or delete erases the contents of the box.

        if ((key == KEY_DEL || key == KEY_BACKSPACE)
         && inputbox->widget.widget_class == &txt_inputbox_class)
        {
            free(*((char **)inputbox->value));
            *((char **) inputbox->value) = strdup("");
        }

        return 0;
    }

    if (key == KEY_ABUTTON)
    {
        FinishEditing(inputbox);
    }

    if (key == KEY_BBUTTON)
    {
        inputbox->editing = 0;
    }

    if (key == KEY_BACKSPACE)
    {
        Backspace(inputbox);
    }

    c = TXT_KEY_TO_UNICODE(key);

    // Add character to the buffer, but only if it's a printable character
    // that we can represent on the screen.
    if (isprint(c)
     || (c >= 128 && TXT_CanDrawCharacter(c)))
    {
        AddCharacter(inputbox, c);
    }

    return 1;
}
コード例 #7
0
ファイル: txt_inputbox.c プロジェクト: JohnnyonFlame/ecwolf
static int TXT_InputBoxKeyPress(TXT_UNCAST_ARG(inputbox), int key)
{
    TXT_CAST_ARG(txt_inputbox_t, inputbox);
    unsigned int c;

    if (!inputbox->editing)
    {
        if (key == KEY_ENTER)
        {
            StartEditing(inputbox);
            return 1;
        }

        // Backspace or delete erases the contents of the box.

        if ((key == KEY_DEL || key == KEY_BACKSPACE)
         && inputbox->widget.widget_class == &txt_inputbox_class)
        {
            free(*((char **)inputbox->value));
            *((char **) inputbox->value) = strdup("");
        }

        return 0;
    }

    if (key == KEY_ENTER)
    {
        FinishEditing(inputbox);
    }

    if (key == KEY_ESCAPE)
    {
        inputbox->editing = 0;
    }

    if (key == KEY_BACKSPACE)
    {
        Backspace(inputbox);
    }

    c = TXT_KEY_TO_UNICODE(key);

    if (c >= 128 || isprint(c))
    {
        // Add character to the buffer

        AddCharacter(inputbox, c);
    }

    return 1;
}
コード例 #8
0
/* Converts a multiple alignment (possibly with gaps) to a bunch of
 * aligned single-letter seqeunces.  Also reorders aligned residues.
 */
SequenceAlignment *GetSequenceAlignment(MultipleAlignment *ma) {
	SequenceAlignment *out = (SequenceAlignment *) malloc(sizeof(SequenceAlignment));
	int chain, block, chain2;
	int *indices = (int*) calloc(ma->numChains, sizeof(int));
	out->numSeqs = ma->numChains;
	out->seqs = (Sequence**) malloc(sizeof(Sequence*) * ma->numChains);

	for (chain=0; chain<ma->numChains; chain++) {
		out->seqs[chain] = CreateSequence(ma->chains[chain]->pdb->idString);
	}
	for (block=0; block < ma->numBlocks; block++) {
		int first = ma->blocks[block].first;
		int last = ma->blocks[block].last;
		for (chain=0; chain<ma->numChains; chain++) {
			int find = first;
			int index;
			while (find <= last && !ma->residues[chain].res[find].exists) find++;
			if (find > last) break;
			index = ma->residues[chain].res[find].index;
			while (indices[chain] < index) {
				for (chain2=0; chain2<ma->numChains; chain2++) {
					if (chain2 != chain) {
						AddCharacter(out->seqs[chain2], '-');
					}
					else {
						AddCharacter(out->seqs[chain2], ma->chains[chain2]->res[indices[chain2]++].residue);
					}
				}
			}
		}
		while (first <= last) {
			for (chain=0; chain<ma->numChains; chain++) {
				if (ma->residues[chain].res[first].exists) {
					AddCharacter(out->seqs[chain], ma->chains[chain]->res[indices[chain]++].residue);
				}
				else {
					AddCharacter(out->seqs[chain], '-');
				}
			}
			first++;
		}
	}
	for (chain=0; chain<ma->numChains; chain++) {
		while (indices[chain] < ma->chains[chain]->length) {
			for (chain2=0; chain2<ma->numChains; chain2++) {
				if (chain2 != chain) {
					AddCharacter(out->seqs[chain2], '-');
				}
				else {
					AddCharacter(out->seqs[chain2], ma->chains[chain2]->res[indices[chain2]++].residue);
				}
			}
		}
	}
	free(indices);
	Reorder(out);
	return out;
}
コード例 #9
0
static int TXT_InputBoxKeyPress(TXT_UNCAST_ARG(inputbox), int key)
{
    TXT_CAST_ARG(txt_inputbox_t, inputbox);

    if (!inputbox->editing)
    {
        if (key == KEY_ENTER)
        {
            SetBufferFromValue(inputbox);
            inputbox->editing = 1;
            return 1;
        }

        return 0;
    }

    if (key == KEY_ENTER)
    {
        free(*((char **)inputbox->value));
        *((char **) inputbox->value) = strdup(inputbox->buffer);

        TXT_EmitSignal(&inputbox->widget, "changed");

        inputbox->editing = 0;
    }

    if (key == KEY_ESCAPE)
    {
        inputbox->editing = 0;
    }

    if (isprint(key))
    {
        // Add character to the buffer

        AddCharacter(inputbox, key);
    }

    if (key == KEY_BACKSPACE)
    {
        Backspace(inputbox);
    }
    
    return 1;
}
コード例 #10
0
static int TXT_IntInputBoxKeyPress(TXT_UNCAST_ARG(inputbox), int key)
{
    TXT_CAST_ARG(txt_inputbox_t, inputbox);

    if (!inputbox->editing)
    {
        if (key == KEY_ENTER)
        {
            strcpy(inputbox->buffer, "");
            inputbox->editing = 1;
            return 1;
        }

        return 0;
    }

    if (key == KEY_ENTER)
    {
        *((int *) inputbox->value) = atoi(inputbox->buffer);

        inputbox->editing = 0;
    }

    if (key == KEY_ESCAPE)
    {
        inputbox->editing = 0;
    }

    if (isdigit(key))
    {
        // Add character to the buffer

        AddCharacter(inputbox, key);
    }

    if (key == KEY_BACKSPACE)
    {
        Backspace(inputbox);
    }
    
    return 1;
}
コード例 #11
0
ファイル: PARSER.C プロジェクト: dougc333/stanford
int AddSymbol(char *e, int *place, CharSetT *cs) {
  int input, symbol, number[3];

  input = NextCharacter(e, *place);
  symbol = input;
  AdvanceParser(e, place);
  if (input == '\\') {
    symbol = NextCharacter(e, *place); 
    AdvanceParser(e, place);
  } 
  if (input == '#') {
    number[0] = NextCharacter(e, *place); AdvanceParser(e, place);
    number[1] = NextCharacter(e, *place); AdvanceParser(e, place);
    number[2] = NextCharacter(e, *place); AdvanceParser(e, place);
    if (!isdigit(number[0]) || !isdigit(number[1]) || !isdigit(number[2]))
      return 0;
    else symbol = ((number[0] - '0') * 100 + (number[1] - '0') * 
		   10 + number[2] - '0');
    if (symbol > 255) return 0;
  }
  AddCharacter(symbol, cs);
  return 1;
}
コード例 #12
0
//! updates a text vertex buffer
void GeometryProvider::UpdateTextVertexBuffer(VertexBuffer* pVertexBuffer, Font* pFont, const std::string& text, const Size& size, Text::E_Alignement alignement, u32 lineSpacing, const Color& color)
{
    s32 maxCharactersPerLine = size.Width/s32(pFont->GetCharacterSize().X);

    std::vector<std::string> words;
    Utils::Tokenize(text.c_str(), " ", words);

    std::vector< LineInfo > lines;
    u32 currentLine = 0;
    s32 charactersRemainingThisLine = maxCharactersPerLine;
    u32 totalCharacters = 0;
    for(u32 currentWord=0; currentWord < words.size(); ++currentWord)
    {
        if(currentLine == lines.size())
        {
            lines.push_back(LineInfo());
        }

        if(s32(words[currentWord].length()) < charactersRemainingThisLine
                || lines[currentLine].words.empty())
        {
            charactersRemainingThisLine -= words[currentWord].length();
            --charactersRemainingThisLine; // consume one space
            if(!lines[currentLine].words.empty())
            {
                lines[currentLine].numCharacters++; // consume one space
                ++totalCharacters;
            }
            u32 wordLength = words[currentWord].length();
            std::string word = words[currentWord].substr(0, Math::Min(wordLength, u32(maxCharactersPerLine)));
            lines[currentLine].words.push_back(word);
            lines[currentLine].numCharacters += word.length();
            totalCharacters += word.length();
        }
        else
        {
            charactersRemainingThisLine = maxCharactersPerLine;
            ++currentLine;
            --currentWord;
        }
    }

    u32 numVertices = totalCharacters*6;
    if(numVertices > pVertexBuffer->GetMaxVertices())
    {
        Vertex3D* pVertices = snew Vertex3D[numVertices];
        pVertexBuffer->SetVertices(pVertices, numVertices);
    }
    pVertexBuffer->SetNumVertices(0);
    pVertexBuffer->SetMaxVertices(numVertices);

    u32 currentCharacter = 0;
    for(u32 i=0; i<lines.size(); ++i)
    {
        Vector2 vCharacterPos(0.0f, f32(i*lineSpacing));

        switch(alignement)
        {
        case Text::A_Center:
            vCharacterPos.X = (f32(size.Width)-(pFont->GetCharacterSize().X*lines[i].numCharacters))/2.0f;
            break;

        case Text::A_Right:
            vCharacterPos.X = f32(size.Width)-(pFont->GetCharacterSize().X*lines[i].numCharacters);
            break;
        }

        for(u32 j=0; j<lines[i].words.size(); ++j)
        {
            for(u32 k=0; k<lines[i].words[j].length(); ++k)
            {
                AddCharacter(pVertexBuffer, pFont, lines[i].words[j].at(k), vCharacterPos, currentCharacter++, color);
                vCharacterPos.X += pFont->GetCharacterSize().X;
            }

            if(j+1 < lines[i].words.size())
            {
                AddCharacter(pVertexBuffer, pFont, ' ', vCharacterPos, currentCharacter++, color);
                vCharacterPos.X += pFont->GetCharacterSize().X;
            }
        }
    }
}
コード例 #13
0
ファイル: ctextinputwidget.cpp プロジェクト: acekiller/poro
void CTextInputWidget::OnKeyboardEvent( CKeyboardEvent* event )
{
	if( event->GetType() == types::key_down )
	{
		switch( event->GetKey() )
		{
		case types::keys::_backspace:
			OnKeyBackspace();
			break;

		case types::keys::_return:
			OnKeyEnter();
			break;

		case types::keys::_tab:
			OnKeyTab();
			break;

		case types::keys::_up:
			OnKeyUp();
			break;

		case types::keys::_down:
			OnKeyDown();
			break;

		case types::keys::_left:
			OnKeyLeft();
			break;

		case types::keys::_right:
			OnKeyRight();
			break;

		case types::keys::_delete:
			OnKeyDelete();
			break;

		case types::keys::_home:
			OnKeyHome();
			break;

		case types::keys::_end:
			OnKeyEnd();
			break;
		case types::keys::_escape:
			OnKeyEsc();
			break;

		default:
			{
				if( IsValidKey( event->GetAsCharacter() ) )
				{
					AddCharacter( event->GetAsCharacter() );
				}
			}
			break;
		}

	}
}
コード例 #14
0
ファイル: PARSER.C プロジェクト: dougc333/stanford
RegExpressionT *S(char *e, int *place) {
  int input, number[3];
  RegExpressionT *ex;
  CharSetT *cs;

  input = NextCharacter(e, *place);  
  switch(input) {
  case '{':
    cs = CreateCharSet();
    while(1) {
      AdvanceParser(e, place);
      input = NextCharacter(e, *place);
      if (input == '}') break;
      switch(input) {
      case 's': AddCharacter(' ', cs); break;
      case 'n': AddCharacter('\n', cs); break;
      case 'r': AddCharacter('\r', cs); break;
      case 't': AddCharacter('\t', cs); break;
      case 'f': AddCharacter('\f', cs); break;
      default: 
#if ERR_MESG
	fprintf(stderr, "Bad regexp: character %c.\n", input);
	fprintf(stderr, "%s == at %d\n", e, *place);
#endif
	free(cs); return NULL;
      }
    }
    AdvanceParser(e, place);
    ex = NewRegularExpression();
    ex->type = CHARSET;
    ex->charset = cs;
    return ex;
  case '$':
    AdvanceParser(e, place);
    ex = NewRegularExpression();
    ex->type = CHARSET;
    ex->charset = BuildPrintableCharSet();
    return ex;
  case '.':
    AdvanceParser(e, place);
    ex = NewRegularExpression();
    ex->type = ANYCHAR;
    return ex;
  case '&':          
    AdvanceParser(e, place);
    ex = NewRegularExpression();
    ex->type = EMPTY;
    return ex;
  case '\\':
    AdvanceParser(e, place);
    input = NextCharacter(e, *place);
    AdvanceParser(e, place);
    ex = NewRegularExpression();
    ex->type = ATOM;
    ex->value = input;
    return ex;
  case '#':
    AdvanceParser(e, place);
    number[0] = NextCharacter(e, *place); AdvanceParser(e, place);
    number[1] = NextCharacter(e, *place); AdvanceParser(e, place);
    number[2] = NextCharacter(e, *place); AdvanceParser(e, place);
    if (!isdigit(number[0]) || !isdigit(number[1]) || !isdigit(number[2]))
      {
#if ERR_MESG
	fprintf(stderr, "Specified character value not a number.\n");
	fprintf(stderr, "%s == at %d\n", e, *place);
#endif
	return NULL;
      }
    input = (((number[0] - '0') * 100) + ((number[1] - '0') * 10) +
	     number[2] - '0');
    if (input >= 256) {
#if ERR_MESG
      fprintf(stderr, "Invalid character value: %d.\n", input);
      fprintf(stderr, "%s == at %d\n", e, *place);
#endif
      return NULL;
    }
    ex = NewRegularExpression();
    ex->type = ATOM;
    ex->value = input;
    return ex;
  default: 
    if (strchr(specialChars, input)) {
#if ERR_MESG
      fprintf(stderr, "Bad regexp: character %c.\n", input);
      fprintf(stderr, "%s == at %d\n", e, *place);
#endif
      return NULL;
    }
    AdvanceParser(e, place);
    ex = NewRegularExpression();
    ex->type = ATOM;
    ex->value = input;
    return ex;       
  }
  return NULL;
}
コード例 #15
0
ファイル: BitmapFont.cpp プロジェクト: pavelsimo/Pong
void BitmapFont::AddCharacter(unsigned int glyph, GLfloat x, GLfloat y, GLfloat w, GLfloat h)
{
    Rect rect(x, y, w, h);
    AddCharacter(glyph, rect);
}
コード例 #16
0
ファイル: txt_spinctrl.c プロジェクト: RobbieJVMW/dockerdoom
static int TXT_SpinControlKeyPress(TXT_UNCAST_ARG(spincontrol), int key)
{
    TXT_CAST_ARG(txt_spincontrol_t, spincontrol);

    // Enter to enter edit mode

    if (spincontrol->editing)
    {
        if (key == KEY_ENTER)
        {
            switch (spincontrol->type)
            {
                case TXT_SPINCONTROL_INT:
                    spincontrol->value->i = atoi(spincontrol->buffer);
                    break;

                case TXT_SPINCONTROL_FLOAT:
                    spincontrol->value->f = (float) atof(spincontrol->buffer);
                    break;
            }

            spincontrol->editing = 0;
            EnforceLimits(spincontrol);
            return 1;
        }

        if (key == KEY_ESCAPE)
        {
            // Abort without saving value
            spincontrol->editing = 0;
            return 1;
        }

        if (isdigit(key) || key == '-' || key == '.')
        {
            AddCharacter(spincontrol, key);
            return 1;
        }

        if (key == KEY_BACKSPACE)
        {
            Backspace(spincontrol);
            return 1;
        }
    }
    else
    {
        // Non-editing mode

        if (key == KEY_ENTER)
        {
            spincontrol->editing = 1;
            strcpy(spincontrol->buffer, "");
            return 1;
        }
        if (key == KEY_LEFTARROW)
        {
            switch (spincontrol->type)
            {
                case TXT_SPINCONTROL_INT:
                    spincontrol->value->i -= spincontrol->step.i;
                    break;

                case TXT_SPINCONTROL_FLOAT:
                    spincontrol->value->f -= spincontrol->step.f;
                    break;
            }

            EnforceLimits(spincontrol);

            return 1;
        }
        
        if (key == KEY_RIGHTARROW)
        {
            switch (spincontrol->type)
            {
                case TXT_SPINCONTROL_INT:
                    spincontrol->value->i += spincontrol->step.i;
                    break;

                case TXT_SPINCONTROL_FLOAT:
                    spincontrol->value->f += spincontrol->step.f;
                    break;
            }

            EnforceLimits(spincontrol);

            return 1;
        }
    }

    return 0;
}
コード例 #17
0
static void VKBAddCharacter(TXT_UNCAST_ARG(widget), int key)
{
    AddCharacter(vkb_inputbox, key);
    VKBUpdateLabel();
}