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

timeentry.C

Go to the documentation of this file.
00001 #include "timeentry.h"
00002 #include <string.h>
00003 
00004 TimeEntry::TimeEntry(BC_WindowBase *gui, 
00005                 int x, 
00006                 int y, 
00007                 int *output_day, 
00008                 double *output_time,
00009                 int time_format)
00010 {
00011         this->gui = gui;
00012         this->x = x;
00013         this->y = y;
00014         this->output_day = output_day;
00015         this->output_time = output_time;
00016         this->time_format = time_format;
00017 }
00018 
00019 TimeEntry::~TimeEntry()
00020 {
00021         if(output_day)
00022         {
00023                 delete day_text;
00024                 delete day_tumbler;
00025         }
00026         delete time_text;
00027 }
00028 
00029 char* TimeEntry::day_table[] = 
00030 {
00031         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "*"
00032 };
00033 
00034 int TimeEntry::day_to_int(char *day)
00035 {
00036         for(int i = 0; i < TOTAL_DAYS; i++)
00037                 if(!strcasecmp(day, day_table[i])) return i;
00038         return 0;
00039 }
00040 
00041 
00042 void TimeEntry::time_to_hours(char *result, double time)
00043 {
00044         int hour = (int)(time / 3600);
00045         sprintf(result, "%d", hour);
00046 }
00047 
00048 void TimeEntry::time_to_minutes(char *result, double time)
00049 {
00050         int hour = (int)(time / 3600);
00051         int minute = (int)(time / 60 - hour * 60);
00052         sprintf(result, "%d", minute);
00053 }
00054 
00055 void TimeEntry::time_to_seconds(char *result, double time)
00056 {
00057         int hour = (int)(time / 3600);
00058         int minute = (int)(time / 60 - hour * 60);
00059         float second = (float)time - (int64_t)hour * 3600 - (int64_t)minute * 60;
00060         sprintf(result, "%.3f", second);
00061 }
00062 
00063 #define DEFAULT_TIMEW 200
00064 
00065 void TimeEntry::create_objects()
00066 {
00067         int x = this->x;
00068         int y = this->y;
00069         char string[BCTEXTLEN];
00070         int time_w = DEFAULT_TIMEW;
00071 
00072         day_text = 0;
00073         day_tumbler = 0;
00074         if(output_day)
00075         {
00076                 gui->add_subwindow(day_text = new DayText(this, 
00077                         x, 
00078                         y, 
00079                         50, 
00080                         day_table, 
00081                         TOTAL_DAYS, 
00082                         day_table[*output_day]));
00083                 x += day_text->get_w();
00084                 time_w -= day_text->get_w();
00085                 gui->add_subwindow(day_tumbler = new DayTumbler(this, 
00086                         day_text, 
00087                         x, 
00088                         y));
00089                 x += day_tumbler->get_w();
00090                 time_w -= day_tumbler->get_w();
00091         }
00092 
00093         gui->add_subwindow(time_text = new TimeTextBox(this, 
00094                 x, 
00095                 y, 
00096                 time_w, 
00097                 Units::totext(string, 
00098                         *output_time, 
00099                         time_format)));
00100         time_text->set_separators(Units::format_to_separators(time_format));
00101 }
00102 
00103 int TimeEntry::get_h()
00104 {
00105         return time_text->get_h();
00106 }
00107 
00108 int TimeEntry::get_w()
00109 {
00110         int w = 0;
00111         if(day_text) w += day_text->get_w();
00112         if(day_tumbler) w += day_tumbler->get_w();
00113         w += time_text->get_w();
00114         return w;
00115 }
00116 
00117 void TimeEntry::reposition_window(int x, int y)
00118 {
00119         int time_w = DEFAULT_TIMEW;
00120 
00121         this->x = x;
00122         this->y = y;
00123         
00124         if(output_day)
00125         {
00126                 day_text->reposition_window(x, y);
00127                 x += day_text->get_w();
00128                 time_w -= day_text->get_w();
00129                 day_tumbler->reposition_window(x, y);
00130                 x += day_tumbler->get_w();
00131                 time_w -= day_tumbler->get_w();
00132         }
00133         
00134         
00135         time_text->reposition_window(x, y, time_w);
00136 }
00137 
00138 void TimeEntry::update(int *day, double *time)
00139 {
00140         char string[BCTEXTLEN];
00141         this->output_day = day;
00142         this->output_time = time;
00143         
00144         if(day)
00145         {
00146                 day_text->update(day_table[*day]);
00147         }
00148         
00149         if(time)
00150                 time_text->update(Units::totext(string,         
00151                         *time, 
00152                         time_format));
00153 }
00154 
00155 int TimeEntry::handle_event()
00156 {
00157         return 1;
00158 }
00159 
00160 DayText::DayText(TimeEntry *timeentry, 
00161                 int x, 
00162                 int y, 
00163                 int w, 
00164                 char **table, 
00165                 int table_items,
00166                 char *text)
00167  : BC_TextBox(x, y, w, 1, text)
00168 {
00169         this->timeentry = timeentry;
00170         this->table = table;
00171         this->table_items = table_items;
00172 }
00173 
00174 int DayText::handle_event()
00175 {
00176         *timeentry->output_day = TimeEntry::day_to_int(get_text());
00177         timeentry->handle_event();
00178         return 1;
00179 }
00180 
00181 
00182 DayTumbler::DayTumbler(TimeEntry *timeentry, 
00183                 DayText *text, 
00184                 int x, 
00185                 int y)
00186  : BC_Tumbler(x, y)
00187 {
00188         this->timeentry = timeentry;
00189         this->text = text;
00190 }
00191 
00192 
00193 int DayTumbler::handle_up_event()
00194 {
00195         *timeentry->output_day += 1;
00196         if(*timeentry->output_day >= text->table_items)
00197                 *timeentry->output_day = 0;
00198         text->update(text->table[*timeentry->output_day]);
00199         timeentry->handle_event();
00200         return 1;
00201 }
00202 
00203 int DayTumbler::handle_down_event()
00204 {
00205         *timeentry->output_day -= 1;
00206         if(*timeentry->output_day < 0)
00207                 *timeentry->output_day = text->table_items - 1;
00208         text->update(text->table[*timeentry->output_day]);
00209         timeentry->handle_event();
00210         return 1;
00211 }
00212 
00213 
00214 
00215 TimeTextBox::TimeTextBox(TimeEntry *timeentry, 
00216                 int x, 
00217                 int y,
00218                 int w, 
00219                 char *default_text)
00220  : BC_TextBox(x, 
00221         y, 
00222         w, 
00223         1, 
00224         default_text)
00225 {
00226         this->timeentry = timeentry;
00227 }
00228 
00229 int TimeTextBox::handle_event()
00230 {
00231         *timeentry->output_time = Units::text_to_seconds(get_text(),
00232                 48000,
00233                 timeentry->time_format,
00234                 0,
00235                 0);
00236         timeentry->handle_event();
00237         return 1;
00238 }

Generated on Sun Jan 8 13:39:00 2006 for Cinelerra-svn by  doxygen 1.4.4