Equals() public method

Tests whether obj is a with the same location and size of this Rectangle.

public Equals ( object obj ) : bool
obj object
return bool
		public void Update(Graphics g, string text, Font font, Padding internalBounds,
			Rectangle bounds, Color color, TextFormatFlags formatFlags, IThemeTextOption[] options) {

			IntPtr compatHdc = this._TextHDC;

			if (bounds.Equals(_TextHDCBounds)) {
				//Same bounds, reuse HDC and Clear it
				IntPtr hClearBrush = Native.GDI.CreateSolidBrush(ColorTranslator.ToWin32(Color.Black));
				Native.RECT cleanRect = new Native.RECT(bounds);
				Native.GDI.FillRect(compatHdc, ref cleanRect, hClearBrush);
				Native.GDI.DeleteObject(hClearBrush);
			}
			else {
				//Other bounds, create new HDC
				IntPtr outputHdc = g.GetHdc();
				IntPtr DIB;
				compatHdc = CreateNewHDC(outputHdc, bounds, out DIB);

				//Store new data
				_TextHDC = compatHdc;
				_TextHDCBounds = bounds;

				//Clear up
				CleanUpHDC(DIB);
				g.ReleaseHdc(outputHdc);
			}

			DrawOnHDC(compatHdc, text, font, internalBounds, bounds, color, formatFlags, options);
		}
        /// <summary>
        /// Returns a rectangle inside 'lookInside' that bounds any energy greater than 'threshold'. 
        /// </summary>
        /// <param name="image"></param>
        /// <param name="lookInside">A rectangle of 'image' to look inside. </param>
        /// <param name="threshold">1-255, the energy threshold to detect activity. 80-150 is a good range.</param>
        /// <returns></returns>
        public Rectangle FindBoxSobel(Bitmap originalImage, Rectangle lookInside, byte threshold)
        {
            Bitmap image = originalImage;
            try {
                //Convert if needed (makes an extra copy)
                if (image.PixelFormat != PixelFormat.Format24bppRgb &&
                    image.PixelFormat != PixelFormat.Format32bppArgb &&
                    image.PixelFormat != PixelFormat.Format32bppRgb) {
                    image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb);
                }

                //Crop if needed (makes an extra copy unless we converted too, then only 1 extra copy)
                if (!lookInside.Equals(new Rectangle(0, 0, image.Width, image.Height))) {
                    Bitmap oldImage = image;
                    try {
                        image = new Crop(lookInside).Apply(image);
                    } finally {
                        if (oldImage != originalImage) oldImage.Dispose(); //Dispose the cloned
                    }
                }

                //Makes 1 more copy at 1/3rd the size, in grayscale
                Rectangle result = FindBoxSobel(image, threshold);
                return new Rectangle(lookInside.X + result.X, lookInside.Y + result.Y, result.Width, result.Height);

            } finally {
                if (image != originalImage) image.Dispose();
            }
        }
    // ------------------------------------------------------------------
    /// <summary>
    /// Gets the brush.
    /// </summary>
    /// <param name="rectangle">The rectangle.</param>
    /// <returns>Brush</returns>
    // ------------------------------------------------------------------
    public Brush GetBrush(Rectangle rectangle) {
      if (rectangle.Equals(Rectangle.Empty)) {
        return new SolidBrush(mStartColor);
      } else {
        if (rectangle.Width == 0) {
          rectangle.Width = 1;
        }

        if (rectangle.Height == 0) {
          rectangle.Height = 1;
        }
        return new LinearGradientBrush(
            rectangle,
            mStartColor,
            mEndColor,
            mAngle,
            true);
      }
    }
Example #4
0
 public bool Contains(Rectangle other)
 {
    return other.Equals(GetIntersection(other));
 }
Example #5
0
        void ProcessArrowScrolling(Rectangle arrowButton, ref bool arrowVisible, ref bool arrowPressed, ref bool timerTicking)
        {
            // Capture the mouse
            Capture = true;
            // Draw the arrow button pushed
            timerTicking = true;
            // Draw pushed button
            buttonPushed = true;
            DrawArrowButton(arrowButton, ButtonState.Pushed);

            // Start timer
            using (System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer())
            {
                timer.Tick += new EventHandler(ScrollingTick);
                timer.Interval = 300;
                timer.Start();

            doScrollingLoop = true;
                while (doScrollingLoop)
                {
                    // Check messages until we find a condition to break out of the loop
                    Win32.MSG msg = new Win32.MSG();
                    WindowsAPI.GetMessage(ref msg, 0, 0, 0);
                    Point point = new Point(0, 0);
                    if (msg.message == (int)Msg.WM_MOUSEMOVE || msg.message == (int)Msg.WM_LBUTTONUP)
                    {
                        point = WindowsAPI.GetPointFromLPARAM((int)msg.lParam);
                    }

                    switch (msg.message)
                    {
                        case (int)Msg.WM_MOUSEMOVE:
                            {
                                if (arrowButton.Contains(point))
                                {
                                    if (!buttonPushed)
                                    {
                                        DrawArrowButton(arrowButton, ButtonState.Pushed);
                                        arrowVisible = true;
                                        arrowPressed = true;
                                        buttonPushed = true;
                                    }
                                }
                                else
                                {
                                    if (buttonPushed)
                                    {
                                        DrawArrowButton(arrowButton, ButtonState.Normal);
                                        arrowVisible = false;
                                        arrowPressed = false;
                                        buttonPushed = false;
                                    }
                                }
                                break;
                            }
                        case (int)Msg.WM_LBUTTONUP:
                            {
                                if (buttonPushed)
                                {
                                    if (!flatArrowButtons)
                                    {
                                        // Only if using regular buttons
                                        DrawArrowButton(arrowButton, ButtonState.Normal);
                                    }
                                    buttonPushed = false;
                                }
                                arrowVisible = false;
                                if (arrowButton.Contains(point))
                                {
                                    if (arrowButton.Equals(upArrowRect))
                                    {
                                        if (firstItem > 0)
                                        {
                                            firstItem--;
                                            Rectangle rc = GetViewPortRect();
                                            Invalidate(rc);
                                        }
                                    }
                                    else if (arrowButton.Equals(downArrowRect))
                                    {
                                        using (Graphics g = Graphics.FromHwnd(Handle))
                                        {
                                            // Get the last item rectangle
                                            OutlookBarBand band = bands[currentBandIndex];
                                            if (band != null)
                                            {
                                                Rectangle rcItem = GetItemRect(g, band, band.Items.Count - 1, Rectangle.Empty);
                                                Rectangle rc = GetViewPortRect();
                                                if (rcItem.Bottom > rc.Bottom)
                                                {
                                                    firstItem++;
                                                    Invalidate(rc);
                                                }
                                            }
                                        }
                                    }
                                }
                                doScrollingLoop = false;
                                break;
                            }
                        case (int)Msg.WM_KEYDOWN:
                            {
                                if ((int)msg.wParam == (int)VirtualKeys.VK_ESCAPE)
                                    doScrollingLoop = false;
                                break;
                            }
                        default:
                            WindowsAPI.DispatchMessage(ref msg);
                            break;
                    }
                }

                // Release the capture
                Capture = false;
                // Stop timer
                timer.Stop();
            }
            // Reset flags
            arrowVisible = false;
            arrowPressed = false;
            timerTicking = false;
            Rectangle viewPortRect = GetViewPortRect();
            Invalidate(viewPortRect);
        }
Example #6
0
        /// <summary>
        /// Adds a marker with its configurations and image to layout manager. 
        /// </summary>
        /// <param name="markerID">The ID of the marker (specified by the ARTag)</param>
        /// <param name="upperLeftCorner">The upper left corner (in pixels) of this marker in the entire
        /// marker array.</param>
        /// <param name="size">The size of this marker to be printed on the marker array. If different
        /// from the original image size, the marker image will be resized to fit this size.</param>
        /// <param name="cropArea">The area to be retained after cropping other parts outside of
        /// this area</param>
        /// <param name="imagefile">The file name of the marker image (must have an extension that
        /// indicates the image format)</param>
        /// <param name="additionalInfos">Additional information that should be added to the config file</param>
        /// <exception cref="ArgumentException">If the given marker ID is already added</exception>
        /// <exception cref="InvalidOperationException"></exception>
        public void AddMarker(int markerID, Point upperLeftCorner, Size size, Rectangle cropArea, String imagefile, 
            List<KeyValuePair<string, string>> additionalInfos)
        {
            if (configs.ContainsKey(markerID))
                throw new ArgumentException("You can't add same marker ID in one config file");

            MarkerConfig config = new MarkerConfig();
            config.ID = markerID;
            config.Position = upperLeftCorner;

            int width = 0, height = 0;
            config.Image = ImageReader.Load(imagefile, ref width, ref height);
            config.ImageWidth = width;
            config.ImageHeight = height;
            config.CropArea = cropArea;
            config.AdditionalInfo = additionalInfos;
            config.ImageFilename = imagefile;

            if (size.Equals(Size.Empty))
            {
                if (!cropArea.Equals(Rectangle.Empty))
                    config.Size = cropArea.Size;
                else
                    config.Size = new Size(width, height);
            }
            else
                config.Size = size;

            // if crop area is not empty, then make sure that the crop area is within the marker size
            if (!cropArea.Equals(Rectangle.Empty))
            {
                if (cropArea.X < 0 || cropArea.X > width)
                    throw new ArgumentException("Your crop area's X position is outside of the marker size");
                if (cropArea.Y < 0 || cropArea.Y > height)
                    throw new ArgumentException("Your crop area's Y position is outside of the marker size");
                if ((cropArea.X + cropArea.Width) > width)
                    throw new ArgumentException("Your crop area's X dimension exceeds the marker width");
                if ((cropArea.Y + cropArea.Height) > height)
                    throw new ArgumentException("Your crop area's Y dimension exceeds the marker height");
            }

            configs.Add(markerID, config);
            markerIDs.Add(markerID);
        }
Example #7
0
        /// <summary>
        /// Matches a top-level window to the application to the window having the specified dimensions.
        /// </summary>
        /// <param name="applicationName">The name of the application as registered with the AT-SPI registry.</param>
        /// <param name="windowRect">A <see cref="System.Drawing.Rectangle"/> representing the window on the screen.</param>
        /// <param name="frameExtents">A WindowManagerFrameExtents structure containing the size (in pixels) of the
        /// decorations placed on the window by the window manager.</param>
        /// <returns>A <see cref="System.IntPtr"/> value that points to the Accessible object representing the top-level window.</returns>
        internal IntPtr MatchTopLevelWindowForApplication(string applicationName, Rectangle windowRect, WindowManagerFrameExtents frameExtents)
        {
            IntPtr windowPointer = IntPtr.Zero;
            IList<IntPtr> topLevelWindows = this.GetTopLevelWindowsForApplication(applicationName);
            foreach (IntPtr candidateWindow in topLevelWindows)
            {
                if (Accessible_isComponent(candidateWindow))
                {
                    // Out variables for API call
                    int x = 0;
                    int y = 0;
                    int width = 0;
                    int height = 0;
                    int relativeX = 0;
                    int relativeY = 0;

                    IntPtr component = Accessible_getComponent(candidateWindow);
                    AccessibleComponent_getExtents(component, out x, out y, out width, out height, AccessibleCoordType.Screen);
                    AccessibleComponent_getPosition(component, out relativeX, out relativeY, AccessibleCoordType.Window);
                    AccessibleComponentLayer layer = AccessibleComponent_getLayer(component);
                    Rectangle componentRectangle = new Rectangle(x, y, width, height);
                    AccessibleComponent_unref(component);

                    // If the component layer is Window, this indicates that the window
                    // rect as passed in by the X server does not include the window frame
                    // as drawn by the window manager. If this is the case, adjust the rectangle
                    // so the window can be found.
                    if (layer == AccessibleComponentLayer.Window)
                    {
                        windowRect.X = windowRect.X - frameExtents.Left;
                        windowRect.Y = windowRect.Y - frameExtents.Top;
                        windowRect.Width = windowRect.Width + frameExtents.Left + frameExtents.Right;
                        windowRect.Height = windowRect.Height + frameExtents.Top + frameExtents.Bottom;
                    }

                    // If we found the window, add its pointer to the referenced objects
                    // cache and remove it from the list of available windows (so it
                    // does not get unreferenced.
                    if (windowRect.Equals(componentRectangle))
                    {
                        referencedObjectCache.Add(candidateWindow);
                        topLevelWindows.Remove(candidateWindow);
                        windowPointer = candidateWindow;
                        break;
                    }
                }
            }

            // Unreference every window not matching as the top-level window
            // for the application.
            foreach (IntPtr referencedWindow in topLevelWindows)
            {
                Accessible_unref(referencedWindow);
            }

            return windowPointer;
        }
Example #8
0
        protected virtual void CommonEditorUse(Control ctl, Rectangle rectTarget) {

            Debug.WriteLineIf(CompModSwitches.DebugGridView.TraceVerbose,  "PropertyGridView:CommonEditorUse");
            Debug.WriteLineIf(GridViewDebugPaint.TraceVerbose,  "Showing common editors");

            Debug.Assert(ctl != null, "Null control passed to CommonEditorUse");

            Rectangle rectCur = ctl.Bounds;

            // the client rect minus the border line
            Rectangle clientRect = this.ClientRectangle;

            clientRect.Inflate(-1,-1);

            try {
                rectTarget = Rectangle.Intersect(clientRect, rectTarget);
                 //if (ctl is Button)
                 //   Debug.WriteStackTrace();


                if (!rectTarget.IsEmpty) {
                    if (!rectTarget.Equals(rectCur)) {
                        ctl.SetBounds(rectTarget.X,rectTarget.Y,
                                      rectTarget.Width,rectTarget.Height);
                    }
                    ctl.Visible = true;
                }
            }
            catch {
                rectTarget = Rectangle.Empty;
            }

            if (rectTarget.IsEmpty) {

                ctl.Visible = false;
            }

            currentEditor = ctl;

        }
 protected virtual void CommonEditorUse(Control ctl, Rectangle rectTarget)
 {
     Rectangle bounds = ctl.Bounds;
     Rectangle clientRectangle = base.ClientRectangle;
     clientRectangle.Inflate(-1, -1);
     try
     {
         rectTarget = Rectangle.Intersect(clientRectangle, rectTarget);
         if (!rectTarget.IsEmpty)
         {
             if (!rectTarget.Equals(bounds))
             {
                 ctl.SetBounds(rectTarget.X, rectTarget.Y, rectTarget.Width, rectTarget.Height);
             }
             ctl.Visible = true;
         }
     }
     catch
     {
         rectTarget = Rectangle.Empty;
     }
     if (rectTarget.IsEmpty)
     {
         ctl.Visible = false;
     }
     this.currentEditor = ctl;
 }
Example #10
0
 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
 {
   bool skipMessage = false;
   Rectangle newBounds = new Rectangle(x, y, width, height);
   if (GUIGraphicsContext._useScreenSelector && isMaximized)
   {
     if (!newBounds.Equals(GUIGraphicsContext.currentScreen.Bounds))
     {
       skipMessage = true;
     }
   }
   if (skipMessage)
   {
     Log.Info("d3dapp: Screenselector: skipped SetBoundsCore {0} does not match {1}", newBounds.ToString(),
              GUIGraphicsContext.currentScreen.Bounds.ToString());
   }
   else
   {
     base.SetBoundsCore(x, y, width, height, specified);
   }
 }
 private RecognitionResult GetAnswer(Rectangle fragment)
 {
     foreach (var answer in sampleResults)
     {
         if (fragment.Equals(answer.Region))
         {
             return answer;
         }
     }
     return null;
 }
        /// <summary>
        /// Wstawia prostok�t do kontenera
        /// </summary>
        /// <param name="r">Prostok�t do wstawienia</param>
        /// <param name="rLeftTop">Lewy g�rny wierzcho�ek prostok�ta</param>
        /// <param name="o">Orientacja prostok�ta</param>
        public void InsertRectangle(Rectangle r, Point rLeftTop, Rectangle.Orientation o)
        {
            Console.WriteLine("insert rect[(" + r.LeftTop.X + ", " + r.LeftTop.Y + "), (" +
                r.RightDown.X + ", " + r.RightDown.Y + ")]" + " -> (" + rLeftTop.X + ", " +
                rLeftTop.Y + ")");

            InsertRectangleCheckParameters(r, rLeftTop);

            if (o.Equals(Rectangle.Orientation.Horizontal) && r.SideA < r.SideB)
                r.Rotate();
            else if (o.Equals(Rectangle.Orientation.Vertical) && r.SideA > r.SideB)
                r.Rotate();

            if (rectangles.Count == 0)
                FirstRectanglePreparation(r);
            else
                r.Move(rLeftTop);

            rectangles.Add(r);

            //jesli to byl pierwszy prostakat wszystko jest dobrze - nie trzeba tego robic
            if (rectangles.Count > 1)
            {
                // spr. czy po dodaniu wciaz prawidlowy prostokat
                if (isCorrectRectangle)
                {
                    // doklejamy od dolu prostokata
                    if (r.LeftTop.X == maxCorrectRect.LeftTop.X &&
                        r.RightDown.X == maxCorrectRect.RightDown.X &&
                        r.LeftTop.Y <= maxCorrectRect.RightDown.Y)
                        UpdateMaxRectangles(r);

                        // doklejamy z prawej strony prostokata
                    else if (r.LeftTop.Y == maxCorrectRect.LeftTop.Y &&
                        r.RightDown.Y == maxCorrectRect.RightDown.Y &&
                        r.LeftTop.X <= maxCorrectRect.RightDown.X)
                        UpdateMaxRectangles(r);

                        // naklejamy na prostokat
                    else if (maxCorrectRect.Covers(r))
                        r.SetParentRectangle(maxCorrectRect);

                        // zaklejamy ca�y prostok�t - to r�wnie g�upi przypadek jak poprzedni, ale skoro kto� tak chce...
                    else if (r.Covers(maxCorrectRect))
                        UpdateMaxRectangles(r);

                        // calosc przestaje byc poprawnym prostokatem
                    else
                    {
                        isCorrectRectangle = false;
                        AddNewEmptyFields(r);
                        UpdateMaxPossibleRectangle(r);
                    }
                }// gdy calosc nie jest prawidlowym prostokatem
                else
                {
                    //sprawdzenie czy dodanie prostokata nie pokrylo calkowicie jakichs emptyFields
                    //spr. czy przeciecia dodanego z empty sa niepuste (jesli tak - usuwamy odpow. empty z listy i wstawiamy zamiast niego empty-dodany)
                    //spr. czy nie zmienil sie maxPossibleRect

                    UpdateEmptyFields(r);
                    if (emptyFields.Count == 0)
                        UpdateMaxCorrectAfterFillingAllEmpties();
                    UpdateMaxPossibleRectangle(r);
                }
            }
        }
Example #13
0
        /// <summary>
        /// Create a BitmapBuffer from a Bitmap, a Rectangle specifying what part from the Bitmap to take and a flag if we need a clone
        /// </summary>
        /// <param name="sourceBmp">Bitmap</param>
        /// <param name="applyRect">Rectangle</param>
        /// <param name="clone">bool specifying if the bitmap needs to be cloned</param>
        public BitmapBuffer(Bitmap sourceBmp, Rectangle applyRect, bool clone)
        {
            this.clone = clone;
            Rectangle sourceRect = new Rectangle(applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height);
            Rectangle bitmapRect = new Rectangle(0,0, sourceBmp.Width, sourceBmp.Height);

            if(sourceRect.Equals(Rectangle.Empty)) {
                sourceRect = bitmapRect;
            } else {
                sourceRect.Intersect(bitmapRect);
            }
            // Does the rect have any pixels?
            if (sourceRect.Height <= 0 || sourceRect.Width <= 0) {
                return;
            }

            if (SupportsPixelFormat(sourceBmp)) {
                if (clone) {
                    // Create copy with supported format
                    this.bitmap = sourceBmp.Clone(sourceRect, sourceBmp.PixelFormat);
                } else {
                    this.bitmap = sourceBmp;
                }
            } else {
                // We can only clone, as we don't support the pixel format!
                if (!clone) {
                    throw new ArgumentException("Not supported pixel format: " + sourceBmp.PixelFormat);
                }
                // When sourceRect is the whole bitmap there is a GDI+ bug in Clone
                // Clone will than return the same PixelFormat as the source
                // a quick workaround is using new Bitmap which uses a default of Format32bppArgb
                if (sourceRect.Equals(bitmapRect)) {
                    this.bitmap = new Bitmap(sourceBmp);
                } else {
                    this.bitmap = sourceBmp.Clone(sourceRect, PixelFormat.Format32bppArgb);
                }
            }
            // Set "this" rect to location 0,0
            // as the Cloned Bitmap is only the part we want to work with
            this.rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
        }
Example #14
0
		private void RenderDiagramImplementation(Rectangle renderRectangle)
		{
			if (! Suspended)
			{
				if (! renderRectangle.Equals(mRenderRectangle)) DisposeGraphicsStateBitmap();
				
				Graphics graphics = CreateGraphics(renderRectangle);
				if (graphics==null) return;			

				OnPreRender(graphics);

				//Render the elements if the renderer isnt locked
				if (!mLocked) RenderDiagramElements(graphics);					
				
				//Render the decorations
				if (mDrawDecorations) RenderDecorations(graphics, renderRectangle);

				OnPostRender(graphics);

				graphics.Dispose();
			}
		}
        public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle applyRect, RenderMode renderMode)
        {
            Rectangle sourceRect = new Rectangle(applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height);
            Rectangle bitmapRect = new Rectangle(0,0, applyBitmap.Width, applyBitmap.Height);

            if(sourceRect.Equals(Rectangle.Empty)) {
                sourceRect = bitmapRect;
            } else {
                sourceRect.Intersect(bitmapRect);
            }
            // Does the rect have any pixels?
            if (sourceRect.Height <= 0 || sourceRect.Width <= 0) {
                return;
            }

            int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);

            // Calculate new sourceRect to include the matrix size if possible

            int leftOffset = Math.Min(sourceRect.X, blurRadius);
            int rightOffset = Math.Min(applyBitmap.Width - (sourceRect.X + sourceRect.Width), blurRadius);
            int topOffset = Math.Min(sourceRect.Y, blurRadius);
            int bottomOffset = Math.Min(applyBitmap.Height - (sourceRect.Y + sourceRect.Height), blurRadius);
            LOG.Debug(String.Format("Offsets: {0},{1},{2},{3}", leftOffset, rightOffset, topOffset, bottomOffset));
            LOG.Debug(String.Format("SourceRect before: {0},{1},{2},{3}", sourceRect.X, sourceRect.Width, sourceRect.Y, sourceRect.Height));
            sourceRect.X -= leftOffset;
            sourceRect.Width += leftOffset + rightOffset;
            sourceRect.Y -= topOffset;
            sourceRect.Height += topOffset + bottomOffset;
            LOG.Debug(String.Format("SourceRect after: {0},{1},{2},{3}", sourceRect.X, sourceRect.Width, sourceRect.Y, sourceRect.Height));
            // Make a copy of the applyBitmap for reading

            using (Bitmap sourceBitmap = applyBitmap.Clone(sourceRect, applyBitmap.PixelFormat)) {
                ApplySmooth(sourceBitmap, applyBitmap, sourceRect, blurRadius);
            }
        }
Example #16
0
        /// <summary>
        /// Crop the surface
        /// </summary>
        /// <param name="cropRectangle"></param>
        /// <returns></returns>
        public bool ApplyCrop(Rectangle cropRectangle)
        {
            if (IsCropPossible(ref cropRectangle))
            {
                Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
                Bitmap tmpImage;
                // Make sure we have information, this this fails
                try
                {
                    tmpImage = ImageHelper.CloneArea(Image, cropRectangle, PixelFormat.DontCare);
                }
                catch (Exception ex)
                {
                    ex.Data.Add("CropRectangle", cropRectangle);
                    ex.Data.Add("Width", Image.Width);
                    ex.Data.Add("Height", Image.Height);
                    ex.Data.Add("Pixelformat", Image.PixelFormat);
                    throw;
                }

                Matrix matrix = new Matrix();
                matrix.Translate(-cropRectangle.Left, -cropRectangle.Top, MatrixOrder.Append);
                // Make undoable
                MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);

                // Do not dispose otherwise we can't undo the image!
                SetImage(tmpImage, false);
                _elements.Transform(matrix);
                if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpImage.Size)))
                {
                    _surfaceSizeChanged(this, null);
                }
                Invalidate();
                return true;
            }
            return false;
        }
Example #17
0
 /// <summary>
 /// Returns all rectangles that intersect with the target rectangle.
 /// </summary>
 /// <param name="rectangle">The target rectangle.</param>
 /// <param name="rectangles">The candidate rectangles.</param>
 /// <returns>A collection of rectangles.</returns>
 public static IEnumerable<Rectangle> ChildrenAndIntersectingSiblings(Rectangle rectangle, IEnumerable<Rectangle> rectangles)
 {
     return rectangles.Where(r => rectangle.HitTest(r) && !rectangle.Equals(r) && !r.Encompasses(rectangle));
 }
    public override void PostRender(float timePassed, int iLayer)
    {
      if (GUIWindowManager.IsRouted)
      {
        return;
      }
      if (iLayer != 2)
      {
        return;
      }
      if (!base.IsAnimating(AnimationType.WindowClose))
      {
        if (GUIPropertyManager.GetProperty("#Play.Current.Thumb") != _thumbLogo)
        {
          _fileName = g_Player.CurrentFile;
        }

        long lPTS1 = (long)(g_Player.CurrentPosition);
        int hh = (int)(lPTS1 / 3600) % 100;
        int mm = (int)((lPTS1 / 60) % 60);
        int ss = (int)((lPTS1 / 1) % 60);

        int iSpeed = g_Player.Speed;
        if (hh == 0 && mm == 0 && ss < 5)
        {
          if (iSpeed < 1)
          {
            iSpeed = 1;
            g_Player.Speed = iSpeed;
            g_Player.SeekAbsolute(0.0d);
          }
        }

        if (_imagePlayLogo != null)
        {
          _imagePlayLogo.Visible = ((g_Player.Paused == false) && (g_Player.Playing));
        }

        if (_imagePauseLogo != null)
        {
          _imagePauseLogo.Visible = (g_Player.Paused == true);
        }

        if (_imageFastForward != null)
        {
          _imageFastForward.Visible = (g_Player.Speed > 1);
        }

        if (_imageRewind != null)
        {
          _imageRewind.Visible = (g_Player.Speed < 0);
        }

        if (_imageNormal != null)
        {
          _imageNormal.Visible = (g_Player.PlaybackType == (int)PlayBackType.NORMAL);
        }

        if (_imageGapless != null)
        {
          _imageGapless.Visible = (g_Player.PlaybackType == (int)PlayBackType.GAPLESS);
        }

        if (_imageCrossfade != null)
        {
          _imageCrossfade.Visible = (g_Player.PlaybackType == (int)PlayBackType.CROSSFADE);
        }

        if (_videoWindow != null)
        {
          _videoWindow.Visible = _visualisationEnabled; // switch it of when we do not have any vizualisation
        }

        if (_videoRectangle != null)
        {
          if (g_Player.Playing) // && !_videoWindow.SetVideoWindow)
          {
            _videoRectangle.Visible = GUIGraphicsContext.ShowBackground;
          }
          else
          {
            _videoRectangle.Visible = false;
          }
        }

        // this is called serveral times per second!
        if (_videoWindow != null)
        {
          // Old code for overlay support? Commented out to fix Mantis:
          // 0001682: Music visualization it's off position when using UI Calibration
          //SetVideoWindow(new Rectangle(_videoWindow.XPosition, _videoWindow.YPosition, _videoWindow.Width, _videoWindow.Height));
        }
          // still needed?
        else if (_videoRectangle != null) // to be compatible to the old version
        {
          SetVideoWindow(new Rectangle(_videoRectangle.XPosition, _videoRectangle.YPosition, _videoRectangle.Width,
                                       _videoRectangle.Height));
        }
        else
        {
          // @ Bav: _videoWindow == null here -> System.NullReferenceException
          //SetVideoWindow(new Rectangle());
          Rectangle dummyRect = new Rectangle();
          if (!dummyRect.Equals(GUIGraphicsContext.VideoWindow))
          {
            GUIGraphicsContext.VideoWindow = dummyRect;
          }

          if (_videoWindow != null)
          {
            _videoWindow.SetVideoWindow = false; // avoid flickering if visualization is turned off
          }
        }
      }
      base.Render(timePassed);
    }
Example #19
0
        private void ProcessSecurityFrame(object sender, EventArgs e)
        {
            //Get Current Frame
            Image<Bgr, byte> currentFrame = capture.QueryFrame();
            Image<Gray, byte> grayFrame = currentFrame.Convert<Gray, byte>();

            facePos = FaceDetection.Detect(grayFrame);
            SecurityStateManager.AddToHistory(grayFrame.Copy(), facePos);
            PrintInstruction();

            if (!facePos.Equals(Rectangle.Empty))
            {
                BlinkStateManager.faceDetected = true;
                Image<Gray, byte> faceImage = grayFrame.Copy(facePos);

                detected = FaceRecognition.Recognize(faceImage);

                SecurityStateManager.AddToHistory(username.Equals(detected));

                checkBlink(faceImage);
            }

            imageBox.Image = currentFrame;
        }
 private void SetVideoWindow(Rectangle newRect)
 {
   if (_visualisationEnabled && _videoWindow != null)
   {
     _videoWindow.SetVideoWindow = true;
     if (!newRect.Equals(GUIGraphicsContext.VideoWindow))
     {
       GUIGraphicsContext.VideoWindow = newRect;
     }
   }
 }
 /// <summary>
 /// Граничи ли първият обект с вторият
 /// </summary>
 /// <param name="firstObject"></param>
 /// <param name="secondObject"></param>
 /// <returns>връща true ако граничат или false ако не граничат</returns>
 private bool IsColliding(Rectangle firstObject, Rectangle secondObject)
 {
     if (!firstObject.Equals(secondObject))
         return firstObject.IntersectsWith(secondObject);
     else
         return false;
 }
        /// <summary>
        /// Apply a bitmap effect to the surface
        /// </summary>
        /// <param name="effect"></param>
        public void ApplyBitmapEffect(Effects effect)
        {
            BackgroundForm backgroundForm = new BackgroundForm("Effect", "Please wait");
            backgroundForm.Show();
            Application.DoEvents();
            try {
                Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
                Bitmap newImage = null;
                Point offset = Point.Empty;
                switch (effect) {
                    case Effects.Shadow:
                        offset = new Point(6, 6);
                        newImage = ImageHelper.CreateShadow((Bitmap)Image, 1f, 7, offset, PixelFormat.Format32bppRgb); //Image.PixelFormat);
                        break;
                    case Effects.TornEdge:
                        offset = new Point(5, 5);
                        using (Bitmap tmpImage = ImageHelper.CreateTornEdge((Bitmap)Image)) {
                            newImage = ImageHelper.CreateShadow(tmpImage, 1f, 6, offset, PixelFormat.Format32bppRgb); //Image.PixelFormat);
                        }
                        break;
                    case Effects.Border:
                        newImage = ImageHelper.CreateBorder((Bitmap)Image, 2, Color.Black, Image.PixelFormat, out offset);
                        break;
                    case Effects.Grayscale:
                        newImage = ImageHelper.CreateGrayscale((Bitmap)Image);
                        break;
                    case Effects.Invert:
                        newImage = ImageHelper.CreateNegative((Bitmap)Image);
                        break;
                    case Effects.RotateClockwise:
                    case Effects.RotateCounterClockwise:
                        MakeUndoable(new DrawableContainerBoundsChangeMemento(elements.AsIDrawableContainerList()), false);
                        RotateFlipType rotateFlipType = RotateFlipType.Rotate270FlipNone;
                        if (effect == Effects.RotateClockwise) {
                            rotateFlipType = RotateFlipType.Rotate90FlipNone;
                        }
                        foreach (DrawableContainer drawableContainer in elements) {
                            if (drawableContainer.CanRotate) {
                                drawableContainer.Rotate(rotateFlipType);
                            }
                        }
                        newImage = ImageHelper.RotateFlip((Bitmap)Image, rotateFlipType);
                        break;
                }
                // The following was added to correct any unneeded pixels, had the bad effect that sometimes everything was cropped... :(
                //Rectangle autoCropRectangle = ImageHelper.FindAutoCropRectangle(newImage, 0);
                //if (!Size.Empty.Equals(autoCropRectangle.Size) && !autoCropRectangle.Size.Equals(newImage.Size)) {
                //    LOG.InfoFormat("Crop to {0}", autoCropRectangle);
                //    using (Bitmap tmpImage = newImage) {
                //        newImage = ImageHelper.CloneArea(newImage, autoCropRectangle, PixelFormat.DontCare);
                //    }
                //    // Fix offset
                //    offset = new Point(offset.X - autoCropRectangle.X, offset.Y - autoCropRectangle.Y);
                //} else {
                //    LOG.DebugFormat("No cropping needed!");
                //}

                if (newImage != null) {
                    // Make sure the elements move according to the offset the effect made the bitmap move
                    elements.MoveBy(offset.X, offset.Y);
                    // Make undoable
                    MakeUndoable(new SurfaceBackgroundChangeMemento(this, offset), false);
                    SetImage(newImage, false);
                    Invalidate();
                    if (SurfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size))) {
                        SurfaceSizeChanged(this);
                    }
                }
            } finally {
                // Always close the background form
                backgroundForm.CloseDialog();
            }
        }
Example #23
0
        public void TestXmlSerialize()
        {
            PointF p = new PointF(0.0f, 0.0f);
             XmlDocument xDoc = Toolbox.XmlSerialize<PointF>(p, new Type[] { typeof(Point) });
             PointF p2 = Toolbox.XmlDeserialize<PointF>(xDoc, new Type[] { typeof(Point) });
             Assert.IsTrue(p.Equals(p2));

             Rectangle rect = new Rectangle(3, 4, 5, 3);
             XmlDocument xDoc2 = Toolbox.XmlSerialize<Rectangle>(rect);
             Rectangle rect2 = Toolbox.XmlDeserialize<Rectangle>(xDoc2);
             Assert.IsTrue(rect.Equals(rect2));
        }
        /// <summary>
        /// Crop the surface
        /// </summary>
        /// <param name="cropRectangle"></param>
        /// <returns></returns>
        public bool ApplyCrop(Rectangle cropRectangle)
        {
            if (isCropPossible(ref cropRectangle)) {
                Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
                // we should not forget to Dispose the images!!
                Bitmap tmpImage = ImageHelper.CloneArea(Image, cropRectangle, PixelFormat.DontCare);

                Point offset = new Point(-cropRectangle.Left, -cropRectangle.Top);
                // Make undoable
                MakeUndoable(new SurfaceBackgroundChangeMemento(this, offset), false);

                SetImage(tmpImage, false);
                elements.MoveBy(offset.X, offset.Y);
                if (SurfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpImage.Size))) {
                    SurfaceSizeChanged(this);
                }
                Invalidate();
                return true;
            }
            return false;
        }
Example #25
0
        void DrawArrowButton(Rectangle buttonRect, ButtonState state)
        {
            if (HasChild())
            {
                // No drawing buttons if there is a child control in the current band
                return;
            }

            // Directly draw the arrow button
            using (Graphics g = Graphics.FromHwnd(Handle))
            {
                bool up = true;
                ScrollButton buttonType = ScrollButton.Up;
                if (buttonRect.Equals(downArrowRect))
                {
                    buttonType = ScrollButton.Down;
                    up = false;
                }

                if (flatArrowButtons && !HasChild())
                {
                    int first;
                    int last;
                    GetVisibleRange(g, out first, out last);

                    if (up && first == 0)
                    {
                        // up arrow is not visible no need to pain it
                        return;
                    }
                    else if (up == false && last == bands[currentBandIndex].Items.Count - 1)
                    {
                        // down arrow is not visible no need to pain it
                        return;
                    }

                    // If using flat button and the mouse is still over the button
                    // then don't allow drawing it without the hightlight
                    Point pos = Control.MousePosition;
                    pos = PointToClient(pos);
                    if (buttonRect.Contains(pos))
                    {
                        if (up)
                            UpFlatArrowState = DrawState.Hot;
                        else
                            DownFlatArrowState = DrawState.Hot;

                        DrawFlatArrowButton(g, buttonRect, up, DrawState.Hot);
                    }
                    else
                    {
                        if (up)
                            UpFlatArrowState = DrawState.Normal;
                        else
                            DownFlatArrowState = DrawState.Normal;

                    DrawFlatArrowButton(g, buttonRect, up, DrawState.Normal);
                    }
                }
                else
                    ControlPaint.DrawScrollButton(g, buttonRect, buttonType, state);
            }
        }
 /// <summary>
 /// Gets the brush.
 /// </summary>
 /// <param name="rectangle">The rectangle.</param>
 /// <returns></returns>
 public Brush GetBrush(Rectangle rectangle)
 {
     if (rectangle.Equals(Rectangle.Empty))
         return new SolidBrush(mStartColor);
     else
         return new LinearGradientBrush(rectangle, mStartColor, mEndColor, mAngle, true);
 }
Example #27
0
 /// <summary>
 /// Apply a bitmap effect to the surface
 /// </summary>
 /// <param name="effect"></param>
 public void ApplyBitmapEffect(IEffect effect)
 {
     BackgroundForm backgroundForm = new BackgroundForm("Effect", "Please wait");
     backgroundForm.Show();
     Application.DoEvents();
     try
     {
         Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
         Point offset;
         Image newImage = ImageHelper.ApplyEffect(Image, effect, out offset);
         if (newImage != null)
         {
             // Make sure the elements move according to the offset the effect made the bitmap move
             elements.MoveBy(offset.X, offset.Y);
             // Make undoable
             MakeUndoable(new SurfaceBackgroundChangeMemento(this, offset), false);
             SetImage(newImage, false);
             Invalidate();
             if (surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size)))
             {
                 surfaceSizeChanged(this, null);
             }
         }
     }
     finally
     {
         // Always close the background form
         backgroundForm.CloseDialog();
     }
 }
Example #28
0
 /// <summary>
 /// Apply a bitmap effect to the surface
 /// </summary>
 /// <param name="effect"></param>
 public void ApplyBitmapEffect(IEffect effect)
 {
     BackgroundForm backgroundForm = new BackgroundForm("Effect", "Please wait");
     backgroundForm.Show();
     Application.DoEvents();
     try
     {
         Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
         Matrix matrix = new Matrix();
         Image newImage = ImageHelper.ApplyEffect(Image, effect, matrix);
         if (newImage != null)
         {
             // Make sure the elements move according to the offset the effect made the bitmap move
             _elements.Transform(matrix);
             // Make undoable
             MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
             SetImage(newImage, false);
             Invalidate();
             if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size)))
             {
                 _surfaceSizeChanged(this, null);
             }
         }
         else
         {
             // clean up matrix, as it hasn't been used in the undo stack.
             matrix.Dispose();
         }
     }
     finally
     {
         // Always close the background form
         backgroundForm.CloseDialog();
     }
 }
Example #29
0
        public void MoveSelected(Point point)
        {
            ICollection<Operator> selected = GetSelected();
            ICollection<Operator> notSelected = GetNotSelected();

            bool moveNecessary = false;
            foreach (Operator selectedOp in selected)
            {
                Point p = Operator.QuantizeLocation(new Point(selectedOp.Left + point.X,
                                                              selectedOp.Top + point.Y));
                Rectangle selectedOpDim = new Rectangle(p.X,
                                                        p.Y,
                                                        selectedOp.Width,
                                                        selectedOp.Height);

                if (!selectedOpDim.Equals(selectedOp.Dimension))
                    moveNecessary = true;

                foreach (Operator nonSelectedOp in notSelected)
                {
                    if (nonSelectedOp.Dimension.IntersectsWith(selectedOpDim))
                    {
                        // Cannot peform move due to a collision.
                        return;
                    }
                }
            }

            if (!moveNecessary)
                return;

            foreach (Operator op in selected)
            {
                operators.Remove(op);
                Disconnect(op);
            }

            foreach (Operator op in selected)
            {
                Move(op, point);
            }

            foreach (Operator op in selected)
            {
                operators.Add(op);
                Connect(op);
            }

            OnMoved(selected);
        }
Example #30
0
        private void TimelineChannelsView_MouseMove(object sender, MouseEventArgs e)
        {
            if (timeline == null)
                return;

            mouseLocation = new Point(e.X, e.Y);

            if (Mode == Modes.Move)
            {
                if (inSelect)
                {
                    lastSelectionRectangle = selectionRectangle;
                    selectionRectangle = CalculateSelectionRectangle();
                    timeline.SelectClips(PixelDimensionToBeatDimension(selectionRectangle));
                    if (!lastSelectionRectangle.Equals(selectionRectangle))
                    {
                        Invalidate(lastSelectionRectangle);
                        Invalidate(selectionRectangle);
                    }
                }

                if (inMove)
                {
                    lastMoveRectangle = moveRectangle;
                    moveRectangle = CalculateMoveRectangle();
                    if (!lastMoveRectangle.Equals(moveRectangle))
                    {
                        Invalidate(lastMoveRectangle);
                        Invalidate(moveRectangle);
                    }
                }

                if (inResize)
                {
                    lastResizeRectangle = resizeRectangle;
                    resizeRectangle = CalculateResizeRectangle();
                    if (!lastResizeRectangle.Equals(resizeRectangle))
                    {
                        Invalidate(lastResizeRectangle);
                        Invalidate(resizeRectangle);
                    }
                }
            }

            if (mode == Modes.DrawGenerator || mode == Modes.DrawSpline)
            {
                if (inDraw)
                {
                    lastDrawRectangle = drawRectangle;
                    drawRectangle = CalculateDrawRectangle();
                    if (!lastDrawRectangle.Equals(drawRectangle))
                    {
                        Invalidate(lastDrawRectangle);
                        Invalidate(drawRectangle);
                    }
                }
            }
        }