+
+void LifeCanvas::OnScroll(wxScrollWinEvent& event)
+{
+ WXTYPE type = (WXTYPE)event.GetEventType();
+ int pos = event.GetPosition();
+ int orient = event.GetOrientation();
+
+ // calculate scroll increment
+ int scrollinc = 0;
+ if (type == wxEVT_SCROLLWIN_TOP)
+ {
+ if (orient == wxHORIZONTAL)
+ scrollinc = -m_viewportW;
+ else
+ scrollinc = -m_viewportH;
+ }
+ else
+ if (type == wxEVT_SCROLLWIN_BOTTOM)
+ {
+ if (orient == wxHORIZONTAL)
+ scrollinc = m_viewportW;
+ else
+ scrollinc = m_viewportH;
+ }
+ else
+ if (type == wxEVT_SCROLLWIN_LINEUP)
+ {
+ scrollinc = -1;
+ }
+ else
+ if (type == wxEVT_SCROLLWIN_LINEDOWN)
+ {
+ scrollinc = +1;
+ }
+ else
+ if (type == wxEVT_SCROLLWIN_PAGEUP)
+ {
+ scrollinc = -10;
+ }
+ else
+ if (type == wxEVT_SCROLLWIN_PAGEDOWN)
+ {
+ scrollinc = +10;
+ }
+ else
+ if (type == wxEVT_SCROLLWIN_THUMBTRACK)
+ {
+ if (orient == wxHORIZONTAL)
+ {
+ scrollinc = pos - m_thumbX;
+ m_thumbX = pos;
+ }
+ else
+ {
+ scrollinc = pos - m_thumbY;
+ m_thumbY = pos;
+ }
+ }
+ else
+ if (type == wxEVT_SCROLLWIN_THUMBRELEASE)
+ {
+ m_thumbX = m_viewportW;
+ m_thumbY = m_viewportH;
+ }
+
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+ // wxGTK and wxMotif update the thumb automatically (wxMSW doesn't);
+ // so reset it back as we always want it to be in the same position.
+ if (type != wxEVT_SCROLLWIN_THUMBTRACK)
+ {
+ SetScrollbar(wxHORIZONTAL, m_viewportW, m_viewportW, 3 * m_viewportW);
+ SetScrollbar(wxVERTICAL, m_viewportH, m_viewportH, 3 * m_viewportH);
+ }
+#endif
+
+ if (scrollinc == 0) return;
+
+ // scroll the window and adjust the viewport
+ if (orient == wxHORIZONTAL)
+ {
+ m_viewportX += scrollinc;
+ ScrollWindow( -m_cellsize * scrollinc, 0, (const wxRect *) NULL);
+ }
+ else
+ {
+ m_viewportY += scrollinc;
+ ScrollWindow( 0, -m_cellsize * scrollinc, (const wxRect *) NULL);
+ }
+}
+
+void LifeCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
+{
+ // do nothing. I just don't want the background to be erased, you know.
+}