d_linesh.h

来自「这是数据结构和算法的国外经典书籍.清华大学出版社出版的<数据结构C++语言」· C头文件 代码 · 共 62 行

H
62
字号
#ifndef LINESHAPE_CLASS
#define LINESHAPE_CLASS

#include "d_shape.h"

// declaration of lineShape class with base class shape
class lineShape: public shape
{
   public:
      lineShape(double x = 0.0, double y = 0.0,
                double x2 = 0.0, double y2 = 0.0,
                shapeColor c = darkgray);
			// constructor. has arguments for base point,
			// the second point on the line and the color

      // line data access member functions
      double getEndX() const;
      double getEndY() const;
      void setEndPoint(double x, double y);
	      // retrieve or set length of the second point

      virtual void draw();
	      // draw the line

   private:
      double endX, endY;
	      // second point on the line
};

lineShape::lineShape(double x, double y, double x2, double y2,
                     shapeColor c):
        shape(x,y,c), endX(x2), endY(y2)
{}

double lineShape::getEndX() const
{
   return endX;
}

double lineShape::getEndY() const
{
   return endY;
}

// change the end point. must recompute length
void lineShape::setEndPoint(double x, double y)
{
   endX = x;
   endY = y;
}

void lineShape::draw()
{
   EZDCOLORVAL old_color;
   
   old_color = ezdSetColor(color.convertToEzdColor());
   shape_handle = ezdDrawLine(baseX, baseY, endX, endY);
   ezdSetColor(old_color);
}

#endif   // LINESHAPE_CLASS

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?