00001 #include "bcsignals.h"
00002 #include "edl.h"
00003 #include "edlsession.h"
00004 #include "localsession.h"
00005 #include "maincursor.h"
00006 #include "mwindow.h"
00007 #include "mwindowgui.h"
00008 #include "trackcanvas.h"
00009
00010
00011 MainCursor::MainCursor(MWindow *mwindow, MWindowGUI *gui)
00012 {
00013 this->mwindow = mwindow;
00014 this->gui = gui;
00015 visible = 0;
00016 active = 0;
00017 playing_back = 0;
00018 }
00019
00020 MainCursor::~MainCursor()
00021 {
00022 }
00023
00024 void MainCursor::create_objects()
00025 {
00026
00027 }
00028
00029 void MainCursor::focus_in_event()
00030 {
00031 }
00032
00033 void MainCursor::focus_out_event()
00034 {
00035 show();
00036 flash();
00037 }
00038
00039 void MainCursor::activate()
00040 {
00041
00042 if(!active)
00043 {
00044 active = 1;
00045 gui->set_repeat(BC_WindowBase::get_resources()->blink_rate);
00046 }
00047 }
00048
00049 void MainCursor::deactivate()
00050 {
00051 if(active)
00052 {
00053 active = 0;
00054 gui->unset_repeat(BC_WindowBase::get_resources()->blink_rate);
00055 show();
00056 flash();
00057 }
00058 }
00059
00060 int MainCursor::repeat_event(int64_t duration)
00061 {
00062 if(!active || !gui->get_has_focus()) return 0;
00063 if(duration != BC_WindowBase::get_resources()->blink_rate) return 0;
00064
00065
00066 if(selectionstart == selectionend)
00067 {
00068 if(!playing_back || (playing_back && !visible))
00069 {
00070 draw(1);
00071 flash();
00072 }
00073 }
00074 return 1;
00075 }
00076
00077 void MainCursor::draw(int do_plugintoggles)
00078 {
00079 if(!visible)
00080 {
00081 selectionstart = mwindow->edl->local_session->get_selectionstart(1);
00082 selectionend = mwindow->edl->local_session->get_selectionend(1);
00083 view_start = mwindow->edl->local_session->view_start;
00084 zoom_sample = mwindow->edl->local_session->zoom_sample;
00085
00086
00087 pixel1 = Units::to_int64((selectionstart *
00088 mwindow->edl->session->sample_rate /
00089 zoom_sample -
00090 view_start));
00091 pixel2 = Units::to_int64((selectionend *
00092 mwindow->edl->session->sample_rate /
00093 zoom_sample -
00094 view_start));
00095 if(pixel1 < -10) pixel1 = -10;
00096 if(pixel2 > gui->canvas->get_w() + 10) pixel2 = gui->canvas->get_w() + 10;
00097 if(pixel2 < pixel1) pixel2 = pixel1;
00098
00099 }
00100
00101 gui->canvas->set_color(WHITE);
00102 gui->canvas->set_inverse();
00103 gui->canvas->draw_box(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h());
00104 gui->canvas->set_opaque();
00105 if(do_plugintoggles) gui->canvas->refresh_plugintoggles();
00106 visible = !visible;
00107 }
00108
00109
00110 void MainCursor::update()
00111 {
00112 int64_t old_pixel1 = pixel1;
00113 int64_t old_pixel2 = pixel2;
00114
00115 if(visible)
00116 {
00117 hide(0);
00118 }
00119
00120 show(1);
00121 if(old_pixel1 != pixel1 || old_pixel2 != pixel2)
00122 gui->canvas->flash(old_pixel1,
00123 0,
00124 old_pixel2 - old_pixel1 + 1,
00125 gui->canvas->get_h());
00126 flash();
00127 }
00128
00129
00130 void MainCursor::flash()
00131 {
00132 gui->canvas->flash(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h());
00133 }
00134
00135 void MainCursor::hide(int do_plugintoggles)
00136 {
00137 if(visible) draw(do_plugintoggles);
00138 }
00139
00140 void MainCursor::show(int do_plugintoggles)
00141 {
00142 if(!visible) draw(do_plugintoggles);
00143 }
00144
00145
00146 void MainCursor::restore(int do_plugintoggles)
00147 {
00148 if(visible)
00149 {
00150 draw(do_plugintoggles);
00151 visible = 1;
00152 }
00153 }