Hello fellas! I am working on Paint 2.0 project which is supposed to be simple yet WORKING graphics editor, using sfml. Yesterday I have encountered the problem which I still can't fix.
I am implementing Pencil tool, but instead of creating normal smooth line it draws dotted and separated ones.
At first, I just made it with drawPixel function but right now I am using Vertices to make lines based on the previous mouseMoved register. In both cases, I get the same scenario.
Here is the function call.
while (mainWindow.pollEvent(event)) {
if (event.type == sf::Event::Closed)
mainWindow.close();
else if ((event.type == sf::Event::MouseMoved) &&
sf::Mouse::isButtonPressed(
sf::Mouse::Left)) // MouseMoved and leftClickHeld
{
switch (currentTool) {
case 0: {
vecLine =
drawPencil(mainWindow, currentColor,
sf::Mouse::getPosition(mainWindow), thickness, 0);
break;
}
}
} else if (event.type == sf::Event::MouseButtonPressed) {
switch (currentTool) {
case 0: {
vecLine =
drawPencil(mainWindow, currentColor,
sf::Mouse::getPosition(mainWindow), thickness, 1);
break;
}
case 1: {
vecLine = drawLine(mainWindow, currentColor,
sf::Mouse::getPosition(mainWindow));
break;
}
}
And here is the function that draws lines
std::vector<std::pair<sf::Vertex, sf::Vertex>>
drawPencil(sf::RenderWindow &mainWindow, sf::Color color,
sf::Vector2i currentPos, unsigned int thickness, int mode) {
if (thickness == 0) {
if (mode == 1) {
line[0].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
line[1].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
line[0].color = color;
line[1].color = color;
} else {
if (firstPoint) {
line[0].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
line[1].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
line[0].color = color;
line[1].color = color;
firstPoint = false;
} else {
line[1].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
firstPoint = true;
vecLine.push_back(std::make_pair(line[0], line[1]));
}
}
return vecLine;
} else {
}
}
Int mode is to deny lines that could be drawn just by clicking and not dragging.
I suspect it's connected with MouseMoved update rate