Browse Source

Fixed GTK/Cairo render

droid
Nikita Tsukanov 11 years ago
parent
commit
a297199e59
  1. 6
      src/Gtk/Perspex.Cairo/CairoPlatform.cs
  2. 23
      src/Gtk/Perspex.Cairo/RenderTarget.cs
  3. 14
      src/Gtk/Perspex.Gtk/WindowImpl.cs
  4. 2
      src/Perspex.Application/Application.cs
  5. 4
      src/Perspex.Controls/Platform/ITopLevelRenderer.cs

6
src/Gtk/Perspex.Cairo/CairoPlatform.cs

@ -38,7 +38,11 @@ namespace Perspex.Cairo
public IRenderTarget CreateRenderer(IPlatformHandle handle, double width, double height)
{
return new RenderTarget(handle, width, height);
if (handle.HandleDescriptor != "GtkWindow")
throw new NotSupportedException(string.Format(
"Don't know how to create a Cairo renderer from a '{0}' handle",
handle.HandleDescriptor));
return new RenderTarget((Gtk.Window)handle, width, height);
}
public IRenderTargetBitmapImpl CreateRenderTargetBitmap(int width, int height)

23
src/Gtk/Perspex.Cairo/RenderTarget.cs

@ -17,19 +17,18 @@ namespace Perspex.Cairo
/// </summary>
public class RenderTarget : IRenderTarget
{
private readonly IPlatformHandle _handle;
private readonly Surface _surface;
private Gdk.Window _window;
private Gtk.Window _window;
/// <summary>
/// Initializes a new instance of the <see cref="RenderTarget"/> class.
/// </summary>
/// <param name="handle">The window handle.</param>
/// <param name="window">The window.</param>
/// <param name="width">The width of the window.</param>
/// <param name="height">The height of the window.</param>
public RenderTarget(IPlatformHandle handle, double width, double height)
public RenderTarget(Gtk.Window window, double width, double height)
{
_handle = handle;
_window = window;
}
public RenderTarget(ImageSurface surface)
@ -56,19 +55,7 @@ namespace Perspex.Cairo
{
if(_surface != null)
return new DrawingContext(_surface);
switch (_handle.HandleDescriptor)
{
case "GdkWindow":
if (_window == null)
_window = new Gdk.Window(_handle.Handle);
return new DrawingContext(_window);
default:
throw new NotSupportedException(string.Format(
"Don't know how to create a Cairo renderer from a '{0}' handle",
_handle.HandleDescriptor));
}
return new DrawingContext(_window.GdkWindow);
}
public void Dispose() => _surface?.Dispose();

14
src/Gtk/Perspex.Gtk/WindowImpl.cs

@ -14,12 +14,10 @@ namespace Perspex.Gtk
{
using Gtk = global::Gtk;
public class WindowImpl : Gtk.Window, IWindowImpl
public class WindowImpl : Gtk.Window, IWindowImpl, IPlatformHandle
{
private IInputRoot _inputRoot;
private IPlatformHandle _windowHandle;
private Size _clientSize;
private Gtk.IMContext _imContext;
@ -46,7 +44,6 @@ namespace Perspex.Gtk
Events = EventMask.PointerMotionMask |
EventMask.ButtonPressMask |
EventMask.ButtonReleaseMask;
_windowHandle = new PlatformHandle(Handle, "GtkWindow");
_imContext = new Gtk.IMMulticontext();
_imContext.Commit += ImContext_Commit;
}
@ -73,7 +70,8 @@ namespace Perspex.Gtk
}
}
IPlatformHandle ITopLevelImpl.Handle => _windowHandle;
IPlatformHandle ITopLevelImpl.Handle => this;
public string HandleDescriptor => "GtkWindow";
public Action Activated { get; set; }
@ -94,7 +92,9 @@ 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);
if (base.GdkWindow != null)
base.GdkWindow.InvalidateRect(
new Rectangle((int) rect.X, (int) rect.Y, (int) rect.Width, (int) rect.Height), true);
}
public Point PointToScreen(Point point)

2
src/Perspex.Application/Application.cs

@ -177,7 +177,7 @@ namespace Perspex
/// <param name="platformID">The value of Environment.OSVersion.Platform.</param>
protected void InitializeSubsystems(int platformID)
{
if (platformID == 4 || platformID == 6)
if (true)
{
InitializeSubsystem("Perspex.Cairo");
InitializeSubsystem("Perspex.Gtk");

4
src/Perspex.Controls/Platform/ITopLevelRenderer.cs

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using Perspex.Platform;
using Perspex.Rendering;
using Perspex.Threading;
namespace Perspex.Controls.Platform
{
@ -42,7 +43,8 @@ namespace Perspex.Controls.Platform
viewport.Resize((int) clientSize.Width, (int) clientSize.Height);
}));
resources.Add(queueManager.RenderNeeded.Subscribe(_
=> topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize))));
=>
Dispatcher.UIThread.InvokeAsync(() => topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize)))));
topLevel.PlatformImpl.Paint = rect =>
{

Loading…
Cancel
Save