Browse Source

More progress

pull/156/head
Nelson Carrillo 11 years ago
parent
commit
49019c440a
  1. 299
      samples/TestApplication/Program.cs
  2. 32
      src/Gtk/Perspex.Cairo/CairoExtensions.cs
  3. 33
      src/Gtk/Perspex.Cairo/Media/DrawingContext.cs
  4. 42
      src/Gtk/Perspex.Cairo/Media/StreamGeometryContextImpl.cs
  5. 27
      src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs
  6. 2
      src/Gtk/Perspex.Gtk/WindowImpl.cs

299
samples/TestApplication/Program.cs

@ -81,7 +81,7 @@ namespace TestApplication
// dispatcher. This makes sure it's initialized. // dispatcher. This makes sure it's initialized.
System.Windows.Threading.Dispatcher foo = System.Windows.Threading.Dispatcher.CurrentDispatcher; System.Windows.Threading.Dispatcher foo = System.Windows.Threading.Dispatcher.CurrentDispatcher;
App application = new App new App
{ {
DataTemplates = new DataTemplates DataTemplates = new DataTemplates
{ {
@ -92,18 +92,13 @@ namespace TestApplication
}, },
}; };
TextBlock fps;
var testCommand = ReactiveCommand.Create();
testCommand.Subscribe(_ => System.Diagnostics.Debug.WriteLine("Test command executed."));
TabControl container; TabControl container;
Window window = new Window Window window = new Window
{ {
Title = "Perspex Test Application", Title = "Perspex Test Application",
Width = 800, Width = 900,
Height = 300, Height = 480,
Content = new Grid Content = new Grid
{ {
ColumnDefinitions = new ColumnDefinitions ColumnDefinitions = new ColumnDefinitions
@ -148,71 +143,60 @@ namespace TestApplication
private static TabItem ButtonsTab() private static TabItem ButtonsTab()
{ {
Button defaultButton;
var showDialog = ReactiveCommand.Create();
Button showDialogButton;
var result = new TabItem var result = new TabItem
{ {
Header = "Button", Header = "Button",
Content = new StackPanel Content = new ScrollViewer()
{ {
Margin = new Thickness(10), CanScrollHorizontally = false,
Orientation = Orientation.Vertical, Content = new StackPanel
Gap = 4, {
Children = new Controls Margin = new Thickness(10),
{ Orientation = Orientation.Vertical,
new TextBlock Gap = 4,
{ Children = new Controls
Text = "Button", {
FontWeight = FontWeight.Medium, new TextBlock
FontSize = 22, {
Foreground = SolidColorBrush.Parse("#212121"), Text = "Button",
}, FontWeight = FontWeight.Medium,
new TextBlock FontSize = 13,
{ Foreground = SolidColorBrush.Parse("#212121"),
Text = "A button control", },
FontSize = 14, new TextBlock
Foreground = SolidColorBrush.Parse("#727272"), {
Margin = new Thickness(0, 0, 0, 10) Text = "A button control",
}, FontSize = 20,
new Button Foreground = SolidColorBrush.Parse("#727272"),
{ Margin = new Thickness(0, 0, 0, 10)
Width = 150, },
Content = "Button" new Button
}, {
new Button Width = 150,
{ Content = "Button"
Width = 150, },
Content = "Disabled", new Button
IsEnabled = false, {
}, Width = 150,
new TabControl Content = "Disabled",
{ IsEnabled = false,
Margin = new Thickness(0, 20, 0, 0), },
new TextBlock
Items = new [] {
{ Text = "Toggle button",
new TabItem FontWeight = FontWeight.Medium,
{ FontSize = 13,
Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "CSHARP" }, Foreground = SolidColorBrush.Parse("#212121"),
Content = new HtmlLabel },
{ new TextBlock
Text = "CSHRP CODEZ" {
} Text = "A button control",
}, FontSize = 20,
new TabItem Foreground = SolidColorBrush.Parse("#727272"),
{ Margin = new Thickness(0, 0, 0, 10)
Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "XAML" }, },
Content = new HtmlLabel }
{ }
Text = "XAML CODEZ"
}
}
}
}
}
}, },
}; };
@ -222,25 +206,95 @@ namespace TestApplication
private static TabItem HtmlTab() private static TabItem HtmlTab()
{ {
var htmlText =
new StreamReader(typeof (Program).Assembly.GetManifestResourceStream("TestApplication.html.htm"))
.ReadToEnd();
return new TabItem return new TabItem
{ {
Header = "HTML Label", Header = "Text",
Content = new ScrollViewer() Content = new ScrollViewer()
{ {
Width = 600, CanScrollHorizontally = false,
MaxHeight = 600, Content = new StackPanel()
HorizontalAlignment = HorizontalAlignment.Center, {
CanScrollHorizontally = false, Margin = new Thickness(10),
VerticalScrollBarVisibility = ScrollBarVisibility.Visible, Orientation = Orientation.Vertical,
Content = Gap = 4,
new HtmlLabel() Children = new Controls
{ {
Text = htmlText new TextBlock
} {
} Text = "Text block",
FontWeight = FontWeight.Medium,
FontSize = 20,
Foreground = SolidColorBrush.Parse("#212121"),
},
new TextBlock
{
Text = "A control for displaying text.",
FontSize = 13,
Foreground = SolidColorBrush.Parse("#727272"),
Margin = new Thickness(0, 0, 0, 10)
},
new TextBlock
{
Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
FontSize = 11
},
new TextBlock
{
Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
FontSize = 11,
FontWeight = FontWeight.Medium
},
new TextBlock
{
Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
FontSize = 11,
FontWeight = FontWeight.Bold
},
new TextBlock
{
Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
FontSize = 11,
FontStyle = FontStyle.Italic,
Margin = new Thickness(0, 0, 0, 20)
},
new TextBlock
{
Text = "HTML label",
FontWeight = FontWeight.Medium,
FontSize = 20,
Foreground = SolidColorBrush.Parse("#212121"),
},
new TextBlock
{
Text = "A label capable of displaying HTML content",
FontSize = 13,
Foreground = SolidColorBrush.Parse("#727272"),
Margin = new Thickness(0, 0, 0, 10)
},
new HtmlLabel
{
Background = SolidColorBrush.Parse("#CCCCCC"),
Padding = new Thickness(5),
Text = @"<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. <a href=""#"">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>"
}
}
}
}
}; };
} }
@ -260,85 +314,37 @@ namespace TestApplication
{ {
Text = "Check box", Text = "Check box",
FontWeight = FontWeight.Medium, FontWeight = FontWeight.Medium,
FontSize = 22, FontSize = 20,
Foreground = SolidColorBrush.Parse("#212121"), Foreground = SolidColorBrush.Parse("#212121"),
}, },
new TextBlock new TextBlock
{ {
Text = "A check box control", Text = "A check box control",
FontSize = 14, FontSize = 13,
Foreground = SolidColorBrush.Parse("#373749"), Foreground = SolidColorBrush.Parse("#727272"),
Margin = new Thickness(0, 0, 0, 10) Margin = new Thickness(0, 0, 0, 10)
}, },
new CheckBox { IsChecked = true, Margin = new Thickness(0, 0, 0, 5), Content = "Checked" }, new CheckBox { IsChecked = true, Margin = new Thickness(0, 0, 0, 5), Content = "Checked" },
new CheckBox { IsChecked = false, Content = "Unchecked" }, new CheckBox { IsChecked = false, Content = "Unchecked" },
new TabControl
{
Margin = new Thickness(0, 20, 0, 0),
Items = new []
{
new TabItem
{
Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "CSHARP" },
Content = new HtmlLabel
{
Text = "CSHRP CODEZ"
}
},
new TabItem
{
Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "XAML" },
Content = new HtmlLabel
{
Text = "XAML CODEZ"
}
}
}
},
new TextBlock new TextBlock
{ {
Margin = new Thickness(0, 40, 0, 0), Margin = new Thickness(0, 40, 0, 0),
Text = "Radio button", Text = "Radio button",
FontWeight = FontWeight.Medium, FontWeight = FontWeight.Medium,
FontSize = 22, FontSize = 20,
Foreground = SolidColorBrush.Parse("#373749"), Foreground = SolidColorBrush.Parse("#212121"),
}, },
new TextBlock new TextBlock
{ {
Text = "A radio button control", Text = "A radio button control",
FontSize = 14, FontSize = 13,
Foreground = SolidColorBrush.Parse("#373749"), Foreground = SolidColorBrush.Parse("#727272"),
Margin = new Thickness(0, 0, 0, 10) Margin = new Thickness(0, 0, 0, 10)
}, },
new RadioButton { IsChecked = true, Margin = new Thickness(0, 0, 0, 5), Content = "Option 1" }, new RadioButton { IsChecked = true, Margin = new Thickness(0, 0, 0, 5), Content = "Option 1" },
new RadioButton { IsChecked = false, Content = "Option 2" }, new RadioButton { IsChecked = false, Content = "Option 2" },
new RadioButton { IsChecked = false, Content = "Option 3" }, new RadioButton { IsChecked = false, Content = "Option 3" },
new TabControl
{
Margin = new Thickness(0, 20, 0, 0),
Items = new []
{
new TabItem
{
Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "CSHARP" },
Content = new HtmlLabel
{
Text = "CSHRP CODEZ"
}
},
new TabItem
{
Header = new TextBlock { FontWeight = FontWeight.Medium, Text = "XAML" },
Content = new HtmlLabel
{
Text = "XAML CODEZ"
}
}
}
}
} }
} }
}; };
@ -359,6 +365,13 @@ namespace TestApplication
Gap = 8, Gap = 8,
Children = new Controls Children = new Controls
{ {
new Perspex.Controls.Shapes.Path {
Fill = Brushes.Red,
Stroke = Brushes.Orange,
Width = 400,
Height = 400,
Data = StreamGeometry.Parse("M18.71,19.5C17.88,20.74 17,21.95 15.66,21.97C14.32,22 13.89,21.18 12.37,21.18C10.84,21.18 10.37,21.95 9.1,22C7.79,22.05 6.8,20.68 5.96,19.47C4.25,17 2.94,12.45 4.7,9.39C5.57,7.87 7.13,6.91 8.82,6.88C10.1,6.86 11.32,7.75 12.11,7.75C12.89,7.75 14.37,6.68 15.92,6.84C16.57,6.87 18.39,7.1 19.56,8.82C19.47,8.88 17.39,10.1 17.41,12.63C17.44,15.65 20.06,16.66 20.09,16.67C20.06,16.74 19.67,18.11 18.71,19.5M13,3.5C13.73,2.67 14.94,2.04 15.94,2C16.07,3.17 15.6,4.35 14.9,5.19C14.21,6.04 13.07,6.7 11.95,6.61C11.8,5.46 12.36,4.26 13,3.5Z")
},
(size = new ScrollBar (size = new ScrollBar
{ {
Minimum = 100, Minimum = 100,

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

@ -43,37 +43,7 @@ namespace Perspex.Cairo
public static Pango.Weight ToCairo(this Perspex.Media.FontWeight weight) public static Pango.Weight ToCairo(this Perspex.Media.FontWeight weight)
{ {
if (weight == Perspex.Media.FontWeight.Light) return (Pango.Weight)weight;
{
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;
} }
public static Pango.Alignment ToCairo(this Perspex.Media.TextAlignment alignment) public static Pango.Alignment ToCairo(this Perspex.Media.TextAlignment alignment)

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

@ -74,14 +74,31 @@ namespace Perspex.Cairo.Media
_context.Scale(scale.X, scale.Y); _context.Scale(scale.X, scale.Y);
destRect /= scale; destRect /= scale;
Gdk.CairoHelper.SetSourcePixbuf( if (opacityOverride < 1.0f) {
_context, _context.PushGroup ();
impl.Surface, Gdk.CairoHelper.SetSourcePixbuf (
-sourceRect.X + destRect.X, _context,
-sourceRect.Y + destRect.Y); impl.Surface,
-sourceRect.X + destRect.X,
_context.Rectangle(destRect.ToCairo()); -sourceRect.Y + destRect.Y);
_context.Fill();
_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(); _context.Restore();
} }

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

@ -12,12 +12,17 @@ namespace Perspex.Cairo.Media
public class StreamGeometryContextImpl : IStreamGeometryContextImpl public class StreamGeometryContextImpl : IStreamGeometryContextImpl
{ {
private readonly StreamGeometryImpl _impl; public StreamGeometryContextImpl(Cairo.Path path = null)
public StreamGeometryContextImpl(StreamGeometryImpl imp)
{ {
_impl = imp;
_surf = new Cairo.ImageSurface(Cairo.Format.Argb32, 0, 0); _surf = new Cairo.ImageSurface (Cairo.Format.Argb32, 0, 0);
_context = new Cairo.Context(_surf); _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) public void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection)
@ -26,35 +31,44 @@ namespace Perspex.Cairo.Media
public void BeginFigure(Point startPoint, bool isFilled) 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) 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) 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.Context _context;
private readonly Cairo.ImageSurface _surf; private readonly Cairo.ImageSurface _surf;
public Cairo.Path Path { get; private set; }
public Rect Bounds { get; private set; }
public void EndFigure(bool isClosed) public void EndFigure(bool isClosed)
{ {
if (isClosed) if (this.Path == null)
_context.ClosePath(); {
if (isClosed)
_context.ClosePath ();
Path = _context.CopyPath ();
}
_impl.Bounds = _context.FillExtents().ToPerspex(); Bounds = _context.FillExtents ().ToPerspex ();
_impl.Path = _context.CopyPath();
} }
public void Dispose() public void Dispose()
{ {
_context.Dispose(); _context.Dispose ();
_surf.Dispose(); _surf.Dispose ();
} }
} }
} }

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

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

2
src/Gtk/Perspex.Gtk/WindowImpl.cs

@ -31,7 +31,7 @@ namespace Perspex.Gtk
public WindowImpl() public WindowImpl()
: base(Gtk.WindowType.Toplevel) : base(Gtk.WindowType.Toplevel)
{ {
DefaultSize = new Gdk.Size(640, 480); DefaultSize = new Gdk.Size(900, 480);
Init(); Init();
} }

Loading…
Cancel
Save