Moin,
ich habe ein kleines Problem mit einer ListBox.
Sie wird zweimal übereinander gezeichnet, wodurch sich das Problem ergibt, dass ich die obere Liste durchscrollen kann, während die darunter liegende nicht scrollbar ist (weil sie keinen Focus hat und auch nicht bekommen kann)
Hier mal die Codes...
Hinzufügen der ListBox und der Items:
Code:
IGUIListBox* listbox = m_pEnv->addListBox(rect<s32>(25, 270, 610, 738));
for(int i = 0; i < 100; i++)
{
listbox->addItem(L"Test");
}
m_pEnv wird einfach per drawAll() gezeichnet.
Hier die draw()-Methode der ListBox (ist verändert, da sie gerade und ungerade Zeilen mit verschiedenen Hintergrundfarben zeichnet, bei Mouseover die Zeilen highlightet und diverse andere Kleinigkeiten.
Code:
//! draws the element and its children
void CGUIListBox::draw()
{
if (!IsVisible)
return;
recalculateItemHeight(); // if the font changed
IGUISkin* skin = Environment->getSkin();
irr::video::IVideoDriver* driver = Environment->getVideoDriver();
core::rect<s32>* clipRect = 0;
// draw background
core::rect<s32> frameRect(AbsoluteRect);
// draw items
core::rect<s32> clientClip(AbsoluteRect);
clientClip.UpperLeftCorner.Y += 1;
clientClip.UpperLeftCorner.X += 1;
clientClip.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X - skin->getSize(EGDS_SCROLLBAR_SIZE);
clientClip.LowerRightCorner.Y -= 1;
clientClip.clipAgainst(AbsoluteClippingRect);
skin->draw3DSunkenPane(this, skin->getColor(EGDC_3D_HIGH_LIGHT), true,
DrawBack, frameRect, &clientClip);
if (clipRect)
clientClip.clipAgainst(*clipRect);
frameRect = AbsoluteRect;
frameRect.UpperLeftCorner.X += 1;
frameRect.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X - skin->getSize(EGDS_SCROLLBAR_SIZE);
frameRect.LowerRightCorner.Y = AbsoluteRect.UpperLeftCorner.Y + ItemHeight;
frameRect.UpperLeftCorner.Y -= ScrollBar->getPos();
frameRect.LowerRightCorner.Y -= ScrollBar->getPos();
for (s32 i=0; i<(s32)Items.size(); ++i)
{
if (frameRect.LowerRightCorner.Y >= AbsoluteRect.UpperLeftCorner.Y &&
frameRect.UpperLeftCorner.Y <= AbsoluteRect.LowerRightCorner.Y)
{
if (i == Selected)
driver->draw2DRectangle(skin->getColor(EGDC_HIGH_LIGHT), frameRect, &clientClip);
else
{
driver->draw2DRectangle((i % 2 == 0) ? BackRowColorEven : BackRowColorOdd, frameRect, &clientClip);
if (i == Highlight)
driver->draw2DRectangle(BackRowColorMouseOver, frameRect, &clientClip);
}
core::rect<s32> textRect = frameRect;
textRect.UpperLeftCorner.X += 3;
if (Font)
{
if (IconBank && (Items[i].icon > -1))
{
core::position2di iconPos = textRect.UpperLeftCorner;
iconPos.Y += textRect.getHeight() / 2;
iconPos.X += ItemsIconWidth/2;
IconBank->draw2DSprite( (u32)Items[i].icon, iconPos, &clientClip,
skin->getColor((i==Selected) ? EGDC_ICON_HIGH_LIGHT : EGDC_ICON),
(i==Selected) ? selectTime : 0 , (i==Selected) ? os::Timer::getTime() : 0, false, true);
}
textRect.UpperLeftCorner.X += ItemsIconWidth+3;
if (i == Selected)
Font->draw(Items[i].text.c_str(), textRect, skin->getColor(EGDC_HIGH_LIGHT_TEXT), false, true, &clientClip);
else if (i == Highlight)
Font->draw(Items[i].text.c_str(), textRect, TextRowColorMouseOver, false, true, &clientClip);
else
Font->draw(Items[i].text.c_str(), textRect, (i % 2 == 0) ? TextRowColorEven : TextRowColorOdd, false, true, &clientClip);
textRect.UpperLeftCorner.X -= ItemsIconWidth+3;
}
}
frameRect.UpperLeftCorner.Y += ItemHeight;
frameRect.LowerRightCorner.Y += ItemHeight;
}
//IGUIElement::draw();
ScrollBar->draw();
}
Hat jemand eine Idee, woran dieser komische Effekt liegen kann.
Das Problem dabei ist, dass der Effekt auch auftritt, wenn ich dir ursprüngliche Irrlicht.dll verwende. Somit vermute ich, dass das dann an meinem Code liegt, mit dem die ListBox aufgerufen wird.
Aber mir ist nicht ersichtlich, wo der Fehler in den paar Zeilen liegen soll.
Danke schonmal für die Hilfe.