diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-03-01 10:32:53 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-03-01 10:32:53 +0100 |
| commit | 1e4e5c961fefe29060f1bda640d3e0fc2a0f3e92 (patch) | |
| tree | a640796a2395a54a30c736f25c1c2bacc18ee92d | |
| parent | 19944e8637bdec5a873c8a5c690973d9ff134c6d (diff) | |
label size adjust, modal window, crowIDE wip
| -rw-r--r-- | Default.style | 2 | ||||
| -rw-r--r-- | Templates/MessageBox.template | 13 | ||||
| -rw-r--r-- | Tests/test.style | 44 | ||||
| -rw-r--r-- | Tests/ui/LabelButton.style | 16 | ||||
| -rw-r--r-- | Tests/ui/MenuItem.style | 22 | ||||
| -rw-r--r-- | src/GraphicObjects/Label.cs | 85 | ||||
| -rw-r--r-- | src/GraphicObjects/MessageBox.cs | 83 | ||||
| -rw-r--r-- | src/GraphicObjects/Window.cs | 46 |
8 files changed, 193 insertions, 118 deletions
diff --git a/Default.style b/Default.style index 2e9e72a1..c5e42347 100644 --- a/Default.style +++ b/Default.style @@ -65,7 +65,7 @@ DockWindow { AllowDrag = "true"; } MessageBox { - Background = "0.3,0.3,0.3,0.3"; + Background = "0.1,0.1,0.2,0.7"; Width = "Fit"; Caption="MessageBox"; Font = "serif, 12"; diff --git a/Templates/MessageBox.template b/Templates/MessageBox.template index 129e24ca..e8b58ad1 100644 --- a/Templates/MessageBox.template +++ b/Templates/MessageBox.template @@ -17,15 +17,18 @@ <GraphicObject Width="5" Height="5"/> </HorizontalStack> </Border> - <HorizontalStack Margin="5"> + <HorizontalStack Margin="5" > <Image Name="Image" Width="50" Height="30" Path="{./MsgIcon}" /> - <Label Margin="5" Font="{./Font}" Width="Fit" Text="{./Message}" - TextAlignment="Left" + <Label Margin="5" Font="{./Font}" Width="Fit" Text="{./Message}" + TextAlignment="Center" Multiline="true" /> </HorizontalStack> - <HorizontalStack Margin="1" Spacing="0" Width="Fit" Height="Fit" HorizontalAlignment="Right"> + <HorizontalStack Margin="4" Spacing="0" Width="Fit" Height="Fit" HorizontalAlignment="Right"> <Button Width="Fit" Caption="{./OkMessage}" MouseClick="./onOkButtonClick" /> - <Button Width="Fit" Caption="{./CancelMessage}" MouseClick="./onCancelButtonClick" /> + <Button Width="Fit" Visible="{./NoButIsVisible}" + Caption="{./NoMessage}" MouseClick="./onNoButtonClick" /> + <Button Width="Fit" Visible="{./CancelButIsVisible}" + Caption="{./CancelMessage}" MouseClick="./onCancelButtonClick" /> </HorizontalStack> </VerticalStack> </Border> diff --git a/Tests/test.style b/Tests/test.style index fc327ab1..e9709b2c 100644 --- a/Tests/test.style +++ b/Tests/test.style @@ -1,34 +1,34 @@ FpsLabel { - Width = 50%; - Font = droid, 10; - Margin = 0; - TextAlignment = Center; - Background = Onyx; + Width = "50%"; + Font = "droid, 10"; + Margin = "0"; + TextAlignment = "Center"; + Background = "Onyx"; } FpsDisp { - Font = droid bold, 10; - Width = 50%; - Margin = 0; - TextAlignment = Center; - Background = Teal; + Font = "droid bold, 10"; + Width = "50%"; + Margin = "0"; + TextAlignment = "Center"; + Background = "Teal"; } CheckBox2 { - Template= #Tests.Interfaces.CheckBox2.imlt; - Background = Onyx; - Checked={Background=Mantis;Font=droid bold, 10}; - Unchecked = {Background=Onyx;Font=droid,10}; + Template= "#Tests.Interfaces.CheckBox2.imlt"; + Background = "Onyx"; + Checked="{Background=Mantis;Font=droid bold, 10}"; + Unchecked = "{Background=Onyx;Font=droid,10}"; } RadioButton2 { - Template=#Tests.Interfaces.CheckBox2.imlt; - Background = Onyx; - Checked = {Background=Mantis;Font=droid bold, 10}; - Unchecked = {Background=Onyx;Font=droid,10}; + Template="#Tests.Interfaces.CheckBox2.imlt"; + Background = "Onyx"; + Checked = "{Background=Mantis;Font=droid bold, 10}"; + Unchecked = "{Background=Onyx;Font=droid,10}"; } labPerf { - Font = droid, 8; - Width = 50%; + Font = "droid, 8"; + Width = "50%"; } labPerfVal{ - Font = droid, 8; - Width = 50%; + Font = "droid, 8"; + Width = "50%"; } diff --git a/Tests/ui/LabelButton.style b/Tests/ui/LabelButton.style index 617cfb8e..7182d868 100644 --- a/Tests/ui/LabelButton.style +++ b/Tests/ui/LabelButton.style @@ -1,8 +1,8 @@ -MouseEnter = {Background = Gray;Foreground = White;} -Fit = true; -MouseLeave = {Background=Transparent;Foreground=Gray;} -MouseDown = {Background=Red;Foreground=White;} -MouseUp = {Background=Gray;Foreground=White;} -Foreground=Gray; -Margin=5; -CornerRadius=5; +MouseEnter = "{Background = Gray;Foreground = White;}"; +Fit = "true"; +MouseLeave = "{Background=Transparent;Foreground=Gray;}"; +MouseDown = "{Background=Red;Foreground=White;}"; +MouseUp = "{Background=Gray;Foreground=White;}"; +Foreground="Gray"; +Margin="5"; +CornerRadius="5"; diff --git a/Tests/ui/MenuItem.style b/Tests/ui/MenuItem.style index bce8e730..969a4abc 100644 --- a/Tests/ui/MenuItem.style +++ b/Tests/ui/MenuItem.style @@ -1,11 +1,11 @@ -Height = Fit; -Width = Stretched; -MinimumSize=60;10; -Margin=2; -CornerRadius=0; -TextAlignment=Left; -Foreground=Gray; -MouseEnter = {Background=SeaGreen;Foreground=White;} -MouseLeave = {Background=Transparent;Foreground=Gray;} -MouseDown = {Background=White;Foreground=DimGray;} -MouseUp = {Background=SeaGreen;Foreground=White;} +Height = "Fit"; +Width = "Stretched"; +MinimumSize="60;10"; +Margin="2"; +CornerRadius="0"; +TextAlignment="Left"; +Foreground="Gray"; +MouseEnter = "{Background=SeaGreen;Foreground=White;}"; +MouseLeave = "{Background=Transparent;Foreground=Gray;}"; +MouseDown = "{Background=White;Foreground=DimGray;}"; +MouseUp = "{Background=SeaGreen;Foreground=White;}"; diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index 56508d23..1189b0e0 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -55,6 +55,7 @@ namespace Crow public virtual void OnTextChanged(Object sender, TextChangeEventArgs e) { + textMeasureIsUpToDate = false; NotifyValueChanged ("Text", Text); TextChanged.Raise (this, e); } @@ -437,48 +438,49 @@ namespace Crow CurrentColumn = 0; OnTextChanged (this, new TextChangeEventArgs (Text)); } + bool textMeasureIsUpToDate = false; + Size cachedTextSize = default(Size); #region GraphicObject overrides protected override int measureRawSize(LayoutingType lt) - { + { if (lines == null) lines = getLines; + if (!textMeasureIsUpToDate) { + using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) { + using (Context gr = new Context (img)) { + //Cairo.FontFace cf = gr.GetContextFontFace (); - using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) { - using (Context gr = new Context (img)) { - //Cairo.FontFace cf = gr.GetContextFontFace (); - - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); + gr.FontOptions = Interface.FontRenderingOptions; + gr.Antialias = Interface.Antialias; + fe = gr.FontExtents; + te = new TextExtents (); - fe = gr.FontExtents; - te = new TextExtents(); + cachedTextSize.Height = (int)Math.Ceiling ((fe.Ascent+fe.Descent) * Math.Max (1, lines.Count)) + Margin * 2; - if (lt == LayoutingType.Height){ - int lc = lines.Count; - //ensure minimal height = text line height - if (lc == 0) - lc = 1; - - return (int)Math.Ceiling(fe.Height * lc) + Margin * 2; - } - try { - foreach (string s in lines) { - string l = s.Replace("\t", new String (' ', Interface.TabSize)); + try { + foreach (string s in lines) { + string l = s.Replace ("\t", new String (' ', Interface.TabSize)); - TextExtents tmp = gr.TextExtents (l); + TextExtents tmp = gr.TextExtents (l); - if (tmp.XAdvance > te.XAdvance) - te = tmp; - } - } catch (Exception ex) { - return -1; + if (tmp.XAdvance > te.XAdvance) + te = tmp; + } + cachedTextSize.Width = (int)Math.Ceiling (te.XAdvance) + Margin * 2; + textMeasureIsUpToDate = true; + } catch { + return -1; + } } - return (int)Math.Ceiling (te.XAdvance) + Margin * 2; } + } - } + return lt == LayoutingType.Height ? cachedTextSize.Height : cachedTextSize.Width; + } protected override void onDraw (Context gr) { base.onDraw (gr); @@ -552,11 +554,12 @@ namespace Crow break; case Alignment.Center://ok rText.X = cb.X + cb.Width / 2 - rText.Width / 2; - rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; + //rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; + rText.Y = cb.Y + (int)Math.Floor((double)cb.Height / 2.0 - (double)rText.Height / 2.0); break; } - gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0); + //gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0); fe = gr.FontExtents; #region draw text cursor @@ -586,8 +589,8 @@ namespace Crow Foreground.SetAsSource (gr); gr.LineWidth = 1.0; - gr.MoveTo (0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * fe.Height); - gr.LineTo (0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * fe.Height); + gr.MoveTo (0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * (fe.Ascent+fe.Descent)); + gr.LineTo (0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * (fe.Ascent+fe.Descent)); gr.Stroke(); } #endregion @@ -597,9 +600,9 @@ namespace Crow // new SolidColor(Color.DarkGreen).SetAsSource(gr); // Rectangle R = new Rectangle ( // rText.X + (int)SelEndCursorPos - 3, -// rText.Y + (int)(SelRelease.Y * fe.Height), +// rText.Y + (int)(SelRelease.Y * (fe.Ascent+fe.Descent)), // 6, -// (int)fe.Height); +// (int)(fe.Ascent+fe.Descent)); // gr.Rectangle (R); // gr.Fill (); // } @@ -607,9 +610,9 @@ namespace Crow // new SolidColor(Color.DarkRed).SetAsSource(gr); // Rectangle R = new Rectangle ( // rText.X + (int)SelStartCursorPos - 3, -// rText.Y + (int)(SelBegin.Y * fe.Height), +// rText.Y + (int)(SelBegin.Y * (fe.Ascent+fe.Descent)), // 6, -// (int)fe.Height); +// (int)(fe.Ascent+fe.Descent)); // gr.Rectangle (R); // gr.Fill (); // } @@ -620,9 +623,9 @@ namespace Crow int lineLength = (int)gr.TextExtents (l).XAdvance; Rectangle lineRect = new Rectangle ( rText.X, - rText.Y + (int)Math.Ceiling(i * fe.Height), + rText.Y + (int)Math.Floor((double)i * (fe.Ascent+fe.Descent)), lineLength, - (int)Math.Ceiling(fe.Height)); + (int)Math.Ceiling((fe.Ascent+fe.Descent))); // if (TextAlignment == Alignment.Center || // TextAlignment == Alignment.Top || @@ -636,7 +639,7 @@ namespace Crow continue; Foreground.SetAsSource (gr); - gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i); + gr.MoveTo (lineRect.X,(double)rText.Y + fe.Ascent + (fe.Ascent+fe.Descent) * i) ; gr.ShowText (l); gr.Fill (); @@ -666,7 +669,7 @@ namespace Crow gr.Save (); gr.Clip (); gr.SetSourceColor (SelectionForeground); - gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i); + gr.MoveTo (lineRect.X, (double)rText.Y + fe.Ascent + (fe.Ascent+fe.Descent) * i); gr.ShowText (l); gr.Fill (); gr.Restore (); @@ -774,7 +777,7 @@ namespace Crow double cPos = 0f; - CurrentLine = (int)(mouseLocalPos.Y / fe.Height); + CurrentLine = (int)(mouseLocalPos.Y / (fe.Ascent+fe.Descent)); //fix cu if (CurrentLine >= lines.Count) diff --git a/src/GraphicObjects/MessageBox.cs b/src/GraphicObjects/MessageBox.cs index e59e0e63..45ef1e00 100644 --- a/src/GraphicObjects/MessageBox.cs +++ b/src/GraphicObjects/MessageBox.cs @@ -38,10 +38,13 @@ namespace Crow #endregion public enum Type { + None, Information, - YesNo, Alert, - Error + Error, + YesNo, + YesNoCancel, + } protected override void loadTemplate (GraphicObject template) @@ -49,13 +52,14 @@ namespace Crow base.loadTemplate (template); NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.Informations.svg"); } - string message, okMessage, cancelMessage; - Type msgType = Type.Information; + string message, okMessage, cancelMessage, noMessage; + Type msgType = Type.None; - public event EventHandler Ok; + public event EventHandler Yes; + public event EventHandler No; public event EventHandler Cancel; - [XmlAttributeAttribute][DefaultValue("Informations")] + [DefaultValue("Informations")] public virtual string Message { get { return message; } @@ -66,7 +70,7 @@ namespace Crow NotifyValueChanged ("Message", message); } } - [XmlAttributeAttribute][DefaultValue("Ok")] + [DefaultValue("Ok")] public virtual string OkMessage { get { return okMessage; } @@ -77,7 +81,7 @@ namespace Crow NotifyValueChanged ("OkMessage", okMessage); } } - [XmlAttributeAttribute][DefaultValue("Cancel")] + [DefaultValue("Cancel")] public virtual string CancelMessage { get { return cancelMessage; } @@ -88,7 +92,18 @@ namespace Crow NotifyValueChanged ("CancelMessage", cancelMessage); } } - [XmlAttributeAttribute][DefaultValue("Information")] + [DefaultValue("No")] + public virtual string NoMessage + { + get { return cancelMessage; } + set { + if (cancelMessage == value) + return; + cancelMessage = value; + NotifyValueChanged ("NoMessage", cancelMessage); + } + } + [DefaultValue("Information")] public virtual Type MsgType { get { return msgType; } @@ -99,34 +114,58 @@ namespace Crow NotifyValueChanged ("MsgType", msgType); switch (msgType) { case Type.Information: - NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.Informations.svg"); + MsgIcon = "#Crow.Images.Icons.Informations.svg"; Caption = "Informations"; OkMessage = "Ok"; - CancelMessage = "Cancel"; + NotifyValueChanged ("CancelButIsVisible", false); + NotifyValueChanged ("NoButIsVisible", false); break; case Type.YesNo: - NotifyValueChanged ("MsgIcon", "#Crow.Icons.question.svg"); + case Type.YesNoCancel: + MsgIcon = "#Crow.Icons.question.svg"; Caption = "Choice"; OkMessage = "Yes"; - CancelMessage = "No"; + NoMessage = "No"; + NotifyValueChanged ("CancelButIsVisible", msgType == Type.YesNoCancel); + NotifyValueChanged ("NoButIsVisible", true); break; case Type.Alert: - NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.IconAlerte.svg"); + MsgIcon = "#Crow.Images.Icons.IconAlerte.svg"; Caption = "Alert"; OkMessage = "Ok"; CancelMessage = "Cancel"; + NotifyValueChanged ("CancelButIsVisible", true); + NotifyValueChanged ("NoButIsVisible", false); break; case Type.Error: - NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.exit.svg"); + MsgIcon = "#Crow.Images.Icons.exit.svg"; Caption = "Error"; OkMessage = "Ok"; + NotifyValueChanged ("CancelButIsVisible", false); + NotifyValueChanged ("NoButIsVisible", false); break; } } } + + string msgIcon = null; + public string MsgIcon { + get { return msgIcon; } + set { + if (value == MsgIcon) + return; + msgIcon = value; + NotifyValueChanged ("MsgIcon", MsgIcon); + } + } void onOkButtonClick (object sender, EventArgs e) { - Ok.Raise (this, null); + Yes.Raise (this, null); + close (); + } + void onNoButtonClick (object sender, EventArgs e) + { + No.Raise (this, null); close (); } void onCancelButtonClick (object sender, EventArgs e) @@ -147,6 +186,18 @@ namespace Crow return mb; } } + public static MessageBox ShowModal (Interface iface, Type msgBoxType, string message){ + lock (iface.UpdateMutex) { + MessageBox mb = new MessageBox (iface) { + Modal = true, + MsgType = msgBoxType, + Message = message + }; + + iface.AddWidget (mb); + return mb; + } + } } } diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index cff96a75..4eef9696 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -47,8 +47,9 @@ namespace Crow } string _icon; - bool _resizable; - bool _movable; + bool resizable; + bool movable; + bool modal; protected bool hoverBorder = false; bool alwaysOnTop = false; Fill titleBarBackground = Color.UnitedNationsBlue; @@ -124,25 +125,37 @@ namespace Crow [XmlAttributeAttribute][DefaultValue(true)] public bool Resizable { get { - return _resizable; + return resizable; } set { - if (_resizable == value) + if (resizable == value) return; - _resizable = value; - NotifyValueChanged ("Resizable", _resizable); + resizable = value; + NotifyValueChanged ("Resizable", resizable); } } [XmlAttributeAttribute][DefaultValue(true)] public bool Movable { get { - return _movable; + return movable; } set { - if (_movable == value) + if (movable == value) return; - _movable = value; - NotifyValueChanged ("Movable", _movable); + movable = value; + NotifyValueChanged ("Movable", movable); + } + } + [XmlAttributeAttribute][DefaultValue(false)] + public bool Modal { + get { + return modal; + } + set { + if (modal == value) + return; + modal = value; + NotifyValueChanged ("Modal", modal); } } [XmlAttributeAttribute][DefaultValue(false)] @@ -167,17 +180,18 @@ namespace Crow [XmlAttributeAttribute][DefaultValue(false)] public bool AlwaysOnTop { get { - return alwaysOnTop; + return modal ? true : alwaysOnTop; } set { if (alwaysOnTop == value) return; + alwaysOnTop = value; - if (alwaysOnTop && Parent != null) + if (AlwaysOnTop && Parent != null) IFace.PutOnTop (this); - NotifyValueChanged ("AlwaysOnTop", alwaysOnTop); + NotifyValueChanged ("AlwaysOnTop", AlwaysOnTop); } } // [XmlAttributeAttribute()][DefaultValue(WindowState.Normal)] @@ -286,7 +300,7 @@ namespace Crow return; } - if (this.HasFocus && _movable) { + if (this.HasFocus && movable) { if (e.Mouse.IsButtonDown (MouseButton.Left)) { MoveAndResize (e.XDelta, e.YDelta, currentDirection); return; @@ -353,6 +367,10 @@ namespace Crow { base.onMouseDown (sender, e); } + public override bool MouseIsIn (Point m) + { + return modal ? true : base.MouseIsIn (m); + } #endregion protected void onMaximized (object sender, EventArgs e){ |