OnScreenKeyboard: Creado el esqueleto base

This commit is contained in:
2023-05-26 11:00:51 +02:00
parent 40701d9029
commit 54947dce2d
3 changed files with 110 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ Código fuente creado por JailDesigner
#include "units/texture.h"
#include "units/screen.h"
#include "units/input.h"
#include "units/on_screen_keyboard.h"
#include "quickcg.h"
using namespace QuickCG;
@@ -32,6 +33,7 @@ Text *text;
Text *debugText;
Texture *texture;
MovingSprite *sprite;
OnScreenKeyboard *osk;
// Variables de uso general
Uint32 ticks = 0; // Variable para la frecuencia de actualización de la lógica del programa
@@ -90,6 +92,9 @@ void initInput();
// Inicializa el texto
void initText();
// Inicializa el teclado en pantalla
void initOnScreenKeyboard();
// Inicializa el sprite
void initSprite();
@@ -235,6 +240,12 @@ void initText()
debugText = new Text(asset->get("debug.txt"), asset->get("debug.png"), renderer);
}
// Inicializa el teclado en pantalla
void initOnScreenKeyboard()
{
osk = new OnScreenKeyboard(renderer, input, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), options);
}
// Inicializa el sprite
void initSprite()
{
@@ -312,6 +323,9 @@ void initAll(char *argv[])
// Inicializa el texto
initText();
// Inicializa el teclado en pantalla
initOnScreenKeyboard();
// Inicializa el sprite
initSprite();
@@ -514,7 +528,8 @@ void update()
// Incrementa el contador
counter++;
// Actualiza el objeto screen
// Actualiza los objetos
osk->update();
screen->update();
// Actualiza el sprite
@@ -608,6 +623,9 @@ void render()
// Dinuja el texto
renderText();
// Dibuja el teclado en pantalla
osk->render();
// Vuelca el buffer en pantalla
screen->blit();
}
@@ -621,6 +639,10 @@ void freeAll()
if (texture != nullptr)
delete texture;
// Finaliza el teclado en pantalla
if (osk != nullptr)
delete osk;
// Finaliza el texto
if (text != nullptr)
delete text;

View File

@@ -0,0 +1,43 @@
#include "on_screen_keyboard.h"
// Constructor
OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string iconFile, string bitmapFile, string textFile, options_t *options)
{
// Inicializa variables
this->renderer = renderer;
this->options = options;
this->input = input;
// Crea objetos
iconTexture = new Texture(renderer, iconFile);
text = new Text(textFile, bitmapFile, renderer);
// Inicializa variables
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
}
// Destructor
OnScreenKeyboard::~OnScreenKeyboard()
{
// Libera la memoria de los objetos
if (iconTexture != nullptr)
{
delete iconTexture;
}
if (text != nullptr)
{
delete text;
}
}
// Actualiza la lógica del objeto
void OnScreenKeyboard::update()
{
}
// Dibuja el objeto en pantalla
void OnScreenKeyboard::render()
{
text->write(0,0,"ON_SCREEN_KEYBOARD");
}

View File

@@ -0,0 +1,43 @@
#pragma once
#include <SDL2/SDL.h>
#include "utils.h"
#include "text.h"
#include "input.h"
#ifndef ON_SCREEN_KEYBOARD_H
#define ON_SCREEN_KEYBOARD_H
using namespace std;
class OnScreenKeyboard
{
private:
// Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana
Texture *iconTexture; // Textura para los gráficos
Text *text; // Objeto para dibujar texto
Input *input; // Gestor de eventos de entrada de teclado o gamepad
options_t *options; // Variable con todas las opciones del programa
// Variables
string letters;
public:
// Constructor
OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string iconFile, string bitmapFile, string textFile, options_t *options);
// Destructor
~OnScreenKeyboard();
// Actualiza la lógica del objeto
void update();
// Dibuja el objeto en pantalla
void render();
};
#endif