]> O.S.I.I.S - jp/crow.git/commitdiff
imledit overlay icon
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 14 Mar 2018 18:20:08 +0000 (19:20 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 14 Mar 2018 18:20:08 +0000 (19:20 +0100)
CrowIDE/CrowIDE.csproj
CrowIDE/src/CrowIDE.cs
CrowIDE/src/Editors/ImlVisualEditor.cs
CrowIDE/src/Editors/SourceEditor.cs
CrowIDE/ui/editors/IMLEdit.itemp
src/ExtensionsMethods.cs
src/Rectangle.cs

index a92b4d9b2f761d544f23724bef5605e5fe186c5c..51f6debed3322b9dd33b9bb23ee4365aa41b2f9e 100644 (file)
     <EmbeddedResource Include="icons\redo.svg" />
     <EmbeddedResource Include="icons\folder.svg" />
     <EmbeddedResource Include="icons\file.svg" />
+    <EmbeddedResource Include="icons\palette.svg" />
     <EmbeddedResource Include="ui\ContextMenu.template">
       <LogicalName>Crow.ContextMenu.template</LogicalName>
     </EmbeddedResource>
index 783db5d162edc31b536276193ef3fdb6f93bfde5..94bec4a435462e51be90b898c5dd5c18239dd5f6 100644 (file)
@@ -249,9 +249,10 @@ namespace Crow.Coding
 
                void CrowIDE_KeyDown (object sender, OpenTK.Input.KeyboardKeyEventArgs e)
                {
-                       if (e.Key == OpenTK.Input.Key.Escape) {
-                               Quit (null, null);
-                       } else if (e.Key == OpenTK.Input.Key.F5) {
+//                     if (e.Key == OpenTK.Input.Key.Escape) {
+//                             Quit (null, null);
+//                     } else
+                       if (e.Key == OpenTK.Input.Key.F5) {
                                try {
                                        CurrentSolution.StartupProject.Compile ();      
                                } catch (Exception ex) {
index 94f71716f608f12cc9c586c9144678d442a237b9..59a8043030932db876a1fd021d6a26653d530602 100644 (file)
@@ -43,6 +43,11 @@ namespace Crow.Coding
                }
                #endregion
 
+               protected override void onInitialized (object sender, EventArgs e)
+               {
+                       initIcons ();
+                       base.onInitialized (sender, e);
+               }
                DesignInterface imlVE;
                GraphicObject selectedItem;
                ImlProjectItem imlProjFile;
@@ -53,6 +58,8 @@ namespace Crow.Coding
                Measure designWidth, designHeight;
                bool updateEnabled;
 
+               SvgPicture icoMove, icoStyle;
+
                public List<Crow.Command> Commands;
                Crow.Command cmdDelete;
 
@@ -62,6 +69,13 @@ namespace Crow.Coding
                        Commands = new List<Crow.Command> (new Crow.Command[] { cmdDelete });
                }
 
+               void initIcons () {
+                       icoMove = new SvgPicture ();
+                       icoMove.Load (IFace, "#Crow.Coding.icons.move-arrows.svg");
+                       icoStyle = new SvgPicture ();
+                       icoStyle.Load (IFace, "#Crow.Coding.icons.palette.svg");
+               }
+
                [DefaultValue(true)]
                public bool DrawGrid {
                        get { return drawGrid; }
@@ -361,6 +375,8 @@ namespace Crow.Coding
                        }
 
                }
+               Rectangle rIcons = default(Rectangle);
+               Size iconSize = new Size(10,10);
 
                protected override void onDraw (Cairo.Context gr)
                {
@@ -409,27 +425,72 @@ namespace Crow.Coding
                        }
 
                        Rectangle hr;
-                       if (HoverWidget != null) {
-                               hr = HoverWidget.ScreenCoordinates (HoverWidget.getSlot ());
-                               gr.SetSourceColor (Color.White);
-                               //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0);
-                               gr.Rectangle (hr, 0.4 / z);
-                       }
 
                        if (SelectedItem?.Parent != null) {
+
+                               gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+                               gr.SetFontSize (Font.Size);
+                               gr.FontOptions = Interface.FontRenderingOptions;
+                               gr.Antialias = Interface.Antialias;
+
                                GraphicObject g = SelectedItem;
                                hr = g.ScreenCoordinates (g.getSlot ());
 
+//                             Rectangle rIcons = new Rectangle (iconSize);
+//                             rIcons.Width *= 4; 
+//                             rIcons.Top = hr.Bottom;
+//                             rIcons.Left = hr.Right - rIcons.Width + iconSize.Width;
+                               Rectangle rIcoMove = new Rectangle (hr.BottomRight, iconSize);
+//                             Rectangle rIcoStyle = rIcoMove;
+//                             rIcoStyle.Left += iconSize.Width + 4;
+
+                               using (Surface mask = new ImageSurface (Format.Argb32, cb.Width, cb.Height)) {
+                                       using (Context ctx = new Context (mask)) {
+                                               ctx.Save();
+                                               ctx.SetSourceRGBA(1.0,1.0,1.0,0.4);
+                                               ctx.Paint ();
+                                               ctx.Rectangle (hr);
+                                               ctx.Operator = Operator.Clear;
+                                               ctx.Fill ();
+                                       }
+
+                                       gr.SetSourceSurface (mask, 0, 0);
+                                       gr.Paint ();
+
+                                       using (Surface ol = new ImageSurface (Format.Argb32, cb.Width, cb.Height)) {
+                                               using (Context ctx = new Context (ol)) {
+                                                       ctx.SetSourceColor (Color.Black);
+                                                       drawDesignOverlay (ctx, g, cb, hr, 0.4 / z, 4.5);
+                                               }
+                                                       
+                                               gr.SetSourceSurface (ol, 0, 0);
+                                               gr.Paint ();
+                                       }
 
-                               //gr.SetDash (new double[]{ 2.0, 2.0 }, 0.0);
-                               gr.SetSourceColor (Color.Black);
-                               //gr.Operator = Operator.Add;
-                               drawDesignOverlay (gr, g, cb, hr, 1.0 / z, 4.0);
-                               gr.SetSourceColor (Color.White);
-                               drawDesignOverlay (gr, g, cb, hr, 1.0 / z, 4.5);
+                                       drawIcon (gr, icoMove, rIcoMove);
+                                       //drawIcon (gr, icoStyle, rIcoStyle);
+
+                               }                                               
+                       }
+                       if (HoverWidget != null) {
+                               hr = HoverWidget.ScreenCoordinates (HoverWidget.getSlot ());
+                               gr.SetSourceColor (Color.SkyBlue);
+                               //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0);
+                               gr.Rectangle (hr, 0.4 / z);
                        }
                        gr.Restore ();
                }
+
+               void drawIcon (Context gr, SvgPicture pic, Rectangle r) {
+//                     gr.SetSourceColor (Color.Black);
+//                     CairoHelpers.CairoRectangle (gr, r.Inflated (1), 2, 1.0);
+                       gr.SetSourceColor (Color.White);
+                       CairoHelpers.CairoRectangle (gr, r.Inflated (1), 2);
+                       gr.Fill ();
+                       gr.Operator = Operator.Clear;
+                       pic.Paint (gr, r);
+                       gr.Operator = Operator.Over;
+               }
                void drawDesignOverlay (Context gr, GraphicObject g, Rectangle cb, Rectangle hr, double coteStroke, double space = 4.5){
                        double z = zoom / 100.0;
                        double coteW = 3, coteL = 5;
@@ -446,10 +507,14 @@ namespace Crow.Coding
 
                        if (g.Width.IsFit)
                                gr.DrawCoteInverse (p1, p2, coteStroke, fill, coteW, coteL);
-                       else if (g.Width.IsRelativeToParent)
+                       else if (g.Width.IsRelativeToParent) {
                                gr.DrawCote (p1, p2, coteStroke, fill, coteW, coteL);
-                       else if (g.Width.IsFixed)
-                               gr.DrawCoteFixed(p1, p2, coteStroke * 2.0, coteW);
+                               if (g.Width.Value < 100)
+                                       drawCenteredTextLine (gr, p1.Add(p2.Substract(p1).Divide (2)), g.Width.ToString());
+                       }else if (g.Width.IsFixed) {
+                               gr.DrawCoteFixed (p1, p2, coteStroke * 2.0, coteW);
+                               drawCenteredTextLine (gr, p1.Add(p2.Substract(p1).Divide (2)), g.Width.Value.ToString());
+                       }
 
                        p1 = new Cairo.PointD (hr.X - space, hr.Top + 0.5);
                        p2 = new Cairo.PointD (hr.X - space, hr.Bottom - 0.5);
@@ -462,10 +527,14 @@ namespace Crow.Coding
                        } 
                        if (g.Height.IsFit)
                                gr.DrawCoteInverse (p1, p2, coteStroke, fill, coteW, coteL);
-                       else if (g.Height.IsRelativeToParent)
+                       else if (g.Height.IsRelativeToParent){
                                gr.DrawCote (p1, p2, coteStroke, fill, coteW, coteL);
-                       else if (g.Width.IsFixed)
-                               gr.DrawCoteFixed(p1, p2, coteStroke * 2.0, coteW);
+                               if (g.Height.Value < 100)
+                                       drawCenteredTextLine (gr, p1.Add(p2.Substract(p1).Divide (2)), g.Height.ToString());
+                       }else if (g.Width.IsFixed) {
+                               gr.DrawCoteFixed (p1, p2, coteStroke * 2.0, coteW);
+                               drawCenteredTextLine (gr, p1.Add(p2.Substract(p1).Divide (2)), g.Height.Value.ToString());
+                       }
 
                        //                              hr.Inflate (2);
                        //gr.SetDash (new double[]{ 1.0, 4.0 }, 0.0);
@@ -474,6 +543,27 @@ namespace Crow.Coding
 //                     gr.Stroke ();
                        gr.Operator = Operator.Over;                    
                }
+
+               void drawCenteredTextLine (Context gr, PointD center, string txt){
+                       FontExtents fe = gr.FontExtents;
+                       TextExtents te = gr.TextExtents (txt);
+
+                       Rectangle rText = new Rectangle(
+                               (int)(center.X - te.Width / 2), (int)(center.Y - (fe.Ascent + fe.Descent) / 2),
+                               (int)te.Width, (int)(fe.Ascent + fe.Descent));
+
+                       gr.Operator = Operator.Clear;
+                       Rectangle r = rText;
+                       r.Inflate (2);
+                       gr.Rectangle (r);
+                       gr.Fill ();
+                       gr.Operator = Operator.Over;
+
+                       gr.MoveTo (rText.X, rText.Y + fe.Ascent);
+                       gr.ShowText (txt);
+                       gr.Fill ();
+
+               }
                protected override void onDragEnter (object sender, DragDropEventArgs e)
                {
                        base.onDragEnter (sender, e);
@@ -859,6 +949,9 @@ namespace Crow.Coding
                                        return;
                                deleteObject (selectedItem);
                                break;
+                       case Key.Escape:
+                               SelectedItem = null;
+                               break;
                        }
                }
        }
index 6ebe2c1ff3ac287ac78fa843a161fa0559da7675..2fcdc2bd52d4da403c6ab72d57abc84fe5f79981 100644 (file)
@@ -374,7 +374,7 @@ namespace Crow.Coding
                                                buffer.ToogleFolding (l);                                       
                                } catch (Exception ex) {
                                        requestedLine = value - 1;
-                                       Console.WriteLine ("Error cur column: " + ex.ToString ());
+                                       Console.WriteLine ("Error cur column: " + ex);
                                }
                        }
                }
index 9bdf5514b0dcb6c2a870b6c5798ec84c8e8adb31..fa7efb5d5d4cbe833554549cf76f3723aef390d4 100644 (file)
@@ -20,7 +20,7 @@
                        </HorizontalStack>
                        <HorizontalStack Width="Fit" Spacing="1">
                                <Label Text="Grid Spacing:"/>
-                               <Slider Value="{²../../../editor.GridSpacing}" Width="150" Height="10" Minimum="5" Maximum="100"/>
+                               <Slider Value="{²../../../editor.GridSpacing}" Width="200" Height="10" Minimum="5" Maximum="100" SmallIncrement="5" LargeIncrement="20"/>
                                <TextBox Text="{../../../editor.GridSpacing}"/>
                        </HorizontalStack>
                </HorizontalStack>
index 231964049762627083976048ffa776a0100cd843..340a8ceb511eabb01fb80179d04e727132259755 100644 (file)
@@ -58,6 +58,9 @@ namespace Crow
                public static Cairo.PointD Substract(this Cairo.PointD p1, Cairo.PointD p2){
                        return new Cairo.PointD(p1.X - p2.X, p1.Y - p2.Y);
                }
+               public static Cairo.PointD Divide(this Cairo.PointD p1, double d){
+                       return new Cairo.PointD(p1.X / d, p1.Y / d);
+               }
                public static Cairo.PointD Add(this Cairo.PointD p1, Cairo.PointD p2){
                        return new Cairo.PointD(p1.X + p2.X, p1.Y + p2.Y);
                }
index 8f48d06d81c9fabc2bcd301760387d55ae51da31..56e4148fb2bf4c6e7e732c3aaa528b81a5478259 100644 (file)
@@ -124,6 +124,14 @@ namespace Crow
                {
                        Inflate (delta, delta);
                }
+               public Rectangle Inflated (int delta) {
+                       return Inflated (delta,delta);
+               }
+               public Rectangle Inflated (int deltaX, int deltaY) {
+                       Rectangle r = this;
+                       r.Inflate (deltaX, deltaY);
+                       return r;
+               }
         public bool ContainsOrIsEqual(Point p)
         {
             return (p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height) ?