home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / CIT.v4 / Demo / TimerTest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  1.5 KB  |  88 lines

  1. #include <CITTimer.h>
  2. #include <CITGroup.h>
  3. #include <CITButton.h>
  4. #include <CITFuelGauge.h>
  5.  
  6. CITApp Application;
  7.  
  8. CITTimer     timer;
  9. CITWorkbench DemoScreen;
  10. CITWindow    DemoWindow;
  11. CITVGroup    winGroup;
  12. CITFuelGauge fuel;
  13. CITButton    quitButton;
  14.  
  15.  
  16. void timerEvent();
  17. void CloseEvent();
  18. void QuitEvent(ULONG ID);
  19.  
  20. int main(void)
  21. {
  22.   BOOL Error=FALSE;
  23.  
  24.   DemoScreen.InsObject(DemoWindow,Error);
  25.     DemoWindow.Position(WPOS_CENTERSCREEN);
  26.     DemoWindow.CloseGadget();
  27.     DemoWindow.DragBar();
  28.     DemoWindow.SizeGadget();
  29.     DemoWindow.DepthGadget();
  30.     DemoWindow.IconifyGadget();
  31.     DemoWindow.Activate();
  32.     DemoWindow.Caption("CITTimer Test");
  33.     DemoWindow.CloseEventHandler(CloseEvent);
  34.     DemoWindow.InsObject(winGroup,Error);
  35.       winGroup.SpaceOuter();
  36.       winGroup.InsObject(fuel,Error);
  37.         fuel.LabelText("Level");
  38.       winGroup.InsObject(quitButton,Error);
  39.         quitButton.Text("Quit");
  40.         quitButton.MaxHeight(30);
  41.         quitButton.EventHandler(QuitEvent);
  42.  
  43.   Application.InsObject(timer,Error);
  44.   Application.InsObject(DemoScreen,Error);
  45.  
  46.   // Ok?
  47.   if( Error )
  48.     return 10;
  49.  
  50.   timer.AddEvent(0.2,timerEvent,0);
  51.  
  52.   Application.Run();
  53.  
  54.   return 0;
  55. }
  56.  
  57.  
  58. int value = 0;
  59. int step  = 1;
  60.  
  61. void timerEvent()
  62. {
  63.   value += step;
  64.   if( value > 100 )
  65.   {
  66.     step = -step;
  67.     value = 100 + step;
  68.   }
  69.   else if( value < 0 )
  70.   {
  71.     step = -step;
  72.     value = step;
  73.   }
  74.  
  75.   fuel.Level(value);
  76.   timer.AddEvent(0.2,timerEvent,0);
  77. }
  78.  
  79. void QuitEvent(ULONG ID)
  80. {
  81.   Application.Stop();
  82. }
  83.  
  84. void CloseEvent()
  85. {
  86.   Application.Stop();
  87. }
  88.