layers.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2016 by Free Pascal development team
  4. layers.library functions for Amiga OS 4.x
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$PACKRECORDS 2}
  12. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit layers;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. interface
  16. {$IFDEF FPC_DOTTEDUNITS}
  17. uses
  18. Amiga.Core.Exec, Amiga.Core.Agraphics, Amiga.Core.Utility;
  19. {$ELSE FPC_DOTTEDUNITS}
  20. uses
  21. exec, agraphics, utility;
  22. {$ENDIF FPC_DOTTEDUNITS}
  23. const
  24. LAYERSIMPLE = 1;
  25. LAYERSMART = 2;
  26. LAYERSUPER = 4;
  27. LAYEROFFSCREEN = 8; // New for V53 (system private)
  28. LAYERUPDATING = $10;
  29. LAYERBACKDROP = $40;
  30. LAYERREFRESH = $80;
  31. LAYER_CLIPRECTS_LOST = $100; // during BeginUpdate or during layerop this happens if out of memory
  32. LAYERIREFRESH = $200;
  33. LAYERIREFRESH2 = $400;
  34. LAYERSAVEBACK = $800; // New for V44: Set if clips are saved back
  35. LAYERHIDDEN = $1000; // New for V45: Layer is invisible
  36. LAYERSTAYTOP = $2000; // New for V45: Layer can't be moved behind other layers
  37. LAYERMOVECHANGESSHAPE = $4000; // New for V45: Report MoveLayer() to shapechangehook
  38. LAYERBACKUP = $8000; // New for V53 (system private)
  39. ALPHA_PREFIX = $01000000;
  40. type
  41. PLayer_Info = ^TLayer_Info;
  42. TLayer_Info = record
  43. top_layer: PLayer; // Frontmost layer
  44. resPtr1: Pointer; // V45 spare
  45. resPtr2: Pointer; // Another V45 spare
  46. FreeClipRects: PClipRect; // Implements a backing store of cliprects to avoid frequent re-allocation of cliprects. Private
  47. Bounds: TRectangle; // clipping bounds of this layer info. All layers are clipped against this
  48. Lock: TSignalSemaphore; // Layer_Info lock
  49. gs_Head: TMinList; // linked list of all semaphores of all layers within this layer info
  50. PrivateReserve3: Smallint; // Private
  51. ClipRectPool: APTR; // V45: Pool for cliprects (private use only)
  52. Flags: Word;
  53. fatten_count: Shortint; // V45 spare, no longer used
  54. LockLayersCount: Shortint; // Counts # times LockLayers has been called
  55. PrivateReserve5: smallint; // Private
  56. BlankHook: PHook; // LayerInfo backfill hook
  57. LayerInfo_extra: Pointer; // Private
  58. end;
  59. const
  60. NEWLAYERINFO_CALLED = 1;
  61. LIF_EXTLBOUNDS = $0200; // System private
  62. LIF_OFFSCREEN = $0400; // System private
  63. LIF_SYNCCOMPOSE = $0800; // System private
  64. LIF_SYNCALWAYS = $1000; // System private
  65. LIF_COLLECTONLY = $2000; // System private
  66. LIF_IGNORE = $4000; // System private
  67. LIF_OPTIMIZE = $8000; // System private
  68. // Special backfill hook values you may want to install here.
  69. LAYERS_NOBACKFILL = PHook(1); // the value needed to get no backfill hook
  70. LAYERS_BACKFILL = PHook(0); // the value needed to get the default backfill hook
  71. // Special codes for ShowLayer(): Give this as target layer where to move your layer to.
  72. LAYER_BACKMOST = PLayer(0);
  73. LAYER_FRONTMOST = PLayer(1);
  74. //CreateBackFillHookA() attributes
  75. LAYERS_DUMMY = TAG_USER;
  76. BFHA_APen = LAYERS_DUMMY + 0; // foreground color (def not 0)
  77. BFHA_BPen = LAYERS_DUMMY + 1; // background color (def not 0)
  78. BFHA_DrMd = LAYERS_DUMMY + 2; // drawmode (def JAM2)
  79. BFHA_PatSize = LAYERS_DUMMY + 3; // pattern size, see SetAfPt()
  80. BFHA_Pattern = LAYERS_DUMMY + 4; // the pattern
  81. BFHA_BitMap = LAYERS_DUMMY + 5; // bitmap to use as backfill
  82. BFHA_Width = LAYERS_DUMMY + 6; // width of bm
  83. BFHA_Height = LAYERS_DUMMY + 7; // height of bm
  84. BFHA_OffsetX = LAYERS_DUMMY + 8; // x offset into the bm
  85. BFHA_OffsetY = LAYERS_DUMMY + 9; // y offset into the bm
  86. //CreateLayerA() attributes
  87. LAYA_MinX = LAYERS_DUMMY + 30; // upper left corner
  88. LAYA_MinY = LAYERS_DUMMY + 31; // of layer
  89. LAYA_MaxX = LAYERS_DUMMY + 32; // lower right corner
  90. LAYA_MaxY = LAYERS_DUMMY + 33; // of layer
  91. LAYA_ShapeRegion = LAYERS_DUMMY + 34; // shape of this layer
  92. LAYA_ShapeHook = LAYERS_DUMMY + 35; // hook to create layer shape
  93. LAYA_InFrontOf = LAYERS_DUMMY + 36; // create the layer in front of the given one
  94. LAYA_BitMap = LAYERS_DUMMY + 37; // common bitmap used by all layers
  95. LAYA_SuperBitMap = LAYERS_DUMMY + 38; // the superbitmap, sets LAYERSUPER
  96. LAYA_SimpleRefresh = LAYERS_DUMMY + 39; // make it a simple refresh layer
  97. LAYA_SmartRefresh = LAYERS_DUMMY + 40; // smart refresh layer (default TRUE)
  98. LAYA_Hidden = LAYERS_DUMMY + 41; // make it invisible
  99. LAYA_Backdrop = LAYERS_DUMMY + 42; // request backdrop layer
  100. LAYA_Flags = LAYERS_DUMMY + 43; // layer flags
  101. LAYA_BackFillHook = LAYERS_DUMMY + 44; // backfill hook for this layer
  102. LAYA_Behind = LAYERS_DUMMY + 45; // create behind layer (default FALSE)
  103. LAYA_StayTop = LAYERS_DUMMY + 46; // create a window that stays on top of all other layers
  104. LAYA_AlphaClips = LAYERS_DUMMY + 47; // alpha shape of this layer
  105. LAYA_AlphaHook = LAYERS_DUMMY + 48; // hook to create layer alpha shape
  106. LAYA_Opaqueness = LAYERS_DUMMY + 49; // opaqueness of this layer
  107. LAYA_Window = LAYERS_DUMMY + 50; // window associated to this layer (system use only)
  108. LAYA_Padding = LAYERS_DUMMY + 51; // extra padding on layer sides, extending screen redraw area (system use only)
  109. //SetLayerInfoAttrsA()/GetLayerInfoAttrsA() attributes
  110. LAYERINFO_BackFillHook = LAYERS_DUMMY + 100; // Backfill hook for this LayerInfo
  111. LAYERINFO_Bounds = LAYERS_DUMMY + 101; // Clipping bounds for this LayerInfo
  112. LAYERINFO_OffScreenBitMap = LAYERS_DUMMY + 102; // Common offscreen bitmap for this LayerInfo's layers
  113. LAYERINFO_ComposeHook = LAYERS_DUMMY + 103; // Compositing hook for this LayerInfo
  114. LAYERINFO_ComposeLock = LAYERS_DUMMY + 104; // Semaphore protecting compositing hook
  115. // The message a backfill hook receives
  116. type
  117. PBackFillMessage = ^TBackFillMessage;
  118. TBackFillMessage = record
  119. Layer: PLayer;
  120. Bounds: TRectangle;
  121. OffsetX: LongInt;
  122. OffsetY: LongInt;
  123. end;
  124. // The message a compose hook receives (system private)
  125. PLayerComposeMsg = ^TLayerComposeMsg;
  126. TLayerComposeMsg = record
  127. Action: LongWord;
  128. LayerInfo: PLayer_Info;
  129. BackBitMap: PBitMap;
  130. Bounds: TRectangle;
  131. end;
  132. const
  133. LCM_COMPOSE = 0;
  134. LCM_DAMAGE = 1;
  135. LAYERSNAME: PAnsiChar = 'layers.library';
  136. var
  137. LayersBase: PLibrary = nil;
  138. ILayers: PInterface = nil;
  139. function LayersObtain(): LongWord; syscall ILayers 60;
  140. function LayersRelease(): LongWord; syscall ILayers 64;
  141. procedure LayersExpunge(); syscall ILayers 68;
  142. function LayersClone(): PInterface; syscall ILayers 72;
  143. procedure InitLayers(Li: PLayer_Info); syscall ILayers 76;
  144. function CreateUpfrontLayer(Li: PLayer_Info; Bm: PBitMap; X0, Y0, X1, Y1, Flags: LongInt; Bm2: PBitMap): PLayer; syscall ILayers 80;
  145. function CreateBehindLayer(Li: PLayer_Info; Bm: PBitMap; X0, Y0, X1, Y1, Flags: LongInt; Bm2: PBitMap): PLayer; syscall ILayers 84;
  146. function UpfrontLayer(Dummy: LongInt; Layer: PLayer): LongInt; syscall ILayers 88;
  147. function BehindLayer(Dummy: LongInt; Layer: PLayer): LongInt; syscall ILayers 92;
  148. function MoveLayer(Dummy: LongInt; Layer: PLayer; Dx, Dy: LongInt): LongInt; syscall ILayers 96;
  149. function SizeLayer(Summy: LongInt; Layer: PLayer; Dx, Dy: LongInt): LongInt; syscall ILayers 100;
  150. procedure ScrollLayer(Dummy: LongInt; Layer: PLayer; Dx, Dy: LongInt); syscall ILayers 104;
  151. function BeginUpdate(L: PLayer): LongInt; syscall ILayers 108;
  152. procedure EndUpdate(Layer: PLayer; Flag: LongWord); syscall ILayers 112;
  153. function DeleteLayer(Dummy: LongInt; Layer: PLayer): LongInt; syscall ILayers 116;
  154. procedure LockLayer(Dummy: LongInt; Layer: PLayer); syscall ILayers 120;
  155. procedure UnlockLayer(Layer: PLayer); syscall ILayers 124;
  156. procedure LockLayers(Li: PLayer_Info); syscall ILayers 128;
  157. procedure UnlockLayers(Li: PLayer_Info); syscall ILayers 132;
  158. procedure LockLayerInfo(Li: PLayer_Info); syscall ILayers 136;
  159. procedure SwapBitsRastPortClipRect(Rp: PRastPort; Cr: PClipRect); syscall ILayers 140;
  160. function WhichLayer(Li: PLayer_Info; X, Y: LongInt): PLayer; syscall ILayers 144;
  161. procedure UnlockLayerInfo(Li: PLayer_Info); syscall ILayers 148;
  162. function NewLayerInfo: PLayer_Info; syscall ILayers 152;
  163. procedure DisposeLayerInfo(Li: PLayer_Info); syscall ILayers 156;
  164. function FattenLayerInfo(Li: PLayer_Info): LongInt; syscall ILayers 160;
  165. procedure ThinLayerInfo(Li: PLayer_Info); syscall ILayers 164;
  166. function MoveLayerInFrontOf(LayerToMove: PLayer; OtherLayer: PLayer): LongInt; syscall ILayers 168;
  167. function InstallClipRegion(Layer: PLayer; const Region: PRegion): PRegion; syscall ILayers 172;
  168. function MoveSizeLayer(Layer: PLayer; Dx, Dy, Dw, Dh: LongInt): LongInt; syscall ILayers 176;
  169. function CreateUpfrontHookLayer(Li: PLayer_Info; Bm: PBitMap; X0, Y0, X1, Y1, Flags: LongInt; Hook: PHook; Bm2: PBitMap): PLayer; syscall ILayers 180;
  170. function CreateBehindHookLayer(Li: PLayer_Info; Bm: PBitMap; X0, Y0, X1, Y1, Flags: LongInt; Hook: PHook; Bm2: PBitMap): PLayer; syscall ILayers 184;
  171. function InstallLayerHook(Layer: PLayer; Hook: PHook): PHook; syscall ILayers 188;
  172. function InstallLayerInfoHook(Li: PLayer_Info; const Hook: PHook): PHook; syscall ILayers 192;
  173. procedure SortLayerCR(Layer: PLayer; Dx, Dy: LongInt); syscall ILayers 196;
  174. procedure DoHookClipRects(Hook: PHook; RPort: PRastPort; const Rect: PRectangle); syscall ILayers 200;
  175. function LayerOccluded(Layer: PLayer): LongInt; syscall ILayers 204;
  176. function HideLayer(Layer: PLayer): LongInt; syscall ILayers 208;
  177. function ShowLayer(Layer: PLayer): LongInt; syscall ILayers 212;
  178. function SetLayerInfoBounds(Li: PLayer_Info; Bounds: PRectangle): LongInt; syscall ILayers 216;
  179. function AllocClipRect(Li: PLayer_Info): PClipRect; syscall ILayers 220;
  180. procedure FreeClipRect(Li: PLayer_Info; Cr: PClipRect); syscall ILayers 224;
  181. function CreateLayerA(Li: PLayer_Info; TList: PTagItem): PLayer; syscall ILayers 228;
  182. // 232 CreateLayer
  183. function ChangeLayerShape(Layer: PLayer; Region: PRegion; Hook: PHook): PRegion; syscall ILayers 236;
  184. function CreateBackFillHookA(TList: PTagItem): PHook; syscall ILayers 240;
  185. // 244 CreateBackFillHook
  186. procedure DeleteBackFillHook(Hook: PHook); syscall ILayers 248;
  187. function SetBackFillHookAttrsA(Hook: PHook; Tags: PTagItem): LongWord; syscall ILayers 252;
  188. // 256 SetBackFillHookAttrs
  189. function GetBackFillHookAttrsA(Hook: PHook; Tags: PTagItem): LongWord; syscall ILayers 260;
  190. // 264 GetBackFillHookAttrs
  191. function ComposeLayersA(L: PLayer; Rect: PRectangle; TagList: PTagItem): LongWord; syscall ILayers 268;
  192. // 272 ComposeLayers
  193. function GetOffScreenLayerBitMap(L: PLayer; FallBack: PBitMap; Bounds: PRectangle): LongWord; syscall ILayers 276;
  194. function SetLayerInfoAttrsA(Li: PLayer_Info; TagList: PTagItem): LongWord; syscall ILayers 280;
  195. // 284 SetLayerInfoAttrs
  196. function GetLayerInfoAttrsA(Li: PLayer_Info; TagList: PTagItem): LongWord; syscall ILayers 288;
  197. // 292 GetLayerInfoAttrs
  198. function ChangeLayerAlpha(L: PLayer; Clips: PClipRect; Hook: PHook): PClipRect; syscall ILayers 296;
  199. function SetForegroundAlpha(L: PLayer; TemplatePtr: APTR; TemplateType, BytesPerRow: LongWord; Left, Top: LongInt; Width, Height, Flags: LongWord): LongWord; syscall ILayers 300;
  200. function SetLayerOpaqueness(L: PLayer; Opaqueness: LongWord): LongWord; syscall ILayers 304;
  201. function SetLayerOverlayRect(L: PLayer; Left, Top, Width, Height: LongInt; Flags: LongWord): LongWord; syscall ILayers 308;
  202. implementation
  203. const
  204. // Change VERSION and LIBVERSION to proper values
  205. LIBVERSION : longword = 0;
  206. initialization
  207. LayersBase := OpenLibrary(LAYERSNAME, LIBVERSION);
  208. if Assigned(LayersBase) then
  209. ILayers := GetInterface(LayersBase, 'main', 1, nil);
  210. finalization
  211. if Assigned(ILayers) then
  212. DropInterface(ILayers);
  213. if Assigned(LayersBase) then
  214. CloseLibrary(LayersBase);
  215. end.