mask mousewheel segv bug, mask opengl sw fallback read to ram, fix tiff config withou...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / maincursor.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcsignals.h"
23 #include "edl.h"
24 #include "edlsession.h"
25 #include "localsession.h"
26 #include "maincursor.h"
27 #include "mwindow.h"
28 #include "mwindowgui.h"
29 #include "preferences.h"
30 #include "timelinepane.h"
31 #include "trackcanvas.h"
32
33
34 MainCursor::MainCursor(MWindow *mwindow, MWindowGUI *gui)
35 {
36         this->mwindow = mwindow;
37         this->gui = gui;
38         visible = 0;
39         active = 0;
40         playing_back = 0;
41         pane = 0;
42 }
43
44 MainCursor::MainCursor(MWindow *mwindow, TimelinePane *pane)
45 {
46         this->mwindow = mwindow;
47         this->gui = mwindow->gui;
48         this->pane = pane;
49         visible = 0;
50         active = 0;
51         playing_back = 0;
52 }
53
54 MainCursor::~MainCursor()
55 {
56 }
57
58 void MainCursor::create_objects()
59 {
60 //      draw();
61 }
62
63 void MainCursor::focus_in_event()
64 {
65 }
66
67 void MainCursor::focus_out_event()
68 {
69         show();
70         flash();
71 }
72
73 void MainCursor::activate()
74 {
75 //printf("MainCursor::activate 1 %d\n", BC_WindowBase::get_resources()->blink_rate);
76         if(!active)
77         {
78                 active = 1;
79                 gui->set_repeat(BC_WindowBase::get_resources()->blink_rate);
80         }
81 }
82
83 void MainCursor::deactivate()
84 {
85         if(active)
86         {
87                 active = 0;
88                 gui->unset_repeat(BC_WindowBase::get_resources()->blink_rate);
89                 show();
90                 flash();
91         }
92 }
93
94 int MainCursor::repeat_event(int64_t duration)
95 {
96         if(!active || !gui->get_has_focus()) return 0;
97         if(duration != BC_WindowBase::get_resources()->blink_rate) return 0;
98
99 // Only flash a single sample selection
100         if(selectionstart == selectionend)
101         {
102                 if(!playing_back || (playing_back && !visible))
103                 {
104                         draw(1);
105                         flash();
106                 }
107         }
108         return 1;
109 }
110
111 void MainCursor::draw(int do_plugintoggles)
112 {
113         if(!visible)
114         {
115                 selectionstart = mwindow->edl->local_session->get_selectionstart(1);
116                 selectionend = mwindow->edl->local_session->get_selectionend(1);
117                 view_start = mwindow->edl->local_session->view_start[pane->number];
118                 zoom_sample = mwindow->edl->local_session->zoom_sample;
119 //printf("MainCursor::draw %f %f\n", selectionstart, selectionend);
120
121                 pixel1 = Units::to_int64((selectionstart *
122                         mwindow->edl->session->sample_rate /
123                         zoom_sample -
124                         view_start));
125                 pixel2 = Units::to_int64((selectionend *
126                         mwindow->edl->session->sample_rate /
127                         zoom_sample -
128                         view_start));
129                 if(pixel1 < -10) pixel1 = -10;
130                 if(pixel2 > pane->canvas->get_w() + 10)
131                         pixel2 = pane->canvas->get_w() + 10;
132                 if(pixel2 < pixel1) pixel2 = pixel1;
133 //printf("MainCursor::draw 2\n");
134         }
135
136         pane->canvas->set_color(mwindow->preferences->highlight_inverse);
137         pane->canvas->set_inverse();
138         pane->canvas->draw_box(pixel1, 0, pixel2 - pixel1 + 1, pane->canvas->get_h());
139         pane->canvas->set_opaque();
140         if(do_plugintoggles) pane->canvas->refresh_plugintoggles();
141         visible = !visible;
142 }
143
144 // Draw the cursor in a new location
145 void MainCursor::update()
146 {
147         int64_t old_pixel1 = pixel1;
148         int64_t old_pixel2 = pixel2;
149
150         if(visible)
151         {
152                 hide(0);
153         }
154
155         show(1);
156         if(old_pixel1 != pixel1 || old_pixel2 != pixel2)
157                 pane->canvas->flash(old_pixel1,
158                         0,
159                         old_pixel2 - old_pixel1 + 1,
160                         pane->canvas->get_h());
161         flash();
162 }
163
164
165 void MainCursor::flash()
166 {
167         pane->canvas->flash(pixel1, 0, pixel2 - pixel1 + 1, pane->canvas->get_h());
168 }
169
170 void MainCursor::hide(int do_plugintoggles)
171 {
172         if(visible) draw(do_plugintoggles);
173 }
174
175 void MainCursor::show(int do_plugintoggles)
176 {
177         if(!visible) draw(do_plugintoggles);
178 }
179
180 // Constitutively redraw the cursor after it is overwritten by a draw
181 void MainCursor::restore(int do_plugintoggles)
182 {
183         if(visible)
184         {
185                 draw(do_plugintoggles);
186                 visible = 1;
187         }
188 }