# Need help with GUI Bug

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

## 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
.Begin(SpriteFlags.None)
.Draw2D(ControlImage, System.Drawing.Point.Empty, 0, oLoc, System.Drawing.Color.FromArgb(&HFFFFFFFF))
.End()
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 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 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 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 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.

-Matt

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011467
• ### Who's Online (See full list)

There are no registered users currently online

×