Developing a GUI in C++ and DirectX_237057.txt - Mason...

This preview shows page 1 - 2 out of 20 pages.

Mason McCuskeyDeveloping a GUI in C++ and DirectXPart I: The Basics, and the MouseBefore I get started, I want to throw out a disclaimer: I’m going to outlinethe approach I used when I created the GUI system for my upcoming title,Quaternion. Treat this text as one solution to a very intricate problem, nothingmore. I’m not saying that this way of making a GUI is the fastest or easiestway; I’m simply outlining a solution that worked for me. Also, this text is notcomplete. Like one of those Bob-Vila TV episodes, it skips over the easy stuffand concentrates on the interesting. There is no attached source file; there arecode snippets in the text, and that’s it. In that code, I’ve stripped out a lotof layers of indirection that aren’t relevant to what I’m trying to show (i.e.the wrappers that you’d probably have for your DirectX functions, non-relevantinitialization and cleanup code, etc). Also, beware of bugs - I’ve done lots ofbug checking, but I’m only human. If you find a bug, please let me know about itby [email protected]I’m making several assumptions about your knowledge. I’m assuming you knowthe basics of how event-driven programming works (message queues, etc), and I’massuming you have a strong grasp of PDL (the commenting language - if you don’tknow what this is, read Code Complete, by Steve McConnell), and C++. I used C++to implement my GUI system, because I’m a card-carrying member of the C++ fanclub, and because the OOP of C++ work great for implementing window and controltypes. Shameless plug for the C++ language: Note the power of OOP in thissolution, and ask yourself if you could do the same thing as easily in C.Let’s start by defining our scope. It’s important to realize up front thatwe’re not remaking Windows 95, we’re just trying to get a simple GUI up for agame, so we don’t have to implement every single control and GUI construct. Weonly need a few parts for this simple GUI: a mouse pointer, a generic window,and some dialog controls to place within that window. We’re also going to need aresource editor, a program that will allow us to design dialogs by graphicallydropping controls at various places.Start with the basics - The Rendering LoopI’m going to start at the top, by defining a function that will calculate anddraw one frame of our GUI system. Let’s call this function RenderGUI(). In PDL,RenderGUI does something like this:void CApplication::RenderGUI(void) {// get position and button status of mouse cursor// calculate mouse cursor’s effects on windows / send messages// render all windows// render mouse// flip to screen}Pretty straightforward for now. Basically, we grab the new position andstatus of the mouse cursor, calculate any changes that are caused by the newposition, render all our windows, render the mouse cursor, then push the wholething to the screen.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 20 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
NoProfessor
Tags

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture