Exemple #1
0
        public override void DrawScene(SDLRenderer renderer)
        {
            // You don't really want to uncomment the next line...
            // Console.WriteLine( "exBlitTextures.DrawScene : Event from SDLRenderer.DrawScene" );

            var tW   = texture.Width;
            var tH   = texture.Height;
            var rect = new SDL.SDL_Rect(0, 0, tW, tH);

            for (int i = 0; i < ITTERATIONS; i++)
            {
                // Adjust color modulation
                var c = Color.FromArgb(
                    random.Next(256),
                    random.Next(256),
                    random.Next(256),
                    random.Next(256)
                    );
                texture.ColorMod = c;

                // Blit the Texture now
                rect.x = random.Next(SDL_WINDOW_WIDTH - tW);
                rect.y = random.Next(SDL_WINDOW_HEIGHT - tH);
                renderer.Blit(rect, texture);
            }
        }
Exemple #2
0
        void BlitAsSprite(SDLRenderer renderer, SDLRenderer.Texture texture, double angle, Color c)
        {
            var pos  = spinCentre.Add(RotateAround(spinDistance, angle));
            var rect = new SDL.SDL_Rect(spriteRect.x + pos.x, spriteRect.y + pos.y, spriteRect.w, spriteRect.h);

            texture.ColorMod = c;
            renderer.Blit(rect, texture);
        }
Exemple #3
0
        public override void DrawScene(SDLRenderer renderer)
        {
            // You don't really want to uncomment the next line...
            // Console.WriteLine( "exDrawText2.DrawScene : Event from SDLRenderer.DrawScene" );

            for (int i = 0; i < ITTERATIONS; i++)
            {
                var rect = new SDL.SDL_Rect(
                    random.Next(SDL_WINDOW_WIDTH - textSize.Width),
                    random.Next(SDL_WINDOW_HEIGHT - textSize.Height),
                    textSize.Width,
                    textSize.Height
                    );
                var c = Color.FromArgb(
                    random.Next(256),
                    random.Next(256),
                    random.Next(256),
                    random.Next(256)
                    );
                textTure.ColorMod = c;
                renderer.Blit(rect, textTure);
            }
        }
Exemple #4
0
        public override void DrawScene(SDLRenderer renderer)
        {
            // You don't really want to uncomment the next line...
            // Console.WriteLine( "exSample1.DrawScene : Event from SDLRenderer.DrawScene" );

            if (true)
            {
                // Draw a couple solid lines over the window
                var p1 = new SDL.SDL_Point(SDL_WINDOW_WIDTH / 2, 0);
                var p2 = new SDL.SDL_Point(SDL_WINDOW_WIDTH / 2, SDL_WINDOW_HEIGHT);
                var p3 = new SDL.SDL_Point(0, SDL_WINDOW_HEIGHT / 2);
                var p4 = new SDL.SDL_Point(SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT / 2);
                var c  = Color.White;
                renderer.DrawLine(p1, p2, c);
                renderer.DrawLine(p3, p4, c);
            }

            if (true)
            {
                // Draw a blue rect
                var rect1 = new SDL.SDL_Rect(32, 32, 64, 64);
                var c     = Color.FromArgb(255, 0, 128, 128);
                renderer.DrawFilledRect(rect1, c);

                // Draw a translucent red rect
                var rect2 = new SDL.SDL_Rect(rect1.x + 32, rect1.y + 32, rect1.w, rect1.h);
                c = Color.FromArgb(128, 255, 0, 0);
                renderer.DrawFilledRect(rect2, c);
                // Outline it
                c = Color.FromArgb(255, 255, 0, 0);
                renderer.DrawRect(rect2, c);

                // Draw a couple translucent lines over the rects
                var p1 = new SDL.SDL_Point(rect1.x, rect1.x);
                var p2 = new SDL.SDL_Point(p1.x + 64, p1.y + 64);
                var p3 = new SDL.SDL_Point(p1.x + 32, p1.y + 64);
                var p4 = new SDL.SDL_Point(p1.x + 64, p1.y + 32);
                c = Color.FromArgb(128, 255, 255, 255);
                renderer.DrawLine(p1, p2, c);
                renderer.DrawLine(p3, p4, c);
            }

            if (true)
            {
                // Draw a yellow circle
                var p1 = new SDL.SDL_Point(192, 64);
                var c  = Color.Yellow;
                renderer.DrawFilledCircle(p1, 32, c);

                // Draw a magenta circle
                var p2 = new SDL.SDL_Point(p1.x + 32, p1.y + 32);
                c = Color.FromArgb(128, 255, 0, 255);
                renderer.DrawFilledCircle(p2, 32, c);
                // Outline it
                c = Color.FromArgb(255, 255, 0, 255);
                renderer.DrawCircle(p2, 32, c);
            }

            if (true)
            {
                var c = Color.White;

                // Blit the surface
                var rect1 = new SDL.SDL_Rect(32, 192, surface.Width, surface.Height);
                surface.ColorMod = c;
                renderer.Blit(rect1, surface);

                // Blit the texture
                var rect2 = new SDL.SDL_Rect(rect1.x + surface.Width / 4, rect1.y + surface.Height / 4, rect1.w, rect1.h);
                texture.ColorMod = c;
                renderer.Blit(rect2, texture);
            }

            if (true)
            {
                // Don't do scene control in DrawScene, this is just an example
                spinAngle += spinStep;
                if (spinAngle > 360.0)
                {
                    spinAngle -= 360.0;
                }

                // Orbit
                var c = Color.FromArgb(255, 64, 64, 64);
                renderer.DrawCircle(spinCentre, (int)spinDistance, c);

                // Blit the surface as a sprite
                BlitAsSprite(renderer, surface, spinAngle, surfaceColor);

                // Blit the texture as a sprite
                BlitAsSprite(renderer, texture, -spinAngle, textureColor);
            }

            if (true)
            {
                // Draw some text
                const string text = "They're Pinky and the Brain!";

                // Solid White Bold
                var c = Color.White;
                var p = new SDL.SDL_Point(32, 384);
                renderer.DrawText(p, font, text, c, SDL_ttf.TTF_STYLE_BOLD);

                // Alpha Red Italic
                c    = Color.FromArgb(128, 255, 0, 0);
                p.y += 16;
                renderer.DrawText(p, font, text, c, SDL_ttf.TTF_STYLE_ITALIC);

                // Solid Green Strike-Through
                c    = Color.FromArgb(255, 0, 255, 0);
                p.y += 16;
                renderer.DrawText(p, font, text, c, SDL_ttf.TTF_STYLE_STRIKETHROUGH);

                // Alpha Blue Underline
                c    = Color.FromArgb(128, 0, 0, 255);
                p.y += 16;
                renderer.DrawText(p, font, text, c, SDL_ttf.TTF_STYLE_UNDERLINE);
            }
        }