📄 squareshape.cpp
字号:
// 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 ¢er, 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -