Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

bctumble.C

Go to the documentation of this file.
00001 #include "bcpixmap.h"
00002 #include "bcresources.h"
00003 #include "bctextbox.h"
00004 #include "bctumble.h"
00005 
00006 
00007 #define TUMBLE_UP 0
00008 #define TUMBLE_UPHI 1
00009 #define TUMBLEBOTTOM_DN 2
00010 #define TUMBLETOP_DN 3
00011 #define TOTAL_STATES 4
00012 
00013 BC_Tumbler::BC_Tumbler(int x, int y, VFrame **data)
00014  : BC_SubWindow(x, y, 0, 0, -1)
00015 {
00016         for(int i = 0; i < TOTAL_STATES; i++)
00017                 images[i] = 0;
00018         status = TUMBLE_UP;
00019         repeat_count = 0;
00020         this->data = data;
00021 }
00022 
00023 
00024 BC_Tumbler::~BC_Tumbler()
00025 {
00026         for(int i = 0; i < TOTAL_STATES; i ++)
00027                 delete images[i];
00028 }
00029 
00030 
00031 
00032 int BC_Tumbler::initialize()
00033 {
00034 // Get the image
00035         if(data)
00036                 set_images(data);
00037         else
00038                 set_images(get_resources()->tumble_data);
00039         w = images[TUMBLE_UP]->get_w();
00040         h = images[TUMBLE_UP]->get_h();
00041 
00042 // Create the subwindow
00043         BC_SubWindow::initialize();
00044 
00045 // Display the bitmap
00046         draw_face();
00047         return 0;
00048 }
00049 
00050 int BC_Tumbler::reposition_window(int x, int y, int w, int h)
00051 {
00052         if (w > 0 || h > 0) 
00053                 printf("BC_Tumbler::reposition_window - w & h haven't been implemented yet!! (probably never will be)");
00054 
00055         BC_WindowBase::reposition_window(x, y);
00056         draw_face();
00057         return 0;
00058 }
00059 
00060 
00061 int BC_Tumbler::update_bitmaps(VFrame **data)
00062 {
00063         set_images(data);
00064         draw_top_background(parent_window, 0, 0, w, h);
00065         draw_face();
00066         return 0;
00067 }
00068 
00069 int BC_Tumbler::set_images(VFrame **data)
00070 {
00071         for(int i = 0; i < TOTAL_STATES; i++)
00072         {
00073                 if(images[i]) delete images[i];
00074                 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
00075         }
00076 
00077         return 0;
00078 }
00079 
00080 int BC_Tumbler::draw_face()
00081 {
00082         draw_top_background(parent_window, 0, 0, w, h);
00083         images[status]->write_drawable(pixmap, 
00084                         0, 
00085                         0,
00086                         w,
00087                         h,
00088                         0,
00089                         0);
00090         flash();
00091         return 0;
00092 }
00093 
00094 int BC_Tumbler::repeat_event(int64_t duration)
00095 {
00096 //printf("BC_Tumbler::repeat_event 1 %d\n", duration);
00097         if(duration == top_level->get_resources()->tooltip_delay)
00098         {
00099                 if(tooltip_text[0] != 0 &&
00100                         status == TUMBLE_UPHI &&
00101                         !tooltip_done)
00102                 {
00103                         show_tooltip();
00104                         tooltip_done = 1;
00105                         return 1;
00106                 }
00107         }
00108         else
00109         if(duration == top_level->get_resources()->tumble_duration)
00110         {
00111 //printf("BC_Tumbler::repeat_event 2\n");
00112                 repeat_count++;
00113                 if(repeat_count == 2) return 0;
00114                 if(status == TUMBLETOP_DN)
00115                 {
00116                         handle_up_event();
00117                         return 1;
00118                 }
00119                 else
00120                 if(status == TUMBLEBOTTOM_DN)
00121                 {
00122                         handle_down_event();
00123                         return 1;
00124                 }
00125         }
00126         return 0;
00127 }
00128 
00129 int BC_Tumbler::cursor_enter_event()
00130 {
00131         if(top_level->event_win == win)
00132         {
00133                 tooltip_done = 0;
00134                 if(! top_level->button_down && status == TUMBLE_UP) 
00135                 {
00136                         status = TUMBLE_UPHI;
00137                         draw_face();
00138                 }
00139         }
00140         return 0;
00141 }
00142 
00143 int BC_Tumbler::cursor_leave_event()
00144 {
00145         hide_tooltip();
00146         if(status == TUMBLE_UPHI)
00147         {
00148                 status = TUMBLE_UP;
00149                 draw_face();
00150         }
00151         return 0;
00152 }
00153 
00154 int BC_Tumbler::button_press_event()
00155 {
00156         hide_tooltip();
00157         if(top_level->event_win == win)
00158         {
00159 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
00160                 if(get_buttonpress() == 4)
00161                 {
00162                         status = TUMBLETOP_DN;
00163                         draw_face();
00164                         flush();
00165                         handle_up_event();
00166 //                      repeat_count = 0;
00167 //                      repeat_event(top_level->get_resources()->tumble_duration);
00168                 }
00169                 else
00170                 if(get_buttonpress() == 5)
00171                 {
00172                         status = TUMBLEBOTTOM_DN;
00173                         draw_face();
00174                         flush();
00175                         handle_down_event();
00176 //                      repeat_count = 0;
00177 //                      repeat_event(top_level->get_resources()->tumble_duration);
00178                 }
00179                 else
00180                 {
00181                         if(top_level->cursor_y < get_h() / 2)
00182                         {
00183                                 status = TUMBLETOP_DN;
00184                         }
00185                         else
00186                         {
00187                                 status = TUMBLEBOTTOM_DN;
00188                         }
00189 
00190                         draw_face();
00191                         flush();
00192 
00193                         top_level->set_repeat(top_level->get_resources()->tumble_duration);
00194                         repeat_count = 0;
00195                         repeat_event(top_level->get_resources()->tumble_duration);
00196 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
00197                 }
00198                 return 1;
00199         }
00200         return 0;
00201 }
00202 
00203 int BC_Tumbler::button_release_event()
00204 {
00205         hide_tooltip();
00206         if(top_level->event_win == win)
00207         {
00208                 if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
00209                 {
00210                         top_level->unset_repeat(top_level->get_resources()->tumble_duration);
00211                         if(cursor_inside())
00212                                 status = TUMBLE_UPHI;
00213                         else
00214                                 status = TUMBLE_UP;
00215                 }
00216                 draw_face();
00217         }
00218         return 0;
00219 }
00220 
00221 int BC_Tumbler::cursor_motion_event()
00222 {
00223         if(top_level->button_down && top_level->event_win == win && 
00224                 !cursor_inside() &&
00225                 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
00226         {
00227                 status = TUMBLE_UP;
00228                 draw_face();
00229         }
00230         return 0;
00231 }
00232 
00233 
00234 
00235 
00236 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
00237  : BC_Tumbler(x, y)
00238 {
00239         this->textbox = textbox;
00240         this->min = min;
00241         this->max = max;
00242         this->increment = 1;
00243 }
00244 
00245 BC_ITumbler::~BC_ITumbler()
00246 {
00247 }
00248 
00249 void BC_ITumbler::set_increment(float value)
00250 {
00251         this->increment = (int64_t)value;
00252         if(increment < 1) increment = 1;
00253 }
00254 
00255 int BC_ITumbler::handle_up_event()
00256 {
00257         int64_t value = atol(textbox->get_text());
00258         value += increment;
00259         if(value > max) value = max;
00260         textbox->update(value);
00261         textbox->handle_event();
00262         return 1;
00263 }
00264 
00265 int BC_ITumbler::handle_down_event()
00266 {
00267         int64_t value = atol(textbox->get_text());
00268         value -= increment;
00269         if(value < min) value = min;
00270         textbox->update(value);
00271         textbox->handle_event();
00272         return 1;
00273 }
00274 
00275 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
00276 {
00277         this->min = min;
00278         this->max = max;
00279 }
00280 
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288 
00289 
00290 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox, 
00291         float min, 
00292         float max, 
00293         int x, 
00294         int y)
00295  : BC_Tumbler(x, y)
00296 {
00297         this->textbox = textbox;
00298         this->min = min;
00299         this->max = max;
00300         this->increment = 1.0;
00301 }
00302 
00303 BC_FTumbler::~BC_FTumbler()
00304 {
00305 }
00306 
00307 int BC_FTumbler::handle_up_event()
00308 {
00309         float value = atof(textbox->get_text());
00310         value += increment;
00311         if(value > max) value = max;
00312         textbox->update(value);
00313         textbox->handle_event();
00314         return 1;
00315 }
00316 
00317 int BC_FTumbler::handle_down_event()
00318 {
00319         float value = atof(textbox->get_text());
00320         value -= increment;
00321         if(value < min) value = min;
00322         textbox->update(value);
00323         textbox->handle_event();
00324         return 1;
00325 }
00326 
00327 void BC_FTumbler::set_boundaries(float min, float max)
00328 {
00329         this->min = min;
00330         this->max = max;
00331 }
00332 
00333 void BC_FTumbler::set_increment(float value)
00334 {
00335         this->increment = value;
00336 }
00337 

Generated on Sun Jan 8 13:26:33 2006 for Guicast-svn by  doxygen 1.4.4