home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * COLORS.CXX
- * (c) 1992 STAR DIVISION
- *******************************************************************/
-
- #include <sv.hxx>
-
- #define FIXDX 50
- #define FIXDY 20
-
- // --- class MyApp -------------------------------------------------
-
- class MyApp : public Application
- {
- public:
- virtual void Main( int, char*[] );
- };
-
- // --- class ColorScrollBar ----------------------------------------
-
- class ColorScrollBar : public AutoScrollBar
- {
- private:
- USHORT nColorId;
-
- public:
- ColorScrollBar( Window* pParent, USHORT nId ) :
- AutoScrollBar( pParent, WB_VSCROLL ),
- nColorId( nId ) {}
-
- USHORT GetId() const { return nColorId; }
- };
-
- // --- class ColorWindow -------------------------------------------
-
- class ColorWindow : public WorkWindow
- {
- private:
- USHORT nColor[3];
- FixedText* pName[3];
- FixedText* pValue[3];
- ColorScrollBar* pScrollBar[3];
- Window aColWindow;
-
- public:
- ColorWindow();
-
- virtual void Resize();
- void MoveHdl( ColorScrollBar* pScrollBar);
- };
-
- // --- ColorWindow::ColorWindow() ----------------------------------
-
- ColorWindow::ColorWindow() :
- WorkWindow( NULL, WB_APP | WB_STDWORK |
- WB_CLIPCHILDREN ),
- aColWindow( this )
- {
- aColWindow.ChangeBackgroundBrush( Brush( Color( COL_BLACK ) ) );
- aColWindow.Show();
-
- for ( USHORT n = 0; n < 3; n++ )
- {
- nColor[n] = 0;
-
- pName[n] = new FixedText( this, WB_CENTER );
- pName[n]->ChangeSizePixel( Size( FIXDX, FIXDY ) );
- pName[n]->Show();
-
- pValue[n] = new FixedText( this, WB_CENTER );
- pValue[n]->ChangeSizePixel( Size( FIXDX, FIXDY ) );
- pValue[n]->SetText( "0" );
- pValue[n]->Show();
-
- pScrollBar[n] = new ColorScrollBar( this, n );
- pScrollBar[n]->ChangeThumbPos( 0 );
- pScrollBar[n]->ChangePageSize( 16 );
- pScrollBar[n]->ChangeRange( Range( 0, 255 ) );
- pScrollBar[n]->ChangeLineMoveHdl(
- LINK( this, ColorWindow::MoveHdl ) );
- pScrollBar[n]->ChangeThumbDragHdl(
- LINK( this, ColorWindow::MoveHdl ) );
- pScrollBar[n]->ChangePageMoveHdl(
- LINK( this, ColorWindow::MoveHdl ) );
- pScrollBar[n]->Show();
- }
-
- pName[0]->SetText( "Red" );
- pName[1]->SetText( "Green" );
- pName[2]->SetText( "Blue" );
-
- SetText( "Colors" );
- Show();
- }
-
- // --- ColorWindow::MoveHdl() --------------------------------------
-
- void ColorWindow::MoveHdl( ColorScrollBar* pScrollBar )
- {
- nColor[pScrollBar->GetId()] +=
- USHORT(256)*pScrollBar->GetDelta();
- pValue[pScrollBar->GetId()]->
- SetText( String( nColor[ pScrollBar->GetId() ] ) );
- aColWindow.ChangeBackgroundBrush(
- Brush( Color( nColor[0], nColor[1], nColor[2] ) ) );
- aColWindow.Invalidate();
- }
-
- // --- ColorWindow::Resize() ---------------------------------------
-
- void ColorWindow::Resize()
- {
- USHORT nSizeX = GetOutputSizePixel().Width();
- USHORT nSizeY = GetOutputSizePixel().Height();
- USHORT nDX = nSizeX/6;
-
- aColWindow.ChangeSizePixel( Size( nSizeX/2, nSizeY ) );
- aColWindow.ChangePosPixel( Point( nSizeX/2, 0 ) );
-
- for ( USHORT n = 0; n < 3; n++ )
- {
- pName[n]->ChangePosPixel( Point( nDX*n+nDX/2-FIXDX/2,
- 0 ) );
- pValue[n]->ChangePosPixel( Point( nDX*n+nDX/2-FIXDX/2,
- nSizeY-FIXDY ) );
- pScrollBar[n]->ChangePosPixel( Point( nDX*n+nDX/2-nSizeX/48,
- FIXDY+5 ) );
- pScrollBar[n]->ChangeSizePixel( Size( nSizeX/24,
- nSizeY-2*FIXDY-10 ) );
- }
- }
-
- // --- MyApp::Main() -----------------------------------------------
-
- void MyApp::Main( int, char*[] )
- {
- ColorWindow aWindow;
- Execute();
- }
-
- // --- aMyApp ------------------------------------------------------
-
- MyApp aMyApp;
-
- #ifdef MAC
- Application* pApp = &aMyApp;
- #endif
-