Browse Source

Merge branch 'perspex-gallery' of https://github.com/ncarrillo/Perspex into ncarrillo-perspex-gallery

pull/160/head
Steven Kirk 11 years ago
parent
commit
1c519bfb3c
  1. 3
      samples/TestApplication/App.cs
  2. 123
      samples/TestApplication/GalleryStyle.cs
  3. 8
      samples/TestApplication/Item.cs
  4. 16
      samples/TestApplication/Node.cs
  5. 1061
      samples/TestApplication/Program.cs
  6. 10
      samples/TestApplication/TestApplication.csproj
  7. BIN
      samples/TestApplication/pattern.jpg
  8. 32
      src/Gtk/Perspex.Cairo/CairoExtensions.cs
  9. 57
      src/Gtk/Perspex.Cairo/Media/DrawingContext.cs
  10. 8
      src/Gtk/Perspex.Cairo/Media/SolidColorBrushImpl.cs
  11. 41
      src/Gtk/Perspex.Cairo/Media/StreamGeometryContextImpl.cs
  12. 29
      src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs
  13. 2
      src/Gtk/Perspex.Cairo/Media/TileBrushes.cs
  14. 4
      src/Gtk/Perspex.Cairo/Perspex.Cairo.csproj
  15. 2
      src/Gtk/Perspex.Cairo/packages.config
  16. 3
      src/Gtk/Perspex.Gtk/WindowImpl.cs
  17. 17
      src/Perspex.Themes.Default/ButtonStyle.cs
  18. 4
      src/Perspex.Themes.Default/CheckBoxStyle.cs
  19. 2
      src/Perspex.Themes.Default/TabItemStyle.cs
  20. 17
      src/Perspex.Themes.Default/ToggleButtonStyle.cs

3
samples/TestApplication/App.cs

@ -12,8 +12,9 @@ namespace TestApplication
public App()
{
RegisterServices();
InitializeSubsystems((int)Environment.OSVersion.Platform);
InitializeSubsystems((int)Environment.OSVersion.Platform);
Styles = new DefaultTheme();
Styles.Add(new SampleTabStyle());
}
}
}

123
samples/TestApplication/GalleryStyle.cs

@ -0,0 +1,123 @@
using Perspex;
using Perspex.Controls;
using Perspex.Controls.Presenters;
using Perspex.Controls.Primitives;
using Perspex.Controls.Templates;
using Perspex.Media;
using Perspex.Styling;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApplication
{
internal class SampleTabStyle : Styles
{
public SampleTabStyle()
{
this.AddRange(new[]
{
new Style (s => s.Class(":container").OfType<TabControl> ())
{
Setters = new[]
{
new Setter (TemplatedControl.TemplateProperty, new ControlTemplate<TabControl> (TabControlTemplate))
}
},
new Style(s => s.Class(":container").OfType<TabControl>().Child().Child().Child().Child().Child().OfType<TabItem>())
{
Setters = new[]
{
new Setter (TemplatedControl.TemplateProperty, new ControlTemplate<TabItem> (TabItemTemplate)),
}
},
new Style(s => s.Name("internalStrip").OfType<TabStrip>().Child().OfType<TabItem>())
{
Setters = new[]
{
new Setter(TemplatedControl.FontSizeProperty, 14.0),
new Setter(TemplatedControl.ForegroundProperty, Brushes.White)
}
},
new Style(s => s.Name("internalStrip").OfType<TabStrip>().Child().OfType<TabItem>().Class("selected"))
{
Setters = new[]
{
new Setter(TemplatedControl.ForegroundProperty, Brushes.White),
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(Colors.White) { Opacity = 0.1 }),
},
},
});
}
public static Control TabItemTemplate(TabItem control)
{
return new ContentPresenter
{
DataTemplates = new DataTemplates
{
new DataTemplate<string>(x => new Border
{
[~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty],
Padding = new Thickness(10),
Child = new TextBlock
{
VerticalAlignment = Perspex.Layout.VerticalAlignment.Center,
Text = x
}
})
},
Name = "headerPresenter",
[~ContentPresenter.ContentProperty] = control[~HeaderedContentControl.HeaderProperty],
};
}
public static Control TabControlTemplate(TabControl control)
{
return new Grid
{
ColumnDefinitions = new ColumnDefinitions
{
new ColumnDefinition(GridLength.Auto),
new ColumnDefinition(new GridLength(1, GridUnitType.Star)),
},
Children = new Controls
{
new Border
{
Width = 190,
Background = SolidColorBrush.Parse("#1976D2"),
Child = new ScrollViewer
{
Content = new TabStrip
{
ItemsPanel = new FuncTemplate<IPanel>(() => new StackPanel { Orientation = Orientation.Vertical, Gap = 4 }),
Margin = new Thickness(0, 10, 0, 0),
Name = "internalStrip",
[!ItemsControl.ItemsProperty] = control[!ItemsControl.ItemsProperty],
[!!SelectingItemsControl.SelectedItemProperty] = control[!!SelectingItemsControl.SelectedItemProperty],
}
}
},
new Deck
{
Name = "deck",
DataTemplates = new DataTemplates
{
new DataTemplate<TabItem>(x => (Control)control.MaterializeDataTemplate(x.Content)),
},
[~Deck.TransitionProperty] = control[~TabControl.TransitionProperty],
[!ItemsControl.ItemsProperty] = control[!ItemsControl.ItemsProperty],
[!SelectingItemsControl.SelectedItemProperty] = control[!SelectingItemsControl.SelectedItemProperty],
[Grid.ColumnProperty] = 1,
}
}
};
}
}
}

8
samples/TestApplication/Item.cs

@ -0,0 +1,8 @@
namespace TestApplication
{
internal class Item
{
public string Name { get; set; }
public string Value { get; set; }
}
}

16
samples/TestApplication/Node.cs

@ -0,0 +1,16 @@
using Perspex.Collections;
namespace TestApplication
{
internal class Node
{
public Node()
{
Children = new PerspexList<Node>();
}
public string Name { get; set; }
public PerspexList<Node> Children { get; set; }
}
}

1061
samples/TestApplication/Program.cs

File diff suppressed because it is too large

10
samples/TestApplication/TestApplication.csproj

@ -72,6 +72,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="App.cs" />
<Compile Include="GalleryStyle.cs" />
<Compile Include="Item.cs" />
<Compile Include="Node.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -80,6 +83,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Gtk\Perspex.Cairo\Perspex.Cairo.csproj">
<Project>{FB05AC90-89BA-4F2F-A924-F37875FB547C}</Project>
<Name>Perspex.Cairo</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Perspex.Animation\Perspex.Animation.csproj">
<Project>{D211E587-D8BC-45B9-95A4-F297C8FA5200}</Project>
<Name>Perspex.Animation</Name>
@ -146,6 +153,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="html.htm" />
<Content Include="pattern.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\src\Shared\perspex.platform.targets" />

BIN
samples/TestApplication/pattern.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

32
src/Gtk/Perspex.Cairo/CairoExtensions.cs

@ -43,37 +43,7 @@ namespace Perspex.Cairo
public static Pango.Weight ToCairo(this Perspex.Media.FontWeight weight)
{
if (weight == Perspex.Media.FontWeight.Light)
{
return Pango.Weight.Light;
}
if (weight == Perspex.Media.FontWeight.Normal || weight == Perspex.Media.FontWeight.Regular)
{
return Pango.Weight.Normal;
}
if (weight == Perspex.Media.FontWeight.DemiBold || weight == Perspex.Media.FontWeight.Medium)
{
return Pango.Weight.Semibold;
}
if (weight == Perspex.Media.FontWeight.Bold)
{
return Pango.Weight.Bold;
}
if (weight == Perspex.Media.FontWeight.UltraBold || weight == Perspex.Media.FontWeight.ExtraBold)
{
return Pango.Weight.Ultrabold;
}
if (weight == Perspex.Media.FontWeight.Black || weight == Perspex.Media.FontWeight.Heavy || weight == Perspex.Media.FontWeight.UltraBlack)
{
return Pango.Weight.Heavy;
}
return Pango.Weight.Ultralight;
return (Pango.Weight)weight;
}
public static Pango.Alignment ToCairo(this Perspex.Media.TextAlignment alignment)

57
src/Gtk/Perspex.Cairo/Media/DrawingContext.cs

@ -74,14 +74,31 @@ namespace Perspex.Cairo.Media
_context.Scale(scale.X, scale.Y);
destRect /= scale;
Gdk.CairoHelper.SetSourcePixbuf(
_context,
impl.Surface,
-sourceRect.X + destRect.X,
-sourceRect.Y + destRect.Y);
_context.Rectangle(destRect.ToCairo());
_context.Fill();
if (opacityOverride < 1.0f) {
_context.PushGroup ();
Gdk.CairoHelper.SetSourcePixbuf (
_context,
impl.Surface,
-sourceRect.X + destRect.X,
-sourceRect.Y + destRect.Y);
_context.Rectangle (destRect.ToCairo ());
_context.Fill ();
_context.PopGroupToSource ();
_context.PaintWithAlpha (opacityOverride);
} else {
_context.PushGroup ();
Gdk.CairoHelper.SetSourcePixbuf (
_context,
impl.Surface,
-sourceRect.X + destRect.X,
-sourceRect.Y + destRect.Y);
_context.Rectangle (destRect.ToCairo ());
_context.Fill ();
_context.PopGroupToSource ();
_context.PaintWithAlpha (opacityOverride);
}
_context.Restore();
}
@ -203,11 +220,14 @@ namespace Perspex.Cairo.Media
/// <returns>A disposable used to undo the opacity.</returns>
public IDisposable PushOpacity(double opacity)
{
opacityOverride = opacity;
var tmp = opacityOverride;
if (opacity < 1.0f)
opacityOverride = opacity;
return Disposable.Create(() =>
{
opacityOverride = 1.0f;
opacityOverride = tmp;
});
}
@ -228,8 +248,10 @@ namespace Perspex.Cairo.Media
private double opacityOverride = 1.0f;
private BrushImpl SetBrush(Brush brush, Size destinationSize)
private IDisposable SetBrush(Brush brush, Size destinationSize)
{
_context.Save ();
var solid = brush as SolidColorBrush;
var linearGradientBrush = brush as LinearGradientBrush;
var imageBrush = brush as ImageBrush;
@ -254,15 +276,17 @@ namespace Perspex.Cairo.Media
}
else
{
impl = new SolidColorBrushImpl(null, 1.0f);
impl = new SolidColorBrushImpl(null, opacityOverride);
}
_context.SetSource(impl.PlatformBrush);
return impl;
return Disposable.Create(() =>
{
_context.Restore();
});
}
private BrushImpl SetPen(Pen pen, Size destinationSize)
private IDisposable SetPen(Pen pen, Size destinationSize)
{
if (pen.DashStyle != null)
{
@ -282,6 +306,9 @@ namespace Perspex.Cairo.Media
_context.LineJoin = Cairo.LineJoin.Miter;
_context.LineCap = Cairo.LineCap.Butt;
if (pen.Brush == null)
return Disposable.Empty;
return SetBrush(pen.Brush, destinationSize);
}
}

8
src/Gtk/Perspex.Cairo/Media/SolidColorBrushImpl.cs

@ -9,11 +9,13 @@ namespace Perspex.Cairo
{
var color = brush?.Color.ToCairo() ?? new Color();
if (brush != null && brush.Opacity > 1)
if (brush != null)
color.A = Math.Min(brush.Opacity, color.A);
color.A = Math.Min(opacityOverride, color.A);
this.PlatformBrush = new SolidPattern(brush?.Color.ToCairo() ?? new Color());
if (opacityOverride < 1.0f)
color.A = Math.Min(opacityOverride, color.A);
this.PlatformBrush = new SolidPattern(color);
}
}
}

41
src/Gtk/Perspex.Cairo/Media/StreamGeometryContextImpl.cs

@ -12,12 +12,17 @@ namespace Perspex.Cairo.Media
public class StreamGeometryContextImpl : IStreamGeometryContextImpl
{
private readonly StreamGeometryImpl _impl;
public StreamGeometryContextImpl(StreamGeometryImpl imp)
public StreamGeometryContextImpl(Cairo.Path path = null)
{
_impl = imp;
_surf = new Cairo.ImageSurface(Cairo.Format.Argb32, 0, 0);
_context = new Cairo.Context(_surf);
_surf = new Cairo.ImageSurface (Cairo.Format.Argb32, 0, 0);
_context = new Cairo.Context (_surf);
this.Path = path;
if (this.Path != null)
{
_context.AppendPath(this.Path);
}
}
public void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection)
@ -26,35 +31,43 @@ namespace Perspex.Cairo.Media
public void BeginFigure(Point startPoint, bool isFilled)
{
_context.MoveTo(startPoint.ToCairo());
if (this.Path == null)
_context.MoveTo(startPoint.ToCairo());
}
public void BezierTo(Point point1, Point point2, Point point3)
{
_context.CurveTo(point1.ToCairo(), point2.ToCairo(), point3.ToCairo());
if (this.Path == null)
_context.CurveTo(point1.ToCairo(), point2.ToCairo(), point3.ToCairo());
}
public void LineTo(Point point)
{
_context.LineTo(point.ToCairo());
if (this.Path == null)
_context.LineTo(point.ToCairo());
}
private readonly Cairo.Context _context;
private readonly Cairo.ImageSurface _surf;
public Cairo.Path Path { get; private set; }
public Rect Bounds { get; private set; }
public void EndFigure(bool isClosed)
{
if (isClosed)
_context.ClosePath();
if (this.Path == null)
{
if (isClosed)
_context.ClosePath ();
_impl.Bounds = _context.FillExtents().ToPerspex();
_impl.Path = _context.CopyPath();
Path = _context.CopyPath ();
Bounds = _context.FillExtents ().ToPerspex ();
}
}
public void Dispose()
{
_context.Dispose();
_surf.Dispose();
_context.Dispose ();
_surf.Dispose ();
}
}
}

29
src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs

@ -15,26 +15,23 @@ namespace Perspex.Cairo.Media
{
public StreamGeometryImpl()
{
_impl = new StreamGeometryContextImpl(this);
_impl = new StreamGeometryContextImpl(null);
}
public StreamGeometryImpl(Cairo.Path path)
public StreamGeometryImpl(StreamGeometryContextImpl impl)
{
_impl = new StreamGeometryContextImpl(this);
Path = path;
}
public Cairo.Path Path
{
get;
set;
_impl = impl;
}
public Rect Bounds
{
get;
set;
}
get { return _impl.Bounds; }
}
public Cairo.Path Path
{
get { return _impl.Path; }
}
private readonly StreamGeometryContextImpl _impl;
@ -55,14 +52,14 @@ namespace Perspex.Cairo.Media
}
public IStreamGeometryImpl Clone()
{
return new StreamGeometryImpl(Path);
{
return new StreamGeometryImpl(_impl);
}
public Rect GetRenderBounds(double strokeThickness)
{
// TODO: Calculate properly.
return Bounds;
return Bounds.Inflate(strokeThickness);
}
public IStreamGeometryContextImpl Open()

2
src/Gtk/Perspex.Cairo/Media/TileBrushes.cs

@ -30,7 +30,7 @@ namespace Perspex.Cairo.Media
var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);
using (var intermediate = new ImageSurface(Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height))
var intermediate = new ImageSurface (Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height);
using (var context = new Context(intermediate))
{
Rect drawRect;

4
src/Gtk/Perspex.Cairo/Perspex.Cairo.csproj

@ -96,11 +96,11 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

2
src/Gtk/Perspex.Cairo/packages.config

@ -3,4 +3,4 @@
<package id="Rx-Core" version="2.2.5" targetFramework="net45" userInstalled="true" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="net45" userInstalled="true" />
<package id="Splat" version="1.6.2" targetFramework="net45" userInstalled="true" />
</packages>
</packages>

3
src/Gtk/Perspex.Gtk/WindowImpl.cs

@ -31,7 +31,7 @@ namespace Perspex.Gtk
public WindowImpl()
: base(Gtk.WindowType.Toplevel)
{
DefaultSize = new Gdk.Size(640, 480);
DefaultSize = new Gdk.Size(900, 480);
Init();
}
@ -89,7 +89,6 @@ namespace Perspex.Gtk
public void Invalidate(Rect rect)
{
base.GdkWindow.InvalidateRect (new Rectangle ((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), true);
}
public Point PointToScreen(Point point)

17
src/Perspex.Themes.Default/ButtonStyle.cs

@ -30,8 +30,8 @@ namespace Perspex.Themes.Default
{
Setters = new[]
{
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffdddddd)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff707070)),
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffaaaaaa)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xffaaaaaa)),
new Setter(TemplatedControl.BorderThicknessProperty, 2),
new Setter(TemplatedControl.ForegroundProperty, new SolidColorBrush(0xff000000)),
new Setter(Control.FocusAdornerProperty, new FuncTemplate<IControl>(FocusAdornerTemplate)),
@ -44,22 +44,15 @@ namespace Perspex.Themes.Default
{
Setters = new[]
{
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffbee6fd)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff3c7fb1)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff888888)),
},
},
new Style(x => x.OfType<Button>().Class(":pointerover").Class(":pressed").Template().Name("border"))
{
Setters = new[]
{
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffc4e5f6)),
},
},
new Style(x => x.OfType<Button>().Class(":pressed").Template().Name("border"))
{
Setters = new[]
{
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xffff628b)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff888888)),
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xff888888)),
},
},
new Style(x => x.OfType<Button>().Class(":disabled").Template().Name("contentPresenter"))

4
src/Perspex.Themes.Default/CheckBoxStyle.cs

@ -73,7 +73,7 @@ namespace Perspex.Themes.Default
new Border
{
Name = "checkBorder",
BorderBrush = Brushes.Black,
BorderBrush = new SolidColorBrush(0xff333333),
BorderThickness = 2,
Width = 18,
Height = 18,
@ -83,7 +83,7 @@ namespace Perspex.Themes.Default
new Path
{
Name = "checkMark",
Fill = Brushes.Black,
Fill = new SolidColorBrush(0xff333333),
Width = 11,
Height = 10,
Stretch = Stretch.Uniform,

2
src/Perspex.Themes.Default/TabItemStyle.cs

@ -27,7 +27,7 @@ namespace Perspex.Themes.Default
{
Setters = new[]
{
new Setter(TemplatedControl.FontSizeProperty, 28.7),
new Setter(TemplatedControl.FontSizeProperty, 16.0),
new Setter(TemplatedControl.ForegroundProperty, Brushes.Gray),
new Setter(TemplatedControl.TemplateProperty, new ControlTemplate<TabItem>(Template)),
},

17
src/Perspex.Themes.Default/ToggleButtonStyle.cs

@ -29,8 +29,8 @@ namespace Perspex.Themes.Default
Setters = new[]
{
new Setter(TemplatedControl.TemplateProperty, new ControlTemplate<ToggleButton>(Template)),
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffdddddd)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff707070)),
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffaaaaaa)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xffaaaaaa)),
new Setter(TemplatedControl.BorderThicknessProperty, 2.0),
new Setter(Control.FocusAdornerProperty, new FuncTemplate<IControl>(ButtonStyle.FocusAdornerTemplate)),
new Setter(TemplatedControl.ForegroundProperty, new SolidColorBrush(0xff000000)),
@ -42,36 +42,37 @@ namespace Perspex.Themes.Default
{
Setters = new[]
{
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xff7f7f7f)),
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xff777777)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff77777)),
},
},
new Style(x => x.OfType<ToggleButton>().Class(":pointerover").Template().Name("border"))
{
Setters = new[]
{
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffbee6fd)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff3c7fb1)),
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xff888888)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff888888)),
},
},
new Style(x => x.OfType<ToggleButton>().Class(":checked").Class(":pointerover").Template().Name("border"))
{
Setters = new[]
{
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffa0a0a0)),
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xff777777)),
},
},
new Style(x => x.OfType<ToggleButton>().Class(":pointerover").Class(":pressed").Template().Name("border"))
{
Setters = new[]
{
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xffc4e5f6)),
new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(0xff888888)),
},
},
new Style(x => x.OfType<ToggleButton>().Class(":pressed").Template().Name("border"))
{
Setters = new[]
{
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xffff628b)),
new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff888888)),
},
},
new Style(x => x.OfType<ToggleButton>().Class(":disabled").Template().Name("border"))

Loading…
Cancel
Save