Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
PolyArea Class Reference
Inheritance diagram for PolyArea:
Inheritance graph
[legend]
Collaboration diagram for PolyArea:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PolyArea (nsIContent *aArea)
virtual void ParseCoords (const nsAString &aSpec)
virtual PRBool IsInside (nscoord x, nscoord y) const
virtual void Draw (nsPresContext *aCX, nsIRenderingContext &aRC)
virtual void GetRect (nsPresContext *aCX, nsRect &aRect)
void HasFocus (PRBool aHasFocus)
void GetHREF (nsAString &aHref) const
void GetArea (nsIContent **aArea) const

Public Attributes

nsCOMPtr< nsIContentmArea
nscoordmCoords
PRInt32 mNumCoords
PRPackedBool mHasFocus

Detailed Description

Definition at line 473 of file nsImageMap.cpp.


Constructor & Destructor Documentation

Definition at line 484 of file nsImageMap.cpp.

  : Area(aArea)
{
}

Member Function Documentation

void PolyArea::Draw ( nsPresContext aCX,
nsIRenderingContext aRC 
) [virtual]

Implements Area.

Definition at line 570 of file nsImageMap.cpp.

{
  if (mHasFocus) {
    if (mNumCoords >= 6) {
      float p2t;
      p2t = aCX->PixelsToTwips();
      nscoord x0 = NSIntPixelsToTwips(mCoords[0], p2t);
      nscoord y0 = NSIntPixelsToTwips(mCoords[1], p2t);
      nscoord x1, y1;
      for (PRInt32 i = 2; i < mNumCoords; i += 2) {
        x1 = NSIntPixelsToTwips(mCoords[i], p2t);
        y1 = NSIntPixelsToTwips(mCoords[i+1], p2t);
        aRC.DrawLine(x0, y0, x1, y1);
        x0 = x1;
        y0 = y1;
      }
      x1 = NSIntPixelsToTwips(mCoords[0], p2t);
      y1 = NSIntPixelsToTwips(mCoords[1], p2t);
      aRC.DrawLine(x0, y0, x1, y1);
    }
  }
}

Here is the call graph for this function:

void Area::GetArea ( nsIContent **  aArea) const [inherited]

Definition at line 123 of file nsImageMap.cpp.

{
  *aArea = mArea;
  NS_IF_ADDREF(*aArea);
}

Here is the caller graph for this function:

void Area::GetHREF ( nsAString &  aHref) const [inherited]

Definition at line 114 of file nsImageMap.cpp.

{
  aHref.Truncate();
  if (mArea) {
    mArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::href, aHref);
  }
}
void PolyArea::GetRect ( nsPresContext aCX,
nsRect aRect 
) [virtual]

Implements Area.

Definition at line 593 of file nsImageMap.cpp.

{
  if (mNumCoords >= 6) {
    float p2t;
    p2t = aCX->PixelsToTwips();
    nscoord x1, x2, y1, y2, xtmp, ytmp;
    x1 = x2 = NSIntPixelsToTwips(mCoords[0], p2t);
    y1 = y2 = NSIntPixelsToTwips(mCoords[1], p2t);
    for (PRInt32 i = 2; i < mNumCoords; i += 2) {
      xtmp = NSIntPixelsToTwips(mCoords[i], p2t);
      ytmp = NSIntPixelsToTwips(mCoords[i+1], p2t);
      x1 = x1 < xtmp ? x1 : xtmp;
      y1 = y1 < ytmp ? y1 : ytmp;
      x2 = x2 > xtmp ? x2 : xtmp;
      y2 = y2 > ytmp ? y2 : ytmp;
    }

    aRect.SetRect(x1, y1, x2, y2);
  }
}

Here is the call graph for this function:

void Area::HasFocus ( PRBool  aHasFocus) [inherited]

Definition at line 329 of file nsImageMap.cpp.

{
  mHasFocus = aHasFocus;
}

Here is the caller graph for this function:

PRBool PolyArea::IsInside ( nscoord  x,
nscoord  y 
) const [virtual]

Implements Area.

Definition at line 508 of file nsImageMap.cpp.

{
  if (mNumCoords >= 6) {
    PRInt32 intersects = 0;
    nscoord wherex = x;
    nscoord wherey = y;
    PRInt32 totalv = mNumCoords / 2;
    PRInt32 totalc = totalv * 2;
    nscoord xval = mCoords[totalc - 2];
    nscoord yval = mCoords[totalc - 1];
    PRInt32 end = totalc;
    PRInt32 pointer = 1;

    if ((yval >= wherey) != (mCoords[pointer] >= wherey))
      if ((xval >= wherex) == (mCoords[0] >= wherex))
        intersects += (xval >= wherex) ? 1 : 0;
      else
        intersects += ((xval - (yval - wherey) *
                        (mCoords[0] - xval) /
                        (mCoords[pointer] - yval)) >= wherex) ? 1 : 0;

    // XXX I wonder what this is doing; this is a translation of ptinpoly.c
    while (pointer < end)  {
      yval = mCoords[pointer];
      pointer += 2;
      if (yval >= wherey)  {
        while((pointer < end) && (mCoords[pointer] >= wherey))
          pointer+=2;
        if (pointer >= end)
          break;
        if ((mCoords[pointer-3] >= wherex) ==
            (mCoords[pointer-1] >= wherex)) {
          intersects += (mCoords[pointer-3] >= wherex) ? 1 : 0;
        } else {
          intersects +=
            ((mCoords[pointer-3] - (mCoords[pointer-2] - wherey) *
              (mCoords[pointer-1] - mCoords[pointer-3]) /
              (mCoords[pointer] - mCoords[pointer - 2])) >= wherex) ? 1:0;
        }
      }  else  {
        while((pointer < end) && (mCoords[pointer] < wherey))
          pointer+=2;
        if (pointer >= end)
          break;
        if ((mCoords[pointer-3] >= wherex) ==
            (mCoords[pointer-1] >= wherex)) {
          intersects += (mCoords[pointer-3] >= wherex) ? 1:0;
        } else {
          intersects +=
            ((mCoords[pointer-3] - (mCoords[pointer-2] - wherey) *
              (mCoords[pointer-1] - mCoords[pointer-3]) /
              (mCoords[pointer] - mCoords[pointer - 2])) >= wherex) ? 1:0;
        }
      }
    }
    if ((intersects & 1) != 0) {
      return PR_TRUE;
    }
  }
  return PR_FALSE;
}
void PolyArea::ParseCoords ( const nsAString &  aSpec) [virtual]

Reimplemented from Area.

Definition at line 489 of file nsImageMap.cpp.

{
  Area::ParseCoords(aSpec);

  if (mNumCoords >= 2) {
    if (mNumCoords & 1U) {
      logMessage(mArea,
                 aSpec,
                 nsIScriptError::warningFlag,
                 "ImageMapPolyOddNumberOfCoords");
    }
  } else {
    logMessage(mArea,
               aSpec,
               nsIScriptError::errorFlag,
               "ImageMapPolyWrongNumberOfCoords");
  }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 90 of file nsImageMap.cpp.

nscoord* Area::mCoords [inherited]

Definition at line 91 of file nsImageMap.cpp.

Definition at line 93 of file nsImageMap.cpp.

Definition at line 92 of file nsImageMap.cpp.


The documentation for this class was generated from the following file: