public UnsafeBitmap(UnsafeBitmap other)
 {
     // copy the bitmap
     bitmap = (Bitmap) other.bitmap.Clone();
     graphics = Graphics.FromImage(bitmap);
     bitmapWidth = other.bitmapWidth;
     bitmapHeight = other.bitmapHeight;
     // the remaining parameters are not set, as the bitmap is in unlocked state
 }
Exemple #2
0
 public UnsafeBitmap(UnsafeBitmap other)
 {
     // copy the bitmap
     bitmap       = (Bitmap)other.bitmap.Clone();
     graphics     = Graphics.FromImage(bitmap);
     bitmapWidth  = other.bitmapWidth;
     bitmapHeight = other.bitmapHeight;
     // the remaining parameters are not set, as the bitmap is in unlocked state
 }
 public UnsafeBitmap Darker()
 {
     UnsafeBitmap result = new UnsafeBitmap(bitmapWidth, bitmapHeight);
     result.LockBitmap();
     for (int i = 0; i < bitmapWidth; i++){
         for (int j = 0; j < bitmapHeight; j++){
             PixelData p = GetPixel(i, j);
             result.SetPixel(i, j, Color.FromArgb(Math.Max(0, p.red - 20), Math.Max(0, p.green - 20), Math.Max(0, p.blue - 20)));
         }
     }
     return result;
 }
Exemple #4
0
 public static void FillShadedRectangle(UnsafeBitmap b, int w, int h)
 {
     b.FillRectangle(Color.White, 0, 0, w - 1, h - 1);
     b.SetPixel(1, 1, Color.FromArgb(230, 238, 252));
     b.SetPixel(1, h - 3, Color.FromArgb(219, 227, 248));
     b.SetPixel(w - 3, 1, Color.FromArgb(220, 230, 249));
     b.SetPixel(w - 3, h - 3, Color.FromArgb(217, 227, 246));
     b.SetPixel(w - 1, h - 3, Color.FromArgb(174, 192, 214));
     b.SetPixel(w - 2, h - 2, Color.FromArgb(174, 196, 219));
     b.SetPixel(0, h - 2, Color.FromArgb(195, 212, 231));
     b.SetPixel(0, h - 1, Color.FromArgb(237, 241, 243));
     b.SetPixel(w - 2, h - 1, Color.FromArgb(236, 242, 247));
     int wi = w - 5;
     int he = h - 5;
     int[][] upper = InterpolateRgb(new[]{225, 234, 254}, new[]{188, 206, 250}, wi);
     int[][] lower = InterpolateRgb(new[]{183, 203, 249}, new[]{174, 200, 247}, wi);
     for (int i = 0; i < wi; i++){
         int[][] pix = InterpolateRgb(new[]{upper[0][i], upper[1][i], upper[2][i]},
             new[]{lower[0][i], lower[1][i], lower[2][i]}, he);
         for (int j = 0; j < he; j++){
             b.SetPixel(i + 2, j + 2, Color.FromArgb(pix[0][j], pix[1][j], pix[2][j]));
         }
     }
     int[][] pix2 = InterpolateRgb(new[]{208, 223, 252}, new[]{170, 192, 243}, he);
     for (int j = 0; j < he; j++){
         b.SetPixel(1, j + 2, Color.FromArgb(pix2[0][j], pix2[1][j], pix2[2][j]));
     }
     pix2 = InterpolateRgb(new[]{185, 202, 243}, new[]{176, 197, 242}, he);
     for (int j = 0; j < he; j++){
         b.SetPixel(w - 3, j + 2, Color.FromArgb(pix2[0][j], pix2[1][j], pix2[2][j]));
     }
     pix2 = InterpolateRgb(new[]{208, 223, 252}, new[]{175, 197, 244}, wi);
     for (int i = 0; i < wi; i++){
         b.SetPixel(i + 2, 1, Color.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i]));
     }
     pix2 = InterpolateRgb(new[]{183, 198, 241}, new[]{176, 196, 242}, wi);
     for (int i = 0; i < wi; i++){
         b.SetPixel(i + 2, h - 3, Color.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i]));
     }
     pix2 = InterpolateRgb(new[]{238, 237, 229}, new[]{160, 181, 211}, he + 2);
     for (int i = 0; i < he + 2; i++){
         b.SetPixel(w - 1, i, Color.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i]));
     }
     pix2 = InterpolateRgb(new[]{170, 192, 225}, new[]{126, 159, 211}, w/2);
     for (int i = 1; i <= w/2; i++){
         b.SetPixel(i, h - 1, Color.FromArgb(pix2[0][i - 1], pix2[1][i - 1], pix2[2][i - 1]));
     }
     pix2 = InterpolateRgb(new[]{126, 159, 211}, new[]{148, 176, 221}, w - 3 - w/2);
     for (int i = w/2 + 1; i <= w - 3; i++){
         b.SetPixel(i, h - 1, Color.FromArgb(pix2[0][i - w/2 - 1], pix2[1][i - w/2 - 1], pix2[2][i - w/2 - 1]));
     }
 }
Exemple #5
0
        public UnsafeBitmap Darker()
        {
            UnsafeBitmap result = new UnsafeBitmap(bitmapWidth, bitmapHeight);

            result.LockBitmap();
            for (int i = 0; i < bitmapWidth; i++)
            {
                for (int j = 0; j < bitmapHeight; j++)
                {
                    PixelData p = GetPixel(i, j);
                    result.SetPixel(i, j, Color.FromArgb(Math.Max(0, p.red - 20), Math.Max(0, p.green - 20), Math.Max(0, p.blue - 20)));
                }
            }
            return(result);
        }
 private void CreateSecondMark(int scrollBarWid)
 {
     int w = scrollBarWid - 1;
     int h = scrollBarWid - 2;
     UnsafeBitmap b = new UnsafeBitmap(w, h);
     b.LockBitmap();
     FormUtil.FillShadedRectangle(b, w, h);
     UnsafeBitmap bh = b.Lighter();
     UnsafeBitmap bp = b.Darker();
     b.UnlockBitmap();
     bh.UnlockBitmap();
     bp.UnlockBitmap();
     secondMark = b.Bitmap;
     secondMark.MakeTransparent();
     secondMarkHighlight = bh.Bitmap;
     secondMarkHighlight.MakeTransparent();
     secondMarkPress = bp.Bitmap;
     secondMarkPress.MakeTransparent();
 }
 private void CreateBar(int scrollBarWid, int width)
 {
     int w = CalcBarSize(width);
     int h = scrollBarWid - 2;
     UnsafeBitmap b = new UnsafeBitmap(w, h);
     b.LockBitmap();
     FormUtil.FillShadedRectangle(b, w, h);
     UnsafeBitmap bh = b.Lighter();
     UnsafeBitmap bp = b.Darker();
     b.UnlockBitmap();
     bh.UnlockBitmap();
     bp.UnlockBitmap();
     bar = b.Bitmap;
     bar.MakeTransparent();
     barHighlight = bh.Bitmap;
     barHighlight.MakeTransparent();
     barPress = bp.Bitmap;
     barPress.MakeTransparent();
 }
Exemple #8
0
        public static void FillShadedRectangle(UnsafeBitmap b, int w, int h)
        {
            b.FillRectangle(Color.White, 0, 0, w - 1, h - 1);
            b.SetPixel(1, 1, Color.FromArgb(230, 238, 252));
            b.SetPixel(1, h - 3, Color.FromArgb(219, 227, 248));
            b.SetPixel(w - 3, 1, Color.FromArgb(220, 230, 249));
            b.SetPixel(w - 3, h - 3, Color.FromArgb(217, 227, 246));
            b.SetPixel(w - 1, h - 3, Color.FromArgb(174, 192, 214));
            b.SetPixel(w - 2, h - 2, Color.FromArgb(174, 196, 219));
            b.SetPixel(0, h - 2, Color.FromArgb(195, 212, 231));
            b.SetPixel(0, h - 1, Color.FromArgb(237, 241, 243));
            b.SetPixel(w - 2, h - 1, Color.FromArgb(236, 242, 247));
            int wi = w - 5;
            int he = h - 5;

            int[][] upper = InterpolateRgb(new[] { 225, 234, 254 }, new[] { 188, 206, 250 }, wi);
            int[][] lower = InterpolateRgb(new[] { 183, 203, 249 }, new[] { 174, 200, 247 }, wi);
            for (int i = 0; i < wi; i++)
            {
                int[][] pix = InterpolateRgb(new[] { upper[0][i], upper[1][i], upper[2][i] },
                                             new[] { lower[0][i], lower[1][i], lower[2][i] }, he);
                for (int j = 0; j < he; j++)
                {
                    b.SetPixel(i + 2, j + 2, Color.FromArgb(pix[0][j], pix[1][j], pix[2][j]));
                }
            }
            int[][] pix2 = InterpolateRgb(new[] { 208, 223, 252 }, new[] { 170, 192, 243 }, he);
            for (int j = 0; j < he; j++)
            {
                b.SetPixel(1, j + 2, Color.FromArgb(pix2[0][j], pix2[1][j], pix2[2][j]));
            }
            pix2 = InterpolateRgb(new[] { 185, 202, 243 }, new[] { 176, 197, 242 }, he);
            for (int j = 0; j < he; j++)
            {
                b.SetPixel(w - 3, j + 2, Color.FromArgb(pix2[0][j], pix2[1][j], pix2[2][j]));
            }
            pix2 = InterpolateRgb(new[] { 208, 223, 252 }, new[] { 175, 197, 244 }, wi);
            for (int i = 0; i < wi; i++)
            {
                b.SetPixel(i + 2, 1, Color.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i]));
            }
            pix2 = InterpolateRgb(new[] { 183, 198, 241 }, new[] { 176, 196, 242 }, wi);
            for (int i = 0; i < wi; i++)
            {
                b.SetPixel(i + 2, h - 3, Color.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i]));
            }
            pix2 = InterpolateRgb(new[] { 238, 237, 229 }, new[] { 160, 181, 211 }, he + 2);
            for (int i = 0; i < he + 2; i++)
            {
                b.SetPixel(w - 1, i, Color.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i]));
            }
            pix2 = InterpolateRgb(new[] { 170, 192, 225 }, new[] { 126, 159, 211 }, w / 2);
            for (int i = 1; i <= w / 2; i++)
            {
                b.SetPixel(i, h - 1, Color.FromArgb(pix2[0][i - 1], pix2[1][i - 1], pix2[2][i - 1]));
            }
            pix2 = InterpolateRgb(new[] { 126, 159, 211 }, new[] { 148, 176, 221 }, w - 3 - w / 2);
            for (int i = w / 2 + 1; i <= w - 3; i++)
            {
                b.SetPixel(i, h - 1, Color.FromArgb(pix2[0][i - w / 2 - 1], pix2[1][i - w / 2 - 1], pix2[2][i - w / 2 - 1]));
            }
        }
 protected void PaintOnGraphicsBitmap(IGraphics g, int width, int height)
 {
     if (backBuffer == null || scatterPlot == null) {
         return;
     }
     UnsafeBitmap copyBackBuffer = new UnsafeBitmap(backBuffer);
     copyBackBuffer.LockBitmap();
     // selected data-points
     foreach (int s in scatterPlot.Selection) {
         double[] w = scatterPlot.GetDataAt(s);
         if (w.Length > 0){
             double x = w[0];
             double y = w[1];
             SymbolProperties gx = GetPointProperties != null ? GetPointProperties(s) : defaultSymbol;
             SymbolType symbolType = SymbolType.allSymbols[gx.Type];
             int symbolSize = gx.Size;
             if (symbolSize > 0){
                 int[] pathX;
                 int[] pathY;
                 symbolType.GetPath(symbolSize, out pathX, out pathY);
                 copyBackBuffer.DrawPath(SelectionColor, ModelToViewX(x, width), ModelToViewY(y, height), pathX, pathY);
             }
         }
     }
     copyBackBuffer.UnlockBitmap();
     // labels
     ScatterPlotLabelMode labelMode = scatterPlot.GetLabelMode();
     bool cutLabels = scatterPlot.CutLabels;
     if (labelMode == ScatterPlotLabelMode.All && scatterPlot.HasLabels) {
         Font font = new Font("Arial", scatterPlot.FontSize, scatterPlot.FontStyle);
         for (;;){
             double[] x;
             double[] y;
             double[] z;
             string[] labels;
             int index;
             try{
                 scatterPlot.GetData(out x, out y, out z, out labels, out index);
             } catch (IndexOutOfRangeException){
                 break;
             }
             if (x == null){
                 break;
             }
             SymbolProperties gx = GetPointProperties != null ? GetPointProperties(index) : defaultSymbol;
             for (int i = 0; i < x.Length; i++){
                 if (labelMode == ScatterPlotLabelMode.All || scatterPlot.IsSelected(i)) {
                     int ix = ModelToViewX(x[i], width);
                     int iy = ModelToViewY(y[i], height);
                     Color c;
                     if (z != null && colorScale != null){
                         c = colorScale.GetColor(z[i]);
                     } else{
                         c = gx.Color;
                     }
                     Brush b = new SolidBrush(c);
                     if (ix >= 0 && iy >= 0 && ix < width && iy < height){
                         if (labels[i] != null){
                             string s = labels[i];
                             if (cutLabels){
                                 if (s.Contains(";")){
                                     s = s.Substring(0, s.IndexOf(';'));
                                 }
                             }
                             copyBackBuffer.DrawString(s, font, b, ix, iy);
                         }
                     }
                 }
             }
         }
         scatterPlot.Reset();
     }
     if (labelMode == ScatterPlotLabelMode.Selected && scatterPlot.HasLabels) {
         Brush br = new SolidBrush(SelectionColor);
         Font font = new Font("Arial", scatterPlot.FontSize, scatterPlot.FontStyle);
         foreach (int s in scatterPlot.Selection) {
             double[] w = scatterPlot.GetDataAt(s);
             string label = scatterPlot.GetLabelAt(s);
             double x = w[0];
             double y = w[1];
             int ix = ModelToViewX(x, width);
             int iy = ModelToViewY(y, height);
             if (ix >= 0 && iy >= 0 && ix < width && iy < height){
                 if (label != null){
                     if (cutLabels){
                         if (label.Contains(";")){
                             label = label.Substring(0, label.IndexOf(';'));
                         }
                     }
                     copyBackBuffer.DrawString(label, font, br, ix, iy);
                 }
             }
         }
     }
     // draw the image
     g.DrawImageUnscaled(copyBackBuffer.Bitmap, 0, 0);
     copyBackBuffer.Dispose();
     g.SmoothingMode = SmoothingMode.AntiAlias;
     DrawPolygons(g, width, height);
     if (drawFunctions != null){
         drawFunctions(g, width, height, ModelToViewX, ModelToViewY, ViewToModelX, ViewToModelY);
     }
     g.SmoothingMode = SmoothingMode.Default;
 }
 protected internal override void OnPaint(IGraphics g, int width, int height)
 {
     if (width <= 0 || height <= 0){
         return;
     }
     if (!Visible){
         return;
     }
     Brush foreBrush = new SolidBrush(ForeColor);
     if (paintBackground && IsInitialized() && !IsDragging()){
         g.DrawString("Loading...", Font, foreBrush, width/2 - 20, height/2 - 10);
     }
     if (scatterPlot == null) {
         return;
     }
     if (width != prevWidth || height != prevHeight){
         InvalidateData();
     }
     prevHeight = height;
     prevWidth = width;
     if (ValuesNeedRecalc()){
         if (!IsDragging()){
             RecalcValues(width, height);
         }
         return;
     }
     if (backBuffer == null){
         lockBackBuffer = true;
         backBuffer = new UnsafeBitmap(width, height);
         backBuffer.LockBitmap();
         PaintOnBackBuffer(width, height);
         backBuffer.UnlockBitmap();
         lockBackBuffer = false;
     }
     vectorGraphics = !(g is CGraphics);
     if (vectorGraphics){
         PaintOnGraphicsVector(g, width, height);
     } else{
         PaintOnGraphicsBitmap(g, width, height);
     }
     if (indicatorX1 != -1 && indicatorX2 != -1 && indicatorY1 != -1 && indicatorY2 != -1){
         g.SmoothingMode = SmoothingMode.AntiAlias;
         Pen indicatorPen = new Pen(Color.Black){DashStyle = DashStyle.Dot};
         switch (MouseMode){
             case ScatterPlotMouseMode.Select:
             case ScatterPlotMouseMode.Zoom:{
                 g.DrawRectangle(indicatorPen, MinIndicatorX, MinIndicatorY, DeltaIndicatorX, DeltaIndicatorY);
             }
                 break;
         }
         g.SmoothingMode = SmoothingMode.Default;
     }
 }
 internal virtual void InvalidateImage()
 {
     if (!lockBackBuffer){
         backBuffer = null;
     }
 }