public static bool Display(ButtonStyle style, ButtonShape button, Transaction transaction) { // note that the parameter is changed if the user selects a different style using (frmButton frm = new frmButton(style, button, transaction)) { DialogResult result = frm.ShowDialog(); frm.Dispose(); // Must be disposed immediately because the style panel registers itself with Globals if (result == DialogResult.OK) { if (style != frm.m_Style) // checks if a different style was selected { if (!style.IsShared) { transaction.Delete(style); // the old one can be deleted as it is not used anywhere else } } //style = frm.m_Style if (frm.m_Style.IsShared) { // check if the style was edited; if so the whole document must be refreshed ButtonStyle previous = (ButtonStyle)transaction.GetObjectPrevious(frm.m_Style); if (previous != null) { if (!frm.m_Style.ContentEquals(previous)) { transaction.RequiresDocumentRepaint = true; } // else we can ignore it - if Previous is nothing then this style has been newly created and cannot apply to any other buttons } } return(true); } return(false); } }
private void UpdateShapeHover(PointF pt) { if (!UseActiveContent || m_Page == null) { return; } Shape shapeHit = m_Page.HitTest(pt, m_Zoom, Page.HitTestMode.ActiveContent); if (!(shapeHit is ButtonShape)) { shapeHit = null; } if (shapeHit != m_ShapeHover) { ClearShapeHover(); if (m_ShapePressed != null && m_ShapePressed != shapeHit) { return; // if a button is pressed, we don't show any hover feedback over other buttons } m_ShapeHover = (ButtonShape)shapeHit; if (m_ShapeHover != null && m_ShapeHover.State == ButtonShape.States.Normal) { m_ShapeHover.State = m_ShapePressed == shapeHit ? ButtonShape.States.Selected : ButtonShape.States.Highlight; } HoverShapeChanged?.Invoke(m_ShapeHover); } }
private void StaticView_MouseUp(object sender, MouseEventArgs e) { if (m_ShapePressed != null) { ButtonShape pressed = m_ShapePressed; m_ShapePressed = null; ClearShapeHover(); ShapePressed(pressed); } }
/// <summary> /// Override this method to apply the custom style for pager button /// </summary> /// <param name="shape">Shape of the numeric button</param> /// <returns>Color as given</returns> public override Color GetPagerButtonBorderColor(ButtonShape shape = ButtonShape.Rectangle) { if (shape == ButtonShape.Rectangle) { return(Color.Transparent); } else { return(Color.FromHex("#CACACA")); } }
public void ctrActionColour_UserChangedColour(object sender, EventArgs e) { m_Filling = true; m_Action = new ParameterAction(m_Action.Change, ctrActionColour.CurrentColour.ToArgb()); ctrActions.SelectedAction = Action.Empty; string temp; ButtonShape.GetDisplayFromAction(m_Action, out temp, out m_NewImage, m_Transaction); txtText.Text = temp; ImageChanged(); m_Filling = false; }
/// <summary>called on mouse exit</summary> private void ClearShapeHover() { if (m_ShapeHover != null) // clear old selection { if (m_ShapeHover.State == ButtonShape.States.Highlight || m_ShapeHover.State == ButtonShape.States.Selected && m_ShapeHover.SelectDuringUserPress) { // Only deselect if it was responding to the presence of the mouse m_ShapeHover.State = ButtonShape.States.Normal; } m_ShapeHover = null; HoverShapeChanged?.Invoke(m_ShapeHover); } }
public void ctrActions_AfterSelect(object sender, EventArgs e) { if (m_Filling) { return; } m_Filling = true; try { Action action = ctrActions.SelectedAction; m_Action = action; if (action.Change == Parameters.Action_Key) { // For simulated keys we don't update the text on selecting the action; we will update is the user actually types a key // However is there is already text, and there is no key selected yet, then we will fill it in based on the text if (txtText.Text.Length > 0 && (action as KeyAction).Key == Keys.None) { SetKeyFromText(); // The display in the box will be updated by ReflectAction } } else if (action.Change == Parameters.Action_Character) { if (txtText.Text.Length > 0 && (action as CharAction).Character == '\0') { SetKeyFromText(); } } else if (action.Change == Parameters.Action_Text) { if (txtText.Text.Length > 0 && string.IsNullOrEmpty((action as TextAction).Text)) { SetKeyFromText(); } } else if (chkDisplayFromAction.Checked && action.Change != Parameters.None) { string temp; ButtonShape.GetDisplayFromAction(m_Action, out temp, out m_NewImage, m_Transaction); txtText.Text = temp; ImageChanged(); } } finally { m_Filling = false; } ReflectAction(); }
private GraphicShape ButtonShapeToGraphic(ButtonShape shape) { switch (shape) { case ButtonShape.Back: return(GraphicShape.Back); case ButtonShape.Rounded: return(GraphicShape.Rounded); case ButtonShape.Rectangle: return(GraphicShape.Rectangle); case ButtonShape.Next: return(GraphicShape.Next); case ButtonShape.Flat: return(GraphicShape.Rounded); case ButtonShape.Ellipse: return(GraphicShape.Ellipse); default: return(GraphicShape.Rounded); } }
public ButtonUI(ButtonUI buttonUI) { StrokeShade = buttonUI.StrokeShade; FillShade = buttonUI.FillShade; StrokeColor = buttonUI.StrokeColor; FillColor = buttonUI.FillColor; IsTextStroked = buttonUI.IsTextStroked; IsSquared = buttonUI.IsSquared; Typeface = buttonUI.Typeface; Gravity = buttonUI.Gravity; Shape = buttonUI.Shape; Padding = buttonUI.Padding; TextSizeRatio = buttonUI.TextSizeRatio; StrokeBorderWidthRatio = buttonUI.StrokeBorderWidthRatio; StrokeTextWidthRatio = buttonUI.StrokeTextWidthRatio; StrokeBorderWidth = buttonUI.StrokeBorderWidth; StrokeTextWidth = buttonUI.StrokeTextWidth; _textSize = buttonUI._textSize; _radiusIn = buttonUI._radiusIn; _radiusOut = buttonUI._radiusOut; }
private ButtonShape m_LayoutButton; // dummy used to draw panels private void PrepareLayout() { pnlLayout.Height = pnlLayout.Width / 5; int panelSize = pnlLayout.Height - pnlLayout.Padding.Vertical; for (int index = 0; index <= 4; index++) { Panel pnl = new Panel() { Tag = index, Margin = new Padding(0), Size = new Size(panelSize, panelSize) }; pnl.Paint += DrawLayoutPanel; pnlLayout.Controls.Add(pnl); } m_LayoutButton = new ButtonShape(); m_LayoutButton.InitialiseFreeStanding(); m_LayoutButton.StyleObjectForParameter(Parameters.FillColour).SetParameterValue(0, Parameters.FillColour); // empty m_LayoutButton.GetTextStyle().SetParameterValue(m_Button.GetTextStyle().ParameterValue(Parameters.FontSize), Parameters.FontSize); float size = (float)Math.Sqrt(m_Button.Bounds.Height * m_Button.Bounds.Width); m_LayoutButton.SetPosition(new RectangleF(0, 0, size, size)); // gives button natural looking size, but needs to be square RefreshPanels(); // sets some of the other data }
protected override void ShapePressed(Shape shape) { if (!(shape is ButtonShape)) { return; } ButtonShape buttonShape = (ButtonShape)shape; if (buttonShape.State == ButtonShape.States.Disabled) { return; } Accessed?.Invoke(this, EventArgs.Empty); switch (buttonShape.Action.Change) { case Parameters.Action_Key: case Parameters.Action_Text: case Parameters.Action_Character: // any typing button needs to put focus back first Globals.Root.PerformAction(Verb.Find(Codes.RestoreFocus)); break; } Globals.Root.PerformAction(buttonShape.Action, EditableView.ClickPosition.Sources.Pad); }
private GraphicShape ButtonShapeToGraphic(ButtonShape shape) { switch (shape) { case ButtonShape.Back: return GraphicShape.Back; case ButtonShape.Rounded: return GraphicShape.Rounded; case ButtonShape.Rectangle: return GraphicShape.Rectangle; case ButtonShape.Next: return GraphicShape.Next; case ButtonShape.Flat: return GraphicShape.Rounded; case ButtonShape.Ellipse: return GraphicShape.Ellipse; default: return GraphicShape.Rounded; } }
private Action m_Action; // cannot directly update m_Button because the View (on the original document) can have trouble rendering if the action is updated but not the image public frmButton(ButtonStyle style, ButtonShape button, Transaction transaction) { m_Filling = true; InitializeComponent(); Strings.Translate(this); // must not be in Load, as the data occasionally has translatable items Strings.Translate(mnuImage); m_Button = button; m_Style = style; // must be before any parameters are attached m_OriginalStyle = style; m_Transaction = transaction; m_Action = button.Action; FillStylesList(); ReflectCustomState(); ctrStyle.DisplayStyle(m_Style); // content txtText.Text = button.LabelText; pnlImagePreview.Image = button.GetImageForPreview(); if (button.TextRatio < 0) { sldTextRatio.Value = 50; rdoTextRatioDefault.Checked = true; } else { sldTextRatio.Value = (int)(button.TextRatio * 100); rdoTextRatioSet.Checked = true; } pnlImagePreview.NoImageString = Strings.Item("Button_NoImage"); PrepareLayout(); pnlLayout.SelectedIndex = Math.Min((int)m_Button.Layout & ((int)ButtonShape.Layouts.Superimpose - 1), pnlLayout.Controls.Count - 1); chkSuperimpose.Checked = (m_Button.Layout & ButtonShape.Layouts.Superimpose) > 0; ShowRatioAndLayout(); // We need the configuration which will (probably) be in effect when the palette is used. We assume user mode // as this is mainly to detect custom shapes. Any available in user mode will also be available in teacher mode Document document = Globals.Root.CurrentDocument; // document being edited; PROBABLY a palette, although buttons can be placed on pages ?? if (document.PaletteWithin != null) { document = document.PaletteWithin.Document; } AppliedConfig applied = new AppliedConfig(); applied.AddConfigAtEnd(document.UserSettings); // Doesn't matter if any of the items passed to AddConfigAtEnd are nothing applied.AddConfigAtEnd(document.BothSettings); // Add the activity, if there is one specified in the document... if (!document.ActivityID.Equals(Guid.Empty)) { Document activity = Activities.GetActivitySettings(document.ActivityID); if (activity != null) { applied.AddConfigAtEnd(activity.UserSettings); applied.AddConfigAtEnd(activity.BothSettings); } } applied.AddConfigAtEnd(Config.UserCurrent); // User mode is assumed. Any custom shapes only present in teacher mode will be ignored // (Note that the actions list isn't really interested in what is visible; only what is defined) applied.AddConfigAtEnd(Config.SystemConfig); ctrActions.Fill(applied); // Actions data chkDisplayFromAction.Checked = button.DisplayFromAction; ctrActions.SelectedAction = m_Action; if (button.Action.Change == Parameters.Action_Key) { chkActionKeyAuto.Checked = !string.IsNullOrEmpty(button.LabelText) && button.LabelText[0].ToKeyData() == (button.Action as KeyAction).Key; } else if (button.Action.Change == Parameters.Action_Character) { chkActionKeyAuto.Checked = true; // I think the only way of achieving this is using the checkbox } else if (button.Action.Change == Parameters.Action_Text) { chkActionKeyAuto.Checked = button.LabelText == (button.Action as TextAction).Text; } ReflectAction(); m_Filling = false; }
public void btnAdd_Click(object sender, EventArgs e) { Transaction transaction = new Transaction(); List <ButtonShape> buttons = m_Page.OfType <ButtonShape>().ToList(); PointF pt; SizeF sz; // Button is positioned to the bottom right of the existing ones; position will actually be ignored if there is a flow buttons.Sort((X, Y) => { // Sorts into an effectively reading order, but backwards. First entry will be bottom right float result = -(X.Bounds.Bottom - Y.Bounds.Bottom); if (Math.Abs(result) < Geometry.NEGLIGIBLE) { result = -(X.Bounds.Right - Y.Bounds.Right); } return(Math.Sign(result)); }); if (buttons.Any()) { sz = new SizeF(buttons.Average(x => x.Bounds.Width), buttons.Average(x => x.Bounds.Height)); pt = buttons.First().Bounds.TopRight() + new SizeF(1, 0); if (pt.X + sz.Width > m_Page.Bounds.Width) // Has gone off the end of the line, start a new line { pt = new PointF(0, pt.Y + sz.Height + 1); } if (pt.Y + sz.Height * 0.6 > m_Page.Size.Height) // off the bottom - Just resets to the top left in this case { pt = new PointF(0, -m_Page.Size.Height); } } else { sz = new SizeF(9, 9); pt = new PointF(0, -m_Page.Size.Height); } ButtonShape create = new ButtonShape(); transaction.Create(create); EditableView.ClickPosition dummyPosition = new EditableView.ClickPosition(pt, m_Page, 1, Shape.SnapModes.Off, Shape.SnapModes.Off, null, EditableView.ClickPosition.Sources.Irrelevant); create.Start(dummyPosition); create.SetStyleObject(frmButton.GetStyleForNewButton(m_Page)); dummyPosition.Exact = dummyPosition.Exact + sz; dummyPosition.Snapped = dummyPosition.Exact; create.Complete(dummyPosition); create.Action = ctrActions.SelectedAction; switch (create.Action.Change) { case Parameters.Action_Character: create.Action = new CharAction(m_Key.ToString()); break; case Parameters.Action_Key: create.Action = new KeyAction(m_eKey); break; case Parameters.Action_Text: if (string.IsNullOrEmpty((create.Action as TextAction)?.Text)) // might already be specified by list { create.Action = new TextAction(txtText.Text); } break; } SharedImage image; string temp; ButtonShape.GetDisplayFromAction(create.Action, out temp, out image, transaction); create.LabelText = temp; if (image != null) { create.SetImage(image); } if (m_Page.IsSingleAutoSize) { IShapeContainer container = (IShapeContainer)m_Page.Shapes.First(); transaction.Edit((Datum)container); container.Contents.Add(create); create.Parent = (IShapeParent)container; container.FinishedModifyingContents(transaction, null); if (create.Bounds.Bottom > m_Page.Bounds.Bottom) // Is off the bottom { transaction.Edit(m_Page); m_Page.SetSizeExcludingMargin(new SizeF(m_Page.Size.Width, pt.Y + sz.Height - m_Page.Bounds.Top)); ((IAutoSize)container).SetBounds(m_Page.Bounds, null); Globals.OnCurrentPageSizeChanged(); } } else { m_Page.AddNew(create, transaction); if (pt.Y > m_Page.Bounds.Bottom - 1) // Is off the bottom { transaction.Edit(m_Page); float height = pt.Y + sz.Height + m_Page.Margin * 2 - m_Page.Bounds.Top; TransformMove delta = new TransformMove(0, -(height - m_Page.PhysicalSize.Height)); // All existing shapes will need to be moved up by this much because the top coordinate of the page will change m_Page.SetSize(new SizeF(m_Page.PhysicalSize.Width, height), m_Page.Margin); foreach (Shape shp in m_Page) { transaction.Edit(shp); shp.ApplyTransformation(delta); } Globals.OnCurrentPageSizeChanged(); } } Globals.Root.StoreNewTransaction(transaction, true); }