// constructor for placement relative to a widget. use screen widget for screen placement. public Position(Widget parent, ePlacement placement, Vector2 size) { XUtils.Assert(placement != ePlacement.Absolute, "wrong constructor for absolute"); Init(parent, placement); switch (placement) { case ePlacement.Centered: Place(size, 0.5f, 0.5f, -0.5f, -0.5f, 0.0f, 0.0f); break; case ePlacement.CenteredLeft: Place(size, 0.0f, 0.5f, 0.0f, -0.5f, 1.0f, 0.0f); break; case ePlacement.CenteredRight: Place(size, 1.0f, 0.5f, -1.0f, -0.5f, -1.0f, 0.0f); break; case ePlacement.CenteredTop: Place(size, 0.5f, 0.0f, -0.5f, 0.0f, 0.0f, 1.0f); break; case ePlacement.CenteredBottom: Place(size, 0.5f, 1.0f, -0.5f, -1.0f, 0.0f, -1.0f); break; case ePlacement.TopLeft: Place(size, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f); break; case ePlacement.TopRight: Place(size, 1.0f, 0.0f, -1.0f, 0.0f, -1.0f, 1.0f); break; case ePlacement.BottomLeft: Place(size, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, -1.0f); break; case ePlacement.BottomRight: Place(size, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f); break; default: XUtils.Assert(false, "placement type not yet supported"); break; } ValidateAABB(); }
public Button(Widget parent, Style style, String text, ePlacement placement) { // optimize later Vector2 label_size = Label.GetSizeOfText(text, style); eFont font = style.mNormalFont; Vector2 font_size = XFontDraw.Instance().GetFontInfo(font).mSize; float padding = style.mButtonPadding; Vector2 size = label_size + 2.0f * new Vector2(padding, padding); InitPanel(parent, style, size, placement); Label label = new Label(this, text, style, ePlacement.Centered); AddChild(label); }
private void Init(Widget parent, ePlacement placement) { mParent = parent; mPlacement = placement; }
public PopupForm(Popup popup) { mPopup = popup; SetStyle(ControlStyles.ResizeRedraw, true); FormBorderStyle = FormBorderStyle.None; StartPosition = FormStartPosition.Manual; this.ShowInTaskbar = false; this.DockPadding.All = BORDER_MARGIN; mControlSize = mPopup.mUserControl.Size; mPopup.mUserControl.Dock = DockStyle.Fill; Controls.Add(mPopup.mUserControl); mWindowSize.Width = mControlSize.Width + 2 * BORDER_MARGIN; mWindowSize.Height = mControlSize.Height + 2 * BORDER_MARGIN; this.Opacity = popup.mOpacity; //These are here to suppress warnings. this.DropDown += new System.EventHandler(DoNothing); this.DropDownClosed += new System.EventHandler(DoNothing); Form parentForm = mPopup.mParent.FindForm(); if (parentForm != null) { parentForm.AddOwnedForm(this); } if (mPopup.mResizable) { mResizingPanel = new Panel(); if (mBackgroundImage == null) { var resources = new System.Resources.ResourceManager(typeof(Popup)); mBackgroundImage = (System.Drawing.Image)resources.GetObject("CornerPicture.Image"); } mResizingPanel.BackgroundImage = mBackgroundImage; mResizingPanel.Width = 12; mResizingPanel.Height = 12; mResizingPanel.BackColor = Color.Red; mResizingPanel.Left = mPopup.mUserControl.Width - 15; mResizingPanel.Top = mPopup.mUserControl.Height - 15; mResizingPanel.Cursor = Cursors.SizeNWSE; mResizingPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; mResizingPanel.Parent = this; mResizingPanel.BringToFront(); this.mResizingPanel.MouseUp += new MouseEventHandler(mResizingPanel_MouseUp); this.mResizingPanel.MouseDown += new MouseEventHandler(mResizingPanel_MouseDown); this.mResizingPanel.MouseMove += new MouseEventHandler(mResizingPanel_MouseMove); } mPlacement = mPopup.mPlacement; // Try to place the popup at the asked location ReLocate(); // Check if the form is out of the screen // And if yes try to adapt the placement Rectangle workingArea = Screen.FromControl(mPopup.mParent).WorkingArea; if (mNormalPos.X + this.Width > workingArea.Right) { if ((mPlacement & ePlacement.Right) != 0) { mPlacement = (mPlacement & ~ePlacement.Right) | ePlacement.Left; } } else { if (mNormalPos.X < workingArea.Left) { if ((mPlacement & ePlacement.Left) != 0) { mPlacement = (mPlacement & ~ePlacement.Left) | ePlacement.Right; } } } if (mNormalPos.Y + this.Height > workingArea.Bottom) { if ((mPlacement & ePlacement.Bottom) != 0) { mPlacement = (mPlacement & ~ePlacement.Bottom) | ePlacement.Top; } } else { if (mNormalPos.Y < workingArea.Top) { if ((mPlacement & ePlacement.Top) != 0) { mPlacement = (mPlacement & ~ePlacement.Top) | ePlacement.Bottom; } } } if (mPlacement != mPopup.mPlacement) { ReLocate(); } // Check if the form is still out of the screen // If yes just move it back into the screen without changing Placement if (mNormalPos.X + mWindowSize.Width > workingArea.Right) { mNormalPos.X = workingArea.Right - mWindowSize.Width; } else { if (mNormalPos.X < workingArea.Left) { mNormalPos.X = workingArea.Left; } } if (mNormalPos.Y + mWindowSize.Height > workingArea.Bottom) { mNormalPos.Y = workingArea.Bottom - mWindowSize.Height; } else { if (mNormalPos.Y < workingArea.Top) { mNormalPos.Y = workingArea.Top; } } // Initialize the animation mProgress = 0; if (mPopup.mAnimationSpeed > 0) { mTimer = new Timer(); // I always aim 25 images per seconds.. seems to be a good value // it looks smooth enough on fast computers and do not drain slower one mTimer.Interval = 1000 / 25; mTimerStarted = System.DateTimeOffset.Now; mTimer.Tick += new System.EventHandler(Showing); mTimer.Start(); Showing(null, null); } else { SetFinalLocation(); } Show(); mPopup.OnDropDown(mPopup.mParent, new System.EventArgs()); }
public void InitPanel(Widget parent, Style style, Vector2 size, ePlacement placement) { Init(); InitWidget(parent, style, placement, size); }
public void InitWidget(Widget parent, Style style, ePlacement placement, Vector2 size) { InitWidgetCommon(style); mPosition = new Position(parent, placement, size); }
public PopupForm(Popup popup) { this.mPopup = popup; this.SetStyle(ControlStyles.ResizeRedraw, true); this.FormBorderStyle = FormBorderStyle.None; this.StartPosition = FormStartPosition.Manual; this.ShowInTaskbar = false; this.DockPadding.All = PopupForm.BORDER_MARGIN; this.mControlSize = this.mPopup.UserControl.Size; this.mPopup.UserControl.Dock = DockStyle.Fill; this.Controls.Add(this.mPopup.UserControl); this.mWindowSize.Width = this.mControlSize.Width + 2*PopupForm.BORDER_MARGIN; this.mWindowSize.Height = this.mControlSize.Height + 2*PopupForm.BORDER_MARGIN; this.Opacity = popup.Opacity; //These are here to suppress warnings. this.DropDown += this.DoNothing; this.DropDownClosed += this.DoNothing; Form parentForm = this.mPopup.mParent.FindForm(); if (parentForm != null) { parentForm.AddOwnedForm(this); } if (this.mPopup.Resizable) { this.mResizingPanel = new Panel(); if (PopupForm.mBackgroundImage == null) { var resources = new System.Resources.ResourceManager(typeof (Popup)); PopupForm.mBackgroundImage = (Image) resources.GetObject("CornerPicture.Image"); } this.mResizingPanel.BackgroundImage = PopupForm.mBackgroundImage; this.mResizingPanel.Width = 12; this.mResizingPanel.Height = 12; this.mResizingPanel.BackColor = Color.Red; this.mResizingPanel.Left = this.mPopup.UserControl.Width - 15; this.mResizingPanel.Top = this.mPopup.UserControl.Height - 15; this.mResizingPanel.Cursor = Cursors.SizeNWSE; this.mResizingPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; this.mResizingPanel.Parent = this; this.mResizingPanel.BringToFront(); this.mResizingPanel.MouseUp += this.mResizingPanel_MouseUp; this.mResizingPanel.MouseDown += this.mResizingPanel_MouseDown; this.mResizingPanel.MouseMove += this.mResizingPanel_MouseMove; } this.mPlacement = this.mPopup.HorizontalPlacement; // Try to place the popup at the asked location this.ReLocate(); // Check if the form is out of the screen // And if yes try to adapt the placement Rectangle workingArea = Screen.FromControl(this.mPopup.mParent).WorkingArea; if (this.mNormalPos.X + this.Width > workingArea.Right) { if ((this.mPlacement & ePlacement.Right) != 0) { this.mPlacement = (this.mPlacement & ~ePlacement.Right) | ePlacement.Left; } } else { if (this.mNormalPos.X < workingArea.Left) { if ((this.mPlacement & ePlacement.Left) != 0) { this.mPlacement = (this.mPlacement & ~ePlacement.Left) | ePlacement.Right; } } } if (this.mNormalPos.Y + this.Height > workingArea.Bottom) { if ((this.mPlacement & ePlacement.Bottom) != 0) { this.mPlacement = (this.mPlacement & ~ePlacement.Bottom) | ePlacement.Top; } } else { if (this.mNormalPos.Y < workingArea.Top) { if ((this.mPlacement & ePlacement.Top) != 0) { this.mPlacement = (this.mPlacement & ~ePlacement.Top) | ePlacement.Bottom; } } } if (this.mPlacement != this.mPopup.HorizontalPlacement) { this.ReLocate(); } // Check if the form is still out of the screen // If yes just move it back into the screen without changing Placement if (this.mNormalPos.X + this.mWindowSize.Width > workingArea.Right) { this.mNormalPos.X = workingArea.Right - this.mWindowSize.Width; } else { if (this.mNormalPos.X < workingArea.Left) { this.mNormalPos.X = workingArea.Left; } } if (this.mNormalPos.Y + this.mWindowSize.Height > workingArea.Bottom) { this.mNormalPos.Y = workingArea.Bottom - this.mWindowSize.Height; } else { if (this.mNormalPos.Y < workingArea.Top) { this.mNormalPos.Y = workingArea.Top; } } // Initialize the animation this.mProgress = 0; if (this.mPopup.AnimationSpeed > 0) { this.mTimer = new Timer(); // I always aim 25 images per seconds.. seems to be a good value // it looks smooth enough on fast computers and do not drain slower one this.mTimer.Interval = 1000/25; this.mTimerStarted = System.DateTimeOffset.Now; this.mTimer.Tick += this.Showing; this.mTimer.Start(); this.Showing(null, null); } else { this.SetFinalLocation(); } this.Show(); this.mPopup.OnDropDown(this.mPopup.mParent, new System.EventArgs()); }
public PopupForm(LISPop popup) { mPopup = popup; SetStyle(ControlStyles.ResizeRedraw, true); FormBorderStyle = FormBorderStyle.None; StartPosition = FormStartPosition.Manual; this.ShowInTaskbar = false; this.DockPadding.All = BORDER_MARGIN; mControlSize = mPopup.mUserControl.Size; mPopup.mUserControl.Dock = DockStyle.Fill; Controls.Add(mPopup.mUserControl); mWindowSize.Width = mControlSize.Width + 2 * BORDER_MARGIN; mWindowSize.Height = mControlSize.Height + 2 * BORDER_MARGIN; this.Opacity = Convert.ToDouble(popup.mOpacity); //These are here to suppress warnings. this.DropDown += new EventHandler(DoNothing); this.DropDownClosed += new EventHandler(DoNothing); Form parentForm = mPopup.mParent.FindForm(); if (parentForm != null) { parentForm.AddOwnedForm(this); } if (mPopup.mResizable) { mResizingPanel = new Panel(); if (mBackgroundImage == null) { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LISPop)); mBackgroundImage = (System.Drawing.Image)resources.GetObject("CornerPicture.Image"); } mResizingPanel.BackgroundImage = mBackgroundImage; mResizingPanel.Width = 12; mResizingPanel.Height = 12; mResizingPanel.BackColor = Color.Red; mResizingPanel.Left = mPopup.mUserControl.Width - 15; mResizingPanel.Top = mPopup.mUserControl.Height - 15; mResizingPanel.Cursor = Cursors.SizeNWSE; mResizingPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; mResizingPanel.Parent = this; mResizingPanel.BringToFront(); this.mResizingPanel.MouseUp += new MouseEventHandler(mResizingPanel_MouseUp); this.mResizingPanel.MouseDown += new MouseEventHandler(mResizingPanel_MouseDown); this.mResizingPanel.MouseMove += new MouseEventHandler(mResizingPanel_MouseMove); } mPlacement = mPopup.mPlacement; ReLocate(); Rectangle workingArea = Screen.FromControl(mPopup.mParent).WorkingArea; if (mNormalPos.X + this.Width > workingArea.Right) { if ((mPlacement & ePlacement.Right) != 0) { mPlacement = (mPlacement & ~ePlacement.Right) | ePlacement.Left; } } else { if (mNormalPos.X < workingArea.Left) { if ((mPlacement & ePlacement.Left) != 0) { mPlacement = (mPlacement & ~ePlacement.Left) | ePlacement.Right; } } } if (mNormalPos.Y + this.Height > workingArea.Bottom) { if ((mPlacement & ePlacement.Bottom) != 0) { mPlacement = (mPlacement & ~ePlacement.Bottom) | ePlacement.Top; } } else { if (mNormalPos.Y < workingArea.Top) { if ((mPlacement & ePlacement.Top) != 0) { mPlacement = (mPlacement & ~ePlacement.Top) | ePlacement.Bottom; } } } if (mPlacement != mPopup.mPlacement) { ReLocate(); } if (mNormalPos.X + mWindowSize.Width > workingArea.Right) { mNormalPos.X = workingArea.Right - mWindowSize.Width; } else { if (mNormalPos.X < workingArea.Left) { mNormalPos.X = workingArea.Left; } } if (mNormalPos.Y + mWindowSize.Height > workingArea.Bottom) { mNormalPos.Y = workingArea.Bottom - mWindowSize.Height; } else { if (mNormalPos.Y < workingArea.Top) { mNormalPos.Y = workingArea.Top; } } // Initialize the animation mProgress = 0; if (mPopup.mAnimationSpeed > 0) { mTimer = new Timer(); mTimer.Interval = 1000 / 25; mTimerStarted = DateTime.Now; mTimer.Tick += new EventHandler(Showing); mTimer.Start(); Showing(null, null); } else { SetFinalLocation(); } Show(); mPopup.OnDropDown(mPopup.mParent, new EventArgs()); }
public Label(Widget parent, String text, Style style, ePlacement placement) { Vector2 label_size = Init(text, style); InitWidget(parent, style, placement, label_size); }