GUI Programming
description
Transcript of GUI Programming
GUI GUI ProgrammingProgramming
Alex FeldmeierAlex Feldmeier
ConceptsConcepts
Create GUI from scratchCreate GUI from scratch OpenGL has no built in GUIOpenGL has no built in GUI Developers create new GUI for every Developers create new GUI for every
gamegame
What you haveWhat you have
Mouse locationMouse location Mouse button up/downMouse button up/down Keyboard key eventsKeyboard key events Ability to draw imagesAbility to draw images
Layout ManagersLayout Managers
Scalable to more complex projectsScalable to more complex projects Resizable to resolutions and aspect Resizable to resolutions and aspect
ratiosratios Standardized format (XML)Standardized format (XML) Drag and drop controlsDrag and drop controls
XMLXML
Standardized formatStandardized format Easier to editEasier to edit Easier to readEasier to read Less codeLess code
Component OverlapComponent Overlap
Which draws on topWhich draws on top Which handles eventsWhich handles events Should you clipShould you clip
ClippingClipping
Used for windowsUsed for windows Need to clip both image and Need to clip both image and
boundariesboundaries Can be hard clipping rotated Can be hard clipping rotated
component (Unity)component (Unity)
TypesTypes
Retained modeRetained mode Contains GUI stateContains GUI state
Immediate modeImmediate mode Rendered when neededRendered when needed
Retained mode (pros)Retained mode (pros)
Industry standard for yearsIndustry standard for years More object orientedMore object oriented Central controlCentral control
Good for looping backGood for looping back Ex: draggingEx: dragging
Only renders when updatingOnly renders when updating
Retained mode (cons)Retained mode (cons)
Lots of callbacksLots of callbacks Harder for changing componentsHarder for changing components Uses separate place for 2D and 3DUses separate place for 2D and 3D
Immediate mode (pros)Immediate mode (pros)
All GUI code in 1 placeAll GUI code in 1 place Build into pre-existing rendering codeBuild into pre-existing rendering code Easier to add widget to screenEasier to add widget to screen Redraws whole screen every time (can Redraws whole screen every time (can
be con)be con) Good for gamesGood for games If component not needed, don’t draw itIf component not needed, don’t draw it
Immediate mode (cons)Immediate mode (cons)
Hard for program to traverse GUIHard for program to traverse GUI GUI doesn’t control everythingGUI doesn’t control everything
1 frame of lag1 frame of lag Needs watchers at end of renderer to Needs watchers at end of renderer to
check what happenedcheck what happened Ex: draggingEx: dragging
Code is decentralizedCode is decentralized
Event Handling Event Handling (Retained Mode)(Retained Mode)
Event classEvent class Component activatedComponent activated
EventListener interfaceEventListener interface handleEvent(Event e);handleEvent(Event e); User-side function to perform event (ex: User-side function to perform event (ex:
button click)button click)
Component StatesComponent States(Immediate Mode)(Immediate Mode)
ActiveActive Mouse clickMouse click
HotHot Mouse hoverMouse hover
FocusFocus Used for keyboard inputUsed for keyboard input
ActiveActive
Mouse clickMouse click Ex: button pressedEx: button pressed Maintains state until mouse releaseMaintains state until mouse release Only hot item can be activeOnly hot item can be active
HotHot
Mouse hoverMouse hover Ex: button highlightsEx: button highlights Loses state when mouse exitsLoses state when mouse exits Only obtainable if (one of the Only obtainable if (one of the
following)following) It is activeIt is active Nothing else is activeNothing else is active
FocusFocus
Takes keyboard inputTakes keyboard input Acts like active but does not lock hotActs like active but does not lock hot
ReferencesReferences Adams, Ernest, and Andrew Rollings. Fundamentals of Game Adams, Ernest, and Andrew Rollings. Fundamentals of Game
Design. Berkeley, CA: New Riders, 2010. Print.Design. Berkeley, CA: New Riders, 2010. Print. Astle, Dave, and Kevin Hawkins. Beginning OpenGL Game Astle, Dave, and Kevin Hawkins. Beginning OpenGL Game
Programming. Boston, MA: Thomson/Course Technology, Programming. Boston, MA: Thomson/Course Technology, 2004. Print.2004. Print.
Eckstein, Robert, Marc Loy, and Dave Wood. Java Swing. Eckstein, Robert, Marc Loy, and Dave Wood. Java Swing. Sebastopol, CA: O'Reilly, 1998. Print.Sebastopol, CA: O'Reilly, 1998. Print.
Harrington, Jan L. Object-oriented C Data Structures for Real Harrington, Jan L. Object-oriented C Data Structures for Real Programmers. San Diego: Morgan Kaufmann, 2002. Print.Programmers. San Diego: Morgan Kaufmann, 2002. Print.
Thorn, Alan. "Game Engine Design and Implementation." Thorn, Alan. "Game Engine Design and Implementation." Game Engine Design and Implementation. Jones & Bartlett Game Engine Design and Implementation. Jones & Bartlett Learning, n.d. Web. 13 Oct. 2013.Learning, n.d. Web. 13 Oct. 2013.
Other sources:Other sources: http://mollyrocket.comhttp://mollyrocket.com http://mollyrocket.com/861http://mollyrocket.com/861 http://johno.se/book/index.htmlhttp://johno.se/book/index.html http://sol.gfxile.net/imgui/http://sol.gfxile.net/imgui/