diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-10-21 18:55:33 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-10-21 18:55:33 +0200 |
| commit | f31ffd683210c50b777dce4e76d0d9912ca925a8 (patch) | |
| tree | de0783b77f39de9fa7ccf04fbd8b53bb17db9905 | |
| parent | 671366cd56e7d6b2a2afb0839e7fb0f895cb2df3 (diff) | |
file dialog
| -rw-r--r-- | GOLib.csproj | 5 | ||||
| -rw-r--r-- | Templates/FileDialog.goml | 24 | ||||
| -rw-r--r-- | Templates/ScrollingListBox.goml | 13 | ||||
| -rwxr-xr-x | Templates/imgItemTemplate.goml | 8 | ||||
| -rwxr-xr-x | Templates/tmpDirItem.goml | 11 | ||||
| -rw-r--r-- | Tests/GOLIBTest_DirViewer.cs | 10 | ||||
| -rw-r--r-- | Tests/GOLIBTests.cs | 5 | ||||
| -rwxr-xr-x | Tests/Interfaces/testDirViewer.goml | 16 | ||||
| -rw-r--r-- | Tests/Interfaces/testFileDialog.goml | 3 | ||||
| -rwxr-xr-x | Tests/Interfaces/testWindow.goml | 1 | ||||
| -rw-r--r-- | Tests/Tests.csproj | 5 | ||||
| -rw-r--r-- | src/GraphicObjects/FileDialog.cs | 141 | ||||
| -rwxr-xr-x | src/GraphicObjects/Image.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/Scroller.cs | 15 | ||||
| -rwxr-xr-x | src/OpenTKGameWindow.cs | 2 |
15 files changed, 244 insertions, 16 deletions
diff --git a/GOLib.csproj b/GOLib.csproj index 2cd31f89..652fccc8 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -128,6 +128,7 @@ <Compile Include="src\GraphicObjects\Combobox.cs" />
<Compile Include="src\SelectionChangeEventArgs.cs" />
<Compile Include="src\ValueChangeEventArgs.cs" />
+ <Compile Include="src\GraphicObjects\FileDialog.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
@@ -207,6 +208,10 @@ <EmbeddedResource Include="Templates\Groupbox.goml" />
<EmbeddedResource Include="Templates\Combobox.goml" />
<EmbeddedResource Include="Templates\ComboboxOverlay.goml" />
+ <EmbeddedResource Include="Templates\FileDialog.goml" />
+ <EmbeddedResource Include="Templates\tmpDirItem.goml" />
+ <EmbeddedResource Include="Templates\ScrollingListBox.goml" />
+ <EmbeddedResource Include="Templates\imgItemTemplate.goml" />
</ItemGroup>
<ItemGroup>
<None Include="Images\Icons\Cursors\hand" />
diff --git a/Templates/FileDialog.goml b/Templates/FileDialog.goml new file mode 100644 index 00000000..c7ca3af3 --- /dev/null +++ b/Templates/FileDialog.goml @@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<Window Title="OpenFile" Height="300" Width="500"> + <VerticalStack Margin="5"> + <TextBoxWidget Margin="1" Width="0" Height="-1" Text="{CurrentPath}"/> + <HorizontalStack > + <ListBox Data="{Directories}" Width="-1" Height="0" + Background="0,5;0,5;0,5;0,5" + SelectedItemChanged="OnSelectedItemChanged" + Template="#go.Templates.ScrollingListBox.goml" + ItemTemplate="#go.Templates.tmpDirItem.goml" > + </ListBox> + <ListBox Data="{Files}" Width="0" Height="0" + Background="0,5;0,5;0,5;0,5" + SelectedItemChanged="onFileListItemChanged" + Template="#go.Templates.ScrollingListBox.goml" + ItemTemplate="#go.Templates.imgItemTemplate.goml"> + </ListBox> + </HorizontalStack> + <HorizontalStack Fit="true" HorizontalAlignment="Right"> + <Button Text="Ok" MouseClick="onFileSelect"/> + <Button Text="Cancel"/> + </HorizontalStack> + </VerticalStack> +</Window> diff --git a/Templates/ScrollingListBox.goml b/Templates/ScrollingListBox.goml new file mode 100644 index 00000000..8883847f --- /dev/null +++ b/Templates/ScrollingListBox.goml @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<Border BorderWidth="1" MinimumSize="20;20" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}"> + <HorizontalStack Margin="1" Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}"> + <Scroller Name="scroller1" Height="{../../../TemplatedHeight}" Width="{../../../TemplatedWidth}" + Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Scroll}"> + <VerticalStack Width="{../../../../TemplatedWidth}" Height="-1" + Name="List" Margin="0" VerticalAlignment="Top" /> + </Scroller> + <Scrollbar Name="scrollbar1" Scroll="{../scroller1.ScrollY}" + MaximumScroll="{../scroller1.MaximumScroll}" Orientation="Vertical" + Width="10" Height="{../../../TemplatedHeight}" /> + </HorizontalStack> +</Border>
\ No newline at end of file diff --git a/Templates/imgItemTemplate.goml b/Templates/imgItemTemplate.goml new file mode 100755 index 00000000..b26276ff --- /dev/null +++ b/Templates/imgItemTemplate.goml @@ -0,0 +1,8 @@ +<?xml version="1.0"?>
+ <VerticalStack Width="0" Height="-1" Focusable="true"
+ MouseEnter="{Background=BlueCrayola}"
+ MouseLeave="{Background=Transparent}">
+ <Image Width="-1" Height="-1" Path="{FullName}" MaximumSize="80;80"/>
+ <Label Text="{Name}" Width="-1" Height="-1" Margin="0" MaximumSize="100;0"/>
+ </VerticalStack>
+
diff --git a/Templates/tmpDirItem.goml b/Templates/tmpDirItem.goml new file mode 100755 index 00000000..de75a919 --- /dev/null +++ b/Templates/tmpDirItem.goml @@ -0,0 +1,11 @@ +<?xml version="1.0"?>
+ <HorizontalStack Width="-1" Height="-1" Focusable="true"
+ HorizontalAlignment="Left"
+ MouseEnter="{Background=BlueCrayola}"
+ MouseLeave="{Background=Transparent}">
+ <Image Width="16" Height="16" Path="#Tests.image.folder1.svg" SvgSub="{Attributes}"/>
+ <Label Text="{Name}" Width="-1" Height="-1" Margin="0"/>
+<!-- <Label Text="{Attributes}" Width="-1" Height="-1" Margin="0"/>
+ <Label Text="{Extension}" Width="-1" Height="-1" Margin="0"/>-->
+ </HorizontalStack>
+
diff --git a/Tests/GOLIBTest_DirViewer.cs b/Tests/GOLIBTest_DirViewer.cs index 9632e665..04ef3871 100644 --- a/Tests/GOLIBTest_DirViewer.cs +++ b/Tests/GOLIBTest_DirViewer.cs @@ -35,6 +35,7 @@ namespace test2 {}
public DirContainer CurDir;
+ FileDialog dialog;
protected override void OnLoad (EventArgs e)
{
@@ -42,9 +43,12 @@ namespace test2 CurDir = new DirContainer(new DirectoryInfo ("/home/jp/"));
- GraphicObject dv = Interface.Load ("Interfaces/testDirViewer.goml");
- this.AddWidget(dv);
- dv.DataSource = CurDir;
+// GraphicObject dv = Interface.Load ("Interfaces/testDirViewer.goml");
+// this.AddWidget(dv);
+// dv.DataSource = CurDir;
+ dialog = new FileDialog();
+ dialog.SearchPattern = ".png|.jpg|.jpeg|.gif|.svg";
+ dialog.Show ();
//LoadInterface("Interfaces/testTypeViewer.goml", out g);
}
diff --git a/Tests/GOLIBTests.cs b/Tests/GOLIBTests.cs index 2c1563ed..4ceb17e0 100644 --- a/Tests/GOLIBTests.cs +++ b/Tests/GOLIBTests.cs @@ -140,7 +140,10 @@ namespace test }
protected override void OnKeyDown (KeyboardKeyEventArgs e)
{
- base.OnKeyDown (e);
+ if (FocusedWidget != null) {
+ base.OnKeyDown (e);
+ return;
+ }
if (e.Key == Key.Escape) {
this.Quit ();
return;
diff --git a/Tests/Interfaces/testDirViewer.goml b/Tests/Interfaces/testDirViewer.goml index 1c418126..1e3ebd31 100755 --- a/Tests/Interfaces/testDirViewer.goml +++ b/Tests/Interfaces/testDirViewer.goml @@ -8,17 +8,17 @@ Background="0,5;0,5;0,5;0,5" SelectedItemChanged="OnSelectedItemChanged" ItemTemplate="Interfaces/tmpDirItem.goml" > -<!-- <Template> - <Border Width="0" Height="0" BorderWidth="1" Margin="1" MinimumSize="0;100" > - <HorizontalStack Width="0" Height="0"> - <Scroller Name="scroller1" Height="0" Width="0" - Margin="10" VerticalScrolling="true" ScrollY="{../scrollbar1.Scroll}"> - <VerticalStack Width="0" Height="-1" Name="List" Margin="0" VerticalAlignment="Top"/> + <Template> + <Border BorderWidth="1" MinimumSize="20;20" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}"> + <HorizontalStack Margin="1" Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}"> + <Scroller Name="scroller1" Height="{../../../TemplatedHeight}" Width="{../../../TemplatedWidth}" + Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Scroll}"> + <VerticalStack Width="{../../../../TemplatedWidth}" Height="-1" Name="List" Margin="0" VerticalAlignment="Top"/> </Scroller> <Scrollbar Name="scrollbar1" Scroll="{../scroller1.ScrollY}" MaximumScroll="{../scroller1.MaximumScroll}" - Orientation="Vertical" Width="10" /> + Orientation="Vertical" Width="10" Height="{../../../TemplatedHeight}" /> </HorizontalStack> </Border> - </Template>--> + </Template> </ListBox> </VerticalStack> diff --git a/Tests/Interfaces/testFileDialog.goml b/Tests/Interfaces/testFileDialog.goml new file mode 100644 index 00000000..715ff2fa --- /dev/null +++ b/Tests/Interfaces/testFileDialog.goml @@ -0,0 +1,3 @@ +<?xml version="1.0"?> +<FileDialog Width="500" Height="300"/> + diff --git a/Tests/Interfaces/testWindow.goml b/Tests/Interfaces/testWindow.goml index 740cfc53..255efa69 100755 --- a/Tests/Interfaces/testWindow.goml +++ b/Tests/Interfaces/testWindow.goml @@ -1,5 +1,4 @@ <?xml version="1.0"?>
-<!--<Group>-->
<Window Name="window1" Left="10" Top="10" Title="Test window"
Width="250" Height="300" >
<VerticalStack Name="contentVSStack" Margin="10" Spacing="10">
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index f9db1b21..e9eccb48 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,7 +8,7 @@ <OutputType>Exe</OutputType> <RootNamespace>Tests</RootNamespace> <AssemblyName>Tests</AssemblyName> - <StartupObject>test.GOLIBTests</StartupObject> + <StartupObject>test2.GOLIBTest_DirViewer</StartupObject> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <OutputPath>..\bin\$(configuration)</OutputPath> <IntermediateOutputPath>obj\$(configuration)</IntermediateOutputPath> @@ -178,6 +178,9 @@ <None Include="Interfaces\testCombobox.goml"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="Interfaces\testFileDialog.goml"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> <ItemGroup> <Folder Include="Interfaces\" /> diff --git a/src/GraphicObjects/FileDialog.cs b/src/GraphicObjects/FileDialog.cs new file mode 100644 index 00000000..3a5e6cb3 --- /dev/null +++ b/src/GraphicObjects/FileDialog.cs @@ -0,0 +1,141 @@ +// +// FileDialog.cs +// +// Author: +// Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// Copyright (c) 2015 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +using System; +using System.Xml.Serialization; +using System.ComponentModel; +using System.IO; +using System.Collections.Generic; +using System.Diagnostics; +using OpenTK.Input; +using System.Linq; +using System.Text.RegularExpressions; + +namespace go +{ + public class FileDialog: IValueChange + { + #region IValueChange implementation + public event EventHandler<ValueChangeEventArgs> ValueChanged; + public virtual void NotifyValueChanged(string MemberName, object _value) + { + ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); + } + #endregion + + Window window; + DirectoryInfo currentDir; + FileInfo selectedFile; + string searchPattern = "*"; + + #region CTOR + public FileDialog () + { + currentDir = new DirectoryInfo (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); + window = Interface.Load("#go.Templates.FileDialog.goml") as Window; + window.DataSource = this; + } + #endregion + + public string CurrentPath { + get { return currentDir.FullName; } + set { + currentDir = new DirectoryInfo (value); + NotifyValueChanged ("CurrentPath", CurrentPath); + } + } + public string SearchPattern { + get { return searchPattern; } + set { + searchPattern = value; + NotifyValueChanged ("Files", Files); + } + } + + public DirectoryInfo[] Directories + { + get { + //currentDir.GetDirectories + List<DirectoryInfo> tmp = currentDir.GetDirectories ().Where(fi => !fi.Attributes.HasFlag(FileAttributes.Hidden)).ToList(); + if (currentDir.Parent != null) + tmp.Insert (0, currentDir.Parent); + return tmp.ToArray (); + } + } + public FileInfo[] Files + { + get { + string[] exts = searchPattern.Replace("*","").Split ('|'); + //return currentDir.GetFiles (searchPattern).Where(fi => !fi.Attributes.HasFlag(FileAttributes.Hidden)).ToArray(); + return currentDir.GetFiles().Where(f => exts.Any + (x => f.Name.EndsWith (x, StringComparison.InvariantCultureIgnoreCase))).ToArray(); + } + } + + public void Show(){ + OpenTKGameWindow.currentWindow.AddWidget(window); + } + + void OnSelectedItemChanged (object sender, SelectionChangeEventArgs e) + { + currentDir = e.NewValue as DirectoryInfo; + NotifyValueChanged ("CurrentPath", CurrentPath); + NotifyValueChanged ("Directories", Directories); + NotifyValueChanged ("Files", Files); + + } + void onFileListItemChanged (object sender, SelectionChangeEventArgs e) + { + selectedFile = e.NewValue as FileInfo; + } + void onFileSelect(object sender, OpenTK.Input.MouseButtonEventArgs e){ + OpenTKGameWindow.currentWindow.DeleteWidget(window); + } + } + public class DirContainer: IValueChange + { + #region IValueChange implementation + public event EventHandler<ValueChangeEventArgs> ValueChanged; + public void NotifyValueChanged(string name, object value) + { + ValueChanged.Raise (this, new ValueChangeEventArgs (name, value)); + } + #endregion + + public DirectoryInfo CurDir; + public DirContainer(DirectoryInfo _dir){ + CurDir = _dir; + } + public string Name { + get { return CurDir.Name; } + } + + void onDirUp(object sender, MouseButtonEventArgs e) + { + + } + public void onMouseDown(object sender, MouseButtonEventArgs e) + { + Debug.WriteLine (sender.ToString ()); + } + + } +} + diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index 10631835..71d568fd 100755 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -76,6 +76,7 @@ namespace go _pic = new BmpPicture ();
_pic.LoadImage (path);
+ registerForGraphicUpdate ();
}
#endregion
diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index 8c2303cc..3f78b598 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -22,6 +22,8 @@ namespace go bool _scrollbarVisible;
double _scrollX = 0.0;
double _scrollY = 0.0;
+ int scrollSpeed;
+
#region public properties
@@ -92,7 +94,14 @@ namespace go }
}
- public static int ScrollSpeed = 10;
+ [XmlAttributeAttribute][DefaultValue(30)]
+ public int ScrollSpeed {
+ get { return scrollSpeed; }
+ set {
+ scrollSpeed = value;
+ ValueChanged.Raise(this, new ValueChangeEventArgs("ScrollSpeed", scrollSpeed));
+ }
+ }
#endregion
@@ -147,6 +156,10 @@ namespace go #region Mouse handling
public override bool MouseIsIn (Point m)
{
+ Debug.WriteLine ("Mouse in scroller: {0} scr coord:{1} mouse:{2}",
+ base.ScreenCoordinates (Slot).ContainsOrIsEqual (m),
+ base.ScreenCoordinates (Slot), m);
+
return Visible ? base.ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false;
}
public override void checkHoverWidget (MouseMoveEventArgs e)
diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 7cc84bca..4e5584c8 100755 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -32,7 +32,7 @@ namespace go // : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title)
{
//VSync = VSyncMode.On;
-
+ currentWindow = this;
//Load cursors
XCursor.Cross = XCursorFile.Load("#go.Images.Icons.Cursors.cross").Cursors[0];
XCursor.Default = XCursorFile.Load("#go.Images.Icons.Cursors.arrow").Cursors[0];
|