123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- Constructor TX11Console.Create;
- Var
- s : AnsiString;
- Begin
- Inherited Create;
- { default flags }
- FFlags := [PTC_X11_TRY_XSHM, PTC_X11_TRY_XF86VIDMODE];
- FTitle := '';
- Configure('/usr/share/ptcpas/ptcpas.conf');
- s := fpgetenv('HOME');
- If s = '' Then
- s := '/';
- If s[Length(s)] <> '/' Then
- s := s + '/';
- s := s + '.ptcpas.conf';
- Configure(s);
- End;
- Destructor TX11Console.Destroy;
- Var
- I : Integer;
- Begin
- Close;
- FreeAndNil(FX11Display);
- For I := Low(FModes) To High(FModes) Do
- FreeAndNil(FModes[I]);
- Inherited Destroy;
- End;
- Procedure TX11Console.Configure(Const AFileName : String);
- Var
- F : Text;
- S : String;
- Begin
- AssignFile(F, AFileName);
- {$I-}
- Reset(F);
- {$I+}
- If IOResult <> 0 Then
- Exit;
- While Not EoF(F) Do
- Begin
- {$I-}
- Readln(F, S);
- {$I+}
- If IOResult <> 0 Then
- Break;
- Option(S);
- End;
- CloseFile(F);
- End;
- Function TX11Console.Option(Const AOption : String) : Boolean;
- Begin
- Result := True;
- If AOption = 'default output' Then
- Begin
- { default is windowed for now }
- FFlags := FFlags - [PTC_X11_FULLSCREEN];
- Exit;
- End;
- If AOption = 'windowed output' Then
- Begin
- FFlags := FFlags - [PTC_X11_FULLSCREEN];
- Exit;
- End;
- If AOption = 'fullscreen output' Then
- Begin
- FFlags := FFlags + [PTC_X11_FULLSCREEN];
- Exit;
- End;
- If AOption = 'leave window open' Then
- Begin
- FFlags := FFlags + [PTC_X11_LEAVE_WINDOW];
- Exit;
- End;
- If AOption = 'leave display open' Then
- Begin
- FFlags := FFlags + [PTC_X11_LEAVE_DISPLAY];
- Exit;
- End;
- If AOption = 'dga' Then
- Begin
- FFlags := FFlags + [PTC_X11_TRY_DGA];
- Exit;
- End;
- If AOption = 'dga off' Then
- Begin
- FFlags := FFlags - [PTC_X11_TRY_DGA];
- Exit;
- End;
- If AOption = 'xf86vidmode' Then
- Begin
- FFlags := FFlags + [PTC_X11_TRY_XF86VIDMODE];
- Exit;
- End;
- If AOption = 'xf86vidmode off' Then
- Begin
- FFlags := FFlags - [PTC_X11_TRY_XF86VIDMODE];
- Exit;
- End;
- If AOption = 'xrandr' Then
- Begin
- FFlags := FFlags + [PTC_X11_TRY_XRANDR];
- Exit;
- End;
- If AOption = 'xrandr off' Then
- Begin
- FFlags := FFlags - [PTC_X11_TRY_XRANDR];
- Exit;
- End;
- If AOption = 'xshm' Then
- Begin
- FFlags := FFlags + [PTC_X11_TRY_XSHM];
- Exit;
- End;
- If AOption = 'xshm off' Then
- Begin
- FFlags := FFlags - [PTC_X11_TRY_XSHM];
- Exit;
- End;
- If AOption = 'default cursor' Then
- Begin
- FFlags := FFlags - [PTC_X11_FULLSCREEN_CURSOR_VISIBLE, PTC_X11_WINDOWED_CURSOR_INVISIBLE];
- UpdateCursor;
- Exit;
- End;
- If AOption = 'show cursor' Then
- Begin
- FFlags := (FFlags - [PTC_X11_WINDOWED_CURSOR_INVISIBLE]) + [PTC_X11_FULLSCREEN_CURSOR_VISIBLE];
- UpdateCursor;
- Exit;
- End;
- If AOption = 'hide cursor' Then
- Begin
- FFlags := (FFlags - [PTC_X11_FULLSCREEN_CURSOR_VISIBLE]) + [PTC_X11_WINDOWED_CURSOR_INVISIBLE];
- UpdateCursor;
- Exit;
- End;
- If AOption = 'enable logging' Then
- Begin
- LOG_enabled := True;
- Result := True;
- Exit;
- End;
- If AOption = 'disable logging' Then
- Begin
- LOG_enabled := False;
- Result := True;
- Exit;
- End;
- If Assigned(FX11Display) Then
- Result := FX11Display.FCopy.Option(AOption)
- Else
- Result := False;
- End;
- Function TX11Console.Modes : PPTCMode;
- Var
- I : Integer;
- Begin
- For I := Low(FModes) To High(FModes) Do
- FreeAndNil(FModes[I]);
- If FX11Display = Nil Then
- FX11Display := CreateDisplay;
- FX11Display.GetModes(FModes);
- Result := @FModes[0];
- End;
- {TODO: Find current pixel depth}
- Procedure TX11Console.Open(Const ATitle : String; APages : Integer = 0);
- Var
- tmp : TPTCFormat;
- Begin
- tmp := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
- Try
- Open(ATitle, tmp, APages);
- Finally
- tmp.Free;
- End;
- End;
- Procedure TX11Console.Open(Const ATitle : String; Const AFormat : TPTCFormat;
- APages : Integer = 0);
- Begin
- Open(ATitle, 640, 480, AFormat, APages);
- End;
- Procedure TX11Console.Open(Const ATitle : String; Const AMode : TPTCMode;
- APages : Integer = 0);
- Begin
- Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
- End;
- Function TX11Console.CreateDisplay : TX11Display;
- Var
- display : PDisplay;
- screen : Integer;
- Begin
- { Check if we can open an X display }
- display := XOpenDisplay(Nil);
- If display = Nil Then
- Raise TPTCError.Create('Cannot open X display');
- { DefaultScreen should be fine }
- screen := DefaultScreen(display);
- {$IFDEF ENABLE_X11_EXTENSION_XF86DGA2}
- If PTC_X11_TRY_DGA In FFlags Then
- Begin
- Try
- Result := TX11DGA2Display.Create(display, screen, FFlags + [PTC_X11_LEAVE_DISPLAY]);
- Result.SetFlags(FFlags);
- Exit;
- Except
- LOG('DGA 2.0 failed');
- End;
- End;
- {$ENDIF ENABLE_X11_EXTENSION_XF86DGA2}
- {$IFDEF ENABLE_X11_EXTENSION_XF86DGA1}
- If PTC_X11_TRY_DGA In FFlags Then
- Begin
- Try
- Result := TX11DGA1Display.Create(display, screen, FFlags + [PTC_X11_LEAVE_DISPLAY]);
- Result.SetFlags(FFlags);
- Except
- LOG('DGA 1.0 failed');
- End;
- End;
- {$ENDIF ENABLE_X11_EXTENSION_XF86DGA1}
- Result := TX11WindowDisplay.Create(display, screen, FFlags);
- End;
- Procedure TX11Console.Open(Const ATitle : String; AWidth, AHeight : Integer;
- Const AFormat : TPTCFormat; APages : Integer = 0);
- Begin
- Close;
- FTitle := ATitle;
- If FX11Display = Nil Then
- FX11Display := CreateDisplay;
- FX11Display.Open(ATitle, AWidth, AHeight, AFormat);
- UpdateCursor;
- End;
- Procedure TX11Console.Close;
- Begin
- FreeAndNil(FX11Display);
- End;
- Procedure TX11Console.Flush;
- Begin
- Update;
- End;
- Procedure TX11Console.Finish;
- Begin
- Update;
- End;
- Procedure TX11Console.Update;
- Begin
- FX11Display.Update;
- End;
- Procedure TX11Console.Update(Const AArea : TPTCArea);
- Begin
- FX11Display.Update(AArea);
- End;
- Function TX11Console.NextEvent(Var AEvent : TPTCEvent; AWait : Boolean; Const AEventMask : TPTCEventMask) : Boolean;
- Begin
- Result := FX11Display.NextEvent(AEvent, AWait, AEventMask);
- End;
- Function TX11Console.PeekEvent(AWait : Boolean; Const AEventMask : TPTCEventMask) : TPTCEvent;
- Begin
- Result := FX11Display.PeekEvent(AWait, AEventMask);
- End;
- Procedure TX11Console.Copy(Var ASurface : TPTCBaseSurface);
- Begin
- {todo!...}
- End;
- Procedure TX11Console.Copy(Var ASurface : TPTCBaseSurface;
- Const ASource, ADestination : TPTCArea);
- Begin
- {todo!...}
- End;
- Function TX11Console.Lock : Pointer;
- Begin
- Result := FX11Display.Lock;
- End;
- Procedure TX11Console.Unlock;
- Begin
- FX11Display.Unlock;
- End;
- Procedure TX11Console.Load(Const APixels : Pointer;
- AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat;
- Const APalette : TPTCPalette);
- Begin
- FX11Display.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette);
- End;
- Procedure TX11Console.Load(Const APixels : Pointer;
- AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat;
- Const APalette : TPTCPalette;
- Const ASource, ADestination : TPTCArea);
- Begin
- FX11Display.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination);
- End;
- Procedure TX11Console.Save(APixels : Pointer;
- AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat;
- Const APalette : TPTCPalette);
- Begin
- {todo!...}
- End;
- Procedure TX11Console.Save(APixels : Pointer;
- AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat;
- Const APalette : TPTCPalette;
- Const ASource, ADestination : TPTCArea);
- Begin
- {todo!...}
- End;
- Procedure TX11Console.Clear;
- Var
- tmp : TPTCColor;
- Begin
- If Format.Direct Then
- tmp := TPTCColor.Create(0, 0, 0, 0)
- Else
- tmp := TPTCColor.Create(0);
- Try
- Clear(tmp);
- Finally
- tmp.Free;
- End;
- End;
- Procedure TX11Console.Clear(Const AColor : TPTCColor);
- Begin
- FX11Display.Clear(AColor);
- End;
- Procedure TX11Console.Clear(Const AColor : TPTCColor;
- Const AArea : TPTCArea);
- Begin
- FX11Display.Clear(AColor, AArea);
- End;
- Procedure TX11Console.Palette(Const APalette : TPTCPalette);
- Begin
- FX11Display.Palette(APalette);
- End;
- Function TX11Console.Palette : TPTCPalette;
- Begin
- Result := FX11Display.Palette;
- End;
- Procedure TX11Console.Clip(Const AArea : TPTCArea);
- Begin
- FX11Display.Clip(AArea);
- End;
- Function TX11Console.GetWidth : Integer;
- Begin
- Result := FX11Display.Width;
- End;
- Function TX11Console.GetHeight : Integer;
- Begin
- Result := FX11Display.Height;
- End;
- Function TX11Console.GetPitch : Integer;
- Begin
- Result := FX11Display.Pitch;
- End;
- Function TX11Console.GetPages : Integer;
- Begin
- Result := 2;
- End;
- Function TX11Console.GetArea : TPTCArea;
- Begin
- Result := FX11Display.Area;
- End;
- Function TX11Console.Clip : TPTCArea;
- Begin
- Result := FX11Display.Clip;
- End;
- Function TX11Console.GetFormat : TPTCFormat;
- Begin
- Result := FX11Display.Format;
- End;
- Function TX11Console.GetName : String;
- Begin
- Result := 'X11';
- End;
- Function TX11Console.GetTitle : String;
- Begin
- Result := FTitle;
- End;
- Function TX11Console.GetInformation : String;
- Begin
- If FX11Display = Nil Then
- Exit('PTC X11');
- Result := 'PTC X11, ';
- If FX11Display.IsFullScreen Then
- Result := Result + 'fullscreen '
- Else
- Result := Result + 'windowed ';
- { TODO: use virtual methods, instead of "is" }
- If FX11Display Is TX11WindowDisplay Then
- Begin
- If TX11WindowDisplay(FX11Display).FPrimary <> Nil Then
- Result := Result + '(' + TX11WindowDisplay(FX11Display).FPrimary.Name + ') '
- Else
- Result := Result + '';
- End
- Else
- Begin
- {$IFDEF ENABLE_X11_EXTENSION_XF86DGA2}
- If FX11Display Is TX11DGA2Display Then
- Result := Result + '(DGA) '
- Else
- {$ENDIF ENABLE_X11_EXTENSION_XF86DGA2}
- {$IFDEF ENABLE_X11_EXTENSION_XF86DGA1}
- If FX11Display Is TX11DGA1Display Then
- Result := Result + '(DGA) '
- Else
- {$ENDIF ENABLE_X11_EXTENSION_XF86DGA1}
- Begin
- {...}
- End;
- End;
- Result := Result + 'mode, ' +
- IntToStr(FX11Display.Width) + 'x' +
- IntToStr(FX11Display.Height) + ', ' +
- IntToStr(FX11Display.Format.Bits) + ' bit';
- End;
- Procedure TX11Console.UpdateCursor;
- Begin
- If Assigned(FX11Display) Then
- Begin
- If FX11Display.IsFullScreen Then
- FX11Display.SetCursor(PTC_X11_FULLSCREEN_CURSOR_VISIBLE In FFlags)
- Else
- FX11Display.SetCursor(Not (PTC_X11_WINDOWED_CURSOR_INVISIBLE In FFlags));
- End;
- End;
|