I had been chasing a problem within the game library that was corrupting Text Fonts when they are being rescaled.
Here is a picture of a corrupted font compared to what the font should be like.
I blew more time than what I am prepared to admit to..... and it ended up being caused be a corrupted windows installation on my development machine, rather than a fault in the library.
Anyway, a little more progress was made with the menu code by creating "Text Class" code and "Input Class" code.
We now have the capability of producing text on the menu screens, as well as having individually focusing entry areas on the menu screens.
Both these are also auto resizing so that the menus will function on ALL current possible screen resolutions.
This is just a proof of concept of these 2 new features.
I will next create proper "Host" and "Client" screens that will use these new menu features, rather than just dump it onto the main screen as was done at the moment (for the picture).
Hopefully in around one week time the menu code will be ready and we can start on re-porting the old game code to the new engine.
For those that are interested, this is what the current Menu Classes look like.
Code: Select all
#include "TV3D.h"
#define NoKeyPressed 0
extern CTVScreen2DImmediate *p2D;
extern CTVTextureFactory *pTextureFactory;
extern CTVScreen2DText *pText;
extern CTVInputEngine *pInput;
extern ProgramSettings Program;
//#################### Background Class ###########################
class Background
{
protected:
int TextureId;
cTV_TEXTURE Texture;
float RealX1, RealY1, RealX2, RealY2;//Real screen values
public:
void BackgroundTexture(int);
void BackgroundSizeUp(int, int);
void BackgroundRender();
};
void Background::BackgroundTexture(int background_texture_id)
{
TextureId = background_texture_id;
}
void Background::BackgroundSizeUp(int GameWidth, int GameHeight)
{
//ScreenNormalisedHeight = GameHeight*(Texture.RealWidth / GameWidth);
Texture = pTextureFactory->GetTextureInfo( TextureId);
RealY1 = ((GameHeight*(Texture.RealWidth / GameWidth)) - Texture.RealHeight) / 2;
RealY2 = GameHeight - RealY1;
RealX1 = 0;
RealX2 = GameWidth;
}
void Background::BackgroundRender()
{
p2D->Draw_Texture(TextureId, RealX1, RealY1, RealX2, RealY2, -1, -2, -2, -2, 0.0, 0.0, 1.0, 1.0);;
}
//###################### Button Class #############################
class Button
{
protected:
float X1, Y1, X2, Y2;//Normalised values
float RealX1, RealY1, RealX2, RealY2;//Real screen values
int UpTextureId, DownTextureId;
int TextureToRender;
public:
Button(float,float,float,float);//X1, Y1, X2, Y2
void Texture(int,int);//Texture Up ID, Texture Down ID.
void SizeUp(int, int);//Screen width, Screen height
int MouseToButton();//Returns a clicked validation
void ButtonRender();
//void ~Button();
};
Button::Button(float x1, float y1, float x2, float y2)
{
X1 = x1;
Y1 = y1;
X2 = x2;
Y2 = y2;
}
void Button::Texture(int up_texture_id, int down_texture_id)
{
UpTextureId = up_texture_id;
DownTextureId = down_texture_id;
TextureToRender = UpTextureId;// initialise with the UpTextureId
}
void Button::SizeUp(int GameWidth, int GameHeight)
{
RealX1 = (X1*GameWidth);
RealY1 = (Y1*GameWidth*0.56f + (GameHeight - GameWidth*0.56f)/2.0f);
RealX2 = (X2*GameWidth);
RealY2 = (Y2*GameWidth*0.56f + (GameHeight - GameWidth*0.56f)/2.0f);
}
int Button::MouseToButton()
{
int X,Y,MouseLPressed;
POINT MousePoint;
if (!Program.iWindowedMode)//External flag
{
GetCursorPos(&MousePoint);
X = (int)MousePoint.x;
Y = (int)MousePoint.y;
}
else
pInput->GetMousePosition ( &X, &Y);
MouseLPressed = pInput->IsMouseButtonPressed(0);
if ((X>(int)RealX1) && (X<(int)RealX2) && (Y>(int)RealY1) && (Y<(int)RealY2))
{
TextureToRender = DownTextureId;
if(MouseLPressed)
return(true);//Button is pressed
else
return(false);//Button is not pressed
}
else
{
TextureToRender = UpTextureId;
return(false);//Cursor is not on the button
}
}
void Button::ButtonRender()
{
p2D->Draw_Texture(TextureToRender, RealX1, RealY1, RealX2, RealY2, -1, -2, -2, -2, 0.0, 0.0, 1.0, 1.0);
}
//###################### Input Class #############################
class Input
{
protected:
float X1, Y1, X2, Y2;//Normalised values
float RealX1, RealY1, RealX2, RealY2;//Real screen values
bool InputBoxActive;
unsigned char KeyArray[255];
int Color,ActiveColor, InactiveColor;
int OldActiveKey, ActiveKey;
int IDFont;
int EntrySize;
public:
Input(float,float,float,float,int);//X1, Y1, X2, Y2.
char CurrentText[255];
void InputSizeUp(int, int);//Screen width, Screen height.
void InputToInput();//Handles input to text window.
void InputRender();//Renders the completed text box.
};
Input::Input(float x1, float y1, float x2, float y2, int entrysize)
{
X1 = x1;
Y1 = y1;
X2 = x2;
Y2 = y2;
EntrySize = entrysize;
}
void Input::InputSizeUp(int GameWidth, int GameHeight)
{
RealX1 = (X1*GameWidth);
RealY1 = (Y1*GameWidth*0.56f + (GameHeight - GameWidth*0.56f)/2.0f);
RealX2 = (X2*GameWidth);
RealY2 = (Y2*GameWidth*0.56f + (GameHeight - GameWidth*0.56f)/2.0f);
//Lets create our texture font, clear type AA.
IDFont = pText->TextureFont_Create("our_font_name_string", "Comic Sans MS", (RealY2 - RealY1)/2, false, false, true, false, true);
InactiveColor = RGBA(0.5, 0.5, 0.5, 1);
ActiveColor = RGBA(1, 0, 0, 1);
}
void Input::InputToInput()
{
char ASCIIFromKey[2];
int X,Y,MouseLPressed;
POINT MousePoint;
if (!Program.iWindowedMode)//External flag
{
GetCursorPos(&MousePoint);
X = (int)MousePoint.x;
Y = (int)MousePoint.y;
}
else
pInput->GetMousePosition ( &X, &Y);
MouseLPressed = pInput->IsMouseButtonPressed(0);
if(MouseLPressed)
{
if ((X>(int)RealX1) && (X<(int)RealX2) && (Y>(int)RealY1) && (Y<(int)RealY2))
InputBoxActive = true;
else
InputBoxActive = false;
}
OldActiveKey = ActiveKey;
pInput->GetKeyPressedArray(KeyArray);
if (InputBoxActive)
{
Color = ActiveColor;
for(int loop=1; loop<255; loop++)
{
if (KeyArray[loop])
{
ActiveKey = loop;
break;
}
else
{
ActiveKey = NoKeyPressed;
}
}
if((ActiveKey != OldActiveKey) && (ActiveKey != NoKeyPressed))
{
ASCIIFromKey[0] = (char) pInput->GetASCIIFromKey((cCONST_TV_KEY) ActiveKey);
ASCIIFromKey[1] = NULL;
if (strlen(CurrentText) < EntrySize)//Maximum sized nt reached yet
{
if(((ASCIIFromKey[0]> 47) && (ASCIIFromKey[0] < 58)) || ((ASCIIFromKey[0]> 64) && (ASCIIFromKey[0] < 91)) || (ASCIIFromKey[0] == 46))
strcat (CurrentText, ASCIIFromKey );
}
if ((ASCIIFromKey[0] == 8) && (strlen(CurrentText) > 0))//Backspace 8
CurrentText[strlen(CurrentText) - 1] = NULL;
}
}
else
Color = InactiveColor;
}
void Input::InputRender()
{
pText->Action_BeginText(true);
p2D->Draw_Box(RealX1, RealY1, RealX2, RealY2, Color);//Draw a 2D box for the HOT zone.
pText->TextureFont_DrawText(CurrentText , RealX1, RealY1, RGBA(1, 1, 1, 1), IDFont);//Draw the font in our viewport.
pText->Action_EndText();
}
//###################### Text Class #############################
class Text
{
protected:
float X1, Y1, X2, Y2;//Normalised values
float RealX1, RealY1, RealX2, RealY2;//Real screen values
char * Content;
int Color;
int IDFont;
public:
Text(float,float,float,float,char*);//X1, Y1, X2, Y2.
void TextSizeUp(int, int);//Screen width, Screen height.
void TextRender();//Renders the text.
};
Text::Text(float x1, float y1, float x2, float y2, char * content)
{
X1 = x1;
Y1 = y1;
X2 = x2;
Y2 = y2;
Content = content;
}
void Text::TextSizeUp(int GameWidth, int GameHeight)
{
RealX1 = (X1*GameWidth);
RealY1 = (Y1*GameWidth*0.56f + (GameHeight - GameWidth*0.56f)/2.0f);
RealX2 = (X2*GameWidth);
RealY2 = (Y2*GameWidth*0.56f + (GameHeight - GameWidth*0.56f)/2.0f);
//Lets create our texture font, clear type AA.
IDFont = pText->TextureFont_Create("our_font_name_string", "Comic Sans MS", (RealY2 - RealY1)/2, true, false, true, false, true);
Color = RGBA(1.0, 1.0, 1.0, 1);
}
void Text::TextRender()
{
pText->Action_BeginText(true);
pText->TextureFont_DrawText(Content , RealX1, RealY1, Color, IDFont);//Draw the font in our viewport.
pText->Action_EndText();
}