Пример #1
0
            internal static Font INTERNAL_Font_Create(SDLRenderer renderer, int ptSize, string filename)
            {
                // Create Font instance
                var font = new Font();

                // Assign the renderer
                font._sdlRenderer = renderer;

                // Create from the renderer
                font._ptSize  = ptSize;
                font._sdlFont = SDL_ttf.TTF_OpenFont(filename, ptSize);
                if (font._sdlFont == IntPtr.Zero)
                {
                    font.Dispose();
                    return(null);
                }

                // Fetch the Surface formatting information
                if (!font.FillOutInfo())
                {
                    // Someting dun goned wrung
                    font.Dispose();
                    return(null);
                }

                return(font);
            }
Пример #2
0
        /// <summary>
        ///  Create a new SDL font.
        /// </summary>
        /// <remarks>
        ///  I'm normally not a huge fan of classes that load themselves, much less a constructor
        ///  that loads itself from a file. I have to make an exception for the moment because
        ///  SDL_image's API only supports loading from a file... once someone (maybe me) adds the
        ///  load from memory calls I can remove this and create a proper byte[] constructor
        ///  instead. (And leave the file loading up to the caller).
        /// </remarks>
        public SDLFont(SDLRenderer renderer, string fontName, int fontSize)
        {
            // Make sure our inputs are valid!
            if (renderer == null)
            {
                throw new ArgumentNullException("renderer");
            }

            if (String.IsNullOrEmpty(fontName))
            {
                throw new ArgumentNullException("fontName");
            }

            if (fontSize <= 0)
            {
                throw new ArgumentOutOfRangeException("fontSize");
            }

            // Make sure the image actually exists on disk before attempting to ask SDL to load it.
            //  (Bonus: SDL doesn't return a null when the image does not exist on disk!)
            if (!File.Exists(fontName))
            {
                throw new FileNotFoundException(fontName);
            }

            // Ask SDL to load our font for us and check if it worked.
            mFont = SDL_ttf.TTF_OpenFont(fontName, fontSize);

            if (mFont == null)
            {
                throw new SDLException("Failed to load font");
            }
        }
Пример #3
0
        static bool LoadMedia()
        {
            //Loading success flag
            bool success = true;

            //Open the font
            Font = SDL_ttf.TTF_OpenFont("lazy.ttf", 28);
            if (Font == IntPtr.Zero)
            {
                Console.WriteLine("Failed to load lazy font! SDL_ttf Error: {0}", SDL.SDL_GetError());
                success = false;
            }
            else
            {
                //Render text
                var textColor = new SDL.SDL_Color();
                if (!_TextTexture.LoadFromRenderedText("The quick brown fox jumps over the lazy dog", textColor))
                {
                    Console.WriteLine("Failed to render text texture!");
                    success = false;
                }
            }

            return(success);
        }
Пример #4
0
    static public void Main()
    {
        System.IntPtr window;
        System.Random rand = new System.Random();

        //	SDL.SDL_LogSetPriority(SDL.SDL_LOG_CATEGORY_APPLICATION, SDL.SDL_LOG_PRIORITY_INFO);
        //	SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");

        SDL.SDL_WindowFlags flags = 0;
//	flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;

        if (SDL.SDL_CreateWindowAndRenderer(WindowWidth, WindowHeight, flags, out window, out Renderer) < 0)
        {
            Quit(2);
        }

        SDL.SDL_SetWindowTitle(window, "TestTtf");
        SDL.SDL_ShowCursor(0);

        SDL_ttf.TTF_Init();
        Font = SDL_ttf.TTF_OpenFont("misaki_gothic.ttf", FontSize);

        if (LoadSprite("icon.bmp", Renderer) < 0)
        {
            Quit(2);
        }

        for (int i = 0; i < NumSprites; ++i)
        {
            Positions[i].x  = rand.Next(WindowWidth - Sprite_w);
            Positions[i].y  = rand.Next(WindowHeight - Sprite_h);
            Positions[i].w  = Sprite_w;
            Positions[i].h  = Sprite_h;
            Velocities[i].x = 0;
            Velocities[i].y = 0;
            while (Velocities[i].x == 0 && Velocities[i].y == 0)
            {
                Velocities[i].x = rand.Next(MaxSpeed * 2 + 1) - MaxSpeed;
                Velocities[i].y = rand.Next(MaxSpeed * 2 + 1) - MaxSpeed;
            }
        }

        Done = 0;

        sw.Start();
        while (Done == 0)
        {
            Loop();
        }

        SDL.SDL_DestroyRenderer(Renderer);
        SDL.SDL_DestroyWindow(window);
        SDL.SDL_Quit();

        SDL_ttf.TTF_CloseFont(Font);
        SDL_ttf.TTF_Quit();


        Quit(0);
    }
Пример #5
0
        public Font(string path, int pointSize, FontStyle style = FontStyle.Normal, bool unicode = true)
        {
            cacheFonts     = SettingsManager.instance.engine.cacheFonts;
            this.pointSize = pointSize;
            this.style     = style;
            this.unicode   = unicode;

            if (SDL_ttf.TTF_WasInit() == 0)
            {
                if (SDL_ttf.TTF_Init() != 0)
                {
                    throw new ApplicationException("Failed to initialize SDL_ttf: " + SDL.SDL_GetError());
                }
            }

            handle = SDL_ttf.TTF_OpenFont(path, pointSize);
            if (handle == IntPtr.Zero)
            {
                throw new ApplicationException("Failed to load font: " + SDL.SDL_GetError());
            }

            SDL_ttf.TTF_SetFontStyle(handle, (int)style);

            familyName = SDL_ttf.TTF_FontFaceFamilyName(handle);

            ushort characterCount = unicode ? ushort.MaxValue : (ushort)256;

            bool generateTextures = true;

            if (cacheFonts)
            {
                if (LoadGlyphDataCached() && LoadTextureDataCached())
                {
                    Log.Info("Font: Using cached font data");
                    generateTextures = false;
                }
                else
                {
                    glyphs = null;
                    foreach (Texture2D texture in textures)
                    {
                        texture.Dispose();
                    }
                    textures.Clear();
                }
            }

            if (generateTextures)
            {
                GenerateGlyphData(characterCount);
                GenerateTextures(characterCount);

                if (cacheFonts)
                {
                    CacheGlyphData();
                }
            }

            loadedFonts++;
        }
Пример #6
0
        public void UpdateFontString(string strOutput, SDL.SDL_Rect dstRect, SdlTextureOrientation orientation = null, int fontSize = 28, SDL.SDL_Color?color = null)
        {
            // checking initialization
            if (SDL_ttf.TTF_WasInit() == 0 && SDL_ttf.TTF_Init() < 0)
            {
                Debug.WriteLine($"Could not create LoadingScreen: {SDL.SDL_GetError() }");
                return;
            }

            var textTexture = SDL.SDL_CreateTextureFromSurface(_renderer, SDL_ttf.TTF_RenderText_Blended(
                                                                   SDL_ttf.TTF_OpenFont(_fontSourceRegular, fontSize),
                                                                   "Initializing...",
                                                                   color ?? new SDL.SDL_Color {
                a = 0xff, r = 0xff, g = 0xff, b = 0xff
            }
                                                                   ));

            orientation = orientation ?? new SdlTextureOrientation();
            SDL.SDL_QueryTexture(textTexture, out uint fmt, out int acs, out dstRect.w, out dstRect.h);

            // TODO: testwise implement horizontal centering (ignoring all other cases for now)
            switch (orientation.Horizontal)
            {
            case TextureOrientation.Center:
                dstRect.x = _rectOrigin.w / 2 - dstRect.w / 2;
                break;
            }

            if (textTexture == IntPtr.Zero)
            {
                Debug.WriteLine($"Could not create texture for ttf: {SDL.SDL_GetError()}");
                return;
            }
            SDL.SDL_RenderCopy(_renderer, textTexture, ref _rectOrigin, ref dstRect);
        }
Пример #7
0
        static bool LoadMedia()
        {
            //Loading success flag
            bool success = true;

            //Open the font
            Font = SDL_ttf.TTF_OpenFont("lazy.ttf", 28);
            if (Font == IntPtr.Zero)
            {
                Console.WriteLine("Failed to load lazy font! SDL_ttf Error: {0}", SDL.SDL_GetError());
                success = false;
            }
            else
            {
                //Set text color as black
                var textColor = new SDL.SDL_Color {
                    a = 255
                };

                //Load prompt texture
                if (!_PromptTextTexture.LoadFromRenderedText("Press Enter to Reset Start Time.", textColor))
                {
                    Console.WriteLine("Unable to render prompt texture!");
                    success = false;
                }
            }

            return(success);
        }
Пример #8
0
        static bool loadMedia()
        {
            //Loading success flag
            bool success = true;

            //Open the font
            gFont = SDL_ttf.TTF_OpenFont("lazy.ttf", 28);
            if (gFont == IntPtr.Zero)
            {
                Console.WriteLine("Failed to load lazy font! SDL_ttf Error: {0}", SDL.SDL_GetError());
                success = false;
            }
            else
            {
                SDL.SDL_Color textColor = new SDL.SDL_Color {
                    a = 0xFF
                };
                if (!gPromptTextTexture.loadFromRenderedText("Enter Text:", textColor))
                {
                    Console.WriteLine("Failed to render prompt text!");
                    success = false;
                }
            }

            return(success);
        }
        //initialize the Three Card Poker sprites and variables
        public unsafe ThreeCardPokerGame(IntPtr interfaceWindow)
        {
            window        = interfaceWindow;
            windowSurface = SDL.SDL_GetWindowSurface(window);

            SDL.SDL_Surface *windowSDLSurface = (SDL.SDL_Surface *)windowSurface;
            clearColor  = SDL.SDL_MapRGB(windowSDLSurface->format, 0, 100, 0);
            textColor.r = 255; textColor.b = 255; textColor.g = 255; textColor.a = 255;

            screenRect.x = 0; screenRect.y = 0;
            screenRect.w = 600; screenRect.h = 480;

            cardSprite     = SDL.SDL_LoadBMP("cards.bmp");
            cardBackSprite = SDL.SDL_LoadBMP("card back blue.bmp");
            playButton     = SDL.SDL_LoadBMP("play button.bmp");
            foldButton     = SDL.SDL_LoadBMP("fold button.bmp");
            dealButton     = SDL.SDL_LoadBMP("deal button.bmp");
            quitButton     = SDL.SDL_LoadBMP("quit button.bmp");

            font                = SDL_ttf.TTF_OpenFont("times.ttf", 20);
            betTextSprite       = SDL_ttf.TTF_RenderText_Solid(font, "Ante: $50", textColor);
            playerWinTextSprite = SDL_ttf.TTF_RenderText_Solid(font, "You won!", textColor);
            dealerWinTextSprite = SDL_ttf.TTF_RenderText_Solid(font, "The dealer won.", textColor);
            drawTextSprite      = SDL_ttf.TTF_RenderText_Solid(font, "Draw...", textColor);
        }
Пример #10
0
        public void LoadInit(IntPtr rendererPtr)
        {
            fontPtr = SDL_ttf.TTF_OpenFont("media/font/typed.ttf", 25);

            if (fontPtr == IntPtr.Zero)
            {
                Console.WriteLine("Error loading font. SDL: {0}", SDL.SDL_GetError());
            }

            textColor = new SDL.SDL_Color
            {
                r = 217,
                g = 204,
                b = 0,
                a = 255
            };

            activeTextColor = new SDL.SDL_Color
            {
                r = 255,
                g = 125,
                b = 0,
                a = 255
            };
        }
Пример #11
0
        protected override Font MakeFont(string name, int size)
        {
            IntPtr ft = SDL_ttf.TTF_OpenFont(name, size);

            if (ft != IntPtr.Zero)
            {
                return(new SDLFont(name, size, ft));
            }
            return(null);
        }
Пример #12
0
        public SDL2GeneralDisplay(string title, int width, int height, int internalWidth, int internalHeight, int x = 0, int y = 0, string fontFile = null, int?fontSize = null)
        {
            SDL_ttf.TTF_Init();
            _font = SDL_ttf.TTF_OpenFont(fontFile ?? "./default.ttf", fontSize ?? 20);

            InternalWidth  = internalWidth;
            InternalHeight = internalHeight;

            ActualWidth  = width;
            ActualHeight = height;

            SDL.SDL_Init(SDL.SDL_INIT_VIDEO);

            try
            {
                _window = SDL.SDL_CreateWindow(title,
                                               SDL.SDL_WINDOWPOS_CENTERED,
                                               SDL.SDL_WINDOWPOS_CENTERED,
                                               width,
                                               height,
                                               SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN
                                               );
            }
            catch { }
            finally
            {
                if (_window == IntPtr.Zero)
                {
                    _window = SDL.SDL_CreateWindow(title,
                                                   SDL.SDL_WINDOWPOS_CENTERED,
                                                   SDL.SDL_WINDOWPOS_CENTERED,
                                                   width,
                                                   height,
                                                   SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE);
                }
            }


            if (x > 0 && y > 0)
            {
                SDL.SDL_SetWindowPosition(_window, x, y);
            }

            Pixels     = new uint[internalWidth * internalHeight * 4];
            PixelsText = new uint[internalWidth * internalHeight * 4];

            _renderer = SDL.SDL_CreateRenderer(_window, -1, 0);

            _texture = SDL.SDL_CreateTexture(_renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, internalWidth, internalHeight);
            SDL.SDL_GL_SetSwapInterval(0);

            unsafe { fixed(uint *t = &Pixels[0]) _bufferPtr = new IntPtr(t); }

            IsOpen = true;
        }
Пример #13
0
        public static TextRenderer Load(string fontPath, int size)
        {
            var font = SDL_ttf.TTF_OpenFont(fontPath, size);

            if (font == IntPtr.Zero)
            {
                throw new InvalidOperationException($"Cant load font {fontPath}: {SDL.SDL_GetError()}");
            }

            return(new TextRenderer(font));
        }
Пример #14
0
        /* #################################################################### */
        /* #                           CONSTRUCTORS                           # */
        /* #################################################################### */

        /* #################################################################### */
        /* #                             DELEGATES                            # */
        /* #################################################################### */

        /* #################################################################### */
        /* #                            PROPERTIES                            # */
        /* #################################################################### */

        /* #################################################################### */
        /* #                              METHODS                             # */
        /* #################################################################### */

        public IntPtr GetFont(string name, int size)
        {
            var key = $"{name}__{size}";

            if (!_fonts.ContainsKey(key))
            {
                var font = SDL_ttf.TTF_OpenFont(Engine.Instance.Path("assets", "base", "fonts", $"{name}.ttf"), size);
                _fonts.Add(key, font);
            }
            return(_fonts[key]);
        }
Пример #15
0
        private void LoadAndPrepareResources()
        {
            music_mp3 = SDL_mixer.Mix_LoadMUS("ringtone.mp3");
            if (music_mp3 == IntPtr.Zero)
            {
                Console.WriteLine("Failed to load mp3! SDL_mixer error {0}", SDL.SDL_GetError());
            }

            SDL_mixer.Mix_PlayMusic(music_mp3, -1);

            music_wav = SDL_mixer.Mix_LoadWAV("beat.wav");
            if (music_wav == IntPtr.Zero)
            {
                Console.WriteLine("Failed to load wav! SDL_mixer error {0}", SDL.SDL_GetError());
            }

            font = SDL_ttf.TTF_OpenFont("lazy.ttf", 64);
            if (font == IntPtr.Zero)
            {
                Console.WriteLine("Failed to load lazy font! SDL_ttf Error: {0}", SDL.SDL_GetError());
            }

            //Render text surface
            var textColor   = new SDL.SDL_Color();
            var textSurface = SDL_ttf.TTF_RenderText_Solid(font, "Hello SDL2 World!", textColor);

            if (textSurface == IntPtr.Zero)
            {
                Console.WriteLine("Unable to render text surface! SDL_ttf Error: {0}", SDL.SDL_GetError());
            }

            texture_text = SDL.SDL_CreateTextureFromSurface(renderer, textSurface);
            if (texture_text == IntPtr.Zero)
            {
                Console.WriteLine("Unable to create texture from rendered text! SDL Error: {0}", SDL.SDL_GetError());
            }
            s_text = Marshal.PtrToStructure <SDL.SDL_Surface>(textSurface);

            IntPtr image_png = SDL_image.IMG_Load("transparent.png");

            if (image_png == IntPtr.Zero)
            {
                Console.WriteLine("Unable to load image! SDL_image Error: {0}", SDL.SDL_GetError());
            }

            s_png = Marshal.PtrToStructure <SDL.SDL_Surface>(image_png);
            SDL.SDL_SetColorKey(image_png, (int)SDL.SDL_bool.SDL_TRUE, SDL.SDL_MapRGB(s_png.format, 0, 0xFF, 0xFF));

            texture_png = SDL.SDL_CreateTextureFromSurface(renderer, image_png);
            if (texture_png == IntPtr.Zero)
            {
                Console.WriteLine("Unable to create texture from png! SDL Error: {0}", SDL.SDL_GetError());
            }
        }
Пример #16
0
    /// <summary>
    /// Loads a font from the Assets directory for a single text size. Supports the following formats: TTF, FON.
    /// </summary>
    /// <param name="path">The path to the font file, relative to the Assets directory.</param>
    /// <param name="pointSize">The size of the text that will be rendered by this font (in points).</param>
    public static Font LoadFont(string path, int pointSize)
    {
        IntPtr handle = SDL_ttf.TTF_OpenFont(GetAssetPath(path), pointSize);

        if (handle == IntPtr.Zero)
        {
            throw new Exception("Failed to load font.");
        }

        return(new Font(handle));
    }
Пример #17
0
        public GameStatusBar(Game game)
        {
            this._current = game;
            this._target  = new SDL.SDL_Rect();

            this._font  = SDL_ttf.TTF_OpenFont("arial.ttf", 15);
            this._color = new SDL.SDL_Color();
            _color.r    = 255;
            _color.g    = 255;
            _color.b    = 255;
        }
Пример #18
0
            public override void Load(string path, ContentLoader contentLoader)
            {
                Canvas   = contentLoader.Canvas as SDLCanvas;
                FilePath = path;

                SDL_Font = SDL_ttf.TTF_OpenFont(FilePath, FontSize);
                FontSize = FontSize;
                if (SDL_Font == SDL_Font.Zero)
                {
                    Logger.Log(LogLevel.Error, $"Error loading SDLFont '{path}' with error : {SDL2.SDL.SDL_GetError()}");
                }
            }
Пример #19
0
 public Font(string Path, int Size = 12)
 {
     FontPointer = SDL_ttf.TTF_OpenFont(Path, Size);
     if (FontPointer == IntPtr.Zero)
     {
         //Console.WriteLine("Something went wrong with TTF_OpenFont.");
         //Console.WriteLine("You are probably going to segfault the program.");
         //string Err = SDL.SDL_GetError();
         //Console.WriteLine(Err);
         string Err = SDL.SDL_GetError();
         throw new SDLException($"TTF_OpenFont error! SDL_GetError = {Err}");
     }
 }
Пример #20
0
        public CharacterStatusBar(CharacterBase character, int X, int Y)
        {
            this._current = character;
            this._target  = new SDL.SDL_Rect();

            this._font  = SDL_ttf.TTF_OpenFont("arial.ttf", 15);
            this._color = new SDL.SDL_Color();
            _color.r    = 255;
            _color.g    = 255;
            _color.b    = 255;

            this._x = X;
            this._y = Y;
        }
Пример #21
0
    //Creates a font from a path
    public Font(string path, ushort fontSize)
    {
        Size = fontSize;

        FontType = SDL_ttf.TTF_OpenFont(path, fontSize);

        if (FontType == null)
        {
            SDL.SDL_ShowSimpleMessageBox
                (SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "Error",
                "Could not create the screen", (IntPtr)null);
            Environment.Exit(4);
        }
    }
Пример #22
0
        /// <summary>
        /// Construct a font from a name and point size
        /// </summary>
        /// <param name="name">The path to the font from the resource folder</param>
        /// <param name="ptsize">The point size of the font</param>
        public Font(string name, int ptsize)
        {
            // Construct the full path
            string path = Path.Combine(Graphics.RESOURCE_PATH, name);

            // Load the font
            IntPtr font = SDL_ttf.TTF_OpenFont(path, ptsize);

            if (font == IntPtr.Zero)
            {
                throw new SDLException("TTF_OpenFont");
            }

            FontPtr = font;
        }
Пример #23
0
        static bool loadMedia()
        {
            //Loading success flag
            bool success = true;

            //Open the font
            gFont = SDL_ttf.TTF_OpenFont("lazy.ttf", 28);
            if (gFont == IntPtr.Zero)
            {
                Console.WriteLine("Failed to load lazy font! SDL_ttf Error: {0}", SDL.SDL_GetError());
                success = false;
            }

            return(success);
        }
Пример #24
0
        IntPtr GetFont(int ptSize)
        {
            if (_fontPoints.ContainsKey(ptSize))
            {
                return(_fontPoints[ptSize]);
            }

            IntPtr fontPtr;

            if ((fontPtr = SDL_ttf.TTF_OpenFont("OpenSans-Light.ttf", ptSize)) == IntPtr.Zero)
            {
                throw new Exception("unable to load font");
            }
            return(_fontPoints[ptSize] = fontPtr);
        }
Пример #25
0
        public int CreateFont(string path, string name, int size)
        {
            //Open the font
            IntPtr font = SDL_ttf.TTF_OpenFont(path, size);

            if (font == IntPtr.Zero)
            {
                Console.WriteLine($"Failed to load {path}! SDL_ttf Error: {0}", SDL.SDL_GetError());
            }
            else
            {
                fonts.Add(name, font);
            }
            return(0);
        }
Пример #26
0
        public Font(string path, int fontPointSize)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            FilePath  = path;
            PointSize = fontPointSize;

            Handle = SDL_ttf.TTF_OpenFont(path, fontPointSize);
            if (Handle == IntPtr.Zero)
            {
                throw new InvalidOperationException(String.Format("TTF_OpenFont: {0}", SDL.SDL_GetError()));
            }
        }
Пример #27
0
        public static IntPtr DrawText(string text, string fontFileTTF, byte r, byte g, byte b, byte a)
        {
            IntPtr font = SDL_ttf.TTF_OpenFont(fontFileTTF, 40);

            SDL_Color color;

            color.r = r;
            color.g = g;
            color.b = b;
            color.a = a;

            IntPtr surfaceMessage = SDL_ttf.TTF_RenderText_Solid(font, text, color);

            IntPtr message = SDL_CreateTextureFromSurface(Screen.Renderer, surfaceMessage);

            SDL_FreeSurface(surfaceMessage);
            return(message);
        }
Пример #28
0
        private static void Init()
        {
            if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) != 0)
            {
                throw new SdlException(nameof(SDL.SDL_Init));
            }

            if (SDL_ttf.TTF_Init() != 0)
            {
                throw new SdlException(nameof(SDL_ttf.TTF_Init));
            }

            _window = SDL.SDL_CreateWindow("Langton`s Ant", 0, 0, 640, 480, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);

            if (_window == IntPtr.Zero)
            {
                throw new SdlException(nameof(SDL.SDL_CreateWindow));
            }

            _renderer = SDL.SDL_CreateRenderer(
                _window, -1,
                SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);

            if (_renderer == IntPtr.Zero)
            {
                throw new SdlException(nameof(SDL.SDL_CreateRenderer));
            }

            _font = SDL_ttf.TTF_OpenFont(_fontPath, 14);

            KeydownHandler = new KeyHandler();
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_ESCAPE, () => _quit = true);
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_F5, LoadWorld);
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_F2, () => _speed -= 10);
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_F3, () => _speed += 10);
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_F4, () => _speed  = 0);
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_z, () => GetWorldRenderer().AddZoom(-10));
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_x, () => GetWorldRenderer().AddZoom(10));
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_c, () => GetWorldRenderer().ResetZoom());
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_RIGHT, () => GetWorldRenderer().MoveZoom(10, 0));
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_UP, () => GetWorldRenderer().MoveZoom(0, -10));
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_LEFT, () => GetWorldRenderer().MoveZoom(-10, 0));
            KeydownHandler.Add(SDL.SDL_Keycode.SDLK_DOWN, () => GetWorldRenderer().MoveZoom(0, 10));
        }
Пример #29
0
        private static IntPtr MakeTextSurface(string message)
        {
            SDL_ttf.TTF_Init();
            var font = SDL_ttf.TTF_OpenFont(ArialFontFilename(), 128);

            if (font == IntPtr.Zero)
            {
                throw new Exception($"Could not initialize font: {SDL_GetError()}");
            }

            var color = new SDL_pixels.SDL_Color {
                r = 255, g = 255, b = 255, a = 255
            };
            var surface = SDL_ttf.TTF_RenderText_Solid(font,
                                                       message, color);

            SDL_ttf.TTF_CloseFont(font);
            SDL_ttf.TTF_Quit();

            return(surface);
        }
Пример #30
0
        public static bool InitEngine()
        {
            // Initialise the log
            log = new Log("harambae_runtime.log");
            log.Info("Engine starting");

            // Initialise required SDL2 components
            int result;

            result = SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING);

            if (result < 0)
            {
                log.Error("Could not init SDL2");
                return(false);
            }

            if (CreateContext(800, 600, false) == false)
            {
                log.Error("Could not create a context");
                return(false);
            }

            // SDL2_TTF

            result = SDL_ttf.TTF_Init();
            if (result < 0)
            {
                log.Error("Could not init SDL2_TTF");
                DestroyContext();
                SDL.SDL_Quit();
                return(false);
            }
            largefont = SDL_ttf.TTF_OpenFont("assets/papyrus.ttf", 32);
            smallfont = SDL_ttf.TTF_OpenFont("assets/papyrus.ttf", 16);

            // SDL2_image
            result = SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_PNG);
            return(true);
        }