d-rect.h

来自「一些学习c++的例题」· C头文件 代码 · 共 61 行

H
61
字号
#ifndef __RECTANGLE_H__
#define __RECTANGLE_H__

#include "graphenv.h"
#include "d-shape.h"
#include "d-point.h"

class CRectangle : public CShape
{
protected:
   CPoint m_Points[2];

public:
   CRectangle(const int left = 0, const int top = 0,
   const int right = 10, const int bottom = 10)
   {
      m_Points[0] = CPoint(left, top);
      m_Points[1] = CPoint(right, bottom);
   }

   CRectangle(const CPoint& p1, const CPoint& p2)
   {
      m_Points[0] = p1;
      m_Points[1] = p2;
   }

   CRectangle(const CRectangle& r)
   {
      m_Points[0] = r.m_Points[0];
      m_Points[1] = r.m_Points[1];
   }

   ~CRectangle() {}

   void Show(const int color) const
   {
      CGraphEnv::SetColor(color);
      CGraphEnv::Rectangle(m_Points[0].x, m_Points[0].y, m_Points[1].x, m_Points[1].y);
   }

   void Move(const int offsetX, const int offsetY)
   {
      CPoint tmp(offsetX, offsetY);
      m_Points[0] += tmp;
      m_Points[1] += tmp;
      Show(CGraphEnv::COLOR_LIGHTBLUE);
      CGraphEnv::Outtextxy(m_Points[0].x + 4, m_Points[0].y + 4, "moved");
   }

   void Inflate(const float s)
   {
      m_Points[0] *= s;
      m_Points[1] *= s;
      Show(CGraphEnv::COLOR_LIGHTGREEN);
      CGraphEnv::Outtextxy(m_Points[0].x + 4, m_Points[0].y + 4, "inflated");
   }
};

#endif

⌨️ 快捷键说明

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