vram32
Empty content…
Empty content…
Check out SetCursor()
code, it removes old cursor when setting to null.
void UI::SetCursor(Cursor* cursor)
{
if (cursor_ == cursor)
return;
// Remove old cursor (if any) and set new
if (cursor_)
{
rootElement_->RemoveChild(cursor_);
cursor_.Reset();
}
if (cursor)
{
rootElement_->AddChild(cursor);
cursor_ = cursor;
IntVector2 pos = cursor_->GetPosition();
const IntVector2& rootSize = rootElement_->GetSize();
const IntVector2& rootPos = rootElement_->GetPosition();
pos.x_ = Clamp(pos.x_, rootPos.x_, rootPos.x_ + rootSize.x_ - 1);
pos.y_ = Clamp(pos.y_, rootPos.y_, rootPos.y_ + rootSize.y_ - 1);
cursor_->SetPosition(pos);
}
}
Better use nullptr
.
“If you have to name the null pointer, call it nullptr; that’s what it’s called in C++11. Then, “nullptr” will be a keyword.” – Bjarne Stroustrup
It’s my favourite return value.