Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
QBCurve Class Reference


Class QBCurve, a quadratic bezier curve, used to implement the rounded rectangles 3/26/99 dwc More...

#include <nsCSSRendering.h>

Collaboration diagram for QBCurve:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 QBCurve ()
void SetControls (nsFloatPoint &aAnc1, nsFloatPoint &aCon, nsFloatPoint &aAnc2)
void SetPoints (float a1x, float a1y, float acx, float acy, float a2x, float a2y)
void SubDivide (nsIRenderingContext *aRenderingContext, nsPoint aPointArray[], PRInt32 *aCurIndex)
 
Divide a Quadratic curve into line segments if it is not smaller than a certain size else it is so small that it can be approximated by 2 lineto calls
void MidPointDivide (QBCurve *A, QBCurve *B)
 
Divide a Quadratic Bezier curve at the mid-point 3/26/99 dwc

Public Attributes

nsFloatPoint mAnc1
nsFloatPoint mCon
nsFloatPoint mAnc2

Detailed Description


Class QBCurve, a quadratic bezier curve, used to implement the rounded rectangles 3/26/99 dwc

Definition at line 313 of file nsCSSRendering.h.


Constructor & Destructor Documentation

QBCurve::QBCurve ( ) [inline]

Definition at line 321 of file nsCSSRendering.h.


Member Function Documentation


Divide a Quadratic Bezier curve at the mid-point 3/26/99 dwc


See documentation in nsCSSRendering.h 4/13/99 dwc

Parameters:
aCurve1-- Curve 1 as a result of the division
aCurve2-- Curve 2 as a result of the division

Definition at line 4033 of file nsCSSRendering.cpp.

{
  float c1x,c1y,c2x,c2y;
  nsFloatPoint a1;

  c1x = (mAnc1.x+mCon.x)/2.0f;
  c1y = (mAnc1.y+mCon.y)/2.0f;
  c2x = (mAnc2.x+mCon.x)/2.0f;
  c2y = (mAnc2.y+mCon.y)/2.0f;

  a1.x = (c1x + c2x)/2.0f;
  a1.y = (c1y + c2y)/2.0f;

  // put the math into our 2 new curves
  A->mAnc1 = this->mAnc1;
  A->mCon.x = c1x;
  A->mCon.y = c1y;
  A->mAnc2 = a1;
  B->mAnc1 = a1;
  B->mCon.x = c2x;
  B->mCon.y = c2y;
  B->mAnc2 = this->mAnc2;
}

Here is the caller graph for this function:

void QBCurve::SetControls ( nsFloatPoint aAnc1,
nsFloatPoint aCon,
nsFloatPoint aAnc2 
) [inline]

Definition at line 322 of file nsCSSRendering.h.

{ mAnc1 = aAnc1; mCon = aCon; mAnc2 = aAnc2;}
void QBCurve::SetPoints ( float  a1x,
float  a1y,
float  acx,
float  acy,
float  a2x,
float  a2y 
) [inline]

Definition at line 323 of file nsCSSRendering.h.

{mAnc1.MoveTo(a1x,a1y),mCon.MoveTo(acx,acy),mAnc2.MoveTo(a2x,a2y);}

Here is the call graph for this function:

Here is the caller graph for this function:

void QBCurve::SubDivide ( nsIRenderingContext aRenderingContext,
nsPoint  aPointArray[],
PRInt32 aCurIndex 
)


Divide a Quadratic curve into line segments if it is not smaller than a certain size else it is so small that it can be approximated by 2 lineto calls


See documentation in nsCSSRendering.h 4/13/99 dwc

Parameters:
aRenderingContext-- The RenderingContext to use to draw with
aPointArray[]-- A list of points we can put line calls into instead of drawing. If null, lines are drawn
aCurInex-- a pointer to an Integer that tells were to put the points into the array, incremented when finished 3/26/99 dwc

Definition at line 3979 of file nsCSSRendering.cpp.

{
  QBCurve   curve1,curve2;
  float     fx,fy,smag, oldfx, oldfy, oldsmag;
  
  if (aCurIndex && (*aCurIndex >= MAXPOLYPATHSIZE))
    return;
  
  oldfx = (this->mAnc1.x + this->mAnc2.x)/2.0f - this->mCon.x;
  oldfy = (this->mAnc1.y + this->mAnc2.y)/2.0f - this->mCon.y;
  oldsmag = oldfx * oldfx + oldfy * oldfy;
  // divide the curve into 2 pieces
  MidPointDivide(&curve1,&curve2);

  fx = (float)fabs(curve1.mAnc2.x - this->mCon.x);
  fy = (float)fabs(curve1.mAnc2.y - this->mCon.y);

  //smag = fx+fy-(PR_MIN(fx,fy)>>1);
  smag = fx*fx + fy*fy;
 
  if (smag>1){
    if (smag + 0.2 > oldsmag)
      return; // we did not get closer
    // split the curve again
    curve1.SubDivide(aRenderingContext,aPointArray,aCurIndex);
    curve2.SubDivide(aRenderingContext,aPointArray,aCurIndex);
  }else{
    if(aPointArray ) {
      // save the points for further processing
      aPointArray[*aCurIndex].x = (nscoord)curve1.mAnc2.x;
      aPointArray[*aCurIndex].y = (nscoord)curve1.mAnc2.y;
      (*aCurIndex)++;
      if (*aCurIndex >= MAXPOLYPATHSIZE)
        return;
      aPointArray[*aCurIndex].x = (nscoord)curve2.mAnc2.x;
      aPointArray[*aCurIndex].y = (nscoord)curve2.mAnc2.y;
      (*aCurIndex)++;
    }else{
      // draw the curve 
      nsTransform2D *aTransform;
      aRenderingContext->GetCurrentTransform(aTransform);

      
      aRenderingContext->DrawLine((nscoord)curve1.mAnc1.x,(nscoord)curve1.mAnc1.y,(nscoord)curve1.mAnc2.x,(nscoord)curve1.mAnc2.y);
      aRenderingContext->DrawLine((nscoord)curve1.mAnc2.x,(nscoord)curve1.mAnc2.y,(nscoord)curve2.mAnc2.x,(nscoord)curve2.mAnc2.y);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 317 of file nsCSSRendering.h.

Definition at line 319 of file nsCSSRendering.h.

Definition at line 318 of file nsCSSRendering.h.


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