home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-13 | 6.0 KB | 207 lines | [TEXT/CWIE] |
- //Copyright (c) 1997 Brian and Aidan Cully
- //All rights reserved
-
- #include <math.h>
- #include <Quickdraw.h>
- #include <Menus.h>
- #include "DrawContent.h"
- #include "Misc.h"
- #include "MenuHandler.h"
- #include "CLStrStuff.h"
- #include "Messages.h"
- #include "CLLine.h"
- #include "CLStringShape.h"
- #include "CLColorStyle.h"
- #include "CLRectShape.h"
- #include "LMath.h"
-
- TEquContent::TEquContent( TLayoutBranch *super, MActionHandler *superHandler, Boolean hasDD,
- TPlane *nplane ):
- TDocContent( super, hasDD, superHandler, nplane )
- {
- }
-
- SInt8 TEquContent::DXDivY( int x, int y, unsigned char *num, unsigned char *den )
- {
- MoveTo( x, y );
- DrawString( num );
- MoveTo( x, y+3 );
- Line( 40, 0 );
- MoveTo( x, y+12+6 );
- DrawString( den );
- }
-
- void TEquContent::DrawSelf( TDrawSlate *gr )
- {
- TEraseRectShape( GetLocalRect() ).RenderOn( gr );
- float a,b,npang;
- int dec,sign,deccount;
- Str32 astr,bstr;
-
- MoveTo(20,20);
- npang = fmod(mPlane->GetAngle(),180);
- if (fabs(npang)<0.001) {
- a = mPlane->GetDistance()*mPlane->GetDistance();
- StrCpy( astr, gcvt(a,5) );
- DrawString("\px^2 + y^2 =");
- DrawString(astr);
- } else if ((npang == 45) || (npang == 135)) {
- a = 4*mPlane->GetDistance()/2;
- if( npang == 135 )
- a = -a;
- DrawString("\px^2 = ");
- StrCpy( astr, gcvt( a, 5 ) );
- DrawString(astr);
- DrawString("\py");
- } else if ((npang < 45) || (npang > 135)) {
- a = mPlane->GetDistance()/mPlane->GetCosAngle();
- a = a*a;
- b = mPlane->GetDistance()*tan((45-mPlane->GetAngle())*M_PI/180);
- b += mPlane->GetDistance()*tan((45+mPlane->GetAngle())*M_PI/180);
- b /= 2;
- b = b*b;
- StrCpy( astr, gcvt( a, 5 ) );
- DXDivY( 20, 20, "\px^2", astr );
- StrCpy( bstr, gcvt( b, 5 ) );
- DXDivY( 80, 20, "\py^2", bstr );
- MoveTo( 70, 28 );
- DrawString("\p+");
- Move(47,0);
- DrawString("\p= 1");
- } else {
- a = mPlane->GetDistance()/mPlane->GetSinAngle();
- a = a*a;
- b = mPlane->GetDistance()*tan((45-mPlane->GetAngle())*M_PI/180);
- b += (mPlane->GetDistance()*tan((45+mPlane->GetAngle())*M_PI/180));
- b /= 2;
- b = b*b;
- StrCpy( astr, gcvt( a, 5 ) );
- DXDivY( 20, 20, "\py^2", astr );
- StrCpy( bstr, gcvt( b, 5 ) );
- DXDivY( 80, 20, "\px^2", bstr );
- MoveTo( 70, 28 );
- DrawString( "\p-" );
- Move(54,0);
- DrawString("\p= 1");
- }
- }
-
- TPlotContent::TPlotContent( TLayoutBranch *super, MActionHandler *superHandler, Boolean hasDD,
- TConic *nconic, TPlane *nplane ):
- TDocContent( super, hasDD, superHandler, nplane ),
- mConic( nconic )
- {
- }
-
- void TPlotContent::DrawSelf( TDrawSlate *gr )
- {
- TEraseRectShape( GetLocalRect() ).RenderOn( gr );
- DrawAxis( gr );
- DrawIntersect( gr );
- }
-
- SInt8 TPlotContent::DrawAxis( TDrawSlate *gr )
- {
- Rect drawRect = GetLocalRect();
- TColorStyle xcol( 0, 0x8000, 0xffff );
- TColorStyle ycol( 0, 0, 0xffff );
- TColorStyle black( 0, 0, 0 );
- int iter;
-
- ::OffsetRect( &drawRect, -drawRect.left, -drawRect.top );
- //color 0xff0000
- TLine( &xcol, 0, drawRect.bottom/2, drawRect.right, drawRect.bottom/2 ).RenderOn( gr );
- //gr->SetColor( 0, 0, 0 );
- TStringShape( &black, drawRect.right-12, drawRect.bottom/2, "x" ).RenderOn( gr );
- TLine( &ycol, drawRect.right/2, 0, drawRect.right/2, drawRect.bottom ).RenderOn( gr );
- TStringShape( &black, drawRect.right/2, drawRect.bottom-8, "y" ).RenderOn( gr );
- for( iter= -6; iter<=6; iter++ ) {
- int x, y;
- x= (drawRect.left+drawRect.right)/2+iter*((drawRect.right-drawRect.left)/12);
- y= (drawRect.top+drawRect.bottom)/2+iter*((drawRect.bottom-drawRect.top)/12);
- TLine( &black, x, drawRect.bottom/2-3, x, drawRect.bottom/2+3 ).RenderOn( gr );
- TLine( &black, drawRect.right/2-3, y, drawRect.right/2+3, y ).RenderOn( gr );
- }
- //color 0xff00
- }
-
- SInt8 TPlotContent::DrawIntersect( TDrawSlate *gr )
- {
- int numint,border[8],numtint,numbint;
- p2d inter2,ptint[180],pbint[180],point,opoint;
- p3d inter3;
- Rect drawRect= GetLocalRect();
- float npang= fmod( mPlane->GetAngle(), 180.0 )-45.0;
-
- numtint = 0;
- numbint = 0;
-
- //gr->SetColor( 0xffff, 0, 0 );
- TColorStyle inter( 0xffff, 0, 0 );
- for(numint=0;numint<mConic->mNumInt;numint++) {
- inter3 = mConic->mConic[mConic->mIntersect[numint]];
- inter2.x = inter3.x;
- inter2.y = mPlane->GetCosAngle()*inter3.y + mPlane->GetSinAngle()*inter3.z;
- if (!(mConic->mIntersect[numint]%2)) {
- ptint[numtint].x = inter2.x;
- ptint[numtint].y = inter2.y;
- numtint++;
- } else {
- pbint[numbint].x = inter2.x;
- pbint[numbint].y = inter2.y;
- numbint++;
- }
- }
- if( numbint < mConic->mNumInt ) {
- point.x = ptint[0].x;
- point.y = ptint[0].y;
- point.x *= (drawRect.right-drawRect.left)/12;
- point.x += (drawRect.right-drawRect.left)/2;
- point.y *= -(drawRect.bottom-drawRect.top)/12;
- point.y += (drawRect.bottom-drawRect.top)/2;
- /*if( (npang < 90.0) && (npang>0.0) )
- numtint--;*/
- for(numint=0;numint<numtint;numint++) {
- opoint = point;
- point.x = ptint[numint].x;
- point.y = ptint[numint].y;
- point.x *= (drawRect.right-drawRect.left)/12;
- point.x += (drawRect.right-drawRect.left)/2;
- point.y *= -(drawRect.bottom-drawRect.top)/12;
- point.y += (drawRect.bottom-drawRect.top)/2;
- //color 0xff
- TLine( &inter, opoint.x,opoint.y,point.x,point.y ).RenderOn( gr );
- //gr->DrawLine( opoint.x,opoint.y,point.x,point.y );
- }
- /*if( (npang < 90.0) && (npang>0.0) )
- numtint++;*/
- }
- if (numtint < mConic->mNumInt) {
- point.x = pbint[0].x;
- point.y = pbint[0].y;
- point.x *= (drawRect.right-drawRect.left)/12;
- point.x += (drawRect.right-drawRect.left)/2;
- point.y *= -(drawRect.bottom-drawRect.top)/12;
- point.y += (drawRect.bottom-drawRect.top)/2;
- /*if( (npang < 90.0) && (npang>0.0) )
- numbint--;*/
- for(numint=0;numint<numbint;numint++) {
- opoint = point;
- point.x = pbint[numint].x;
- point.y = pbint[numint].y;
- point.x *= (drawRect.right-drawRect.left)/12;
- point.x += (drawRect.right-drawRect.left)/2;
- point.y *= -(drawRect.bottom-drawRect.top)/12;
- point.y += (drawRect.bottom-drawRect.top)/2;
- /*if ((opoint.y == point.y) || (opoint.x == point.x)) {
- opoint.x = point.x;
- opoint.y = point.y;
- }*/
- //color 0xff
- TLine( &inter, opoint.x,opoint.y,point.x,point.y ).RenderOn( gr );
- //gr->DrawLine( opoint.x,opoint.y,point.x,point.y );
- }
- /*if( (npang < 90.0) && (npang>0.0) )
- numbint++;*/
- }
- }