Exemplo n.º 1
0
        internal Surface(IFont font, string text, Color color, int wrapLength)
        {
            if (font == null)
            {
                throw new ArgumentNullException(nameof(font));
            }

            // Only check null instead of Empty/Whitespace because SDL allows everything but null for rendering fonts.
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            if (wrapLength < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(wrapLength), "Wrap length must be greater than or equal to 0.");
            }

            Type = SurfaceType.Text;
            SDL.SDL_Color rawColor = new SDL.SDL_Color()
            {
                r = color.R, g = color.G, b = color.B
            };

            IntPtr unsafeHandle = IntPtr.Zero;

            if (wrapLength > 0)
            {
                unsafeHandle = SDL_ttf.TTF_RenderText_Blended_Wrapped(font.Handle, text, rawColor, (uint)wrapLength);
            }
            else
            {
                unsafeHandle = SDL_ttf.TTF_RenderText_Blended(font.Handle, text, rawColor);
            }

            if (unsafeHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException($"Error while loading text surface: {SDL.SDL_GetError()}");
            }

            safeHandle = new SafeSurfaceHandle(unsafeHandle);

            GetSurfaceMetaData();
        }
Exemplo n.º 2
0
        internal Surface(string filePath, SurfaceType surfaceType)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            FilePath = filePath;
            Type     = surfaceType;

            IntPtr unsafeHandle = SDL_image.IMG_Load(FilePath);

            if (unsafeHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException($"Error while loading image surface: {SDL.SDL_GetError()}");
            }

            safeHandle = new SafeSurfaceHandle(unsafeHandle);

            GetSurfaceMetaData();
        }