console.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. Constructor TX11Console.Create;
  2. Var
  3. s : AnsiString;
  4. Begin
  5. x11disp := Nil;
  6. m_flags := 0;
  7. FillChar(m_modes, SizeOf(m_modes), 0);
  8. m_title := '';
  9. m_modes[0] := TPTCMode.Create;
  10. configure('/usr/share/ptc/ptc.conf');
  11. s := fpgetenv('HOME');
  12. If s = '' Then
  13. s := '/';
  14. If s[Length(s)] <> '/' Then
  15. s := s + '/';
  16. s := s + '.ptc.conf';
  17. configure(s);
  18. End;
  19. Destructor TX11Console.Destroy;
  20. Var
  21. I : Integer;
  22. Begin
  23. close;
  24. m_title := '';
  25. FreeAndNil(x11disp);
  26. For I := Low(m_modes) To High(m_modes) Do
  27. FreeAndNil(m_modes[I]);
  28. Inherited Destroy;
  29. End;
  30. Procedure TX11Console.configure(Const _file : String);
  31. Var
  32. F : Text;
  33. S : String;
  34. Begin
  35. ASSignFile(F, _file);
  36. {$I-}
  37. Reset(F);
  38. {$I+}
  39. If IOResult <> 0 Then
  40. Exit;
  41. While Not EoF(F) Do
  42. Begin
  43. {$I-}
  44. Readln(F, S);
  45. {$I+}
  46. If IOResult <> 0 Then
  47. Break;
  48. option(S);
  49. End;
  50. CloseFile(F);
  51. End;
  52. Function TX11Console.option(Const _option : String) : Boolean;
  53. Begin
  54. option := True;
  55. If _option = 'dga pedantic init' Then
  56. Begin
  57. m_flags := m_flags Or PTC_X11_PEDANTIC_DGA;
  58. Exit;
  59. End;
  60. If _option = 'dga off' Then
  61. Begin
  62. m_flags := m_flags Or PTC_X11_NODGA;
  63. Exit;
  64. End;
  65. If _option = 'leave window open' Then
  66. Begin
  67. m_flags := m_flags Or PTC_X11_LEAVE_WINDOW;
  68. Exit;
  69. End;
  70. If _option = 'leave display open' Then
  71. Begin
  72. m_flags := m_flags Or PTC_X11_LEAVE_DISPLAY;
  73. Exit;
  74. End;
  75. If x11disp <> Nil Then
  76. option := x11disp.m_copy.option(_option)
  77. Else
  78. option := False;
  79. End;
  80. Function TX11Console.modes : PPTCMode;
  81. Begin
  82. modes := @m_modes;
  83. End;
  84. {TODO: Find current pixel depth}
  85. Procedure TX11Console.open(Const _title : String; _pages : Integer);
  86. Var
  87. tmp : TPTCFormat;
  88. Begin
  89. setTitle(_title);
  90. tmp := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
  91. Try
  92. open(_title, tmp, _pages);
  93. Finally
  94. tmp.Free;
  95. End;
  96. End;
  97. Procedure TX11Console.open(Const _title : String; Const _format : TPTCFormat;
  98. _pages : Integer);
  99. Begin
  100. setTitle(_title);
  101. open(_title, 640, 480, _format, _pages);
  102. End;
  103. Procedure TX11Console.open(Const _title : String; _width, _height : Integer;
  104. Const _format : TPTCFormat; _pages : Integer);
  105. Var
  106. disp : PDisplay;
  107. screen : Integer;
  108. Begin
  109. close;
  110. setTitle(_title);
  111. { Check if we can open an X display }
  112. disp := XOpenDisplay(Nil);
  113. If disp = Nil Then
  114. Raise TPTCError.Create('Cannot open X display');
  115. { DefaultScreen should be fine }
  116. screen := DefaultScreen(disp);
  117. FreeAndNil(x11disp);
  118. {ifndef HAVE_DGA}
  119. If (m_flags And PTC_X11_NODGA) = 0 Then
  120. Begin
  121. Try
  122. x11disp := TX11DGADisplay.Create;
  123. x11disp.flags(m_flags Or PTC_X11_LEAVE_DISPLAY);
  124. x11disp.open(_title, _width, _height, _format, disp, screen);
  125. x11disp.flags(m_flags);
  126. Except
  127. FreeAndNil(x11disp);
  128. End;
  129. End;
  130. If x11disp = Nil Then
  131. Begin
  132. x11disp := TX11WindowDisplay.Create;
  133. x11disp.flags(m_flags);
  134. x11disp.open(_title, _width, _height, _format, disp, screen);
  135. End;
  136. End;
  137. Procedure TX11Console.open(Const _title : String; Const _mode : TPTCMode;
  138. _pages : Integer);
  139. Begin
  140. setTitle(_title);
  141. End;
  142. Procedure TX11Console.close;
  143. Begin
  144. FreeAndNil(x11disp);
  145. End;
  146. Procedure TX11Console.flush;
  147. Begin
  148. update;
  149. End;
  150. Procedure TX11Console.finish;
  151. Begin
  152. update;
  153. End;
  154. Procedure TX11Console.update;
  155. Begin
  156. x11disp.update;
  157. End;
  158. Procedure TX11Console.update(Const _area : TPTCArea);
  159. Begin
  160. x11disp.update(_area);
  161. End;
  162. Procedure TX11Console.internal_ReadKey(k : TPTCKey);
  163. Begin
  164. x11disp.internal_ReadKey(k);
  165. End;
  166. Function TX11Console.internal_PeekKey(k : TPTCKey) : Boolean;
  167. Begin
  168. Result := x11disp.internal_PeekKey(k);
  169. End;
  170. Procedure TX11Console.copy(Var surface : TPTCBaseSurface);
  171. Begin
  172. {todo!...}
  173. End;
  174. Procedure TX11Console.copy(Var surface : TPTCBaseSurface;
  175. Const source, destination : TPTCArea);
  176. Begin
  177. {todo!...}
  178. End;
  179. Function TX11Console.lock : Pointer;
  180. Begin
  181. lock := x11disp.lock;
  182. End;
  183. Procedure TX11Console.unlock;
  184. Begin
  185. x11disp.unlock;
  186. End;
  187. Procedure TX11Console.load(Const pixels : Pointer;
  188. _width, _height, _pitch : Integer;
  189. Const _format : TPTCFormat;
  190. Const _palette : TPTCPalette);
  191. Begin
  192. x11disp.load(pixels, _width, _height, _pitch, _format, _palette);
  193. End;
  194. Procedure TX11Console.load(Const pixels : Pointer;
  195. _width, _height, _pitch : Integer;
  196. Const _format : TPTCFormat;
  197. Const _palette : TPTCPalette;
  198. Const source, destination : TPTCArea);
  199. Begin
  200. x11disp.load(pixels, _width, _height, _pitch, _format, _palette, source, destination);
  201. End;
  202. Procedure TX11Console.save(pixels : Pointer;
  203. _width, _height, _pitch : Integer;
  204. Const _format : TPTCFormat;
  205. Const _palette : TPTCPalette);
  206. Begin
  207. {todo!...}
  208. End;
  209. Procedure TX11Console.save(pixels : Pointer;
  210. _width, _height, _pitch : Integer;
  211. Const _format : TPTCFormat;
  212. Const _palette : TPTCPalette;
  213. Const source, destination : TPTCArea);
  214. Begin
  215. {todo!...}
  216. End;
  217. Procedure TX11Console.clear;
  218. Var
  219. tmp : TPTCColor;
  220. Begin
  221. If format.direct Then
  222. tmp := TPTCColor.Create(0, 0, 0, 0)
  223. Else
  224. tmp := TPTCColor.Create(0);
  225. Try
  226. clear(tmp);
  227. Finally
  228. tmp.Free;
  229. End;
  230. End;
  231. Procedure TX11Console.clear(Const color : TPTCColor);
  232. Begin
  233. x11disp.clear(color);
  234. End;
  235. Procedure TX11Console.clear(Const color : TPTCColor;
  236. Const _area : TPTCArea);
  237. Begin
  238. x11disp.clear(color, _area);
  239. End;
  240. Procedure TX11Console.palette(Const _palette : TPTCPalette);
  241. Begin
  242. x11disp.palette(_palette);
  243. End;
  244. Function TX11Console.palette : TPTCPalette;
  245. Begin
  246. palette := x11disp.palette;
  247. End;
  248. Procedure TX11Console.clip(Const _area : TPTCArea);
  249. Begin
  250. x11disp.clip(_area);
  251. End;
  252. Function TX11Console.width : Integer;
  253. Begin
  254. width := x11disp.width;
  255. End;
  256. Function TX11Console.height : Integer;
  257. Begin
  258. height := x11disp.height;
  259. End;
  260. Function TX11Console.pitch : Integer;
  261. Begin
  262. pitch := x11disp.pitch;
  263. End;
  264. Function TX11Console.pages : Integer;
  265. Begin
  266. pages := 1;
  267. End;
  268. Function TX11Console.area : TPTCArea;
  269. Begin
  270. area := x11disp.area;
  271. End;
  272. Function TX11Console.clip : TPTCArea;
  273. Begin
  274. clip := x11disp.clip;
  275. End;
  276. Function TX11Console.format : TPTCFormat;
  277. Begin
  278. format := x11disp.format;
  279. End;
  280. Function TX11Console.name : String;
  281. Begin
  282. name := 'X11';
  283. End;
  284. Function TX11Console.title : String;
  285. Begin
  286. title := m_title;
  287. End;
  288. Function TX11Console.information : String;
  289. Var
  290. s : String;
  291. Begin
  292. If x11disp = Nil Then
  293. Exit('PTC X11');
  294. information := 'PTC X11, ';
  295. If x11disp Is TX11WindowDisplay Then
  296. Begin
  297. If TX11WindowDisplay(x11disp).m_primary <> Nil Then
  298. Begin
  299. {$IFDEF HAVE_X11_EXTENSIONS_XSHM}
  300. If TX11WindowDisplay(x11disp).m_primary Is TX11SHMImage Then
  301. information := information + 'windowed (MIT-Shm) mode'
  302. Else
  303. {$ENDIF HAVE_X11_EXTENSIONS_XSHM}
  304. information := information + 'windowed (XImage) mode';
  305. End
  306. Else
  307. information := information + 'windowed mode';
  308. End
  309. Else
  310. information := information + 'direct graphics access (DGA) mode';
  311. information := information + ', ';
  312. Str(x11disp.width, s);
  313. information := information + s + 'x';
  314. Str(x11disp.height, s);
  315. information := information + s + ', ';
  316. Str(x11disp.format.bits, s);
  317. information := information + s + ' bit';
  318. End;
  319. Procedure TX11Console.setTitle(_title : String);
  320. Begin
  321. m_title := _title;
  322. End;