Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Objects for GUI and calculating width in pixels

Author
Message
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 3rd May 2011 13:06
So I've been (along with several shaders, help from gg and various users w/ terraforming large numbers of plane objects and so on and so fourth for a WIP) building a GUI using plane objects w/ .PNG textures for alpha mapping. I have a plane that upon a button click, I would like it to shrink to 1/15th it's size and move to the upper right corner of the screen. (or upper left if it's easier) I could position the object soundly if I had/knew of a way to convert from 3d width to 2d width, grab 2d position w/ pick commands then reposition in 3d based on the target 2d location. I've been looking around now for a bit and I'd really appreciate any pointers/help understanding how to do this

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 3rd May 2011 23:11 Edited at: 3rd May 2011 23:11
I don't think you need to worry about knowing the button size.

I would do this by using an object for the cursor and just detecting collision with the object against the planes used for the buttons. A bit like this:



Hope this helps.
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 4th May 2011 04:16 Edited at: 4th May 2011 04:19
I'm sorry I tend to not be clear - I have a title object... whats using an image that has the game's name on it. When you click "new game" a new object with the next set of things (image) on it comes up... what I want to do is scale down the title object and move it to the upper left corner of the screen - since screen sizes vary, I need to ensure that the scale and position of the title object are always correct. All of my buttons work fine just a scale down and reposition relative to the size of the screen

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 4th May 2011 12:01 Edited at: 4th May 2011 12:01
Take a look at my post here:
http://forum.thegamecreators.com/?m=forum_view&t=177139&b=1&msg=2111926#m2111926
It has a link to Cloggy's snippets. It's the "HUD" one in the snippet list you want.

Regards
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 4th May 2011 14:38
Sorry, that was my fault for not reading your post correctly.

However, I still don't think that you need to know the screen size or resolution.

If your buttons are all 3D object, then the size of the screen being used doesn't matter nor does the resolution as 3D object are not position according to the screen pixels.

Providing the camera is fixed and all your buttons are the same distance from the camera then you should be able to position the buttons anywhere and scale them as you see fit, without anything being in the wrong place on any screen.

It's then just a case of figuring out a way of picking the buttons.

If you're using an object for the cursor (like I did in my example above) then use collision detection between the cursor object and the button objects. The size of the screen and the resolution are not required as far as I can see.

If you're using the actual mouse position (i.e. it's screen position) then you need a way to pick the button object. I suspect at this point knowing the screen resolution might be required.

I can see this being a problem in 2D as size and position of sprites are all tied into the screen resolution, the same would be true if you were using text in a 3D application, but I don't see why you need to know the screen size at all for 3D. Changing the resolution would just make things more or less pixalated but wouldn't actually alter the physical size or position of any of the objects.

Or maybe I'm missing something. Not having done any serious GUI coding I wouldn't be suprised.

I'll have a bit of play, as I find this quite interesting and will be useful to me, and I'll let you know.
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 19th May 2011 23:45
Okay - well I've gotten it to do what I want it to, but now I have a problem - how do I report the same position in 2d (like say I have a text box via textured 3d object) and keep the cursor on the right location (I.E. the textured text box?)

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 20th May 2011 08:42
Bump

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 20th May 2011 10:47
Quote: "Okay - well I've gotten it to do what I want it to, but now I have a problem - how do I report the same position in 2d (like say I have a text box via textured 3d object) and keep the cursor on the right location (I.E. the textured text box?)"


Need a little more to go on

What method are you using?
With Cloggy's method you can use pick object to get status if the cursor is over an object. Or you can store the "top left x,y" and "bottom right x,y" corner (2D) coordinates of the object and use MouseX,MouseY to compare those with.

Regards
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 24th May 2011 20:51
okay a simple diagram lol - attached.

basically since the screen resolution is changing or can be changed by the user, and because the cursor is a 2d restrained command, I need to gather how many pixels there are in the screen and where in 2d the position of the cursor should be in order to always be over my 3d plain, which has a bg image on it to make it look like a text box. got it?

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
waffle
23
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 26th May 2011 02:55
Here is a simplified method that has worked for me in DBC...
should be the same in DBPro...

1 - position your 3D object
2 - Copy this object to use for "testing"....
3 - Position this "test" object on the left/right/top/bottom
of the original object, and each time you place it,
save the GET SCREEN POSITION X(), GET SCREEN POSITION Y() for the object
4 - The width/height of the object would be the difference of these values.

Now, all you need do is compare the MouseX/Y to the
3D objects ScreenX/Y +/- the width/height ....

This will work under any screen resolution, And makes placing text simple..

Login to post a reply

Server time is: 2026-07-11 02:36:55
Your offset time is: 2026-07-11 02:36:55