예제 #1
0
        /// <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();

            Manager.ImageCompositor.CreateSpriteFont(Theme.FontName);

            // Calculate the width and height
            Config.Width  = 1;                                                                      // width should be really thin
            Config.Height = (int)Manager.ImageCompositor.ReadSizeString(Theme.FontName, "M").Y - 1; // height should be compared to the used font
            this.UpdateDrawSizeByConfig();

            // create the texture
            this.CurrentTextureName = Manager.ImageCompositor.CreateRectangleTexture(this.Name, (int)Config.Width, (int)Config.Height, 0, GUIColor.MidnightBlue(), GUIColor.MidnightBlue());

            // create a new color for the texture..
            var count      = (int)(Config.Width * Config.Height);
            var colorArray = new GUIColor[count];

            for (var i = 0; i < count; i++)
            {
                colorArray[i] = GUIColor.MidnightBlue();
            }

            var map = new ColorMap(colorArray, (int)this.Config.Width, (int)this.Config.Height);

            Manager.ImageCompositor.UpdateTexture(this.CurrentTextureName, map);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScrollBarBase"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        protected ScrollBarBase(string name) : base(name)
        {
            Theme.FillColor = GUIColor.White();

            this.ConfigStep  = DefaultStep;
            this.ConfigValue = DefaultValue;
            this.ConfigMin   = DefaultMin;
            this.ConfigMax   = DefaultMax;
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorBoxGradient"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 public ColorBoxGradient(string name) : base(name)
 {
     this.hsl = new HSL {
         H = 0.3, S = 0.6, L = 0.8
     };
     this.rgba              = AdobeColors.HSLToRGB(this.hsl);
     this.drawStyle         = DrawStyle.Hue;
     Config.Width           = Theme.ControlWidth;
     Config.Height          = Theme.ControlWidth;
     this.redrawControlFlag = true;
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ListBox"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 public ListBox(string name) : base(name)
 {
     this.FontColor         = GUIColor.MidnightBlue();
     this.ListBoxItems      = new Collection <ListBoxItem>();
     this.SelectedIndex     = -1;
     this.ItemHeight        = this.Theme.ControlHeight;
     this.Theme.FillColor   = GUIColor.White();
     this.Theme.BorderColor = GUIColor.Black();
     this.Config.Width      = this.Theme.ControlWidth;
     this.Config.Height     = this.Theme.ControlWidth;
 }
예제 #5
0
 public Color GetColor(GUIColor col)
 {
     if ((int)col < cols.Count)
     {
         return(cols[(int)col]);
     }
     else
     {
         return(Color.white);
     }
 }
예제 #6
0
        /// <summary>
        /// Draw the texture at DrawPosition combined with its offset
        /// </summary>
        public override void DrawMyData()
        {
            // we are killing the default behavior of drawing data , cause sometimes we DON'T want to be shown.
            // base.DrawMyData();

            // draw the cursor if _blink is not on, and if the cursor should be shown.
            if (this.ConfigBlinking && this.ConfigShowCursor)
            {
                Manager.ImageCompositor.Draw(this.CurrentTextureName, this.State, GUIColor.White());
            }
        }
예제 #7
0
파일: GuiColor.cs 프로젝트: shangshen/cozy
        /// <summary>
        /// Implements the operator /.
        /// </summary>
        /// <param name="left">The left item to operate.</param>
        /// <param name="right">The right item to operate.</param>
        /// <returns>
        /// The result of the operator.
        /// </returns>
        public static GUIColor operator /(GUIColor left, GUIColor right)
        {
            var newClr = new GUIColor
            {
                A = (byte)(left.A / right.A),
                R = (byte)(left.R / right.R),
                G = (byte)(left.G / right.G),
                B = (byte)(left.B / right.B)
            };

            return(newClr);
        }
예제 #8
0
파일: GuiColor.cs 프로젝트: shangshen/cozy
        /// <summary>
        /// Implements the operator /.
        /// </summary>
        /// <param name="left">The left item to operate.</param>
        /// <param name="value">The value to operate.</param>
        /// <returns>
        /// The result of the operator.
        /// </returns>
        public static GUIColor operator /(GUIColor left, float value)
        {
            var newClr = new GUIColor
            {
                A = (byte)(left.A / value),
                R = (byte)(left.R / value),
                G = (byte)(left.G / value),
                B = (byte)(left.B / value)
            };

            return(newClr);
        }
예제 #9
0
        /// <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()
        {
            // this needs to happen first
            base.LoadContent();

            // set my appearance values
            Theme.BorderWidth = 0;
            Theme.FillColor   = GUIColor.Transparent();

            // make the internal stuff that i show
            this.mustredraw = true;
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckBox"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public CheckBox(string name)
            : base(name)
        {
            this.FontColor = GUIColor.MidnightBlue();

            this.Theme.FillColor   = this.Theme.InputFillColor;
            this.Theme.BorderColor = this.Theme.BorderColor;

            this.Config.Width  = this.Theme.ControlWidth;
            this.Config.Height = this.Theme.ControlHeight;

            this.ConfigText = string.Empty;
        }
예제 #11
0
        /// <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.UpdateDrawPositionByConfigAndParent();
            this.UpdateDrawSizeByConfig();
            this.UpdateDrawSourceRectangleByConfig();

            const int Width  = 10;
            const int Height = 10;
            var       color  = new GUIColor(0, 0, 255);

            this.CurrentTextureName = this.Manager.ImageCompositor.CreateFlatTexture(this.Name + "-Background", Width, Height, color);
        }
예제 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Grid"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public Grid(string name) : base(name)
        {
            this.cellHeight        = Theme.ControlHeight;
            this.cellWidth         = Theme.ControlWidth;
            this.configLineWidth   = DefaultGridLineWidth;
            this.configColumnCount = 4;
            this.configRowCount    = 4;

            Config.Width  = this.cellWidth * this.ConfigRowCount;
            Config.Height = this.cellHeight * this.ConfigColumnCount;

            this.gridColor = Theme.FillColor;

            this.mustredraw = true;
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorSliderVertical"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public ColorSliderVertical(string name) : base(name)
        {
            // Initialize Colors
            this.hsl = new HSL {
                H = 1.0, S = 1.0, L = 1.0
            };
            this.rgba = AdobeColors.HSLToRGB(this.hsl);

            // pick a format to show
            this.drawStyle = DrawStyle.Hue;

            this.Padding = 9;

            Config.Width  = Theme.ControlHeight;
            Config.Height = Theme.ControlWidth;
        }
예제 #15
0
        /// <summary>Fills in the content of the control showing all values of Blue (0 to 255) for the given
        /// Red and Green.</summary>
        /// <param name="map">The map to update.</param>
        private void DrawStyleBlue(ref ColorMap map)
        {
            // i represents the current line of pixels we want to draw horizontally
            for (var i = 0; i < map.Height; i++)
            {
                // red is based on the current vertical position
                var blue = 255 - Round(255 * (double)i / map.Height);

                // Get the Color for this line
                var rgb = GUIColor.FromARGB(this.rgba.R, this.rgba.G, blue);
                for (var l = 0; l < map.Width; l++)
                {
                    map.Set(l, i, rgb);
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Draw the texture at DrawPosition combined with its offset
        /// </summary>
        public override void DrawMyData()
        {
            if (this.columnLineTextureNames == null)
            {
                return;
            }

            // draw the background
            // Manager.ImageCompositor.Draw(CurrentTextureName, this.State, GUIColor.White());

            // draw lines if needed
            if (this.configLineWidth <= 0)
            {
                return;
            }

            var tempState = new DrawState();

            // draw the column lines
            for (var i = 0; i < this.columnLineTextureNames.Length; i++)
            {
                tempState.DrawPosition    = new DVector2((float)i * (this.cellWidth + this.configLineWidth), 0) + State.DrawPosition;
                tempState.Width           = this.configLineWidth;
                tempState.Height          = Config.Height;
                tempState.SourceRectangle = new Rectangle(0, 0, tempState.Width, tempState.Height);

                var name = this.columnLineTextureNames[i];
                Manager.ImageCompositor.Draw(name, tempState, GUIColor.White());

                // System.Diagnostics.Debug.WriteLine("Drawing column line at : " + tempState.DrawPosition + " to " + (tempState.DrawPosition + new DVector2(tempState.Width, tempState.Height)));
            }

            // draw the row lines
            for (var i = 0; i < this.rowLineTextureNames.Length; i++)
            {
                tempState.DrawPosition    = new DVector2(0, (float)i * (this.cellHeight + this.configLineWidth)) + State.DrawPosition;
                tempState.Width           = Config.Width;
                tempState.Height          = this.configLineWidth;
                tempState.SourceRectangle = new Rectangle(0, 0, tempState.Width, tempState.Height);

                var name = this.rowLineTextureNames[i];
                Manager.ImageCompositor.Draw(name, tempState, GUIColor.White());

                // System.Diagnostics.Debug.WriteLine("Drawing row line at : " + tempState.DrawPosition + " to " + (tempState.DrawPosition + new DVector2(tempState.Width, tempState.Height)));
            }
        }
예제 #17
0
        public virtual void DrawPanel(float currentTime)
        {
            this.inserted = false;

            Rect rect = new Rect(0, 0, 25, 15);

            using (GUIColor color = new GUIColor(this.enabled ? Color.green : GUI.backgroundColor, GUI.contentColor))
            {
                bool bTmp;
                bTmp = GUI.Toggle(rect, this.enabled, "E", new GUIStyle("button"));
                if (bTmp != this.enabled)
                {
                    this.enabled = bTmp;
                }
            }

            rect.x = 25;
            if (GUI.Button(rect, "K"))
            {
                this.InsertKeyframesAtTime(currentTime);
            }

            rect.x  = 0;
            rect.y += rect.height;
            if (GUI.Button(rect, "C"))
            {
                this.InsertNewClip();
                this.inserted = true;
            }

            rect.x = 25;
            if (GUI.Button(rect, "-"))
            {
                this.Delete();
            }
            rect.x     = 0;
            rect.y    += rect.height;
            rect.width = rect.width * 2;

            GUILayout.BeginArea(rect);
            this.DrawPanelExtra(currentTime);
            GUILayout.EndArea();
        }
예제 #18
0
        /// <summary>
        /// Redraws the box.
        /// </summary>
        private void RedrawBox()
        {
            // when there are no changes , do nothing
            if (this.currentrgba.Equals(this.rgba))
            {
                return;
            }

            // we have a new color , destroy the old , plant the new
            if (Manager.ImageCompositor.Contains(this.CurrentTextureName))
            {
                // destroy the old !
                Manager.ImageCompositor.Delete(this.CurrentTextureName);
            }

            // create the new
            this.CurrentTextureName = Manager.ImageCompositor.CreateRectangleTexture(this.Name + "-FillColor", (int)Config.Width, (int)Config.Height, 1, this.rgba, Theme.BorderColor);
            this.currentrgba        = this.rgba;
        }
예제 #19
0
        private static void SetSelectionRectangle(Rectangle rectangle, TextBoxSelectionBox textBoxSelectionBox, GUIColor color)
        {
            if (rectangle.Width >= 1 && rectangle.Height >= 1)
            {
                textBoxSelectionBox.CurrentTextureName = textBoxSelectionBox.Manager.ImageCompositor.CreateRectangleTexture(textBoxSelectionBox.Name, (int)rectangle.Width, (int)rectangle.Height, 0, GUIColor.White(), GUIColor.White());
                var size  = textBoxSelectionBox.Manager.ImageCompositor.ReadSizeTexture(textBoxSelectionBox.CurrentTextureName);
                var count = (int)size.X * (int)size.Y;

                var colorArray = new GUIColor[count];
                for (var i = 0; i < count; i++)
                {
                    colorArray[i] = color;
                }

                var map = new ColorMap(colorArray, (int)size.X, (int)size.Y);

                textBoxSelectionBox.Manager.ImageCompositor.UpdateTexture(textBoxSelectionBox.CurrentTextureName, map);

                textBoxSelectionBox.ConfigActive = true;
            }
        }
예제 #20
0
        /// <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()
        {
            if (this.hsl == null)
            {
                this.hsl = new HSL {
                    H = 1.0, S = 1.0, L = 1.0
                };
                this.rgba = AdobeColors.HSLToRGB(this.hsl);
            }

            Config.Width  = Theme.ControlHeight;
            Config.Height = Theme.ControlWidth;

            // create left indicator
            this.IndicatorLeft = new ColorSliderVerticalIndicator(Name + "-indicatorLeft")
            {
                Side    = Side.Left,
                Manager = Manager
            };
            this.AddControl(this.IndicatorLeft);

            // create right indicator
            this.IndicatorRight = new ColorSliderVerticalIndicator(Name + "-indicatorRight")
            {
                Side    = Side.Right,
                Manager = Manager
            };
            this.AddControl(this.IndicatorRight);

            this.SetIndicatorPosition(0);

            this.RedrawControl();

            // do the basic stuff
            base.LoadContent();
            this.UpdateDrawPositionByConfigAndParent();
            this.UpdateDrawSizeByConfig();
        }
예제 #21
0
        /// <summary>
        /// Draws the specified texture using specified draw-state , with a tint color.
        /// </summary>
        /// <param name="name">The name of the item to draw.</param>
        /// <param name="drawState">The state that contains all the info to draw the item.</param>
        /// <param name="tintColor">The color to use to tint the shown item.</param>
        public override void Draw(string name, DrawState drawState, GUIColor tintColor)
        {
#if DEBUG
            if (drawState == null)
            {
                throw new ArgumentNullException("drawState", "DrawState is used for drawing. This can not be Null.");
            }
#endif
            // get the texture to draw
            var texture = this.resourcesTexture.Read(name);

            // calculate what part to draw where
            var scaleVector = new Vector2(drawState.Width / texture.Width, drawState.Height / texture.Height);
            var position    = new Vector2(drawState.DrawPosition.X + drawState.Offset.X, drawState.DrawPosition.Y + drawState.Offset.Y);
            var origin      = new Vector2();
            var color       = new Color(tintColor.R, tintColor.G, tintColor.B, tintColor.A);

            Rectangle srcRect;
            if (drawState.SourceRectangle == null)
            {
                srcRect = new Rectangle(0, 0, texture.Width, texture.Height);
            }
            else
            {
                srcRect = new Rectangle((int)drawState.SourceRectangle.PositionX, (int)drawState.SourceRectangle.PositionY, (int)drawState.SourceRectangle.Width, (int)drawState.SourceRectangle.Height);
            }

            this.spriteBatch.Draw(
                texture,
                position,
                srcRect,
                color,
                0,
                origin,
                scaleVector,
                SpriteEffects.None,
                0);
        }
예제 #22
0
        /// <summary>Creates the texture.</summary>
        /// <param name="name">The name of the texture.</param>
        /// <param name="width">The width of the texture.</param>
        /// <param name="height">The height of the texture.</param>
        /// <param name="color">The color of texture.</param>
        /// <returns>The created texture.</returns>
        /// <exception cref="ArgumentNullException">Name is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">width can not be smaller then 1 and height can not be smaller then 1. </exception>
        public string Create(string name, int width, int height, GUIColor color)
        {
#if DEBUG
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (width < 1)
            {
                throw new ArgumentOutOfRangeException("width", "width can not be smaller then 1");
            }

            if (height < 1)
            {
                throw new ArgumentOutOfRangeException("height", "height can not be smaller then 1");
            }
#endif

            var texture = new Texture2D(this.device, width, height, false, SurfaceFormat.Color);
            var count   = width * height;
            var array   = new GUIColor[count];

            for (var i = 0; i < array.Length; i++)
            {
                array[i] = color;
            }

            texture.SetData(array);

            var resourceName = UniqueNameCreator.GetUniqueName(name);
            texture.Name = resourceName;

            Resources.Add(resourceName, texture);

            return(resourceName);
        }
예제 #23
0
 /// <summary>Creates a rectangle texture. </summary>
 /// <param name="preferredName">The preferred name to use.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="borderWidth">Width of the border.</param>
 /// <param name="fillColor">Color of the fill.</param>
 /// <param name="borderColor">Color of the border.</param>
 /// <returns>The URL to the created texture resource that looks like a rectangle.</returns>
 public abstract string CreateRectangleTexture(string preferredName, int width, int height, int borderWidth, GUIColor fillColor, GUIColor borderColor);
예제 #24
0
 /// <summary>
 /// Creates a flat texture with one color.
 /// </summary>
 /// <param name="preferredName">The preferred name to use.</param>
 /// <param name="width">The width of the line texture.</param>
 /// <param name="height">The height of the line texture.</param>
 /// <param name="color">The fill color of the line texture.</param>
 /// <returns>the name to use to find the texture back.</returns>
 public abstract string CreateFlatTexture(string preferredName, int width, int height, GUIColor color);
예제 #25
0
 /// <summary>Draws the string using specified location font and color.</summary>
 /// <param name="fontName">Name of the font.</param>
 /// <param name="text">The text to draw.</param>
 /// <param name="position">The position of the text.</param>
 /// <param name="fontColor">Color of the font.</param>
 public abstract void DrawString(string fontName, string text, DVector2 position, GUIColor fontColor);
예제 #26
0
 /// <summary>
 /// Clears the current render target with given color.
 /// </summary>
 /// <param name="clearColor">Color of the clear.</param>
 public abstract void Clear(GUIColor clearColor);
예제 #27
0
파일: GuiColor.cs 프로젝트: xxy1991/cozy
 /// <summary>Does a Equals check by checking the values of A,R,G and B.</summary>
 /// <param name="other">The other.</param>
 /// <returns>true if all are the same.</returns>
 public bool Equals(GUIColor other)
 {
     return (this.R == other.R) && (this.G == other.G) && (this.B == other.B) && (this.A == other.A);
 }
예제 #28
0
 /// <summary>
 /// Draws the specified texture using specified draw-state , with a tint color.
 /// </summary>
 /// <param name="name">The name of the item to draw.</param>
 /// <param name="drawState">The state that contains all the info to draw the item.</param>
 /// <param name="tintColor">The color to use to tint the shown item.</param>
 public abstract void Draw(string name, DrawState drawState, GUIColor tintColor);
예제 #29
0
파일: GuiColor.cs 프로젝트: xxy1991/cozy
 public GUIColor Subtract(GUIColor left, GUIColor right)
 {
     return left - right;
 }
예제 #30
0
파일: GuiColor.cs 프로젝트: xxy1991/cozy
 /// <summary>Adds the specified left color to the right and returns the result.</summary>
 /// <param name="left">The left item to operate.</param>
 /// <param name="right">The right item to operate.</param>
 /// <returns>Left color added to the Right color.</returns>
 public static GUIColor Add(GUIColor left, GUIColor right)
 {
     return left + right;
 }
예제 #31
0
파일: GuiColor.cs 프로젝트: xxy1991/cozy
 /// <summary>
 /// Implements the operator /.
 /// </summary>
 /// <param name="left">The left item to operate.</param>
 /// <param name="right">The right item to operate.</param>
 /// <returns>
 /// The result of the operator.
 /// </returns>
 public static GUIColor operator /(GUIColor left, GUIColor right)
 {
     var newClr = new GUIColor
     {
         A = (byte)(left.A / right.A),
         R = (byte)(left.R / right.R),
         G = (byte)(left.G / right.G),
         B = (byte)(left.B / right.B)
     };
     return newClr;
 }
예제 #32
0
파일: GuiColor.cs 프로젝트: xxy1991/cozy
 public GUIColor Multiply(GUIColor left, GUIColor right)
 {
     return left * right;
 }
예제 #33
0
파일: GuiColor.cs 프로젝트: xxy1991/cozy
 public GUIColor Divide(GUIColor left, GUIColor right)
 {
     return left / right;
 }
예제 #34
0
파일: GuiColor.cs 프로젝트: xxy1991/cozy
 /// <summary>
 /// Implements the operator /.
 /// </summary>
 /// <param name="left">The left item to operate.</param>
 /// <param name="value">The value to operate.</param>
 /// <returns>
 /// The result of the operator.
 /// </returns>
 public static GUIColor operator /(GUIColor left, float value)
 {
     var newClr = new GUIColor
     {
         A = (byte)(left.A / value),
         R = (byte)(left.R / value),
         G = (byte)(left.G / value),
         B = (byte)(left.B / value)
     };
     return newClr;
 }
예제 #35
0
    // Draws the chat
    public void DrawChat()
    {
        using (new GUIVertical()) {
            // Chat messages
            using (new GUIScrollView(ref chatScrollPosition)) {
                using (new GUIVertical()) {
                    for (int i = 0; i < entries.Count; i++)
                    {
                        var entry   = entries[i];
                        var msgRect = GUILayoutUtility.GetRect(entry.guiContent, textStyle);

                        GUIHelper.Shadowed(
                            msgRect.x, msgRect.y,
                            (x, y) => {
                            GUI.contentColor = entry.color;
                            msgRect.x        = x;
                            msgRect.y        = y;
                            GUI.Label(msgRect, entry.guiContent, textStyle);
                        }
                            );
                    }

                    GUI.contentColor = Color.white;
                }
            }

            // Set chat input color
            if (inGameLobby.currentState == GameLobbyState.Game)
            {
                if (chatInputFocused)
                {
                    chatInputColor = Color.white;
                }
                else
                {
                    chatInputColor = new Color(1f, 1f, 1f, 0f);
                }
            }
            else
            {
                chatInputColor = Color.white;
            }

            GUI.color = chatInputColor;

            // Channel + input field
            using (new GUIHorizontal()) {
                // Channel switch
                if (inGameLobby.currentState != GameLobbyState.Game || chatInputFocused)
                {
                    GUI.contentColor = GUIColor.GetChannelColor(currentChannel);
                    GUILayout.Box(currentChannel, GUILayout.ExpandWidth(false));
                    GUI.contentColor = Color.white;
                }
                else
                {
                    GUILayout.Box("_", GUILayout.ExpandWidth(false));
                }

                // Save settings before changing them
                //var wordWrap = GUI.skin.textField.wordWrap;
                var richText = GUI.skin.textField.richText;
                //var fixedWidth = GUI.skin.textField.fixedWidth;

                //GUI.skin.textField.wordWrap = true;
                GUI.skin.textField.richText = true;
                //GUI.skin.textField.fixedWidth = GUIArea.width * 0.1f;

                // Chat input field
                GUI.enabled = chatInputEnabled && chatInputFocused;
                GUI.SetNextControlName("LobbyChatInput");
                GUILayout.Box("");

                chatText = GUI.TextField(GUILayoutUtility.GetLastRect(), chatText, 300);

                // Reset old settings
                //GUI.skin.textField.wordWrap = wordWrap;
                GUI.skin.textField.richText = richText;
                //GUI.skin.textField.fixedWidth = fixedWidth;
            }

            GUILayout.Space(4);

            GUI.enabled = true;
            GUI.color   = Color.white;

            // Debug

            /*GUI.Label(new Rect(300, 0, 500, 25), GUI.GetNameOfFocusedControl());
             * GUI.Label(new Rect(300, 25, 500, 25), Event.current.type.ToString());
             * GUI.Label(new Rect(300, 50, 500, 25), inGameLobby.currentState.ToString());
             * GUI.Label(new Rect(300, 75, 500, 25), chatInputEnabled.ToString());*/

            // Only on editing the current message we save it in array
            if (myMessagesIndex == myMessages.Count - 1)
            {
                myMessages[myMessages.Count - 1] = chatText;
            }

            if (chatInputFocused)
            {
                // This is for Asian IME input, we only send
                // if Return hasn't been used to change the text.
                if (Event.current.type == EventType.KeyDown)
                {
                    chatTextBeforeReturn = chatText;
                }

                // The KeyUp event follows afterwards
                if (Event.current.type == EventType.KeyUp)
                {
                    switch (Event.current.keyCode)
                    {
                    // Return
                    case KeyCode.Return:
                        if (chatText == chatTextBeforeReturn)
                        {
                            SendChat();

                            if (inGameLobby.currentState == GameLobbyState.Game)
                            {
                                GUIHelper.ClearAllFocus();
                            }
                        }
                        break;

                    // Up
                    case KeyCode.UpArrow:
                        if (myMessages.Count == 0)
                        {
                            break;
                        }

                        myMessagesIndex -= 1;
                        if (myMessagesIndex < 0)
                        {
                            myMessagesIndex = 0;
                        }
                        chatText = myMessages[myMessagesIndex];
                        break;

                    // Down
                    case KeyCode.DownArrow:
                        if (myMessages.Count == 0)
                        {
                            break;
                        }

                        myMessagesIndex += 1;
                        if (myMessagesIndex >= myMessages.Count)
                        {
                            myMessagesIndex = myMessages.Count - 1;
                            chatText        = myMessages[myMessagesIndex];
                        }
                        else
                        {
                            chatText = myMessages[myMessagesIndex];
                        }
                        break;

                    // Space
                    case KeyCode.Space:
                        ChannelChange();
                        break;

                        /*case KeyCode.A:
                         *      if(Event.current.modifiers == EventModifiers.Control) {
                         *              //GUIHelper.ClearAllFocus();
                         *              //GUIHelper.Focus("LobbyChatInput");
                         *              TextEditor t = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                         *              t.SelectAll();
                         *              //LogManager.General.Log("Select all!");
                         *      }
                         *      break;*/
                    }
                }
            }
            else
            {
                if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Return && Login.instance.popupWindow == null)
                {
                    GUIHelper.Focus("LobbyChatInput");
                    Event.current.Use();
                }
            }
        }

        // Update focus info
        chatInputFocused = GUI.GetNameOfFocusedControl() == "LobbyChatInput";
    }
예제 #36
0
        /// <summary>Creates a rectangle texture.</summary>
        /// <param name="preferredName">The preferred name to use.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="borderWidth">Width of the border.</param>
        /// <param name="fillColor">Color of the fill.</param>
        /// <param name="borderColor">Color of the border.</param>
        /// <returns>The URL to the created texture resource that looks like a rectangle.</returns>
        /// <exception cref="ArgumentException">Width can not be zero or less;width
        /// or
        /// height can not be zero or less;height
        /// or
        /// Control name can not be null;preferredName
        /// or
        /// Border width can not be smaller then zero;borderWidth.</exception>
        public override string CreateRectangleTexture(string preferredName, int width, int height, int borderWidth, GUIColor fillColor, GUIColor borderColor)
        {
#if DEBUG
            if (width <= 0)
            {
                throw new ArgumentException("width can not be zero or less", "width");
            }

            if (height <= 0)
            {
                throw new ArgumentException("height can not be zero or less", "height");
            }

            if (string.IsNullOrEmpty(preferredName))
            {
                throw new ArgumentException("Control name can not be null", "preferredName");
            }

            if (borderWidth < 0)
            {
                throw new ArgumentException("Border width can not be smaller then zero", "borderWidth");
            }
#endif

            var textureName = this.resourcesTexture.Create(preferredName, width, height, fillColor);

            // var colordata = RectangleBrush.CreateRectangleColorMap(width, height,borderWidth,1,1, fillColor, borderColor);
            var colordata = ColorMapDrawer.CreateRectangleColorMap(width, height, borderWidth, fillColor, borderColor);
            // var colordata = ColorMapDrawer.CreateRoundedRectangleColorMap(
            //                                                            width,
            //                                                            height,
            //                                                            borderWidth,
            //                                                            20,
            //                                                            fillColor,
            //                                                            borderColor);
            this.resourcesTexture.Update(textureName, colordata.ToArray());

            return(textureName);
        }
예제 #37
0
        /// <summary>
        /// Clears the current render target with given color.
        /// </summary>
        /// <param name="clearColor">Color of the clear.</param>
        public override void Clear(GUIColor clearColor)
        {
            var clr = new Color(clearColor.R, clearColor.G, clearColor.B, clearColor.A);

            this.device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, clr, 1, 0);
        }