diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-24 01:54:22 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-24 01:54:22 +0100 |
| commit | af3dc048f37ef4340feebbfb0a9b612ae99b559b (patch) | |
| tree | 3ecd623fc858acf33f8720a14ffc12939b69d3e1 | |
| parent | f987a58bfb6df496a4ca82f6425d27a421269e8b (diff) | |
maximize and minimize for window
| -rw-r--r-- | Crow.csproj | 6 | ||||
| -rw-r--r-- | Default.style | 7 | ||||
| -rw-r--r-- | Images/Icons/exit.svg | 54 | ||||
| -rw-r--r-- | Images/Icons/maximize.svg | 11 | ||||
| -rw-r--r-- | Images/Icons/minimize.svg | 11 | ||||
| -rw-r--r-- | Images/Icons/normalize.svg | 22 | ||||
| -rwxr-xr-x | Templates/ToolWindow.template | 24 | ||||
| -rwxr-xr-x | Templates/Window.template | 23 | ||||
| -rw-r--r-- | src/GraphicObjects/Window.cs | 131 |
9 files changed, 193 insertions, 96 deletions
diff --git a/Crow.csproj b/Crow.csproj index b541152c..d66d6f66 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -290,6 +290,12 @@ <EmbeddedResource Include="Templates\ColorPicker.template"> <LogicalName>Crow.ColorPicker.template</LogicalName> </EmbeddedResource> + <EmbeddedResource Include="Templates\ToolWindow.template"> + <LogicalName>Crow.ToolWindow.template</LogicalName> + </EmbeddedResource> + <EmbeddedResource Include="Images\Icons\maximize.svg" /> + <EmbeddedResource Include="Images\Icons\minimize.svg" /> + <EmbeddedResource Include="Images\Icons\normalize.svg" /> </ItemGroup> <ItemGroup> <None Include="README.md" /> diff --git a/Default.style b/Default.style index dc8abd86..de3e8d8c 100644 --- a/Default.style +++ b/Default.style @@ -62,6 +62,13 @@ TextBox { } Window { Focusable = true; + MinimumSize=5,5; + Width = 150; + Height = 150; +} +ToolWindow { + Template = #Crow.ToolWindow.template; + Focusable = true; MinimumSize=50,50; Width = 150; Height = 150; diff --git a/Images/Icons/exit.svg b/Images/Icons/exit.svg index 3d688cc7..cb8d1c27 100644 --- a/Images/Icons/exit.svg +++ b/Images/Icons/exit.svg @@ -1,62 +1,10 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- Created with Inkscape (http://www.inkscape.org/) --> - <svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="64" height="64" - viewBox="0 0 64 64.000002" - id="svg2" - version="1.1" - inkscape:version="0.91 r13725" - sodipodi:docname="exit.svg"> - <defs - id="defs4" /> - <sodipodi:namedview - id="base" - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1.0" - inkscape:pageopacity="0.0" - inkscape:pageshadow="2" - inkscape:zoom="2.6992188" - inkscape:cx="-13.949137" - inkscape:cy="63.946457" - inkscape:document-units="px" - inkscape:current-layer="svg2" - showgrid="false" - units="px" - inkscape:window-width="1280" - inkscape:window-height="984" - inkscape:window-x="0" - inkscape:window-y="16" - inkscape:window-maximized="1" /> - <metadata - id="metadata7"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> - </cc:Work> - </rdf:RDF> - </metadata> - <rect - style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:8.89073467;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:0;stroke-dasharray:none;stroke-opacity:1" - id="rect4136" - width="55.122551" - height="55.122551" - x="4.4468598" - y="4.3914709" - ry="8.8907347" /> + viewBox="0 0 64 64"> <path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:9;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="m 13.884262,15.143117 c 24.231966,13.49131 34.18672,34.186719 34.18672,34.186719" diff --git a/Images/Icons/maximize.svg b/Images/Icons/maximize.svg new file mode 100644 index 00000000..b70604a6 --- /dev/null +++ b/Images/Icons/maximize.svg @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + width="14" + height="14" + viewBox="0 0 14 14"> + <path + style="fill:none;stroke:#ffffff;stroke-width:2" + d="m 2,2 10,0 0,10 -10,0 z"/> +</svg> diff --git a/Images/Icons/minimize.svg b/Images/Icons/minimize.svg new file mode 100644 index 00000000..dc3dcd2e --- /dev/null +++ b/Images/Icons/minimize.svg @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + width="64" + height="64" + viewBox="0 0 14 14"> + <path + style="fill:#ffffff;stroke:none" + d="m 1,6 12,0 0,4 -12,0 z"/> +</svg> diff --git a/Images/Icons/normalize.svg b/Images/Icons/normalize.svg new file mode 100644 index 00000000..b8b44bd5 --- /dev/null +++ b/Images/Icons/normalize.svg @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + width="14" + height="14" + viewBox="0 0 14 14"> +<!-- <rect y="7" x="7" height="40" width="40" + style="opacity:1;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:3;stroke-opacity:1" /> + <rect y="7" x="7" height="10" width="40" + style="opacity:1;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:3;stroke-opacity:1" /> + <rect y="17" x="17" height="40" width="40" + style="opacity:1;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:3;stroke-opacity:1" /> + <rect y="17" x="17" height="10" width="40" + style="opacity:1;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:3;stroke-opacity:1" />--> + <path + style="fill:none;stroke:#ffffff;stroke-width:1" + d="m 1,1 8,0 0,8 -8,0 z"/> + <path + style="fill:none;stroke:#ffffff;stroke-width:1" + d="m 4,4 8,0 0,8 -8,0 z"/> +</svg> diff --git a/Templates/ToolWindow.template b/Templates/ToolWindow.template new file mode 100755 index 00000000..7325193c --- /dev/null +++ b/Templates/ToolWindow.template @@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<Border BorderWidth="1" Foreground="White" CornerRadius="{./CornerRadius}" + Background="{./Background}" + MouseEnter="./onBorderMouseEnter" + MouseLeave="./onBorderMouseLeave"> + <VerticalStack Spacing="0"> +<!-- <Border Name="TitleBar" BorderWidth="1" Foreground="White" Width="{./WidthPolicy}" Height="Fit" + Background="vgradient|0:0.4,0.6,0.0,0.5|1:0.0,0.8,0.8,0.9">--> + <HorizontalStack Background="vgradient|0:0.4,0.6,0.0,0.5|1:0.0,0.8,0.8,0.9" + Name="hs" Margin="2" Spacing="0" Height="Fit"> + <GraphicObject Width="5"/> + <Image Margin="1" Width="12" Height="12" Path="{./Icon}"/> + <Label Width="Stretched" Foreground="White" Margin="1" TextAlignment="Center" Text="{./Title}" /> + <Border CornerRadius="6" BorderWidth="1" Foreground="Transparent" Height="12" Width="12" + MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}"> + <Image Focusable="true" Name="Image" Margin="0" Width="Stretched" Height="Stretched" Path="#Crow.Images.Icons.exit2.svg" + MouseClick="./butQuitPress"/> + </Border> + <GraphicObject Width="5"/> + </HorizontalStack> +<!-- </Border>--> + <Container Name="Content" MinimumSize="50,50" Background="0.5,0.5,0.5,0.5"/> + </VerticalStack> +</Border> diff --git a/Templates/Window.template b/Templates/Window.template index 7325193c..d729021c 100755 --- a/Templates/Window.template +++ b/Templates/Window.template @@ -10,15 +10,30 @@ Name="hs" Margin="2" Spacing="0" Height="Fit"> <GraphicObject Width="5"/> <Image Margin="1" Width="12" Height="12" Path="{./Icon}"/> - <Label Width="Stretched" Foreground="White" Margin="1" TextAlignment="Center" Text="{./Title}" /> - <Border CornerRadius="6" BorderWidth="1" Foreground="Transparent" Height="12" Width="12" + <Label Width="Stretched" Foreground="White" Margin="2" TextAlignment="Center" Text="{./Title}" /> + <Border Visible="{./ShowMinimize}" BorderWidth="1" Foreground="Transparent" Height="12" Width="12" MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}"> - <Image Focusable="true" Name="Image" Margin="0" Width="Stretched" Height="Stretched" Path="#Crow.Images.Icons.exit2.svg" + <Image Focusable="true" Path="#Crow.Images.Icons.minimize.svg" + MouseClick="./onMinimized"/> + </Border> + <Border Visible="{./ShowNormal}" BorderWidth="1" Foreground="Transparent" Height="12" Width="12" + MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}"> + <Image Focusable="true" Path="#Crow.Images.Icons.normalize.svg" + MouseClick="./onUnmaximized"/> + </Border> + <Border Visible="{./ShowMaximize}" BorderWidth="1" Foreground="Transparent" Height="12" Width="12" + MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}"> + <Image Focusable="true" Path="#Crow.Images.Icons.maximize.svg" + MouseClick="./onMaximized"/> + </Border> + <Border BorderWidth="1" Foreground="Transparent" Height="14" Width="14" + MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}"> + <Image Focusable="true" Path="#Crow.Images.Icons.exit2.svg" MouseClick="./butQuitPress"/> </Border> <GraphicObject Width="5"/> </HorizontalStack> <!-- </Border>--> - <Container Name="Content" MinimumSize="50,50" Background="0.5,0.5,0.5,0.5"/> + <Container Name="Content" MinimumSize="0,0" Background="0.5,0.5,0.5,0.5"/> </VerticalStack> </Border> diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index 86f05d86..0b203dfd 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -46,15 +46,19 @@ namespace Crow bool _resizable; bool _movable; bool hoverBorder = false; - bool isMaximized = false; - Measure savedH, savedW; + + Rectangle savedBounds; + bool _minimized = false; Container _contentContainer; Direction currentDirection = Direction.None; + #region Events public event EventHandler Closing; public event EventHandler Maximized; public event EventHandler Unmaximized; + public event EventHandler Minimize; + #endregion #region CTOR public Window () : base() { @@ -64,73 +68,98 @@ namespace Crow #region TemplatedContainer overrides public override GraphicObject Content { - get { - return _contentContainer == null ? null : _contentContainer.Child; - } - set { - _contentContainer.SetChild(value); - } + get { return _contentContainer == null ? null : _contentContainer.Child; } + set { _contentContainer.SetChild(value); } } protected override void loadTemplate(GraphicObject template = null) { base.loadTemplate (template); _contentContainer = this.child.FindByName ("Content") as Container; + + NotifyValueChanged ("ShowNormal", false); + NotifyValueChanged ("ShowMinimize", true); + NotifyValueChanged ("ShowMaximize", true); } #endregion #region public properties - [XmlAttributeAttribute()][DefaultValue("Window")] + [XmlAttributeAttribute][DefaultValue("Window")] public string Title { get { return _title; } set { + if (_title == value) + return; _title = value; NotifyValueChanged ("Title", _title); } } - [XmlAttributeAttribute()][DefaultValue("#Crow.Images.Icons.crow.png")] + [XmlAttributeAttribute][DefaultValue("#Crow.Images.Icons.crow.png")] public string Icon { get { return _icon; } set { + if (_icon == value) + return; _icon = value; NotifyValueChanged ("Icon", _icon); } } - [XmlAttributeAttribute()][DefaultValue(true)] + [XmlAttributeAttribute][DefaultValue(true)] public bool Resizable { get { return _resizable; } set { + if (_resizable == value) + return; _resizable = value; NotifyValueChanged ("Resizable", _resizable); } } - [XmlAttributeAttribute()][DefaultValue(true)] + [XmlAttributeAttribute][DefaultValue(true)] public bool Movable { get { return _movable; } set { + if (_movable == value) + return; _movable = value; NotifyValueChanged ("Movable", _movable); } } - [XmlAttributeAttribute()][DefaultValue(false)] - public bool IsMaximized { - get { return isMaximized; } + [XmlAttributeAttribute][DefaultValue(false)] + public bool IsMinimized { + get { return _minimized; } set{ - if (value == isMaximized) + if (value == IsMinimized) return; - isMaximized = value; - if (isMaximized) - onMaximized (this, null); - else - onUnmaximized (this, null); + _minimized = value; + _contentContainer.Visible = !_minimized; - NotifyValueChanged ("IsMaximized", isMaximized); + NotifyValueChanged ("IsMinimized", _minimized); } } + [XmlIgnore]public bool IsMaximized { + get { return Width == Measure.Stretched & Height == Measure.Stretched & !_minimized; } + } + [XmlIgnore]public bool IsNormal { + get { return !(IsMaximized|_minimized); } + } +// [XmlAttributeAttribute()][DefaultValue(WindowState.Normal)] +// public virtual WindowState State { +// get { return _state; } +// set { +// if (_state == value) +// return; +// _state = value; +// NotifyValueChanged ("State", _state); +// NotifyValueChanged ("IsNormal", IsNormal); +// NotifyValueChanged ("IsMaximized", IsMaximized); +// NotifyValueChanged ("IsMinimized", IsMinimized); +// NotifyValueChanged ("IsNotMinimized", IsNotMinimized); +// } +// } #endregion #region GraphicObject Overrides @@ -219,14 +248,6 @@ namespace Crow return; } } -// GraphicObject firstFocusableAncestor = otkgw.hoverWidget; -// while (firstFocusableAncestor != this) { -// if (firstFocusableAncestor == null) -// return; -// if (firstFocusableAncestor.Focusable) -// return; -// firstFocusableAncestor = firstFocusableAncestor.Parent as GraphicObject; -// } if (Resizable) { Direction lastDir = currentDirection; @@ -289,21 +310,56 @@ namespace Crow base.onMouseDown (sender, e); } #endregion + protected void onMaximized (object sender, EventArgs e){ - savedW = this.Width; - savedH = this.Height; - this.Width = Measure.Stretched; - this.Height = Measure.Stretched; + lock (CurrentInterface.LayoutMutex) { + if (!IsMinimized) + savedBounds = this.LastPaintedSlot; + this.Left = this.Top = 0; + this.RegisterForLayouting (LayoutingType.Positioning); + this.Width = this.Height = Measure.Stretched; + IsMinimized = false; + Resizable = false; + NotifyValueChanged ("ShowNormal", true); + NotifyValueChanged ("ShowMinimize", true); + NotifyValueChanged ("ShowMaximize", false); + } Maximized.Raise (sender, e); + + + } protected void onUnmaximized (object sender, EventArgs e){ - this.Width = savedW; - this.Height = savedH; + lock (CurrentInterface.LayoutMutex) { + this.Left = savedBounds.Left; + this.Top = savedBounds.Top; + this.Width = savedBounds.Width; + this.Height = savedBounds.Height; + IsMinimized = false; + Resizable = true; + NotifyValueChanged ("ShowNormal", false); + NotifyValueChanged ("ShowMinimize", true); + NotifyValueChanged ("ShowMaximize", true); + } Unmaximized.Raise (sender, e); } + protected void onMinimized (object sender, EventArgs e){ + lock (CurrentInterface.LayoutMutex) { + if (IsNormal) + savedBounds = this.LastPaintedSlot; + Width = 200; + Height = 20; + Resizable = false; + IsMinimized = true; + NotifyValueChanged ("ShowNormal", true); + NotifyValueChanged ("ShowMinimize", false); + NotifyValueChanged ("ShowMaximize", true); + } + Minimize.Raise (sender, e); + } protected void onBorderMouseLeave (object sender, MouseMoveEventArgs e) { hoverBorder = false; @@ -316,9 +372,6 @@ namespace Crow } - protected void butMaximizePress (object sender, MouseButtonEventArgs e){ - IsMaximized = !IsMaximized; - } protected void butQuitPress (object sender, MouseButtonEventArgs e) { CurrentInterface.MouseCursor = XCursor.Default; |