home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / SliderCDEF 1.0 / SliderTester.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-10  |  2.6 KB  |  119 lines  |  [TEXT/KAHL]

  1. #include "SliderCDEF.h"
  2.  
  3. #define rCustomCtrl            128
  4. #define rMainWindow        128
  5.  
  6. #define kTop                53
  7. #define kLeft                13
  8. #define kWidth                400
  9. #define kHeight                16
  10. #define kTitleText            "\pSlider CDEF"
  11. #define kTitleTextLeft        153
  12. #define kTitleTextBottom        30
  13. #define kMessageText        "\pPress any key to quit"
  14. #define kMessageTextLeft        150
  15. #define kMessageTextBottom    90
  16.  
  17.  
  18. void DrawShadowText( Str255 theText, short h, short v  );
  19.  
  20. Boolean gQuit;
  21.  
  22. void main( void )
  23. {
  24.     WindowPtr    mainWindow, theWindow;
  25.     EventRecord    theEvent;
  26.     ControlHandle    sliderControl, theControl;
  27.     short        part;
  28.     Point            pt;
  29.     short        itemHit;
  30.     
  31.     gQuit = false;
  32.     InitGraf( &qd.thePort );
  33.     InitFonts();
  34.     InitWindows();
  35.     InitMenus();
  36.     TEInit();
  37.     InitDialogs( nil );
  38.     InitCursor();    
  39.  
  40.     mainWindow = GetNewCWindow( rMainWindow, nil, (WindowPtr) -1L );
  41.     SetPort( mainWindow) ;
  42.     ShowWindow( mainWindow );
  43.  
  44.     sliderControl = GetNewControl( rCustomCtrl,  mainWindow );
  45.     ShowControl( sliderControl );
  46.  
  47.     while( !gQuit ) {
  48.         if ( WaitNextEvent( everyEvent, &theEvent, 1, nil ) ) {
  49.             switch( theEvent.what ) {
  50.                 case mouseDown:
  51.                     part = FindWindow( theEvent.where, &theWindow );
  52.                     if ( part == inDrag ) {
  53.                         DragWindow( theWindow, theEvent.where, &(**(GetGrayRgn())).rgnBBox );
  54.                     } else if ( part == inContent ) {
  55.                         pt = theEvent.where;
  56.                         GlobalToLocal( &pt );
  57.                         SetPort( mainWindow) ;
  58.                         part = FindControl( pt, theWindow, &theControl );
  59.                         if ( part ) {
  60.                             TrackControl( theControl, pt, nil );
  61.                         }
  62.                     }
  63.                     break;
  64.                 case autoKey:
  65.                 case keyDown:
  66.                     gQuit = true;
  67.                     break;
  68.                 case updateEvt:
  69.                     // Get the window from the event's message field.
  70.                     theWindow = (WindowPtr) theEvent.message;
  71.                     
  72.                     // Begin updating.
  73.                     BeginUpdate( theWindow );
  74.                     
  75.                     // Set the pen to normal and set the font attributes.
  76.                     PenNormal();
  77.                     TextFont( helvetica );
  78.                     TextFace( bold + italic);
  79.  
  80.                     // Draw the title text.
  81.                     TextSize( 18 );                    
  82.                     DrawShadowText( kTitleText, kTitleTextLeft,
  83.                         kTitleTextBottom );
  84.  
  85.                     // Draw the message text.
  86.                     TextSize( 10 );
  87.                     DrawShadowText( kMessageText, kMessageTextLeft,
  88.                         kMessageTextBottom );
  89.  
  90.                     // Update the window's control (the slider).
  91.                     DrawControls( theWindow );
  92.  
  93.                     // End updating.
  94.                     EndUpdate( theWindow );
  95.                     break;
  96.             }
  97.         }
  98.     }
  99. }
  100.  
  101.  
  102.  
  103. // DrawShadowText
  104. //
  105. // Utility routine to draw 3-d appearing text.
  106. void DrawShadowText( Str255 theText, short h, short v  )
  107. {
  108.     RGBColor    color;
  109.     
  110.     color.red = color.blue = color.green = 0xFFFF;
  111.     RGBForeColor( &color );
  112.     MoveTo( h+1, v+1 );
  113.     DrawString( theText );
  114.  
  115.     color.red = color.blue = color.green = 0x0000;
  116.     RGBForeColor( &color );
  117.     MoveTo( h, v );
  118.     DrawString( theText );
  119. }