Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Jul 25, 2019
1 parent e2f9203 commit fc89907
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 49 deletions.
2 changes: 1 addition & 1 deletion define_types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface
{$endif}

const
kVers = 'v1.0.20190707';
kVers = 'v1.0.20190720';
NaN : double = 1/0;
kTab = chr(9);
kCR = chr (13);
Expand Down
95 changes: 51 additions & 44 deletions surfice.lps
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ProjectSession>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units Count="46">
<Units Count="47">
<Unit0>
<Filename Value="surfice.lpr"/>
<IsPartOfProject Value="True"/>
Expand All @@ -18,8 +18,8 @@
<ComponentName Value="GLForm1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<TopLine Value="6130"/>
<CursorPos X="59" Y="6148"/>
<TopLine Value="843"/>
<CursorPos X="37" Y="862"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
Expand Down Expand Up @@ -123,7 +123,6 @@
</Unit13>
<Unit14>
<Filename Value="mesh.pas"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="2"/>
<CursorPos X="3" Y="6"/>
<UsageCount Value="108"/>
Expand Down Expand Up @@ -155,9 +154,9 @@
</Unit17>
<Unit18>
<Filename Value="define_types.pas"/>
<EditorIndex Value="4"/>
<TopLine Value="28"/>
<CursorPos X="28" Y="47"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="5"/>
<CursorPos X="25" Y="10"/>
<UsageCount Value="110"/>
<Loaded Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
Expand Down Expand Up @@ -328,7 +327,7 @@
</Unit39>
<Unit40>
<Filename Value="meshify_simplify.pas"/>
<EditorIndex Value="3"/>
<EditorIndex Value="4"/>
<TopLine Value="226"/>
<CursorPos X="34" Y="250"/>
<UsageCount Value="30"/>
Expand Down Expand Up @@ -375,127 +374,135 @@
<CursorPos X="3" Y="115"/>
<UsageCount Value="6"/>
</Unit45>
<Unit46>
<Filename Value="uscale.pas"/>
<EditorIndex Value="3"/>
<TopLine Value="10"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit46>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="mesh.pas"/>
<Caret Line="5205" Column="16" TopLine="5174"/>
<Caret Line="5337" Column="19" TopLine="5306"/>
</Position1>
<Position2>
<Filename Value="mesh.pas"/>
<Caret Line="5266" Column="19" TopLine="5235"/>
<Caret Line="5949" Column="16" TopLine="5918"/>
</Position2>
<Position3>
<Filename Value="mesh.pas"/>
<Caret Line="5337" Column="19" TopLine="5306"/>
<Caret Line="6006" Column="16" TopLine="5990"/>
</Position3>
<Position4>
<Filename Value="mesh.pas"/>
<Caret Line="5949" Column="16" TopLine="5918"/>
<Caret Line="6092" Column="16" TopLine="5997"/>
</Position4>
<Position5>
<Filename Value="mesh.pas"/>
<Caret Line="6006" Column="16" TopLine="5990"/>
<Caret Line="6240" Column="17" TopLine="6209"/>
</Position5>
<Position6>
<Filename Value="mesh.pas"/>
<Caret Line="6092" Column="16" TopLine="5997"/>
<Caret Line="6326" Column="7" TopLine="6295"/>
</Position6>
<Position7>
<Filename Value="mesh.pas"/>
<Caret Line="6240" Column="17" TopLine="6209"/>
<Caret Line="6812" Column="9" TopLine="6788"/>
</Position7>
<Position8>
<Filename Value="mesh.pas"/>
<Caret Line="6326" Column="7" TopLine="6295"/>
<Caret Line="6908" Column="9" TopLine="6876"/>
</Position8>
<Position9>
<Filename Value="mesh.pas"/>
<Caret Line="6812" Column="9" TopLine="6788"/>
<Caret Line="6326" Column="45" TopLine="6308"/>
</Position9>
<Position10>
<Filename Value="mesh.pas"/>
<Caret Line="6908" Column="9" TopLine="6876"/>
<Caret Line="6"/>
</Position10>
<Position11>
<Filename Value="mesh.pas"/>
<Caret Line="6326" Column="45" TopLine="6308"/>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="233" Column="4" TopLine="216"/>
</Position11>
<Position12>
<Filename Value="mesh.pas"/>
<Caret Line="6"/>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="234" Column="8" TopLine="216"/>
</Position12>
<Position13>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="233" Column="4" TopLine="216"/>
<Caret Line="304" Column="29" TopLine="277"/>
</Position13>
<Position14>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="234" Column="8" TopLine="216"/>
<Caret Line="187" Column="35" TopLine="168"/>
</Position14>
<Position15>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="304" Column="29" TopLine="277"/>
<Caret Line="212" Column="37" TopLine="180"/>
</Position15>
<Position16>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="187" Column="35" TopLine="168"/>
<Caret Line="290" Column="7" TopLine="277"/>
</Position16>
<Position17>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="212" Column="37" TopLine="180"/>
<Caret Line="230" Column="12" TopLine="220"/>
</Position17>
<Position18>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="290" Column="7" TopLine="277"/>
<Caret Line="235" Column="19" TopLine="219"/>
</Position18>
<Position19>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="230" Column="12" TopLine="220"/>
<Caret Line="233" Column="52" TopLine="224"/>
</Position19>
<Position20>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="235" Column="19" TopLine="219"/>
<Caret Line="253" Column="18" TopLine="224"/>
</Position20>
<Position21>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="233" Column="52" TopLine="224"/>
<Caret Line="281" Column="17" TopLine="271"/>
</Position21>
<Position22>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="253" Column="18" TopLine="224"/>
<Caret Line="289" Column="38" TopLine="271"/>
</Position22>
<Position23>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="281" Column="17" TopLine="271"/>
<Caret Line="290" Column="8" TopLine="271"/>
</Position23>
<Position24>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="289" Column="38" TopLine="271"/>
<Filename Value="mesh.pas"/>
<Caret Line="6" Column="3"/>
</Position24>
<Position25>
<Filename Value="meshify_simplify.pas"/>
<Caret Line="290" Column="8" TopLine="271"/>
<Filename Value="mesh.pas"/>
<Caret Line="118" Column="21" TopLine="88"/>
</Position25>
<Position26>
<Filename Value="mesh.pas"/>
<Caret Line="6" Column="3"/>
<Caret Line="140" Column="22" TopLine="110"/>
</Position26>
<Position27>
<Filename Value="mesh.pas"/>
<Caret Line="118" Column="21" TopLine="88"/>
<Caret Line="2492" Column="23" TopLine="2460"/>
</Position27>
<Position28>
<Filename Value="mesh.pas"/>
<Caret Line="140" Column="22" TopLine="110"/>
<Caret Line="2559" Column="16" TopLine="2528"/>
</Position28>
<Position29>
<Filename Value="mesh.pas"/>
<Caret Line="2492" Column="23" TopLine="2460"/>
<Filename Value="mainunit.pas"/>
<Caret Line="6132" Column="27" TopLine="6130"/>
</Position29>
<Position30>
<Filename Value="mesh.pas"/>
<Caret Line="2559" Column="16" TopLine="2528"/>
<Filename Value="mainunit.pas"/>
<Caret Line="862" Column="37" TopLine="843"/>
</Position30>
</JumpHistory>
<RunParams>
Expand Down
102 changes: 98 additions & 4 deletions uscale.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
interface

uses
{$IFDEF LCLGtk2} Gtk2Def, gtk2, Gtk2Proc, {$ENDIF}
{$IFDEF LCLGtk2} FileUtil, Process, Gtk2Def, gtk2, Gtk2Proc, strutils,{$ENDIF}
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,
StdCtrls, Buttons, Menus;

procedure ConstrainTrackBars;

implementation

procedure ConstrainTrackBar(Control: TControl);
procedure ConstrainTrackBar(Control: TControl; scale: single);
var
i: integer;
WinControl: TWinControl;
Expand All @@ -36,6 +36,7 @@ procedure ConstrainTrackBar(Control: TControl);
gtk_widget_size_request(Widget,@Widget^.requisition);
(Control as TTrackBar).Constraints.MaxHeight := Widget^.requisition.height;
(Control as TTrackBar).Height := (Control as TTrackBar).Constraints.MaxHeight;
(Control as TTrackBar).Width := round((Control as TTrackBar).Width * scale);
end;
{$ENDIF}
end;
Expand All @@ -44,15 +45,108 @@ procedure ConstrainTrackBar(Control: TControl);
if WinControl.ControlCount = 0 then
exit;
for i := 0 to WinControl.ControlCount - 1 do
ConstrainTrackBar(WinControl.Controls[i]);
ConstrainTrackBar(WinControl.Controls[i], scale);
end;

{$IFDEF LCLGtk2}
function str2XPix(str: string): integer;
// '1920x1080+0+0' -> 1920 1280x778+0+0
var
s: string;
begin
result := 0;
if length(str) < 1 then exit;
if not (str[1] in ['0'..'9']) then exit;
if not AnsiContainsText(str, 'x') then exit;
if not AnsiContainsText(str, '+') then exit;
s := copy(str, 1, PosEx('x',str)-1);
result := strtointdef(s,0);
end;

function getDPIXRANDR(): single;
var
AProcess: TProcess;
Exe, mmStr: String;
dpi, mm: single;
i, k, xPix: integer;
AStringList, BStringList: TStringList;
begin
result := 144.0;
Exe := FindDefaultExecutablePath('xrandr');
if length(Exe) < 1 then begin
Exe := '/opt/X11/bin/xrandr';
//Exe := '/Users/rorden/vx.sh';
if not fileexists(Exe) then
Exe := '';
end;
writeln('xrandr : '+Exe);
if length(Exe) < 1 then exit;
if not FileExists(Exe) then exit;
//result := 1;
AProcess := TProcess.Create(nil);
AProcess.Executable:=Exe;
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
AProcess.Execute;
if (AProcess.ExitCode = 0) then begin
AStringList := TStringList.Create;
BStringList := TStringList.Create;
AStringList.LoadFromStream(AProcess.Output);
if AStringList.Count > 0 then begin //"uint32 2"
for i := 0 to (AStringList.Count-1) do begin
if not AnsiContainsText(AStringList.Strings[i], 'connected') then continue;
writeln(AStringList.Strings[i]);
BStringList.DelimitedText := AStringList.Strings[i];
if (BStringList.Count < 5) then continue;
k := 0;
xPix := -1;
while (k < (BStringList.Count-1)) and (xPix < 1) do begin
xPix := str2XPix(BStringList.Strings[k]);
k := k + 1;
end;
if xPix < 1 then continue;
mmStr := BStringList.Strings[BStringList.Count-3];
if length(mmStr) < 3 then continue; //"9mm"
if mmStr[length(mmStr)] <> 'm' then continue;
if mmStr[length(mmStr)-1] = 'c' then
mm := 10.0 //cm
else if mmStr[length(mmStr)-1] = 'm' then
mm := 1.0 //mm
else
continue;
delete(mmStr,length(mmStr)-1,2);
mm := strtointdef(mmStr,0)*mm;
if mm <= 0 then continue;
dpi := xPix/( mm/25.4);
writeln(format(' Xpix %d Xmm %g dpi %g',[xPix, mm, dpi]));
//Form1.Memo1.lines.Add( inttostr(xPix)+':'+floattostr(mm)+' dpi '+floattostr(dpi));
if dpi > 0 then
result := dpi;
//result := 96/dpi;
//if (result < 1) then result := 1;
break;
end; //for i: each line of output
end; //if output
AStringList.Free;
BStringList.Free;
end;
AProcess.Free;
end;
{$ENDIF}


procedure ConstrainTrackBars;
var
i: integer;
scale: single;
begin
scale := 1.0;
{$IFDEF LCLGtk2}
scale := getDPIXRANDR() / 144;
if (scale < 1) then scale := 1;
writeln('Scale factor: ', scale);
{$ENDIF}
for i := 0 to Screen.FormCount - 1 do
ConstrainTrackBar(Screen.Forms[i]);
ConstrainTrackBar(Screen.Forms[i], scale);
end;

end.
Expand Down

0 comments on commit fc89907

Please sign in to comment.