예제 #1
0
        /// <summary>
        ///
        /// </summary>
        public void Run()
        {
            int  flags    = (Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT);
            int  bpp      = 16;
            int  width    = 640;
            int  height   = 480;
            bool quitFlag = false;

            Random rand = new Random();

            //string musicFile = "Data/SdlExamples.Reactangles.sound.ogg";

            Sdl.SDL_Event evt;

            try
            {
                Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
                Sdl.SDL_WM_SetCaption("Tao.Sdl Example - GfxPrimitives", "");
                IntPtr surfacePtr = Sdl.SDL_SetVideoMode(
                    width,
                    height,
                    bpp,
                    flags);

                Sdl.SDL_Rect rect2 =
                    new Sdl.SDL_Rect(0, 0, (short)width, (short)height);
                Sdl.SDL_SetClipRect(surfacePtr, ref rect2);
                while (quitFlag == false)
                {
                    Sdl.SDL_PollEvent(out evt);

                    if (evt.type == Sdl.SDL_QUIT)
                    {
                        quitFlag = true;
                    }
                    else if (evt.type == Sdl.SDL_KEYDOWN)
                    {
                        if ((evt.key.keysym.sym == (int)Sdl.SDLK_ESCAPE) ||
                            (evt.key.keysym.sym == (int)Sdl.SDLK_q))
                        {
                            quitFlag = true;
                        }
                    }

                    try
                    {
                        SdlGfx.filledCircleRGBA(surfacePtr, (short)rand.Next(10, width - 100), (short)rand.Next(10, height - 100), (short)rand.Next(10, 100), (byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255));
                        Sdl.SDL_Flip(surfacePtr);
                        Thread.Sleep(100);
                    }
                    catch (Exception) {}
                }
            }
            catch
            {
                Sdl.SDL_Quit();
                throw;
            }
        }
예제 #2
0
        public void filledCircleRGBA()
        {
            this.InitSdl();

            //Random rand = new Random();
            int result = SdlGfx.filledCircleRGBA(surfacePtr, 100, 100, 50, 200, 0, (byte)0, 254);

            result = Sdl.SDL_Flip(surfacePtr);
            Thread.Sleep(sleepTime);
            Assert.AreEqual(result, 0);
            this.Quit();
        }
예제 #3
0
 /// <summary>
 /// Draw filled primitive onto surface
 /// </summary>
 /// <param name="surface">Surface to draw to</param>
 /// <param name="color">Color to fill primitive</param>
 /// <param name="antiAlias">antialias primitive</param>
 /// <param name="fill">fill primitive with color</param>
 public void Draw(Surface surface, System.Drawing.Color color, bool antiAlias, bool fill)
 {
     if (surface == null)
     {
         throw new ArgumentNullException("surface");
     }
     if (fill)
     {
         int result = SdlGfx.filledCircleRGBA(surface.Handle, this.PositionX, this.PositionY, this.Radius, color.R, color.G, color.B,
                                              color.A);
         GC.KeepAlive(this);
         if (result != (int)SdlFlag.Success)
         {
             throw SdlException.Generate();
         }
     }
     else
     {
         int result = 0;
         if (antiAlias)
         {
             result = SdlGfx.aacircleRGBA(surface.Handle, this.PositionX, this.PositionY, this.Radius, color.R, color.G, color.B,
                                          color.A);
             GC.KeepAlive(this);
         }
         else
         {
             result = SdlGfx.circleRGBA(surface.Handle, this.PositionX, this.PositionY, this.Radius, color.R, color.G, color.B,
                                        color.A);
             GC.KeepAlive(this);
         }
         if (result != (int)SdlFlag.Success)
         {
             throw SdlException.Generate();
         }
     }
 }