Home » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_199510.adf » AW1095_1 » Freeware/InTheMag/AcornAns/!Lorna/c/main

Freeware/InTheMag/AcornAns/!Lorna/c/main

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_199510.adf » AW1095_1
Filename: Freeware/InTheMag/AcornAns/!Lorna/c/main
Read OK:
File size: 344F bytes
Load address: 0000
Exec address: 0000
File contents
/*
 *  Name:    Lorna (well, why not - would you want to be called DEMO06OCT?)
 *
 *  Purpose: Simple example of a desktop application, demonstrating several features including -
 *
 *             � Creation & opening of a single window
 *             � Maintaining window using an event handler
 *             � Responding to clicks in the window & on an icon in the window
 *             � Converting between screen coords & work area coords
 *             � Plotting directly in the window using the ordinary os graphics commands
 *             � Clipping objects to be plotted against the region of screen being redrawn
 *
 *           This takes the form of an application which opens one window on running & maintains this
 *           until closed, that act also quitting the application. Select or Adjust clicks in the window
 *           result in 'objects' (coloured shapes) being created within the window at the location of the
 *           click. Clicking on the one icon in the window, labelled 'Clear', removes all objects so far
 *           created.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "wimpt.h"
#include "wimp.h"
#include "win.h"
#include "werr.h"
#include "event.h"
#include "res.h"
#include "template.h"
#include "bbc.h"
#include "os.h"

typedef enum {          /* Allow us to subsequently refer to the icons & window background by name */
  WINDOW = -1,          /* rather than just by number; this makes our code much more intelligible. */
  CLEAR,
  INFO
} lorna_icon;

typedef enum {          /* We will draw two types of object in our window: red circles & blue squares. */
  CIRCLE = 0,           /* This lets us flag what each object is by name rather than by number. */
  SQUARE
} object_type;

typedef struct {        /* We need to remember where each object is in our window & what type it is. */
  object_type type;     /* This structure maintains that information & we will store an array of these. */
  int x, y;             /* - nb x,y are coords of object centre & are relative to the window's work area */
} object;               /*   origin (ie its top left corner), so they don't change if the window is moved  */
                        /*   or scrolled. */

                        /* Each object will be the same size. The following constant defines this in
                           os graphics units. */
#define OBJECTSIZE 32   /* For a circle object this will be its radius,
                           For a square object this will be half its side length. */

#define MAXNUMOBJECTS 128

                        /* When we check to see if an object overlaps a region of screen being redrawn,
                           or request that a particular region be redrawn, we add in a small border
                           around the object concerned for safety, to avoid numerical rounding errors */
#define BORDER 8        /* which could otherwise results in small overlaps etc being missed. This is the
                           width of that border strip in os graphics units. */

/***********************************************************************************************************/

wimp_w lorna;           /* The handle for our single window. */
int num_objects;        /* A record of the number of objects currently existing in our window. */
object *objects;        /* A pointer to our array of objects. */

/***********************************************************************************************************/

os_error *force_redraw_all(void)        /* This function makes the wimp shortly return a redraw event for */
{                                       /* our window, which will cause all of it to be replotted. */
  wimp_redrawstr r;                     /* We call this when we've done something which necessitates */
  r.w = lorna;                          /* altering much of the window's appearance, such as when we */
  r.box.x0 = r.box.y1 = 0;              /* remove all the objects in it. */
  r.box.x1 = 32768;             /* (a nice big number to ensure we cover all of the work area). */
  r.box.y0 = -32768;
  return wimpt_complain(wimp_force_redraw(&r));
}

os_error *force_redraw_object(object *obj)      /* As in force_redraw_all, this fn causes the wimp to */
{                                               /* return a redraw event for our window eventually, */
  wimp_redrawstr r;                             /* however this time the region to be redrawn is that */
  r.w = lorna;                                  /* covered by the single object whose data is pointed to */
  r.box.x0 = obj->x-OBJECTSIZE-BORDER;          /* by obj. */
  r.box.x1 = obj->x+OBJECTSIZE+BORDER;
  r.box.y0 = obj->y-OBJECTSIZE-BORDER;          /* Notice the use of BORDER to ensure we cover an area */
  r.box.y1 = obj->y+OBJECTSIZE+BORDER;          /* slightly bigger than the object. Strictly this */
  return wimpt_complain(wimp_force_redraw(&r)); /* shouldn't be needed, however small pixel sized errors
                                                   can occur in the plotted position of the object & this
                                                   border ensures the redraw region still covers the object
                                                   even if it is out of position by such an amount. */
}

void redraw_window(wimp_w handle)               /* This function is called when our event handler is asked */
{                                               /* by the wimp to redraw part/s of our window. */
  BOOL more;                                    /* It goes through the prescribed loop, each pass being */
  wimp_redrawstr r;                             /* given one rectangular region to redraw. */
  int i;                                        /* For each such region we must check all of our objects, */
  int xo, yo;                                   /* & for any which overlaps the region being redrawn, we */
  int sx, sy;                                   /* plot it. */
  object *obj;                                  /* It is important that we do clip each object rather than */
                                                /* simply plot all, as this can massively affect redraw */
  /* Start the redraw */                        /* speed which it is important to keep high. */
  r.w = handle;
  wimpt_noerr(wimp_redraw_wind(&r, &more));
  while (more)
  {
    /* Redraw rectangle r.g (screen coords), clipping objects to rectangle r.g */
    xo = r.scx - r.box.x0;                      /* NB xo,yo are work area coords of the screen's origin. */
    yo = r.scy - r.box.y1;
    for (i=0, obj=objects; i<num_objects; i++, obj++) {
      sx = obj->x - xo;                         /* Screen coords of centre of object. */
      sy = obj->y - yo;
      if (sx-OBJECTSIZE < r.g.x1+BORDER  &&     /* If left side of object is to left of clip region's right*/
          sx+OBJECTSIZE > r.g.x0-BORDER  &&     /* & right side of object is to right of clip region's left*/
          sy-OBJECTSIZE < r.g.y1+BORDER  &&     /* & bottom is below top of clip region */
          sy+OBJECTSIZE > r.g.y0-BORDER     )   /* & top is above bottom of clip region, */
                                                /* then object & clip region do intersect, so plot object. */
        switch (obj->type)
        {
          case CIRCLE:
            wimpt_noerr(wimp_setcolour(11));
            wimpt_noerr(bbc_circlefill(sx, sy, OBJECTSIZE));
            wimpt_noerr(wimp_setcolour(7));
            wimpt_noerr(bbc_circle(sx, sy, OBJECTSIZE));
            break;

          case SQUARE:
            wimpt_noerr(wimp_setcolour(15));
            wimpt_noerr(bbc_rectanglefill(sx-OBJECTSIZE, sy-OBJECTSIZE, OBJECTSIZE*2, OBJECTSIZE*2));
            wimpt_noerr(wimp_setcolour(7));
            wimpt_noerr(bbc_rectangle(sx-OBJECTSIZE, sy-OBJECTSIZE, OBJECTSIZE*2, OBJECTSIZE*2));
            break;
        }
    }
    wimp_get_rectangle(&r, &more);
  }

  return;
}

void lorna_event_handler(wimp_eventstr *e, void *handle)        /* Once our window is created this fn does */
{                                                               /* all the hard work of maintaining it.*/
  wimp_wstate s;                /* The 'main' function repeatedly calls event_process, a library fn, & it */
  int xo, yo;                   /* polls the wimp. Whenever it gets an event for our window, it calls this
                                   function, which must deal with the event appropriately. */
  handle = handle;      /* (we don't need handle: this stops compiler warning) */

  switch (e->e)
  {
    case wimp_EBUT:
      switch (e->data.but.m.i)
      {
        case WINDOW:    /* Got a click on the window or the text legend, so try to add another object. */
        case INFO:
          if (num_objects<MAXNUMOBJECTS) {
            if (e->data.but.m.bbits&(wimp_BRIGHT|wimp_BLEFT)) {
              wimpt_complain(wimp_get_wind_state(lorna, &s));
              xo = s.o.x - s.o.box.x0;  /* xo,yo are work area coords of screen origin. */
              yo = s.o.y - s.o.box.y1;
              objects[num_objects].x = e->data.but.m.x + xo;    /* Set object centre to location of ptr, */
              objects[num_objects].y = e->data.but.m.y + yo;    /* after converting to work area coords. */
              objects[num_objects].type = (e->data.but.m.bbits & wimp_BLEFT) ? CIRCLE : SQUARE;
              force_redraw_object(objects+num_objects);         /* Ensure region containing new object is */
              num_objects++;                                    /* redrawn shortly. */
            }
          }
          else werr(0, "Too many objects already! Try clicking on 'Clear'.");
          break;

        case CLEAR:     /* Got a click on the 'Clear' icon, */
          num_objects = 0;
          force_redraw_all();   /* so reset objects & force redraw of window. */
          break;
      }
      break;

    case wimp_EREDRAW:  /* Must redraw part of our window, so call appropriate function to do this. */
      if (e->data.o.w != lorna) break;
      redraw_window(e->data.o.w);
      break;

    case wimp_EOPEN:    /* Pass on open request. */
      if (e->data.o.w != lorna) break;
      wimpt_complain(wimp_open_wind(&e->data.o));
      break;

    case wimp_ECLOSE:   /* Pass on close request. */
      if (e->data.o.w != lorna) break;
      wimpt_complain(wimp_close_wind(e->data.o.w));
      win_activedec();  /* We only have one window & want its closure to quit our application, so we tell  */
      break;            /* library code that our only important window has closed & when we next call
                           event_process in our main loop it will terminate our application itself. */

    default:            /* Ignore any other event. */
      break;
  }
}


BOOL initialise(void)
{
  wimp_wind *window;    /* Pointer to window definition. */
  wimp_wstate s;

  wimpt_init("Lorna");  /* Initialise relevant parts of library, */
  res_init("Lorna");
  template_init();      /* including loading of our templates file. */

  window = template_syshandle("Lorna");
  if (window == 0) return FALSE;
  if (wimpt_complain(wimp_create_wind(window, &lorna))) return FALSE;   /* Create our one & only window, */
  win_register_event_handler(lorna, lorna_event_handler, 0);            /* & register our event handler. */

  if (wimpt_complain(wimp_get_wind_state(lorna, &s))) return FALSE;
  s.o.behind = -1;                                                      /* (to open window at stack top). */
  if (wimpt_complain(wimp_open_wind(&s.o))) return FALSE;               /* Ask for our window to be opened.*/
  win_activeinc();                                                      /* Tell library about our window,
                                so that when we call event_process in main it won't immediately quit!
                                (nb this wouldn't be needed if we put an icon on the icon bar since the
                                 library code to do that itself calls win_activeinc). */

  objects = calloc(MAXNUMOBJECTS, sizeof(object)); /* Reserve some space for upto MAXNUMOBJECTS objects */
  if (objects == 0) return FALSE;

  return TRUE;                                                          /* All okay. */
}

int main(void)          /* Our 'main' function, entered when application is first run. */
{
  if (initialise()) {   /* Call initialise function & if anything goes wrong, quit, otherwise repeatedly */
    while (TRUE) event_process();       /* call event_process which polls the wimp & enters other parts of */
  }                                     /* our code via our window's event_handler, when needed. */
  return 0;
}                       /* Something to note: initialise may fail after registering the application as a
                           task, in which case you might have thought we couldn't simply exit via a return
                           from main as we first need to close the task down, however that is actually still
                           being done! The library code which sets us up as a task registers a function to
                           be called upon exit via atexit(). After we call return in main, this function is
                           called & it deals with the tidying up including closure of our task.
                         */
00000000  2f 2a 0a 20 2a 20 20 4e  61 6d 65 3a 20 20 20 20  |/*. *  Name:    |
00000010  4c 6f 72 6e 61 20 28 77  65 6c 6c 2c 20 77 68 79  |Lorna (well, why|
00000020  20 6e 6f 74 20 2d 20 77  6f 75 6c 64 20 79 6f 75  | not - would you|
00000030  20 77 61 6e 74 20 74 6f  20 62 65 20 63 61 6c 6c  | want to be call|
00000040  65 64 20 44 45 4d 4f 30  36 4f 43 54 3f 29 0a 20  |ed DEMO06OCT?). |
00000050  2a 0a 20 2a 20 20 50 75  72 70 6f 73 65 3a 20 53  |*. *  Purpose: S|
00000060  69 6d 70 6c 65 20 65 78  61 6d 70 6c 65 20 6f 66  |imple example of|
00000070  20 61 20 64 65 73 6b 74  6f 70 20 61 70 70 6c 69  | a desktop appli|
00000080  63 61 74 69 6f 6e 2c 20  64 65 6d 6f 6e 73 74 72  |cation, demonstr|
00000090  61 74 69 6e 67 20 73 65  76 65 72 61 6c 20 66 65  |ating several fe|
000000a0  61 74 75 72 65 73 20 69  6e 63 6c 75 64 69 6e 67  |atures including|
000000b0  20 2d 0a 20 2a 0a 20 2a  20 20 20 20 20 20 20 20  | -. *. *        |
000000c0  20 20 20 20 20 a4 20 43  72 65 61 74 69 6f 6e 20  |     . Creation |
000000d0  26 20 6f 70 65 6e 69 6e  67 20 6f 66 20 61 20 73  |& opening of a s|
000000e0  69 6e 67 6c 65 20 77 69  6e 64 6f 77 0a 20 2a 20  |ingle window. * |
000000f0  20 20 20 20 20 20 20 20  20 20 20 20 a4 20 4d 61  |            . Ma|
00000100  69 6e 74 61 69 6e 69 6e  67 20 77 69 6e 64 6f 77  |intaining window|
00000110  20 75 73 69 6e 67 20 61  6e 20 65 76 65 6e 74 20  | using an event |
00000120  68 61 6e 64 6c 65 72 0a  20 2a 20 20 20 20 20 20  |handler. *      |
00000130  20 20 20 20 20 20 20 a4  20 52 65 73 70 6f 6e 64  |       . Respond|
00000140  69 6e 67 20 74 6f 20 63  6c 69 63 6b 73 20 69 6e  |ing to clicks in|
00000150  20 74 68 65 20 77 69 6e  64 6f 77 20 26 20 6f 6e  | the window & on|
00000160  20 61 6e 20 69 63 6f 6e  20 69 6e 20 74 68 65 20  | an icon in the |
00000170  77 69 6e 64 6f 77 0a 20  2a 20 20 20 20 20 20 20  |window. *       |
00000180  20 20 20 20 20 20 a4 20  43 6f 6e 76 65 72 74 69  |      . Converti|
00000190  6e 67 20 62 65 74 77 65  65 6e 20 73 63 72 65 65  |ng between scree|
000001a0  6e 20 63 6f 6f 72 64 73  20 26 20 77 6f 72 6b 20  |n coords & work |
000001b0  61 72 65 61 20 63 6f 6f  72 64 73 0a 20 2a 20 20  |area coords. *  |
000001c0  20 20 20 20 20 20 20 20  20 20 20 a4 20 50 6c 6f  |           . Plo|
000001d0  74 74 69 6e 67 20 64 69  72 65 63 74 6c 79 20 69  |tting directly i|
000001e0  6e 20 74 68 65 20 77 69  6e 64 6f 77 20 75 73 69  |n the window usi|
000001f0  6e 67 20 74 68 65 20 6f  72 64 69 6e 61 72 79 20  |ng the ordinary |
00000200  6f 73 20 67 72 61 70 68  69 63 73 20 63 6f 6d 6d  |os graphics comm|
00000210  61 6e 64 73 0a 20 2a 20  20 20 20 20 20 20 20 20  |ands. *         |
00000220  20 20 20 20 a4 20 43 6c  69 70 70 69 6e 67 20 6f  |    . Clipping o|
00000230  62 6a 65 63 74 73 20 74  6f 20 62 65 20 70 6c 6f  |bjects to be plo|
00000240  74 74 65 64 20 61 67 61  69 6e 73 74 20 74 68 65  |tted against the|
00000250  20 72 65 67 69 6f 6e 20  6f 66 20 73 63 72 65 65  | region of scree|
00000260  6e 20 62 65 69 6e 67 20  72 65 64 72 61 77 6e 0a  |n being redrawn.|
00000270  20 2a 0a 20 2a 20 20 20  20 20 20 20 20 20 20 20  | *. *           |
00000280  54 68 69 73 20 74 61 6b  65 73 20 74 68 65 20 66  |This takes the f|
00000290  6f 72 6d 20 6f 66 20 61  6e 20 61 70 70 6c 69 63  |orm of an applic|
000002a0  61 74 69 6f 6e 20 77 68  69 63 68 20 6f 70 65 6e  |ation which open|
000002b0  73 20 6f 6e 65 20 77 69  6e 64 6f 77 20 6f 6e 20  |s one window on |
000002c0  72 75 6e 6e 69 6e 67 20  26 20 6d 61 69 6e 74 61  |running & mainta|
000002d0  69 6e 73 20 74 68 69 73  0a 20 2a 20 20 20 20 20  |ins this. *     |
000002e0  20 20 20 20 20 20 75 6e  74 69 6c 20 63 6c 6f 73  |      until clos|
000002f0  65 64 2c 20 74 68 61 74  20 61 63 74 20 61 6c 73  |ed, that act als|
00000300  6f 20 71 75 69 74 74 69  6e 67 20 74 68 65 20 61  |o quitting the a|
00000310  70 70 6c 69 63 61 74 69  6f 6e 2e 20 53 65 6c 65  |pplication. Sele|
00000320  63 74 20 6f 72 20 41 64  6a 75 73 74 20 63 6c 69  |ct or Adjust cli|
00000330  63 6b 73 20 69 6e 20 74  68 65 20 77 69 6e 64 6f  |cks in the windo|
00000340  77 0a 20 2a 20 20 20 20  20 20 20 20 20 20 20 72  |w. *           r|
00000350  65 73 75 6c 74 20 69 6e  20 27 6f 62 6a 65 63 74  |esult in 'object|
00000360  73 27 20 28 63 6f 6c 6f  75 72 65 64 20 73 68 61  |s' (coloured sha|
00000370  70 65 73 29 20 62 65 69  6e 67 20 63 72 65 61 74  |pes) being creat|
00000380  65 64 20 77 69 74 68 69  6e 20 74 68 65 20 77 69  |ed within the wi|
00000390  6e 64 6f 77 20 61 74 20  74 68 65 20 6c 6f 63 61  |ndow at the loca|
000003a0  74 69 6f 6e 20 6f 66 20  74 68 65 0a 20 2a 20 20  |tion of the. *  |
000003b0  20 20 20 20 20 20 20 20  20 63 6c 69 63 6b 2e 20  |         click. |
000003c0  43 6c 69 63 6b 69 6e 67  20 6f 6e 20 74 68 65 20  |Clicking on the |
000003d0  6f 6e 65 20 69 63 6f 6e  20 69 6e 20 74 68 65 20  |one icon in the |
000003e0  77 69 6e 64 6f 77 2c 20  6c 61 62 65 6c 6c 65 64  |window, labelled|
000003f0  20 27 43 6c 65 61 72 27  2c 20 72 65 6d 6f 76 65  | 'Clear', remove|
00000400  73 20 61 6c 6c 20 6f 62  6a 65 63 74 73 20 73 6f  |s all objects so|
00000410  20 66 61 72 0a 20 2a 20  20 20 20 20 20 20 20 20  | far. *         |
00000420  20 20 63 72 65 61 74 65  64 2e 0a 20 2a 2f 0a 0a  |  created.. */..|
00000430  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 69 6f 2e  |#include <stdio.|
00000440  68 3e 0a 23 69 6e 63 6c  75 64 65 20 3c 73 74 64  |h>.#include <std|
00000450  6c 69 62 2e 68 3e 0a 23  69 6e 63 6c 75 64 65 20  |lib.h>.#include |
00000460  3c 73 74 72 69 6e 67 2e  68 3e 0a 0a 23 69 6e 63  |<string.h>..#inc|
00000470  6c 75 64 65 20 22 77 69  6d 70 74 2e 68 22 0a 23  |lude "wimpt.h".#|
00000480  69 6e 63 6c 75 64 65 20  22 77 69 6d 70 2e 68 22  |include "wimp.h"|
00000490  0a 23 69 6e 63 6c 75 64  65 20 22 77 69 6e 2e 68  |.#include "win.h|
000004a0  22 0a 23 69 6e 63 6c 75  64 65 20 22 77 65 72 72  |".#include "werr|
000004b0  2e 68 22 0a 23 69 6e 63  6c 75 64 65 20 22 65 76  |.h".#include "ev|
000004c0  65 6e 74 2e 68 22 0a 23  69 6e 63 6c 75 64 65 20  |ent.h".#include |
000004d0  22 72 65 73 2e 68 22 0a  23 69 6e 63 6c 75 64 65  |"res.h".#include|
000004e0  20 22 74 65 6d 70 6c 61  74 65 2e 68 22 0a 23 69  | "template.h".#i|
000004f0  6e 63 6c 75 64 65 20 22  62 62 63 2e 68 22 0a 23  |nclude "bbc.h".#|
00000500  69 6e 63 6c 75 64 65 20  22 6f 73 2e 68 22 0a 0a  |include "os.h"..|
00000510  74 79 70 65 64 65 66 20  65 6e 75 6d 20 7b 20 20  |typedef enum {  |
00000520  20 20 20 20 20 20 20 20  2f 2a 20 41 6c 6c 6f 77  |        /* Allow|
00000530  20 75 73 20 74 6f 20 73  75 62 73 65 71 75 65 6e  | us to subsequen|
00000540  74 6c 79 20 72 65 66 65  72 20 74 6f 20 74 68 65  |tly refer to the|
00000550  20 69 63 6f 6e 73 20 26  20 77 69 6e 64 6f 77 20  | icons & window |
00000560  62 61 63 6b 67 72 6f 75  6e 64 20 62 79 20 6e 61  |background by na|
00000570  6d 65 20 2a 2f 0a 20 20  57 49 4e 44 4f 57 20 3d  |me */.  WINDOW =|
00000580  20 2d 31 2c 20 20 20 20  20 20 20 20 20 20 2f 2a  | -1,          /*|
00000590  20 72 61 74 68 65 72 20  74 68 61 6e 20 6a 75 73  | rather than jus|
000005a0  74 20 62 79 20 6e 75 6d  62 65 72 3b 20 74 68 69  |t by number; thi|
000005b0  73 20 6d 61 6b 65 73 20  6f 75 72 20 63 6f 64 65  |s makes our code|
000005c0  20 6d 75 63 68 20 6d 6f  72 65 20 69 6e 74 65 6c  | much more intel|
000005d0  6c 69 67 69 62 6c 65 2e  20 2a 2f 0a 20 20 43 4c  |ligible. */.  CL|
000005e0  45 41 52 2c 0a 20 20 49  4e 46 4f 0a 7d 20 6c 6f  |EAR,.  INFO.} lo|
000005f0  72 6e 61 5f 69 63 6f 6e  3b 0a 0a 74 79 70 65 64  |rna_icon;..typed|
00000600  65 66 20 65 6e 75 6d 20  7b 20 20 20 20 20 20 20  |ef enum {       |
00000610  20 20 20 2f 2a 20 57 65  20 77 69 6c 6c 20 64 72  |   /* We will dr|
00000620  61 77 20 74 77 6f 20 74  79 70 65 73 20 6f 66 20  |aw two types of |
00000630  6f 62 6a 65 63 74 20 69  6e 20 6f 75 72 20 77 69  |object in our wi|
00000640  6e 64 6f 77 3a 20 72 65  64 20 63 69 72 63 6c 65  |ndow: red circle|
00000650  73 20 26 20 62 6c 75 65  20 73 71 75 61 72 65 73  |s & blue squares|
00000660  2e 20 2a 2f 0a 20 20 43  49 52 43 4c 45 20 3d 20  |. */.  CIRCLE = |
00000670  30 2c 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |0,           /* |
00000680  54 68 69 73 20 6c 65 74  73 20 75 73 20 66 6c 61  |This lets us fla|
00000690  67 20 77 68 61 74 20 65  61 63 68 20 6f 62 6a 65  |g what each obje|
000006a0  63 74 20 69 73 20 62 79  20 6e 61 6d 65 20 72 61  |ct is by name ra|
000006b0  74 68 65 72 20 74 68 61  6e 20 62 79 20 6e 75 6d  |ther than by num|
000006c0  62 65 72 2e 20 2a 2f 0a  20 20 53 51 55 41 52 45  |ber. */.  SQUARE|
000006d0  0a 7d 20 6f 62 6a 65 63  74 5f 74 79 70 65 3b 0a  |.} object_type;.|
000006e0  0a 74 79 70 65 64 65 66  20 73 74 72 75 63 74 20  |.typedef struct |
000006f0  7b 20 20 20 20 20 20 20  20 2f 2a 20 57 65 20 6e  |{        /* We n|
00000700  65 65 64 20 74 6f 20 72  65 6d 65 6d 62 65 72 20  |eed to remember |
00000710  77 68 65 72 65 20 65 61  63 68 20 6f 62 6a 65 63  |where each objec|
00000720  74 20 69 73 20 69 6e 20  6f 75 72 20 77 69 6e 64  |t is in our wind|
00000730  6f 77 20 26 20 77 68 61  74 20 74 79 70 65 20 69  |ow & what type i|
00000740  74 20 69 73 2e 20 2a 2f  0a 20 20 6f 62 6a 65 63  |t is. */.  objec|
00000750  74 5f 74 79 70 65 20 74  79 70 65 3b 20 20 20 20  |t_type type;    |
00000760  20 2f 2a 20 54 68 69 73  20 73 74 72 75 63 74 75  | /* This structu|
00000770  72 65 20 6d 61 69 6e 74  61 69 6e 73 20 74 68 61  |re maintains tha|
00000780  74 20 69 6e 66 6f 72 6d  61 74 69 6f 6e 20 26 20  |t information & |
00000790  77 65 20 77 69 6c 6c 20  73 74 6f 72 65 20 61 6e  |we will store an|
000007a0  20 61 72 72 61 79 20 6f  66 20 74 68 65 73 65 2e  | array of these.|
000007b0  20 2a 2f 0a 20 20 69 6e  74 20 78 2c 20 79 3b 20  | */.  int x, y; |
000007c0  20 20 20 20 20 20 20 20  20 20 20 20 2f 2a 20 2d  |            /* -|
000007d0  20 6e 62 20 78 2c 79 20  61 72 65 20 63 6f 6f 72  | nb x,y are coor|
000007e0  64 73 20 6f 66 20 6f 62  6a 65 63 74 20 63 65 6e  |ds of object cen|
000007f0  74 72 65 20 26 20 61 72  65 20 72 65 6c 61 74 69  |tre & are relati|
00000800  76 65 20 74 6f 20 74 68  65 20 77 69 6e 64 6f 77  |ve to the window|
00000810  27 73 20 77 6f 72 6b 20  61 72 65 61 20 2a 2f 0a  |'s work area */.|
00000820  7d 20 6f 62 6a 65 63 74  3b 20 20 20 20 20 20 20  |} object;       |
00000830  20 20 20 20 20 20 20 20  2f 2a 20 20 20 6f 72 69  |        /*   ori|
00000840  67 69 6e 20 28 69 65 20  69 74 73 20 74 6f 70 20  |gin (ie its top |
00000850  6c 65 66 74 20 63 6f 72  6e 65 72 29 2c 20 73 6f  |left corner), so|
00000860  20 74 68 65 79 20 64 6f  6e 27 74 20 63 68 61 6e  | they don't chan|
00000870  67 65 20 69 66 20 74 68  65 20 77 69 6e 64 6f 77  |ge if the window|
00000880  20 69 73 20 6d 6f 76 65  64 20 20 2a 2f 0a 20 20  | is moved  */.  |
00000890  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000008a0  20 20 20 20 20 20 2f 2a  20 20 20 6f 72 20 73 63  |      /*   or sc|
000008b0  72 6f 6c 6c 65 64 2e 20  2a 2f 0a 0a 20 20 20 20  |rolled. */..    |
000008c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000008d0  20 20 20 20 2f 2a 20 45  61 63 68 20 6f 62 6a 65  |    /* Each obje|
000008e0  63 74 20 77 69 6c 6c 20  62 65 20 74 68 65 20 73  |ct will be the s|
000008f0  61 6d 65 20 73 69 7a 65  2e 20 54 68 65 20 66 6f  |ame size. The fo|
00000900  6c 6c 6f 77 69 6e 67 20  63 6f 6e 73 74 61 6e 74  |llowing constant|
00000910  20 64 65 66 69 6e 65 73  20 74 68 69 73 20 69 6e  | defines this in|
00000920  0a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
00000930  20 20 20 20 20 20 20 20  20 20 20 20 6f 73 20 67  |            os g|
00000940  72 61 70 68 69 63 73 20  75 6e 69 74 73 2e 20 2a  |raphics units. *|
00000950  2f 0a 23 64 65 66 69 6e  65 20 4f 42 4a 45 43 54  |/.#define OBJECT|
00000960  53 49 5a 45 20 33 32 20  20 20 2f 2a 20 46 6f 72  |SIZE 32   /* For|
00000970  20 61 20 63 69 72 63 6c  65 20 6f 62 6a 65 63 74  | a circle object|
00000980  20 74 68 69 73 20 77 69  6c 6c 20 62 65 20 69 74  | this will be it|
00000990  73 20 72 61 64 69 75 73  2c 0a 20 20 20 20 20 20  |s radius,.      |
000009a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000009b0  20 20 20 20 20 46 6f 72  20 61 20 73 71 75 61 72  |     For a squar|
000009c0  65 20 6f 62 6a 65 63 74  20 74 68 69 73 20 77 69  |e object this wi|
000009d0  6c 6c 20 62 65 20 68 61  6c 66 20 69 74 73 20 73  |ll be half its s|
000009e0  69 64 65 20 6c 65 6e 67  74 68 2e 20 2a 2f 0a 0a  |ide length. */..|
000009f0  23 64 65 66 69 6e 65 20  4d 41 58 4e 55 4d 4f 42  |#define MAXNUMOB|
00000a00  4a 45 43 54 53 20 31 32  38 0a 0a 20 20 20 20 20  |JECTS 128..     |
00000a10  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000a20  20 20 20 2f 2a 20 57 68  65 6e 20 77 65 20 63 68  |   /* When we ch|
00000a30  65 63 6b 20 74 6f 20 73  65 65 20 69 66 20 61 6e  |eck to see if an|
00000a40  20 6f 62 6a 65 63 74 20  6f 76 65 72 6c 61 70 73  | object overlaps|
00000a50  20 61 20 72 65 67 69 6f  6e 20 6f 66 20 73 63 72  | a region of scr|
00000a60  65 65 6e 20 62 65 69 6e  67 20 72 65 64 72 61 77  |een being redraw|
00000a70  6e 2c 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |n,.             |
00000a80  20 20 20 20 20 20 20 20  20 20 20 20 20 20 6f 72  |              or|
00000a90  20 72 65 71 75 65 73 74  20 74 68 61 74 20 61 20  | request that a |
00000aa0  70 61 72 74 69 63 75 6c  61 72 20 72 65 67 69 6f  |particular regio|
00000ab0  6e 20 62 65 20 72 65 64  72 61 77 6e 2c 20 77 65  |n be redrawn, we|
00000ac0  20 61 64 64 20 69 6e 20  61 20 73 6d 61 6c 6c 20  | add in a small |
00000ad0  62 6f 72 64 65 72 0a 20  20 20 20 20 20 20 20 20  |border.         |
00000ae0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000af0  20 20 61 72 6f 75 6e 64  20 74 68 65 20 6f 62 6a  |  around the obj|
00000b00  65 63 74 20 63 6f 6e 63  65 72 6e 65 64 20 66 6f  |ect concerned fo|
00000b10  72 20 73 61 66 65 74 79  2c 20 74 6f 20 61 76 6f  |r safety, to avo|
00000b20  69 64 20 6e 75 6d 65 72  69 63 61 6c 20 72 6f 75  |id numerical rou|
00000b30  6e 64 69 6e 67 20 65 72  72 6f 72 73 20 2a 2f 0a  |nding errors */.|
00000b40  23 64 65 66 69 6e 65 20  42 4f 52 44 45 52 20 38  |#define BORDER 8|
00000b50  20 20 20 20 20 20 20 20  2f 2a 20 77 68 69 63 68  |        /* which|
00000b60  20 63 6f 75 6c 64 20 6f  74 68 65 72 77 69 73 65  | could otherwise|
00000b70  20 72 65 73 75 6c 74 73  20 69 6e 20 73 6d 61 6c  | results in smal|
00000b80  6c 20 6f 76 65 72 6c 61  70 73 20 65 74 63 20 62  |l overlaps etc b|
00000b90  65 69 6e 67 20 6d 69 73  73 65 64 2e 20 54 68 69  |eing missed. Thi|
00000ba0  73 20 69 73 20 74 68 65  0a 20 20 20 20 20 20 20  |s is the.       |
00000bb0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000bc0  20 20 20 20 77 69 64 74  68 20 6f 66 20 74 68 61  |    width of tha|
00000bd0  74 20 62 6f 72 64 65 72  20 73 74 72 69 70 20 69  |t border strip i|
00000be0  6e 20 6f 73 20 67 72 61  70 68 69 63 73 20 75 6e  |n os graphics un|
00000bf0  69 74 73 2e 20 2a 2f 0a  0a 2f 2a 2a 2a 2a 2a 2a  |its. */../******|
00000c00  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000c60  2a 2a 2a 2a 2a 2f 0a 0a  77 69 6d 70 5f 77 20 6c  |*****/..wimp_w l|
00000c70  6f 72 6e 61 3b 20 20 20  20 20 20 20 20 20 20 20  |orna;           |
00000c80  2f 2a 20 54 68 65 20 68  61 6e 64 6c 65 20 66 6f  |/* The handle fo|
00000c90  72 20 6f 75 72 20 73 69  6e 67 6c 65 20 77 69 6e  |r our single win|
00000ca0  64 6f 77 2e 20 2a 2f 0a  69 6e 74 20 6e 75 6d 5f  |dow. */.int num_|
00000cb0  6f 62 6a 65 63 74 73 3b  20 20 20 20 20 20 20 20  |objects;        |
00000cc0  2f 2a 20 41 20 72 65 63  6f 72 64 20 6f 66 20 74  |/* A record of t|
00000cd0  68 65 20 6e 75 6d 62 65  72 20 6f 66 20 6f 62 6a  |he number of obj|
00000ce0  65 63 74 73 20 63 75 72  72 65 6e 74 6c 79 20 65  |ects currently e|
00000cf0  78 69 73 74 69 6e 67 20  69 6e 20 6f 75 72 20 77  |xisting in our w|
00000d00  69 6e 64 6f 77 2e 20 2a  2f 0a 6f 62 6a 65 63 74  |indow. */.object|
00000d10  20 2a 6f 62 6a 65 63 74  73 3b 20 20 20 20 20 20  | *objects;      |
00000d20  20 20 2f 2a 20 41 20 70  6f 69 6e 74 65 72 20 74  |  /* A pointer t|
00000d30  6f 20 6f 75 72 20 61 72  72 61 79 20 6f 66 20 6f  |o our array of o|
00000d40  62 6a 65 63 74 73 2e 20  2a 2f 0a 0a 2f 2a 2a 2a  |bjects. */../***|
00000d50  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000db0  2a 2a 2a 2a 2a 2a 2a 2a  2f 0a 0a 6f 73 5f 65 72  |********/..os_er|
00000dc0  72 6f 72 20 2a 66 6f 72  63 65 5f 72 65 64 72 61  |ror *force_redra|
00000dd0  77 5f 61 6c 6c 28 76 6f  69 64 29 20 20 20 20 20  |w_all(void)     |
00000de0  20 20 20 2f 2a 20 54 68  69 73 20 66 75 6e 63 74  |   /* This funct|
00000df0  69 6f 6e 20 6d 61 6b 65  73 20 74 68 65 20 77 69  |ion makes the wi|
00000e00  6d 70 20 73 68 6f 72 74  6c 79 20 72 65 74 75 72  |mp shortly retur|
00000e10  6e 20 61 20 72 65 64 72  61 77 20 65 76 65 6e 74  |n a redraw event|
00000e20  20 66 6f 72 20 2a 2f 0a  7b 20 20 20 20 20 20 20  | for */.{       |
00000e30  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000e50  2f 2a 20 6f 75 72 20 77  69 6e 64 6f 77 2c 20 77  |/* our window, w|
00000e60  68 69 63 68 20 77 69 6c  6c 20 63 61 75 73 65 20  |hich will cause |
00000e70  61 6c 6c 20 6f 66 20 69  74 20 74 6f 20 62 65 20  |all of it to be |
00000e80  72 65 70 6c 6f 74 74 65  64 2e 20 2a 2f 0a 20 20  |replotted. */.  |
00000e90  77 69 6d 70 5f 72 65 64  72 61 77 73 74 72 20 72  |wimp_redrawstr r|
00000ea0  3b 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;               |
00000eb0  20 20 20 20 20 20 2f 2a  20 57 65 20 63 61 6c 6c  |      /* We call|
00000ec0  20 74 68 69 73 20 77 68  65 6e 20 77 65 27 76 65  | this when we've|
00000ed0  20 64 6f 6e 65 20 73 6f  6d 65 74 68 69 6e 67 20  | done something |
00000ee0  77 68 69 63 68 20 6e 65  63 65 73 73 69 74 61 74  |which necessitat|
00000ef0  65 73 20 2a 2f 0a 20 20  72 2e 77 20 3d 20 6c 6f  |es */.  r.w = lo|
00000f00  72 6e 61 3b 20 20 20 20  20 20 20 20 20 20 20 20  |rna;            |
00000f10  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2a  |              /*|
00000f20  20 61 6c 74 65 72 69 6e  67 20 6d 75 63 68 20 6f  | altering much o|
00000f30  66 20 74 68 65 20 77 69  6e 64 6f 77 27 73 20 61  |f the window's a|
00000f40  70 70 65 61 72 61 6e 63  65 2c 20 73 75 63 68 20  |ppearance, such |
00000f50  61 73 20 77 68 65 6e 20  77 65 20 2a 2f 0a 20 20  |as when we */.  |
00000f60  72 2e 62 6f 78 2e 78 30  20 3d 20 72 2e 62 6f 78  |r.box.x0 = r.box|
00000f70  2e 79 31 20 3d 20 30 3b  20 20 20 20 20 20 20 20  |.y1 = 0;        |
00000f80  20 20 20 20 20 20 2f 2a  20 72 65 6d 6f 76 65 20  |      /* remove |
00000f90  61 6c 6c 20 74 68 65 20  6f 62 6a 65 63 74 73 20  |all the objects |
00000fa0  69 6e 20 69 74 2e 20 2a  2f 0a 20 20 72 2e 62 6f  |in it. */.  r.bo|
00000fb0  78 2e 78 31 20 3d 20 33  32 37 36 38 3b 20 20 20  |x.x1 = 32768;   |
00000fc0  20 20 20 20 20 20 20 20  20 20 2f 2a 20 28 61 20  |          /* (a |
00000fd0  6e 69 63 65 20 62 69 67  20 6e 75 6d 62 65 72 20  |nice big number |
00000fe0  74 6f 20 65 6e 73 75 72  65 20 77 65 20 63 6f 76  |to ensure we cov|
00000ff0  65 72 20 61 6c 6c 20 6f  66 20 74 68 65 20 77 6f  |er all of the wo|
00001000  72 6b 20 61 72 65 61 29  2e 20 2a 2f 0a 20 20 72  |rk area). */.  r|
00001010  2e 62 6f 78 2e 79 30 20  3d 20 2d 33 32 37 36 38  |.box.y0 = -32768|
00001020  3b 0a 20 20 72 65 74 75  72 6e 20 77 69 6d 70 74  |;.  return wimpt|
00001030  5f 63 6f 6d 70 6c 61 69  6e 28 77 69 6d 70 5f 66  |_complain(wimp_f|
00001040  6f 72 63 65 5f 72 65 64  72 61 77 28 26 72 29 29  |orce_redraw(&r))|
00001050  3b 0a 7d 0a 0a 6f 73 5f  65 72 72 6f 72 20 2a 66  |;.}..os_error *f|
00001060  6f 72 63 65 5f 72 65 64  72 61 77 5f 6f 62 6a 65  |orce_redraw_obje|
00001070  63 74 28 6f 62 6a 65 63  74 20 2a 6f 62 6a 29 20  |ct(object *obj) |
00001080  20 20 20 20 20 2f 2a 20  41 73 20 69 6e 20 66 6f  |     /* As in fo|
00001090  72 63 65 5f 72 65 64 72  61 77 5f 61 6c 6c 2c 20  |rce_redraw_all, |
000010a0  74 68 69 73 20 66 6e 20  63 61 75 73 65 73 20 74  |this fn causes t|
000010b0  68 65 20 77 69 6d 70 20  74 6f 20 2a 2f 0a 7b 20  |he wimp to */.{ |
000010c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000010e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2a  |              /*|
000010f0  20 72 65 74 75 72 6e 20  61 20 72 65 64 72 61 77  | return a redraw|
00001100  20 65 76 65 6e 74 20 66  6f 72 20 6f 75 72 20 77  | event for our w|
00001110  69 6e 64 6f 77 20 65 76  65 6e 74 75 61 6c 6c 79  |indow eventually|
00001120  2c 20 2a 2f 0a 20 20 77  69 6d 70 5f 72 65 64 72  |, */.  wimp_redr|
00001130  61 77 73 74 72 20 72 3b  20 20 20 20 20 20 20 20  |awstr r;        |
00001140  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001150  20 20 20 20 20 2f 2a 20  68 6f 77 65 76 65 72 20  |     /* however |
00001160  74 68 69 73 20 74 69 6d  65 20 74 68 65 20 72 65  |this time the re|
00001170  67 69 6f 6e 20 74 6f 20  62 65 20 72 65 64 72 61  |gion to be redra|
00001180  77 6e 20 69 73 20 74 68  61 74 20 2a 2f 0a 20 20  |wn is that */.  |
00001190  72 2e 77 20 3d 20 6c 6f  72 6e 61 3b 20 20 20 20  |r.w = lorna;    |
000011a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000011b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2a  |              /*|
000011c0  20 63 6f 76 65 72 65 64  20 62 79 20 74 68 65 20  | covered by the |
000011d0  73 69 6e 67 6c 65 20 6f  62 6a 65 63 74 20 77 68  |single object wh|
000011e0  6f 73 65 20 64 61 74 61  20 69 73 20 70 6f 69 6e  |ose data is poin|
000011f0  74 65 64 20 74 6f 20 2a  2f 0a 20 20 72 2e 62 6f  |ted to */.  r.bo|
00001200  78 2e 78 30 20 3d 20 6f  62 6a 2d 3e 78 2d 4f 42  |x.x0 = obj->x-OB|
00001210  4a 45 43 54 53 49 5a 45  2d 42 4f 52 44 45 52 3b  |JECTSIZE-BORDER;|
00001220  20 20 20 20 20 20 20 20  20 20 2f 2a 20 62 79 20  |          /* by |
00001230  6f 62 6a 2e 20 2a 2f 0a  20 20 72 2e 62 6f 78 2e  |obj. */.  r.box.|
00001240  78 31 20 3d 20 6f 62 6a  2d 3e 78 2b 4f 42 4a 45  |x1 = obj->x+OBJE|
00001250  43 54 53 49 5a 45 2b 42  4f 52 44 45 52 3b 0a 20  |CTSIZE+BORDER;. |
00001260  20 72 2e 62 6f 78 2e 79  30 20 3d 20 6f 62 6a 2d  | r.box.y0 = obj-|
00001270  3e 79 2d 4f 42 4a 45 43  54 53 49 5a 45 2d 42 4f  |>y-OBJECTSIZE-BO|
00001280  52 44 45 52 3b 20 20 20  20 20 20 20 20 20 20 2f  |RDER;          /|
00001290  2a 20 4e 6f 74 69 63 65  20 74 68 65 20 75 73 65  |* Notice the use|
000012a0  20 6f 66 20 42 4f 52 44  45 52 20 74 6f 20 65 6e  | of BORDER to en|
000012b0  73 75 72 65 20 77 65 20  63 6f 76 65 72 20 61 6e  |sure we cover an|
000012c0  20 61 72 65 61 20 2a 2f  0a 20 20 72 2e 62 6f 78  | area */.  r.box|
000012d0  2e 79 31 20 3d 20 6f 62  6a 2d 3e 79 2b 4f 42 4a  |.y1 = obj->y+OBJ|
000012e0  45 43 54 53 49 5a 45 2b  42 4f 52 44 45 52 3b 20  |ECTSIZE+BORDER; |
000012f0  20 20 20 20 20 20 20 20  20 2f 2a 20 73 6c 69 67  |         /* slig|
00001300  68 74 6c 79 20 62 69 67  67 65 72 20 74 68 61 6e  |htly bigger than|
00001310  20 74 68 65 20 6f 62 6a  65 63 74 2e 20 53 74 72  | the object. Str|
00001320  69 63 74 6c 79 20 74 68  69 73 20 2a 2f 0a 20 20  |ictly this */.  |
00001330  72 65 74 75 72 6e 20 77  69 6d 70 74 5f 63 6f 6d  |return wimpt_com|
00001340  70 6c 61 69 6e 28 77 69  6d 70 5f 66 6f 72 63 65  |plain(wimp_force|
00001350  5f 72 65 64 72 61 77 28  26 72 29 29 3b 20 2f 2a  |_redraw(&r)); /*|
00001360  20 73 68 6f 75 6c 64 6e  27 74 20 62 65 20 6e 65  | shouldn't be ne|
00001370  65 64 65 64 2c 20 68 6f  77 65 76 65 72 20 73 6d  |eded, however sm|
00001380  61 6c 6c 20 70 69 78 65  6c 20 73 69 7a 65 64 20  |all pixel sized |
00001390  65 72 72 6f 72 73 0a 20  20 20 20 20 20 20 20 20  |errors.         |
000013a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000013c0  20 20 20 20 20 20 20 20  20 20 63 61 6e 20 6f 63  |          can oc|
000013d0  63 75 72 20 69 6e 20 74  68 65 20 70 6c 6f 74 74  |cur in the plott|
000013e0  65 64 20 70 6f 73 69 74  69 6f 6e 20 6f 66 20 74  |ed position of t|
000013f0  68 65 20 6f 62 6a 65 63  74 20 26 20 74 68 69 73  |he object & this|
00001400  0a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
00001410  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001430  20 20 20 20 62 6f 72 64  65 72 20 65 6e 73 75 72  |    border ensur|
00001440  65 73 20 74 68 65 20 72  65 64 72 61 77 20 72 65  |es the redraw re|
00001450  67 69 6f 6e 20 73 74 69  6c 6c 20 63 6f 76 65 72  |gion still cover|
00001460  73 20 74 68 65 20 6f 62  6a 65 63 74 0a 20 20 20  |s the object.   |
00001470  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000014a0  65 76 65 6e 20 69 66 20  69 74 20 69 73 20 6f 75  |even if it is ou|
000014b0  74 20 6f 66 20 70 6f 73  69 74 69 6f 6e 20 62 79  |t of position by|
000014c0  20 73 75 63 68 20 61 6e  20 61 6d 6f 75 6e 74 2e  | such an amount.|
000014d0  20 2a 2f 0a 7d 0a 0a 76  6f 69 64 20 72 65 64 72  | */.}..void redr|
000014e0  61 77 5f 77 69 6e 64 6f  77 28 77 69 6d 70 5f 77  |aw_window(wimp_w|
000014f0  20 68 61 6e 64 6c 65 29  20 20 20 20 20 20 20 20  | handle)        |
00001500  20 20 20 20 20 20 20 2f  2a 20 54 68 69 73 20 66  |       /* This f|
00001510  75 6e 63 74 69 6f 6e 20  69 73 20 63 61 6c 6c 65  |unction is calle|
00001520  64 20 77 68 65 6e 20 6f  75 72 20 65 76 65 6e 74  |d when our event|
00001530  20 68 61 6e 64 6c 65 72  20 69 73 20 61 73 6b 65  | handler is aske|
00001540  64 20 2a 2f 0a 7b 20 20  20 20 20 20 20 20 20 20  |d */.{          |
00001550  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001570  20 20 20 20 20 2f 2a 20  62 79 20 74 68 65 20 77  |     /* by the w|
00001580  69 6d 70 20 74 6f 20 72  65 64 72 61 77 20 70 61  |imp to redraw pa|
00001590  72 74 2f 73 20 6f 66 20  6f 75 72 20 77 69 6e 64  |rt/s of our wind|
000015a0  6f 77 2e 20 2a 2f 0a 20  20 42 4f 4f 4c 20 6d 6f  |ow. */.  BOOL mo|
000015b0  72 65 3b 20 20 20 20 20  20 20 20 20 20 20 20 20  |re;             |
000015c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000015d0  20 20 20 20 20 20 20 2f  2a 20 49 74 20 67 6f 65  |       /* It goe|
000015e0  73 20 74 68 72 6f 75 67  68 20 74 68 65 20 70 72  |s through the pr|
000015f0  65 73 63 72 69 62 65 64  20 6c 6f 6f 70 2c 20 65  |escribed loop, e|
00001600  61 63 68 20 70 61 73 73  20 62 65 69 6e 67 20 2a  |ach pass being *|
00001610  2f 0a 20 20 77 69 6d 70  5f 72 65 64 72 61 77 73  |/.  wimp_redraws|
00001620  74 72 20 72 3b 20 20 20  20 20 20 20 20 20 20 20  |tr r;           |
00001630  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001640  20 20 2f 2a 20 67 69 76  65 6e 20 6f 6e 65 20 72  |  /* given one r|
00001650  65 63 74 61 6e 67 75 6c  61 72 20 72 65 67 69 6f  |ectangular regio|
00001660  6e 20 74 6f 20 72 65 64  72 61 77 2e 20 2a 2f 0a  |n to redraw. */.|
00001670  20 20 69 6e 74 20 69 3b  20 20 20 20 20 20 20 20  |  int i;        |
00001680  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000016a0  2f 2a 20 46 6f 72 20 65  61 63 68 20 73 75 63 68  |/* For each such|
000016b0  20 72 65 67 69 6f 6e 20  77 65 20 6d 75 73 74 20  | region we must |
000016c0  63 68 65 63 6b 20 61 6c  6c 20 6f 66 20 6f 75 72  |check all of our|
000016d0  20 6f 62 6a 65 63 74 73  2c 20 2a 2f 0a 20 20 69  | objects, */.  i|
000016e0  6e 74 20 78 6f 2c 20 79  6f 3b 20 20 20 20 20 20  |nt xo, yo;      |
000016f0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001700  20 20 20 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |             /* |
00001710  26 20 66 6f 72 20 61 6e  79 20 77 68 69 63 68 20  |& for any which |
00001720  6f 76 65 72 6c 61 70 73  20 74 68 65 20 72 65 67  |overlaps the reg|
00001730  69 6f 6e 20 62 65 69 6e  67 20 72 65 64 72 61 77  |ion being redraw|
00001740  6e 2c 20 77 65 20 2a 2f  0a 20 20 69 6e 74 20 73  |n, we */.  int s|
00001750  78 2c 20 73 79 3b 20 20  20 20 20 20 20 20 20 20  |x, sy;          |
00001760  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001770  20 20 20 20 20 20 20 20  20 2f 2a 20 70 6c 6f 74  |         /* plot|
00001780  20 69 74 2e 20 2a 2f 0a  20 20 6f 62 6a 65 63 74  | it. */.  object|
00001790  20 2a 6f 62 6a 3b 20 20  20 20 20 20 20 20 20 20  | *obj;          |
000017a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000017b0  20 20 20 20 20 20 20 20  2f 2a 20 49 74 20 69 73  |        /* It is|
000017c0  20 69 6d 70 6f 72 74 61  6e 74 20 74 68 61 74 20  | important that |
000017d0  77 65 20 64 6f 20 63 6c  69 70 20 65 61 63 68 20  |we do clip each |
000017e0  6f 62 6a 65 63 74 20 72  61 74 68 65 72 20 74 68  |object rather th|
000017f0  61 6e 20 2a 2f 0a 20 20  20 20 20 20 20 20 20 20  |an */.          |
00001800  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001820  20 20 20 20 20 20 2f 2a  20 73 69 6d 70 6c 79 20  |      /* simply |
00001830  70 6c 6f 74 20 61 6c 6c  2c 20 61 73 20 74 68 69  |plot all, as thi|
00001840  73 20 63 61 6e 20 6d 61  73 73 69 76 65 6c 79 20  |s can massively |
00001850  61 66 66 65 63 74 20 72  65 64 72 61 77 20 2a 2f  |affect redraw */|
00001860  0a 20 20 2f 2a 20 53 74  61 72 74 20 74 68 65 20  |.  /* Start the |
00001870  72 65 64 72 61 77 20 2a  2f 20 20 20 20 20 20 20  |redraw */       |
00001880  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001890  20 2f 2a 20 73 70 65 65  64 20 77 68 69 63 68 20  | /* speed which |
000018a0  69 74 20 69 73 20 69 6d  70 6f 72 74 61 6e 74 20  |it is important |
000018b0  74 6f 20 6b 65 65 70 20  68 69 67 68 2e 20 2a 2f  |to keep high. */|
000018c0  0a 20 20 72 2e 77 20 3d  20 68 61 6e 64 6c 65 3b  |.  r.w = handle;|
000018d0  0a 20 20 77 69 6d 70 74  5f 6e 6f 65 72 72 28 77  |.  wimpt_noerr(w|
000018e0  69 6d 70 5f 72 65 64 72  61 77 5f 77 69 6e 64 28  |imp_redraw_wind(|
000018f0  26 72 2c 20 26 6d 6f 72  65 29 29 3b 0a 20 20 77  |&r, &more));.  w|
00001900  68 69 6c 65 20 28 6d 6f  72 65 29 0a 20 20 7b 0a  |hile (more).  {.|
00001910  20 20 20 20 2f 2a 20 52  65 64 72 61 77 20 72 65  |    /* Redraw re|
00001920  63 74 61 6e 67 6c 65 20  72 2e 67 20 28 73 63 72  |ctangle r.g (scr|
00001930  65 65 6e 20 63 6f 6f 72  64 73 29 2c 20 63 6c 69  |een coords), cli|
00001940  70 70 69 6e 67 20 6f 62  6a 65 63 74 73 20 74 6f  |pping objects to|
00001950  20 72 65 63 74 61 6e 67  6c 65 20 72 2e 67 20 2a  | rectangle r.g *|
00001960  2f 0a 20 20 20 20 78 6f  20 3d 20 72 2e 73 63 78  |/.    xo = r.scx|
00001970  20 2d 20 72 2e 62 6f 78  2e 78 30 3b 20 20 20 20  | - r.box.x0;    |
00001980  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001990  20 20 2f 2a 20 4e 42 20  78 6f 2c 79 6f 20 61 72  |  /* NB xo,yo ar|
000019a0  65 20 77 6f 72 6b 20 61  72 65 61 20 63 6f 6f 72  |e work area coor|
000019b0  64 73 20 6f 66 20 74 68  65 20 73 63 72 65 65 6e  |ds of the screen|
000019c0  27 73 20 6f 72 69 67 69  6e 2e 20 2a 2f 0a 20 20  |'s origin. */.  |
000019d0  20 20 79 6f 20 3d 20 72  2e 73 63 79 20 2d 20 72  |  yo = r.scy - r|
000019e0  2e 62 6f 78 2e 79 31 3b  0a 20 20 20 20 66 6f 72  |.box.y1;.    for|
000019f0  20 28 69 3d 30 2c 20 6f  62 6a 3d 6f 62 6a 65 63  | (i=0, obj=objec|
00001a00  74 73 3b 20 69 3c 6e 75  6d 5f 6f 62 6a 65 63 74  |ts; i<num_object|
00001a10  73 3b 20 69 2b 2b 2c 20  6f 62 6a 2b 2b 29 20 7b  |s; i++, obj++) {|
00001a20  0a 20 20 20 20 20 20 73  78 20 3d 20 6f 62 6a 2d  |.      sx = obj-|
00001a30  3e 78 20 2d 20 78 6f 3b  20 20 20 20 20 20 20 20  |>x - xo;        |
00001a40  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001a50  20 2f 2a 20 53 63 72 65  65 6e 20 63 6f 6f 72 64  | /* Screen coord|
00001a60  73 20 6f 66 20 63 65 6e  74 72 65 20 6f 66 20 6f  |s of centre of o|
00001a70  62 6a 65 63 74 2e 20 2a  2f 0a 20 20 20 20 20 20  |bject. */.      |
00001a80  73 79 20 3d 20 6f 62 6a  2d 3e 79 20 2d 20 79 6f  |sy = obj->y - yo|
00001a90  3b 0a 20 20 20 20 20 20  69 66 20 28 73 78 2d 4f  |;.      if (sx-O|
00001aa0  42 4a 45 43 54 53 49 5a  45 20 3c 20 72 2e 67 2e  |BJECTSIZE < r.g.|
00001ab0  78 31 2b 42 4f 52 44 45  52 20 20 26 26 20 20 20  |x1+BORDER  &&   |
00001ac0  20 20 2f 2a 20 49 66 20  6c 65 66 74 20 73 69 64  |  /* If left sid|
00001ad0  65 20 6f 66 20 6f 62 6a  65 63 74 20 69 73 20 74  |e of object is t|
00001ae0  6f 20 6c 65 66 74 20 6f  66 20 63 6c 69 70 20 72  |o left of clip r|
00001af0  65 67 69 6f 6e 27 73 20  72 69 67 68 74 2a 2f 0a  |egion's right*/.|
00001b00  20 20 20 20 20 20 20 20  20 20 73 78 2b 4f 42 4a  |          sx+OBJ|
00001b10  45 43 54 53 49 5a 45 20  3e 20 72 2e 67 2e 78 30  |ECTSIZE > r.g.x0|
00001b20  2d 42 4f 52 44 45 52 20  20 26 26 20 20 20 20 20  |-BORDER  &&     |
00001b30  2f 2a 20 26 20 72 69 67  68 74 20 73 69 64 65 20  |/* & right side |
00001b40  6f 66 20 6f 62 6a 65 63  74 20 69 73 20 74 6f 20  |of object is to |
00001b50  72 69 67 68 74 20 6f 66  20 63 6c 69 70 20 72 65  |right of clip re|
00001b60  67 69 6f 6e 27 73 20 6c  65 66 74 2a 2f 0a 20 20  |gion's left*/.  |
00001b70  20 20 20 20 20 20 20 20  73 79 2d 4f 42 4a 45 43  |        sy-OBJEC|
00001b80  54 53 49 5a 45 20 3c 20  72 2e 67 2e 79 31 2b 42  |TSIZE < r.g.y1+B|
00001b90  4f 52 44 45 52 20 20 26  26 20 20 20 20 20 2f 2a  |ORDER  &&     /*|
00001ba0  20 26 20 62 6f 74 74 6f  6d 20 69 73 20 62 65 6c  | & bottom is bel|
00001bb0  6f 77 20 74 6f 70 20 6f  66 20 63 6c 69 70 20 72  |ow top of clip r|
00001bc0  65 67 69 6f 6e 20 2a 2f  0a 20 20 20 20 20 20 20  |egion */.       |
00001bd0  20 20 20 73 79 2b 4f 42  4a 45 43 54 53 49 5a 45  |   sy+OBJECTSIZE|
00001be0  20 3e 20 72 2e 67 2e 79  30 2d 42 4f 52 44 45 52  | > r.g.y0-BORDER|
00001bf0  20 20 20 20 20 29 20 20  20 2f 2a 20 26 20 74 6f  |     )   /* & to|
00001c00  70 20 69 73 20 61 62 6f  76 65 20 62 6f 74 74 6f  |p is above botto|
00001c10  6d 20 6f 66 20 63 6c 69  70 20 72 65 67 69 6f 6e  |m of clip region|
00001c20  2c 20 2a 2f 0a 20 20 20  20 20 20 20 20 20 20 20  |, */.           |
00001c30  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001c50  20 20 20 20 20 2f 2a 20  74 68 65 6e 20 6f 62 6a  |     /* then obj|
00001c60  65 63 74 20 26 20 63 6c  69 70 20 72 65 67 69 6f  |ect & clip regio|
00001c70  6e 20 64 6f 20 69 6e 74  65 72 73 65 63 74 2c 20  |n do intersect, |
00001c80  73 6f 20 70 6c 6f 74 20  6f 62 6a 65 63 74 2e 20  |so plot object. |
00001c90  2a 2f 0a 20 20 20 20 20  20 20 20 73 77 69 74 63  |*/.        switc|
00001ca0  68 20 28 6f 62 6a 2d 3e  74 79 70 65 29 0a 20 20  |h (obj->type).  |
00001cb0  20 20 20 20 20 20 7b 0a  20 20 20 20 20 20 20 20  |      {.        |
00001cc0  20 20 63 61 73 65 20 43  49 52 43 4c 45 3a 0a 20  |  case CIRCLE:. |
00001cd0  20 20 20 20 20 20 20 20  20 20 20 77 69 6d 70 74  |           wimpt|
00001ce0  5f 6e 6f 65 72 72 28 77  69 6d 70 5f 73 65 74 63  |_noerr(wimp_setc|
00001cf0  6f 6c 6f 75 72 28 31 31  29 29 3b 0a 20 20 20 20  |olour(11));.    |
00001d00  20 20 20 20 20 20 20 20  77 69 6d 70 74 5f 6e 6f  |        wimpt_no|
00001d10  65 72 72 28 62 62 63 5f  63 69 72 63 6c 65 66 69  |err(bbc_circlefi|
00001d20  6c 6c 28 73 78 2c 20 73  79 2c 20 4f 42 4a 45 43  |ll(sx, sy, OBJEC|
00001d30  54 53 49 5a 45 29 29 3b  0a 20 20 20 20 20 20 20  |TSIZE));.       |
00001d40  20 20 20 20 20 77 69 6d  70 74 5f 6e 6f 65 72 72  |     wimpt_noerr|
00001d50  28 77 69 6d 70 5f 73 65  74 63 6f 6c 6f 75 72 28  |(wimp_setcolour(|
00001d60  37 29 29 3b 0a 20 20 20  20 20 20 20 20 20 20 20  |7));.           |
00001d70  20 77 69 6d 70 74 5f 6e  6f 65 72 72 28 62 62 63  | wimpt_noerr(bbc|
00001d80  5f 63 69 72 63 6c 65 28  73 78 2c 20 73 79 2c 20  |_circle(sx, sy, |
00001d90  4f 42 4a 45 43 54 53 49  5a 45 29 29 3b 0a 20 20  |OBJECTSIZE));.  |
00001da0  20 20 20 20 20 20 20 20  20 20 62 72 65 61 6b 3b  |          break;|
00001db0  0a 0a 20 20 20 20 20 20  20 20 20 20 63 61 73 65  |..          case|
00001dc0  20 53 51 55 41 52 45 3a  0a 20 20 20 20 20 20 20  | SQUARE:.       |
00001dd0  20 20 20 20 20 77 69 6d  70 74 5f 6e 6f 65 72 72  |     wimpt_noerr|
00001de0  28 77 69 6d 70 5f 73 65  74 63 6f 6c 6f 75 72 28  |(wimp_setcolour(|
00001df0  31 35 29 29 3b 0a 20 20  20 20 20 20 20 20 20 20  |15));.          |
00001e00  20 20 77 69 6d 70 74 5f  6e 6f 65 72 72 28 62 62  |  wimpt_noerr(bb|
00001e10  63 5f 72 65 63 74 61 6e  67 6c 65 66 69 6c 6c 28  |c_rectanglefill(|
00001e20  73 78 2d 4f 42 4a 45 43  54 53 49 5a 45 2c 20 73  |sx-OBJECTSIZE, s|
00001e30  79 2d 4f 42 4a 45 43 54  53 49 5a 45 2c 20 4f 42  |y-OBJECTSIZE, OB|
00001e40  4a 45 43 54 53 49 5a 45  2a 32 2c 20 4f 42 4a 45  |JECTSIZE*2, OBJE|
00001e50  43 54 53 49 5a 45 2a 32  29 29 3b 0a 20 20 20 20  |CTSIZE*2));.    |
00001e60  20 20 20 20 20 20 20 20  77 69 6d 70 74 5f 6e 6f  |        wimpt_no|
00001e70  65 72 72 28 77 69 6d 70  5f 73 65 74 63 6f 6c 6f  |err(wimp_setcolo|
00001e80  75 72 28 37 29 29 3b 0a  20 20 20 20 20 20 20 20  |ur(7));.        |
00001e90  20 20 20 20 77 69 6d 70  74 5f 6e 6f 65 72 72 28  |    wimpt_noerr(|
00001ea0  62 62 63 5f 72 65 63 74  61 6e 67 6c 65 28 73 78  |bbc_rectangle(sx|
00001eb0  2d 4f 42 4a 45 43 54 53  49 5a 45 2c 20 73 79 2d  |-OBJECTSIZE, sy-|
00001ec0  4f 42 4a 45 43 54 53 49  5a 45 2c 20 4f 42 4a 45  |OBJECTSIZE, OBJE|
00001ed0  43 54 53 49 5a 45 2a 32  2c 20 4f 42 4a 45 43 54  |CTSIZE*2, OBJECT|
00001ee0  53 49 5a 45 2a 32 29 29  3b 0a 20 20 20 20 20 20  |SIZE*2));.      |
00001ef0  20 20 20 20 20 20 62 72  65 61 6b 3b 0a 20 20 20  |      break;.   |
00001f00  20 20 20 20 20 7d 0a 20  20 20 20 7d 0a 20 20 20  |     }.    }.   |
00001f10  20 77 69 6d 70 5f 67 65  74 5f 72 65 63 74 61 6e  | wimp_get_rectan|
00001f20  67 6c 65 28 26 72 2c 20  26 6d 6f 72 65 29 3b 0a  |gle(&r, &more);.|
00001f30  20 20 7d 0a 0a 20 20 72  65 74 75 72 6e 3b 0a 7d  |  }..  return;.}|
00001f40  0a 0a 76 6f 69 64 20 6c  6f 72 6e 61 5f 65 76 65  |..void lorna_eve|
00001f50  6e 74 5f 68 61 6e 64 6c  65 72 28 77 69 6d 70 5f  |nt_handler(wimp_|
00001f60  65 76 65 6e 74 73 74 72  20 2a 65 2c 20 76 6f 69  |eventstr *e, voi|
00001f70  64 20 2a 68 61 6e 64 6c  65 29 20 20 20 20 20 20  |d *handle)      |
00001f80  20 20 2f 2a 20 4f 6e 63  65 20 6f 75 72 20 77 69  |  /* Once our wi|
00001f90  6e 64 6f 77 20 69 73 20  63 72 65 61 74 65 64 20  |ndow is created |
00001fa0  74 68 69 73 20 66 6e 20  64 6f 65 73 20 2a 2f 0a  |this fn does */.|
00001fb0  7b 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |{               |
00001fc0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001ff0  2f 2a 20 61 6c 6c 20 74  68 65 20 68 61 72 64 20  |/* all the hard |
00002000  77 6f 72 6b 20 6f 66 20  6d 61 69 6e 74 61 69 6e  |work of maintain|
00002010  69 6e 67 20 69 74 2e 2a  2f 0a 20 20 77 69 6d 70  |ing it.*/.  wimp|
00002020  5f 77 73 74 61 74 65 20  73 3b 20 20 20 20 20 20  |_wstate s;      |
00002030  20 20 20 20 20 20 20 20  20 20 2f 2a 20 54 68 65  |          /* The|
00002040  20 27 6d 61 69 6e 27 20  66 75 6e 63 74 69 6f 6e  | 'main' function|
00002050  20 72 65 70 65 61 74 65  64 6c 79 20 63 61 6c 6c  | repeatedly call|
00002060  73 20 65 76 65 6e 74 5f  70 72 6f 63 65 73 73 2c  |s event_process,|
00002070  20 61 20 6c 69 62 72 61  72 79 20 66 6e 2c 20 26  | a library fn, &|
00002080  20 69 74 20 2a 2f 0a 20  20 69 6e 74 20 78 6f 2c  | it */.  int xo,|
00002090  20 79 6f 3b 20 20 20 20  20 20 20 20 20 20 20 20  | yo;            |
000020a0  20 20 20 20 20 20 20 2f  2a 20 70 6f 6c 6c 73 20  |       /* polls |
000020b0  74 68 65 20 77 69 6d 70  2e 20 57 68 65 6e 65 76  |the wimp. Whenev|
000020c0  65 72 20 69 74 20 67 65  74 73 20 61 6e 20 65 76  |er it gets an ev|
000020d0  65 6e 74 20 66 6f 72 20  6f 75 72 20 77 69 6e 64  |ent for our wind|
000020e0  6f 77 2c 20 69 74 20 63  61 6c 6c 73 20 74 68 69  |ow, it calls thi|
000020f0  73 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |s.              |
00002100  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002110  20 20 20 20 20 66 75 6e  63 74 69 6f 6e 2c 20 77  |     function, w|
00002120  68 69 63 68 20 6d 75 73  74 20 64 65 61 6c 20 77  |hich must deal w|
00002130  69 74 68 20 74 68 65 20  65 76 65 6e 74 20 61 70  |ith the event ap|
00002140  70 72 6f 70 72 69 61 74  65 6c 79 2e 20 2a 2f 0a  |propriately. */.|
00002150  20 20 68 61 6e 64 6c 65  20 3d 20 68 61 6e 64 6c  |  handle = handl|
00002160  65 3b 20 20 20 20 20 20  2f 2a 20 28 77 65 20 64  |e;      /* (we d|
00002170  6f 6e 27 74 20 6e 65 65  64 20 68 61 6e 64 6c 65  |on't need handle|
00002180  3a 20 74 68 69 73 20 73  74 6f 70 73 20 63 6f 6d  |: this stops com|
00002190  70 69 6c 65 72 20 77 61  72 6e 69 6e 67 29 20 2a  |piler warning) *|
000021a0  2f 0a 0a 20 20 73 77 69  74 63 68 20 28 65 2d 3e  |/..  switch (e->|
000021b0  65 29 0a 20 20 7b 0a 20  20 20 20 63 61 73 65 20  |e).  {.    case |
000021c0  77 69 6d 70 5f 45 42 55  54 3a 0a 20 20 20 20 20  |wimp_EBUT:.     |
000021d0  20 73 77 69 74 63 68 20  28 65 2d 3e 64 61 74 61  | switch (e->data|
000021e0  2e 62 75 74 2e 6d 2e 69  29 0a 20 20 20 20 20 20  |.but.m.i).      |
000021f0  7b 0a 20 20 20 20 20 20  20 20 63 61 73 65 20 57  |{.        case W|
00002200  49 4e 44 4f 57 3a 20 20  20 20 2f 2a 20 47 6f 74  |INDOW:    /* Got|
00002210  20 61 20 63 6c 69 63 6b  20 6f 6e 20 74 68 65 20  | a click on the |
00002220  77 69 6e 64 6f 77 20 6f  72 20 74 68 65 20 74 65  |window or the te|
00002230  78 74 20 6c 65 67 65 6e  64 2c 20 73 6f 20 74 72  |xt legend, so tr|
00002240  79 20 74 6f 20 61 64 64  20 61 6e 6f 74 68 65 72  |y to add another|
00002250  20 6f 62 6a 65 63 74 2e  20 2a 2f 0a 20 20 20 20  | object. */.    |
00002260  20 20 20 20 63 61 73 65  20 49 4e 46 4f 3a 0a 20  |    case INFO:. |
00002270  20 20 20 20 20 20 20 20  20 69 66 20 28 6e 75 6d  |         if (num|
00002280  5f 6f 62 6a 65 63 74 73  3c 4d 41 58 4e 55 4d 4f  |_objects<MAXNUMO|
00002290  42 4a 45 43 54 53 29 20  7b 0a 20 20 20 20 20 20  |BJECTS) {.      |
000022a0  20 20 20 20 20 20 69 66  20 28 65 2d 3e 64 61 74  |      if (e->dat|
000022b0  61 2e 62 75 74 2e 6d 2e  62 62 69 74 73 26 28 77  |a.but.m.bbits&(w|
000022c0  69 6d 70 5f 42 52 49 47  48 54 7c 77 69 6d 70 5f  |imp_BRIGHT|wimp_|
000022d0  42 4c 45 46 54 29 29 20  7b 0a 20 20 20 20 20 20  |BLEFT)) {.      |
000022e0  20 20 20 20 20 20 20 20  77 69 6d 70 74 5f 63 6f  |        wimpt_co|
000022f0  6d 70 6c 61 69 6e 28 77  69 6d 70 5f 67 65 74 5f  |mplain(wimp_get_|
00002300  77 69 6e 64 5f 73 74 61  74 65 28 6c 6f 72 6e 61  |wind_state(lorna|
00002310  2c 20 26 73 29 29 3b 0a  20 20 20 20 20 20 20 20  |, &s));.        |
00002320  20 20 20 20 20 20 78 6f  20 3d 20 73 2e 6f 2e 78  |      xo = s.o.x|
00002330  20 2d 20 73 2e 6f 2e 62  6f 78 2e 78 30 3b 20 20  | - s.o.box.x0;  |
00002340  2f 2a 20 78 6f 2c 79 6f  20 61 72 65 20 77 6f 72  |/* xo,yo are wor|
00002350  6b 20 61 72 65 61 20 63  6f 6f 72 64 73 20 6f 66  |k area coords of|
00002360  20 73 63 72 65 65 6e 20  6f 72 69 67 69 6e 2e 20  | screen origin. |
00002370  2a 2f 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |*/.             |
00002380  20 79 6f 20 3d 20 73 2e  6f 2e 79 20 2d 20 73 2e  | yo = s.o.y - s.|
00002390  6f 2e 62 6f 78 2e 79 31  3b 0a 20 20 20 20 20 20  |o.box.y1;.      |
000023a0  20 20 20 20 20 20 20 20  6f 62 6a 65 63 74 73 5b  |        objects[|
000023b0  6e 75 6d 5f 6f 62 6a 65  63 74 73 5d 2e 78 20 3d  |num_objects].x =|
000023c0  20 65 2d 3e 64 61 74 61  2e 62 75 74 2e 6d 2e 78  | e->data.but.m.x|
000023d0  20 2b 20 78 6f 3b 20 20  20 20 2f 2a 20 53 65 74  | + xo;    /* Set|
000023e0  20 6f 62 6a 65 63 74 20  63 65 6e 74 72 65 20 74  | object centre t|
000023f0  6f 20 6c 6f 63 61 74 69  6f 6e 20 6f 66 20 70 74  |o location of pt|
00002400  72 2c 20 2a 2f 0a 20 20  20 20 20 20 20 20 20 20  |r, */.          |
00002410  20 20 20 20 6f 62 6a 65  63 74 73 5b 6e 75 6d 5f  |    objects[num_|
00002420  6f 62 6a 65 63 74 73 5d  2e 79 20 3d 20 65 2d 3e  |objects].y = e->|
00002430  64 61 74 61 2e 62 75 74  2e 6d 2e 79 20 2b 20 79  |data.but.m.y + y|
00002440  6f 3b 20 20 20 20 2f 2a  20 61 66 74 65 72 20 63  |o;    /* after c|
00002450  6f 6e 76 65 72 74 69 6e  67 20 74 6f 20 77 6f 72  |onverting to wor|
00002460  6b 20 61 72 65 61 20 63  6f 6f 72 64 73 2e 20 2a  |k area coords. *|
00002470  2f 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |/.              |
00002480  6f 62 6a 65 63 74 73 5b  6e 75 6d 5f 6f 62 6a 65  |objects[num_obje|
00002490  63 74 73 5d 2e 74 79 70  65 20 3d 20 28 65 2d 3e  |cts].type = (e->|
000024a0  64 61 74 61 2e 62 75 74  2e 6d 2e 62 62 69 74 73  |data.but.m.bbits|
000024b0  20 26 20 77 69 6d 70 5f  42 4c 45 46 54 29 20 3f  | & wimp_BLEFT) ?|
000024c0  20 43 49 52 43 4c 45 20  3a 20 53 51 55 41 52 45  | CIRCLE : SQUARE|
000024d0  3b 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;.              |
000024e0  66 6f 72 63 65 5f 72 65  64 72 61 77 5f 6f 62 6a  |force_redraw_obj|
000024f0  65 63 74 28 6f 62 6a 65  63 74 73 2b 6e 75 6d 5f  |ect(objects+num_|
00002500  6f 62 6a 65 63 74 73 29  3b 20 20 20 20 20 20 20  |objects);       |
00002510  20 20 2f 2a 20 45 6e 73  75 72 65 20 72 65 67 69  |  /* Ensure regi|
00002520  6f 6e 20 63 6f 6e 74 61  69 6e 69 6e 67 20 6e 65  |on containing ne|
00002530  77 20 6f 62 6a 65 63 74  20 69 73 20 2a 2f 0a 20  |w object is */. |
00002540  20 20 20 20 20 20 20 20  20 20 20 20 20 6e 75 6d  |             num|
00002550  5f 6f 62 6a 65 63 74 73  2b 2b 3b 20 20 20 20 20  |_objects++;     |
00002560  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002570  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2f  |               /|
00002580  2a 20 72 65 64 72 61 77  6e 20 73 68 6f 72 74 6c  |* redrawn shortl|
00002590  79 2e 20 2a 2f 0a 20 20  20 20 20 20 20 20 20 20  |y. */.          |
000025a0  20 20 7d 0a 20 20 20 20  20 20 20 20 20 20 7d 0a  |  }.          }.|
000025b0  20 20 20 20 20 20 20 20  20 20 65 6c 73 65 20 77  |          else w|
000025c0  65 72 72 28 30 2c 20 22  54 6f 6f 20 6d 61 6e 79  |err(0, "Too many|
000025d0  20 6f 62 6a 65 63 74 73  20 61 6c 72 65 61 64 79  | objects already|
000025e0  21 20 54 72 79 20 63 6c  69 63 6b 69 6e 67 20 6f  |! Try clicking o|
000025f0  6e 20 27 43 6c 65 61 72  27 2e 22 29 3b 0a 20 20  |n 'Clear'.");.  |
00002600  20 20 20 20 20 20 20 20  62 72 65 61 6b 3b 0a 0a  |        break;..|
00002610  20 20 20 20 20 20 20 20  63 61 73 65 20 43 4c 45  |        case CLE|
00002620  41 52 3a 20 20 20 20 20  2f 2a 20 47 6f 74 20 61  |AR:     /* Got a|
00002630  20 63 6c 69 63 6b 20 6f  6e 20 74 68 65 20 27 43  | click on the 'C|
00002640  6c 65 61 72 27 20 69 63  6f 6e 2c 20 2a 2f 0a 20  |lear' icon, */. |
00002650  20 20 20 20 20 20 20 20  20 6e 75 6d 5f 6f 62 6a  |         num_obj|
00002660  65 63 74 73 20 3d 20 30  3b 0a 20 20 20 20 20 20  |ects = 0;.      |
00002670  20 20 20 20 66 6f 72 63  65 5f 72 65 64 72 61 77  |    force_redraw|
00002680  5f 61 6c 6c 28 29 3b 20  20 20 2f 2a 20 73 6f 20  |_all();   /* so |
00002690  72 65 73 65 74 20 6f 62  6a 65 63 74 73 20 26 20  |reset objects & |
000026a0  66 6f 72 63 65 20 72 65  64 72 61 77 20 6f 66 20  |force redraw of |
000026b0  77 69 6e 64 6f 77 2e 20  2a 2f 0a 20 20 20 20 20  |window. */.     |
000026c0  20 20 20 20 20 62 72 65  61 6b 3b 0a 20 20 20 20  |     break;.    |
000026d0  20 20 7d 0a 20 20 20 20  20 20 62 72 65 61 6b 3b  |  }.      break;|
000026e0  0a 0a 20 20 20 20 63 61  73 65 20 77 69 6d 70 5f  |..    case wimp_|
000026f0  45 52 45 44 52 41 57 3a  20 20 2f 2a 20 4d 75 73  |EREDRAW:  /* Mus|
00002700  74 20 72 65 64 72 61 77  20 70 61 72 74 20 6f 66  |t redraw part of|
00002710  20 6f 75 72 20 77 69 6e  64 6f 77 2c 20 73 6f 20  | our window, so |
00002720  63 61 6c 6c 20 61 70 70  72 6f 70 72 69 61 74 65  |call appropriate|
00002730  20 66 75 6e 63 74 69 6f  6e 20 74 6f 20 64 6f 20  | function to do |
00002740  74 68 69 73 2e 20 2a 2f  0a 20 20 20 20 20 20 69  |this. */.      i|
00002750  66 20 28 65 2d 3e 64 61  74 61 2e 6f 2e 77 20 21  |f (e->data.o.w !|
00002760  3d 20 6c 6f 72 6e 61 29  20 62 72 65 61 6b 3b 0a  |= lorna) break;.|
00002770  20 20 20 20 20 20 72 65  64 72 61 77 5f 77 69 6e  |      redraw_win|
00002780  64 6f 77 28 65 2d 3e 64  61 74 61 2e 6f 2e 77 29  |dow(e->data.o.w)|
00002790  3b 0a 20 20 20 20 20 20  62 72 65 61 6b 3b 0a 0a  |;.      break;..|
000027a0  20 20 20 20 63 61 73 65  20 77 69 6d 70 5f 45 4f  |    case wimp_EO|
000027b0  50 45 4e 3a 20 20 20 20  2f 2a 20 50 61 73 73 20  |PEN:    /* Pass |
000027c0  6f 6e 20 6f 70 65 6e 20  72 65 71 75 65 73 74 2e  |on open request.|
000027d0  20 2a 2f 0a 20 20 20 20  20 20 69 66 20 28 65 2d  | */.      if (e-|
000027e0  3e 64 61 74 61 2e 6f 2e  77 20 21 3d 20 6c 6f 72  |>data.o.w != lor|
000027f0  6e 61 29 20 62 72 65 61  6b 3b 0a 20 20 20 20 20  |na) break;.     |
00002800  20 77 69 6d 70 74 5f 63  6f 6d 70 6c 61 69 6e 28  | wimpt_complain(|
00002810  77 69 6d 70 5f 6f 70 65  6e 5f 77 69 6e 64 28 26  |wimp_open_wind(&|
00002820  65 2d 3e 64 61 74 61 2e  6f 29 29 3b 0a 20 20 20  |e->data.o));.   |
00002830  20 20 20 62 72 65 61 6b  3b 0a 0a 20 20 20 20 63  |   break;..    c|
00002840  61 73 65 20 77 69 6d 70  5f 45 43 4c 4f 53 45 3a  |ase wimp_ECLOSE:|
00002850  20 20 20 2f 2a 20 50 61  73 73 20 6f 6e 20 63 6c  |   /* Pass on cl|
00002860  6f 73 65 20 72 65 71 75  65 73 74 2e 20 2a 2f 0a  |ose request. */.|
00002870  20 20 20 20 20 20 69 66  20 28 65 2d 3e 64 61 74  |      if (e->dat|
00002880  61 2e 6f 2e 77 20 21 3d  20 6c 6f 72 6e 61 29 20  |a.o.w != lorna) |
00002890  62 72 65 61 6b 3b 0a 20  20 20 20 20 20 77 69 6d  |break;.      wim|
000028a0  70 74 5f 63 6f 6d 70 6c  61 69 6e 28 77 69 6d 70  |pt_complain(wimp|
000028b0  5f 63 6c 6f 73 65 5f 77  69 6e 64 28 65 2d 3e 64  |_close_wind(e->d|
000028c0  61 74 61 2e 6f 2e 77 29  29 3b 0a 20 20 20 20 20  |ata.o.w));.     |
000028d0  20 77 69 6e 5f 61 63 74  69 76 65 64 65 63 28 29  | win_activedec()|
000028e0  3b 20 20 2f 2a 20 57 65  20 6f 6e 6c 79 20 68 61  |;  /* We only ha|
000028f0  76 65 20 6f 6e 65 20 77  69 6e 64 6f 77 20 26 20  |ve one window & |
00002900  77 61 6e 74 20 69 74 73  20 63 6c 6f 73 75 72 65  |want its closure|
00002910  20 74 6f 20 71 75 69 74  20 6f 75 72 20 61 70 70  | to quit our app|
00002920  6c 69 63 61 74 69 6f 6e  2c 20 73 6f 20 77 65 20  |lication, so we |
00002930  74 65 6c 6c 20 20 2a 2f  0a 20 20 20 20 20 20 62  |tell  */.      b|
00002940  72 65 61 6b 3b 20 20 20  20 20 20 20 20 20 20 20  |reak;           |
00002950  20 2f 2a 20 6c 69 62 72  61 72 79 20 63 6f 64 65  | /* library code|
00002960  20 74 68 61 74 20 6f 75  72 20 6f 6e 6c 79 20 69  | that our only i|
00002970  6d 70 6f 72 74 61 6e 74  20 77 69 6e 64 6f 77 20  |mportant window |
00002980  68 61 73 20 63 6c 6f 73  65 64 20 26 20 77 68 65  |has closed & whe|
00002990  6e 20 77 65 20 6e 65 78  74 20 63 61 6c 6c 0a 20  |n we next call. |
000029a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000029b0  20 20 20 20 20 20 20 20  20 20 65 76 65 6e 74 5f  |          event_|
000029c0  70 72 6f 63 65 73 73 20  69 6e 20 6f 75 72 20 6d  |process in our m|
000029d0  61 69 6e 20 6c 6f 6f 70  20 69 74 20 77 69 6c 6c  |ain loop it will|
000029e0  20 74 65 72 6d 69 6e 61  74 65 20 6f 75 72 20 61  | terminate our a|
000029f0  70 70 6c 69 63 61 74 69  6f 6e 20 69 74 73 65 6c  |pplication itsel|
00002a00  66 2e 20 2a 2f 0a 0a 20  20 20 20 64 65 66 61 75  |f. */..    defau|
00002a10  6c 74 3a 20 20 20 20 20  20 20 20 20 20 20 20 2f  |lt:            /|
00002a20  2a 20 49 67 6e 6f 72 65  20 61 6e 79 20 6f 74 68  |* Ignore any oth|
00002a30  65 72 20 65 76 65 6e 74  2e 20 2a 2f 0a 20 20 20  |er event. */.   |
00002a40  20 20 20 62 72 65 61 6b  3b 0a 20 20 7d 0a 7d 0a  |   break;.  }.}.|
00002a50  0a 0a 42 4f 4f 4c 20 69  6e 69 74 69 61 6c 69 73  |..BOOL initialis|
00002a60  65 28 76 6f 69 64 29 0a  7b 0a 20 20 77 69 6d 70  |e(void).{.  wimp|
00002a70  5f 77 69 6e 64 20 2a 77  69 6e 64 6f 77 3b 20 20  |_wind *window;  |
00002a80  20 20 2f 2a 20 50 6f 69  6e 74 65 72 20 74 6f 20  |  /* Pointer to |
00002a90  77 69 6e 64 6f 77 20 64  65 66 69 6e 69 74 69 6f  |window definitio|
00002aa0  6e 2e 20 2a 2f 0a 20 20  77 69 6d 70 5f 77 73 74  |n. */.  wimp_wst|
00002ab0  61 74 65 20 73 3b 0a 0a  20 20 77 69 6d 70 74 5f  |ate s;..  wimpt_|
00002ac0  69 6e 69 74 28 22 4c 6f  72 6e 61 22 29 3b 20 20  |init("Lorna");  |
00002ad0  2f 2a 20 49 6e 69 74 69  61 6c 69 73 65 20 72 65  |/* Initialise re|
00002ae0  6c 65 76 61 6e 74 20 70  61 72 74 73 20 6f 66 20  |levant parts of |
00002af0  6c 69 62 72 61 72 79 2c  20 2a 2f 0a 20 20 72 65  |library, */.  re|
00002b00  73 5f 69 6e 69 74 28 22  4c 6f 72 6e 61 22 29 3b  |s_init("Lorna");|
00002b10  0a 20 20 74 65 6d 70 6c  61 74 65 5f 69 6e 69 74  |.  template_init|
00002b20  28 29 3b 20 20 20 20 20  20 2f 2a 20 69 6e 63 6c  |();      /* incl|
00002b30  75 64 69 6e 67 20 6c 6f  61 64 69 6e 67 20 6f 66  |uding loading of|
00002b40  20 6f 75 72 20 74 65 6d  70 6c 61 74 65 73 20 66  | our templates f|
00002b50  69 6c 65 2e 20 2a 2f 0a  0a 20 20 77 69 6e 64 6f  |ile. */..  windo|
00002b60  77 20 3d 20 74 65 6d 70  6c 61 74 65 5f 73 79 73  |w = template_sys|
00002b70  68 61 6e 64 6c 65 28 22  4c 6f 72 6e 61 22 29 3b  |handle("Lorna");|
00002b80  0a 20 20 69 66 20 28 77  69 6e 64 6f 77 20 3d 3d  |.  if (window ==|
00002b90  20 30 29 20 72 65 74 75  72 6e 20 46 41 4c 53 45  | 0) return FALSE|
00002ba0  3b 0a 20 20 69 66 20 28  77 69 6d 70 74 5f 63 6f  |;.  if (wimpt_co|
00002bb0  6d 70 6c 61 69 6e 28 77  69 6d 70 5f 63 72 65 61  |mplain(wimp_crea|
00002bc0  74 65 5f 77 69 6e 64 28  77 69 6e 64 6f 77 2c 20  |te_wind(window, |
00002bd0  26 6c 6f 72 6e 61 29 29  29 20 72 65 74 75 72 6e  |&lorna))) return|
00002be0  20 46 41 4c 53 45 3b 20  20 20 2f 2a 20 43 72 65  | FALSE;   /* Cre|
00002bf0  61 74 65 20 6f 75 72 20  6f 6e 65 20 26 20 6f 6e  |ate our one & on|
00002c00  6c 79 20 77 69 6e 64 6f  77 2c 20 2a 2f 0a 20 20  |ly window, */.  |
00002c10  77 69 6e 5f 72 65 67 69  73 74 65 72 5f 65 76 65  |win_register_eve|
00002c20  6e 74 5f 68 61 6e 64 6c  65 72 28 6c 6f 72 6e 61  |nt_handler(lorna|
00002c30  2c 20 6c 6f 72 6e 61 5f  65 76 65 6e 74 5f 68 61  |, lorna_event_ha|
00002c40  6e 64 6c 65 72 2c 20 30  29 3b 20 20 20 20 20 20  |ndler, 0);      |
00002c50  20 20 20 20 20 20 2f 2a  20 26 20 72 65 67 69 73  |      /* & regis|
00002c60  74 65 72 20 6f 75 72 20  65 76 65 6e 74 20 68 61  |ter our event ha|
00002c70  6e 64 6c 65 72 2e 20 2a  2f 0a 0a 20 20 69 66 20  |ndler. */..  if |
00002c80  28 77 69 6d 70 74 5f 63  6f 6d 70 6c 61 69 6e 28  |(wimpt_complain(|
00002c90  77 69 6d 70 5f 67 65 74  5f 77 69 6e 64 5f 73 74  |wimp_get_wind_st|
00002ca0  61 74 65 28 6c 6f 72 6e  61 2c 20 26 73 29 29 29  |ate(lorna, &s)))|
00002cb0  20 72 65 74 75 72 6e 20  46 41 4c 53 45 3b 0a 20  | return FALSE;. |
00002cc0  20 73 2e 6f 2e 62 65 68  69 6e 64 20 3d 20 2d 31  | s.o.behind = -1|
00002cd0  3b 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;               |
00002ce0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00002d00  20 20 20 20 20 20 20 2f  2a 20 28 74 6f 20 6f 70  |       /* (to op|
00002d10  65 6e 20 77 69 6e 64 6f  77 20 61 74 20 73 74 61  |en window at sta|
00002d20  63 6b 20 74 6f 70 29 2e  20 2a 2f 0a 20 20 69 66  |ck top). */.  if|
00002d30  20 28 77 69 6d 70 74 5f  63 6f 6d 70 6c 61 69 6e  | (wimpt_complain|
00002d40  28 77 69 6d 70 5f 6f 70  65 6e 5f 77 69 6e 64 28  |(wimp_open_wind(|
00002d50  26 73 2e 6f 29 29 29 20  72 65 74 75 72 6e 20 46  |&s.o))) return F|
00002d60  41 4c 53 45 3b 20 20 20  20 20 20 20 20 20 20 20  |ALSE;           |
00002d70  20 20 20 20 2f 2a 20 41  73 6b 20 66 6f 72 20 6f  |    /* Ask for o|
00002d80  75 72 20 77 69 6e 64 6f  77 20 74 6f 20 62 65 20  |ur window to be |
00002d90  6f 70 65 6e 65 64 2e 2a  2f 0a 20 20 77 69 6e 5f  |opened.*/.  win_|
00002da0  61 63 74 69 76 65 69 6e  63 28 29 3b 20 20 20 20  |activeinc();    |
00002db0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00002de0  20 20 2f 2a 20 54 65 6c  6c 20 6c 69 62 72 61 72  |  /* Tell librar|
00002df0  79 20 61 62 6f 75 74 20  6f 75 72 20 77 69 6e 64  |y about our wind|
00002e00  6f 77 2c 0a 20 20 20 20  20 20 20 20 20 20 20 20  |ow,.            |
00002e10  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002e20  20 20 20 20 73 6f 20 74  68 61 74 20 77 68 65 6e  |    so that when|
00002e30  20 77 65 20 63 61 6c 6c  20 65 76 65 6e 74 5f 70  | we call event_p|
00002e40  72 6f 63 65 73 73 20 69  6e 20 6d 61 69 6e 20 69  |rocess in main i|
00002e50  74 20 77 6f 6e 27 74 20  69 6d 6d 65 64 69 61 74  |t won't immediat|
00002e60  65 6c 79 20 71 75 69 74  21 0a 20 20 20 20 20 20  |ely quit!.      |
00002e70  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002e80  20 20 20 20 20 20 20 20  20 20 28 6e 62 20 74 68  |          (nb th|
00002e90  69 73 20 77 6f 75 6c 64  6e 27 74 20 62 65 20 6e  |is wouldn't be n|
00002ea0  65 65 64 65 64 20 69 66  20 77 65 20 70 75 74 20  |eeded if we put |
00002eb0  61 6e 20 69 63 6f 6e 20  6f 6e 20 74 68 65 20 69  |an icon on the i|
00002ec0  63 6f 6e 20 62 61 72 20  73 69 6e 63 65 20 74 68  |con bar since th|
00002ed0  65 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |e.              |
00002ee0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002ef0  20 20 20 6c 69 62 72 61  72 79 20 63 6f 64 65 20  |   library code |
00002f00  74 6f 20 64 6f 20 74 68  61 74 20 69 74 73 65 6c  |to do that itsel|
00002f10  66 20 63 61 6c 6c 73 20  77 69 6e 5f 61 63 74 69  |f calls win_acti|
00002f20  76 65 69 6e 63 29 2e 20  2a 2f 0a 0a 20 20 6f 62  |veinc). */..  ob|
00002f30  6a 65 63 74 73 20 3d 20  63 61 6c 6c 6f 63 28 4d  |jects = calloc(M|
00002f40  41 58 4e 55 4d 4f 42 4a  45 43 54 53 2c 20 73 69  |AXNUMOBJECTS, si|
00002f50  7a 65 6f 66 28 6f 62 6a  65 63 74 29 29 3b 20 2f  |zeof(object)); /|
00002f60  2a 20 52 65 73 65 72 76  65 20 73 6f 6d 65 20 73  |* Reserve some s|
00002f70  70 61 63 65 20 66 6f 72  20 75 70 74 6f 20 4d 41  |pace for upto MA|
00002f80  58 4e 55 4d 4f 42 4a 45  43 54 53 20 6f 62 6a 65  |XNUMOBJECTS obje|
00002f90  63 74 73 20 2a 2f 0a 20  20 69 66 20 28 6f 62 6a  |cts */.  if (obj|
00002fa0  65 63 74 73 20 3d 3d 20  30 29 20 72 65 74 75 72  |ects == 0) retur|
00002fb0  6e 20 46 41 4c 53 45 3b  0a 0a 20 20 72 65 74 75  |n FALSE;..  retu|
00002fc0  72 6e 20 54 52 55 45 3b  20 20 20 20 20 20 20 20  |rn TRUE;        |
00002fd0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00003000  20 20 2f 2a 20 41 6c 6c  20 6f 6b 61 79 2e 20 2a  |  /* All okay. *|
00003010  2f 0a 7d 0a 0a 69 6e 74  20 6d 61 69 6e 28 76 6f  |/.}..int main(vo|
00003020  69 64 29 20 20 20 20 20  20 20 20 20 20 2f 2a 20  |id)          /* |
00003030  4f 75 72 20 27 6d 61 69  6e 27 20 66 75 6e 63 74  |Our 'main' funct|
00003040  69 6f 6e 2c 20 65 6e 74  65 72 65 64 20 77 68 65  |ion, entered whe|
00003050  6e 20 61 70 70 6c 69 63  61 74 69 6f 6e 20 69 73  |n application is|
00003060  20 66 69 72 73 74 20 72  75 6e 2e 20 2a 2f 0a 7b  | first run. */.{|
00003070  0a 20 20 69 66 20 28 69  6e 69 74 69 61 6c 69 73  |.  if (initialis|
00003080  65 28 29 29 20 7b 20 20  20 2f 2a 20 43 61 6c 6c  |e()) {   /* Call|
00003090  20 69 6e 69 74 69 61 6c  69 73 65 20 66 75 6e 63  | initialise func|
000030a0  74 69 6f 6e 20 26 20 69  66 20 61 6e 79 74 68 69  |tion & if anythi|
000030b0  6e 67 20 67 6f 65 73 20  77 72 6f 6e 67 2c 20 71  |ng goes wrong, q|
000030c0  75 69 74 2c 20 6f 74 68  65 72 77 69 73 65 20 72  |uit, otherwise r|
000030d0  65 70 65 61 74 65 64 6c  79 20 2a 2f 0a 20 20 20  |epeatedly */.   |
000030e0  20 77 68 69 6c 65 20 28  54 52 55 45 29 20 65 76  | while (TRUE) ev|
000030f0  65 6e 74 5f 70 72 6f 63  65 73 73 28 29 3b 20 20  |ent_process();  |
00003100  20 20 20 20 20 2f 2a 20  63 61 6c 6c 20 65 76 65  |     /* call eve|
00003110  6e 74 5f 70 72 6f 63 65  73 73 20 77 68 69 63 68  |nt_process which|
00003120  20 70 6f 6c 6c 73 20 74  68 65 20 77 69 6d 70 20  | polls the wimp |
00003130  26 20 65 6e 74 65 72 73  20 6f 74 68 65 72 20 70  |& enters other p|
00003140  61 72 74 73 20 6f 66 20  2a 2f 0a 20 20 7d 20 20  |arts of */.  }  |
00003150  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00003170  20 20 20 2f 2a 20 6f 75  72 20 63 6f 64 65 20 76  |   /* our code v|
00003180  69 61 20 6f 75 72 20 77  69 6e 64 6f 77 27 73 20  |ia our window's |
00003190  65 76 65 6e 74 5f 68 61  6e 64 6c 65 72 2c 20 77  |event_handler, w|
000031a0  68 65 6e 20 6e 65 65 64  65 64 2e 20 2a 2f 0a 20  |hen needed. */. |
000031b0  20 72 65 74 75 72 6e 20  30 3b 0a 7d 20 20 20 20  | return 0;.}    |
000031c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000031d0  20 20 20 2f 2a 20 53 6f  6d 65 74 68 69 6e 67 20  |   /* Something |
000031e0  74 6f 20 6e 6f 74 65 3a  20 69 6e 69 74 69 61 6c  |to note: initial|
000031f0  69 73 65 20 6d 61 79 20  66 61 69 6c 20 61 66 74  |ise may fail aft|
00003200  65 72 20 72 65 67 69 73  74 65 72 69 6e 67 20 74  |er registering t|
00003210  68 65 20 61 70 70 6c 69  63 61 74 69 6f 6e 20 61  |he application a|
00003220  73 20 61 0a 20 20 20 20  20 20 20 20 20 20 20 20  |s a.            |
00003230  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 74  |               t|
00003240  61 73 6b 2c 20 69 6e 20  77 68 69 63 68 20 63 61  |ask, in which ca|
00003250  73 65 20 79 6f 75 20 6d  69 67 68 74 20 68 61 76  |se you might hav|
00003260  65 20 74 68 6f 75 67 68  74 20 77 65 20 63 6f 75  |e thought we cou|
00003270  6c 64 6e 27 74 20 73 69  6d 70 6c 79 20 65 78 69  |ldn't simply exi|
00003280  74 20 76 69 61 20 61 20  72 65 74 75 72 6e 0a 20  |t via a return. |
00003290  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000032a0  20 20 20 20 20 20 20 20  20 20 66 72 6f 6d 20 6d  |          from m|
000032b0  61 69 6e 20 61 73 20 77  65 20 66 69 72 73 74 20  |ain as we first |
000032c0  6e 65 65 64 20 74 6f 20  63 6c 6f 73 65 20 74 68  |need to close th|
000032d0  65 20 74 61 73 6b 20 64  6f 77 6e 2c 20 68 6f 77  |e task down, how|
000032e0  65 76 65 72 20 74 68 61  74 20 69 73 20 61 63 74  |ever that is act|
000032f0  75 61 6c 6c 79 20 73 74  69 6c 6c 0a 20 20 20 20  |ually still.    |
00003300  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003310  20 20 20 20 20 20 20 62  65 69 6e 67 20 64 6f 6e  |       being don|
00003320  65 21 20 54 68 65 20 6c  69 62 72 61 72 79 20 63  |e! The library c|
00003330  6f 64 65 20 77 68 69 63  68 20 73 65 74 73 20 75  |ode which sets u|
00003340  73 20 75 70 20 61 73 20  61 20 74 61 73 6b 20 72  |s up as a task r|
00003350  65 67 69 73 74 65 72 73  20 61 20 66 75 6e 63 74  |egisters a funct|
00003360  69 6f 6e 20 74 6f 0a 20  20 20 20 20 20 20 20 20  |ion to.         |
00003370  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003380  20 20 62 65 20 63 61 6c  6c 65 64 20 75 70 6f 6e  |  be called upon|
00003390  20 65 78 69 74 20 76 69  61 20 61 74 65 78 69 74  | exit via atexit|
000033a0  28 29 2e 20 41 66 74 65  72 20 77 65 20 63 61 6c  |(). After we cal|
000033b0  6c 20 72 65 74 75 72 6e  20 69 6e 20 6d 61 69 6e  |l return in main|
000033c0  2c 20 74 68 69 73 20 66  75 6e 63 74 69 6f 6e 20  |, this function |
000033d0  69 73 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |is.             |
000033e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 63 61  |              ca|
000033f0  6c 6c 65 64 20 26 20 69  74 20 64 65 61 6c 73 20  |lled & it deals |
00003400  77 69 74 68 20 74 68 65  20 74 69 64 79 69 6e 67  |with the tidying|
00003410  20 75 70 20 69 6e 63 6c  75 64 69 6e 67 20 63 6c  | up including cl|
00003420  6f 73 75 72 65 20 6f 66  20 6f 75 72 20 74 61 73  |osure of our tas|
00003430  6b 2e 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |k..             |
00003440  20 20 20 20 20 20 20 20  20 20 20 20 2a 2f 0a     |            */.|
0000344f