GUI Programming Alex Feldmeier
Concepts Create GUI from scratch OpenGL has no built in GUI Developers create new GUI for every game
What you have Mouse location Mouse button up/down Keyboard key events Ability to draw images
Layout Managers Scalable to more complex projects Resizable to resolutions and aspect ratios Standardized format (XML) Drag and drop controls
XML Standardized format Easier to edit Easier to read Less code
Component Overlap Which draws on top Which handles events Should you clip
Clipping Used for windows Need to clip both image and boundaries Can be hard clipping rotated component (Unity)
Types Retained mode Immediate mode Contains GUI state Rendered when needed
Retained mode (pros) Industry standard for years More object oriented Central control Good for looping back Ex: dragging Only renders when updating
Retained mode (cons) Lots of callbacks Harder for changing components Uses separate place for 2D and 3D
Immediate mode (pros) All GUI code in 1 place Build into pre-existing rendering code Easier to add widget to screen Redraws whole screen every time (can be con) Good for games If component not needed, don’t draw it
Immediate mode (cons) Hard for program to traverse GUI 1 frame of lag GUI doesn’t control everything 1 frame of lag Needs watchers at end of renderer to check what happened Ex: dragging Code is decentralized
Event Handling (Retained Mode) Event class Component activated EventListener interface handleEvent(Event e); User-side function to perform event (ex: button click)
Component States (Immediate Mode) Active Mouse click Hot Mouse hover Focus Used for keyboard input
Active Mouse click Ex: button pressed Maintains state until mouse release Only hot item can be active
Hot Mouse hover Ex: button highlights Loses state when mouse exits Only obtainable if (one of the following) It is active Nothing else is active
Focus Takes keyboard input Acts like active but does not lock hot
References Adams, Ernest, and Andrew Rollings. Fundamentals of Game Design. Berkeley, CA: New Riders, 2010. Print. Astle, Dave, and Kevin Hawkins. Beginning OpenGL Game Programming. Boston, MA: Thomson/Course Technology, 2004. Print. Eckstein, Robert, Marc Loy, and Dave Wood. Java Swing. Sebastopol, CA: O'Reilly, 1998. Print. Harrington, Jan L. Object-oriented C Data Structures for Real Programmers. San Diego: Morgan Kaufmann, 2002. Print. Thorn, Alan. "Game Engine Design and Implementation." Game Engine Design and Implementation. Jones & Bartlett Learning, n.d. Web. 13 Oct. 2013. Other sources: http://mollyrocket.com http://mollyrocket.com/861 http://johno.se/book/index.html http://sol.gfxile.net/imgui/