Windows10,vs2022
在完成鼠标划线功能之后我打算利用绘制白色线条的方式去做一个橡皮擦,结果在运行时发现橡皮擦在使用的时候如果鼠标移动过快会产生断点,但是画线的时候无论怎么移动鼠标都不会产生断点。
#include <easyx.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>
using namespace std;
struct Point {
int x = 0, y = 0;
Point() {
x = -1;
y = -1;
}
Point(int xx,int yy) {
x = xx;
y = yy;
}
};
class LineTool {
public:
int size = 1;
COLORREF color = BLACK;
Point point_begin;
bool LIsDown = false,RIsDown = false;
LineTool() {
LIsDown = false;
}
LineTool(int LineSize, COLORREF LineColor) {
size = LineSize;
color = LineColor;
LIsDown = false;
}
//鼠标信号处理
void CallMouse(MOUSEMSG m) {
//左键画线
if (m.uMsg == WM_LBUTTONDOWN)
{
LIsDown = true;
point_begin = Point(m.x, m.y);
}
if (m.uMsg == WM_LBUTTONUP) {
LIsDown = false;
}
if (m.uMsg == WM_MOUSEMOVE && LIsDown) {
setlinestyle(PS_ENDCAP_ROUND, size);
setlinecolor(color);
line(point_begin.x, point_begin.y, m.x, m.y);
}
point_begin.x = m.x;
point_begin.y = m.y;
//右键擦除
if (m.uMsg == WM_RBUTTONDOWN)
{
RIsDown = true;
point_begin = Point(m.x, m.y);
}
if (m.uMsg == WM_RBUTTONUP) {
RIsDown = false;
}
if (m.uMsg == WM_MOUSEMOVE && RIsDown) {
setlinestyle(PS_ENDCAP_ROUND, 10);
setlinecolor(WHITE);
line(point_begin.x, point_begin.y, m.x, m.y);
}
point_begin.x = m.x;
point_begin.y = m.y;
}
};
int main() {
initgraph(1366, 768);
setbkcolor(WHITE);
cleardevice();
LineTool* pLine = new LineTool(5,RED);
while(1) {
while (MouseHit()) {
MOUSEMSG m = GetMouseMsg();
pLine->CallMouse(m);
}
}
closegraph();
return 0;
}




