Skip to content

Commit

Permalink
Upgrade to latest CGE changes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaliskambi committed Sep 2, 2024
1 parent 73c3b96 commit dcbfa91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
30 changes: 16 additions & 14 deletions castle_model_viewer.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ type
class procedure ClickButtonScreenshot(Sender: TObject);
class procedure ClickButtonAnimations(Sender: TObject);
class procedure OnWarningHandle(const Category, S: string);
class procedure Press(const Sender: TCastleUserInterface;
const Event: TInputPressRelease; var Handled: boolean);
end;

{ Custom viewport class ------------------------------------------------ }
Expand All @@ -203,6 +205,7 @@ type
procedure RenderFromView3D(const Params: TRenderParams); override;
public
constructor Create(AOwner: TComponent); override;
procedure Resize; override;
procedure BeforeRender; override;
procedure Render; override;
function BaseLightsForRaytracer: TLightInstancesList;
Expand Down Expand Up @@ -243,6 +246,13 @@ begin
Cursor := mcDefault;
end;

procedure TV3DViewport.Resize;
begin
inherited;
// Call ResizeViewports to change size of all viewports, when container size changed
ResizeViewports(V3DSceneWindow.Window, MainViewport);
end;

{ Helper functions ----------------------------------------------------------- }

{ Show a multi-line message, allow to copy it to clipboard etc. }
Expand Down Expand Up @@ -768,7 +778,8 @@ begin
SetViewpointForWholeScene(0, 1, true , true);
end;

procedure Press(Container: TCastleContainer; const Event: TInputPressRelease);
class procedure THelper.Press(const Sender: TCastleUserInterface;
const Event: TInputPressRelease; var Handled: boolean);
begin
{ Although some of these shortcuts are also assigned to menu items,
catching them here is more reliable -- allows to handle also Ctrl+number
Expand Down Expand Up @@ -3702,11 +3713,6 @@ begin
Window.Controls.InsertFront(NavigationUi);
end;

procedure Resize(Container: TCastleContainer);
begin
ResizeViewports(V3DSceneWindow.Window, MainViewport);
end;

class procedure THelper.ClickButtonOpen(Sender: TObject);
var
Url: String;
Expand Down Expand Up @@ -4075,14 +4081,10 @@ begin
Window.MainMenu := CreateMainMenu;
Window.MainMenuVisible := not Param_HideMenu;
Window.OnMenuClick := @MenuClick;
// castle-model-viewer uses deprecated OnXxx events.
// We should migrate to TCastleView -- but for now there's no significant
// reason to migrate, we can upgrade castle-model-viewer when necessary when
// CGE will remove it.
{$warnings off}
Window.OnResize := @Resize;
Window.OnPress := @Press;
{$warnings on}
{ TODO: Use TCastleView to handle these events,
and inside that TCastleView should be a viewport.
Currently we abuse MainViewport for it. }
MainViewport.OnPress := {$ifdef FPC}@{$endif} THelper(nil).Press;
Window.OnDropFiles := @DropFiles;
Window.AutoRedisplay := false;

Expand Down
2 changes: 1 addition & 1 deletion code/v3dsceneraytrace.pas
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ procedure RaytraceToWin(
CallData.Image := Window.SaveScreen;

{ switch to our mode }
SavedMode := TGLMode.CreateReset(Window, nil, nil, @NoClose);
SavedMode := TGLMode.CreateReset(Window);

StatusText := TRayTracerStatus.Create(Window);
Window.Controls.InsertFront(StatusText);
Expand Down

0 comments on commit dcbfa91

Please sign in to comment.