home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * EXAMPLE2.CXX
- * (c) 1992-1994 STAR DIVISION
- *******************************************************************/
-
- #include <sv.hxx>
-
- #define MID_PENCOLOR 10
- #define MID_PENRED 11
- #define MID_PENBLUE 12
- #define MID_PENYELLOW 13
- #define MID_PENWIDTH 20
- #define MID_PENSMALL 21
- #define MID_PENMEDIUM 22
- #define MID_PENTHICK 23
-
- // --- class MyApp -------------------------------------------------
-
- class MyApp : public Application
- {
- public:
- virtual void Main( int, char*[] );
- };
-
- // --- class MyWin -------------------------------------------------
-
- class MyWin : public WorkWindow
- {
- private:
- USHORT nColor;
- USHORT nWidth;
- Point aLastPoint;
-
- public:
- MyWin();
-
- virtual BOOL Close();
- virtual void MouseButtonDown( const MouseEvent& rMEvt );
- virtual void MouseButtonUp( const MouseEvent& rMEvt );
- virtual void MouseMove( const MouseEvent& rMEvt );
-
- long ColorSelect( Menu* pMenu );
- long WidthSelect( Menu* pMenu );
- };
-
- // --- MyWin::MyWin() ----------------------------------------------
-
- MyWin::MyWin() : WorkWindow( NULL, WB_STDWORK | WB_APP )
- {
- nColor = 0;
- nWidth = 0;
- }
-
- // --- MyWin::Close() ----------------------------------------------
-
- BOOL MyWin::Close()
- {
- QueryBox aBox( this, WB_OK_CANCEL | WB_DEF_OK, "Exit Paint" );
-
- if ( aBox.Execute() == RET_OK )
- return WorkWindow::Close();
- else
- return FALSE;
- }
-
- // --- MyWin::MouseButtonDown() ------------------------------------
-
- void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
- {
- CaptureMouse();
- aLastPoint = rMEvt.GetPosPixel();
- }
-
- // --- MyWin::MouseButtonUp() --------------------------------------
-
- void MyWin::MouseButtonUp( const MouseEvent& )
- {
- ReleaseMouse();
- }
-
- // --- MyWin::MouseMove() ------------------------------------------
-
- void MyWin::MouseMove( const MouseEvent& rMEvt )
- {
- if ( rMEvt.IsLeft() )
- {
- DrawLine( aLastPoint, rMEvt.GetPosPixel() );
- aLastPoint = rMEvt.GetPosPixel();
- }
- }
-
- // --- MyWin::ColorSelect() ----------------------------------------
-
- long MyWin::ColorSelect( Menu* pMenu )
- {
- if ( nColor )
- pMenu->CheckItem( nColor, FALSE );
- nColor = pMenu->GetCurItemId();
- pMenu->CheckItem( nColor );
-
- Pen aPen = GetPen();
- switch( nColor )
- {
- case MID_PENRED:
- aPen.ChangeColor( Color( COL_RED ) );
- break;
- case MID_PENBLUE:
- aPen.ChangeColor( Color( COL_BLUE ) );
- break;
- case MID_PENYELLOW:
- aPen.ChangeColor( Color( COL_YELLOW ) );
- break;
- }
- ChangePen( aPen );
-
- return TRUE;
- }
-
- // --- MyWin::WidthSelect() ----------------------------------------
-
- long MyWin::WidthSelect( Menu* pMenu )
- {
- if ( nWidth )
- pMenu->CheckItem( nWidth, FALSE );
- nWidth = pMenu->GetCurItemId();
- pMenu->CheckItem( nWidth );
-
- Pen aPen = GetPen();
- switch ( nWidth )
- {
- case MID_PENSMALL:
- aPen.ChangeWidth( 1 );
- break;
- case MID_PENMEDIUM:
- aPen.ChangeWidth( 4 );
- break;
- case MID_PENTHICK:
- aPen.ChangeWidth( 8 );
- break;
- }
- ChangePen( aPen );
-
- return TRUE;
- }
-
- // --- MyApp::Main() -----------------------------------------------
-
- void MyApp::Main( int, char*[] )
- {
- MyWin aMainWin;
-
- PopupMenu aColorMenu;
- PopupMenu aWidthMenu;
- MenuBar aMenuBar;
-
- aMenuBar.InsertItem( MID_PENCOLOR, "~Color" );
- aMenuBar.InsertItem( MID_PENWIDTH, "~Width" );
-
- aMenuBar.ChangePopupMenu( MID_PENCOLOR, &aColorMenu );
- aMenuBar.ChangePopupMenu( MID_PENWIDTH, &aWidthMenu );
-
- aColorMenu.InsertItem( MID_PENRED, "~Red",
- MENU_APPEND, MIB_CHECKABLE );
- aColorMenu.InsertItem( MID_PENBLUE, "~Blue",
- MENU_APPEND, MIB_CHECKABLE );
- aColorMenu.InsertItem( MID_PENYELLOW, "~Yellow",
- MENU_APPEND, MIB_CHECKABLE );
-
- aWidthMenu.InsertItem( MID_PENSMALL, "~Small",
- MENU_APPEND, MIB_CHECKABLE );
- aWidthMenu.InsertItem( MID_PENMEDIUM, "~Medium",
- MENU_APPEND, MIB_CHECKABLE );
- aWidthMenu.InsertItem( MID_PENTHICK, "~Large",
- MENU_APPEND, MIB_CHECKABLE );
-
- aColorMenu.PushSelectHdl( LINK( &aMainWin,
- MyWin, ColorSelect ) );
- aWidthMenu.PushSelectHdl( LINK( &aMainWin,
- MyWin, WidthSelect ) );
-
- ChangeAppMenu( &aMenuBar );
-
- aMainWin.SetText( "StarView Paint" );
- aMainWin.Show();
-
- Execute();
- }
-
- // --- aMyApp ------------------------------------------------------
-
- MyApp aMyApp;
-