예제 #1
0
        private void DrawColorBoxes()
        {
            if (UseBitmapBuffer)
            {
                PaintBuffer.Clear();
            }
            else
            {
                PaintBitmap.Lock();
                PaintBitmap.Clear();
            }

            int step = PaintBuffer.Size.Height / _colors.Length;

            // draw color boxes on left side of bitmap
            for (int i = 0; i < _colors.Length; i++)
            {
                Color opaque      = _colors[i];
                Color translucent = Color.FromArgb(63, opaque.R, opaque.G, opaque.B);

                // draw translucent variant to the right of opaque color
                RectI opaqueBounds      = new RectI(0, i * step, _opaqueWidth, step);
                RectI translucentBounds = new RectI(
                    _opaqueWidth, i * step, _translucentWidth - _opaqueWidth, step);

                if (UseBitmapBuffer)
                {
                    PaintBuffer.Clear(opaqueBounds, opaque);
                    PaintBuffer.Clear(translucentBounds, translucent);
                }
                else
                {
                    PaintBitmap.Clear(opaqueBounds, opaque);
                    PaintBitmap.Clear(translucentBounds, translucent);
                }
            }

            if (UseBitmapBuffer)
            {
                PaintBuffer.Write();
            }
            else
            {
                PaintBitmap.Unlock();
            }
        }
예제 #2
0
        private void DrawOnBitmap(MouseEventArgs args, PointI p)
        {
            RectI bounds = RectI.Empty;

            if (!UseBitmapBuffer)
            {
                PaintBitmap.Lock();
            }

            if (args.LeftButton == MouseButtonState.Pressed)
            {
                bounds = new RectI(p.X, p.Y, 1, 1);
                DrawPixel(p.X, p.Y, PaintColor);
            }
            else if (args.RightButton == MouseButtonState.Pressed)
            {
                const int r = 4;

                // define rectangle around cursor position
                int x0 = Math.Max(_translucentWidth, p.X - r), y0 = Math.Max(0, p.Y - r),
                    x1 = Math.Min(PaintBuffer.Size.Width - 1, p.X + r),
                    y1 = Math.Min(PaintBuffer.Size.Height - 1, p.Y + r);

                bounds = new RectI(x0, y0, x1 - x0 + 1, y1 - y0 + 1);
                for (int x = x0; x <= x1; x++)
                {
                    for (int y = y0; y <= y1; y++)
                    {
                        DrawPixel(x, y, PaintColor);
                    }
                }
            }

            if (UseBitmapBuffer)
            {
                PaintBuffer.Write(bounds);
            }
            else
            {
                PaintBitmap.Unlock();
            }
        }