Exemplo n.º 1
0
        // function that executes when the tile is touched
        void TextTile_Touch(object sender, View.TouchEventArgs e)
        {
            if (e.Event.Action == MotionEventActions.Up)
            {
                MyTextView thisTile = (MyTextView)sender;

                // just write the position of the tile in the Xamarin console, to see each tile when moves
                Console.WriteLine("\r tile is at: \r x={0} \r y={1}", thisTile.xPos, thisTile.yPos);

                // compute the distace between the tile which was pressed and the empty space
                float xDif = (float)Math.Pow(thisTile.xPos - emptySpot.X, 2);
                float yDif = (float)Math.Pow(thisTile.yPos - emptySpot.Y, 2);
                float dist = (float)Math.Sqrt(xDif + yDif);

                // if the tile was near the empty space
                if (dist == 1)
                {
                    // memorize the current position of the tile
                    Point curPoint = new Point(thisTile.xPos, thisTile.yPos);

                    // we want to put the tile on the place of the empty space
                    GridLayout.Spec rowSpec = GridLayout.InvokeSpec(emptySpot.Y);
                    GridLayout.Spec colSpec = GridLayout.InvokeSpec(emptySpot.X);

                    GridLayout.LayoutParams newLocParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                    // the tile moves in the empty space
                    thisTile.xPos = emptySpot.X;
                    thisTile.yPos = emptySpot.Y;

                    // we set the appearance of the tile
                    newLocParams.Width  = tileWidth - 10;
                    newLocParams.Height = tileWidth - 10;
                    newLocParams.SetMargins(5, 5, 5, 5);

                    thisTile.LayoutParameters = newLocParams;

                    // the empty place goes where was the pressed tile before
                    emptySpot = curPoint;
                }
            }
        }
Exemplo n.º 2
0
        public bool Run(ExceptionDialogData data)
        {
            using (var alert = new NSAlert {
                AlertStyle = NSAlertStyle.Critical
            }) {
                IdeTheme.ApplyTheme(alert.Window);
                alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;

                alert.MessageText = data.Title ?? GettextCatalog.GetString("Error");

                if (!string.IsNullOrEmpty(data.Message))
                {
                    alert.InformativeText = data.Message;
                }

                List <AlertButton> buttons = null;
                if (data.Buttons != null && data.Buttons.Length > 0)
                {
                    buttons = data.Buttons.Reverse().ToList();
                }

                if (buttons != null)
                {
                    foreach (var button in buttons)
                    {
                        var label = button.Label;
                        if (button.IsStockButton)
                        {
                            label = Gtk.Stock.Lookup(label).Label;
                        }
                        label = label.Replace("_", "");

                        //this message seems to be a standard Mac message since alert handles it specially
                        if (button == AlertButton.CloseWithoutSave)
                        {
                            label = GettextCatalog.GetString("Don't Save");
                        }

                        alert.AddButton(label);
                    }
                }

                if (data.Exception != null)
                {
                    var         scrollSize = new CGSize(400, 130);
                    const float spacing    = 4;

                    string title    = GettextCatalog.GetString("View details");
                    string altTitle = GettextCatalog.GetString("Hide details");

                    var buttonFrame = new CGRect(0, 0, 0, 0);
                    var button      = new NSButton(buttonFrame)
                    {
                        BezelStyle     = NSBezelStyle.Disclosure,
                        Title          = "",
                        AlternateTitle = "",
                    };
                    button.SetButtonType(NSButtonType.OnOff);
                    button.SizeToFit();

                    var label = new MDClickableLabel(title)
                    {
                        Alignment = NSTextAlignment.Left,
                    };
                    label.SizeToFit();

                    button.SetFrameSize(new CGSize(button.Frame.Width, NMath.Max(button.Frame.Height, label.Frame.Height)));
                    label.SetFrameOrigin(new CGPoint(button.Frame.Width + 5, button.Frame.Y));

                    var text = new MyTextView(new CGRect(0, 0, float.MaxValue, float.MaxValue))
                    {
                        HorizontallyResizable = true,
                    };
                    text.TextContainer.ContainerSize       = new CGSize(float.MaxValue, float.MaxValue);
                    text.TextContainer.WidthTracksTextView = true;
                    text.InsertText(new NSString(data.Exception.ToString()));
                    text.Editable = false;

                    var scrollView = new NSScrollView(new CGRect(CGPoint.Empty, CGSize.Empty))
                    {
                        HasHorizontalScroller = true,
                        HasVerticalScroller   = true,
                    };

                    var accessory = new NSView(new CGRect(0, 0, scrollSize.Width, button.Frame.Height));
                    accessory.AddSubview(scrollView);
                    accessory.AddSubview(button);
                    accessory.AddSubview(label);

                    alert.AccessoryView = accessory;

                    button.Activated += delegate {
                        nfloat change;
                        if (button.State == NSCellStateValue.On)
                        {
                            change                  = scrollSize.Height + spacing;
                            label.StringValue       = altTitle;
                            scrollView.Hidden       = false;
                            scrollView.Frame        = new CGRect(CGPoint.Empty, scrollSize);
                            scrollView.DocumentView = text;
                        }
                        else
                        {
                            change            = -(scrollSize.Height + spacing);
                            label.StringValue = title;
                            scrollView.Hidden = true;
                            scrollView.Frame  = new CGRect(CGPoint.Empty, CGSize.Empty);
                        }
                        var f = accessory.Frame;
                        f.Height       += change;
                        accessory.Frame = f;
                        var lf = label.Frame;
                        lf.Y       += change;
                        label.Frame = lf;
                        var bf = button.Frame;
                        bf.Y        += change;
                        button.Frame = bf;
                        label.SizeToFit();
                        var panel = alert.Window;
                        var pf    = panel.Frame;
                        pf.Height += change;
                        pf.Y      -= change;
                        panel.SetFrame(pf, true, true);
                        //unless we assign the icon again, it starts nesting old icon into the warning icon
                        alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
                        alert.Layout();
                    };
                    label.OnMouseUp += (sender, e) => button.PerformClick(e.Event);
                }

                var result = (int)(nint)alert.RunModal() - (int)(long)NSAlertButtonReturn.First;
                data.ResultButton = buttons != null ? buttons [result] : null;
                GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow);
            }

            return(true);
        }
		public bool Run (ExceptionDialogData data)
		{
			using (var alert = new NSAlert { AlertStyle = NSAlertStyle.Critical }) {
				alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
				
				alert.MessageText = data.Title ?? GettextCatalog.GetString ("Error");
				
				if (!string.IsNullOrEmpty (data.Message)) {
					alert.InformativeText = data.Message;
				}

				List<AlertButton> buttons = null;
				if (data.Buttons != null && data.Buttons.Length > 0)
					buttons = data.Buttons.Reverse ().ToList ();

				if (buttons != null) {
					foreach (var button in buttons) {
						var label = button.Label;
						if (button.IsStockButton)
							label = Gtk.Stock.Lookup (label).Label;
						label = label.Replace ("_", "");

						//this message seems to be a standard Mac message since alert handles it specially
						if (button == AlertButton.CloseWithoutSave)
							label = GettextCatalog.GetString ("Don't Save");

						alert.AddButton (label);
					}
				}

				if (data.Exception != null) {
					var scrollSize = new CGSize (400, 130);
					const float spacing = 4;
					
					string title = GettextCatalog.GetString ("View details");
					string altTitle = GettextCatalog.GetString ("Hide details");
					
					var buttonFrame = new CGRect (0, 0, 0, 0);
					var button = new NSButton (buttonFrame) {
						BezelStyle = NSBezelStyle.Disclosure,
						Title = "",
						AlternateTitle = "",
					};
					button.SetButtonType (NSButtonType.OnOff);
					button.SizeToFit ();
					
					var label = new MDClickableLabel (title) {
						Alignment = NSTextAlignment.Left,
					};
					label.SizeToFit ();
					
					button.SetFrameSize (new CGSize (button.Frame.Width, NMath.Max (button.Frame.Height, label.Frame.Height)));
					label.SetFrameOrigin (new CGPoint (button.Frame.Width + 5, button.Frame.Y));
					
					var text = new MyTextView (new CGRect (0, 0, float.MaxValue, float.MaxValue)) {
						HorizontallyResizable = true,
					};
					text.TextContainer.ContainerSize = new CGSize (float.MaxValue, float.MaxValue);
					text.TextContainer.WidthTracksTextView = true;
					text.InsertText (new NSString (data.Exception.ToString ()));
					text.Editable = false;

					var scrollView = new NSScrollView (new CGRect (CGPoint.Empty, CGSize.Empty)) {
						HasHorizontalScroller = true,
						HasVerticalScroller = true,
					};
					
					var accessory = new NSView (new CGRect (0, 0, scrollSize.Width, button.Frame.Height));
					accessory.AddSubview (scrollView);
					accessory.AddSubview (button);
					accessory.AddSubview (label);
					
					alert.AccessoryView = accessory;
					
					button.Activated += delegate {
						nfloat change;
						if (button.State == NSCellStateValue.On) {
							change = scrollSize.Height + spacing;
							label.StringValue = altTitle;
							scrollView.Hidden = false;
							scrollView.Frame = new CGRect (CGPoint.Empty, scrollSize);
							scrollView.DocumentView = text;
						} else {
							change = -(scrollSize.Height + spacing);
							label.StringValue = title;
							scrollView.Hidden = true;
							scrollView.Frame = new CGRect (CGPoint.Empty, CGSize.Empty);
						}
						var f = accessory.Frame;
						f.Height += change;
						accessory.Frame = f;
						var lf = label.Frame;
						lf.Y += change;
						label.Frame = lf;
						var bf = button.Frame;
						bf.Y += change;
						button.Frame = bf;
						label.SizeToFit ();
						var panel = alert.Window;
						var pf = panel.Frame;
						pf.Height += change;
						pf.Y -= change;
						panel.SetFrame (pf, true, true);
						//unless we assign the icon again, it starts nesting old icon into the warning icon
						alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
						alert.Layout ();
					};
					label.OnMouseUp += (sender, e) => button.PerformClick (e.Event);
				}

				var result = (int)(nint)alert.RunModal () - (int)(long)NSAlertButtonReturn.First;
				data.ResultButton = buttons != null ? buttons [result] : null;
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}
Exemplo n.º 4
0
 public ChangesetDiffView(Driver driver)
 {
     this.driver = driver;
         textView = MyTextViewFactory.CreateNewTextView();
         Add(textView);
 }
Exemplo n.º 5
0
        // method to create the grid layout
        private void makeTilesMethod()
        {
            // the grid is 4 x 4 -> the width of a tile is a quarter of the width of the grid
            tileWidth = gameViewWidth / 4;

            // create a counter to keep in mind the number of the tile
            int counter = 1;

            // initialize the lists for storing the coordinates of the tiles
            tilesList       = new ArrayList();
            coordinatesList = new ArrayList();

            // we need to create all 16 tiles, they being placed on 4 rows and 4 columns
            for (int row = 0; row < 4; ++row)
            {
                for (int column = 0; column < 4; ++column)
                {
                    // we want to make a tile and add it in our main layout
                    MyTextView textTile = new MyTextView(this);

                    // we want to put a tile on the row 'row' and column 'column'
                    GridLayout.Spec rowSpec = GridLayout.InvokeSpec(row);
                    GridLayout.Spec colSpec = GridLayout.InvokeSpec(column);

                    GridLayout.LayoutParams tileLayoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);

                    // print the number of the tile on it
                    textTile.Text = counter.ToString();
                    textTile.SetTextColor(Color.Black);
                    textTile.TextSize = 40;
                    textTile.Gravity  = GravityFlags.Center; // put the text in the center of the tile

                    // set the width and height of the tile
                    tileLayoutParams.Width  = tileWidth - 10; // (-10) for visibility
                    tileLayoutParams.Height = tileWidth - 10; // (-10) for visibility
                    tileLayoutParams.SetMargins(5, 5, 5, 5);  // for making a nice looking contour


                    // make the changes in the actual textTile
                    textTile.LayoutParameters = tileLayoutParams;
                    textTile.SetBackgroundColor(Color.Green);

                    // keep the coordinates of a tile (as a point in space, where the X coordinate is the column and Y coordiante is the row)
                    Point thisLocation = new Point(column, row);
                    // add the coordiante of this point in the coordinatesList
                    coordinatesList.Add(thisLocation);
                    // add the tile in the list, to use it later
                    tilesList.Add(textTile);

                    // remember the position if the tile
                    textTile.xPos = thisLocation.X;
                    textTile.yPos = thisLocation.Y;

                    // assign a method to execute when we toch the button
                    textTile.Touch += TextTile_Touch;

                    // add the tile in the main layout
                    mainLayout.AddView(textTile);

                    // increase the counter to the next number
                    counter = counter + 1;
                }
            }

            // remove the 16th tile -> tilesList start from the position 0 (not 1 as expected), so the 16th element is on the position 15
            mainLayout.RemoveView((MyTextView)tilesList[15]);
            // remove the 16th tile also from our list
            tilesList.RemoveAt(15);
        }
Exemplo n.º 6
0
 public FileView(Driver driver)
 {
     this.driver = driver;
     view        = MyTextViewFactory.CreateNewTextView();
     Add(view);
 }
Exemplo n.º 7
0
 public ChangesetDiffView(Driver driver)
 {
     this.driver = driver;
     textView    = MyTextViewFactory.CreateNewTextView();
     Add(textView);
 }
Exemplo n.º 8
0
 public FileView(Driver driver)
 {
     this.driver = driver;
         view = MyTextViewFactory.CreateNewTextView();
         Add(view);
 }