Exemplo n.º 1
0
 protected virtual void Dispose(bool disposing)
 {
     if (FontPtr != IntPtr.Zero) // only dispose once!
     {
         SDL_ttf.TTF_CloseFont(FontPtr);
     }
 }
Exemplo n.º 2
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);
    }
Exemplo n.º 3
0
        private static void close()
        {
            //Open data for writing
            //Create file for writing
            using (var bw = new BinaryWriter(File.OpenWrite("nums.bin"), Encoding.Default))
            {
                //Initialize data
                for (int i = 0; i < TOTAL_DATA; ++i)
                {
                    bw.Write(gData[i]);
                }
            }

            //Free loaded images
            gPromptTextTexture.free();
            for (int i = 0; i < TOTAL_DATA; ++i)
            {
                gDataTextures[i].free();
            }

            //Free global font
            SDL_ttf.TTF_CloseFont(gFont);
            gFont = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyRenderer(gRenderer);
            SDL.SDL_DestroyWindow(gWindow);
            gWindow   = IntPtr.Zero;
            gRenderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_ttf.TTF_Quit();
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
        private bool ReleaseAndQuit(IntPtr window, IntPtr renderer, IntPtr font, IntPtr image)
        {
            if (window != IntPtr.Zero)
            {
                SDL.SDL_DestroyWindow(window);
            }

            if (renderer != IntPtr.Zero)
            {
                SDL.SDL_DestroyRenderer(renderer);
            }

            if (font != IntPtr.Zero)
            {
                SDL_ttf.TTF_CloseFont(font);
            }

            if (image != IntPtr.Zero)
            {
                SDL.SDL_DestroyTexture(image);
            }

            SDL_image.IMG_Quit();
            SDL.SDL_Quit();

            return(false);
        }
Exemplo n.º 5
0
 internal static void deinitialiser_2d()
 {
     foreach (var image in images)
     {
         SDL.SDL_DestroyTexture(image.Value);
     }
     images.Clear();
     SDL_image.IMG_Quit();
     for (int i = 0; i < 73; i++)
     {
         if (police[i] != IntPtr.Zero)
         {
             SDL_ttf.TTF_CloseFont(police[i]);
             police[i] = IntPtr.Zero;
         }
     }
     SDL_ttf.TTF_Quit();
     if (rendu != IntPtr.Zero)
     {
         SDL.SDL_DestroyRenderer(rendu);
         rendu = IntPtr.Zero;
     }
     if (fenetre != IntPtr.Zero)
     {
         SDL.SDL_DestroyWindow(fenetre);
         fenetre = IntPtr.Zero;
     }
 }
Exemplo n.º 6
0
 private void Dispose(bool disposing)
 {
     if (Handle != IntPtr.Zero)
     {
         SDL_ttf.TTF_CloseFont(Handle);
         Handle = IntPtr.Zero;
     }
 }
Exemplo n.º 7
0
        private bool CollectFontInfo(Font ifont)
        {
            IntPtr font = IntPtr.Zero;

            if (UseRWops && CreateRWopsCacheOnFontRegister)
            {
                font = SDL_ttf.TTF_OpenFontIndexRW(ifont.RWops, 1, 16, ifont.index);
            }
            else
            {
                font = SDL_ttf.TTF_OpenFontIndex(ifont.filename, 16, ifont.index);
            }

            if (font.ShowSDLError("FontManager.CollectFontInfo(): Failed to load font!"))
            {
                return(false);
            }
            else
            {
                int    fontfaces           = (int)SDL_ttf.TTF_FontFaces(font);
                string fontface_familyname = SDL_ttf.TTF_FontFaceFamilyName(font);
                string fontface_stylename  = SDL_ttf.TTF_FontFaceStyleName(font);
                bool   fontface_mono       = (SDL_ttf.TTF_FontFaceIsFixedWidth(font) > 0);
                int    font_style          = SDL_ttf.TTF_GetFontStyle(font);

                ifont.fontFamilyId = GetFontFamilyId(fontface_familyname, true);
                ifont.fontStyle    = font_style;
                ifont.mono         = fontface_mono;

                /*
                 * Console.WriteLine("  Hash:{0}", _fonts[font_id].hash);
                 * Console.WriteLine("  TTF_FontFaces: {0}", fontfaces);
                 * Console.WriteLine("  TTF_FontFaceIsFixedWidth: {0}", fontface_mono);
                 *
                 * Console.WriteLine("  TTF_FontFaceFamilyName: {0}", fontface_familyname);
                 * Console.WriteLine("  TTF_FontFaceStyleName: {0}", fontface_stylename);
                 * Console.WriteLine("  TTF_GetFontStyle: {0}", font_style);
                 */

                if (ifont.index == 0 && fontfaces > 1)
                {
                    for (int index = 1; index < fontfaces; index++)
                    {
                        //Console.WriteLine("         index: {0}", index);
                        Font sub_ifont = ifont.Clone();
                        sub_ifont.index = index;
                        if (CollectFontInfo(sub_ifont))
                        {
                            _fonts.Add(sub_ifont);
                        }
                    }
                }
                SDL_ttf.TTF_CloseFont(font);
                return(true);
            }
        }
Exemplo n.º 8
0
        public static void QuitEngine()
        {
            SDL_ttf.TTF_CloseFont(smallfont);
            SDL_ttf.TTF_CloseFont(largefont);
            SDL_ttf.TTF_Quit();
            DestroyContext();
            SDL.SDL_Quit();

            log.Info("Quitting engine");
            log.Close();
        }
Exemplo n.º 9
0
        private void WindowClosing(object sender, FormClosingEventArgs e)
        {
            renderCancellationToken.Cancel();

            SDL.SDL_DestroyTexture(textTexture);
            SDL.SDL_FreeSurface(textSurface);

            SDL_ttf.TTF_CloseFont(glFont);

            SDL.SDL_DestroyWindow(gameWindow);
            gameWindow = IntPtr.Zero;

            SDL_ttf.TTF_Quit();
            SDL.SDL_Quit();
        }
Exemplo n.º 10
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                }

                foreach (var font in _fonts)
                {
                    SDL_ttf.TTF_CloseFont(font.Value);
                }

                SDL_ttf.TTF_Quit();
                disposedValue = true;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        ///  Destroys the unmanaged SDL renderer.
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (!mDisposed)
            {
                if (disposing)
                {
                    // Free any managed objects.
                }

                // Free your own state (unmanaged objects).
                SDL_ttf.TTF_CloseFont(mFont);
                mFont = IntPtr.Zero;

                Console.WriteLine("Destroyed SDLFont");

                mDisposed = true;
            }
        }
Exemplo n.º 12
0
        public void ClearFontCache()
        {
            if (UseFontCache)
            {
                foreach (var family in _fontCache)
                {
                    foreach (var style in _fontCache[family.Key])
                    {
                        foreach (var size in _fontCache[family.Key][style.Key])
                        {
                            SDL_ttf.TTF_CloseFont(size.Value);
                        }
                    }
                }
            }

            _fontCache.Clear();
        }
Exemplo n.º 13
0
        private static void Quit()
        {
            if (!(_font == IntPtr.Zero))
            {
                SDL_ttf.TTF_CloseFont(_font);
            }

            if (!(_renderer == IntPtr.Zero))
            {
                SDL.SDL_DestroyRenderer(_renderer);
            }

            if (!(_window == IntPtr.Zero))
            {
                SDL.SDL_DestroyWindow(_window);
            }

            SDL_ttf.TTF_Quit();
            SDL.SDL_Quit();
        }
Exemplo n.º 14
0
        private static void close()
        {
            //Free loaded images
            gFPSTextTexture.free();

            //Free global font
            SDL_ttf.TTF_CloseFont(gFont);
            gFont = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyRenderer(gRenderer);
            SDL.SDL_DestroyWindow(gWindow);
            gWindow   = IntPtr.Zero;
            gRenderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_ttf.TTF_Quit();
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Exemplo n.º 15
0
        private static void Close()
        {
            //Free loaded images
            _TextTexture.Free();

            //Free global font
            SDL_ttf.TTF_CloseFont(Font);
            Font = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyRenderer(Renderer);
            SDL.SDL_DestroyWindow(_Window);
            _Window  = IntPtr.Zero;
            Renderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_ttf.TTF_Quit();
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
Arquivo: Font.cs Projeto: xxami/Pulsus
        public void Dispose()
        {
            if (handle == IntPtr.Zero)
            {
                return;
            }

            foreach (Texture2D texture in textures)
            {
                texture.Dispose();
            }
            textures.Clear();

            SDL_ttf.TTF_CloseFont(handle);
            handle = IntPtr.Zero;

            // unload SDL_ttf
            loadedFonts--;
            if (loadedFonts <= 0)
            {
                SDL_ttf.TTF_Quit();
            }
        }
Exemplo n.º 18
0
 public void Cleanup()
 {
     SDL_ttf.TTF_CloseFont(fontPtr);
 }
Exemplo n.º 19
0
 public void Dispose()
 {
     SDL_ttf.TTF_CloseFont(font);
 }
Exemplo n.º 20
0
        protected override void DestroyFont(Font font)
        {
            IntPtr ft = font.GetFont();

            SDL_ttf.TTF_CloseFont(ft);
        }
Exemplo n.º 21
0
 protected override void ReleaseUnmanagedResources()
 {
     SDL_ttf.TTF_CloseFont(_handle);
 }
Exemplo n.º 22
0
 public override void Cleanup()
 {
     SDL_ttf.TTF_CloseFont(SDL_Font);
 }
Exemplo n.º 23
0
        public void Dispose()
        {
            SDL_ttf.TTF_CloseFont(myPtr);

            GC.SuppressFinalize(this);
        }
Exemplo n.º 24
0
 public void destroy()
 {
     SDL_ttf.TTF_CloseFont(font);
 }
Exemplo n.º 25
0
 protected override bool ReleaseHandle()
 {
     SDL_ttf.TTF_CloseFont(handle);
     return(true);
 }