2 Copyright © 2002, The AROS Development Team.
12 #include <exec/devices.h>
13 #include <exec/memory.h>
14 #include <workbench/icon.h>
16 #include <clib/alib_protos.h>
18 #include <proto/graphics.h>
19 #include <proto/exec.h>
20 #include <proto/intuition.h>
21 #include <proto/icon.h>
23 #include <proto/timer.h>
24 #include <proto/utility.h>
26 #include "dragndrop.h"
27 #include "muimaster_intern.h"
30 /* #define MYDEBUG 1 */
33 extern struct Library
*MUIMasterBase
;
37 ULONG
IconControl( struct DiskObject
*icon
, ... )
39 return IconControlA(icon
,(struct TagItem
*)((((ULONG
*)&icon
)+1)));
42 struct DiskObject
*GetIconTags( CONST_STRPTR name
, ... )
44 return GetIconTagList(name
,(struct TagItem
*)(((ULONG
*)&name
)+1));
60 //-------------------------------------
62 //-------------------------------------
63 static struct MinNode
*Node_Prev(APTR node
)
65 if(node
== NULL
) return NULL
;
66 if(((struct MinNode
*)node
)->mln_Pred
== NULL
) return NULL
;
67 if(((struct MinNode
*)node
)->mln_Pred
->mln_Pred
== NULL
)
69 return ((struct MinNode
*)node
)->mln_Pred
;
71 //-------------------------------------
73 //-------------------------------------
74 static struct MinNode
*List_Last(APTR list
)
76 if( !((struct MinList
*)list
)->mlh_TailPred
) return NULL
;
78 if(((struct MinList
*)list
)->mlh_TailPred
->mln_Pred
== NULL
) return NULL
;
79 return ((struct MinList
*)list
)->mlh_TailPred
;
81 //-------------------------------------
83 static ULONG
List_Length(APTR list
)
85 struct MinNode
*node
= List_First(list
);
90 node
= Node_Next(node
);
94 //-------------------------------------
95 static struct MinNode
*List_Find(APTR list
, ULONG num
)
97 struct MinNode
*node
= List_First(list
);
100 if(!(node
= Node_Next(node
))) break;
105 //-------------------------------------
109 struct MinList dnd_List
;
110 struct Screen
*dnd_Screen
;
111 struct BitMap
*dnd_TempBitMap
;
114 struct RastPort dnd_RastPort;
115 struct Layer_Info *dnd_LayerInfo;
116 struct Layer *dnd_Layer;
122 struct MinNode bmn_Node
;
123 struct BitMap
*bmn_BitMap
;
138 struct BitMap
*bmn_SaveBitMap
;
140 struct DragNDrop
*bmn_DnD
;
143 #define bmn_Succ bmn_Node.mln_Succ
144 #define bmn_Pred bmn_Node.mln_Pred
146 /* Tags for GUI_CreateBitMapNodeA() */
147 #define GUI_BitMap (TAG_USER+1) /* struct BitMap * */
148 #define GUI_Mask (TAG_USER+2) /* APTR */
149 #define GUI_LeftOffset (TAG_USER+3) /* LONG */
150 #define GUI_TopOffset (TAG_USER+4) /* LONG */
151 #define GUI_Width (TAG_USER+5) /* LONG */
152 #define GUI_Height (TAG_USER+6) /* LONG */
154 //-------------------------------------
155 STATIC VOID
List_Sort_Mode_1( struct MinList
*list
)
157 BOOL notfinished
=TRUE
;
159 /* Sort list (quick & dirty bubble sort) */
162 struct BitMapNode
*first
;
164 /* Reset not finished flag */
168 if(( first
= List_First(list
)))
170 struct BitMapNode
*second
;
172 /* One bubble sort round */
173 while(( second
= Node_Next(first
)))
176 if(first
->bmn_Top
> second
->bmn_Top
) sort
=TRUE
;
177 else if(first
->bmn_Top
== second
->bmn_Top
&& first
->bmn_Left
> second
->bmn_Left
) sort
= TRUE
;
182 Remove((struct Node
*)first
);
183 Insert((struct List
*)list
,(struct Node
*)first
,(struct Node
*)second
);
190 //-------------------------------------
192 STATIC VOID
List_Sort_Mode_2( struct MinList
*list
)
194 BOOL notfinished
=TRUE
;
196 /* Sort list (quick & dirty bubble sort) */
199 struct BitMapNode
*first
;
201 /* Reset not finished flag */
205 if(( first
= List_First(list
)))
207 struct BitMapNode
*second
;
209 /* One bubble sort round */
210 while(( second
= Node_Next(first
)))
213 if(first
->bmn_Top
> second
->bmn_Top
) sort
=TRUE
;
214 else if(first
->bmn_Top
== second
->bmn_Top
&& first
->bmn_Left
< second
->bmn_Left
) sort
= TRUE
;
219 Remove((struct Node
*)first
);
220 Insert((struct List
*)list
,(struct Node
*)first
,(struct Node
*)second
);
228 //-------------------------------------
229 STATIC VOID
List_Sort_Mode_3( struct MinList
*list
)
231 BOOL notfinished
=TRUE
;
233 /* Sort list (quick & dirty bubble sort) */
236 struct BitMapNode
*first
;
238 /* Reset not finished flag */
242 if(( first
= List_First(list
)))
244 struct BitMapNode
*second
;
246 /* One bubble sort round */
247 while(( second
= Node_Next(first
)))
250 if(first
->bmn_Left
> second
->bmn_Left
) sort
=TRUE
;
251 else if(first
->bmn_Left
== second
->bmn_Left
&& first
->bmn_Top
> second
->bmn_Top
) sort
= TRUE
;
256 Remove((struct Node
*)first
);
257 Insert((struct List
*)list
,(struct Node
*)first
,(struct Node
*)second
);
264 //-------------------------------------
265 STATIC BOOL
AndRectangle( struct Rectangle
*a
, struct Rectangle
*b
, struct Rectangle
*c
)
267 c
->MinX
= MAX(a
->MinX
,b
->MinX
);
268 c
->MinY
= MAX(a
->MinY
,b
->MinY
);
269 c
->MaxX
= MIN(a
->MaxX
,b
->MaxX
);
270 c
->MaxY
= MIN(a
->MaxY
,b
->MaxY
);
272 if((c
->MinX
> c
->MaxX
) || (c
->MinY
> c
->MaxY
)) return FALSE
;
276 //-------------------------------------
278 //-------------------------------------
279 STATIC VOID
SafeBltBitMapRastPort( struct BitMap
*srcBitMap
, long xSrc
, long ySrc
,
280 struct RastPort
*destRP
, long xDest
, long yDest
, long xSize
,
281 long ySize
, unsigned long minterm
)
283 struct BitMap
*destBitMap
= destRP
->BitMap
;
284 LONG srcMaxWidth
, srcMaxHeight
;
285 LONG destMaxWidth
, destMaxHeight
;
287 srcMaxWidth
= GetBitMapAttr(srcBitMap
, BMA_WIDTH
);
288 srcMaxHeight
= GetBitMapAttr(srcBitMap
, BMA_HEIGHT
);
289 destMaxWidth
= GetBitMapAttr(destBitMap
, BMA_WIDTH
);
290 destMaxHeight
= GetBitMapAttr(destBitMap
, BMA_HEIGHT
);
320 if( xSize
+ xSrc
> srcMaxWidth
) xSize
= srcMaxWidth
-xSrc
;
321 if( ySize
+ ySrc
> srcMaxHeight
) ySize
= srcMaxHeight
-ySrc
;
322 if( xSize
+ xDest
> destMaxWidth
) xSize
= destMaxWidth
-xDest
;
323 if( ySize
+ yDest
> destMaxHeight
) ySize
= destMaxHeight
-yDest
;
325 if(xSize
> 0 && ySize
> 0)
327 BltBitMapRastPort(srcBitMap
,xSrc
,ySrc
,destRP
,xDest
,yDest
,xSize
,ySize
,minterm
);
330 //-------------------------------------
331 STATIC LONG
SafeBltBitMap( struct BitMap
*srcBitMap
, long xSrc
, long ySrc
,
332 struct BitMap
*destBitMap
, long xDest
, long yDest
, long xSize
,
333 long ySize
, unsigned long minterm
, unsigned long mask
,
336 LONG srcMaxWidth
, srcMaxHeight
;
337 LONG destMaxWidth
, destMaxHeight
;
339 srcMaxWidth
= GetBitMapAttr(srcBitMap
, BMA_WIDTH
);
340 srcMaxHeight
= GetBitMapAttr(srcBitMap
, BMA_HEIGHT
);
341 destMaxWidth
= GetBitMapAttr(destBitMap
, BMA_WIDTH
);
342 destMaxHeight
= GetBitMapAttr(destBitMap
, BMA_HEIGHT
);
372 if( xSize
+ xSrc
> srcMaxWidth
) xSize
= srcMaxWidth
-xSrc
;
373 if( ySize
+ ySrc
> srcMaxHeight
) ySize
= srcMaxHeight
-ySrc
;
374 if( xSize
+ xDest
> destMaxWidth
) xSize
= destMaxWidth
-xDest
;
375 if( ySize
+ yDest
> destMaxHeight
) ySize
= destMaxHeight
-yDest
;
377 if(xSize
> 0 && ySize
> 0)
379 return BltBitMap( srcBitMap
, xSrc
, ySrc
, destBitMap
, xDest
, yDest
, xSize
, ySize
, minterm
, mask
, tempA
);
384 //-------------------------------------
385 STATIC VOID
BltBackgroundBitMap( struct BitMapNode
*dest_bmn
, long xSrc
, long ySrc
, long xSize
, long ySize
, ULONG use_temp
)
387 struct BitMap
*srcBitMap
,*destBitMap
;
388 struct DragNDrop
*dnd
= dest_bmn
->bmn_DnD
;
389 LONG maxWidth
, maxHeight
;
390 LONG xDest
= 0, yDest
= 0;
392 struct Rectangle rect
;
395 rect
.MaxX
= xSrc
+ xSize
- 1;
396 rect
.MaxY
= ySrc
+ ySize
- 1;
398 srcBitMap
= dnd
->dnd_Screen
->RastPort
.BitMap
;
400 if(use_temp
) destBitMap
= dnd
->dnd_TempBitMap
;
401 else destBitMap
= dest_bmn
->bmn_SaveBitMap
;
403 maxWidth
= GetBitMapAttr(srcBitMap
, BMA_WIDTH
);
404 maxHeight
= GetBitMapAttr(srcBitMap
, BMA_HEIGHT
);
420 if( xSize
+ xSrc
> maxWidth
) xSize
= maxWidth
-xSrc
;
421 if( ySize
+ ySrc
> maxHeight
) ySize
= maxHeight
-ySrc
;
423 if(xSize
> 0 && ySize
> 0)
425 struct BitMapNode
*bmn
= List_First(&dnd
->dnd_List
);
427 SafeBltBitMap(srcBitMap
,xSrc
,ySrc
,destBitMap
,xDest
,yDest
,xSize
,ySize
,0xc0, -1, NULL
);
430 // BltBitMapRastPort(destBitMap,0,0,
431 // &dnd->dnd_Screen->RastPort, 2*dest_bmn->bmn_Left+150, dest_bmn->bmn_Top+200, xSize, ySize,0xc0);
437 struct Rectangle bmn_rect
,result_rect
;
438 bmn_rect
.MinX
= bmn
->bmn_SaveX
;
439 bmn_rect
.MinY
= bmn
->bmn_SaveY
;
440 bmn_rect
.MaxX
= bmn_rect
.MinX
+ bmn
->bmn_SaveWidth
- 1;
441 bmn_rect
.MaxY
= bmn_rect
.MinY
+ bmn
->bmn_SaveHeight
- 1;
443 if(AndRectangle(&rect
,&bmn_rect
,&result_rect
))
445 LONG bmn_x
= result_rect
.MinX
- bmn_rect
.MinX
;
446 LONG bmn_y
= result_rect
.MinY
- bmn_rect
.MinY
;
447 LONG bmn_width
= result_rect
.MaxX
- result_rect
.MinX
+ 1;
448 LONG bmn_height
= result_rect
.MaxY
- result_rect
.MinY
+ 1;
449 LONG xDest
= result_rect
.MinX
- rect
.MinX
;
450 LONG yDest
= result_rect
.MinY
- rect
.MinY
;
452 SafeBltBitMap(bmn
->bmn_SaveBitMap
, bmn_x
, bmn_y
,
453 destBitMap
, xDest
, yDest
, bmn_width
, bmn_height
,0xc0,-1,NULL
);
455 // BltBitMapRastPort(destBitMap,0,0,
456 // &dnd->dnd_Screen->RastPort, 100,300, xSize, ySize,0xc0);
460 bmn
= Node_Next(bmn
);
463 // BltBitMapRastPort(destBitMap,0,0,
464 // &dnd->dnd_Screen->RastPort, 2*dest_bmn->bmn_Left+150, dest_bmn->bmn_Top+200, xSize, ySize,0xc0);
468 //-------------------------------------
469 STATIC VOID
BltBitMapNode(struct BitMapNode
*src_bmn
, LONG offx
, LONG offy
, struct RastPort
*rp
, LONG x
, LONG y
, LONG width
, LONG height
)
471 struct BitMap
*destBitMap
= rp
->BitMap
;
472 LONG destMaxWidth
= GetBitMapAttr(destBitMap
, BMA_WIDTH
);
473 LONG destMaxHeight
= GetBitMapAttr(destBitMap
, BMA_HEIGHT
);
489 if( width
+ x
> destMaxWidth
) width
= destMaxWidth
- x
;
490 if( height
+ y
> destMaxHeight
) height
= destMaxHeight
- y
;
492 if(width
> 0 && height
> 0)
494 if(src_bmn
->bmn_Mask
)
496 BltMaskBitMapRastPort( src_bmn
->bmn_BitMap
, offx
, offy
,
497 rp
, x
, y
, width
, height
, 0xe2, (PLANEPTR
)src_bmn
->bmn_Mask
);
500 BltBitMapRastPort( src_bmn
->bmn_BitMap
, offx
, offy
,
501 rp
, x
, y
, width
, height
, 0xc0 );
505 //-------------------------------------
506 STATIC VOID
BltNearBitMaps(struct BitMapNode
*src_bmn
, struct RastPort
*rp
, LONG x
, LONG y
, LONG width
, LONG height
)
508 struct DragNDrop
*dnd
= src_bmn
->bmn_DnD
;
509 struct BitMapNode
*bmn
= List_First(&dnd
->dnd_List
);
510 struct Rectangle rect
;
514 rect
.MaxX
= x
+ width
- 1;
515 rect
.MaxY
= y
+ height
- 1;
519 if(bmn
!= src_bmn
&& bmn
->bmn_Drawed
)
521 struct Rectangle bmn_rect
,result_rect
;
522 bmn_rect
.MinX
= bmn
->bmn_SaveX
;
523 bmn_rect
.MinY
= bmn
->bmn_SaveY
;
524 bmn_rect
.MaxX
= bmn_rect
.MinX
+ bmn
->bmn_SaveWidth
- 1;
525 bmn_rect
.MaxY
= bmn_rect
.MinY
+ bmn
->bmn_SaveHeight
- 1;
527 if(AndRectangle(&rect
,&bmn_rect
,&result_rect
))
529 LONG bmn_x
= result_rect
.MinX
- bmn_rect
.MinX
;
530 LONG bmn_y
= result_rect
.MinY
- bmn_rect
.MinY
;
531 LONG bmn_width
= result_rect
.MaxX
- result_rect
.MinX
+ 1;
532 LONG bmn_height
= result_rect
.MaxY
- result_rect
.MinY
+ 1;
533 LONG xDest
= result_rect
.MinX
- rect
.MinX
;
534 LONG yDest
= result_rect
.MinY
- rect
.MinY
;
536 BltBitMapNode(bmn
, bmn_x
, bmn_y
,
537 rp
, xDest
, yDest
, bmn_width
, bmn_height
);
541 bmn
= Node_Next(bmn
);
544 //-------------------------------------
545 STATIC VOID
RestoreBackground( struct BitMapNode
*src_bmn
, struct RastPort
*rp
)
547 LONG save_x
= src_bmn
->bmn_SaveX
;
548 LONG save_y
= src_bmn
->bmn_SaveY
;
549 LONG save_width
= src_bmn
->bmn_SaveWidth
;
550 LONG save_height
= src_bmn
->bmn_SaveHeight
;
552 struct DragNDrop
*dnd
= src_bmn
->bmn_DnD
;
553 struct BitMapNode
*bmn
= List_First(&dnd
->dnd_List
);
554 struct Rectangle last_rect
;
556 last_rect
.MinX
= save_x
;
557 last_rect
.MinY
= save_y
;
558 last_rect
.MaxX
= save_x
+ save_width
- 1;
559 last_rect
.MaxY
= save_y
+ save_height
- 1;
561 SafeBltBitMapRastPort( src_bmn
->bmn_SaveBitMap
,0,0,
562 rp
, save_x
, save_y
, save_width
, save_height
, 0xc0 );
567 if(bmn
!= src_bmn
&& bmn
->bmn_Drawed
)
569 struct Rectangle bmn_rect
,result_rect
;
570 bmn_rect
.MinX
= bmn
->bmn_SaveX
;
571 bmn_rect
.MinY
= bmn
->bmn_SaveY
;
572 bmn_rect
.MaxX
= bmn_rect
.MinX
+ bmn
->bmn_SaveWidth
- 1;
573 bmn_rect
.MaxY
= bmn_rect
.MinY
+ bmn
->bmn_SaveHeight
- 1;
575 if(AndRectangle(&last_rect
,&bmn_rect
,&result_rect
))
577 LONG bmn_x
= result_rect
.MinX
- bmn_rect
.MinX
;
578 LONG bmn_y
= result_rect
.MinY
- bmn_rect
.MinY
;
579 LONG bmn_width
= result_rect
.MaxX
- result_rect
.MinX
+ 1;
580 LONG bmn_height
= result_rect
.MaxY
- result_rect
.MinY
+ 1;
581 /* LONG xDest = result_rect.MinX - last_rect.MinX; */
582 /* LONG yDest = result_rect.MinY - last_rect.MinY; */
584 BltBitMapNode(bmn
, bmn_x
, bmn_y
,
585 rp
, result_rect
.MinX
, result_rect
.MinY
, bmn_width
, bmn_height
);
587 // SafeBltBitMapRastPort(bmn->bmn_SaveBitMap, bmn_x, bmn_y,
588 // rp, xDest, yDest, bmn_width, bmn_height,0xc0);
592 bmn
= Node_Next(bmn
);
595 //-------------------------------------
596 struct BitMapNode
*CreateBitMapNodeA( struct TagItem
*tagList
)
598 struct BitMapNode
*bmn
= (struct BitMapNode
*)AllocMem( sizeof(struct BitMapNode
), MEMF_CLEAR
);
601 /* BOOL alloc=FALSE; */
602 struct TagItem
*tl
=tagList
;
605 while(( tag
= NextTagItem((const struct TagItem
**) &tl
)))
607 ULONG id
= tag
->ti_Tag
;
608 ULONG data
= tag
->ti_Data
;
613 bmn
->bmn_BitMap
= (struct BitMap
*)data
;
617 bmn
->bmn_Mask
= (APTR
)data
;
621 bmn
->bmn_Left
= (LONG
)data
;
625 bmn
->bmn_Top
= (LONG
)data
;
629 bmn
->bmn_Width
= (LONG
)data
;
633 bmn
->bmn_Height
= (LONG
)data
;
639 if( !bmn
->bmn_BitMap
)
641 FreeMem(bmn
, sizeof(struct BitMapNode
));
647 //-------------------------------------
648 VOID
DeleteBitMapNode(struct BitMapNode
*bmn
)
650 if( bmn
->bmn_SaveBitMap
) FreeBitMap(bmn
->bmn_SaveBitMap
);
651 FreeMem( bmn
, sizeof(struct BitMapNode
));
653 //-------------------------------------
654 struct BitMap
*GetBitMap( struct BitMapNode
*bmn
)
656 if( bmn
) return bmn
->bmn_BitMap
;
659 //-------------------------------------
660 VOID
AttachBitMapNode( struct DragNDrop
*dnd
, struct BitMapNode
*bmn
)
662 AddTail( (struct List
*)&dnd
->dnd_List
, (struct Node
*)&bmn
->bmn_Node
);
665 //-------------------------------------
666 VOID
DetachBitMapNode( struct BitMapNode
*bmn
)
668 if( bmn
->bmn_Succ
&& bmn
->bmn_Pred
)
670 Remove((struct Node
*)&bmn
->bmn_Node
);
671 bmn
->bmn_Succ
= bmn
->bmn_Pred
= NULL
;
675 //-------------------------------------
676 VOID
DrawBitMapNode( struct BitMapNode
*bmn
, LONG x
, LONG y
)
678 LONG width
= bmn
->bmn_Width
;
679 LONG height
= bmn
->bmn_Height
;
680 LONG save_x
= bmn
->bmn_SaveX
;
681 LONG save_y
= bmn
->bmn_SaveY
;
682 LONG save_width
= bmn
->bmn_SaveWidth
;
683 LONG save_height
= bmn
->bmn_SaveHeight
;
685 struct BitMap
*temp_bmap
;
686 BOOL draw
=TRUE
;//FALSE;
688 if(!bmn
|| !bmn
->bmn_DnD
|| !bmn
->bmn_DnD
->dnd_Screen
) return;
689 rp
= &bmn
->bmn_DnD
->dnd_Screen
->RastPort
;
690 temp_bmap
= bmn
->bmn_DnD
->dnd_TempBitMap
;
692 if( !bmn
->bmn_SaveBitMap
) return;
694 /* if( bmn->bmn_SaveWidth > 0 && bmn->bmn_SaveHeight > 0 )
698 RestoreBackground(bmn,rp);
703 LONG maxWidth
, maxHeight
/* , offx=0, offy=0, save_offx=0, save_offy=0 */;
704 LONG real_width
= width
, real_height
= height
;
705 LONG real_save_width
= save_width
, real_save_height
= save_height
;
707 maxWidth
= GetBitMapAttr(rp
->BitMap
, BMA_WIDTH
);
708 maxHeight
= GetBitMapAttr(rp
->BitMap
, BMA_HEIGHT
);
710 if( x
< 0 ) real_width
+= x
;
711 if( y
< 0 ) real_height
+= y
;
712 if( save_x
< 0 ) real_save_width
+= save_x
;
713 if( save_y
< 0 ) real_save_height
+= save_y
;
715 if( real_width
+ x
> maxWidth
) real_width
= maxWidth
-x
;
716 if( real_height
+ y
> maxHeight
) real_height
= maxHeight
-y
;
717 if( real_save_width
+ x
> maxWidth
) real_save_width
= maxWidth
-x
;
718 if( real_save_height
+ y
> maxHeight
) real_save_height
= maxHeight
-y
;
720 if((real_width
>0 && real_height
> 0)||(real_save_width
>0&&real_save_height
>0))
728 // SafeBltBitMap(rp->BitMap, x,y,
729 // bmn->bmn_SaveBitMap, 0,0, width, height, 0xc0, -1, NULL);
731 // bmn->bmn_SaveWidth = 0;
732 // bmn->bmn_SaveHeight = 0;
734 // BltBackgroundBitMap(bmn->bmn_DnD, x, y,
735 // bmn->bmn_SaveBitMap, 0,0, width, height);
737 if( bmn
->bmn_SaveWidth
> 0 && bmn
->bmn_SaveHeight
> 0 )
738 RestoreBackground(bmn
,rp
);
740 BltBackgroundBitMap(bmn
, x
, y
, width
, height
,FALSE
);
742 // BltBitMapRastPort(bmn->bmn_SaveBitMap,0,0,
743 // rp, 20+bmn->bmn_Left*2,20+bmn->bmn_Top,width,height,0xc0);
746 BltBitMapNode(bmn
, 0,0, rp
,x
,y
,width
,height
);
749 struct RastPort temp_rp
;
750 struct Rectangle save_rect
,rect
,result_rect
;
751 InitRastPort(&temp_rp
);
752 temp_rp
.BitMap
= temp_bmap
;
754 save_rect
.MinX
= save_x
;
755 save_rect
.MinY
= save_y
;
756 save_rect
.MaxX
= save_x
+ save_width
- 1;
757 save_rect
.MaxY
= save_y
+ save_height
- 1;
761 rect
.MaxX
= x
+ width
-1;
762 rect
.MaxY
= y
+ height
-1;
764 if(AndRectangle(&rect
,&save_rect
,&result_rect
))
766 LONG result_width
= result_rect
.MaxX
- result_rect
.MinX
+ 1;
767 LONG result_height
= result_rect
.MaxY
- result_rect
.MinY
+ 1;
768 LONG result_x
= result_rect
.MinX
- save_rect
.MinX
;
769 LONG result_y
= result_rect
.MinY
- save_rect
.MinY
;
770 // cout << rect.MinX << " " << rect.MaxX << " " << rect.MinY << " " << rect.MaxY << endl;
771 // cout << save_rect.MinX << " " << save_rect.MaxX << " " << save_rect.MinY << " " << save_rect.MaxY << endl;
772 // cout << result_rect.MinX << " " << result_rect.MaxX << " " << result_rect.MinY << " " << result_rect.MaxY << endl;
773 // cout << "soffx:" << save_offx << " offx:" << offx << " rx:" << result_x << " " << result_y << " " << " w: " << width << " " << result_width << " " << result_height << endl;
775 // SetRast(&temp_rp,0);
777 // Neuen Hintergrund in temporäre Bitmap
778 // SafeBltBitMapRastPort( rp->BitMap, x, y,
779 // &temp_rp, 0, 0, width, height,0xc0);
781 BltBackgroundBitMap(bmn
, x
, y
, width
, height
, TRUE
);
784 // BltBitMapRastPort(temp_bmap,0,0,
785 // rp, 100+bmn->bmn_Left,20+bmn->bmn_Top,bmn->bmn_Width,bmn->bmn_Height,0xc0);
787 // Teile des alten Hintergrundes, die neu verdeckt werden in temporäre Bitmap
788 BltBitMapRastPort( bmn
->bmn_SaveBitMap
, result_x
, result_y
,
789 &temp_rp
, (result_x
?0:(save_width
-result_width
)),result_y
?0:(save_height
-result_height
),
790 result_width
,result_height
,0xc0);
793 // BltBitMapRastPort(temp_bmap,0,0,
794 // rp, 180+bmn->bmn_Left,20+bmn->bmn_Top,bmn->bmn_Width,bmn->bmn_Height,0xc0);
797 // Teile des alten Hintergrundes, die nicht mehr verdeckt werden auf Screen
798 if((save_width
- result_width
)>0)
800 SafeBltBitMapRastPort( bmn
->bmn_SaveBitMap
, (result_x
?0:(result_width
)),0,
801 rp
,save_x
+(result_x
?0:(result_width
)),save_y
,
802 save_width
-result_width
,save_height
,0xc0);
805 if((save_height
- result_height
)>0)
807 SafeBltBitMapRastPort( bmn
->bmn_SaveBitMap
, 0,result_y
?0:(result_height
),
808 rp
,save_x
,save_y
+(result_y
?0:(result_height
)),
809 save_width
,save_height
-result_height
,0xc0);
812 // temporäre BitMap ist neuer Hintergrund
813 BltBitMap(temp_bmap
,0,0,
814 bmn
->bmn_SaveBitMap
, 0,0,width
,height
,0xc0,-1,NULL
);
816 // darzustellende BitMap in temporäre BitMap
817 BltBitMapNode(bmn
, 0,0,&temp_rp
,0,0,width
,height
);
819 // Angenzende BitMaps in temporäre BitMap
820 BltNearBitMaps(bmn
, &temp_rp
,x
,y
,width
,height
);
822 // BltBitMapRastPort(temp_bmap,0,0,
823 // rp, 240+bmn->bmn_Left,20+bmn->bmn_Top,width,height,0xc0);
826 // temporäre (fertige) BitMap darstellen
827 SafeBltBitMapRastPort(temp_bmap
,0,0,
828 rp
,x
,y
,width
,height
,0xc0);
830 // BltBitMapRastPort(bmn->bmn_SaveBitMap,0,0,
831 // rp, 40+bmn->bmn_Left,20+bmn->bmn_Top,bmn->bmn_Width,bmn->bmn_Height,0xc0);
835 if( bmn
->bmn_SaveWidth
> 0 && bmn
->bmn_SaveHeight
> 0 )
836 RestoreBackground(bmn
,rp
);
838 BltBackgroundBitMap(bmn
, x
, y
, width
, height
,FALSE
);
840 /* BltBitMapRastPort( bmn->bmn_SaveBitMap,0,0,
841 rp, bmn->bmn_SaveX, bmn->bmn_SaveY, bmn->bmn_SaveWidth, bmn->bmn_SaveHeight, 0xc0 );
843 SafeBltBitMap(rp->BitMap, x,y,
844 bmn->bmn_SaveBitMap, 0,0, width, height, 0xc0, -1, NULL);
846 BltBitMapNode(bmn
, 0,0,rp
,x
,y
,width
,height
);
848 DeinitRastPort(&temp_rp
);
852 bmn
->bmn_Drawed
= TRUE
;
855 bmn
->bmn_SaveWidth
= width
;
856 bmn
->bmn_SaveHeight
= height
;
857 // bmn->bmn_SaveOffX = offx;
858 // bmn->bmn_SaveOffY = offy;
860 //-------------------------------------
861 VOID
UndrawBitMapNode(struct BitMapNode
*bmn
)
863 struct RastPort
*rp
= &bmn
->bmn_DnD
->dnd_Screen
->RastPort
;
865 if( !bmn
->bmn_SaveBitMap
) return;
867 if( bmn
->bmn_SaveWidth
> 0 && bmn
->bmn_SaveHeight
> 0 )
869 SafeBltBitMapRastPort( bmn
->bmn_SaveBitMap
,0,0,
870 rp
, bmn
->bmn_SaveX
, bmn
->bmn_SaveY
, bmn
->bmn_SaveWidth
, bmn
->bmn_SaveHeight
, 0xc0 );
872 bmn
->bmn_SaveWidth
= 0;
873 bmn
->bmn_SaveHeight
= 0;
875 //-------------------------------------
877 //-------------------------------------
878 struct DragNDrop
*CreateDragNDropA( struct TagItem
*tlist
)
880 struct DragNDrop
*dnd
= (struct DragNDrop
*)AllocMem( sizeof(struct DragNDrop
), MEMF_CLEAR
);
883 NewList( (struct List
*)&dnd
->dnd_List
);
885 /* if(dnd->dnd_LayerInfo = NewLayerInfo()))
887 dnd->dnd_Screen = NULL
888 dnd->dnd_TempBitMap = NULL;
891 struct RastPort *rp = &dnd->dnd_RastPort;
896 if(dnd->dnd_Layer = CreateBehindLayer(dnd->dnd_LayerInfo,
901 FreeMem( dnd, sizeof(struct DragNDrop ));*/
906 //-------------------------------------
907 VOID
DeleteDragNDrop( struct DragNDrop
*dnd
)
909 struct BitMapNode
*node
;
911 FinishDragNDrop(dnd
);
913 while ((node
= (struct BitMapNode
*)RemTail((struct List
*)&dnd
->dnd_List
)))
914 DeleteBitMapNode(node
);
916 FreeMem( dnd
, sizeof(struct DragNDrop
));
918 //-------------------------------------
919 VOID
DrawDragNDrop(struct DragNDrop
*dnd
, LONG x
, LONG y
)
923 static LONG first
=TRUE
;
927 struct BitMapNode
*node
;
929 LONG diffx
= x
- lastx
;
930 LONG diffy
= y
- lasty
;
932 if(!dnd
|| !dnd
->dnd_Screen
) return;
934 scr
= dnd
->dnd_Screen
;
939 if(abs(diffy
) < abs(diffx
))//y==lasty)
941 if(diffx
>0) reverse
= TRUE
;
942 List_Sort_Mode_3(&dnd
->dnd_List
);
945 if(diffy
>0) reverse
= TRUE
;
946 List_Sort_Mode_1(&dnd
->dnd_List
);
950 /* if(first) reverse = FALSE;
953 if( x<lastx) reverse = FALSE;
956 if(x==lastx && y < lasty) reverse=FALSE;
960 if(x>lastx && y < lasty)
962 List_Sort_Mode_2(&dnd->dnd_List);
966 if(x<lastx && y > lasty)
968 List_Sort_Mode_2(&dnd->dnd_List);
974 // cout << x << " " << lastx << " " << y << " " << lasty << " " << reverse << endl;
977 node
= List_First(&dnd
->dnd_List
);
980 node
->bmn_Drawed
= FALSE
;
981 node
= Node_Next(node
);
986 node
= List_First(&dnd
->dnd_List
);
989 DrawBitMapNode( node
, x
+ node
->bmn_Left
, y
+ node
->bmn_Top
);
990 node
= Node_Next(node
);
994 node
= (struct BitMapNode
*)List_Last(&dnd
->dnd_List
);
997 DrawBitMapNode(node
, x
+ node
->bmn_Left
, y
+ node
->bmn_Top
);
998 node
= (struct BitMapNode
*)Node_Prev(node
);
1005 //-------------------------------------
1006 VOID
UndrawDragNDrop(struct DragNDrop
*dnd
)
1008 struct BitMapNode
*node
;
1009 node
= (struct BitMapNode
*)List_Last(&dnd
->dnd_List
);
1012 UndrawBitMapNode(node
);
1013 node
= (struct BitMapNode
*)Node_Prev(node
);
1016 //-------------------------------------
1017 BOOL
PrepareDragNDrop(struct DragNDrop
*dnd
,struct Screen
*scr
)
1019 struct BitMapNode
*bmn
;
1020 struct RastPort
*rp
;
1022 LONG maxwidth
=0,maxheight
=0;
1025 if(!dnd
|| !scr
) return FALSE
;
1026 dnd
->dnd_Screen
= scr
;
1028 rp
= &scr
->RastPort
;
1029 depth
= GetBitMapAttr( rp
->BitMap
, BMA_DEPTH
);
1031 bmn
= List_First(&dnd
->dnd_List
);
1034 bmn
->bmn_SaveWidth
= bmn
->bmn_SaveHeight
= 0;
1035 if( bmn
->bmn_Width
> maxwidth
) maxwidth
=bmn
->bmn_Width
;
1036 if( bmn
->bmn_Height
> maxheight
) maxheight
=bmn
->bmn_Height
;
1038 if( !(bmn
->bmn_SaveBitMap
= AllocBitMap( bmn
->bmn_Width
, bmn
->bmn_Height
, depth
, BMF_MINPLANES
, rp
->BitMap
)))
1043 bmn
= Node_Next(bmn
);
1046 if(ok
&& maxwidth
&& maxheight
)
1048 dnd
->dnd_TempBitMap
= /*NULL;// */ AllocBitMap(maxwidth
,maxheight
,depth
,BMF_MINPLANES
,rp
->BitMap
);
1052 bmn
= List_First(&dnd
->dnd_List
);
1055 if(bmn
->bmn_SaveBitMap
)
1057 FreeBitMap(bmn
->bmn_SaveBitMap
);
1058 bmn
->bmn_SaveBitMap
= NULL
;
1060 bmn
= Node_Next(bmn
);
1065 //-------------------------------------
1066 VOID
FinishDragNDrop(struct DragNDrop
*dnd
)
1068 struct BitMapNode
*bmn
;
1069 if(dnd
->dnd_TempBitMap
) FreeBitMap(dnd
->dnd_TempBitMap
);
1071 bmn
= List_First(&dnd
->dnd_List
);
1074 if(bmn
->bmn_SaveBitMap
)
1076 FreeBitMap(bmn
->bmn_SaveBitMap
);
1077 bmn
->bmn_SaveBitMap
= NULL
;
1079 bmn
= Node_Next(bmn
);
1083 //-------------------------------------
1085 /**********************************************************************
1086 Varargs function of CreateBitMapNode(). Note that we need a dummy
1087 because we need at least one parameter
1088 **********************************************************************/
1089 struct BitMapNode
*VARARGS68K
CreateBitMapNode(void *dummy
, ...)
1091 #ifndef __amigaos4__
1092 return CreateBitMapNodeA( (struct TagItem
*)(((ULONG
*)&dummy
)+1));
1095 struct TagItem
*tagList
;
1096 struct BitMapNode
*res
;
1098 va_startlinear(argptr
, dummy
);
1099 tagList
= va_getlinearva(argptr
,struct TagItem
*);
1100 res
= CreateBitMapNodeA(tagList
);
1106 /******************************************************************************/
1125 struct Library
*TimerBase
;
1128 struct MsgPort
*msgport
;
1129 struct timerequest
*iorequest
;
1130 struct Library
*timerbase
;
1134 //-------------------------------------
1135 ASM VOID
TIMER_DeleteTimer( register __a0 APTR t
)
1139 struct TimerStruct
*timer
= (struct TimerStruct
*)t
;
1142 if( timer
->timerbase
)
1146 // printf("Test1\n");
1147 AbortIO((struct IORequest
*)timer
->iorequest
);
1148 // printf("Test2\n");
1149 WaitIO((struct IORequest
*)timer
->iorequest
);
1152 CloseDevice((struct IORequest
*)timer
->iorequest
);
1154 if( timer
->iorequest
) DeleteIORequest(timer
->iorequest
);
1155 if( timer
->msgport
) DeleteMsgPort(timer
->msgport
);
1160 //-------------------------------------
1161 ASM APTR
TIMER_CreateTimer()
1163 struct TimerStruct
*timer
= (struct TimerStruct
*)AllocVec( sizeof(struct TimerStruct
),0x10000);
1166 if(( timer
->msgport
= CreateMsgPort()))
1168 if(( timer
->iorequest
= (struct timerequest
*)CreateIORequest( timer
->msgport
, sizeof(struct timerequest
))))
1170 if( !OpenDevice( TIMERNAME
, UNIT_VBLANK
, (struct IORequest
*)timer
->iorequest
, NULL
))
1173 /*TimerBase = */timer
->timerbase
= (struct Library
*)timer
->iorequest
->tr_node
.io_Device
;
1175 timer
->timerbase
= (struct Library
*)timer
->iorequest
->tr_node
.io_Device
;
1181 TIMER_DeleteTimer(timer
);
1185 //-------------------------------------
1186 ASM
struct MsgPort
*TIMER_GetMsgPort( register __a0 APTR t
)
1188 if( !t
) return NULL
;
1189 return ((struct TimerStruct
*)t
)->msgport
;
1191 //-------------------------------------
1192 ASM ULONG
TIMER_GetSigMask( register __a0 APTR t
)
1194 if( !t
) return NULL
;
1195 return (1UL << (((struct TimerStruct
*)t
)->msgport
->mp_SigBit
));
1197 //-------------------------------------
1198 ASM APTR
TIMER_StartTimer( register __a0 APTR t
, register __d0 ULONG secs
, register __d1 ULONG mics
)
1200 struct TimerStruct
*timer
;
1201 struct timerequest
*req
;
1203 if( !t
) return NULL
;
1205 timer
= (struct TimerStruct
*)t
;
1206 if( timer
->sent
) return NULL
;
1208 req
= timer
->iorequest
;
1209 req
->tr_node
.io_Command
= TR_ADDREQUEST
;
1210 req
->tr_time
.tv_secs
= secs
;
1211 req
->tr_time
.tv_micro
= mics
;
1213 SendIO((struct IORequest
*)req
);
1216 //-------------------------------------
1217 ASM VOID
TIMER_StopTimer( register __a0 APTR t
)
1219 struct TimerStruct
*timer
;
1222 timer
= (struct TimerStruct
*)t
;
1225 AbortIO((struct IORequest
*)timer
->iorequest
);
1226 WaitIO((struct IORequest
*)timer
->iorequest
);
1230 //-------------------------------------
1232 //-------------------------------------
1233 struct BitMap
*CreateBitmapFromIcon(struct Screen
*scr
, struct DiskObject
*dobj
, LONG
*width
, LONG
*height
)
1235 struct Rectangle rect
;
1236 static struct TagItem rect_tags
[] =
1238 ICONDRAWA_Borderless
, TRUE
,
1242 static struct TagItem draw_tags
[] =
1244 ICONDRAWA_Borderless
,TRUE
,
1245 ICONDRAWA_EraseBackground
,TRUE
,
1249 if(!dobj
) return NULL
;
1251 if(GetIconRectangleA(NULL
,dobj
,NULL
,&rect
,rect_tags
))
1254 struct BitMap
*bmap
;
1255 if(GetBitMapAttr(scr
->RastPort
.BitMap
,BMA_FLAGS
) & BMF_STANDARD
) standard
= TRUE
;
1256 else standard
= FALSE
;
1258 *width
= rect
.MaxX
- rect
.MinX
+ 1;
1259 *height
= rect
.MaxY
- rect
.MinY
+ 1;
1261 // cout << rect.MinY << " " << rect.MaxY << endl;
1263 bmap
= AllocBitMap(*width
,*height
,8,/*NULL,NULL);// */ BMF_MINPLANES
, standard
?NULL
:scr
->RastPort
.BitMap
);
1270 DrawIconStateA(&rp
,dobj
,NULL
,0,0,IDS_SELECTED
,draw_tags
);
1271 DeinitRastPort(&rp
);
1279 //-------------------------------------
1282 struct DragNDrop
*drag
;
1284 //-------------------------------------
1288 static LONG lmx
,lmy
;
1290 WaitPort( wnd
->UserPort
);
1291 while( ready
== FALSE
)
1293 struct IntuiMessage
*imsg
;
1294 while((imsg
= (struct IntuiMessage
*)GetMsg( wnd
->UserPort
)))
1296 ULONG cl
= imsg
->Class
;
1297 UWORD code
= imsg
->Code
;
1298 // LONG mx = imsg->MouseX;
1299 // LONG my = imsg->MouseY;
1301 ReplyMsg((struct Message
*)imsg
);
1305 case IDCMP_CLOSEWINDOW
:
1309 case IDCMP_VANILLAKEY
:
1311 DrawDragNDrop(drag
,wnd
->WScreen
->MouseX
,wnd
->WScreen
->MouseY
);
1312 lmx
= wnd
->WScreen
->MouseX
;
1313 lmy
= wnd
->WScreen
->MouseY
;
1317 case IDCMP_MOUSEBUTTONS
:
1318 if(code
== SELECTDOWN
)
1320 DrawDragNDrop(drag
,wnd
->WScreen
->MouseX
,wnd
->WScreen
->MouseY
);
1321 lmx
= wnd
->WScreen
->MouseX
;
1322 lmy
= wnd
->WScreen
->MouseY
;
1326 case IDCMP_MOUSEMOVE
:
1327 // cout << wnd->WScreen->MouseX - lmx << " " << wnd->WScreen->MouseY - lmy << endl;
1328 // WaitBOVP(&wnd->WScreen->ViewPort);
1329 DrawDragNDrop(drag
,wnd
->WScreen
->MouseX
,wnd
->WScreen
->MouseY
);
1335 //-------------------------------------
1337 UBYTE fullmask
[8192];
1342 for (i
=0;i
<8192;i
++) fullmask
[i
] = 0xff;
1344 wnd
= OpenWindowTags( NULL
,
1346 WA_InnerHeight
, 200,
1347 WA_IDCMP
, IDCMP_CLOSEWINDOW
|IDCMP_MOUSEMOVE
|IDCMP_INTUITICKS
|IDCMP_MOUSEBUTTONS
|IDCMP_VANILLAKEY
,
1349 WA_DepthGadget
, TRUE
,
1350 WA_CloseGadget
, TRUE
,
1351 WA_ReportMouse
, TRUE
,
1353 WA_GimmeZeroZero
, TRUE
,
1359 struct DiskObject
*obj1
= GetIconTags("SYS:Prefs",
1360 ICONGETA_GenerateImageMasks
,TRUE
,
1362 struct DiskObject
*obj2
= GetIconTags("SYS:Picasso96",
1363 ICONGETA_GenerateImageMasks
,TRUE
,
1365 struct DiskObject
*obj3
= GetIconTags("SYS:Tools",
1366 ICONGETA_GenerateImageMasks
,TRUE
,
1369 struct BitMap
*bmap1
= CreateBitmapFromIcon(wnd
->WScreen
, obj1
,&width
,&height
);
1370 struct BitMap
*bmap2
= CreateBitmapFromIcon(wnd
->WScreen
, obj2
,&width
,&height
);
1371 struct BitMap
*bmap3
= CreateBitmapFromIcon(wnd
->WScreen
, obj3
,&width
,&height
);
1372 if(bmap1
&&bmap2
&&bmap3
)
1374 APTR mask1
,mask2
,mask3
;
1375 IconControl(obj1
,ICONCTRLA_GetImageMask1
,&mask1
,TAG_DONE
);
1376 IconControl(obj2
,ICONCTRLA_GetImageMask1
,&mask2
,TAG_DONE
);
1377 IconControl(obj3
,ICONCTRLA_GetImageMask1
,&mask3
,TAG_DONE
);
1378 if((drag
= CreateDragNDropA(NULL
)))
1380 struct BitMapNode
*bmn1
= CreateBitMapNode(
1386 GUI_LeftOffset
, -35,
1389 struct BitMapNode
*bmn2
= CreateBitMapNode(
1397 struct BitMapNode
*bmn3
= CreateBitMapNode(
1406 struct BitMapNode
*bmn4
= CreateBitMapNode(
1414 struct BitMapNode
*bmn5
= CreateBitMapNode(
1423 struct BitMapNode
*bmn6
= CreateBitMapNode(
1428 GUI_LeftOffset
, 100,
1432 if(bmn1
&& bmn2
&& bmn3
&& bmn4
&& bmn5
&& bmn6
)
1434 AttachBitMapNode(drag
,bmn1
);
1435 AttachBitMapNode(drag
,bmn2
);
1436 AttachBitMapNode(drag
,bmn3
);
1437 AttachBitMapNode(drag
,bmn4
);
1438 AttachBitMapNode(drag
,bmn5
);
1439 AttachBitMapNode(drag
,bmn6
);
1440 PrepareDragNDrop(drag
,wnd
->WScreen
);
1442 FinishDragNDrop(drag
);
1443 DetachBitMapNode(bmn6
);
1444 DetachBitMapNode(bmn5
);
1445 DetachBitMapNode(bmn4
);
1446 DetachBitMapNode(bmn3
);
1447 DetachBitMapNode(bmn2
);
1448 DetachBitMapNode(bmn1
);
1450 if(bmn6
) DeleteBitMapNode(bmn6
);
1451 if(bmn5
) DeleteBitMapNode(bmn5
);
1452 if(bmn4
) DeleteBitMapNode(bmn4
);
1453 if(bmn3
) DeleteBitMapNode(bmn3
);
1454 if(bmn2
) DeleteBitMapNode(bmn2
);
1455 if(bmn1
) DeleteBitMapNode(bmn1
);
1456 DeleteDragNDrop(drag
);
1460 if(bmap3
) FreeBitMap(bmap3
);
1461 if(bmap2
) FreeBitMap(bmap2
);
1462 if(bmap1
) FreeBitMap(bmap1
);
1464 if(obj3
) FreeDiskObject(obj3
);
1465 if(obj2
) FreeDiskObject(obj2
);
1466 if(obj1
) FreeDiskObject(obj1
);
1471 //-------------------------------------