From 9d381671ec0b1266448eddbf4c4935cdc7d23a9f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Tue, 4 Dec 2018 14:09:07 +0100 Subject: [PATCH] docking save/restore; use image surfaces as cache for graphic object instead of backend similar which blink too much --- Default.style | 10 +- Templates/MenuItem.template | 9 +- Tests/BasicTests.cs | 146 ++++++++++++++++-- Tests/GraphicObjects/LaggingGraphicObject.cs | 59 +++++++ Tests/Interfaces/Container/0.crow | 10 +- Tests/Interfaces/Divers/0.crow | 2 +- Tests/Interfaces/Divers/testFocus.crow | 82 ++++++++++ Tests/Interfaces/Divers/testMenu.crow | 6 + .../Experimental/DockWindow.template | 5 + Tests/Interfaces/Experimental/testDock.crow | 4 +- Tests/Interfaces/colorItem2.crow | 10 ++ Tests/Tests.csproj | 15 ++ Tests/image/blank-file.svg | 6 + Tests/test.style | 3 + Tests/ui/MenuItem.template | 29 ++++ Tests/ui/dbgLog.crow | 64 ++++---- Tests/ui/dbgLogColors.crow | 60 +++++++ src/BmpPicture.cs | 13 +- src/Configuration.cs | 11 +- src/GraphicObjects/DockStack.cs | 96 ++++++++++++ src/GraphicObjects/DockWindow.cs | 11 +- src/GraphicObjects/GenericStack.cs | 6 + src/GraphicObjects/GraphicObject.cs | 36 ++++- src/GraphicObjects/Group.cs | 6 +- src/GraphicObjects/Image.cs | 2 +- src/GraphicObjects/Menu.cs | 11 +- src/GraphicObjects/MenuItem.cs | 12 +- src/GraphicObjects/TextBox.cs | 48 +++--- src/Interface.cs | 31 +++- src/Measure.cs | 4 +- src/Mono.Cairo/Surface.cs | 4 +- src/Mono.Cairo/XcbSurface.cs | 6 +- src/Picture.cs | 2 +- src/SvgPicture.cs | 17 +- src/debug/DbgEventTypeColors.cs | 77 +++++++++ src/debug/DbgLogViewer.cs | 113 +++++++------- src/debug/DebugLogger.cs | 8 +- 37 files changed, 841 insertions(+), 193 deletions(-) create mode 100644 Tests/GraphicObjects/LaggingGraphicObject.cs create mode 100755 Tests/Interfaces/Divers/testFocus.crow create mode 100755 Tests/Interfaces/Divers/testMenu.crow create mode 100755 Tests/Interfaces/colorItem2.crow create mode 100644 Tests/image/blank-file.svg create mode 100644 Tests/ui/MenuItem.template create mode 100755 Tests/ui/dbgLogColors.crow create mode 100644 src/debug/DbgEventTypeColors.cs diff --git a/Default.style b/Default.style index 9709eef9..c2f553e4 100644 --- a/Default.style +++ b/Default.style @@ -43,6 +43,7 @@ Label { Menu { Margin = "1"; Background = "vgradient|0:DimGrey|1:Black"; + //Background = "Transparent"; Height = "Fit"; Width = "Stretched"; VerticalAlignment = "Top"; @@ -52,10 +53,13 @@ MenuItem { Caption = "MenuItem"; Width = "Stretched"; Height = "Fit"; - Background = "Transparent"; + //Background = "vgradient|0:DimGrey|1:Black"; + //Background = "Transparent"; Foreground = "LightGrey"; - MouseEnter = "{Background = vgradient|0:SteelBlue|1:Jet;Foreground=White;}"; - MouseLeave = "{Foreground=LightGrey;Background=Transparent;}"; + MouseEnter = "{Background=SteelBlue;}"; + MouseLeave = "{Background=Transparent;}"; + //MouseEnter = "{Background = vgradient|0:SteelBlue|1:Jet;Foreground=White;}"; + //MouseLeave = "{Foreground=LightGrey;Background=Transparent;}"; SelectionBackground = "Transparent"; } MessageBox { diff --git a/Templates/MenuItem.template b/Templates/MenuItem.template index 2c912fee..4f77fb46 100644 --- a/Templates/MenuItem.template +++ b/Templates/MenuItem.template @@ -1,4 +1,5 @@  + @@ -6,10 +7,6 @@ - + + + diff --git a/Tests/BasicTests.cs b/Tests/BasicTests.cs index c3d3a781..c8f71d9d 100644 --- a/Tests/BasicTests.cs +++ b/Tests/BasicTests.cs @@ -2,44 +2,102 @@ using System; using System.Runtime.InteropServices; using Crow; using System.Threading; +using System.Collections.Generic; +using System.Linq; namespace tests { - class MainClass + class MainClass : Interface { - static Interface app; + static MainClass app; + public Command CMDTest; + public Measure TestWidth = 100; + IList testList = Color.ColorDic.Values.ToList(); + public IList TestList { + set{ + testList = value; + NotifyValueChanged ("TestList", testList); + } + get { return testList; } + } + public List> ColorsKVPList { + get { + return DbgLogViewer.colors.ToList(); + } + } + + protected override void InitBackend () + { + base.InitBackend (); + Keyboard.KeyDown += App_KeyboardKeyDown; + } public static void Main(string[] args) { - using (app = new Interface ()) { + using (app = new MainClass ()) { // XWindow win = new XWindow (app); // win.Show (); //app.LoadIMLFragment (@""); - app.Keyboard.KeyDown += App_KeyboardKeyDown; - + app.CMDTest = new Command(new Action(() => Console.WriteLine("test cmd"))) { Caption = "Test", Icon = new SvgPicture("#Tests.image.blank-file.svg"), CanExecute = true}; + //app.AddWidget (@"Interfaces/Divers/testFocus.crow").DataSource = app; + //app.AddWidget (@"Interfaces/Divers/testMenu.crow").DataSource = app; //app.AddWidget (@"Interfaces/Divers/0.crow").DataSource = app; //app.AddWidget (@"Interfaces/Splitter/1.crow").DataSource = app; //app.AddWidget (@"Interfaces/Container/0.crow").DataSource = app; + + //app.AddWidget (@"Interfaces/Divers/colorPicker.crow").DataSource = app; //app.AddWidget ("Interfaces/Divers/perfMeasures.crow").DataSource = app; - //app.AddWidget ("#Tests.ui.dbgLog.crow").DataSource = app; + + /*app.AddWidget ("#Tests.ui.dbgLog.crow").DataSource = app; + + GraphicObject go = app.AddWidget ("#Tests.ui.dbgLogColors.crow"); + go.DataSource = app; + + (go.FindByName("combo") as ComboBox).SelectedItemChanged += combo_selectedItemChanged; + (go.FindByName("kvpList") as ListBox).SelectedItemChanged += kvpList_selectedItemChanged;*/ + app.AddWidget (@"Interfaces/Experimental/testDock.crow").DataSource = app; - app.LoadIMLFragment (@""); + /*app.LoadIMLFragment (@""); app.LoadIMLFragment (@""); app.LoadIMLFragment (@""); - /*app.LoadIMLFragment (@""); + + app.LoadIMLFragment (@""); app.LoadIMLFragment (@""); app.LoadIMLFragment (@"");*/ - + long cpt = 0; + Measure testWidth = 100; + int increment = 1; + while (true) { - #if MEASURE_TIME + cpt++; + /* + testWidth += increment; + + if (increment > 0) { + if (testWidth > 500) + increment = -increment; + } else if (testWidth < 100) + increment = -increment; + app.NotifyValueChanged ("TestWidth", testWidth); +*/ + + /*app.NotifyValueChanged ("CPT", cpt); + + if (cpt % 2 == 0) + app.NotifyValueChanged ("TestColor", Color.Red); + else + app.NotifyValueChanged ("TestColor", Color.Blue);*/ + + /*#if MEASURE_TIME foreach (PerformanceMeasure m in app.PerfMeasures) m.NotifyChanges (); - #endif - Thread.Sleep(10); + #endif*/ + app.ProcessEvents (); + //Thread.Sleep(1); } } /*using (Display disp = new Display()) @@ -60,16 +118,74 @@ namespace tests }*/ } - static void App_KeyboardKeyDown (object sender, KeyEventArgs e) + void onColorUpdate (object sender, MouseButtonEventArgs e) + { + DbgLogViewer.colorsConf.Set (selectedEvtType.ToString (), newColor); + DbgLogViewer.colors [selectedEvtType] = newColor; + NotifyValueChanged ("ColorsKVPList", ColorsKVPList); + } + static DbgEvtType selectedEvtType; + static Color newColor; + + static void kvpList_selectedItemChanged (object sender, SelectionChangeEventArgs e) + { + if (e.NewValue == null) + return; + selectedEvtType = ((KeyValuePair)e.NewValue).Key; + } + static void combo_selectedItemChanged (object sender, SelectionChangeEventArgs e) + { + newColor = (Color)e.NewValue; + + } + + void App_KeyboardKeyDown (object sender, KeyEventArgs e) { Console.WriteLine((byte)e.Key); //#if DEBUG_LOG - /*switch (e.Key) { + switch (e.Key) { case Key.F2: DebugLog.save (app); break; - }*/ + case Key.F4: + app.NotifyValueChanged ("ColorsKVPList", app.ColorsKVPList); + break; + case Key.F6: + saveDocking (); + break; + case Key.F7: + reloadDocking (); + break; + case Key.F8: + app.LoadIMLFragment (@""); + break; + } //#endif } + + void saveDocking () { + DockStack ds = FindByName ("mainDock") as DockStack; + if (ds == null) { + Console.WriteLine ("main dock not found in graphic tree"); + return; + } + string conf = ds.ExportConfig (); + Console.WriteLine ("docking conf = " + conf); + Configuration.Global.Set ("DockingTests", conf); + } + void reloadDocking () { + DockStack ds = FindByName ("mainDock") as DockStack; + if (ds == null) { + Console.WriteLine ("main dock not found in graphic tree"); + return; + } + + string conf = Configuration.Global.Get ("DockingTests"); + if (string.IsNullOrEmpty (conf)) + return; + + + ds.ImportConfig (conf); + } } } diff --git a/Tests/GraphicObjects/LaggingGraphicObject.cs b/Tests/GraphicObjects/LaggingGraphicObject.cs new file mode 100644 index 00000000..98aeaf15 --- /dev/null +++ b/Tests/GraphicObjects/LaggingGraphicObject.cs @@ -0,0 +1,59 @@ +// +// SimpleGauge.cs +// +// Author: +// jp <> +// +// Copyright (c) 2013-2017 Jean-Philippe Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using Crow; +using System.ComponentModel; +using Cairo; + +namespace Crow +{ + public class LaggingGraphicObject : GraphicObject + { + protected override void onDraw (Context gr) + { + base.onDraw (gr); + + + for (int i = 0; i < 100000; i++) { + gr.SetSourceColor (Color.Red); + gr.Rectangle (0, 0, 100, 100); + gr.Stroke (); + + } + + //System.Threading.Thread.Sleep (1000); + + } + + public override void onMouseMove (object sender, MouseMoveEventArgs e) + { + + + RegisterForRedraw (); + } + } +} + diff --git a/Tests/Interfaces/Container/0.crow b/Tests/Interfaces/Container/0.crow index df2f4733..2f662fe8 100755 --- a/Tests/Interfaces/Container/0.crow +++ b/Tests/Interfaces/Container/0.crow @@ -1,5 +1,7 @@ - - - \ No newline at end of file + + + + diff --git a/Tests/Interfaces/Divers/0.crow b/Tests/Interfaces/Divers/0.crow index 9a03ecef..b37fdb6a 100755 --- a/Tests/Interfaces/Divers/0.crow +++ b/Tests/Interfaces/Divers/0.crow @@ -51,7 +51,7 @@ - +