2 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
3 // This file is part of the "Irrlicht Engine".
\r
4 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
6 #include "CGUIEnvironment.h"
\r
8 #ifdef _IRR_COMPILE_WITH_GUI_
\r
10 #include "IVideoDriver.h"
\r
12 #include "CGUISkin.h"
\r
13 #include "CGUIButton.h"
\r
14 #include "CGUIScrollBar.h"
\r
15 #include "CGUIFont.h"
\r
16 #include "CGUISpriteBank.h"
\r
17 #include "CGUIImage.h"
\r
18 #include "CGUICheckBox.h"
\r
19 #include "CGUIListBox.h"
\r
20 #include "CGUIImageList.h"
\r
21 #include "CGUIFileOpenDialog.h"
\r
22 #include "CGUIStaticText.h"
\r
23 #include "CGUIEditBox.h"
\r
24 #include "CGUITabControl.h"
\r
25 #include "CGUIComboBox.h"
\r
27 #include "IWriteFile.h"
\r
28 #ifdef IRR_ENABLE_BUILTIN_FONT
\r
29 #include "BuiltInFont.h"
\r
38 const io::path CGUIEnvironment::DefaultFontName = "#DefaultFont";
\r
41 CGUIEnvironment::CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op)
\r
42 : IGUIElement(EGUIET_ROOT, 0, 0, 0, core::rect<s32>(driver ? core::dimension2d<s32>(driver->getScreenSize()) : core::dimension2d<s32>(0,0))),
\r
43 Driver(driver), Hovered(0), HoveredNoSubelement(0), Focus(0), LastHoveredMousePos(0,0), CurrentSkin(0),
\r
44 FileSystem(fs), UserReceiver(0), Operator(op), FocusFlags(EFF_SET_ON_LMOUSE_DOWN|EFF_SET_ON_TAB)
\r
56 IGUIEnvironment::setDebugName("CGUIEnvironment");
\r
61 IGUISkin* skin = createSkin( gui::EGST_WINDOWS_METALLIC );
\r
65 //set tooltip default
\r
66 ToolTip.LastTime = 0;
\r
67 ToolTip.EnterTime = 0;
\r
68 ToolTip.LaunchTime = 1000;
\r
69 ToolTip.RelaunchTime = 500;
\r
70 ToolTip.Element = 0;
\r
72 // environment is root tab group
\r
79 CGUIEnvironment::~CGUIEnvironment()
\r
81 clearDeletionQueue();
\r
83 if ( HoveredNoSubelement && HoveredNoSubelement != this )
\r
85 HoveredNoSubelement->drop();
\r
86 HoveredNoSubelement = 0;
\r
89 if (Hovered && Hovered != this)
\r
101 if (ToolTip.Element)
\r
103 ToolTip.Element->drop();
\r
104 ToolTip.Element = 0;
\r
110 CurrentSkin->drop();
\r
116 // delete all sprite banks
\r
117 for (i=0; i<Banks.size(); ++i)
\r
119 Banks[i].Bank->drop();
\r
121 // delete all fonts
\r
122 for (i=0; i<Fonts.size(); ++i)
\r
123 Fonts[i].Font->drop();
\r
133 FileSystem->drop();
\r
145 void CGUIEnvironment::loadBuiltInFont()
\r
147 #ifdef IRR_ENABLE_BUILTIN_FONT
\r
148 io::IReadFile* file = FileSystem->createMemoryReadFile(BuiltInFontData,
\r
149 BuiltInFontDataSize, DefaultFontName, false);
\r
151 CGUIFont* font = new CGUIFont(this, DefaultFontName );
\r
152 if (!font->load(file))
\r
154 os::Printer::log("Error: Could not load built-in Font. Did you compile without the BMP loader?", ELL_ERROR);
\r
161 f.NamedPath.setPath(DefaultFontName);
\r
163 Fonts.push_back(f);
\r
170 //! draws all gui elements
\r
171 void CGUIEnvironment::drawAll(bool useScreenSize)
\r
173 if (useScreenSize && Driver)
\r
175 core::dimension2d<s32> dim(Driver->getScreenSize());
\r
176 if (AbsoluteRect.LowerRightCorner.X != dim.Width ||
\r
177 AbsoluteRect.UpperLeftCorner.X != 0 ||
\r
178 AbsoluteRect.LowerRightCorner.Y != dim.Height ||
\r
179 AbsoluteRect.UpperLeftCorner.Y != 0
\r
182 setRelativePosition(core::recti(0,0,dim.Width, dim.Height));
\r
186 // make sure tooltip is always on top
\r
187 if (ToolTip.Element)
\r
188 bringToFront(ToolTip.Element);
\r
191 OnPostRender ( os::Timer::getTime () );
\r
193 clearDeletionQueue();
\r
197 //! sets the focus to an element
\r
198 bool CGUIEnvironment::setFocus(IGUIElement* element)
\r
200 if (Focus == element)
\r
205 // GUI Environment should just reset the focus to 0
\r
206 if (element == this)
\r
209 // stop element from being deleted
\r
213 // focus may change or be removed in this call
\r
214 IGUIElement *currentFocus = 0;
\r
217 currentFocus = Focus;
\r
218 currentFocus->grab();
\r
220 e.EventType = EET_GUI_EVENT;
\r
221 e.GUIEvent.Caller = Focus;
\r
222 e.GUIEvent.Element = element;
\r
223 e.GUIEvent.EventType = EGET_ELEMENT_FOCUS_LOST;
\r
224 if (Focus->OnEvent(e))
\r
228 currentFocus->drop();
\r
231 currentFocus->drop();
\r
237 currentFocus = Focus;
\r
239 currentFocus->grab();
\r
241 // send focused event
\r
243 e.EventType = EET_GUI_EVENT;
\r
244 e.GUIEvent.Caller = element;
\r
245 e.GUIEvent.Element = Focus;
\r
246 e.GUIEvent.EventType = EGET_ELEMENT_FOCUSED;
\r
247 if (element->OnEvent(e))
\r
252 currentFocus->drop();
\r
258 currentFocus->drop();
\r
263 // element is the new focus so it doesn't have to be dropped
\r
270 //! returns the element with the focus
\r
271 IGUIElement* CGUIEnvironment::getFocus() const
\r
276 //! returns the element last known to be under the mouse cursor
\r
277 IGUIElement* CGUIEnvironment::getHovered() const
\r
283 //! removes the focus from an element
\r
284 bool CGUIEnvironment::removeFocus(IGUIElement* element)
\r
286 if (Focus && Focus==element)
\r
289 e.EventType = EET_GUI_EVENT;
\r
290 e.GUIEvent.Caller = Focus;
\r
291 e.GUIEvent.Element = 0;
\r
292 e.GUIEvent.EventType = EGET_ELEMENT_FOCUS_LOST;
\r
293 if (Focus->OnEvent(e))
\r
308 //! Returns whether the element has focus
\r
309 bool CGUIEnvironment::hasFocus(const IGUIElement* element, bool checkSubElements) const
\r
311 if (element == Focus)
\r
314 if ( !checkSubElements || !element )
\r
317 IGUIElement* f = Focus;
\r
318 while ( f && f->isSubElement() )
\r
320 f = f->getParent();
\r
321 if ( f == element )
\r
328 //! returns the current video driver
\r
329 video::IVideoDriver* CGUIEnvironment::getVideoDriver() const
\r
335 //! returns the current file system
\r
336 io::IFileSystem* CGUIEnvironment::getFileSystem() const
\r
342 //! returns a pointer to the OS operator
\r
343 IOSOperator* CGUIEnvironment::getOSOperator() const
\r
349 //! clear all GUI elements
\r
350 void CGUIEnvironment::clear()
\r
352 // Remove the focus
\r
359 if (Hovered && Hovered != this)
\r
364 if ( HoveredNoSubelement && HoveredNoSubelement != this)
\r
366 HoveredNoSubelement->drop();
\r
367 HoveredNoSubelement = 0;
\r
370 getRootGUIElement()->removeAllChildren();
\r
374 //! called by ui if an event happened.
\r
375 bool CGUIEnvironment::OnEvent(const SEvent& event)
\r
380 && (event.EventType != EET_MOUSE_INPUT_EVENT)
\r
381 && (event.EventType != EET_KEY_INPUT_EVENT)
\r
382 && (event.EventType != EET_GUI_EVENT || event.GUIEvent.Caller != this))
\r
384 ret = UserReceiver->OnEvent(event);
\r
391 void CGUIEnvironment::OnPostRender( u32 time )
\r
394 if ( ToolTip.Element == 0 &&
\r
395 HoveredNoSubelement && HoveredNoSubelement != this &&
\r
396 (time - ToolTip.EnterTime >= ToolTip.LaunchTime
\r
397 || (time - ToolTip.LastTime >= ToolTip.RelaunchTime && time - ToolTip.LastTime < ToolTip.LaunchTime)) &&
\r
398 HoveredNoSubelement->getToolTipText().size() &&
\r
400 getSkin()->getFont(EGDF_TOOLTIP)
\r
403 core::rect<s32> pos;
\r
405 pos.UpperLeftCorner = LastHoveredMousePos;
\r
406 core::dimension2du dim = getSkin()->getFont(EGDF_TOOLTIP)->getDimension(HoveredNoSubelement->getToolTipText().c_str());
\r
407 dim.Width += getSkin()->getSize(EGDS_TEXT_DISTANCE_X)*2;
\r
408 dim.Height += getSkin()->getSize(EGDS_TEXT_DISTANCE_Y)*2;
\r
410 pos.UpperLeftCorner.Y -= dim.Height+1;
\r
411 pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + dim.Height-1;
\r
412 pos.LowerRightCorner.X = pos.UpperLeftCorner.X + dim.Width;
\r
414 pos.constrainTo(getAbsolutePosition());
\r
416 ToolTip.Element = addStaticText(HoveredNoSubelement->getToolTipText().c_str(), pos, true, true, this, -1, true);
\r
417 ToolTip.Element->setOverrideColor(getSkin()->getColor(EGDC_TOOLTIP));
\r
418 ToolTip.Element->setBackgroundColor(getSkin()->getColor(EGDC_TOOLTIP_BACKGROUND));
\r
419 ToolTip.Element->setOverrideFont(getSkin()->getFont(EGDF_TOOLTIP));
\r
420 ToolTip.Element->setSubElement(true);
\r
421 ToolTip.Element->grab();
\r
423 s32 textHeight = ToolTip.Element->getTextHeight();
\r
424 pos = ToolTip.Element->getRelativePosition();
\r
425 pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + textHeight;
\r
426 ToolTip.Element->setRelativePosition(pos);
\r
429 if (ToolTip.Element && ToolTip.Element->isVisible() ) // (isVisible() check only because we might use visibility for ToolTip one day)
\r
431 ToolTip.LastTime = time;
\r
433 // got invisible or removed in the meantime?
\r
434 if ( !HoveredNoSubelement ||
\r
435 !HoveredNoSubelement->isVisible() ||
\r
436 !HoveredNoSubelement->getParent()
\r
437 ) // got invisible or removed in the meantime?
\r
439 ToolTip.Element->remove();
\r
440 ToolTip.Element->drop();
\r
441 ToolTip.Element = 0;
\r
445 IGUIElement::OnPostRender ( time );
\r
448 void CGUIEnvironment::addToDeletionQueue(IGUIElement* element)
\r
454 DeletionQueue.push_back(element);
\r
457 void CGUIEnvironment::clearDeletionQueue()
\r
459 if (DeletionQueue.empty())
\r
462 for (u32 i=0; i<DeletionQueue.size(); ++i)
\r
464 DeletionQueue[i]->remove();
\r
465 DeletionQueue[i]->drop();
\r
468 DeletionQueue.clear();
\r
472 void CGUIEnvironment::updateHoveredElement(core::position2d<s32> mousePos)
\r
474 IGUIElement* lastHovered = Hovered;
\r
475 IGUIElement* lastHoveredNoSubelement = HoveredNoSubelement;
\r
476 LastHoveredMousePos = mousePos;
\r
478 Hovered = getElementFromPoint(mousePos);
\r
480 if ( ToolTip.Element && Hovered == ToolTip.Element )
\r
482 // When the mouse is over the ToolTip we remove that so it will be re-created at a new position.
\r
483 // Note that ToolTip.EnterTime does not get changed here, so it will be re-created at once.
\r
484 ToolTip.Element->remove();
\r
485 ToolTip.Element->drop();
\r
486 ToolTip.Element = 0;
\r
488 // Get the real Hovered
\r
489 Hovered = getElementFromPoint(mousePos);
\r
492 // for tooltips we want the element itself and not some of it's subelements
\r
493 HoveredNoSubelement = Hovered;
\r
494 while ( HoveredNoSubelement && HoveredNoSubelement->isSubElement() )
\r
496 HoveredNoSubelement = HoveredNoSubelement->getParent();
\r
499 if (Hovered && Hovered != this)
\r
501 if ( HoveredNoSubelement && HoveredNoSubelement != this)
\r
502 HoveredNoSubelement->grab();
\r
504 if (Hovered != lastHovered)
\r
507 event.EventType = EET_GUI_EVENT;
\r
511 event.GUIEvent.Caller = lastHovered;
\r
512 event.GUIEvent.Element = 0;
\r
513 event.GUIEvent.EventType = EGET_ELEMENT_LEFT;
\r
514 lastHovered->OnEvent(event);
\r
519 event.GUIEvent.Caller = Hovered;
\r
520 event.GUIEvent.Element = Hovered;
\r
521 event.GUIEvent.EventType = EGET_ELEMENT_HOVERED;
\r
522 Hovered->OnEvent(event);
\r
526 if ( lastHoveredNoSubelement != HoveredNoSubelement )
\r
528 if (ToolTip.Element)
\r
530 ToolTip.Element->remove();
\r
531 ToolTip.Element->drop();
\r
532 ToolTip.Element = 0;
\r
535 if ( HoveredNoSubelement )
\r
537 u32 now = os::Timer::getTime();
\r
538 ToolTip.EnterTime = now;
\r
542 if (lastHovered && lastHovered != this)
\r
543 lastHovered->drop();
\r
544 if (lastHoveredNoSubelement && lastHoveredNoSubelement != this)
\r
545 lastHoveredNoSubelement->drop();
\r
549 //! This sets a new event receiver for gui events. Usually you do not have to
\r
550 //! use this method, it is used by the internal engine.
\r
551 void CGUIEnvironment::setUserEventReceiver(IEventReceiver* evr)
\r
553 UserReceiver = evr;
\r
557 //! posts an input event to the environment
\r
558 bool CGUIEnvironment::postEventFromUser(const SEvent& event)
\r
560 switch(event.EventType)
\r
562 case EET_GUI_EVENT:
\r
564 // hey, why is the user sending gui events..?
\r
568 case EET_MOUSE_INPUT_EVENT:
\r
570 updateHoveredElement(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));
\r
572 if ( Hovered != Focus )
\r
574 IGUIElement * focusCandidate = Hovered;
\r
576 // Only allow enabled elements to be focused (unless EFF_CAN_FOCUS_DISABLED is set)
\r
577 if ( Hovered && !Hovered->isEnabled() && !(FocusFlags & EFF_CAN_FOCUS_DISABLED))
\r
578 focusCandidate = NULL; // we still remove focus from the active element
\r
580 // Please don't merge this into a single if clause, it's easier to debug the way it is
\r
581 if (FocusFlags & EFF_SET_ON_LMOUSE_DOWN &&
\r
582 event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN )
\r
584 setFocus(focusCandidate);
\r
586 else if ( FocusFlags & EFF_SET_ON_RMOUSE_DOWN &&
\r
587 event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN )
\r
589 setFocus(focusCandidate);
\r
591 else if ( FocusFlags & EFF_SET_ON_MOUSE_OVER &&
\r
592 event.MouseInput.Event == EMIE_MOUSE_MOVED )
\r
594 setFocus(focusCandidate);
\r
598 // sending input to focus
\r
599 if (Focus && Focus->OnEvent(event))
\r
602 // focus could have died in last call
\r
603 if (!Focus && Hovered)
\r
605 return Hovered->OnEvent(event);
\r
609 case EET_KEY_INPUT_EVENT:
\r
611 if (Focus && Focus->OnEvent(event))
\r
614 // For keys we handle the event before changing focus to give elements the chance for catching the TAB
\r
615 // Send focus changing event
\r
616 // CAREFUL when changing - there's an identical check in CGUIModalScreen::OnEvent
\r
617 if (FocusFlags & EFF_SET_ON_TAB &&
\r
618 event.KeyInput.PressedDown &&
\r
619 event.KeyInput.Key == KEY_TAB)
\r
621 IGUIElement *next = getNextElement(event.KeyInput.Shift, event.KeyInput.Control);
\r
622 if (next && next != Focus)
\r
624 if (setFocus(next))
\r
630 case EET_STRING_INPUT_EVENT:
\r
631 if (Focus && Focus->OnEvent(event))
\r
642 //! returns the current gui skin
\r
643 IGUISkin* CGUIEnvironment::getSkin() const
\r
645 return CurrentSkin;
\r
649 //! Sets a new GUI Skin
\r
650 void CGUIEnvironment::setSkin(IGUISkin* skin)
\r
652 if (CurrentSkin==skin)
\r
656 CurrentSkin->drop();
\r
658 CurrentSkin = skin;
\r
661 CurrentSkin->grab();
\r
665 //! Creates a new GUI Skin based on a template.
\r
666 /** \return Returns a pointer to the created skin.
\r
667 If you no longer need the skin, you should call IGUISkin::drop().
\r
668 See IReferenceCounted::drop() for more information. */
\r
669 IGUISkin* CGUIEnvironment::createSkin(EGUI_SKIN_TYPE type)
\r
671 IGUISkin* skin = new CGUISkin(type, Driver);
\r
673 IGUIFont* builtinfont = getBuiltInFont();
\r
674 IGUIFontBitmap* bitfont = 0;
\r
675 if (builtinfont && builtinfont->getType() == EGFT_BITMAP)
\r
676 bitfont = (IGUIFontBitmap*)builtinfont;
\r
678 IGUISpriteBank* bank = 0;
\r
679 skin->setFont(builtinfont);
\r
682 bank = bitfont->getSpriteBank();
\r
684 skin->setSpriteBank(bank);
\r
690 //! adds a button. The returned pointer must not be dropped.
\r
691 IGUIButton* CGUIEnvironment::addButton(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text, const wchar_t *tooltiptext)
\r
693 IGUIButton* button = new CGUIButton(this, parent ? parent : this, id, rectangle);
\r
695 button->setText(text);
\r
698 button->setToolTipText ( tooltiptext );
\r
705 //! adds a scrollbar. The returned pointer must not be dropped.
\r
706 IGUIScrollBar* CGUIEnvironment::addScrollBar(bool horizontal, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id)
\r
708 IGUIScrollBar* bar = new CGUIScrollBar(horizontal, this, parent ? parent : this, id, rectangle);
\r
714 //! Adds an image element.
\r
715 IGUIImage* CGUIEnvironment::addImage(video::ITexture* image, core::position2d<s32> pos,
\r
716 bool useAlphaChannel, IGUIElement* parent, s32 id, const wchar_t* text)
\r
718 core::dimension2d<s32> sz(0,0);
\r
720 sz = core::dimension2d<s32>(image->getOriginalSize());
\r
722 IGUIImage* img = new CGUIImage(this, parent ? parent : this,
\r
723 id, core::rect<s32>(pos, sz));
\r
726 img->setText(text);
\r
728 if (useAlphaChannel)
\r
729 img->setUseAlphaChannel(true);
\r
732 img->setImage(image);
\r
739 //! adds an image. The returned pointer must not be dropped.
\r
740 IGUIImage* CGUIEnvironment::addImage(const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text, bool useAlphaChannel)
\r
742 IGUIImage* img = new CGUIImage(this, parent ? parent : this,
\r
746 img->setText(text);
\r
748 if ( useAlphaChannel )
\r
749 img->setUseAlphaChannel(true);
\r
756 //! adds a checkbox
\r
757 IGUICheckBox* CGUIEnvironment::addCheckBox(bool checked, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id, const wchar_t* text)
\r
759 IGUICheckBox* b = new CGUICheckBox(checked, this,
\r
760 parent ? parent : this , id , rectangle);
\r
770 //! adds a list box
\r
771 IGUIListBox* CGUIEnvironment::addListBox(const core::rect<s32>& rectangle,
\r
772 IGUIElement* parent, s32 id, bool drawBackground)
\r
774 IGUIListBox* b = new CGUIListBox(this, parent ? parent : this, id, rectangle,
\r
775 true, drawBackground, false);
\r
777 if (CurrentSkin && CurrentSkin->getSpriteBank())
\r
779 b->setSpriteBank(CurrentSkin->getSpriteBank());
\r
781 else if (getBuiltInFont() && getBuiltInFont()->getType() == EGFT_BITMAP)
\r
783 b->setSpriteBank( ((IGUIFontBitmap*)getBuiltInFont())->getSpriteBank());
\r
791 //! adds a file open dialog. The returned pointer must not be dropped.
\r
792 IGUIFileOpenDialog* CGUIEnvironment::addFileOpenDialog(const wchar_t* title,
\r
793 bool modal, IGUIElement* parent, s32 id,
\r
794 bool restoreCWD, io::path::char_type* startDir)
\r
796 parent = parent ? parent : this;
\r
801 IGUIFileOpenDialog* d = new CGUIFileOpenDialog(title, this, parent, id,
\r
802 restoreCWD, startDir);
\r
809 //! adds a static text. The returned pointer must not be dropped.
\r
810 IGUIStaticText* CGUIEnvironment::addStaticText(const wchar_t* text,
\r
811 const core::rect<s32>& rectangle,
\r
812 bool border, bool wordWrap,
\r
813 IGUIElement* parent, s32 id, bool background)
\r
815 IGUIStaticText* d = new CGUIStaticText(text, border, this,
\r
816 parent ? parent : this, id, rectangle, background);
\r
818 d->setWordWrap(wordWrap);
\r
825 //! Adds an edit box. The returned pointer must not be dropped.
\r
826 IGUIEditBox* CGUIEnvironment::addEditBox(const wchar_t* text,
\r
827 const core::rect<s32>& rectangle, bool border,
\r
828 IGUIElement* parent, s32 id)
\r
830 IGUIEditBox* d = new CGUIEditBox(text, border, this,
\r
831 parent ? parent : this, id, rectangle);
\r
838 //! Adds a tab control to the environment.
\r
839 IGUITabControl* CGUIEnvironment::addTabControl(const core::rect<s32>& rectangle,
\r
840 IGUIElement* parent, bool fillbackground, bool border, s32 id)
\r
842 IGUITabControl* t = new CGUITabControl(this, parent ? parent : this,
\r
843 rectangle, fillbackground, border, id);
\r
849 //! Adds tab to the environment.
\r
850 IGUITab* CGUIEnvironment::addTab(const core::rect<s32>& rectangle,
\r
851 IGUIElement* parent, s32 id)
\r
853 IGUITab* t = new CGUITab(this, parent ? parent : this,
\r
860 //! Adds a combo box to the environment.
\r
861 IGUIComboBox* CGUIEnvironment::addComboBox(const core::rect<s32>& rectangle,
\r
862 IGUIElement* parent, s32 id)
\r
864 IGUIComboBox* t = new CGUIComboBox(this, parent ? parent : this,
\r
871 //! returns the font
\r
872 IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
\r
874 // search existing font
\r
877 f.NamedPath.setPath(filename);
\r
879 s32 index = Fonts.binary_search(f);
\r
881 return Fonts[index].Font;
\r
883 // font doesn't exist, attempt to load it
\r
885 // does the file exist?
\r
887 if (!FileSystem->existFile(filename))
\r
889 os::Printer::log("Could not load font because the file does not exist", f.NamedPath.getPath(), ELL_ERROR);
\r
896 CGUIFont* font = new CGUIFont(this, filename);
\r
897 ifont = (IGUIFont*)font;
\r
900 io::path directory;
\r
901 core::splitFilename(filename, &directory);
\r
902 if (!font->load(xml, directory))
\r
915 CGUIFont* font = new CGUIFont(this, f.NamedPath.getPath() );
\r
916 ifont = (IGUIFont*)font;
\r
917 if (!font->load(f.NamedPath.getPath()))
\r
927 Fonts.push_back(f);
\r
933 //! add an externally loaded font
\r
934 IGUIFont* CGUIEnvironment::addFont(const io::path& name, IGUIFont* font)
\r
939 f.NamedPath.setPath(name);
\r
940 s32 index = Fonts.binary_search(f);
\r
942 return Fonts[index].Font;
\r
944 Fonts.push_back(f);
\r
950 //! remove loaded font
\r
951 void CGUIEnvironment::removeFont(IGUIFont* font)
\r
955 for ( u32 i=0; i<Fonts.size(); ++i )
\r
957 if ( Fonts[i].Font == font )
\r
959 Fonts[i].Font->drop();
\r
966 //! returns default font
\r
967 IGUIFont* CGUIEnvironment::getBuiltInFont() const
\r
972 return Fonts[0].Font;
\r
976 IGUISpriteBank* CGUIEnvironment::getSpriteBank(const io::path& filename)
\r
978 // search for the file name
\r
981 b.NamedPath.setPath(filename);
\r
983 s32 index = Banks.binary_search(b);
\r
985 return Banks[index].Bank;
\r
987 // we don't have this sprite bank, we should load it
\r
988 if (!FileSystem->existFile(b.NamedPath.getPath()))
\r
990 if ( filename != DefaultFontName )
\r
992 os::Printer::log("Could not load sprite bank because the file does not exist", b.NamedPath.getPath(), ELL_DEBUG);
\r
1003 IGUISpriteBank* CGUIEnvironment::addEmptySpriteBank(const io::path& name)
\r
1005 // no duplicate names allowed
\r
1008 b.NamedPath.setPath(name);
\r
1010 const s32 index = Banks.binary_search(b);
\r
1014 // create a new sprite bank
\r
1016 b.Bank = new CGUISpriteBank(this);
\r
1017 Banks.push_back(b);
\r
1023 //! Creates the image list from the given texture.
\r
1024 IGUIImageList* CGUIEnvironment::createImageList( video::ITexture* texture,
\r
1025 core::dimension2d<s32> imageSize, bool useAlphaChannel )
\r
1027 CGUIImageList* imageList = new CGUIImageList( Driver );
\r
1028 if( !imageList->createImageList( texture, imageSize, useAlphaChannel ) )
\r
1030 imageList->drop();
\r
1037 //! Returns the root gui element.
\r
1038 IGUIElement* CGUIEnvironment::getRootGUIElement()
\r
1044 //! Returns the next element in the tab group starting at the focused element
\r
1045 IGUIElement* CGUIEnvironment::getNextElement(bool reverse, bool group)
\r
1047 // start the search at the root of the current tab group
\r
1048 IGUIElement *startPos = Focus ? Focus->getTabGroup() : 0;
\r
1049 s32 startOrder = -1;
\r
1051 // if we're searching for a group
\r
1052 if (group && startPos)
\r
1054 startOrder = startPos->getTabOrder();
\r
1057 if (!group && Focus && !Focus->isTabGroup())
\r
1059 startOrder = Focus->getTabOrder();
\r
1060 if (startOrder == -1)
\r
1062 // this element is not part of the tab cycle,
\r
1063 // but its parent might be...
\r
1064 IGUIElement *el = Focus;
\r
1065 while (el && el->getParent() && startOrder == -1)
\r
1067 el = el->getParent();
\r
1068 startOrder = el->getTabOrder();
\r
1074 if (group || !startPos)
\r
1075 startPos = this; // start at the root
\r
1077 // find the element
\r
1078 IGUIElement *closest = 0;
\r
1079 IGUIElement *first = 0;
\r
1080 startPos->getNextElement(startOrder, reverse, group, first, closest, false, (FocusFlags & EFF_CAN_FOCUS_DISABLED) != 0);
\r
1083 return closest; // we found an element
\r
1085 return first; // go to the end or the start
\r
1087 return this; // no group found? root group
\r
1092 void CGUIEnvironment::setFocusBehavior(u32 flags)
\r
1094 FocusFlags = flags;
\r
1097 u32 CGUIEnvironment::getFocusBehavior() const
\r
1099 return FocusFlags;
\r
1102 //! creates an GUI Environment
\r
1103 IGUIEnvironment* createGUIEnvironment(io::IFileSystem* fs,
\r
1104 video::IVideoDriver* Driver,
\r
1107 return new CGUIEnvironment(fs, Driver, op);
\r
1111 } // end namespace gui
\r
1112 } // end namespace irr
\r
1114 #endif // _IRR_COMPILE_WITH_GUI_
\r