diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-12-04 14:09:07 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-12-04 14:09:07 +0100 |
| commit | 9d381671ec0b1266448eddbf4c4935cdc7d23a9f (patch) | |
| tree | 34e9b4b0296eea8dba03024491934413bcd54083 | |
| parent | a64627699d4919d389522d92032ce4f05704d313 (diff) | |
docking save/restore; use image surfaces as cache for graphic object instead of backend similar which blink too much
37 files changed, 841 insertions, 193 deletions
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 @@ <?xml version="1.0"?> +<HorizontalStack> <Popper Font="{./Font}" Caption="{./Caption}" Background="{./Background}" PopDirection="{./PopDirection}" Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click" IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}"> @@ -6,10 +7,6 @@ <CheckBox IsChecked="{²./IsPopped}" Caption="{./Caption}" Background="{./Background}" Foreground="{./Foreground}"> <Template> <Border Name="border1" - MouseEnter="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}" - MouseLeave="{Foreground=Transparent}" - MouseDown="{Foreground=vgradient|0:Black|0.05:Grey|0.85:Grey|1:White}" - MouseUp="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}" MinimumSize = "60,0" Foreground="Transparent" Background="{./Background}"> @@ -21,7 +18,9 @@ </Template> </CheckBox> </Template> - <Border Foreground="DimGrey" Width="{../PopWidth}" Height="{../PopHeight}" Background="Jet"> + <Border Foreground="DimGrey" Width="{../PopWidth}" Height="{../PopHeight}" Background="vgradient|0:DimGrey|1:Black"> <VerticalStack Name="ItemsContainer"/> </Border> </Popper> +<GraphicObject Background="Green" Width="5" Height="5" Visible="{./AutomaticOpening}"/> +</HorizontalStack> 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<Color> testList = Color.ColorDic.Values.ToList(); + public IList<Color> TestList { + set{ + testList = value; + NotifyValueChanged ("TestList", testList); + } + get { return testList; } + } + public List<KeyValuePair<DbgEvtType, Color>> 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 (@"<SimpleGauge Level='40' Margin='5' Background='Jet' Foreground='Grey' Width='30' Height='50%'/>"); - 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 (@"<DockWindow Width='150' Height='150' Name='dock1'/>"); + /*app.LoadIMLFragment (@"<DockWindow Width='150' Height='150' Name='dock1'/>"); app.LoadIMLFragment (@"<DockWindow Width='150' Height='150' Name='dock2'/>"); app.LoadIMLFragment (@"<DockWindow Width='150' Height='150' Name='dock3'/>"); - /*app.LoadIMLFragment (@"<DockWindow Width='150' Height='150'/>"); + + app.LoadIMLFragment (@"<DockWindow Width='150' Height='150'/>"); app.LoadIMLFragment (@"<DockWindow Width='150' Height='150'/>"); app.LoadIMLFragment (@"<DockWindow Width='150' Height='150'/>");*/ - + 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<DbgEvtType, Color>)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 (@"<DockWindow Width='150' Height='150'/>"); + 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<string> ("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 @@ <?xml version="1.0"?> -<Container Background="DimGrey" Margin="10" Width="90%" Height="90%"> - <GraphicObject Margin="10" Background="SeaGreen" - MinimumSize="50,50"/> -</Container>
\ No newline at end of file +<VerticalStack Margin="10" Background="Jet" > + <Label Text="{CPT}" Background="Red" Font="mono, 60" Margin="0"/> + <LaggingGraphicObject Name="lagging" Margin="10" Background="{TestColor}"/> +</VerticalStack> + + 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 @@ </VerticalStack> </HorizontalStack> <HorizontalStack Height="Fit" Margin="5"> - <Label Text="MouseEvents" Width="50%" Margin="3" + <Label Text="MouseEvents" Width="50%" Margin="3" Focusable="true" Background="Jet" Foreground="DimGrey" TextAlignment="Center" diff --git a/Tests/Interfaces/Divers/testFocus.crow b/Tests/Interfaces/Divers/testFocus.crow new file mode 100755 index 00000000..97a57457 --- /dev/null +++ b/Tests/Interfaces/Divers/testFocus.crow @@ -0,0 +1,82 @@ +<?xml version="1.0"?> +<VerticalStack> + <Menu> + <MenuItem Caption="File" Width="Fit"> + <MenuItem Command="{CMDTest}"/> + <MenuItem Caption="Open"/> + <MenuItem Caption="Save"/> + <MenuItem Caption="Quit"/> + </MenuItem> + <MenuItem Caption="Edit" Name="edit" Width="Fit"> + <MenuItem Caption="Cut"/> + <MenuItem Caption="Copy"/> + <MenuItem Caption="Paste"/> + <MenuItem Caption="Special" Name="special" Width="Fit"> + <MenuItem Caption="Cut"/> + <MenuItem Caption="Copy"/> + <MenuItem Caption="Paste"/> + </MenuItem> + <MenuItem Caption="Special2" Name="special" Width="Fit"> + <MenuItem Caption="Cut"/> + <MenuItem Caption="Copy"/> + <MenuItem Caption="Paste"/> + </MenuItem> + </MenuItem> + <MenuItem Caption="Help" Width="Fit"> + <MenuItem Caption="About"/> + <MenuItem Caption="Help"/> + </MenuItem> + </Menu> + <HorizontalStack Height="Fit"> + <Label Text="Hover:" Width="50" Foreground="Grey"/> + <Label Text="{HoverWidget}"/> + </HorizontalStack> + <HorizontalStack Height="Fit"> + <Label Text="Focus:" Width="50" Foreground="Grey"/> + <Label Text="{FocusedWidget}"/> + </HorizontalStack> + <HorizontalStack Height="Fit"> + <Label Text="Active:" Width="50" Foreground="Grey"/> + <Label Text="{ActiveWidget}"/> + </HorizontalStack> + <Container Fit="true" Margin="50" Background="SlateGrey"> + <Label Text="MouseEvents" Margin="3" Focusable="true" Fit="true" + Background="Jet" + Foreground="DimGrey" + TextAlignment="Center" + MouseEnter="{Foreground=White}" + MouseLeave="{Foreground=DimGrey}" + MouseDown="{Background=DarkRed}" + MouseClick="{Foreground=Green}" + MouseDoubleClick="{Foreground=Yellow}" + MouseUp="{Background=Jet}"/> + </Container> + <TextBox Width="300" Margin="10"/> + <Slider Width="300" Height="12"/> + <ComboBox Data="{TestList}" Width="120"> + <ItemTemplate DataType="Crow.Color"> + <HorizontalStack + HorizontalAlignment="Left" + Height="Fit" Width="200" Margin="1" Focusable="true" + MouseEnter="{Background=hgradient|0:DarkRed|1:Transparent}" + MouseLeave="{Background=Transparent}"> + <GraphicObject Height="12" Width="20" Background="{}" Margin="0" CornerRadius="3"/> + <Label Text="{}" Margin="0" Width="Stretched"/> + </HorizontalStack> + </ItemTemplate> + </ComboBox> + <HorizontalStack Height="Fit" Margin="1" Background="DimGrey" Width="200"> + <VerticalStack Spacing="2" Width="50%"> + <CheckBox Caption="test" MouseEnter="{Background=Blue}" MouseLeave="{Background=Transparent}"/> + <CheckBox /> + <CheckBox /> + <CheckBox IsChecked="true"/> + </VerticalStack> + <VerticalStack Spacing="2" Width="50%"> + <RadioButton Fit="true"/> + <RadioButton Fit="true" IsChecked="true"/> + <RadioButton Fit="true"/> + <RadioButton Fit="true"/> + </VerticalStack> + </HorizontalStack> +</VerticalStack> diff --git a/Tests/Interfaces/Divers/testMenu.crow b/Tests/Interfaces/Divers/testMenu.crow new file mode 100755 index 00000000..08822445 --- /dev/null +++ b/Tests/Interfaces/Divers/testMenu.crow @@ -0,0 +1,6 @@ +<?xml version="1.0"?> +<Menu> + <MenuItem Caption="File" Width="Fit"> + <MenuItem Command="{CMDTest}"/> + </MenuItem> +</Menu> diff --git a/Tests/Interfaces/Experimental/DockWindow.template b/Tests/Interfaces/Experimental/DockWindow.template index 2d39bd4b..ab518ad9 100755 --- a/Tests/Interfaces/Experimental/DockWindow.template +++ b/Tests/Interfaces/Experimental/DockWindow.template @@ -11,6 +11,11 @@ <Label Text="{./DockingPosition}" TextAlignment="Left" Width="Fit" Foreground="White" /> </HorizontalStack> + <Label Text="{./Width}" TextAlignment="Left" Width="Fit" + Foreground="White" /> + <Label Text="{./Height}" TextAlignment="Left" Width="Fit" + Foreground="White" /> + <HorizontalStack Visible="{./IsDocked}" Height="Fit" Margin="1" Background="Grey"> <Label Text="{./Caption}" TextAlignment="Left" Width="Stretched" Foreground="Jet" /> diff --git a/Tests/Interfaces/Experimental/testDock.crow b/Tests/Interfaces/Experimental/testDock.crow index 62a5203c..c0e6e96b 100644 --- a/Tests/Interfaces/Experimental/testDock.crow +++ b/Tests/Interfaces/Experimental/testDock.crow @@ -1,6 +1,6 @@ <?xml version="1.0"?> -<Window Width="Stretched" Height="Stretched"> - <DockStack Background="#60101050" Margin="20"> +<Window Width="Stretched" Height="Stretched" Background="Jet"> + <DockStack Name="mainDock" Background="DarkRed" Margin="20"> </DockStack> </Window> <!--- diff --git a/Tests/Interfaces/colorItem2.crow b/Tests/Interfaces/colorItem2.crow new file mode 100755 index 00000000..4e29d380 --- /dev/null +++ b/Tests/Interfaces/colorItem2.crow @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<Border Foreground="Transparent" Focusable="true" HorizontalAlignment="Left" Height="Fit"> + <HorizontalStack Margin="0" + MouseEnter="{Background=CornflowerBlue}" + MouseLeave="{Background=Transparent}"> + <GraphicObject Height="8" Width="14" Background="{}" Margin="0" CornerRadius="2"/> + <Label Text="{}" Margin="0" Width="Stretched" Font="mono, 8"/> + </HorizontalStack> +</Border> + diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 049ab6f9..2d3717cf 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -102,6 +102,7 @@ <Compile Include="GraphicObjects\HexaContainer.cs" /> <Compile Include="GraphicObjects\TechBorder.cs" /> <Compile Include="keysyms.cs" /> + <Compile Include="GraphicObjects\LaggingGraphicObject.cs" /> </ItemGroup> <ItemGroup> <None Include="image\u.svg"> @@ -379,6 +380,12 @@ <None Include="Interfaces\TemplatedContainer\testTabView2.crow"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="Interfaces\Divers\testFocus.crow"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="Interfaces\Divers\testMenu.crow"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> <ItemGroup> <Folder Include="Interfaces\" /> @@ -423,6 +430,14 @@ <EmbeddedResource Include="Interfaces\Experimental\DockWindow.template"> <LogicalName>Crow.DockWindow.template</LogicalName> </EmbeddedResource> + <EmbeddedResource Include="ui\MenuItem.template"> + <LogicalName>Crow.MenuItem.template</LogicalName> + </EmbeddedResource> + <EmbeddedResource Include="image\blank-file.svg" /> + <EmbeddedResource Include="ui\dbgLogColors.crow" /> + <EmbeddedResource Include="Interfaces\colorItem2.crow"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </EmbeddedResource> </ItemGroup> <ItemGroup> <ProjectReference Include="..\Crow.csproj"> diff --git a/Tests/image/blank-file.svg b/Tests/image/blank-file.svg new file mode 100644 index 00000000..8136979e --- /dev/null +++ b/Tests/image/blank-file.svg @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generated by IcoMoon.io --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"> +<path fill="#FFFFFF" d="M10 0h-8v16h12v-12l-4-4zM9 5h4v10h-10v-14h6v4zM10 4v-3l3 3h-3z"></path> +</svg> diff --git a/Tests/test.style b/Tests/test.style index 14acbbdf..7f912f54 100644 --- a/Tests/test.style +++ b/Tests/test.style @@ -38,3 +38,6 @@ DbgLogViewer{ Foreground = "LightGrey"; Focusable = "true"; } +DockWindow{ + Background = "0.1,0.1,0.1,0.5"; +} diff --git a/Tests/ui/MenuItem.template b/Tests/ui/MenuItem.template new file mode 100644 index 00000000..bf01f99d --- /dev/null +++ b/Tests/ui/MenuItem.template @@ -0,0 +1,29 @@ +<?xml version="1.0"?> +<Popper Font="{./Font}" Caption="{./Caption}" Background="{./Background}" PopDirection="{./PopDirection}" + Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click" + IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}" IsEnabled="{./IsEnabled}"> + <Template> + <CheckBox IsChecked="{²./IsPopped}" Caption="{./Caption}" Background="{./Background}" Foreground="{./Foreground}"> + <Template> + <Border Name="border1" + MouseEnter="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}" + MouseLeave="{Foreground=Transparent}" + MouseDown="{Foreground=vgradient|0:Black|0.05:Grey|0.85:Grey|1:White}" + MouseUp="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}" + MinimumSize = "40,0" + Foreground="Transparent" + Background="{./Background}"> + <HorizontalStack HorizontalAlignment="Left" Margin="1"> + <Image Width="10" Height="10" Picture="{../../../../../Icon}"/> + <Label Text="{./Caption}" + Foreground="{./Foreground}" + Font="{./Font}" /> + </HorizontalStack> + </Border> + </Template> + </CheckBox> + </Template> + <Border Foreground="DimGrey" Width="{../PopWidth}" Height="{../PopHeight}" Background="Jet"> + <VerticalStack Name="ItemsContainer"/> + </Border> +</Popper> diff --git a/Tests/ui/dbgLog.crow b/Tests/ui/dbgLog.crow index 86ed0edc..cf7e2ae4 100755 --- a/Tests/ui/dbgLog.crow +++ b/Tests/ui/dbgLog.crow @@ -1,32 +1,34 @@ <?xml version="1.0"?> -<VerticalStack> - <HorizontalStack Height="Fit"> - <Label Text="Scale X:"/> - <Label Text="{../../view.XScale}"/> - <Label Text="Scroll X:"/> - <Label Text="{../../view.ScrollX}"/> - <Label Text="Max Scroll X:"/> - <Label Text="{../../view.MaxScrollX}"/> - <Label Text="Scroll Y:"/> - <Label Text="{../../view.ScrollY}"/> - <Label Text="Visible Lines:"/> - <Label Text="{../../view.VisibleLines}"/> - <Label Text="Visible Ticks:"/> - <Label Text="{../../view.VisibleTicks}"/> - <Label Text="CurrentLine:"/> - <Label Text="{../../view.CurrentLine}"/> - </HorizontalStack> - <HorizontalStack> - <DbgLogViewer Margin="0" Name="view" LogFile="debug.log" MouseWheelSpeed="10"/> - <ScrollBar Name="scrollbar1" Orientation="Vertical" - Value="{²../view.ScrollY}" Maximum="{../view.MaxScrollY}" - CursorSize="{../view.ChildHeightRatio}" - LargeIncrement="{../view.PageHeight}" SmallIncrement="30" - Width="14" /> - </HorizontalStack> - <ScrollBar Style="HScrollBar" Name="scrollbarX" Orientation="Horizontal" - Value="{²../view.ScrollX}" Maximum="{../view.MaxScrollX}" - CursorSize="{../view.ChildWidthRatio}" - LargeIncrement="{../view.PageWidth}" SmallIncrement="30" - Height="14" /> -</VerticalStack> +<Window Width="Stretched" Height="Stretched"> + <VerticalStack> + <HorizontalStack Height="Fit"> + <Label Text="Scale X:"/> + <Label Text="{../../view.XScale}"/> + <Label Text="Scroll X:"/> + <Label Text="{../../view.ScrollX}"/> + <Label Text="Max Scroll X:"/> + <Label Text="{../../view.MaxScrollX}"/> + <Label Text="Scroll Y:"/> + <Label Text="{../../view.ScrollY}"/> + <Label Text="Visible Lines:"/> + <Label Text="{../../view.VisibleLines}"/> + <Label Text="Visible Ticks:"/> + <Label Text="{../../view.VisibleTicks}"/> + <Label Text="CurrentLine:"/> + <Label Text="{../../view.CurrentLine}"/> + </HorizontalStack> + <HorizontalStack> + <DbgLogViewer Margin="0" Name="view" LogFile="debug.log" MouseWheelSpeed="10"/> + <ScrollBar Name="scrollbar1" Orientation="Vertical" + Value="{²../view.ScrollY}" Maximum="{../view.MaxScrollY}" + CursorSize="{../view.ChildHeightRatio}" + LargeIncrement="{../view.PageHeight}" SmallIncrement="30" + Width="12" /> + </HorizontalStack> + <ScrollBar Style="HScrollBar" Name="scrollbarX" Orientation="Horizontal" + Value="{²../view.ScrollX}" Maximum="{../view.MaxScrollX}" + CursorSize="{../view.ChildWidthRatio}" + LargeIncrement="{../view.PageWidth}" SmallIncrement="30" + Height="12" /> + </VerticalStack> +</Window>
\ No newline at end of file diff --git a/Tests/ui/dbgLogColors.crow b/Tests/ui/dbgLogColors.crow new file mode 100755 index 00000000..cc9fdb24 --- /dev/null +++ b/Tests/ui/dbgLogColors.crow @@ -0,0 +1,60 @@ +<?xml version="1.0"?> +<Window Template="#Crow.ToolWindow.template" AlwaysOnTop="true" Width="400" Height="300" + HorizontalAlignment="Right" VerticalAlignment="Bottom"> + <VerticalStack> + <Button Caption="update" MouseClick="onColorUpdate"/> + <HorizontalStack Height="Fit" DataSource="{../kvpList.SelectedItem}" Margin="10"> + <Label Text="{Key}" Margin="0" Width="Stretched" Font="mono, 8"/> + <ComboBox Data="{TestList}" ItemTemplate="#Tests.Interfaces.colorItem2.crow" Name="combo" + SelectedItem="{Value}"> + <Template> + <Popper Caption="{./SelectedItem}" Name="popper" PopDirection="Bottom" Foreground="{./Foreground}" Background="{./Background}"> + <Template> + <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}" Foreground="{./Foreground}" Background="{./Background}"> + <Template> + <Border CornerRadius="0" Foreground="LightGrey"> + <HorizontalStack Margin="0" Spacing="1"> + <!---<GraphicObject Height="8" Width="14" Background="{./Caption}" Margin="0" CornerRadius="2"/>--> + <Label MinimumSize="80,10" Text="{./Caption}" Margin="0" Width="Stretched" Font="mono, 8"/> + <Button Width="14" Height="14" Focusable="false" + Template="#Crow.Templates.ArrowBut.template"> + <Image Margin="0" Path="#Crow.Images.Icons.updown.svg" SvgSub="down"/> + </Button> + </HorizontalStack> + </Border> + </Template> + </CheckBox> + </Template> + <Border Background="DimGrey" BorderWidth="1" Margin="1" + MinimumSize="{../../MinimumPopupSize}" Fit="true"> + <Scroller Name="scroller1" Margin="2" + MaximumSize="0,200" + HorizontalAlignment="Left"> + <VerticalStack + Height="Fit" Name="ItemsContainer" Margin="0" + HorizontalAlignment="Left" + VerticalAlignment="Top"/> + </Scroller> + </Border> + </Popper> + </Template> + </ComboBox> + <GraphicObject Height="8" Width="14" Background="{Value}" Margin="0" CornerRadius="2"/> + </HorizontalStack> + <HorizontalStack> + <ListBox Name="kvpList" Data="{ColorsKVPList}" Margin="0" + Template="#Crow.Templates.ScrollingListBox.template"> + <ItemTemplate> + <Border Foreground="Transparent" Focusable="true" HorizontalAlignment="Left" Height="Fit"> + <HorizontalStack Margin="0" + MouseEnter="{Background=CornflowerBlue}" + MouseLeave="{Background=Transparent}"> + <GraphicObject Height="8" Width="14" Background="{Value}" Margin="0" CornerRadius="2"/> + <Label Text="{Key}" Margin="0" Width="Stretched" Font="mono, 8"/> + </HorizontalStack> + </Border> + </ItemTemplate> + </ListBox> + </HorizontalStack> + </VerticalStack> +</Window>
\ No newline at end of file diff --git a/src/BmpPicture.cs b/src/BmpPicture.cs index e3af9c79..1c7250b8 100644 --- a/src/BmpPicture.cs +++ b/src/BmpPicture.cs @@ -55,19 +55,18 @@ namespace Crow /// load the image for rendering from the path given as argument /// </summary> /// <param name="path">image path, may be embedded</param> - public override void Load (Interface iface, string path) - { - Path = path; - if (sharedResources.ContainsKey (path)) { - sharedPicture sp = sharedResources [path]; + void Load () + { + if (sharedResources.ContainsKey (Path)) { + sharedPicture sp = sharedResources [Path]; image = (byte[])sp.Data; Dimensions = sp.Dims; return; } - using (Stream stream = iface.GetStreamFromPath (path)) { + using (Stream stream = Interface.StaticGetStreamFromPath (Path)) { loadBitmap (new System.Drawing.Bitmap (stream)); } - sharedResources [path] = new sharedPicture (image, Dimensions); + sharedResources [Path] = new sharedPicture (image, Dimensions); } //load image via System.Drawing.Bitmap, cairo load png only diff --git a/src/Configuration.cs b/src/Configuration.cs index a6328c0a..4acba6af 100644 --- a/src/Configuration.cs +++ b/src/Configuration.cs @@ -29,6 +29,7 @@ using System.Reflection; using System.IO; using System.Collections.Generic; using System.Threading; +using System.Linq; namespace Crow { @@ -102,6 +103,7 @@ namespace Crow } startSavingThread (); } + static Configuration () { string configRoot = @@ -128,6 +130,13 @@ namespace Crow } globalConfig = new Configuration (globalConfigPath); } + + public string[] Names { + get { + return items.Keys.ToArray (); + } + } + void startSavingThread(){ Thread t = new Thread (savingThread); t.IsBackground = true; @@ -139,7 +148,7 @@ namespace Crow save (); isDirty = false; } - Thread.Sleep (1000); + Thread.Sleep (100); } } /// <summary> diff --git a/src/GraphicObjects/DockStack.cs b/src/GraphicObjects/DockStack.cs index f2174024..aa7c33da 100644 --- a/src/GraphicObjects/DockStack.cs +++ b/src/GraphicObjects/DockStack.cs @@ -26,6 +26,8 @@ using System; using Crow.IML; using System.Linq; +using System.Text; +using System.IO; namespace Crow { @@ -369,6 +371,100 @@ namespace Crow if (dw != null) dw.DockingPosition = (Orientation == Orientation.Horizontal ? Alignment.Right : Alignment.Bottom); } + + //read next value in config string until next ';' + string getConfAttrib (string conf, ref int i) { + int nextI = conf.Substring (i).IndexOf (';'); + string tmp = conf.Substring (i, nextI); + i += nextI + 1; + return tmp; + } + /// <summary> + /// Imports the config. + /// </summary> + /// <param name="conf">Conf.</param> + /// <param name="dataSource">Data source for the docked windows</param> + public void ImportConfig (string conf, object dataSource = null) { + lock (IFace.UpdateMutex) { + ClearChildren (); + stretchedChild = null; + int i = 0; + Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i)); + importConfig (conf, ref i, dataSource); + } + } + public string ExportConfig () { + return Orientation.ToString() + ";" + exportConfig(); + } + void importConfig (string conf, ref int i, object dataSource) { + if (conf [i++] != '(') + return; + while (i < conf.Length - 4) { + string sc = conf.Substring (i, 4); + i += 4; + switch (sc) { + case "WIN;": + DockWindow dw = null; + string wName = getConfAttrib (conf, ref i); + try { + dw = IFace.Load (wName) as DockWindow; + } catch { + dw = new DockWindow (IFace); + } + + dw.Name = wName; + dw.Width = Measure.Parse (getConfAttrib (conf, ref i)); + dw.Height = Measure.Parse (getConfAttrib (conf, ref i)); + dw.DockingPosition = (Alignment)Enum.Parse (typeof(Alignment), getConfAttrib (conf, ref i)); + dw.IsDocked = true; + dw.DataSource = dataSource; + this.AddChild (dw); + + break; + case "STK;": + DockStack ds = new DockStack (IFace); + ds.Width = Measure.Parse (getConfAttrib (conf, ref i)); + ds.Height = Measure.Parse (getConfAttrib (conf, ref i)); + ds.Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i)); + + this.AddChild (ds); + + ds.importConfig (conf, ref i, dataSource); + break; + case "SPL;": + Splitter sp = new Splitter (IFace); + sp.Width = Measure.Parse (getConfAttrib (conf, ref i)); + sp.Height = Measure.Parse (getConfAttrib (conf, ref i)); + sp.Thickness = int.Parse (getConfAttrib (conf, ref i)); + this.AddChild (sp); + break; + } + char nextC = conf [i++]; + if (nextC == ')') + break; + } + } + string exportConfig () { + StringBuilder tmp = new StringBuilder("("); + + for (int i = 0; i < Children.Count; i++) { + if (Children [i] is DockWindow) { + DockWindow dw = Children [i] as DockWindow; + tmp.Append (string.Format("WIN;{0};{1};{2};{3};",dw.Name, dw.Width, dw.Height, dw.DockingPosition)); + } else if (Children [i] is DockStack) { + DockStack ds = Children [i] as DockStack; + tmp.Append (string.Format("STK;{0};{1};{2};{3}", ds.Width, ds.Height, ds.Orientation, ds.exportConfig())); + } else if (Children [i] is Splitter) { + Splitter sp = Children [i] as Splitter; + tmp.Append (string.Format("SPL;{0};{1};{2};", sp.Width, sp.Height, sp.Thickness)); + } + if (i < Children.Count - 1) + tmp.Append ("|"); + } + + tmp.Append (")"); + return tmp.ToString (); + } } } diff --git a/src/GraphicObjects/DockWindow.cs b/src/GraphicObjects/DockWindow.cs index 1ae3b0b4..d6385057 100644 --- a/src/GraphicObjects/DockWindow.cs +++ b/src/GraphicObjects/DockWindow.cs @@ -31,12 +31,11 @@ namespace Crow public class DockWindow : Window { #region CTOR - public DockWindow () : base () - { - } + public DockWindow () {} + public DockWindow (Interface iface) : base (iface) {} #endregion - int undockThreshold = 4; + int undockThreshold = 10; bool isDocked = false; Alignment docking = Alignment.Undefined; @@ -170,10 +169,6 @@ namespace Crow Undock (); base.close (); } - - public string ExportWinConfigs () { - return string.Format ("{0};{1};{2}", this.Name, DockingPosition, savedSlot); - } } } diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 64841d4b..f281311c 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -242,5 +242,11 @@ namespace Crow else adjustStretchedGo (LayoutingType.Height); } + + public override void ClearChildren () + { + base.ClearChildren (); + stretchedGO = null; + } } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 2bf20f27..747609b0 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -945,11 +945,17 @@ namespace Crow if (value != null) rootDataLevel = true; - + + #if DEBUG_LOG + DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GOLockLayouting, this); + #endif lock (IFace.LayoutMutex) { OnDataSourceChanged (this, dse); NotifyValueChanged ("DataSource", DataSource); } + #if DEBUG_LOG + dbgEvt.end = DebugLog.chrono.ElapsedTicks; + #endif } get { return rootDataLevel ? dataSource : dataSource == null ? @@ -1358,8 +1364,13 @@ namespace Crow public virtual void RegisterClip(Rectangle clip){ #if DEBUG_LOG DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GORegisterClip, this); - #endif - Rectangle r = clip + ClientRectangle.Position; + #endif + Rectangle cb = ClientRectangle; + Rectangle r = clip + cb.Position; + if (r.Right > cb.Right) + r.Width -= r.Right - cb.Right; + if (r.Bottom > cb.Bottom) + r.Height -= r.Bottom - cb.Bottom; if (CacheEnabled && !IsDirty) Clipping.UnionRectangle (r); if (Parent == null) @@ -1372,7 +1383,7 @@ namespace Crow dbgEvt.end = DebugLog.chrono.ElapsedTicks; #endif } - /// <summary> Full update, taking care of sizing policy </summary> + /// <summary> Full update, content and layouting, taking care of sizing policy </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterForGraphicUpdate () { @@ -1382,7 +1393,7 @@ namespace Crow else if (RegisteredLayoutings == LayoutingType.None) IFace.EnqueueForRepaint (this); } - /// <summary> query an update of the content, a redraw </summary> + /// <summary> query an update of the content without layouting changes</summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterForRedraw () { @@ -1641,14 +1652,21 @@ namespace Crow #if DEBUG_LOG DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GORecreateCache, this); #endif - IsDirty = false; + + /*if (bmp == null) + bmp = IFace.surf.CreateSimilar (Content.ColorAlpha, Slot.Width, Slot.Height); + else if (LastPaintedSlot.Width != Slot.Width || LastPaintedSlot.Height != Slot.Height) + bmp.SetSize (Slot.Width, Slot.Height);*/ bmp?.Dispose (); - bmp = IFace.surf.CreateSimilar(Content.ColorAlpha, Slot.Width, Slot.Height); + bmp = new ImageSurface(Format.Argb32, Slot.Width, Slot.Height); + using (Context gr = new Context (bmp)) { gr.Antialias = Interface.Antialias; onDraw (gr); } - bmp.Flush (); + + IsDirty = false; + #if DEBUG_LOG dbgEvt.end = DebugLog.chrono.ElapsedTicks; #endif @@ -1657,6 +1675,7 @@ namespace Crow #if DEBUG_LOG DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GOUpdateCacheAndPaintOnCTX, this); #endif + Rectangle rb = Slot + Parent.ClientRectangle.Position; if (clearBackground) { ctx.Save (); @@ -1665,6 +1684,7 @@ namespace Crow ctx.Fill (); ctx.Restore (); } + ctx.SetSourceSurface (bmp, rb.X, rb.Y); ctx.Paint (); Clipping.Dispose (); diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index a90947a5..ece1f090 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -340,7 +340,11 @@ namespace Crow childrenRWLock.ExitReadLock (); #if DEBUG_CLIP_RECTANGLE - Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8)); + /*gr.LineWidth = 1; + gr.SetSourceColor(Color.DarkMagenta.AdjustAlpha (0.8)); + for (int i = 0; i < Clipping.NumRectangles; i++) + gr.Rectangle(Clipping.GetRectangle(i)); + gr.Stroke ();*/ #endif } gr.Dispose (); diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index e83183c0..5960101a 100644 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -173,7 +173,7 @@ namespace Crow else pic = new BmpPicture (path); - pic.Load (IFace, path); + pic.Scaled = scaled; pic.KeepProportions = keepProps; diff --git a/src/GraphicObjects/Menu.cs b/src/GraphicObjects/Menu.cs index dbc1d636..0ddb8eae 100644 --- a/src/GraphicObjects/Menu.cs +++ b/src/GraphicObjects/Menu.cs @@ -51,10 +51,15 @@ namespace Crow NotifyValueChanged ("Orientation", orientation); } } - [XmlIgnore]public bool AutomaticOpenning + [XmlIgnore]public bool AutomaticOpening { get { return autoOpen; } - set { autoOpen = value; } + set { + if (autoOpen == value) + return; + autoOpen = value; + NotifyValueChanged ("AutomaticOpening", autoOpen); + } } #endregion @@ -70,7 +75,7 @@ namespace Crow public override void onMouseLeave (object sender, MouseMoveEventArgs e) { base.onMouseLeave (sender, e); - AutomaticOpenning = false; + AutomaticOpening = false; } } } diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs index 47bd978f..3b25a9fe 100644 --- a/src/GraphicObjects/MenuItem.cs +++ b/src/GraphicObjects/MenuItem.cs @@ -46,7 +46,7 @@ namespace Crow Measure popWidth, popHeight; #region Public properties - [XmlAttributeAttribute][DefaultValue(false)] + [DefaultValue(false)] public bool IsOpened { get { return isOpened; } set { @@ -58,12 +58,12 @@ namespace Crow if (isOpened) { onOpen (this, null); if (LogicalParent is Menu) - (LogicalParent as Menu).AutomaticOpenning = true; + (LogicalParent as Menu).AutomaticOpening = true; }else onClose (this, null); } } - [XmlAttributeAttribute][DefaultValue(null)] + [DefaultValue(null)] public virtual Command Command { get { return command; } set { @@ -148,7 +148,7 @@ namespace Crow closeMenu (); } if(!IsOpened) - (LogicalParent as Menu).AutomaticOpenning = false; + (LogicalParent as Menu).AutomaticOpening = false; } protected virtual void onOpen (object sender, EventArgs e){ Open.Raise (this, null); @@ -167,7 +167,7 @@ namespace Crow Menu menu = LogicalParent as Menu; if (menu == null) return; - if (menu.AutomaticOpenning && items.Children.Count>0) + if (menu.AutomaticOpening && items.Children.Count>0) IsOpened = true; } public override void onMouseLeave (object sender, MouseMoveEventArgs e) @@ -181,6 +181,8 @@ namespace Crow MenuItem tmp = LogicalParent as MenuItem; while (tmp != null) { tmp.IsOpened = false; + tmp.Background = Color.Transparent; + tmp.AutomaticOpening = false; tmp = tmp.LogicalParent as MenuItem; } } diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index 7d14f800..5da67e31 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -69,7 +69,7 @@ namespace Crow public override void onKeyDown (object sender, KeyEventArgs e) { base.onKeyDown (sender, e); - /* + Key key = e.Key; switch (key) @@ -85,12 +85,12 @@ namespace Crow if (selectionIsEmpty) { if (!MoveRight ()) return; - }else if (e.Shift) + }else if (IFace.Keyboard.Shift) IFace.Clipboard = this.SelectedText; this.DeleteChar (); break; - case Key.ISO_Enter: case Key.KP_Enter: + case Key.Return: if (!selectionIsEmpty) this.DeleteChar (); if (Multiline) @@ -104,46 +104,46 @@ namespace Crow SelRelease = -1; break; case Key.Home: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = new Point (CurrentColumn, CurrentLine); - if (e.Control) + if (IFace.Keyboard.Ctrl) CurrentLine = 0; CurrentColumn = 0; SelRelease = new Point (CurrentColumn, CurrentLine); break; } SelRelease = -1; - if (e.Control) + if (IFace.Keyboard.Ctrl) CurrentLine = 0; CurrentColumn = 0; break; case Key.End: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = CurrentPosition; - if (e.Control) + if (IFace.Keyboard.Ctrl) CurrentLine = int.MaxValue; CurrentColumn = int.MaxValue; SelRelease = CurrentPosition; break; } SelRelease = -1; - if (e.Control) + if (IFace.Keyboard.Ctrl) CurrentLine = int.MaxValue; CurrentColumn = int.MaxValue; break; case Key.Insert: - if (e.Shift) + if (IFace.Keyboard.Shift) this.Insert (IFace.Clipboard); - else if (e.Control && !selectionIsEmpty) + else if (IFace.Keyboard.Ctrl && !selectionIsEmpty) IFace.Clipboard = this.SelectedText; break; case Key.Left: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = new Point(CurrentColumn, CurrentLine); - if (e.Control) + if (IFace.Keyboard.Ctrl) GotoWordStart (); else if (!MoveLeft ()) return; @@ -151,16 +151,16 @@ namespace Crow break; } SelRelease = -1; - if (e.Control) + if (IFace.Keyboard.Ctrl) GotoWordStart (); else MoveLeft(); break; case Key.Right: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = CurrentPosition; - if (e.Control) + if (IFace.Keyboard.Ctrl) GotoWordEnd (); else if (!MoveRight ()) return; @@ -168,13 +168,13 @@ namespace Crow break; } SelRelease = -1; - if (e.Control) + if (IFace.Keyboard.Ctrl) GotoWordEnd (); else MoveRight (); break; case Key.Up: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = CurrentPosition; CurrentLine--; @@ -185,7 +185,7 @@ namespace Crow CurrentLine--; break; case Key.Down: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = CurrentPosition; CurrentLine++; @@ -197,13 +197,11 @@ namespace Crow break; case Key.Menu: break; - case Key.NumLock: - break; - case Key.PageDown: + case Key.Num_Lock: break; - case Key.PageUp: + case Key.Page_Down: break; - case Key.RWin: + case Key.Page_Up: break; case Key.Tab: this.Insert ("\t"); @@ -211,7 +209,7 @@ namespace Crow default: break; } - */ + RegisterForGraphicUpdate(); } public override void onKeyPress (object sender, KeyPressEventArgs e) diff --git a/src/Interface.cs b/src/Interface.cs index 77137761..3c586685 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -119,6 +119,7 @@ namespace Crow } #endregion + protected bool running; protected virtual void InitBackend () { backend = new Crow.XCB.XCBBackend (); //backend = new Crow.XLib.XLibBackend (); @@ -128,8 +129,10 @@ namespace Crow Keyboard.KeyUp += Keyboard_KeyUp; Keyboard.KeyPress += Keyboard_KeyPress; - initTooltip (); - initContextMenus (); + //initTooltip (); + //initContextMenus (); + + running = true; Thread t = new Thread (interfaceThread); t.IsBackground = true; @@ -168,10 +171,10 @@ namespace Crow void interfaceThread() { - while (true) { + while (running) { Update (); - backend.ProcessEvents (); + Thread.Sleep (1); } } @@ -208,6 +211,9 @@ namespace Crow } #endregion + public void ProcessEvents() { + backend.ProcessEvents (); + } public void Init () { CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture; @@ -575,10 +581,15 @@ namespace Crow _activeWidget = value; + #if DEBUG_FOCUS + NotifyValueChanged("ActiveWidget", _activeWidget); + #endif + if (_activeWidget != null) { _activeWidget.IsActive = true; #if DEBUG_FOCUS + NotifyValueChanged("ActiveWidget", _activeWidget); Debug.WriteLine("Active => " + _activeWidget.ToString()); }else Debug.WriteLine("Active => null"); @@ -599,6 +610,9 @@ namespace Crow _hoverWidget.IsHover = false; _hoverWidget = value; + #if DEBUG_FOCUS + NotifyValueChanged("HoverWidget", _hoverWidget); + #endif if (_hoverWidget != null) { @@ -621,6 +635,9 @@ namespace Crow if (_focusedWidget != null) _focusedWidget.HasFocus = false; _focusedWidget = value; + #if DEBUG_FOCUS + NotifyValueChanged("FocusedWidget", _focusedWidget); + #endif if (_focusedWidget != null) _focusedWidget.HasFocus = true; } @@ -810,7 +827,11 @@ namespace Crow } #if DEBUG_CLIP_RECTANGLE - clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5)); + ctx.LineWidth = 1; + ctx.SetSourceColor(Color.Magenta.AdjustAlpha (0.5)); + for (int i = 0; i < clipping.NumRectangles; i++) + ctx.Rectangle(clipping.GetRectangle(i)); + ctx.Stroke (); #endif clipping.Dispose (); diff --git a/src/Measure.cs b/src/Measure.cs index 0374f5d9..c40c6703 100644 --- a/src/Measure.cs +++ b/src/Measure.cs @@ -31,7 +31,7 @@ namespace Crow /// <summary> /// Measurement unit /// </summary> - public enum Unit { Pixel, Percent, Inherit } + public enum Unit {Undefined, Pixel, Percent, Inherit } /// <summary> /// Measure class allow proportional sizes as well as stretched and fit on content. /// </summary> @@ -114,7 +114,7 @@ namespace Crow public static Measure Parse(string s){ if (string.IsNullOrEmpty (s)) - return Measure.Stretched; + return default(Measure); string st = s.Trim (); int tmp = 0; diff --git a/src/Mono.Cairo/Surface.cs b/src/Mono.Cairo/Surface.cs index 6a55496a..e7a2a5e4 100644 --- a/src/Mono.Cairo/Surface.cs +++ b/src/Mono.Cairo/Surface.cs @@ -120,7 +120,7 @@ namespace Cairo { IntPtr p = NativeMethods.cairo_surface_create_similar ( this.Handle, content, width, height); - return new Cairo.Surface (p, true); + return Surface.Lookup(p, true); } ~Surface () @@ -152,6 +152,8 @@ namespace Cairo { NativeMethods.cairo_surface_destroy (handle); handle = IntPtr.Zero; } + public virtual void SetSize (int width, int height) { + } public Status Finish () { diff --git a/src/Mono.Cairo/XcbSurface.cs b/src/Mono.Cairo/XcbSurface.cs index 142ebf9e..b9995ee6 100644 --- a/src/Mono.Cairo/XcbSurface.cs +++ b/src/Mono.Cairo/XcbSurface.cs @@ -45,10 +45,10 @@ namespace Cairo { IntPtr ptr = NativeMethods.cairo_xcb_surface_create_for_bitmap (connection, bitmap, screen, width, height); return new XcbSurface (ptr, true); } - - public void SetSize (int width, int height) - { + public override void SetSize (int width, int height) + { NativeMethods.cairo_xcb_surface_set_size (Handle, width, height); + Console.WriteLine ("new size ({0},{1})", width, height); } } } diff --git a/src/Picture.cs b/src/Picture.cs index 3784780b..f2f45261 100644 --- a/src/Picture.cs +++ b/src/Picture.cs @@ -96,7 +96,7 @@ namespace Crow /// load the image for rendering from the stream given as argument /// </summary> /// <param name="stream">picture stream</param> - public abstract void Load(Interface iface, string path); + //public abstract void Load(Interface iface, string path); #endregion /// <summary> diff --git a/src/SvgPicture.cs b/src/SvgPicture.cs index f676a497..dee6c8e0 100644 --- a/src/SvgPicture.cs +++ b/src/SvgPicture.cs @@ -48,19 +48,20 @@ namespace Crow /// </summary> /// <param name="path">image path, may be embedded</param> public SvgPicture (string path) : base(path) - {} + { + Load (); + } #endregion - public override void Load (Interface iface, string path) - { - Path = path; - if (sharedResources.ContainsKey (path)) { - sharedPicture sp = sharedResources [path]; + void Load () + { + if (sharedResources.ContainsKey (Path)) { + sharedPicture sp = sharedResources [Path]; hSVG = (Rsvg.Handle)sp.Data; Dimensions = sp.Dims; return; } - using (Stream stream = iface.GetStreamFromPath (path)) { + using (Stream stream = Interface.StaticGetStreamFromPath (Path)) { using (MemoryStream ms = new MemoryStream ()) { stream.CopyTo (ms); @@ -68,7 +69,7 @@ namespace Crow Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height); } } - sharedResources [path] = new sharedPicture (hSVG, Dimensions); + sharedResources [Path] = new sharedPicture (hSVG, Dimensions); } public void LoadSvgFragment (string fragment) { diff --git a/src/debug/DbgEventTypeColors.cs b/src/debug/DbgEventTypeColors.cs new file mode 100644 index 00000000..e0881182 --- /dev/null +++ b/src/debug/DbgEventTypeColors.cs @@ -0,0 +1,77 @@ +// +// DbgEventTypeColors.cs +// +// Author: +// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// 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 Cairo; +using System.Linq; + +namespace Crow +{ + #if DEBUG_LOG + public class DbgEventTypeColors : GraphicObject + { + protected override void onDraw (Context gr) + { + base.onDraw (gr); + + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); + gr.FontOptions = Interface.FontRenderingOptions; + gr.Antialias = Interface.Antialias; + + DbgEvtType[] types = DbgLogViewer.colors.Keys.ToArray (); + Color[] colors = DbgLogViewer.colors.Values.ToArray (); + + Rectangle r = ClientRectangle; + FontExtents fe = gr.FontExtents; + + double penY = fe.Height + r.Top; + double penX = (double)r.Left; + + + for (int i = 0; i < types.Length; i++) { + string n = types [i].ToString(); + Color c = colors[i]; + Foreground.SetAsSource (gr); + + gr.MoveTo (penX + 25.0, penY - fe.Descent); + gr.ShowText (n); + + Rectangle rc = new Rectangle((int)penX, (int)(penY - fe.Height), 20, (int)fe.Height); + rc.Inflate (-2); + gr.Rectangle (rc); + gr.StrokePreserve (); + + gr.SetSourceColor (c); + gr.Fill (); + + penY += fe.Height; + + } + } + } + #endif +} + diff --git a/src/debug/DbgLogViewer.cs b/src/debug/DbgLogViewer.cs index 7c8a1bdf..6124d6f9 100644 --- a/src/debug/DbgLogViewer.cs +++ b/src/debug/DbgLogViewer.cs @@ -34,8 +34,12 @@ namespace Crow { public class DbgLogViewer : ScrollingObject { + public static Dictionary<DbgEvtType,Color> colors; + + public static Configuration colorsConf = new Configuration("dbgcolor.conf"); + #region debug viewer private classes - class DbgData { + public class DbgData { public int objInstanceNum; public LayoutingType layout; public LayoutingQueueItem.Result result; @@ -44,7 +48,7 @@ namespace Crow objInstanceNum = _obj; } } - class DbgEvent { + public class DbgEvent { public long begin, end; public DbgEvtType type; public DbgData data = null; @@ -99,7 +103,19 @@ namespace Crow } #endregion + public static void reloadColors () { + colors = new Dictionary<DbgEvtType, Color>(); + foreach (string n in colorsConf.Names) { + DbgEvtType t = (DbgEvtType)Enum.Parse (typeof(DbgEvtType), n); + Color c = colorsConf.Get<Color> (n); + colors.Add (t, c); + } + + } #region CTOR + static DbgLogViewer() { + reloadColors (); + } protected DbgLogViewer () : base(){} public DbgLogViewer (Interface iface) : base(iface){} #endregion @@ -156,8 +172,13 @@ namespace Crow void storeEvent (DbgEvent evt) { if (evt.data == null)//global events events.Add (evt); - else - objs.Where (o => o.instanceNum == evt.data.objInstanceNum).FirstOrDefault ().events.Add (evt); + else { + DbgGo go = objs.Where (o => o.instanceNum == evt.data.objInstanceNum).FirstOrDefault (); + if (go == null) + Console.WriteLine ("Unknown instance: " + evt.data.objInstanceNum); + else + go.events.Add (evt); + } } void loadDebugFile() { @@ -289,50 +310,7 @@ namespace Crow } } - Crow.Color getObjEventColor (DbgEvent evt) { - if (evt.type.HasFlag (DbgEvtType.GOLayouting)) { - if (evt.type == DbgEvtType.GOProcessLayouting) { - switch (evt.data.result) { - case LayoutingQueueItem.Result.Success: - return Crow.Color.Green; - case LayoutingQueueItem.Result.Deleted: - return Crow.Color.Red; - case LayoutingQueueItem.Result.Discarded: - return Crow.Color.DarkRed; - case LayoutingQueueItem.Result.Requeued: - return Crow.Color.Orange; - } - } else if (evt.type == DbgEvtType.GOProcessLayoutingWithNoParent) - return Color.IndianRed; - else - return Crow.Color.Blue; - } - switch (evt.type) { - case DbgEvtType.GOClassCreation: - return Color.GhostWhite; - case DbgEvtType.GOInitialization: - return Color.Cyan; - case DbgEvtType.GOClippingRegistration: - return Color.Cyan; - case DbgEvtType.GORegisterClip: - return Color.Cyan; - case DbgEvtType.GORegisterForGraphicUpdate: - return Color.Cyan; - case DbgEvtType.GOEnqueueForRepaint: - return Color.Cyan; - case DbgEvtType.GODraw: - return Color.Cyan; - case DbgEvtType.GORecreateCache: - return Color.Cyan; - case DbgEvtType.GOUpdateCacheAndPaintOnCTX: - return Color.Cyan; - case DbgEvtType.GOPaint: - return Color.Cyan; - case DbgEvtType.GONewDataSource: - return Color.Cyan; - } - return Crow.Color.RebeccaPurple; - } + protected override void onDraw (Cairo.Context gr) { @@ -341,7 +319,7 @@ namespace Crow gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize (Font.Size); gr.FontOptions = Interface.FontRenderingOptions; - gr.Antialias = Interface.Antialias; + gr.Antialias = Cairo.Antialias.None; if (objs == null) return; @@ -353,13 +331,19 @@ namespace Crow double penY = topMargin + ClientRectangle.Top; for (int i = 0; i < visibleLines; i++) { + if (i + ScrollY >= objs.Count) + break; DbgGo g = objs [i + ScrollY]; + foreach (DbgEvent evt in g.events) { + + if (evt.end - minTicks <= ScrollX) continue; if (evt.begin - minTicks > ScrollX + visibleTicks) break; + double x = xScale * (evt.begin - minTicks - ScrollX) ; double w = Math.Max (Math.Max(2.0, 2.0 * xScale), (double)(evt.end - evt.begin) * xScale); if (x < 0.0) { @@ -373,11 +357,32 @@ namespace Crow //if (x + w > cb.Right) // continue; - gr.SetSourceColor (getObjEventColor (evt)); + Color c = Color.Black; + + if (evt.type == DbgEvtType.GOProcessLayouting) { + switch (evt.data.result) { + case LayoutingQueueItem.Result.Success: + c = Crow.Color.Green; + break; + case LayoutingQueueItem.Result.Deleted: + c = Crow.Color.Red; + break; + case LayoutingQueueItem.Result.Discarded: + c = Crow.Color.OrangeRed; + break; + case LayoutingQueueItem.Result.Requeued: + c = Crow.Color.Orange; + break; + } + } else if (colors.ContainsKey (evt.type)) + c = colors [evt.type]; + else + System.Diagnostics.Debugger.Break (); + + gr.SetSourceColor (c); gr.Rectangle (x, penY, w, fe.Height); gr.Fill (); - } penY += fe.Height; @@ -458,7 +463,9 @@ namespace Crow gr.MoveTo (x- 0.5 * te.Width, penY - gr.FontExtents.Descent); gr.SetSourceColor (Crow.Color.Jet); gr.ShowText (s); + } + } public override void Paint (ref Cairo.Context ctx) { @@ -569,7 +576,9 @@ namespace Crow if (selStart >= 0 && IFace.Mouse.IsButtonDown(MouseButton.Left)) selEnd = currentTick; - RegisterForRedraw (); + if (RegisteredLayoutings == LayoutingType.None && !IsDirty) + IFace.EnqueueForRepaint (this); + } public override void onMouseDown (object sender, MouseButtonEventArgs e) { diff --git a/src/debug/DebugLogger.cs b/src/debug/DebugLogger.cs index 18e4ae19..38cbc2af 100644 --- a/src/debug/DebugLogger.cs +++ b/src/debug/DebugLogger.cs @@ -65,6 +65,11 @@ namespace Crow GOUpdateCacheAndPaintOnCTX = 0x020c, GOPaint = 0x020d, GONewDataSource = 0x020e, + GOLock = 0x0800, + GOLockUpdate = 0x0a01, + GOLockClipping = 0x0a02, + GOLockRender = 0x0a03, + GOLockLayouting = 0x0a04, } /// <summary> @@ -162,7 +167,8 @@ namespace Crow s.WriteLine ("[Events]"); foreach (DbgEvent e in events) - s.WriteLine (e.ToString ()); + if (e != null) + s.WriteLine (e.ToString ()); } } } |