r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / maincursor.C
blobb24ef1a16141bcb7de8f734105a8f5b3e591b5a1
1 #include "edl.h"
2 #include "edlsession.h"
3 #include "localsession.h"
4 #include "maincursor.h"
5 #include "mwindow.h"
6 #include "mwindowgui.h"
7 #include "trackcanvas.h"
10 MainCursor::MainCursor(MWindow *mwindow, MWindowGUI *gui)
12         this->mwindow = mwindow;
13         this->gui = gui;
14         visible = 0;
15         active = 0;
16         playing_back = 0;
19 MainCursor::~MainCursor()
23 void MainCursor::create_objects()
25 //      draw();
28 void MainCursor::activate()
30 //printf("MainCursor::activate 1 %d\n", BC_WindowBase::get_resources()->blink_rate);
31         if(!active)
32         {
33                 active = 1;
34                 gui->set_repeat(BC_WindowBase::get_resources()->blink_rate);
35         }
38 void MainCursor::deactivate()
40         if(active)
41         {
42                 active = 0;
43                 gui->unset_repeat(BC_WindowBase::get_resources()->blink_rate);
44                 show();
45                 flash();
46         }
49 int MainCursor::repeat_event(int64_t duration)
51         if(!active) return 0;
52 //printf("MainCursor::repeat_event 1 %d\n", duration);
53         if(duration != BC_WindowBase::get_resources()->blink_rate) return 0;
55 // Only flash a single sample selection
56         if(selectionstart == selectionend)
57         {
58                 if(!playing_back || (playing_back && !visible))
59                 {
60                         draw();
61                         flash();
62                 }
63         }
64 //printf("MainCursor::repeat_event 2 %d\n", duration);
65         return 1;
68 void MainCursor::draw()
70         if(!visible)
71         {
72 //printf("MainCursor::draw 1\n");
73                 selectionstart = mwindow->edl->local_session->selectionstart;
74                 selectionend = mwindow->edl->local_session->selectionend;
75                 view_start = mwindow->edl->local_session->view_start;
76                 zoom_sample = mwindow->edl->local_session->zoom_sample;
78                 pixel1 = Units::to_int64((selectionstart * 
79                         mwindow->edl->session->sample_rate / 
80                         zoom_sample - 
81                         view_start));
82                 pixel2 = Units::to_int64((selectionend *
83                         mwindow->edl->session->sample_rate / 
84                         zoom_sample - 
85                         view_start));
86                 if(pixel1 < -10) pixel1 = -10;
87                 if(pixel2 > gui->canvas->get_w() + 10) pixel2 = gui->canvas->get_w() + 10;
88                 if(pixel2 < pixel1) pixel2 = pixel1;
89 //printf("MainCursor::draw 2\n");
90         }
92         gui->canvas->set_color(WHITE);
93         gui->canvas->set_inverse();
94         gui->canvas->draw_box(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h());
95         gui->canvas->set_opaque();
96         visible = !visible;
99 // Draw the cursor in a new location
100 void MainCursor::update()
102         if(visible)
103         {
104                 hide();
105                 flash();
106         }
107         show();
108         flash();
112 void MainCursor::flash()
114         gui->canvas->flash(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h());
117 void MainCursor::hide()
119         if(visible) draw();
122 void MainCursor::show()
124 //printf("MainCursor::show 1 %d\n", visible);
125         if(!visible) draw();
128 // Constitutively redraw the cursor after it is overwritten by a draw
129 void MainCursor::restore()
131         if(visible)
132         {
133                 draw();
134                 visible = 1;
135         }