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 // draw(); 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 //printf("MainCursor::activate 1 %d\n", BC_WindowBase::get_resources()->blink_rate); 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 // Only flash a single sample selection 00066 if(selectionstart == selectionend) 00067 { 00068 if(!playing_back || (playing_back && !visible)) 00069 { 00070 draw(); 00071 flash(); 00072 } 00073 } 00074 return 1; 00075 } 00076 00077 void MainCursor::draw() 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 pixel1 = Units::to_int64((selectionstart * 00087 mwindow->edl->session->sample_rate / 00088 zoom_sample - 00089 view_start)); 00090 pixel2 = Units::to_int64((selectionend * 00091 mwindow->edl->session->sample_rate / 00092 zoom_sample - 00093 view_start)); 00094 if(pixel1 < -10) pixel1 = -10; 00095 if(pixel2 > gui->canvas->get_w() + 10) pixel2 = gui->canvas->get_w() + 10; 00096 if(pixel2 < pixel1) pixel2 = pixel1; 00097 //printf("MainCursor::draw 2\n"); 00098 } 00099 00100 gui->canvas->set_color(WHITE); 00101 gui->canvas->set_inverse(); 00102 gui->canvas->draw_box(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h()); 00103 gui->canvas->set_opaque(); 00104 visible = !visible; 00105 } 00106 00107 // Draw the cursor in a new location 00108 void MainCursor::update() 00109 { 00110 if(visible) 00111 { 00112 hide(); 00113 flash(); 00114 } 00115 show(); 00116 flash(); 00117 } 00118 00119 00120 void MainCursor::flash() 00121 { 00122 gui->canvas->flash(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h()); 00123 gui->flush(); 00124 } 00125 00126 void MainCursor::hide() 00127 { 00128 if(visible) draw(); 00129 } 00130 00131 void MainCursor::show() 00132 { 00133 if(!visible) draw(); 00134 } 00135 00136 // Constitutively redraw the cursor after it is overwritten by a draw 00137 void MainCursor::restore() 00138 { 00139 if(visible) 00140 { 00141 draw(); 00142 visible = 1; 00143 } 00144 }
1.4.4