Example #1
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            if (hues != null)
            {
                if (bitmapCache[brightness] == null)
                {
                    bitmapCache[brightness] = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);

                    int min = showAllColors ? 0 : 1;
                    int max = showAllColors ? 0 : 0x3e9;
                    HuesRenderer.DrawField(bitmapCache[brightness], hues, min, max, hueSize, brightness);
                }

                pe.Graphics.DrawImageUnscaled(bitmapCache[brightness], 0, 0);

                PaintFocusRectangle(pe.Graphics);
            }
            else
            {
                pe.Graphics.DrawRectangle(SystemPens.WindowText, 0, 0, Width - 1, Height - 1);

                SizeF fontSize = pe.Graphics.MeasureString(Name, SystemFonts.DialogFont);
                pe.Graphics.DrawString(Name, SystemFonts.DialogFont, SystemBrushes.WindowText, (Width - fontSize.Width) / 2, (Height - fontSize.Height) / 2);
            }

            base.OnPaint(pe);
        }
Example #2
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            if (hues != null)
            {
                if (cache == null)
                {
                    cache = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                    HuesRenderer.DrawSpectrum(cache, hues, hueIndex);
                }

                pe.Graphics.DrawImageUnscaled(cache, 0, 0);
            }
            else
            {
                pe.Graphics.DrawRectangle(SystemPens.WindowText, 0, 0, Width - 1, Height - 1);

                SizeF fontSize = pe.Graphics.MeasureString(Name, SystemFonts.DialogFont);
                pe.Graphics.DrawString(Name, SystemFonts.DialogFont, SystemBrushes.WindowText, (Width - fontSize.Width) / 2, (Height - fontSize.Height) / 2);
            }

            base.OnPaint(pe);
        }
Example #3
0
        public static void DrawField(Bitmap bitmap, Hues hues, int startHueIndex, int endHueIndex, Size hueSize, int brightness)
        {
            // Check arguments
            if (bitmap == null)
            {
                throw new ArgumentNullException("bitmap");
            }
            if (hues == null)
            {
                throw new ArgumentNullException("hues");
            }

            if (bitmap.PixelFormat != PixelFormat.Format16bppArgb1555)
            {
                throw new ArgumentException("Invalid bitmap pixel format.", "bitmap");
            }

            if (startHueIndex != 0)
            {
                startHueIndex = HuesRenderer.Range(startHueIndex, hues.MinIndex, hues.MaxIndex);
            }
            if (endHueIndex != 0)
            {
                endHueIndex = HuesRenderer.Range(endHueIndex, hues.MinIndex, hues.MaxIndex);
            }
            hueSize.Width  = HuesRenderer.Range(hueSize.Width, 1, 64);
            hueSize.Height = HuesRenderer.Range(hueSize.Height, 1, 64);
            brightness     = HuesRenderer.Range(brightness, 0, 31);

            int columns = bitmap.Size.Width / hueSize.Width;
            int rows    = bitmap.Size.Height / hueSize.Height;

            BitmapData data = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);

            for (int y = 0; y < rows; y++)
            {
                short[] line = new short[bitmap.Size.Width];

                for (int x = 0; x < columns; x++)
                {
                    int id = startHueIndex + x * rows + y + 1;

                    if (id <= hues.MaxIndex && (endHueIndex == 0 || id <= endHueIndex))
                    {
                        ushort color = hues.Get(id).Colors[brightness];

                        for (int i = 0; i < hueSize.Width; i++)
                        {
                            line[x * hueSize.Width + i] = (short)(color | 0x8000);
                        }
                    }
                }

                for (int i = 0; i < hueSize.Height; i++)
                {
                    int offset = (int)data.Scan0 + (y * hueSize.Height + i) * data.Stride;
                    Marshal.Copy(line, 0, (IntPtr)offset, line.Length);
                }
            }

            bitmap.UnlockBits(data);
        }