예제 #1
0
        /// <summary>
        /// Handles X events. Gets point and reads it's color.
        /// </summary>
        /// <param name="xEvent">X event.</param>
        /// <param name="gdkEvent">Gdk event.</param>
        private FilterReturn OnColorMouseChanged(IntPtr xEvent, Event gdkEvent)
        {
            try
            {
                IXButtonEvent evnt = null;

                switch (this.architecture)
                {
                case Architectures.X86:
                    evnt = (XButtonEvent32)Marshal.PtrToStructure(xEvent, typeof(XButtonEvent32));
                    break;

                case Architectures.X86_64:
                    evnt = (XButtonEvent64)Marshal.PtrToStructure(xEvent, typeof(XButtonEvent64));
                    break;
                }

                switch (evnt.Type)
                {
                case EventType.ButtonRelease:
                    this.pixbuf = Pixbuf.FromDrawable(this.rootWindow, this.rootWindow.Colormap, evnt.X, evnt.Y, 0, 0, 1, 1);
                    byte r, g, b;

                    unsafe
                    {
                        byte *ptr = (byte *)this.pixbuf.Pixels.ToPointer();
                        r = *ptr;
                        g = *(++ptr);
                        b = *(++ptr);
                    }

                    this.Ungrab();
                    new ColorWindow(r, g, b).ShowAll();

                    break;

                case EventType.KeyPress:
                case EventType.KeyRelease:
                    this.Ungrab();
                    break;
                }
            }
            catch (Exception ex)
            {
                this.Ungrab();
                Tools.PrintInfo(ex, this.GetType());
            }

            return(FilterReturn.Continue);
        }
예제 #2
0
        /// <summary>
        /// Handles X events. Gets first and second selection points and sets selected screen region as clipboard content.
        /// </summary>
        /// <param name="xEvent">X event.</param>
        /// <param name="gdkEvent">Gdk event.</param>
        private FilterReturn OnScreenshotMouseChanged(IntPtr xEvent, Event gdkEvent)
        {
            try
            {
                IXButtonEvent evnt = null;

                switch (this.architecture)
                {
                case Architectures.X86:
                    evnt = (XButtonEvent32)Marshal.PtrToStructure(xEvent, typeof(XButtonEvent32));
                    break;

                case Architectures.X86_64:
                    evnt = (XButtonEvent64)Marshal.PtrToStructure(xEvent, typeof(XButtonEvent64));
                    break;
                }

                switch (evnt.Type)
                {
                case EventType.ButtonPress:
                    this.rectangle = new Rectangle(evnt.X, evnt.Y);
                    this.pixbuf    = Pixbuf.FromDrawable(this.rootWindow, this.rootWindow.Colormap, 0, 0, 0, 0, this.rootWindow.Screen.Width, this.rootWindow.Screen.Height);
                    this.CreateWindow();

                    break;

                case EventType.ButtonRelease:
                    this.rectangle.SetEndPoint(evnt.X, evnt.Y);
                    Pixbuf pb = this.GetPixmapFromRectangle();

                    this.Ungrab();
                    this.rectangle = null;

                    if (pb != null)
                    {
                        new ImageWindow(pb).ShowAll();
                        pb.Dispose();
                    }

                    break;

                case EventType.MotionNotify:
                    if (this.rectangle != null && this.rectangle.X2 != evnt.X && this.rectangle.Y2 != evnt.Y)
                    {
                        this.rectangle.SetEndPoint(evnt.X, evnt.Y);
                        this.window.Move(this.rectangle.X1 < this.rectangle.X2 ? this.rectangle.X1 : this.rectangle.X2, this.rectangle.Y1 < this.rectangle.Y2 ? this.rectangle.Y1 : this.rectangle.Y2);
                        this.window.Resize(this.rectangle.Width, this.rectangle.Height);
                    }

                    break;

                case EventType.KeyPress:
                case EventType.KeyRelease:
                    this.Ungrab();
                    this.rectangle = null;

                    break;
                }
            }
            catch (Exception ex)
            {
                this.Ungrab();
                Tools.PrintInfo(ex, this.GetType());
            }

            return(FilterReturn.Continue);
        }