/// <summary> /// Called when graphics resources need to be loaded. /// Use this for the usage of : /// - creation of the internal embedded controls. /// - setting of the variables and resources in this control /// - to load any game-specific graphics resources /// - take over the config width and height and use it into State /// - overriding how this item looks like , by settings its texture or theme /// Call base.LoadContent before you do your override code, this will cause : /// - State.SourceRectangle to be reset to the Config.Size /// </summary> public override void LoadContent() { base.LoadContent(); this.UpdateDrawSizeByConfig(); this.ConfigDebug = false; if (this.ConfigDebug) { this.textureImage = this.Manager.ImageCompositor.CreateRectangleTexture( this.Name + "-" + this.ImagePath, (int)this.Config.Width, (int)this.Config.Height, 0, GUIColor.Gainsboro(), GUIColor.White()); } else { this.textureImage = Manager.ImageCompositor.CreateImageTexture( this.Name + "-" + this.ImagePath, this.ImagePath); } // get the used texture , and set the final size in state to the size of the texture var sourceSize = Manager.ImageCompositor.ReadSizeTexture(this.textureImage); State.SourceRectangle.Width = sourceSize.X; State.SourceRectangle.Height = sourceSize.Y; // scale to smallest var shrinkVertical = sourceSize.X / Config.Height; var shrinkHorizontal = sourceSize.Y / Config.Width; // find the biggest shrink var sc = shrinkHorizontal > shrinkVertical ? shrinkHorizontal : shrinkVertical; // use this scale State.Width = sourceSize.X / sc; State.Height = sourceSize.Y / sc; var left = (Config.Width / 2) - (State.Width / 2); var top = (Config.Height / 2) - (State.Height / 2); State.Offset = new DVector2(left, top); }
/// <summary> /// Redraws the control using a chosen style. /// </summary> private void RedrawControl() { this.SetIndicatorPosition(this.gradientValue); var width = (int)Config.Width; var heigth = (int)Config.Height; if (Manager.ImageCompositor.Contains(this.CurrentTextureName) == false) { this.CurrentTextureName = Manager.ImageCompositor.CreateFlatTexture(this.Name + "-Background", width, heigth, GUIColor.Gainsboro()); } var array = new ColorMap(width, heigth); switch (this.drawStyle) { case DrawStyle.Hue: this.DrawStyleHue(ref array); break; case DrawStyle.Saturation: this.DrawStyleSaturation(ref array); break; case DrawStyle.Brightness: this.DrawStyleLuminance(ref array); break; case DrawStyle.Red: this.DrawStyleRed(ref array); break; case DrawStyle.Green: this.DrawStyleGreen(ref array); break; case DrawStyle.Blue: this.DrawStyleBlue(ref array); break; } Manager.ImageCompositor.UpdateTexture(this.CurrentTextureName, array); }