r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / timeentry.C
blobdb4978a6a618608ec76ed81faa56764f1fd588b4
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)
10         this->gui = gui;
11         this->x = x;
12         this->y = y;
13         this->output_day = output_day;
14         this->output_time = output_time;
17 TimeEntry::~TimeEntry()
19         if(output_day)
20         {
21                 delete day_text;
22                 delete day_tumbler;
23         }
24         delete time_text;
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;
36         return 0;
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()
65         int x = this->x;
66         int y = this->y;
67         char string[BCTEXTLEN];
68         int time_w = DEFAULT_TIMEW;
70         if(output_day)
71         {
72                 gui->add_subwindow(day_text = new DayText(this, 
73                         x, 
74                         y, 
75                         50, 
76                         day_table, 
77                         TOTAL_DAYS, 
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, 
82                         day_text, 
83                         x, 
84                         y));
85                 x += day_tumbler->get_w();
86                 time_w -= day_tumbler->get_w();
87         }
89         gui->add_subwindow(time_text = new TimeTextBox(this, 
90                 x, 
91                 y, 
92                 time_w, 
93                 Units::totext(string,   
94                         *output_time, 
95                         TIME_HMS)));
98 void TimeEntry::reposition_window(int x, int y)
100         int time_w = DEFAULT_TIMEW;
102         this->x = x;
103         this->y = y;
104         
105         if(output_day)
106         {
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();
113         }
114         
115         
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;
124         
125         if(day)
126         {
127                 day_text->update(day_table[*day]);
128         }
129         
130         if(time)
131                 time_text->update(Units::totext(string,         
132                         *time, 
133                         TIME_HMS));
136 int TimeEntry::handle_event()
138         return 1;
141 DayText::DayText(TimeEntry *timeentry, 
142                 int x, 
143                 int y, 
144                 int w, 
145                 char **table, 
146                 int table_items,
147                 char *text)
148  : BC_TextBox(x, y, w, 1, text)
150         this->timeentry = timeentry;
151         this->table = table;
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();
159         return 1;
163 DayTumbler::DayTumbler(TimeEntry *timeentry, 
164                 DayText *text, 
165                 int x, 
166                 int y)
167  : BC_Tumbler(x, y)
169         this->timeentry = timeentry;
170         this->text = text;
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();
181         return 1;
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();
191         return 1;
196 TimeTextBox::TimeTextBox(TimeEntry *timeentry, 
197                 int x, 
198                 int y,
199                 int w, 
200                 char *default_text)
201  : BC_TextBox(x, 
202         y, 
203         w, 
204         1, 
205         default_text)
207         this->timeentry = timeentry;
210 int TimeTextBox::handle_event()
212         *timeentry->output_time = Units::text_to_seconds(get_text(),
213                 48000,
214                 TIME_HMS,
215                 0,
216                 0);
217 //printf("TimeTextBox::handle_event %.3f\n", *timeentry->output_time);
218         timeentry->handle_event();
219         return 1;