Ejemplo n.º 1
0
        /// <summary>
        /// Create a cursor that can be set using SetUserCursor or SetShapeCursor.
        /// An ImageList image can be resized with LDImage.Resize.
        /// </summary>
        /// <param name="imageName">The file path or ImageList image.</param>
        /// <param name="xHotSpot">The x pixel to use as the hot spot, indexed from 0.</param>
        /// <param name="yHotSpot">The y pixel to use as the hot spot, indexed from 0.</param>
        /// <returns>A cursor.</returns>
        public static Primitive CreateCursor(Primitive imageName, Primitive xHotSpot, Primitive yHotSpot)
        {
            Type ShapesType    = typeof(Shapes);
            Type ImageListType = typeof(ImageList);
            Dictionary <string, BitmapSource> _savedImages;
            BitmapSource img;
            string       cursorName = "";

            try
            {
                _savedImages = (Dictionary <string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_savedImages.TryGetValue((string)imageName, out img))
                {
                    imageName = ImageList.LoadImage(imageName);
                    if (!_savedImages.TryGetValue((string)imageName, out img))
                    {
                        return(cursorName);
                    }
                }

                MethodInfo method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                cursorName = method.Invoke(null, new object[] { "Cursor" }).ToString();

                Bitmap bmp    = FastPixel.GetBitmap(img);
                Cursor cursor = createCursor(bmp, xHotSpot, yHotSpot);
                cursors[cursorName] = cursor;
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return(cursorName);
        }
Ejemplo n.º 2
0
		protected void ShowNeuronBasedOnState(FastPixel fp, NeuronPlot np)
		{
			Color color = Color.Black;

			switch (np.Neuron.ActionState)
			{
				case Neuron.State.Integrating:
					int offset = np.Neuron.Config.ActionPotentialThreshold - np.Neuron.CurrentMembranePotential;
					int range = np.Neuron.Config.ActionPotentialThreshold - np.Neuron.Config.RestingPotential;
					int percent = 255 - (offset * 255 / range);
					int cval = percent.Min(0).Max(255);
					color = Color.FromArgb(0, cval, 0);
					break;

				case Neuron.State.Firing:
					color = Color.White;
					break;

				case Neuron.State.RefractoryStart:
				case Neuron.State.AbsoluteRefractory:
					color = Color.FromArgb(255, 64, 64);
					break;

				case Neuron.State.RelativeRefractory:
					color = Color.Yellow;
					break;
			}

			Plot(fp, np.Location, color);
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes this spriteframe.
        /// </summary>
        /// <param name="Alpha">Does this spriteframe have an alpha-buffer? Only applicable for SPR2.</param>
        /// <param name="HasZBuffer">Does this spriteframe have a z-buffer? Only applicable for SPR2.</param>
        public void Init(bool Alpha, bool HasZBuffer)
        {
            m_HasAlpha = Alpha;

            if (m_Width > 0 && m_Height > 0)
            {
                m_BitmapData = new FastPixel(new Bitmap(m_Width, m_Height), Alpha);
                m_BitmapData.Lock();

                if (HasZBuffer)
                {
                    m_HasZBuffer = true;

                    m_ZBuffer = new FastPixel(new Bitmap(m_Width, m_Height), Alpha);
                    m_ZBuffer.Lock();
                }
            }
            else
            {
                m_BitmapData = new FastPixel(new Bitmap(1, 1), Alpha);
                m_BitmapData.Lock();

                if (HasZBuffer)
                {
                    m_HasZBuffer = true;

                    m_ZBuffer = new FastPixel(new Bitmap(1, 1), Alpha);
                    m_ZBuffer.Lock();
                }
            }
        }
Ejemplo n.º 4
0
        public void BuildImage(bool save = true)
        {
            if (Image != null)
            {
                Image.Dispose();
            }

            Image = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);

            using (var fp = new FastPixel(Image, true))
            {
                for (int y = 0; y < Height; ++y)
                {
                    for (int x = 0; x < Width; ++x)
                    {
                        fp.SetPixel(x, y, Color.FromArgb((byte)(Luminance[x, y] * 255), 0, 0, 0));
                    }
                }
            }

            if (save)
            {
                Image.Save("Brushes\\" + Editor.GetLanguageString(Name) + " [" + Width + "].png");
            }
        }
Ejemplo n.º 5
0
 public void Plot(FastPixel fp, Point location, Color color)
 {
     fp.SetPixel(location, color);
     fp.SetPixel(location + new Size(1, 0), color);
     fp.SetPixel(location + new Size(0, 1), color);
     fp.SetPixel(location + new Size(1, 1), color);
 }
Ejemplo n.º 6
0
        protected void ShowNeuronBasedOnState(FastPixel fp, NeuronPlot np)
        {
            Color color = Color.Black;

            switch (np.Neuron.ActionState)
            {
            case Neuron.State.Integrating:
                int offset  = np.Neuron.Config.ActionPotentialThreshold - np.Neuron.CurrentMembranePotential;
                int range   = np.Neuron.Config.ActionPotentialThreshold - np.Neuron.Config.RestingPotential;
                int percent = 255 - (offset * 255 / range);
                int cval    = percent.Min(0).Max(255);
                color = Color.FromArgb(0, cval, 0);
                break;

            case Neuron.State.Firing:
                color = Color.White;
                break;

            case Neuron.State.RefractoryStart:
            case Neuron.State.AbsoluteRefractory:
                color = Color.FromArgb(255, 64, 64);
                break;

            case Neuron.State.RelativeRefractory:
                color = Color.Yellow;
                break;
            }

            Plot(fp, np.Location, color);
        }
Ejemplo n.º 7
0
        public override void Load(Bitmap image)
        {
            Generate();
            Bind();

            SetMipmapping(false);
            SetRepeat(false);

            int[,] tempData = new int[image.Width, image.Height];

            unsafe
            {
                fixed(int *ptr = tempData)
                {
                    int i = 0;

                    using (var fp = new FastPixel(image, true))
                    {
                        for (int y = 0; y < image.Height; ++y)
                        {
                            for (int x = 0; x < image.Width; ++x)
                            {
                                Color argb = fp.GetPixel(x, y);
                                ptr[i++] = (argb.R << 0) | (argb.G << 8) | (argb.B << 16) | (argb.A << 24);
                            }
                        }
                    }

                    Upload((IntPtr)ptr, image.Width, image.Height);
                }
            }
        }
Ejemplo n.º 8
0
        public void Compile()
        {
            _CompiledPassable.Clear();
            FastPixel _FP;

            _FP = new FastPixel(new Bitmap(GetLayerImage("passable")));
            _FP.Lock();
            for (int x = 0; x < 800; x = x + 50)
            {
                for (int y = 0; y < 600; y = y + 50)
                {
                    bool _HasNonPassablePixel = false;

                    for (int _TmpX = x; _TmpX < x + 50; _TmpX++)
                    {
                        for (int _TmpY = y; _TmpY < y + 50; _TmpY++)
                        {
                            if (_FP.GetPixel(_TmpX, _TmpY).ToArgb() == Color.Red.ToArgb())
                            {
                                _HasNonPassablePixel = true;
                                break;
                            }
                        }
                        if (_HasNonPassablePixel == true)
                        {
                            break;
                        }
                    }

                    _CompiledPassable.Add(_HasNonPassablePixel);
                }
            }
            _FP.Unlock(false);
            _FP = null;
        }
Ejemplo n.º 9
0
 public void Draw(FastPixel fp)
 {
     if (Node != null)
     {
         //IIntentStates nodeIntentStates;
         //if (intentStates.TryGetValue(Node.Id, out nodeIntentStates))
         //{
         //    if (nodeIntentStates != null)
         //    {
         //        foreach (IIntentState<LightingValue> intentState in nodeIntentStates)
         //        {
         //            Draw(fp, intentState.GetValue().GetAlphaChannelIntensityAffectedColor());
         //        }
         //    }
         //}
         Color color;
         if (PreviewPixel.IntentNodeToColor.TryGetValue(Node, out color))
         {
             //if (nodeIntentStates != null)
             //{
             //foreach (IIntentState<LightingValue> intentState in nodeIntentStates)
             //{
             Draw(fp, color);
             //}
             //}
         }
     }
 }
Ejemplo n.º 10
0
		public void Plot(FastPixel fp, Point location, Color color)
		{
			fp.SetPixel(location, color);
			fp.SetPixel(location + new Size(1, 0), color);
			fp.SetPixel(location + new Size(0, 1), color);
			fp.SetPixel(location + new Size(1, 1), color);
		}
Ejemplo n.º 11
0
 public override void Draw(FastPixel fp, bool editMode, List <ElementNode> highlightedElements, bool selected)
 {
     foreach (PreviewBaseShape shape in Strings)
     {
         shape.Draw(fp, editMode, highlightedElements, selected);
     }
     DrawSelectPoints(fp);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Create a cursor file.
        /// </summary>
        /// <param name="imageName">The file path or ImageList image to create cursor from.  Best results will be obtained from a square image.</param>
        /// <param name="cursorPath">The full path to save the cursor file (using extension *.cur).</param>
        /// <param name="size">The pixel size of cursor.</param>
        /// <param name="xHotSpot">Pixel from left of cursor hot spot, indexed from 0.
        /// For images where the aspect ratio is maintained, the xHotSpot is also scaled.</param>
        /// <param name="yHotSpot">Pixel from top of cursor hot spot, indexed from 0.</param>
        /// <returns></returns>
        public static Primitive CreateCursor(Primitive imageName, Primitive cursorPath, Primitive size, Primitive xHotSpot, Primitive yHotSpot)
        {
            try
            {
                Type ImageListType = typeof(ImageList);
                Dictionary <string, BitmapSource> _savedImages;
                BitmapSource img;

                _savedImages = (Dictionary <string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_savedImages.TryGetValue((string)imageName, out img))
                {
                    imageName = ImageList.LoadImage(imageName);
                    if (!_savedImages.TryGetValue((string)imageName, out img))
                    {
                        return("FAILED");
                    }
                }
                Bitmap bmp        = FastPixel.GetBitmap(img);
                double scaleWidth = bSquare ? 1 : (double)bmp.Width / (double)bmp.Height;

                using (FileStream outStream = new FileStream(cursorPath, FileMode.Create))
                {
                    BinaryWriter bw = new BinaryWriter(outStream);
                    bw.Write((byte)0);                  // 0-1 reserved (0)
                    bw.Write((byte)0);
                    bw.Write((short)2);                 // 2-3 image type, 1=Icon, 2=Cursor	// bw.Write(icoType);
                    bw.Write((short)1);                 // 4-5 number of images

                    Bitmap bmpIcon = new Bitmap(bmp, new Size((int)(size * scaleWidth), size));
                    byte[] data;
                    using (MemoryStream ms = new MemoryStream())
                    {
                        bmpIcon.Save(ms, imageFormat);
                        data = ms.ToArray();
                    }

                    int offset = 6 + 16;
                    bw.Write((byte)(size * scaleWidth));      //	0 image width	(entry Image#1)
                    bw.Write((byte)size);                     //	1 image height
                    bw.Write((byte)0);                        //	2 number of colors (0 if the image does not use a color palette)
                    bw.Write((byte)0);                        //	3 reserved (0)
                    bw.Write((short)(xHotSpot * scaleWidth)); //	4-5 color planes (Ico: 0 or 1; Cur: horiz. coord. of xHotspot, # of pxl from left)
                    bw.Write((short)yHotSpot);                //	6-7 bits per pixel (Ico: bpPxl; Cur: vert. coord. of yHotspot, # of pxl from top)
                    bw.Write((int)data.Length);               //	8-11 size [Bytes] of image data
                    bw.Write((int)offset);                    //	12-15 offset [Bytes] of Bmp/Png image data from beginning (6 + 16)
                    bw.Write(data);                           // write image data (must contain the whole png data file)

                    bw.Flush();
                }
                return("SUCCESS");
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return("FAILED");
            }
        }
Ejemplo n.º 13
0
    public void initialize()
    {
        bmp = new Bitmap(width, height);
        Graphics gr = Graphics.FromImage(bmp);
        gr.Clear(Color.Black); // Set the empty color: black
        //gr.DrawImage(bmp, new Rectangle(0, 0, width, height));

        stage = new FastPixel(bmp);
        stage.Lock();
    }
Ejemplo n.º 14
0
 public override void Draw(FastPixel fp, bool editMode, List <ElementNode> highlightedElements, bool selected)
 {
     foreach (PreviewPixel pixel in Pixels)
     {
         //if (highlightedElements != null && highlightedElements.Contains(pixel.Node))
         //    pixel.Draw(fp, Color.HotPink);
         //else
         //    pixel.Draw(fp, Color.White);
         DrawPixel(pixel, fp, editMode, highlightedElements, selected);
     }
 }
Ejemplo n.º 15
0
		public override bool Draw(FastPixel fp, Graphics gr, List<NeuronPlot> plots)
		{
			fp.Clear(Color.Black);

			foreach (NeuronPlot np in plots)
			{
				ShowNeuronBasedOnState(fp, np);
			}

			return true;
		}
Ejemplo n.º 16
0
        public override bool Draw(FastPixel fp, Graphics gr, List <NeuronPlot> plots)
        {
            fp.Clear(Color.Black);

            foreach (NeuronPlot np in plots)
            {
                ShowNeuronBasedOnState(fp, np);
            }

            return(true);
        }
Ejemplo n.º 17
0
    public void initialize()
    {
        blockDict = Acorn.LoadBlocks();
        foreground_cache = new RawColor[width, height];

        bmp = new Bitmap(width, height);
        Graphics gr = Graphics.FromImage(bmp);
        gr.Clear(Color.Black); // Set the empty color: black
        gr.DrawImage(bmp, new Rectangle(0, 0, width, height));

        stage = new FastPixel(bmp);
        stage.Lock();
    }
Ejemplo n.º 18
0
        public Bitmap DoThreshold(Bitmap bitmap, int threshold)
        {
            _img_height = bitmap.Height;
            _img_width  = bitmap.Width;
            FastPixel _fast_pixel = new FastPixel(); //宣告快速繪圖物件

            _fast_pixel.image = bitmap;
            _fast_pixel.Bmp2RGB(bitmap);                      //讀取RGB亮度陣列
            _fast_pixel.array_Gray = _fast_pixel.array_Green; //灰階陣列為綠光陣列

            byte[,] array_Outline = GetScribeLine(_fast_pixel, threshold);
            return(_fast_pixel.BWImg(array_Outline));
        }
Ejemplo n.º 19
0
		protected void ShowNeuronBasedOnFiredCountDown(FastPixel fp, NeuronPlot np)
		{
			if (np.Neuron.ActionState == Neuron.State.Firing)
			{
				np.FiredCountDown = 11;
			}

			if (np.FiredCountDown > 0)
			{
				--np.FiredCountDown;
				Color color = countDownColor[np.FiredCountDown];
				Plot(fp, np.Location, color);
			}
		}
Ejemplo n.º 20
0
        protected void ShowNeuronBasedOnFiredCountDown(FastPixel fp, NeuronPlot np)
        {
            if (np.Neuron.ActionState == Neuron.State.Firing)
            {
                np.FiredCountDown = 11;
            }

            if (np.FiredCountDown > 0)
            {
                --np.FiredCountDown;
                Color color = countDownColor[np.FiredCountDown];
                Plot(fp, np.Location, color);
            }
        }
Ejemplo n.º 21
0
 public static void initDrawingArea(int i, int j, int[] pixels)
 {
     DrawingArea.pixels = pixels;
     width  = j;
     height = i;
     if (pixels != null && i > 0 && j > 0)
     {
         if (bmp == null || bmp.Width != width || bmp.Height != height)
         {
             bmp = new Bitmap(width, height);
             fp  = new FastPixel(bmp);
         }
     }
     setDrawingArea(i, 0, j, 0);
 }
Ejemplo n.º 22
0
 public virtual void DrawPixel(PreviewPixel pixel, FastPixel fp, bool editMode, List <ElementNode> highlightedElements, bool selected)
 {
     if (selected)
     {
         pixel.Draw(fp, PreviewTools.SelectedItemColor);
     }
     else if (highlightedElements.Contains(pixel.Node))
     {
         pixel.Draw(fp, Color.HotPink);
     }
     else
     {
         pixel.Draw(fp, Color.White);
     }
 }
Ejemplo n.º 23
0
        public void FindAngle(Bitmap bitmap, int threshold, double[] die_size)
        {
            _img_height = bitmap.Height;
            _img_width  = bitmap.Width;
            FastPixel _fast_pixel = new FastPixel(); //宣告快速繪圖物件

            _fast_pixel.image = bitmap;
            _fast_pixel.Bmp2RGB(bitmap);                      //讀取RGB亮度陣列
            _fast_pixel.array_Gray = _fast_pixel.array_Green; //灰階陣列為綠光陣列
            WidthAverage           = die_size[0];
            HeightAverage          = die_size[1];

            byte[,] array_Outline = GetScribeLine(_fast_pixel, threshold);
            Targets(array_Outline, _fast_pixel.nx, _fast_pixel.ny, die_size);
        }
Ejemplo n.º 24
0
 public void DrawSelectPoints(FastPixel fp)
 {
     if (_selectPoints != null)
     {
         foreach (PreviewPoint point in _selectPoints)
         {
             if (point != null)
             {
                 if (point.PointType == PreviewPoint.PointTypes.Size)
                 {
                     fp.DrawRectangle(new Rectangle(point.X - (SelectPointSize / 2), point.Y - (SelectPointSize / 2), SelectPointSize, SelectPointSize), Color.White);
                 }
             }
         }
     }
 }
Ejemplo n.º 25
0
        private void Generate_Click(object sender, EventArgs e)
        {
            Point RandomPoint = new Point();

            Random _R = new Random();

            RandomPoint.X = _R.Next(WorldBox.Width);
            RandomPoint.Y = _R.Next(WorldBox.Height);

            FastPixel _FP = new FastPixel(new Bitmap(WorldBox.Width, WorldBox.Height));

            List <Point> DonePoints = new List <Point>();
            List <Point> ToDoPoints = new List <Point>();

            _FP.SetPixel(RandomPoint, Color.Blue);
        }
        private void RenderGrid(Bitmap render, int scale, Color gridColor,
                                Color selColor)
        {
            FastPixel fs = new FastPixel();

            fs.New(render);
            fs.Lock();

            // Horizontal gridlines
            for (int y = 0; y < render.Height; y += scale)
            {
                for (int x = 0; x < render.Width; x++)
                {
                    fs.SetPixel(x, y, gridColor);
                }
            }

            // Vertical gridlines
            for (int x = 0; x < render.Width; x += scale)
            {
                for (int y = 0; y < render.Height; y++)
                {
                    fs.SetPixel(x, y, gridColor);
                }
            }

            // Selection box
            if (renderSelection)
            {
                for (int x = sClip.x * scale;
                     x < render.Width && x < (sClip.x + sClip.width) * scale;
                     x++)
                {
                    fs.SetPixel(x, sClip.y * scale, selColor);
                    fs.SetPixel(x, (sClip.y + sClip.height) * scale, selColor);
                }
                for (int y = sClip.y * scale;
                     y < render.Height && y < (sClip.y + sClip.height) * scale;
                     y++)
                {
                    fs.SetPixel((sClip.x + sClip.width) * scale, y, selColor);
                    fs.SetPixel(sClip.x * scale, y, selColor);
                }
            }

            fs.Unlock();
        }
Ejemplo n.º 27
0
		// TODO: This needs to be implemented as a memory mapped bitmap.
		protected override void OnPaint(PaintEventArgs e)
		{
			if (bitmap == null)
			{
				bitmap = new Bitmap(Width, Height, e.Graphics);
				fp = new FastPixel(bitmap);
			}

			fp.Lock();
			bool updateFromBitmap = Chart.Draw(fp, e.Graphics, plots);
			fp.Unlock(true);

			if (updateFromBitmap)
			{
				e.Graphics.DrawImage(bitmap, Point.Empty);
			}
		}
Ejemplo n.º 28
0
        public static ContextMenu getMenu(Dictionary <string, BitmapSource> _savedImages, Primitive items, Primitive images, int iconSize)
        {
            BitmapSource img;
            ContextMenu  menu        = new ContextMenu();
            int          itemCount   = SBArray.GetItemCount(items);
            Primitive    itemIndices = SBArray.GetAllIndices(items);

            for (int i = 1; i <= itemCount; i++)
            {
                string itemText  = items[itemIndices[i]];
                string imageName = images[itemIndices[i]];
                // Add the item
                MenuItem menuItem = new MenuItem();
                menuItem.Header = itemText;
                menuItem.Click += new RoutedEventHandler(_MenuClickEvent);
                menuItem.Tag    = (string)(itemIndices[i]);
                // Creates the item image.
                if (imageName != "")
                {
                    if (!_savedImages.TryGetValue(imageName, out img))
                    {
                        imageName = ImageList.LoadImage(imageName);
                        _savedImages.TryGetValue(imageName, out img);
                    }
                    if (null != img)
                    {
                        System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                        image.Source = img;
                        if (iconSize > 0)
                        {
                            Bitmap dImg = FastPixel.GetBitmap(img);
                            System.Drawing.Image.GetThumbnailImageAbort dummyCallback = new System.Drawing.Image.GetThumbnailImageAbort(LDWebCam.ResizeAbort);
                            dImg         = (Bitmap)dImg.GetThumbnailImage(iconSize, iconSize, dummyCallback, IntPtr.Zero);
                            image.Source = FastPixel.GetBitmapImage(dImg);
                        }
                        menuItem.Icon = image;
                    }
                }
                menu.Items.Add(menuItem);
            }
            if (menu.Items.Count == 0)
            {
                return(null);
            }
            return(menu);
        }
Ejemplo n.º 29
0
 public void Draw(FastPixel fp, Color newColor)
 {
     fp.DrawCircle(drawArea, newColor);
     //if (newColor.A > 0)
     //{
     //    if (MaxAlpha != 255)
     //    {
     //        double newAlpha = ((double)newColor.A / 255) * (double)MaxAlpha;
     //        Color outColor = Color.FromArgb((int)newAlpha, newColor.R, newColor.G, newColor.B);
     //        fp.DrawCircle(drawArea, outColor);
     //    }
     //    else
     //    {
     //        fp.DrawCircle(drawArea, newColor);
     //    }
     //    color = newColor;
     //}
 }
Ejemplo n.º 30
0
        public Brush(string file)
        {
            Name = Path.GetFileNameWithoutExtension(file);

            Image     = new Bitmap(file);
            Luminance = new float[Image.Width, Image.Height];

            using (var fp = new FastPixel(Image, true))
            {
                for (int y = 0; y < Height; ++y)
                {
                    for (int x = 0; x < Width; ++x)
                    {
                        Luminance[x, y] = fp.GetPixel(x, y).A / 255.0f;
                    }
                }
            }
        }
Ejemplo n.º 31
0
        // TODO: This needs to be implemented as a memory mapped bitmap.
        protected override void OnPaint(PaintEventArgs e)
        {
            if (bitmap == null)
            {
                bitmap = new Bitmap(Width, Height, e.Graphics);
                fp     = new FastPixel(bitmap);
            }

            fp.Lock();
            bool updateFromBitmap = Chart.Draw(fp, e.Graphics, plots);

            fp.Unlock(true);

            if (updateFromBitmap)
            {
                e.Graphics.DrawImage(bitmap, Point.Empty);
            }
        }
Ejemplo n.º 32
0
 public static void initDrawingArea(int h, int w, Color[] _pixels)
 {
     pixels = new int[_pixels.Length];
     for (int i = 0; i < pixels.Length; i++)
     {
         pixels[i] = _pixels[i].ToArgb();
     }
     width  = w;
     height = h;
     if (pixels != null && h > 0 && w > 0)
     {
         if (bmp == null || bmp.Width != width || bmp.Height != height)
         {
             bmp = new Bitmap(width, height);
             fp  = new FastPixel(bmp);
         }
     }
     setDrawingArea(h, 0, w, 0);
 }
Ejemplo n.º 33
0
        public virtual void Draw(FastPixel fp, bool editMode, List <ElementNode> highlightedElements, bool selected)
        {
            foreach (PreviewPixel pixel in Pixels)
            {
                DrawPixel(pixel, fp, editMode, highlightedElements, selected);
                //if (selected)
                //{
                //    pixel.Draw(fp, PreviewTools.SelectedItemColor);
                //}
                //if (highlightedElements.Contains(pixel.Node))
                //{
                //    pixel.Draw(fp, Color.HotPink);
                //}
                //else
                //    pixel.Draw(fp, Color.White);
            }

            DrawSelectPoints(fp);
        }
Ejemplo n.º 34
0
        public void CommitChanges(Texture currentSkin, bool save)
        {
            using (var grabber = new ColorGrabber(currentSkin, Width, Height))
            {
                grabber.Load();

                if (currentSkin != GLImage)
                {
                    grabber.Texture = GLImage;
                    grabber.Save();
                }

                if (save)
                {
                    var newBitmap = new Bitmap(Width, Height);

                    using (var fp = new FastPixel(newBitmap, true))
                    {
                        for (int y = 0; y < Height; ++y)
                        {
                            for (int x = 0; x < Width; ++x)
                            {
                                ColorPixel c = grabber[x, y];
                                fp.SetPixel(x, y, Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue));
                            }
                        }
                    }

                    newBitmap.Save(File.FullName);
                    newBitmap.Dispose();

                    var md = new Dictionary <string, string>();
                    md.Add("Model", Model.Path);
                    PNGMetadata.WriteMetadata(File.FullName, md);

                    SetImages(true);

                    Dirty = false;
                }
            }
        }
Ejemplo n.º 35
0
        //public override void Draw(Graphics graphics, Color color)
        //{
        //    if (_strings != null)
        //    {
        //        for (int stringNum = 0; stringNum < _stringCount; stringNum++)
        //        {
        //            PreviewLine line = (PreviewLine)_strings[stringNum];
        //            if (stringNum < (int)_stringsInDegrees)
        //            {
        //                line.Draw(graphics, color);
        //            }
        //            else
        //            {
        //                line.Draw(graphics, Color.Transparent);
        //            }
        //        }
        //    }
        //    base.Draw(graphics, color);
        //}

        //public override void Draw(FastPixel fp, Color color)
        //{
        //    if (_strings != null) {
        //        _stringsInDegrees = (double)_stringCount * ((double)_degrees / 360);
        //        for (int i = 0; i < (int)_stringsInDegrees; i++)
        //        {
        //            _strings[i].Draw(fp, color);
        //        }
        //    }
        //    base.Draw(fp, color);
        //}

        //public override void Draw(FastPixel fp)
        //{
        //    if (_strings != null) {
        //        _stringsInDegrees = (double)_stringCount * ((double)_degrees / 360);
        //        for (int i = 0; i < _stringsInDegrees; i++)
        //        {
        //            _strings[i].Draw(fp);
        //        }
        //    }
        //    base.Draw(fp);
        //}

        public override void Draw(FastPixel fp, bool editMode, List <ElementNode> highlightedElements, bool selected)
        {
            if (_strings != null)
            {
                _stringsInDegrees = (double)_stringCount * ((double)_degrees / 360);
                for (int i = 0; i < _stringsInDegrees; i++)
                {
                    foreach (PreviewPixel pixel in _strings[i]._pixels)
                    {
                        DrawPixel(pixel, fp, editMode, highlightedElements, selected);

                        //if (highlightedElements.Contains(pixel.Node))
                        //    pixel.Draw(fp, PreviewTools.HighlightedElementColor);
                        //else
                        //    pixel.Draw(fp, Color.White);
                    }
                }
            }

            base.Draw(fp, editMode, highlightedElements, selected);
        }
Ejemplo n.º 36
0
		public override bool Draw(FastPixel fp, Graphics gr, List<NeuronPlot> plots)
		{
			gr.Clear(Color.White);

			foreach (NeuronPlot np in plots)
			{
				int colorIdx = TestNeuronFiring(np);
				Pen pen = np == selectedNeuron ? penGreen : penBlack;

				// Draw the neuron circle as a border if not firing, otherwise as a solid circle on a fire event and post-fire countdown.
				if (colorIdx == -1)
				{
					gr.DrawEllipse(pen, new Rectangle(np.Location.X - 5, np.Location.Y - 5, 10, 10));
				}
				else
				{
					gr.FillEllipse(brushCountDown[colorIdx], new Rectangle(np.Location.X - 5, np.Location.Y - 5, 10, 10));
					gr.DrawEllipse(pen, new Rectangle(np.Location.X - 5, np.Location.Y - 5, 10, 10));
				}

				// If no connections, just draw a vertical "no connection" endpoint
				if (np.Neuron.Connections.Count == 0)
				{
					Point endpoint = np.Location - new Size(0, 45);
					DrawSynapse(pen, gr, np.Location, endpoint, Connection.CMode.Excitatory);
				}
				else
				{
					foreach (Connection conn in np.Neuron.Connections)
					{
						NeuronPlot npConn = plots.Single(p => p.Neuron == conn.Neuron);
						Point endpoint = npConn.Location;
						DrawSynapse(pen, gr, np.Location, endpoint, conn.Mode);
					}
				}
			}

			return false;
		}
Ejemplo n.º 37
0
        public override bool Draw(FastPixel fp, Graphics gr, List <NeuronPlot> plots)
        {
            gr.Clear(Color.White);

            foreach (NeuronPlot np in plots)
            {
                int colorIdx = TestNeuronFiring(np);
                Pen pen      = np == selectedNeuron ? penGreen : penBlack;

                // Draw the neuron circle as a border if not firing, otherwise as a solid circle on a fire event and post-fire countdown.
                if (colorIdx == -1)
                {
                    gr.DrawEllipse(pen, new Rectangle(np.Location.X - 5, np.Location.Y - 5, 10, 10));
                }
                else
                {
                    gr.FillEllipse(brushCountDown[colorIdx], new Rectangle(np.Location.X - 5, np.Location.Y - 5, 10, 10));
                    gr.DrawEllipse(pen, new Rectangle(np.Location.X - 5, np.Location.Y - 5, 10, 10));
                }

                // If no connections, just draw a vertical "no connection" endpoint
                if (np.Neuron.Connections.Count == 0)
                {
                    Point endpoint = np.Location - new Size(0, 45);
                    DrawSynapse(pen, gr, np.Location, endpoint, Connection.CMode.Excitatory);
                }
                else
                {
                    foreach (Connection conn in np.Neuron.Connections)
                    {
                        NeuronPlot npConn   = plots.Single(p => p.Neuron == conn.Neuron);
                        Point      endpoint = npConn.Location;
                        DrawSynapse(pen, gr, np.Location, endpoint, conn.Mode);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 38
0
            public void RenderSubSprite(Bitmap render, int x, int y,
                                        int scale, bool drawTransparent)
            {
                FastPixel fs = new FastPixel();

                fs.New(render);
                fs.Lock();

                byte[,] pixels;
                for (int j = 0; j < Height; j++)
                {
                    for (int i = 0; i < Width; i++)
                    {
                        pixels = tileSet.GetTile(Tile + i + (j * Width));
                        for (int yy = 0; yy < 8; yy++)
                        {
                            for (int xx = 0; xx < 8; xx++)
                            {
                                for (int ys = 0; ys < scale; ys++)
                                {
                                    for (int xs = 0; xs < scale; xs++)
                                    {
                                        byte pix = pixels[FlipY ? 7 - yy : yy, FlipX ? 7 - xx : xx];
                                        if (!((pix == 0) && !drawTransparent))
                                        {
                                            fs.SetPixel(
                                                xs + ((x + xx + (FlipX ? Width - 1 - i : i) * 8) * scale),
                                                ys + ((y + yy + (FlipY ? Height - 1 - j : j) * 8) * scale),
                                                pal.GetColor(pix));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                fs.Unlock();
            }
Ejemplo n.º 39
0
        public virtual void Draw(FastPixel.FastPixel fp, bool editMode, HashSet<Guid> highlightedElements, bool selected,
            bool forceDraw)
        {
            foreach (PreviewPixel pixel in Pixels) {

                DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
            }

            DrawSelectPoints(fp);
        }
Ejemplo n.º 40
0
		private void RenderBufferedGraphics(FastPixel.FastPixel fp /*, Bitmap floodBG*/)
		{
			if (this.InvokeRequired)
			{
				this.Invoke(new RenderBufferedGraphicsDelgate(RenderBufferedGraphics), fp /*, floodBG*/);
			}
			else
				// No, this doesn't allocate every time. It first checks to see if the screen is 
				// resized or the graphics buffer is not allocated. So it is checked for validity every time
				// and re-allocated only if the something changed.
				AllocateGraphicsBuffer(false);

			// First, draw our background image opaque
			bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
			bufferedGraphics.Graphics.DrawImage(fp.Bitmap, 0, 0, fp.Width, fp.Height);
			if (!this.Disposing && bufferedGraphics != null)
				bufferedGraphics.Render(Graphics.FromHwnd(this.Handle));
		}
Ejemplo n.º 41
0
 public void Init(bool Alpha)
 {
     if (m_Width > 0 && m_Height > 0)
     {
         m_BitmapData = new FastPixel(new Bitmap(m_Width, m_Height), Alpha);
         m_BitmapData.Lock();
     }
     else
     {
         m_BitmapData = new FastPixel(new Bitmap(1, 1), Alpha);
         m_BitmapData.Lock();
     }
 }
Ejemplo n.º 42
0
 public override void Draw(FastPixel.FastPixel fp, bool editMode, List<ElementNode> highlightedElements, bool selected,
     bool forceDraw)
 {
     foreach (PreviewBaseShape shape in Strings) {
         shape.Draw(fp, editMode, highlightedElements, selected, forceDraw);
     }
     DrawSelectPoints(fp);
 }
Ejemplo n.º 43
0
		public void Draw(FastPixel.FastPixel fp, bool forceDraw)
		{
			if (forceDraw) {
				Draw(fp, color);
			}
			else if (Node != null) {
				if (PreviewPixel.IntentNodeToColor.TryGetValue(Node, out color)) {
					Draw(fp, color);
				}
			}
		}
Ejemplo n.º 44
0
 public virtual void DrawPixel(PreviewPixel pixel, FastPixel.FastPixel fp, bool editMode, List<ElementNode> highlightedElements,
     bool selected, bool forceDraw)
 {
     if (forceDraw) {
         pixel.Draw(fp, forceDraw);
     }
     else if (selected) {
         pixel.Draw(fp, PreviewTools.SelectedItemColor);
     }
     else if (highlightedElements != null && highlightedElements.Contains(pixel.Node)) {
         pixel.Draw(fp, Color.HotPink);
     }
     else {
         pixel.Draw(fp, Color.White);
     }
 }
Ejemplo n.º 45
0
		public void DrawSelectPoints(FastPixel.FastPixel fp)
		{
			if (_selectPoints != null) {
				foreach (PreviewPoint point in _selectPoints) {
					if (point != null) {
						if (point.PointType == PreviewPoint.PointTypes.Size) {
                            int x = Convert.ToInt32((point.X) * ZoomLevel) - (SelectPointSize / 2);
                            int y = Convert.ToInt32(point.Y * ZoomLevel) - (SelectPointSize / 2);
                            fp.DrawRectangle(
								new Rectangle(x, y, SelectPointSize, SelectPointSize),
								Color.White);
						}
					}
				}
			}
		}
Ejemplo n.º 46
0
 public override void Draw(FastPixel.FastPixel fp, bool editMode, List<ElementNode> highlightedElements, bool selected,
     bool forceDraw)
 {
     foreach (PreviewPixel pixel in Pixels) {
         //if (highlightedElements != null && highlightedElements.Contains(pixel.Node))
         //    pixel.Draw(fp, Color.HotPink);
         //else
         //    pixel.Draw(fp, Color.White);
         DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
     }
 }
Ejemplo n.º 47
0
		public void Draw(FastPixel.FastPixel fp, Color newColor)
		{
			fp.DrawCircle(drawArea, newColor);
		}
Ejemplo n.º 48
0
        /// <summary>
        /// Initializes this spriteframe.
        /// </summary>
        /// <param name="Alpha">Does this spriteframe have an alpha-buffer? Only applicable for SPR2.</param>
        /// <param name="HasZBuffer">Does this spriteframe have a z-buffer? Only applicable for SPR2.</param>
        public void Init(bool Alpha, bool HasZBuffer)
        {
            m_HasAlpha = Alpha;

            if (m_Width > 0 && m_Height > 0)
            {
                m_BitmapData = new FastPixel(new Bitmap(m_Width, m_Height), Alpha);
                m_BitmapData.Lock();

                if (HasZBuffer)
                {
                    m_HasZBuffer = true;

                    m_ZBuffer = new FastPixel(new Bitmap(m_Width, m_Height), Alpha);
                    m_ZBuffer.Lock();
                }
            }
            else
            {
                m_BitmapData = new FastPixel(new Bitmap(1, 1), Alpha);
                m_BitmapData.Lock();

                if (HasZBuffer)
                {
                    m_HasZBuffer = true;

                    m_ZBuffer = new FastPixel(new Bitmap(1, 1), Alpha);
                    m_ZBuffer.Lock();
                }
            }
        }
Ejemplo n.º 49
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states)
        {
			
			if(_isDiscreteColored)
			{
				int col = 1;
				Rectangle drawRect = new Rectangle(drawArea.X, drawArea.Y, drawArea.Width, drawArea.Height);
				// Get states for each color
				IEnumerable<Color> colors = IntentHelpers.GetAlphaAffectedDiscreteColorsForIntents(states);
				foreach (Color c in colors)
				{
					if (c != Color.Transparent && c.A > byte.MinValue)
					{
						fp.DrawCircle(drawRect, c);

						if (col % 2 == 0)
						{
							drawRect.Y += PixelSize;
							drawRect.X = drawArea.X;
						} else
						{
							drawRect.X = drawArea.X + PixelSize;
						}

						col++;
					}
				}
			}
			else
			{
				Color intentColor = IntentHelpers.GetAlphaRGBMaxColorForIntents(states);
				if (intentColor != Color.Transparent && intentColor.A > 0)
				{
					fp.DrawCircle(drawArea, intentColor);
				}
			}
        }
Ejemplo n.º 50
0
		public virtual void DrawPixel(PreviewPixel pixel, FastPixel.FastPixel fp, bool editMode, List<ElementNode> highlightedElements,
		                              bool selected, bool forceDraw)
		{
            if (forceDraw)
            {
                pixel.Draw(fp, forceDraw);
            }
            else
            {
                Color pixelColor = Color.White;
                if (
                    (_pixels.Count > 0) &&
                    (pixel == _pixels[0] || (_strings != null && _strings.Count > 0 && _strings[0].Pixels != null && _strings[0].Pixels.Count > 0 && _strings[0].Pixels[0] == pixel))
                   )
                {
                    pixelColor = Color.Yellow;
                    pixel.PixelSize = PixelSize + 2;
                }
                else
                {
                    if (selected)
                    {
                        pixelColor = PreviewTools.SelectedItemColor;
                    }
                    else if (highlightedElements != null && highlightedElements.Contains(pixel.Node))
                    {
                        pixelColor = Color.HotPink;
                    }
                    else
                    {
                        if (pixel.Node != null)
                        {
                            pixelColor = Color.Turquoise;
                        }
                        else
                        {
                            pixelColor = Color.White;
                        }
                    }
                }
                pixel.Draw(fp, pixelColor);
            }
		}
Ejemplo n.º 51
0
		public override void Draw(FastPixel.FastPixel fp, bool editMode, List<ElementNode> highlightedElements, bool selected,
		                          bool forceDraw)
		{
			if (_strings != null) {
				for (int i = 0; i < _strings.Count; i++) {
					foreach (PreviewPixel pixel in _strings[i]._pixels) {
						DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
					}
				}
			}

			base.Draw(fp, editMode, highlightedElements, selected, forceDraw);
		}
Ejemplo n.º 52
0
        public override void Draw(FastPixel.FastPixel fp, bool editMode, List<ElementNode> highlightedElements, bool selected,
            bool forceDraw)
        {
            //if (_strings != null) {
            //    _stringsInDegrees = (double) _stringCount*((double) _degrees/360);
            //    for (int i = 0; i < _stringsInDegrees; i++) {
            //        foreach (PreviewPixel pixel in _strings[i]._pixels) {
            //            //Console.WriteLine(pixel.X + ":" + pixel.Y);
            //            DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);

            //            //if (highlightedElements.Contains(pixel.Node))
            //            //    pixel.Draw(fp, PreviewTools.HighlightedElementColor);
            //            //else
            //            //    pixel.Draw(fp, Color.White);
            //        }
            //    }
            //}

            //base.Draw(fp, editMode, highlightedElements, selected, forceDraw);

            // DB: Added 8/4/2013
            if (_strings != null)
            {
                //_stringsInDegrees = (double)_stringCount * ((double)_degrees / 360);
                for (int i = 0; i < StringCount; i++)
                {
                    foreach (PreviewPixel pixel in _strings[i]._pixels)
                    {
                        DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
                    }
                }
            }

            base.Draw(fp, editMode, highlightedElements, selected, forceDraw);
        }
Ejemplo n.º 53
0
		public abstract bool Draw(FastPixel fp, Graphics gr, List<NeuronPlot> plots);
Ejemplo n.º 54
0
        public virtual void Draw(FastPixel.FastPixel fp, bool editMode, List<ElementNode> highlightedElements, bool selected,
            bool forceDraw)
        {
            //Pixels.AsParallel().ForAll(pixel => {
            foreach (PreviewPixel pixel in Pixels) {
                DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
            }
            //});

            DrawSelectPoints(fp);
        }
Ejemplo n.º 55
0
        public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender)
        {
            _buffer = buffer;
            _bufferHeight = buffer.GetLength(0);
            _bufferWidth = buffer.GetLength(1);
            const int speedfactor = 4;

            if (txtBoxFile.Text != _pictureName) {
                _pictureName = txtBoxFile.Text;
                var image = Image.FromFile(_pictureName);
                _fp = new FastPixel(new Bitmap(image));
            }

            if (_fp == null) {
                return _buffer;
            }

            var imgwidth = _fp.Width;
            var imght = _fp.Height;
            var yoffset = (_bufferHeight + imght) / 2;
            var xoffset = (imgwidth - _bufferWidth) / 2;
            var limit = (cbDirection.SelectedIndex < 2) ? imgwidth + _bufferWidth : imght + _bufferHeight;
            var movement = Convert.ToInt32((eventToRender % (limit * speedfactor)) / speedfactor);

            _fp.Lock();
            for (var x = 0; x < imgwidth; x++) {
                for (var y = 0; y < imght; y++) {
                    var fpColor = _fp.GetPixel(x, y);
                    if (fpColor == Color.Transparent) {
                        fpColor = Color.Black;
                    }

                    switch (cbDirection.SelectedIndex) {
                        case 0: // left
                            SetPixel(x + _bufferWidth - movement, yoffset - y, fpColor);
                            break;
                        case 1: // right
                            SetPixel(x + movement - imgwidth, yoffset - y, fpColor);
                            break;
                        case 2: // up
                            SetPixel(x - xoffset, movement - y, fpColor);
                            break;
                        case 3: // down
                            SetPixel(x - xoffset, _bufferHeight + imght - y - movement, fpColor);
                            break;
                        default: // no movement - centered
                            SetPixel(x - xoffset, yoffset - y, fpColor);
                            break;
                    }
                }
            }
            _fp.Unlock();
            return _buffer;
        }
Ejemplo n.º 56
0
 public void DrawSelectPoints(FastPixel.FastPixel fp)
 {
     if (_selectPoints != null) {
         foreach (PreviewPoint point in _selectPoints) {
             if (point != null) {
                 if (point.PointType == PreviewPoint.PointTypes.Size) {
                     fp.DrawRectangle(
                         new Rectangle(point.X - (SelectPointSize/2), point.Y - (SelectPointSize/2), SelectPointSize, SelectPointSize),
                         Color.White);
                 }
             }
         }
     }
 }
Ejemplo n.º 57
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states)
        {
            if(_isDiscreteColored)
            {
                int col = 1;
                Rectangle drawRect = new Rectangle(drawArea.X, drawArea.Y, drawArea.Width, drawArea.Height);
                // Get states for each color
                List<Color> colors = _discreteHandler.GetAlphaAffectedColor(states);
                foreach (Color c in colors)
                {
                    if (c != Color.Transparent && c.A > byte.MinValue)
                    {
                        fp.DrawCircle(drawRect, c);

                        if (col % 2 == 0)
                        {
                            drawRect.Y += PixelSize;
                            drawRect.X = drawArea.X;
                        } else
                        {
                            drawRect.X = drawArea.X + PixelSize;
                        }

                        col++;
                    }
                }
            }
            else
            {
                var state = states.FirstOrDefault();
                if (state != null)
                {
                    Color intentColor = _fullColorHandler.GetFullColor(state);
                    if (intentColor.A > 0)
                    {
                        fp.DrawCircle(drawArea, intentColor);
                    }

                }

            }
        }