layers.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2004 Karoly Balogh for Genesi S.a.r.l. <www.genesi.lu>
  4. layers.library interface unit for MorphOS/PowerPC
  5. Based on work of Nils Sjoholm member of the Amiga RTL
  6. development team.
  7. MorphOS port was done on a free Pegasos II/G4 machine
  8. provided by Genesi S.a.r.l. <www.genesi.lu>
  9. See the file COPYING.FPC, included in this distribution,
  10. for details about the copyright.
  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.
  14. **********************************************************************}
  15. {$PACKRECORDS 2}
  16. {$IFNDEF FPC_DOTTEDUNITS}
  17. unit layers;
  18. {$ENDIF FPC_DOTTEDUNITS}
  19. interface
  20. {$IFDEF FPC_DOTTEDUNITS}
  21. uses Amiga.Core.Exec, Amiga.Core.Agraphics, Amiga.Core.Utility;
  22. {$ELSE FPC_DOTTEDUNITS}
  23. uses exec, agraphics, utility;
  24. {$ENDIF FPC_DOTTEDUNITS}
  25. const
  26. LAYERSIMPLE = 1;
  27. LAYERSMART = 2;
  28. LAYERSUPER = 4;
  29. LAYERUPDATING = $10;
  30. LAYERBACKDROP = $40;
  31. LAYERREFRESH = $80;
  32. LAYER_CLIPRECTS_LOST = $100; // during BeginUpdate or during layerop this happens if out of memory
  33. LAYERIREFRESH = $200;
  34. LAYERIREFRESH2 = $400;
  35. type
  36. PLayer_Info = ^TLayer_Info;
  37. TLayer_Info = packed record
  38. top_layer : PLayer;
  39. check_lp : PLayer; // Private
  40. obs : PClipRect;
  41. FreeClipRects : PClipRect; // Private
  42. PrivateReserve1, // Private
  43. PrivateReserve2 : LongInt; // Private
  44. Lock : TSignalSemaphore; // Private
  45. gs_Head : TMinList; // Private
  46. PrivateReserve3 : SmallInt; // Private
  47. PrivateReserve4 : APTR; // Private
  48. Flags : Word;
  49. fatten_count : ShortInt; // Private
  50. LockLayersCount : ShortInt; // Private
  51. PrivateReserve5 : SmallInt; // Private
  52. BlankHook, // Private
  53. LayerInfo_extra : APTR; // Private
  54. end;
  55. const
  56. NEWLAYERINFO_CALLED = 1;
  57. // LAYERS_NEVERBACKFILL, available since v52.22
  58. // unlike with NOBACKFILL, the new layer will not be filled with contents
  59. // of layers underneath it, contents is lost after resize
  60. LAYERS_NEVERBACKFILL = 2;
  61. LAYERS_NOBACKFILL = 1;
  62. LAYERS_BACKFILL = 0;
  63. // Tags for Create#?LayerTagList
  64. LA_Dummy = TAG_USER + 1024;
  65. LA_BackfillHook = LA_Dummy + $0001;
  66. LA_TransRegion = LA_Dummy + $0002;
  67. LA_TransHook = LA_Dummy + $0003;
  68. LA_WindowPtr = LA_Dummy + $0004;
  69. LA_SuperBitMap = LA_Dummy + $0005; // replaces bm2 in function call
  70. LR_Dummy = TAG_USER + 1150;
  71. LR_Destination_RastPort = LR_Dummy + 1; // PRastPort to render in
  72. LR_Destination_BitMap = LR_Dummy + 2; // PBitMap to render in. mutually exclusive with LR_Destination_RastPort. Do note that the destination
  73. // bitmap (or the rastport's bitmap) MUST be in the same format as the source you want to render from!
  74. LR_Destination_Bounds = LR_Dummy + 3; // PRectangle. the graphics will be rendered inside of the given boundaries. if not passed, the call assumes the buffer has at least the same size as LayerInfo
  75. LR_LayerInfo_Bounds = LR_Dummy + 4; // PRectangle. limits the portion of a LayerInfo to draw
  76. LR_Erase = LR_Dummy + 5; // LongBool. setting to FALSE will make the layers be drawn without the background being cleared with the screen's backfill hook TRUE by default
  77. LR_RenderList = LR_Dummy + 6; // PPLayer. a nil terminated list of PLayer pointers to render if they are within given bounds
  78. LR_IgnoreList = LR_Dummy + 7; // PPLayer. a nil terminated list of PLayer pointers to ommit when rendering the layerinfo. mutually exclusive with LR_RenderList!
  79. LAYERSNAME: PAnsiChar = 'layers.library';
  80. var
  81. LayersBase: PLibrary = nil;
  82. procedure InitLayers(Li: PLayer_Info location 'a0'); SysCall LayersBase 030;
  83. function CreateUpfrontLayer(Li: PLayer_Info location 'a0'; Bm: PBitmap location 'a1'; X0: LongInt location 'd0'; Y0: LongInt location 'd1'; X1: LongInt location 'd2'; Y1: LongInt location 'd3'; Flags: LongInt location 'd4'; Bm2: PBitmap location 'a2'): PLayer; SysCall LayersBase 036;
  84. function CreateBehindLayer(Li: PLayer_Info location 'a0'; Bm: PBitmap location 'a1'; X0: LongInt location 'd0'; Y0: LongInt location 'd1'; X1: LongInt location 'd2'; Y1: LongInt location 'd3'; Flags: LongInt location 'd4'; Bm2: PBitmap location 'a2'): PLayer; SysCall LayersBase 042;
  85. function UpfrontLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'): LongInt; SysCall LayersBase 048;
  86. function BehindLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'): LongInt; SysCall LayersBase 054;
  87. function MoveLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'; Dx: LongInt location 'd0'; Dy: LongInt location 'd1'): LongInt; SysCall LayersBase 060;
  88. function SizeLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'; Dx: LongInt location 'd0'; Dy: LongInt location 'd1'): LongInt; SysCall LayersBase 066;
  89. procedure ScrollLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'; Dx: LongInt location 'd0'; Dy: LongInt location 'd1'); SysCall LayersBase 072;
  90. function BeginUpdate(L: PLayer location 'a0'): LongInt; SysCall LayersBase 078;
  91. procedure EndUpdate(Layer: PLayer location 'a0'; Flag: LongWord location 'd0'); SysCall LayersBase 084;
  92. function DeleteLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'): LongInt; SysCall LayersBase 090;
  93. procedure LockLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'); SysCall LayersBase 096;
  94. procedure UnlockLayer(Layer: PLayer location 'a0'); SysCall LayersBase 102;
  95. procedure LockLayers(Li: PLayer_Info location 'a0'); SysCall LayersBase 108;
  96. procedure UnlockLayers(Li: PLayer_Info location 'a0'); SysCall LayersBase 114;
  97. procedure LockLayerInfo(Li: PLayer_Info location 'a0'); SysCall LayersBase 120;
  98. procedure SwapBitsRastPortClipRect(Rp: PRastPort location 'a0'; Cr: PClipRect location 'a1'); SysCall LayersBase 126;
  99. function WhichLayer(Li: PLayer_Info location 'a0'; X: LongInt location 'd0'; Y: LongInt location 'd1'): PLayer; SysCall LayersBase 132;
  100. procedure UnlockLayerInfo(Li: PLayer_Info location 'a0'); SysCall LayersBase 138;
  101. function NewLayerInfo: PLayer_Info; SysCall LayersBase 144;
  102. procedure DisposeLayerInfo(Li: PLayer_Info location 'a0'); SysCall LayersBase 150;
  103. function FattenLayerInfo(Li: PLayer_Info location 'a0'): LongInt; SysCall LayersBase 156;
  104. procedure ThinLayerInfo(Li: PLayer_Info location 'a0'); SysCall LayersBase 162;
  105. function MoveLayerInFrontOf(Layer_To_Move: PLayer location 'a0'; Other_Layer: PLayer location 'a1'): LongInt; SysCall LayersBase 168;
  106. function InstallClipRegion(Layer: PLayer location 'a0'; const Region: PRegion location 'a1'): PRegion; SysCall LayersBase 174;
  107. function MoveSizeLayer(Layer: PLayer location 'a0'; Dx: LongInt location 'd0'; Dy: LongInt location 'd1'; Dw: LongInt location 'd2'; Dh: LongInt location 'd3'): LongInt; SysCall LayersBase 180;
  108. function CreateUpfrontHookLayer(Li: PLayer_Info location 'a0'; Bm: PBitmap location 'a1'; X0: LongInt location 'd0'; Y0: LongInt location 'd1'; X1: LongInt location 'd2'; Y1: LongInt location 'd3'; Flags: LongInt location 'd4'; Hook: PHook location 'a3'; Bm2: PBitmap location 'a2'): PLayer; SysCall LayersBase 186;
  109. function CreateBehindHookLayer(Li: PLayer_Info location 'a0'; Bm: PBitmap location 'a1'; X0: LongInt location 'd0'; Y0: LongInt location 'd1'; X1: LongInt location 'd2'; Y1: LongInt location 'd3'; Flags: LongInt location 'd4'; Hook: PHook location 'a3'; Bm2: PBitmap location 'a2'): PLayer; SysCall LayersBase 192;
  110. function InstallLayerHook(Layer: PLayer location 'a0'; Hook: PHook location 'a1'): PHook; SysCall LayersBase 198;
  111. function InstallLayerInfoHook(Li: PLayer_Info location 'a0'; const Hook: PHook location 'a1'): PHook; SysCall LayersBase 204;
  112. procedure SortLayerCR(Layer: PLayer location 'a0'; Dx: LongInt location 'd0'; Dy: LongInt location 'd1'); SysCall LayersBase 210;
  113. procedure DoHookClipRects(Hook: PHook location 'a0'; RPort: PRastPort location 'a1'; const Rect: PRectangle location 'a2'); SysCall LayersBase 216;
  114. // V50 (MorphOS)
  115. function CreateUpfrontLayerTagList(Li: PLayer_Info location 'a0'; Bm: PBitmap location 'a1'; X0: LongInt location 'd0'; Y0: LongInt location 'd1'; X1: LongInt location 'd2'; Y1: LongInt location 'd3'; Flags: LongInt location 'd4'; Taglist: PTagItem location 'a2'): PLayer; SysCall LayersBase 234;
  116. function CreateBehindLayerTagList(Li: PLayer_Info location 'a0'; Bm: PBitmap location 'a1'; X0: LongInt location 'd0'; Y0: LongInt location 'd1'; X1: LongInt location 'd2'; Y1: LongInt location 'd3'; Flags: LongInt location 'd4'; Taglist: PTagItem location 'a2'): PLayer; SysCall LayersBase 240;
  117. // V52 (MorphOS)
  118. function WhichLayerBehindLayer(L: PLayer location 'a0'; X: LongInt location 'd0'; Y: LongInt location 'd1'): PLayer; SysCall LayersBase 252;
  119. function IsLayerVisible(L: PLayer location 'a0'): LongBool; SysCall LayersBase 258;
  120. function RenderLayerInfoTagList(Li: PLayer_Info location 'a0'; Tags: PTagItem location 'a1'): LongBool; SysCall LayersBase 282;
  121. procedure LockLayerUpdates(L: PLayer location 'a0'); SysCall LayersBase 288;
  122. procedure UnlockLayerUpdates(L: PLayer location 'a0'); SysCall LayersBase 294;
  123. function IsVisibleInLayer(L: PLayer location 'a0'; X0: LongInt location 'd0'; Y0: LongInt location 'd1'; X1: LongInt location 'd2'; Y1: LongInt location 'd3'): LongBool; SysCall LayersBase 300;
  124. function IsLayerHitable(L: PLayer location 'a0'): LongBool; SysCall LayersBase 306;
  125. // Var args Version
  126. function RenderLayerInfoTags(Li: PLayer_Info; const Tags: array of PtrUInt): LongBool; inline;
  127. { Helper func }
  128. function InitLayersLibrary : boolean;
  129. implementation
  130. function RenderLayerInfoTags(Li: PLayer_Info; const Tags: array of PtrUInt): LongBool; inline;
  131. begin
  132. RenderLayerInfoTags := RenderLayerInfoTagList(Li, @Tags);
  133. end;
  134. const
  135. { Change VERSION and LIBVERSION to proper values }
  136. VERSION : string[2] = '50';
  137. LIBVERSION : longword = 50;
  138. function InitLayersLibrary : boolean;
  139. begin
  140. InitLayersLibrary := Assigned(LayersBase);
  141. end;
  142. initialization
  143. LayersBase := OpenLibrary(LAYERSNAME,LIBVERSION);
  144. finalization
  145. if Assigned(LayersBase) then
  146. CloseLibrary(LayersBase);
  147. end.