You are previewing X Window Programming from Scratch.
O'Reilly logo
X Window Programming from Scratch

Book Description

X Window Programming From Scratch shows how to create a graphical user interface and accomplish graphic rendering using the X Window System software. It offers a unique approach to skill development by leading you through basic to very advanced concepts. This book provides a guide to the Linux operating system for application development, step-by-step instruction to the correct usage and syntax of C, a comprehensive introduction of the X Window System for interface creation and graphic rendering, and a complete structured project to "learn by doing."

Table of Contents

  1. Copyright
    1. Dedication
  2. About the Author
  3. Acknowledgments
  4. Tell Us What You Think!
  5. Introduction
    1. Beyond the Title
    2. Software Checklist
      1. Linux Operating System
        1. Downloading Linux from the Internet
        2. Linux Distributions
      2. C Compiler
      3. X Window System
    3. Who Should Read This Book?
    4. Conventions Used in This Book
    5. Getting Started
  6. I. Gathering Information
    1. 1. UNIX for Developers
      1. The man Command
      2. Organization and Navigation
        1. Directories
          1. The mkdir Command
          2. The rmdir command
          3. The ls Command
        2. Permissions
          1. Beyond the Obvious
            1. Read Permission
            2. Write Permission
            3. Execute Permission
        3. chmod
        4. The cd Command
      3. The C Compiler
      4. Object Files
      5. Source Files
      6. The vi Editor
      7. The make Utility
        1. The cc Command
          1. gcc -c
          2. gcc -o
          3. gcc -g
          4. gcc -W
          5. gcc -D
          6. gcc -I
          7. gcc -l
          8. gcc -L
        2. Makefile
          1. Comments
          2. Variables
          3. Targets
          4. include
            1. make.defines
            2. The ln -s Command
      8. System Tools and Useful Commands
        1. grep, Pipes, Redirection, and more
        2. The find Command
      9. Next Steps
    2. 2. Programming Constructs
      1. Decisions
        1. The if Statement
        2. The else Statement
        3. Types of Conditions
          1. Numbers
          2. Characters
          3. Strings
        4. The if else Statement
        5. The case Statement
      2. Loops
        1. The for Loop
        2. The while Loop
        3. The do while Loop
      3. Functions
        1. Declarations
        2. Return Type
        3. Function Name
        4. Parameters
        5. Definition
        6. The return Statement
      4. Data
        1. Data Types
          1. The char Data Type
          2. The int Data Type
          3. The short Data Type
          4. The long Data Type
          5. The float Data Type
          6. Defining Structures
          7. Defining Data Types
          8. Data by Reference
      5. Next Steps
    3. 3. A Word on C
      1. Hello World
        1. Comment Tokens
        2. The Function main
        3. Code Bodies
        4. Variable Scope
        5. Built-In Functions
          1. The printf Command
          2. The fopen Function
          3. The C String Library
        6. Memory Management
          1. The static Keyword
          2. The extern Keyword
        7. Dynamic Memory Allocation
          1. malloc (Memory Allocation)
          2. free (Returning Allocated Memory)
        8. Memory Leaks
        9. Definitions and Macros
          1. The define Directive
      2. Conclusion
      3. Next Steps
  7. II. The Pieces of X
    1. 4. Windowing Concepts
      1. Origins of the X Window System
      2. The Pieces of X
        1. Client/Server Model
          1. X Clients
          2. Windows
          3. Window Hierarchy
            1. Expose
        2. Next Steps
    2. 5. Widget Sets
      1. The Power and Convenience of Using Widget Sets
      2. The Athena Widget Set
        1. The Core Widget
        2. Widgets That Manage Other Widgets
          1. The Box Widget
          2. The Form Widget
          3. The Label Widget
          4. The Command Widget
        3. The Motif Widgets
          1. The Core and ApplicationShell Widgets
          2. The XmRowColumn Widget
          3. The XmForm Widget
          4. The XmLabel Widget
          5. The XmPushButton Widget
      3. Next Steps
    3. 6. Components of an X Window Application
      1. Connecting to the X Server
        1. Employing Widget Resources Using Variable Argument Lists
      2. Creating the Application Interface
        1. Creating Buttons
        2. Creating Pixmap Icons
        3. Assigning Actions
      3. Managing Windows
      4. Processing Events
      5. Summary
      6. Next Steps
    4. 7. Xlib Graphic Primitives
      1. The Graphics Context
        1. The GC Function
        2. GCForeground and GCBackground
        3. GCLineWidth
        4. GCTile
      2. Graphic Primitive Functions
        1. XDrawPoint
        2. XDrawLine
        3. XDrawRectangle
        4. XDrawArc
        5. Filled Graphics
      3. Next Steps
  8. III. Back to School
    1. 8. Vector Versus Raster Graphics
      1. Vector Graphics
      2. Raster Graphics
      3. Next Steps
    2. 9. Object Bounds Checking
      1. Point-Array–Based Object Bounds
      2. Arc Object Bounds
      3. Employing Object Bounds
      4. Next Steps
    3. 10. Trigonometric and Geometric Functions
      1. Calculating Point and Line Intersections
      2. Calculating Slope
      3. Calculating Point and Arc Intersections
      4. Next Steps
    4. 11. Graphic Transformations
      1. Moving
        1. Moving a Line
        2. Moving an Arc
      2. Scaling
        1. Scaling a Line
        2. Scaling an Arc
      3. Rotating
        1. Rotating a Line
        2. Rotating an Arc
          1. Rotating an Ellipse
          2. Rotating Arcs Less than 360 Degrees
      4. Next Steps
    5. 12. Coordinate Systems
      1. Rectangular Coordinates
      2. Polar Coordinate System
      3. Next Steps
  9. IV. Laying Out the Parts
    1. 13. Application Structure
      1. Project Structure
        1. Intuitiveness
        2. Aesthetics
        3. Laying Out the User Interface
      2. Parsing the Command Line
      3. The getopt Function
      4. The XtVaGetApplicationResources Function
      5. Setting Up a Canvas
      6. Building the Project
      7. Next Steps
    2. 14. Program Flow
      1. Processing Events
      2. X Event Hooks
        1. Widget Callbacks
        2. Event Handlers
        3. Widget Translation Tables
      3. Next Steps
    3. 15. Common Object Definition
      1. Line Object Data Structure
      2. Text Object Data Structure
        1. Understanding Vector Fonts
      3. The GXText Data Structure
      4. Arc Object Data Structure
      5. Common Object Data Structure
      6. Next Steps
    4. 16. Object Manipulation
      1. Copying an Object
      2. Deleting an Object
      3. Refreshing Objects
      4. Parsing for an Object
      5. Managing Object Handles
      6. Managing the Status of an Object
      7. Processing User Navigation of Objects
      8. Next Steps
    5. 17. Utilities and Tools
      1. Common Object Creation
        1. Linked List Management
      2. Creating a Graphics Context
        1. Graphics Context Tiling
      3. Using the Cursor as State Indicator
      4. Next Steps
    6. 18. File Formats
      1. Understanding Files
      2. Binary File Formatting
      3. ASCII File Formatting
        1. Tagged File Formats
        2. Position-Specific File Formats
      4. Magic Numbers
      5. Next Steps
    7. 19. Save and Restore
      1. File Format Strategy
      2. Save and Restore Program Hooks
      3. Common-Object Save and Restore
      4. Object-Specific Save and Restore
      5. Next Steps
  10. V. Adding Objects to the Editor
    1. 20. Latex Line Object
      1. Creating a Latex Line Object
      2. Drawing and Erasing a Line Object
      3. Finding a Line Object
      4. Selecting and Deselecting a Line Object
      5. Moving a Line Object
      6. Scaling a Line Object
      7. Copying a Line Object
      8. Saving and Restoring a Line Object
      9. Next Steps
    2. 21. Pencil Line Object
      1. Creating a Pencil Object
      2. Pencil Object Management
      3. Next Steps
    3. 22. Object Templates
      1. The Box Object
      2. The Arrow Object
      3. Next Steps
    4. 23. Arc Object
      1. Creating an Arc Object
      2. Drawing and Erasing an Arc Object
      3. Finding an Arc Object
      4. Selecting and Deselecting an Arc Object
      5. Moving an Arc Object
      6. Scaling an Arc Object
      7. Copying an Arc Object
      8. Saving and Restoring an Arc Object
      9. Next Steps
    5. 24. Vector Text Object
      1. Creating a Text Object
      2. Drawing and Erasing a Text Object
      3. Finding a Text Object
      4. Selecting and Deselecting a Text Object
      5. Moving a Text Object
      6. Scaling a Text Object
      7. Copying a Text Object
      8. Saving and Restoring a Text Object
      9. Next Steps
  11. VI. Adding a Print Driver
    1. 25. Introduction to PostScript
      1. PostScript
      2. Learning PostScript
        1. Stacks
      3. PostScript Commands
        1. Comments
      4. PostScript Programming
      5. Viewing PostScript Files
        1. Comments Understood by Ghostscript
      6. Next Steps
    2. 26. Color Versus Black and White
      1. Determining a Printer's Capability
      2. Defining Color Images for Black and White Printers
      3. Next Steps
    3. 27. Working with XImages and Colormaps
      1. Printing the Canvas
      2. Creating an XImage
      3. Creating a PostScript Prolog
      4. Parsing the X Colormap
      5. Writing the PostScript Page Definition File
      6. Directing the Output to a Printer or File
      7. Next Steps
  12. VII. What's Next?
    1. 28. Extending the Graphics Editor
      1. Attributes
        1. Color
        2. Line Attributes
          1. Line Width
          2. Line Style
        3. Arc Angles
      2. Rotating Objects
      3. Next Steps
    2. 29. Adding Context-Sensitive Help
      1. Processing Help-Related Events
      2. Widget Paths
      3. Relating Widgets to Text
      4. Next Steps
  13. VIII. Appendixes
    1. A. Command Shells and Scripting
      1. UNIX Command Shells
        1. Command Shell Environment
          1. Shell Variables
            1. Bourne Shell Variables
          2. C Shell Variables
          3. Aliases
          4. Environment Files
            1. Bourne Shell Environment Files
            2. C Shell Environment Files
      2. Scripting with the Bourne Shell
        1. Shell Variables
          1. Quoting Variables
          2. Performing Tests
          3. Case Tables
          4. Looping
            1. The while Loop
            2. The for Loop
        2. Writing a Script with Function Calls
          1. The sleep Command
          2. The read Command
          3. The exit Command
      3. Debugging Shell Scripts
    2. B. Application Layout Code Listing
      1. make.defines File Contents
      2. GNUmakefile File Contents
      3. gxMain.c File Contents
      4. gxGraphics.c File Contents
      5. gxGx.c File Contents
      6. gxArc.c File Contents
      7. gxLine.c File Contents
      8. gxText.c File Contents
      9. gxGraphics.h File Contents
      10. gxIcons.h File Contents
      11. gxBitmaps.h File Contents
      12. gxProtos.h File Contents
    3. C. Additional Vector Font Sets and vector_chars.h
      1. Script Simple Vector Font Set
      2. Triplex Bold Vector Font Set
      3. Triplex Bold Italic Vector Font Set
      4. The vector_chars.h Header File