www.pudn.com > source.zip > MySW.cpp


#include "gui.h" 
 
void MyScrolledWindow::SetBmp(wxImage *_bmp)  
{ 
  xDst = yDst = 0; 
  // center if image is smaller than the window 
  if (_bmp!=NULL) 
    { 
      if (_bmp->GetWidth() < 200) xDst = (200-_bmp->GetWidth())/2; 
      if (_bmp->GetHeight() < 200) yDst = (200-_bmp->GetHeight())/2; 
      memDC.SelectObject(*_bmp); 
    } 
  bmp = _bmp;  
} 
 
	 
void MyScrolledWindow::OnDraw(wxDC& dc) 
{ 
  if (bmp != NULL) 
    { 
      // determine which part of the image is visible in the window. 
      int x, y; 
      GetViewStart(&x, &y); 
      x *= 10; y *= 10;	   // must be multiplied by ScrollUnit 
      // copy the visible part into the window 
      int _xDst, _yDst; 
      CalcUnscrolledPosition(xDst, yDst, &_xDst, &_yDst); 
      dc.Blit(_xDst, _yDst, 200, 200, &memDC, x, y); 
       
      // draw the training rectangle on the input image     
	  MyFrame *parent = (MyFrame *)GetParent(); 
      if (parent->GetInputWindow() == this) 
	{ 
	  int x1, y1, w, h; 
	  parent->GetRegion(x1, y1, w, h); 
	  if (x1!=0 || y1!=0 || w!=0 || h!=0) 
	    { 
	      wxPen pen(*wxGREEN_PEN); 
	      wxBrush brush(*wxTRANSPARENT_BRUSH); 
	      dc.SetPen(pen); 
	      dc.SetBrush(brush); 
	      dc.DrawRectangle(x1+xDst, y1+yDst, w, h); 
	    } 
	} 
    } 
} 
 
void MyScrolledWindow::OnMouseMotion(wxMouseEvent& event) 
{ 
  if (event.LeftIsDown()) 
    { 
      // comvert window coordinates to image coordinates 
      int x, y; 
      GetViewStart(&x, &y); 
      x *= 10; y *= 10;		// must be multiplied by ScrollUnit 
      MyFrame *frame = (MyFrame *)GetParent(); 
      if (frame->GetActRegion() != -1)		// in this case regs != NULL 
	{ 
	  if (event.m_x >= xDst && event.m_x < xDst+bmp->GetWidth() && 
	      event.m_y >= yDst && event.m_y < yDst+bmp->GetHeight()) 
	    frame->SetRegs2(event.m_x+x-xDst, event.m_y+y-yDst); // scroll added 
	  Refresh(); 
		} 
	} 
} 
 
void MyScrolledWindow::OnLeftDown(wxMouseEvent& event) 
{ 
  // comvert window coordinates to image coordinates 
  int x, y; 
  GetViewStart(&x, &y); 
  x *= 10; y *= 10;	 // must be multiplied by ScrollUnit 
 
  MyFrame *frame = (MyFrame *)GetParent(); 
  if (frame->GetActRegion() != -1)	// in this case regs != NULL 
    { 
      if (event.m_x >= xDst && event.m_x < xDst+bmp->GetWidth() && 
	  event.m_y >= yDst && event.m_y < yDst+bmp->GetHeight()) 
	frame->SetRegs1(event.m_x+x-xDst, event.m_y+y-yDst); // scroll added 
	} 
}