home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / starview / examples / dialog / colors.cxx < prev    next >
C/C++ Source or Header  |  1992-07-31  |  4KB  |  148 lines

  1. /*******************************************************************
  2. *  COLORS.CXX
  3. *  (c) 1992 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7.  
  8. #define FIXDX      50
  9. #define FIXDY      20
  10.  
  11. // --- class MyApp -------------------------------------------------
  12.  
  13. class MyApp : public Application
  14. {
  15. public:
  16.     virtual void Main( int, char*[] );
  17. };
  18.  
  19. // --- class ColorScrollBar ----------------------------------------
  20.  
  21. class ColorScrollBar : public AutoScrollBar
  22. {
  23. private:
  24.     USHORT  nColorId;
  25.  
  26. public:
  27.             ColorScrollBar( Window* pParent, USHORT nId ) :
  28.                 AutoScrollBar( pParent, WB_VSCROLL ),
  29.                 nColorId( nId ) {}
  30.  
  31.     USHORT  GetId() const { return nColorId; }
  32. };
  33.  
  34. // --- class ColorWindow -------------------------------------------
  35.  
  36. class ColorWindow : public WorkWindow
  37. {
  38. private:
  39.     USHORT          nColor[3];
  40.     FixedText*      pName[3];
  41.     FixedText*      pValue[3];
  42.     ColorScrollBar* pScrollBar[3];
  43.     Window          aColWindow;
  44.  
  45. public:
  46.                     ColorWindow();
  47.  
  48.     virtual void    Resize();
  49.     void            MoveHdl( ColorScrollBar* pScrollBar);
  50. };
  51.  
  52. // --- ColorWindow::ColorWindow() ----------------------------------
  53.  
  54. ColorWindow::ColorWindow() :
  55.                  WorkWindow( NULL, WB_APP | WB_STDWORK |
  56.                                    WB_CLIPCHILDREN ),
  57.                  aColWindow( this )
  58. {
  59.     aColWindow.ChangeBackgroundBrush( Brush( Color( COL_BLACK ) ) );
  60.     aColWindow.Show();
  61.  
  62.     for ( USHORT n = 0; n < 3; n++ )
  63.     {
  64.         nColor[n] = 0;
  65.  
  66.         pName[n] = new FixedText( this, WB_CENTER );
  67.         pName[n]->ChangeSizePixel( Size( FIXDX, FIXDY ) );
  68.         pName[n]->Show();
  69.  
  70.         pValue[n] = new FixedText( this, WB_CENTER );
  71.         pValue[n]->ChangeSizePixel( Size( FIXDX, FIXDY ) );
  72.         pValue[n]->SetText( "0" );
  73.         pValue[n]->Show();
  74.  
  75.         pScrollBar[n] = new ColorScrollBar( this, n );
  76.         pScrollBar[n]->ChangeThumbPos( 0 );
  77.         pScrollBar[n]->ChangePageSize( 16 );
  78.         pScrollBar[n]->ChangeRange( Range( 0, 255 ) );
  79.         pScrollBar[n]->ChangeLineMoveHdl(
  80.                            LINK( this, ColorWindow::MoveHdl ) );
  81.         pScrollBar[n]->ChangeThumbDragHdl(
  82.                            LINK( this, ColorWindow::MoveHdl ) );
  83.         pScrollBar[n]->ChangePageMoveHdl(
  84.                            LINK( this, ColorWindow::MoveHdl ) );
  85.         pScrollBar[n]->Show();
  86.     }
  87.  
  88.     pName[0]->SetText( "Red" );
  89.     pName[1]->SetText( "Green" );
  90.     pName[2]->SetText( "Blue" );
  91.  
  92.     SetText( "Colors" );
  93.     Show();
  94. }
  95.  
  96. // --- ColorWindow::MoveHdl() --------------------------------------
  97.  
  98. void ColorWindow::MoveHdl( ColorScrollBar* pScrollBar )
  99. {
  100.     nColor[pScrollBar->GetId()] +=
  101.         USHORT(256)*pScrollBar->GetDelta();
  102.     pValue[pScrollBar->GetId()]->
  103.         SetText( String( nColor[ pScrollBar->GetId() ] ) );
  104.     aColWindow.ChangeBackgroundBrush(
  105.         Brush( Color( nColor[0], nColor[1], nColor[2] ) ) );
  106.     aColWindow.Invalidate();
  107. }
  108.  
  109. // --- ColorWindow::Resize() ---------------------------------------
  110.  
  111. void ColorWindow::Resize()
  112. {
  113.     USHORT nSizeX = GetOutputSizePixel().Width();
  114.     USHORT nSizeY = GetOutputSizePixel().Height();
  115.     USHORT nDX = nSizeX/6;
  116.  
  117.     aColWindow.ChangeSizePixel( Size( nSizeX/2, nSizeY ) );
  118.     aColWindow.ChangePosPixel( Point( nSizeX/2, 0 ) );
  119.  
  120.     for ( USHORT n = 0; n < 3; n++ )
  121.     {
  122.         pName[n]->ChangePosPixel( Point( nDX*n+nDX/2-FIXDX/2,
  123.                                          0 ) );
  124.         pValue[n]->ChangePosPixel( Point( nDX*n+nDX/2-FIXDX/2,
  125.                                           nSizeY-FIXDY ) );
  126.         pScrollBar[n]->ChangePosPixel( Point( nDX*n+nDX/2-nSizeX/48,
  127.                                               FIXDY+5 ) );
  128.         pScrollBar[n]->ChangeSizePixel( Size( nSizeX/24,
  129.                                               nSizeY-2*FIXDY-10 ) );
  130.     }
  131. }
  132.  
  133. // --- MyApp::Main() -----------------------------------------------
  134.  
  135. void MyApp::Main( int, char*[] )
  136. {
  137.     ColorWindow aWindow;
  138.     Execute();
  139. }
  140.  
  141. // --- aMyApp ------------------------------------------------------
  142.  
  143. MyApp aMyApp;
  144.  
  145. #ifdef MAC
  146.     Application* pApp = &aMyApp;
  147. #endif
  148.