Get Scribble sample working.
* cairo/cairo-api.xml: add the Content enum type and fix surface symbol. * gdk/gdk-sharp.dll.config.in: s/3.0/3/ on the so name. * sample/Makefile.am: enable scribble.exe build * sample/Scribble.cs: rewrite for new API, specifically replace pixmap drawing usage with cairo, and use OnDrawn in place of OnExposeEvent. Also Made it a subclass of DrawingArea instead of handling events.
This commit is contained in:
parent
d757f1b63a
commit
27b71b1982
4 changed files with 99 additions and 98 deletions
|
@ -1,7 +1,10 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<api>
|
<api>
|
||||||
|
<namespace name="Cairo">
|
||||||
|
<enum cname="cairo_content_t" name="Content" type="enum" />
|
||||||
|
</namespace>
|
||||||
<symbol type="manual" cname="cairo_t" name="Cairo.Context"/>
|
<symbol type="manual" cname="cairo_t" name="Cairo.Context"/>
|
||||||
<symbol type="manual" cname="cairo_font_options_t" name="Cairo.FontOptions"/>
|
<symbol type="manual" cname="cairo_font_options_t" name="Cairo.FontOptions"/>
|
||||||
<symbol type="manual" cname="cairo_region_t" name="Cairo.Region"/>
|
<symbol type="manual" cname="cairo_region_t" name="Cairo.Region"/>
|
||||||
<symbol type="marshal" cname="cairo_surface_t" name="Cairo.Surface" native_type="IntPtr" to_fmt="{0}.Handle" from_fmt="Cairo.Surface.LookupSurface ({0})" />
|
<symbol type="marshal" cname="cairo_surface_t" name="Cairo.Surface" marshal_type="IntPtr" call_fmt="{0}.Handle" from_fmt="Cairo.Surface.LookupSurface ({0})" />
|
||||||
</api>
|
</api>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<dllmap dll="libglib-2.0-0.dll" target="libglib-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
<dllmap dll="libglib-2.0-0.dll" target="libglib-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
||||||
<dllmap dll="libgobject-2.0-0.dll" target="libgobject-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
<dllmap dll="libgobject-2.0-0.dll" target="libgobject-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
||||||
<dllmap dll="libgdk-win32-3.0-0.dll" target="libgdk-3.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
<dllmap dll="libgdk-win32-3.0-0.dll" target="libgdk-3@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
||||||
<dllmap dll="libgdk_pixbuf-2.0-0.dll" target="libgdk_pixbuf-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
<dllmap dll="libgdk_pixbuf-2.0-0.dll" target="libgdk_pixbuf-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -8,7 +8,7 @@ DOTNET_TARGETS=
|
||||||
DOTNET_ASSEMBLY=
|
DOTNET_ASSEMBLY=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TARGETS = gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe treeviewdemo.exe managedtreeviewdemo.exe nodeviewdemo.exe treemodeldemo.exe actions.exe spawn.exe assistant.exe registerprop.exe gexceptiontest.exe native-instantiation.exe polarfixed.exe cairo-sample.exe # custom-widget.exe custom-cellrenderer.exe scribble.exe scribble-xinput.exe testdnd.exe $(DOTNET_TARGETS)
|
TARGETS = gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe treeviewdemo.exe managedtreeviewdemo.exe nodeviewdemo.exe treemodeldemo.exe actions.exe spawn.exe assistant.exe registerprop.exe gexceptiontest.exe native-instantiation.exe polarfixed.exe cairo-sample.exe scribble.exe # custom-widget.exe custom-cellrenderer.exe scribble-xinput.exe testdnd.exe $(DOTNET_TARGETS)
|
||||||
|
|
||||||
DEBUGS = $(addsuffix .mdb, $(TARGETS))
|
DEBUGS = $(addsuffix .mdb, $(TARGETS))
|
||||||
|
|
||||||
|
|
|
@ -1,121 +1,119 @@
|
||||||
// Scribble.cs - port of Gtk+ scribble demo
|
// Copyright (c) 2011 Novell, Inc.
|
||||||
//
|
//
|
||||||
// Author: Rachel Hestilow <hestilow@ximian.com>
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
//
|
// a copy of this software and associated documentation files (the
|
||||||
// (c) 2002 Rachel Hestilow
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
// the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
using Gtk;
|
||||||
|
using Gdk;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace GtkSamples {
|
namespace GtkSamples {
|
||||||
|
|
||||||
using Gtk;
|
public class ScribbleArea : DrawingArea {
|
||||||
using Gdk;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
public class Scribble {
|
|
||||||
private static Gtk.DrawingArea darea;
|
|
||||||
private static Gdk.Pixmap pixmap = null;
|
|
||||||
|
|
||||||
public static int Main (string[] args)
|
public static int Main (string[] args)
|
||||||
{
|
{
|
||||||
Application.Init ();
|
Application.Init ();
|
||||||
Gtk.Window win = new Gtk.Window ("Scribble demo");
|
Gtk.Window win = new Gtk.Window ("Scribble");
|
||||||
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
|
win.DeleteEvent += delegate { Application.Quit (); };
|
||||||
|
win.BorderWidth = 8;
|
||||||
darea = new Gtk.DrawingArea ();
|
Frame frm = new Frame (null);
|
||||||
darea.SetSizeRequest (200, 200);
|
frm.ShadowType = ShadowType.In;
|
||||||
win.Add (darea);
|
frm.Add (new ScribbleArea ());
|
||||||
|
win.Add (frm);
|
||||||
darea.ExposeEvent += new ExposeEventHandler (ExposeEvent);
|
|
||||||
darea.ConfigureEvent += new ConfigureEventHandler (ConfigureEvent);
|
|
||||||
darea.MotionNotifyEvent += new MotionNotifyEventHandler (MotionNotifyEvent);
|
|
||||||
darea.ButtonPressEvent += new ButtonPressEventHandler (ButtonPressEvent);
|
|
||||||
darea.Events = EventMask.ExposureMask | EventMask.LeaveNotifyMask |
|
|
||||||
EventMask.ButtonPressMask | EventMask.PointerMotionMask |
|
|
||||||
EventMask.PointerMotionHintMask;
|
|
||||||
|
|
||||||
win.ShowAll ();
|
win.ShowAll ();
|
||||||
Application.Run ();
|
Application.Run ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Window_Delete (object obj, DeleteEventArgs args)
|
Cairo.Surface surface;
|
||||||
|
|
||||||
|
public ScribbleArea ()
|
||||||
{
|
{
|
||||||
Application.Quit ();
|
SetSizeRequest (200, 200);
|
||||||
args.RetVal = true;
|
Events |= EventMask.ButtonPressMask | EventMask.PointerMotionMask | EventMask.PointerMotionHintMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExposeEvent (object obj, ExposeEventArgs args)
|
void ClearSurface ()
|
||||||
{
|
{
|
||||||
Gdk.Rectangle area = args.Event.Area;
|
using (Cairo.Context ctx = new Cairo.Context (surface)) {
|
||||||
args.Event.Window.DrawDrawable (darea.Style.BlackGC,
|
ctx.SetSourceRGB (1, 1, 1);
|
||||||
pixmap,
|
ctx.Paint ();
|
||||||
area.X, area.Y,
|
}
|
||||||
area.X, area.Y,
|
|
||||||
area.Width, area.Height);
|
|
||||||
|
|
||||||
args.RetVal = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ConfigureEvent (object obj, ConfigureEventArgs args)
|
|
||||||
{
|
|
||||||
Gdk.EventConfigure ev = args.Event;
|
|
||||||
Gdk.Window window = ev.Window;
|
|
||||||
Gdk.Rectangle allocation = darea.Allocation;
|
|
||||||
|
|
||||||
pixmap = new Gdk.Pixmap (window, allocation.Width, allocation.Height, -1);
|
|
||||||
pixmap.DrawRectangle (darea.Style.WhiteGC, true, 0, 0,
|
|
||||||
allocation.Width, allocation.Height);
|
|
||||||
|
|
||||||
args.RetVal = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawBrush (double x, double y, bool black)
|
void DrawBrush (double x, double y)
|
||||||
{
|
{
|
||||||
Gdk.Rectangle update_rect = new Gdk.Rectangle ();
|
using (Cairo.Context ctx = new Cairo.Context (surface)) {
|
||||||
update_rect.X = (int) x - 5;
|
ctx.Rectangle ((int) x - 3, (int) y - 3, 6, 6);
|
||||||
update_rect.Y = (int) y - 5;
|
ctx.Fill ();
|
||||||
update_rect.Width = 10;
|
|
||||||
update_rect.Height = 10;
|
|
||||||
|
|
||||||
pixmap.DrawRectangle (black ? darea.Style.BlackGC : darea.Style.WhiteGC, true,
|
|
||||||
update_rect.X, update_rect.Y,
|
|
||||||
update_rect.Width, update_rect.Height);
|
|
||||||
darea.QueueDrawArea (update_rect.X, update_rect.Y,
|
|
||||||
update_rect.Width, update_rect.Height);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ButtonPressEvent (object obj, ButtonPressEventArgs args)
|
|
||||||
{
|
|
||||||
Gdk.EventButton ev = args.Event;
|
|
||||||
if (ev.Button == 1 && pixmap != null)
|
|
||||||
DrawBrush (ev.X, ev.Y, true);
|
|
||||||
else if (ev.Button == 3 && pixmap != null)
|
|
||||||
DrawBrush (ev.X, ev.Y, false);
|
|
||||||
args.RetVal = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void MotionNotifyEvent (object obj, MotionNotifyEventArgs args)
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
Gdk.ModifierType state;
|
|
||||||
Gdk.EventMotion ev = args.Event;
|
|
||||||
Gdk.Window window = ev.Window;
|
|
||||||
|
|
||||||
if (ev.IsHint) {
|
|
||||||
Gdk.ModifierType s;
|
|
||||||
window.GetPointer (out x, out y, out s);
|
|
||||||
state = s;
|
|
||||||
} else {
|
|
||||||
x = (int) ev.X;
|
|
||||||
y = (int) ev.Y;
|
|
||||||
state = ev.State;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((state & Gdk.ModifierType.Button1Mask) != 0 && pixmap != null)
|
QueueDrawArea ((int) x - 3, (int) y - 3, 6, 6);
|
||||||
DrawBrush (x, y, true);
|
}
|
||||||
else if ((state & Gdk.ModifierType.Button3Mask) != 0 && pixmap != null)
|
|
||||||
DrawBrush (x, y, false);
|
protected override bool OnButtonPressEvent (EventButton ev)
|
||||||
|
{
|
||||||
|
if (surface == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
args.RetVal = true;
|
switch (ev.Button) {
|
||||||
|
case 1:
|
||||||
|
DrawBrush (ev.X, ev.Y);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
ClearSurface ();
|
||||||
|
QueueDraw ();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnConfigureEvent (EventConfigure ev)
|
||||||
|
{
|
||||||
|
surface = ev.Window.CreateSimilarSurface (Cairo.Content.Color, AllocatedWidth, AllocatedHeight);
|
||||||
|
ClearSurface ();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnDrawn (Cairo.Context ctx)
|
||||||
|
{
|
||||||
|
ctx.SetSourceSurface (surface, 0, 0);
|
||||||
|
ctx.Paint ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnMotionNotifyEvent (EventMotion ev)
|
||||||
|
{
|
||||||
|
if (surface == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
Gdk.ModifierType state;
|
||||||
|
ev.Window.GetPointer (out x, out y, out state);
|
||||||
|
if ((state & Gdk.ModifierType.Button1Mask) != 0)
|
||||||
|
DrawBrush (x, y);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue