home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / wntmsci / german / example2.cx_ / EXAMPLE2.CXX
Encoding:
C/C++ Source or Header  |  1994-01-18  |  4.9 KB  |  192 lines

  1. /*******************************************************************
  2. *  EXAMPLE2.CXX
  3. *  (c) 1992-1994 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. #define MID_PENCOLOR  10
  9. #define MID_PENRED    11
  10. #define MID_PENBLUE   12
  11. #define MID_PENYELLOW 13
  12. #define MID_PENWIDTH  20
  13. #define MID_PENSMALL  21
  14. #define MID_PENMEDIUM 22
  15. #define MID_PENTHICK  23
  16.  
  17. // --- class MyApp -------------------------------------------------
  18.  
  19. class MyApp : public Application
  20. {
  21. public:
  22.     virtual void Main( int, char*[] );
  23. };
  24.  
  25. // --- class MyWin -------------------------------------------------
  26.  
  27. class MyWin : public WorkWindow
  28. {
  29. private:
  30.     USHORT          nColor;
  31.     USHORT          nWidth;
  32.     Point           aLastPoint;
  33.  
  34. public:
  35.                     MyWin();
  36.  
  37.     virtual BOOL    Close();
  38.     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
  39.     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
  40.     virtual void    MouseMove( const MouseEvent& rMEvt );
  41.  
  42.     long            ColorSelect( Menu* pMenu );
  43.     long            WidthSelect( Menu* pMenu );
  44. };
  45.  
  46. // --- MyWin::MyWin() ----------------------------------------------
  47.  
  48. MyWin::MyWin() : WorkWindow( NULL, WB_STDWORK | WB_APP )
  49. {
  50.     nColor = 0;
  51.     nWidth = 0;
  52. }
  53.  
  54. // --- MyWin::Close() ----------------------------------------------
  55.  
  56. BOOL MyWin::Close()
  57. {
  58.     QueryBox aBox( this, WB_OK_CANCEL | WB_DEF_OK, "Exit Paint" );
  59.  
  60.     if ( aBox.Execute() == RET_OK )
  61.         return WorkWindow::Close();
  62.     else
  63.         return FALSE;
  64. }
  65.  
  66. // --- MyWin::MouseButtonDown() ------------------------------------
  67.  
  68. void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
  69. {
  70.     CaptureMouse();
  71.     aLastPoint = rMEvt.GetPosPixel();
  72. }
  73.  
  74. // --- MyWin::MouseButtonUp() --------------------------------------
  75.  
  76. void MyWin::MouseButtonUp( const MouseEvent& )
  77. {
  78.     ReleaseMouse();
  79. }
  80.  
  81. // --- MyWin::MouseMove() ------------------------------------------
  82.  
  83. void MyWin::MouseMove( const MouseEvent& rMEvt )
  84. {
  85.     if ( rMEvt.IsLeft() )
  86.     {
  87.         DrawLine( aLastPoint, rMEvt.GetPosPixel() );
  88.         aLastPoint = rMEvt.GetPosPixel();
  89.     }
  90. }
  91.  
  92. // --- MyWin::ColorSelect() ----------------------------------------
  93.  
  94. long MyWin::ColorSelect( Menu* pMenu )
  95. {
  96.     if ( nColor )
  97.         pMenu->CheckItem( nColor, FALSE );
  98.     nColor = pMenu->GetCurItemId();
  99.     pMenu->CheckItem( nColor );
  100.  
  101.     Pen aPen = GetPen();
  102.     switch( nColor )
  103.     {
  104.         case MID_PENRED:
  105.              aPen.ChangeColor( Color( COL_RED ) );
  106.              break;
  107.         case MID_PENBLUE:
  108.              aPen.ChangeColor( Color( COL_BLUE ) );
  109.              break;
  110.         case MID_PENYELLOW:
  111.              aPen.ChangeColor( Color( COL_YELLOW ) );
  112.              break;
  113.     }
  114.     ChangePen( aPen );
  115.  
  116.     return TRUE;
  117. }
  118.  
  119. // --- MyWin::WidthSelect() ----------------------------------------
  120.  
  121. long MyWin::WidthSelect( Menu* pMenu )
  122. {
  123.     if ( nWidth )
  124.         pMenu->CheckItem( nWidth, FALSE );
  125.     nWidth = pMenu->GetCurItemId();
  126.     pMenu->CheckItem( nWidth );
  127.  
  128.     Pen aPen = GetPen();
  129.     switch ( nWidth )
  130.     {
  131.         case MID_PENSMALL:
  132.             aPen.ChangeWidth( 1 );
  133.             break;
  134.         case MID_PENMEDIUM:
  135.             aPen.ChangeWidth( 4 );
  136.             break;
  137.         case MID_PENTHICK:
  138.             aPen.ChangeWidth( 8 );
  139.             break;
  140.     }
  141.     ChangePen( aPen );
  142.  
  143.     return TRUE;
  144. }
  145.  
  146. // --- MyApp::Main() -----------------------------------------------
  147.  
  148. void MyApp::Main( int, char*[] )
  149. {
  150.     MyWin       aMainWin;
  151.  
  152.     PopupMenu   aColorMenu;
  153.     PopupMenu   aWidthMenu;
  154.     MenuBar     aMenuBar;
  155.  
  156.     aMenuBar.InsertItem( MID_PENCOLOR, "~Color" );
  157.     aMenuBar.InsertItem( MID_PENWIDTH, "~Width" );
  158.  
  159.     aMenuBar.ChangePopupMenu( MID_PENCOLOR, &aColorMenu );
  160.     aMenuBar.ChangePopupMenu( MID_PENWIDTH, &aWidthMenu );
  161.  
  162.     aColorMenu.InsertItem( MID_PENRED, "~Red",
  163.                            MENU_APPEND, MIB_CHECKABLE );
  164.     aColorMenu.InsertItem( MID_PENBLUE, "~Blue",
  165.                            MENU_APPEND, MIB_CHECKABLE );
  166.     aColorMenu.InsertItem( MID_PENYELLOW, "~Yellow",
  167.                            MENU_APPEND, MIB_CHECKABLE );
  168.  
  169.     aWidthMenu.InsertItem( MID_PENSMALL, "~Small",
  170.                            MENU_APPEND, MIB_CHECKABLE );
  171.     aWidthMenu.InsertItem( MID_PENMEDIUM, "~Medium",
  172.                            MENU_APPEND, MIB_CHECKABLE );
  173.     aWidthMenu.InsertItem( MID_PENTHICK, "~Large",
  174.                            MENU_APPEND, MIB_CHECKABLE );
  175.  
  176.     aColorMenu.PushSelectHdl( LINK( &aMainWin,
  177.                                     MyWin, ColorSelect ) );
  178.     aWidthMenu.PushSelectHdl( LINK( &aMainWin,
  179.                                     MyWin, WidthSelect ) );
  180.  
  181.     ChangeAppMenu( &aMenuBar );
  182.  
  183.     aMainWin.SetText( "StarView Paint" );
  184.     aMainWin.Show();
  185.  
  186.     Execute();
  187. }
  188.  
  189. // --- aMyApp ------------------------------------------------------
  190.  
  191. MyApp aMyApp;
  192.