Scrolling updates.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3917 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -74,7 +74,6 @@ public:
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnOption(wxCommandEvent &event);
|
||||
void OnMouseMove(wxMouseEvent &event);
|
||||
|
||||
wxColour SelectColour();
|
||||
void PrepareDC(wxDC& dc);
|
||||
@@ -105,6 +104,7 @@ public:
|
||||
|
||||
void DrawTestLines( int x, int y, int width, wxDC &dc );
|
||||
void OnPaint(wxPaintEvent &event);
|
||||
void OnMouseMove(wxMouseEvent &event);
|
||||
|
||||
protected:
|
||||
MyFrame *m_owner;
|
||||
@@ -199,6 +199,7 @@ bool MyApp::OnInit()
|
||||
// handlers) which process them.
|
||||
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
||||
EVT_PAINT (MyCanvas::OnPaint)
|
||||
EVT_MOTION (MyCanvas::OnMouseMove)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
MyCanvas::MyCanvas( MyFrame *parent )
|
||||
@@ -307,6 +308,20 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
|
||||
|
||||
}
|
||||
|
||||
void MyCanvas::OnMouseMove(wxMouseEvent &event)
|
||||
{
|
||||
wxClientDC dc(this);
|
||||
PrepareDC(dc);
|
||||
m_owner->PrepareDC(dc);
|
||||
|
||||
wxPoint pos = event.GetPosition();
|
||||
long x = dc.DeviceToLogicalX( pos.x );
|
||||
long y = dc.DeviceToLogicalY( pos.y );
|
||||
wxString str;
|
||||
str.Printf( "Current mouse position: %d,%d", (int)x, (int)y );
|
||||
m_owner->SetStatusText( str );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyFrame
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -315,7 +330,6 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
|
||||
// handlers) which process them. It can be also done at run-time, but for the
|
||||
// simple menu events like this the static method is much simpler.
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MOTION (MyFrame::OnMouseMove)
|
||||
EVT_MENU (Minimal_Quit, MyFrame::OnQuit)
|
||||
EVT_MENU (Minimal_About, MyFrame::OnAbout)
|
||||
EVT_MENU_RANGE(MenuOption_First, MenuOption_Last, MyFrame::OnOption)
|
||||
@@ -504,19 +518,6 @@ void MyFrame::PrepareDC(wxDC& dc)
|
||||
dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed );
|
||||
}
|
||||
|
||||
void MyFrame::OnMouseMove(wxMouseEvent &event)
|
||||
{
|
||||
wxClientDC dc(this);
|
||||
PrepareDC(dc);
|
||||
|
||||
wxPoint pos = event.GetPosition();
|
||||
long x = dc.DeviceToLogicalX( pos.x );
|
||||
long y = dc.DeviceToLogicalY( pos.y );
|
||||
wxString str;
|
||||
str.Printf( "Current mouse position: %d,%d", (int)x, (int)y );
|
||||
SetStatusText( str );
|
||||
}
|
||||
|
||||
wxColour MyFrame::SelectColour()
|
||||
{
|
||||
wxColour col;
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
void OnDeleteButton( wxCommandEvent &event );
|
||||
void OnMoveButton( wxCommandEvent &event );
|
||||
void OnScrollWin( wxCommandEvent &event );
|
||||
void OnMouseDown( wxMouseEvent &event );
|
||||
|
||||
wxButton *m_button;
|
||||
|
||||
@@ -95,6 +96,7 @@ IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
|
||||
|
||||
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
||||
EVT_PAINT( MyCanvas::OnPaint)
|
||||
EVT_LEFT_DOWN( MyCanvas::OnMouseDown)
|
||||
EVT_BUTTON( ID_QUERYPOS, MyCanvas::OnQueryPosition)
|
||||
EVT_BUTTON( ID_ADDBUTTON, MyCanvas::OnAddButton)
|
||||
EVT_BUTTON( ID_DELBUTTON, MyCanvas::OnDeleteButton)
|
||||
@@ -174,20 +176,40 @@ MyCanvas::~MyCanvas()
|
||||
{
|
||||
}
|
||||
|
||||
void MyCanvas::OnMouseDown( wxMouseEvent &event )
|
||||
{
|
||||
wxPoint pt( event.GetPosition() );
|
||||
int x,y;
|
||||
CalcUnscrolledPosition( pt.x, pt.y, &x, &y );
|
||||
wxLogMessage( "Mouse down event at: %d %d, scrolled: %d %d", pt.x, pt.y, x, y );
|
||||
}
|
||||
|
||||
void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
{
|
||||
wxPaintDC dc( this );
|
||||
PrepareDC( dc );
|
||||
|
||||
dc.DrawText( "Press mouse button to test calculations!", 160, 50 );
|
||||
|
||||
dc.DrawText( "Some text", 140, 140 );
|
||||
|
||||
dc.DrawRectangle( 100, 160, 200, 200 );
|
||||
}
|
||||
|
||||
void MyCanvas::OnQueryPosition( wxCommandEvent &WXUNUSED(event) )
|
||||
{
|
||||
wxPoint pt( m_button->GetPosition() );
|
||||
wxLogMessage( """wxButton"" position %d %d", pt.x, pt.y );
|
||||
if ((pt.x == 10) && (pt.y == 110))
|
||||
wxLogMessage( "-> Correct." );
|
||||
else
|
||||
wxLogMessage( "-> Incorrect." );
|
||||
wxLogMessage( "Position of ""Query position"" is %d %d", pt.x, pt.y );
|
||||
pt = ClientToScreen( pt );
|
||||
wxLogMessage( "Position of ""Query position"" on screen is %d %d", pt.x, pt.y );
|
||||
}
|
||||
|
||||
void MyCanvas::OnAddButton( wxCommandEvent &WXUNUSED(event) )
|
||||
{
|
||||
wxLogMessage( "Inserting button at position 10,70..." );
|
||||
(void) new wxButton( this, ID_NEWBUTTON, "new button", wxPoint(10,70), wxSize(80,25) );
|
||||
wxButton *button = new wxButton( this, ID_NEWBUTTON, "new button", wxPoint(10,70), wxSize(80,25) );
|
||||
wxPoint pt( button->GetPosition() );
|
||||
wxLogMessage( "-> Position after inserting %d %d", pt.x, pt.y );
|
||||
}
|
||||
|
||||
void MyCanvas::OnDeleteButton( wxCommandEvent &event )
|
||||
@@ -204,7 +226,11 @@ void MyCanvas::OnMoveButton( wxCommandEvent &event )
|
||||
{
|
||||
wxLogMessage( "Moving button 10 pixels downward.." );
|
||||
wxWindow *win = FindWindow( event.GetId() );
|
||||
win->Move( -1, win->GetPosition().y + 10 );
|
||||
wxPoint pt( win->GetPosition() );
|
||||
wxLogMessage( "-> Position before move is %d %d", pt.x, pt.y );
|
||||
win->Move( -1, pt.y + 10 );
|
||||
pt = win->GetPosition();
|
||||
wxLogMessage( "-> Position after move is %d %d", pt.x, pt.y );
|
||||
}
|
||||
|
||||
void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
|
||||
@@ -215,18 +241,6 @@ void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
|
||||
Scroll( -1, y+2 );
|
||||
}
|
||||
|
||||
void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
{
|
||||
wxPaintDC dc( this );
|
||||
PrepareDC( dc );
|
||||
|
||||
dc.DrawText( "Some text", 140, 140 );
|
||||
|
||||
dc.DrawRectangle( 10, 70, 80, 25 );
|
||||
|
||||
dc.DrawRectangle( 100, 160, 200, 200 );
|
||||
}
|
||||
|
||||
// MyFrame
|
||||
|
||||
const int ID_QUIT = 108;
|
||||
|
||||
Reference in New Issue
Block a user