GUI Programming

18
GUI Programming GUI Programming Alex Feldmeier Alex Feldmeier

description

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 - PowerPoint PPT Presentation

Transcript of GUI Programming

Page 1: GUI Programming

GUI GUI ProgrammingProgramming

Alex FeldmeierAlex Feldmeier

Page 2: GUI Programming

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

Page 3: GUI Programming

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

Page 4: GUI Programming

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

Page 5: GUI Programming

XMLXML

Standardized formatStandardized format Easier to editEasier to edit Easier to readEasier to read Less codeLess code

Page 6: GUI Programming

Component OverlapComponent Overlap

Which draws on topWhich draws on top Which handles eventsWhich handles events Should you clipShould you clip

Page 7: GUI Programming

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)

Page 8: GUI Programming

TypesTypes

Retained modeRetained mode Contains GUI stateContains GUI state

Immediate modeImmediate mode Rendered when neededRendered when needed

Page 9: GUI Programming

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

Page 10: GUI Programming

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

Page 11: GUI Programming

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

Page 12: GUI Programming

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

Page 13: GUI Programming

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)

Page 14: GUI Programming

Component StatesComponent States(Immediate Mode)(Immediate Mode)

ActiveActive Mouse clickMouse click

HotHot Mouse hoverMouse hover

FocusFocus Used for keyboard inputUsed for keyboard input

Page 15: GUI Programming

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

Page 16: GUI Programming

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

Page 17: GUI Programming

FocusFocus

Takes keyboard inputTakes keyboard input Acts like active but does not lock hotActs like active but does not lock hot

Page 18: GUI Programming

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/