on_screen_keyboard: Ya se pueden añadir y quitar caracteres al texto de salida
This commit is contained in:
2
main.cpp
2
main.cpp
@@ -243,7 +243,7 @@ void initText()
|
|||||||
// Inicializa el teclado en pantalla
|
// Inicializa el teclado en pantalla
|
||||||
void initOnScreenKeyboard()
|
void initOnScreenKeyboard()
|
||||||
{
|
{
|
||||||
osk = new OnScreenKeyboard(renderer, input, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), options, options->screen.nativeWidth - 30, options->screen.nativeHeight - 80);
|
osk = new OnScreenKeyboard(renderer, input, asset->get("smb2.png"), asset->get("smb2.txt"), options, options->screen.nativeWidth - 30, options->screen.nativeHeight - 80, "JailDesigner");
|
||||||
osk->setBgColor({123, 99, 63});
|
osk->setBgColor({123, 99, 63});
|
||||||
osk->setCaption("JAILER_ID");
|
osk->setCaption("JAILER_ID");
|
||||||
osk->setChars(USE_UPPER | USE_LOWER | USE_NUMBER);
|
osk->setChars(USE_UPPER | USE_LOWER | USE_NUMBER);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// #include <iostream>
|
// #include <iostream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string iconFile, string bitmapFile, string textFile, options_t *options, int width, int height, color_t color)
|
OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string bitmapFile, string textFile, options_t *options, int width, int height, string output, color_t color)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
@@ -12,13 +12,13 @@ OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string
|
|||||||
this->height = height;
|
this->height = height;
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
iconTexture = new Texture(renderer, iconFile);
|
|
||||||
text = new Text(textFile, bitmapFile, renderer);
|
text = new Text(textFile, bitmapFile, renderer);
|
||||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
||||||
textureCursor = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, text->getCharacterSize() * 2, text->getCharacterSize() * 2);
|
textureCursor = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, text->getCharacterSize() * 2, text->getCharacterSize() * 2);
|
||||||
SDL_SetTextureBlendMode(textureCursor, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(textureCursor, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
|
this->output = output;
|
||||||
char_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
char_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
char_lower = "abcdefghijklmnopqrstuvwxyz";
|
char_lower = "abcdefghijklmnopqrstuvwxyz";
|
||||||
char_numbers = "0123456789";
|
char_numbers = "0123456789";
|
||||||
@@ -48,11 +48,6 @@ OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string
|
|||||||
OnScreenKeyboard::~OnScreenKeyboard()
|
OnScreenKeyboard::~OnScreenKeyboard()
|
||||||
{
|
{
|
||||||
// Libera la memoria de los objetos
|
// Libera la memoria de los objetos
|
||||||
if (iconTexture != nullptr)
|
|
||||||
{
|
|
||||||
delete iconTexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (text != nullptr)
|
if (text != nullptr)
|
||||||
{
|
{
|
||||||
delete text;
|
delete text;
|
||||||
@@ -93,8 +88,8 @@ void OnScreenKeyboard::fillTexture()
|
|||||||
const int y_rect = text->getCharacterSize();
|
const int y_rect = text->getCharacterSize();
|
||||||
const int w_rect = width - text->getCharacterSize() - x_rect;
|
const int w_rect = width - text->getCharacterSize() - x_rect;
|
||||||
const int h_rect = text->getCharacterSize();
|
const int h_rect = text->getCharacterSize();
|
||||||
SDL_Rect rect = {x_rect, y_rect, w_rect, h_rect};
|
outputDest = {x_rect, y_rect, w_rect, h_rect};
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &outputDest);
|
||||||
|
|
||||||
// Dibuja los caracteres que conformaran el teclado
|
// Dibuja los caracteres que conformaran el teclado
|
||||||
const int dist = text->getCharacterSize() * 2;
|
const int dist = text->getCharacterSize() * 2;
|
||||||
@@ -106,10 +101,10 @@ void OnScreenKeyboard::fillTexture()
|
|||||||
const int pos = i + (j * columns);
|
const int pos = i + (j * columns);
|
||||||
if (pos < (int)layout.size())
|
if (pos < (int)layout.size())
|
||||||
{
|
{
|
||||||
//color_t color = randColor();
|
// color_t color = randColor();
|
||||||
//SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
// SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||||
//SDL_Rect rect = {offset_x + (layout.at(pos).col * dist), offset_y + (layout.at(pos).row * dist), dist, dist};
|
// SDL_Rect rect = {offset_x + (layout.at(pos).col * dist), offset_y + (layout.at(pos).row * dist), dist, dist};
|
||||||
//SDL_RenderFillRect(renderer, &rect);
|
// SDL_RenderFillRect(renderer, &rect);
|
||||||
text->write(offset_x + (layout.at(pos).col * dist) + 4, offset_y + (layout.at(pos).row * dist) + 4, layout.at(pos).caption);
|
text->write(offset_x + (layout.at(pos).col * dist) + 4, offset_y + (layout.at(pos).row * dist) + 4, layout.at(pos).caption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,6 +189,12 @@ void OnScreenKeyboard::checkInput()
|
|||||||
|
|
||||||
if (input->checkInput(INPUT_DOWN, REPEAT_FALSE))
|
if (input->checkInput(INPUT_DOWN, REPEAT_FALSE))
|
||||||
incCursorRow();
|
incCursorRow();
|
||||||
|
|
||||||
|
if (input->checkInput(INPUT_ACCEPT, REPEAT_FALSE))
|
||||||
|
addChar();
|
||||||
|
|
||||||
|
if (input->checkInput(INPUT_CANCEL, REPEAT_FALSE))
|
||||||
|
removeChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disminuye en una columna la posición del cursor
|
// Disminuye en una columna la posición del cursor
|
||||||
@@ -230,6 +231,21 @@ void OnScreenKeyboard::updateCursor()
|
|||||||
cursor.dest.y = dest.y + offset_y + (cursor.row * cursor.dest.h);
|
cursor.dest.y = dest.y + offset_y + (cursor.row * cursor.dest.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Añade un caracter a la salida
|
||||||
|
void OnScreenKeyboard::addChar()
|
||||||
|
{
|
||||||
|
const int pos = cursor.col + cursor.row * columns;
|
||||||
|
if (pos < layout.size())
|
||||||
|
output = output + layout.at(pos).caption;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Borra el último caracter de la salida
|
||||||
|
void OnScreenKeyboard::removeChar()
|
||||||
|
{
|
||||||
|
if (output.length() > 0)
|
||||||
|
output = output.substr(0, output.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza la lógica del objeto
|
// Actualiza la lógica del objeto
|
||||||
void OnScreenKeyboard::update()
|
void OnScreenKeyboard::update()
|
||||||
{
|
{
|
||||||
@@ -245,6 +261,7 @@ void OnScreenKeyboard::render()
|
|||||||
{
|
{
|
||||||
SDL_RenderCopy(renderer, texture, nullptr, &dest);
|
SDL_RenderCopy(renderer, texture, nullptr, &dest);
|
||||||
SDL_RenderCopy(renderer, textureCursor, nullptr, &cursor.dest);
|
SDL_RenderCopy(renderer, textureCursor, nullptr, &cursor.dest);
|
||||||
|
text->write(dest.x + outputDest.x, dest.y + outputDest.y, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el color de fondo
|
// Establece el color de fondo
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ class OnScreenKeyboard
|
|||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Texture *iconTexture; // Textura para los gráficos
|
|
||||||
Text *text; // Objeto para dibujar texto
|
Text *text; // Objeto para dibujar texto
|
||||||
Input *input; // Gestor de eventos de entrada de teclado o gamepad
|
Input *input; // Gestor de eventos de entrada de teclado o gamepad
|
||||||
options_t *options; // Variable con todas las opciones del programa
|
options_t *options; // Variable con todas las opciones del programa
|
||||||
@@ -61,6 +60,8 @@ private:
|
|||||||
SDL_Rect dest; // Coordenadas donde se dibuja el objeto en pantalla
|
SDL_Rect dest; // Coordenadas donde se dibuja el objeto en pantalla
|
||||||
vector<key_t> layout; // Contiene la disposición del teclado
|
vector<key_t> layout; // Contiene la disposición del teclado
|
||||||
cursor_t cursor; // Variable para gestionar el cursor
|
cursor_t cursor; // Variable para gestionar el cursor
|
||||||
|
string output; // Texto de salida
|
||||||
|
SDL_Rect outputDest; // Rectangulo con el texto de salida
|
||||||
|
|
||||||
// Rellena la textura de fondo con el color y el texto
|
// Rellena la textura de fondo con el color y el texto
|
||||||
void fillTexture();
|
void fillTexture();
|
||||||
@@ -95,9 +96,15 @@ private:
|
|||||||
// Actualiza la posición de la textura del cursor
|
// Actualiza la posición de la textura del cursor
|
||||||
void updateCursor();
|
void updateCursor();
|
||||||
|
|
||||||
|
// Añade un caracter a la salida
|
||||||
|
void addChar();
|
||||||
|
|
||||||
|
// Borra el último caracter de la salida
|
||||||
|
void removeChar();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string iconFile, string bitmapFile, string textFile, options_t *options, int width, int height, color_t color = {0, 0, 0});
|
OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string bitmapFile, string textFile, options_t *options, int width, int height, string output = "", color_t color = {0, 0, 0});
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~OnScreenKeyboard();
|
~OnScreenKeyboard();
|
||||||
|
|||||||
Reference in New Issue
Block a user