3 #include "edlsession.h"
5 #include "mwindowgui.h"
7 #include "trackcanvas.h"
10 #include "zoompanel.h"
13 ZoomHash::ZoomHash(double value, char *text)
16 this->text = new char[strlen(text) + 1];
17 strcpy(this->text, text);
41 ZoomPanel::ZoomPanel(MWindow *mwindow,
42 BC_WindowBase *subwindow,
51 this->mwindow = mwindow;
52 this->subwindow = subwindow;
59 this->zoom_type = zoom_type;
60 this->menu_images = 0;
61 this->tumbler_images = 0;
66 ZoomPanel::ZoomPanel(MWindow *mwindow,
67 BC_WindowBase *subwindow,
76 this->mwindow = mwindow;
77 this->subwindow = subwindow;
84 this->zoom_type = zoom_type;
85 this->menu_images = 0;
86 this->tumbler_images = 0;
87 this->user_table = user_table;
88 this->user_size = user_size;
91 ZoomPanel::~ZoomPanel()
95 zoom_table.remove_all_objects();
98 void ZoomPanel::calculate_menu()
102 for(int i = 0; i < user_size; i++)
104 zoom_text->add_item(new BC_MenuItem(value_to_text(user_table[i], 0)));
105 zoom_table.append(new ZoomHash(user_table[i], value_to_text(user_table[i], 0)));
110 for(double zoom = min; zoom <= max; zoom *= 2)
112 zoom_text->add_item(new BC_MenuItem(value_to_text(zoom, 0)));
113 zoom_table.append(new ZoomHash(zoom, value_to_text(zoom, 0)));
118 void ZoomPanel::update_menu()
120 while(zoom_text->total_items())
122 zoom_text->remove_item(0);
125 zoom_table.remove_all_objects();
129 void ZoomPanel::set_menu_images(VFrame **data)
131 this->menu_images = data;
134 void ZoomPanel::set_tumbler_images(VFrame **data)
136 this->tumbler_images = data;
139 int ZoomPanel::create_objects()
141 subwindow->add_subwindow(zoom_text = new ZoomPopup(mwindow,
145 x += zoom_text->get_w();
146 subwindow->add_subwindow(zoom_tumbler = new ZoomTumbler(mwindow,
154 void ZoomPanel::reposition_window(int x, int y)
156 zoom_text->reposition_window(x, y);
157 x += zoom_text->get_w();
158 zoom_tumbler->reposition_window(x, y);
162 int ZoomPanel::get_w()
164 return zoom_text->get_w() + zoom_tumbler->get_w();
167 double ZoomPanel::get_value()
172 char* ZoomPanel::get_text()
174 return zoom_text->get_text();
177 void ZoomPanel::set_text(char *text)
179 zoom_text->set_text(text);
182 void ZoomPanel::update(double value)
185 zoom_text->set_text(value_to_text(value));
188 void ZoomPanel::update(char *value)
190 zoom_text->set_text(value);
194 char* ZoomPanel::value_to_text(double value, int use_table)
198 for(int i = 0; i < zoom_table.total; i++)
200 //printf("ZoomPanel::value_to_text %p\n", zoom_table.values[i]);
201 if(EQUIV(zoom_table.values[i]->value, value))
202 return zoom_table.values[i]->text;
204 //printf("ZoomPanel::value_to_text: should never get here\n");
205 return zoom_table.values[0]->text;
210 case ZOOM_PERCENTAGE:
211 sprintf(string, "%d%%", (int)(value * 100));
215 sprintf(string, "%.1f", value);
219 sprintf(string, "%ld", (long)value);
224 double total_seconds = (double)mwindow->gui->canvas->get_w() *
226 mwindow->edl->session->sample_rate;
227 Units::totext(string,
229 mwindow->edl->session->time_format,
230 mwindow->edl->session->sample_rate,
231 mwindow->edl->session->frame_rate,
232 mwindow->edl->session->frames_per_foot);
239 double ZoomPanel::text_to_zoom(char *text, int use_table)
243 for(int i = 0; i < zoom_table.total; i++)
245 if(!strcasecmp(text, zoom_table.values[i]->text))
246 return zoom_table.values[i]->value;
248 return zoom_table.values[0]->value;
253 case ZOOM_PERCENTAGE:
254 return atof(text) / 100;
263 double total_samples = Units::fromtext(text,
264 mwindow->edl->session->sample_rate,
265 mwindow->edl->session->time_format,
266 mwindow->edl->session->frame_rate,
267 mwindow->edl->session->frames_per_foot);
268 total_samples /= mwindow->gui->canvas->get_w();
269 double difference = fabs(total_samples - result);
270 while(fabs(result - total_samples) <= difference)
272 difference = fabs(result - total_samples);
287 ZoomPopup::ZoomPopup(MWindow *mwindow, ZoomPanel *panel, int x, int y)
291 panel->value_to_text(panel->value, 0),
295 this->mwindow = mwindow;
299 ZoomPopup::~ZoomPopup()
303 int ZoomPopup::handle_event()
305 panel->value = panel->text_to_zoom(get_text());
306 panel->handle_event();
312 ZoomTumbler::ZoomTumbler(MWindow *mwindow, ZoomPanel *panel, int x, int y)
315 panel->tumbler_images)
317 this->mwindow = mwindow;
321 ZoomTumbler::~ZoomTumbler()
325 int ZoomTumbler::handle_up_event()
327 if(panel->user_table)
329 int current_index = 0;
330 for(current_index = 0; current_index < panel->user_size; current_index++)
331 if(EQUIV(panel->user_table[current_index], panel->value)) break;
333 CLAMP(current_index, 0, panel->user_size - 1);
334 panel->value = panel->user_table[current_index];
339 RECLIP(panel->value, panel->min, panel->max);
342 panel->zoom_text->set_text(panel->value_to_text(panel->value));
343 panel->handle_event();
347 int ZoomTumbler::handle_down_event()
349 if(panel->user_table)
351 int current_index = 0;
352 for(current_index = 0; current_index < panel->user_size; current_index++)
353 if(EQUIV(panel->user_table[current_index], panel->value)) break;
355 CLAMP(current_index, 0, panel->user_size - 1);
356 panel->value = panel->user_table[current_index];
361 RECLIP(panel->value, panel->min, panel->max);
363 panel->zoom_text->set_text(panel->value_to_text(panel->value));
364 panel->handle_event();