palettei.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. {
  2. Free Pascal port of the OpenPTC C++ library.
  3. Copyright (C) 2001-2003 Nikolay Nikolov ([email protected])
  4. Original C++ version by Glenn Fiedler ([email protected])
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. }
  17. Constructor TPTCPalette.Create;
  18. Var
  19. zero : Array[0..255] Of int32;
  20. Begin
  21. m_locked := False;
  22. If Not Hermes_Init Then
  23. Raise TPTCError.Create('could not initialize hermes');
  24. m_handle := Hermes_PaletteInstance;
  25. If m_handle = 0 Then
  26. Raise TPTCError.Create('could not create hermes palette instance');
  27. FillChar(zero, SizeOf(zero), 0);
  28. load(zero);
  29. End;
  30. Constructor TPTCPalette.Create(Const _data : Array Of int32);
  31. Begin
  32. m_locked := False;
  33. If Not Hermes_Init Then
  34. Raise TPTCError.Create('could not initialize hermes');
  35. m_handle := Hermes_PaletteInstance;
  36. If m_handle = 0 Then
  37. Raise TPTCError.Create('could not create hermes palette instance');
  38. load(_data);
  39. End;
  40. Constructor TPTCPalette.Create(Const palette : TPTCPalette);
  41. Begin
  42. m_locked := False;
  43. If Not Hermes_Init Then
  44. Raise TPTCError.Create('could not initialize hermes');
  45. m_handle := Hermes_PaletteInstance;
  46. If m_handle = 0 Then
  47. Raise TPTCError.Create('could not create hermes palette instance');
  48. ASSign(palette);
  49. End;
  50. Destructor TPTCPalette.Destroy;
  51. Begin
  52. If m_locked Then
  53. Raise TPTCError.Create('palette is still locked');
  54. Hermes_PaletteReturn(m_handle);
  55. Hermes_Done;
  56. Inherited Destroy;
  57. End;
  58. Procedure TPTCPalette.Assign(Const palette : TPTCPalette);
  59. Begin
  60. If Self = palette Then
  61. Raise TPTCError.Create('self assignment is not allowed');
  62. Hermes_PaletteSet(m_handle, Hermes_PaletteGet(palette.m_handle));
  63. End;
  64. Function TPTCPalette.Equals(Const palette : TPTCPalette) : Boolean;
  65. Begin
  66. Equals := CompareDWord(Hermes_PaletteGet(m_handle)^, Hermes_PaletteGet(palette.m_handle)^, 1024 Div 4) = 0;
  67. End;
  68. Function TPTCPalette.lock : Pint32;
  69. Begin
  70. If m_locked Then
  71. Raise TPTCError.Create('palette is already locked');
  72. m_locked := True;
  73. lock := Hermes_PaletteGet(m_handle);
  74. End;
  75. Procedure TPTCPalette.unlock;
  76. Begin
  77. If Not m_locked Then
  78. Raise TPTCError.Create('palette is not locked');
  79. m_locked := False;
  80. End;
  81. Procedure TPTCPalette.load(Const _data : Array Of int32);
  82. Begin
  83. Hermes_PaletteSet(m_handle, @_data);
  84. End;
  85. Procedure TPTCPalette.load(_data : Pointer);
  86. Begin
  87. Hermes_PaletteSet(m_handle, _data);
  88. End;
  89. Procedure TPTCPalette.save(Var _data : Array Of int32);
  90. Begin
  91. Move(Hermes_PaletteGet(m_handle)^, _data, 1024);
  92. End;
  93. Procedure TPTCPalette.save(_data : Pointer);
  94. Begin
  95. Move(Hermes_PaletteGet(m_handle)^, _data^, 1024);
  96. End;
  97. Function TPTCPalette.data : Pint32;
  98. Begin
  99. data := Hermes_PaletteGet(m_handle);
  100. End;