smika's picture

Hidden border window move and resize

We are developing a user interface toolkit (buttons, labels, entries, etc) on top of OpenTK. Since our goals include custom appearance and a touchscreen friendly user interface we use today a NativeWindow with hidden borders and provide custom title bar and border.

Performing move and resize using the regular mouse events is not suitable since the mouse easily gets outside the window during these operations. In order to solve this it would probably be good to have specialized functions that start a move or resize operation and hand over it to the window manager to complete. In windows this is done by some calls to functions in "user32.dll". These require the native window handle as argument. This handle is for architectural reasons not available for applications that use OpenTK. So right now we face the issue of adding functionality to start move and resize operations to OpenTK. Is this of more general interest? Are there other preferable methods? Will an API like this be implementable on the other supported platforms as well?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Is there a MSDN link to those functions?

Would standard drag & drop events provide a solution to this issue? (They are not implemented in OpenTK right now but they might be in the future).

zahirtezcan's picture

@the Fiddler
Actually drag and drop events are for (especially) inter application data provision. That is, you may want to move an image on your picture box to another window to indicate that the image will be used for the desired action by the other window's application. Then you define data objects to windows system by starting the drag event from picture box(drag source) and set the window as a drop target and filter incoming data at panel blah blah

@smika (and possibly the Fiddler)
First, usual windows forms events works outside the window in a way such that; after you press button and start dragging, events continue to be fired even if the pointer is outside the window. If this is not the case then there could be some problem in OpenTK native support

Second, for the functions in user32.dll, what kind of functions are you subjecting and please specify the functions so we may investigate

the Fiddler's picture
Quote:

First, usual windows forms events works outside the window in a way such that; after you press button and start dragging, events continue to be fired even if the pointer is outside the window. If this is not the case then there could be some problem in OpenTK native support

That's what I was thinking with "drag & drop events". I wonder, is this normal win32 behavior or do you have to implement this manually by capturing the pointer on mouse down?

smika's picture

This what it could look like in the Windows case:

        #region StartMove
        public void StartMove()
        {
            Functions.ReleaseCapture();
            Functions.SendMessage(this.window.WindowHandle, WindowMessage.NCLBUTTONDOWN, (IntPtr)0x2, IntPtr.Zero);
        }
        #endregion
        #region StartResize
        public void StartResize(ResizeDirection direction)
        {
            int parameter = 61440;
            switch (direction)
            {
                case ResizeDirection.Left:
                    parameter += 1;
                    break;
                case ResizeDirection.Right:
                    parameter += 2;
                    break;
                case ResizeDirection.Top:
                    parameter += 3;
                    break;
                case ResizeDirection.Bottom:
                    parameter += 6;
                    break;
                case ResizeDirection.LeftTop:
                    parameter += 4;
                    break;
                case ResizeDirection.LeftBottom:
                    parameter += 7;
                    break;
                case ResizeDirection.RightTop:
                    parameter += 5;
                    break;
                case ResizeDirection.RightBottom:
                    parameter += 8;
                    break;
            }
            Functions.SendMessage(this.window.WindowHandle, WindowMessage.SYSCOMMAND, (IntPtr)parameter, IntPtr.Zero);
        }
        #endregion

The user of this will probably have to call these functions whenever a move with the left button pressed occurs close to the window border or inside the window header.

zahirtezcan's picture

I don't remember the native win32 behaviour, but this is the case for a Windows.Forms application. I guess it captures the mouse when the down event occurs. I have created a test case with a red panel in a form. Then listened to the mousemove event. Events continue to fire even if my pointer is outside the window. (I can see the result on Output window of VS )

AttachmentSize
MouseMotionTest.zip35.86 KB
the Fiddler's picture

Thanks for the test. I also think that WinForms are capturing the mouse (will have to check with the Mono source to verify). This behavior is simple to implement inside OpenTK and I think it would solve the original issue, no?

zahirtezcan's picture

It will solve the issue of managing borderless windows. But, if we are talking about new event type, then it should be discussed more