r663: This commit was generated by cvs2svn to compensate for changes in r662,
[cinelerra_cv.git] / cinelerra / maincursor.C
blob316c783fb722682ecdcaf3a96a8b66ad531406b1
1 #include "bcsignals.h"
2 #include "edl.h"
3 #include "edlsession.h"
4 #include "localsession.h"
5 #include "maincursor.h"
6 #include "mwindow.h"
7 #include "mwindowgui.h"
8 #include "trackcanvas.h"
11 MainCursor::MainCursor(MWindow *mwindow, MWindowGUI *gui)
13         this->mwindow = mwindow;
14         this->gui = gui;
15         visible = 0;
16         active = 0;
17         playing_back = 0;
20 MainCursor::~MainCursor()
24 void MainCursor::create_objects()
26 //      draw();
29 void MainCursor::focus_in_event()
33 void MainCursor::focus_out_event()
35         show();
36         flash();
39 void MainCursor::activate()
41 //printf("MainCursor::activate 1 %d\n", BC_WindowBase::get_resources()->blink_rate);
42         if(!active)
43         {
44                 active = 1;
45                 gui->set_repeat(BC_WindowBase::get_resources()->blink_rate);
46         }
49 void MainCursor::deactivate()
51         if(active)
52         {
53                 active = 0;
54                 gui->unset_repeat(BC_WindowBase::get_resources()->blink_rate);
55                 show();
56                 flash();
57         }
60 int MainCursor::repeat_event(int64_t duration)
62         if(!active || !gui->get_has_focus()) return 0;
63         if(duration != BC_WindowBase::get_resources()->blink_rate) return 0;
65 // Only flash a single sample selection
66         if(selectionstart == selectionend)
67         {
68                 if(!playing_back || (playing_back && !visible))
69                 {
70                         draw();
71                         flash();
72                 }
73         }
74         return 1;
77 void MainCursor::draw()
79         if(!visible)
80         {
81                 selectionstart = mwindow->edl->local_session->get_selectionstart(1);
82                 selectionend = mwindow->edl->local_session->get_selectionend(1);
83                 view_start = mwindow->edl->local_session->view_start;
84                 zoom_sample = mwindow->edl->local_session->zoom_sample;
86                 pixel1 = Units::to_int64((selectionstart * 
87                         mwindow->edl->session->sample_rate / 
88                         zoom_sample - 
89                         view_start));
90                 pixel2 = Units::to_int64((selectionend *
91                         mwindow->edl->session->sample_rate / 
92                         zoom_sample - 
93                         view_start));
94                 if(pixel1 < -10) pixel1 = -10;
95                 if(pixel2 > gui->canvas->get_w() + 10) pixel2 = gui->canvas->get_w() + 10;
96                 if(pixel2 < pixel1) pixel2 = pixel1;
97 //printf("MainCursor::draw 2\n");
98         }
100         gui->canvas->set_color(WHITE);
101         gui->canvas->set_inverse();
102         gui->canvas->draw_box(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h());
103         gui->canvas->set_opaque();
104         visible = !visible;
107 // Draw the cursor in a new location
108 void MainCursor::update()
110         if(visible)
111         {
112                 hide();
113                 flash();
114         }
115         show();
116         flash();
120 void MainCursor::flash()
122         gui->canvas->flash(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h());
123         gui->flush();
126 void MainCursor::hide()
128         if(visible) draw();
131 void MainCursor::show()
133         if(!visible) draw();
136 // Constitutively redraw the cursor after it is overwritten by a draw
137 void MainCursor::restore()
139         if(visible)
140         {
141                 draw();
142                 visible = 1;
143         }