private void LinkFn(CanvasPieceLayoutScope scope, jQueryObject element, dynamic attr)
        {
            element.Width(scope.Width);
            element.Height(scope.Height);
  
            element[0].Style.Display = "inline-block";
            var context = (CanvasRenderingContext2D)((CanvasElement)element[0]).GetContext(CanvasContextId.Render2D);
            Action updatePieceLayout = () =>
            {
                context.Canvas.Width = context.Canvas.Width;

                context.Me().webkitImageSmoothingEnabled = false;
                context.Me().mozImageSmoothingEnabled = false;
                context.Me().imageSmoothingEnabled = false;

                context.FillStyle = "#FFFFFF";
                context.FillRect(0, 0, scope.Width, scope.Height);
                context.BeginPath();
                context.Rect(0, 0, scope.Width, scope.Height);
                context.Clip();
                context.ClosePath();
                if (scope.PieceLayout == null) return;

                var rect = scope.PieceLayout.GetRectangle(scope.ObjectData);

                context.Scale(scope.Width / ((double)rect.Width), scope.Height / ((double)rect.Height));
                context.Translate(-rect.X, -rect.Y);
                scope.PieceLayout.DrawUI(context, true, -1, scope.ObjectData);
            };

            scope.Watch("pieceLayout", updatePieceLayout);
            scope.Watch("pieceLayout.pieces", updatePieceLayout, true);
        }
        private void LinkFn(CanvasPieceScope scope, jQueryObject element, dynamic attr)
        {
            element.Width(scope.Width);
            element.Height(scope.Height);
            element[0].Style.Display = scope.Inline ? "inline-block" : "block";
            var context = (CanvasRenderingContext2D)((CanvasElement)element[0]).GetContext(CanvasContextId.Render2D);

            Action updateAsset = () =>
                                 {
                                     context.Canvas.Width = context.Canvas.Width;

                                     context.Me().webkitImageSmoothingEnabled = false;
                                     context.Me().mozImageSmoothingEnabled = false;
                                     context.Me().imageSmoothingEnabled = false;

                                     var levelObjectAssetFrames = scope.Asset.Frames;
                                     if (levelObjectAssetFrames.Count == 0) return;
                                     levelObjectAssetFrames[0].DrawSimple(context, new Point(0, 0), scope.Width, scope.Height, false, false);
                                 };

            scope.Watch("asset", updateAsset);
            scope.Watch("asset.frames", updateAsset);
            scope.Watch("asset.width", updateAsset);
            scope.Watch("asset.height", updateAsset);

        }
Beispiel #3
0
        private void ResizeElement(jQueryObject element)
        {
            var xFactor = GetXFactor(element);

            if (xFactor != 0)
            {
                var initialWidth = element.GetDataValue("flexify-width").As <int?>();
                if (initialWidth == null)
                {
                    var width = element.GetWidth();
                    element.Data("flexify-width", width);
                    initialWidth = width;
                }

                element.Width(Math.Truncate(initialWidth.Value + xFactor * xDifference));
            }

            var yFactor = GetYFactor(element);

            if (yFactor != 0)
            {
                var initialHeight = element.GetDataValue("flexify-height").As <int?>();
                if (initialHeight == null)
                {
                    var height = element.GetHeight();
                    element.Data("flexify-height", height);
                    initialHeight = height;
                }

                element.Height(Math.Truncate(initialHeight.Value + yFactor * yDifference));
            }

            if (element.HasClass("require-layout"))
            {
                element.TriggerHandler("layout");
            }
        }
        private void LinkFn(CanvasTilePieceScope scope, jQueryObject element, dynamic attr)
        {
            element.Width(scope.Width);
            element.Height(scope.Height);
            if (scope.Edit)
            {
                element.Click(ev =>
                              {
                                  TilePieceInfo tilePieceInfo = scope.TilePiece;

                                  if (tilePieceInfo == null) return;
                                  var x = ev.OffsetX;
                                  var y = ev.OffsetY;


                                  var _x = (int)(x / ((double)scope.Width / TileChunk.Size));
                                  var _y = (int)(y / ((double)scope.Height / TileChunk.Size));

                                  //                                  scope.DebugDrawOptions.OutlineTilePiece = scope.TileChunk.GetTilePieceInfo(_x, _y, true);

                              });
            }
            var zero = new Point(0, 0);

            var context = (CanvasRenderingContext2D)((CanvasElement)element[0]).GetContext(CanvasContextId.Render2D);
            Action updateTilePiece = () =>
                                 {

                                     if (scope.TilePiece == null) return;
                                     var tilePiece = scope.TilePiece.GetTilePiece();

                                     context.Canvas.Width = context.Canvas.Width;

                                     context.Me().webkitImageSmoothingEnabled = false;
                                     context.Me().mozImageSmoothingEnabled = false;
                                     context.Me().imageSmoothingEnabled = false;

                                     context.Scale(scope.Width / ((double)TileChunk.TileSideLength), scope.Height / ((double)TileChunk.TileSideLength));
                                     tilePiece.DrawBase(context, zero, ChunkLayer.Low, false, false);
                                     tilePiece.DrawBase(context, zero, ChunkLayer.High, false, false);

                                     for (int index = 0; index < tilePiece.AnimatedPaletteIndexes.Count; index++)
                                     {
                                         var animatedPaletteIndex = tilePiece.AnimatedPaletteIndexes[index];
                                         tilePiece.DrawAnimatedPalette(context, zero, ChunkLayer.Low, false, false, animatedPaletteIndex);
                                         tilePiece.DrawAnimatedPalette(context, zero, ChunkLayer.High, false, false, animatedPaletteIndex);
                                     }


                                     for (int index = 0; index < tilePiece.AnimatedTileIndexes.Count; index++)
                                     {
                                         var animatedTileIndex = tilePiece.AnimatedTileIndexes[index];
                                         tilePiece.DrawAnimatedTile(context, zero, ChunkLayer.Low, false, false, animatedTileIndex);
                                         tilePiece.DrawAnimatedTile(context, zero, ChunkLayer.High, false, false, animatedTileIndex);
                                     }
                                 
                                      

                                 };

            scope.Watch("tilePiece", updateTilePiece);

            Window.SetInterval(() =>
                               {
/*
                                   if (tilePieceInfo == null) return;
                                   if (!tilePieceInfo.ShouldAnimate())
                                   {
                                       if (scope.ShouldAnimate)
                                       {
                                           updateTilePiece();
                                       }
                                       else
                                           scope.Digest();
                                   }
*/
                               }, 1000 / 60);
        }
Beispiel #5
0
        private void LoadFinish()
        {
            if (imageObject != null && imageObject.Is("img"))
            {
                if (Settings.DisplayType == 0)
                {
                    imageObject.Height(height);
                }
                else if (Settings.DisplayType == 2)
                {
                    imageObject.Width(width);
                }
                else
                {
                    double widthFactor = width / imageElement.Width;
                    double heightFactor = height / imageElement.Height;
                    double factor = widthFactor < heightFactor ? widthFactor : heightFactor;
                    imageObject
                        .Width(Math.Round(imageElement.Width * factor))
                        .Height(Math.Round(imageElement.Height * factor));
                }
            }
            else
            {
                imageObject = jQuery.FromHtml("<div></div>").Append(imagePart1Object).Append(imagePart2Object);

                if (Settings.DisplayType == 0)
                {
                    imagePart1Object.Height(height);
                    imagePart2Object.Height(height);
                    imageObject.Height(height).Width(imageElementPart1.Width / imageElementPart1.Height * height * 2);
                }
                else if (Settings.DisplayType == 2)
                {
                    int halfWidth = Math.Round(width / 2);
                    imagePart1Object.Width(halfWidth);
                    imagePart2Object.Width(halfWidth);
                    imageObject.Width(halfWidth * 2);
                }
                else
                {
                    double widthFactor = width / imageElementPart1.Width / 2;
                    double heightFactor = height / imageElementPart1.Height;
                    double factor = widthFactor < heightFactor ? widthFactor : heightFactor;
                    int halfWidth = Math.Round(imageElementPart1.Width * factor);
                    int sHeight = Math.Round(imageElementPart1.Height * factor);
                    imagePart1Object.Width(halfWidth).Height(sHeight);
                    imagePart2Object.Width(halfWidth).Height(sHeight);
                    imageObject.Width(halfWidth * 2).Height(sHeight);
                }
            }

            loading = false;
            loaded = true;
            onload();
        }
        private void LinkFn(CanvasPieceLayoutEditScope scope, jQueryObject element, dynamic attr)
        {
            element.Width(scope.Width);
            element.Height(scope.Height);

            var mouseDown = false;
            var lastPosition = new FloatPoint(scope.Width / 2f, scope.Height / 2f);
            LevelObjectPieceLayoutPiece movingPiece = null;


            element.MouseDown((e) =>
                              {
                                  lastPosition.X = e.OffsetX;
                                  lastPosition.Y = e.OffsetY;
                                  mouseDown = true;



                                  var posX = (e.OffsetX - scope.ZeroPosition.X) / scope.Scale;
                                  var posY = (e.OffsetY - scope.ZeroPosition.Y) / scope.Scale;


                                  foreach (var levelObjectPieceLayoutPiece in scope.PieceLayout.Pieces)
                                  {

                                      LevelObjectPiece piece = scope.ObjectData.Pieces[levelObjectPieceLayoutPiece.PieceIndex];
                                      var asset = scope.ObjectData.Assets[piece.AssetIndex];
                                      if (asset.Frames.Count > 0)
                                      {
                                          var frm = asset.Frames[0];

                                          if (pointInArea(levelObjectPieceLayoutPiece.X - frm.OffsetX, levelObjectPieceLayoutPiece.Y - frm.OffsetY, 30, posX, posY))
                                          {
                                              movingPiece = levelObjectPieceLayoutPiece;
                                              scope.SelectedPieceLayoutPiece = movingPiece;


                                              lastPosition.X = posX;
                                              lastPosition.Y = posY;
                                              return;

                                          }
                                      }
                                  }


                              });

            element.MouseUp((e) =>
                            {

                                mouseDown = false;
                                movingPiece = null;
                            });

            element.MouseMove((e) => scope.Apply(() =>
                                                 {
                                                     if (!mouseDown) return;

                                                     var x = e.OffsetX;
                                                     var y = e.OffsetY;



                                                     if (movingPiece != null)
                                                     {

                                                         float posX = (e.OffsetX - scope.ZeroPosition.X) / scope.Scale;
                                                         float posY = (e.OffsetY - scope.ZeroPosition.Y) / scope.Scale;

                                                         if (Math.Abs((int)(posX - lastPosition.X)) > 0)
                                                         {
                                                             movingPiece.X += (int)(posX - lastPosition.X);
                                                             lastPosition.X = posX;
                                                         }
                                                         if (Math.Abs((int)(posY - lastPosition.Y)) > 0)
                                                         {
                                                             movingPiece.Y += (int)(posY - lastPosition.Y);
                                                             lastPosition.Y = posY;
                                                         }
                                                     }
                                                     else
                                                     {
                                                         scope.ZeroPosition.X += (int)(x - lastPosition.X);
                                                         scope.ZeroPosition.Y += (int)(y - lastPosition.Y);

                                                         lastPosition.X = e.OffsetX;
                                                         lastPosition.Y = e.OffsetY;
                                                     }
                                                 }));



            element[0].Style.Display = "inline-block";
            var context = (CanvasRenderingContext2D)((CanvasElement)element[0]).GetContext(CanvasContextId.Render2D);
            scope.Scale = 1;
            scope.ZeroPosition = new Point(0, 0);

            Action updatePieceLayout = () =>
            {
                context.Canvas.Width = context.Canvas.Width;

                context.Me().webkitImageSmoothingEnabled = false;
                context.Me().mozImageSmoothingEnabled = false;
                context.Me().imageSmoothingEnabled = false;

                context.FillStyle = "#FFFFFF";
                context.FillRect(0, 0, scope.Width, scope.Height);

                context.BeginPath();
                context.Rect(0, 0, scope.Width, scope.Height);
                context.Clip();
                context.ClosePath();

                context.Translate(scope.ZeroPosition.X, scope.ZeroPosition.Y);
                context.Scale(scope.Scale, scope.Scale);
                scope.PieceLayout.DrawUI(context, scope.ShowImages, scope.PieceLayout.Pieces.IndexOf(scope.SelectedPieceLayoutPiece), scope.ObjectData);
            };

            scope.Watch("pieceLayout", updatePieceLayout);
            scope.Watch("pieceLayout.pieces", updatePieceLayout, true);
            scope.Watch("scale", updatePieceLayout);
            scope.Watch("showImages", updatePieceLayout);
            scope.Watch("zeroPosition", updatePieceLayout, true);
            scope.Watch("selectedPieceLayoutPiece", updatePieceLayout);

        }
 private static void OnResizeSearchResults(jQueryObject searchResultsDiv)
 {
     int height = jQuery.Window.GetHeight();
     searchResultsDiv.Height(height - 30);
 }
        private static void OnResizeSearchResults(jQueryObject searchResultsDiv)
        {
            int height = jQuery.Window.GetHeight();

            searchResultsDiv.Height(height - 30);
        }
        private void LinkFn(CanvasTileChunkScope scope, jQueryObject element, dynamic attr)
        {
            element.Width(scope.Width);
            element.Height(scope.Height);
            if (scope.Edit)
            {
                element.Click(ev =>
                              {
                                  if (scope.TileChunk == null) return;
                                  var x = ev.OffsetX;
                                  var y = ev.OffsetY;


                                  var _x = (int)(x / ((double)scope.Width / TileChunk.Size));
                                  var _y = (int)(y / ((double)scope.Height / TileChunk.Size));

                                  scope.DebugDrawOptions.OutlineTilePiece = scope.TileChunk.GetTilePieceInfo(_x, _y, true);

                              });
            }
            var context = (CanvasRenderingContext2D)((CanvasElement)element[0]).GetContext(CanvasContextId.Render2D);
            Action updateTileChunk = () =>
                                 {
                                     if (scope.TileChunk == null) return;
                                     var drawOptions = scope.DrawOptions ?? DefaultDrawOptions;

                                     context.Canvas.Width = context.Canvas.Width;

                                     context.Me().webkitImageSmoothingEnabled = false;
                                     context.Me().mozImageSmoothingEnabled = false;
                                     context.Me().imageSmoothingEnabled = false;

                                     context.Scale(scope.Width / ((double)TileChunk.Size), scope.Height / ((double)TileChunk.Size));
                                     if (drawOptions.ShowLowLayer && !scope.TileChunk.OnlyForeground())
                                         scope.TileChunk.Draw(context, new Point(0, 0), ChunkLayer.Low);
                                     if (drawOptions.ShowHighLayer && !scope.TileChunk.OnlyBackground())
                                         scope.TileChunk.Draw(context, new Point(0, 0), ChunkLayer.High);

                                     if (scope.DebugDrawOptions != null)
                                     {
                                         if (drawOptions.ShowLowLayer && !scope.TileChunk.OnlyForeground())
                                             scope.TileChunk.DrawAnimationDebug(context, new Point(0, 0), ChunkLayer.Low, scope.DebugDrawOptions);
                                         if (drawOptions.ShowHighLayer && !scope.TileChunk.OnlyBackground())
                                             scope.TileChunk.DrawAnimationDebug(context, new Point(0, 0), ChunkLayer.High, scope.DebugDrawOptions);
                                     }
                                 };

            scope.Watch("tileChunk", updateTileChunk);
            scope.Watch("drawOptions", updateTileChunk, true);
            scope.Watch("debugDrawOptions", updateTileChunk, true);
            scope.Watch("tileChunk.currentTileAnimationFrameIndexCache", updateTileChunk, true);
            scope.Watch("tileChunk.currentPaletteAnimationFrameIndexCache", updateTileChunk, true);

            Window.SetInterval(() =>
                               {
                                   if (scope.TileChunk == null) return;
                                   if (!scope.TileChunk.NeverAnimates())
                                   {
                                       if (scope.ShouldAnimate)
                                       {
                                           updateTileChunk();
                                       }
                                       else
                                           scope.Digest();
                                   }
                               }, 1000 / 60);
        }