home *** CD-ROM | disk | FTP | other *** search
/ Geek 6 / Geek-006.iso / linux / video / xmovie-1.5.3.tar.gz / xmovie-1.5.3.tar / xmovie-1.5.3 / guicast / bctumble.C < prev    next >
C/C++ Source or Header  |  2000-11-29  |  4KB  |  239 lines

  1. #include "bcpixmap.h"
  2. #include "bcresources.h"
  3. #include "bctextbox.h"
  4. #include "bctumble.h"
  5.  
  6.  
  7. #define TUMBLE_UP 0
  8. #define TUMBLE_UPHI 1
  9. #define TUMBLEBOTTOM_DN 2
  10. #define TUMBLETOP_DN 3
  11. #define TOTAL_STATES 4
  12.  
  13. BC_Tumbler::BC_Tumbler(int x, int y)
  14.  : BC_SubWindow(x, y, 0, 0, -1)
  15. {
  16.     for(int i = 0; i < TOTAL_STATES; i++)
  17.         images[i] = 0;
  18.     status = TUMBLE_UP;
  19.     repeat_count = 0;
  20. }
  21.  
  22.  
  23. BC_Tumbler::~BC_Tumbler()
  24. {
  25.     for(int i = 0; i < TOTAL_STATES; i ++)
  26.         delete images[i];
  27. }
  28.  
  29.  
  30.  
  31. int BC_Tumbler::initialize()
  32. {
  33. // Get the image
  34.     set_images(get_resources()->tumble_data);
  35.     w = images[TUMBLE_UP]->get_w();
  36.     h = images[TUMBLE_UP]->get_h();
  37.  
  38. // Create the subwindow
  39.     BC_SubWindow::initialize();
  40.  
  41. // Display the bitmap
  42.     draw_face();
  43.     return 0;
  44. }
  45.  
  46. int BC_Tumbler::reposition_window(int x, int y)
  47. {
  48.     BC_WindowBase::reposition_window(x, y);
  49.     return 0;
  50. }
  51.  
  52.  
  53. int BC_Tumbler::update_bitmaps(VFrame **data)
  54. {
  55.     set_images(data);
  56.     draw_top_background(parent_window, 0, 0, w, h);
  57.     draw_face();
  58.     return 0;
  59. }
  60.  
  61. int BC_Tumbler::set_images(VFrame **data)
  62. {
  63.     for(int i = 0; i < TOTAL_STATES; i++)
  64.     {
  65.         if(images[i]) delete images[i];
  66.         images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
  67.     }
  68.  
  69.     return 0;
  70. }
  71.  
  72. int BC_Tumbler::draw_face()
  73. {
  74.     draw_top_background(parent_window, 0, 0, w, h);
  75.     images[status]->write_drawable(pixmap, 
  76.             0, 
  77.             0,
  78.             w,
  79.             h,
  80.             0,
  81.             0);
  82.     flash();
  83.     return 0;
  84. }
  85.  
  86. int BC_Tumbler::repeat_event(long duration)
  87. {
  88.     if(duration == top_level->get_resources()->tooltip_delay)
  89.     {
  90.         if(tooltip_text[0] != 0 &&
  91.             status == TUMBLE_UPHI &&
  92.             !tooltip_done)
  93.         {
  94.             show_tooltip();
  95.             tooltip_done = 1;
  96.             return 1;
  97.         }
  98.     }
  99.     else
  100.     if(duration == top_level->get_resources()->tumble_duration)
  101.     {
  102.         repeat_count++;
  103.         if(repeat_count == 2) return 0;
  104.         if(status == TUMBLETOP_DN)
  105.         {
  106.             handle_up_event();
  107.             return 1;
  108.         }
  109.         else
  110.         if(status == TUMBLEBOTTOM_DN)
  111.         {
  112.             handle_down_event();
  113.             return 1;
  114.         }
  115.     }
  116.     return 0;
  117. }
  118.  
  119. int BC_Tumbler::cursor_enter_event()
  120. {
  121.     if(top_level->event_win == win)
  122.     {
  123.         tooltip_done = 0;
  124.         if(! top_level->button_down && status == TUMBLE_UP) 
  125.         {
  126.             status = TUMBLE_UPHI;
  127.             draw_face();
  128.         }
  129.     }
  130.     return 0;
  131. }
  132.  
  133. int BC_Tumbler::cursor_leave_event()
  134. {
  135.     hide_tooltip();
  136.     if(status == TUMBLE_UPHI)
  137.     {
  138.         status = TUMBLE_UP;
  139.         draw_face();
  140.     }
  141.     return 0;
  142. }
  143.  
  144. int BC_Tumbler::button_press_event()
  145. {
  146.     hide_tooltip();
  147.     if(top_level->event_win == win)
  148.     {
  149.         if(top_level->cursor_y < get_h() / 2)
  150.         {
  151.             status = TUMBLETOP_DN;
  152.         }
  153.         else
  154.         {
  155.             status = TUMBLEBOTTOM_DN;
  156.         }
  157.  
  158.         draw_face();
  159.         flush();
  160.         
  161.         top_level->set_repeat(top_level->get_resources()->tumble_duration);
  162.         repeat_count = 0;
  163.         repeat_event(top_level->get_resources()->tumble_duration);
  164.     }
  165.     return 0;
  166. }
  167.  
  168. int BC_Tumbler::button_release_event()
  169. {
  170.     hide_tooltip();
  171.     if(top_level->event_win == win)
  172.     {
  173.         if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
  174.         {
  175.             top_level->unset_repeat(top_level->get_resources()->tumble_duration);
  176.             if(cursor_inside())
  177.                 status = TUMBLE_UPHI;
  178.             else
  179.                 status = TUMBLE_UP;
  180.         }
  181.         draw_face();
  182.     }
  183.     return 0;
  184. }
  185.  
  186. int BC_Tumbler::cursor_motion_event()
  187. {
  188.     if(top_level->button_down && top_level->event_win == win && 
  189.         !cursor_inside() &&
  190.         !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
  191.     {
  192.         status = TUMBLE_UP;
  193.         draw_face();
  194.     }
  195.     return 0;
  196. }
  197.  
  198.  
  199.  
  200.  
  201. BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, long min, long max, int x, int y)
  202.  : BC_Tumbler(x, y)
  203. {
  204.     this->textbox = textbox;
  205.     this->min = min;
  206.     this->max = max;
  207. }
  208.  
  209. BC_ITumbler::~BC_ITumbler()
  210. {
  211. }
  212.  
  213. int BC_ITumbler::handle_up_event()
  214. {
  215.     long value = atol(textbox->get_text());
  216.     value++;
  217.     if(value > max) value = max;
  218.     textbox->update(value);
  219.     textbox->handle_event();
  220.     return 1;
  221. }
  222.  
  223. int BC_ITumbler::handle_down_event()
  224. {
  225.     long value = atol(textbox->get_text());
  226.     value--;
  227.     if(value < min) value = min;
  228.     textbox->update(value);
  229.     textbox->handle_event();
  230.     return 1;
  231. }
  232.  
  233. void BC_ITumbler::set_boundaries(long min, long max)
  234. {
  235.     this->min = min;
  236.     this->max = max;
  237. }
  238.  
  239.