private int getPointPositionY_ByValue(double value, object objContainer)
        {
            //int mouseClickY = pt.Y;
            double H     = Convert.ToDouble(ServiceTools.getPropValue(objContainer, "Height"));
            double dReal = (maxValue - minValue);
            double y     = H - (H / dReal) * (value - minValue);

            return(Convert.ToInt32(y));
        }
        private Rectangle RectangleOnImageFromRealValuesRectangle(RectangleF rectF2convert, object objContainer)
        {
            Rectangle rectOut = new Rectangle();

            rectOut.X      = Convert.ToInt32(rectF2convert.X);
            rectOut.Y      = getPointPositionY_ByValue(rectF2convert.Location.Y, objContainer);
            rectOut.Width  = Convert.ToInt32(rectF2convert.Width);
            rectOut.Height = Convert.ToInt32((Convert.ToDouble(ServiceTools.getPropValue(objContainer, "Height")) * (double)(rectF2convert.Height) / (maxValue - minValue)));

            return(rectOut);
        }
示例#3
0
        private void ShowToolTip(MouseEventArgs e, String textToShow, object theElement)
        {
            if (textToolTip == null)
            {
                textToolTip = new ToolTip();
            }
            else
            {
                if (previousTooltipMouseLocation == e.Location)
                {
                    return;
                }
                textToolTip.Dispose();
                textToolTip = new ToolTip();
            }
            Point loc = (Point)ServiceTools.getPropValue(theElement, "Location");

            textToolTip.Show(textToShow, this, e.X + loc.X, e.Y + loc.Y);
            previousTooltipMouseLocation = e.Location;
        }
        //private MouseEventArgs _eDown, _eUp;


        public PictureBoxSelection(object sender, Point pDown, Point pUp, object imgData)
        {
            int mouseEventMaxWidthPix  = ((PictureBox)sender).Image.Width;
            int mouseEventMaxHeightPix = ((PictureBox)sender).Image.Height;

            usedImageData = imgData;
            _pDown        = pDown;
            _pUp          = pUp;

            if (_pDown.X < 0)
            {
                _pDown.X = 0;
            }
            else if (_pDown.X > mouseEventMaxWidthPix)
            {
                _pDown.X = mouseEventMaxWidthPix;
            }
            //else if ((_pDown.X % 4 > 2) && (_pDown.X + 4 - _pDown.X % 4 < mouseEventMaxWidthPix)) _pDown.X += 4 - _pDown.X%4;
            //else _pDown.X -= _pDown.X % 4;

            if (_pDown.Y < 0)
            {
                _pDown.Y = 0;
            }
            else if (_pDown.Y > mouseEventMaxHeightPix)
            {
                _pDown.Y = mouseEventMaxHeightPix;
            }
            //else if ((_pDown.Y % 4 > 2) && (_pDown.Y + 4 - _pDown.Y % 4 < mouseEventMaxHeightPix)) _pDown.Y += 4 - _pDown.Y % 4;
            //else _pDown.Y -= _pDown.Y % 4;

            if (_pUp.X < 0)
            {
                _pUp.X = 0;
            }
            else if (_pUp.X > mouseEventMaxWidthPix)
            {
                _pUp.X = mouseEventMaxWidthPix;
            }
            //else if ((_pUp.X % 4 > 2) && (_pUp.X + 4 - _pUp.X % 4 < mouseEventMaxWidthPix)) _pUp.X += 4 - _pUp.X % 4;
            //else _pUp.X -= _pUp.X % 4;

            if (_pUp.Y < 0)
            {
                _pUp.Y = 0;
            }
            else if (_pUp.Y > mouseEventMaxHeightPix)
            {
                _pUp.Y = mouseEventMaxHeightPix;
            }
            //else if ((_pUp.Y % 4 > 2) && (_pUp.Y + 4 - _pUp.Y % 4 < mouseEventMaxHeightPix)) _pUp.Y += 4 - _pUp.Y % 4;
            //else _pUp.Y -= _pUp.Y % 4;


            underlyingPictureBox = (PictureBox)sender;
            if (usedImageData.GetType().Equals(typeof(imageConditionAndData)))
            {
                k                 = (double)(((imageConditionAndData)usedImageData).dataRepresentingImageColored().Width) / (double)(underlyingPictureBox.Image.Width);
                selectionRect     = new Rectangle(Math.Min(_pDown.X, _pUp.X), Math.Min(_pDown.Y, _pUp.Y), Math.Max(_pDown.X, _pUp.X) - Math.Min(_pDown.X, _pUp.X), Math.Max(_pDown.Y, _pUp.Y) - Math.Min(_pDown.Y, _pUp.Y));
                selectionRectReal = new Rectangle(
                    Convert.ToInt32(Math.Round((double)selectionRect.Location.X * k, 0)),
                    Convert.ToInt32(Math.Round((double)selectionRect.Location.Y * k, 0)),
                    Convert.ToInt32(Math.Round((double)selectionRect.Width * k, 0)),
                    Convert.ToInt32(Math.Round((double)selectionRect.Height * k, 0)));
                if (selectionRectReal.Width % 4 != 0)
                {
                    selectionRectReal.Width += 4 - (selectionRectReal.Width % 4);
                }
                if (selectionRectReal.Height % 4 != 0)
                {
                    selectionRectReal.Height += 4 - (selectionRectReal.Height % 4);
                }
                if (selectionRectReal.Right > (int)ServiceTools.getPropValue(usedImageData, "Width"))
                {
                    selectionRectReal.Location = new Point(selectionRectReal.Location.X - (selectionRectReal.Right - (int)ServiceTools.getPropValue(usedImageData, "Width")), selectionRectReal.Location.Y);
                }
                if (selectionRectReal.Bottom > (int)ServiceTools.getPropValue(usedImageData, "Height"))
                {
                    selectionRectReal.Location = new Point(selectionRectReal.Location.X, selectionRectReal.Location.Y - (selectionRectReal.Bottom - (int)ServiceTools.getPropValue(usedImageData, "Height")));
                }
            }
            else if (usedImageData.GetType().Equals(typeof(ColorSchemeRuler)))
            {
                ColorSchemeRuler tmpRuler     = (ColorSchemeRuler)usedImageData;
                Point            tmpEventArgs = (_pDown.Y > _pUp.Y) ? (_pUp) : (_pDown);
                k                        = (double)(tmpRuler.maxValue - tmpRuler.minValue) / (double)(underlyingPictureBox.Image.Height);
                selectionRect            = new Rectangle(0, Math.Min(_pDown.Y, _pUp.Y), ((PictureBox)sender).Width, Math.Max(_pDown.Y, _pUp.Y) - Math.Min(_pDown.Y, _pUp.Y));
                selectionRectSchemeRuler = new RectangleF(
                    0.0f,
                    (float)(tmpRuler.GetValueByClickEvent((PictureBox)sender, tmpEventArgs)),
                    (float)((PictureBox)sender).Width,
                    (float)(selectionRect.Height * k)
                    );
            }
        }
        /// <summary>
        /// Gets the value by point position.
        /// Note the point is in the objContainer coordinates
        /// </summary>
        /// <param name="pt">The point in the objContainer coordinates</param>
        /// <param name="objContainer">The object container (image, bitmap, PictureBox or other object with the "Height" property defined)</param>
        /// <returns></returns>
        public double GetValueByPointPosition(Point pt, object objContainer)
        {
            int mouseClickY = pt.Y;

            return(1.0d - ((double)mouseClickY / (double)(ServiceTools.getPropValue(objContainer, "Height"))) * (maxValue - minValue) + minValue);
        }