Esempio n. 1
0
        private void DrawLine(Vector3 from, Vector3 to, Color color)
        {
            var vertices = new List<PositionColored>();

            vertices.Add(new PositionColored(from, color.ToArgb()));
            vertices.Add(new PositionColored(to, color.ToArgb()));

            var buffer = vertices.ToArray();

            SetTarget(Vector3.Zero);

            D3D.Device.DrawUserPrimitives(PrimitiveType.LineStrip, vertices.Count - 1, buffer);
        }
Esempio n. 2
0
		public LinearGradientBrush (RectangleF rect, Color color1, Color color2, LinearGradientMode linearGradientMode)
		{
			Status status = GDIPlus.GdipCreateLineBrushFromRect (ref rect, color1.ToArgb (), color2.ToArgb (), linearGradientMode, WrapMode.Tile, out nativeObject);
			GDIPlus.CheckStatus (status);

			rectangle = rect;
		}
Esempio n. 3
0
        public static async Task <BlueprintPA> GetBluePrintAsync(CancellationToken _worker, Bitmap src)
        {
            int  maxDepth     = 0;
            bool isMultiLayer = Options.Get.IsMultiLayer;
            bool isSide       = Options.Get.IsSideView;

            if (Materials.ColorMap.Count == 0)
            {
                TaskManager.SafeReport(0, "Compiling the color map");
                Materials.CompileColorMap(_worker, false);
            }
            TaskManager.SafeReport(100, "Colormap is compiled");
            _worker.SafeThrowIfCancellationRequested();

            int[,] blocksTemp = new int[src.Width, src.Height];

            List <Color> availableColors = Materials.ColorMap.Keys.ToList();

            TaskManager.SafeReport(0, "Rendering the blueprint...");
            using (var padlock = await AsyncDuplicateLock.Get.LockAsync(src))
            {
                src.ToViewStream(_worker, (x, y, cc) =>
                {
                    int r  = cc.R;
                    int b  = cc.B;
                    int gg = cc.G;
                    if (((r == 255 && b == 255 && gg == 255) || (r == 0 && b == 0 && gg == 0)) && cc.A < 30)
                    {
                        var mi           = Materials.Air.getAverageColor(isSide).ToArgb();
                        blocksTemp[x, y] = mi;
                    }
                    else
                    {
                        Color?c  = Materials.FindBestMatch(availableColors, cc);
                        int ccii = c?.ToArgb() ?? 0;
                        if (c != null)
                        {
                            int len = Materials.ColorMap[c.Value].Length;
                            if (len > maxDepth)
                            {
                                maxDepth = len;
                            }
                        }
                        blocksTemp[x, y] = ccii;
                    }

                    return(cc);
                });
            }

            Materials.BestMatchCache.Save();

            return(new BlueprintPA()
            {
                BlocksMap = blocksTemp,
                Image = src,
                MaxDepth = maxDepth
            });
        }
Esempio n. 4
0
 public void ShouldConvertToArgb()
 {
     // 0xAARRGGBB
     const int val = 0x11223344;
     var color = new Color(val);
     var argb = color.ToArgb();
     Assert.AreEqual(val, argb);
 }
Esempio n. 5
0
		public LinearGradientBrush (PointF point1, PointF point2, Color color1, Color color2)
		{
			Status status = GDIPlus.GdipCreateLineBrush (ref point1, ref point2, color1.ToArgb (), color2.ToArgb (), WrapMode.Tile, out nativeObject);
			GDIPlus.CheckStatus (status);

			status = GDIPlus.GdipGetLineRect (nativeObject, out rectangle);
			GDIPlus.CheckStatus (status);
		}
Esempio n. 6
0
        public void DrawRectangle(float x, float y, float width, float height, Color color)
        {
            _device.Device.VertexFormat = CustomVertex.TransformedColored.Format;
            color = Color.Red;
            var vertex = new CustomVertex.TransformedColored[4];

            vertex[0].Position = new Vector4(x, y, 0f, 0f);
            vertex[0].Color = color.ToArgb();
            vertex[1].Position = new Vector4(x + width, y, 0f, 0f);
            vertex[1].Color = color.ToArgb();
            vertex[2].Position = new Vector4(x, y + height, 0f, 0f);
            vertex[2].Color = color.ToArgb();
            vertex[3].Position = new Vector4(x + width, y + height, 0f, 0f);
            vertex[3].Color = color.ToArgb();

            _device.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, vertex);
        }
Esempio n. 7
0
        private void buttonApplyColor2_Click(object sender, EventArgs e)
        {
            Color?color = GetColorFromTextBoxes(2);

            if (color != null)
            {
                SendCommandWithOneParameter("CHANGE_COLOR_2", color?.ToArgb().ToString(), false);
            }
        }
 public static string FormatColourString(Color colour, ColourRepresentations format)
 {
     switch (format)
     {
         case ColourRepresentations.RGB:
             return colour.R.ToString() + "," + colour.G.ToString() + "," + colour.B.ToString();
         case ColourRepresentations.Hex:
             return "#" + colour.ToArgb().ToString("X6");
         default:
             return colour.ToString();
     }
 }
Esempio n. 9
0
        public void TestingColorNullable(Color?init)
        {
            ResetBois();

            PrimitiveWriter.WriteValue(Writer, init);
            ResetStream();

            var final = PrimitiveReader.ReadColorNullable(Reader);

            Assert.True(init?.ToArgb() == final?.ToArgb(), $"Color value are not same, expected: {init?.ToArgb()}, actual: {final?.ToArgb()}");

            // saving name and compare against it is pointless
            //final.Should().BeEquivalentTo(init, because: "The colors name are not same");
        }
Esempio n. 10
0
        public int AddAnnounce(string message, Color?color = null)
        {
            var announce = new AutoAnnounceMessage {
                Color = color?.ToArgb(), Message = message
            };

            announce.AssignIdentifier();

            m_announces.Add(announce.Id, announce);

            WorldServer.Instance.IOTaskPool.ExecuteInContext(() => Database.Insert(announce));

            return(announce.Id);
        }
Esempio n. 11
0
    public static bool NameAvailable(string name, ListBox colList, Color col)
    {
        //        foreach (ListItem li in colList.Items)
        //            if (li.Text == name)
        //                return false;

        if (colList.Items.FindByText(name) != null)
            return false;

        if (colList.Items.FindByValue(col.ToArgb().ToString()) !=  null)
            return false;

        return true;
    }
Esempio n. 12
0
        /// <summary>Generate a GraphicsPath from this bitmap by rastering the non-background pixels</summary>
        public static GraphicsPath ToGraphicsPath(this Bitmap bitmap, Color?bk_colour = null)
        {
            var gp = new GraphicsPath();

            // Copy the bitmap to memory
            int[] px; int sign;
            using (var bits = bitmap.LockBits(ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb))
            {
                const int bytes_per_px = 4;
                sign = Math_.Sign(bits.Value.Stride);
                px   = new int[Math.Abs(bits.Value.Stride) * bits.Value.Height / bytes_per_px];
                Marshal.Copy(bits.Value.Scan0, px, 0, px.Length);
            }

            // Get the transparent colour
            var bkcol = bk_colour?.ToArgb() ?? px[0];

            // Generates a graphics path by rastering a bitmap into rectangles
            var y    = sign > 0 ? 0 : bitmap.Height - 1;
            var yend = sign > 0 ? bitmap.Height : -1;

            for (; y != yend; y += sign)
            {
                // Find the first non-background colour pixel
                int x0; for (x0 = 0; x0 != bitmap.Width && px[y * bitmap.Height + x0] == bkcol; ++x0)
                {
                }

                // Find the last non-background colour pixel
                int x1; for (x1 = bitmap.Width; x1-- != 0 && px[y * bitmap.Height + x1] == bkcol;)
                {
                }

                // Add a rectangle for the raster line
                gp.AddRectangle(new Rectangle(x0, y, x1 - x0 + 1, 1));
            }
            return(gp);
        }
Esempio n. 13
0
		public void SetWrapMode (WrapMode mode, Color color, bool clamp)
		{
			Status status = GDIPlus.GdipSetImageAttributesWrapMode (nativeImageAttr, mode, color.ToArgb (), clamp);
    			GDIPlus.CheckStatus (status);
		}
Esempio n. 14
0
		public void SetColorKey (Color colorLow, Color colorHigh, ColorAdjustType type)
		{
			Status status = GDIPlus.GdipSetImageAttributesColorKeys (nativeImageAttr, type, true, 
				colorLow.ToArgb (), colorHigh.ToArgb ());
			GDIPlus.CheckStatus (status);
		}
Esempio n. 15
0
            /// <summary>
            /// Establece el color de fuente actual.
            /// </summary>
            /// <param name="val">Color de la fuente.</param>
            public void SetFormatColor(Color val)
            {
                if (currentFormat.Color.ToArgb() != val.ToArgb())
                {
                    int indColor = colorTable.IndexOf(val);

                    if (indColor == -1)
                    {
                        colorTable.AddColor(val);
                        indColor = colorTable.IndexOf(val);
                    }

                    currentFormat.Color = val;
                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "cf", true, indColor));
                }
            }
Esempio n. 16
0
		public static Color FindColorMatch (Color c)
		{
			uint argb = (uint) c.ToArgb ();
			for (int i = 0; i < KnownColors.ArgbValues.Length; i++) {
				if (argb == KnownColors.ArgbValues [i])
					return KnownColors.FromKnownColor ((KnownColor)i);
                        }
			return Color.Empty;
		}
Esempio n. 17
0
 private static string ColorToHex(Color color)
 {
     string toReturn = string.Format("0x{0:X8}", color.ToArgb()); toReturn = "#" + toReturn.Substring(toReturn.Length - 6, 6);
     return toReturn;
 }
Esempio n. 18
0
		public LinearGradientBrush (RectangleF rect, Color color1, Color color2, float angle, bool isAngleScaleable)
		{
			Status status = GDIPlus.GdipCreateLineBrushFromRectWithAngle (ref rect, color1.ToArgb (), color2.ToArgb (), angle, isAngleScaleable, WrapMode.Tile, out nativeObject);
			GDIPlus.CheckStatus (status);

			rectangle = rect;
		}
Esempio n. 19
0
 void SendLightMode(string command, int lightMode, Color?color1, Color?color2, int brightness, int interval, int steps, string direction)   // or REVERSE
 {
     if (serialPort.IsOpen)
     {
         serialPort.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", command, lightMode, color1?.ToArgb(), color2?.ToArgb(), brightness, interval, steps, direction));
     }
 }
Esempio n. 20
0
 /// <summary>
 /// Obtiene el índice de un color determinado en la tabla.
 /// </summary>
 /// <param name="color">Color a consultar.</param>
 /// <returns>Indice del color consultado.</returns>
 public int IndexOf(Color color)
 {
     return colors.IndexOf(color.ToArgb());
 }
Esempio n. 21
0
 public static void SetPixel(this BitmapData bd, uint x, uint y, Color c)
 {
     bd.SetPixelInt(x, y, (uint)c.ToArgb());
 }
Esempio n. 22
0
		public SolidBrush (Color color)
                {
			this.color = color;
			Status status = GDIPlus.GdipCreateSolidFill (color.ToArgb (), out nativeObject);
			GDIPlus.CheckStatus (status);
		}
Esempio n. 23
0
 public void Clear(Color color)
 {
     ABitmap.EraseColor(color.ToArgb());
 }
Esempio n. 24
0
 public override string ToString()
 {
     return(string.Format("[{0}x{1}-{2}x{3}, 0x{4}]", Left, Top, Right, Bottom, Color.ToArgb().ToString("X8")));
 }
Esempio n. 25
0
 /// <summary>
 /// Inserta un nuevo color en la tabla de colores.
 /// </summary>
 /// <param name="color">Nuevo color a insertar.</param>
 public void AddColor(Color color)
 {
     colors.Add(color.ToArgb());
 }
Esempio n. 26
0
 /// <summary>
 /// Sets the default fonts color.
 /// </summary>
 /// <param name="colorValue"></param>
 public void Color(Color colorValue)
 {
     _pdfReport.DataBuilder.DefaultFontsColor(new BaseColor(colorValue.ToArgb()));
 }
 public static void BkColor(Color color)
 {
     BkColorImpl(color.ToArgb());
 }
Esempio n. 28
0
		// FIXME: Linear scan
		public static Color FindColorMatch (Color c)
		{
			uint argb = (uint) c.ToArgb ();
			
			// 1-based
			const int first_real_color_index = (int) KnownColor.AliceBlue;
			const int last_real_color_index = (int) KnownColor.YellowGreen;
			
			for (int i = first_real_color_index - 1; i < last_real_color_index; i++) {
				if (argb == KnownColors.ArgbValues [i])
					return KnownColors.FromKnownColor ((KnownColor)i);
			}
			
			return Color.Empty;
		}
    /// <summary>
    /// Draw some text on the screen
    /// </summary>
    public void DrawText(float xpos, float ypos, Color color, string text, RenderFlags flags)
    {
        if (text == null)
            return;

        // Setup renderstate
        savedStateBlock.Capture();
        drawTextStateBlock.Apply();
        device.SetTexture(0, fontTexture);
        device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
        device.PixelShader = null;
        device.SetStreamSource(0, vertexBuffer, 0);

        // Set filter states
        if ((flags & RenderFlags.Filtered) != 0) {
            samplerState0.MinFilter = TextureFilter.Linear;
            samplerState0.MagFilter = TextureFilter.Linear;
        }

        // Adjust for character spacing
        xpos -= spacingPerChar;
        float fStartX = xpos;

        // Fill vertex buffer
        int iv = 0;
        int dwNumTriangles = 0;

        foreach (char c in text) {
            if (c == '\n') {
                xpos = fStartX;
                ypos += (textureCoords[0,3]-textureCoords[0,1])*textureHeight;
            }

            if ((c-32) < 0 || (c-32) >= 128-32)
                continue;

            float tx1 = textureCoords[c-32,0];
            float ty1 = textureCoords[c-32,1];
            float tx2 = textureCoords[c-32,2];
            float ty2 = textureCoords[c-32,3];

            float w = (tx2-tx1) *  textureWidth / textureScale;
            float h = (ty2-ty1) * textureHeight / textureScale;

            int intColor = color.ToArgb();
            if (c != ' ') {
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+0-0.5f,ypos+h-0.5f,0.9f,1.0f), intColor, tx1, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+0-0.5f,ypos+0-0.5f,0.9f,1.0f), intColor, tx1, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+w-0.5f,ypos+h-0.5f,0.9f,1.0f), intColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+w-0.5f,ypos+0-0.5f,0.9f,1.0f), intColor, tx2, ty1);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+w-0.5f,ypos+h-0.5f,0.9f,1.0f), intColor, tx2, ty2);
                fontVertices[iv++] = new CustomVertex.TransformedColoredTextured(new Vector4(xpos+0-0.5f,ypos+0-0.5f,0.9f,1.0f), intColor, tx1, ty1);
                dwNumTriangles += 2;

                if (dwNumTriangles*3 > (MaxNumfontVertices-6)) {
                    // Set the data for the vertexbuffer
                    vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, dwNumTriangles);
                    dwNumTriangles = 0;
                    iv = 0;
                }
            }

            xpos += w - (2 * spacingPerChar);
        }

        // Set the data for the vertex buffer
        vertexBuffer.SetData(fontVertices, 0, LockFlags.Discard);
        if (dwNumTriangles > 0)
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, dwNumTriangles);

        // Restore the modified renderstates
        savedStateBlock.Apply();
    }
Esempio n. 30
-1
 public override void DrawPixel(int x, int y, Color color)
 {
     DX.DrawBox(
         x*pixelWidth, y*pixelHeight,
         x*pixelWidth + pixelWidth, y*pixelHeight + pixelHeight,
         color.ToArgb(), 1);
 }