demo: El teclado se crea y se destruye según se use o no
This commit is contained in:
45
main.cpp
45
main.cpp
@@ -33,7 +33,7 @@ Text *text;
|
||||
Text *debugText;
|
||||
Texture *texture;
|
||||
MovingSprite *sprite;
|
||||
OnScreenKeyboard *osk;
|
||||
OnScreenKeyboard *osk = nullptr;
|
||||
|
||||
// Variables de uso general
|
||||
Uint32 ticks = 0; // Variable para la frecuencia de actualización de la lógica del programa
|
||||
@@ -251,6 +251,30 @@ void initOnScreenKeyboard()
|
||||
osk->setChars(USE_UPPER | USE_LOWER | USE_NUMBER);
|
||||
}
|
||||
|
||||
// Elimina el teclado en pantalla
|
||||
void deleteOnScreenKeyboard()
|
||||
{
|
||||
if (osk != nullptr)
|
||||
{
|
||||
delete osk;
|
||||
osk = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el teclado en pantalla
|
||||
void renderOnScreenKeyboard()
|
||||
{
|
||||
if (osk != nullptr)
|
||||
osk->render();
|
||||
}
|
||||
|
||||
// Actualiza el teclado en pantalla
|
||||
void updateOnScreenKeyboard()
|
||||
{
|
||||
if (osk != nullptr)
|
||||
osk->update();
|
||||
}
|
||||
|
||||
// Inicializa el sprite
|
||||
void initSprite()
|
||||
{
|
||||
@@ -329,7 +353,7 @@ void initAll(char *argv[])
|
||||
initText();
|
||||
|
||||
// Inicializa el teclado en pantalla
|
||||
initOnScreenKeyboard();
|
||||
// initOnScreenKeyboard();
|
||||
|
||||
// Inicializa el sprite
|
||||
initSprite();
|
||||
@@ -382,6 +406,13 @@ void checkEvents()
|
||||
screen->showNotification("Ejemplo de notificacion", "con 2 lineas de texto", 0);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_T:
|
||||
if (osk == nullptr)
|
||||
initOnScreenKeyboard();
|
||||
else
|
||||
deleteOnScreenKeyboard();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -534,11 +565,9 @@ void update()
|
||||
counter++;
|
||||
|
||||
// Actualiza los objetos
|
||||
osk->update();
|
||||
screen->update();
|
||||
|
||||
// Actualiza el sprite
|
||||
updateSprite();
|
||||
updateOnScreenKeyboard(); // Actualiza el teclado en pantalla
|
||||
screen->update(); // Actualiza la pantalla
|
||||
updateSprite(); // Actualiza el sprite
|
||||
|
||||
// Actualiza el efecto de fondo
|
||||
updateFX();
|
||||
@@ -629,7 +658,7 @@ void render()
|
||||
renderText();
|
||||
|
||||
// Dibuja el teclado en pantalla
|
||||
osk->render();
|
||||
renderOnScreenKeyboard();
|
||||
|
||||
// Vuelca el buffer en pantalla
|
||||
screen->blit();
|
||||
|
||||
Reference in New Issue
Block a user