HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Use of effective scale in positioning controls  (Read 867 times)


  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Use of effective scale in positioning controls
« on: Apr 04, 13, 04:38:50 PM »

I was looking over the code for the way that GUIContolClassMethods positions controls in various methods and I came across something I am not sure about.

In method centerControlOver(), it gets the effective scale of me and later multiplies that scale by the size to get the absolute size in screen space:
Code: (hsl) [Select]
  var scale = me.getEffectiveScale()
  if parentControl == None             // use the screen, yo
    screen as Vector3 = GetViewPortSize()
    me.position.x = (screen.x - (scale * me.size.x)) / 2
    me.position.y = (screen.y - (scale * me.size.y)) / 2

which looks to be correct, except that the position calculated is in screen space, so should it be then divided by the scale of the control before being assigned to the position?

But below that in method positionControlAtMouse(), it is directly using the size of the control to compare to screen coordinates, as in line 655:
Code: (hsl) [Select]
if ((currentMousePos.y + me.size.y) > screen.y)   // no room below!
It seems to me like that size should also be multiplied by the effective scale in order for the size to be in screen space.  Does that seem correct?

As a side note, the reason I was looking at that positionControlAtMouse() method was because it is the only place I found that will check if a control would be at all off-screen, and if so adjust the position so it is not.  That would be handy code to have in a separate method for ensuring any given window is not offscreen, for instance after it is positioned by the centerControlOver(), which I am finding sometimes positions things off-screen if the parent control is close to the edge.

I will just go ahead and write an individual method myself, but it could be a nice addition to the Clean Engine in the future.
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.