Shape.h
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:7k
源码类别:
绘图程序
开发平台:
Visual C++
- // Shape.h: interface for the CShape class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_SHAPE_H__7A2777F2_C8C5_4853_A468_CF20CEE5E178__INCLUDED_)
- #define AFX_SHAPE_H__7A2777F2_C8C5_4853_A468_CF20CEE5E178__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "GraphDefines.h"
- #include "afxtempl.h"
- #include "math.h"
- ////////////////////////////////////////Struct tEdge
- //此结构用于图形填充
- typedef struct tEdge
- {
- int ymin;
- float x,dx;
- struct tEdge *next;
- }Edge;
- typedef Edge* pEdge;
- class CShape : public CObject
- {
- //for serialization
- DECLARE_SERIAL(CShape)
- /////////////////////////////////////
- public:
- CShape();
- CShape(COLORREF color,int penWidth,float angle=0);
- virtual ~CShape();
- CShape(CShape* const shape);
- public:
- /////////////////////////
- //virtual functions
- virtual void Serialize( CArchive& );
- virtual void SetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY){};
- virtual void GetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY){};
- virtual void Draw(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth){return ;};
- virtual void DrawPoints(CDC *pDC,COLORREF color){return;} ;
- virtual void DrawPointsCutTo(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo){return;} ;
- virtual void CreatGraph(CArray<CPoint,CPoint>& ptArray,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle=_shape_none_fill){
- m_nPenWidth=nPenWidth;
- m_color=color;
- m_nFillStyle=nStyle;
- m_FillColor=fillColor;
- }
- virtual void CreatGraph(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle=_shape_none_fill){
- m_nPenWidth=nPenWidth;
- m_color=color;
- m_nFillStyle=nStyle;
- m_FillColor=fillColor;
- }
- void DrawCutToRect(CDC *pDC,CFlRect m_rectFrom,CRect m_rectTo);
- void DrawCutToRect(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo);
- void DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,CFlRect m_rectFrom,CRect m_rectTo);
- void DrawCutToRect(CDC *pDC,COLORREF color,int penWidth,CFlRect m_rectFrom,CRect m_rectTo);
- virtual void DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth,CFlRect m_rectFrom,CRect m_rectTo){return;};
- virtual void Move(CDC *pDC,float stepx,float stepy){}
- virtual void PartMove(CDC *pDC,float PrevX,float PrevY,float CurX,float CurY){}
- virtual void Rotate(CDC *pDC,float CX,float CY,float flAngle){}
- virtual void Magnify(CDC *pDC,float CX,float CY,float flScale){}
- //在矩形内上下反转
- virtual void TopToBottom(CDC* pDC,CRect rect){return;}
- //在矩形内左右反转
- virtual void LeftToRight(CDC* pDC,CRect rect){return;}
- virtual void ExPort(FILE* outStream);//增加导出txt功能时用
- virtual void ImPort(FILE* inStream);
- virtual CShape* GetCopy(){
- CShape* pShape=new CShape(this);
- return pShape;
- }
- virtual CString GetNameString(){
- return " ";
- }
- virtual float GetSelectLineRate(){return 0;}
- virtual GRAPH_SHAPE_TYPE GetShapeKind(){
- return _shape_none;
- }
- virtual void RefreshData(bool bRefresh){}
- //IsInRect
- //return value
- //0----------out
- //1----------cut
- //2----------in
- //3----------Contain the rect
- virtual int IsInRect(CRect rect){
- return 0;
- }
- //GetPtState
- //para
- //float flx,float fly -----the point value
- //float flRate-------------the Rate of magnify of point and line
- //return value
- //0----------out
- //1----------on component point
- //2----------on out line
- virtual int GetPtState(float flx,float fly,float flRate){
- return 0;
- }
- //IsPointinRegion
- //return value
- //0----------out
- //1----------in
- virtual int IsPointinRegion(POINT point){return 0;};
- /////////////////////////
- virtual CRect GetBoundaryRect(){
- return CRect(0,0,0,0);
- }
- virtual CPoint GetCenterPoint(){
- return CPoint(0,0);
- }
- //Begin of deletion
- //For Project GraphSoft,delete by FNST)Xiagongli 2004.3.31
- //virtual int GetPointNum(){
- // return 04;
- //}
- //end of deletion
- public:
- void Draw(CDC *pDC);
- void Draw(CDC *pDC,COLORREF color);
- void Draw(CDC *pDC,COLORREF color,COLORREF fillColor);
- void Draw(CDC *pDC,COLORREF color,int penWidth);
- inline void SetColor(COLORREF color){
- m_color=color;
- }
- inline void SetPenWidth(int penWidth){
- m_nPenWidth=penWidth;
- }
- inline void SetAngle(float angle){
- m_flAngle=angle;
- }
- inline float GetAngle(){
- return m_flAngle;
- }
- inline const COLORREF GetColor()const{
- return m_color;
- }
- inline void MultiplyScale(float scale)
- {
- if(scale>0)
- m_flScale*=scale;
- }
- inline float GetScale(){
- return m_flScale;
- }
- inline const int GetPenWidth()const{
- return m_nPenWidth;
- }
- inline void SetSelectFlag( bool bFlag ) {
- m_bSelect_flag = bFlag ;
- }
- inline const bool IsSelected()const{
- return m_bSelect_flag;
- }
- inline void SetDrawPointsFlag(int nFlag){
- m_nDrawPoints=nFlag;
- }
- inline int GetDrawPointsFlag(){
- return m_nDrawPoints;
- }
- inline void SetFillStyle(SHAPE_FILLSTYLE nStyle){
- m_nFillStyle=nStyle;
- }
- inline SHAPE_FILLSTYLE GetFillStyle(){
- return m_nFillStyle;
- }
- inline void SetFillColor(COLORREF color){
- m_FillColor=color;
- }
- inline COLORREF GetFillColor(){
- return m_FillColor;
- }
- inline unsigned long GetID(){
- return m_nID;
- }
- inline void SetID(unsigned long nID){
- m_nID=nID;
- }
- void BresenhamLine(CDC *pDC,CPoint m_pStart,CPoint m_pEnd,COLORREF color);
- void BresenhamLine(CDC *pDC,int x1,int y1,int x2,int y2,COLORREF color);
- void BresenhamLine(CDC *pDC,int x1,int y1,int x2,int y2,COLORREF color,CRect rect);
- void DotLine(CDC *pDC,int x1,int y1,int x2,int y2,COLORREF color);
- //Polygon Fill color
- void InsertEdge(Edge *list,Edge *edge);
- //void MakeEdgeRec(POINT lower,POINT upper,int yComp,Edge *edge,Edge *edges[]);
- void BuildEdgeList(int cnt,POINT *pts,Edge *edges[],int nScanMin);
- void BuildActiveList(int scan,Edge *active,Edge *edges[],int nScanMin);
- void FillScan(CDC *pDC,int scan,Edge *active,COLORREF color);
- void DeleteAfter(Edge *q);
- void UpdateActiveList(int scan,Edge *active);
- void AreaFill(CDC *pDC,int cnt,POINT *pts,COLORREF color);
- public:
- int PtStateToRect(float x,float y,CRect rectRes);//判断一个点与矩形的相对位置,
- int PtStateToRect(CPoint point,CRect rectRes);//判断一个点与矩形的相对位置
- protected:
- int DrawLineToRect(CDC *pDC,POINT start,POINT end,CFlRect m_rectFrom,CRect m_rectTo);
- protected:
- static unsigned long m_nObjectNum;
- unsigned long m_nID;//not save
- protected:
- CPoint m_ptRotateCenterTemp;//not save
- float m_flAngleTemp;//not save
- CPoint m_ptMagnifyCenterTemp;//not save
- float m_flScaleTemp;//not save
- bool m_bModified;//not save
- int m_nSelectPtNum;//not save
- int m_nSelectLineNum;//not save
- SHAPE_FILLSTYLE m_nFillStyle;//save
- private:
- //attributes
- ////////////////////////
- COLORREF m_color;
- COLORREF m_FillColor;
- int m_nPenWidth;
- float m_flAngle;
- float m_flScale;
- int m_nDrawPoints;
- bool m_bSelect_flag;//not save
- ////////////////////////
- };
- #endif // !defined(AFX_SHAPE_H__7A2777F2_C8C5_4853_A468_CF20CEE5E178__INCLUDED_)