forked from neurolabusc/surf-ice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.pas
executable file
·657 lines (616 loc) · 21.8 KB
/
prefs.pas
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
unit prefs;
{$D-,O+,Q-,R-,S-} //Delphi L-,Y-
{$H+}
interface
uses {$ifndef isTerminalApp}graphics,Dialogs,{$endif}IniFiles,SysUtils,define_types,Classes; //,
const
knMRU = 10;
kRenderPoor = 0;
kRenderBetter = 1;
//kRenderBest = 2;
kSaveAsObj = 0;
kSaveAsGii = 1;
kSaveAsMz3 = 2;
kSaveAsTrackVtk = 0;
kSaveAsTrackBfloat = 1;
kSaveAsTrackTrk = 2;
type
TMRU = array [1..knMRU] of string;
TPrefs = record
SmoothVoxelwiseData,
OverlayClip, StartupScript, SupportBetterRenderQuality, AdditiveOverlay,Perspective, OrientCube, MultiSample, BlackDefaultBackground,
Colorbar,TracksAreTubes, ScreenCaptureTransparentBackground,LoadTrackOnLaunch,ColorBarPrecedenceTracksNotOverlays,
ZDimIsUp, ShaderForBackgroundOnly, CoreTrackDisableDepth, SkipPrefWriting, isFlipMeshOverlay, DarkMode, RetinaDisplay, GenerateSmoothCurves : boolean;
TrackTubeSlices, ScreenCaptureZoom,ColorbarColor,ColorBarPosition,
window_width, window_height, RenderQuality, SaveAsFormat,SaveAsFormatTrack, OcclusionAmount: integer;
ObjColor,BackColor: TColor;
PrevFilename, PrevScriptName: TMRU;
//{$IFDEF Darwin}BaseDirname, {$ENDIF} //OSX Sierra puts application in random directory, so 'Sample' 'BrainNet' folders will be in unknown locations
PyLib, FontName, PrevTrackname, PrevNodename, PrevOverlayname,PrevScript, InitScript : string;
TextColor,TextBorder,GridAndBorder: TRGBA;
ColorbarSize: single;
//ColorBarPos: TUnitRect;
ScreenPan: TPoint3f;
end;
function IniFile(lRead: boolean; lFilename: string; var lPrefs: TPrefs): boolean;
procedure IniByte(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: byte);
procedure IniInt(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: integer);
procedure IniFloat(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: single);
procedure IniColor(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: TColor);
procedure SetDefaultPrefs (var lPrefs: TPrefs; lEverything, askUserIfMissing: boolean);
procedure IniRGBA(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: TRGBA);
procedure FillMRU (var lMRU: TMRU; lSearchPath,lSearchExt: string; lForce: boolean);
procedure Add2MRU (var lMRU: TMRU; lNewFilename: string); //add new file to most-recent list
implementation
uses
{$IFDEF Darwin}mainunit, {$ENDIF}
userdir;
function IsNovel (lName: string; var lMRU: TMRU; lnOK: integer):boolean;
var lI,lN: integer;
begin
result := false;
lN := lNOK;
if lnOK > knMRU then
lN := knMRU;
if lN < 1 then begin
result := true;
exit;
end;
for lI := 1 to lN do
if lMRU[lI] = lName then
exit;
result := true;
end;
procedure Add2MRU (var lMRU: TMRU; lNewFilename: string); //add new file to most-recent list
var
lNewM,lOldM,lStr: string;
lPos,lN : integer;
begin
lNewM := extractfilename(lNewFilename);
//first, increase position of all old MRUs
lN := 0; //Number of MRU files
for lPos := 1 to (knMRU) do begin//first, eliminate duplicates
lStr := lMRU[lPos];
lOldM := extractfilename(lStr);
if (lStr <> '') {and (lStr <> lNewFileName)} and (lNewM <> lOldM) then begin
inc(lN);
lMRU[lN] := lStr;
end; //keep in MRU list
end; //for each MRU
//next, increment positions
if lN >= knMRU then
lN := knMRU - 1;
for lPos := lN downto 1 do
lMRU[lPos+1] := lMRU[lPos];
if (lN+2) < (knMRU) then //+1 as we have added a file
for lPos := (lN+2) to knMRU do
lMRU[lPos] := '';
lMRU[1] := lNewFilename;
end;//Add2MRU
procedure FillMRU (var lMRU: TMRU; lSearchPath,lSearchExt: string; lForce: boolean);
//e.g. SearchPath includes final pathdelim, e.g. c:\filedir\
var
lSearchRec: TSearchRec;
lI,lMax,lOK: integer;
lS: TStringList;
begin
lOK := 0;
if (not lForce) and (lMRU[1] <> '') then begin
//exit; //only fill empty MRUs...
for lI := 1 to knMRU do begin
if (lMRU[lI] <> '') and (fileexists(lMRU[lI])) and (IsNovel (lMRU[lI], lMRU, lOK)) then begin
inc(lOK);
lMRU[lOK] := lMRU[lI];
end; //if file exists
end; //for each MRU
if lOK = knMRU then
exit; //all slots filled;
for lI := (lOK+1) to knMRU do
lMRU[lI] := '';//empty slot
end; //check exisiting MRUs
lS := TStringList.Create;
if FindFirst(lSearchPath+'*'+lSearchExt, faAnyFile, lSearchRec) = 0 then
repeat
if (lSearchRec.Name <> '') and (lSearchRec.Name[1] <> '.') and IsNovel (lSearchPath+lSearchRec.Name, lMRU, lOK) then
lS.Add(lSearchPath+lSearchRec.Name) ;
until (FindNext(lSearchRec) <> 0);
FindClose(lSearchRec);
lMax := lS.count;
if lMax > 0 then begin
lS.sort;
if lMax > knMRU then
lMax := knMRU;
for lI := (lOK+1) to lMax do
lMRu[lI] := lS[lI-1];
end;
Freeandnil(lS);
end;//UpdateLUT
procedure IniFloat(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: single);
//read or write an integer value to the initialization file
var
lStr: string;
begin
if not lRead then begin
lIniFile.WriteString('FLT',lIdent,FloattoStr(lValue));
exit;
end;
lStr := lIniFile.ReadString('FLT',lIdent, '');
if length(lStr) > 0 then
lValue := StrToFloat(lStr);
end; //IniFloat
procedure IniByte(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: byte);
//read or write an integer value to the initialization file
var
lStr: string;
begin
if not lRead then begin
lIniFile.WriteString('BYT',lIdent,InttoStr(lValue));
exit;
end;
lStr := lIniFile.ReadString('BYT',lIdent, '');
if length(lStr) > 0 then
lValue := StrToInt(lStr);
end; //IniFloat
{$IFDEF Darwin}
function FixName (fnm, fldr: string; var lPrefs: TPrefs): string;
begin
result := fnm;
if fileexists(result) then exit;
result := ExtractFilePath(gPrefs.PrevFilename[1])+ExtractFileName(fnm);
if fileexists(result) then exit;
result := ExtractFilePath(lPrefs.PrevFilename[1])+ExtractFileName(fnm);
if fileexists(result) then exit;
result := ExtractFilePath(extractfiledir(gPrefs.PrevFilename[1]))+fldr+pathdelim+ExtractFileName(fnm);
if fileexists(result) then exit;
result := ExtractFilePath(extractfiledir(lPrefs.PrevFilename[1]))+fldr+pathdelim+ExtractFileName(fnm);
if fileexists(result) then exit;
if fileexists(result) then exit;
result := fnm;
end;
//attempt to correct if app is running using Gatekeeper Application Path Randomization
function DeTranslocate(fnm, fldr: string; var lPrefs: TPrefs): string;
const
kMeshFilter = 'Mesh (mz3)|*.mz3';
begin
result := fnm;
if fileexists(result) then exit;
result := FixName (fnm, fldr,lPrefs);
if fileexists(result) then exit;
//if pos('AppTranslocation',paramstr(0)) < 1 then exit;
//result := ExtractFilePath(gPrefs.PrevFilename[1])+ExtractFileName(fnm);
if fileexists(result) then exit;
//showmessage(lPrefs.PrevFilename[1]);
showmessage('Please find file '+extractfilename(fnm));
GLForm1.OpenDialog.Filter := kMeshFilter;
GLForm1.OpenDialog.Title := 'Select '+extractfilename(fnm);
if not GLForm1.OpenDialog.Execute then exit;
result := GLForm1.OpenDialog.FileName;
end;
{$ENDIF}
const
kNumDefaultMesh = 6;
function DefaultMeshName (indx: integer; var lPrefs: TPrefs; askUserIfMissing: boolean): string;
var
fldr,lPath,lName: string;
begin
lPath := ExtractFileDir(AppDir2());
lPath := lPath + PathDelim;
if indx = 1 then
fldr := 'sample'
else if indx < 5 then
fldr := 'BrainNet'
else
fldr := 'fs';
case indx of
2: lName := lPath + fldr+ PathDelim + 'BrainMesh_ICBM152_smoothed.mz3';
3: lName := lPath + fldr+ PathDelim + 'BrainMesh_ICBM152Left_smoothed.mz3';
4: lName := lPath + fldr+ PathDelim + 'BrainMesh_ICBM152Right_smoothed.mz3';
5: lName := lPath + fldr+ PathDelim + 'lh.inflated';
6: lName := lPath + fldr+ PathDelim + 'lh.pial';
else begin
lName := lPath + 'sample'+ PathDelim + 'mni152_2009.mz3';
{$IFDEF Darwin}
//lName := FixName (lName, lPrefs);
if (indx = 1) and (askUserIfMissing) then begin
lName := DeTranslocate(lName, fldr, lPrefs);
end;
{$ENDIF}
end;
end;
result := lName;
if fileexists(lName) then exit; //success
{$IFDEF Darwin}
//if (indx <> 1) then
result := FixName (result, fldr, lPrefs);
if fileexists(result) then exit; //success
{$ENDIF}
result := ''; //failure!
end;
(* below: basic outline for OSX Sierra - unused since we now code sign a DMG
function DefaultMeshName (indx: integer; var lPrefs: TPrefs): string;
var
lPath,lName {$IFDEF Darwin}, lExt {$ENDIF}: string;
{$IFDEF Darwin}
dirDlg : TSelectDirectoryDialog;
{$ENDIF}
begin
lPath := ExtractFileDir(AppDir());
{$IFDEF Darwin} //OSX Sierra: application in randomized location on your drive https://9to5mac.com/2016/06/15/macos-sierra-gatekeeper-changes/
if (length(lPrefs.BaseDirname) < 1) or (not fileexists(lPrefs.BaseDirname)) then begin
FilenameParts (lPath, lPath,lName,lExt) ;
lName := lPath + 'sample';
showmessage(lName);
if not fileexists(lName) then begin
dirDlg := TSelectDirectoryDialog.Create(nil);
dirDlg.Title:='Please select "sample" folder';
if dirDlg.Execute then begin
//lName := dirDlg.FileName;
FilenameParts (dirDlg.FileName, lPath,lName,lExt) ;
lName := lPath;
end;
dirDlg.Free;
end;
lPrefs.BaseDirname := lName;
end else
lPath := lPrefs.BaseDirname;
{$ELSE}
lPath := lPath + PathDelim;
{$ENDIF}
case indx of
2: lName := lPath + 'BrainNet'+ PathDelim + 'BrainMesh_ICBM152_smoothed.mz3';
3: lName := lPath + 'BrainNet'+ PathDelim + 'BrainMesh_ICBM152Left_smoothed.mz3';
4: lName := lPath + 'BrainNet'+ PathDelim + 'BrainMesh_ICBM152Right_smoothed.mz3';
5: lName := lPath + 'fs'+ PathDelim + 'lh.inflated';
6: lName := lPath + 'fs'+ PathDelim + 'lh.pial';
else
lName := lPath + 'sample'+ PathDelim + 'mni152_2009.mz3';
end;
if fileexists(lName) then
result := lName
else
result := '';
end; *)
procedure SetDefaultPrefs (var lPrefs: TPrefs; lEverything, askUserIfMissing: boolean);
var
i: integer;
begin
if lEverything then begin //These values are typically not changed...
with lPrefs do begin
//CrossHairs := true;
ColorbarSize := 0.035;
ObjColor := RGBToColor(212, 168, 168);
BackColor := RGBToColor(0, 0, 0);
TextColor := RGBA(255,255,255,255);
TextBorder := RGBA(92,92,132,255);
GridAndBorder := RGBA(106,106,142,222);
//ColorBarPos:= CreateUnitRect (0.1,0.1,0.9,0.14);
ScreenPan.X := 0; ScreenPan.Y := 0; ScreenPan.Z := 0;
for i := 1 to knMRU do begin
PrevFilename[i] := '';
PrevScriptName[i] := '';
end;
//lPrefs.BaseDirName := '';
for i := 1 to kNumDefaultMesh do
PrevFilename[i] := DefaultMeshName(i, lPrefs, askUserIfMissing);
FontName := '';
PyLib := '';
end;
end;
with lPrefs do begin
RenderQuality := kRenderBetter;
ColorBarPrecedenceTracksNotOverlays := false;
SupportBetterRenderQuality := false;
Colorbar := true;
ColorbarColor := 4;
ColorBarPosition := 3;
ZDimIsUp := true;
GenerateSmoothCurves := true;
ShaderForBackgroundOnly := false;
CoreTrackDisableDepth := false;
LoadTrackOnLaunch := false;
TracksAreTubes := true;
TrackTubeSlices := 5;
ScreenCaptureZoom := 2;
SaveAsFormat := kSaveAsObj;
SaveAsFormatTrack := kSaveAsTrackVtk;
OcclusionAmount := 25;
//MultiPassRendering := true;
MultiSample := true;
OrientCube := true;
Perspective := false;
AdditiveOverlay := false;
SkipPrefWriting := false;
isFlipMeshOverlay := false;
RetinaDisplay := true;
DarkMode := false;
BlackDefaultBackground := false;
OverlayClip := false;
StartupScript := false;
ScreenCaptureTransparentBackground := true;
SmoothVoxelwiseData := true;
PrevTrackname := '';
PrevOverlayname := '';
PrevScript := '';
PrevNodename := '';
end;//with lPrefs
end; //Proc SetDefaultPrefs
(*procedure SetDefaultPrefsMRU (var lPrefs: TPrefs);
var
lI: integer;
begin
SetDefaultPrefs(lPrefs,true);
for lI := 1 to knMRU do begin
lPrefs.PrevFilename[lI] := '';
end;
end; *)
procedure IniInt(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: integer);
//read or write an integer value to the initialization file
var
lStr: string;
begin
if not lRead then begin
lIniFile.WriteString('INT',lIdent,IntToStr(lValue));
exit;
end;
lStr := lIniFile.ReadString('INT',lIdent, '');
if length(lStr) > 0 then
lValue := StrToInt(lStr);
end; //IniInt
function Bool2Char (lBool: boolean): char;
begin
if lBool then
result := '1'
else
result := '0';
end;
function Char2Bool (lChar: char): boolean;
begin
if lChar = '1' then
result := true
else
result := false;
end;
procedure IniBool(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: boolean);
//read or write a boolean value to the initialization file
var
lStr: string;
begin
if not lRead then begin
lIniFile.WriteString('BOOL',lIdent,Bool2Char(lValue));
exit;
end;
lStr := lIniFile.ReadString('BOOL',lIdent, '');
if length(lStr) > 0 then
lValue := Char2Bool(lStr[1]);
end; //IniBool
procedure IniStrX(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: string);
//read or write a string value to the initialization file
begin
if not lRead then begin
if lValue = '' then
lIniFile.WriteString('STR',lIdent,'_')
else
lIniFile.WriteString('STR',lIdent,lValue);
exit;
end;
lValue := lIniFile.ReadString('STR',lIdent, '');
if lValue = '_' then
lValue := '';
end; //IniStr
procedure IniStr(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: string);
//read or write a string value to the initialization file
begin
if not lRead then begin
lIniFile.WriteString('STR',lIdent,lValue);
exit;
end;
lValue := lIniFile.ReadString('STR',lIdent, '');
end; //IniStr
const
kStrSep = '|';
function RGBToStr (lU: TColor) : string;
begin
result := Inttostr(red(lU))+ kStrSep+Inttostr(green(lU))+ kStrSep+Inttostr(blue(lU));
end;
function StrToRGB(lS: string; var lU: TColor): boolean;
var
strlst:TStringList;
begin
result := false;
strlst:=TStringList.Create;
strlst.Delimiter:=kStrSep;
strlst.DelimitedText := lS;
if strlst.Count > 2 then begin
lU := RGBToColor( strtoint(strlst[0]), strtoint(strlst[1]), strtoint(strlst[2]))
end;
strlst.free;
end;
procedure IniColor(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: TColor);
var
lStr: string;
begin
if not lRead then begin
lIniFile.WriteString('RGB255',lIdent,RGBToStr(lValue));
exit;
end;
lStr := lIniFile.ReadString('RGB255',lIdent, '');
StrToRGB(lStr,lValue);
end; //IniRGBA
procedure IniMRU(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lMRU: TMRU; var lPrefs: TPrefs);
var
lI,lOK: integer;
lStr: string;
function Novel: boolean;
var
lX: integer;
begin
result := true;
if (lOK < 1) or (lOK > knMRU) then exit;
result := false;
for lX := 1 to lOK do
if lMRU[lX] = lStr then
exit;
result := true;
end;
begin
if lRead then begin //compress files so lowest values are OK
lOK := 0;
for lI := 1 to knMRU do begin
IniStr(lRead,lIniFile,lIdent+inttostr(lI),lStr);
if (length(lStr) > 0) and (fileexistsF(lStr)) and (Novel) then begin
inc(lOK);
lMRU[lOK] := lStr;
end else
lMRU[lI] := '';
end; //for each MRU
//file empty slots
lI := 0;
while (lOK < knMRU) and (lI < kNumDefaultMesh) do begin
lI := lI + 1;
lStr := DefaultMeshName(lI, lPrefs, lOK = 0);
if (length(lStr) > 0) and (fileexistsF(lStr)) and (Novel) then begin
inc(lOK);
lMRU[lOK] := lStr;
end;
end;
end else
for lI := 1 to knMRU do
IniStr(lRead,lIniFile,lIdent+inttostr(lI),lMRU[lI]); //write values
end;
function RGBAToStr (lU: tRGBA) : string;
//floatrect values 0..1 convert to byte 0..1
begin
result := Inttostr(lU.r)+ kStrSep+Inttostr(lU.g)+ kStrSep+Inttostr(lU.b)+ kStrSep+Inttostr(lU.a);
end;
function StrToRGBA(lS: string; var lU: TRGBA): boolean;
var
strlst:TStringList;
begin
result := false;
strlst:=TStringList.Create;
strlst.Delimiter:=kStrSep;
strlst.DelimitedText := lS;
if strlst.Count > 3 then begin
lU := RGBA( strtoint(strlst[0]), strtoint(strlst[1]), strtoint(strlst[2]), strtoint(strlst[3])) ;
result := true;
end;
strlst.free;
end;
procedure IniRGBA(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: TRGBA);
//read or write an integer value to the initialization file
var
lStr: string;
begin
if not lRead then begin
//lI64 := lValue.rgbred + lValue.rgbGreen shl 8 + lValue.rgbBlue shl 16 + lValue.rgbReserved shl 24;
//lIniFile.WriteString('RGBA',lIdent,InttoStr(lI64));
lIniFile.WriteString('RGBA255',lIdent,RGBAToStr(lValue));
exit;
end;
lStr := lIniFile.ReadString('RGBA255',lIdent, '');
StrToRGBA(lStr,lValue);
end; //IniRGBA
function UnitToByteStr (lS: single): string;
begin
result := inttostr(round(255 * UnitBound(lS)));
end;
function UnitRectToStr (lU: TUnitRect) : string;
//floatrect values 0..1 convert to byte 0..1
begin
result := UnitToByteStr(lU.L)+ kStrSep+UnitToByteStr(lU.T)+ kStrSep+UnitToByteStr(lU.R)+ kStrSep+UnitToByteStr(lU.B);
end;
function StrToUnitRect (lS: string; var lU: TUnitRect): boolean;
var
lQ : TRGBA;
begin
result := false;
if not StrToRGBA(lS,lQ) then
exit;
lU.L := lQ.r / 255;
lU.T := lQ.g / 255;
lU.R := lQ.b / 255;
lU.B := lQ.a / 255;
result := true;
end;
procedure IniUnitRect(lRead: boolean; lIniFile: TIniFile; lIdent: string; var lValue: TUnitRect);
var
lS: string;
lU: TUnitRect;
begin
if not lRead then begin
lIniFile.WriteString('STR',lIdent,UnitRectToStr (lValue));
exit;
end;
lS := lIniFile.ReadString('STR',lIdent, '');
if StrToUnitRect (lS, lU) then
lValue := lU;
end; //IniUnitRect
function IniFile(lRead: boolean; lFilename: string; var lPrefs: TPrefs): boolean;
//Read or write initialization variables to disk
var
lIniFile: TIniFile;
begin
result := false;
DefaultFormatSettings.DecimalSeparator := '.'; //OBJ/GII/Etc write real numbers as 1.23 not 1,23
if (lRead) then
SetDefaultPrefs (lPrefs, true, not Fileexists(lFilename));
if (not lRead) and (lPrefs.SkipPrefWriting) then exit;
if not lRead then FileMode := fmOpenWrite;
if (lRead) and (not FileexistsF(lFilename)) then
exit;
lIniFile := TIniFile.Create(lFilename);
IniBool(lRead,lIniFile, 'MultiSample',lPrefs.MultiSample);
IniBool(lRead,lIniFile, 'OrientCube',lPrefs.OrientCube);
IniBool(lRead,lIniFile, 'Perspective',lPrefs.Perspective);
IniBool(lRead,lIniFile, 'AdditiveOverlay',lPrefs.AdditiveOverlay);
IniBool(lRead,lIniFile, 'StartupScript',lPrefs.StartupScript);
{$IFDEF LCLCocoa}
IniBool(lRead,lIniFile, 'RetinaDisplay',lPrefs.RetinaDisplay);
IniBool(lRead,lIniFile, 'DarkMode',lPrefs.DarkMode);
{$ENDIF}
IniBool(lRead,lIniFile, 'BlackDefaultBackground',lPrefs.BlackDefaultBackground);
//IniBool(lRead,lIniFile, 'MultiPassRendering',lPrefs.MultiPassRendering);
//IniBool(lRead,lIniFile, 'SaveAsObj',lPrefs.SaveAsObj);
IniBool(lRead,lIniFile, 'TracksAreTubes',lPrefs.TracksAreTubes);
IniBool(lRead,lIniFile, 'ZDimIsUp',lPrefs.ZDimIsUp);
IniBool(lRead,lIniFile,'GenerateSmoothCurves',lPrefs.GenerateSmoothCurves);
//IniBool(lRead,lIniFile, 'ShaderForBackgroundOnly',lPrefs.ShaderForBackgroundOnly);
IniBool(lRead,lIniFile, 'CoreTrackDisableDepth',lPrefs.CoreTrackDisableDepth);
IniBool(lRead,lIniFile, 'LoadTrackOnLaunch',lPrefs.LoadTrackOnLaunch);
IniBool(lRead,lIniFile, 'Colorbar',lPrefs.Colorbar);
IniBool(lRead,lIniFile, 'SmoothVoxelwiseData',lPrefs.SmoothVoxelwiseData);
IniBool(lRead,lIniFile, 'ScreenCaptureTransparentBackground',lPrefs.ScreenCaptureTransparentBackground);
IniColor(lRead,lIniFile, 'ObjColor',lPrefs.ObjColor);
IniColor(lRead,lIniFile, 'BackColor',lPrefs.BackColor);
IniStr(lRead, lIniFile, 'PrevTrackname', lPrefs.PrevTrackname);
IniStr(lRead, lIniFile, 'PrevNodename', lPrefs.PrevNodename);
IniStr(lRead, lIniFile, 'PrevOverlayname', lPrefs.PrevOverlayname);
IniStr(lRead,lIniFile,'PrevScript',lPrefs.PrevScript);
IniStrX(lRead,lIniFile,'FontName',lPrefs.FontName);
IniStrX(lRead,lIniFile,'PyLib',lPrefs.PyLib);
IniMRU(lRead,lIniFile,'PrevFilename',lPrefs.PrevFilename, lPrefs);
//IniMRU(lRead,lIniFile,'PrevScriptName',lPrefs.PrevScriptName);
IniRGBA(lRead,lIniFile, 'TextColor',lPrefs.TextColor);
IniRGBA(lRead,lIniFile, 'TextBorder',lPrefs.TextBorder);
IniRGBA(lRead,lIniFile, 'GridAndBorder',lPrefs.GridAndBorder);
//IniUnitRect(lRead,lIniFile, 'ColorBarPos',lPrefs.ColorBarPos);
IniInt(lRead,lIniFile,'TrackTubeSlices',lPrefs.TrackTubeSlices);
IntBound(lPrefs.TrackTubeSlices, 3,13);
IniInt(lRead,lIniFile,'ScreenCaptureZoom',lPrefs.ScreenCaptureZoom);
IntBound(lPrefs.ScreenCaptureZoom, 1,7);
IniInt(lRead,lIniFile,'ColorbarColor',lPrefs.ColorbarColor);
IntBound(lPrefs.ColorbarColor, 0,4);
IniInt(lRead,lIniFile,'ColorBarPosition',lPrefs.ColorBarPosition);
//IniInt(lRead,lIniFile,'ColorbarPosition',lPrefs.ColorbarPosition);
//IntBound(lPrefs.ColorbarPosition, 0,4);
IniInt(lRead,lIniFile,'RenderQuality',lPrefs.RenderQuality);
IniInt(lRead,lIniFile,'SaveAsFormat',lPrefs.SaveAsFormat);
IniInt(lRead,lIniFile,'SaveAsFormatTrack',lPrefs.SaveAsFormatTrack);
IniInt(lRead,lIniFile,'OcclusionAmount',lPrefs.OcclusionAmount);
IniFloat(lRead,lIniFile,'ColorbarSize',lPrefs.ColorbarSize);
if (lPrefs.RenderQuality < kRenderPoor) then lPrefs.RenderQuality:= kRenderPoor;
if (lPrefs.RenderQuality > kRenderBetter) then lPrefs.RenderQuality:= kRenderBetter;
lIniFile.Free;
FileMode := fmOpenRead;
end;
end.