swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: window error


From: Marcus G. Daniels
Subject: Re: window error
Date: 29 Mar 1998 17:25:39 -0800

>>>>> "D3" == Doug Donalson <address@hidden> writes:

D3> I have tracked down the error to the line of code that sets the
D3> X,Y coordinates of the ZoomRaster.  With all the 2-D displays
D3> commented out my sim runs (with the EZ graphs).  I added one
D3> ZoomRaster both with the standard call "world getXsize" and also
D3> with X and Y hard coded at (int) 11.  In both cases it comes up
D3> with the error.  When I comment the line out, the display appears
D3> but is empty.  

Thanks again for investigating this problem.
Here's a patch that should fix it.

Index: ChangeLog
===================================================================
RCS file: /opt/src/hive/cvs/Swarm/swarm/src/tkobjc/ChangeLog,v
retrieving revision 1.89
retrieving revision 1.91
diff -c -r1.89 -r1.91
*** ChangeLog   1998/03/20 07:06:03     1.89
--- ChangeLog   1998/03/30 01:00:11     1.91
***************
*** 1,3 ****
--- 1,29 ----
+ 1998-03-29  Marcus G. Daniels  <address@hidden>
+ 
+       * win32dib.c (dib_createBitmap): Round frameWidth up to 4.
+       (dib_blit, dib_paintBlit): Round down in case width + x exceeds
+       frameWidth.
+ 
+       * internal.m (tkobjc_raster_clear): New function.
+ 
+       * internal.h: Declare tkobjc_raster_clear.
+ 
+       * ZoomRaster.m ([ZoomRaster -_setConfigureInfo_:]): New method.
+       ([ZoomRaster -createEnd]): Call _setConfigureInfo_ for Configure
+       and Expose instead of just a (inline) Configure.
+       ([ZoomRaster -handleConfigureWidth:Height:]): Let newWidth exceed
+       newHeight (Win32 seems to like to think better of small window
+       widths).
+       ([ZoomRaster -handleExposeWidth:Height:]): New method.  Calls
+       tkobjc_raster_clear for new extent.
+ 
+       * ZoomRaster.h: Declare handleExposeWidth:Height:.
+ 
+       * Raster.m ([Raster +createBegin:]): Define default 
+       width and height in a createBegin, not createEnd.
+ 
+       * Raster.h: Declare createBegin and createEnd.
+ 
  1998-03-20  Marcus G. Daniels  <address@hidden>
  
        * TkExtra.m (ensureBltSupportFiles): Don't call getSwarmHome
Index: Raster.h
===================================================================
RCS file: /opt/src/hive/cvs/Swarm/swarm/src/tkobjc/Raster.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -c -r1.14 -r1.15
*** Raster.h    1998/03/18 01:46:11     1.14
--- Raster.h    1998/03/30 00:50:58     1.15
***************
*** 26,31 ****
--- 26,33 ----
    unsigned width, height;
  }
  
+ + createBegin: aZone;
+ - createEnd;
  - (id <Colormap>)getColormap;
  - setColormap: (id <Colormap>)colormap;
  - drawPointX: (int)x Y: (int)y Color: (Color)c;
Index: Raster.m
===================================================================
RCS file: /opt/src/hive/cvs/Swarm/swarm/src/tkobjc/Raster.m,v
retrieving revision 1.17
retrieving revision 1.18
diff -c -r1.17 -r1.18
*** Raster.m    1998/03/18 01:46:11     1.17
--- Raster.m    1998/03/30 00:50:58     1.18
***************
*** 17,29 ****
  
  @implementation Raster
  
  - createEnd
  {
    // initialize the superclass.
    [super createEnd];
  
-   // create a frame widget, set its height
-   width = 100U; height = 100U;
    // BMcM - 12-FEB-97: force widget to have *no* background;
    //   fixes problem with newer tcl/tk (7.5/4.1 up?) whereby raster
    //   was being erased, *after* our -drawself, on all <Expose>
--- 17,37 ----
  
  @implementation Raster
  
+ + createBegin: aZone
+ {
+   Raster *obj = [super createBegin: aZone];
+   
+   obj->width = 100U;
+   obj->height = 100U;
+ 
+   return obj;
+ }
+ 
  - createEnd
  {
    // initialize the superclass.
    [super createEnd];
  
    // BMcM - 12-FEB-97: force widget to have *no* background;
    //   fixes problem with newer tcl/tk (7.5/4.1 up?) whereby raster
    //   was being erased, *after* our -drawself, on all <Expose>
***************
*** 71,83 ****
    return self;
  }
  
! // set the width for the widget. We maintain our own values of this, to
  // avoid problems with Tk's caching.
  // For pixmap handling, we create a new pixmap, erase it, copy the old
  // one to it and redraw ourselves.
  - setWidth: (unsigned)newWidth Height: (unsigned)newHeight
  {
    Pixmap oldpm = pm;
    int oldWidth = width;
    int oldHeight = height;
  
--- 79,92 ----
    return self;
  }
  
! // Set the width for the widget. We maintain our own values of this, to
  // avoid problems with Tk's caching.
  // For pixmap handling, we create a new pixmap, erase it, copy the old
  // one to it and redraw ourselves.
  - setWidth: (unsigned)newWidth Height: (unsigned)newHeight
  {
    Pixmap oldpm = pm;
+ 
    int oldWidth = width;
    int oldHeight = height;
  
Index: ZoomRaster.h
===================================================================
RCS file: /opt/src/hive/cvs/Swarm/swarm/src/tkobjc/ZoomRaster.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -c -r1.5 -r1.6
*** ZoomRaster.h        1998/01/24 22:37:57     1.5
--- ZoomRaster.h        1998/03/30 00:50:59     1.6
***************
*** 19,23 ****
--- 19,24 ----
  - (unsigned)getZoomFactor;
  - setZoomFactor: (unsigned)z;
  - handleConfigureWidth: (unsigned)newWidth Height: (unsigned)newHeight;
+ - handleExposeWidth: (unsigned)newWidth Height: (unsigned)newHeight;
  
  @end
Index: ZoomRaster.m
===================================================================
RCS file: /opt/src/hive/cvs/Swarm/swarm/src/tkobjc/ZoomRaster.m,v
retrieving revision 1.11
retrieving revision 1.12
diff -c -r1.11 -r1.12
*** ZoomRaster.m        1998/03/18 01:46:11     1.11
--- ZoomRaster.m        1998/03/30 00:50:59     1.12
***************
*** 20,30 ****
    return logicalHeight;
  }
  
  - createEnd
  {
    [super createEnd];
!   // we do things to the parent widget that are really only allowed
!   // on toplevels. This check is at least friendly.
    if (!([parent isKindOfClassNamed: "Frame"]) && ([parent getParent] == 0))
      [WindowCreation 
        raiseEvent: 
--- 20,43 ----
    return logicalHeight;
  }
  
+ - _setConfigureInfo_ : (const char *)eventName
+ {
+   [globalTkInterp 
+     eval: 
+       "bind %s <%s> { %s handle%sWidth: %s Height: %s }",
+     [parent getWidgetName], 
+     eventName,
+     [self getObjcName],
+     eventName,
+     "%w", "%h"];
+   return self;
+ }
+ 
  - createEnd
  {
    [super createEnd];
!   // We do things to the parent widget that are really only allowed
!   // on toplevels.  This check is at least friendly.
    if (!([parent isKindOfClassNamed: "Frame"]) && ([parent getParent] == 0))
      [WindowCreation 
        raiseEvent: 
***************
*** 35,50 ****
    logicalHeight = height;
    zoomFactor = 1U;
  
!   [globalTkInterp 
!     eval: 
!       "bind %s <Configure> { %s handleConfigureWidth: %s Height: %s }",
!     [parent getWidgetName],
!     [self getObjcName],
!     "%w", "%h"];
    return self;
  }
  
- 
  - (unsigned)getZoomFactor
  {
    return zoomFactor;
--- 48,58 ----
    logicalHeight = height;
    zoomFactor = 1U;
  
!   [self _setConfigureInfo_: "Configure"];
!   [self _setConfigureInfo_: "Expose"];
    return self;
  }
  
  - (unsigned)getZoomFactor
  {
    return zoomFactor;
***************
*** 96,104 ****
  // note that they are passed to us in absolute values, not gridded.
  - handleConfigureWidth: (unsigned)newWidth Height: (unsigned)newHeight
  {
!   unsigned newZoom = newWidth / logicalWidth;
  
!   if (newZoom != newHeight / logicalHeight)
      [WindowUsage raiseEvent: "nonsquare zoom given.\n"];
  
  #ifdef DEBUG
--- 104,115 ----
  // note that they are passed to us in absolute values, not gridded.
  - handleConfigureWidth: (unsigned)newWidth Height: (unsigned)newHeight
  {
!   unsigned newZoom = newHeight / logicalHeight;
  
!   if (newWidth >  newHeight)
!     newWidth = newHeight;
! 
!   if (newZoom != newWidth / logicalWidth)
      [WindowUsage raiseEvent: "nonsquare zoom given.\n"];
  
  #ifdef DEBUG
***************
*** 106,118 ****
         [self getObjcName], zoomFactor, newZoom, newWidth, newHeight);
  #endif
    
!   // this check isn't just an optimization, it prevents an infinite
    // recursion: [self setZoomFactor] reconfigures the widget, which in turn
    // generates a configure event.
    if (newZoom != zoomFactor)
      [self setZoomFactor: newZoom];
    return self;
  }
    
  // override setWidth to set it for them according to zoom factor.
  - setWidth: (unsigned)newWidth Height: (unsigned)newHeight
--- 117,136 ----
         [self getObjcName], zoomFactor, newZoom, newWidth, newHeight);
  #endif
    
!   // This check isn't just an optimization, it prevents an infinite
    // recursion: [self setZoomFactor] reconfigures the widget, which in turn
    // generates a configure event.
    if (newZoom != zoomFactor)
      [self setZoomFactor: newZoom];
    return self;
  }
+ 
+ - handleExposeWidth: (unsigned)newWidth Height: (unsigned)newHeight
+ {
+   if (newWidth > width || newHeight > height)
+     tkobjc_raster_clear (self, width, height);
+   return self;
+ }
    
  // override setWidth to set it for them according to zoom factor.
  - setWidth: (unsigned)newWidth Height: (unsigned)newHeight
***************
*** 122,133 ****
  
    [super setWidth: newWidth * zoomFactor Height: newHeight * zoomFactor];
  
!   // set up gridded geometry so this is resizeable. Only works if
    // the parent is a toplevel.
    [globalTkInterp eval: "wm grid %s %u %u %u %u; wm aspect %s 1 1 1 1",
                  [parent getWidgetName],  zoomFactor, zoomFactor,
                  logicalWidth, logicalHeight, [parent getWidgetName]];
- 
    return self;
  }
  
--- 140,150 ----
  
    [super setWidth: newWidth * zoomFactor Height: newHeight * zoomFactor];
  
!   // Set up gridded geometry so this is resizeable. Only works if
    // the parent is a toplevel.
    [globalTkInterp eval: "wm grid %s %u %u %u %u; wm aspect %s 1 1 1 1",
                  [parent getWidgetName],  zoomFactor, zoomFactor,
                  logicalWidth, logicalHeight, [parent getWidgetName]];
    return self;
  }
  
***************
*** 135,141 ****
  - drawPointX: (int)x Y: (int)y Color: (Color)c
  {
    [super fillRectangleX0: x * zoomFactor Y0: y * zoomFactor
!          X1: (x+1) * zoomFactor Y1: (y+1) * zoomFactor
         Color: c];
  
    return self;
--- 152,158 ----
  - drawPointX: (int)x Y: (int)y Color: (Color)c
  {
    [super fillRectangleX0: x * zoomFactor Y0: y * zoomFactor
!          X1: (x + 1) * zoomFactor Y1: (y + 1) * zoomFactor
         Color: c];
  
    return self;
***************
*** 144,150 ****
  - fillRectangleX0: (int)x0 Y0: (int)y0 X1: (int)x1 Y1: (int)y1 Color: (Color)c
  {
    [super fillRectangleX0: x0 * zoomFactor Y0: y0 * zoomFactor
!          X1: (x1) * zoomFactor Y1: (y1) * zoomFactor
         Color: c];
  
    return self;
--- 161,167 ----
  - fillRectangleX0: (int)x0 Y0: (int)y0 X1: (int)x1 Y1: (int)y1 Color: (Color)c
  {
    [super fillRectangleX0: x0 * zoomFactor Y0: y0 * zoomFactor
!          X1: x1 * zoomFactor Y1: y1 * zoomFactor
         Color: c];
  
    return self;
Index: internal.h
===================================================================
RCS file: /opt/src/hive/cvs/Swarm/swarm/src/tkobjc/internal.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -c -r1.8 -r1.9
*** internal.h  1998/03/13 20:03:30     1.8
--- internal.h  1998/03/30 00:50:59     1.9
***************
*** 30,35 ****
--- 30,36 ----
  void tkobjc_deleteEventHandler (id widget, Tk_EventProc proc);
  
  void tkobjc_raster_erase (Raster *raster);
+ void tkobjc_raster_clear (Raster *raster, unsigned oldWidth, unsigned 
oldHeight);
  void tkobjc_raster_setColormap (Raster *raster);
  
  void tkobjc_raster_fillRectangle (Raster *raster,
Index: internal.m
===================================================================
RCS file: /opt/src/hive/cvs/Swarm/swarm/src/tkobjc/internal.m,v
retrieving revision 1.17
retrieving revision 1.19
diff -c -r1.17 -r1.19
*** internal.m  1998/03/18 23:16:21     1.17
--- internal.m  1998/03/30 01:20:43     1.19
***************
*** 111,116 ****
--- 111,117 ----
    Tk_DeleteEventHandler (tkwin, StructureNotifyMask, proc, widget);
  }
  
+ 
  static void
  Xfill (Display *display, GC gc, Pixmap pm,
         int x, int y,
***************
*** 244,249 ****
--- 245,251 ----
    dib_t *dib = dib_create ();
    
    raster->pm = (Pixmap)dib;
+ 
    dib_createBitmap (dib, TkWinGetHWND (Tk_WindowId (tkwin)),
                    raster->width, raster->height);
    tkobjc_raster_setColormap (raster);
***************
*** 279,284 ****
--- 281,333 ----
  }
  
  void
+ tkobjc_raster_clear (Raster *raster, unsigned oldWidth, unsigned oldHeight)
+ {
+ #ifdef _WIN32
+   Tk_Window tkwin = raster->tkwin;
+   Display *display = Tk_Display (tkwin);
+   Window w = Tk_WindowId (tkwin);
+   HPALETTE oldPalette, palette;
+   HBRUSH brush;
+   HWND hwnd = TkWinGetHWND (w);
+   RECT rc;
+   HDC dc = GetDC (hwnd);
+   TkWindow *winPtr;
+   unsigned newWidth;
+   unsigned newHeight;
+ 
+   palette = TkWinGetPalette (display->screens[0].cmap);
+   oldPalette = SelectPalette (dc, palette, FALSE);
+ 
+   winPtr = TkWinGetWinPtr (w);
+   brush = CreateSolidBrush (winPtr->atts.background_pixel);
+   GetWindowRect (hwnd, &rc);
+   newWidth = rc.right - rc.left;
+   newHeight = rc.bottom - rc.top;
+ 
+   if (newWidth > oldWidth)
+     {
+       rc.right = newWidth;
+       rc.left = oldWidth;
+       rc.bottom = rc.bottom - rc.top;
+       rc.top = 0;
+       FillRect (dc, &rc, brush);
+     }
+   if (newHeight > oldHeight)
+     {
+       rc.right = oldWidth;
+       rc.left = 0;
+       rc.bottom = newHeight;
+       rc.top = oldHeight;
+       FillRect (dc, &rc, brush);
+     }
+   DeleteObject (brush);
+   SelectPalette (dc, oldPalette, TRUE);
+   ReleaseDC (hwnd, dc);
+ #endif
+ }
+ 
+ void
  tkobjc_raster_copy (Raster *raster, Pixmap oldpm,
                      unsigned oldWidth, unsigned oldHeight)
  {
***************
*** 295,298 ****
      abort ();
  #endif
  }
- 
--- 344,346 ----
Index: win32dib.c
===================================================================
RCS file: /opt/src/hive/cvs/Swarm/swarm/src/tkobjc/win32dib.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -c -r1.3 -r1.4
*** win32dib.c  1998/03/15 22:10:45     1.3
--- win32dib.c  1998/03/30 01:00:12     1.4
***************
*** 66,71 ****
--- 66,74 ----
    HDC hdc = GetDC (window);
    dib->window = window;
  
+   if (width & 3)
+     width += 4 - (width & 3);
+ 
    if (dib->bitmap)
      {
        xfree (dib->dibInfo);
***************
*** 153,159 ****
    if (dib->bitmap)
      {
        BOOL result;
!       
        SelectPalette (dib->destDC, dib->palette, FALSE);
        RealizePalette (dib->destDC);
        result = BitBlt (dib->destDC,
--- 156,166 ----
    if (dib->bitmap)
      {
        BOOL result;
!       int diff = destX + sourceWidth - dib->dibInfo->bmiHead.biWidth;
! 
!       if (diff > 0)
!       sourceWidth -= diff;
! 
        SelectPalette (dib->destDC, dib->palette, FALSE);
        RealizePalette (dib->destDC);
        result = BitBlt (dib->destDC,
***************
*** 177,188 ****
    int frameWidth = dib->dibInfo->bmiHead.biWidth;
    BYTE *base;
    int yoff;
  
!   /* GDI raster lines are even length. */
!   if (frameWidth & 1)
!     frameWidth++;
  
    base = (BYTE *)dib->bits + (y * frameWidth);
    for (yoff = 0; yoff < height; yoff++)
      {
        int xoff;
--- 184,198 ----
    int frameWidth = dib->dibInfo->bmiHead.biWidth;
    BYTE *base;
    int yoff;
+   int diff;
+ 
+   diff = x + width - frameWidth;
  
!   if (diff > 0)
!     width -= diff;
  
    base = (BYTE *)dib->bits + (y * frameWidth);
+ 
    for (yoff = 0; yoff < height; yoff++)
      {
        int xoff;
***************
*** 200,208 ****
               int sourceX, int sourceY,
               int sourceWidth, int sourceHeight)
  {
    if (dib->bitmap == NULL)
      return FALSE;
!   
    GdiFlush ();
  
    {
--- 210,226 ----
               int sourceX, int sourceY,
               int sourceWidth, int sourceHeight)
  {
+   int frameWidth = dib->dibInfo->bmiHead.biWidth;
+   int diff;
+ 
+   diff = (destX + sourceWidth) - frameWidth;
+ 
+   if (diff > 0)
+     sourceWidth -= diff;
+ 
    if (dib->bitmap == NULL)
      return FALSE;
! 
    GdiFlush ();
  
    {

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]