Ejemplo n.º 1
0
        /// <summary>
        /// Gets the 32-bit ARGB simple color from the given hex string.
        /// </summary>
        /// <returns>The hex.</returns>
        /// <param name="hex">Hex.</param>
        public static SimpleColor FromHex(string hex)
        {
            if (hex == null)
            {
                throw new ArgumentNullException("hex");
            }
            if (hex.Length < 7)
            {
                throw new ArgumentOutOfRangeException("hex",
                                                      string.Format("The given string can never be a color: {0} too short.", hex));
            }

            if (hex.Length == 7)
            {
                return(SimpleColor.FromArgb(
                           Int32.Parse("FF" + hex.Replace("#", ""), System.Globalization.NumberStyles.HexNumber,
                                       System.Globalization.CultureInfo.InvariantCulture)));
            }
            else if (hex.Length == 9)
            {
                return(SimpleColor.FromArgb(
                           Int32.Parse(hex.Replace("#", ""), System.Globalization.NumberStyles.HexNumber,
                                       System.Globalization.CultureInfo.InvariantCulture)));
            }
            else if (hex.Length == 10)
            {
                return(SimpleColor.FromArgb(
                           Int32.Parse(hex.Replace("0x", ""), System.Globalization.NumberStyles.HexNumber,
                                       System.Globalization.CultureInfo.InvariantCulture)));
            }
            else
            {
                throw new ArgumentOutOfRangeException("hex",
                                                      string.Format("The given string can is not a hex-color: {0}.", hex));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the 32-bit ARGB simple color from the known color enumeration.
        /// </summary>
        /// <param name="kc"></param>
        /// <param name="alpha"></param>
        /// <returns></returns>
        public static SimpleColor FromKnownColor(KnownColor kc, int alpha)
        {
            SimpleColor knownColor = SimpleColor.FromKnownColor(kc);

            return(SimpleColor.FromArgb(alpha, knownColor.R, knownColor.G, knownColor.B));
        }
Ejemplo n.º 3
0
		/// <summary>
		/// Adds a basic series of triangles to render.
		/// </summary>
		/// <param name="corners">Triangle data.</param>
		/// <param name="argb">The ARGB colors.</param>
		public void AddTriangles(float[] corners, int argb)
		{
            lock (_triangles)
            {
                // a float is 4 bytes, therefore we multiply the number if
                // vertices with 4.
                ByteBuffer vbb = ByteBuffer.AllocateDirect(corners.Length * 4);
                vbb.Order(ByteOrder.NativeOrder());
                FloatBuffer vertexBuffer = vbb.AsFloatBuffer();
                vertexBuffer.Put(corners);
                vertexBuffer.Position(0);

                // The order we like to connect them.
                SimpleColor color = new SimpleColor()
                {
                    Value = argb
                };
                int count = corners.Length / 3;
                byte[] colors = new byte[count * 4];
                for (int idx = 0; idx < count; idx++)
                {
                    colors[idx * 4] = (byte)color.R;
                    colors[idx * 4 + 1] = (byte)color.G;
                    colors[idx * 4 + 2] = (byte)color.B;
                    colors[idx * 4 + 3] = (byte)color.A;
                }

                // a float is 4 bytes, therefore we multiply the number if
                // vertices with 4.
                ByteBuffer cbb = ByteBuffer.AllocateDirect(colors.Length);
                cbb.Order(ByteOrder.NativeOrder());
                cbb.Put(colors);
                cbb.Position(0);

                _triangles.Add(new TriangleProcessed()
                {
                    Vertices = vertexBuffer,
                    Colors = cbb,
                    Count = corners.Length / 3
                });
            }
		}
Ejemplo n.º 4
0
 /// <summary>
 /// Gets the 32-bit ARGB simple color from the specified 8-bit color values (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.
 /// </summary>
 /// <param name="red"></param>
 /// <param name="green"></param>
 /// <param name="blue"></param>
 /// <returns></returns>
 public static SimpleColor FromArgb(int red, int green, int blue)
 {
     return(SimpleColor.FromArgb(255, red, green, blue));
 }
Ejemplo n.º 5
0
		/// <summary>
		/// Raises the draw frame event.
		/// </summary>
		/// <param name="gl">Gl.</param>
        public void OnDrawFrame(IGL10 gl)
        {
            lock (_triangles)
            {
                // Replace the current matrix with the identity matrix
                gl.GlMatrixMode(GL10.GlProjection);
                gl.GlLoadIdentity(); // OpenGL docs
                gl.GlOrthof(_left, _right, _bottom, _top, -1, 1);


                SimpleColor color = SimpleColor.FromKnownColor(KnownColor.White);
                gl.GlClearColor(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);
                gl.GlClear(GL10.GlColorBufferBit);

                for (int idx = 0; idx < _triangles.Count; idx++)
                {
                    gl.GlVertexPointer(3, GL10.GlFloat, 0, _triangles[idx].Vertices);
                    gl.GlEnableClientState(GL10.GlVertexArray);
                    gl.GlColorPointer(4, GL10.GlUnsignedByte, 0, _triangles[idx].Colors);
                    gl.GlEnableClientState(GL10.GlColorArray);

                    gl.GlDrawArrays(GL10.GlTriangleStrip, 0, _triangles[idx].Count);
                }

                for (int idx = 0; idx < _lines.Count; idx++)
                {
                    gl.GlVertexPointer(3, GL10.GlFloat, 0, _lines[idx].Vertices);
                    gl.GlEnableClientState(GL10.GlVertexArray);

                    color = new SimpleColor()
                    {
                        Value = _lines[idx].Color
                    };
                    gl.GlColor4f(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);
                    gl.GlLineWidth(_lines[idx].Width);
                    gl.GlDrawArrays(GL10.GlLineStrip, 0, _lines[idx].Count);
                }
            }
        }