4 TimeEntry::TimeEntry(BC_WindowBase *gui,
13 this->output_day = output_day;
14 this->output_time = output_time;
17 TimeEntry::~TimeEntry()
27 char* TimeEntry::day_table[] =
29 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "*"
32 int TimeEntry::day_to_int(char *day)
34 for(int i = 0; i < TOTAL_DAYS; i++)
35 if(!strcasecmp(day, day_table[i])) return i;
40 void TimeEntry::time_to_hours(char *result, double time)
42 int hour = (int)(time / 3600);
43 sprintf(result, "%d", hour);
46 void TimeEntry::time_to_minutes(char *result, double time)
48 int hour = (int)(time / 3600);
49 int minute = (int)(time / 60 - hour * 60);
50 sprintf(result, "%d", minute);
53 void TimeEntry::time_to_seconds(char *result, double time)
55 int hour = (int)(time / 3600);
56 int minute = (int)(time / 60 - hour * 60);
57 float second = (float)time - (int64_t)hour * 3600 - (int64_t)minute * 60;
58 sprintf(result, "%.3f", second);
61 #define DEFAULT_TIMEW 200
63 void TimeEntry::create_objects()
67 char string[BCTEXTLEN];
68 int time_w = DEFAULT_TIMEW;
72 gui->add_subwindow(day_text = new DayText(this,
78 day_table[*output_day]));
79 x += day_text->get_w();
80 time_w -= day_text->get_w();
81 gui->add_subwindow(day_tumbler = new DayTumbler(this,
85 x += day_tumbler->get_w();
86 time_w -= day_tumbler->get_w();
89 gui->add_subwindow(time_text = new TimeTextBox(this,
98 void TimeEntry::reposition_window(int x, int y)
100 int time_w = DEFAULT_TIMEW;
107 day_text->reposition_window(x, y);
108 x += day_text->get_w();
109 time_w -= day_text->get_w();
110 day_tumbler->reposition_window(x, y);
111 x += day_tumbler->get_w();
112 time_w -= day_tumbler->get_w();
116 time_text->reposition_window(x, y, time_w);
119 void TimeEntry::update(int *day, double *time)
121 char string[BCTEXTLEN];
122 this->output_day = day;
123 this->output_time = time;
127 day_text->update(day_table[*day]);
131 time_text->update(Units::totext(string,
136 int TimeEntry::handle_event()
141 DayText::DayText(TimeEntry *timeentry,
148 : BC_TextBox(x, y, w, 1, text)
150 this->timeentry = timeentry;
152 this->table_items = table_items;
155 int DayText::handle_event()
157 *timeentry->output_day = TimeEntry::day_to_int(get_text());
158 timeentry->handle_event();
163 DayTumbler::DayTumbler(TimeEntry *timeentry,
169 this->timeentry = timeentry;
174 int DayTumbler::handle_up_event()
176 *timeentry->output_day += 1;
177 if(*timeentry->output_day >= text->table_items)
178 *timeentry->output_day = 0;
179 text->update(text->table[*timeentry->output_day]);
180 timeentry->handle_event();
184 int DayTumbler::handle_down_event()
186 *timeentry->output_day -= 1;
187 if(*timeentry->output_day < 0)
188 *timeentry->output_day = text->table_items - 1;
189 text->update(text->table[*timeentry->output_day]);
190 timeentry->handle_event();
196 TimeTextBox::TimeTextBox(TimeEntry *timeentry,
207 this->timeentry = timeentry;
210 int TimeTextBox::handle_event()
212 *timeentry->output_time = Units::text_to_seconds(get_text(),
217 //printf("TimeTextBox::handle_event %.3f\n", *timeentry->output_time);
218 timeentry->handle_event();