home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / starview / examples / input / connect.cxx < prev   
Encoding:
C/C++ Source or Header  |  1992-08-01  |  2.4 KB  |  100 lines

  1. /*******************************************************************
  2. *  CONNECT.CXX
  3. *  (c) 1992 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. #define MAXPOINTS 500
  9.  
  10. // --- class MyApp -------------------------------------------------
  11.  
  12. class MyApp : public Application
  13. {
  14. public:
  15.     virtual void Main( int, char*[] );
  16. };
  17.  
  18. // --- class ConnectWindow -----------------------------------------
  19.  
  20. class ConnectWindow : public WorkWindow
  21. {
  22. private:
  23.     Point           aPointArray[MAXPOINTS];
  24.     short           nPointCount;
  25.  
  26. public:
  27.                     ConnectWindow();
  28.  
  29.     virtual void    MouseButtonDown( const MouseEvent& );
  30.     virtual void    MouseMove( const MouseEvent& );
  31.     virtual void    MouseButtonUp( const MouseEvent& );
  32.     virtual void    Paint( const Rectangle& );
  33. };
  34.  
  35. // --- ConnectWindow::ConnectWindow() ------------------------------
  36.  
  37. ConnectWindow::ConnectWindow() :
  38.                 WorkWindow( NULL, WB_APP | WB_STDWORK )
  39. {
  40.     nPointCount = 0;
  41.     SetText( "Connect" );
  42.     Show();
  43. }
  44.  
  45. // --- ConnectWindow::MouseMove() ----------------------------------
  46.  
  47. void ConnectWindow::MouseMove( const MouseEvent& rMEvt )
  48. {
  49.     if ( (rMEvt.GetMode() == MOUSE_SIMPLEDRAG) &&
  50.          (nPointCount < MAXPOINTS) )
  51.     {
  52.         aPointArray[nPointCount] = rMEvt.GetPosPixel();
  53.         DrawPoint( aPointArray[nPointCount] );
  54.         nPointCount++;
  55.     }
  56. }
  57.  
  58. // --- ConnectWindow::MouseButtonDown() ----------------------------
  59.  
  60. void ConnectWindow::MouseButtonDown( const MouseEvent& )
  61. {
  62.     nPointCount = 0;
  63.     Invalidate();
  64.     Update();
  65.     CaptureMouse();
  66. }
  67.  
  68. // --- ConnectWindow::MouseButtonUp() ------------------------------
  69.  
  70. void ConnectWindow::MouseButtonUp( const MouseEvent& )
  71. {
  72.     ReleaseMouse();
  73.     Invalidate();
  74. }
  75.  
  76. // --- ConnectWindow::Paint() --------------------------------------
  77.  
  78. void ConnectWindow::Paint( const Rectangle& )
  79. {
  80.     for ( short i = 0; i < (nPointCount-1); i++ )
  81.         for ( short j = 0; j < nPointCount; j++ )
  82.             DrawLine( aPointArray[i], aPointArray[j] );
  83. }
  84.  
  85. // --- MyApp:Main() ------------------------------------------------
  86.  
  87. void MyApp::Main( int, char*[] )
  88. {
  89.     ConnectWindow aWindow;
  90.     Execute();
  91. }
  92.  
  93. // --- aMyApp ------------------------------------------------------
  94.  
  95. MyApp aMyApp;
  96.  
  97. #ifdef MAC
  98.     Application* pApp = &aMyApp;
  99. #endif
  100.