コード例 #1
0
        private void add(Vector2 offset)
        {
            pTexture trailTexture = SkinManager.t_cursortrail;

            if (trailTexture == null)
            {
                return;
            }

            float drawSize = trailTexture.DisplayWidth * GameBase.WindowManager.RatioInverse * osu.Input.InputManager.s_Cursor.Scale * osu.Input.InputManager.s_Cursor.VectorScale.X;

            RectangleF texCoordsRect = new RectangleF(0, 0,
                                                      (float)trailTexture.Width / TextureGl.GetPotDimension(trailTexture.Width),
                                                      (float)trailTexture.Height / TextureGl.GetPotDimension(trailTexture.Height));

            int   vertexIndex = currentIndex * 4;
            float fadeTime    = fadeClock + 1f;

            vertexBuffer.Vertices[vertexIndex].Position        = offset + new Vector2(-drawSize / 2, -drawSize / 2);
            vertexBuffer.Vertices[vertexIndex].TexturePosition = new Vector2(0, 0);
            vertexBuffer.Vertices[vertexIndex].Colour          = Color.White;
            vertexBuffer.Vertices[vertexIndex].Time            = fadeTime;

            vertexBuffer.Vertices[vertexIndex + 1].Position        = offset + new Vector2(-drawSize / 2, drawSize / 2);
            vertexBuffer.Vertices[vertexIndex + 1].TexturePosition = new Vector2(0, texCoordsRect.Height);
            vertexBuffer.Vertices[vertexIndex + 1].Colour          = Color.White;
            vertexBuffer.Vertices[vertexIndex + 1].Time            = fadeTime;

            vertexBuffer.Vertices[vertexIndex + 2].Position        = offset + new Vector2(drawSize / 2, drawSize / 2);
            vertexBuffer.Vertices[vertexIndex + 2].TexturePosition = new Vector2(texCoordsRect.Width, texCoordsRect.Height);
            vertexBuffer.Vertices[vertexIndex + 2].Colour          = Color.White;
            vertexBuffer.Vertices[vertexIndex + 2].Time            = fadeTime;

            vertexBuffer.Vertices[vertexIndex + 3].Position        = offset + new Vector2(drawSize / 2, -drawSize / 2);
            vertexBuffer.Vertices[vertexIndex + 3].TexturePosition = new Vector2(texCoordsRect.Width, 0);
            vertexBuffer.Vertices[vertexIndex + 3].Colour          = Color.White;
            vertexBuffer.Vertices[vertexIndex + 3].Time            = fadeTime;

            fadeTimes[currentIndex]   = fadeTime;
            needsUpload[currentIndex] = true;

            currentIndex = (currentIndex + 1) % MAX_SPRITES;
        }
コード例 #2
0
        internal override pTexture CreateText(string text, float size, OpenTK.Vector2 restrictBounds, OpenTK.Graphics.Color4 Color4, bool shadow, bool bold, bool underline, TextAlignment alignment, bool forceAa, out OpenTK.Vector2 measured, OpenTK.Graphics.Color4 background, OpenTK.Graphics.Color4 border, int borderWidth, bool measureOnly, string fontFace)
        {
            //UIFont font = bold ? UIFont.FromName("GillSans-Bold", size) : UIFont.FromName("GillSans",size);
            //UIFont font = bold ? UIFont.BoldSystemFontOfSize(size) : UIFont.SystemFontOfSize(size);
            UIFont font = UIFont.FromName(bold ? "Futura-CondensedExtraBold" : "Futura-Medium",size);

            CGSize actualSize = CGSize.Empty;

            // Render the text to a UILabel to calculate sizing
            // and line-wrapping, and then copy the pixels to our texture buffer.
            UILabel textLabel = new UILabel();
            textLabel.Font = font;
            textLabel.BackgroundColor = UIColor.Clear;
            textLabel.TextColor = UIColor.White;
            textLabel.LineBreakMode = UILineBreakMode.WordWrap;
            textLabel.Lines = 0; // Needed for multiple lines
            textLabel.Text = text;

            textLabel.TextAlignment = UITextAlignment.Left;
            switch (alignment) {
            case TextAlignment.Centre:
                textLabel.TextAlignment = UITextAlignment.Center;
                break;
            case TextAlignment.Right:
                textLabel.TextAlignment = UITextAlignment.Right;
                break;
            }

            if (restrictBounds == Vector2.Zero)
            {
                textLabel.SizeToFit();
                actualSize = textLabel.Frame.Size;

                restrictBounds = new Vector2((float)actualSize.Width, (float)actualSize.Height);
            }
            else if (restrictBounds.Y == 0)
            {
                SizeF boundsSize = new SizeF (restrictBounds.X, GameBase.NativeSize.Height);
                actualSize = textLabel.SizeThatFits(boundsSize);
                textLabel.Frame = new CGRect(CGPoint.Empty, actualSize);

                restrictBounds = new Vector2((float)actualSize.Width, (float)actualSize.Height);
            }

            int width = TextureGl.GetPotDimension((int)restrictBounds.X);
            int height = TextureGl.GetPotDimension((int)restrictBounds.Y);

            IntPtr data = Marshal.AllocHGlobal(width * height);
            unsafe {
                byte* bytes = (byte*)data;
                for (int i = width * height - 1; i >= 0; i--) bytes[i] = 0;
            }

            using (CGColorSpace colorSpace = CGColorSpace.CreateDeviceGray())
            using (CGBitmapContext context = new CGBitmapContext(data, width, height, 8, width, colorSpace,CGImageAlphaInfo.None))
            {
                context.TranslateCTM(0, height);
                context.ScaleCTM(1, -1);

                UIGraphics.PushContext(context);

                textLabel.SetNeedsDisplay();
                textLabel.Layer.DrawInContext (context);
                
                UIGraphics.PopContext();

                measured = new Vector2((float)actualSize.Width, (float)actualSize.Height);

    			SpriteManager.TexturesEnabled = true;

                TextureGl gl = new TextureGl(width, height);
                gl.SetData(data, 0, All.Alpha);

                Marshal.FreeHGlobal(data);

                return new pTexture(gl, (int)actualSize.Width, (int)actualSize.Height);
            }
        }
コード例 #3
0
        public override bool Draw()
        {
            if (bypass)
            {
                return(false);
            }

            SpriteManager.Current.SetBlending(Additive);

            pTexture texture = Texture;

            if (texture == null || texture.IsDisposed)
            {
                return(true);
            }

            Vector2 d = new Vector2(drawRectangle.X + drawOriginScaled.X, drawRectangle.Y + drawOriginScaled.Y);

            if (vertexBuffer == null)
            {
                vertexBuffer = new QuadVertexBuffer <ParticleVertex2d>(amountParticles, BufferUsageHint.StaticDraw);

                RectangleF texCoordsRect = new RectangleF(0, 0,
                                                          (float)texture.Width / TextureGl.GetPotDimension(texture.Width),
                                                          (float)texture.Height / TextureGl.GetPotDimension(texture.Height));

                for (int i = 0; i < amountParticles; ++i)
                {
                    int vertexIndex = i * 4;

                    int     time      = RNG.Next(500, 1200);
                    double  angle     = RNG.NextDouble(Math.PI * 2.0);
                    Vector2 direction = drawScaleVector * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * (float)RNG.NextDouble(radius);

                    if (time > maxTime)
                    {
                        maxTime = time;
                    }

                    vertexBuffer.Vertices[vertexIndex + 0].Position        = d + new Vector2(-drawRectangle.Width / 2, -drawRectangle.Height / 2);
                    vertexBuffer.Vertices[vertexIndex + 0].TexturePosition = new Vector2(0, 0);
                    vertexBuffer.Vertices[vertexIndex + 0].Colour          = Color.White;
                    vertexBuffer.Vertices[vertexIndex + 0].Time            = time;
                    vertexBuffer.Vertices[vertexIndex + 0].Direction       = direction;

                    vertexBuffer.Vertices[vertexIndex + 1].Position        = d + new Vector2(-drawRectangle.Width / 2, drawRectangle.Height / 2);
                    vertexBuffer.Vertices[vertexIndex + 1].TexturePosition = new Vector2(0, texCoordsRect.Height);
                    vertexBuffer.Vertices[vertexIndex + 1].Colour          = Color.White;
                    vertexBuffer.Vertices[vertexIndex + 1].Time            = time;
                    vertexBuffer.Vertices[vertexIndex + 1].Direction       = direction;

                    vertexBuffer.Vertices[vertexIndex + 2].Position        = d + new Vector2(drawRectangle.Width / 2, drawRectangle.Height / 2);
                    vertexBuffer.Vertices[vertexIndex + 2].TexturePosition = new Vector2(texCoordsRect.Width, texCoordsRect.Height);
                    vertexBuffer.Vertices[vertexIndex + 2].Colour          = Color.White;
                    vertexBuffer.Vertices[vertexIndex + 2].Time            = time;
                    vertexBuffer.Vertices[vertexIndex + 2].Direction       = direction;

                    vertexBuffer.Vertices[vertexIndex + 3].Position        = d + new Vector2(drawRectangle.Width / 2, -drawRectangle.Height / 2);
                    vertexBuffer.Vertices[vertexIndex + 3].TexturePosition = new Vector2(texCoordsRect.Width, 0);
                    vertexBuffer.Vertices[vertexIndex + 3].Colour          = Color.White;
                    vertexBuffer.Vertices[vertexIndex + 3].Time            = time;
                    vertexBuffer.Vertices[vertexIndex + 3].Direction       = direction;
                }

                vertexBuffer.Update();
            }

            if (texture.TextureGl != null && texture.TextureGl.Bind())
            {
                OsuGlControl.ParticleShader.Properties[@"g_Gravity"]   = gravity;
                OsuGlControl.ParticleShader.Properties[@"g_FadeClock"] = (float)(getClockTime() - startTime);
                OsuGlControl.ParticleShader.Begin();
                vertexBuffer.Draw();
                OsuGlControl.ParticleShader.End();
            }

            return(true);
        }