/*
    ####             #    #     # #
    #   #            #    #       #          The FreeWare C library for 
    #   #  ##   ###  #  # #     # ###             RISC OS machines
    #   # #  # #     # #  #     # #  #   ___________________________________
    #   # ####  ###  ##   #     # #  #                                      
    #   # #        # # #  #     # #  #    Please refer to the accompanying
    ####   ### ####  #  # ##### # ###    documentation for conditions of use
    ________________________________________________________________________

    File:    Handler.HtchRedraw.c
    Author:  Copyright  1993 Mark H. Wilkinson
    Version: 1.00 (28 Sept 1993)
    Purpose: Hatch the work area of a window. Useful when testing
             a program before you get round to writing your own redraw
             routines so you can see that something is happening.
*/


#include "Desk.WimpSWIS.h"
#include "Desk.GFX.h"
#include "Desk.Handler.h"

#define Desk_hatch_size 48

extern Desk_bool Desk_Handler_HatchRedraw(Desk_event_pollblock *event, void *reference)
{
  Desk_window_redrawblock redraw;
  Desk_bool more;
  int Desk_origin_x, Desk_origin_y;
  int xstart, height, xcorr, ycorr, x;

  Desk_UNUSED( reference);
  
  redraw.window = event->data.openblock.window;
  Desk_Wimp_eRedrawWindow(&redraw, &more);
  Desk_origin_x = redraw.rect.min.x - redraw.scroll.x;
  Desk_origin_y = redraw.rect.max.y - redraw.scroll.y;

  while (more)
  {
    height = redraw.cliprect.max.y - redraw.cliprect.min.y;
    xstart = redraw.cliprect.min.x - height;
    xcorr = (xstart - Desk_origin_x) % Desk_hatch_size;
    ycorr = (Desk_origin_y - redraw.cliprect.min.y) % Desk_hatch_size;
    for (x = xstart-xcorr-ycorr; x < redraw.cliprect.max.x; x += Desk_hatch_size) {
      Desk_GFX_Move(x, redraw.cliprect.min.y);
      Desk_GFX_DrawBy(height, height);
    }
    ycorr = (Desk_origin_y - redraw.cliprect.max.y) % Desk_hatch_size;
    for (x = xstart-xcorr+ycorr-Desk_hatch_size; x < redraw.cliprect.max.x; x += Desk_hatch_size) {
      Desk_GFX_Move(x, redraw.cliprect.max.y-1);
      Desk_GFX_DrawBy(height, -height);
    }

    Desk_Wimp_eGetRectangle(&redraw, &more);
  }

  return(Desk_bool_TRUE);
}
