I removed the title bar and borders from my window and now I am trying to make it move when I click and move using this code:
void mouseDrag(const MouseEvent& event) override {
int x = event.getScreenPosition().x - event.getPosition().x;
int y = event.getScreenPosition().y - event.getPosition().y;
setTopLeftPosition(x, y);
}
It does move but I have 2 problems: 1) I have to click 2 times and then it starts moving and 2) when I start moving it, it gets empty (just grey color) no components inside it. How can I fix this?
[EDIT]
I get a bit closer with this code:
if (event.eventComponent == this) {
int x = event.getScreenPosition().x - lastMouseDownX;
int y = event.getScreenPosition().y - lastMouseDownY;
getParentComponent()->setTopLeftPosition(x, y);
}
Now the window moves without getting grey but the movement is flickering a lot and "jumps" positions.
It was actually really simple. All I had to do was to remove this line:
addMouseListener(this, true);
from the main gui component's constructor. Still, I don't know why this line made the window movement flickering. If anyone knows please comment.