1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
|
{
Free Pascal port of the OpenPTC C++ library.
Copyright (C) 2001-2003, 2006, 2007, 2009-2013 Nikolay Nikolov (nickysn@users.sourceforge.net)
Original C++ version by Glenn Fiedler (ptc@gaffer.org)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version
with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
type
TPTCConsole = class(TPTCBaseConsole)
private
FConsole: IPTCConsole;
FModes: array of IPTCMode;
FOptionsQueue: array of string;
FHackyOptionConsoleFlag: Boolean;
FUseOpenGL: Boolean;
function ConsoleCreate(AIndex: Integer): IPTCConsole;
function ConsoleCreate(const AName: string): IPTCConsole;
procedure Check;
procedure AddOptionToOptionsQueue(const AOption: string);
procedure ExecuteOptionsFromOptionsQueue;
procedure ClearOptionsQueue;
procedure PassOpenGLOptionsToInnerConsole;
function GetOpenGL_Enabled: Boolean; override;
procedure SetOpenGL_Enabled(AValue: Boolean); override;
public
constructor Create; override;
destructor Destroy; override;
procedure Configure(const AFile: string); override;
function Option(const AOption: string): Boolean; override;
function Modes: TPTCModeList; override;
procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
procedure Open(const ATitle: string; AFormat: IPTCFormat;
APages: Integer = 0); overload; override;
procedure Open(const ATitle: string; AWidth, AHeight: Integer;
AFormat: IPTCFormat; APages: Integer = 0); overload; override;
procedure Open(const ATitle: string; AMode: IPTCMode;
APages: Integer = 0); overload; override;
procedure Close; override;
procedure InternalResize(AWidth, AHeight: Integer); override;
procedure Flush; override;
procedure Finish; override;
procedure Update; override;
procedure Update(AArea: IPTCArea); override;
procedure Copy(ASurface: IPTCSurface); override;
procedure Copy(ASurface: IPTCSurface;
ASource, ADestination: IPTCArea); override;
function Lock: Pointer; override;
procedure Unlock; override;
procedure Load(const APixels: Pointer;
AWidth, AHeight, APitch: Integer;
AFormat: IPTCFormat;
APalette: IPTCPalette); override;
procedure Load(const APixels: Pointer;
AWidth, AHeight, APitch: Integer;
AFormat: IPTCFormat;
APalette: IPTCPalette;
ASource, ADestination: IPTCArea); override;
procedure Save(APixels: Pointer;
AWidth, AHeight, APitch: Integer;
AFormat: IPTCFormat;
APalette: IPTCPalette); override;
procedure Save(APixels: Pointer;
AWidth, AHeight, APitch: Integer;
AFormat: IPTCFormat;
APalette: IPTCPalette;
ASource, ADestination: IPTCArea); override;
procedure Clear; override;
procedure Clear(AColor: IPTCColor); override;
procedure Clear(AColor: IPTCColor;
AArea: IPTCArea); override;
procedure Palette(APalette: IPTCPalette); override;
function Palette: IPTCPalette; override;
procedure Clip(AArea: IPTCArea); override;
function GetWidth: Integer; override;
function GetHeight: Integer; override;
function GetPitch: Integer; override;
function GetPages: Integer; override;
function GetArea: IPTCArea; override;
function Clip: IPTCArea; override;
function GetFormat: IPTCFormat; override;
function GetName: string; override;
function GetTitle: string; override;
function GetInformation: string; override;
function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; override;
procedure OpenGL_SwapBuffers; override;
procedure OpenGL_SetSwapInterval(AInterval: Integer); override;
function OpenGL_GetSwapInterval: Integer; override;
end;
class function TPTCConsoleFactory.CreateNew: IPTCConsole;
begin
Result := TPTCConsole.Create;
end;
const
{$IFDEF GO32V2}
ConsoleTypesNumber = 4;
{$ENDIF GO32V2}
{$IF defined(Win32) OR defined(Win64)}
ConsoleTypesNumber = 2;
{$ENDIF defined(Win32) OR defined(Win64)}
{$IFDEF WinCE}
ConsoleTypesNumber = 2;
{$ENDIF WinCE}
{$IFDEF UNIX}
ConsoleTypesNumber = 1;
{$ENDIF UNIX}
ConsoleTypes: array [0..ConsoleTypesNumber - 1] of
record
ConsoleClass: class of TPTCBaseConsole;
Names: array [1..2] of string;
OpenGL: Boolean;
end =
(
{$IFDEF GO32V2}
(ConsoleClass: TVESAConsole; Names: ('VESA', ''); OpenGL: False),
(ConsoleClass: TVGAConsole; Names: ('VGA', 'Fakemode'); OpenGL: False),
(ConsoleClass: TCGAConsole; Names: ('CGA', ''); OpenGL: False),
(ConsoleClass: TTEXTFX2Console; Names: ('TEXTFX2', 'Text'); OpenGL: False)
{$ENDIF GO32V2}
{$IF defined(Win32) OR defined(Win64)}
(ConsoleClass: TDirectXConsole; Names: ('DirectX', ''); OpenGL: False),
(ConsoleClass: TGDIConsole; Names: ('GDI', ''); OpenGL: True)
{$ENDIF defined(Win32) OR defined(Win64)}
{$IFDEF WinCE}
(ConsoleClass: TWinCEGAPIConsole; Names: ('GAPI', ''); OpenGL: False),
(ConsoleClass: TWinCEGDIConsole; Names: ('GDI', ''); OpenGL: False)
{$ENDIF WinCE}
{$IFDEF UNIX}
(ConsoleClass: TX11Console; Names: ('X11', ''); OpenGL: {$IFDEF ENABLE_X11_EXTENSION_GLX}True{$ELSE}False{$ENDIF})
{$ENDIF UNIX}
);
constructor TPTCConsole.Create;
{$IFDEF UNIX}
var
s: AnsiString;
{$ENDIF UNIX}
begin
inherited Create;
FConsole := nil;
FHackyOptionConsoleFlag := False;
{$IFDEF UNIX}
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);
{$ENDIF UNIX}
{$IFDEF Win32}
Configure('ptcpas.cfg');
{$ENDIF Win32}
{$IFDEF GO32V2}
Configure('ptcpas.cfg');
{$ENDIF GO32V2}
{$IFDEF WinCE}
{todo: configure WinCE}
{$ENDIF WinCE}
end;
destructor TPTCConsole.Destroy;
begin
Close;
FConsole := nil;
inherited Destroy;
end;
procedure TPTCConsole.Configure(const AFile: string);
var
F: TextFile;
S: string;
begin
AssignFile(F, AFile);
{$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;
procedure TPTCConsole.AddOptionToOptionsQueue(const AOption: string);
begin
SetLength(FOptionsQueue, Length(FOptionsQueue) + 1);
FOptionsQueue[High(FOptionsQueue)] := AOption;
end;
procedure TPTCConsole.ExecuteOptionsFromOptionsQueue;
var
I: Integer;
begin
for I := Low(FOptionsQueue) to High(FOptionsQueue) do
FConsole.Option(FOptionsQueue[I]);
end;
procedure TPTCConsole.ClearOptionsQueue;
begin
SetLength(FOptionsQueue, 0);
end;
function TPTCConsole.Option(const AOption: String): Boolean;
begin
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(FConsole) then
Result := FConsole.Option(AOption)
else
begin
FConsole := ConsoleCreate(AOption);
if Assigned(FConsole) then
begin
FHackyOptionConsoleFlag := True;
PassOpenGLOptionsToInnerConsole;
ExecuteOptionsFromOptionsQueue;
{ ClearOptionsQueue;}
Result := True;
end
else
begin
{ TODO: check if the option is supported by at least one console and return false otherwise... }
AddOptionToOptionsQueue(AOption);
Result := True;
end;
end;
end;
function TPTCConsole.Modes: TPTCModeList;
var
_console: IPTCConsole;
index, mode: Integer;
local: Integer;
_modes: TPTCModeList;
begin
if Assigned(FConsole) then
Result := FConsole.Modes
else
begin
_console := nil;
SetLength(FModes, 0);
index := -1;
mode := 0;
repeat
Inc(index);
try
_console := ConsoleCreate(index);
except
on TPTCError do begin
_console := nil;
continue;
end;
end;
if _console = nil then
break;
_modes := _console.modes;
SetLength(FModes, Length(FModes) + Length(_modes));
for local := Low(_modes) to High(_modes) do
begin
FModes[mode] := _modes[local];
Inc(mode);
end;
until False;
{ todo: strip duplicate modes from list? }
Result := FModes;
end;
end;
procedure TPTCConsole.Open(const ATitle: string; APages: Integer);
var
composite, tmp: TPTCError;
index: Integer;
success: Boolean;
begin
if Assigned(FConsole) then
begin
try
FConsole.open(ATitle, APages);
exit;
except
on error: TPTCError do begin
FConsole := nil;
if FHackyOptionConsoleFlag then
begin
FHackyOptionConsoleFlag := False;
raise TPTCError.Create('could not open console', error);
end;
end;
end;
end;
index := -1;
composite := TPTCError.Create;
success := False;
try
repeat
Inc(index);
try
FConsole := ConsoleCreate(index);
if FConsole = nil then
break;
PassOpenGLOptionsToInnerConsole;
ExecuteOptionsFromOptionsQueue;
FConsole.Open(ATitle, APages);
{ ClearOptionsQueue;}
success := True;
exit;
except
on error: TPTCError do begin
tmp := TPTCError.Create(error.message, composite);
try
composite.Assign(tmp);
finally
tmp.Free;
end;
FConsole := nil;
continue;
end;
end;
until False;
FConsole := nil;
raise TPTCError.Create(composite);
finally
composite.Free;
if not success then
FConsole := nil;
end;
end;
procedure TPTCConsole.Open(const ATitle: string; AFormat: IPTCFormat;
APages: Integer);
var
composite, tmp: TPTCError;
index: Integer;
success: Boolean;
begin
if Assigned(FConsole) then
begin
try
FConsole.open(ATitle, AFormat, APages);
exit;
except
on error: TPTCError do begin
FConsole := nil;
if FHackyOptionConsoleFlag then
begin
FHackyOptionConsoleFlag := False;
raise TPTCError.Create('could not open console', error);
end;
end;
end;
end;
index := -1;
composite := TPTCError.Create;
success := False;
try
repeat
Inc(index);
try
FConsole := ConsoleCreate(index);
if FConsole = nil then
break;
PassOpenGLOptionsToInnerConsole;
ExecuteOptionsFromOptionsQueue;
FConsole.open(ATitle, AFormat, APages);
{ ClearOptionsQueue;}
success := True;
exit;
except
on error: TPTCError do begin
tmp := TPTCError.Create(error.message, composite);
try
composite.Assign(tmp);
finally
tmp.Free;
end;
FConsole := nil;
Continue;
end;
end;
until False;
FConsole := nil;
raise TPTCError.Create(composite);
finally
composite.Free;
if not success then
FConsole := nil;
end;
end;
procedure TPTCConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
AFormat: IPTCFormat; APages: Integer);
var
composite, tmp: TPTCError;
index: Integer;
success: Boolean;
begin
if Assigned(FConsole) then
begin
try
FConsole.Open(ATitle, AWidth, AHeight, AFormat, APages);
exit;
except
on error: TPTCError do begin
FConsole := nil;
if FHackyOptionConsoleFlag then
begin
FHackyOptionConsoleFlag := False;
raise TPTCError.Create('could not open console', error);
end;
end;
end;
end;
index := -1;
composite := TPTCError.Create;
success := False;
try
repeat
Inc(index);
try
FConsole := ConsoleCreate(index);
if FConsole = nil then
Break;
PassOpenGLOptionsToInnerConsole;
ExecuteOptionsFromOptionsQueue;
FConsole.Open(ATitle, AWidth, AHeight, AFormat, APages);
{ ClearOptionsQueue;}
success := True;
exit;
except
on error: TPTCError do begin
tmp := TPTCError.Create(error.message, composite);
try
composite.Assign(tmp);
finally
tmp.Free;
end;
FConsole := nil;
Continue;
end;
end;
until False;
FConsole := nil;
raise TPTCError.Create(composite);
finally
composite.Free;
if not success then
FConsole := nil;
end;
end;
procedure TPTCConsole.Open(const ATitle: string; AMode: IPTCMode;
APages: Integer);
var
composite, tmp: TPTCError;
index: Integer;
success: Boolean;
begin
if Assigned(FConsole) then
begin
try
FConsole.Open(ATitle, AMode, APages);
exit;
except
on error: TPTCError do begin
FConsole := nil;
if FHackyOptionConsoleFlag then
begin
FHackyOptionConsoleFlag := False;
raise TPTCError.Create('could not open console', error);
end;
end;
end;
end;
index := -1;
composite := TPTCError.Create;
success := False;
try
repeat
Inc(index);
try
FConsole := ConsoleCreate(index);
if FConsole = nil then
Break;
PassOpenGLOptionsToInnerConsole;
ExecuteOptionsFromOptionsQueue;
FConsole.Open(ATitle, AMode, APages);
{ ClearOptionsQueue;}
success := True;
exit;
except
on error: TPTCError do begin
tmp := TPTCError.Create(error.message, composite);
try
composite.Assign(tmp);
finally
tmp.Free;
end;
FConsole := nil;
Continue;
end;
end;
until False;
FConsole := nil;
raise TPTCError.Create(composite);
finally
composite.Free;
if not success then
FConsole := nil;
end;
end;
procedure TPTCConsole.Close;
begin
if Assigned(FConsole) then
FConsole.Close;
FHackyOptionConsoleFlag := False;
end;
procedure TPTCConsole.Flush;
begin
Check;
FConsole.Flush;
end;
procedure TPTCConsole.Finish;
begin
Check;
FConsole.Finish;
end;
procedure TPTCConsole.Update;
begin
Check;
FConsole.Update;
end;
procedure TPTCConsole.Update(AArea: IPTCArea);
begin
Check;
FConsole.Update(AArea);
end;
procedure TPTCConsole.Copy(ASurface: IPTCSurface);
begin
Check;
FConsole.Copy(ASurface);
end;
procedure TPTCConsole.Copy(ASurface: IPTCSurface;
ASource, ADestination: IPTCArea);
begin
Check;
FConsole.Copy(ASurface, ASource, ADestination);
end;
function TPTCConsole.Lock: Pointer;
begin
Check;
Result := FConsole.Lock;
end;
procedure TPTCConsole.Unlock;
begin
Check;
FConsole.Unlock;
end;
procedure TPTCConsole.Load(const APixels: Pointer;
AWidth, AHeight, APitch: Integer;
AFormat: IPTCFormat;
APalette: IPTCPalette);
begin
Check;
FConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette);
end;
procedure TPTCConsole.Load(const APixels: Pointer;
AWidth, AHeight, APitch: Integer;
AFormat: IPTCFormat;
APalette: IPTCPalette;
ASource, ADestination: IPTCArea);
begin
Check;
FConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette,
ASource, ADestination);
end;
procedure TPTCConsole.Save(Apixels: Pointer;
AWidth, AHeight, APitch: Integer;
AFormat: IPTCFormat;
APalette: IPTCPalette);
begin
Check;
FConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette);
end;
procedure TPTCConsole.Save(APixels: Pointer;
AWidth, AHeight, APitch: Integer;
AFormat: IPTCFormat;
APalette: IPTCPalette;
ASource, ADestination: IPTCArea);
begin
Check;
FConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette,
ASource, ADestination);
end;
procedure TPTCConsole.Clear;
begin
Check;
FConsole.Clear;
end;
procedure TPTCConsole.Clear(AColor: IPTCColor);
begin
Check;
FConsole.Clear(AColor);
end;
procedure TPTCConsole.Clear(AColor: IPTCColor;
AArea: IPTCArea);
begin
Check;
FConsole.Clear(AColor, AArea);
end;
procedure TPTCConsole.Palette(APalette: IPTCPalette);
begin
Check;
FConsole.Palette(APalette);
end;
function TPTCConsole.Palette: IPTCPalette;
begin
Check;
Result := FConsole.Palette;
end;
procedure TPTCConsole.Clip(AArea: IPTCArea);
begin
Check;
FConsole.Clip(AArea);
end;
function TPTCConsole.GetWidth: Integer;
begin
Check;
Result := FConsole.GetWidth;
end;
function TPTCConsole.GetHeight: Integer;
begin
Check;
Result := FConsole.GetHeight;
end;
function TPTCConsole.GetPitch: Integer;
begin
Check;
Result := FConsole.GetPitch;
end;
function TPTCConsole.GetPages: Integer;
begin
Check;
Result := FConsole.GetPages;
end;
function TPTCConsole.GetArea: IPTCArea;
begin
Check;
Result := FConsole.GetArea;
end;
function TPTCConsole.Clip: IPTCArea;
begin
Check;
Result := FConsole.Clip;
end;
function TPTCConsole.GetFormat: IPTCFormat;
begin
Check;
Result := FConsole.GetFormat;
end;
function TPTCConsole.GetName: string;
begin
Result := '';
if Assigned(FConsole) then
Result := FConsole.GetName
else
{$IFDEF GO32V2}
Result := 'DOS';
{$ENDIF GO32V2}
{$IFDEF WIN32}
Result := 'Win32';
{$ENDIF WIN32}
{$IFDEF WIN64}
Result := 'Win64';
{$ENDIF WIN64}
{$IFDEF LINUX}
Result := 'Linux';
{$ENDIF LINUX}
end;
function TPTCConsole.GetTitle: string;
begin
Check;
Result := FConsole.GetTitle;
end;
function TPTCConsole.GetInformation: string;
begin
Check;
Result := FConsole.GetInformation;
end;
function TPTCConsole.NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
begin
Check;
Result := FConsole.NextEvent(AEvent, AWait, AEventMask);
end;
function TPTCConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
begin
Check;
Result := FConsole.PeekEvent(AWait, AEventMask);
end;
function TPTCConsole.ConsoleCreate(AIndex: Integer): IPTCConsole;
var
ResultObj: TPTCBaseConsole;
begin
Result := nil;
if (AIndex >= Low(ConsoleTypes)) and (AIndex <= High(ConsoleTypes)) then
begin
if OpenGL_Enabled and not ConsoleTypes[AIndex].OpenGL then
raise TPTCError.Create('Console does not support OpenGL');
ResultObj := ConsoleTypes[AIndex].ConsoleClass.Create;
Result := ResultObj;
ResultObj.FOpenGLAttributes := FOpenGLAttributes;
end;
if Result <> nil then
Result.KeyReleaseEnabled := KeyReleaseEnabled;
end;
function TPTCConsole.ConsoleCreate(const AName: string): IPTCConsole;
var
I, J: Integer;
begin
Result := nil;
if AName = '' then
exit;
for I := Low(ConsoleTypes) to High(ConsoleTypes) do
for J := Low(ConsoleTypes[I].Names) to High(ConsoleTypes[I].Names) do
if AName = ConsoleTypes[I].Names[J] then
begin
Result := ConsoleCreate(I);
exit;
end;
end;
procedure TPTCConsole.Check;
begin
if FConsole = nil then
raise TPTCError.Create('console is not open (core)');
end;
procedure TPTCConsole.PassOpenGLOptionsToInnerConsole;
begin
FConsole.OpenGL_Enabled := FUseOpenGL;
end;
function TPTCConsole.GetOpenGL_Enabled: Boolean;
begin
if FConsole <> nil then
Result := FConsole.OpenGL_Enabled
else
Result := FUseOpenGL;
end;
procedure TPTCConsole.SetOpenGL_Enabled(AValue: Boolean);
begin
if FConsole <> nil then
FConsole.OpenGL_Enabled := AValue
else
FUseOpenGL := AValue;
end;
procedure TPTCConsole.OpenGL_SwapBuffers;
begin
Check;
FConsole.OpenGL_SwapBuffers;
end;
procedure TPTCConsole.OpenGL_SetSwapInterval(AInterval: Integer);
begin
Check;
FConsole.OpenGL_SetSwapInterval(AInterval);
end;
function TPTCConsole.OpenGL_GetSwapInterval: Integer;
begin
Check;
Result := FConsole.OpenGL_GetSwapInterval;
end;
procedure TPTCConsole.InternalResize(AWidth, AHeight: Integer);
begin
Check;
FConsole.InternalResize(AWidth, AHeight);
end;
|