DirectX® 9 User Interfaces: Design and Implementation Alan Thorn This page intentionally left blank. DirectX® 9 User Interfaces: Design and Implementation Alan Thorn Wordware Publishing, Inc. Library of Congress Cataloging-in-Publication Data Thorn, Alan. DirectX 9 user interfaces : design and implementation / by Alan Thorn. p. cm. ISBN 1-55622-249-1 (pbk.) 1. User interfaces (Computer systems). 2. DirectX. I. Title. QA76.9.U83T53 2004 005.4'38—dc22 2003025230 CIP © 2004, Wordware Publishing, Inc. All Rights Reserved 2320 Los Rios Boulevard Plano, Texas 75074 No part of this book may be reproduced in any form or by any means without permission in writing from Wordware Publishing, Inc. Printed in the United States of America ISBN 1-55622-249-1 10987654321 0401 DirectX is a registered trademark of Microsoft Corporation in the United States and/or other countries. Microsoft DirectX 9.0 SDK Update (Summer 2003) copyright Microsoft Corporation, 2002. All rights reserved. All brand names and product names mentioned in this book are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of service marks or trademarks should not be regarded as intent to infringe on the property of others. The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products. This book is sold as is, without warranty of any kind, either express or implied, respecting the contents of this book and any disks or programs that may accompany it, including but not limited to implied warranties for the book’s quality, performance, merchantability, or fitness for any particular purpose. Neither Wordware Publishing, Inc. nor its dealers or distributors shall be liable to the purchaser or any other person or entity with respect to any liability,loss, or damage caused or alleged to have been caused directly or indirectly by this book. All inquiries for volume purchases of this book should be addressed to Wordware Publishing, Inc., at the above address. Telephone inquiries may be made by calling: (972) 423-0090 Dedication To my mother, Christine; my father, Gary; and my sister, Angela. v This page intentionally left blank. Contents Acknowledgements .........................xv Introduction.............................xvii Chapter 1 User Interfaces .......................1 1.1 User Interfaces — What Are They? ...............2 1.2 Controls — Gadgets and Gizmos .................4 1.2.1 Text Boxes..........................5 1.2.2 Text Edits ..........................6 1.2.3 Buttons ...........................7 1.2.4 Labels ............................8 1.2.5 List Boxes ..........................9 1.2.6 Drop-Down Lists......................10 1.2.7 Check Boxes ........................11 1.2.8 Menus ...........................12 1.2.9 Page Controls/Tab Controls ................13 1.2.10 Windows and Other Containers .............14 1.3 Interface Flow Diagrams — Interfaces on Paper ........15 1.4 Interface Design — Tips and Tricks ...............16 1.4.1 Be Consistent .......................17 1.4.2 Know Your Audience....................17 1.4.3 Justification and Alignment ................18 1.4.4 Grouping Data .......................19 1.4.5 Error Handling .......................19 1.4.6 Disabling Program Features ................20 1.4.7 Graphics, Colors, Icons, and Art ..............21 1.4.8 Balancing Text and Symbols ................21 1.4.9 Paths and Navigation....................22 1.4.10 Keyboard Support.....................24 1.4.11 ToolTips.........................24 1.5 Conclusion ............................24 Chapter 2 Introducing DirectX ....................27 2.1 DirectX — What Is It? ......................28 2.1.1 Direct3D — Graphics ...................29 2.1.2 DirectInput — Keyboards, Mice, and Joysticks ......29 2.1.3 DirectMusic and DirectSound — MIDI and WAV .....30 vii Contents 2.1.4 DirectPlay — Networking .................30 2.1.5 DirectShow — Programmable Media Player .......30 2.2 DirectX — Other Features ...................31 2.2.1 Mesh Viewer ........................31 2.2.2 ErrorLookup........................32 2.2.3 Caps Viewer ........................33 2.2.4 GraphEdit .........................34 2.2.5 Texture Tool ........................35 2.3 System Requirements ......................36 2.4 Where to Obtain DirectX ....................36 2.5 Installation ............................37 2.6 Installed Files ..........................38 2.7 Configuring Visual C++.....................39 2.8 Coding with Hungarian Notation ................42 2.9 Conclusion ............................43 Chapter 3 Introducing Direct3D ...................45 3.1 Direct3D Concepts — Overview and Mathematics .......46 3.2 Getting Started..........................48 3.3 Programming Direct3D Applications ..............51 3.4 Initializing Direct3D .......................52 3.5 Creating a Direct3D Device — A Graphics Card ........53 3.6 Preparing to Render .......................56 3.7 Initializing World Data ......................58 3.7.1 Direct3D Surfaces — IDirect3DSurface9 .........59 3.7.2 Direct3D Surfaces — Loading Image Files ........60 3.7.3 Direct3D Surfaces — Rendering .............62 3.7.4 Direct3D Textures — IDirect3DTexture9.........65 3.7.5 Direct3D Textures — Preparing to Render ........66 3.7.6 Direct3D Textures — Rendering .............67 3.8 Alpha Blending..........................72 3.8.1 Using Adobe Photoshop ..................73 3.8.2 Using Paint Shop Pro ...................74 3.8.3 Using the DirectX Texture Tool ..............75 3.8.4 Enabling Alpha Blending in Direct3D ...........76 3.9 Conclusion ............................77 Chapter 4 Introducing DirectInput ..................79 4.1 DirectInput Basics ........................80 4.2 Getting Started..........................80 4.3 Programming...........................82 4.4 Creating a DirectInput Object ..................83 4.5 Creating DirectInput Devices ..................85 4.6 The Keyboard ..........................86 4.6.1 Creating the Keyboard ...................86 4.6.2 Configuring the Keyboard .................87 viii Contents 4.6.3 Reading from the Keyboard ................90 4.7 The Mouse ............................92 4.7.1 Creating the Mouse ....................92 4.7.2 Setting the Cursor .....................93 4.7.3 Reading from the Mouse..................95 4.7.4 Processing the Cursor Position ..............96 4.7.5 Reading Mouse Buttons ..................97 4.8 Conclusion ............................98 Chapter 5 Wrapping Direct3D ....................99 5.1 CXSurface — Wrapping Surfaces ...............100 5.1.1 Instantiating and Deleting CXSurface ..........101 5.1.2 Loading Images ......................102 5.1.3 Copying Surfaces .....................102 5.1.4 Representing the Back Buffer ..............103 5.1.5 Rendering .........................104 5.1.6 Using CXSurface .....................104 5.2 CXTexture — Wrapping Textures ...............106 5.2.1 Instantiating and Deleting ................107 5.2.2 Loading Images ......................107 5.2.3 Preparing to Render ...................108 5.3 CXPen — Wrapping ID3DXSprite ...............109 5.3.1 Instantiating and Deleting ................109 5.3.2 Rendering Textures....................110 5.3.3 Using CXPen and CXTexture...............111 5.4 Conclusion ...........................112 Chapter 6 Abstracting DirectInput ..................113 6.1 CXInput — The DirectInput Object ..............114 6.1.1 Instantiating the DirectInput Object ...........115 6.1.2 Creating Input Devices ..................116 6.2 CXKeyboard — Wrapping the Keyboard Device........117 6.2.1 Instantiating Keyboard Devices .............118 6.2.2 Reading from CXKeyboard ................119 6.3 Wrapping the Mouse Device ..................121 6.3.1 CXMouseSurface — Wrapping a List of Cursors ....121 6.3.2 Linked Lists — A Definition ...............122 6.3.3 Navigating Linked Lists .................123 6.3.4 Adding New Items to Linked Lists ............124 6.3.5 Deleting Linked Lists...................125 6.3.6 CXMouseSurface — Other Properties..........125 6.3.7 Wrapping the Mouse Device with CXMouse ......126 6.3.8 Initializing Mouse Cursors with CXMouse .......129 6.3.9 Changing Mouse Cursors with CXMouse ........131 6.3.10 Reading Mouse Data with CXMouse ..........132 6.3.11 Reading Cursor Positions with CXMouse .......133 ix Contents 6.3.12 Reading Button States with CXMouse .........133 6.4 Conclusion ...........................134 Chapter 7 Beginning CXControl...................135 7.1 UI LIB (User Interface Library) — What Is It? ........136 7.2 UI LIB — Controls as Classes .................136 7.3 Controls — Class Hierarchy and Base Controls ........137 7.4 CXControl — The Beginnings .................138 7.5 Defining CXControl — Controls and a Canvas.........139 7.6 CXControl — Parent, Sibling, and Child Controls .......140 7.6.1 Adding Child Controls ..................143 7.6.2 Clearing Child Controls..................144 7.6.3 Removing Specific Children ...............145 7.6.4 Counting Child Controls .................146 7.7 Absolute and Relative Positioning ...............146 7.7.1 Computing Positions ...................149 7.8 CXControl — The Class Declaration Thus Far ........150 7.9 Conclusion ...........................151 Chapter 8 Continuing CXControl ..................153 8.1 Messages ............................154 8.1.1 Posting Messages.....................157 8.1.2 Message Specifics ....................157 8.2 Handling Mouse
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages377 Page
-
File Size-