r1053: Add Russian translation.
[cinelerra_cv.git] / cinelerra / timeentry.C
blobd70beb7a8df7ddc1f500c445388eca0e7b3eca11
1 #include "timeentry.h"
2 #include <string.h>
4 TimeEntry::TimeEntry(BC_WindowBase *gui, 
5                 int x, 
6                 int y, 
7                 int *output_day, 
8                 double *output_time,
9                 int time_format)
11         this->gui = gui;
12         this->x = x;
13         this->y = y;
14         this->output_day = output_day;
15         this->output_time = output_time;
16         this->time_format = time_format;
19 TimeEntry::~TimeEntry()
21         if(output_day)
22         {
23                 delete day_text;
24                 delete day_tumbler;
25         }
26         delete time_text;
29 char* TimeEntry::day_table[] = 
31         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "*"
34 int TimeEntry::day_to_int(char *day)
36         for(int i = 0; i < TOTAL_DAYS; i++)
37                 if(!strcasecmp(day, day_table[i])) return i;
38         return 0;
42 void TimeEntry::time_to_hours(char *result, double time)
44         int hour = (int)(time / 3600);
45         sprintf(result, "%d", hour);
48 void TimeEntry::time_to_minutes(char *result, double time)
50         int hour = (int)(time / 3600);
51         int minute = (int)(time / 60 - hour * 60);
52         sprintf(result, "%d", minute);
55 void TimeEntry::time_to_seconds(char *result, double time)
57         int hour = (int)(time / 3600);
58         int minute = (int)(time / 60 - hour * 60);
59         float second = (float)time - (int64_t)hour * 3600 - (int64_t)minute * 60;
60         sprintf(result, "%.3f", second);
63 #define DEFAULT_TIMEW 200
65 void TimeEntry::create_objects()
67         int x = this->x;
68         int y = this->y;
69         char string[BCTEXTLEN];
70         int time_w = DEFAULT_TIMEW;
72         day_text = 0;
73         day_tumbler = 0;
74         if(output_day)
75         {
76                 gui->add_subwindow(day_text = new DayText(this, 
77                         x, 
78                         y, 
79                         50, 
80                         day_table, 
81                         TOTAL_DAYS, 
82                         day_table[*output_day]));
83                 x += day_text->get_w();
84                 time_w -= day_text->get_w();
85                 gui->add_subwindow(day_tumbler = new DayTumbler(this, 
86                         day_text, 
87                         x, 
88                         y));
89                 x += day_tumbler->get_w();
90                 time_w -= day_tumbler->get_w();
91         }
93         gui->add_subwindow(time_text = new TimeTextBox(this, 
94                 x, 
95                 y, 
96                 time_w, 
97                 Units::totext(string, 
98                         *output_time, 
99                         time_format)));
100         time_text->set_separators(Units::format_to_separators(time_format));
103 int TimeEntry::get_h()
105         return time_text->get_h();
108 int TimeEntry::get_w()
110         int w = 0;
111         if(day_text) w += day_text->get_w();
112         if(day_tumbler) w += day_tumbler->get_w();
113         w += time_text->get_w();
114         return w;
117 void TimeEntry::reposition_window(int x, int y)
119         int time_w = DEFAULT_TIMEW;
121         this->x = x;
122         this->y = y;
123         
124         if(output_day)
125         {
126                 day_text->reposition_window(x, y);
127                 x += day_text->get_w();
128                 time_w -= day_text->get_w();
129                 day_tumbler->reposition_window(x, y);
130                 x += day_tumbler->get_w();
131                 time_w -= day_tumbler->get_w();
132         }
133         
134         
135         time_text->reposition_window(x, y, time_w);
138 void TimeEntry::update(int *day, double *time)
140         char string[BCTEXTLEN];
141         this->output_day = day;
142         this->output_time = time;
143         
144         if(day)
145         {
146                 day_text->update(day_table[*day]);
147         }
148         
149         if(time)
150                 time_text->update(Units::totext(string,         
151                         *time, 
152                         time_format));
155 int TimeEntry::handle_event()
157         return 1;
160 DayText::DayText(TimeEntry *timeentry, 
161                 int x, 
162                 int y, 
163                 int w, 
164                 char **table, 
165                 int table_items,
166                 char *text)
167  : BC_TextBox(x, y, w, 1, text)
169         this->timeentry = timeentry;
170         this->table = table;
171         this->table_items = table_items;
174 int DayText::handle_event()
176         *timeentry->output_day = TimeEntry::day_to_int(get_text());
177         timeentry->handle_event();
178         return 1;
182 DayTumbler::DayTumbler(TimeEntry *timeentry, 
183                 DayText *text, 
184                 int x, 
185                 int y)
186  : BC_Tumbler(x, y)
188         this->timeentry = timeentry;
189         this->text = text;
193 int DayTumbler::handle_up_event()
195         *timeentry->output_day += 1;
196         if(*timeentry->output_day >= text->table_items)
197                 *timeentry->output_day = 0;
198         text->update(text->table[*timeentry->output_day]);
199         timeentry->handle_event();
200         return 1;
203 int DayTumbler::handle_down_event()
205         *timeentry->output_day -= 1;
206         if(*timeentry->output_day < 0)
207                 *timeentry->output_day = text->table_items - 1;
208         text->update(text->table[*timeentry->output_day]);
209         timeentry->handle_event();
210         return 1;
215 TimeTextBox::TimeTextBox(TimeEntry *timeentry, 
216                 int x, 
217                 int y,
218                 int w, 
219                 char *default_text)
220  : BC_TextBox(x, 
221         y, 
222         w, 
223         1, 
224         default_text)
226         this->timeentry = timeentry;
229 int TimeTextBox::handle_event()
231         *timeentry->output_time = Units::text_to_seconds(get_text(),
232                 48000,
233                 timeentry->time_format,
234                 0,
235                 0);
236         timeentry->handle_event();
237         return 1;