x11displayi.inc 11 KB

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