squareshape.cpp

来自「一个漂亮的万花筒游戏」· C++ 代码 · 共 57 行

CPP
57
字号
// SquareShape.cpp: implementation of the SquareShape class.
//
//////////////////////////////////////////////////////////////////////
#include <assert.h>
#include "ezwin.h"
#include "math.h"
#include "WindowObject.h"
#include "Shape.h"
#include "SquareShape.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SquareShape::SquareShape(SimpleWindow &Window,
 const Position &center, const color &c, float s) :
 Shape(Window, center, c), SideLength(s) {
 // No code needed!
}

float SquareShape::GetSideLength() const {
	return SideLength;
}

void SquareShape::Draw() {
	const Position Center = GetPosition();
	const float SideLength = GetSideLength();

	const Position UpperLeft = Center
	 + Position(-.5f * SideLength, -.5f * SideLength);
	const Position LowerRight = Center
	 + Position(.5f * SideLength, .5f * SideLength);
	GetWindow().RenderRectangle(UpperLeft, LowerRight,
	 GetColor(), HasBorder());
   return;
}


void SquareShape::SetSize(float s) {
	SideLength = s;
   return;
}

void SquareShape::Erase() {
	const Position Center = GetPosition();
	const float SideLength = GetSideLength();

	const Position UpperLeft = Center
	 + Position(-.5f * SideLength, -.5f * SideLength);
	const Position LowerRight = Center
	 + Position(.5f * SideLength, .5f * SideLength);
	GetWindow().RenderRectangle(UpperLeft, LowerRight,
	 White, HasBorder());
   return;
}

⌨️ 快捷键说明

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