I have an idea where let's just assume it's a bunch of notes that are scattered on a desktop.
This desktop can be scrolled and within it you can move around the notes.
So far, I have my notes, and they can intercept mouse down and mouse up events to draw in a different colour (so that I can see they've clicked).
However, when it comes to making them move along with the mouse, I have a feeling I'm about to go about it the wrong way. I was going to intercept the move event and have the "notes" follow the mouse.
But I think there's probably some problems with that, like if the mouse moves too quick.
Does my "desktop" need to actually handle the repositioning of the notes instead of the notes themselves? So far I'm unable to do this because the "notes" are intercepting the click events before the "desktop" receives them.
I haven't been able to find any of the samples that do something like this.
How do I correctly make something like a desktop component?
-
- In need of some credit
- Posts: 4
- Joined: Mon Jun 08, 2015 6:05 am
Re: How do I correctly make something like a desktop component?
That's the correct way to do this.However, when it comes to making them move along with the mouse, I have a feeling I'm about to go about it the wrong way. I was going to intercept the move event and have the "notes" follow the mouse.
Probably just a little bug with the coordinate calculations.But I think there's probably some problems with that, like if the mouse moves too quick.
Here's a relevant code snippet from the "shaped" sample that comes with wxWidgets. It should demonstrate what you need:
Code: Select all
void ShapedFrame::OnLeftDown(wxMouseEvent& evt)
{
CaptureMouse();
wxPoint pos = ClientToScreen(evt.GetPosition());
wxPoint origin = GetPosition();
int dx = pos.x - origin.x;
int dy = pos.y - origin.y;
m_delta = wxPoint(dx, dy);
}
void ShapedFrame::OnLeftUp(wxMouseEvent& WXUNUSED(evt))
{
if (HasCapture())
{
ReleaseMouse();
}
}
void ShapedFrame::OnMouseMove(wxMouseEvent& evt)
{
wxPoint pt = evt.GetPosition();
if (evt.Dragging() && evt.LeftIsDown())
{
wxPoint pos = ClientToScreen(pt);
Move(wxPoint(pos.x - m_delta.x, pos.y - m_delta.y));
}
}
Use the source, Luke!
-
- In need of some credit
- Posts: 4
- Joined: Mon Jun 08, 2015 6:05 am
Re: How do I correctly make something like a desktop component?
Oh awesome, CaptureMouse() is what does the trick. Thanks a lot.