home *** CD-ROM | disk | FTP | other *** search
File List | 1989-02-10 | 4.9 KB | 174 lines |
- _WRITING PORTABLE APPLICATIONS WITH X/GEM_
- by Bill Fitler
-
- [LISTING ONE]
-
- /* GEM uses 16 bit quantities for raster
- coordinates */
- typedef short int WORD;
- WORD pxl_width, pxl_height;
- WORD work_in[11], ws_handle, work_out[57];
- ...
- /* Open the workstation after filling in initial
- defaults into work_in[] */
- if( v_opnwk(work_in,&ws_handle,work_out) == FAILURE )
- { /* Handle fatal error */ }
- /* After successful open, ws_handle identifies the
- desired workstation and work_out contains 57
- units of information about the device,
- including the width and height of each pixel in
- microns */
- pxl_width = work_out[3];
- pxl_height = work_out[4];
- ...
- /* Returns a value in y units that is scaled to x
- units */
- WORD scale_y(WORD raw_y)
- {
- return raw_y * pxl_width / pxl_height;
- }
- ...
- /* Draw a square on the screen that is "x_units"
- wide and looks square */
- VOID draw_square(WORD x, WORD y, WORD x_units)
- {
- WORD xy[10];
- xy[0] = x; xy[1] = y;
- xy[2] = x+x_units; xy[3] = y;
- xy[4] = x+x_units; xy[5] = y+scale_y(x_units);
- xy[6] = x; xy[7] = y+scale_y(x_units);
- xy[8] = x; xy[9] = y;
- v_pline(ws_handle,5,xy);
- }
-
- [LISTING TWO]
-
- SAMPLE SOURCE OUTPUT FROM RESOURCE CONSTRUCTION SET
-
-
- #define T0OBJ 0
- #define FREEBB 1
- #define FREEIMG 1
- #define FREESTR 4
-
- BYTE *rs_strings[] = {
- "This is a Sample Dialog",
- "with an image and two buttons.",
- "OK",
- "Cancel"};
-
- WORD IMAG0[] = {
- 0x7FF, 0xFFFF, 0xFF80, 0xC00,
- 0x0, 0xC0, 0x183F, 0xF03F,
- 0xF060, 0x187F, 0xF860, 0x1860,
- 0x187F, 0xF860, 0x1860, 0x187F,
- 0xF860, 0x1860, 0x187F, 0xF860,
- 0x1860, 0x187F, 0xF860, 0x1860,
- 0x187F, 0xF860, 0x1860, 0x187F,
- 0xF860, 0x1860, 0x187F, 0xF860,
- 0x1860, 0x187F, 0xF860, 0x1860,
- 0x187F, 0xF860, 0x1860, 0x187F,
- 0xF860, 0x1860, 0x183F, 0xF03F,
- 0xF060, 0xC00, 0x0, 0xC0,
- 0x7FF, 0xFFFF, 0xFF80, 0x0,
- 0x0, 0x0, 0x3F30, 0xC787,
- 0x8FE0, 0xC39, 0xCCCC, 0xCC00,
- 0xC36, 0xCFCC, 0xF80, 0xC30,
- 0xCCCD, 0xCC00, 0x3F30, 0xCCC7,
- 0xCFE0, 0x0, 0x0, 0x0};
-
- LONG rs_frstr[] = {
- 0};
-
- BITBLK rs_bitblk[] = {
- 0L, 6, 24, 0, 0, 1};
-
- LONG rs_frimg[] = {
- 0};
-
- ICONBLK rs_iconblk[] = {
- 0};
-
- TEDINFO rs_tedinfo[] = {
- 0};
-
- OBJECT rs_object[] = {
- -1, 1, 5, G_BOX, LASTOB, SHADOWED, 0x21100L, 0,0, 43,9,
- 2, -1, -1, G_STRING, NONE, NORMAL, 0x0L, 10,4, 23,1,
- 3, -1, -1, G_STRING, NONE, NORMAL, 0x1L, 7,5, 30,1,
- 4, -1, -1, G_BUTTON, SELECTABLE, NORMAL, 0x2L, 10,7,
- 8,1,
- 5, -1, -1, G_BUTTON, SELECTABLE, NORMAL, 0x3L, 24,7,
- 8,1,
- 0, -1, -1, G_IMAGE, LASTOB, NORMAL, 0x0L, 19,1, 6,3};
-
- LONG rs_trindex[] = {
- 0L};
-
- struct foobar {
- WORD dummy;
- WORD *image;
- } rs_imdope[] = {
- 0, &IMAG0[0]};
-
- #define NUM_STRINGS 4
- #define NUM_FRSTR 0
- #define NUM_IMAGES 1
- #define NUM_BB 1
- #define NUM_FRIMG 0
- #define NUM_IB 0
- #define NUM_TI 0
- #define NUM_OBS 6
- #define NUM_TREE 1
-
- BYTE pname[] = "SAMPLE.RSC";
-
-
- [LISTING THREE]
-
- /* mevent.h - define structure for GEM evnt_event() */
-
- typedef struct mevent
- {
- UWORD e_flags; /* events to wait on */
- UWORD e_bclk; /* num button clicks */
- UWORD e_bmsk; /* which mouse buttons */
- UWORD e_bst; /* button up or down */
- UWORD e_m1flags; /* return on entry or exit */
- GRECT e_m1; /* rect 1 x,y,width,height */
- UWORD e_m2flags; /* return on entry or exit */
- GRECT e_m2; /* rect 2 x,y,width,height */
- LONG e_mepbuf; /* message buffer pointer */
- ULONG e_time; /* time to wait (ms) */
- WORD e_mx; /* return x */
- WORD e_my; /* return y */
- UWORD e_mb; /* return which buttons */
- UWORD e_ks; /* return kb state */
- UWORD e_kr; /* return kb code */
- UWORD e_br; /* return num button clicks */
- CHAR e_reserved[24]; /* for system use */
- } MEVENT;
-
- WORD evnt_event( MEVENT * );
-
-
-
- [LISTING FOUR]
-
- MEVENT ev_str;
- ev_str.e_flags = E_KEYBD | E_TIMER;
- ev_str.e_time = 10000L; /* in milliseconds */
- ret_flags = evnt_event( &ev_str );
- if( ret_flags & E_KEYBD )
- {
- /* The user pressed a key:
- Key code of key pressed returned in ev_str.e_kr;
- State of shift and control keys in ev_str.e_ks */
- }
- if( ret_flags & E_TIMER )
- {
- /* 10,000 milliseconds have elapsed since the call
- */
- }
-