Ejemplo n.º 1
0
        private void chooseimage()
        {
            //April 6th, birthday of windows 3.1

            if (DateTime.Now.Month == 4 && DateTime.Now.Day == 6)
            {
                useBackground = panWin31.BackgroundImage;
            }
            else
            {
                //select a random start image from the available start images.
                Image[] selectfrom = new Image[] { panStandard.BackgroundImage, panStandard2.BackgroundImage, panStandard3.BackgroundImage };

                Image useimage = selectfrom[rgen.Next(selectfrom.Length)];



                useBackground = useimage;
            }


            //new as of July 14th 2011: colourize to a random hue 50% of the time.
            if (rgen.NextDouble() > 0.5d)
            {
                //choose a random colour...
                Color           colourizeto     = new HSLColor(rgen.NextDouble() * 240, 240, 120);
                ImageAttributes attribcolourize = new ImageAttributes();
                attribcolourize.SetColorMatrix(ColorMatrices.GetColourizer((float)(colourizeto.R) / 255, (float)(colourizeto.G) / 255,
                                                                           (float)(colourizeto.B) / 255));
                useBackground = BCBlockGameState.AppyImageAttributes(useBackground, attribcolourize);
            }
        }
Ejemplo n.º 2
0
        public static StandardImageBackgroundGDI GetStandardBackgroundDrawer(PointF Movement, float fade = 0.4f)
        {
            ImageAttributes useBGAttributes = new ImageAttributes();

            useBGAttributes.SetColorMatrix(ColorMatrices.GetFader(fade));
            var sib = new StandardImageBackgroundGDI(new StandardImageBackgroundDrawGDICapsule()
            {
                _BackgroundImage = TetrisGame.StandardTiledTetrisBackground, theAttributes = useBGAttributes, Movement = Movement
            });

            return(sib);
        }
Ejemplo n.º 3
0
        public static StandardImageBackgroundGDI GetStandardBackgroundDrawer(float fade = 0.4f)
        {
            ImageAttributes useBGAttributes = new ImageAttributes();

            useBGAttributes.SetColorMatrix(ColorMatrices.GetFader(fade));
            double xpoint = 1 + TetrisGame.rgen.NextDouble() * 2;
            double ypoint = 1 + TetrisGame.rgen.NextDouble() * 2;
            var    sib    = new StandardImageBackgroundGDI(new StandardImageBackgroundDrawGDICapsule()
            {
                _BackgroundImage = TetrisGame.StandardTiledTetrisBackground, theAttributes = useBGAttributes, Movement = new PointF((float)xpoint, (float)ypoint)
            });

            return(sib);
        }
        private static DirectXDownloaderPlaneData CreatePlane(DirectXContext dx, int width, int height, DirectXDownloaderFormatPlane plane)
        {
            var config = new DirectXPipelineConfig
            {
                VertexShaderFile     = "format_conversion.hlsl",
                VertexShaderFunction = plane.VS,
                PixelShaderFile      = "format_conversion.hlsl",
                PixelShaderFunction  = plane.PS,
            };

            var pipeline = new DirectXPipeline <ConverterFilterConstantBuffer>(config, dx);

            pipeline.SetDebugColor(0, 0, 0, 1);
            pipeline.SetPosition(DirectXPipelineConfig.FullRectangle, new Viewport(0, 0, width / plane.WidthFactor, height / plane.HeightFactor));
            var colorMatrix = ColorMatrices.GetInverted(ColorMatrices.Full709);
            var cm          = colorMatrix.Values;
            var cb          = new ConverterFilterConstantBuffer
            {
                width      = width,
                height     = height,
                width_i    = 1.0f / width,
                width_d2   = width / 2,
                height_d2  = height / 2,
                width_x2_i = 0.5f / width,

                color_vec0      = new Vector4(cm[0], cm[1], cm[2], cm[3]),
                color_vec1      = new Vector4(cm[4], cm[5], cm[6], cm[7]),
                color_vec2      = new Vector4(cm[8], cm[9], cm[10], cm[11]),
                color_range_min = new Vector3(0.0f, 0.0f, 0.0f),
                color_range_max = new Vector3(1.0f, 1.0f, 1.0f),
            };

            pipeline.SetConstantBuffer(cb, false);

            return(new DirectXDownloaderPlaneData
            {
                Format = plane,
                Pipeline = pipeline,
                GpuTexture = dx.Pool.Get("downloadGpu", DirectXResource.Desc(width / plane.WidthFactor, height / plane.HeightFactor, plane.Format)),
                CpuTexture = dx.Pool.Get("downloadCpu", DirectXResource.Desc(width / plane.WidthFactor, height / plane.HeightFactor, plane.Format, BindFlags.None, ResourceUsage.Staging, ResourceOptionFlags.None, CpuAccessFlags.Read))
            });
        }
        public void DrawProc(GameplayGameState pState, IStateOwner pOwner, Graphics g, RectangleF Bounds)
        {
            if (useBackground == null || !StoredBackground.Equals(Bounds) || pState.DoRefreshBackground)
            {
                RefreshBackground(pState, Bounds);
            }

            g.DrawImage(useBackground, Bounds);
            var PlayField = pState.PlayField;

            if (PlayField != null)
            {
                PlayField.Draw(pOwner, g, Bounds);
            }


            foreach (var activeblock in PlayField.BlockGroups)
            {
                int dl        = 0;
                var GrabGhost = pState.GetGhostDrop(pOwner, activeblock, out dl, 3);
                if (GrabGhost != null)
                {
                    var BlockWidth  = PlayField.GetBlockWidth(Bounds);
                    var BlockHeight = PlayField.GetBlockHeight(Bounds);

                    foreach (var iterateblock in activeblock)
                    {
                        RectangleF BlockBounds = new RectangleF(BlockWidth * (GrabGhost.X + iterateblock.X), BlockHeight * (GrabGhost.Y + iterateblock.Y - 2), PlayField.GetBlockWidth(Bounds), PlayField.GetBlockHeight(Bounds));
                        TetrisBlockDrawGDIPlusParameters tbd = new TetrisBlockDrawGDIPlusParameters(g, BlockBounds, GrabGhost, pOwner.Settings);
                        ImageAttributes Shade = new ImageAttributes();
                        Shade.SetColorMatrix(ColorMatrices.GetFader(0.5f));
                        tbd.ApplyAttributes = Shade;
                        //tbd.OverrideBrush = GhostBrush;
                        var GetHandler = RenderingProvider.Static.GetHandler(typeof(Graphics), iterateblock.Block.GetType(), typeof(TetrisBlockDrawGDIPlusParameters));
                        GetHandler.Render(pOwner, tbd.g, iterateblock.Block, tbd);
                        //iterateblock.Block.DrawBlock(tbd);
                    }
                }
            }
        }
 private void RefreshBackground(GameplayGameState pState, RectangleF buildSize)
 {
     StoredBackground = buildSize;
     useBackground    = new Bitmap((int)buildSize.Width, (int)buildSize.Height, PixelFormat.Format32bppPArgb);
     using (Graphics bgg = Graphics.FromImage(useBackground))
     {
         var bgdrawdata = pState.PlayField.Theme.GetThemePlayFieldBackground(pState.PlayField, pState.GameHandler);
         var drawbg     = bgdrawdata.BackgroundImage;
         bgg.CompositingQuality = CompositingQuality.AssumeLinear;
         bgg.InterpolationMode  = InterpolationMode.NearestNeighbor;
         bgg.SmoothingMode      = SmoothingMode.HighSpeed;
         if (bgdrawdata.TintColor != Color.Transparent)
         {
             ImageAttributes useAttributes = new ImageAttributes();
             var             getmatrix     = ColorMatrices.GetColourizer(bgdrawdata.TintColor);
             useAttributes.SetColorMatrix(getmatrix);
             bgg.DrawImage(drawbg, new RectangleF(0f, 0f, buildSize.Width, buildSize.Height), useAttributes);
         }
         else
         {
             bgg.DrawImage(drawbg, new RectangleF(0f, 0f, buildSize.Width, buildSize.Height), new RectangleF(0f, 0f, drawbg.Width, drawbg.Height), GraphicsUnit.Pixel);
         }
     }
 }
Ejemplo n.º 7
0
        public override void RenderStats(IStateOwner pOwner, Graphics pRenderTarget, GameplayGameState Source, BaseDrawParameters Element)
        {
            var Bounds = Element.Bounds;
            var g      = pRenderTarget;

            bool RedrawsNeeded = !LastDrawStat.Equals(Bounds);

            LastDrawStat = Bounds;
            if (StatisticsBackground == null || RedrawsNeeded || GeneratedImageTheme != Source.PlayField.Theme)
            {
                GenerateStatisticsBackground(Source);
            }

            g.DrawImage(StatisticsBackground, Bounds);
            //g.Clear(Color.Black);
            if (!Source.HasTetrominoImages() || RedrawsNeeded)
            {
                RedrawStatusbarTetrominoBitmaps(pOwner, Source, Bounds);
            }

            lock (Source.LockTetImageRedraw)
            {
                var    useStats = Source.GameStats;
                double Factor   = Bounds.Height / 644d;
                int    DesiredFontPixelHeight = (int)(Bounds.Height * (23d / 644d));
                using (Font standardFont = new Font(TetrisGame.RetroFont, DesiredFontPixelHeight, FontStyle.Bold, GraphicsUnit.Pixel))
                {
                    var LocalScores    = Source.GetLocalScores();
                    var TopScore       = LocalScores == null ? 0 : LocalScores.GetScores().First().Score;
                    int MaxScoreLength = Math.Max(TopScore.ToString().Length, useStats.Score.ToString().Length);

                    String CurrentScoreStr = useStats.Score.ToString().PadLeft(MaxScoreLength + 2);
                    String TopScoreStr     = TopScore.ToString().PadLeft(MaxScoreLength + 2);
                    //TODO: redo this segment separately, so we can have the labels left-aligned and the values right-aligned.
                    // String BuildStatString = "Time:  " + FormatGameTime(pOwner).ToString().PadLeft(MaxScoreLength + 2) + "\n" +
                    //                          "Score: " + CurrentScoreStr + "\n" +
                    //                          "Top:   " + TopScoreStr + " \n" +
                    //                          "Lines: " + GameStats.LineCount.ToString().PadLeft(MaxScoreLength+2);

                    g.FillRectangle(LightenBrush, 0, 5, Bounds.Width, (int)(450 * Factor));
                    String[] StatLabels   = new string[] { "Time:", "Score:", "Top:", "Lines:" };
                    int      LineCount    = Source.GameStats is TetrisStatistics ? (Source.GameStats as TetrisStatistics).LineCount : 0;
                    String[] StatValues   = new string[] { FormatGameTime(pOwner), useStats.Score.ToString(), TopScore.ToString(), LineCount.ToString() };
                    Point    StatPosition = new Point((int)(7 * Factor), (int)(7 * Factor));

                    int CurrentYPosition = StatPosition.Y;
                    for (int statindex = 0; statindex < StatLabels.Length; statindex++)
                    {
                        var   MeasureLabel = g.MeasureString(StatLabels[statindex], standardFont);
                        var   MeasureValue = g.MeasureString(StatValues[statindex], standardFont);
                        float LargerHeight = Math.Max(MeasureLabel.Height, MeasureValue.Height);

                        //we want to draw the current stat label at position StatPosition.X,CurrentYPosition...

                        TetrisGame.DrawText(g, standardFont, StatLabels[statindex], Brushes.Black, Brushes.White, StatPosition.X, CurrentYPosition);

                        //we want to draw the current stat value at Bounds.Width-ValueWidth.
                        TetrisGame.DrawText(g, standardFont, StatValues[statindex], Brushes.Black, Brushes.White, (float)(Bounds.Width - MeasureValue.Width - (5 * Factor)), CurrentYPosition);

                        //add the larger of the two heights to the current Y Position.
                        CurrentYPosition += (int)LargerHeight;
                        CurrentYPosition += 2;
                    }



                    Type[] useTypes = new Type[] { typeof(Tetromino_I), typeof(Tetromino_O), typeof(Tetromino_J), typeof(Tetromino_T), typeof(Tetromino_L), typeof(Tetromino_S), typeof(Tetromino_Z) };

                    int[] PieceCounts = null;

                    if (useStats is TetrisStatistics ts)
                    {
                        PieceCounts = new int[] { ts.I_Piece_Count, ts.O_Piece_Count, ts.J_Piece_Count, ts.T_Piece_Count, ts.L_Piece_Count, ts.S_Piece_Count, ts.Z_Piece_Count };
                    }
                    else
                    {
                        PieceCounts = new int[] { 0, 0, 0, 0, 0, 0, 0 };
                    }


                    int             StartYPos = (int)(140 * Factor);
                    int             useXPos   = (int)(30 * Factor);
                    ImageAttributes ShadowTet = TetrisGame.GetShadowAttributes();
                    if (Source.GameHandler is StandardTetrisHandler)
                    {
                        for (int i = 0; i < useTypes.Length; i++)
                        {
                            PointF BaseCoordinate = new PointF(useXPos, StartYPos + (int)((float)i * (40d * Factor)));
                            PointF TextPos        = new PointF(useXPos + (int)(100d * Factor), BaseCoordinate.Y);
                            String StatText       = "" + PieceCounts[i];
                            SizeF  StatTextSize   = g.MeasureString(StatText, standardFont);
                            String sNomTypeKey    = Source.PlayField.Theme.GetNominoTypeKey(useTypes[i], Source.GameHandler, Source.PlayField);
                            Image  TetrominoImage = TetrisGame.Choose(Source.NominoImages[sNomTypeKey]);
                            PointF ImagePos       = new PointF(BaseCoordinate.X, BaseCoordinate.Y + (StatTextSize.Height / 2 - TetrominoImage.Height / 2));

                            g.DrawImage(TetrominoImage, ImagePos);
                            g.DrawString(StatText, standardFont, Brushes.White, new PointF(TextPos.X + 4, TextPos.Y + 4));
                            g.DrawString(StatText, standardFont, Brushes.Black, TextPos);
                        }
                    }

                    Point NextDrawPosition = new Point((int)(40f * Factor), (int)(420 * Factor));
                    Size  NextSize         = new Size((int)(200f * Factor), (int)(200f * Factor));
                    Point CenterPoint      = new Point(NextDrawPosition.X + NextSize.Width / 2, NextDrawPosition.Y + NextSize.Height / 2);
                    //now draw the "Next" Queue. For now we'll just show one "next" item.
                    if (Source.NextBlocks.Count > 0)
                    {
                        var QueueList = Source.NextBlocks.ToArray();
                        //(from t in QueueList select Source.GetTetrominoSKBitmap(pOwner,t)).ToArray()
                        Image[] NextTetrominoes = (from t in QueueList select Source.GetTetrominoImage(pOwner, t)).ToArray(); //  TetrisGame.Choose(Source.NominoImages[Source.PlayField.Theme.GetNominoKey(t,Source.GameHandler,Source.PlayField)])).ToArray();
                        Image   DisplayBox      = TetrisGame.Imageman["display_box"];
                        //draw it at 40,420. (Scaled).
                        float ScaleDiff = 0;
                        iActiveSoundObject PlayingMusic;
                        if ((PlayingMusic = TetrisGame.Soundman.GetPlayingMusic_Active()) != null)
                        {
                            Source.StoredLevels.Enqueue(PlayingMusic.Level);
                        }

                        if (Source.StoredLevels.Count >= 4)
                        {
                            ScaleDiff = Math.Min(30, 10 * Source.StoredLevels.Dequeue());
                        }

                        if (!TetrisGame.DJMode)
                        {
                            ScaleDiff = 0;
                        }

                        g.DrawImage
                            (DisplayBox,
                            new Rectangle(new Point((int)(NextDrawPosition.X - ScaleDiff), (int)(NextDrawPosition.Y - ScaleDiff)), new Size((int)(NextSize.Width + (ScaleDiff * 2)), (int)(NextSize.Height + (ScaleDiff * 2)))), 0, 0, DisplayBox.Width, DisplayBox.Height, GraphicsUnit.Pixel);

                        g.FillEllipse(Brushes.Black, CenterPoint.X - 5, CenterPoint.Y - 5, 10, 10);

                        for (int i = NextTetrominoes.Length - 1; i > -1; i--)
                        {
                            double StartAngle         = Math.PI;
                            double AngleIncrementSize = (Math.PI * 1.8) / (double)NextTetrominoes.Length;
                            //we draw starting at StartAngle, in increments of AngleIncrementSize.
                            //i is the index- we want to increase the angle by that amount (well, obviously, I suppose...

                            double UseAngleCurrent = StartAngle + AngleIncrementSize * (float)i + Source.NextAngleOffset;

                            double UseXPosition = CenterPoint.X + ((float)((NextSize.Width) / 2.2) * Math.Cos(UseAngleCurrent));
                            double UseYPosition = CenterPoint.Y + ((float)((NextSize.Height) / 2.2) * Math.Sin(UseAngleCurrent));


                            var NextTetromino = NextTetrominoes[i];

                            float Deviation = (i - NextTetrominoes.Length / 2);
                            Point Deviate   = new Point((int)(Deviation * 20 * Factor), (int)(Deviation * 20 * Factor));

                            Point DrawTetLocation = new Point((int)UseXPosition - (NextTetromino.Width / 2), (int)UseYPosition - NextTetromino.Height / 2);
                            //Point DrawTetLocation = new Point(Deviate.X + (int)(NextDrawPosition.X + ((float)NextSize.Width / 2) - ((float)NextTetromino.Width / 2)),
                            //    Deviate.Y + (int)(NextDrawPosition.Y + ((float)NextSize.Height / 2) - ((float)NextTetromino.Height / 2)));
                            double AngleMovePercent = Source.NextAngleOffset / AngleIncrementSize;
                            double NumAffect        = Source.NextAngleOffset == 0 ? 0 : AngleIncrementSize / Source.NextAngleOffset;
                            Size   DrawTetSize      = new Size
                                                      (
                                (int)((float)NextTetromino.Width * (0.3 + (1 - ((float)(i) * 0.15f) - .15f * AngleMovePercent))),
                                (int)((float)NextTetromino.Height * (0.3 + (1 - ((float)(i) * 0.15f) - .15f * AngleMovePercent))));


                            //g.TranslateTransform(CenterPoint.X,CenterPoint.Y);

                            g.TranslateTransform(DrawTetLocation.X + DrawTetSize.Width / 2, DrawTetLocation.Y + DrawTetSize.Width / 2);


                            double DrawTetAngle = UseAngleCurrent;
                            DrawTetAngle += (Math.PI * AngleMovePercent);
                            float useDegrees = 180 + (float)(DrawTetAngle * (180 / Math.PI));

                            g.RotateTransform((float)useDegrees);

                            g.TranslateTransform(-(DrawTetLocation.X + DrawTetSize.Width / 2), -(DrawTetLocation.Y + DrawTetSize.Height / 2));
                            //g.TranslateTransform(-CenterPoint.X,-CenterPoint.Y);


                            if (DrawTetSize.Width > 0 && DrawTetSize.Height > 0)
                            {
                                //ImageAttributes Shade = GetShadowAttributes(1.0f - ((float)i * 0.3f));
                                ImageAttributes Shade = new ImageAttributes();
                                Shade.SetColorMatrix(ColorMatrices.GetFader(1.0f - ((float)i * 0.1f)));


                                g.DrawImage
                                    (NextTetromino, new Rectangle((int)DrawTetLocation.X, (int)DrawTetLocation.Y, DrawTetSize.Width, DrawTetSize.Height), 0f, 0f,
                                    (float)NextTetromino.Width, (float)NextTetromino.Height, GraphicsUnit.Pixel, Shade);
                            }

                            g.ResetTransform();
                        }
                    }

                    if (Source.HoldBlock != null)
                    {
                        var   GetKey        = Source.PlayField.Theme.GetNominoKey(Source.HoldBlock, Source.GameHandler, Source.PlayField);
                        Image HoldTetromino = Source.GetTetrominoImage(pOwner, Source.HoldBlock);
                        g.DrawImage(HoldTetromino, CenterPoint.X - HoldTetromino.Width / 2, CenterPoint.Y - HoldTetromino.Height / 2);
                    }
                }
            }
        }