~akirad/cinecutie/trunk

« back to all changes in this revision

Viewing changes to guicast/bcdragwindow.C

  • Committer: Paolo Rampino
  • Date: 2010-02-17 19:46:21 UTC
  • Revision ID: git-v1:c39ff77ffa6ae08441c12e7d7f54e3897ddde7f1
Initial Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "bcdragwindow.h"
 
23
#include "bcpixmap.h"
 
24
 
 
25
#include "vframe.h"
 
26
#include <unistd.h>
 
27
 
 
28
BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window, 
 
29
        BC_Pixmap *pixmap, 
 
30
        int icon_x, 
 
31
        int icon_y)
 
32
 : BC_Popup(parent_window, 
 
33
        icon_x, 
 
34
        icon_y,
 
35
        pixmap->get_w(),
 
36
        pixmap->get_h(),
 
37
        -1,
 
38
        0,
 
39
        pixmap)
 
40
{
 
41
        init_x = icon_x;
 
42
        init_y = icon_y;
 
43
        end_x = BC_INFINITY;
 
44
        end_y = BC_INFINITY;
 
45
        icon_offset_x = init_x - parent_window->get_abs_cursor_x(0);
 
46
        icon_offset_y = init_y - parent_window->get_abs_cursor_y(0);
 
47
//printf("BC_DragWindow::BC_DragWindow 1 %d %d\n", icon_offset_x, icon_offset_y);
 
48
        do_animation = 1;
 
49
}
 
50
 
 
51
 
 
52
BC_DragWindow::BC_DragWindow(BC_WindowBase *parent_window, 
 
53
        VFrame *frame, 
 
54
        int icon_x, 
 
55
        int icon_y)
 
56
 : BC_Popup(parent_window, 
 
57
        icon_x, 
 
58
        icon_y,
 
59
        frame->get_w(),
 
60
        frame->get_h(),
 
61
        -1,
 
62
        0,
 
63
        prepare_frame(frame, parent_window))
 
64
{
 
65
        delete temp_frame;  // created in prepare_frame inside constructor
 
66
        init_x = icon_x;
 
67
        init_y = icon_y;
 
68
        end_x = BC_INFINITY;
 
69
        end_y = BC_INFINITY;
 
70
        icon_offset_x = init_x - parent_window->get_abs_cursor_x(0);
 
71
        icon_offset_y = init_y - parent_window->get_abs_cursor_y(0);
 
72
//printf("BC_DragWindow::BC_DragWindow 1 %d %d\n", icon_offset_x, icon_offset_y);
 
73
        do_animation = 1;
 
74
}
 
75
 
 
76
BC_DragWindow::~BC_DragWindow()
 
77
{
 
78
}
 
79
 
 
80
int BC_DragWindow::get_init_x(BC_WindowBase *parent_window, int icon_x)
 
81
{
 
82
        int output_x, temp = 0;
 
83
        Window tempwin;
 
84
        XTranslateCoordinates(parent_window->top_level->display, 
 
85
                parent_window->win, 
 
86
                parent_window->top_level->rootwin, 
 
87
                icon_x, 
 
88
                temp, 
 
89
                &output_x, 
 
90
                &temp, 
 
91
                &tempwin);
 
92
        return output_x;
 
93
}
 
94
 
 
95
int BC_DragWindow::get_init_y(BC_WindowBase *parent_window, int icon_y)
 
96
{
 
97
        int output_y, temp = 0;
 
98
        Window tempwin;
 
99
        XTranslateCoordinates(parent_window->top_level->display, 
 
100
                parent_window->win, 
 
101
                parent_window->top_level->rootwin, 
 
102
                temp, 
 
103
                icon_y, 
 
104
                &temp, 
 
105
                &output_y, 
 
106
                &tempwin);
 
107
        return output_y;
 
108
}
 
109
 
 
110
int BC_DragWindow::cursor_motion_event()
 
111
{
 
112
        reposition_window(get_abs_cursor_x(0) + icon_offset_x, 
 
113
                get_abs_cursor_y(0) + icon_offset_y, 
 
114
                get_w(), 
 
115
                get_h());
 
116
        flush();
 
117
        return 1;
 
118
}
 
119
 
 
120
int BC_DragWindow::get_offset_x()
 
121
{
 
122
        return icon_offset_x;
 
123
}
 
124
 
 
125
int BC_DragWindow::get_offset_y()
 
126
{
 
127
        return icon_offset_y;
 
128
}
 
129
 
 
130
int BC_DragWindow::drag_failure_event()
 
131
{
 
132
        if(!do_animation) return 0;
 
133
 
 
134
        if(end_x == BC_INFINITY)
 
135
        {
 
136
                end_x = get_x();
 
137
                end_y = get_y();
 
138
        }
 
139
 
 
140
        for(int i = 0; i < 10; i++)
 
141
        {
 
142
                int new_x = end_x + (init_x - end_x) * i / 10;
 
143
                int new_y = end_y + (init_y - end_y) * i / 10;
 
144
 
 
145
                reposition_window(new_x, 
 
146
                        new_y, 
 
147
                        get_w(), 
 
148
                        get_h());
 
149
                flush();
 
150
                usleep(1000);
 
151
        }
 
152
        return 0;
 
153
}
 
154
 
 
155
void BC_DragWindow::set_animation(int value)
 
156
{
 
157
        this->do_animation = value;
 
158
}
 
159
 
 
160
BC_Pixmap *BC_DragWindow::prepare_frame(VFrame *frame, BC_WindowBase *parent_window)
 
161
{
 
162
        temp_frame = 0;
 
163
        
 
164
        if(frame->get_color_model() == BC_RGBA8888)
 
165
        {
 
166
                temp_frame = new VFrame(*frame);
 
167
        }
 
168
        else
 
169
        {
 
170
                temp_frame = new VFrame(0, 
 
171
                                        frame->get_w(), 
 
172
                                        frame->get_h(), 
 
173
                                        BC_RGBA8888); 
 
174
 
 
175
                cmodel_transfer(temp_frame->get_rows(), 
 
176
                        frame->get_rows(),
 
177
                        0,
 
178
                        0,
 
179
                        0,
 
180
                        0,
 
181
                        0,
 
182
                        0,
 
183
                        0, 
 
184
                        0, 
 
185
                        frame->get_w(), 
 
186
                        frame->get_h(),
 
187
                        0, 
 
188
                        0, 
 
189
                        temp_frame->get_w(), 
 
190
                        temp_frame->get_h(),
 
191
                        frame->get_color_model(), 
 
192
                        temp_frame->get_color_model(),
 
193
                        0,
 
194
                        frame->get_w(),
 
195
                        temp_frame->get_w());
 
196
        }
 
197
        temp_frame->get_rows()[(temp_frame->get_h() / 2)][(temp_frame->get_w() / 2) * 4 + 3] = 0;
 
198
        my_pixmap = new BC_Pixmap(parent_window,
 
199
                        temp_frame,
 
200
                        PIXMAP_ALPHA);
 
201
 
 
202
        return (my_pixmap);
 
203
}
 
204
 
 
205