[dasher] Clarify+standardize meaning/ordering of coordinates for DasherDrawRectangle



commit a4e866a1b5353d6b154ed205759dc359bff98f6d
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Sat Oct 16 22:25:44 2010 +0100

    Clarify+standardize meaning/ordering of coordinates for DasherDrawRectangle
    
    Inc its many calls - fixing occassional bug in DisjointRender where entire
     screen would become the colour of a single node.

 Src/DasherCore/DasherView.cpp       |   12 +++++++++---
 Src/DasherCore/DasherView.h         |    2 +-
 Src/DasherCore/DasherViewSquare.cpp |   21 +++++++++++----------
 3 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/Src/DasherCore/DasherView.cpp b/Src/DasherCore/DasherView.cpp
index 6b5540e..cc5e271 100644
--- a/Src/DasherCore/DasherView.cpp
+++ b/Src/DasherCore/DasherView.cpp
@@ -184,14 +184,20 @@ void CDasherView::DasherPolyarrow(myint *x, myint *y, int n, int iWidth, int iCo
 
 // Draw a box specified in Dasher co-ordinates
 
-void CDasherView::DasherDrawRectangle(myint iLeft, myint iTop, myint iRight, myint iBottom, const int Color, int iOutlineColour, int iThickness) {
+void CDasherView::DasherDrawRectangle(myint iDasherMaxX, myint iDasherMinY, myint iDasherMinX, myint iDasherMaxY, const int Color, int iOutlineColour, int iThickness) {
+  //This assertion is more aggressive than necessary (Dasher has been working
+  // in many cases where it would fail, with only occassional display glitches)
+  // so if it causes trouble, it should be safe to remove...
+  DASHER_ASSERT(iDasherMinX <= iDasherMaxX && iDasherMinY <= iDasherMaxY);
+  //TODO Parameter names correspond to the values passed in,
+  // but the below will only match up with screen coords for LR orientation...
   screenint iScreenLeft;
   screenint iScreenTop;
   screenint iScreenRight;
   screenint iScreenBottom;
 
-  Dasher2Screen(iLeft, iTop, iScreenLeft, iScreenTop);
-  Dasher2Screen(iRight, iBottom, iScreenRight, iScreenBottom);
+  Dasher2Screen(iDasherMaxX, iDasherMinY, iScreenLeft, iScreenTop);
+  Dasher2Screen(iDasherMinX, iDasherMaxY, iScreenRight, iScreenBottom);
 
   Screen()->DrawRectangle(iScreenLeft, iScreenTop, iScreenRight, iScreenBottom, Color, iOutlineColour, iThickness);
 }
diff --git a/Src/DasherCore/DasherView.h b/Src/DasherCore/DasherView.h
index 9a25807..291493c 100644
--- a/Src/DasherCore/DasherView.h
+++ b/Src/DasherCore/DasherView.h
@@ -148,7 +148,7 @@ public:
   /// \param iOutlineColor colour in which to draw outline, -1 => use default
   /// \param iThickness line width for outline, < 1 => no outline.
   ///
-  void DasherDrawRectangle(myint iLeft, myint iTop, myint iRight, myint iBottom, const int Color, int iOutlineColour, int iThickness);
+  void DasherDrawRectangle(myint iDasherMaxX, myint iDasherMinY, myint iDasherMinX, myint iDasherMaxY, const int Color, int iOutlineColour, int iThickness);
 
   ///
   /// Draw a centred rectangle specified in Dasher co-ordinates (used for mouse cursor)
diff --git a/Src/DasherCore/DasherViewSquare.cpp b/Src/DasherCore/DasherViewSquare.cpp
index 967692b..d5a78b5 100644
--- a/Src/DasherCore/DasherViewSquare.cpp
+++ b/Src/DasherCore/DasherViewSquare.cpp
@@ -369,7 +369,7 @@ void CDasherViewSquare::Circle(myint Range, myint y1, myint y2, int fCol, int oC
     if (x2==iDasherMaxX && x1==iDasherMaxX) {
       //circle entirely covers screen
       DASHER_ASSERT(y1==iDasherMinY);
-      DasherDrawRectangle(iDasherMaxX, iDasherMaxY, 0, iDasherMinY, fCol, oCol, lWidth);
+      DasherDrawRectangle(iDasherMaxX, iDasherMinY, 0, iDasherMaxY, fCol, oCol, lWidth);
       return;
     }
     //will also need final point at top-right (0,y2 in dasher coords)....
@@ -511,7 +511,7 @@ void CDasherViewSquare::DisjointRender(CDasherNode *pRender, myint y1, myint y2,
     //allow empty node to be expanded, it's big enough.
     policy.pushNode(pRender, y1, y2, true, dMaxCost);
     //and render whole node in one go
-    DasherDrawRectangle(std::min(Range,iDasherMaxX), std::min(y2,iDasherMaxY),0, std::max(y1,iDasherMinY), myColor, -1, 0);
+    DasherDrawRectangle(std::min(Range,iDasherMaxX), std::max(y1,iDasherMinY),0, std::min(y2,iDasherMaxY), myColor, -1, 0);
     //fall through to draw outline
   } else {
     //Node has children. It can therefore be collapsed...however,
@@ -574,8 +574,8 @@ void CDasherViewSquare::DisjointRender(CDasherNode *pRender, myint y1, myint y2,
           //fill in to its left
           DasherDrawRectangle(std::min(y2-y1,iDasherMaxX), std::max(newy1,iDasherMinY), std::min(newy2-newy1,iDasherMaxX), std::min(newy2,iDasherMaxY), myColor, -1, 0);
         
-          if (lasty<newy1) //fill in interval above child up to the last drawn child
-            DasherDrawRectangle(std::min(Range,iDasherMaxX), std::min(newy1,iDasherMaxY),0, std::max(lasty,iDasherMinY), myColor, -1, 0);
+          if (std::max(lasty,iDasherMinY)<newy1) //fill in interval above child up to the last drawn child
+            DasherDrawRectangle(std::min(Range,iDasherMaxX), std::max(lasty,iDasherMinY),0, std::min(newy1,iDasherMaxY), myColor, -1, 0);
           lasty = newy2;
           DisjointRender(pChild, newy1, newy2, pPrevText, policy, dMaxCost, myColor, pOutput);
         } else {
@@ -589,16 +589,16 @@ void CDasherViewSquare::DisjointRender(CDasherNode *pRender, myint y1, myint y2,
         }
       }
       //all children rendered.
-      if (lasty<y2) {
+      if (lasty<min(y2,iDasherMaxY)) {
         // Finish off the drawing process, filling in any part of the parent below the last-rendered child
-        DasherDrawRectangle(std::min(Range,iDasherMaxX), std::min(y2, iDasherMaxY), 0, std::max(lasty, iDasherMinY), myColor, -1, 0);
+        DasherDrawRectangle(std::min(Range,iDasherMaxX), std::max(lasty, iDasherMinY), 0, std::min(y2, iDasherMaxY), myColor, -1, 0);
       }
     }
     //end rendering children, fall through to outline
   }
   // Lastly, draw the outline
   if(GetLongParameter(LP_OUTLINE_WIDTH) && (!pRender->Parent() || pRender->getColour()!=pRender->Parent()->getColour())) {
-    DasherDrawRectangle(std::min(Range,iDasherMaxX), std::min(y2,iDasherMaxY),0, std::max(y1,iDasherMinY), -1, -1, abs(GetLongParameter(LP_OUTLINE_WIDTH)));
+    DasherDrawRectangle(std::min(Range,iDasherMaxX), std::max(y1,iDasherMinY),0, std::min(y2,iDasherMaxY), -1, -1, abs(GetLongParameter(LP_OUTLINE_WIDTH)));
   }
 }
 
@@ -637,7 +637,7 @@ void CDasherViewSquare::NewRender(CDasherNode *pRender, myint y1, myint y2,
   if (GetLongParameter(LP_OUTLINE_WIDTH)>=0) {
     switch (GetLongParameter(LP_SHAPE_TYPE)) {
       case 1: //overlapping rects
-        DasherDrawRectangle(std::min(Range,iDasherMaxX), std::min(y2,iDasherMaxY),0, std::max(y1,iDasherMinY), myColor, -1, 0);
+        DasherDrawRectangle(std::min(Range,iDasherMaxX), std::max(y1,iDasherMinY), 0, std::min(y2,iDasherMaxY), myColor, -1, 0);
         break;
       case 2: //simple triangles
         TruncateTri(Range, y1, y2, (y1+y2)/2, (y1+y2)/2, myColor, -1, 0);
@@ -715,7 +715,8 @@ void CDasherViewSquare::NewRender(CDasherNode *pRender, myint y1, myint y2,
       //if child still covers screen, render _just_ it and return
       myint newy1 = y1 + (Range * (myint)pChild->Lbnd()) / (myint)norm;
       myint newy2 = y1 + (Range * (myint)pChild->Hbnd()) / (myint)norm;
-      if (newy2-newy1 < GetLongParameter(LP_MIN_NODE_SIZE) //too small, but stored as only - so all others are smaller still...
+      if ((newy2-newy1 < GetLongParameter(LP_MIN_NODE_SIZE) //too small, but stored as only - so all others are smaller still...
+             && newy1 <= iDasherMaxY && newy2 >= iDasherMinY) //check too-small node is at least partly onscreen
           || (newy1 < iDasherMinY && newy2 > iDasherMaxY)) { //covers entire y-axis!
         NewRender(pChild, newy1, newy2, pPrevText, 
                   policy, dMaxCost, myColor, pOutput);
@@ -779,7 +780,7 @@ void CDasherViewSquare::NewRender(CDasherNode *pRender, myint y1, myint y2,
   if(GetLongParameter(LP_OUTLINE_WIDTH) && (!pRender->Parent() || pRender->getColour()!=pRender->Parent()->getColour())) {
     switch (GetLongParameter(LP_SHAPE_TYPE)) {
       case 1: //overlapping rects
-        DasherDrawRectangle(std::min(Range,iDasherMaxX), std::min(y2,iDasherMaxY),0, std::max(y1,iDasherMinY), -1, -1, abs(GetLongParameter(LP_OUTLINE_WIDTH)));
+        DasherDrawRectangle(std::min(Range,iDasherMaxX), std::max(y1,iDasherMinY), 0, std::min(y2,iDasherMaxY), -1, -1, abs(GetLongParameter(LP_OUTLINE_WIDTH)));
         break;
       case 2: //simple triangles
         TruncateTri(Range, y1, y2, (y1+y2)/2, (y1+y2)/2, -1, -1, abs(GetLongParameter(LP_OUTLINE_WIDTH)));



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