/// <see cref="IUISpriteManager.CreateSprite"/> public override UISprite CreateSprite(RCColor color, RCIntVector spriteSize) { if (this.ObjectDisposed) { throw new ObjectDisposedException("XnaSpriteManager"); } if (color == RCColor.Undefined) { throw new ArgumentNullException("color"); } if (spriteSize == RCIntVector.Undefined) { throw new ArgumentNullException("spriteSize"); } /// Create the empty bitmap and fill with the given color Bitmap emptyBitmap = new Bitmap(spriteSize.X, spriteSize.Y, PixelFormat.Format24bppRgb); Graphics gc = Graphics.FromImage(emptyBitmap); gc.Clear(Color.FromArgb(color.R, color.G, color.B)); gc.Dispose(); lock (this.lockObj) { /// Create the XnaSprite object and register it to this sprite manager. XnaSprite newSprite = new XnaSprite(emptyBitmap, new RCIntVector(1, 1), this.platform); this.sprites.Add(newSprite); TraceManager.WriteAllTrace("XnaSpriteManager.CreateSprite: Sprite created", XnaTraceFilters.INFO); return(newSprite); } }
public MySensitiveObject(RCIntVector position, RCIntRectangle range, string name, RCColor basicColor, RCColor highColor) : base(position, range) { this.nameStrBasic = new UIString(name, UIResourceManager.GetResource <UIFont>("RC.App.Fonts.Font6"), new RCIntVector(2, 2), RCColor.WhiteHigh); this.nameStrHigh = new UIString(name, UIResourceManager.GetResource <UIFont>("RC.App.Fonts.Font6"), new RCIntVector(2, 2), RCColor.LightRed); this.backgroundBasic = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(basicColor, this.Range.Size, new RCIntVector(2, 2)); this.backgroundHigh = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(highColor, this.Range.Size, new RCIntVector(2, 2)); this.backgroundBasic.Upload(); this.backgroundHigh.Upload(); this.name = name; this.isHighlighted = false; this.activatorBtn = UIMouseButton.Undefined; this.MouseSensor.Enter += this.OnEnter; this.MouseSensor.Leave += this.OnLeave; this.MouseSensor.ButtonDown += this.OnButtonDown; this.MouseSensor.ButtonUp += this.OnButtonUp; this.MouseSensor.Wheel += this.OnWheel; this.MouseSensor.Move += this.OnMove; }
/// <see cref="UISprite.TransparentColor_set"/> protected override void TransparentColor_set(RCColor newColor) { if (this.isLocked) { throw new UIException("Sprite is locked"); } if (newColor == RCColor.Undefined) { /// The transparent bitmap should be deleted and the original bitmap has to be loaded. this.transparentBitmap.Dispose(); this.transparentBitmap = null; TraceManager.WriteAllTrace("XnaSprite: transparent bitmap destroyed", XnaTraceFilters.DETAILS); } else { /// The transparent bitmap should be replaced and has to be loaded. if (this.transparentBitmap != null) { this.transparentBitmap.Dispose(); } this.transparentBitmap = new Bitmap(this.rawBitmap.Width, this.rawBitmap.Height, PixelFormat.Format24bppRgb); XnaBitmapUtils.CopyBitmapScaled(this.rawBitmap, this.transparentBitmap, this.PixelSize, this.PixelSize); this.transparentBitmap.MakeTransparent(Color.FromArgb(newColor.R, newColor.G, newColor.B)); TraceManager.WriteAllTrace("XnaSprite: transparent bitmap replaced", XnaTraceFilters.DETAILS); } }
/// <summary> /// Gets the font sprite with the given pixel size and font color. /// </summary> /// <param name="pixelSize">The pixel size of the font sprite.</param> /// <param name="fontColor">The color of the font sprite.</param> /// <returns>The font sprite with the given pixel size and font color.</returns> public UISprite GetFontSprite(RCIntVector pixelSize, RCColor fontColor) { if (pixelSize == RCIntVector.Undefined) { throw new ArgumentNullException("pixelSize"); } if (fontColor == RCColor.Undefined) { throw new ArgumentNullException("fontColor"); } UIFontSpriteDefinition spriteDef = new UIFontSpriteDefinition(pixelSize, fontColor); if (!this.fontSprites.ContainsKey(spriteDef)) { /// Load the font sprite with the given pixel size and color if necessary. UISprite newFontSprite = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(fontColor, this.originalFontSprite.Size, pixelSize); IUIRenderContext newFontSpriteCtx = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateRenderContext(newFontSprite); newFontSpriteCtx.RenderSprite(this.originalFontSprite, new RCIntVector(0, 0)); UIRoot.Instance.GraphicsPlatform.SpriteManager.CloseRenderContext(newFontSprite); newFontSprite.TransparentColor = this.transparentColor; newFontSprite.Upload(); this.fontSprites.Add(spriteDef, newFontSprite); } return(this.fontSprites[spriteDef]); }
public MySensitiveAnimObject(RCIntVector position, RCIntRectangle range, string name, RCColor basicColor, RCColor highColor) : base(position, range, name, basicColor, highColor) { this.anim = UIResourceManager.GetResource <UIAnimation>("RC.App.Animations.MainMenuTitleAnim"); this.anim.Reset(true); this.anim.Start(); }
public MyDraggableObject(RCIntVector position, RCIntRectangle range, string name, RCColor basicColor, RCColor highColor) : base(position, range, name, basicColor, highColor) { this.hookPosition = RCIntVector.Undefined; this.Activated += this.OnHooked; this.MouseSensor.Move += this.OnDrag; this.Inactivated += this.OnUnhooked; }
public MySlider(RCIntVector position, RCIntVector size, Settings settings, RCColor trackColor, RCColor sliderColor, RCColor disabledColor) : base(position, size, settings) { this.trackBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(trackColor, settings.Alignment == Alignment.Horizontal ? new RCIntVector(settings.TrackSize.X, settings.TrackSize.Y * 2 + 1) : new RCIntVector(settings.TrackSize.Y * 2 + 1, settings.TrackSize.X), new RCIntVector(2, 2)); this.sliderBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(sliderColor, new RCIntVector(settings.SliderLeft + settings.SliderRight + 1, settings.SliderTop + settings.SliderBottom + 1), new RCIntVector(2, 2)); this.disabledTrackBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(disabledColor, settings.Alignment == Alignment.Horizontal ? new RCIntVector(settings.TrackSize.X, settings.TrackSize.Y * 2 + 1) : new RCIntVector(settings.TrackSize.Y * 2 + 1, settings.TrackSize.X), new RCIntVector(2, 2)); this.disabledSliderBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(disabledColor, new RCIntVector(settings.SliderLeft + settings.SliderRight + 1, settings.SliderTop + settings.SliderBottom + 1), new RCIntVector(2, 2)); this.trackBackground.Upload(); this.sliderBackground.Upload(); this.disabledTrackBackground.Upload(); this.disabledSliderBackground.Upload(); }
/// <summary> /// Constructs a multi-variant sprite palette. /// </summary> /// <param name="imageData">The byte sequence that contains the image data of this sprite palette.</param> /// <param name="transpColor">The the transparent color of the image data or RCColor.Undefined if no transparent color is defined.</param> /// <param name="ownerMaskColorStr">The mask color of the image data or RCColor.Undefined if no mask color is defined.</param> public SpritePalette(byte[] imageData, RCColor transpColor, RCColor ownerMaskColor) { if (imageData == null || imageData.Length == 0) { throw new ArgumentNullException("imageData"); } this.index = -1; this.imageData = imageData; this.transparentColor = transpColor; this.maskColor = ownerMaskColor; this.sourceRegions = new List <RCIntRectangle>(); this.offsets = new List <RCIntVector>(); this.indexTable = new Dictionary <string, Dictionary <TVariant, int> >(); }
/// <summary> /// Initializes a new UIFontSpriteDefinition with the specified pixel size and font color. /// </summary> /// <param name="pixelSize">The pixel size of the font sprite.</param> /// <param name="fontColor">The color of the font sprite.</param> public UIFontSpriteDefinition(RCIntVector pixelSize, RCColor fontColor) { if (pixelSize == RCIntVector.Undefined) { throw new ArgumentNullException("pixelSize"); } if (fontColor == RCColor.Undefined) { throw new ArgumentNullException("fontColor"); } this.isDefined = true; this.pixelSize = pixelSize; this.fontColor = fontColor; }
/// <summary> /// Constructs a UIString from the given composite format string. /// </summary> /// <param name="format">The composite format of the UIString.</param> /// <param name="font">The font of the string.</param> /// <param name="pixelSize">The pixel size of the string.</param> /// <param name="color">The color of the string.</param> /// <remarks> /// The composite format string consists of zero or more runs of text intermixed with zero or more indexed /// placeholders, called format items, that correspond to the variable sections of this UIString. /// The formatting process replaces each format item with the corresponding variable section of this UIString. /// The syntax of a format item is as follows: {index}. /// Here the index is an integer that represents the index of the corresponding variable section. /// The leading and trailing brace characters, "{" and "}", are required. To specify a single literal brace /// character in format, specify two leading or trailing brace characters; that is, "{{" or "}}". /// Note that every whitespace characters in the format string will be replaced by spaces. /// </remarks> public UIString(string format, UIFont font, RCIntVector pixelSize, RCColor color) { if (format == null || format.Length == 0) { throw new ArgumentNullException("format"); } if (font == null) { throw new ArgumentNullException("font"); } if (pixelSize == RCIntVector.Undefined) { throw new ArgumentNullException("pixelSize"); } if (color == RCColor.Undefined) { throw new ArgumentNullException("color"); } /// Parse the incoming format string. format = Regex.Replace(format, "\\s", " "); List <PlaceHolder> placeHolders = SearchPlaceHolders(format); this.constantParts = ChopFormatString(format, placeHolders); /// Create or collect the necessary images this.font = font; this.fontSprite = this.font.GetFontSprite(pixelSize, color); this.stringRibbon = CreateEmptyStringRibbon(this.constantParts, this.font, this.fontSprite); this.variableIndices = new List <int>(); foreach (PlaceHolder ph in placeHolders) { this.variableIndices.Add(ph.Number); } /// Fill the ribbon and create the internal data structures for rendering this string. this.Initialize(); if (this.stringRibbon != null) { //this.stringRibbon.Save(format + ".png"); this.stringRibbon.TransparentColor = this.fontSprite.TransparentColor; this.stringRibbon.Upload(); } this.allFragmentCache = null; this.widthCache = new CachedValue <int>(this.ComputeWidth); }
public MyButton(RCIntVector position, RCIntVector size, RCColor basicColor, RCColor highlightedColor, RCColor disabledColor, string text) : base(position, size) { this.textStr = new UIString(text, UIResourceManager.GetResource <UIFont>("RC.App.Fonts.Font6"), new RCIntVector(2, 2), RCColor.Black); this.basicBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(basicColor, this.Range.Size - new RCIntVector(2, 2), new RCIntVector(2, 2)); this.highlightedBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(highlightedColor, this.Range.Size - new RCIntVector(2, 2), new RCIntVector(2, 2)); this.disabledBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(disabledColor, this.Range.Size - new RCIntVector(2, 2), new RCIntVector(2, 2)); this.basicBackground.Upload(); this.highlightedBackground.Upload(); this.disabledBackground.Upload(); }
/// <summary> /// Constructs a TileVariant object. /// </summary> /// <param name="imageData">The byte sequence that contains the image data of this variant.</param> /// <param name="transparentColor">The transparent color of the image of this variant.</param> /// <param name="tileset">Reference to the tileset of this variant.</param> public IsoTileVariant(byte[] imageData, RCColor transparentColor, TileSet tileset) { if (imageData == null || imageData.Length == 0) { throw new ArgumentNullException("imageData"); } if (transparentColor == RCColor.Undefined) { throw new ArgumentNullException("transparentColor"); } if (tileset == null) { throw new ArgumentNullException("tileset"); } this.imageData = imageData; this.transparentColor = transparentColor; this.cellDataChangesets = new List <ICellDataChangeSet>(); this.tileset = tileset; }
public MyDropdownSelector(RCIntVector position, RCIntVector size, string[] options, RCColor basicTextColor, RCColor highlightedTextColor, RCColor basicBackground, RCColor highlightedBackground, RCColor optListBackground, RCColor disabledBackground) : base(position, size, options.Length) { this.basicOptions = new UIString[options.Length]; this.highlightedOptions = new UIString[options.Length]; for (int i = 0; i < options.Length; i++) { this.basicOptions[i] = new UIString(options[i], UIResourceManager.GetResource <UIFont>("RC.App.Fonts.Font6"), new RCIntVector(2, 2), basicTextColor); this.highlightedOptions[i] = new UIString(options[i], UIResourceManager.GetResource <UIFont>("RC.App.Fonts.Font6"), new RCIntVector(2, 2), highlightedTextColor); } this.basicBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(basicBackground, new RCIntVector(size.X, size.Y), new RCIntVector(2, 2)); this.highlightedBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(highlightedBackground, new RCIntVector(size.X, size.Y), new RCIntVector(2, 2)); this.optListBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(optListBackground, new RCIntVector(size.X, size.Y * this.basicOptions.Length), new RCIntVector(2, 2)); this.disabledBackground = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(disabledBackground, new RCIntVector(size.X, size.Y), new RCIntVector(2, 2)); this.basicBackground.Upload(); this.highlightedBackground.Upload(); this.optListBackground.Upload(); this.disabledBackground.Upload(); }
/// <summary> /// Creates a brush with the given color. /// </summary> private UISprite CreateBrush(RCColor color) { return(UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(color, new RCIntVector(1, 1), UIWorkspace.Instance.PixelScaling)); }
/// <summary> /// Constructs a TerrainObjectType instance. /// </summary> /// <param name="name">The name of the TerrainObjectType.</param> /// <param name="imageData">The byte sequence that contains the image data of the TerrainObjectType.</param> /// <param name="quadraticSize">The size of the TerrainObjectType in quadratic tiles.</param> /// <param name="transparentColor">The transparent color of this TerrainObjectType.</param> /// <param name="tileset">Reference to the tileset that this TerrainObjectType belongs to.</param> public TerrainObjectType(string name, byte[] imageData, RCIntVector quadraticSize, RCColor transparentColor, TileSet tileset) { if (name == null) { throw new ArgumentNullException("name"); } if (imageData == null || imageData.Length == 0) { throw new ArgumentNullException("imageData"); } if (quadraticSize == RCIntVector.Undefined) { throw new ArgumentNullException("quadraticSize"); } if (transparentColor == RCColor.Undefined) { throw new ArgumentNullException("transparentColor"); } if (tileset == null) { throw new ArgumentNullException("tileset"); } if (quadraticSize.X <= 0 || quadraticSize.Y <= 0) { throw new ArgumentOutOfRangeException("quadraticSize", "Quadratic size cannot be 0 in any direction!"); } this.name = name; this.imageData = imageData; this.quadraticSize = quadraticSize; this.transparentColor = transparentColor; this.tileset = tileset; this.areaCanBeExcluded = true; this.constraints = new List <ITerrainObjectConstraint>(); this.cellDataChangesets = new List <ICellDataChangeSet>(); this.includedQuadCoords = new RCSet <RCIntVector>(); for (int x = 0; x < quadraticSize.X; x++) { for (int y = 0; y < quadraticSize.Y; y++) { this.includedQuadCoords.Add(new RCIntVector(x, y)); } } }
/// <summary> /// Internal method to setting a new transparent color. /// </summary> /// <param name="newColor">The new transparent color to set.</param> /// <remarks>This method is only called when the transparent color has been changed.</remarks> protected abstract void TransparentColor_set(RCColor newColor);
/// <summary> /// Creates a TerrainObjectType. /// </summary> /// <param name="name">The name of the TerrainObjectType.</param> /// <param name="imgData">The byte sequence that contains the image data of the TerrainObjectType.</param> /// <param name="quadSize">The size of the TerrainObjectType in quadratic tiles.</param> /// <param name="transparentColor">The transparent color of the TerrainObjectType.</param> public void CreateTerrainObjectType(string name, byte[] imgData, RCIntVector quadSize, RCColor transparentColor) { if (this.isFinalized) { throw new InvalidOperationException("It is not possible to create new TerrainObjectType for a finalized TileSet!"); } if (name == null) { throw new ArgumentNullException("name"); } if (this.terrainObjectTypes.ContainsKey(name)) { throw new TileSetException(string.Format("TerrainObjectType with name '{0}' already exists!", name)); } TerrainObjectType newTerrainObject = new TerrainObjectType(name, imgData, quadSize, transparentColor, this); newTerrainObject.SetIndex(this.allTerrainObjectList.Count); this.terrainObjectTypes.Add(name, newTerrainObject); this.allTerrainObjectList.Add(newTerrainObject); }
/// <see cref="IUISpriteManager.CreateSprite"/> public abstract UISprite CreateSprite(RCColor color, RCIntVector spriteSize, RCIntVector pixelSize);