Jump to content
  • Advertisement
  • entries
  • comments
  • views

GUI movie

Sign in to follow this  


The GUI is coming along pretty nicely. I got alignment implemented (you can align to a combination of left, top, right, and/or bottom. Left out-ranks right and top out-ranks bottom for simplicity.) I also implemented a Dialog class that can be moved, destroyed/closed, and resized. Oh, I also implemented the Label class.

One of the cool things is that since the bitmap font system already supports color formatters you can format the text via the text rather than a variable. For example I could do a rainbow text using:

MyButton.Text = "^0B^1u^2t^3t^4o^5n";
Color values are set by the user, so they could be anything.
By default they're:
0xffffffff, // white, ^0, default
0xff000000, // black, ^1
0xffff0000, // red, ^2
0xff00ff00, // green, ^3
0xff0000ff, // blue, ^4
0xffffff00, // yellow, ^5
Color::FromArgb(255, 0, 64, 128), // ^6
Color::FromArgb(255, 255, 90, 90), // ^7
Color::FromArgb(255, 60, 255, 60), // ^8
Color::FromArgb(255, 220, 165, 65), // ^9

Now, this next code is probably going to make no sense and look pretty bad, but oh well. Once I get the XML layout file done it'll be much easier to handle.

// My controls
// (X, Y, Width, Height, Text, ToolTipText, Parent, Manage /*this last one lets the system know if it should manage the memory for the control.*/)//
dft::Gui::Dialog DemoDialog(10, 10, 300, 400, "Player Inventory", "", 0, false);
dft::Gui::Button DialogButton(10, 10, 100, 17, "Show Dialog", "", 0, false);
dft::Gui::BaseControl *Label = 0;
dft::Gui::BaseControl *Label2 = 0;
dft::Gui::BaseControl *Button = 0;

class GameClass : public Systems::BaseGame
D3DXMATRIX ProjectionMatrix;
dft::Graphics::Texture::ManagedPointer SourceTexture;
dft::Graphics::BitmapFont::ManagedPointer SourceFont;

static void DialogButton_OnClick(dft::Gui::BaseControl *Control, const dft::Input::MouseEvent &Event)
if(Event.Button == dft::Input::MouseButtons::Left)
DemoDialog.Dead = false;
DemoDialog.Visible = true;
GameClass(const std::string &GameName) : BaseGame(GameName)

bool Initialize()
ParentEngine->GfxDevice.SetRenderState(D3DRS_LIGHTING, false);
ParentEngine->GfxDevice.SetRenderState(D3DRS_ALPHABLENDENABLE, true);
ParentEngine->GfxDevice.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
ParentEngine->GfxDevice.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
ParentEngine->GfxDevice.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
ParentEngine->GfxDevice.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

//There isn't an extension on the font path because it requires both a .png file and .dat file.
SourceFont = dft::Graphics::BitmapFont::FromFile(ParentEngine->GfxDevice, dft::GetAbsolutePath("Fonts/tahoma8"));
return false;

ParentEngine->ClearColor = Graphics::Color::CornflowerBlue;
D3DXMatrixOrthoOffCenterLH(&ProjectionMatrix, 0, (float)ParentEngine->GfxDevice.BackBufferWidth, (float)ParentEngine->GfxDevice.BackBufferHeight, 0, 0.0f, 100.0f);
ParentEngine->GfxDevice.SetTransform(D3DTS_PROJECTION, &ProjectionMatrix);

SourceTexture = dft::Graphics::Texture::FromFile(ParentEngine->GfxDevice, dft::GetAbsolutePath("Graphics/test skin.png"));
return false;

DialogButton.FontFormatting = dft::Graphics::FontFormatting::Center | dft::Graphics::FontFormatting::VCenter;
DialogButton.Visible = true;
DialogButton.OnClick = DialogButton_OnClick;

DemoDialog.FontFormatting = dft::Graphics::FontFormatting::Center;
DemoDialog.Visible = true;

dft::Rectangle Rect;
SourceFont->CalculateStringRect("Omg, it's a label!", Rect);
Label = DemoDialog.AddChild(new dft::Gui::Label(5, 17, Rect.Width(), Rect.Height(), "Omg, it's a label!", "Tool Tip Text!!!", &DemoDialog, true));
Label->Visible = true;

SourceFont->CalculateStringRect("Omg, it's another label!", Rect);
Label2 = DemoDialog.AddChild(new dft::Gui::Label(5, 17 + Rect.Height(), Rect.Width(), Rect.Height(), "Omg, it's another label!", "Tool Tip Text!!!", &DemoDialog, true));
Label2->Visible = true;

Button = DemoDialog.AddChild(new dft::Gui::Button(0, 0, 100, 17, "Quit", "Click this button to exit the demo.", &DemoDialog, true));
Button->Alignment = dft::Gui::Align::Right | dft::Gui::Align::Bottom;
Button->Padding = dft::Rectangle(5, 5, 5, 5);
Button->FontFormatting = dft::Graphics::FontFormatting::Center | dft::Graphics::FontFormatting::VCenter;
Button->Visible = true;
Button->OnClick = Quit_OnClick;

ParentEngine->EventHandlers += DemoDialog;
ParentEngine->EventHandlers += DialogButton;
return true;

void Update(float Seconds)
if(DemoDialog.Dead) // Once the Manager class is done, Dead widgets will be removed.
DemoDialog.Visible = false;
Label->Text = dft::Rectangle(DemoDialog.Location, DemoDialog.Size).ToString();
Label->Size.Width = SourceFont->CalculateStringWidth(Label->Text, true);

Label2->Text = Button->Location.ToString();
Label2->Size.Width = SourceFont->CalculateStringWidth(Label->Text, true);

void Frame()
DialogButton.Render(ParentEngine->GfxDevice, SourceTexture, SourceFont);
DemoDialog.Render(ParentEngine->GfxDevice, SourceTexture, SourceFont);

void CleanUp()

bool OnKeyDown(const Input::KeyEvent &Event)
case Input::Keys::Escape:
return false;
return true;

bool OnKeyUp(const Input::KeyEvent &Event)
case Input::Keys::PrintScreen:
return false;
return true;

int WINAPI WinMain(HINSTANCE, HINSTANCE, char *, int)
#ifdef _DEBUG

HtmlLog::SetUp("debuglog.html", "HTML Log");
Systems::Engine::Access()->Run(new GameClass("Project MalykAI"));

// Fallback catch blocks
catch(const UnuseableValueException &Exception) { Exception.LogToHtmlLog(); }
catch(const NullPointerException &Exception) { Exception.LogToHtmlLog(); }
catch(const DivideByZeroException &Exception) { Exception.LogToHtmlLog(); }
catch(const FileNotFoundException &Exception) { Exception.LogToHtmlLog(); }
catch(const BadPointerException &Exception) { Exception.LogToHtmlLog(); }
catch(const ItemFoundException &Exception) { Exception.LogToHtmlLog(); }
catch(const ItemNotFoundException &Exception) { Exception.LogToHtmlLog(); }

return 0;

That's the code for the current movie.

There are some major design flaws in both my GUI system and my engine system, but that's what refactoring is for. BUT, that'll come later, after MalykAI is finished. I know there's a better way to design my GUI, but the system I've got set up works decently so I'll stick with it for now. I'm done refactoring things until after MalykAI is done.

Now, for the best part: THE MOVIE. Comments and questions are welcome!

I want to get a couple more controls finished before I release a demo. I've had a few friends test it and I THINK I've worked the rendering issues out. We'll find out in a few days.

Now I'm off to get some work done on MalykAI. I want to finish the gravity system off soon, but I have to get the entity system done before hand. So, I guess that's what I'll be doing for the rest of the night.
Sign in to follow this  


Recommended Comments

Not sure if it's just me, or perhaps Firefox, but all of your text is appearing the same colour as the background: black. [sad]

Share this comment

Link to comment
Original post by HopeDagger
Not sure if it's just me, or perhaps Firefox, but all of your text is appearing the same colour as the background: black. [sad]

Crap, sorry I forgot about the white theme. I'll fix it! Thanks for the heads up!

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!