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