
/*
 * Find the background colour pallette entry for a given window
 */
static os_colour pallette_colour(wimp_colour wcol)
{
   enum {palette_entries=20};
   os_PALETTE(palette_entries) screenpalette;
   os_colour pal_entry;

   (void) xwimp_read_palette((os_palette *) &screenpalette);

   /* Mask out the lower byte which holds Tint info (AND NOT &ff) */
   pal_entry = screenpalette.entries[wcol] &(~0xff);
   /* Double-up the nibles */
   pal_entry |= pal_entry >> 4;

   return pal_entry;
}


/* Redraw handler for the main window */
static osbool redraw_window( wimp_event_no event_code,
                              wimp_block *block,
                              toolbox_block *id_block,
                              void *handle )
{
   wimp_draw redraw;
   int more;
   font_f font1;
   os_colour col_back, col_front;   /* Colours for the font plotting */
   int size1 = 36 << 4; /* size in 1/16th points */
   int origin_x, origin_y; /* screen location of work area origin */
   int x,y;    /* Coordinates to plot at */
   wimp_window_info winfo;

   NOT_USED(event_code);
   NOT_USED(id_block);
   NOT_USED(handle);

   /* Load the font */
   (void) xfont_find_font( "Crown.Script", size1, size1, 0, 0,
                           &font1, NULL, NULL );

   /* Set the background colour for the text to the window background */
   winfo.w = block->redraw.w;
   (void) xwimp_get_window_info_header_only(&winfo);
   col_back = pallette_colour(winfo.work_bg);

   /* Choose the text foreground colour */
   col_front = os_COLOUR_GREEN;

   /* Initialise the redraw block with the handle of this window */
   redraw.w = block->redraw.w;

   /* Redraw loop */
   (void) xwimp_redraw_window(&redraw, &more);

   /* Calculate location of work area origin in screen coordinates */
   origin_x = redraw.box.x0 - redraw.xscroll;
   origin_y = redraw.box.y1 - redraw.yscroll;

   while(more) {
      /* For some obscure reason the colour must be set inside the loop */
      (void) xcolourtrans_set_font_colours( font1, col_back, col_front, 14,
                                    NULL, NULL, NULL );

      /* Calculate pos from work area origin */
      x = origin_x + 64;
      y = origin_y - 200;
      (void) xfont_paint( font1, "Stuck to the document, follows scroll",
                  font_OS_UNITS | font_GIVEN_FONT | font_KERN,
                  x, y, NULL, NULL, 0 );

      (void) xwimp_get_rectangle(&redraw, &more);
   }

   (void) xfont_lose_font(font1);

   return 1; /* Indicate that the event was handled by this routine */
}

