display.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. {$INCLUDE xunikey.inc}
  2. Constructor TX11Display.Create;
  3. Begin
  4. m_disp := Nil;
  5. m_colours := Nil;
  6. m_cmap := 0;
  7. m_flags := 0;
  8. m_width := 0;
  9. m_height := 0;
  10. m_functionkeys := Nil;
  11. m_normalkeys := Nil;
  12. m_copy := Nil;
  13. m_clear := Nil;
  14. m_palette := Nil;
  15. m_clip := Nil;
  16. m_area := Nil;
  17. m_format := Nil;
  18. m_copy := TPTCCopy.Create;
  19. m_clear := TPTCClear.Create;
  20. m_palette := TPTCPalette.Create;
  21. m_clip := TPTCArea.Create;
  22. m_area := TPTCArea.Create;
  23. m_format := TPTCFormat.Create;
  24. setKeyMapping;
  25. End;
  26. Destructor TX11Display.Destroy;
  27. Begin
  28. // Writeln('lll1');
  29. { Just close the display, everything else is done by the subclasses }
  30. If (m_disp <> Nil) And ((m_flags And PTC_X11_LEAVE_DISPLAY) = 0) Then
  31. Begin
  32. // Writeln('lalalalala1');
  33. XFlush(m_disp);
  34. // Writeln('lalalalala2');
  35. XCloseDisplay(m_disp);
  36. // Writeln('lalalalala3');
  37. m_disp := Nil;
  38. // Writeln('lalalalala4');
  39. End;
  40. // Writeln('lll2');
  41. FreeMemAndNil(m_normalkeys);
  42. FreeMemAndNil(m_functionkeys);
  43. // Writeln('lll3');
  44. m_copy.Free;
  45. m_clear.Free;
  46. m_palette.Free;
  47. m_clip.Free;
  48. m_area.Free;
  49. m_format.Free;
  50. Inherited Destroy;
  51. End;
  52. Procedure TX11Display.load(Const pixels : Pointer; _width, _height, _pitch : Integer;
  53. Const _format : TPTCFormat; Const _palette : TPTCPalette);
  54. Var
  55. Area_ : TPTCArea;
  56. console_pixels : Pointer;
  57. Begin
  58. If clip.Equals(area) Then
  59. Begin
  60. console_pixels := lock;
  61. Try
  62. Try
  63. m_copy.request(_format, format);
  64. m_copy.palette(_palette, palette);
  65. m_copy.copy(pixels, 0, 0, _width, _height, _pitch, console_pixels, 0, 0,
  66. width, height, pitch);
  67. Except
  68. On error : TPTCError Do
  69. Begin
  70. Raise TPTCError.Create('failed to load pixels to console', error);
  71. End;
  72. End;
  73. Finally
  74. unlock;
  75. End;
  76. End
  77. Else
  78. Begin
  79. Area_ := TPTCArea.Create(0, 0, width, height);
  80. Try
  81. load(pixels, _width, _height, _pitch, _format, _palette, Area_, area);
  82. Finally
  83. Area_.Free;
  84. End;
  85. End;
  86. End;
  87. Procedure TX11Display.load(Const pixels : Pointer; _width, _height, _pitch : Integer;
  88. Const _format : TPTCFormat; Const _palette : TPTCPalette;
  89. Const source, destination : TPTCArea);
  90. Var
  91. console_pixels : Pointer;
  92. clipped_source, clipped_destination : TPTCArea;
  93. tmp : TPTCArea;
  94. Begin
  95. clipped_destination := Nil;
  96. clipped_source := TPTCArea.Create;
  97. Try
  98. clipped_destination := TPTCArea.Create;
  99. console_pixels := lock;
  100. Try
  101. Try
  102. tmp := TPTCArea.Create(0, 0, _width, _height);
  103. Try
  104. TPTCClipper.clip(source, tmp, clipped_source, destination, clip, clipped_destination);
  105. Finally
  106. tmp.Free;
  107. End;
  108. m_copy.request(_format, format);
  109. m_copy.palette(_palette, palette);
  110. m_copy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
  111. console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
  112. Except
  113. On error:TPTCError Do
  114. Begin
  115. Raise TPTCError.Create('failed to load pixels to console area', error);
  116. End;
  117. End;
  118. Finally
  119. unlock;
  120. End;
  121. Finally
  122. clipped_source.Free;
  123. clipped_destination.Free;
  124. End;
  125. End;
  126. Procedure TX11Display.save(pixels : Pointer; _width, _height, _pitch : Integer;
  127. Const _format : TPTCFormat; Const _palette : TPTCPalette);
  128. Begin
  129. End;
  130. Procedure TX11Display.save(pixels : Pointer; _width, _height, _pitch : Integer;
  131. Const _format : TPTCFormat; Const _palette : TPTCPalette;
  132. Const source, destination : TPTCArea);
  133. Begin
  134. End;
  135. Procedure TX11Display.clear(Const color : TPTCColor);
  136. Begin
  137. End;
  138. Procedure TX11Display.clear(Const color : TPTCColor; Const _area : TPTCArea);
  139. Begin
  140. End;
  141. Function TX11Display.palette : TPTCPalette;
  142. Begin
  143. {...}
  144. palette := m_palette;
  145. End;
  146. Procedure TX11Display.clip(Const _area : TPTCArea);
  147. Begin
  148. m_clip.ASSign(_area);
  149. End;
  150. Function TX11Display.width : Integer;
  151. Begin
  152. width := m_width;
  153. End;
  154. Function TX11Display.height : Integer;
  155. Begin
  156. height := m_height;
  157. End;
  158. Function TX11Display.clip : TPTCArea;
  159. Begin
  160. clip := m_clip;
  161. End;
  162. Function TX11Display.area : TPTCArea;
  163. Var
  164. tmp : TPTCArea;
  165. Begin
  166. tmp := TPTCArea.Create(0, 0, m_width, m_height);
  167. Try
  168. m_area.ASSign(tmp);
  169. Finally
  170. tmp.Free;
  171. End;
  172. area := m_area;
  173. End;
  174. Function TX11Display.format : TPTCFormat;
  175. Begin
  176. format := m_format;
  177. End;
  178. Procedure TX11Display.flags(_flags : LongInt);
  179. Begin
  180. m_flags := _flags;
  181. End;
  182. Function TX11Display.getX11Display : PDisplay;
  183. Begin
  184. getX11Display := m_disp;
  185. End;
  186. Function TX11Display.getX11Screen : Integer;
  187. Begin
  188. getX11Screen := m_screen;
  189. End;
  190. Function TX11Display.getFormat(Const _format : TPTCFormat) : TPTCFormat;
  191. Var
  192. tmp_depth : Integer;
  193. numfound : Integer;
  194. i : Integer;
  195. pfv : PXPixmapFormatValues;
  196. Begin
  197. getFormat := Nil;
  198. { Check if our screen has the same format available. I hate how X }
  199. { keeps bits_per_pixel and depth different }
  200. tmp_depth := (PXPrivDisplay(m_disp))^.screens[m_screen].root_depth;
  201. pfv := XListPixmapFormats(m_disp, @numfound);
  202. Try
  203. For i := 0 To numfound - 1 Do
  204. Begin
  205. If pfv[i].depth = tmp_depth Then
  206. Begin
  207. tmp_depth := pfv[i].bits_per_pixel;
  208. End;
  209. End;
  210. Finally
  211. XFree(pfv);
  212. End;
  213. If (tmp_depth = 8) And _format.indexed Then
  214. getFormat := TPTCFormat.Create(8)
  215. Else
  216. If (tmp_depth = 8) And _format.direct Then
  217. getFormat := TPTCFormat.Create(8, $E0, $1C, $03)
  218. Else
  219. getFormat := TPTCFormat.Create(tmp_depth,
  220. (PXPrivDisplay(m_disp))^.screens[m_screen].root_visual^.red_mask,
  221. (PXPrivDisplay(m_disp))^.screens[m_screen].root_visual^.green_mask,
  222. (PXPrivDisplay(m_disp))^.screens[m_screen].root_visual^.blue_mask);
  223. End;
  224. Procedure TX11Display.setKeyMapping;
  225. Var
  226. _I : Integer;
  227. Begin
  228. FreeMemAndNil(m_functionkeys);
  229. FreeMemAndNil(m_normalkeys);
  230. m_functionkeys := GetMem(256 * SizeOf(Integer));
  231. m_normalkeys := GetMem(256 * SizeOf(Integer));
  232. For _I := 0 To 255 Do
  233. Begin
  234. m_functionkeys[_I] := Integer(PTCKEY_UNDEFINED);
  235. m_normalkeys[_I] := Integer(PTCKEY_UNDEFINED);
  236. End;
  237. { Assign function key indices from X definitions }
  238. m_functionkeys[$FF And XK_BackSpace] := Integer(PTCKEY_BACKSPACE);
  239. m_functionkeys[$FF And XK_Tab] := Integer(PTCKEY_TAB);
  240. m_functionkeys[$FF And XK_Clear] := Integer(PTCKEY_CLEAR);
  241. m_functionkeys[$FF And XK_Return] := Integer(PTCKEY_ENTER);
  242. m_functionkeys[$FF And XK_Pause] := Integer(PTCKEY_PAUSE);
  243. m_functionkeys[$FF And XK_Scroll_Lock] := Integer(PTCKEY_SCROLLLOCK);
  244. m_functionkeys[$FF And XK_Escape] := Integer(PTCKEY_ESCAPE);
  245. m_functionkeys[$FF And XK_Delete] := Integer(PTCKEY_DELETE);
  246. m_functionkeys[$FF And XK_Kanji] := Integer(PTCKEY_KANJI);
  247. m_functionkeys[$FF And XK_Home] := Integer(PTCKEY_HOME);
  248. m_functionkeys[$FF And XK_Left] := Integer(PTCKEY_LEFT);
  249. m_functionkeys[$FF And XK_Up] := Integer(PTCKEY_UP);
  250. m_functionkeys[$FF And XK_Right] := Integer(PTCKEY_RIGHT);
  251. m_functionkeys[$FF And XK_Down] := Integer(PTCKEY_DOWN);
  252. m_functionkeys[$FF And XK_Page_Up] := Integer(PTCKEY_PAGEUP);
  253. m_functionkeys[$FF And XK_Page_Down] := Integer(PTCKEY_PAGEDOWN);
  254. m_functionkeys[$FF And XK_End] := Integer(PTCKEY_END);
  255. m_functionkeys[$FF And XK_Print] := Integer(PTCKEY_PRINTSCREEN);
  256. m_functionkeys[$FF And XK_Insert] := Integer(PTCKEY_INSERT);
  257. m_functionkeys[$FF And XK_Num_Lock] := Integer(PTCKEY_NUMLOCK);
  258. m_functionkeys[$FF And XK_KP_0] := Integer(PTCKEY_NUMPAD0);
  259. m_functionkeys[$FF And XK_KP_1] := Integer(PTCKEY_NUMPAD1);
  260. m_functionkeys[$FF And XK_KP_2] := Integer(PTCKEY_NUMPAD2);
  261. m_functionkeys[$FF And XK_KP_3] := Integer(PTCKEY_NUMPAD3);
  262. m_functionkeys[$FF And XK_KP_4] := Integer(PTCKEY_NUMPAD4);
  263. m_functionkeys[$FF And XK_KP_5] := Integer(PTCKEY_NUMPAD5);
  264. m_functionkeys[$FF And XK_KP_6] := Integer(PTCKEY_NUMPAD6);
  265. m_functionkeys[$FF And XK_KP_7] := Integer(PTCKEY_NUMPAD7);
  266. m_functionkeys[$FF And XK_KP_8] := Integer(PTCKEY_NUMPAD8);
  267. m_functionkeys[$FF And XK_KP_9] := Integer(PTCKEY_NUMPAD9);
  268. m_functionkeys[$FF And XK_F1] := Integer(PTCKEY_F1);
  269. m_functionkeys[$FF And XK_F2] := Integer(PTCKEY_F2);
  270. m_functionkeys[$FF And XK_F3] := Integer(PTCKEY_F3);
  271. m_functionkeys[$FF And XK_F4] := Integer(PTCKEY_F4);
  272. m_functionkeys[$FF And XK_F5] := Integer(PTCKEY_F5);
  273. m_functionkeys[$FF And XK_F6] := Integer(PTCKEY_F6);
  274. m_functionkeys[$FF And XK_F7] := Integer(PTCKEY_F7);
  275. m_functionkeys[$FF And XK_F8] := Integer(PTCKEY_F8);
  276. m_functionkeys[$FF And XK_F9] := Integer(PTCKEY_F9);
  277. m_functionkeys[$FF And XK_F10] := Integer(PTCKEY_F10);
  278. m_functionkeys[$FF And XK_F11] := Integer(PTCKEY_F11);
  279. m_functionkeys[$FF And XK_F12] := Integer(PTCKEY_F12);
  280. m_functionkeys[$FF And XK_Shift_L] := Integer(PTCKEY_SHIFT);
  281. m_functionkeys[$FF And XK_Shift_R] := Integer(PTCKEY_SHIFT);
  282. m_functionkeys[$FF And XK_Control_L] := Integer(PTCKEY_CONTROL);
  283. m_functionkeys[$FF And XK_Control_R] := Integer(PTCKEY_CONTROL);
  284. m_functionkeys[$FF And XK_Caps_Lock] := Integer(PTCKEY_CAPSLOCK);
  285. m_functionkeys[$FF And XK_Meta_L] := Integer(PTCKEY_META);
  286. m_functionkeys[$FF And XK_Meta_R] := Integer(PTCKEY_META);
  287. m_functionkeys[$FF And XK_Alt_L] := Integer(PTCKEY_ALT);
  288. m_functionkeys[$FF And XK_Alt_R] := Integer(PTCKEY_ALT);
  289. { Assign normal key indices }
  290. m_normalkeys[$FF And XK_space] := Integer(PTCKEY_SPACE);
  291. m_normalkeys[$FF And XK_comma] := Integer(PTCKEY_COMMA);
  292. m_normalkeys[$FF And XK_minus] := Integer(PTCKEY_SUBTRACT);
  293. m_normalkeys[$FF And XK_period] := Integer(PTCKEY_PERIOD);
  294. m_normalkeys[$FF And XK_slash] := Integer(PTCKEY_SLASH);
  295. m_normalkeys[$FF And XK_0] := Integer(PTCKEY_ZERO);
  296. m_normalkeys[$FF And XK_1] := Integer(PTCKEY_ONE);
  297. m_normalkeys[$FF And XK_2] := Integer(PTCKEY_TWO);
  298. m_normalkeys[$FF And XK_3] := Integer(PTCKEY_THREE);
  299. m_normalkeys[$FF And XK_4] := Integer(PTCKEY_FOUR);
  300. m_normalkeys[$FF And XK_5] := Integer(PTCKEY_FIVE);
  301. m_normalkeys[$FF And XK_6] := Integer(PTCKEY_SIX);
  302. m_normalkeys[$FF And XK_7] := Integer(PTCKEY_SEVEN);
  303. m_normalkeys[$FF And XK_8] := Integer(PTCKEY_EIGHT);
  304. m_normalkeys[$FF And XK_9] := Integer(PTCKEY_NINE);
  305. m_normalkeys[$FF And XK_semicolon] := Integer(PTCKEY_SEMICOLON);
  306. m_normalkeys[$FF And XK_equal] := Integer(PTCKEY_EQUALS);
  307. m_normalkeys[$FF And XK_bracketleft] := Integer(PTCKEY_OPENBRACKET);
  308. m_normalkeys[$FF And XK_backslash] := Integer(PTCKEY_BACKSLASH);
  309. m_normalkeys[$FF And XK_bracketright] := Integer(PTCKEY_CLOSEBRACKET);
  310. m_normalkeys[$FF And XK_a] := Integer(PTCKEY_A);
  311. m_normalkeys[$FF And XK_b] := Integer(PTCKEY_B);
  312. m_normalkeys[$FF And XK_c] := Integer(PTCKEY_C);
  313. m_normalkeys[$FF And XK_d] := Integer(PTCKEY_D);
  314. m_normalkeys[$FF And XK_e] := Integer(PTCKEY_E);
  315. m_normalkeys[$FF And XK_f] := Integer(PTCKEY_F);
  316. m_normalkeys[$FF And XK_g] := Integer(PTCKEY_G);
  317. m_normalkeys[$FF And XK_h] := Integer(PTCKEY_H);
  318. m_normalkeys[$FF And XK_i] := Integer(PTCKEY_I);
  319. m_normalkeys[$FF And XK_j] := Integer(PTCKEY_J);
  320. m_normalkeys[$FF And XK_k] := Integer(PTCKEY_K);
  321. m_normalkeys[$FF And XK_l] := Integer(PTCKEY_L);
  322. m_normalkeys[$FF And XK_m] := Integer(PTCKEY_M);
  323. m_normalkeys[$FF And XK_n] := Integer(PTCKEY_N);
  324. m_normalkeys[$FF And XK_o] := Integer(PTCKEY_O);
  325. m_normalkeys[$FF And XK_p] := Integer(PTCKEY_P);
  326. m_normalkeys[$FF And XK_q] := Integer(PTCKEY_Q);
  327. m_normalkeys[$FF And XK_r] := Integer(PTCKEY_R);
  328. m_normalkeys[$FF And XK_s] := Integer(PTCKEY_S);
  329. m_normalkeys[$FF And XK_t] := Integer(PTCKEY_T);
  330. m_normalkeys[$FF And XK_u] := Integer(PTCKEY_U);
  331. m_normalkeys[$FF And XK_v] := Integer(PTCKEY_V);
  332. m_normalkeys[$FF And XK_w] := Integer(PTCKEY_W);
  333. m_normalkeys[$FF And XK_x] := Integer(PTCKEY_X);
  334. m_normalkeys[$FF And XK_y] := Integer(PTCKEY_Y);
  335. m_normalkeys[$FF And XK_z] := Integer(PTCKEY_Z);
  336. End;