Ejemplo n.º 1
0
        internal void PlaceRect(SDL.SDL_Rect node)
        {
            int numRectanglesToProcess = FreeRectangles.Count;

            for (int i = 0; i < numRectanglesToProcess; ++i)
            {
                if (SplitFreeNode(FreeRectangles[i], ref node))
                {
                    FreeRectangles.RemoveAt(i);
                    --i;
                    --numRectanglesToProcess;
                }
            }

            PruneFreeList();

            UsedRectangles.Add(node);
        }
Ejemplo n.º 2
0
        private bool checkCollision(SDL.SDL_Rect a, SDL.SDL_Rect b)
        {
            //The sides of the rectangles
            int leftA, leftB;
            int rightA, rightB;
            int topA, topB;
            int bottomA, bottomB;

            //Calculate the sides of rect A
            leftA   = a.x;
            rightA  = a.x + a.w;
            topA    = a.y;
            bottomA = a.y + a.h;

            //Calculate the sides of rect B
            leftB   = b.x;
            rightB  = b.x + b.w;
            topB    = b.y;
            bottomB = b.y + b.h;

            //If any of the sides from A are outside of B
            if (bottomA <= topB)
            {
                return(false);
            }

            if (topA >= bottomB)
            {
                return(false);
            }

            if (rightA <= leftB)
            {
                return(false);
            }

            if (leftA >= rightB)
            {
                return(false);
            }

            //If none of the sides from A are outside B
            return(true);
        }
Ejemplo n.º 3
0
    static void MoveSprites(System.IntPtr renderer, System.IntPtr sprite)
    {
        SDL.SDL_Rect rect = new SDL.SDL_Rect();
        rect.x = 0; rect.y = 0; rect.w = Sprite_w; rect.h = Sprite_h;

        if (!Skip)
        {
            SDL.SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
            SDL.SDL_RenderClear(renderer);
        }

        for (int i = 0; i < NumSprites; ++i)
        {
            Positions[i].x += Velocities[i].x;
            if ((Positions[i].x < 0) || (Positions[i].x >= (WindowWidth - Sprite_w)))
            {
                Velocities[i].x = -Velocities[i].x;
                Positions[i].x += Velocities[i].x;
            }
            Positions[i].y += Velocities[i].y;
            if ((Positions[i].y < 0) || (Positions[i].y >= (WindowHeight - Sprite_h)))
            {
                Velocities[i].y = -Velocities[i].y;
                Positions[i].y += Velocities[i].y;
            }
            if (!Skip)
            {
                SDL.SDL_RenderCopy(renderer, sprite, ref rect, ref Positions[i]);
            }
        }
        SDL.SDL_Color color = new SDL.SDL_Color {
            r = 0x00, g = 0x00, b = 0xff, a = 0x00
        };
        int x = 0;
        int y = 0;

        DrawText(System.String.Format("こんにちわ世界 \n frame {0}", FrameCount), x, y, color, renderer);
        DrawText(System.String.Format("Memory {0}", System.GC.GetTotalMemory(false)), 0, 120, color, renderer);
        NumFrame++;
        if (!Skip)
        {
            SDL.SDL_RenderPresent(renderer);
        }
    }
Ejemplo n.º 4
0
        private bool checkCollision(Circle a, SDL.SDL_Rect b)
        {
            //Closest point on collision box
            int cX, cY;

            //Find closest x offset
            if (a.x < b.x)
            {
                cX = b.x;
            }
            else if (a.x > b.x + b.w)
            {
                cX = b.x + b.w;
            }
            else
            {
                cX = a.x;
            }

            //Find closest y offset
            if (a.y < b.y)
            {
                cY = b.y;
            }
            else if (a.y > b.y + b.h)
            {
                cY = b.y + b.h;
            }
            else
            {
                cY = a.y;
            }

            //If the closest point is inside the circle
            if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r)
            {
                //This box and the circle have collided
                return(true);
            }

            //If the shapes have not collided
            return(false);
        }
Ejemplo n.º 5
0
        public void DrawText(float x, float y, string text, SDL.SDL_Color color, TextAlignment alignment = TextAlignment.Default, DisplayFont font = null)
        {
            var surfacePtr = SDL_ttf.TTF_RenderUNICODE_Solid(font?.Font ?? _font, text, color);

            SDL.SDL_Surface surface = (SDL.SDL_Surface)Marshal.PtrToStructure(surfacePtr, typeof(SDL.SDL_Surface));
            var             texture = SDL.SDL_CreateTextureFromSurface(_renderer, surfacePtr);
            int             w       = surface.w;
            int             h       = surface.h;
            int             xx      = (int)(x * ActualWidth);
            int             yy      = (int)(y * ActualHeight);

            if (alignment.HasFlag(TextAlignment.HorizontalCenter))
            {
                xx -= w / 2;
            }
            else if (alignment.HasFlag(TextAlignment.HorizontalRight))
            {
                xx -= w;
            }

            if (alignment.HasFlag(TextAlignment.VerticalCenter))
            {
                yy -= h / 2;
            }
            else if (alignment.HasFlag(TextAlignment.VerticalBottom))
            {
                yy -= h;
            }


            SDL.SDL_FreeSurface(surfacePtr);
            var src = new SDL.SDL_Rect()
            {
                x = 0, y = 0, w = w, h = h
            };
            var target = new SDL.SDL_Rect()
            {
                x = xx, y = yy, w = w, h = h
            };

            SDL.SDL_RenderCopy(_renderer, texture, ref src, ref target);
            SDL.SDL_DestroyTexture(texture);
        }
Ejemplo n.º 6
0
        void RenderDateAndTime()
        {
            int x = fontTileSize;

            SDL.SDL_SetRenderTarget(renderer, bufferTexture);
            SDL.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
            SDL.SDL_RenderClear(renderer);
            foreach (Char c in clockTimeString)
            {
                var srcRect = fontRectMap[c];
                var dstRect = new SDL.SDL_Rect()
                {
                    x = x, y = 0, w = fontTileSize, h = fontTileSize
                };
                SDL.SDL_RenderCopy(renderer, fontTexture, ref srcRect, ref dstRect);
                x += fontTileSize;
            }

            x = 0;

            foreach (Char c in clockDateString)
            {
                var srcRect = fontRectMap[c];
                var dstRect = new SDL.SDL_Rect()
                {
                    x = x, y = fontTileSize, w = fontTileSize, h = fontTileSize
                };
                SDL.SDL_RenderCopy(renderer, fontTexture, ref srcRect, ref dstRect);
                x += fontTileSize;
            }

            SDL.SDL_SetRenderTarget(renderer, IntPtr.Zero);
            var srcRect2 = new SDL.SDL_Rect()
            {
                x = 0, y = 0, w = bufferTextureWidth, h = bufferTextureHeight
            };
            var dstRect2 = new SDL.SDL_Rect()
            {
                x = 0, y = 0, w = currentWindowSize.width, h = currentWindowSize.height
            };

            SDL.SDL_RenderCopy(renderer, bufferTexture, ref srcRect2, ref dstRect2);
        }
Ejemplo n.º 7
0
        internal static void dessinerTexte(int x, int y, int px, Color couleur, String format, params Object[] args)
        {
            IntPtr surfaceMessage;
            IntPtr texMessage;

            SDL.SDL_Rect boiteMessage;
            Size         tailleBoiteMessage;

            if (rendu == IntPtr.Zero || police[px] == IntPtr.Zero)
            {
                return;
            }

            tailleBoiteMessage = getTailleRectangleTexte(px, format, args);
            surfaceMessage     = SDL_ttf.TTF_RenderText_Solid(police[px], String.Format(format, args), new SDL.SDL_Color()
            {
                a = couleur.A, r = couleur.R, g = couleur.G, b = couleur.B
            });

            if (surfaceMessage == IntPtr.Zero)
            {
                return;
            }

            texMessage = SDL.SDL_CreateTextureFromSurface(rendu, surfaceMessage);

            if (texMessage == IntPtr.Zero)
            {
                SDL.SDL_FreeSurface(surfaceMessage);
                surfaceMessage = IntPtr.Zero;
                return;
            }
            boiteMessage = new SDL.SDL_Rect()
            {
                x = x, y = y, w = tailleBoiteMessage.Width, h = tailleBoiteMessage.Height
            };
            SDL.SDL_RenderCopy(rendu, texMessage, IntPtr.Zero, ref boiteMessage);
            SDL.SDL_FreeSurface(surfaceMessage);
            surfaceMessage = IntPtr.Zero;
            SDL.SDL_DestroyTexture(texMessage);
            texMessage = IntPtr.Zero;
        }
Ejemplo n.º 8
0
    //Renders an image as if it is a background
    //(Scaling its size to match the screen size)
    public static void RenderBackground(Image background)
    {
        SDL.SDL_Rect source = new SDL.SDL_Rect
        {
            x = 0,
            y = 0,
            w = background.Width,
            h = background.Height
        };

        SDL.SDL_Rect target = new SDL.SDL_Rect
        {
            x = 0,
            y = 0,
            w = ScreenWidth,
            h = ScreenHeight
        };

        SDL.SDL_RenderCopy(Renderer, background.Texture, ref source, ref target);
    }
Ejemplo n.º 9
0
        public void Draw(IntPtr rendererId, Point location)
        {
            var source = new SDL.SDL_Rect()
            {
                x = this.X,
                y = this.Y,
                w = Width,
                h = Height
            };

            var destination = new SDL.SDL_Rect()
            {
                x = location.X,
                y = location.Y,
                w = Width,
                h = Height
            };

            SDL.SDL_RenderCopy(rendererId, TextureId, ref source, ref destination);
        }
Ejemplo n.º 10
0
        public void Draw(IntPtr rendererId, Point location, Rect sourceRectangle)
        {
            var source = new SDL.SDL_Rect()
            {
                x = (int)(this.X + sourceRectangle.X),
                y = (int)(this.Y + sourceRectangle.Y),
                w = (int)sourceRectangle.Width,
                h = (int)sourceRectangle.Height
            };

            var destination = new SDL.SDL_Rect()
            {
                x = location.X,
                y = location.Y,
                w = (int)sourceRectangle.Width,
                h = (int)sourceRectangle.Height
            };

            SDL.SDL_RenderCopy(rendererId, TextureId, ref source, ref destination);
        }
Ejemplo n.º 11
0
        public static void ApplyColorBuffer(IntPtr renderer)
        {
            UpdateBufferTexture();

            float srcAspect = textureWidth / textureHeight;

            SDL.SDL_GetRendererOutputSize(renderer, out int outputWidth, out int outputHeight);
            float heightRatio  = (float)outputHeight / textureHeight;
            float widthRatio   = (float)outputWidth / textureWidth;
            float minDimension = MathF.Min(heightRatio, widthRatio);
            int   upScale      = (int)MathF.Floor(minDimension);
            var   outputRect   = new SDL.SDL_Rect();

            outputRect.w = textureWidth * upScale;
            outputRect.h = textureHeight * upScale;
            outputRect.x = (outputWidth / 2) - (outputRect.w / 2);
            outputRect.y = (outputHeight / 2) - (outputRect.h / 2);

            SDL.SDL_RenderCopy(renderer, drawTexture, IntPtr.Zero, ref outputRect);
        }
Ejemplo n.º 12
0
        void Render()
        {
            SDL.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
            SDL.SDL_RenderClear(renderer);

            for (int i = 0; i < 4; i++)
            {
                var srcRect = new SDL.SDL_Rect()
                {
                    x = 64 * (shapeToDraw + 2), y = 0, w = 64, h = 64
                };
                var tgtRectr = new SDL.SDL_Rect()
                {
                    x = point[i].X * 32, y = point[i].Y * 32, w = 32, h = 32
                };
                SDL.SDL_RenderCopy(renderer, tilesTexture, ref srcRect, ref tgtRectr);
            }

            SDL.SDL_RenderPresent(renderer);
        }
Ejemplo n.º 13
0
        public void DrawText(int x, int y, Font font, string text)
        {
            PicoSurface surface = font.FontSurface;

            SDL.SDL_Rect destRect = new SDL.SDL_Rect();

            int glyphSize = font.GlyphSize;

            for (int i = 0; i < text.Length; i++)
            {
                SDL.SDL_Rect glyphRect = font[text[i]];

                destRect.x = x + (i * glyphSize);
                destRect.y = y;
                destRect.w = glyphSize;
                destRect.h = glyphSize;

                SDL.SDL_RenderCopy(_ctx, surface.Texture, ref glyphRect, ref destRect);
            }
        }
Ejemplo n.º 14
0
        unsafe private YanesdkResult Blt_(Surface src, int x, int y)
        {
            if (surface == IntPtr.Zero)
            {
                return(YanesdkResult.PreconditionError);                                        // 転送先が構築されていない
            }
            if (src.surface == IntPtr.Zero)
            {
                return(YanesdkResult.InvalidParameter);                                        // 転送元が構築されていない
            }
            SDL.SDL_Surface *surface_ = (SDL.SDL_Surface *)src.surface;
            SDL.SDL_Rect     dest     = new SDL.SDL_Rect();
            dest.x = (short)x;
            dest.y = (short)y;
            dest.w = (ushort)surface_->w;
            dest.h = (ushort)surface_->h;

            return(SDL.SDL_BlitSurface(src.surface, IntPtr.Zero, surface, (IntPtr)(&dest)) == 0 ?
                   YanesdkResult.NoError : YanesdkResult.SdlError);
        }
Ejemplo n.º 15
0
        public void draw()
        {
            // Draw a black background for now
            SDL.SDL_Rect r = new SDL.SDL_Rect();

            SDL.SDL_SetRenderDrawColor(Engine.renderer, 0, 0, 0, 255);
            SDL.SDL_RenderClear(Engine.renderer);

            // Draw the title at the top, centered
            uint f;     // scratch var
            int  a;     // scratch var

            SDL.SDL_QueryTexture(title, out f, out a, out r.w, out r.h);
            r.x = (Engine.GetContextWidth() / 2) - (r.w / 2);
            r.y = 16;

            SDL.SDL_SetRenderDrawColor(Engine.renderer, 255, 255, 255, 255);
            SDL.SDL_RenderCopy(Engine.renderer, title, IntPtr.Zero, ref r);

            // Draw all options
            for (int i = 0; i < options.Count; i++)
            {
                if (i == selected)
                {
                    SDL.SDL_SetTextureColorMod(options[i], 127, 127, 127);
                }

                SDL.SDL_QueryTexture(options[i], out f, out a, out r.w, out r.h);
                r.x = (Engine.GetContextWidth() / 2) - (r.w / 2);
                r.y = 128 + (32 * i);
                SDL.SDL_RenderCopy(Engine.renderer, options[i], IntPtr.Zero, ref r);

                if (i == selected)
                {
                    SDL.SDL_SetTextureColorMod(options[i], 255, 255, 255);
                }
            }

            // Present
            SDL.SDL_RenderPresent(Engine.renderer);
        }
Ejemplo n.º 16
0
        //Renders texture at given point
        public void Render(int x, int y, SDL.SDL_Rect?clip)
        {
            //Set rendering space and render to screen
            var renderQuad = new SDL.SDL_Rect {
                x = x, y = y, w = _Width, h = _Height
            };

            //Set clip rendering dimensions
            if (clip != null)
            {
                renderQuad.w = clip.Value.w;
                renderQuad.h = clip.Value.h;

                var myClip = clip.Value;

                SDL.SDL_RenderCopy(Program.Renderer, _Texture, ref myClip, ref renderQuad);
                return;
            }

            SDL.SDL_RenderCopy(Program.Renderer, _Texture, IntPtr.Zero, ref renderQuad);
        }
Ejemplo n.º 17
0
        public void Draw(ISprite sprite)
        {
            var spr = sprite as SDL2Sprite;

            if (spr.texture == IntPtr.Zero)
            {
                return;
            }

            var loc = spr.GetRenderPoint();

            var destRect = new SDL.SDL_Rect
            {
                x = loc.X,
                y = loc.Y,
                w = spr.FrameSize.Width,
                h = spr.FrameSize.Height
            };

            SDL.SDL_RenderCopy(renderer, spr.texture, IntPtr.Zero, ref destRect);
        }
Ejemplo n.º 18
0
        private static unsafe void Render(PieceGrid pieceGrid, bool mini, Dictionary <Point, ICARule> tweakPoints1, IntPtr windowPtr, SDL.SDL_Surface *screenSurface)
        {
            int size = 10;

            SDL.SDL_Surface *[] surfaces   = StateSurfaces;
            SDL.SDL_Surface *[] bgSurfaces = RuleBackgroundSurfaces;
            if (mini)
            {
                size       = 3;
                surfaces   = StateSurfacesMini;
                bgSurfaces = RuleBackgroundSurfacesMini;
            }
            SDL.SDL_Rect rect = new SDL.SDL_Rect();
            rect.h = size;
            rect.w = size;
            foreach (var kvp in pieceGrid.PointPieces)
            {
                rect.x = kvp.Key.X * size;
                rect.y = kvp.Key.Y * size;
                if (kvp.Value.StateValue >= 1)
                {
                    if (!rulesOnlyDisplay)
                    {
                        SDL.SDL_BlitSurface((IntPtr)surfaces[kvp.Value.StateValue], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                    }
                }
                else
                {
                    if (tweakPoints1.TryGetValue(kvp.Key, out ICARule rule))
                    {
                        SDL.SDL_BlitSurface((IntPtr)bgSurfaces[RuleBackgroundIndexes[rule]], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                    }
                    else
                    {
                        SDL.SDL_BlitSurface((IntPtr)surfaces[0], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                    }
                }
            }
            SDL.SDL_UpdateWindowSurface(windowPtr);
        }
Ejemplo n.º 19
0
        public void DrawText(SDL.SDL_Point p, Font font, string text, Color c, int style = SDL_ttf.TTF_STYLE_NORMAL)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var oldStyle = font.Style;

            font.Style = style;

            Surface surface = font.TextBlended(text, c);

            font.Style = oldStyle;

            var rect = new SDL.SDL_Rect(p.x, p.y, surface.Width, surface.Height);

            Blit(rect, surface);

            surface.Dispose();
            surface = null;
        }
Ejemplo n.º 20
0
        private static unsafe void RenderSprites(bool mini, IntPtr windowPtr, SDL.SDL_Surface *screenSurface)
        {
            int size = 10;

            SDL.SDL_Surface *[] surfaces   = StateSurfaces;
            SDL.SDL_Surface *[] bgSurfaces = RuleBackgroundSurfaces;
            if (mini)
            {
                size       = 3;
                surfaces   = StateSurfacesMini;
                bgSurfaces = RuleBackgroundSurfacesMini;
            }
            SDL.SDL_Rect rect = new SDL.SDL_Rect();
            rect.h = size;
            rect.w = size;
            var pieceGrid = new PieceGrid(100);
            int index     = 0;

            foreach (var kvp in pieceGrid.PointPieces)
            {
                rect.x = kvp.Key.X * size;
                rect.y = kvp.Key.Y * size;
                if (index < surfaces.Length)
                {
                    SDL.SDL_BlitSurface((IntPtr)surfaces[index++], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                }
                else if (index - surfaces.Length < bgSurfaces.Length)
                {
                    int convertedIndex = index - surfaces.Length;
                    index++;
                    SDL.SDL_BlitSurface((IntPtr)bgSurfaces[convertedIndex], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                }
                else
                {
                    index = 0;
                }
            }
            SDL.SDL_UpdateWindowSurface(windowPtr);
        }
Ejemplo n.º 21
0
        //Renders texture at given point
        public void Render(IntPtr renderer, int x, int y, SDL.SDL_Rect?clip = null, double angle = 0, SDL.SDL_Point?center = null, SDL.SDL_RendererFlip flip = SDL.SDL_RendererFlip.SDL_FLIP_NONE)
        {
            //Set rendering space and render to screen
            var renderQuad = new SDL.SDL_Rect {
                x = x, y = y, w = _Width, h = _Height
            };
            var myCenter = center ?? new SDL.SDL_Point();

            //Set clip rendering dimensions
            if (clip != null)
            {
                renderQuad.w = clip.Value.w;
                renderQuad.h = clip.Value.h;

                var myClip = clip.Value;

                SDL.SDL_RenderCopyEx(renderer, _Texture, ref myClip, ref renderQuad, angle, ref myCenter, flip);
                return;
            }

            SDL.SDL_RenderCopyEx(renderer, _Texture, IntPtr.Zero, ref renderQuad, angle, ref myCenter, flip);
        }
Ejemplo n.º 22
0
        public void Draw(Sprite sprite,
                         Vector2 position,
                         Vector2 origin,
                         float rotation,
                         Vector2 scale)
        {
            if (sprite == null)
            {
                throw new ArgumentNullException(nameof(sprite));
            }

            //if (!sprite.IsVisible) return;

            var src = new SDL.SDL_Rect
            {
                x = sprite.TextureRegion.X,
                y = sprite.TextureRegion.Y,
                w = sprite.TextureRegion.Width,
                h = sprite.TextureRegion.Height,
            };

            var scaledWidth  = src.w * scale.X;
            var scaledHeight = src.h * scale.Y;
            var dst          = new SDL.SDL_Rect
            {
                x = (int)(position.X - origin.X * scaledWidth),
                y = (int)(position.Y - origin.Y * scaledHeight),
                w = (int)scaledWidth,
                h = (int)scaledHeight
            };

            SDL.SDL_RenderCopyEx(_handle,
                                 sprite.TextureRegion.Texture.Handle,
                                 ref src,
                                 ref dst,
                                 0D,
                                 IntPtr.Zero,
                                 SDL.SDL_RendererFlip.SDL_FLIP_NONE);
        }
Ejemplo n.º 23
0
        SDL.SDL_Rect FindPositionForNewNodeBottomLeft(int width, int height, ref int bestY, ref int bestX)
        {
            SDL.SDL_Rect bestNode = new SDL.SDL_Rect();
            //memset(bestNode, 0, sizeof(SDL.SDL_Rect));

            bestY = int.MaxValue;

            for (int i = 0; i < FreeRectangles.Count; ++i)
            {
                // Try to place the rectangle in upright (non-flipped) orientation.
                if (FreeRectangles[i].w >= width && FreeRectangles[i].h >= height)
                {
                    int topSideY = FreeRectangles[i].y + height;
                    if (topSideY < bestY || topSideY == bestY && FreeRectangles[i].x < bestX)
                    {
                        bestNode.x = FreeRectangles[i].x;
                        bestNode.y = FreeRectangles[i].y;
                        bestNode.w = width;
                        bestNode.h = height;
                        bestY      = topSideY;
                        bestX      = FreeRectangles[i].x;
                    }
                }
                if (AllowRotations && FreeRectangles[i].w >= height && FreeRectangles[i].h >= width)
                {
                    int topSideY = FreeRectangles[i].y + width;
                    if (topSideY < bestY || topSideY == bestY && FreeRectangles[i].x < bestX)
                    {
                        bestNode.x = FreeRectangles[i].x;
                        bestNode.y = FreeRectangles[i].y;
                        bestNode.w = height;
                        bestNode.h = width;
                        bestY      = topSideY;
                        bestX      = FreeRectangles[i].x;
                    }
                }
            }
            return(bestNode);
        }
Ejemplo n.º 24
0
        private void DrawTile(int x, int y, int width, int height, Color color, MapOrientation orientation = MapOrientation.Isometric)
        {
            if (orientation == MapOrientation.Orthogonal)
            {
                SDL.SDL_Rect rect = new SDL.SDL_Rect();
                rect.x = x;
                rect.y = y;
                rect.w = width;
                rect.h = height;
                SDL.SDL_SetRenderDrawBlendMode(game.ren, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);
                SDL.SDL_SetRenderDrawColor(game.ren, color.R, color.G, color.B, color.Alpha);
                SDL.SDL_RenderDrawRect(game.ren, ref rect);
            }
            else
            {
                SDL.SDL_SetRenderDrawBlendMode(game.ren, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);
                SDL.SDL_SetRenderDrawColor(game.ren, color.R, color.G, color.B, color.Alpha);
                int leftX   = x;
                int leftY   = y;
                int topX    = x + width / 2;
                int topY    = y - height / 2;
                int rightX  = x + width;
                int rightY  = y;
                int bottomX = x + width / 2;
                int bottomY = y + height / 2;

                //int x1 = x;
                //int x2 = x + width / 2;
                //int x3 = x + width;
                //int y1 = y;
                //int y2 = y + height / 2;
                //int y3 = y + height;
                SDL.SDL_RenderDrawLine(game.ren, leftX, leftY, topX, topY);
                SDL.SDL_RenderDrawLine(game.ren, topX, topY, rightX, rightY);
                SDL.SDL_RenderDrawLine(game.ren, rightX, rightY, bottomX, bottomY);
                SDL.SDL_RenderDrawLine(game.ren, bottomX, bottomY, leftX, leftY);
            }
        }
Ejemplo n.º 25
0
        public void Draw(SDLTexture texture, int x, int y)
        {
            // Sanity check our inputs, make sure they are valid.
            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }

            if (x < 0)
            {
                throw new ArgumentOutOfRangeException("x");
            }
            else if (y < 0)
            {
                throw new ArgumentOutOfRangeException("y");
            }

            // Set up the target rectangle, which is the area on the screen that this texture will
            // be drawn to.
            SDL.SDL_Rect target = new SDL.SDL_Rect();

            target.x = x;
            target.y = y;
            target.w = texture.Width;
            target.h = texture.Height;

            // Set up the source rectangle, which is the area of the texture that will be drawn to
            // the screen.
            SDL.SDL_Rect source = new SDL.SDL_Rect();

            source.x = 0;
            source.y = 0;
            source.w = texture.Width;
            source.h = texture.Height;

            // Now issue the draw command to SDL.
            SDL.SDL_RenderCopy(mRenderer, texture.TexturePtr, ref source, ref target);
        }
Ejemplo n.º 26
0
        internal SDL.SDL_Rect ScoreRect(int width, int height, FreeRectChoiceHeuristic method, ref int score1, ref int score2)
        {
            SDL.SDL_Rect newNode = new SDL.SDL_Rect();
            score1 = int.MaxValue;
            score2 = int.MaxValue;
            switch (method)
            {
            case FreeRectChoiceHeuristic.RectBestShortSideFit:
                newNode = FindPositionForNewNodeBestShortSideFit(width, height, ref score1, ref score2);
                break;

            case FreeRectChoiceHeuristic.RectBottomLeftRule:
                newNode = FindPositionForNewNodeBottomLeft(width, height, ref score1, ref score2);
                break;

            case FreeRectChoiceHeuristic.RectContactPointRule:
                newNode = FindPositionForNewNodeContactPoint(width, height, ref score1);
                score1  = -score1;                        // Reverse since we are minimizing, but for contact point score bigger is better.
                break;

            case FreeRectChoiceHeuristic.RectBestLongSideFit:
                newNode = FindPositionForNewNodeBestLongSideFit(width, height, ref score2, ref score1);
                break;

            case FreeRectChoiceHeuristic.RectBestAreaFit:
                newNode = FindPositionForNewNodeBestAreaFit(width, height, ref score1, ref score2);
                break;
            }

            // Cannot fit the current rectangle.
            if (newNode.h == 0)
            {
                score1 = int.MaxValue;
                score2 = int.MaxValue;
            }

            return(newNode);
        }
Ejemplo n.º 27
0
 private void addKey(Key key)
 {
     SDL.SDL_Rect r = new SDL.SDL_Rect();
     if (key is WhiteKey)
     {
         r.x    = lastX;
         r.w    = (int)(KeyWidth * key.ScaleX);
         r.h    = (int)(KeyHeight * key.ScaleY);
         r.y    = PianoY;
         lastX += r.w;
         WhiteKeys.Add(key);
     }
     else
     {
         r.w = (int)(KeyWidth * key.ScaleX);
         r.h = (int)(KeyHeight * key.ScaleY);
         r.y = PianoY;
         r.x = lastX - (r.w / 2);
         BlackKeys.Add(key);
     }
     key.Rect = r;
     KeyGraphics.Add(key);
 }
Ejemplo n.º 28
0
        public void Draw(ISprite sprite, int xSegments, int ySegments, int offset)
        {
            var spr     = sprite as SDL2Sprite;
            var segSize = xSegments * ySegments;

            for (var y = 0; y < ySegments; y++)
            {
                for (var x = 0; x < xSegments; x++)
                {
                    var textureIndex = x + (y * xSegments) + (offset * xSegments * ySegments);
                    spr.Frame = Math.Min(spr.TotalFrames - 1, Math.Max(0, textureIndex));

                    var destRect = new SDL.SDL_Rect
                    {
                        x = sprite.Location.X + (x * 256),
                        y = sprite.Location.Y + (y * 256) - (int)(spr.FrameSize.Height - spr.source.Frames[textureIndex].Height),
                        w = spr.FrameSize.Width,
                        h = spr.FrameSize.Height
                    };
                    SDL.SDL_RenderCopy(renderer, spr.texture, IntPtr.Zero, ref destRect);
                }
            }
        }
Ejemplo n.º 29
0
        private void LoadGlyphMap()
        {
            // 128x128 Image
            // Assume chars:  !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~
            // With int values from 32 to 126
            // In an image with 96 cells for each char, with 16 horizontal and 6 vertical 8x8 cells.

            for (int c = 32; c <= 126; c++)
            {
                int glyphX = (c % COUNT_CELL_HORZ) * CELL_W;
                int glyphY = (c / COUNT_CELL_HORZ) * CELL_W;

                SDL.SDL_Rect glyphRect = new SDL.SDL_Rect()
                {
                    x = glyphX,
                    y = glyphY,
                    w = CELL_W,
                    h = CELL_H
                };

                GlyphQuadMap[c] = glyphRect;
            }
        }
Ejemplo n.º 30
0
    //Renders an image on a static position
    public static void RenderStatic
        (IntPtr texture, float posX, float posY
        , ushort spriteWidth, ushort spriteHeight
        , ushort spriteX, ushort spriteY)
    {
        SDL.SDL_Rect source = new SDL.SDL_Rect
        {
            x = spriteX,
            y = spriteY,
            w = spriteWidth,
            h = spriteHeight
        };

        SDL.SDL_Rect target = new SDL.SDL_Rect
        {
            x = (int)(posX),
            y = (int)(posY),
            w = spriteWidth,
            h = spriteHeight
        };

        SDL.SDL_RenderCopy(Renderer, texture, ref source, ref target);
    }