Permalink
Browse files

Breaking change: Width, Height and Rect now use Single, not Integers

This may cause some compatibility break in user applications. But it seems unavoidable. Float-based coordinates turned out to be a good idea. But having many methods/properies as dual - integer version, and float version with Float prefix/suffix, looks messy. Especially since we want to encourage using float-based properties for everything.

- Width, Height, Left, Bottom, and many others are now Single, not Integer/Cardinal

- Rect returns now TFloatRectangle

- CalculatedXxx are still integer, but deprecated, and you should use float EffectiveXxx

- ScreenRect is still TRectangle, but deprecated, and you should use RenderRect

- Removed many XxxFloatXxx methods (not present in engine stable version, so we can remove them)

- Where possible, various methods now take both TRectangle / TFloatRectangle, or TVector2Integer / TVector2
  • Loading branch information...
michaliskambi committed Sep 16, 2018
1 parent 956e82a commit 8e757e15aae388b2b02b04f957af2099bde8d1f3
Showing with 760 additions and 785 deletions.
  1. +4 −4 examples/2d_standard_ui/edit_test/game.pas
  2. +2 −2 examples/2d_standard_ui/zombie_fighter/gamestateaskdialog.pas
  3. +5 −5 examples/3d_rendering_processing/multiple_viewports.lpr
  4. +1 −1 examples/fixed_camera_game/code/gamestateplay.pas
  5. +6 −6 examples/fonts/html_text.lpr
  6. +10 −10 examples/fonts/test_local_characters/game.pas
  7. +10 −10 examples/fps_game/game.pas
  8. +1 −1 examples/mobile/test_bump_mapping/game.pas
  9. +1 −1 examples/physics/physics_3d_demo/game.pas
  10. +17 −17 examples/play_animation/gameinitialize.pas
  11. +9 −8 examples/resource_animations/resource_animations.lpr
  12. +1 −1 examples/window/multi_window.lpr
  13. +20 −4 src/3d/castlecameras.pas
  14. +9 −9 src/3d/castlerays.pas
  15. +21 −0 src/base/castlerectangles.pas
  16. +8 −0 src/base/castlevectors_integer.inc
  17. +32 −0 src/fonts/opengl/castlefonts.pas
  18. +3 −3 src/game/castle2dscenemanager.pas
  19. +13 −12 src/game/castlescenemanager.pas
  20. +87 −10 src/images/opengl/castleglutils_draw_primitive_2d.inc
  21. +164 −281 src/ui/castleuicontrols.pas
  22. +29 −55 src/ui/opengl/castlecontrols_button.inc
  23. +3 −3 src/ui/opengl/castlecontrols_crosshair.inc
  24. +9 −9 src/ui/opengl/castlecontrols_edit.inc
  25. +8 −8 src/ui/opengl/castlecontrols_groups.inc
  26. +25 −51 src/ui/opengl/castlecontrols_imagecontrol.inc
  27. +17 −43 src/ui/opengl/castlecontrols_label.inc
  28. +7 −6 src/ui/opengl/castlecontrols_panel.inc
  29. +5 −5 src/ui/opengl/castlecontrols_progressbar.inc
  30. +2 −2 src/ui/opengl/castlecontrols_rectanglecontrol.inc
  31. +16 −15 src/ui/opengl/castlecontrols_scrollview.inc
  32. +6 −6 src/ui/opengl/castlecontrols_shape.inc
  33. +6 −0 src/ui/opengl/castlecontrols_simplebackground.inc
  34. +43 −43 src/ui/opengl/castlecontrols_sliders.inc
  35. +7 −7 src/ui/opengl/castlecontrols_switchcontrol.inc
  36. +12 −11 src/ui/opengl/castlecontrols_tableview.inc
  37. +11 −11 src/ui/opengl/castlecontrols_touchcontrol.inc
  38. +2 −2 src/ui/opengl/castlecontrols_userinterfacefont.inc
  39. +25 −25 src/ui/opengl/castledialogstates_dialog.inc
  40. +3 −3 src/ui/opengl/castleflasheffect.pas
  41. +2 −2 src/ui/opengl/castleglcontainer.pas
  42. +9 −9 src/ui/opengl/castleinspectorcontrol.pas
  43. +7 −7 src/ui/opengl/castlenotifications.pas
  44. +25 −25 src/ui/opengl/castleonscreenmenu.pas
  45. +3 −3 src/ui/opengl/castleuistate.pas
  46. +6 −6 src/x3d/opengl/castlescreeneffects.pas
  47. +16 −19 tests/testcastleuicontrols.pas
  48. +10 −4 tools/castle-editor/TODO.md
  49. +20 −16 tools/castle-editor/code/framedesign.pas
  50. +2 −4 tools/castle-editor/data/project_templates/empty/files/data/main.castle-user-interface
@@ -76,8 +76,8 @@ procedure ApplicationInitialize;
Group.InsertFront(ButtonCopyText);
Spacer := TCastleUserInterfaceRect.Create(Application);
Spacer.FloatWidth := 1;
Spacer.FloatHeight := 20;
Spacer.Width := 1;
Spacer.Height := 20;
Group.InsertFront(Spacer);
Label2 := TCastleLabel.Create(Application);
@@ -92,8 +92,8 @@ procedure ApplicationInitialize;
Group.InsertFront(Edit2);
Spacer := TCastleUserInterfaceRect.Create(Application);
Spacer.FloatWidth := 1;
Spacer.FloatHeight := 20;
Spacer.Width := 1;
Spacer.Height := 20;
Group.InsertFront(Spacer);
Label3 := TCastleLabel.Create(Application);
@@ -63,8 +63,8 @@ constructor TStateAskDialog.TZombieDialog.Create(AOwner: TComponent; const Male:
Color := HexToColor('5f3939'); // equivalent: Vector4(95/255, 57/255, 57/255, 1.0);
InsideRect := TCastleRectangleControl.Create(Self);
InsideRect.Width := CalculatedWidth - 10;
InsideRect.Height := CalculatedHeight - 10;
InsideRect.Width := EffectiveWidth - 10;
InsideRect.Height := EffectiveHeight - 10;
InsideRect.Color := Silver;
InsideRect.Anchor(hpMiddle);
InsideRect.Anchor(vpMiddle);
@@ -131,7 +131,7 @@ TFocusedFrame = class(TCastleUserInterfaceRect)
procedure TFocusedFrame.Render;
begin
if Focused then
Theme.Draw(ScreenRect, tiActiveFrame);
Theme.Draw(RenderRect, tiActiveFrame);
end;
procedure TFocusedFrame.SetFocused(const Value: boolean);
@@ -158,11 +158,11 @@ procedure TFocusedFrame.SetFocused(const Value: boolean);
procedure Resize(Container: TUIContainer);
var
W, H, TopMargin: Integer;
W, H, TopMargin: Single;
begin
TopMargin := OpenButton.CalculatedHeight + 2 * Margin;
W := Window.Width div 2;
H := (Window.Height - TopMargin) div 2;
TopMargin := OpenButton.EffectiveHeight + 2 * Margin;
W := Window.Width / 2;
H := (Window.Height - TopMargin) / 2;
Viewports[0].Left := Margin;
Viewports[0].Bottom := Margin;
@@ -55,7 +55,7 @@ implementation
procedure TStatePlay.Resize;
begin
inherited;
CurrentLocation.Scene.SceneManagerRect := SceneManager.ScreenRect;
CurrentLocation.Scene.SceneManagerRect := SceneManager.RenderRect.Round;
end;
procedure TStatePlay.Start;
@@ -84,9 +84,9 @@ procedure WindowResize(Container: TUIContainer);
Label1.MaxWidth := Container.UnscaledWidth - Margin * 2 - ScrollView.ScrollBarWidth;
ScrollView.Width := Container.UnscaledWidth;
ScrollView.Height := Container.UnscaledHeight - 2 * Margin - ButtonHtml.CalculatedHeight;
ScrollView.ScrollArea.Width := Label1.CalculatedWidth;
ScrollView.ScrollArea.Height := Label1.CalculatedHeight;
ScrollView.Height := Container.UnscaledHeight - 2 * Margin - ButtonHtml.EffectiveHeight;
ScrollView.ScrollArea.Width := Label1.EffectiveWidth;
ScrollView.ScrollArea.Height := Label1.EffectiveHeight;
end;
var
@@ -122,7 +122,7 @@ procedure WindowResize(Container: TUIContainer);
ButtonWrap := TCastleButton.Create(Window);
ButtonWrap.Caption := 'Wrap';
ButtonWrap.Toggle := true;
ButtonWrap.Left := 2 * Margin + ButtonHtml.CalculatedWidth;
ButtonWrap.Left := 2 * Margin + ButtonHtml.EffectiveWidth;
ButtonWrap.Bottom := Margin;
ButtonWrap.OnClick := @TButtonHandler(nil).ClickWrap;
ButtonWrap.Pressed := true;
@@ -139,15 +139,15 @@ procedure WindowResize(Container: TUIContainer);
ButtonAlignMiddle := TCastleButton.Create(Window);
ButtonAlignMiddle.Caption := 'Middle';
ButtonAlignMiddle.Toggle := true;
ButtonAlignMiddle.Anchor(hpRight, -2 * Margin - ButtonAlignRight.CalculatedWidth);
ButtonAlignMiddle.Anchor(hpRight, -2 * Margin - ButtonAlignRight.EffectiveWidth);
ButtonAlignMiddle.Bottom := Margin;
ButtonAlignMiddle.OnClick := @TButtonHandler(nil).ClickAlignMiddle;
Window.Controls.InsertFront(ButtonAlignMiddle);
ButtonAlignLeft := TCastleButton.Create(Window);
ButtonAlignLeft.Caption := 'Left';
ButtonAlignLeft.Toggle := true;
ButtonAlignLeft.Anchor(hpRight, -3 * Margin - ButtonAlignRight.CalculatedWidth - ButtonAlignMiddle.CalculatedWidth);
ButtonAlignLeft.Anchor(hpRight, -3 * Margin - ButtonAlignRight.EffectiveWidth - ButtonAlignMiddle.EffectiveWidth);
ButtonAlignLeft.Bottom := Margin;
ButtonAlignLeft.OnClick := @TButtonHandler(nil).ClickAlignLeft;
ButtonAlignLeft.Pressed := true;
@@ -155,7 +155,7 @@ procedure ApplicationInitialize;
Scene: TCastleScene;
TestLabel: TCastleLabel;
Config: TCastleConfig;
Y: Integer;
Y: Single;
ButtonExternalFont, ButtonExternalFontChinese: TCastleButton;
ButtonEmbeddedFont, ButtonEmbeddedFontChinese: TCastleButton;
Doc: TXMLDocument;
@@ -195,31 +195,31 @@ procedure ApplicationInitialize;
ButtonExternalFont.Left := 10;
ButtonExternalFont.Bottom := Y;
Window.Controls.InsertFront(ButtonExternalFont);
Y += ButtonExternalFont.CalculatedHeight + 10;
Y := Y + (ButtonExternalFont.EffectiveHeight + 10);
ButtonExternalFontChinese := TCastleButton.Create(Application);
ButtonExternalFontChinese.Caption := 'Switch to external font (only Chinese chars)';
ButtonExternalFontChinese.OnClick := @FontContainer.ButtonExternalFontChineseClick;
ButtonExternalFontChinese.Left := 10;
ButtonExternalFontChinese.Bottom := Y;
Window.Controls.InsertFront(ButtonExternalFontChinese);
Y += ButtonExternalFontChinese.CalculatedHeight + 10;
Y := Y + (ButtonExternalFontChinese.EffectiveHeight + 10);
ButtonEmbeddedFont := TCastleButton.Create(Application);
ButtonEmbeddedFont.Caption := 'Switch to embedded font (without Chinese chars)';
ButtonEmbeddedFont.OnClick := @FontContainer.ButtonEmbeddedFontClick;
ButtonEmbeddedFont.Left := 10;
ButtonEmbeddedFont.Bottom := Y;
Window.Controls.InsertFront(ButtonEmbeddedFont);
Y += ButtonEmbeddedFont.CalculatedHeight + 10;
Y := Y + (ButtonEmbeddedFont.EffectiveHeight + 10);
ButtonEmbeddedFontChinese := TCastleButton.Create(Application);
ButtonEmbeddedFontChinese.Caption := 'Switch to embedded font (only Chinese chars)';
ButtonEmbeddedFontChinese.OnClick := @FontContainer.ButtonEmbeddedFontChineseClick;
ButtonEmbeddedFontChinese.Left := 10;
ButtonEmbeddedFontChinese.Bottom := Y;
Window.Controls.InsertFront(ButtonEmbeddedFontChinese);
Y += ButtonEmbeddedFontChinese.CalculatedHeight + 10;
Y := Y + (ButtonEmbeddedFontChinese.EffectiveHeight + 10);
TestLabel := TCastleLabel.Create(Application);
TestLabel.Caption := 'String hardcoded in Pascal sources:' + NL +
@@ -230,7 +230,7 @@ procedure ApplicationInitialize;
TestLabel.Bottom := Y;
TestLabel.Left := 100;
Window.Controls.InsertFront(TestLabel);
Y += TestLabel.CalculatedHeight + 10;
Y := Y + (TestLabel.EffectiveHeight + 10);
Config := TCastleConfig.Create(application);
try
@@ -242,7 +242,7 @@ procedure ApplicationInitialize;
TestLabel.Left := 100;
TestLabel.Color := Green;
Window.Controls.InsertFront(TestLabel);
Y += TestLabel.CalculatedHeight + 10;
Y := Y + (TestLabel.EffectiveHeight + 10);
finally FreeAndNil(Config) end;
Doc := URLReadXML(ApplicationData('example_strings.xml'));
@@ -257,7 +257,7 @@ procedure ApplicationInitialize;
TestLabel.Left := 100;
TestLabel.Color := Yellow;
Window.Controls.InsertFront(TestLabel);
Y += TestLabel.CalculatedHeight + 10;
Y := Y + (TestLabel.EffectiveHeight + 10);
finally FreeAndNil(Doc) end;
TextReader := TTextReader.Create(ApplicationData('example_text.txt'));
@@ -272,7 +272,7 @@ procedure ApplicationInitialize;
TestLabel.Left := 100;
TestLabel.Color := LightBlue;
Window.Controls.InsertFront(TestLabel);
Y += TestLabel.CalculatedHeight + 10;
Y := Y + (TestLabel.EffectiveHeight + 10);
finally FreeAndNil(TextReader) end;
StringList := TStringList.Create;
@@ -291,7 +291,7 @@ procedure ApplicationInitialize;
TestLabel.Left := 100;
TestLabel.Color := Olive;
Window.Controls.InsertFront(TestLabel);
Y += TestLabel.CalculatedHeight + 10;
Y := Y + (TestLabel.EffectiveHeight + 10);
finally FreeAndNil(StringList) end;
end;
@@ -70,7 +70,7 @@ TButtons = class(TComponent)
constructor TButtons.Create(AOwner: TComponent);
var
NextButtonBottom: Integer;
NextButtonBottom: Single;
begin
inherited;
@@ -88,7 +88,7 @@ constructor TButtons.Create(AOwner: TComponent);
ToggleMouseLookButton.Left := ControlsMargin;
ToggleMouseLookButton.Bottom := NextButtonBottom;
Window.Controls.InsertFront(ToggleMouseLookButton);
NextButtonBottom := NextButtonBottom + (ToggleMouseLookButton.CalculatedHeight + ControlsMargin);
NextButtonBottom := NextButtonBottom + (ToggleMouseLookButton.EffectiveHeight + ControlsMargin);
{ Do not show this on touch device, as Application.Terminate
(or Window.Close, or anything similar) doesn't make sense on mobile devices.
@@ -101,7 +101,7 @@ constructor TButtons.Create(AOwner: TComponent);
ExitButton.Left := ControlsMargin;
ExitButton.Bottom := NextButtonBottom;
Window.Controls.InsertFront(ExitButton);
NextButtonBottom := NextButtonBottom + (ExitButton.CalculatedHeight + ControlsMargin);
NextButtonBottom := NextButtonBottom + (ExitButton.EffectiveHeight + ControlsMargin);
end;
RenderDebugCreaturesButton := TCastleButton.Create(Application);
@@ -111,7 +111,7 @@ constructor TButtons.Create(AOwner: TComponent);
RenderDebugCreaturesButton.Left := ControlsMargin;
RenderDebugCreaturesButton.Bottom := NextButtonBottom;
Window.Controls.InsertFront(RenderDebugCreaturesButton);
NextButtonBottom := NextButtonBottom + (RenderDebugCreaturesButton.CalculatedHeight + ControlsMargin);
NextButtonBottom := NextButtonBottom + (RenderDebugCreaturesButton.EffectiveHeight + ControlsMargin);
RenderDebugItemsButton := TCastleButton.Create(Application);
RenderDebugItemsButton.Caption := 'Items Debug Visualization';
@@ -120,39 +120,39 @@ constructor TButtons.Create(AOwner: TComponent);
RenderDebugItemsButton.Left := ControlsMargin;
RenderDebugItemsButton.Bottom := NextButtonBottom;
Window.Controls.InsertFront(RenderDebugItemsButton);
NextButtonBottom := NextButtonBottom + (RenderDebugItemsButton.CalculatedHeight + ControlsMargin);
NextButtonBottom := NextButtonBottom + (RenderDebugItemsButton.EffectiveHeight + ControlsMargin);
ScrenshotButton := TCastleButton.Create(Application);
ScrenshotButton.Caption := 'Screenshot (F5)';
ScrenshotButton.OnClick := @ScreenshotButtonClick;
ScrenshotButton.Left := ControlsMargin;
ScrenshotButton.Bottom := NextButtonBottom;
Window.Controls.InsertFront(ScrenshotButton);
NextButtonBottom := NextButtonBottom + (ScrenshotButton.CalculatedHeight + ControlsMargin);
NextButtonBottom := NextButtonBottom + (ScrenshotButton.EffectiveHeight + ControlsMargin);
AddCreatureButton := TCastleButton.Create(Application);
AddCreatureButton.Caption := 'Add creature (F9)';
AddCreatureButton.OnClick := @AddCreatureButtonClick;
AddCreatureButton.Left := ControlsMargin;
AddCreatureButton.Bottom := NextButtonBottom;
Window.Controls.InsertFront(AddCreatureButton);
NextButtonBottom := NextButtonBottom + (AddCreatureButton.CalculatedHeight + ControlsMargin);
NextButtonBottom := NextButtonBottom + (AddCreatureButton.EffectiveHeight + ControlsMargin);
AddItemButton := TCastleButton.Create(Application);
AddItemButton.Caption := 'Add item (F10)';
AddItemButton.OnClick := @AddItemButtonClick;
AddItemButton.Left := ControlsMargin;
AddItemButton.Bottom := NextButtonBottom;
Window.Controls.InsertFront(AddItemButton);
NextButtonBottom := NextButtonBottom + (AddItemButton.CalculatedHeight + ControlsMargin);
NextButtonBottom := NextButtonBottom + (AddItemButton.EffectiveHeight + ControlsMargin);
AttackButton := TCastleButton.Create(Application);
AttackButton.Caption := 'Attack (Ctrl)';
AttackButton.OnClick := @AttackButtonClick;
AttackButton.Left := ControlsMargin;
AttackButton.Bottom := NextButtonBottom;
Window.Controls.InsertFront(AttackButton);
NextButtonBottom := NextButtonBottom + (AttackButton.CalculatedHeight + ControlsMargin);
NextButtonBottom := NextButtonBottom + (AttackButton.EffectiveHeight + ControlsMargin);
end;
procedure TButtons.ToggleMouseLookButtonClick(Sender: TObject);
@@ -250,7 +250,7 @@ procedure TButtons.AttackButtonClick(Sender: TObject);
{ Player HUD ---------------------------------------------------------------- }
type
TPlayerHUD = class(TCastleUserInterface)
TPlayerHUD = class(TCastleUserInterfaceRect)
public
procedure Render; override;
end;
@@ -28,7 +28,7 @@ implementation
uses SysUtils, Math,
CastleWindow, CastleScene, CastleControls, CastleLog,
CastleFilesUtils, CastleSceneCore, CastleKeysMouse, CastleColors,
CastleVectors, CastleTransform, X3DNodes, CastleTimeUtils
CastleVectors, CastleTransform, X3DNodes, CastleTimeUtils,
CastleApplicationProperties;
var
@@ -139,7 +139,7 @@ procedure ApplicationInitialize;
ButtonLevelComplex.Caption := 'Complex Level (Mesh Collider)';
ButtonLevelComplex.OnClick := @TEventHandler(nil).LoadLevelComplex;
ButtonLevelComplex.Anchor(hpLeft, 10);
ButtonLevelComplex.Anchor(vpTop, -10 - ButtonLevelSimple.CalculatedHeight - 10);
ButtonLevelComplex.Anchor(vpTop, -10 - ButtonLevelSimple.EffectiveHeight - 10);
Window.Controls.InsertFront(ButtonLevelComplex);
end;
Oops, something went wrong.

0 comments on commit 8e757e1

Please sign in to comment.