r954: Improve icons of the liveaudio and livevideo effects.
[cinelerra_cv.git] / cinelerra / maincursor.C
blobc82d18cd5542393ecb132b15157ad8ba43ca7744
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(1);
71                         flash();
72                 }
73         }
74         return 1;
77 void MainCursor::draw(int do_plugintoggles)
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;
85 //printf("MainCursor::draw %f %f\n", selectionstart, selectionend);
87                 pixel1 = Units::to_int64((selectionstart * 
88                         mwindow->edl->session->sample_rate / 
89                         zoom_sample - 
90                         view_start));
91                 pixel2 = Units::to_int64((selectionend *
92                         mwindow->edl->session->sample_rate / 
93                         zoom_sample - 
94                         view_start));
95                 if(pixel1 < -10) pixel1 = -10;
96                 if(pixel2 > gui->canvas->get_w() + 10) pixel2 = gui->canvas->get_w() + 10;
97                 if(pixel2 < pixel1) pixel2 = pixel1;
98 //printf("MainCursor::draw 2\n");
99         }
101         gui->canvas->set_color(WHITE);
102         gui->canvas->set_inverse();
103         gui->canvas->draw_box(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h());
104         gui->canvas->set_opaque();
105         if(do_plugintoggles) gui->canvas->refresh_plugintoggles();
106         visible = !visible;
109 // Draw the cursor in a new location
110 void MainCursor::update()
112         int64_t old_pixel1 = pixel1;
113         int64_t old_pixel2 = pixel2;
115         if(visible)
116         {
117                 hide(0);
118         }
120         show(1);
121         if(old_pixel1 != pixel1 || old_pixel2 != pixel2)
122                 gui->canvas->flash(old_pixel1, 
123                         0, 
124                         old_pixel2 - old_pixel1 + 1, 
125                         gui->canvas->get_h());
126         flash();
130 void MainCursor::flash()
132         gui->canvas->flash(pixel1, 0, pixel2 - pixel1 + 1, gui->canvas->get_h());
135 void MainCursor::hide(int do_plugintoggles)
137         if(visible) draw(do_plugintoggles);
140 void MainCursor::show(int do_plugintoggles)
142         if(!visible) draw(do_plugintoggles);
145 // Constitutively redraw the cursor after it is overwritten by a draw
146 void MainCursor::restore(int do_plugintoggles)
148         if(visible)
149         {
150                 draw(do_plugintoggles);
151                 visible = 1;
152         }