private Layer borderWindowRootLayer = null;
private Layer borderWindowBottomLayer = null;
private bool isBorderWindow = false;
- private bool isInterceptTouch = false;
- private Timer overlayTimer;
private Color overlayBackgroundColor;
// for border area
BottomRight = ResizeDirection.BottomRight,
Move,
}
+
+ /// <summary>
+ /// This enum is the policy when resizing the border window.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public enum BorderResizePolicyType
+ {
+ /// <summary>
+ /// The window can be resized freely.
+ /// </summary>
+ Free = 0,
+ /// <summary>
+ /// The window is resized according to the ratio.
+ /// </summary>
+ KeepRatio = 1,
+ /// <summary>
+ /// The window is not resized and is fixed.
+ /// </summary>
+ Fixed = 2,
+ }
#endregion //Enums
#region Interfaces
WindowSize += new Size2D((int)borderInterface.BorderLineThickness * 2, (int)(borderHeight + borderInterface.BorderLineThickness * 2));
}
- if (borderInterface.OverlayMode == true)
+ // If it is BorderResizePolicyType.KeepRatio type, it will be resized according to the ratio.
+ if (borderInterface.ResizePolicy == BorderResizePolicyType.KeepRatio)
{
- rootView.InterceptTouchEvent += OverlayInterceptTouch;
+ AddAuxiliaryHint("wm.policy.win.resize_aspect_ratio", "1");
}
// Add a view to the border layer.
return direction;
}
-
- private bool OverlayInterceptTouch(object sender, View.TouchEventArgs e)
- {
- if (e.Touch.GetState(0) == PointStateType.Down)
- {
- if (isInterceptTouch == true && overlayTimer != null)
- {
- overlayTimer.Start();
- }
- }
- return false;
- }
-
- private bool OnTick(object o, Timer.TickEventArgs e)
- {
- GetBorderWindowBottomLayer().LowerToBottom();
- if (borderView != null)
- {
- borderView.Hide();
- }
- isInterceptTouch = false;
-
- overlayTimer.Stop();
- overlayTimer.Dispose();
- overlayTimer = null;
- return false;
- }
-
- // Intercept touch on window.
- private bool OnWinInterceptTouch(object sender, Window.TouchEventArgs e)
- {
- if (e.Touch.GetState(0) == PointStateType.Up)
- {
- if (isInterceptTouch == false && overlayTimer == null)
- {
- overlayTimer = new Timer(3000);
- overlayTimer.Tick += OnTick;
- overlayTimer.Start();
- GetBorderWindowBottomLayer().RaiseToTop();
- if (borderView != null)
- {
- borderView.Show();
- }
- isInterceptTouch = true;
- }
- }
- return false;
- }
-
private void OverlayMode(bool enable)
{
if (borderInterface.OverlayMode == true)
{
if (enable == true)
{
- InterceptTouchEvent += OnWinInterceptTouch;
if (borderView != null)
{
overlayBackgroundColor = new Color(borderView.BackgroundColor);
}
else
{
- if (overlayTimer != null)
- {
- overlayTimer.Stop();
- overlayTimer.Dispose();
- overlayTimer = null;
- }
- isInterceptTouch = false;
- InterceptTouchEvent -= OnWinInterceptTouch;
GetBorderWindowBottomLayer().LowerToBottom();
if (borderView != null)
{
private View windowView = null;
private bool isWinGestures = false;
private Timer timer;
+ private Timer overlayTimer;
private CurrentGesture currentGesture = CurrentGesture.None;
private bool disposed = false;
[EditorBrowsable(EditorBrowsableState.Never)]
public bool OverlayMode {get; set;}
+ /// <summary>
+ /// Set the window resizing policy.
+ /// Default value is BorderResizePolicyType.Free;
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Window.BorderResizePolicyType ResizePolicy {get; set;}
+
/// <summary>
/// Creates a default border
BorderHeight = DefaultHeight;
MinSize = DefaultMinSize;
OverlayMode = false;
+ ResizePolicy = Window.BorderResizePolicyType.Free;
}
/// <summary>
BorderWindow.RequestMoveToServer();
}
}
- else if (direction != Window.BorderDirection.None)
+ else if (direction != Window.BorderDirection.None && ResizePolicy != Window.BorderResizePolicyType.Fixed)
{
OnRequestResize();
BorderWindow.RequestResizeToServer((Window.ResizeDirection)direction);
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool OnLeftTopCornerIconTouched(object sender, View.TouchEventArgs e)
{
- if (e == null)
- {
- return false;
- }
- if (e.Touch.GetState(0) == PointStateType.Down)
+ if (e != null && e.Touch.GetState(0) == PointStateType.Down)
{
ClearWindowGesture();
- OnRequestResize();
- BorderWindow.RequestResizeToServer(Window.ResizeDirection.TopLeft);
+ if (ResizePolicy != Window.BorderResizePolicyType.Fixed)
+ {
+ OnRequestResize();
+ BorderWindow.RequestResizeToServer(Window.ResizeDirection.TopLeft);
+ }
}
- return true;
+ return false;
}
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool OnRightTopCornerIconTouched(object sender, View.TouchEventArgs e)
{
- if (e == null)
- {
- return false;
- }
- if (e.Touch.GetState(0) == PointStateType.Down)
+ if (e != null && e.Touch.GetState(0) == PointStateType.Down)
{
ClearWindowGesture();
- OnRequestResize();
- BorderWindow.RequestResizeToServer(Window.ResizeDirection.TopRight);
+ if (ResizePolicy != Window.BorderResizePolicyType.Fixed)
+ {
+ OnRequestResize();
+ BorderWindow.RequestResizeToServer(Window.ResizeDirection.TopRight);
+ }
}
- return true;
+ return false;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool OnLeftBottomCornerIconTouched(object sender, View.TouchEventArgs e)
{
- if (e == null)
- {
- return false;
- }
- if (e.Touch.GetState(0) == PointStateType.Down)
+ if (e != null && e.Touch.GetState(0) == PointStateType.Down)
{
ClearWindowGesture();
- OnRequestResize();
- BorderWindow.RequestResizeToServer(Window.ResizeDirection.BottomLeft);
+ if (ResizePolicy != Window.BorderResizePolicyType.Fixed)
+ {
+ OnRequestResize();
+ BorderWindow.RequestResizeToServer(Window.ResizeDirection.BottomLeft);
+ }
}
- return true;
+ return false;
}
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool OnRightBottomCornerIconTouched(object sender, View.TouchEventArgs e)
{
- if (e == null)
- {
- return false;
- }
- if (e.Touch.GetState(0) == PointStateType.Down)
+ if (e != null && e.Touch.GetState(0) == PointStateType.Down)
{
ClearWindowGesture();
- OnRequestResize();
- BorderWindow.RequestResizeToServer(Window.ResizeDirection.BottomRight);
+ if (ResizePolicy != Window.BorderResizePolicyType.Fixed)
+ {
+ OnRequestResize();
+ BorderWindow.RequestResizeToServer(Window.ResizeDirection.BottomRight);
+ }
}
- return true;
+ return false;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool OnMinimizeIconTouched(object sender, View.TouchEventArgs e)
{
- if (e == null)
- {
- return false;
- }
- if (e.Touch.GetState(0) == PointStateType.Up)
+ if (e != null && e.Touch.GetState(0) == PointStateType.Up)
{
MinimizeBorderWindow();
}
- return true;
+ return false;
}
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool OnMaximizeIconTouched(object sender, View.TouchEventArgs e)
{
- if (e == null)
- {
- return false;
- }
- if (e.Touch.GetState(0) == PointStateType.Up)
+ if (e != null && e.Touch.GetState(0) == PointStateType.Up)
{
MaximizeBorderWindow();
}
- return true;
+ return false;
}
/// <summary>
{
return false;
}
- if (e.Touch.GetState(0) == PointStateType.Up)
+ if (e != null && e.Touch.GetState(0) == PointStateType.Up)
{
- BorderWindow.Destroy();
- BorderWindow = null;
+ CloseBorderWindow();
}
- return true;
+ return false;
}
{
return;
}
+ this.borderView = borderView;
// Register to resize and move through pan gestures.
borderPanGestureDetector = new PanGestureDetector();
borderPanGestureDetector.Attach(borderView);
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual void OnResized(int width, int height)
{
+ if (overlayTimer != null)
+ {
+ overlayTimer.Stop();
+ overlayTimer.Dispose();
+ overlayTimer = null;
+ BorderWindow?.GetBorderWindowBottomLayer().LowerToBottom();
+ borderView?.Show();
+ }
UpdateIcons();
}
UpdateIcons();
}
+ /// <summary>
+ /// Show the border when OverlayMode is true and the window is now Maximize.
+ /// </summary>
+ /// <param name="time">Time(ms) for borders to disappear again</param>
+ /// <returns>True if border became show, false otherwise</returns>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public virtual bool OverlayBorderShow(uint time = 3000)
+ {
+ if (BorderWindow != null && BorderWindow.IsMaximized())
+ {
+ if (overlayTimer == null)
+ {
+ overlayTimer = new Timer(time);
+ overlayTimer.Tick += (s, e) =>
+ {
+ BorderWindow.GetBorderWindowBottomLayer().LowerToBottom();
+ borderView?.Hide();
+ overlayTimer?.Stop();
+ overlayTimer?.Dispose();
+ overlayTimer = null;
+ return false;
+ };
+ overlayTimer.Start();
+ BorderWindow.GetBorderWindowBottomLayer().RaiseToTop();
+ borderView?.Show();
+ }
+ else
+ {
+ overlayTimer.Start();
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary>
+ /// Hide the border when OverlayMode is true and the window is now Maximize.
+ /// </summary>
+ /// <returns>True if border became hide, false otherwise</returns>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public virtual bool OverlayBorderHide()
+ {
+ if (BorderWindow != null && BorderWindow.IsMaximized())
+ {
+ borderView?.Hide();
+ return true;
+ }
+ return false;
+ }
+
[EditorBrowsable(EditorBrowsableState.Never)]
protected virtual void Dispose(bool disposing)
{
leftCornerIcon?.Dispose();
rightCornerIcon?.Dispose();
timer?.Dispose();
+ overlayTimer?.Dispose();
windowView?.Dispose();
borderView?.Dispose();
}