addWindow Dramas

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

addWindow Dramas

Post by renegadeandy »

Hey hey.

Having a bit of an issue with a window gui problem. I want to make the bottom panel for my GUI which will be used as the main control centre for my RTS game kinda like the bottom panel you see in this screenshot of warcraft 3:

http://www.theblisspages.com/images/warcraft3.jpg

Now, i thought this would be simple - get a window and stick it 1/5th of the way down the screensize height, and then stretch it for the width of the screen and I ended up with this code:

(I want this to use the screensizes because otherwise it will be rubish should i include the option to change resolutions.

Code: Select all

gui::IGUIWindow *window = guienv->addWindow(core::rect<s32>(0,driver->getScreenSize().Height - driver->getScreenSize().Height/5,driver->getScreenSize().Width,2000));
Now the reason I have 2000 in for the y2 value is because it is casuing me trouble, no matter what large number I set this to it always keeps the window at the same size...

am i correct in saying x,y are bottom left, and x2,y2 are top right - if this is the case then this should be working fine.

Please help me! :oops:
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

Actually it is top-left and bottom-right. And it would've taken you less time to check that yourself, than writing that lengthy post. :)
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

well the folks on irc seem to have been incredibly confused by it all and told me otherwise...

cheers guys!

Anyway so if it is top left to top right,, does the bottom left of the screen equate to 0,0 and top left 0,1024 (or however high your monitor is in terms of resolution)?
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

No! It is:

Code: Select all

core::rect<s32>(top-left x, top-left y, bottom-right x, bottom-right y)
So, your full screen window would be

Code: Select all

core::rect<s32>(0,0,1024,768)
It seems you are confusing that your sceen Y increases as you go down, not up.
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

riiight, so i would want the following:



(0,0,widthofscreen, height of screen - height of screen / 4) to create a window segment which covers the bottom quarter of the screen?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

No. All points are relative to the top left corner of the rendering window.

That means that core::position2di(0, 0) is the top left corner. If you use core::rect<s32>(0, 0, w, h), your window will start at the top left corner of the rendering area and will be w units wide and h units tall. Your example will fill the top 3/4 of the screen. You want

Code: Select all

const core::dimension2di ss = driver->getScreenSize();

// [x1=0                ]: left of rect is at 0 pixels from left edge of screen
// [y1=ss.Height * 3 / 4]: top edge is 3/4 of screen height from top
// [x2=ss.Width         ]: right edge is 0 pixels from right edge of screen
// [y2=ss.Height        ]: bottom edge is 0 pixels from the bottom
const core::rect<s32> ws(0, ss.Height * 3 / 4, ss.Width, ss.Height);
You could do the calculations like this if it makes more sense to you...

Code: Select all

core::rect<s32> rect_getFromEdges(s32 in_from_left, s32 in_from_top, s32 in_from_right, s32 in_from_bottom, video::IVideoDriver* driver)
{
    const core::dimension2di ss = driver->getScreenSize ();
    return core::rect<s32>(in_from_left, in_from_top, ss.Width - in_from_right, ss.Height - in_from_bottom);
}
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

got it with

Code: Select all

gui::IGUIWindow * window = guienv->addWindow(core::rect<s32>(core::position2d<s32>(0,static_cast<int>(device->getVideoDriver()->getScreenSize().Height/4)*3),
		core::dimension2d<s32>(device->getVideoDriver()->getScreenSize().Width, static_cast<int>(device->getVideoDriver()->getScreenSize().Height/4))), 
		false, L"Main menu", guienv->getRootGUIElement(), id);
Anyways - i need to hide the title of this window - i know you cannot do this and must override something or whatever, but has anybody found a decent, simple way to do this - and if so, please link it to me.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

renegadeandy wrote:i need to hide the title of this window - i know you cannot do this and must override something or whatever, but has anybody found a decent, simple way to do this - and if so, please link it to me.
you could also use an IGUITab...
simply use addTab instead of addWindow... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

You also can use IGUIImage -- you will be able to assign background image for your "window" very easy.
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

got tabs working - however I am using IGuiImage but i dont see the option for background - where does this exist?
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

By saying "background" I ment the image which IGUIImage allows to assign to it (because of the nature and purposes of this control). That image will be "background" for all children of created IGUIImage.

So, what you do:

Code: Select all

gui::IGUIImage *imgPanel;

imgPanel = irrGUI->addImage(core::rect<s32>(0,0,512,512));
imgPanel->setImage(irrVideo->getTexture("background.png"));

// now you place controls on this "window" in the next way:

irrGUI->addStaticText(L"Static text", core::rect<s32>(10, 10, 200, 40), false, true, imgPanel);

// and so on...
That is it.

P.S.: now if you want to move or hide panel, you do it only for imgPanel.
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

kinda already have that with this code:

Code: Select all

gui::IGUIWindow * window = guienv->addWindow(core::rect<s32>(core::position2d<s32>(0,static_cast<int>(device->getVideoDriver()->getScreenSize().Height/4)*3),
		core::dimension2d<s32>(device->getVideoDriver()->getScreenSize().Width, static_cast<int>(device->getVideoDriver()->getScreenSize().Height/4))));

	
	
	   gui::IGUIImage *image = guienv->addImage(
	      driver->getTexture("resources/bottom-overlay.png"),
	      core::position2d<s32>(0,0), false, window);

	  image->setRelativePosition(core::rect<s32>(0,0,1280,256));
	  image->setUseAlphaChannel(true);
	   image->setScaleImage(true);
Is that equivalent then?
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Looks like yes, but anyway, i do not understand why do you need IGUIWindow at all, since you are completely covering it with the image.

P.S.: anyway, your code will work also.
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

because i need to add buttons etc and it will keep it all in one place.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

You can add any GUI controls to the IGUIImage (just like it would be IGUIWindow).... and they all will be in one place.
:)
Post Reply