private static void puzzleCleared(int shapesUsed)
        {
            mainScreen.HelpPanel.Off(true);

            ResetCurrentPuzzleShapes(true, false);
            CurrentPuzzle.IsCleared = true;
            CurrentPuzzleSet.UnlockNextPuzzle();

            // update statistics & build solution
            PlayerSolution solution = new PlayerSolution();

            solution.PuzzleKey      = CurrentPuzzle.Key;
            solution.SolutionShapes = new List <PlayerSolutionShape>();

            foreach (Shape shape in CurrentPuzzleSet.ShapesDict.Values)
            {
                if (shape.IsValid)
                {
                    Vector2 position = new Vector2(shape.DestRect.X, shape.DestRect.Y);

                    PlayerSolutionShape userShape = new PlayerSolutionShape();
                    userShape.ShapeKey            = shape.Key;
                    userShape.OriginPoint         = PuzzleEngine.GetPuzzleTilePosition(new Vector2(shape.DestRect.X, shape.DestRect.Y));
                    userShape.IsFlippedHorizontal = shape.IsFlippedHorizontal;
                    userShape.IsFlippedVertical   = shape.IsFlippedVertical;
                    userShape.RotationIdx         = shape.CurrentRotationIdx;

                    solution.SolutionShapes.Add(userShape);

                    CurrentPuzzle.Statistics.ShapesUsedKeys.Add(shape.Key);
                }
            }

            CurrentPuzzle.PlayerSolution = solution;
            CurrentPuzzle.SetCompletedStats(shapesUsed, PuzzleTimer);
            CurrentPuzzleSet.Statistics      += CurrentPuzzle.Statistics;
            Cursor.CursorMode                 = CursorState.Hidden;
            CurrentPuzzle.IsRenderPortrait    = true;
            SelectedPickerEntry.IsRenderEntry = true;
            IsCheckRender = true;
            MainScreen.PuzzlePanel.ResetPuzzleName();
            MainScreen.PuzzlePanel.InitSolutionDict(solution.SolutionShapes);
            MainScreen.PuzzlePanel.PanelState   = PuzzlePanel.PuzzlePanelState.Cleared;
            MainScreen.PuzzlePanel.ClearedState = PuzzlePanel.PuzzleClearedState.Prepare;
        }
        private static Texture2D renderPuzzlePortraitTexture(Puzzle puzzle, Dictionary <int, Shape> shapesDict)
        {
            SpriteBatch    spriteBatch = Session.ScreenManager.SpriteBatch;
            GraphicsDevice device      = Session.ScreenManager.GraphicsDevice;

            renderTarget = new RenderTarget2D(device,
                                              (int)PuzzleSet.BackgroundSize.X,
                                              (int)PuzzleSet.BackgroundSize.Y,
                                              false,
                                              SurfaceFormat.Color,
                                              DepthFormat.None,
                                              device.PresentationParameters.MultiSampleCount,
                                              RenderTargetUsage.DiscardContents);

            device.SetRenderTarget(renderTarget);

            spriteBatch.Begin();

            spriteBatch.Draw(PuzzleEngine.CurrentPuzzleSet.GetForegroundTex(puzzle.ForegroundTextureName),
                             Vector2.Zero,
                             null,
                             Color.White,
                             0f,
                             Vector2.Zero,
                             1f,
                             SpriteEffects.None,
                             0);

            PuzzleEngine.DrawTileLayers(spriteBatch, puzzle, Vector2.Zero);

            if (puzzle.IsCleared)
            {
                // no idea why i have to add 6 px to the offset??
                Vector2 offset = new Vector2(-puzzle.TileSize.X / 2 + 6, -puzzle.TileSize.Y / 2 + 6);

                // account for gridshift in puzzle
                if (puzzle.IsGridShiftX && puzzle.IsGridShiftY)
                {
                    offset += new Vector2(puzzle.TileSize.X / 2, puzzle.TileSize.Y / 2);
                }
                else if (puzzle.IsGridShiftX)
                {
                    offset.X += (puzzle.TileSize.X / 2);
                }
                else if (puzzle.IsGridShiftY)
                {
                    offset.Y += (puzzle.TileSize.Y / 2);
                }

                foreach (PlayerSolutionShape pss in puzzle.PlayerSolution.SolutionShapes)
                {
                    shapesDict[pss.ShapeKey].Render(spriteBatch, offset, pss, 1);
                }
            }

            spriteBatch.End();

            device.SetRenderTarget(null);
//            renderTarget.SaveAsJpeg(new FileStream("puzzle_"+puzzle.Place+"_"+puzzle.Key+".jpg", FileMode.Create), renderTarget.Width, renderTarget.Height);
            return(renderTarget);
        }