home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD2.mdf
/
c
/
library
/
starview
/
examples
/
output
/
metafile.cxx
< prev
Wrap
C/C++ Source or Header
|
1992-07-31
|
5KB
|
214 lines
/*******************************************************************
* METAFILE.CXX
* (c) 1992 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;
GDIMetaFile aMtf;
public:
MyWin();
virtual BOOL Close();
virtual void MouseButtonDown( const MouseEvent& rMEvt );
virtual void MouseButtonUp( const MouseEvent& rMEvt );
virtual void MouseMove( const MouseEvent& rMEvt );
virtual void Paint( const Rectangle& );
long ColorSelect( Menu* pMenu );
long WidthSelect( Menu* pMenu );
};
// --- MyWin::MyWin() ----------------------------------------------
MyWin::MyWin() : WorkWindow( NULL, WB_STDWORK | WB_APP )
{
nColor = 0;
nWidth = 0;
aMtf.Record( this );
aMtf.SaveStatus();
aMtf.Stop();
}
// --- 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();
aMtf.Record( this );
}
// --- MyWin::MouseButtonUp() --------------------------------------
void MyWin::MouseButtonUp( const MouseEvent& )
{
aMtf.Stop();
ReleaseMouse();
}
// --- MyWin::MouseMove() ------------------------------------------
void MyWin::MouseMove( const MouseEvent& rMEvt )
{
if ( rMEvt.GetMode() == MOUSE_SIMPLEDRAG )
{
DrawLine( aLastPoint, rMEvt.GetPosPixel() );
aLastPoint = rMEvt.GetPosPixel();
}
}
// --- MyWin::Paint() ----------------------------------------------
void MyWin::Paint( const Rectangle& )
{
aMtf.WindStart();
aMtf.Play( this );
}
// --- 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;
}
aMtf.Record( this );
ChangePen( aPen );
aMtf.Stop();
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;
}
aMtf.Record( this );
ChangePen( aPen );
aMtf.Stop();
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" );
aColorMenu.InsertItem( MID_PENBLUE, "~Blue" );
aColorMenu.InsertItem( MID_PENYELLOW, "~Yellow" );
aWidthMenu.InsertItem( MID_PENSMALL, "~Small" );
aWidthMenu.InsertItem( MID_PENMEDIUM, "~Medium" );
aWidthMenu.InsertItem( MID_PENTHICK, "~Large" );
aColorMenu.PushSelectHdl( LINK( &aMainWin,
MyWin::ColorSelect ) );
aWidthMenu.PushSelectHdl( LINK( &aMainWin,
MyWin::WidthSelect ) );
ChangeAppMenu( &aMenuBar );
aMainWin.SetText( "StarView Paint" );
aMainWin.Show();
Execute();
}
// --- aMyApp ------------------------------------------------------
MyApp aMyApp;
#ifdef MAC
Application* pApp = &aMyApp;
#endif