/// <summary> /// Loads the sprite into memory. /// </summary> /// <param name="_logMsgs">True if messages should be logged to console, false otherwise</param> public void Create(bool _logMsgs = true) { int newId; GL.GenTextures(1, out newId); Id = newId; if (Id <= 0) { if (_logMsgs || (mLogMessageOverride)) { TackConsole.EngineLog(EngineLogType.Error, string.Format("Error with generating sprite texture. Sprite. TextureId cannot be set to 0 or below. (Current Id = {0})", Id)); } return; } GL.Enable(EnableCap.Texture2D); GL.ActiveTexture(TextureUnit.Texture0); SpriteManager.AddSprite(this, _logMsgs); if (_logMsgs || (mLogMessageOverride)) { TackConsole.EngineLog(EngineLogType.Message, string.Format("Generated Sprite texture with TextureId '{0}'", Id)); } }
public static Sprite LoadFromFile(string path) { Sprite newSprite = new Sprite(); Bitmap newBp; try { newBp = new Bitmap(Directory.GetCurrentDirectory() + "\\" + path); } catch (FileNotFoundException) { TackConsole.EngineLog(EngineLogType.Error, string.Format("Failed to load image data. No file found at path: '{0}'", path)); return(newSprite); } catch (Exception e) { TackConsole.EngineLog(EngineLogType.Error, string.Format("'{0}'", e.ToString())); return(newSprite); } newSprite.Width = newBp.Width; newSprite.Height = newBp.Height; BitmapData bmpData = newBp.LockBits(new System.Drawing.Rectangle(0, 0, newBp.Width, newBp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); newSprite.PixelFormat = bmpData.PixelFormat; newSprite.m_stride = bmpData.Stride; newSprite.Data = new byte[Math.TackMath.AbsVali(bmpData.Stride) * newBp.Height]; System.Runtime.InteropServices.Marshal.Copy(bmpData.Scan0, newSprite.Data, 0, newSprite.Data.Length); newBp.UnlockBits(bmpData); newBp.Dispose(); return(newSprite); }
internal static void LoadDefaultSprite() { Bitmap defaultBitmap = new Bitmap(32, 32); Graphics g = Graphics.FromImage(defaultBitmap); g.Clear(Color.White); DefaultSprite = LoadFromBitmap(defaultBitmap); DefaultSprite.Create(); defaultBitmap.Dispose(); TackConsole.EngineLog(EngineLogType.Message, "Loaded the default sprite into Sprite.DefaultSprite"); }
public void Create() { for (int i = 0; i < mSpriteCount; i++) { /* * mSingleSpriteTextures[i] = Sprite.LoadFromBitmap(mSpriteSheetTexture.GetBitmap().Clone( * new System.Drawing.RectangleF(i * mSingleSpriteWidth, 0, mSingleSpriteWidth, mSingleSpriteHeight), mSpriteSheetTexture.GetBitmap().PixelFormat)); * * mSingleSpriteTextures[i].Width = mSingleSpriteWidth; * mSingleSpriteTextures[i].Height = mSingleSpriteHeight; * * mSingleSpriteTextures[i].Create(); */ } TackConsole.EngineLog(EngineLogType.Message, string.Format("Created {0} Sprites from a SpriteSheet. SingleWidth: {1}, SingleHeight{2}", mSpriteCount, mSingleSpriteWidth, mSingleSpriteHeight)); }
internal TackConsole() { // Set the static instance ActiveInstance = this; m_logPath = string.Format("logs/log_{0}_{1}_{2}.txt", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year); if (!Directory.Exists(Directory.GetCurrentDirectory() + "/logs")) { Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/logs"); } mInputFieldStyle = new InputFieldStyle(); mInputFieldStyle.BackgroundColour = new Colour4b(100, 100, 100, 190); mInputFieldStyle.FontColour = new Colour4b(0, 0, 0, 255); mInputFieldStyle.SpriteTexture = Sprite.DefaultSprite; mInputFieldStyle.FontSize = 10f; mInputFieldStyle.VerticalAlignment = VerticalAlignment.Middle; mInputFieldStyle.FontFamilyId = 0; //TackGUI.LoadFontFromFile(Environment.GetFolderPath(Environment.SpecialFolder.Fonts) + "\\cour.ttf"); mInputFieldStyle.Scrollable = false; mActivationKey = KeyboardKey.Tilde; mConsoleUIStyle = new TextAreaStyle() { BackgroundColour = new Colour4b(0, 0, 0, 190), FontColour = new Colour4b(0, 255, 0, 255), FontFamilyId = TackGUI.GetFontFamilyId("Courier New"), FontSize = 10f, VerticalAlignment = VerticalAlignment.Top, ScrollPosition = 0, Scrollable = true }; mCaretBoxStyle = new BoxStyle() { Colour = new Colour4b(255, 0, 0, 255), }; mConsoleInputField = null; mConsoleTextArea = null; mConsoleGUIActive = true; }