Re: Center Window Based On Parent Window

new topic     » goto parent     » topic index » view thread      » older message » newer message

Christopher B wrote:

> Hello All,
>
> I am trying to center a window based on the position of the parent window.
> So the newly opened window will always be in the center of the parent
> window. I know how to center a window, but I am having problems with this,
> anyone has a solution?

global function centerX (integer parentX, integer parentWidth, integer
childWidth)
   return parentX + (parentWidth-childWidth)/2
end function

global function centerY (integer parentY, integer parentHeight, integer
childHeight)
   return parentY + (parentHeight-childHeight)/2
end function

-- Demo
integer parentX, parentY, parentWidth, parentHeight, childWidth, childHeight
integer childX, childY

parentX = 100
parentY =  20
parentWidth  = 80
parentHeight = 40
childWidth  = 60
childHeight = 30

childX = centerX(parentX, parentWidth, childWidth)
childY = centerY(parentY, parentHeight, childHeight)
printf(1, "Upper left corner of the child window is {%d,%d}.", {childX,childY})


Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu