Results 1 to 17 of 17

Thread: Relative coordinates in a GUI system [Resolved]

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    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
    Last edited by SLH; Sep 17th, 2004 at 03:25 PM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  2. #2
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    When your running that for the Children you shouldn't be using ResX & ResY? You should be using the Parrents Size?
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  3. #3

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Thanks for your reply.


    I've shown the relative coordinates (the window positions aren't quite right, but you get the idea).

    GUI_SCALEX = 1000
    GUI_SCALEY = 1000

    i.e. if i put a child at 450,450,550,550 it should show up in the middle of it's parent (no matter where the parent is).

    If i made the parent window's coordinates 450,450,550,550 it would be in the middle of the screen, so i know that a window with no parent works ok.
    Attached Images Attached Images  
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  4. #4
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Am I right though in say to position Child you don't bother with ResX & ResY at all all you need is the Parent Width & Hight and also the parents position?
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  5. #5

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Originally posted by Electroman
    When your running that for the Children you shouldn't be using ResX & ResY? You should be using the Parrents Size?
    ehh...

    I simply call the parents VirtX(orY)toPixels method, to get how much to add to the coordinate i get.

    I have to do m_pParents->VirtXtoPixels as opposed to just VirtXtoPixels, otherwise i get infinate recursion.


    Formula i'm using:

    childrealxpos = parent's real xpos + my real xpos relative to my parent.

    parent's real pos i get by recursion
    my real xpos relative to parent is this line:return((int)((double)virtX*(double)tmpWidth/GUI_SCALEX) + tmpAdd)

    tmpWidth is only calculated in an if operator because the base window (with no parent) is relative to RESX/RESY as opposed to a parent.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  6. #6

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Originally posted by Electroman
    Am I right though in say to position Child you don't bother with ResX & ResY at all all you need is the Parent Width & Hight and also the parents position?
    Correct.

    Here's the virtxtopixels re-written using if's as opposed to ?:

    Code:
    int VirtXtoPixels(int virtX)
    {
        int tmpWidth;
        if(m_pParent)
            tmpWidth = m_pParent->m_rPosition.right-m_pParent->m_rPosition.left;
        else
            tmpWidth =RESX;
    
        int tmpAdd;
        if(m_pParent)
            tmpAdd = m_pParent->VirtXtoPixels(m_pParent->m_rPosition.left);
        else
            tmpAdd = 0;
        return((int)((double)virtX*(double)tmpWidth/GUI_SCALEX) + tmpAdd);
    }
    Last edited by SLH; Sep 16th, 2004 at 08:51 AM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    yea the ?'s had thown me off a bit, I read the code properly and spotted it though, it was just I'd seen ResX and ResY on both and didn't look further, opps.


    Anyway what is the bug? Am I write guessing the whole thing works when the scale is 1000 but goes funny at lower values? Or does it not work at all?

    I had similar issues with the Vector Game I made cos I included a scaling thing which allowed the camera to zoom in and out, the problem was that I had to make it scale from the centre not 0,0 and also the positioning of the objects was being related to 0,0 not the centre. maybe that will help?
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  8. #8

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    I don't change GUI_SCALEX or GUI_SCALEY, but even if i do the child window are displayed in the wrong positions.

    A window with NULL m_pParent works.

    The coordinates (0,0) for a child window seems to work, but any other value doesn't.

    Meaning if the child's top-left corner is placed as (0,0) it is correctly displayed in it's parent's top left. However, the child's bottom-right corner is displayed wrongly, sometimes outside the parent all together.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  9. #9
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    What do you keep Scale set to? If you set it to 1 then I would expect everything to work fine? Just tried putting some numbers thoguh it and they seemed ok with Scale at 1 anyway?
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  10. #10

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Originally posted by Electroman
    What do you keep Scale set to? If you set it to 1 then I would expect everything to work fine? Just tried putting some numbers thoguh it and they seemed ok with Scale at 1 anyway?
    ?? Where/what is 'Scale'?
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  11. #11
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Posted by SLH
    ?? Where/what is 'Scale'?
    I mean GUI_SCALEX & GUI_SCALEY . Sorry couldn't think of the exact names .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  12. #12

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    The are both = 1000, i never change them.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  13. #13
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Posted by SLH
    The are both = 1000, i never change them.
    Try them at 1 and see if that looks right .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  14. #14

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Thanks for your continued help. Your suggestion didn't work, unfortunatly.


    To explain what i'm doing more throughly:

    When i setup a window i give it coordinates as a proportion of GUI_SCALEX and GUI_SCALEY (stored in the RECT m_rPosition)

    The position where the window is actually drawn depends on where it's parent is, if it has one, and these coordinates.

    A window with no parent is drawn relative to the screen's resolution, hence RESX and RESY in the 'else' of the (m_pParent) if statements.

    A window with a parent is drawn in a position relative to the parent i.e. moving the parent will also move the child, hence working out the width/height of the parent, so i know how far along the parent to draw the child.

    Sorry if i'm not explaining myself very well.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  15. #15
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Yea I understand what you're tryign to do but I hadn't realised the Rect m_rPosition had been scaled first of all.


    BTW shouldn't tmpAdd be devided by GUI_SCALEX or GUI_SCALEY when you add it on? Apart from that I would have thought it would work.....unless you need some brackets in the tmpWidth/GUI_SCALEX bit to makesure the order it happens in is right? Can't remember but I'm pretty sure Devision is first so they shouldn't be needed.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  16. #16

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Since tmpAdd is calculated using the parent's call to VirttoPixels it should be an absolute value, and so shouldn't need to be divided by GUI_SCALE.

    I did try it though, but it didn't work
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  17. #17

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Sorted it!

    Here's my final code:
    Code:
    int VirtXtoPixels(int virtX)
    	{
    		int tmpAdd;
    		int tmpWidth;
    		if(!m_pParent)
    			return (int)((double)virtX/GUI_SCALE * (double)RESX);
    
    		tmpWidth = m_pParent->VirtXtoPixels(m_pParent->m_rPosition.right-m_pParent->m_rPosition.left);
    		tmpAdd = m_pParent->VirtXtoPixels(m_pParent->m_rPosition.left);
    		return (int)(virtX/GUI_SCALE * tmpWidth + tmpAdd);
    		
    	}
    	int VirtYtoPixels(int virtY)
    	{
    		int tmpAdd;
    		int tmpHeight;
    		if(!m_pParent)
    			return (int)((double)virtY/GUI_SCALE * (double)RESY);
    
    		tmpHeight = m_pParent->VirtYtoPixels(m_pParent->m_rPosition.bottom-m_pParent->m_rPosition.top);
    		tmpAdd = m_pParent->VirtYtoPixels(m_pParent->m_rPosition.top);
    		return (int)(virtY/GUI_SCALE * tmpHeight + tmpAdd);
    	}
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width