📄 sketchpad.cpp
字号:
#include "canvas.h"
// illustrates MKAdapter with SketchAnEtch (stealing shamelessly
// from EtchASketch, a trademarked product)
class SketchPad : public MKAdapter
{
public:
SketchPad(const Point& start); // begin to draw at start
void processKey(const Key& key, AnimatedCanvas& c);
private:
static const int DELTA; // each key click moves this amount
Point myPoint; // current point in drawing
};
const int SketchPad::DELTA = 2;
SketchPad::SketchPad(const Point& start)
: myPoint(start)
{
}
void SketchPad::processKey(const Key& key, AnimatedCanvas& c)
// post: line drawn from oldpoint to newpoint in given direction
// specified by key (arrow key)
{
Point newPoint = myPoint;
if (key.isuparrow())
{ newPoint.y -= DELTA;
}
else if (key.isdownarrow())
{ newPoint.y += DELTA;
}
else if (key.isleftarrow())
{ newPoint.x -= DELTA;
}
else if (key.isrightarrow())
{ newPoint.x += DELTA;
}
c.DrawLine(myPoint,newPoint);
myPoint = newPoint;
}
int main()
{
const int WIDTH=200, HEIGHT=200;
Canvas c(WIDTH,HEIGHT,20,20); // double buffering off
c.SetColor(CanvasColor::BLACK);
c.SetTitle("Tapestry SketchAnEtch");
SketchPad sp = SketchPad(Point(WIDTH/2,HEIGHT/2)); // start in middle
c.addShape(sp);
c.runUntilEscape(10);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -