Created
November 21, 2011 04:31
-
-
Save Daniel15/1381620 to your computer and use it in GitHub Desktop.
Semi-transparent window in GTK# (Mono, C#)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using System.Runtime.InteropServices; | |
using Cairo; | |
using Gtk; | |
public class GtkDimScreen | |
{ | |
private DrawingArea drawingArea; | |
public static void Main () | |
{ | |
new GtkDimScreen(); | |
} | |
public GtkDimScreen() | |
{ | |
Application.Init (); | |
var window = new Gtk.Window ("Invisible sandwich"); | |
// Turn off title bar | |
window.Decorated = false; | |
// Create Cairo drawing area | |
drawingArea = new DrawingArea(); | |
drawingArea.ScreenChanged += OnScreenChanged; | |
drawingArea.ExposeEvent += OnExposeEvent; | |
// Add drawing area to window | |
var box = new HBox (true, 0); | |
box.Add (drawingArea); | |
window.Add (box); | |
window.ShowAll (); | |
window.Maximize(); | |
Application.Run (); | |
} | |
protected void OnScreenChanged(object o, ScreenChangedArgs args) | |
{ | |
// Use the RGBA colour map, so that alpha values work | |
drawingArea.Screen.DefaultColormap = drawingArea.Screen.RgbaColormap; | |
} | |
protected void OnExposeEvent(object o, ExposeEventArgs args) | |
{ | |
using (Context ctx = Gdk.CairoHelper.Create(drawingArea.GdkWindow)) | |
{ | |
// Paint a semitransparent colour onto the background | |
ctx.SetSourceRGBA(0, 0, 0, 0.4); | |
ctx.Operator = Operator.Source; | |
ctx.Paint(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you telll me how to add widget in that transparent area