bool CGUIEditBox::processIMEEvent(const SEvent& event) { switch(event.InputMethodEvent.Event) { case EIME_CHAR_INPUT: inputChar(event.InputMethodEvent.Char); return true; case EIME_CHANGE_POS: { core::position2di pos = calculateICPos(); IGUIFont* font = OverrideFont; IGUISkin* skin = Environment->getSkin(); if (!OverrideFont) font = skin->getFont(); irr::updateICPos(event.InputMethodEvent.Handle, pos.X,pos.Y, font->getDimension(L"|").Height); return true; } default: break; } return false; }
//! draws the element and its children void CGUIWindow::draw() { if ( IsVisible ) { IGUISkin* skin = Environment->getSkin(); core::rect<s32> rect = AbsoluteRect; // draw body fast if ( DrawBackground ) { rect = skin->draw3DWindowBackground(this, DrawTitlebar, skin->getColor(EGDC_ACTIVE_BORDER), AbsoluteRect, &AbsoluteClippingRect); if (DrawTitlebar && Text.size()) { rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X); rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y); rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; IGUIFont* font = skin->getFont(EGDF_WINDOW); if (font) { font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, &AbsoluteClippingRect); } } } } IGUIElement::draw(); }
void CGUITextureCacheBrowser::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); core::rect<s32> rect = AbsoluteRect; core::rect<s32> *cl = &AbsoluteClippingRect; // draw body fast rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER), AbsoluteRect, &AbsoluteClippingRect); // draw window text if (Text.size()) { rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X); rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y); rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; IGUIFont* font = skin->getFont(); if (font) font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, cl); } IGUIElement::draw(); }
void CGUITabControl::selectTab(core::position2d<s32> p) { IGUISkin* skin = Environment->getSkin(); IGUIFont* font = skin->getFont(); core::rect<s32> frameRect(AbsoluteRect); s32 tabheight = skin->getSize(gui::EGDS_BUTTON_HEIGHT); frameRect.UpperLeftCorner.Y += 2; frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + tabheight; s32 pos = frameRect.UpperLeftCorner.X + 2; for (u32 i=0; i<Tabs.size(); ++i) { // get Text const wchar_t* text = 0; if (Tabs[i]) text = Tabs[i]->getText(); // get text length s32 len = 20; if (font) len += font->getDimension(text).Width; frameRect.UpperLeftCorner.X = pos; frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len; pos += len; if (frameRect.isPointInside(p)) { setActiveTab(i); return; } } }
//! draws the element and its children void CGUIFileOpenDialog::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); core::rect<s32> rect = AbsoluteRect; rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER), rect, &AbsoluteClippingRect); if (Text.size()) { rect.UpperLeftCorner.X += 2; rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; IGUIFont* font = skin->getFont(EGDF_WINDOW); if (font) font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, &AbsoluteClippingRect); } IGUIElement::draw(); }
s32 CGUIStaticText::getTextWidth() const { IGUIFont * font = OverrideFont; if(!OverrideFont) { IGUISkin * skin = Environment->getSkin(); if(skin) font = skin->getFont(); } if(!font) return 0; if(WordWrap) { s32 widest = 0; for(u32 line = 0; line < BrokenText.size(); ++line) { s32 width = font->getDimension(BrokenText[line].c_str()).Width; if(width > widest) widest = width; } return widest; } else { return font->getDimension(Text.c_str()).Width; } }
void CGUIContextMenu::recalculateSize() { IGUISkin* skin = Environment->getSkin(); IGUIFont* font = skin->getFont(EGDF_MENU); if (!font) return; core::rect<s32> rect; rect.UpperLeftCorner = RelativeRect.UpperLeftCorner; s32 width = 100; s32 height = 3; u32 i; for (i=0; i<Items.size(); ++i) { if (Items[i].IsSeparator) { Items[i].Dim.Width = 100; Items[i].Dim.Height = 10; } else { Items[i].Dim = font->getDimension(Items[i].Text.c_str()); Items[i].Dim.Width += 40; if (Items[i].Dim.Width > width) width = Items[i].Dim.Width; } Items[i].PosY = height; height += Items[i].Dim.Height; } height += 5; if (height < 10) height = 10; rect.LowerRightCorner.X = RelativeRect.UpperLeftCorner.X + width; rect.LowerRightCorner.Y = RelativeRect.UpperLeftCorner.Y + height; setRelativePosition(rect); // recalculate submenus for (i=0; i<Items.size(); ++i) { if (Items[i].SubMenu) { // move submenu const s32 w = Items[i].SubMenu->getAbsolutePosition().getWidth(); const s32 h = Items[i].SubMenu->getAbsolutePosition().getHeight(); Items[i].SubMenu->setRelativePosition( core::rect<s32>(width-5, Items[i].PosY, width+w-5, Items[i].PosY+h)); } } }
//! draws the element and its children void CGUIMenu::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); IGUIFont* font = skin->getFont(EGDF_MENU); if (font != LastFont) { if (LastFont) LastFont->drop(); LastFont = font; if (LastFont) LastFont->grab(); recalculateSize(); } core::rect<s32> rect = AbsoluteRect; // draw frame skin->draw3DToolBar(this, rect, &AbsoluteClippingRect); // loop through all menu items rect = AbsoluteRect; for (s32 i=0; i<(s32)Items.size(); ++i) { if (!Items[i].IsSeparator) { rect = getRect(Items[i], AbsoluteRect); // draw highlighted if (i == HighLighted && Items[i].Enabled) { skin->draw3DSunkenPane(this, skin->getColor(EGDC_3D_DARK_SHADOW), true, true, rect, &AbsoluteClippingRect); } // draw text EGUI_DEFAULT_COLOR c = EGDC_BUTTON_TEXT; if (i == HighLighted) c = EGDC_HIGH_LIGHT_TEXT; if (!Items[i].Enabled) c = EGDC_GRAY_TEXT; if (font) font->draw(Items[i].Text.c_str(), rect, skin->getColor(c), true, true, &AbsoluteClippingRect); } } IGUIElement::draw(); }
void CGUIEditBox::calculateScrollPos() { #ifndef SERVER_ONLY if (!AutoScroll) return; // calculate horizontal scroll position s32 cursLine = getLineFromPos(CursorPos); setTextRect(cursLine); // don't do horizontal scrolling when wordwrap is enabled. if (!WordWrap) { // get cursor position IGUISkin* skin = Environment->getSkin(); if (!skin) return; IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont(); if (!font) return; core::stringw *txtLine = MultiLine ? &BrokenText[cursLine] : &Text; s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] : CursorPos; s32 cStart = CurrentTextRect.UpperLeftCorner.X + HScrollPos + font->getDimension(txtLine->subString(0, cPos).c_str()).Width; s32 cEnd = cStart + font->getDimension(L"_ ").Width; if (FrameRect.LowerRightCorner.X < cEnd) HScrollPos = cEnd - FrameRect.LowerRightCorner.X; else if (FrameRect.UpperLeftCorner.X > cStart) HScrollPos = cStart - FrameRect.UpperLeftCorner.X; else HScrollPos = 0; // todo: adjust scrollbar } // vertical scroll position if (FrameRect.LowerRightCorner.Y < CurrentTextRect.LowerRightCorner.Y + VScrollPos) VScrollPos = CurrentTextRect.LowerRightCorner.Y - FrameRect.LowerRightCorner.Y + VScrollPos; else if (FrameRect.UpperLeftCorner.Y > CurrentTextRect.UpperLeftCorner.Y + VScrollPos) VScrollPos = CurrentTextRect.UpperLeftCorner.Y - FrameRect.UpperLeftCorner.Y + VScrollPos; else VScrollPos = 0; // todo: adjust scrollbar #if defined(_IRR_COMPILE_WITH_X11_DEVICE_) CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice()); if (dl) { dl->setIMELocation(calculateICPos()); } #endif #endif // SERVER_ONLY }
//! Get the font which is used right now for drawing IGUIFont* CGUIButton::getActiveFont() const { if ( OverrideFont ) return OverrideFont; IGUISkin* skin = Environment->getSkin(); if (skin) return skin->getFont(EGDF_BUTTON); return 0; }
//! Adds a button to the tool bar IGUIButton* CGUIToolBar::addButton(SINT32 id, const wchar_t* text, const wchar_t* tooltiptext, ITexture* img, ITexture* pressed, bool isPushButton, bool useAlphaChannel) { ButtonX += 3; rect<SINT32> rectangle(ButtonX, 2, ButtonX + 1, 3); if (img) { const dimension2du &size = img->getOriginalSize(); rectangle.LowerRightCorner.x = rectangle.UpperLeftCorner.x + size.Width + 8; rectangle.LowerRightCorner.y = rectangle.UpperLeftCorner.y + size.Height + 6; } if (text) { IGUISkin* skin = Environment->getSkin(); IGUIFont * font = skin->getFont(EGDF_BUTTON); if (font) { dimension2d<UINT32> dim = font->getDimension(text); if ((SINT32)dim.Width > rectangle.getWidth()) rectangle.LowerRightCorner.x = rectangle.UpperLeftCorner.x + dim.Width + 8; if ((SINT32)dim.Height > rectangle.getHeight()) rectangle.LowerRightCorner.y = rectangle.UpperLeftCorner.y + dim.Height + 6; } } ButtonX += rectangle.getWidth(); IGUIButton* button = new CGUIButton(Environment, this, id, rectangle); button->drop(); if (text) button->setText(text); if (tooltiptext) button->setToolTipText(tooltiptext); if (img) button->setImage(img); if (pressed) button->setPressedImage(pressed); if (isPushButton) button->setIsPushButton(isPushButton); if (useAlphaChannel) button->setUseAlphaChannel(useAlphaChannel); return button; }
void CGUIListBox::recalculateItemHeight() { IGUISkin* skin = Environment->getSkin(); if (Font != skin->getFont()) { if (Font) Font->drop(); Font = skin->getFont(); ItemHeight = 0; if (Font) { ItemHeight = Font->getDimension(L"A").Height + 4; Font->grab(); } } TotalItemHeight = ItemHeight * Items.size(); ScrollBar->setMax(TotalItemHeight - AbsoluteRect.getHeight()); }
bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl) { if ( startIndex >= (s32)Tabs.size() ) startIndex -= 1; if ( startIndex < 0 ) startIndex = 0; IGUISkin* skin = Environment->getSkin(); if (!skin) return false; IGUIFont* font = skin->getFont(); core::rect<s32> frameRect(AbsoluteRect); if (Tabs.empty()) return false; if (!font) return false; s32 pos = frameRect.UpperLeftCorner.X + 2; for (s32 i=startIndex; i<(s32)Tabs.size(); ++i) { // get Text const wchar_t* text = 0; if (Tabs[i]) text = Tabs[i]->getText(); // get text length s32 len = font->getDimension(text).Width + TabExtraWidth; frameRect.LowerRightCorner.X += len; frameRect.UpperLeftCorner.X = pos; frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len; pos += len; if ( withScrollControl && pos > AbsoluteRect.LowerRightCorner.X - TabMaxWidth) return true; if ( !withScrollControl && pos > AbsoluteRect.LowerRightCorner.X ) return true; } return false; }
//! draws the element and its children void CGUIComboBox::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); // font changed while the listbox is open? if ( ActiveFont != skin->getFont() && ListBox ) { // close and re-open to use new font-size openCloseMenu(); openCloseMenu(); } IGUIElement *currentFocus = Environment->getFocus(); if (currentFocus != LastFocus) { HasFocus = currentFocus == this || isMyChild(currentFocus); LastFocus = currentFocus; } // set colors each time as skin-colors can be changed SelectedText->setBackgroundColor(skin->getColor(EGDC_HIGH_LIGHT)); if(isEnabled()) { SelectedText->setDrawBackground(HasFocus); SelectedText->setOverrideColor(skin->getColor(HasFocus ? EGDC_HIGH_LIGHT_TEXT : EGDC_BUTTON_TEXT)); } else { SelectedText->setDrawBackground(false); SelectedText->setOverrideColor(skin->getColor(EGDC_GRAY_TEXT)); } ListButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL)); ListButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL)); core::rect<s32> frameRect(AbsoluteRect); // draw the border skin->draw3DSunkenPane(this, skin->getColor(EGDC_3D_HIGH_LIGHT), true, true, frameRect, &AbsoluteClippingRect); // draw children IGUIElement::draw(); }
void CGUIComboBox::openCloseMenu() { if (ListBox) { // close list box Environment->setFocus(this); ListBox->remove(); ListBox = 0; } else { if (Parent) Parent->bringToFront(this); IGUISkin* skin = Environment->getSkin(); s32 h = Items.size(); if (h > 5) h = 5; if (h == 0) h = 1; IGUIFont* font = skin->getFont(); if (font) h *= (font->getDimension(L"A").Height + 4); // open list box core::rect<s32> r(0, AbsoluteRect.getHeight(), AbsoluteRect.getWidth(), AbsoluteRect.getHeight() + h); ListBox = new CGUIListBox(Environment, this, -1, r, false, true, true); ListBox->setSubElement(true); ListBox->setNotClipped(true); ListBox->drop(); // ensure that list box is always completely visible if (ListBox->getAbsolutePosition().LowerRightCorner.Y > Environment->getRootGUIElement()->getAbsolutePosition().getHeight()) ListBox->setRelativePosition( core::rect<s32>(0, -ListBox->getAbsolutePosition().getHeight(), AbsoluteRect.getWidth(), 0) ); for (s32 i=0; i<(s32)Items.size(); ++i) ListBox->addItem(Items[i].Name.c_str()); ListBox->setSelected(Selected); // set focus Environment->setFocus(ListBox); } }
bool CGUITabControl::selectTab(core::position2d<s32> p) { IGUISkin* skin = Environment->getSkin(); IGUIFont* font = skin->getFont(); core::rect<s32> frameRect(AbsoluteRect); if ( VerticalAlignment == EGUIA_UPPERLEFT ) { frameRect.UpperLeftCorner.Y += 2; frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight; } else { frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight; } s32 pos = frameRect.UpperLeftCorner.X + 2; if (!frameRect.isPointInside(p)) return false; for (s32 i=CurrentScrollTabIndex; i<(s32)Tabs.size(); ++i) { // get Text const wchar_t* text = 0; if (Tabs[i]) text = Tabs[i]->getText(); // get text length s32 len = font->getDimension(text).Width + TabExtraWidth; frameRect.UpperLeftCorner.X = pos; frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len; if ( ScrollControl && pos > AbsoluteRect.LowerRightCorner.X) return false; pos += len; if (frameRect.isPointInside(p)) { setActiveTab(i); return true; } } return false; }
//! draws the element and its children void CGUICheckBox::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); if (skin) { const core::rect<s32> rect = AbsoluteRect; const s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH); core::rect<s32> checkRect(AbsoluteRect.UpperLeftCorner.X, ((AbsoluteRect.getHeight() - height) / 2) + AbsoluteRect.UpperLeftCorner.Y, 0, 0); checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height; checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height; EGUI_DEFAULT_COLOR col = EGDC_GRAY_EDITABLE; if ( isEnabled() ) col = Pressed ? EGDC_FOCUSED_EDITABLE : EGDC_EDITABLE; skin->draw3DSunkenPane(this, skin->getColor(col), false, true, checkRect, &AbsoluteClippingRect); if (Checked) { skin->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(), checkTime, os::Timer::getTime(), false, &AbsoluteClippingRect); } if (Text.size()) { checkRect = AbsoluteRect; checkRect.UpperLeftCorner.X += height + 5; IGUIFont* font = skin->getFont(); if (font) { font->draw(Text.c_str(), checkRect, skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), false, true, &AbsoluteClippingRect); } } } IGUIElement::draw(); }
void CGUIComboBox::openCloseMenu() { if (ListBox) { // close list box Environment->setFocus(this); ListBox->remove(); ListBox = 0; } else { if (Parent) Parent->bringToFront(this); IGUISkin* skin = Environment->getSkin(); s32 h = Items.size(); if (h > 5) h = 5; if (h == 0) h = 1; IGUIFont* font = skin->getFont(); if (font) h *= (font->getDimension(L"A").Height + 4); // open list box core::rect<s32> r(0, AbsoluteRect.getHeight(), AbsoluteRect.getWidth(), AbsoluteRect.getHeight() + h); ListBox = new CGUIListBox(Environment, this, -1, r, false, true, true); ListBox->setSubElement(true); ListBox->drop(); for (s32 i=0; i<(s32)Items.size(); ++i) ListBox->addItem(Items[i].c_str()); ListBox->setSelected(Selected); // set focus Environment->setFocus(ListBox); } }
s32 CGUIEditBox::getCursorPos(s32 x, s32 y) { IGUIFont* font = OverrideFont; IGUISkin* skin = Environment->getSkin(); if (!OverrideFont) font = skin->getFont(); const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1; core::stringw *txtLine=0; s32 startPos=0; x+=3; for (u32 i=0; i < lineCount; ++i) { setTextRect(i); if (i == 0 && y < CurrentTextRect.UpperLeftCorner.Y) y = CurrentTextRect.UpperLeftCorner.Y; if (i == lineCount - 1 && y > CurrentTextRect.LowerRightCorner.Y ) y = CurrentTextRect.LowerRightCorner.Y; // is it inside this region? if (y >= CurrentTextRect.UpperLeftCorner.Y && y <= CurrentTextRect.LowerRightCorner.Y) { // we've found the clicked line txtLine = (WordWrap || MultiLine) ? &BrokenText[i] : &Text; startPos = (WordWrap || MultiLine) ? BrokenTextPositions[i] : 0; break; } } if (x < CurrentTextRect.UpperLeftCorner.X) x = CurrentTextRect.UpperLeftCorner.X; s32 idx = txtLine ? font->getCharacterFromPos(txtLine->c_str(), x - CurrentTextRect.UpperLeftCorner.X) : -1; // click was on or left of the line if (idx != -1) return idx + startPos; // click was off the right edge of the line, go to end. return txtLine->size() + startPos; }
//! draws the element and its children void CGUIComboBox::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); IGUIElement *currentFocus = Environment->getFocus(); if (currentFocus != LastFocus) { HasFocus = currentFocus == this || isMyChild(currentFocus); LastFocus = currentFocus; } core::rect<s32> frameRect(AbsoluteRect); // draw the border skin->draw3DSunkenPane(this, skin->getColor(EGDC_3D_HIGH_LIGHT), true, true, frameRect, &AbsoluteClippingRect); // Draw text if (Selected != -1) { frameRect = AbsoluteRect; frameRect.UpperLeftCorner.X += 2; frameRect.UpperLeftCorner.Y += 2; frameRect.LowerRightCorner.X -= ListButton->getAbsolutePosition().getWidth() + 2; frameRect.LowerRightCorner.Y -= 2; if (HasFocus) skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), frameRect, &AbsoluteClippingRect); IGUIFont* font = skin->getFont(); if (font) font->draw(Items[Selected].c_str(), frameRect, skin->getColor(HasFocus ? EGDC_HIGH_LIGHT_TEXT : EGDC_BUTTON_TEXT), false, true, &AbsoluteClippingRect); } // draw buttons IGUIElement::draw(); }
//! draws the element and its children void CGUIWindow::draw() { if (IsVisible) { IGUISkin* skin = Environment->getSkin(); // update each time because the skin is allowed to change this always. updateClientRect(); if ( CurrentIconColor != skin->getColor(EGDC_WINDOW_SYMBOL) ) refreshSprites(); core::rect<s32> rect = AbsoluteRect; // draw body fast if (DrawBackground) { rect = skin->draw3DWindowBackground(this, DrawTitlebar, skin->getColor(IsActive ? EGDC_ACTIVE_BORDER : EGDC_INACTIVE_BORDER), AbsoluteRect, &AbsoluteClippingRect); if (DrawTitlebar && Text.size()) { rect.UpperLeftCorner.X += skin->getSize(EGDS_TITLEBARTEXT_DISTANCE_X); rect.UpperLeftCorner.Y += skin->getSize(EGDS_TITLEBARTEXT_DISTANCE_Y); rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; IGUIFont* font = skin->getFont(EGDF_WINDOW); if (font) { font->draw(Text.c_str(), rect, skin->getColor(IsActive ? EGDC_ACTIVE_CAPTION:EGDC_INACTIVE_CAPTION), false, true, &AbsoluteClippingRect); } } } } IGUIElement::draw(); }
//! Returns the height of the text in pixels when it is drawn. s32 CGUIStaticText::getTextHeight() { IGUISkin* skin = Environment->getSkin(); if (!skin) return 0; IGUIFont* font = OverrideFont; if (!OverrideFont) font = skin->getFont(); if (!font) return 0; s32 height = font->getDimension(L"A").Height; if (WordWrap) height *= BrokenText.size(); return height; }
//! draws the element and its children void CGUIColorSelectDialog::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); core::rect<s32> rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER), AbsoluteRect, &AbsoluteClippingRect); if (Text.size()) { rect.UpperLeftCorner.X += 2; rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; IGUIFont* font = skin->getFont(EGDF_WINDOW); if (font) font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, &AbsoluteClippingRect); } IGUIElement::draw(); // draw color selector after the window elements core::vector2di pos(ColorRing.Control->getAbsolutePosition().UpperLeftCorner); pos.X += ColorRing.Texture->getOriginalSize().Width/2; pos.Y += ColorRing.Texture->getOriginalSize().Height/2; #if 0 const f32 h = Battery[4]->getValue(); const f32 s = Battery[5]->getValue(); const f32 l = Battery[6]->getValue(); const f32 factor = 58.f*(((s==0)&&(l<50))?(l*0.33f/50):( (s<100)?((.33f+(s*0.33f/100))):((0.66f+(l-50)*0.33f/50)))); #else const f32 factor = 44; #endif pos.X += core::round32(sinf(Battery[4]->getValue()*core::DEGTORAD)*factor); pos.Y -= core::round32(cosf(Battery[4]->getValue()*core::DEGTORAD)*factor); Environment->getVideoDriver()->draw2DPolygon(pos, 4, 0xffffffff, 4); }
//! draws the element and its children void CGUICheckBox::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); core::rect<s32> rect = AbsoluteRect; s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH); core::rect<s32> checkRect(AbsoluteRect.UpperLeftCorner.X, ((AbsoluteRect.getHeight() - height) / 2) + AbsoluteRect.UpperLeftCorner.Y, 0, 0); checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height; checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height; skin->draw3DSunkenPane(this, skin->getColor(Pressed || !IsEnabled ? EGDC_3D_FACE : EGDC_ACTIVE_CAPTION), false, true, checkRect, &AbsoluteClippingRect); if (Checked && Environment->getSkin()) Environment->getSkin()->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(), checkTime, os::Timer::getTime(), false, &AbsoluteClippingRect); if (Text.size()) { checkRect = AbsoluteRect; checkRect.UpperLeftCorner.X += height + 5; IGUIFont* font = skin->getFont(); if (font) font->draw(Text.c_str(), checkRect, skin->getColor(IsEnabled ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), false, true, &AbsoluteClippingRect); } IGUIElement::draw(); }
//! calculate the position of input composition window core::position2di CGUIEditBox::calculateICPos() { core::position2di pos; IGUIFont* font = OverrideFont; IGUISkin* skin = Environment->getSkin(); if (!OverrideFont) font = skin->getFont(); //drop the text that clipping on the right side if (WordWrap | MultiLine) { // todo : It looks like a heavy drinker. Strange!! pos.X = CurrentTextRect.LowerRightCorner.X - font->getDimension(Text.subString(CursorPos, BrokenTextPositions[getLineFromPos(CursorPos)] + BrokenText[getLineFromPos(CursorPos)].size() - CursorPos).c_str()).Width; pos.Y = CurrentTextRect.UpperLeftCorner.Y + font->getDimension(L"|").Height + (Border ? 3 : 0) - ((MultiLine | WordWrap) ? 3 : 0); } else { pos.X = CurrentTextRect.LowerRightCorner.X - font->getDimension(Text.subString(CursorPos, Text.size() - CursorPos).c_str()).Width; pos.Y = AbsoluteRect.getCenter().Y + (Border ? 3 : 0); //bug? The text is always drawn in the height of the center. SetTextAlignment() doesn't influence. } return pos; }
void CGUIMenu::recalculateSize() { IGUISkin* skin = Environment->getSkin(); IGUIFont* font = skin->getFont(EGDF_MENU); if (!font) { if (Parent && skin) RelativeRect = core::rect<s32>(0,0, Parent->getAbsolutePosition().LowerRightCorner.X, skin->getSize(EGDS_MENU_HEIGHT)); return; } core::rect<s32> rect; rect.UpperLeftCorner.X = 0; rect.UpperLeftCorner.Y = 0; s32 height = font->getDimension(L"A").Height + 5; //if (skin && height < skin->getSize ( EGDS_MENU_HEIGHT )) // height = skin->getSize(EGDS_MENU_HEIGHT); s32 width = 0; s32 i; for (i=0; i<(s32)Items.size(); ++i) { if (Items[i].IsSeparator) { Items[i].Dim.Width = 0; Items[i].Dim.Height = height; } else { Items[i].Dim = font->getDimension(Items[i].Text.c_str()); Items[i].Dim.Width += 20; } Items[i].PosY = width; width += Items[i].Dim.Width; } if (Parent) width = Parent->getAbsolutePosition().getWidth(); rect.LowerRightCorner.X = width; rect.LowerRightCorner.Y = height; setRelativePosition(rect); // recalculate submenus for (i=0; i<(s32)Items.size(); ++i) if (Items[i].SubMenu) { // move submenu s32 w = Items[i].SubMenu->getAbsolutePosition().getWidth(); s32 h = Items[i].SubMenu->getAbsolutePosition().getHeight(); Items[i].SubMenu->setRelativePosition( core::rect<s32>(Items[i].PosY, height , Items[i].PosY+w-5, height+h)); } }
//! draws the element and its children void CGUIContextMenu::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); if (!skin) return; IGUIFont* font = skin->getFont(EGDF_MENU); if (font != LastFont) { if (LastFont) LastFont->drop(); LastFont = font; if (LastFont) LastFont->grab(); recalculateSize(); } IGUISpriteBank* sprites = skin->getSpriteBank(); core::rect<s32> rect = AbsoluteRect; core::rect<s32>* clip = 0; // draw frame skin->draw3DMenuPane(this, AbsoluteRect, clip); // loop through all menu items rect = AbsoluteRect; s32 y = AbsoluteRect.UpperLeftCorner.Y; for (s32 i=0; i<(s32)Items.size(); ++i) { if (Items[i].IsSeparator) { // draw separator rect = AbsoluteRect; rect.UpperLeftCorner.Y += Items[i].PosY + 3; rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 1; rect.UpperLeftCorner.X += 5; rect.LowerRightCorner.X -= 5; skin->draw2DRectangle(this, skin->getColor(EGDC_3D_SHADOW), rect, clip); rect.LowerRightCorner.Y += 1; rect.UpperLeftCorner.Y += 1; skin->draw2DRectangle(this, skin->getColor(EGDC_3D_HIGH_LIGHT), rect, clip); y += 10; } else { rect = getRect(Items[i], AbsoluteRect); // draw highlighted if (i == HighLighted && Items[i].Enabled) { core::rect<s32> r = AbsoluteRect; r.LowerRightCorner.Y = rect.LowerRightCorner.Y; r.UpperLeftCorner.Y = rect.UpperLeftCorner.Y; r.LowerRightCorner.X -= 5; r.UpperLeftCorner.X += 5; skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), r, clip); } // draw text EGUI_DEFAULT_COLOR c = EGDC_BUTTON_TEXT; if (i == HighLighted) c = EGDC_HIGH_LIGHT_TEXT; if (!Items[i].Enabled) c = EGDC_GRAY_TEXT; if (font) font->draw(Items[i].Text.c_str(), rect, skin->getColor(c), false, true, clip); // draw submenu symbol if (Items[i].SubMenu && sprites) { core::rect<s32> r = rect; r.UpperLeftCorner.X = r.LowerRightCorner.X - 15; sprites->draw2DSprite(skin->getIcon(EGDI_CURSOR_RIGHT), r.getCenter(), clip, skin->getColor(c), (i == HighLighted) ? ChangeTime : 0, (i == HighLighted) ? os::Timer::getTime() : 0, (i == HighLighted), true); } // draw checked symbol if (Items[i].Checked && sprites) { core::rect<s32> r = rect; r.LowerRightCorner.X = r.UpperLeftCorner.X - 15; r.UpperLeftCorner.X = r.LowerRightCorner.X + 15; sprites->draw2DSprite(skin->getIcon(EGDI_CHECK_BOX_CHECKED), r.getCenter(), clip, skin->getColor(c), (i == HighLighted) ? ChangeTime : 0, (i == HighLighted) ? os::Timer::getTime() : 0, (i == HighLighted), true); } } } IGUIElement::draw(); }
//! draws the element and its children void CGUIStaticText::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); irr::video::IVideoDriver* driver = Environment->getVideoDriver(); core::rect<s32> frameRect(AbsoluteRect); // draw background if (Background) { driver->draw2DRectangle( skin->getColor(gui::EGDC_3D_FACE), frameRect, &AbsoluteClippingRect); } // draw the border if (Border) { skin->draw3DSunkenPane(this, 0, true, false, frameRect, &AbsoluteClippingRect); frameRect.UpperLeftCorner.X += 3; } // draw the text if (Text.size()) { IGUIFont* font = OverrideFont; if (!OverrideFont) font = skin->getFont(); if (font) { if (!WordWrap) font->draw(Text.c_str(), frameRect, OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), false, true, &AbsoluteClippingRect); else { if (font != LastBreakFont) breakText(); core::rect<s32> r = frameRect; s32 height = font->getDimension(L"A").Height; for (u32 i=0; i<BrokenText.size(); ++i) { font->draw(BrokenText[i].c_str(), r, OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), false, false, &AbsoluteClippingRect); r.LowerRightCorner.Y += height; r.UpperLeftCorner.Y += height; } } } } IGUIElement::draw(); }
//! Breaks the single text line. void CGUIStaticText::breakText() { IGUISkin* skin = Environment->getSkin(); if (!WordWrap || !skin) return; BrokenText.clear(); IGUIFont* font = OverrideFont; if (!OverrideFont) font = skin->getFont(); if (!font) return; LastBreakFont = font; core::stringw line; core::stringw word; core::stringw whitespace; s32 size = Text.size(); s32 length = 0; s32 elWidth = RelativeRect.getWidth() - 6; wchar_t c; for (s32 i=0; i<size; ++i) { c = Text[i]; bool lineBreak = false; if (c == L'\n') { lineBreak = true; c = ' '; } if (c == L' ' || c == 0 || i == (size-1)) { if (word.size()) { // here comes the next whitespace, look if // we can break the last word to the next line. s32 whitelgth = font->getDimension(whitespace.c_str()).Width; s32 worldlgth = font->getDimension(word.c_str()).Width; if (length + worldlgth + whitelgth > elWidth) { // break to next line length = worldlgth; BrokenText.push_back(line); line = word; } else { // add word to line line += whitespace; line += word; length += whitelgth + worldlgth; } word = L""; whitespace = L""; } whitespace += c; // compute line break if (lineBreak) { line += whitespace; line += word; BrokenText.push_back(line); line = L""; word = L""; whitespace = L""; length = 0; } } else { // yippee this is a word.. word += c; } } line += whitespace; line += word; BrokenText.push_back(line); }
//! draws the element and its children void CGUIButton::draw() { if (!IsVisible) return; IGUISkin* skin = Environment->getSkin(); video::IVideoDriver* driver = Environment->getVideoDriver(); IGUIFont* font = OverrideFont; if (!OverrideFont) font = skin->getFont(EGDF_BUTTON); core::rect<s32> rect = AbsoluteRect; // todo: move sprite up and text down if the pressed state has a sprite // draw sprites for focused and mouse-over core::position2di spritePos = AbsoluteRect.getCenter(); if (!Pressed) { if (Border) skin->draw3DButtonPaneStandard(this, rect, &AbsoluteClippingRect); if (Image) { core::position2d<s32> pos = AbsoluteRect.getCenter(); pos.X -= ImageRect.getWidth() / 2; pos.Y -= ImageRect.getHeight() / 2; driver->draw2DImage(Image, pos, ImageRect, &AbsoluteClippingRect, video::SColor(255,255,255,255), UseAlphaChannel); } if (SpriteBank && ButtonSprites[EGBS_BUTTON_UP].Index != -1) { // draw pressed sprite SpriteBank->draw2DSprite(ButtonSprites[EGBS_BUTTON_UP].Index, spritePos, &AbsoluteClippingRect, ButtonSprites[EGBS_BUTTON_UP].Color, ClickTime, os::Timer::getTime(), ButtonSprites[EGBS_BUTTON_UP].Loop, true); } } else { if (Border) skin->draw3DButtonPanePressed(this, rect, &AbsoluteClippingRect); if (PressedImage) { core::position2d<s32> pos = AbsoluteRect.getCenter(); pos.X -= PressedImageRect.getWidth() / 2; pos.Y -= PressedImageRect.getHeight() / 2; // patch by Alan Tyndall/Jonas Petersen if (Image == PressedImage && PressedImageRect == ImageRect) { pos.X += 1; pos.Y += 1; } driver->draw2DImage(PressedImage, pos, PressedImageRect, &AbsoluteClippingRect, video::SColor(255,255,255,255), UseAlphaChannel); } if (SpriteBank && ButtonSprites[EGBS_BUTTON_DOWN].Index != -1) { // draw sprite SpriteBank->draw2DSprite(ButtonSprites[EGBS_BUTTON_DOWN].Index, spritePos, &AbsoluteClippingRect, ButtonSprites[EGBS_BUTTON_DOWN].Color, ClickTime, os::Timer::getTime(), ButtonSprites[EGBS_BUTTON_DOWN].Loop, true); } } if (Text.size()) { rect = AbsoluteRect; if (Pressed) rect.UpperLeftCorner.Y += 2; if (font) font->draw(Text.c_str(), rect, skin->getColor(IsEnabled ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), true, true, &AbsoluteClippingRect); } IGUIElement::draw(); }