www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/06/21/11:09:34

Date: Mon, 21 Jun 93 14:20:29 GMT
From: Joe Clark <joe AT ziggy DOT larc DOT nasa DOT gov>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Save/Restore screen area - CORRECTION

jakobs AT utrurt DOT uni-trier DOT de (Oliver Jakobs) pointed out that I left out
a line of code from my previous example.  I created the savedimage
context but never filled it with anything.  Here's the corrected
version:


/*  I made savedimage a global so that it could be saved or restored
    anytime throughout the program  */

Grcontext *savedimage;

void save_backgrnd(void)
{
  int imagesizex, imagesizey;
  
  /*  The right, left, top and bottom coordinates can be any part or
      all of the current context (which in my case the current context
      was the screen  */
				  
  imagesizex = rightx - leftx;
  imagesizey = bottomy - topy;
				  
  /*  Create the memory location (a "context") to hold the image,
      the last two NULL pointers just tell the library to use
      it's own memory allocation instead of one you provide  */
			  
  savedimage = GrCreateContext(imagesizex, imagesizey, NULL, NULL);
  
  /*  ADDED LINES  */
  /*    Save the desired screen area to the savedimage context  */

  GrBitBlt(savedimage, 0, 0, NULL, leftx, topy, rightx, bottomy, GrWRITE);


}
  
  
void restore_backgrnd(void)
{
      
  int imagesizex, imagesizey;

  /*  leftx, rightx, topy, bottomy are globals that are unchanged
      since save_backgrnd() was called  */
      
  imagesizex = rightx - leftx;
  imagesizey = bottomy - topy;
      
  /*   Restore the area in memory to a context.  If NULL is entered
       as the context then it is drawn to the screen.  Remember
       that 0, 0 for x,y in savedimage is leftx, topy in screen
       coordinates  */
      
  GrBitBlt(NULL, leftx, topy, savedimage, 0, 0, imagesizex, imagesizey,
           GrWRITE);
      
  GrDestroyContext(savedimage);
      
}


***********************************************************************
* Joe Clark                     |  Internet : joe AT ziggy DOT larc DOT nasa DOT gov *
* NASA Langley Research Center  |                                     *
* MS 152E                       |  Phone : 804-864-6655               *
* Hampton, VA 23665             |  FAX  : 804-864-7793                *
***********************************************************************


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019