[3ae31e9] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | appskel.c -- GEM application skeleton
|
---|
| 4 | Version 1 -- 1988-08-10 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "stddefs.h"
|
---|
| 9 | #include "obdefs.h"
|
---|
| 10 | #include "define.h"
|
---|
| 11 | #include "gemdefs.h"
|
---|
| 12 | #include "osbind.h"
|
---|
| 13 |
|
---|
| 14 | /*
|
---|
| 15 | =============================================================================
|
---|
| 16 | Defines
|
---|
| 17 | =============================================================================
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | #define WI_KIND (SIZER | MOVER | FULLER | CLOSER | NAME)
|
---|
| 21 |
|
---|
| 22 | #define NO_WINDOW (-1)
|
---|
| 23 |
|
---|
| 24 | #define MIN_WIDTH (2 * gl_wbox)
|
---|
| 25 | #define MIN_HEIGHT (3 * gl_hbox)
|
---|
| 26 |
|
---|
| 27 | /*
|
---|
| 28 | =============================================================================
|
---|
| 29 | Externals
|
---|
| 30 | =============================================================================
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | extern int gl_apid;
|
---|
| 34 |
|
---|
| 35 | /* |
---|
| 36 |
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | /*
|
---|
| 40 | =============================================================================
|
---|
| 41 | Globals
|
---|
| 42 | =============================================================================
|
---|
| 43 | */
|
---|
| 44 |
|
---|
| 45 | int gl_hchar;
|
---|
| 46 | int gl_wchar;
|
---|
| 47 | int gl_wbox;
|
---|
| 48 | int gl_hbox; /* system sizes */
|
---|
| 49 |
|
---|
| 50 | int phys_handle; /* physical workstation handle */
|
---|
| 51 | int handle; /* virtual workstation handle */
|
---|
| 52 | int wi_handle; /* window handle */
|
---|
| 53 | int top_window; /* handle of topped window */
|
---|
| 54 |
|
---|
| 55 | int xdesk; /* desktop */
|
---|
| 56 | int ydesk;
|
---|
| 57 | int hdesk;
|
---|
| 58 | int wdesk;
|
---|
| 59 |
|
---|
| 60 | int xold; /* old window */
|
---|
| 61 | int yold;
|
---|
| 62 | int hold;
|
---|
| 63 | int wold;
|
---|
| 64 |
|
---|
| 65 | int xwork; /* work area */
|
---|
| 66 | int ywork;
|
---|
| 67 | int hwork;
|
---|
| 68 | int wwork;
|
---|
| 69 |
|
---|
| 70 | int msgbuff[8]; /* event message buffer */
|
---|
| 71 | int keycode; /* keycode returned by event-keyboard */
|
---|
| 72 | int mx; /* mouse x pos. */
|
---|
| 73 | int my; /* mouse y pos. */
|
---|
| 74 | int butdown; /* button state tested for, UP/DOWN */
|
---|
| 75 | int ret; /* dummy return variable */
|
---|
| 76 |
|
---|
| 77 | int hidden; /* current state of cursor */
|
---|
| 78 | int fulled; /* current state of window */
|
---|
| 79 |
|
---|
| 80 | int contrl[12];
|
---|
| 81 | int intin[128];
|
---|
| 82 | int ptsin[128];
|
---|
| 83 | int intout[128];
|
---|
| 84 | int ptsout[128];
|
---|
| 85 |
|
---|
| 86 | int work_in[11]; /* Input to GSX parameter array */
|
---|
| 87 | int work_out[57]; /* Output from GSX parameter array */
|
---|
| 88 | int pxyarray[10]; /* input point array */
|
---|
| 89 |
|
---|
| 90 | /* |
---|
| 91 |
|
---|
| 92 | */
|
---|
| 93 |
|
---|
| 94 | /*
|
---|
| 95 | =============================================================================
|
---|
| 96 | hide_mouse() -- hide the mouse cursor
|
---|
| 97 | =============================================================================
|
---|
| 98 | */
|
---|
| 99 |
|
---|
| 100 | hide_mouse()
|
---|
| 101 | {
|
---|
| 102 | if(NOT hidden) {
|
---|
| 103 |
|
---|
| 104 | graf_mouse(M_OFF, 0x0L);
|
---|
| 105 | hidden = TRUE;
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /*
|
---|
| 110 | =============================================================================
|
---|
| 111 | show_mouse() -- show the mouse cursor
|
---|
| 112 | =============================================================================
|
---|
| 113 | */
|
---|
| 114 |
|
---|
| 115 | show_mouse()
|
---|
| 116 | {
|
---|
| 117 | if(hidden) {
|
---|
| 118 |
|
---|
| 119 | graf_mouse(M_ON, 0x0L);
|
---|
| 120 | hidden = FALSE;
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | /* |
---|
| 125 |
|
---|
| 126 | */
|
---|
| 127 |
|
---|
| 128 | /*
|
---|
| 129 | =============================================================================
|
---|
| 130 | open_vwork() -- open virtual workstation
|
---|
| 131 | =============================================================================
|
---|
| 132 | */
|
---|
| 133 |
|
---|
| 134 | open_vwork()
|
---|
| 135 | {
|
---|
| 136 | int i;
|
---|
| 137 |
|
---|
| 138 | for(i = 0; i < 10; work_in[i++] = 1);
|
---|
| 139 |
|
---|
| 140 | work_in[10] = 2;
|
---|
| 141 | handle = phys_handle;
|
---|
| 142 |
|
---|
| 143 | v_opnvwk(work_in, &handle, work_out);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | /*
|
---|
| 147 | =============================================================================
|
---|
| 148 | set_clip() -- set clipping rectangle
|
---|
| 149 | =============================================================================
|
---|
| 150 | */
|
---|
| 151 |
|
---|
| 152 | set_clip(x, y, w, h)
|
---|
| 153 | int x, y, w, h;
|
---|
| 154 | {
|
---|
| 155 | int clip[4];
|
---|
| 156 |
|
---|
| 157 | clip[0] = x;
|
---|
| 158 | clip[1] = y;
|
---|
| 159 | clip[2] = x + w;
|
---|
| 160 | clip[3] = y + h;
|
---|
| 161 |
|
---|
| 162 | vs_clip(handle, 1, clip);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | /* |
---|
| 166 |
|
---|
| 167 | */
|
---|
| 168 |
|
---|
| 169 | /*
|
---|
| 170 | =============================================================================
|
---|
| 171 | open_window() -- open window
|
---|
| 172 | =============================================================================
|
---|
| 173 | */
|
---|
| 174 |
|
---|
| 175 | open_window()
|
---|
| 176 | {
|
---|
| 177 | wi_handle = wind_create(WI_KIND, xdesk, ydesk, wdesk, hdesk);
|
---|
| 178 |
|
---|
| 179 | wind_set(wi_handle, WF_NAME, " IMA SAMPLE ", 0, 0);
|
---|
| 180 |
|
---|
| 181 | graf_growbox(xdesk + wdesk / 2, ydesk + hdesk / 2,
|
---|
| 182 | gl_wbox, gl_hbox,
|
---|
| 183 | xdesk, ydesk,
|
---|
| 184 | wdesk, hdesk);
|
---|
| 185 |
|
---|
| 186 | wind_open(wi_handle, xdesk, ydesk, wdesk, hdesk);
|
---|
| 187 |
|
---|
| 188 | wind_get(wi_handle, WF_WORKXYWH,
|
---|
| 189 | &xwork, &ywork, &wwork, &hwork);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /* |
---|
| 193 |
|
---|
| 194 | */
|
---|
| 195 |
|
---|
| 196 | /*
|
---|
| 197 | =============================================================================
|
---|
| 198 | do_redraw() -- find and redraw all clipping rectangles
|
---|
| 199 | =============================================================================
|
---|
| 200 | */
|
---|
| 201 |
|
---|
| 202 | do_redraw(xc, yc, wc, hc)
|
---|
| 203 | int xc, yc, wc, hc;
|
---|
| 204 | {
|
---|
| 205 | GRECT t1, t2;
|
---|
| 206 |
|
---|
| 207 | hide_mouse();
|
---|
| 208 | wind_update(TRUE);
|
---|
| 209 |
|
---|
| 210 | t2.g_x = xc;
|
---|
| 211 | t2.g_y = yc;
|
---|
| 212 | t2.g_w = wc;
|
---|
| 213 | t2.g_h = hc;
|
---|
| 214 |
|
---|
| 215 | wind_get(wi_handle, WF_FIRSTXYWH,
|
---|
| 216 | &t1.g_x, &t1.g_y, &t1.g_w, &t1.g_h);
|
---|
| 217 |
|
---|
| 218 | while (t1.g_w AND t1.g_h) {
|
---|
| 219 |
|
---|
| 220 | if (rc_intersect(&t2, &t1)) {
|
---|
| 221 |
|
---|
| 222 | set_clip(t1.g_x, t1.g_y, t1.g_w, t1.g_h);
|
---|
| 223 | draw_sample();
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | wind_get(wi_handle, WF_NEXTXYWH,
|
---|
| 227 | &t1.g_x, &t1.g_y, &t1.g_w, &t1.g_h);
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | wind_update(FALSE);
|
---|
| 231 | show_mouse();
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | /* |
---|
| 235 |
|
---|
| 236 | */
|
---|
| 237 |
|
---|
| 238 | /*
|
---|
| 239 | =============================================================================
|
---|
| 240 | main() -- Application Initialization
|
---|
| 241 | =============================================================================
|
---|
| 242 | */
|
---|
| 243 |
|
---|
| 244 | main()
|
---|
| 245 | {
|
---|
| 246 | appl_init();
|
---|
| 247 |
|
---|
| 248 | phys_handle = graf_handle(&gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox);
|
---|
| 249 |
|
---|
| 250 | wind_get(0, WF_WORKXYWH, &xdesk, &ydesk, &wdesk, &hdesk);
|
---|
| 251 |
|
---|
| 252 | open_vwork();
|
---|
| 253 | open_window();
|
---|
| 254 | graf_mouse(ARROW, 0x0L);
|
---|
| 255 |
|
---|
| 256 | hidden=FALSE;
|
---|
| 257 | fulled=FALSE;
|
---|
| 258 | butdown=TRUE;
|
---|
| 259 |
|
---|
| 260 | multi();
|
---|
| 261 | }
|
---|
| 262 | /* |
---|
| 263 |
|
---|
| 264 | */
|
---|
| 265 |
|
---|
| 266 | /*
|
---|
| 267 | =============================================================================
|
---|
| 268 | multi() -- dispatch apllication tasks
|
---|
| 269 | =============================================================================
|
---|
| 270 | */
|
---|
| 271 |
|
---|
| 272 | multi()
|
---|
| 273 | {
|
---|
| 274 | int event;
|
---|
| 275 |
|
---|
| 276 | do {
|
---|
| 277 |
|
---|
| 278 | event = evnt_multi(MU_MESAG | MU_BUTTON | MU_KEYBD,
|
---|
| 279 | 1, 1, butdown,
|
---|
| 280 | 0, 0, 0, 0, 0,
|
---|
| 281 | 0, 0, 0, 0, 0,
|
---|
| 282 | msgbuff, 0, 0, &mx, &my, &ret, &ret, &keycode, &ret);
|
---|
| 283 |
|
---|
| 284 | wind_update(TRUE);
|
---|
| 285 |
|
---|
| 286 | /* |
---|
| 287 |
|
---|
| 288 | */
|
---|
| 289 | if (event & MU_MESAG)
|
---|
| 290 | switch (msgbuff[0]) {
|
---|
| 291 |
|
---|
| 292 | case WM_REDRAW:
|
---|
| 293 |
|
---|
| 294 | do_redraw(msgbuff[4], msgbuff[5],
|
---|
| 295 | msgbuff[6], msgbuff[7]);
|
---|
| 296 |
|
---|
| 297 | break;
|
---|
| 298 |
|
---|
| 299 | case WM_NEWTOP:
|
---|
| 300 | case WM_TOPPED:
|
---|
| 301 |
|
---|
| 302 | wind_set(wi_handle, WF_TOP, 0, 0, 0, 0);
|
---|
| 303 | break;
|
---|
| 304 |
|
---|
| 305 | case WM_SIZED:
|
---|
| 306 | case WM_MOVED:
|
---|
| 307 |
|
---|
| 308 | if(msgbuff[6] < MIN_WIDTH)
|
---|
| 309 | msgbuff[6] = MIN_WIDTH;
|
---|
| 310 |
|
---|
| 311 | if(msgbuff[7] < MIN_HEIGHT)
|
---|
| 312 | msgbuff[7] = MIN_HEIGHT;
|
---|
| 313 |
|
---|
| 314 | wind_set(wi_handle, WF_CURRXYWH,
|
---|
| 315 | msgbuff[4], msgbuff[5],
|
---|
| 316 | msgbuff[6], msgbuff[7]);
|
---|
| 317 |
|
---|
| 318 | wind_get(wi_handle, WF_WORKXYWH,
|
---|
| 319 | &xwork, &ywork, &wwork, &hwork);
|
---|
| 320 |
|
---|
| 321 | break;
|
---|
| 322 | /* |
---|
| 323 |
|
---|
| 324 | */
|
---|
| 325 | case WM_FULLED:
|
---|
| 326 |
|
---|
| 327 | if(fulled) {
|
---|
| 328 |
|
---|
| 329 | wind_calc(WC_WORK, WI_KIND,
|
---|
| 330 | xold, yold, wold, hold,
|
---|
| 331 | &xwork, &ywork, &wwork, &hwork);
|
---|
| 332 |
|
---|
| 333 | wind_set(wi_handle, WF_CURRXYWH,
|
---|
| 334 | xold, yold, wold, hold);
|
---|
| 335 |
|
---|
| 336 | } else {
|
---|
| 337 |
|
---|
| 338 | wind_calc(WC_BORDER, WI_KIND,
|
---|
| 339 | xwork, ywork, wwork, hwork,
|
---|
| 340 | &xold, &yold, &wold, &hold);
|
---|
| 341 |
|
---|
| 342 | wind_calc(WC_WORK, WI_KIND,
|
---|
| 343 | xdesk, ydesk, wdesk, hdesk,
|
---|
| 344 | &xwork, &ywork, &wwork, &hwork);
|
---|
| 345 |
|
---|
| 346 | wind_set(wi_handle, WF_CURRXYWH,
|
---|
| 347 | xdesk, ydesk, wdesk, hdesk);
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | fulled ^= TRUE;
|
---|
| 351 | break;
|
---|
| 352 |
|
---|
| 353 | } /* end of switch (msgbuff[0]) */
|
---|
| 354 | /* |
---|
| 355 |
|
---|
| 356 | */
|
---|
| 357 | if ((event & MU_BUTTON) AND (wi_handle EQ top_window))
|
---|
| 358 | if(butdown)
|
---|
| 359 | butdown = FALSE;
|
---|
| 360 | else
|
---|
| 361 | butdown = TRUE;
|
---|
| 362 |
|
---|
| 363 | if(event & MU_KEYBD) {
|
---|
| 364 |
|
---|
| 365 | do_redraw(xwork, ywork, wwork, hwork);
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | wind_update(FALSE);
|
---|
| 369 |
|
---|
| 370 | } while(NOT ((event & MU_MESAG) AND (msgbuff[0] EQ WM_CLOSED)));
|
---|
| 371 |
|
---|
| 372 | wind_close(wi_handle);
|
---|
| 373 |
|
---|
| 374 | graf_shrinkbox(xwork + wwork / 2, ywork + hwork / 2,
|
---|
| 375 | gl_wbox, gl_hbox, xwork, ywork, wwork, hwork);
|
---|
| 376 |
|
---|
| 377 | wind_delete(wi_handle);
|
---|
| 378 | v_clsvwk(handle);
|
---|
| 379 |
|
---|
| 380 | appl_exit();
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | /* |
---|
| 384 |
|
---|
| 385 | */
|
---|
| 386 |
|
---|
| 387 | /*
|
---|
| 388 | =============================================================================
|
---|
| 389 | draw_sample() -- SAMPLE: Draw Filled Ellipse.
|
---|
| 390 | =============================================================================
|
---|
| 391 | */
|
---|
| 392 |
|
---|
| 393 | draw_sample()
|
---|
| 394 | {
|
---|
| 395 | int temp[4];
|
---|
| 396 |
|
---|
| 397 | vsf_interior(handle, 2);
|
---|
| 398 | vsf_style(handle, 8);
|
---|
| 399 | vsf_color(handle, 0);
|
---|
| 400 |
|
---|
| 401 | temp[0] = xwork;
|
---|
| 402 | temp[1] = ywork;
|
---|
| 403 | temp[2] = xwork + wwork - 1;
|
---|
| 404 | temp[3] = ywork + hwork - 1;
|
---|
| 405 |
|
---|
| 406 | v_bar(handle, temp); /* blank the interior */
|
---|
| 407 | vsf_interior(handle, 4);
|
---|
| 408 | vsf_color(handle, 1);
|
---|
| 409 |
|
---|
| 410 | v_ellipse(handle, xwork + wwork / 2, ywork + hwork / 2,
|
---|
| 411 | wwork / 2, hwork / 2);
|
---|
| 412 | }
|
---|