4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcsignals.h"
25 #include "edlsession.h"
27 #include "mwindowgui.h"
29 #include "trackcanvas.h"
32 #include "zoompanel.h"
35 ZoomHash::ZoomHash(double value, const char *text)
38 this->text = new char[strlen(text) + 1];
39 strcpy(this->text, text);
63 ZoomPanel::ZoomPanel(MWindow *mwindow,
64 BC_WindowBase *subwindow,
73 this->mwindow = mwindow;
74 this->subwindow = subwindow;
81 this->zoom_type = zoom_type;
82 this->menu_images = 0;
83 this->tumbler_images = 0;
88 ZoomPanel::ZoomPanel(MWindow *mwindow,
89 BC_WindowBase *subwindow,
98 this->mwindow = mwindow;
99 this->subwindow = subwindow;
106 this->zoom_type = zoom_type;
107 this->menu_images = 0;
108 this->tumbler_images = 0;
109 this->user_table = user_table;
110 this->user_size = user_size;
113 ZoomPanel::~ZoomPanel()
117 zoom_table.remove_all_objects();
120 void ZoomPanel::calculate_menu()
124 for(int i = 0; i < user_size; i++)
126 zoom_text->add_item(new BC_MenuItem(value_to_text(user_table[i], 0)));
127 zoom_table.append(new ZoomHash(user_table[i], value_to_text(user_table[i], 0)));
132 for(double zoom = min; zoom <= max; zoom *= 2)
134 zoom_text->add_item(new BC_MenuItem(value_to_text(zoom, 0)));
135 zoom_table.append(new ZoomHash(zoom, value_to_text(zoom, 0)));
140 int ZoomPanel::calculate_w(int menu_w)
142 return BC_PopupMenu::calculate_w(menu_w) + BC_Tumbler::calculate_w();
145 void ZoomPanel::update_menu()
147 while(zoom_text->total_items()) zoom_text->del_item(0);
149 zoom_table.remove_all_objects();
153 void ZoomPanel::set_menu_images(VFrame **data)
155 this->menu_images = data;
158 void ZoomPanel::set_tumbler_images(VFrame **data)
160 this->tumbler_images = data;
163 void ZoomPanel::create_objects()
165 subwindow->add_subwindow(zoom_text = new ZoomPopup(mwindow,
169 x += zoom_text->get_w();
170 subwindow->add_subwindow(zoom_tumbler = new ZoomTumbler(mwindow,
177 void ZoomPanel::reposition_window(int x, int y)
179 zoom_text->reposition_window(x, y);
180 x += zoom_text->get_w();
181 zoom_tumbler->reposition_window(x, y);
185 int ZoomPanel::get_w()
187 return zoom_text->get_w() + zoom_tumbler->get_w();
190 double ZoomPanel::get_value()
195 char* ZoomPanel::get_text()
197 return zoom_text->get_text();
200 void ZoomPanel::set_text(const char *text)
202 zoom_text->set_text(text);
205 void ZoomPanel::update(double value)
208 zoom_text->set_text(value_to_text(value));
211 void ZoomPanel::update(const char *value)
213 zoom_text->set_text(value);
217 char* ZoomPanel::value_to_text(double value, int use_table)
221 for(int i = 0; i < zoom_table.total; i++)
223 //printf("ZoomPanel::value_to_text %p\n", zoom_table.values[i]);
224 if(EQUIV(zoom_table.values[i]->value, value))
225 return zoom_table.values[i]->text;
227 //printf("ZoomPanel::value_to_text: should never get here\n");
228 return zoom_table.values[0]->text;
233 case ZOOM_PERCENTAGE:
234 sprintf(string, "%d%%", (int)(value * 100));
238 sprintf(string, "%.1f", value);
242 sprintf(string, "%ld", (long)value);
247 // sprintf(string, "%ld", (long)value);
248 double total_seconds = (double)(mwindow->theme->mcanvas_w -
249 mwindow->theme->patchbay_w -
250 BC_ScrollBar::get_span(SCROLL_VERT)) *
252 mwindow->edl->session->sample_rate;
253 Units::totext(string,
255 mwindow->edl->session->time_format,
256 mwindow->edl->session->sample_rate,
257 mwindow->edl->session->frame_rate,
258 mwindow->edl->session->frames_per_foot);
265 double ZoomPanel::text_to_zoom(char *text, int use_table)
268 for(int i = 0; i < zoom_table.total; i++) {
269 if(!strcasecmp(text, zoom_table.values[i]->text))
270 return zoom_table.values[i]->value;
272 return zoom_table.values[0]->value;
277 case ZOOM_PERCENTAGE:
278 result = atof(text) / 100;
286 double total_samples = Units::fromtext(text,
287 mwindow->edl->session->sample_rate,
288 mwindow->edl->session->time_format,
289 mwindow->edl->session->frame_rate,
290 mwindow->edl->session->frames_per_foot);
291 total_samples /= mwindow->theme->mcanvas_w -
292 mwindow->theme->patchbay_w -
293 BC_ScrollBar::get_span(SCROLL_VERT);
294 double difference = fabs(total_samples - result);
295 while(fabs(result - total_samples) <= difference) {
296 difference = fabs(result - total_samples);
311 ZoomPopup::ZoomPopup(MWindow *mwindow, ZoomPanel *panel, int x, int y)
315 panel->value_to_text(panel->value, 0),
319 this->mwindow = mwindow;
323 ZoomPopup::~ZoomPopup()
327 int ZoomPopup::handle_event()
329 panel->value = panel->text_to_zoom(get_text());
330 panel->handle_event();
336 ZoomTumbler::ZoomTumbler(MWindow *mwindow, ZoomPanel *panel, int x, int y)
339 panel->tumbler_images)
341 this->mwindow = mwindow;
345 ZoomTumbler::~ZoomTumbler()
349 int ZoomTumbler::handle_up_event()
351 if(panel->user_table)
353 int current_index = 0;
354 for(current_index = 0; current_index < panel->user_size; current_index++)
355 if(EQUIV(panel->user_table[current_index], panel->value)) break;
357 CLAMP(current_index, 0, panel->user_size - 1);
358 panel->value = panel->user_table[current_index];
363 RECLIP(panel->value, panel->min, panel->max);
366 panel->zoom_text->set_text(panel->value_to_text(panel->value));
367 panel->handle_event();
371 int ZoomTumbler::handle_down_event()
373 if(panel->user_table)
375 int current_index = 0;
376 for(current_index = 0; current_index < panel->user_size; current_index++)
377 if(EQUIV(panel->user_table[current_index], panel->value)) break;
379 CLAMP(current_index, 0, panel->user_size - 1);
380 panel->value = panel->user_table[current_index];
385 RECLIP(panel->value, panel->min, panel->max);
387 panel->zoom_text->set_text(panel->value_to_text(panel->value));
388 panel->handle_event();