r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / guicast / bcdragwindow.C
blob21514aa237b4e29b3e7a3c07d4b9de8c64174e74
1 #include "bcdragwindow.h"
2 #include "bcpixmap.h"
4 #include "vframe.h"
5 #include <unistd.h>
7 BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window, 
8         BC_Pixmap *pixmap, 
9         int icon_x, 
10         int icon_y)
11  : BC_Popup(parent_window, 
12         icon_x, 
13         icon_y,
14         pixmap->get_w(),
15         pixmap->get_h(),
16         -1,
17         0,
18         pixmap)
20         init_x = icon_x;
21         init_y = icon_y;
22         end_x = BC_INFINITY;
23         end_y = BC_INFINITY;
24         icon_offset_x = init_x - parent_window->get_abs_cursor_x(0);
25         icon_offset_y = init_y - parent_window->get_abs_cursor_y(0);
26 //printf("BC_DragWindow::BC_DragWindow 1 %d %d\n", icon_offset_x, icon_offset_y);
27         do_animation = 1;
31 BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window, 
32         VFrame *frame, 
33         int icon_x, 
34         int icon_y)
35  : BC_Popup(parent_window, 
36         icon_x, 
37         icon_y,
38         frame->get_w(),
39         frame->get_h(),
40         -1,
41         0,
42         prepare_frame(frame, parent_window))
44         delete temp_frame;  // created in prepare_frame inside constructor
45         init_x = icon_x;
46         init_y = icon_y;
47         end_x = BC_INFINITY;
48         end_y = BC_INFINITY;
49         icon_offset_x = init_x - parent_window->get_abs_cursor_x(0);
50         icon_offset_y = init_y - parent_window->get_abs_cursor_y(0);
51 //printf("BC_DragWindow::BC_DragWindow 1 %d %d\n", icon_offset_x, icon_offset_y);
52         do_animation = 1;
55 BC_DragWindow::~BC_DragWindow()
59 int BC_DragWindow::get_init_x(BC_WindowBase *parent_window, int icon_x)
61         int output_x, temp = 0;
62         Window tempwin;
63         XTranslateCoordinates(parent_window->top_level->display, 
64                 parent_window->win, 
65                 parent_window->top_level->rootwin, 
66                 icon_x, 
67                 temp, 
68                 &output_x, 
69                 &temp, 
70                 &tempwin);
71         return output_x;
74 int BC_DragWindow::get_init_y(BC_WindowBase *parent_window, int icon_y)
76         int output_y, temp = 0;
77         Window tempwin;
78         XTranslateCoordinates(parent_window->top_level->display, 
79                 parent_window->win, 
80                 parent_window->top_level->rootwin, 
81                 temp, 
82                 icon_y, 
83                 &temp, 
84                 &output_y, 
85                 &tempwin);
86         return output_y;
89 int BC_DragWindow::cursor_motion_event()
91         reposition_window(get_abs_cursor_x(0) + icon_offset_x, 
92                 get_abs_cursor_y(0) + icon_offset_y, 
93                 get_w(), 
94                 get_h());
95         flush();
96         return 1;
99 int BC_DragWindow::get_offset_x()
101         return icon_offset_x;
104 int BC_DragWindow::get_offset_y()
106         return icon_offset_y;
109 int BC_DragWindow::drag_failure_event()
111         if(!do_animation) return 0;
113         if(end_x == BC_INFINITY)
114         {
115                 end_x = get_x();
116                 end_y = get_y();
117         }
119         for(int i = 0; i < 10; i++)
120         {
121                 int new_x = end_x + (init_x - end_x) * i / 10;
122                 int new_y = end_y + (init_y - end_y) * i / 10;
124                 reposition_window(new_x, 
125                         new_y, 
126                         get_w(), 
127                         get_h());
128                 flush();
129                 usleep(1000);
130         }
131         return 0;
134 void BC_DragWindow::set_animation(int value)
136         this->do_animation = value;
139 BC_Pixmap *BC_DragWindow::prepare_frame(VFrame *frame, BC_WindowBase *parent_window)
141         temp_frame = 0;
142         
143         if(frame->get_color_model() == BC_RGBA8888)
144         {
145                 temp_frame = new VFrame(*frame);
146         }
147         else
148         {
149                 temp_frame = new VFrame(0, 
150                                         frame->get_w(), 
151                                         frame->get_h(), 
152                                         BC_RGBA8888); 
154                 cmodel_transfer(temp_frame->get_rows(), 
155                         frame->get_rows(),
156                         0,
157                         0,
158                         0,
159                         0,
160                         0,
161                         0,
162                         0, 
163                         0, 
164                         frame->get_w(), 
165                         frame->get_h(),
166                         0, 
167                         0, 
168                         temp_frame->get_w(), 
169                         temp_frame->get_h(),
170                         frame->get_color_model(), 
171                         temp_frame->get_color_model(),
172                         0,
173                         frame->get_w(),
174                         temp_frame->get_w());
175         }
176         temp_frame->get_rows()[(temp_frame->get_h() / 2)][(temp_frame->get_w() / 2) * 4 + 3] = 0;
177         my_pixmap = new BC_Pixmap(parent_window,
178                         temp_frame,
179                         PIXMAP_ALPHA);
181         return (my_pixmap);