Skip to content

Commit

Permalink
rename anchor to pivot
Browse files Browse the repository at this point in the history
This is because anchor might be used for another meaning in the future
(anchoring a control to top-left of a parent control, for example).
  • Loading branch information
tzachshabtay committed Dec 16, 2017
1 parent a8ee2a7 commit 2386411
Show file tree
Hide file tree
Showing 64 changed files with 200 additions and 201 deletions.
4 changes: 2 additions & 2 deletions Docs/articles/animations.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ as an overall speed for the entire animation.

## Animation per-frame configuration

An animation frame is actually using a `ISprite` object, which wraps around an image and gives it a lot of the capabilities that objects have. So you can have a position, scale, rotation, anchor, tint and even a custom renderer for each frame individually (those properties will be relative to the object, so if you have a frame with a position of (10, 5) it means that the frame will be offset from the rest of the object/animations by 10 pixels to the right and 5 pixels to the bottom).
An animation frame is actually using a `ISprite` object, which wraps around an image and gives it a lot of the capabilities that objects have. So you can have a position, scale, rotation, pivot, tint and even a custom renderer for each frame individually (those properties will be relative to the object, so if you have a frame with a position of (10, 5) it means that the frame will be offset from the rest of the object/animations by 10 pixels to the right and 5 pixels to the bottom).

Also, for each image, you can configure how to render the texture:

Expand Down Expand Up @@ -99,7 +99,7 @@ Directional animations allow grouping animations for different directions togeth

Another form of animation is tweening (short for [inbetweening](https://en.wikipedia.org/wiki/Inbetweening)), which lets you interpolate values over time, which can be very useful for animating movements.

Built-in tweens exist for animating position/scale/rotation/anchor/color for objects/sprites/viewports, and also for animating volume/pitch for sounds:
Built-in tweens exist for animating position/scale/rotation/pivot/color for objects/sprites/viewports, and also for animating volume/pitch for sounds:

```csharp
//Will move hero's x position to 100 in 5 seconds (linearly), without waiting for it to complete.
Expand Down
10 changes: 5 additions & 5 deletions Docs/articles/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ so if you move the panel around all the buttons will move with it, if you hide t

You can scale all objects to make them bigger or smaller. You can either scale by a factor (i.e scale by 2 to have double the size- note that this refers to scaling the original
size by 2, not the current size), or scale to a specific size (i.e I want my object to have a size of (200,500) pixels.
There are also convenience methods for flipping the object vertically and/or horizontally (this will shift the scale and also change the anchor accordingly).
There are also convenience methods for flipping the object vertically and/or horizontally (this will shift the scale and also change the pivot accordingly).

Note that if the object is in a scaling area, then the scaling area takes over scaling, which you can disable by setting `IgnoreScalingArea` to true.

### Rotation

You can set (and get) an angle (in degrees) for every object you desire.

### Anchor
### Pivot

Anchor is the pivot point for the scale, rotation and position.
The anchor's units are normalized to the object's size, so (0,0) is the bottom left and (1,1) is the top right.
So if, for example your anchor is (0.5,0.5) and you rotate the object, the object will pivot on its center (so it would mainly stay in the same place), and all (x,y) positions for the object would refer to its center.
This is the pivot point for the scale, rotation and position.
The pivot's units are normalized to the object's size, so (0,0) is the bottom left and (1,1) is the top right.
So if, for example your pivot is (0.5,0.5) and you rotate the object, the object will pivot on its center (so it would mainly stay in the same place), and all (x,y) positions for the object would refer to its center.

### Position (Translate)

Expand Down
6 changes: 3 additions & 3 deletions Source/AGS.API/Graphics/Animations/IAnimationComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public interface IAnimationComponent : IComponent
IAnimation Animation { get; }

/// <summary>
/// Gets or sets a value indicating whether the anchor (the pivot point for position/rotate/scale) will
/// Gets or sets a value indicating whether the pivot (the pivot point for position/rotate/scale) will
/// be drawn on the screen as a cross. This can be used for debugging the game.
/// </summary>
/// <value><c>true</c> if debug draw anchor; otherwise, <c>false</c>.</value>
bool DebugDrawAnchor { get; set; }
/// <value><c>true</c> if debug draw pivot; otherwise, <c>false</c>.</value>
bool DebugDrawPivot { get; set; }

/// <summary>
/// An event when fires whenever an animation is started on this container.
Expand Down
17 changes: 8 additions & 9 deletions Source/AGS.API/Graphics/IImageComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,22 @@ public interface IHasImage : INotifyPropertyChanged
Color Tint { get; set; }

/// <summary>
/// Gets or sets the anchor. The anchor for an image is the pivot point from which
/// the position, scale and rotation are determined. For example, rotating an image
/// from it's center point will rotate it in place, while rotating it from it's bottom-left
/// point will rotate the entire image around the bottom-left. I might help to think of an anchor
/// as the point on an image on which you place your finger on before rotating.
/// Gets or sets the pivot point from which the position, scale and rotation are determined.
/// For example, rotating an image from it's center point will rotate it in place,
/// while rotating it from it's bottom-left point will rotate the entire image around the bottom-left.
/// It might help to think of the pivot as the point on an image on which you place your finger on before rotating.
///
/// The units of the anchor point is in relation for the image size, where (0f,0f) is the bottom-left
/// The units of the pivot point is in relation for the image size, where (0f,0f) is the bottom-left
/// corner, and (1f,1f) is the top-right corner. The default is (0.5f, 0f), which means the bottom-center
/// point of the image.
/// </summary>
/// <example>
/// <code>
/// image.Anchor = new PointF(0.5f, 0.5f); //placing the anchor point in the middle of the image
/// image.Pivot = new PointF(0.5f, 0.5f); //placing the pivot point in the middle of the image
/// </code>
/// </example>
/// <value>The anchor.</value>
PointF Anchor { get; set; }
/// <value>The pivot.</value>
PointF Pivot { get; set; }

/// <summary>
/// Gets or sets the image.
Expand Down
4 changes: 2 additions & 2 deletions Source/AGS.API/Objects/Characters/Talking/IPortraitConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public enum PortraitPositioning
/// <summary>
/// If the speaker is in the left side of the screen the portrait will be positioned on the left,
/// otherwise on the right.
/// Note that the portrait's anchor will be automacially set to left in order for the portrait
/// Note that the portrait's pivot will be automacially set to left in order for the portrait
/// to be properly positioned.
/// </summary>
SpeakerPosition,
/// <summary>
/// The portraits will alternate in positions so if two characters are having a dialog,
/// each of them will have the portrait on a sepearate side.
/// Note that the portrait's anchor will be automacially set to left in order for the portrait
/// Note that the portrait's pivot will be automacially set to left in order for the portrait
/// to be properly positioned.
/// </summary>
Alternating,
Expand Down
4 changes: 2 additions & 2 deletions Source/AGS.API/Objects/IScaleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public interface IScale: INotifyPropertyChanged
void ScaleTo(float width, float height);

/// <summary>
/// Flips the scale horizontally (this is done by negating <see cref="ScaleX"/> and <see cref="IHasImage.Anchor"/>'s X).
/// Flips the scale horizontally (this is done by negating <see cref="ScaleX"/> and <see cref="IHasImage.Pivot"/>'s X).
/// </summary>
void FlipHorizontally();

/// <summary>
/// Flips the scale vertucally (this is done by negating <see cref="ScaleY"/> and <see cref="IHasImage.Anchor"/>'s Y).
/// Flips the scale vertucally (this is done by negating <see cref="ScaleY"/> and <see cref="IHasImage.Pivot"/>'s Y).
/// </summary>
void FlipVertically();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public FeaturesLabelsPanel(IGame game, IObject parent)
200f, 50f, 25f, _parent.Height - 25f, parent,
new AGSTextConfig(autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight), false);
_label.RenderLayer = parent.RenderLayer;
_label.Anchor = new PointF(0f, 1f);
_label.Pivot = new PointF(0f, 1f);
_label.Tint = Colors.DarkOliveGreen;
_label.Border = AGSBorders.SolidColor(Colors.LightSeaGreen, 3f);
_label.MouseEnter.Subscribe(_ => _label.Tint = Colors.DarkGoldenrod);
Expand Down
4 changes: 2 additions & 2 deletions Source/Demo/DemoQuest/GUI/FeaturesWindow/FeaturesTopWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Load(IGame game)
IGameFactory factory = game.Factory;
_panel = factory.UI.GetPanel(_panelId, 800, 600,
_layer.IndependentResolution.Value.Width / 2f, _layer.IndependentResolution.Value.Height / 2f);
_panel.Anchor = new PointF(0.5f, 0.5f);
_panel.Pivot = new PointF(0.5f, 0.5f);
_panel.Visible = false;
_panel.Tint = Colors.Black;
_panel.Border = AGSBorders.SolidColor(Colors.Green, borderWidth, hasRoundCorners: true);
Expand All @@ -49,7 +49,7 @@ public void Load(IGame game)
new AGSTextConfig(factory.Graphics.Brushes.LoadSolidBrush(Colors.Red),
autoFit: AutoFit.TextShouldFitLabel, alignment: Alignment.MiddleCenter),
width: 40f, height: 40f);
xButton.Anchor = new PointF();
xButton.Pivot = new PointF();
xButton.RenderLayer = _layer;
xButton.Tint = Colors.Transparent;
xButton.MouseEnter.Subscribe(_ => xButton.TextConfig = AGSTextConfig.ChangeColor(xButton.TextConfig, Colors.Yellow, Colors.White, 0.3f));
Expand Down
14 changes: 7 additions & 7 deletions Source/Demo/DemoQuest/GUI/FeaturesWindow/FeaturesTweenPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public FeaturesTweenPanel(IGame game, IObject parent, IPanel window)
( "Lightness", () => o.TweenLightness(0f, time, ease())),
( "ScaleX", () => o.TweenScaleX(2f, time, ease())),
( "ScaleY", () => o.TweenScaleY(2f, time, ease())),
( "AnchorX", () => o.TweenAnchorX(1f, time, ease())),
( "AnchorY", () => o.TweenAnchorY(1f, time, ease())),
( "PivotX", () => o.TweenPivotX(1f, time, ease())),
( "PivotY", () => o.TweenPivotY(1f, time, ease())),
};
};
Expand Down Expand Up @@ -124,7 +124,7 @@ public FeaturesTweenPanel(IGame game, IObject parent, IPanel window)
_clearTweensButton = addButton("FeaturesTweenClearAll", "Clear All", _addTweenButton.X, 20f, clearTweens);
_tweensListPanel = _game.Factory.UI.GetPanel("FeaturesTweenListPanel", 600f, 250f, 0f, _parent.Height - 200f, parent, false);
_tweensListPanel.Tint = Colors.Transparent;
_tweensListPanel.Anchor = new PointF(0f, 1f);
_tweensListPanel.Pivot = new PointF(0f, 1f);
_tweensListPanel.AddComponent<IBoundingBoxWithChildrenComponent>();
_game.Factory.UI.CreateScrollingPanel(_tweensListPanel);
var layout = _tweensListPanel.AddComponent<IStackLayoutComponent>();
Expand Down Expand Up @@ -312,13 +312,13 @@ public RunningTween(string name, Tween tween, IGame game, IObject parent)
_panel.Visible = false;
_panel.RenderLayer = parent.RenderLayer;
_panel.Tint = Colors.Transparent;
_panel.Anchor = new PointF(0f, 1f);
_panel.Pivot = new PointF(0f, 1f);

_slider = factory.GetSlider($"FeaturesTweenSlider_{tweenId}", null, null, 0f, 0f, tween.DurationInTicks, _panel);
_slider.Location = new AGSLocation(10f, 10f);
_slider.HandleGraphics.Anchor = new PointF(0.5f, 0.5f);
_slider.HandleGraphics.Pivot = new PointF(0.5f, 0.5f);
_slider.Direction = SliderDirection.LeftToRight;
_slider.Graphics.Anchor = new PointF(0f, 0.5f);
_slider.Graphics.Pivot = new PointF(0f, 0.5f);
_slider.Graphics.Image = new EmptyImage(_panel.Width - 100f, 10f);
_slider.Graphics.Border = AGSBorders.SolidColor(Colors.DarkGray, 0.5f, true);
_slider.HandleGraphics.Border = AGSBorders.SolidColor(Colors.White, 0.5f, true);
Expand All @@ -328,7 +328,7 @@ public RunningTween(string name, Tween tween, IGame game, IObject parent)
_label = factory.GetLabel($"FeaturesTweenLabel_{tweenId}", name, 100f, 20f,
_slider.X + _slider.Graphics.Width / 2f, _slider.Y + 10f, _panel,
new AGSTextConfig(autoFit: AutoFit.TextShouldFitLabel));
_label.Anchor = new PointF(0.5f, 0f);
_label.Pivot = new PointF(0.5f, 0f);

AGSTextConfig idleConfig = new AGSTextConfig(alignment: Alignment.MiddleCenter, brush: _game.Factory.Graphics.Brushes.LoadSolidBrush(Colors.White));
AGSTextConfig hoverConfig = new AGSTextConfig(alignment: Alignment.MiddleCenter, brush: _game.Factory.Graphics.Brushes.LoadSolidBrush(Colors.Black));
Expand Down
2 changes: 1 addition & 1 deletion Source/Demo/DemoQuest/GUI/InventoryPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task LoadAsync(IGame game)
IGameFactory factory = game.Factory;

_panel = await factory.UI.GetPanelAsync("Inventory Panel", "../../Assets/Gui/DialogBox/inventory.bmp", 160f, 100f);
_panel.Anchor = new PointF (0.5f, 0.5f);
_panel.Pivot = new PointF (0.5f, 0.5f);
_panel.Visible = false;

await loadButton("Inventory Look Button", factory, "magnify/", 5f, RotatingCursorScheme.LOOK_MODE);
Expand Down
2 changes: 1 addition & 1 deletion Source/Demo/DemoQuest/GUI/MouseCursors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private async Task<IObject> loadCursor(string filename, IGameFactory factory)
{
IAnimation animation = await factory.Graphics.LoadAnimationFromFilesAsync(loadConfig: _loadConfig, files: new[]{ _baseFolder + filename });
var cursor = factory.Object.GetObject($"Cursor_{filename}");
cursor.Anchor = new PointF(0f, 1f);
cursor.Pivot = new PointF(0f, 1f);
cursor.IgnoreScalingArea = true;
cursor.IgnoreViewport = true;
cursor.StartAnimation(animation);
Expand Down
10 changes: 5 additions & 5 deletions Source/Demo/DemoQuest/GUI/OptionsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task LoadAsync(IGame game)
_game = game;
IGameFactory factory = game.Factory;
_panel = await factory.UI.GetPanelAsync(_panelId, "../../Assets/Gui/DialogBox/options.bmp", 160f, 100f);
_panel.Anchor = new PointF(0.5f, 0.5f);
_panel.Pivot = new PointF(0.5f, 0.5f);
_panel.Visible = false;
_panel.AddComponent<IModalWindowComponent>();

Expand All @@ -45,21 +45,21 @@ public async Task LoadAsync(IGame game)
_sliderFolder + "handle.bmp", 0.5f, 0f, 1f, _panel, loadConfig: loadConfig);
volumeSlider.X = 120f;
volumeSlider.Y = 10f;
volumeSlider.HandleGraphics.Anchor = new PointF(0.5f, 0.5f);
volumeSlider.HandleGraphics.Pivot = new PointF(0.5f, 0.5f);
volumeSlider.OnValueChanged(onVolumeChanged, _game);

ILabel volumeLabel = factory.UI.GetLabel("Volume Label", "Volume", 50f, 30f, 120f, 85f, _panel, _textConfig);
volumeLabel.Anchor = new PointF(0.5f, 0f);
volumeLabel.Pivot = new PointF(0.5f, 0f);

ISlider speedSlider = await factory.UI.GetSliderAsync("Speed Slider", _sliderFolder + "slider.bmp",
_sliderFolder + "handle.bmp", 100f, 1f, 200f, _panel, loadConfig: loadConfig);
speedSlider.X = 180f;
speedSlider.Y = 10f;
speedSlider.HandleGraphics.Anchor = new AGS.API.PointF(0.5f, 0.5f);
speedSlider.HandleGraphics.Pivot = new AGS.API.PointF(0.5f, 0.5f);
speedSlider.OnValueChanged(onSpeedChanged, _game);

ILabel speedLabel = factory.UI.GetLabel("Speed Label", "Speed", 50f, 30f, 180f, 85f, _panel, _textConfig);
speedLabel.Anchor = new PointF(0.5f, 0f);
speedLabel.Pivot = new PointF(0.5f, 0f);

_game.Events.OnSavedGameLoad.Subscribe(findPanel);

Expand Down
6 changes: 3 additions & 3 deletions Source/Demo/DemoQuest/GUI/TopBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task<IPanel> LoadAsync(IGame game)
_inventoryItemIcon = factory.Object.GetObject("Inventory Item Icon");
_inventoryItemIcon.X = 10f;
_inventoryItemIcon.Y = 10f;
_inventoryItemIcon.Anchor = new AGS.API.PointF (0f, 0f);
_inventoryItemIcon.Pivot = new AGS.API.PointF (0f, 0f);
_inventoryItemIcon.TreeNode.SetParent(activeInvButton.TreeNode);
_inventoryItemIcon.RenderLayer = _panel.RenderLayer;
_inventoryItemIcon.Enabled = false;
Expand All @@ -67,7 +67,7 @@ public async Task<IPanel> LoadAsync(IGame game)
ILabel label = game.Factory.UI.GetLabel("Hotspot Label", "", 150f, 20f, 200f, 0f, _panel, new AGSTextConfig(brush: AGSGame.Device.BrushLoader.LoadSolidBrush(Colors.LightGreen),
alignment: Alignment.MiddleCenter, autoFit: AutoFit.TextShouldFitLabel, paddingBottom: 5f,
font: game.Factory.Fonts.LoadFont(AGSGameSettings.DefaultTextFont.FontFamily, 10f)));
label.Anchor = new AGS.API.PointF(0.5f, 0f);
label.Pivot = new AGS.API.PointF(0.5f, 0f);
VerbOnHotspotLabel hotspotLabel = new VerbOnHotspotLabel(() => _scheme.CurrentMode, game, label);
hotspotLabel.Start();

Expand Down Expand Up @@ -104,7 +104,7 @@ private void onRepeatedlyExecute()
if (_lastInventoryItem != null)
{
_inventoryItemIcon.Image = _lastInventoryItem.CursorGraphics.Image;
_inventoryItemIcon.Animation.Sprite.Anchor = new PointF (0.5f, 0.5f);
_inventoryItemIcon.Animation.Sprite.Pivot = new PointF (0.5f, 0.5f);
_inventoryItemIcon.ScaleTo(15f, 15f);
}
_inventoryItemIcon.Visible = (_lastInventoryItem != null);
Expand Down
6 changes: 3 additions & 3 deletions Source/Demo/DemoQuest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private static void addDebugLabels(IGame game)
{
ILabel fpsLabel = game.Factory.UI.GetLabel("FPS Label", "", 30, 25, 320, 2, config: new AGSTextConfig(alignment: Alignment.TopLeft,
autoFit: AutoFit.LabelShouldFitText));
fpsLabel.Anchor = new PointF (1f, 0f);
fpsLabel.Pivot = new PointF (1f, 0f);
fpsLabel.Scale = new PointF(0.5f, 0.5f);
fpsLabel.RenderLayer = new AGSRenderLayer(-99999);
fpsLabel.Enabled = true;
Expand All @@ -216,7 +216,7 @@ private static void addDebugLabels(IGame game)
ILabel label = game.Factory.UI.GetLabel("Mouse Position Label", "", 1, 1, 320, 17, config: new AGSTextConfig(alignment: Alignment.TopRight,
autoFit: AutoFit.LabelShouldFitText));
label.Tint = Colors.SlateBlue.WithAlpha(125);
label.Anchor = new PointF (1f, 0f);
label.Pivot = new PointF (1f, 0f);
label.Scale = new PointF(0.5f, 0.5f);
label.RenderLayer = fpsLabel.RenderLayer;
MousePositionLabel mouseLabel = new MousePositionLabel(game, label);
Expand All @@ -225,7 +225,7 @@ private static void addDebugLabels(IGame game)
ILabel debugHotspotLabel = game.Factory.UI.GetLabel("Debug Hotspot Label", "", 1f, 1f, 320, 32, config: new AGSTextConfig(alignment: Alignment.TopRight,
autoFit: AutoFit.LabelShouldFitText));
debugHotspotLabel.Tint = Colors.DarkSeaGreen.WithAlpha(125);
debugHotspotLabel.Anchor = new PointF(1f, 0f);
debugHotspotLabel.Pivot = new PointF(1f, 0f);
debugHotspotLabel.Scale = new PointF(0.5f, 0.5f);
debugHotspotLabel.RenderLayer = fpsLabel.RenderLayer;
HotspotLabel hotspot = new HotspotLabel(game, debugHotspotLabel) { DebugMode = true };
Expand Down
2 changes: 1 addition & 1 deletion Source/Engine/AGS.Engine.Android/Drawing/AndroidBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public IBitmap Crop(AGS.API.Rectangle cropRect)
{
debugDraw = factory.Object.GetObject(id ?? path ?? "Mask Drawable");
debugDraw.Image = factory.Graphics.LoadImage(new AndroidBitmap(debugMask, _graphics), null, path);
debugDraw.Anchor = new AGS.API.PointF ();
debugDraw.Pivot = new AGS.API.PointF ();
}

return new AGSMask (mask, debugDraw);
Expand Down

0 comments on commit 2386411

Please sign in to comment.