Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Update most remaining samples to the new APIs #8

Merged
merged 8 commits into from
Jun 30, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions gdk/Rectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ public override int GetHashCode ()
{
return !(r1 == r2);
}

public static explicit operator GLib.Value (Gdk.Rectangle boxed)
{
GLib.Value val = GLib.Value.Empty;
val.Init (Gdk.Rectangle.GType);
val.Val = boxed;
return val;
}

public static explicit operator Gdk.Rectangle (GLib.Value val)
{
return (Gdk.Rectangle) val.Val;
}

public override string ToString ()
{
Expand Down
2 changes: 1 addition & 1 deletion gtk/Gtk.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
<attr path="/api/namespace/object[@cname='GtkContainer']/virtual_method[@cname='forall']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkDialog']/constructor[@cname='gtk_dialog_new_with_buttons']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkDialog']/method[@name='AddButtons']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkDialog']/method[@name='GetActionArea']/return-type" name="type">GtkHButtonBox*</attr>
<attr path="/api/namespace/object[@cname='GtkDialog']/method[@name='GetActionArea']/return-type" name="type">GtkButtonBox*</attr>
<attr path="/api/namespace/object[@cname='GtkDialog']/method[@name='GetContentArea']/return-type" name="type">GtkBox*</attr>
<attr path="/api/namespace/object[@cname='GtkDialog']/method[@name='Response']" name="name">Respond</attr>
<attr path="/api/namespace/object[@cname='GtkDialog']/method[@name='SetDefaultResponse']/*/*[@name='response_id']" name="type">GtkResponseType</attr>
Expand Down
2 changes: 1 addition & 1 deletion sample/GtkDemo/DemoApplicationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected override bool OnDeleteEvent (Gdk.Event evt)
protected override bool OnWindowStateEvent (Gdk.EventWindowState evt)
{
if ((evt.ChangedMask & (Gdk.WindowState.Maximized | Gdk.WindowState.Fullscreen)) != 0)
statusbar.HasResizeGrip = (evt.NewWindowState & (Gdk.WindowState.Maximized | Gdk.WindowState.Fullscreen)) == 0;
HasResizeGrip = (evt.NewWindowState & (Gdk.WindowState.Maximized | Gdk.WindowState.Fullscreen)) == 0;
return false;
}

Expand Down
37 changes: 19 additions & 18 deletions sample/GtkDemo/DemoColorSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace GtkDemo
[Demo ("Color Selection", "DemoColorSelection.cs")]
public class DemoColorSelection : Gtk.Window
{
private Gdk.Color color;
private Gdk.RGBA color;
private Gtk.DrawingArea drawingArea;

public DemoColorSelection () : base ("Color Selection")
Expand All @@ -30,19 +30,22 @@ public DemoColorSelection () : base ("Color Selection")
vbox.PackStart (frame, true, true, 0);

drawingArea = new DrawingArea ();
drawingArea.ExposeEvent += new ExposeEventHandler (ExposeEventCallback);
drawingArea.Drawn += new DrawnHandler (DrawnCallback);
// set a minimum size
drawingArea.SetSizeRequest (200,200);
// set the color
color = new Gdk.Color (0, 0, 0xff);
drawingArea.ModifyBg (StateType.Normal, color);
color.Red = 0;
color.Green = 0;
color.Blue = 1;
color.Alpha = 1;
drawingArea.OverrideBackgroundColor (StateFlags.Normal, color);
frame.Add (drawingArea);

Alignment alignment = new Alignment (1.0f, 0.5f, 0.0f, 0.0f);
Button button = new Button ("_Change the above color");
button.Clicked += new EventHandler (ChangeColorCallback);
alignment.Add (button);
vbox.PackStart (alignment);
vbox.PackStart (alignment, false, false, 0);

ShowAll ();
}
Expand All @@ -53,31 +56,29 @@ protected override bool OnDeleteEvent (Gdk.Event evt)
return true;
}

// Expose callback for the drawing area
private void ExposeEventCallback (object o, ExposeEventArgs args)
// Drawn callback for the drawing area
private void DrawnCallback (object o, DrawnArgs args)
{
EventExpose eventExpose = args.Event;
Gdk.Window window = eventExpose.Window;
Rectangle area = eventExpose.Area;
Cairo.Context cr = args.Cr;

Gdk.RGBA rgba = StyleContext.GetBackgroundColor (StateFlags.Normal);
cr.SetSourceRGBA (rgba.Red, rgba.Green, rgba.Blue, rgba.Alpha);
cr.Paint ();

window.DrawRectangle (drawingArea.Style.BackgroundGC (StateType.Normal),
true,
area.X, area.Y,
area.Width, area.Height);
args.RetVal = true;
}

private void ChangeColorCallback (object o, EventArgs args)
{
using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog ("Changing color")) {
colorSelectionDialog.TransientFor = this;
colorSelectionDialog.ColorSelection.PreviousColor = color;
colorSelectionDialog.ColorSelection.CurrentColor = color;
colorSelectionDialog.ColorSelection.SetPreviousRgba (color);
colorSelectionDialog.ColorSelection.CurrentRgba = color;
colorSelectionDialog.ColorSelection.HasPalette = true;

if (colorSelectionDialog.Run () == (int) ResponseType.Ok) {
Gdk.Color selected = colorSelectionDialog.ColorSelection.CurrentColor;
drawingArea.ModifyBg (StateType.Normal, selected);
Gdk.RGBA selected = colorSelectionDialog.ColorSelection.CurrentRgba;
drawingArea.OverrideBackgroundColor (StateFlags.Normal, selected);
}

colorSelectionDialog.Hide ();
Expand Down
2 changes: 1 addition & 1 deletion sample/GtkDemo/DemoDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void InteractiveDialogClicked (object o, EventArgs args)

HBox hbox = new HBox (false, 8);
hbox.BorderWidth = 8;
dialog.VBox.PackStart (hbox, false, false, 0);
dialog.ContentArea.PackStart (hbox, false, false, 0);

Image stock = new Image (Stock.DialogQuestion, IconSize.Dialog);
hbox.PackStart (stock, false, false, 0);
Expand Down
89 changes: 41 additions & 48 deletions sample/GtkDemo/DemoDrawingArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace GtkDemo
[Demo ("Drawing Area", "DemoDrawingArea.cs")]
public class DemoDrawingArea : Gtk.Window
{
private Pixmap pixmap = null;
private Cairo.Surface surface = null;

public DemoDrawingArea () : base ("Drawing Area")
{
Expand All @@ -45,7 +45,7 @@ public DemoDrawingArea () : base ("Drawing Area")
// set a minimum size
da.SetSizeRequest (100,100);
frame.Add (da);
da.ExposeEvent += new ExposeEventHandler (CheckerboardExpose);
da.Drawn += new DrawnHandler (CheckerboardDrawn);

// Create the scribble area
label = new Label ("<u>Scribble area</u>");
Expand All @@ -62,7 +62,7 @@ public DemoDrawingArea () : base ("Drawing Area")
frame.Add (da);

// Signals used to handle backing pixmap
da.ExposeEvent += new ExposeEventHandler (ScribbleExpose);
da.Drawn += new DrawnHandler (ScribbleDrawn);
da.ConfigureEvent += new ConfigureEventHandler (ScribbleConfigure);

// Event signals
Expand All @@ -84,39 +84,34 @@ protected override bool OnDeleteEvent (Gdk.Event evt)
return true;
}

private void CheckerboardExpose (object o, ExposeEventArgs args)
private void CheckerboardDrawn (object o, DrawnArgs args)
{
const int CheckSize = 10;
const int Spacing = 2;

DrawingArea da = o as DrawingArea;

// It would be a bit more efficient to keep these
// GC's around instead of recreating on each expose, but
// this is the lazy/slow way.
Gdk.GC gc1 = new Gdk.GC (da.GdkWindow);
gc1.RgbFgColor = new Gdk.Color (117, 0, 117);

Gdk.GC gc2 = new Gdk.GC (da.GdkWindow);
gc2.RgbFgColor = new Gdk.Color (255, 255, 255);
Widget widget = o as Widget;
Cairo.Context cr = args.Cr;

int i, j, xcount, ycount;
Gdk.Rectangle alloc = da.Allocation;

// At the start of a draw handler, a clip region has been set on
// the Cairo context, and the contents have been cleared to the
// widget's background color.

Rectangle alloc = widget.Allocation;
// Start redrawing the Checkerboard
xcount = 0;
i = Spacing;
while (i < alloc.Width) {
j = Spacing;
ycount = xcount % 2; // start with even/odd depending on row
while (j < alloc.Height) {
Gdk.GC gc;
if (ycount % 2 != 0)
gc = gc1;
cr.SetSourceRGB (0.45777, 0, 0.45777);
else
gc = gc2;
da.GdkWindow.DrawRectangle (gc, true, i, j,
CheckSize, CheckSize);
cr.SetSourceRGB (1, 1, 1);
// If we're outside the clip, this will do nothing.
cr.Rectangle (i, j, CheckSize, CheckSize);

j += CheckSize + Spacing;
++ycount;
Expand All @@ -130,33 +125,29 @@ private void CheckerboardExpose (object o, ExposeEventArgs args)
args.RetVal = true;
}

private void ScribbleExpose (object o, ExposeEventArgs args)
private void ScribbleDrawn (object o, DrawnArgs args)
{
Widget widget = o as Widget;
Gdk.Window window = widget.GdkWindow;
Rectangle area = args.Event.Area;

// We use the "ForegroundGC" for the widget since it already exists,
// but honestly any GC would work. The only thing to worry about
// is whether the GC has an inappropriate clip region set.
window.DrawDrawable (widget.Style.ForegroundGC (StateType.Normal),
pixmap,
area.X, area.Y,
area.X, area.Y,
area.Width, area.Height);
Cairo.Context cr = args.Cr;

cr.SetSourceSurface (surface, 0, 0);
cr.Paint ();
}

// Create a new pixmap of the appropriate size to store our scribbles
// Create a new surface of the appropriate size to store our scribbles
private void ScribbleConfigure (object o, ConfigureEventArgs args)
{
Widget widget = o as Widget;
Rectangle allocation = widget.Allocation;

if (surface != null)
surface.Destroy ();

pixmap = new Pixmap (widget.GdkWindow, allocation.Width, allocation.Height, -1);
var allocation = widget.Allocation;

// Initialize the pixmap to white
pixmap.DrawRectangle (widget.Style.WhiteGC, true, 0, 0,
allocation.Width, allocation.Height);
surface = widget.Window.CreateSimilarSurface (Cairo.Content.Color, allocation.Width, allocation.Height);
var cr = new Cairo.Context (surface);

cr.Paint ();
((IDisposable)cr).Dispose ();

// We've handled the configure event, no need for further processing.
args.RetVal = true;
Expand All @@ -166,7 +157,7 @@ private void ScribbleMotionNotify (object o, MotionNotifyEventArgs args)
{

// paranoia check, in case we haven't gotten a configure event
if (pixmap == null)
if (surface == null)
return;

// This call is very important; it requests the next motion event.
Expand All @@ -192,19 +183,21 @@ private void ScribbleMotionNotify (object o, MotionNotifyEventArgs args)
// Draw a rectangle on the screen
private void DrawBrush (Widget widget, double x, double y)
{
Rectangle update_rect = new Rectangle ((int)x - 3, (int)y - 3, 6, 6);

// Paint to the pixmap, where we store our state
pixmap.DrawRectangle (widget.Style.BlackGC, true,
update_rect.X, update_rect.Y,
update_rect.Width, update_rect.Height);
widget.GdkWindow.InvalidateRect (update_rect, false);
var update_rect = new Gdk.Rectangle ((int)x - 3, (int)y - 3, 6, 6);
var cr = new Cairo.Context (surface);

cr.Fill ();
Gdk.CairoHelper.Rectangle (cr, update_rect);

((IDisposable)cr).Dispose ();

widget.Window.InvalidateRect (update_rect, false);
}

private void ScribbleButtonPress (object o, ButtonPressEventArgs args)
{
// paranoia check, in case we haven't gotten a configure event
if (pixmap == null)
if (surface == null)
return;

EventButton ev = args.Event;
Expand Down
2 changes: 1 addition & 1 deletion sample/GtkDemo/DemoEntryCompletion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public DemoEntryCompletion () : base ("Demo Entry Completion", null, DialogFlags

VBox vbox = new VBox (false, 5);
vbox.BorderWidth = 5;
this.VBox.PackStart (vbox, true, true, 0);
this.ContentArea.PackStart (vbox, true, true, 0);

Label label = new Label ("Completion demo, try writing <b>total</b> or <b>gnome</b> for example.");
label.UseMarkup = true;
Expand Down
2 changes: 1 addition & 1 deletion sample/GtkDemo/DemoExpander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public DemoExpander () : base ("Demo Expander", null, DialogFlags.DestroyWithPar
Resizable = false;

VBox vbox = new VBox (false, 5);
this.VBox.PackStart (vbox, true, true, 0);
this.ContentArea.PackStart (vbox, true, true, 0);
vbox.BorderWidth = 5;

vbox.PackStart (new Label ("Expander demo. Click on the triangle for details."), false, false, 0);
Expand Down
2 changes: 1 addition & 1 deletion sample/GtkDemo/DemoHyperText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void MotionNotify (object sender, MotionNotifyEventArgs args)
view.WindowToBufferCoords (TextWindowType.Widget, (int) args.Event.X, (int) args.Event.Y, out x, out y);
SetCursorIfAppropriate (view, x, y);

view.GdkWindow.GetPointer (out x, out y, out state);
view.Window.GetPointer (out x, out y, out state);
}

// Also update the cursor image if the window becomes visible
Expand Down
2 changes: 1 addition & 1 deletion sample/GtkDemo/DemoImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void ProgressivePreparedCallback (object obj, EventArgs args)
{
Gdk.Pixbuf pixbuf = pixbufLoader.Pixbuf;
pixbuf.Fill (0xaaaaaaff);
progressiveImage.FromPixbuf = pixbuf;
progressiveImage.Pixbuf = pixbuf;
}

void ProgressiveUpdatedCallback (object obj, AreaUpdatedArgs args)
Expand Down
6 changes: 3 additions & 3 deletions sample/GtkDemo/DemoMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ private ScrolledWindow CreateText (TextBuffer buffer, bool IsSource)
scrolledWindow.Add (textView);

if (IsSource) {
FontDescription fontDescription = FontDescription.FromString ("Courier 12");
textView.ModifyFont (fontDescription);
FontDescription fontDescription = FontDescription.FromString ("monospace");
textView.OverrideFont (fontDescription);
textView.WrapMode = Gtk.WrapMode.None;
} else {
// Make it a bit nicer for text
Expand All @@ -191,7 +191,7 @@ private ScrolledWindow CreateText (TextBuffer buffer, bool IsSource)
}

return scrolledWindow;
}
}

private TreeStore FillTree ()
{
Expand Down
24 changes: 7 additions & 17 deletions sample/GtkDemo/DemoPixbuf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,13 @@ static DemoPixbuf ()
}

// Expose callback for the drawing area
void Expose (object o, ExposeEventArgs args)
void DrawnCallback (object o, DrawnArgs args)
{
Widget widget = (Widget) o;
Gdk.Rectangle area = args.Event.Area;
byte[] pixels;
int rowstride;

rowstride = frame.Rowstride;
pixels = new byte[(frame.Height - area.Y) * rowstride];
IntPtr src = (IntPtr)(frame.Pixels.ToInt64 () + rowstride * area.Y + area.X * 3);
Marshal.Copy (src, pixels, 0, pixels.Length);

widget.GdkWindow.DrawRgbImageDithalign (widget.Style.BlackGC,
area.X, area.Y, area.Width, area.Height,
Gdk.RgbDither.Normal,
pixels, rowstride,
area.X, area.Y);
Cairo.Context cr = args.Cr;

Gdk.CairoHelper.SetSourcePixbuf (cr, frame, 0, 0);
cr.Paint ();

args.RetVal = true;
}

Expand Down Expand Up @@ -152,7 +142,7 @@ public DemoPixbuf () : base ("Pixbufs")
frame = new Pixbuf (Colorspace.Rgb, false, 8, backWidth, backHeight);

drawingArea = new DrawingArea ();
drawingArea.ExposeEvent += new ExposeEventHandler (Expose);
drawingArea.Drawn += new DrawnHandler (DrawnCallback);

Add (drawingArea);
timeoutId = GLib.Timeout.Add (FrameDelay, new GLib.TimeoutHandler(timeout));
Expand Down
Loading