Relative coordinates in a GUI system [Resolved]
I'm making a GUI for directx.
A window has either a parent (window it's displayed in) or NULL (it's the desktop).
A window's coordinates range from 0 to GUI_SCALEX and 0 to GUI_SCALEY.
RESX and RESY dictate the resolution for the screen.
I've attached the code i'm using below.
It works for the desktop window (parent of NULL), but not it's child window.
Can anyone see what i've done wrong?
Code:
int VirtXtoPixels(int virtX)
{
int tmpWidth = (m_pParent) ? m_pParent->m_rPosition.right-m_pParent->m_rPosition.left : RESX;
int tmpAdd = (m_pParent) ? m_pParent->VirtXtoPixels(m_pParent->m_rPosition.left) : 0;
return((int)((double)virtX*(double)tmpWidth/GUI_SCALEX) + tmpAdd);
}
int VirtYtoPixels(int virtY)
{
int tmpHeight = (m_pParent) ? m_pParent->m_rPosition.bottom-m_pParent->m_rPosition.top : RESY;
int tmpAdd = (m_pParent) ? m_pParent->VirtYtoPixels(m_pParent->m_rPosition.top) : 0;
return((int)((double)virtY*(double)tmpHeight/GUI_SCALEY) + tmpAdd);
}
FYI ?: is a ternary operator with the following syntax:
Test ? True statement : false statement