mirror of
https://github.com/moparisthebest/Simba
synced 2024-12-22 07:18:51 -05:00
Added some stuff.. :)
This commit is contained in:
parent
ca34d1011c
commit
487e5e5144
@ -586,8 +586,8 @@ begin
|
||||
OwnerSheet := TTabSheet(TheOwner);
|
||||
OwnerPage := TPageControl(OwnerSheet.Owner);
|
||||
|
||||
if FileExists(MainDir + DS + 'default.simba') then
|
||||
SynEdit.Lines.LoadFromFile(MainDir + DS + 'default.simba');
|
||||
if FileExistsUTF8(SimbaForm.DefScriptPath) then
|
||||
SynEdit.Lines.LoadFromFile(SimbaForm.DefScriptPath);
|
||||
StartText:= SynEdit.Lines.text;
|
||||
ScriptDefault:= StartText;
|
||||
ScriptName:= 'Untitled';
|
||||
|
@ -355,6 +355,7 @@ type
|
||||
procedure HandleOpenFileData;
|
||||
procedure HandleWriteFileData;
|
||||
procedure HandleScriptStartData;
|
||||
function GetDefScriptPath: string;
|
||||
function GetScriptPath : string;
|
||||
function GetExtPath: string;
|
||||
function GetFontPath: String;
|
||||
@ -365,6 +366,7 @@ type
|
||||
function GetShowParamHintAuto: boolean;
|
||||
function GetShowCodeCompletionAuto: Boolean;
|
||||
function GetSimbaNews: String;
|
||||
procedure SetDefScriptPath(const AValue: string);
|
||||
procedure SetExtPath(const AValue: string);
|
||||
procedure SetFontPath(const AValue: String);
|
||||
procedure SetIncludePath(const AValue: String);
|
||||
@ -434,6 +436,7 @@ type
|
||||
property PluginPath : string read GetPluginPath write SetPluginPath;
|
||||
property ExtPath : string read GetExtPath write SetExtPath;
|
||||
property ScriptDir : string read GetScriptPath write SetScriptPath;
|
||||
property DefScriptPath : string read GetDefScriptPath write SetDefScriptPath;
|
||||
property CurrHighlighter : TSynCustomHighlighter read GetHighlighter;
|
||||
end;
|
||||
|
||||
@ -594,6 +597,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSimbaForm.GetDefScriptPath: string;
|
||||
begin
|
||||
result :=LoadSettingDef('Settings/SourceEditor/DefScriptPath', ExpandFileName(MainDir+DS+'default.simba'));
|
||||
end;
|
||||
|
||||
function TSimbaForm.GetScriptPath: string;
|
||||
begin
|
||||
result :=IncludeTrailingPathDelimiter(LoadSettingDef('Settings/Scripts/Path', ExpandFileName(MainDir+DS+'Scripts' + DS)));
|
||||
@ -1956,7 +1964,7 @@ end;
|
||||
|
||||
procedure TSimbaForm.MenuItemHandbookClick(Sender: TObject);
|
||||
begin
|
||||
OpenURL('http://wizzup.org/static/Simba/doc/ps_handbook/');
|
||||
OpenURL('http://wizzup.org/static/simba/doc/ps_handbook/');
|
||||
end;
|
||||
|
||||
procedure TSimbaForm.MenuItemColourHistoryClick(Sender: TObject);
|
||||
@ -2031,6 +2039,7 @@ begin
|
||||
exit;
|
||||
end;
|
||||
FunctionListTimer.Enabled:= false;
|
||||
CloseAction := caFree;
|
||||
FreeAndNil(ExtManager);
|
||||
end;
|
||||
|
||||
@ -2182,7 +2191,7 @@ begin
|
||||
for i := 0 to high(RecentFileItems) do
|
||||
RecentFileItems[i].Free;
|
||||
if ExtManager <> nil then
|
||||
ExtManager.free;
|
||||
FreeAndNil(extmanager);
|
||||
Tabs.free;
|
||||
Selector.Free;
|
||||
Picker.Free;
|
||||
@ -2445,6 +2454,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSimbaForm.SetDefScriptPath(const AValue: string);
|
||||
begin
|
||||
SetSetting('Settings/SourceEditor/DefScriptPath',AValue,True);
|
||||
end;
|
||||
|
||||
procedure TSimbaForm.SetExtPath(const AValue: string);
|
||||
begin
|
||||
SetSetting('Settings/Extensions/Path',AValue,true);
|
||||
@ -2989,7 +3003,7 @@ begin
|
||||
with CurrScript do
|
||||
begin
|
||||
try
|
||||
SynEdit.Lines.SaveToFile(MainDir + DS + 'default.simba');
|
||||
SynEdit.Lines.SaveToFile(DefScriptPath);
|
||||
mDebugLn('Script saved as default.');
|
||||
Result := True;
|
||||
except
|
||||
|
@ -70,8 +70,7 @@ end;
|
||||
|
||||
function ps_DTMFromString(const DTMString: String): Integer; extdecl;
|
||||
begin
|
||||
With CurrThread.Client.MDTMs do
|
||||
Result := AddDTM(StringToDTM(DTMString));
|
||||
Result := CurrThread.Client.MDTMs.StringToDTM(DTMString);
|
||||
end;
|
||||
|
||||
procedure ps_FreeDTM(DTM: Integer); extdecl;
|
||||
@ -108,3 +107,8 @@ function ps_SDTMToMDTM(Const DTM: TSDTM): TMDTM;extdecl;
|
||||
begin
|
||||
result := SDTMToMDTM(DTM);
|
||||
end;
|
||||
|
||||
function ps_CreateDTMPoint(x,y,c,t,asz : integer; bp : boolean) : TMDTMPoint;
|
||||
begin
|
||||
result := CreateDTMPoint(x,y,c,t,asz,bp);
|
||||
end;
|
||||
|
@ -91,6 +91,10 @@ begin
|
||||
RegisterProperty('Name','String',iptrw);
|
||||
RegisterMethod('function ToString : string');
|
||||
RegisterMethod('function Valid:boolean');
|
||||
RegisterMethod('procedure DeletePoint( Point : integer);');
|
||||
RegisterMethod('procedure SwapPoint(p1,p2 : integer);');
|
||||
RegisterMethod('procedure MovePoint(fromIndex,toIndex : integer);');
|
||||
RegisterMethod('procedure AddPoint( Point : TMDTMPoint);');
|
||||
RegisterProperty('Count','Integer',iptrw);
|
||||
RegisterProperty('Points','TMDTMPointArray',iptr);
|
||||
end;
|
||||
|
@ -44,6 +44,7 @@ AddFunction(@ps_PrintDTM, 'procedure PrintDTM(const DTM : TMDTM);');
|
||||
AddFunction(@ps_GetDTM ,'function GetDTM(index: Integer) : TMDTM');
|
||||
AddFunction(@ps_MDTMToSDTM, 'function MDTMToSDTM(Const DTM: TMDTM): TSDTM;');
|
||||
AddFunction(@ps_SDTMToMDTM, 'function SDTMToMDTM(Const DTM: TSDTM): TMDTM;');
|
||||
AddFunction(@ps_CreateDTMPoint,'function CreateDTMPoint(x,y,c,t,asz : integer; bp : boolean) : TMDTMPoint;');
|
||||
|
||||
{maths}
|
||||
SetCurrSection('Math');
|
||||
|
@ -139,7 +139,11 @@ begin;
|
||||
RegisterMethod(@TMDTM.Free,'Free');
|
||||
RegisterMethod(@TMDTM.ToString,'ToString');
|
||||
RegisterMethod(@TMDTM.Valid,'Valid');
|
||||
RegisterMethod(@TMDTM.DeletePoint,'DeletePoint');
|
||||
RegisterMethod(@TMDTM.SwapPoint,'SwapPoint');
|
||||
Registermethod(@TMDTM.MovePoint,'MovePoint');
|
||||
RegisterMethod(@TMDTM.AddPoint,'AddPoint');
|
||||
RegisterPropertyHelper(@TMDTMCount_R,@TMDTMCount_W,'Count');
|
||||
RegisterPropertyHelper(@TMDTMPoints_R,nil,'Points');
|
||||
RegisterMethod(@TMDTMPoints_R,nil,'Points');
|
||||
end;
|
||||
end;
|
||||
|
@ -92,7 +92,7 @@ begin
|
||||
exit;
|
||||
if compress(BufferString,destlen,PChar(Str),length(str)) = Z_OK then
|
||||
begin
|
||||
setlength(result,Destlen + 4);
|
||||
setlength(result,Destlen + SizeOf(Integer));
|
||||
PInteger(@result[1])^ := Length(str);
|
||||
Move(bufferstring[0],result[5],Destlen);
|
||||
end;
|
||||
|
@ -47,6 +47,10 @@ type
|
||||
Index : integer;
|
||||
function ToString : string;
|
||||
function Valid : boolean;
|
||||
procedure DeletePoint( Point : integer);
|
||||
procedure SwapPoint(p1,p2 : integer);
|
||||
procedure MovePoint(fromIndex,toIndex : integer);
|
||||
procedure AddPoint( Point : TMDTMPoint);
|
||||
property PPoints : PMDTMPoint read GetPointerPoints;
|
||||
property Count : integer read FLen write SetPointCount;
|
||||
property Points : TMDTMPointArray read FPoints;
|
||||
@ -62,7 +66,7 @@ type
|
||||
function AddDTM(const d: TMDTM): Integer;overload;
|
||||
function GetDTM(index: Integer) :TMDTM;
|
||||
procedure FreeDTM(DTM: Integer);
|
||||
function StringToDTM(const S: String): TMDTM;
|
||||
function StringToDTM(const S: String): Integer;
|
||||
property DTM[Index : integer]: TMDTM read GetDTM; default;
|
||||
constructor Create(Owner: TObject);
|
||||
destructor Destroy; override;
|
||||
@ -72,6 +76,7 @@ implementation
|
||||
uses
|
||||
dtmutil, paszlib,
|
||||
client,
|
||||
DCPbase64,
|
||||
graphics, // for TColor
|
||||
math // for max
|
||||
;
|
||||
@ -139,41 +144,92 @@ begin
|
||||
Result:=StrToInt('$' + HexNum);
|
||||
end;
|
||||
|
||||
function TMDTMS.StringToDTM(const S: String): TMDTM;
|
||||
function TMDTMS.StringToDTM(const S: String): Integer;
|
||||
var
|
||||
b: PBufferByteArray;
|
||||
MDTM : TMDTM;
|
||||
Source : String;
|
||||
DestLen : longword;
|
||||
i,ii,c : integer;
|
||||
DPoints : PMDTMPoint;
|
||||
Ptr : Pointer;
|
||||
function ReadInteger : integer;
|
||||
begin
|
||||
Result := TMDTM.Create;
|
||||
Result := PInteger(ptr)^;
|
||||
inc(ptr,sizeof(integer));
|
||||
end;
|
||||
function ReadBoolean : boolean;
|
||||
begin
|
||||
result := PBoolean(ptr)^;
|
||||
inc(ptr,sizeof(boolean));
|
||||
end;
|
||||
|
||||
begin
|
||||
MDTM := TMDTM.Create;
|
||||
Result := AddDTM(MDTM);
|
||||
ii := Length(S);
|
||||
if (ii = 0) or (ii mod 2 <> 0) then
|
||||
Exit;
|
||||
ii := ii div 2;
|
||||
SetLength(Source,ii);
|
||||
for i := 1 to ii do
|
||||
Source[i] := Chr(HexToInt(S[i * 2 - 1] + S[i * 2]));
|
||||
DestLen := BufferLen;
|
||||
if uncompress(Bufferstring,Destlen,pchar(Source), ii) = Z_OK then
|
||||
begin;
|
||||
if (Destlen mod 36) > 0 then
|
||||
raise Exception.CreateFmt('Invalid DTM passed to StringToDTM: %s',[s]);
|
||||
DestLen := DestLen div 36;
|
||||
Result.Count:= DestLen;
|
||||
DPoints := result.PPoints;
|
||||
b := PBufferByteArray(BufferString);
|
||||
for i := 0 to DestLen - 1 do
|
||||
if (ii = 0) then
|
||||
exit;
|
||||
if S[1] = 'm' then
|
||||
begin
|
||||
if ii < 9 then
|
||||
raise Exception.CreateFMT('Invalid DTM-String passed to StringToDTM: %s',[s]);
|
||||
Writeln(copy(s,2,ii-1));
|
||||
Source := Base64DecodeStr(copy(s,2,ii-1));
|
||||
i:= PLongint(@source[1])^; //The 4 four bytes should contain the dest len!
|
||||
if i < 1 then
|
||||
raise Exception.CreateFMT('Invalid DTM-String passed to StringToDTM: %s',[s]);
|
||||
DestLen := BufferLen;
|
||||
ptr := @Source[1 + sizeof(longint)];
|
||||
if uncompress(BufferString,DestLen,ptr,length(source)-sizeof(integer)) = Z_OK then
|
||||
begin
|
||||
ptr := BufferString;
|
||||
MDTM.Count:= ReadInteger;
|
||||
ii := MDTM.Count;
|
||||
if (MDTM.Count * TMDTMPointSize) <> (Destlen - SizeOf(integer)) then
|
||||
raise Exception.CreateFMT('Invalid DTM-String passed to StringToDTM: %s',[s]);
|
||||
DPoints := MDTM.PPoints;
|
||||
for i := 0 to ii-1 do
|
||||
DPoints[i].x := ReadInteger;
|
||||
for i := 0 to ii-1 do
|
||||
DPoints[i].y := ReadInteger;
|
||||
for i := 0 to ii-1 do
|
||||
DPoints[i].c := ReadInteger;
|
||||
for i := 0 to ii-1 do
|
||||
DPoints[i].t := ReadInteger;
|
||||
for i := 0 to ii-1 do
|
||||
DPoints[i].asz := ReadInteger;
|
||||
for i := 0 to ii-1 do
|
||||
DPoints[i].bp := ReadBoolean;
|
||||
end;
|
||||
end else
|
||||
begin
|
||||
if (ii mod 2 <> 0) then
|
||||
exit;
|
||||
ii := ii div 2;
|
||||
SetLength(Source,ii);
|
||||
for i := 1 to ii do
|
||||
Source[i] := Chr(HexToInt(S[i * 2 - 1] + S[i * 2]));
|
||||
DestLen := BufferLen;
|
||||
if uncompress(Bufferstring,Destlen,pchar(Source), ii) = Z_OK then
|
||||
begin;
|
||||
c := i * 36;
|
||||
DPoints[i].x := PInteger(@b^[c+1])^;
|
||||
DPoints[i].y := PInteger(@b^[c+5])^;
|
||||
DPoints[i].asz := PInteger(@b^[c+12])^;
|
||||
// Result.ash[i] := PInteger(@b^[c+16])^;
|
||||
DPoints[i].c := PInteger(@b^[c+20])^;
|
||||
DPoints[i].t := PInteger(@b^[c+24])^;
|
||||
DPoints[i].bp := False;
|
||||
if (Destlen mod 36) > 0 then
|
||||
raise Exception.CreateFMT('Invalid DTM-String passed to StringToDTM: %s',[s]);
|
||||
DestLen := DestLen div 36;
|
||||
MDTM.Count:= DestLen;
|
||||
DPoints := MDTM.PPoints;
|
||||
b := PBufferByteArray(BufferString);
|
||||
for i := 0 to DestLen - 1 do
|
||||
begin;
|
||||
c := i * 36;
|
||||
DPoints[i].x := PInteger(@b^[c+1])^;
|
||||
DPoints[i].y := PInteger(@b^[c+5])^;
|
||||
DPoints[i].asz := PInteger(@b^[c+12])^;
|
||||
// DPoints.ash[i] := PInteger(@b^[c+16])^;
|
||||
DPoints[i].c := PInteger(@b^[c+20])^;
|
||||
DPoints[i].t := PInteger(@b^[c+24])^;
|
||||
DPoints[i].bp := False;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -254,9 +310,59 @@ begin
|
||||
FLen := AValue;
|
||||
end;
|
||||
|
||||
function TMDTM.ToString: string;
|
||||
begin
|
||||
//We save the data as arrays for each point (so we can add features to DTMs without having to change
|
||||
//the way the ToString is done..
|
||||
//E.G. A DTM with 3 points would become
|
||||
//LenXXXYYYCCCTTTASZASZASZBPBPBP
|
||||
|
||||
function TMDTM.ToString: string;
|
||||
var
|
||||
i,len : integer;
|
||||
Ptr,Start : Pointer;
|
||||
Destlen : Longword;
|
||||
procedure WriteInteger(int : integer);
|
||||
begin
|
||||
PLongInt(Ptr)^ := int;
|
||||
Inc(ptr,sizeof(int));
|
||||
end;
|
||||
procedure WriteBool(bool : boolean);
|
||||
begin;
|
||||
PBoolean(Ptr)^ := bool;
|
||||
inc(ptr,sizeof(boolean));
|
||||
end;
|
||||
|
||||
begin
|
||||
result := '';
|
||||
if Count < 1 then
|
||||
exit;
|
||||
len := Count * TMDTMPointSize + SizeOf(Integer);
|
||||
Start:= GetMem(len);
|
||||
Ptr := Start;
|
||||
WriteInteger(FLen);
|
||||
for i := 0 to FLen-1 do
|
||||
WriteInteger(FPoints[i].x);
|
||||
for i := 0 to FLen-1 do
|
||||
WriteInteger(FPoints[i].y);
|
||||
for i := 0 to FLen-1 do
|
||||
WriteInteger(FPoints[i].c);
|
||||
for i := 0 to FLen-1 do
|
||||
WriteInteger(FPoints[i].t);
|
||||
for i := 0 to FLen-1 do
|
||||
WriteInteger(FPoints[i].asz);
|
||||
for i := 0 to FLen-1 do
|
||||
WriteBool(FPoints[i].bp);
|
||||
Destlen :=BufferLen;
|
||||
if compress(BufferString,destlen,pchar(start),len) = Z_OK then
|
||||
begin
|
||||
setlength(result,Destlen + SizeOf(Integer));
|
||||
PInteger(@result[1])^ := len;
|
||||
Writeln(len);
|
||||
Move(bufferstring[0],result[1 + sizeof(integer)],Destlen);
|
||||
//We now have Size + Compressed data.. Lets Base64Encrypt it!
|
||||
Result := 'm' + Base64EncodeStr(result);
|
||||
//It now looks like m + base64encoded data! The 'm' is to indicate we used this encryption method.
|
||||
end;
|
||||
Freemem(start,len);
|
||||
end;
|
||||
|
||||
function TMDTM.Valid: boolean;
|
||||
@ -264,8 +370,43 @@ begin
|
||||
result := false;
|
||||
if Count < 1 then
|
||||
exit;
|
||||
NormalizeDTM(self);
|
||||
result := true;
|
||||
end;
|
||||
|
||||
procedure TMDTM.DeletePoint(Point: integer);
|
||||
begin
|
||||
MovePoint(Point,FLen-1);
|
||||
Count := Count - 1;
|
||||
end;
|
||||
|
||||
procedure TMDTM.SwapPoint(p1, p2: integer);
|
||||
var
|
||||
Temp : TMDTMPoint;
|
||||
begin
|
||||
Temp := FPoints[p1];
|
||||
FPoints[p1] := FPoints[p2];
|
||||
FPoints[p2] := Temp;
|
||||
end;
|
||||
|
||||
procedure TMDTM.MovePoint(fromIndex, toIndex: integer);
|
||||
var
|
||||
i : integer;
|
||||
begin
|
||||
if fromIndex > toIndex then //We are going down
|
||||
begin
|
||||
for i := fromindex downto Toindex+1 do
|
||||
SwapPoint(i,i-1);
|
||||
end else if fromIndex < toIndex then
|
||||
for i := fromindex to toindex - 1 do
|
||||
SwapPoint(i,i+1);
|
||||
end;
|
||||
|
||||
procedure TMDTM.AddPoint(Point: TMDTMPoint);
|
||||
begin
|
||||
Count:= Count + 1;
|
||||
FPoints[FLen-1] := Point;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -34,6 +34,7 @@ uses
|
||||
function MDTMToSDTM(Const DTM: TMDTM): TSDTM;
|
||||
function SDTMToMDTM(Const DTM: TSDTM): TMDTM;
|
||||
procedure PrintDTM(const aDTM : TMDTM);
|
||||
function CreateDTMPoint(x,y,c,t,asz : integer; bp : boolean) : TMDTMPoint;
|
||||
|
||||
{procedure iniTSDTM(out d: TMDTM; len: integer);}
|
||||
function ValidMainPointBox(var dtm: TMDTM; const x1, y1, x2, y2: Integer): TBox;
|
||||
@ -54,24 +55,16 @@ const
|
||||
implementation
|
||||
uses math,MufasaBase;
|
||||
|
||||
procedure RotatePoints_(Var P: TPointArray; A, cx, cy: Extended);
|
||||
Var
|
||||
I, L: Integer;
|
||||
CosA,SinA : extended;
|
||||
|
||||
Begin
|
||||
L := High(P);
|
||||
CosA := Cos(a);
|
||||
SinA := Sin(a);
|
||||
For I := 0 To L Do
|
||||
Begin
|
||||
P[I].X := Trunc(cx + CosA * (p[i].x - cx) - SinA * (p[i].y - cy));
|
||||
P[I].Y := Trunc(cy + SinA * (p[i].x - cx) + CosA * (p[i].y - cy));
|
||||
End;
|
||||
// I recon it's faster than Point().
|
||||
End;
|
||||
|
||||
|
||||
function CreateDTMPoint(x,y,c,t,asz : integer; bp : boolean) : TMDTMPoint;
|
||||
begin
|
||||
result.x := x;
|
||||
result.y := y;
|
||||
result.c := c;
|
||||
result.t := t;
|
||||
result.asz := asz;
|
||||
result.bp := bp;
|
||||
end;
|
||||
|
||||
procedure PrintDTM(const aDTM : TMDTM);
|
||||
var
|
||||
|
@ -117,6 +117,9 @@ type
|
||||
Asz: Area size;
|
||||
bp: Bad Point;
|
||||
}
|
||||
const
|
||||
TMDTMPointSize = 5*SizeOf(integer)+Sizeof(boolean);
|
||||
type
|
||||
TMDTMPoint = record //TMufasaDTMPoint
|
||||
x,y,c,t,asz : integer;
|
||||
bp : boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user