layers.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. unit layers;
  17. interface
  18. uses exec, agraphics, utility;
  19. const
  20. LAYERSIMPLE = 1;
  21. LAYERSMART = 2;
  22. LAYERSUPER = 4;
  23. LAYERUPDATING = $10;
  24. LAYERBACKDROP = $40;
  25. LAYERREFRESH = $80;
  26. LAYER_CLIPRECTS_LOST = $100; // during BeginUpdate or during layerop this happens if out of memory
  27. LAYERIREFRESH = $200;
  28. LAYERIREFRESH2 = $400;
  29. type
  30. PLayer_Info = ^TLayer_Info;
  31. TLayer_Info = packed record
  32. top_layer : PLayer;
  33. check_lp : PLayer; // Private
  34. obs : PClipRect;
  35. FreeClipRects : PClipRect; // Private
  36. PrivateReserve1, // Private
  37. PrivateReserve2 : LongInt; // Private
  38. Lock : TSignalSemaphore; // Private
  39. gs_Head : TMinList; // Private
  40. PrivateReserve3 : SmallInt; // Private
  41. PrivateReserve4 : APTR; // Private
  42. Flags : Word;
  43. fatten_count : ShortInt; // Private
  44. LockLayersCount : ShortInt; // Private
  45. PrivateReserve5 : SmallInt; // Private
  46. BlankHook, // Private
  47. LayerInfo_extra : APTR; // Private
  48. end;
  49. const
  50. NEWLAYERINFO_CALLED = 1;
  51. // LAYERS_NEVERBACKFILL, available since v52.22
  52. // unlike with NOBACKFILL, the new layer will not be filled with contents
  53. // of layers underneath it, contents is lost after resize
  54. LAYERS_NEVERBACKFILL = 2;
  55. LAYERS_NOBACKFILL = 1;
  56. LAYERS_BACKFILL = 0;
  57. // Tags for Create#?LayerTagList
  58. LA_Dummy = TAG_USER + 1024;
  59. LA_BackfillHook = LA_Dummy + $0001;
  60. LA_TransRegion = LA_Dummy + $0002;
  61. LA_TransHook = LA_Dummy + $0003;
  62. LA_WindowPtr = LA_Dummy + $0004;
  63. LA_SuperBitMap = LA_Dummy + $0005; // replaces bm2 in function call
  64. LR_Dummy = TAG_USER + 1150;
  65. LR_Destination_RastPort = LR_Dummy + 1; // PRastPort to render in
  66. LR_Destination_BitMap = LR_Dummy + 2; // PBitMap to render in. mutually exclusive with LR_Destination_RastPort. Do note that the destination
  67. // bitmap (or the rastport's bitmap) MUST be in the same format as the source you want to render from!
  68. 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
  69. LR_LayerInfo_Bounds = LR_Dummy + 4; // PRectangle. limits the portion of a LayerInfo to draw
  70. 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
  71. LR_RenderList = LR_Dummy + 6; // PPLayer. a nil terminated list of PLayer pointers to render if they are within given bounds
  72. LR_IgnoreList = LR_Dummy + 7; // PPLayer. a nil terminated list of PLayer pointers to ommit when rendering the layerinfo. mutually exclusive with LR_RenderList!
  73. LAYERSNAME: PChar = 'layers.library';
  74. var
  75. LayersBase: PLibrary = nil;
  76. procedure InitLayers(Li: PLayer_Info location 'a0'); SysCall LayersBase 030;
  77. 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;
  78. 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;
  79. function UpfrontLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'): LongInt; SysCall LayersBase 048;
  80. function BehindLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'): LongInt; SysCall LayersBase 054;
  81. function MoveLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'; Dx: LongInt location 'd0'; Dy: LongInt location 'd1'): LongInt; SysCall LayersBase 060;
  82. function SizeLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'; Dx: LongInt location 'd0'; Dy: LongInt location 'd1'): LongInt; SysCall LayersBase 066;
  83. procedure ScrollLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'; Dx: LongInt location 'd0'; Dy: LongInt location 'd1'); SysCall LayersBase 072;
  84. function BeginUpdate(L: PLayer location 'a0'): LongInt; SysCall LayersBase 078;
  85. procedure EndUpdate(Layer: PLayer location 'a0'; Flag: LongWord location 'd0'); SysCall LayersBase 084;
  86. function DeleteLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'): LongInt; SysCall LayersBase 090;
  87. procedure LockLayer(Dummy: LongInt location 'a0'; Layer: PLayer location 'a1'); SysCall LayersBase 096;
  88. procedure UnlockLayer(Layer: PLayer location 'a0'); SysCall LayersBase 102;
  89. procedure LockLayers(Li: PLayer_Info location 'a0'); SysCall LayersBase 108;
  90. procedure UnlockLayers(Li: PLayer_Info location 'a0'); SysCall LayersBase 114;
  91. procedure LockLayerInfo(Li: PLayer_Info location 'a0'); SysCall LayersBase 120;
  92. procedure SwapBitsRastPortClipRect(Rp: PRastPort location 'a0'; Cr: PClipRect location 'a1'); SysCall LayersBase 126;
  93. function WhichLayer(Li: PLayer_Info location 'a0'; X: LongInt location 'd0'; Y: LongInt location 'd1'): PLayer; SysCall LayersBase 132;
  94. procedure UnlockLayerInfo(Li: PLayer_Info location 'a0'); SysCall LayersBase 138;
  95. function NewLayerInfo: PLayer_Info; SysCall LayersBase 144;
  96. procedure DisposeLayerInfo(Li: PLayer_Info location 'a0'); SysCall LayersBase 150;
  97. function FattenLayerInfo(Li: PLayer_Info location 'a0'): LongInt; SysCall LayersBase 156;
  98. procedure ThinLayerInfo(Li: PLayer_Info location 'a0'); SysCall LayersBase 162;
  99. function MoveLayerInFrontOf(Layer_To_Move: PLayer location 'a0'; Other_Layer: PLayer location 'a1'): LongInt; SysCall LayersBase 168;
  100. function InstallClipRegion(Layer: PLayer location 'a0'; const Region: PRegion location 'a1'): PRegion; SysCall LayersBase 174;
  101. 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;
  102. 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;
  103. 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;
  104. function InstallLayerHook(Layer: PLayer location 'a0'; Hook: PHook location 'a1'): PHook; SysCall LayersBase 198;
  105. function InstallLayerInfoHook(Li: PLayer_Info location 'a0'; const Hook: PHook location 'a1'): PHook; SysCall LayersBase 204;
  106. procedure SortLayerCR(Layer: PLayer location 'a0'; Dx: LongInt location 'd0'; Dy: LongInt location 'd1'); SysCall LayersBase 210;
  107. procedure DoHookClipRects(Hook: PHook location 'a0'; RPort: PRastPort location 'a1'; const Rect: PRectangle location 'a2'); SysCall LayersBase 216;
  108. // V50 (MorphOS)
  109. 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;
  110. 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;
  111. // V52 (MorphOS)
  112. function WhichLayerBehindLayer(L: PLayer location 'a0'; X: LongInt location 'd0'; Y: LongInt location 'd1'): PLayer; SysCall LayersBase 252;
  113. function IsLayerVisible(L: PLayer location 'a0'): LongBool; SysCall LayersBase 258;
  114. function RenderLayerInfoTagList(Li: PLayer_Info location 'a0'; Tags: PTagItem location 'a1'): LongBool; SysCall LayersBase 282;
  115. procedure LockLayerUpdates(L: PLayer location 'a0'); SysCall LayersBase 288;
  116. procedure UnlockLayerUpdates(L: PLayer location 'a0'); SysCall LayersBase 294;
  117. 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;
  118. function IsLayerHitable(L: PLayer location 'a0'): LongBool; SysCall LayersBase 306;
  119. // Var args Version
  120. function RenderLayerInfoTags(Li: PLayer_Info; const Tags: array of PtrUInt): LongBool; inline;
  121. { Helper func }
  122. function InitLayersLibrary : boolean;
  123. implementation
  124. function RenderLayerInfoTags(Li: PLayer_Info; const Tags: array of PtrUInt): LongBool; inline;
  125. begin
  126. RenderLayerInfoTags := RenderLayerInfoTagList(Li, @Tags);
  127. end;
  128. const
  129. { Change VERSION and LIBVERSION to proper values }
  130. VERSION : string[2] = '50';
  131. LIBVERSION : longword = 50;
  132. function InitLayersLibrary : boolean;
  133. begin
  134. InitLayersLibrary := Assigned(LayersBase);
  135. end;
  136. initialization
  137. LayersBase := OpenLibrary(LAYERSNAME,LIBVERSION);
  138. finalization
  139. if Assigned(LayersBase) then
  140. CloseLibrary(LayersBase);
  141. end.