update menu.cpp
This commit is contained in:
@@ -26,10 +26,10 @@ void Menu::init(std::string name, int x, int y, int backgroundType, LTexture *te
|
|||||||
mVerticalPadding = 1;
|
mVerticalPadding = 1;
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
mPosY = y;
|
mPosY = y;
|
||||||
mRectBG.rect.x = 0;
|
mRectBG.x = 0;
|
||||||
mRectBG.rect.y = 0;
|
mRectBG.y = 0;
|
||||||
mRectBG.rect.w = 0;
|
mRectBG.w = 0;
|
||||||
mRectBG.rect.h = 0;
|
mRectBG.h = 0;
|
||||||
mRectBG.r = 0;
|
mRectBG.r = 0;
|
||||||
mRectBG.g = 0;
|
mRectBG.g = 0;
|
||||||
mRectBG.b = 0;
|
mRectBG.b = 0;
|
||||||
@@ -37,10 +37,10 @@ void Menu::init(std::string name, int x, int y, int backgroundType, LTexture *te
|
|||||||
mSelector.rect.y = 0;
|
mSelector.rect.y = 0;
|
||||||
mSelector.rect.w = 0;
|
mSelector.rect.w = 0;
|
||||||
mSelector.rect.h = 0;
|
mSelector.rect.h = 0;
|
||||||
mSelector.r = 0;
|
mSelector.rect.r = 0;
|
||||||
mSelector.g = 0;
|
mSelector.rect.g = 0;
|
||||||
mSelector.b = 0;
|
mSelector.rect.b = 0;
|
||||||
mSelector.a = 255;
|
mSelector.rect.a = 255;
|
||||||
mBackgroundType = backgroundType;
|
mBackgroundType = backgroundType;
|
||||||
mText = text;
|
mText = text;
|
||||||
mRenderer = renderer;
|
mRenderer = renderer;
|
||||||
@@ -157,7 +157,6 @@ void Menu::reset()
|
|||||||
{
|
{
|
||||||
mItemSelected = MENU_NO_OPTION;
|
mItemSelected = MENU_NO_OPTION;
|
||||||
mSelector.index = 0;
|
mSelector.index = 0;
|
||||||
//moveSelectorSprite(mSelector.index);
|
|
||||||
mSelector.origin = mSelector.target = mSelector.y = mItem[0].y;
|
mSelector.origin = mSelector.target = mSelector.y = mItem[0].y;
|
||||||
mSelector.moving = false;
|
mSelector.moving = false;
|
||||||
}
|
}
|
||||||
@@ -245,15 +244,17 @@ void Menu::update()
|
|||||||
// Pinta el menu en pantalla
|
// Pinta el menu en pantalla
|
||||||
void Menu::render()
|
void Menu::render()
|
||||||
{
|
{
|
||||||
|
SDL_Rect rect = {mRectBG.x, mRectBG.y, mRectBG.w, mRectBG.h};
|
||||||
|
|
||||||
// Rendereritza el fondo del menu
|
// Rendereritza el fondo del menu
|
||||||
if (mBackgroundType == MENU_BACKGROUND_SOLID)
|
if (mBackgroundType == MENU_BACKGROUND_SOLID)
|
||||||
{
|
{
|
||||||
SDL_SetRenderDrawColor(mRenderer, mRectBG.r, mRectBG.g, mRectBG.b, mRectBG.a);
|
SDL_SetRenderDrawColor(mRenderer, mRectBG.r, mRectBG.g, mRectBG.b, mRectBG.a);
|
||||||
SDL_RenderFillRect(mRenderer, &mRectBG.rect);
|
SDL_RenderFillRect(mRenderer, &rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renderiza el rectangulo del selector
|
// Renderiza el rectangulo del selector
|
||||||
SDL_SetRenderDrawColor(mRenderer, mSelector.r, mSelector.g, mSelector.b, mSelector.a);
|
SDL_SetRenderDrawColor(mRenderer, mSelector.rect.r, mSelector.rect.g, mSelector.rect.b, mSelector.rect.a);
|
||||||
SDL_RenderFillRect(mRenderer, &mSelector.rect);
|
SDL_RenderFillRect(mRenderer, &mSelector.rect);
|
||||||
|
|
||||||
// Renderitza el text
|
// Renderitza el text
|
||||||
@@ -274,37 +275,37 @@ void Menu::render()
|
|||||||
void Menu::setRectSize()
|
void Menu::setRectSize()
|
||||||
{
|
{
|
||||||
Uint8 i = 0;
|
Uint8 i = 0;
|
||||||
mRectBG.rect.w = 0;
|
mRectBG.w = 0;
|
||||||
mRectBG.rect.h = 0;
|
mRectBG.h = 0;
|
||||||
mSelector.rect.w = 0;
|
mSelector.rect.w = 0;
|
||||||
mSelector.rect.h = 0;
|
mSelector.rect.h = 0;
|
||||||
|
|
||||||
// Obtenemos la anchura del item mas ancho y la altura de la suma de alturas de los items
|
// Obtenemos la anchura del item mas ancho y la altura de la suma de alturas de los items
|
||||||
for (i = 0; i < mTotalItems; i++)
|
for (i = 0; i < mTotalItems; i++)
|
||||||
{
|
{
|
||||||
if (mItem[i].w > mRectBG.rect.w)
|
if (mItem[i].w > mRectBG.w)
|
||||||
{
|
{
|
||||||
mRectBG.rect.w = mItem[i].w;
|
mRectBG.w = mItem[i].w;
|
||||||
}
|
}
|
||||||
mRectBG.rect.h += mItem[i].h + mItem[i].hPaddingDown;
|
mRectBG.h += mItem[i].h + mItem[i].hPaddingDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
// La anchura de la cadena más larga, mas un caracter, mas la anchura del sprite del selector
|
// La anchura de la cadena más larga, mas un caracter, mas la anchura del sprite del selector
|
||||||
mRectBG.rect.w += (mText->getHeight() * 1); // + mSelectorSprite.getWidth();
|
mRectBG.w += (mText->getHeight() * 1); // + mSelectorSprite.getWidth();
|
||||||
|
|
||||||
// La altura de la suma de los items mas un caracter y menos un pixel (porque el texto en realidad es de 7 pixeles)
|
// La altura de la suma de los items mas un caracter y menos un pixel (porque el texto en realidad es de 7 pixeles)
|
||||||
mRectBG.rect.h += (mText->getHeight() * 1) - 1;
|
mRectBG.h += (mText->getHeight() * 1) - 1;
|
||||||
|
|
||||||
// La posición X es la del menú menos la anchura del sprite del selector y menos medio caracter
|
// La posición X es la del menú menos la anchura del sprite del selector y menos medio caracter
|
||||||
mRectBG.rect.x = mPosX - (mText->getHeight() / 2); // - mSelectorSprite.getWidth();
|
mRectBG.x = mPosX - (mText->getHeight() / 2); // - mSelectorSprite.getWidth();
|
||||||
|
|
||||||
// La posición Y es la del menu menos la altura de medio caracter i el padding
|
// La posición Y es la del menu menos la altura de medio caracter i el padding
|
||||||
mRectBG.rect.y = mPosY - (mText->getHeight() / 2) - mVerticalPadding;
|
mRectBG.y = mPosY - (mText->getHeight() / 2) - mVerticalPadding;
|
||||||
|
|
||||||
// Establecemos los valores del rectangulo del selector a partir de los valores del rectangulo de fondo
|
// Establecemos los valores del rectangulo del selector a partir de los valores del rectangulo de fondo
|
||||||
mSelector.rect.h = (mText->getHeight() * 1) + 1;
|
mSelector.rect.h = (mText->getHeight() * 1) + 1;
|
||||||
mSelector.rect.w = mRectBG.rect.w;
|
mSelector.rect.w = mRectBG.w;
|
||||||
mSelector.rect.x = mRectBG.rect.x;
|
mSelector.rect.x = mRectBG.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
@@ -325,10 +326,10 @@ void Menu::setBackgroundColor(int r, int g, int b, int alpha)
|
|||||||
// Establece el color del rectangulo del selector
|
// Establece el color del rectangulo del selector
|
||||||
void Menu::setSelectorColor(int r, int g, int b, int alpha)
|
void Menu::setSelectorColor(int r, int g, int b, int alpha)
|
||||||
{
|
{
|
||||||
mSelector.r = r;
|
mSelector.rect.r = r;
|
||||||
mSelector.g = g;
|
mSelector.rect.g = g;
|
||||||
mSelector.b = b;
|
mSelector.rect.b = b;
|
||||||
mSelector.a = alpha;
|
mSelector.rect.a = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el color del texto del selector
|
// Establece el color del texto del selector
|
||||||
|
|||||||
@@ -114,11 +114,14 @@ private:
|
|||||||
|
|
||||||
struct rectangle
|
struct rectangle
|
||||||
{
|
{
|
||||||
SDL_Rect rect; // Rectangulo
|
Uint8 x; // Posición en el eje X
|
||||||
Uint8 r; // Rojo
|
Uint8 y; // Posición en el eje Y
|
||||||
Uint8 g; // Verde
|
Uint8 w; // Anchura
|
||||||
Uint8 b; // Azul
|
Uint8 h; // Altura
|
||||||
Uint8 a; // Transparencia
|
Uint8 r; // Rojo
|
||||||
|
Uint8 g; // Verde
|
||||||
|
Uint8 b; // Azul
|
||||||
|
Uint8 a; // Transparencia
|
||||||
};
|
};
|
||||||
|
|
||||||
rectangle mRectBG; // Rectangulo de fondo del menu
|
rectangle mRectBG; // Rectangulo de fondo del menu
|
||||||
@@ -143,14 +146,10 @@ private:
|
|||||||
double target; // Coordenada de destino
|
double target; // Coordenada de destino
|
||||||
double y; // Coordenada actual
|
double y; // Coordenada actual
|
||||||
Uint8 numJumps; // Numero de pasos preestablecido para llegar al destino
|
Uint8 numJumps; // Numero de pasos preestablecido para llegar al destino
|
||||||
double despY; // (target - origin) / numJumps
|
double despY; // Desplazamiento en el eje Y que realiza el selector en cada iteración. (target - origin) / numJumps
|
||||||
bool moving; // Indica si el selector está avanzando hacia el destino
|
bool moving; // Indica si el selector está avanzando hacia el destino
|
||||||
Uint8 index; // Elemento del menu que tiene el foco
|
Uint8 index; // Elemento del menu que tiene el foco
|
||||||
SDL_Rect rect; // Rectangulo para dibujar el selector
|
rectangle rect; // Rectangulo del selectur
|
||||||
Uint8 r; // Color para el selector. Rojo
|
|
||||||
Uint8 g; // Color para el selector. Verde
|
|
||||||
Uint8 b; // Color para el selector. Azul
|
|
||||||
Uint8 a; // Color para el selector. Transparencia
|
|
||||||
Uint8 itemR; // Color para el texto seleccionado. Rojo
|
Uint8 itemR; // Color para el texto seleccionado. Rojo
|
||||||
Uint8 itemG; // Color para el texto seleccionado. Verde
|
Uint8 itemG; // Color para el texto seleccionado. Verde
|
||||||
Uint8 itemB; // Color para el texto seleccionado. Azul
|
Uint8 itemB; // Color para el texto seleccionado. Azul
|
||||||
|
|||||||
Reference in New Issue
Block a user