home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / segal / timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-21  |  4.1 KB  |  176 lines

  1. /*
  2.  *    timer.c - for use with SEGAL
  3.  *
  4.  *    By Bryan Skene
  5.  *
  6.  *    Usage:
  7.  *    1. strcpy a message into timer.message
  8.  *    2. call begin timer()
  9.  *    3. at various intervals, call set_timer(percentage_done)
  10.  *    4. when 100% done, call end_timer()
  11.  */
  12.  
  13. #include "common.h"
  14.  
  15. /*****************************************/
  16. void
  17. begin_itimer(sec, usec)
  18. int sec, usec;
  19. {
  20.     itimer.it_value.tv_sec = sec;
  21.     itimer.it_interval.tv_sec = sec;
  22.     itimer.it_value.tv_usec = usec;
  23.     itimer.it_interval.tv_usec = usec;
  24. }
  25.  
  26. /******************************************/
  27. LOGIC
  28. begin_timer()
  29. {
  30.     unsigned long standout();
  31.     void set_timer();
  32.  
  33.     if(timer.semaphore == LOCKED) return(FALSE);
  34.  
  35.     timer.semaphore = LOCKED;
  36.  
  37.     xv_set(View_pop_timer->pop_timer,
  38.         XV_SHOW, TRUE,
  39.         NULL);
  40.     xv_set(View_pop_timer->msg_timer,
  41.         PANEL_LABEL_STRING, timer.message,
  42.         NULL);
  43.  
  44.     timer.width = (int) xv_get(View_pop_timer->canv_timer,
  45.         XV_WIDTH, NULL);
  46.     timer.height = (int) xv_get(View_pop_timer->canv_timer,
  47.         XV_HEIGHT, NULL);
  48.  
  49.     XSetForeground(display, gc, standout(CWHITE));
  50.     XFillRectangle(display, timer.xid, gc,
  51.         0, 0,
  52.         timer.width, timer.height);
  53.  
  54.     set_timer(0.0);
  55.  
  56.     return(TRUE);
  57. }
  58.  
  59. /******************************************/
  60. void
  61. set_timer(percent)
  62. float percent;
  63. {
  64.     unsigned long standout();
  65.  
  66.     XSetForeground(display, gc, standout(PURPLE));
  67.     XFillRectangle(display, timer.xid, gc,
  68.         0, 0,
  69.         (int) ((float) timer.width * percent), timer.height);
  70. }
  71.  
  72. /******************************************/
  73. void
  74. end_timer()
  75. {
  76.     xv_set(View_pop_timer->pop_timer,
  77.         XV_SHOW, FALSE,
  78.         NULL);
  79.  
  80.     timer.semaphore = UNLOCKED;
  81. }
  82.  
  83. /******************************************/
  84. void
  85. timer_resize_proc()
  86. {
  87.     timer.width = (int) xv_get(View_pop_timer->pop_timer,
  88.         XV_WIDTH, NULL);
  89.  
  90.     xv_set(View_pop_timer->canv_timer,
  91.         XV_WIDTH, timer.width,
  92.         NULL);
  93. }
  94.  
  95. /******************************************/
  96. void
  97. enq_bg_job(job, arg)
  98. int job, arg;
  99. {
  100. /* Enter a job into the background queue because there is already a job
  101.  * running in the bg.
  102.  */
  103.     timer.queue[timer.qrear].job = job;
  104.     timer.queue[timer.qrear].arg = arg;
  105.  
  106.     timer.qrear++;
  107.     if(timer.qrear == MAX_JOBS) timer.qrear = 0;
  108. }
  109.  
  110. /******************************************/
  111. void
  112. deq_bg_job()
  113. {
  114. /* If there is a bg job in the queue, setup the appropriate values and then
  115.  * invoke notify_set_itimer_func().  If not, turn off the bg job stuff.
  116.  * Called at the completion of a bg job.
  117.  */
  118.     Notify_value bg_load_image_frame();
  119.     Notify_value bg_load_mask_frame();
  120.     Notify_value bg_save_image_frame();
  121.     Notify_value bg_save_mask_frame();
  122.     LOGIC begin_timer();
  123.  
  124.     if(timer.qfront == timer.qrear) return;
  125.  
  126.     begin_itimer(INTERVAL_SEC, INTERVAL_uSEC);
  127.  
  128.     switch(timer.queue[timer.qfront].job) {
  129.     case JOB_LOAD_IMAGE :
  130.         segal.bg_i = segal.f1;
  131.         begin_itimer(INTERVAL_SEC, INTERVAL_uSEC);
  132.         sprintf(timer.message, "Loading frames: %s ...", img.fname);
  133.         notify_set_itimer_func(File_pop_load_image->pop_load_image,
  134.             bg_load_image_frame, ITIMER_REAL, &itimer, NULL);
  135.         break;
  136.     case JOB_LOAD_MASK :
  137.         segal.new_m = timer.queue[timer.qfront].arg;
  138.         m[segal.new_m].f = 0;
  139.         begin_itimer(INTERVAL_SEC, INTERVAL_uSEC);
  140.         sprintf(timer.message, "Loading frames: %s ...", m[segal.new_m].fname);
  141.         notify_set_itimer_func(File_pop_load_mask->pop_load_mask,
  142.             bg_load_mask_frame, ITIMER_REAL, &itimer, NULL);
  143.         break;
  144.     case JOB_SAVE_IMAGE :
  145.         segal.bg_i = 0;
  146.         begin_itimer(INTERVAL_SEC, INTERVAL_uSEC);
  147.         sprintf(timer.message, "Saving frames: %s ...", img.fname);
  148.         notify_set_itimer_func(File_pop_load_image->pop_load_image,
  149.             bg_save_image_frame, ITIMER_REAL, &itimer, NULL);
  150.         break;
  151.     case JOB_SAVE_MASK :
  152.         segal.new_m = timer.queue[timer.qfront].arg;
  153.         m[segal.new_m].f = 0;
  154.         begin_itimer(INTERVAL_SEC, INTERVAL_uSEC);
  155.         sprintf(timer.message, "Saving frames: %s ...", m[segal.new_m].fname);
  156.         notify_set_itimer_func(File_pop_load_mask->pop_load_mask,
  157.             bg_save_mask_frame, ITIMER_REAL, &itimer, NULL);
  158.         break;
  159.     case JOB_QUIT :
  160.         xv_set(View_win->win,
  161.             FRAME_NO_CONFIRM, TRUE,
  162.             NULL);
  163.  
  164.         xv_destroy_safe(View_win->win);
  165.         exit(0);
  166.     default :
  167.         break;
  168.  
  169.     }
  170.  
  171.     timer.qfront++;
  172.     if(timer.qfront == MAX_JOBS) timer.qfront = 0;
  173.  
  174.     if(!begin_timer()) prgmerr(0, "Job queue list not completed");
  175. }
  176.