Like when I draw a rectangle over the bitmap,
and after the left button is up it turns it into something like this,
representing a selected area.
I have tried doing this,
In the mouse motion handler,
Code: Select all
if (event.ControlDown())
{
// int x,y;
// event.GetPosition(&x,&y);
// wxScrolledWindow sw(this);
// sw.CalcUnscrolledPosition(x, y, &xx, &yy);
m_CurrentPoint = wxPoint(pos.x , pos.y) ;
wxRect rect (m_AnchorPoint, m_CurrentPoint) ;
wxClientDC dc(this) ;
PrepareDC(dc) ;
wxDCOverlay overlaydc(m_Overlay, &dc);
overlaydc.Clear();
dc.SetPen(wxPen(*wxLIGHT_GREY, 2));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(rect);
}
Code: Select all
if (event.ControlDown())
{
// int x,y;
// event.GetPosition(&x,&y);
// wxScrolledWindow sw(this);
// sw.CalcUnscrolledPosition(x, y, &xx, &yy);
// m_AnchorPoint = wxPoint(xx, yy) ;
m_CurrentPoint = wxPoint(pos.x, pos.y);
// m_rubberBand = true ;
CaptureMouse();
SetCursor(wxCURSOR_CLOSED_HAND);
wxLogDebug("Control pressed");
}
else
{
SetCursor(wxCURSOR_ARROW);
return;
}
Code: Select all
if (event.ControlDown())
{
wxLogDebug("Control pressed");
ReleaseMouse();
{
wxClientDC dc(this);
PrepareDC(dc);
wxDCOverlay overlaydc(m_Overlay, &dc);
overlaydc.Clear();
}
m_Overlay.Reset();
// m_rubberBand = false;
// wxScrolledWindow sw;
// wxPoint endpoint = sw.CalcUnscrolledPosition(event.GetPosition());
// Don't pop up the message box if nothing was actually selected.
// if ( endpoint != m_AnchorPoint )
// {
// wxLogMessage("Selected rectangle from (%d, %d) to (%d, %d)",
// m_AnchorPoint.x, m_AnchorPoint.y,
// endpoint.x, endpoint.y);
m_AnchorPoint = m_CurrentPoint;
m_CurrentPoint = wxPoint(pos.x, 0);
DrawSelectionArea(m_AnchorPoint.x, m_CurrentPoint.y, m_CurrentPoint.x - m_AnchorPoint.x, this->GetSize().GetHeight());
// }
}
Code: Select all
void WaveformViewer::DrawSelectionArea(int xx, int yy, int ww, int hh)
{
wxClientDC dc(this);
dc.SetPen(wxPen(wxColour(200, 200, 200, 100), 2, wxPENSTYLE_SOLID));
// dc.SetPen(*wxTRANSPARENT_PEN);
// dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(wxRect(xx, yy, ww, hh));
}
The code is incomplete and some calculations are wrong as I copied the code from the sample drawing program, however it uses a method CalcUnscrolledPosition() which a method of wxScrolledWindow, but I am drawing on wxPanel, what should be the equivalent of this method for wxPanel?
Also it starts drawing the rectangle as soon as I press CTRL but I only want to drawn when CTRL+LMB is pressed, and stop at the position where LMB is up.