123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- Constructor TGDIConsole.Create;
- Begin
- Inherited Create;
- FDefaultWidth := 320;
- FDefaultHeight := 200;
- FDefaultFormat := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
- FCopy := TPTCCopy.Create;
- FClear := TPTCClear.Create;
- FArea := TPTCArea.Create;
- FClip := TPTCArea.Create;
- FPalette := TPTCPalette.Create;
- FOpen := False;
- { configure console }
- Configure('ptcpas.cfg');
- End;
- Destructor TGDIConsole.Destroy;
- Begin
- Close;
- {...}
- FWin32DIB.Free;
- FWindow.Free;
- FPalette.Free;
- FEventQueue.Free;
- FCopy.Free;
- FClear.Free;
- FArea.Free;
- FClip.Free;
- FDefaultFormat.Free;
- Inherited Destroy;
- End;
- Procedure TGDIConsole.Open(Const ATitle : String; APages : Integer = 0);
- Begin
- Open(ATitle, FDefaultFormat, APages);
- End;
- Procedure TGDIConsole.Open(Const ATitle : String; Const AFormat : TPTCFormat;
- APages : Integer = 0);
- Begin
- Open(ATitle, FDefaultWidth, FDefaultHeight, AFormat, APages);
- End;
- Procedure TGDIConsole.Open(Const ATitle : String; Const AMode : TPTCMode;
- APages : Integer = 0);
- Begin
- Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
- End;
- Procedure TGDIConsole.Open(Const ATitle : String; AWidth, AHeight : Integer;
- Const AFormat : TPTCFormat; APages : Integer = 0);
- Var
- tmp : TPTCArea;
- Begin
- If FOpen Then
- Close;
- (* FWindow := TWin32Window.Create('PTC_GDI_FULLSCREEN',
- ATitle,
- WS_EX_TOPMOST,
- DWord(WS_POPUP Or WS_SYSMENU Or WS_VISIBLE), // fpc windows RTL bug - WS_POPUP should be a DWord!!!
- SW_NORMAL,
- 0, 0,
- GetSystemMetrics(SM_CXSCREEN),
- GetSystemMetrics(SM_CYSCREEN),
- False, False);*)
- FWindow := TWin32Window.Create('PTC_GDI_WINDOWED_FIXED',
- ATitle,
- 0,
- WS_VISIBLE Or WS_SYSMENU Or WS_CAPTION Or WS_MINIMIZEBOX,
- SW_NORMAL,
- CW_USEDEFAULT, CW_USEDEFAULT,
- AWidth, AHeight,
- {m_center_window}False,
- False);
- (* FWindow := TWin32Window.Create('PTC_GDI_WINDOWED_RESIZABLE',
- ATitle,
- 0,
- WS_OVERLAPPEDWINDOW Or WS_VISIBLE,
- SW_NORMAL,
- CW_USEDEFAULT, CW_USEDEFAULT,
- AWidth, AHeight,
- {m_center_window}False,
- False);*)
- FWin32DIB := TWin32DIB.Create(AWidth, AHeight);
- FreeAndNil(FKeyboard);
- FreeAndNil(FMouse);
- FreeAndNil(FEventQueue);
- FEventQueue := TEventQueue.Create;
- FKeyboard := TWin32Keyboard.Create(FWindow.Handle, FWindow.Thread, False, FEventQueue);
- FMouse := TWin32Mouse.Create(FWindow.Handle, FWindow.Thread, False, FEventQueue, {FFullScreen}False, AWidth, AHeight);
- tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
- Try
- FArea.Assign(tmp);
- FClip.Assign(tmp);
- Finally
- tmp.Free;
- End;
- FWindow.Update;
- FTitle := ATitle;
- FOpen := True;
- End;
- Procedure TGDIConsole.Close;
- Begin
- If Not FOpen Then
- Exit;
- {...}
- FreeAndNil(FKeyboard);
- FreeAndNil(FMouse);
- FreeAndNil(FWin32DIB);
- FreeAndNil(FWindow);
- FreeAndNil(FEventQueue);
- FTitle := '';
- FOpen := False;
- End;
- Procedure TGDIConsole.Copy(Var ASurface : TPTCBaseSurface);
- Begin
- // todo...
- End;
- Procedure TGDIConsole.Copy(Var ASurface : TPTCBaseSurface;
- Const ASource, ADestination : TPTCArea);
- Begin
- // todo...
- End;
- Procedure TGDIConsole.Load(Const APixels : Pointer;
- AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat;
- Const APalette : TPTCPalette);
- Var
- Area_ : TPTCArea;
- console_pixels : Pointer;
- Begin
- CheckOpen( 'TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
- CheckUnlocked('TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
- 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 TGDIConsole.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
- CheckOpen( 'TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
- CheckUnlocked('TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
- 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 TGDIConsole.Save(APixels : Pointer;
- AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat;
- Const APalette : TPTCPalette);
- Begin
- // todo...
- End;
- Procedure TGDIConsole.Save(APixels : Pointer;
- AWidth, AHeight, APitch : Integer;
- Const AFormat : TPTCFormat;
- Const APalette : TPTCPalette;
- Const ASource, ADestination : TPTCArea);
- Begin
- // todo...
- End;
- Function TGDIConsole.Lock : Pointer;
- Begin
- Result := FWin32DIB.Pixels; // todo...
- FLocked := True;
- End;
- Procedure TGDIConsole.Unlock;
- Begin
- FLocked := False;
- End;
- Procedure TGDIConsole.Clear;
- Begin
- // todo...
- End;
- Procedure TGDIConsole.Clear(Const AColor : TPTCColor);
- Begin
- // todo...
- End;
- Procedure TGDIConsole.Clear(Const AColor : TPTCColor;
- Const AArea : TPTCArea);
- Begin
- // todo...
- End;
- Procedure TGDIConsole.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 TGDIConsole.Option(Const AOption : String) : Boolean;
- Begin
- // todo...
- Result := FCopy.Option(AOption);
- End;
- Procedure TGDIConsole.Palette(Const APalette : TPTCPalette);
- Begin
- // todo...
- End;
- Procedure TGDIConsole.Clip(Const AArea : TPTCArea);
- Var
- tmp : TPTCArea;
- Begin
- CheckOpen('TGDIConsole.Clip(AArea)');
- tmp := TPTCClipper.Clip(AArea, FArea);
- Try
- FClip.Assign(tmp);
- Finally
- tmp.Free;
- End;
- End;
- Function TGDIConsole.Clip : TPTCArea;
- Begin
- CheckOpen('TGDIConsole.Clip');
- Result := FClip;
- End;
- Function TGDIConsole.Palette : TPTCPalette;
- Begin
- CheckOpen('TGDIConsole.Palette');
- Result := FPalette;
- End;
- Function TGDIConsole.Modes : PPTCMode;
- Begin
- // todo...
- Result := Nil;
- End;
- Procedure TGDIConsole.Flush;
- Begin
- CheckOpen( 'TGDIConsole.Flush');
- CheckUnlocked('TGDIConsole.Flush');
- // todo...
- End;
- Procedure TGDIConsole.Finish;
- Begin
- CheckOpen( 'TGDIConsole.Finish');
- CheckUnlocked('TGDIConsole.Finish');
- // todo...
- End;
- Procedure TGDIConsole.Update;
- Var
- ClientRect : RECT;
- DeviceContext : HDC;
- Begin
- CheckOpen( 'TGDIConsole.Update');
- CheckUnlocked('TGDIConsole.Update');
- FWindow.Update;
- DeviceContext := GetDC(FWindow.m_window);
- If DeviceContext <> 0 Then
- Begin
- If GetClientRect(FWindow.m_window, @ClientRect) Then
- Begin
- StretchDIBits(DeviceContext,
- 0, 0, ClientRect.right, ClientRect.bottom,
- 0, 0, FWin32DIB.Width, FWin32DIB.Height,
- FWin32DIB.Pixels,
- FWin32DIB.BMI^,
- DIB_RGB_COLORS,
- SRCCOPY);
- End;
- ReleaseDC(FWindow.m_window, DeviceContext);
- End;
- End;
- Procedure TGDIConsole.Update(Const AArea : TPTCArea);
- Begin
- Update;
- End;
- Function TGDIConsole.NextEvent(Var AEvent : TPTCEvent; AWait : Boolean; Const AEventMask : TPTCEventMask) : Boolean;
- Begin
- CheckOpen('TGDIConsole.NextEvent');
- // CheckUnlocked('TGDIConsole.NextEvent');
- FreeAndNil(AEvent);
- Repeat
- { update window }
- FWindow.Update;
- { try to find an event that matches the EventMask }
- AEvent := FEventQueue.NextEvent(AEventMask);
- Until (Not AWait) Or (AEvent <> Nil);
- Result := AEvent <> Nil;
- End;
- Function TGDIConsole.PeekEvent(AWait : Boolean; Const AEventMask : TPTCEventMask) : TPTCEvent;
- Begin
- CheckOpen('TGDIConsole.PeekEvent');
- // CheckUnlocked('TGDIConsole.PeekEvent');
- Repeat
- { update window }
- FWindow.Update;
- { try to find an event that matches the EventMask }
- Result := FEventQueue.PeekEvent(AEventMask);
- Until (Not AWait) Or (Result <> Nil);
- End;
- Function TGDIConsole.GetWidth : Integer;
- Begin
- CheckOpen('TGDIConsole.GetWidth');
- Result := FWin32DIB.Width;
- End;
- Function TGDIConsole.GetHeight : Integer;
- Begin
- CheckOpen('TGDIConsole.GetHeight');
- Result := FWin32DIB.Height;
- End;
- Function TGDIConsole.GetPitch : Integer;
- Begin
- CheckOpen('TGDIConsole.GetPitch');
- Result := FWin32DIB.Pitch;
- End;
- Function TGDIConsole.GetArea : TPTCArea;
- Begin
- CheckOpen('TGDIConsole.GetArea');
- Result := FArea;
- End;
- Function TGDIConsole.GetFormat : TPTCFormat;
- Begin
- CheckOpen('TGDIConsole.GetFormat');
- Result := FWin32DIB.Format;
- End;
- Function TGDIConsole.GetPages : Integer;
- Begin
- CheckOpen('TGDIConsole.GetPages');
- Result := 2;
- End;
- Function TGDIConsole.GetName : String;
- Begin
- Result := 'GDI';
- End;
- Function TGDIConsole.GetTitle : String;
- Begin
- CheckOpen('TGDIConsole.GetTitle');
- Result := FTitle;
- End;
- Function TGDIConsole.GetInformation : String;
- Begin
- CheckOpen('TGDIConsole.GetInformation');
- Result := ''; // todo...
- End;
- Procedure TGDIConsole.CheckOpen(AMessage : String);
- Begin
- If Not FOpen Then
- Try
- Raise TPTCError.Create('console is not open');
- Except
- On error : TPTCError Do
- Raise TPTCError.Create(AMessage, error);
- End;
- End;
- Procedure TGDIConsole.CheckUnlocked(AMessage : String);
- Begin
- If FLocked Then
- Try
- Raise TPTCError.Create('console is locked');
- Except
- On error : TPTCError Do
- Raise TPTCError.Create(AMessage, error);
- End;
- End;
|