home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Core / source / gworld.cp < prev    next >
Encoding:
Text File  |  1995-03-19  |  5.5 KB  |  90 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    gworld.cp
  3. //    Date:                    8/23/94
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains the methods of the gworld widget class.
  7. //
  8. //------------------------------------------------------------------------------
  9.  
  10. #include     "gworld.h"
  11.  
  12. //------------------------------------------------------------------------------
  13. //    constructor
  14. //------------------------------------------------------------------------------
  15. gworld::gworld (window *w) : widget ()                                                                                    //    constructor
  16. {                                                                                                                                                                //    begin
  17.     Rect    junk = {0, 0, 10, 10};                                                                                                    //    any normal, valid rectangle to start out
  18.     NewGWorld (&world, 0, &junk, 0, 0, 0);                                                                                //    create the gworld
  19.     owner = w->Port ();                                                                                                                        //    get the port that we will be copying this to
  20. }                                                                                                                                                                //    end
  21.  
  22. //------------------------------------------------------------------------------
  23. //    destructor
  24. //------------------------------------------------------------------------------
  25. gworld::~gworld (void)                                                                                                                    //    destructor
  26. {                                                                                                                                                                //    begin
  27.     DisposeGWorld (world);                                                                                                                //    finished with the gworld
  28. }                                                                                                                                                                //    end
  29.  
  30. //------------------------------------------------------------------------------
  31. //    Set the cursor to what is appropriate for the gworld
  32. //------------------------------------------------------------------------------
  33. void    gworld::SetCursor (void)                                                                                                    //    method to set the cursor to the correct shape
  34. {                                                                                                                                                                //    begin
  35.     ::SetCursor (*(GetCursor (crossCursor)));                                                                            //    set the cursor to a plus
  36. }                                                                                                                                                                //    end
  37.  
  38. //------------------------------------------------------------------------------
  39. //    resize the gworld and all the children accordingly
  40. //------------------------------------------------------------------------------
  41. void    gworld::Resize (EventRecord &event)                                                                                //    method to recompute sizing information from parent
  42. {                                                                                                                                                                //    begin
  43.     Rect    rect = (*(parent->region))->rgnBBox;                                                                        //    temporary to simplify code
  44.     InsetRect (&rect, 1, 1);                                                                                                            //    inset the rect just a bit, to make room for the frame
  45.     RectRgn (region, &rect);                                                                                                            //    adjust the widget region
  46.     rect.right -= rect.left; rect.bottom -= rect.top;                                                            //    subtractions to make the rectangle zero based
  47.     rect.left = 0; rect.top = 0;                                                                                                    //    set the zero values
  48.     UpdateGWorld (&world, 0, &rect, 0, 0, 0);                                                                            //    update the gworld buffers
  49.     pixmap = GetGWorldPixMap (world);                                                                                            //    get a fresh copy of the pixel map handle, since memory may have moved
  50.     widget::Resize (event);                                                                                                                //    default behavior
  51. }                                                                                                                                                                //    end
  52.  
  53. //------------------------------------------------------------------------------
  54. //    draw the gworld
  55. //------------------------------------------------------------------------------
  56. void        gworld::StartDrawing (gw_erase e)                                                                                //    lock down the gworld and set the port appropriately
  57. {                                                                                                                                                                //    begin
  58.     LockPixels (pixmap);                                                                                                                    //    make sure memory won't move
  59.     GetGWorld (&curport, &curworld);                                                                                            //    store the current drawing environment parameters
  60.     SetGWorld ((CGrafPtr) world, 0);                                                                                            //    make the gworld buffer the current drawing environment
  61.     if (e)                                                                                                                                                //    if the user wants a clean page
  62.         EraseRect (&world->portRect);                                                                                                //    erase the buffer
  63. }                                                                                                                                                                //    end
  64.  
  65. //------------------------------------------------------------------------------
  66. //    draw the gworld
  67. //------------------------------------------------------------------------------
  68. void        gworld::StopDrawing (gw_update u)                                                                                //    unlock the gworld and reset the port
  69. {                                                                                                                                                                //    begin
  70.     SetGWorld (curport, curworld);                                                                                                //    restore the original drawing environment
  71.     if (u)                                                                                                                                                //    if the user wants to see the results immediately
  72.         CopyBits ((BitMap *) *pixmap, &owner->portBits, &world->portRect, &(*region)->rgnBBox, srcCopy, 0);
  73.     UnlockPixels (pixmap);                                                                                                                //    let the memory move again
  74. }                                                                                                                                                                //    end
  75.  
  76. //------------------------------------------------------------------------------
  77. //    draw the gworld
  78. //------------------------------------------------------------------------------
  79. void    gworld::Draw (void)                                                                                                                //    method to draw the gworld
  80. {                                                                                                                                                                //    begin
  81.     LockPixels (pixmap);                                                                                                                    //    make sure that memory doesn't move
  82.     CopyBits ((BitMap *) *pixmap, &owner->portBits, &world->portRect, &(*region)->rgnBBox, srcCopy, 0);
  83.     UnlockPixels (pixmap);                                                                                                                //    memory can move now
  84.     Rect    rect = (*region)->rgnBBox;                                                                                            //    copy the bounding rect
  85.     InsetRect (&rect, -1, -1);                                                                                                        //    expand it by one pixel
  86.     FrameRect (&rect);                                                                                                                        //    frame it
  87. }                                                                                                                                                                //    end
  88.  
  89. //------------------------------------------------------------------------------
  90.