/packages/ptc/src/core/baseconsolei.inc

https://github.com/slibre/freepascal · Pascal · 234 lines · 175 code · 26 blank · 33 comment · 4 complexity · 6925311c34c7cb93330eb61c1f1f6d13 MD5 · raw file

  1. {
  2. Free Pascal port of the OpenPTC C++ library.
  3. Copyright (C) 2001-2003, 2006, 2007, 2009-2012 Nikolay Nikolov (nickysn@users.sourceforge.net)
  4. Original C++ version by Glenn Fiedler (ptc@gaffer.org)
  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. with the following modification:
  10. As a special exception, the copyright holders of this library give you
  11. permission to link this library with independent modules to produce an
  12. executable, regardless of the license terms of these independent modules,and
  13. to copy and distribute the resulting executable under terms of your choice,
  14. provided that you also meet, for each linked independent module, the terms
  15. and conditions of the license of that module. An independent module is a
  16. module which is not derived from or based on this library. If you modify
  17. this library, you may extend this exception to your version of the library,
  18. but you are not obligated to do so. If you do not wish to do so, delete this
  19. exception statement from your version.
  20. This library is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. Lesser General Public License for more details.
  24. You should have received a copy of the GNU Lesser General Public
  25. License along with this library; if not, write to the Free Software
  26. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. }
  28. type
  29. TPTCBaseConsole = class(TInterfacedObject, IPTCConsole, IPTCSurface)
  30. private
  31. FReleaseEnabled: Boolean;
  32. procedure SetKeyReleaseEnabled(AValue: Boolean);
  33. function GetKeyReleaseEnabled: Boolean;
  34. function GetWidth: Integer; virtual; abstract;
  35. function GetHeight: Integer; virtual; abstract;
  36. function GetPitch: Integer; virtual; abstract;
  37. function GetArea: IPTCArea; virtual; abstract;
  38. function GetFormat: IPTCFormat; virtual; abstract;
  39. function GetPages: Integer; virtual; abstract;
  40. function GetName: string; virtual; abstract;
  41. function GetTitle: string; virtual; abstract;
  42. function GetInformation: string; virtual; abstract;
  43. function GetOpenGL_Enabled: Boolean; virtual; abstract;
  44. procedure SetOpenGL_Enabled(AValue: Boolean); virtual; abstract;
  45. function GetOpenGL_Attributes: IPTCOpenGLAttributes;
  46. protected
  47. FOpenGLAttributes: IPTCOpenGLAttributes;
  48. public
  49. constructor Create; virtual;
  50. procedure Copy(ASurface: IPTCSurface); virtual; abstract;
  51. procedure Copy(ASurface: IPTCSurface;
  52. ASource, ADestination: IPTCArea); virtual; abstract;
  53. function Lock: Pointer; virtual; abstract;
  54. procedure Unlock; virtual; abstract;
  55. procedure Load(const APixels: Pointer;
  56. AWidth, AHeight, APitch: Integer;
  57. AFormat: IPTCFormat;
  58. APalette: IPTCPalette); virtual; abstract;
  59. procedure Load(const APixels: Pointer;
  60. AWidth, AHeight, APitch: Integer;
  61. AFormat: IPTCFormat;
  62. APalette: IPTCPalette;
  63. ASource, ADestination: IPTCArea); virtual; abstract;
  64. procedure Save(APixels: Pointer;
  65. AWidth, AHeight, APitch: Integer;
  66. AFormat: IPTCFormat;
  67. APalette: IPTCPalette); virtual; abstract;
  68. procedure Save(APixels: Pointer;
  69. AWidth, AHeight, APitch: Integer;
  70. AFormat: IPTCFormat;
  71. APalette: IPTCPalette;
  72. ASource, ADestination: IPTCArea); virtual; abstract;
  73. procedure Clear; virtual; abstract;
  74. procedure Clear(AColor: IPTCColor); virtual; abstract;
  75. procedure Clear(AColor: IPTCColor;
  76. AArea: IPTCArea); virtual; abstract;
  77. procedure Palette(APalette: IPTCPalette); virtual; abstract;
  78. procedure Clip(AArea: IPTCArea); virtual; abstract;
  79. function Option(const AOption: String): Boolean; virtual; abstract;
  80. function Clip: IPTCArea; virtual; abstract;
  81. function Palette: IPTCPalette; virtual; abstract;
  82. procedure Configure(const AFileName: String); virtual; abstract;
  83. function Modes: TPTCModeList; virtual; abstract;
  84. procedure Open(const ATitle: string; APages: Integer = 0); overload; virtual; abstract;
  85. procedure Open(const ATitle: string; AFormat: IPTCFormat;
  86. APages: Integer = 0); overload; virtual; abstract;
  87. procedure Open(const ATitle: string; AWidth, AHeight: Integer;
  88. AFormat: IPTCFormat; APages: Integer = 0); overload; virtual; abstract;
  89. procedure Open(const ATitle: string; AMode: IPTCMode;
  90. APages: Integer = 0); overload; virtual; abstract;
  91. procedure Close; virtual; abstract;
  92. procedure Flush; virtual; abstract;
  93. procedure Finish; virtual; abstract;
  94. procedure Update; virtual; abstract;
  95. procedure Update(AArea: IPTCArea); virtual; abstract;
  96. { event handling }
  97. function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; virtual; abstract;
  98. function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; virtual; abstract;
  99. { key handling }
  100. function KeyPressed: Boolean;
  101. function PeekKey(out AKey: IPTCKeyEvent): Boolean;
  102. procedure ReadKey(out AKey: IPTCKeyEvent);
  103. procedure ReadKey;
  104. property KeyReleaseEnabled: Boolean read GetKeyReleaseEnabled write SetKeyReleaseEnabled;
  105. property Pages: Integer read GetPages;
  106. property Name: string read GetName;
  107. property Title: string read GetTitle;
  108. property Information: string read GetInformation;
  109. property Width: Integer read GetWidth;
  110. property Height: Integer read GetHeight;
  111. property Pitch: Integer read GetPitch;
  112. property Area: IPTCArea read GetArea;
  113. property Format: IPTCFormat read GetFormat;
  114. property OpenGL_Enabled: Boolean read GetOpenGL_Enabled write SetOpenGL_Enabled;
  115. procedure OpenGL_SwapBuffers; virtual; abstract;
  116. procedure OpenGL_SetSwapInterval(AInterval: Integer); virtual; abstract;
  117. function OpenGL_GetSwapInterval: Integer; virtual; abstract;
  118. end;
  119. TPTCOpenGLLessConsole = class(TPTCBaseConsole)
  120. private
  121. function GetOpenGL_Enabled: Boolean; override;
  122. procedure SetOpenGL_Enabled(AValue: Boolean); override;
  123. public
  124. procedure OpenGL_SwapBuffers; override;
  125. procedure OpenGL_SetSwapInterval(AInterval: Integer); override;
  126. function OpenGL_GetSwapInterval: Integer; override;
  127. end;
  128. constructor TPTCBaseConsole.Create;
  129. begin
  130. FReleaseEnabled := False;
  131. FOpenGLAttributes := TPTCOpenGLAttributes.Create;
  132. end;
  133. function TPTCBaseConsole.GetOpenGL_Attributes: IPTCOpenGLAttributes;
  134. begin
  135. Result := FOpenGLAttributes;
  136. end;
  137. function TPTCBaseConsole.KeyPressed: Boolean;
  138. var
  139. k, kpeek: IPTCEvent;
  140. begin
  141. repeat
  142. kpeek := PeekEvent(False, [PTCKeyEvent]);
  143. if kpeek = nil then
  144. exit(False);
  145. if FReleaseEnabled or (kpeek as IPTCKeyEvent).Press then
  146. exit(True);
  147. NextEvent(k, False, [PTCKeyEvent]);
  148. until False;
  149. end;
  150. procedure TPTCBaseConsole.ReadKey(out AKey: IPTCKeyEvent);
  151. var
  152. ev: IPTCEvent;
  153. begin
  154. repeat
  155. NextEvent(ev, True, [PTCKeyEvent]);
  156. until FReleaseEnabled or (ev as IPTCKeyEvent).Press;
  157. AKey := ev as IPTCKeyEvent;
  158. end;
  159. function TPTCBaseConsole.PeekKey(out AKey: IPTCKeyEvent): Boolean;
  160. begin
  161. if KeyPressed then
  162. begin
  163. ReadKey(AKey);
  164. Result := True;
  165. end
  166. else
  167. Result := False;
  168. end;
  169. procedure TPTCBaseConsole.ReadKey;
  170. var
  171. k: IPTCKeyEvent;
  172. begin
  173. ReadKey(k);
  174. end;
  175. procedure TPTCBaseConsole.SetKeyReleaseEnabled(AValue: Boolean);
  176. begin
  177. FReleaseEnabled := AValue;
  178. end;
  179. function TPTCBaseConsole.GetKeyReleaseEnabled: Boolean;
  180. begin
  181. Result := FReleaseEnabled;
  182. end;
  183. function TPTCOpenGLLessConsole.GetOpenGL_Enabled: Boolean;
  184. begin
  185. Result := False;
  186. end;
  187. procedure TPTCOpenGLLessConsole.SetOpenGL_Enabled(AValue: Boolean);
  188. begin
  189. if AValue then
  190. raise TPTCError.Create('Console does not support OpenGL');
  191. end;
  192. procedure TPTCOpenGLLessConsole.OpenGL_SwapBuffers;
  193. begin
  194. raise TPTCError.Create('Console does not support OpenGL');
  195. end;
  196. procedure TPTCOpenGLLessConsole.OpenGL_SetSwapInterval(AInterval: Integer);
  197. begin
  198. raise TPTCError.Create('Console does not support OpenGL');
  199. end;
  200. function TPTCOpenGLLessConsole.OpenGL_GetSwapInterval: Integer;
  201. begin
  202. Result := -1;
  203. raise TPTCError.Create('Console does not support OpenGL');
  204. end;