コード例 #1
0
ファイル: RectsView.cs プロジェクト: jamiebriant/monomac
		// Shared initialization code
		void Initialize ()
		{			
			if (beenHere) return;
			
			beenHere = true;
			
			// Moved from the initWithFrame constructor because it was giving a 
			// not initialized correctly message.
			RectangleF aRect;
			ColorRect firstRect;
			
			SetBoundsOrigin (new PointF (-108.0f,-108.0f));
			
			rects = new List<ColorRect> ();
			selectedItem = null;
			
			aRect = new RectangleF (30.0f, 45.0f, 57.0f, 118.0f);
			firstRect = new ColorRect (aRect, NSColor.Blue);
			rects.Add (firstRect);                          

			//-------------------------------------------------------------------
			
			NSBundle mainBundle;
			string path;
			
			mainBundle = NSBundle.MainBundle;
			path = mainBundle.PathForResource ("EdgeMarkerLeft","tiff");
			leftImage = new NSImage(path);
			
			path = mainBundle.PathForResource ("EdgeMarkerRight","tiff");
			rightImage = new NSImage(path);
			
			path = mainBundle.PathForResource ("EdgeMarkerTop","tiff");
			topImage = new NSImage(path);

			path = mainBundle.PathForResource ("EdgeMarkerBottom","tiff");
			bottomImage = new NSImage (path);
			
			upArray = new NSNumber[] { NSNumber.FromDouble (2.0) };
			downArray = new NSNumber[] { NSNumber.FromDouble (0.5),
										NSNumber.FromDouble (0.2)};
			
			// Setup our custom ruler units
			NSRulerView.RegisterUnit ("MyCustomRulerUnits", "mcru", 100.0f, upArray, downArray);

		}
コード例 #2
0
ファイル: RectsView.cs プロジェクト: tartoufo1973/mac-samples
        public void rulerViewDidAddMarker(NSRulerView aRulerView, NSRulerMarker aMarker)
        {
            float      theOtherCoord;
            RectangleF newRect;
            NSColor    newColor;
            ColorRect  newColorRect;

            var visibleRect = VisibleRect();

            aMarker.Removable = true;

            if (aRulerView.Orientation == NSRulerOrientation.Horizontal)
            {
                theOtherCoord = MaxY(visibleRect) - 165.0f;
                newRect       = new RectangleF(aMarker.MarkerLocation, theOtherCoord, 115.0f, 115.0f);
            }
            else
            {
                if (IsFlipped)
                {
                    theOtherCoord = MinX(visibleRect) + 50.0f;
                    newRect       = new RectangleF(theOtherCoord, aMarker.MarkerLocation, 115.0f, 115.0f);
                }
                else
                {
                    theOtherCoord = MinX(visibleRect) + 50.0f;
                    newRect       = new RectangleF(theOtherCoord, aMarker.MarkerLocation - 115.0f, 115.0f, 115.0f);
                }
            }

            newColor = NSColor.FromDeviceRgba((float)rand.NextDouble(),
                                              (float)rand.NextDouble(),
                                              (float)rand.NextDouble(),
                                              1.0f);
            newColorRect = new ColorRect(newRect, newColor);
            rects.Add(newColorRect);
            selectRect(newColorRect);
        }
コード例 #3
0
ファイル: RectsView.cs プロジェクト: tartoufo1973/mac-samples
        public override void MouseDown(NSEvent theEvent)
        {
            ColorRect   oldSelectedItem = selectedItem;
            ColorRect   thisRect;
            PointF      mouseLoc    = PointF.Empty;
            PointF      mouseOffset = PointF.Empty;
            NSEventMask eventMask;
            bool        dragged = false;
            bool        timerOn = false;

            NSEvent autoScrollEvent = null;

            selectedItem = null;

            if (!Window.MakeFirstResponder(this))
            {
                return;
            }

            mouseLoc = ConvertPointFromView(theEvent.LocationInWindow, null);

            // we go from last to first
            for (int x = rects.Count - 1; x >= 0; x--)
            {
                thisRect = rects[x];

                if (IsMouseInRect(mouseLoc, thisRect.Frame))
                {
                    selectedItem = thisRect;
                    break;
                }
            }

            if (oldSelectedItem != selectedItem)
            {
                if (oldSelectedItem != null)
                {
                    SetNeedsDisplayInRect(oldSelectedItem.Frame);
                }
                if (selectedItem != null)
                {
                    SetNeedsDisplayInRect(selectedItem.Frame);
                }

                updateRulers();
            }

            if (selectedItem == null || selectedItem.IsLocked)
            {
                return;
            }

            mouseOffset.X = mouseLoc.X - selectedItem.Frame.Location.X;
            mouseOffset.Y = mouseLoc.Y - selectedItem.Frame.Location.Y;

            eventMask = NSEventMask.LeftMouseDragged | NSEventMask.LeftMouseUp
                        | NSEventMask.Periodic;

            while (theEvent != null)
            {
                RectangleF visibleRect = VisibleRect();

                switch (theEvent.Type)
                {
                case NSEventType.Periodic:
                    if (autoScrollEvent != null)
                    {
                        Autoscroll(autoScrollEvent);
                    }
                    moveSelectedItemWithEvent(autoScrollEvent, mouseOffset);
                    break;

                case NSEventType.LeftMouseDragged:
                    if (!dragged)
                    {
                        drawRulerLinesWithRect(selectedItem.Frame);
                    }

                    dragged  = true;
                    mouseLoc = ConvertPointFromView(theEvent.LocationInWindow, null);

                    moveSelectedItemWithEvent(theEvent, mouseOffset);

                    if (!IsMouseInRect(mouseLoc, visibleRect))
                    {
                        if (!timerOn)
                        {
                            NSEvent.StartPeriodicEventsAfterDelay(0.1, 0.1);
                            timerOn = true;
                        }

                        autoScrollEvent = theEvent;
                        break;
                    }
                    else
                    {
                        if (timerOn)
                        {
                            NSEvent.StopPeriodicEvents();
                            timerOn         = false;
                            autoScrollEvent = null;
                        }
                    }
                    DisplayIfNeeded();
                    break;

                case NSEventType.LeftMouseUp:
                    if (timerOn)
                    {
                        NSEvent.StopPeriodicEvents();
                        timerOn         = false;
                        autoScrollEvent = null;
                    }
                    if (dragged)
                    {
                        eraseRulerLinesWithRect(selectedItem.Frame);
                    }
                    updateRulers();
                    return;

                default:
                    break;
                }

                theEvent = this.Window.NextEventMatchingMask(eventMask);
            }
        }
コード例 #4
0
ファイル: RectsView.cs プロジェクト: jamiebriant/monomac
		public void rulerViewDidAddMarker (NSRulerView aRulerView, NSRulerMarker aMarker)
		{
			float theOtherCoord;
			RectangleF newRect;
			NSColor newColor;
			ColorRect newColorRect;
			
			var visibleRect = VisibleRect();
			
			aMarker.Removable = true;
			
			if (aRulerView.Orientation == NSRulerOrientation.Horizontal){
				theOtherCoord = MaxY (visibleRect) - 165.0f;
				newRect = new RectangleF (aMarker.MarkerLocation, theOtherCoord, 115.0f, 115.0f);
			} else {
				if (IsFlipped) {
					theOtherCoord = MinX (visibleRect) + 50.0f;
					newRect = new RectangleF(theOtherCoord, aMarker.MarkerLocation, 115.0f, 115.0f);
				} else {
					theOtherCoord = MinX(visibleRect) + 50.0f;
					newRect = new RectangleF (theOtherCoord, aMarker.MarkerLocation - 115.0f, 115.0f, 115.0f);
				}
			}
				
			newColor = NSColor.FromDeviceRgba ((float)rand.NextDouble (),
			                                        (float)rand.NextDouble (),
			                                        (float)rand.NextDouble (),
			                                        1.0f);
			newColorRect = new ColorRect (newRect, newColor);
			rects.Add (newColorRect);
			selectRect (newColorRect);
		}		
コード例 #5
0
ファイル: RectsView.cs プロジェクト: jamiebriant/monomac
		public void rulerViewDidRemoveMarker (NSRulerView aRulerView, NSRulerMarker aMarker)
		{
			if (selectedItem == null) 
				return;
			
			SetNeedsDisplayInRect (selectedItem.Frame);
			rects.Remove (selectedItem);
			selectedItem = null;
			updateRulers ();
		}
コード例 #6
0
ファイル: RectsView.cs プロジェクト: jamiebriant/monomac
		private void selectRect (ColorRect aColorRect)
		{
			if (selectedItem == aColorRect) 
				return;
			
			if (selectedItem != null)
				SetNeedsDisplayInRect (selectedItem.Frame);
			
			if (aColorRect == null) 
				selectedItem = null;
			else 
				if (rects.Contains (aColorRect))
					selectedItem = aColorRect;
			
			updateRulers ();
			
			if (selectedItem != null)
				SetNeedsDisplayInRect (selectedItem.Frame);
		}
コード例 #7
0
ファイル: RectsView.cs プロジェクト: jamiebriant/monomac
		public override void MouseDown (NSEvent theEvent)
		{
			ColorRect oldSelectedItem = selectedItem;
			ColorRect thisRect;
			PointF mouseLoc = PointF.Empty;
			PointF mouseOffset = PointF.Empty;
			NSEventMask eventMask;
			bool dragged = false;
			bool timerOn = false;
			
			NSEvent autoScrollEvent = null;
			
			selectedItem = null;
			
			if (!Window.MakeFirstResponder (this)) 
				return;
			
			mouseLoc = ConvertPointfromView (theEvent.LocationInWindow, null);
			
			// we go from last to first
			for (int x = rects.Count - 1;x >= 0; x--){
				thisRect = rects[x];
				
				if (MouseinRect(mouseLoc,thisRect.Frame)){
					selectedItem = thisRect;
					break;
				}
			}
			
			if (oldSelectedItem != selectedItem){
				if (oldSelectedItem != null)
					SetNeedsDisplayInRect (oldSelectedItem.Frame);
				if (selectedItem != null)
					SetNeedsDisplayInRect (selectedItem.Frame);
			 	
				updateRulers ();
			}
			
			if (selectedItem == null || selectedItem.IsLocked) 
				return;
			
			mouseOffset.X = mouseLoc.X - selectedItem.Frame.Location.X;
			mouseOffset.Y = mouseLoc.Y - selectedItem.Frame.Location.Y;
			
			eventMask = NSEventMask.LeftMouseDragged | NSEventMask.LeftMouseUp
						| NSEventMask.Periodic;
			
			while (theEvent != null) {
				RectangleF visibleRect = VisibleRect ();
				
				switch (theEvent.Type){					
				case NSEventType.Periodic:
					if (autoScrollEvent != null)
						Autoscroll(autoScrollEvent);
					moveSelectedItemWithEvent (autoScrollEvent, mouseOffset);
					break;
					
				case NSEventType.LeftMouseDragged:
					if (!dragged)
						drawRulerLinesWithRect (selectedItem.Frame);
					
					dragged = true;
					mouseLoc = ConvertPointfromView (theEvent.LocationInWindow, null);
					
					moveSelectedItemWithEvent (theEvent, mouseOffset);
					
					if (!MouseinRect (mouseLoc, visibleRect)){
						if (!timerOn){
							NSEvent.StartPeriodicEventsAfterDelay (0.1,0.1);
							timerOn = true;
						}
						
						autoScrollEvent = theEvent;
						break;						
					} else {
						if (timerOn){
 							NSEvent.StopPeriodicEvents ();
							timerOn = false;
							autoScrollEvent = null;
						}
						
					}
					DisplayIfNeeded ();
					break;
					
				case NSEventType.LeftMouseUp:
					if (timerOn){
						NSEvent.StopPeriodicEvents ();
						timerOn = false;
						autoScrollEvent = null;
					}
					if (dragged)
						eraseRulerLinesWithRect (selectedItem.Frame);
					updateRulers ();
					return;

				default:
					break;
				}
				
				theEvent = this.Window.NextEventMatchingMask (eventMask);
			}
		}