1
/*********************************************************************************
3
**********************************************************************************
5
* Copyright (C) 2006 John Varouhakis *
8
* This program is free software; you can redistribute it and/or modify *
9
* it under the terms of the GNU General Public License as published by *
10
* the Free Software Foundation; either version 2 of the License, or *
11
* (at your option) any later version. *
13
* This program is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License *
19
* along with this program; if not, write to the Free Software *
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
24
* For further information contact me at johnvarouhakis@gmail.com *
25
**********************************************************************************/
1
/******************************************************************************
3
*******************************************************************************
5
* Copyright (C) 2006,2007 John Varouhakis *
8
* This program is free software; you can redistribute it and/or modify *
9
* it under the terms of the GNU General Public License as published by *
10
* the Free Software Foundation; either version 2 of the License, or *
11
* (at your option) any later version. *
13
* This program is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License *
19
* along with this program; if not, write to the Free Software *
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
24
* For further information contact me at johnvarouhakis@gmail.com *
25
******************************************************************************/
28
28
#include <recordmydesktop.h>
29
//return 1 and null if geom1 in geom2 ,2 and null if geom2 in geom1,0 if they don't collide
30
//-1 and two geoms if they collide and geom1 is broken.//-2 and one or two geoms if they collide and geom2 is broken.
29
//return 1 and null if geom1 in geom2 ,2 and null if geom2 in geom1,
30
//0 if they don't collide
31
//-1 and two geoms if they collide and geom1 is broken.
32
//-2 and one or two geoms if they collide and geom2 is broken.
31
33
//-10 if group and replace is possible
32
int CollideRects(WGeometry *wgeom1,WGeometry *wgeom2,WGeometry **wgeom_return,int *ngeoms){
34
int CollideRects(WGeometry *wgeom1,
36
WGeometry **wgeom_return,
34
39
if((wgeom1->x>=wgeom2->x)&&
35
40
(wgeom1->x+wgeom1->width<=wgeom2->x+wgeom2->width)&&
59
64
//this happens because libxdamage may generate many events for one change
60
65
//and some of them may be in the the exact same region
61
66
//so identical rects would be considered not colliding
62
//in order though to avoid endless recursion on the RectInsert
67
//in order though to avoid endless recursion on the RectInsert
63
68
//function should always start at the next element(which is logical since
64
//if any rect makes it to a points none of it's part collides with previous
69
//if any rect makes it to a points none of it's part collides with previous
65
70
//nodes on the list, too)
66
71
int x1[2]={wgeom1->x,wgeom1->x+wgeom1->width};
67
72
int y1[2]={wgeom1->y,wgeom1->y+wgeom1->height};
97
103
wgeom_return[0]->height=wgeom2->height+wgeom2->y-wgeom1->y;
100
else if((enclosed[1][0]&&enclosed[1][2])&&(wgeom1->height==wgeom2->height)){
101
// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
106
else if((enclosed[1][0]&&enclosed[1][2])&&
107
(wgeom1->height==wgeom2->height)){
103
109
wgeom_return[0]->x=wgeom1->x;
104
110
wgeom_return[0]->y=wgeom1->y;
105
111
wgeom_return[0]->width=wgeom2->width+wgeom2->x-wgeom1->x;
106
wgeom_return[0]->height=wgeom1->height;
112
wgeom_return[0]->height=wgeom1->height;
109
else if((enclosed[1][3]&&enclosed[1][1])&&(wgeom1->height==wgeom2->height)){
110
// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
115
else if((enclosed[1][3]&&enclosed[1][1])&&
116
(wgeom1->height==wgeom2->height)){
112
118
wgeom_return[0]->x=wgeom2->x;
113
119
wgeom_return[0]->y=wgeom2->y;
151
156
else if(tot1==2){
152
157
//if the first one breaks(which is already inserted)
153
//then we reenter the part that was left and the one
158
//then we reenter the part that was left and the one
154
159
//that was to be inserted
155
// wgeom_return[1]=wgeom2;
156
160
wgeom_return[1]->x=wgeom2->x;
157
161
wgeom_return[1]->y=wgeom2->y;
158
162
wgeom_return[1]->width=wgeom2->width;
159
163
wgeom_return[1]->height=wgeom2->height;
160
// wgeom_return[0]=(WGeometry *)malloc(sizeof(WGeometry));
161
164
wgeom_return[0]->x=wgeom1->x;
162
165
wgeom_return[0]->y=wgeom1->y;
163
166
wgeom_return[0]->width=wgeom1->width;
300
300
int ngeoms=0,insert_ok=1,i=0;
302
while(insert_ok){//if something is broken list does not procceed(except on -1 collres case)
303
int collres/*=0;//*/=CollideRects(&(temp->geom),wgeom,wgeom_return,&ngeoms);
302
while(insert_ok){ //if something is broken list does not procceed
303
//(except on -1 collres case)
304
int collres=CollideRects(&(temp->geom),wgeom,wgeom_return,&ngeoms);
307
308
for(i=0;i<ngeoms;i++){
308
wgeom_return[i]->width+=(wgeom_return[i]->width%2)|(wgeom_return[i]->x%2);
309
wgeom_return[i]->height+=(wgeom_return[i]->height%2)|(wgeom_return[i]->y%2);
309
wgeom_return[i]->width+=(wgeom_return[i]->width%2)|
310
(wgeom_return[i]->x%2);
311
wgeom_return[i]->height+=(wgeom_return[i]->height%2)|
312
(wgeom_return[i]->y%2);
310
313
wgeom_return[i]->width+=(wgeom_return[i]->width%2);
311
314
wgeom_return[i]->height+=(wgeom_return[i]->height%2);
312
315
wgeom_return[i]->x-=wgeom_return[i]->x%2;
353
356
case 2://done,area is already covered
356
case -1://current node is broken and reinserted(in same pos)
359
case -1://current node is broken and reinserted
357
361
//newnode is also reinserted
358
if((wgeom_return[0]->width>0)&&(wgeom_return[0]->height>0)){
362
if((wgeom_return[0]->width>0)&&
363
(wgeom_return[0]->height>0)){
359
364
temp->geom.x=wgeom_return[0]->x;
360
365
temp->geom.y=wgeom_return[0]->y;
361
366
temp->geom.width=wgeom_return[0]->width;
372
else{//it might happen that the old and now broken node
373
//is of zero width or height(so it isn't reinserted)
374
/*TODO this may cause lines to be left not updated
375
so maybe it is needed to increase the size by one
376
pixel(zero width or height cause BadValue*/
377
else{//it might happen that the old and now broken node
378
//is of zero width or height
379
//(so it isn't reinserted)
377
380
if((temp->prev==NULL)&&(temp->next!=NULL)){
378
381
*root=(*root)->next;
379
382
(*root)->prev=NULL;