/// <summary> /// Constructor /// </summary> /// <param name="positionsX">array of x positions of points</param> /// <param name="positionsY">array of y positions of points</param> public Polygon(short[] positionsX, short[] positionsY) { if (positionsX == null) { throw new ArgumentNullException("positionsX"); } if (positionsY == null) { throw new ArgumentNullException("positionsY"); } this.x = positionsX; this.y = positionsY; this.n = 0; this.list = new ArrayList(); this.xTotal = 0; this.yTotal = 0; if (x.Length != y.Length) { throw SdlException.Generate(); } else { this.n = x.Length; } }
/// <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.filledPieRGBA(surface.Handle, this.PositionX, this.PositionY, this.Radius, this.StartingAngle, this.EndingAngle, color.R, color.G, color.B, color.A); GC.KeepAlive(this); if (result != (int)SdlFlag.Success) { throw SdlException.Generate(); } } else { int result = SdlGfx.pieRGBA( surface.Handle, this.PositionX, this.PositionY, this.Radius, this.StartingAngle, this.EndingAngle, color.R, color.G, color.B, color.A); GC.KeepAlive(this); if (result != (int)SdlFlag.Success) { throw SdlException.Generate(); } } }
/// <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 (antiAlias) { int result = SdlGfx.aalineRGBA( surface.Handle, this.XPosition1, this.YPosition1, this.XPosition2, this.YPosition2, color.R, color.G, color.B, color.A); GC.KeepAlive(this); if (result != (int)SdlFlag.Success) { throw SdlException.Generate(); } } else { int result = SdlGfx.lineRGBA( surface.Handle, this.XPosition1, this.YPosition1, this.XPosition2, this.YPosition2, color.R, color.G, color.B, color.A); GC.KeepAlive(this); if (result != (int)SdlFlag.Success) { throw SdlException.Generate(); } } }
/// <summary> /// Sets an OpenGL attribute /// </summary> /// <param name="attribute">The attribute to set</param> /// <param name="attributeValue">The new attribute value</param> public static void GLSetAttribute(OpenGLAttr attribute, int attributeValue) { if (Sdl.SDL_GL_SetAttribute((int)attribute, attributeValue) != 0) { throw SdlException.Generate(); } }
/// <summary> /// Sets the distance (attenuate sounds based on distance /// from listener) for a specific channel /// </summary> /// <param name="distanceValue"> /// Distance value from 0-255 inclusive /// </param> /// <remarks></remarks> public void Distance(byte distanceValue) { if (SdlMixer.Mix_SetDistance(this.index, distanceValue) == 0) { throw SdlException.Generate(); } }
/// <summary> /// Plays the music sample /// </summary> /// <param name="numberOfTimes"> /// The number of times to play. /// Specify 1 to play a single time, -1 to loop forever. /// </param> public static void Play(int numberOfTimes) { if (SdlMixer.Mix_PlayMusic(m_CurrentMusic.Handle, numberOfTimes) != 0) { throw SdlException.Generate(); } }
/// <summary> /// Sets the "position" of a sound (approximate '3D' audio) /// for a specific channel /// </summary> /// <param name="angle">The angle of the sound, between 0 and 359, /// 0 = directly in front</param> /// <param name="distance">The distance of the sound from 0-255 /// inclusive</param> /// <remarks></remarks> public void SetPosition(int angle, int distance) { if (SdlMixer.Mix_SetPosition(this.index, (short)angle, (byte)distance) == 0) { throw SdlException.Generate(); } }
/// <summary> /// Sets the panning (stereo attenuation) for a specific channel /// </summary> /// <param name="left">A left speaker value from 0-255 inclusive</param> /// <param name="right">A right speaker value from 0-255 inclusive</param> /// <remarks></remarks> public void SetPanning(int left, int right) { if (SdlMixer.Mix_SetPanning(this.index, (byte)left, (byte)right) == 0) { throw SdlException.Generate(); } }
/// <summary> /// Flips the left and right stereo for the channel /// </summary> /// <param name="flip">True to flip, False to reset to normal</param> /// <remarks></remarks> public void ReverseStereo(bool flip) { if (SdlMixer.Mix_SetReverseStereo(this.index, flip ? 1 : 0) == 0) { throw SdlException.Generate(); } }
/// <summary> /// Fades out music /// </summary> /// <param name="milliseconds"> /// The number of milliseconds to fade out for /// </param> public static void Fadeout(int milliseconds) { if (SdlMixer.Mix_FadeOutMusic(milliseconds) != 1) { throw SdlException.Generate(); } }
/// <summary> /// Plays the music sample and fades it in /// </summary> /// <param name="numberOfTimes"> /// The number of times to play. /// Specify 1 to play a single time, -1 to loop forever. /// </param> /// <param name="milliseconds"> /// The number of milliseconds to fade in for /// </param> public static void FadeIn(int numberOfTimes, int milliseconds) { if (SdlMixer.Mix_FadeInMusic(m_CurrentMusic.Handle, numberOfTimes, milliseconds) != 0) { throw SdlException.Generate(); } }
/// <summary> /// Constructor /// </summary> /// <param name="positionsX">array of x positions of points</param> /// <param name="positionsY">array of y positions of points</param> /// <param name="surface">Textured surface</param> /// <param name="textureOffsetX">Texture is offset on the X axis</param> /// <param name="textureOffsetY">Texture is offset on the Y axis</param> public TexturedPolygon(Surface surface, short[] positionsX, short[] positionsY, int textureOffsetX, int textureOffsetY) { if (positionsX == null) { throw new ArgumentNullException("positionsX"); } if (positionsY == null) { throw new ArgumentNullException("positionsY"); } this.x = positionsX; this.y = positionsY; this.n = 0; this.list = new ArrayList(); this.xTotal = 0; this.yTotal = 0; this.texturedSurface = surface; this.textureOffsetX = textureOffsetX; this.textureOffsetY = textureOffsetY; if (x.Length != y.Length) { throw SdlException.Generate(); } else { this.n = x.Length; } }
/// <summary> /// Enable keyboard autorepeat /// </summary> /// <param name="delay"> /// Delay in system ticks before repeat starts. /// Set to 0 to disable key repeat. /// </param> /// <param name="rate"> /// Rate in system ticks at which key repeats. /// </param> /// <remarks>This method will initialize the Video subsystem as well.</remarks> public static void EnableKeyRepeat(int delay, int rate) { if (Sdl.SDL_EnableKeyRepeat(delay, rate) == (int)SdlFlag.Error) { throw SdlException.Generate(); } }
/// <summary> /// Plays the music sample and fades it in /// </summary> /// <param name="numberOfTimes"> /// The number of times to play. /// Specify 1 to play a single time, -1 to loop forever. /// </param> /// <param name="milliseconds"> /// The number of milliseconds to fade in for /// </param> public void FadeIn(int numberOfTimes, int milliseconds) { MusicPlayer.CurrentMusic = this; if (SdlMixer.Mix_FadeInMusic(this.Handle, numberOfTimes, milliseconds) != 0) { throw SdlException.Generate(); } }
/// <summary> /// Sets gamma for all colors /// </summary> /// <param name="gammaValue">Gamma to set for all colors</param> public static void Gamma(float gammaValue) { int result = Sdl.SDL_SetGamma(gammaValue, gammaValue, gammaValue); if (result != 0) { throw SdlException.Generate(); } }
/// <summary> /// Sets gamma /// </summary> /// <param name="red">Red</param> /// <param name="green">Green</param> /// <param name="blue">Blue</param> public static void Gamma(float red, float green, float blue) { int result = Sdl.SDL_SetGamma(red, green, blue); if (result != 0) { throw SdlException.Generate(); } }
/// <summary> /// Sets green gamma ramp /// </summary> /// <param name="gammaArray"></param> public static void SetGammaRampGreen(short[] gammaArray) { int result = Sdl.SDL_SetGammaRamp(null, gammaArray, null); if (result != 0) { throw SdlException.Generate(); } }
/// <summary> /// Loads a music sample from a byte array returning the pointer to the sample. /// </summary> /// <param name="data">data buffer to load.</param> /// <returns>The IntPtr handle to the music sample in memory.</returns> /// <exception cref="SdlException">Thrown if an error occurs when loading the sample.</exception> internal static IntPtr LoadMusic(byte[] data) { IntPtr handle = SdlMixer.Mix_LoadMUS_RW(Sdl.SDL_RWFromMem(data, data.Length)); if (handle == IntPtr.Zero) { throw SdlException.Generate(); } return(handle); }
/// <summary> /// Ejects this drive /// </summary> /// <remarks></remarks> public void Eject() { int result = Sdl.SDL_CDEject(this.Handle); GC.KeepAlive(this); if (result == (int)SdlFlag.Error) { throw SdlException.Generate(); } }
/// <summary> /// Loads a music sample from a filename returning the pointer to the sample. /// </summary> /// <param name="filename">The file path to load.</param> /// <returns>The IntPtr handle to the music sample in memory.</returns> /// <exception cref="SdlException">Thrown if an error occurs when loading the sample.</exception> internal static IntPtr LoadMusic(string filename) { IntPtr handle = SdlMixer.Mix_LoadMUS(filename); if (handle == IntPtr.Zero) { throw SdlException.Generate(); } return(handle); }
/// <summary> /// Creates a joystick object to read information about a joystick /// </summary> /// <param name="index">The 0-based index of the joystick to read</param> /// <returns>A Joystick object</returns> public static Joystick OpenJoystick(int index) { IntPtr joystick = Sdl.SDL_JoystickOpen(index); if (!IsValidJoystickNumber(index) || (joystick == IntPtr.Zero)) { throw SdlException.Generate(); } return(new Joystick(joystick)); }
/// <summary> /// Opens a CD-ROM drive for manipulation /// </summary> /// <param name="index"> /// The number of the drive to open, from 0 - CDAudio.NumDrives /// </param> /// <returns> /// The CDDrive object representing the CD-ROM drive /// </returns> /// <remarks> /// Opens a CD-ROM drive for manipulation /// </remarks> public static CDDrive OpenDrive(int index) { IntPtr cd = Sdl.SDL_CDOpen(index); if (!IsValidDriveNumber(index) || (cd == IntPtr.Zero)) { throw SdlException.Generate(); } return(new CDDrive(cd, index)); }
/// <summary> /// Gets the value of an OpenGL attribute /// </summary> /// <param name="attribute">The attribute to get</param> /// <returns>The current attribute value</returns> public static int GLGetAttribute(OpenGLAttr attribute) { int returnValue; if (Sdl.SDL_GL_GetAttribute((int)attribute, out returnValue) != 0) { throw SdlException.Generate(); } return(returnValue); }
/// <summary> /// Loads a .wav, .ogg, .mp3, .mod or .mid file from a byte array /// </summary> /// <param name="data">The data to load</param> /// <param name="size">Output variable for the size of the sound object.</param> /// <returns>A new Sound object</returns> internal static IntPtr Load(byte[] data, out long size) { IntPtr p = SdlMixer.Mix_LoadWAV_RW(Sdl.SDL_RWFromMem(data, data.Length), 1); if (p == IntPtr.Zero) { throw SdlException.Generate(); } size = data.Length; return(p); }
/// <summary> /// Plays the tracks on a CD in the drive /// </summary> /// <remarks></remarks> /// <param name="startTrack"> /// The starting track to play (numbered 0-99) /// </param> /// <param name="numberOfTracks"> /// The number of tracks to play /// </param> public void Play(int startTrack, int numberOfTracks) { int result = Sdl.SDL_CDPlayTracks( this.Handle, startTrack, 0, numberOfTracks, 0); GC.KeepAlive(this); if (result == (int)SdlFlag.Error) { throw SdlException.Generate(); } }
/// <summary> /// Play CD from the first track. /// </summary> /// <remarks></remarks> public void Play() { int result = Sdl.SDL_CDPlayTracks( this.Handle, 0, 0, 0, 0); GC.KeepAlive(this); if (result == (int)SdlFlag.Error) { throw SdlException.Generate(); } }
/// <summary> /// Loads a .wav, .ogg, .mp3, .mod or .mid file into memory /// </summary> /// <param name="file">The filename to load</param> /// <param name="size">Output long variable for the size of the sound object.</param> /// <returns>A new Sound object</returns> internal static IntPtr Load(string file, out long size) { IntPtr p = SdlMixer.Mix_LoadWAV_RW(Sdl.SDL_RWFromFile(file, "rb"), 1); if (p == IntPtr.Zero) { throw SdlException.Generate(); } size = new FileInfo(file).Length; return(p); }
/// <summary> /// Gets red gamma ramp /// </summary> public static short[] GetGammaRampRed() { short[] red = new short[256]; int result = Sdl.SDL_GetGammaRamp(red, null, null); if (result != 0) { throw SdlException.Generate(); } return(red); }
/// <summary> /// Gets blue gamma ramp /// </summary> public static short[] GetGammaRampBlue() { short[] blue = new short[256]; int result = Sdl.SDL_GetGammaRamp(null, null, blue); if (result != 0) { throw SdlException.Generate(); } return(blue); }
/// <summary> /// Gets green gamma ramp /// </summary> public static short[] GetGammaRampGreen() { short[] green = new short[256]; int result = Sdl.SDL_GetGammaRamp(null, green, null); if (result != 0) { throw SdlException.Generate(); } return(green); }