123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- {$INCLUDE xunikey.inc}
- Constructor TX11Display.Create(ADisplay : PDisplay; AScreen : Integer; Const AFlags : TX11Flags);
- Begin
- FFlags := AFlags;
- FDisplay := ADisplay;
- FScreen := AScreen;
- FCopy := TPTCCopy.Create;
- FClear := TPTCClear.Create;
- FPalette := TPTCPalette.Create;
- FClip := TPTCArea.Create;
- FArea := TPTCArea.Create;
- FFormat := TPTCFormat.Create;
- FEventQueue := TEventQueue.Create;
- SetKeyMapping;
- End;
- Destructor TX11Display.Destroy;
- Begin
- { Just close the display, everything else is done by the subclasses }
- If (FDisplay <> Nil) And (Not (PTC_X11_LEAVE_DISPLAY In FFlags)) Then
- Begin
- XFlush(FDisplay);
- XCloseDisplay(FDisplay);
- FDisplay := Nil;
- End;
- FreeMemAndNil(FNormalKeys);
- FreeMemAndNil(FFunctionKeys);
- FCopy.Free;
- FClear.Free;
- FPalette.Free;
- FClip.Free;
- FArea.Free;
- FFormat.Free;
- FEventQueue.Free;
- Inherited Destroy;
- End;
- Procedure TX11Display.Load(Const APixels : Pointer; AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat; Const APalette : TPTCPalette);
- Var
- Area_ : TPTCArea;
- console_pixels : Pointer;
- Begin
- If Clip.Equals(Area) Then
- Begin
- Try
- console_pixels := Lock;
- Try
- FCopy.Request(AFormat, Format);
- FCopy.Palette(APalette, Palette);
- FCopy.Copy(APixels, 0, 0, AWidth, AHeight, APitch, console_pixels, 0, 0,
- Width, Height, Pitch);
- Finally
- Unlock;
- End;
- Except
- On error : TPTCError Do
- Raise TPTCError.Create('failed to load pixels to console', error);
- End;
- End
- Else
- Begin
- Area_ := TPTCArea.Create(0, 0, width, height);
- Try
- Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area_, Area);
- Finally
- Area_.Free;
- End;
- End;
- End;
- Procedure TX11Display.Load(Const APixels : Pointer; AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat; Const APalette : TPTCPalette;
- Const ASource, ADestination : TPTCArea);
- Var
- console_pixels : Pointer;
- clipped_source, clipped_destination : TPTCArea;
- tmp : TPTCArea;
- Begin
- clipped_source := Nil;
- clipped_destination := Nil;
- Try
- console_pixels := Lock;
- Try
- clipped_source := TPTCArea.Create;
- clipped_destination := TPTCArea.Create;
- tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
- Try
- TPTCClipper.Clip(ASource, tmp, clipped_source, ADestination, Clip, clipped_destination);
- Finally
- tmp.Free;
- End;
- FCopy.request(AFormat, Format);
- FCopy.palette(APalette, Palette);
- FCopy.copy(APixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, APitch,
- console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, Pitch);
- Finally
- Unlock;
- clipped_source.Free;
- clipped_destination.Free;
- End;
- Except
- On error : TPTCError Do
- Raise TPTCError.Create('failed to load pixels to console area', error);
- End;
- End;
- Procedure TX11Display.Save(APixels : Pointer; AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat; Const APalette : TPTCPalette);
- Begin
- End;
- Procedure TX11Display.Save(APixels : Pointer; AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat; Const APalette : TPTCPalette;
- Const ASource, ADestination : TPTCArea);
- Begin
- End;
- Procedure TX11Display.Clear(Const AColor : TPTCColor);
- Begin
- End;
- Procedure TX11Display.Clear(Const AColor : TPTCColor; Const AArea : TPTCArea);
- Begin
- End;
- Function TX11Display.Palette : TPTCPalette;
- Begin
- Result := FPalette;
- End;
- Procedure TX11Display.Clip(Const AArea : TPTCArea);
- Begin
- FClip.Assign(AArea);
- End;
- Function TX11Display.GetWidth : Integer;
- Begin
- Result := FWidth;
- End;
- Function TX11Display.GetHeight : Integer;
- Begin
- Result := FHeight;
- End;
- Function TX11Display.Clip : TPTCArea;
- Begin
- Result := FClip;
- End;
- Function TX11Display.GetArea : TPTCArea;
- Var
- tmp : TPTCArea;
- Begin
- tmp := TPTCArea.Create(0, 0, FWidth, FHeight);
- Try
- FArea.Assign(tmp);
- Finally
- tmp.Free;
- End;
- Result := FArea;
- End;
- Function TX11Display.GetFormat : TPTCFormat;
- Begin
- Result := FFormat;
- End;
- Procedure TX11Display.SetFlags(AFlags : TX11Flags);
- Begin
- FFlags := AFlags;
- End;
- Function TX11Display.GetX11Display : PDisplay;
- Begin
- Result := FDisplay;
- End;
- Function TX11Display.GetX11Screen : Integer;
- Begin
- Result := FScreen;
- End;
- Function TX11Display.GetX11Format(Const AFormat : TPTCFormat) : TPTCFormat;
- Var
- tmp_depth : Integer;
- numfound : Integer;
- i : Integer;
- pfv : PXPixmapFormatValues;
- Begin
- Result := Nil;
- { Check if our screen has the same format available. I hate how X }
- { keeps bits_per_pixel and depth different }
- tmp_depth := DisplayPlanes(FDisplay, FScreen);
- pfv := XListPixmapFormats(FDisplay, @numfound);
- Try
- For i := 0 To numfound - 1 Do
- Begin
- If pfv[i].depth = tmp_depth Then
- Begin
- tmp_depth := pfv[i].bits_per_pixel;
- Break;
- End;
- End;
- Finally
- XFree(pfv);
- End;
- If (tmp_depth = 8) And AFormat.Indexed Then
- Result := TPTCFormat.Create(8)
- Else
- If (tmp_depth = 8) And AFormat.Direct Then
- Result := TPTCFormat.Create(8, $E0, $1C, $03)
- Else
- Result := TPTCFormat.Create(tmp_depth,
- DefaultVisual(FDisplay, FScreen)^.red_mask,
- DefaultVisual(FDisplay, FScreen)^.green_mask,
- DefaultVisual(FDisplay, FScreen)^.blue_mask);
- End;
- Procedure TX11Display.SetKeyMapping;
- Var
- _I : Integer;
- Begin
- FreeMemAndNil(FFunctionKeys);
- FreeMemAndNil(FNormalKeys);
- FFunctionKeys := GetMem(256 * SizeOf(Integer));
- FNormalKeys := GetMem(256 * SizeOf(Integer));
- For _I := 0 To 255 Do
- Begin
- FFunctionKeys[_I] := Integer(PTCKEY_UNDEFINED);
- FNormalKeys[_I] := Integer(PTCKEY_UNDEFINED);
- End;
- { Assign function key indices from X definitions }
- FFunctionKeys[$FF And XK_BackSpace] := Integer(PTCKEY_BACKSPACE);
- FFunctionKeys[$FF And XK_Tab] := Integer(PTCKEY_TAB);
- FFunctionKeys[$FF And XK_Clear] := Integer(PTCKEY_CLEAR);
- FFunctionKeys[$FF And XK_Return] := Integer(PTCKEY_ENTER);
- FFunctionKeys[$FF And XK_Pause] := Integer(PTCKEY_PAUSE);
- FFunctionKeys[$FF And XK_Scroll_Lock] := Integer(PTCKEY_SCROLLLOCK);
- FFunctionKeys[$FF And XK_Escape] := Integer(PTCKEY_ESCAPE);
- FFunctionKeys[$FF And XK_Delete] := Integer(PTCKEY_DELETE);
- FFunctionKeys[$FF And XK_Kanji] := Integer(PTCKEY_KANJI);
- FFunctionKeys[$FF And XK_Home] := Integer(PTCKEY_HOME);
- FFunctionKeys[$FF And XK_Left] := Integer(PTCKEY_LEFT);
- FFunctionKeys[$FF And XK_Up] := Integer(PTCKEY_UP);
- FFunctionKeys[$FF And XK_Right] := Integer(PTCKEY_RIGHT);
- FFunctionKeys[$FF And XK_Down] := Integer(PTCKEY_DOWN);
- FFunctionKeys[$FF And XK_Page_Up] := Integer(PTCKEY_PAGEUP);
- FFunctionKeys[$FF And XK_Page_Down] := Integer(PTCKEY_PAGEDOWN);
- FFunctionKeys[$FF And XK_End] := Integer(PTCKEY_END);
- FFunctionKeys[$FF And XK_Print] := Integer(PTCKEY_PRINTSCREEN);
- FFunctionKeys[$FF And XK_Insert] := Integer(PTCKEY_INSERT);
- FFunctionKeys[$FF And XK_Num_Lock] := Integer(PTCKEY_NUMLOCK);
- FFunctionKeys[$FF And XK_KP_0] := Integer(PTCKEY_NUMPAD0);
- FFunctionKeys[$FF And XK_KP_1] := Integer(PTCKEY_NUMPAD1);
- FFunctionKeys[$FF And XK_KP_2] := Integer(PTCKEY_NUMPAD2);
- FFunctionKeys[$FF And XK_KP_3] := Integer(PTCKEY_NUMPAD3);
- FFunctionKeys[$FF And XK_KP_4] := Integer(PTCKEY_NUMPAD4);
- FFunctionKeys[$FF And XK_KP_5] := Integer(PTCKEY_NUMPAD5);
- FFunctionKeys[$FF And XK_KP_6] := Integer(PTCKEY_NUMPAD6);
- FFunctionKeys[$FF And XK_KP_7] := Integer(PTCKEY_NUMPAD7);
- FFunctionKeys[$FF And XK_KP_8] := Integer(PTCKEY_NUMPAD8);
- FFunctionKeys[$FF And XK_KP_9] := Integer(PTCKEY_NUMPAD9);
- FFunctionKeys[$FF And XK_F1] := Integer(PTCKEY_F1);
- FFunctionKeys[$FF And XK_F2] := Integer(PTCKEY_F2);
- FFunctionKeys[$FF And XK_F3] := Integer(PTCKEY_F3);
- FFunctionKeys[$FF And XK_F4] := Integer(PTCKEY_F4);
- FFunctionKeys[$FF And XK_F5] := Integer(PTCKEY_F5);
- FFunctionKeys[$FF And XK_F6] := Integer(PTCKEY_F6);
- FFunctionKeys[$FF And XK_F7] := Integer(PTCKEY_F7);
- FFunctionKeys[$FF And XK_F8] := Integer(PTCKEY_F8);
- FFunctionKeys[$FF And XK_F9] := Integer(PTCKEY_F9);
- FFunctionKeys[$FF And XK_F10] := Integer(PTCKEY_F10);
- FFunctionKeys[$FF And XK_F11] := Integer(PTCKEY_F11);
- FFunctionKeys[$FF And XK_F12] := Integer(PTCKEY_F12);
- FFunctionKeys[$FF And XK_Shift_L] := Integer(PTCKEY_SHIFT);
- FFunctionKeys[$FF And XK_Shift_R] := Integer(PTCKEY_SHIFT);
- FFunctionKeys[$FF And XK_Control_L] := Integer(PTCKEY_CONTROL);
- FFunctionKeys[$FF And XK_Control_R] := Integer(PTCKEY_CONTROL);
- FFunctionKeys[$FF And XK_Caps_Lock] := Integer(PTCKEY_CAPSLOCK);
- FFunctionKeys[$FF And XK_Meta_L] := Integer(PTCKEY_META);
- FFunctionKeys[$FF And XK_Meta_R] := Integer(PTCKEY_META);
- FFunctionKeys[$FF And XK_Alt_L] := Integer(PTCKEY_ALT);
- FFunctionKeys[$FF And XK_Alt_R] := Integer(PTCKEY_ALT);
- { Assign normal key indices }
- FNormalKeys[$FF And XK_space] := Integer(PTCKEY_SPACE);
- FNormalKeys[$FF And XK_comma] := Integer(PTCKEY_COMMA);
- FNormalKeys[$FF And XK_minus] := Integer(PTCKEY_SUBTRACT);
- FNormalKeys[$FF And XK_period] := Integer(PTCKEY_PERIOD);
- FNormalKeys[$FF And XK_slash] := Integer(PTCKEY_SLASH);
- FNormalKeys[$FF And XK_0] := Integer(PTCKEY_ZERO);
- FNormalKeys[$FF And XK_1] := Integer(PTCKEY_ONE);
- FNormalKeys[$FF And XK_2] := Integer(PTCKEY_TWO);
- FNormalKeys[$FF And XK_3] := Integer(PTCKEY_THREE);
- FNormalKeys[$FF And XK_4] := Integer(PTCKEY_FOUR);
- FNormalKeys[$FF And XK_5] := Integer(PTCKEY_FIVE);
- FNormalKeys[$FF And XK_6] := Integer(PTCKEY_SIX);
- FNormalKeys[$FF And XK_7] := Integer(PTCKEY_SEVEN);
- FNormalKeys[$FF And XK_8] := Integer(PTCKEY_EIGHT);
- FNormalKeys[$FF And XK_9] := Integer(PTCKEY_NINE);
- FNormalKeys[$FF And XK_semicolon] := Integer(PTCKEY_SEMICOLON);
- FNormalKeys[$FF And XK_equal] := Integer(PTCKEY_EQUALS);
- FNormalKeys[$FF And XK_bracketleft] := Integer(PTCKEY_OPENBRACKET);
- FNormalKeys[$FF And XK_backslash] := Integer(PTCKEY_BACKSLASH);
- FNormalKeys[$FF And XK_bracketright] := Integer(PTCKEY_CLOSEBRACKET);
- FNormalKeys[$FF And XK_a] := Integer(PTCKEY_A);
- FNormalKeys[$FF And XK_b] := Integer(PTCKEY_B);
- FNormalKeys[$FF And XK_c] := Integer(PTCKEY_C);
- FNormalKeys[$FF And XK_d] := Integer(PTCKEY_D);
- FNormalKeys[$FF And XK_e] := Integer(PTCKEY_E);
- FNormalKeys[$FF And XK_f] := Integer(PTCKEY_F);
- FNormalKeys[$FF And XK_g] := Integer(PTCKEY_G);
- FNormalKeys[$FF And XK_h] := Integer(PTCKEY_H);
- FNormalKeys[$FF And XK_i] := Integer(PTCKEY_I);
- FNormalKeys[$FF And XK_j] := Integer(PTCKEY_J);
- FNormalKeys[$FF And XK_k] := Integer(PTCKEY_K);
- FNormalKeys[$FF And XK_l] := Integer(PTCKEY_L);
- FNormalKeys[$FF And XK_m] := Integer(PTCKEY_M);
- FNormalKeys[$FF And XK_n] := Integer(PTCKEY_N);
- FNormalKeys[$FF And XK_o] := Integer(PTCKEY_O);
- FNormalKeys[$FF And XK_p] := Integer(PTCKEY_P);
- FNormalKeys[$FF And XK_q] := Integer(PTCKEY_Q);
- FNormalKeys[$FF And XK_r] := Integer(PTCKEY_R);
- FNormalKeys[$FF And XK_s] := Integer(PTCKEY_S);
- FNormalKeys[$FF And XK_t] := Integer(PTCKEY_T);
- FNormalKeys[$FF And XK_u] := Integer(PTCKEY_U);
- FNormalKeys[$FF And XK_v] := Integer(PTCKEY_V);
- FNormalKeys[$FF And XK_w] := Integer(PTCKEY_W);
- FNormalKeys[$FF And XK_x] := Integer(PTCKEY_X);
- FNormalKeys[$FF And XK_y] := Integer(PTCKEY_Y);
- FNormalKeys[$FF And XK_z] := Integer(PTCKEY_Z);
- End;
|