コード例 #1
0
        public InteractiveAdjacentCardGroup(GamePage parent, NormalizedPosition origin, Common.Orientation orientation)
            : base(parent, origin, orientation)
        {
            EndInteractiveSession();

            // bind callbacks to handlers
            _canvasFacade.CardClicked        += OnCardClicked;
            _canvasFacade.CardPointerEntered += OnCardPointerEntered;
            _canvasFacade.CardPointerExited  += OnCardPointerExited;
        }
コード例 #2
0
ファイル: CardGroup.cs プロジェクト: comoody/WizardMobile
        public CardGroup(ICanvasProvider canvasFacade, NormalizedPosition origin, Common.Orientation orientation)
        {
            _canvasFacade      = canvasFacade;
            _displayCards      = new List <UniqueDisplayCard>();
            Origin             = origin;
            _orientation       = orientation;
            OrientationDegress = (double)orientation;
            _curZIndex         = 0;

            // async initialization from canvas facade
            _canvasFacade.GetNormalizedCardImageSize().ContinueWith(task => _cardImageSize = task.Result);
        }
コード例 #3
0
        /*************************** ICanvasFacade implementation *******************************/
        public void AddCard(UniqueDisplayCard card, NormalizedPosition canvasPositon, double orientationDegrees, int zIndex)
        {
            Image image = CreateCardImage(card);

            SetUiElementNormalizedCanvasPosition(image, canvasPositon, true, _cardBitmapSize);
            SetCardImageAngle(image, orientationDegrees);
            Canvas.SetZIndex(image, zIndex);

            image.PointerReleased += (sender, args) => FireCardClickedEvent(card);
            image.PointerEntered  += (sender, args) => FireCardPointerEnteredEvent(card);
            image.PointerExited   += (sender, args) => FireCardPointerExitedEvent(card);
            game_canvas.Children.Add(image);
        }
コード例 #4
0
        /************************************** helpers **********************************************/
        // translates a high level normalized canvas position (0 -> 100) to actual canvas position (0 -> actual dimension)
        // NOTE optionally takes into acount image size so that it seems like the image is centered on pos
        private Point DenormalizePosition(NormalizedPosition pos, Size?boundingRectSize = null)
        {
            double x = pos.NormalizedX * game_canvas.ActualWidth / CanvasNormalization.MAX_X;
            double y = pos.NormalizedY * game_canvas.ActualHeight / CanvasNormalization.MAX_Y;

            // optionally shift x and y so that it seems like the point is centered around a given image
            if (boundingRectSize.HasValue)
            {
                x -= boundingRectSize.Value.Width / 2;
                y -= boundingRectSize.Value.Height / 2;
            }

            return(new Point(x, y));
        }
コード例 #5
0
        public void ShowImage(string imageKey, NormalizedPosition position, double orientationDegrees, double scaleFactor)
        {
            var bitmapImage = game_canvas.Resources[imageKey] as BitmapImage;

            // scale down and maintain aspect ratio
            bitmapImage.DecodePixelHeight = (int)(game_canvas.ActualHeight * scaleFactor);
            Image image = new Image();

            image.Source = bitmapImage;
            image.Name   = imageKey;

            SetUiElementNormalizedCanvasPosition(image, position);
            Canvas.SetZIndex(image, 1);

            game_canvas.Children.Add(image);
        }
コード例 #6
0
        public void UpdateCard
        (
            UniqueDisplayCard cardToUpdate,
            NormalizedPosition canvasPositon = null,
            double?orientationDegrees        = null,
            int?zIndex  = null,
            bool?dimmed = null
        )
        {
            // check if the card bitmap needs an update
            Image imageToUpdate          = this.FindName(cardToUpdate.Id) as Image;
            var   originalBitmapFilepath = (imageToUpdate.Source as BitmapImage).UriSource.AbsolutePath;

            // if the original element already contains the updated bitmap, no change is needed, otherwise, replace the bitmap
            if (!originalBitmapFilepath.Contains(cardToUpdate.DisplayKey))
            {
                var bitmapImage = RetrieveCardBitmap(cardToUpdate.DisplayKey);
                imageToUpdate.Source = bitmapImage;
            }

            // update the position if provided
            if (canvasPositon != null)
            {
                // update position. if already equal, this is a noop
                SetUiElementNormalizedCanvasPosition(imageToUpdate, canvasPositon, true);
            }

            // update the orientnation if provided
            if (orientationDegrees.HasValue)
            {
                // update the orientation. if already equal, this is a noop
                SetCardImageAngle(imageToUpdate, orientationDegrees.Value);
            }

            if (zIndex.HasValue)
            {
                Canvas.SetZIndex(imageToUpdate, zIndex.Value);
            }

            if (dimmed.HasValue)
            {
                imageToUpdate.Opacity = dimmed.Value ? 0.5 : 1.0;
            }
        }
コード例 #7
0
        // sets the FrameworkElement to be at the indicated position, optionally centered around a given bounding rectangle
        // @param centered: should element position be centered around bounding rect of element (by default the bounding rect of an element is Size(ActionWidth, ActualHeight)
        // @param prerenderSizeOverride: if present, the bounding rectangle is set to be the size override instead of ActualWidth, ActualHieght
        //              - this is useful for elements that are set in position before being rendered, in a state where they don't have an ActualHieght or ActualWidth yet
        //              - if the element is ever resized
        private void SetUiElementNormalizedCanvasPosition(FrameworkElement element, NormalizedPosition position, bool centered = false, Size?prerenderSizeOverride = null)
        {
            Action positionSetter = () =>
            {
                Size?boundingRect = null;  // bounding rect is only determined if the element should be centered
                if (centered)
                {
                    // if the element hasn't rendered (actual size == 0) and a prerender override size is provided, then the override size will be used
                    if (element.ActualWidth == 0 && prerenderSizeOverride != null)
                    {
                        boundingRect = prerenderSizeOverride;
                        RegisterPreRenderSize(element, prerenderSizeOverride.Value);
                    }
                    else
                    {
                        // otherwise, the size is derived from the current width and height
                        boundingRect = new Size?(new Size(element.ActualWidth, element.ActualHeight));
                    }
                }

                var denormalizedPosition = DenormalizePosition(position, boundingRect);
                Canvas.SetLeft(element, denormalizedPosition.X);
                Canvas.SetTop(element, denormalizedPosition.Y);
                RegisterElementCanvasPosition(element, position, centered);
            };

            // call the position setter once to set the position
            positionSetter();

            // if the element should be centered, attach a listener that recenters the elemenet on size change to guarentee that the element is always centered
            if (centered)
            {
                // check if a position setter was previously subscribed to this event. If so, it must be removed so that it doesn't update to a stale position
                if (_elementSizeChangedHandlers.ContainsKey(element))
                {
                    element.SizeChanged -= _elementSizeChangedHandlers[element];
                }
                _elementSizeChangedHandlers[element] = (object sender, SizeChangedEventArgs args) => positionSetter();
                element.SizeChanged += _elementSizeChangedHandlers[element];
            }
        }
コード例 #8
0
 private void RegisterElementCanvasPosition(FrameworkElement el, NormalizedPosition pos, bool centered)
 {
     _normalizedCanvasPositionRegistry[el] = new Tuple <NormalizedPosition, bool>(pos, centered);
 }
コード例 #9
0
 public AdjacentCardGroup(GamePage parent, NormalizedPosition origin, Orientation orientation)
     : base(parent, origin, orientation)
 {
 }
コード例 #10
0
 public DealerButtonPosition(ICanvasProvider canvasProvider, NormalizedPosition origin)
 {
     _canvasProvider     = canvasProvider;
     _origin             = origin;
     _isDisplayingButton = false;
 }
コード例 #11
0
 public StackCardGroup(GamePage parent, NormalizedPosition origin, Common.Orientation orientation)
     : base(parent, origin, orientation)
 {
 }