14.6 Initializing the Calculator

The initCalc routine in Example 14-9 performs three major functions: it loads the font to be used in all text, creates GCs for foreground and background of the calculator, and then sets the initial pixmaps for all pads. The windows for each pad do not exist yet.

Again, we’ll begin with the declarations that are used in the routine.

Example 14-9. basecalc — declarations for initCalc

/* Pattern for disabled buttons (Light Gray) */ #define lgray_width 16 #define lgray_height 16 static char lgray_bits[] = { 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22}; /* Background pattern for calculator (Dark Gray) */ #define gray_width 16 #define gray_height 16 static char gray_bits[] = { 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55}; #define WHITE 0 #define BLACK 1 #define DARKGRAY 2 #define LIGHTGRAY 3 int pressedColor = WHITE; int unpressedColor = BLACK; int disabledColor = LIGHTGRAY; int displayColor = WHITE; #define NBUTTONS 38 struct windata { int color; /* Color */ char *text; /* Pointer to the text string */ int x; /* x coordinate of text */ int y; /* y coordinate of text */ int value; /* 0 to 16 for number, symbol for operator */ int type; /* Digit, operator, conversion, ...

Get XLIB Programming Manual, Rel. 5, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.