Compare commits
2 Commits
5d58d24cb9
...
cc421e56ea
| Author | SHA1 | Date | |
|---|---|---|---|
| cc421e56ea | |||
| ad9a3fb594 |
BIN
data/8bithud.png
Normal file
BIN
data/8bithud.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
194
data/8bithud.txt
Normal file
194
data/8bithud.txt
Normal file
@@ -0,0 +1,194 @@
|
||||
# box width
|
||||
8
|
||||
# box height
|
||||
8
|
||||
# 32 espacio ( )
|
||||
2
|
||||
# 33 !
|
||||
2
|
||||
# 34 "
|
||||
5
|
||||
# 35 #
|
||||
6
|
||||
# 36 $
|
||||
6
|
||||
# 37 %
|
||||
6
|
||||
# 38 &
|
||||
6
|
||||
# 39 '
|
||||
2
|
||||
# 40 (
|
||||
3
|
||||
# 41 )
|
||||
3
|
||||
# 42 *
|
||||
4
|
||||
# 43 +
|
||||
3
|
||||
# 44 ,
|
||||
2
|
||||
# 45 -
|
||||
3
|
||||
# 46 .
|
||||
2
|
||||
# 47 /
|
||||
4
|
||||
# 48 0
|
||||
6
|
||||
# 49 1
|
||||
6
|
||||
# 50 2
|
||||
6
|
||||
# 51 3
|
||||
6
|
||||
# 52 4
|
||||
6
|
||||
# 53 5
|
||||
6
|
||||
# 54 6
|
||||
6
|
||||
# 55 7
|
||||
6
|
||||
# 56 8
|
||||
6
|
||||
# 57 9
|
||||
6
|
||||
# 58 :
|
||||
2
|
||||
# 59 ;
|
||||
2
|
||||
# 60 <
|
||||
4
|
||||
# 61 =
|
||||
3
|
||||
# 62 >
|
||||
4
|
||||
# 63 ?
|
||||
6
|
||||
# 64 @
|
||||
8
|
||||
# 65 A
|
||||
6
|
||||
# 66 B
|
||||
6
|
||||
# 67 C
|
||||
6
|
||||
# 68 D
|
||||
6
|
||||
# 69 E
|
||||
6
|
||||
# 70 F
|
||||
6
|
||||
# 71 G
|
||||
6
|
||||
# 72 H
|
||||
6
|
||||
# 73 I
|
||||
6
|
||||
# 74 J
|
||||
6
|
||||
# 75 K
|
||||
6
|
||||
# 76 L
|
||||
6
|
||||
# 77 M
|
||||
6
|
||||
# 78 N
|
||||
6
|
||||
# 79 O
|
||||
6
|
||||
# 80 P
|
||||
6
|
||||
# 81 Q
|
||||
6
|
||||
# 82 R
|
||||
6
|
||||
# 83 S
|
||||
6
|
||||
# 84 T
|
||||
6
|
||||
# 85 U
|
||||
6
|
||||
# 86 V
|
||||
5
|
||||
# 87 W
|
||||
6
|
||||
# 88 X
|
||||
6
|
||||
# 89 Y
|
||||
6
|
||||
# 90 Z
|
||||
6
|
||||
# 91 [
|
||||
3
|
||||
# 92 \
|
||||
5
|
||||
# 93 ]
|
||||
3
|
||||
# 94 ^
|
||||
4
|
||||
# 95 _
|
||||
6
|
||||
# 96 `
|
||||
2
|
||||
# 97 a
|
||||
5
|
||||
# 98 b
|
||||
5
|
||||
# 99 c
|
||||
5
|
||||
# 100 d
|
||||
5
|
||||
# 101 e
|
||||
5
|
||||
# 102 f
|
||||
5
|
||||
# 103 g
|
||||
5
|
||||
# 104 h
|
||||
5
|
||||
# 105 i
|
||||
4
|
||||
# 106 j
|
||||
5
|
||||
# 107 k
|
||||
5
|
||||
# 108 l
|
||||
5
|
||||
# 109 m
|
||||
6
|
||||
# 110 n
|
||||
5
|
||||
# 111 o
|
||||
5
|
||||
# 112 p
|
||||
5
|
||||
# 113 q
|
||||
5
|
||||
# 114 r
|
||||
5
|
||||
# 115 s
|
||||
5
|
||||
# 116 t
|
||||
4
|
||||
# 117 u
|
||||
5
|
||||
# 118 v
|
||||
5
|
||||
# 119 w
|
||||
6
|
||||
# 120 x
|
||||
4
|
||||
# 121 y
|
||||
4
|
||||
# 122 z
|
||||
5
|
||||
# 123 {
|
||||
3
|
||||
# 124 |
|
||||
2
|
||||
# 125 }
|
||||
3
|
||||
# 126 ~
|
||||
3
|
||||
2
main.cpp
2
main.cpp
@@ -246,7 +246,7 @@ 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->setBgColor({123, 99, 63});
|
||||
osk->setCaption("JAILER_ID");
|
||||
osk->setChars(USE_UPPER | USE_NUMBER);
|
||||
osk->setChars(USE_UPPER | USE_LOWER | USE_NUMBER);
|
||||
}
|
||||
|
||||
// Inicializa el sprite
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "on_screen_keyboard.h"
|
||||
//#include <iostream>
|
||||
|
||||
// Constructor
|
||||
OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string iconFile, string bitmapFile, string textFile, options_t *options, int width, int height, color_t color)
|
||||
@@ -24,9 +25,6 @@ OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string
|
||||
use_char_lower = false;
|
||||
use_char_numbers = false;
|
||||
use_char_symbol = false;
|
||||
totalChars = getTotalChars();
|
||||
columns = getColumns();
|
||||
rows = getRows();
|
||||
setLayout();
|
||||
caption = "";
|
||||
dest = {(options->screen.nativeWidth - width) / 2, (options->screen.nativeHeight - height) / 2, width, height};
|
||||
@@ -58,6 +56,15 @@ OnScreenKeyboard::~OnScreenKeyboard()
|
||||
// Rellena la textura de fondo con el color y el texto
|
||||
void OnScreenKeyboard::fillTexture()
|
||||
{
|
||||
// Destruye la textura si la hubiera
|
||||
if (texture)
|
||||
SDL_DestroyTexture(texture);
|
||||
|
||||
// Crea la textura
|
||||
height = (text->getCharacterSize() * 4) + (text->getCharacterSize() * rows * 2);
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
||||
dest = {(options->screen.nativeWidth - width) / 2, (options->screen.nativeHeight - height) / 2, width, height};
|
||||
|
||||
// Empieza a dibujar en la textura
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
|
||||
@@ -80,12 +87,20 @@ void OnScreenKeyboard::fillTexture()
|
||||
|
||||
// Dibuja los caracteres que conformaran el teclado
|
||||
int dist = text->getCharacterSize() * 2;
|
||||
for (int i = 0; i < columns; ++i)
|
||||
int offset_x = text->getCharacterSize();
|
||||
int offset_y = text->getCharacterSize() * 3;
|
||||
for (int j = 0; j < rows; ++j)
|
||||
for (int i = 0; i < columns; ++i)
|
||||
{
|
||||
int pos = i + (j * columns);
|
||||
if (pos < (int)layout.size())
|
||||
text->write(i * dist, j * dist, layout.at(i + (j * columns)));
|
||||
{
|
||||
color_t color = randColor();
|
||||
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_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);
|
||||
}
|
||||
}
|
||||
|
||||
// Deja de dibujar en la textura
|
||||
@@ -106,21 +121,16 @@ int OnScreenKeyboard::getTotalChars()
|
||||
// Calcula cuantas columnas necesita el teclado
|
||||
int OnScreenKeyboard::getColumns()
|
||||
{
|
||||
const int charSize = text->getCharacterSize();
|
||||
int w = width - (charSize * 2);
|
||||
int total = 0;
|
||||
while (w > 0)
|
||||
{
|
||||
w -= (charSize * 2);
|
||||
++total;
|
||||
}
|
||||
return total;
|
||||
const int keyWidth = text->getCharacterSize() * 2;
|
||||
int rowWidth = width - text->getCharacterSize();
|
||||
|
||||
return rowWidth / keyWidth;
|
||||
}
|
||||
|
||||
// Calcula cuantas filas necesita el teclado
|
||||
int OnScreenKeyboard::getRows()
|
||||
{
|
||||
return totalChars / getColumns();
|
||||
return (totalChars / getColumns())+1;
|
||||
}
|
||||
|
||||
// Establece la disposición del teclado
|
||||
@@ -129,23 +139,34 @@ void OnScreenKeyboard::setLayout()
|
||||
totalChars = getTotalChars();
|
||||
columns = getColumns();
|
||||
rows = getRows();
|
||||
int index_col = 0;
|
||||
int index_row = 0;
|
||||
|
||||
// Establece los caracteres a escribir
|
||||
string allChars = "";
|
||||
allChars = use_char_upper ? allChars + char_upper : allChars;
|
||||
allChars = use_char_lower ? allChars + char_lower : allChars;
|
||||
allChars = use_char_numbers ? allChars + char_numbers : allChars;
|
||||
allChars = use_char_symbol ? allChars + char_symbol : allChars;
|
||||
|
||||
layout.clear();
|
||||
if (use_char_upper)
|
||||
for (int i = 0; i < char_upper.length(); ++i)
|
||||
layout.push_back(char_upper.substr(i, 1));
|
||||
for (int i = 0; i < allChars.length(); ++i)
|
||||
{
|
||||
key_t key;
|
||||
key.col = index_col;
|
||||
key.row = index_row;
|
||||
key.caption = allChars.substr(i, 1);
|
||||
layout.push_back(key);
|
||||
|
||||
if (use_char_lower)
|
||||
for (int i = 0; i < char_lower.length(); ++i)
|
||||
layout.push_back(char_lower.substr(i, 1));
|
||||
//std::cout << key.caption << " " << key.col << " " << key.row << " " << std::endl;
|
||||
|
||||
if (use_char_numbers)
|
||||
for (int i = 0; i < char_numbers.length(); ++i)
|
||||
layout.push_back(char_numbers.substr(i, 1));
|
||||
|
||||
if (use_char_symbol)
|
||||
for (int i = 0; i < char_symbol.length(); ++i)
|
||||
layout.push_back(char_symbol.substr(i, 1));
|
||||
++index_col;
|
||||
if (index_col == columns)
|
||||
{
|
||||
index_col = 0;
|
||||
++index_row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la lógica del objeto
|
||||
|
||||
@@ -26,6 +26,14 @@ private:
|
||||
options_t *options; // Variable con todas las opciones del programa
|
||||
SDL_Texture *texture; // Textura donde dibujar el objeto
|
||||
|
||||
// Estructuras
|
||||
struct key_t
|
||||
{
|
||||
int col; // Posición horizontal de la tecla
|
||||
int row; // Posición vertical de la tecla
|
||||
string caption; // Texto de la tecla
|
||||
};
|
||||
|
||||
// Variables
|
||||
string char_upper; // Cadena de texto con las letras en mayúscula
|
||||
string char_lower; // Cadena de texto con las letras en minuscula
|
||||
@@ -43,7 +51,7 @@ private:
|
||||
int width; // Ancho del objeto
|
||||
int height; // Altura del objeto
|
||||
SDL_Rect dest; // Coordenadas donde se dibuja el objeto en pantalla
|
||||
vector<string> layout; // Contiene la disposición del teclado
|
||||
vector<key_t> layout; // Contiene la disposición del teclado
|
||||
|
||||
// Rellena la textura de fondo con el color y el texto
|
||||
void fillTexture();
|
||||
|
||||
@@ -602,3 +602,13 @@ color_t lightenColor(color_t color, int amount)
|
||||
newColor.b = min(255, color.b + amount);
|
||||
return newColor;
|
||||
}
|
||||
|
||||
// Obtiene un color aleatorio
|
||||
color_t randColor()
|
||||
{
|
||||
color_t newColor;
|
||||
newColor.r = rand() % 256;
|
||||
newColor.g = rand() % 256;
|
||||
newColor.b = rand() % 256;
|
||||
return newColor;
|
||||
}
|
||||
@@ -207,4 +207,7 @@ color_t darkenColor(color_t color, int amount);
|
||||
// Aclara un color
|
||||
color_t lightenColor(color_t color, int amount);
|
||||
|
||||
// Obtiene un color aleatorio
|
||||
color_t randColor();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user