Skip to content

Commit

Permalink
Shapebox tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 11, 2023
1 parent 99a9df4 commit fdfb97c
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 161 deletions.
15 changes: 8 additions & 7 deletions Source/codetools/simba.ide_codetools_insight.pas
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,12 @@ function TCodeinsight.ParseExpression(Expr: TExpressionItems; Flags: EParseExpre
for Decl in GetMembersOfType(Decl) do
if Decl.IsName(Expr.Text) then
begin
if (Decl is TDeclaration_Var) and (TDeclaration_Var(Decl).VarType <> nil) then
Result := EnsureTypeDeclaration(TDeclaration_Var(Decl).VarType)
else
if Expr.IsLastItem then
Result := Decl
else
if (Decl is TDeclaration_Var) and (TDeclaration_Var(Decl).VarType <> nil) then
Result := EnsureTypeDeclaration(TDeclaration_Var(Decl).VarType)
else
if (Decl is TDeclaration_Method) and Assigned(TDeclaration_Method(Decl).ResultType) then
Result := EnsureTypeDeclaration(TDeclaration_Method(Decl).ResultType);

Expand Down Expand Up @@ -498,10 +498,11 @@ function TCodeinsight.ParseExpression(Expr: TExpressionItems; Flags: EParseExpre
end;

Result := Decl;

if (EParseExpressionFlag.WantMethodResult in Flags) then
if (Result is TDeclaration_Method) and Assigned(TDeclaration_Method(Result).ResultType) then
Result := EnsureTypeDeclaration(TDeclaration_Method(Result).ResultType);
if (EParseExpressionFlag.WantVarType in Flags) and (Result is TDeclaration_Var) then
Result := EnsureTypeDeclaration(TDeclaration_Var(Result).VarType)
else
if (EParseExpressionFlag.WantMethodResult in Flags) and (Result is TDeclaration_Method) and (TDeclaration_Method(Result).ResultType <> nil) then
Result := EnsureTypeDeclaration(TDeclaration_Method(Result).ResultType);
end;

function TCodeinsight.ParseExpression(Expr: String; Flags: EParseExpressionFlags): TDeclaration;
Expand Down
2 changes: 1 addition & 1 deletion Source/editor/simba.editor_autocomplete.pas
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ procedure TSimbaAutoComplete.DoEditorCommand(Sender: TObject; AfterProcessing: B
end else
Filter := '';

FDecls := FCodeinsight.GetMembersOfType(FCodeinsight.ParseExpression(Expression, [EParseExpressionFlag.WantMethodResult]));
FDecls := FCodeinsight.GetMembersOfType(FCodeinsight.ParseExpression(Expression, [EParseExpressionFlag.WantMethodResult, EParseExpressionFlag.WantVarType]));
end else
begin
Filter := Expression;
Expand Down
97 changes: 25 additions & 72 deletions Source/imagebox/simba.imagebox_image.pas
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ TSimbaImageBoxBitmap = class(TObject)
procedure DrawPoly(Poly: TPointArray; Connect: Boolean; Color: TColor);
procedure DrawPoint(P: TPoint; Color: TColor);
procedure DrawPoints(TPA: TPointArray; Color: TColor);
procedure DrawEllipse(Center: TPoint; RadiusX, RadiusY: Integer; Color: TColor);
procedure DrawCircle(Center: TPoint; Radius: Integer; Color: TColor);
procedure DrawCircleFilled(Center: TPoint; Radius: Integer; Color: TColor);
procedure DrawHeatmap(const Mat: TSingleMatrix);
Expand Down Expand Up @@ -539,83 +538,46 @@ procedure TSimbaImageBoxBitmap.DrawPoints(TPA: TPointArray; Color: TColor);
end;
end;

procedure TSimbaImageBoxBitmap.DrawEllipse(Center: TPoint; RadiusX, RadiusY: Integer; Color: TColor);
procedure TSimbaImageBoxBitmap.DrawCircle(Center: TPoint; Radius: Integer; Color: TColor);

{$DEFINE MACRO_ELLIPSE :=
{$DEFINE MACRO_CIRCLE :=
var
RadXSq, RadYSq: Integer;
TwoSqX, TwoSqY: Integer;
X, Y, P, PX, PY: Integer;
X, Y, Err: Integer;
begin
RadXSq := RadiusX * RadiusX;
RadYSq := RadiusY * RadiusY;
TwoSqX := 2 * RadXSq;
TwoSqY := 2 * RadYSq;
X := 0;
Y := RadiusY;
PX := 0;
PY := TwoSqX * Y;
PixelProc(Center.Y+Y, Center.X+X, Color);
PixelProc(Center.Y+Y, Center.X-X, Color);
PixelProc(Center.Y-Y, Center.X+X, Color);
PixelProc(Center.Y-Y, Center.X-X, Color);
P := Round(RadYSQ - (RadXSQ * RadiusY) + (0.25 * RadXSQ));
while PX<PY do
begin
Inc(X);
Inc(PX, TwoSqY);
if (P < 0) then
Inc(P, RadYSq + PX)
else begin
Dec(Y);
Dec(PY, TwoSqX);
Inc(P, RadYSq + PX - PY);
end;
// Filled
//DrawLine(TPoint.Create(Center.Y+Y,Center.X+X), TPoint.Create(Center.Y+Y,Center.X-X), Color);
//DrawLine(TPoint.Create(Center.Y-Y,Center.X+X), TPoint.Create(Center.Y-Y,Center.X-X), Color);
X := -Radius;
Y := 0;
PixelProc(Center.Y+Y, Center.X+X, Color);
PixelProc(Center.Y+Y, Center.X-X, Color);
PixelProc(Center.Y-Y, Center.X+X, Color);
PixelProc(Center.Y-Y, Center.X-X, Color);
end;
Err := 2-2*Radius;
P := Round(RadYSQ * Sqr(X + 0.5) + RadXSQ * Sqr(Y - 1) - RadXSQ * RadYSQ);
while (Y>0) do
while (X < 0) do
begin
Dec(Y);
Dec(PY, TwoSqX);
if (P > 0) then
Inc(P, RadXSq - PY)
else begin
Inc(X);
Inc(PX, TwoSqY);
Inc(P, RadXSq - PY + PX);
end;
PixelProc(Center.X - X, Center.Y + Y, Color);
PixelProc(Center.X - Y, Center.Y - X, Color);
PixelProc(Center.X + X, Center.Y - Y, Color);
PixelProc(Center.X + Y, Center.Y + X, Color);
// Filled
//DrawLine(TPoint.Create(Center.Y+Y,Center.X+X), TPoint.Create(Center.Y+Y,Center.X-X), Color);
//DrawLine(TPoint.Create(Center.Y-Y,Center.X+X), TPoint.Create(Center.Y-Y,Center.X-X), Color);
Radius := Err;
if (Radius <= Y) then
begin
Y += 1;
Err += Y*2+1;
end;
PixelProc(Center.Y+Y,Center.X+X, Color);
PixelProc(Center.Y+Y,Center.X-X, Color);
PixelProc(Center.Y-Y,Center.X+X, Color);
PixelProc(Center.Y-Y,Center.X-X, Color);
if (Radius > X) or (Err > Y) then
begin
X += 1;
Err += X*2+1;
end;
end;
end;
}

{$DEFINE PixelProc := PixelBGR}
procedure DrawBGR(Color: TBGR); MACRO_ELLIPSE
procedure DrawBGR(Color: TBGR); MACRO_CIRCLE
{$DEFINE PixelProc := PixelBGRA}
procedure DrawBGRA(Color: TBGRA); MACRO_ELLIPSE
procedure DrawBGRA(Color: TBGRA); MACRO_CIRCLE
{$DEFINE PixelProc := PixelARGB}
procedure DrawARGB(Color: TARGB); MACRO_ELLIPSE
procedure DrawARGB(Color: TARGB); MACRO_CIRCLE

begin
case FPixelFormat of
Expand All @@ -625,15 +587,6 @@ procedure TSimbaImageBoxBitmap.DrawPoints(TPA: TPointArray; Color: TColor);
end;
end;

procedure TSimbaImageBoxBitmap.DrawCircle(Center: TPoint; Radius: Integer; Color: TColor);
begin
case FPixelFormat of
'BGR': DrawEllipse(Center, Radius, Radius, Color);
'BGRA': DrawEllipse(Center, Radius, Radius, Color);
'ARGB': DrawEllipse(Center, Radius, Radius, Color);
end;
end;

procedure TSimbaImageBoxBitmap.DrawCircleFilled(Center: TPoint; Radius: Integer; Color: TColor);

{$DEFINE MACRO_CIRCLE_FILLED :=
Expand Down
2 changes: 1 addition & 1 deletion Source/package/simba.package_autoupdater.pas
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ procedure TPackageUpdater.DoTerminateOnMainThread(Sender: TObject);
if (FUpdates.Count > 0) then
begin
SimbaMainToolBar.ButtonPackage.Hint := 'Open packages' + LineEnding + FUpdates.Text;
SimbaMainToolBar.ButtonPackage.ImageIndex := IMG_PACKAGE + Min(FUpdates.Count, 9);
SimbaMainToolBar.ButtonPackage.ImageIndex := IMG_PACKAGE + Min(1 + FUpdates.Count, 9);
end else
begin
SimbaMainToolBar.ButtonPackage.Hint := 'Open packages';
Expand Down
6 changes: 0 additions & 6 deletions Source/script/imports/simba.import_imagebox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ procedure _LapeSimbaImageBoxBitmap_DrawBoxTransparent(const Params: PParamArray)
PSimbaImageBoxBitmap(Params^[0])^.DrawBoxTransparent(PBox(Params^[1])^, PColor(Params^[2])^, PSingle(Params^[3])^);
end;

procedure _LapeSimbaImageBoxBitmap_DrawEllipse(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaImageBoxBitmap(Params^[0])^.DrawEllipse(PPoint(Params^[1])^, PInteger(Params^[2])^, PInteger(Params^[3])^, PColor(Params^[4])^);
end;

procedure _LapeSimbaImageBoxBitmap_DrawHeatmap(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaImageBoxBitmap(Params^[0])^.DrawHeatmap(PSingleMatrix(Params^[1])^);
Expand Down Expand Up @@ -291,7 +286,6 @@ procedure ImportSimbaImageBox(Compiler: TSimbaScript_Compiler);
addGlobalFunc('procedure TImageBoxImage.DrawCircle(Center: TPoint; Radius: Integer; Color: TColor);', @_LapeSimbaImageBoxBitmap_DrawCircle);
addGlobalFunc('procedure TImageBoxImage.DrawCircleFilled(Center: TPoint; Radius: Integer; Color: TColor);', @_LapeSimbaImageBoxBitmap_DrawCircleFilled);
addGlobalFunc('procedure TImageBoxImage.DrawBoxTransparent(Box: TBox; Color: TColor; Transparency: Single);', @_LapeSimbaImageBoxBitmap_DrawBoxTransparent);
addGlobalFunc('procedure TImageBoxImage.DrawEllipse(Center: TPoint; RadiusX, RadiusY: Integer; Color: TColor);', @_LapeSimbaImageBoxBitmap_DrawEllipse);
addGlobalFunc('procedure TImageBoxImage.DrawHeatmap(const Mat: TSingleMatrix);', @_LapeSimbaImageBoxBitmap_DrawHeatmap);

addGlobalType('procedure(Sender: TObject; Bitmap: TImageBoxImage; Rect: TLazRect) of object', 'TImageBoxPaintAreaEvent', FFI_DEFAULT_ABI);
Expand Down
81 changes: 56 additions & 25 deletions Source/script/imports/simba.import_shapebox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ implementation
PComponent = ^TComponent;
PPanel = ^TPanel;
PButton = ^TButton;
PNotifyEvent = ^TNotifyEvent;

procedure _LapeSimbaShapeBox_Create(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaImageBox(Result)^ := TSimbaShapeBox.Create(PComponent(Params^[0])^);
PSimbaImageBox(Result)^ := TSimbaShapeBox.Create(PComponent(Params^[0])^, PInteger(Params^[1])^);
end;

procedure _LapeSimbaShapeBox_SaveToFile(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
Expand Down Expand Up @@ -131,49 +132,74 @@ procedure _LapeSimbaShapeBox_GetShape(const Params: PParamArray; const Result: P
PShapeBoxShape(Result)^ := PSimbaShapeBox(Params^[0])^.Shape[PInteger(Params^[1])^];
end;

procedure _LapeSimbaShapeBox_GetShapeIndex(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
procedure _LapeSimbaShapeBox_GetCount(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PInteger(Result)^ := PSimbaShapeBox(Params^[0])^.ShapeIndex;
PInteger(Result)^ := PSimbaShapeBox(Params^[0])^.Count;
end;

procedure _LapeSimbaShapeBox_GetShapeCount(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
procedure _LapeSimbaShapeBox_QueryName_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PInteger(Result)^ := PSimbaShapeBox(Params^[0])^.ShapeCount;
PBoolean(Result)^ := PSimbaShapeBox(Params^[0])^.QueryName;
end;

procedure _LapeSimbaShapeBox_UserDataSize_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
procedure _LapeSimbaShapeBox_QueryName_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PInteger(Result)^ := PSimbaShapeBox(Params^[0])^.UserDataSize;
PSimbaShapeBox(Params^[0])^.QueryName := PBoolean(Params^[1])^;
end;

procedure _LapeSimbaShapeBox_UserDataSize_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
procedure _LapeSimbaShapeBox_CopyShape(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaShapeBox(Params^[0])^.UserDataSize := PInteger(Params^[1])^;
PInteger(Result)^ := PSimbaShapeBox(Params^[0])^.CopyShape(PInteger(Params^[1])^);
end;

procedure _LapeSimbaShapeBox_QueryNameOnNew_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
procedure _LapeSimbaShapeBox_DeleteShape(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := PSimbaShapeBox(Params^[0])^.QueryNameOnNew;
PSimbaShapeBox(Params^[0])^.DeleteShape(PInteger(Params^[1])^);
end;

procedure _LapeSimbaShapeBox_QueryNameOnNew_WRite(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
procedure _LapeSimbaShapeBox_DeleteAllShapes(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaShapeBox(Params^[0])^.QueryNameOnNew := PBoolean(Params^[1])^;
PSimbaShapeBox(Params^[0])^.DeleteAllShapes();
end;

procedure _LapeSimbaShapeBox_CopyShape(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
procedure _LapeSimbaShapeBox_BeginUpdate(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PInteger(Result)^ := PSimbaShapeBox(Params^[0])^.CopyShape(PInteger(Params^[1])^);
PSimbaShapeBox(Params^[0])^.BeginUpdate();
end;

procedure _LapeSimbaShapeBox_DeleteShape(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
procedure _LapeSimbaShapeBox_EndUpdate(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaShapeBox(Params^[0])^.DeleteShape(PInteger(Params^[1])^);
PSimbaShapeBox(Params^[0])^.EndUpdate();
end;

procedure _LapeSimbaShapeBox_DeleteAllShapes(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
procedure _LapeSimbaShapeBox_OnSelectionChange_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaShapeBox(Params^[0])^.DeleteAllShapes();
PNotifyEvent(Result)^ := PSimbaShapeBox(Params^[0])^.OnSelectionChange;
end;

procedure _LapeSimbaShapeBox_OnSelectionChange_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaShapeBox(Params^[0])^.OnSelectionChange := PNotifyEvent(Params^[1])^;
end;

procedure _LapeSimbaShapeBox_HasSelection(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := PSimbaShapeBox(Params^[0])^.HasSelection;
end;

procedure _LapeSimbaShapeBox_GetSelectedShape(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PShapeBoxShape(Result)^ := PSimbaShapeBox(Params^[0])^.SelectedShape;
end;

procedure _LapeSimbaShapeBox_SelectedIndex_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PInteger(Result)^ := PSimbaShapeBox(Params^[0])^.SelectedIndex;
end;

procedure _LapeSimbaShapeBox_SelectedIndex_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaShapeBox(Params^[0])^.SelectedIndex := PInteger(Params^[1])^;
end;

procedure ImportSimbaShapeBox(Compiler: TSimbaScript_Compiler);
Expand All @@ -200,19 +226,24 @@ procedure ImportSimbaShapeBox(Compiler: TSimbaScript_Compiler);
'end;'
], 'TShapeBoxShape');

addClassConstructor('TShapeBox', '(Owner: TLazComponent)', @_LapeSimbaShapeBox_Create);
addClassConstructor('TShapeBox', '(Owner: TLazComponent; UserDataSize: Integer = 0)', @_LapeSimbaShapeBox_Create);

addGlobalFunc('function TShapeBox.GetShape(Index: Integer): TShapeBoxShape', @_LapeSimbaShapeBox_GetShape);
addGlobalFunc('function TShapeBox.ShapeCount: Integer', @_LapeSimbaShapeBox_GetShapeCount);
addGlobalFunc('function TShapeBox.ShapeIndex: Integer', @_LapeSimbaShapeBox_GetShapeIndex);
addClassVar('TShapeBox', 'OnSelectionChange', 'TLazNotifyEvent', @_LapeSimbaShapeBox_OnSelectionChange_Read, @_LapeSimbaShapeBox_OnSelectionChange_Write);
addClassVar('TShapeBox', 'QueryName', 'Boolean', @_LapeSimbaShapeBox_QueryName_Read, @_LapeSimbaShapeBox_QueryName_Write);
addClassVar('TShapeBox', 'SelectedIndex', 'Integer', @_LapeSimbaShapeBox_SelectedIndex_Read, @_LapeSimbaShapeBox_SelectedIndex_Write);

addClassVar('TShapeBox', 'UserDataSize', 'Integer', @_LapeSimbaShapeBox_UserDataSize_Read, @_LapeSimbaShapeBox_UserDataSize_Write);
addClassVar('TShapeBox', 'QueryNameOnNew', 'Boolean', @_LapeSimbaShapeBox_QueryNameOnNew_Read, @_LapeSimbaShapeBox_QueryNameOnNew_Write);
addGlobalFunc('function TShapeBox.HasSelection: Boolean', @_LapeSimbaShapeBox_HasSelection);
addGlobalFunc('function TShapeBox.GetSelectedShape: TShapeBoxShape', @_LapeSimbaShapeBox_GetSelectedShape);
addGlobalFunc('function TShapeBox.GetShape(Index: Integer): TShapeBoxShape', @_LapeSimbaShapeBox_GetShape);
addGlobalFunc('function TShapeBox.GetCount: Integer', @_LapeSimbaShapeBox_GetCount);

addGlobalFunc('function TShapeBox.CopyShape(Index: Integer): Integer;', @_LapeSimbaShapeBox_CopyShape);
addGlobalFunc('procedure TShapeBox.DeleteShape(Index: Integer);', @_LapeSimbaShapeBox_DeleteShape);
addGlobalFunc('procedure TShapeBox.DeleteAllShapes;', @_LapeSimbaShapeBox_DeleteAllShapes);

addGlobalFunc('procedure TShapeBox.BeginUpdate;', @_LapeSimbaShapeBox_BeginUpdate);
addGlobalFunc('procedure TShapeBox.EndUpdate;', @_LapeSimbaShapeBox_EndUpdate);

addGlobalFunc('procedure TShapeBox.SaveToFile(FileName: String);', @_LapeSimbaShapeBox_SaveToFile);
addGlobalFunc('procedure TShapeBox.LoadFromFile(FileName: String);', @_LapeSimbaShapeBox_LoadFromFile);

Expand Down
3 changes: 3 additions & 0 deletions Source/simba.ide_showdeclaration.pas
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ procedure ShowDeclaration(Declaration: TDeclaration);
begin
if (Declaration is TDeclaration_Method) then
SimbaDebugLn([EDebugLn.FOCUS], ['Declared internally in Simba: ' + Declaration.Lexer.FileName, TDeclaration_Method(Declaration).HeaderString])
else
if (Declaration is TDeclaration_Var) then
SimbaDebugLn([EDebugLn.FOCUS], ['Declared internally in Simba: ' + Declaration.Lexer.FileName, TDeclaration_Var(Declaration).Name + TDeclaration_Var(Declaration).VarTypeString + TDeclaration_Var(Declaration).VarDefaultString])
else
SimbaDebugLn([EDebugLn.FOCUS], ['Declared internally in Simba: ' + Declaration.Lexer.FileName, Declaration.Text])
end;
Expand Down
Loading

0 comments on commit fdfb97c

Please sign in to comment.