]> O.S.I.I.S - jp/crow.git/commitdiff
label size adjust, modal window, crowIDE wip
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 1 Mar 2018 09:32:53 +0000 (10:32 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 1 Mar 2018 09:32:53 +0000 (10:32 +0100)
Default.style
Templates/MessageBox.template
Tests/test.style
Tests/ui/LabelButton.style
Tests/ui/MenuItem.style
src/GraphicObjects/Label.cs
src/GraphicObjects/MessageBox.cs
src/GraphicObjects/Window.cs

index 2e9e72a1af06333fbc6ea7f118e12e4f9dfc1ec8..c5e42347c95ddb33da07867a8aac3bdf2912bb2f 100644 (file)
@@ -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";
index 129e24ca244efcaec17af5d3aad5c63c972a8079..e8b58ad147c47c87fd5559478f1b437d8661fec9 100644 (file)
                                <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>
index fc327ab142284da222906b97fb0a98290af5f132..e9709b2c28bcdba5235c4fd86474a962b372880f 100644 (file)
@@ -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%";
 }
index 617cfb8e877f9d2d77d5cc1e221bcb83f752e0ed..7182d8682b0a1bb49e69774e386a2ced2600c22d 100644 (file)
@@ -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";
index bce8e730104778121cf21e906a077d5f5011bd3f..969a4abc27d5b830c836acf09ee804f69c802fd0 100644 (file)
@@ -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;}";
index 56508d2308c9ec87f21dbd6d0bf11b2dd844920d..1189b0e0642fef8b65f66a212ea058d4fbf32dd5 100644 (file)
@@ -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;
-
-                       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);
-
-
-                                       fe = gr.FontExtents;
-                                       te = new TextExtents();
-
-                                       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;
+                       if (!textMeasureIsUpToDate) {
+                               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.FontOptions = Interface.FontRenderingOptions;
+                                               gr.Antialias = Interface.Antialias;
+
+                                               fe = gr.FontExtents;
+                                               te = new TextExtents ();
+
+                                               cachedTextSize.Height = (int)Math.Ceiling ((fe.Ascent+fe.Descent) * Math.Max (1, lines.Count)) + Margin * 2;
+
+                                               try {
+                                                       foreach (string s in lines) {
+                                                               string l = s.Replace ("\t", new String (' ', Interface.TabSize));
+
+                                                               TextExtents tmp = gr.TextExtents (l);
+
+                                                               if (tmp.XAdvance > te.XAdvance)
+                                                                       te = tmp;
+                                                       }
+                                                       cachedTextSize.Width = (int)Math.Ceiling (te.XAdvance) + Margin * 2;
+                                                       textMeasureIsUpToDate = true;
+                                               } catch {                                                       
+                                                       return -1;
+                                               }                                       
                                        }
-                                       try {
-                                               foreach (string s in lines) {
-                                                       string l = s.Replace("\t", new String (' ', Interface.TabSize));
-
-                                                       TextExtents tmp = gr.TextExtents (l);
-
-                                                       if (tmp.XAdvance > te.XAdvance)
-                                                               te = tmp;
-                                               }
-                                       } catch (Exception ex) {
-                                               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)
index e59e0e63d77b5b9e3f83e446a1b79bde6a36bff3..45ef1e009ce3bf85824663018e2471d6d1db07ca 100644 (file)
@@ -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;
+                       }
+               }
        }
 }
 
index cff96a7574d946a2b0cfd87168fc21c86533c4d9..4eef9696fbc3eeb3ce24fa5281804b2f8fc64f6b 100644 (file)
@@ -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){