Ja es pot "enner llour neim". Falta decidir quin de tots els dissenys m'agrada mes

This commit is contained in:
2024-09-29 22:25:31 +02:00
parent edc45b6cec
commit 2d5859b1c4
9 changed files with 327 additions and 99 deletions

View File

@@ -2,20 +2,19 @@
#include <algorithm> // for max, min
// Constructor
EnterName::EnterName(std::string *name)
EnterName::EnterName()
{
// Obtiene el puntero al nombre
this->name = name;
name = "";
// Inicia la lista de caracteres permitidos
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
// characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
pos = 0;
numCharacters = (int)characterList.size();
for (int i = 0; i < NAME_LENGHT; ++i)
{
characterIndex[i] = 0;
}
// Pone la lista de indices para que refleje el nombre
updateCharacterIndex();
}
// Destructor
@@ -45,6 +44,7 @@ void EnterName::incIndex()
{
characterIndex[pos] = 0;
}
updateName();
}
// Decrementa el índice
@@ -55,14 +55,54 @@ void EnterName::decIndex()
{
characterIndex[pos] = numCharacters - 1;
}
updateName();
}
// Actualiza la variable
void EnterName::updateName()
{
name->clear();
name.clear();
for (int i = 0; i < NAME_LENGHT; ++i)
{
name->push_back(characterList[characterIndex[i]]);
name.push_back(characterList[characterIndex[i]]);
}
}
// Actualiza la variable
void EnterName::updateCharacterIndex()
{
for (int i = 0; i < NAME_LENGHT; ++i)
{
characterIndex[i] = 0;
}
for (int i = 0; i < (int)name.size(); ++i)
{
characterIndex[i] = findIndex(name.at(i));
}
}
// Encuentra el indice de un caracter en "characterList"
int EnterName::findIndex(char character)
{
for (int i = 0; i < (int)characterList.size(); ++i)
{
if (character == characterList[i])
{
return i;
}
}
return 0;
}
// Obtiene el nombre
std::string EnterName::getName()
{
return name;
}
// Obtiene la posición que se está editando
int EnterName::getPos()
{
return pos;
}