Advertisement Jump to content
Sign in to follow this  

Need help with GUI Bug

This topic is 4893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright, I'm using VB.NET and DX9. Assume a class for a control (UIControl). The Control's Size is suppose to be 120x32. When I have the application in Windowed mode, the control is 81x21. When I go to Fullscreen mode (no resolution change other than window size), the control is 128x32. Furthermore, when I stretch my window size, the image also changes size. This is frustrating. My assumption was that by specifying the size, location, etc... of the control in my render methods that it would actually display that way. Here's how I render:
'Assume ControlImage is a Texture (DX9 Texture)

    Public Function GetAbsolutePosition() As Point
        Dim lX As Int32
        Dim lY As Int32

        lX = moLoc.X
        lY = moLoc.Y

        If ParentControl Is Nothing = False Then
            Dim oTmp As Point
            oTmp = ParentControl.GetAbsolutePosition()
            lX += oTmp.X
            lY += oTmp.Y
            oTmp = Nothing
        End If

        Return New Point(lX, lY)
    End Function

    Public Overridable Sub Control_OnRender() Handles MyBase.OnRender
        Dim oRect As Rectangle
        Dim oLoc As System.Drawing.Point

        oLoc = GetAbsolutePosition()
        With oRect
            .Location() = oLoc
            .Width = Width
            .Height = Height

            'render the back image if there is one
            If ControlImage Is Nothing = False Then
                With moUILib.Pen
                    .Draw2D(ControlImage, System.Drawing.Point.Empty, 0, oLoc, System.Drawing.Color.FromArgb(&HFFFFFFFF))
                End With
            End If
            moFont.DrawText(Nothing, Caption, oRect, FontFormat, ForeColor)
        End With
    End Sub

What is also annoying is that when I click on the form I get the coordinates of where I clicked on the form. I then compare that to the controls on the form (checking for click events). The location of the control is off... I walked the code but could not find out why. The code says that it is located at 300x300 (for example) and I clicked at 305x310 (for example). In this instance, it is correct that I clicked on the button... but the problem is, I was clicking about 200 pixels away. Any thoughts? Is there a transform I need to set before I do my interface work? I thought by doing Draw2D it would do the work for me. Thanks, Matt

Share this post

Link to post
Share on other sites
It's most likely what you do when you re-initialize the perspective projection and/or the presentation parameters after resizing the window. You're doing that, right? :) I guess it also depends on whether you are using an orthogonal projection or pre-transformed, pre-lit vertices.

Share this post

Link to post
Share on other sites
My Matrix routine:

Private Sub SetupMatrices()
moDevice.Transform.View = Matrix.LookAtLH(New Vector3(0, 1000, -1000), _
New Vector3(0, 0, 0), New Vector3(0.0#, 1.0#, 0.0#)) 'up is always this
moDevice.Transform.Projection = Matrix.PerspectiveFovLH(0.7853981633974475, 1, 1, 10000)
End Sub

There are no vertices and I am not using Ortho.

Also, as of right now I am not resetting my presentation params... but that does not explain why windowed and non-windowed mode are working the way they are and why the control is not the correct size.

Share this post

Link to post
Share on other sites
Did you forget to set up your form's coordinate to be independent with destop resolution ?. As I remember (I stopped working with VB quite a long time), the form's Width, Height and position properties by default are automatically managed by the internal structure of the form and it depends on your desktop resolution, so that your control's position remain unchaged when switching res.

Share this post

Link to post
Share on other sites
I'm an idiot. :)

Just thought I would include that preface before making an ass out of myself...

The following lines of code were in my Present Parms configuration when running windowed mode:

.BackBufferHeight = uDispMode.Height
.BackBufferWidth = uDispMode.Width

I have thus changed this to be:

.BackBufferHeight = Me.ClientSize.Height
.BackBufferWidth = Me.ClientSize.Width

I'm going to muck with the Fullscreen mode next and see if it is a similar problem.

Thanks for hinting me in the right direction.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!