help with ui mouse intersection

Started by
30 comments, last by 31337noob 18 years, 3 months ago
hi, i have one problem with my UI and that problem is this. i think i am caluclating my intersection wrong. when i have a button in my window, i cant click everywhere on that button. only half of that button i can click on.


void UIControl::getAbsPos(D3DXVECTOR2 *position)
{
	position->x += this->getX();
	position->y += this->getY();

	if(this->parent)
		this->parent->getAbsPos(position);
}

bool UIControl::cursorIntersection(int x, int y)
{
	D3DXVECTOR2 cabs;
	cabs.x = 0;
	cabs.y = 0;

	this->getAbsPos(&cabs);

	if((x >= cabs.x) && (x <= (cabs.x + this->getWidth())))
		if((y >= cabs.y) && y <= ((cabs.y + this->getHeight())))
			return true;

	return false;
}

//in a message loop
if(this->cursorIntersection(LOWORD(lParam), HIWORD(lParam))
{
   //code
}


please help me thanks in advanced
Advertisement
help me...............
why are you += here?:

position->x += this->getX();
position->y += this->getY();
http://www.thedizzle.com
Quote:Original post by rgirard413
why are you += here?:

position->x += this->getX();
position->y += this->getY();


otherwise it screws up the window positions.
Quote:Original post by 31337noob
when i have a button in my window, i cant click everywhere on that button. only half of that button i can click on.

To investigate the problem furthur...:

What half is active, and where is the button located than?

How does the active area change if you re-locate the button a little bit?

Where is the origin of the co-ordinate system in use (left top, left bottom, middle of the window), and is the origin of the x,y parameters the same?

(I assume the following to play no role, since most often a control is missed totally if this would be wrong.) To what direction do the co-ordinates grow? (Say, do your pointer co-ordinates grow in the same direction as the control's co-ordinates do?)

Quote:Original post by 31337noob
i think i am caluclating my intersection wrong.

The snippet you've posted seems me correct. I expect the problem to be caused elsewhere.
Quote:Original post by haegarr
Quote:Original post by 31337noob
when i have a button in my window, i cant click everywhere on that button. only half of that button i can click on.

To investigate the problem furthur...:

What half is active, and where is the button located than?

How does the active area change if you re-locate the button a little bit?

Where is the origin of the co-ordinate system in use (left top, left bottom, middle of the window), and is the origin of the x,y parameters the same?

(I assume the following to play no role, since most often a control is missed totally if this would be wrong.) To what direction do the co-ordinates grow? (Say, do your pointer co-ordinates grow in the same direction as the control's co-ordinates do?)

Quote:Original post by 31337noob
i think i am caluclating my intersection wrong.

The snippet you've posted seems me correct. I expect the problem to be caused elsewhere.



How does the active area change if you re-locate the button a little bit?
it does change but still doesnt get the whole button

Where is the origin of the co-ordinate system in use (left top, left bottom, middle of the window), and is the origin of the x,y parameters the same?

top-left
Quote:Original post by 31337noob
How does the active area change if you re-locate the button a little bit?
it does change but still doesnt get the whole button

Ok, but the question is _how_ does it change. E.g. if you shift the button to the right / bottom (say you increase the value of getX() / getY()), does the active area grow or shrink? Does it grow / shrink exactly by the amount of the shift? So you can determine whether there is an absolute or a relative border.

Is the active area always to the right / bottom? Is the button totally active if you shift it far enough into one of the quadrants? Then you may have a sign resp. origin problem.

Since the posted code isn't IMHO sufficient to locate the problem, I suggest you to do the following: Restrict the UIControl to have none or at most one parent. Locate it so that it is in (0,0) and covers the whole window area. Set a breakpoint into UIControl::cursorIntersection, and investigate the values of x,y and cabs for various clicks. Then you should follow the questions above. From the results you could determine the cause of the problem.
ok, here is what i know so far.

i put the parent window at (0,0) and the button at (0,0)

when i move the window to the bottom of the screen, i can go below the picture of the button and it can be clicked on. how can that happen if i am not even on the button. ok, now if i move the window to the top left, i can click on the very top of the button but i cant click on the bottom of the button or the right part of the button. now if i move the window to the right, i still cant click on the right part of the button.

i do know why it doesnt register the right part though. the width and height is a little off.

so i think the problem is the absoulte function.

so what do you think?

please help.


what do i do next?

i bet if we get the abs thing working the whole thing will be working.
ok, this is werider. i just found out it doesnt do this werid problem when its in fullscreen. ok so how can i deal with it when its not in fullscreen.
so what do i do?

This topic is closed to new replies.

Advertisement