mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-01 15:50:27 +02:00
Reformat the code, using:
find -type f | # list all regular files grep -E '\.(h|cpp|mm)$' | # filter for source files grep -v '/mt_' | # filter out generated files grep -v '/vendor/' | # and vendored GL grep -v '/test/image_loader_test.cpp' | # and this file (has giant literals arrays) xargs -n 1 -P $(nproc) clang-format -i # reformat everything Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
@ -19,22 +19,21 @@ namespace gui
|
||||
{
|
||||
|
||||
//! constructor
|
||||
CGUIComboBox::CGUIComboBox(IGUIEnvironment* environment, IGUIElement* parent,
|
||||
s32 id, core::rect<s32> rectangle)
|
||||
: IGUIComboBox(environment, parent, id, rectangle),
|
||||
ListButton(nullptr), SelectedText(nullptr), ListBox(nullptr), LastFocus(nullptr),
|
||||
Selected(-1), HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_CENTER), MaxSelectionRows(5), HasFocus(false),
|
||||
ActiveFont(nullptr)
|
||||
CGUIComboBox::CGUIComboBox(IGUIEnvironment *environment, IGUIElement *parent,
|
||||
s32 id, core::rect<s32> rectangle) :
|
||||
IGUIComboBox(environment, parent, id, rectangle),
|
||||
ListButton(nullptr), SelectedText(nullptr), ListBox(nullptr), LastFocus(nullptr),
|
||||
Selected(-1), HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_CENTER), MaxSelectionRows(5), HasFocus(false),
|
||||
ActiveFont(nullptr)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CGUIComboBox");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
IGUISkin* skin = Environment->getSkin();
|
||||
IGUISkin *skin = Environment->getSkin();
|
||||
|
||||
ListButton = Environment->addButton(core::recti(0,0,1,1), this, -1, L"");
|
||||
if (skin && skin->getSpriteBank())
|
||||
{
|
||||
ListButton = Environment->addButton(core::recti(0, 0, 1, 1), this, -1, L"");
|
||||
if (skin && skin->getSpriteBank()) {
|
||||
ListButton->setSpriteBank(skin->getSpriteBank());
|
||||
ListButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL));
|
||||
ListButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL));
|
||||
@ -43,7 +42,7 @@ CGUIComboBox::CGUIComboBox(IGUIEnvironment* environment, IGUIElement* parent,
|
||||
ListButton->setSubElement(true);
|
||||
ListButton->setTabStop(false);
|
||||
|
||||
SelectedText = Environment->addStaticText(L"", core::recti(0,0,1,1), false, false, this, -1, false);
|
||||
SelectedText = Environment->addStaticText(L"", core::recti(0, 0, 1, 1), false, false, this, -1, false);
|
||||
SelectedText->setSubElement(true);
|
||||
SelectedText->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
|
||||
SelectedText->setTextAlignment(EGUIA_UPPERLEFT, EGUIA_CENTER);
|
||||
@ -58,7 +57,6 @@ CGUIComboBox::CGUIComboBox(IGUIEnvironment* environment, IGUIElement* parent,
|
||||
setTabOrder(-1);
|
||||
}
|
||||
|
||||
|
||||
void CGUIComboBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical)
|
||||
{
|
||||
HAlign = horizontal;
|
||||
@ -66,15 +64,13 @@ void CGUIComboBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT ve
|
||||
SelectedText->setTextAlignment(horizontal, vertical);
|
||||
}
|
||||
|
||||
|
||||
//! Set the maximal number of rows for the selection listbox
|
||||
void CGUIComboBox::setMaxSelectionRows(u32 max)
|
||||
{
|
||||
MaxSelectionRows = max;
|
||||
|
||||
// force recalculation of open listbox
|
||||
if (ListBox)
|
||||
{
|
||||
if (ListBox) {
|
||||
openCloseMenu();
|
||||
openCloseMenu();
|
||||
}
|
||||
@ -86,16 +82,14 @@ u32 CGUIComboBox::getMaxSelectionRows() const
|
||||
return MaxSelectionRows;
|
||||
}
|
||||
|
||||
|
||||
//! Returns amount of items in box
|
||||
u32 CGUIComboBox::getItemCount() const
|
||||
{
|
||||
return Items.size();
|
||||
}
|
||||
|
||||
|
||||
//! returns string of an item. the idx may be a value from 0 to itemCount-1
|
||||
const wchar_t* CGUIComboBox::getItem(u32 idx) const
|
||||
const wchar_t *CGUIComboBox::getItem(u32 idx) const
|
||||
{
|
||||
if (idx >= Items.size())
|
||||
return 0;
|
||||
@ -113,17 +107,15 @@ u32 CGUIComboBox::getItemData(u32 idx) const
|
||||
}
|
||||
|
||||
//! Returns index based on item data
|
||||
s32 CGUIComboBox::getIndexForItemData(u32 data ) const
|
||||
s32 CGUIComboBox::getIndexForItemData(u32 data) const
|
||||
{
|
||||
for ( u32 i = 0; i < Items.size (); ++i )
|
||||
{
|
||||
if ( Items[i].Data == data )
|
||||
for (u32 i = 0; i < Items.size(); ++i) {
|
||||
if (Items[i].Data == data)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//! Removes an item from the combo box.
|
||||
void CGUIComboBox::removeItem(u32 idx)
|
||||
{
|
||||
@ -136,18 +128,16 @@ void CGUIComboBox::removeItem(u32 idx)
|
||||
Items.erase(idx);
|
||||
}
|
||||
|
||||
|
||||
//! Returns caption of this element.
|
||||
const wchar_t* CGUIComboBox::getText() const
|
||||
const wchar_t *CGUIComboBox::getText() const
|
||||
{
|
||||
return getItem(Selected);
|
||||
}
|
||||
|
||||
|
||||
//! adds an item and returns the index of it
|
||||
u32 CGUIComboBox::addItem(const wchar_t* text, u32 data)
|
||||
u32 CGUIComboBox::addItem(const wchar_t *text, u32 data)
|
||||
{
|
||||
Items.push_back( SComboData ( text, data ) );
|
||||
Items.push_back(SComboData(text, data));
|
||||
|
||||
if (Selected == -1)
|
||||
setSelected(0);
|
||||
@ -155,7 +145,6 @@ u32 CGUIComboBox::addItem(const wchar_t* text, u32 data)
|
||||
return Items.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
//! deletes all items in the combo box
|
||||
void CGUIComboBox::clear()
|
||||
{
|
||||
@ -163,14 +152,12 @@ void CGUIComboBox::clear()
|
||||
setSelected(-1);
|
||||
}
|
||||
|
||||
|
||||
//! returns id of selected item. returns -1 if no item is selected.
|
||||
s32 CGUIComboBox::getSelected() const
|
||||
{
|
||||
return Selected;
|
||||
}
|
||||
|
||||
|
||||
//! sets the selected item. Set this to -1 if no item should be selected
|
||||
void CGUIComboBox::setSelected(s32 idx)
|
||||
{
|
||||
@ -184,7 +171,6 @@ void CGUIComboBox::setSelected(s32 idx)
|
||||
SelectedText->setText(Items[Selected].Name.c_str());
|
||||
}
|
||||
|
||||
|
||||
//! Sets the selected item and emits a change event.
|
||||
/** Set this to -1 if no item should be selected */
|
||||
void CGUIComboBox::setAndSendSelected(s32 idx)
|
||||
@ -193,67 +179,54 @@ void CGUIComboBox::setAndSendSelected(s32 idx)
|
||||
sendSelectionChangedEvent();
|
||||
}
|
||||
|
||||
|
||||
//! called if an event happened.
|
||||
bool CGUIComboBox::OnEvent(const SEvent& event)
|
||||
bool CGUIComboBox::OnEvent(const SEvent &event)
|
||||
{
|
||||
if (isEnabled())
|
||||
{
|
||||
switch(event.EventType)
|
||||
{
|
||||
if (isEnabled()) {
|
||||
switch (event.EventType) {
|
||||
|
||||
case EET_KEY_INPUT_EVENT:
|
||||
if (ListBox && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE)
|
||||
{
|
||||
if (ListBox && event.KeyInput.PressedDown && event.KeyInput.Key == KEY_ESCAPE) {
|
||||
// hide list box
|
||||
openCloseMenu();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE)
|
||||
{
|
||||
if (!event.KeyInput.PressedDown)
|
||||
{
|
||||
} else if (event.KeyInput.Key == KEY_RETURN || event.KeyInput.Key == KEY_SPACE) {
|
||||
if (!event.KeyInput.PressedDown) {
|
||||
openCloseMenu();
|
||||
}
|
||||
|
||||
ListButton->setPressed(ListBox == nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (event.KeyInput.PressedDown)
|
||||
{
|
||||
} else if (event.KeyInput.PressedDown) {
|
||||
s32 oldSelected = Selected;
|
||||
bool absorb = true;
|
||||
switch (event.KeyInput.Key)
|
||||
{
|
||||
case KEY_DOWN:
|
||||
setSelected(Selected+1);
|
||||
break;
|
||||
case KEY_UP:
|
||||
setSelected(Selected-1);
|
||||
break;
|
||||
case KEY_HOME:
|
||||
case KEY_PRIOR:
|
||||
setSelected(0);
|
||||
break;
|
||||
case KEY_END:
|
||||
case KEY_NEXT:
|
||||
setSelected((s32)Items.size()-1);
|
||||
break;
|
||||
default:
|
||||
absorb = false;
|
||||
switch (event.KeyInput.Key) {
|
||||
case KEY_DOWN:
|
||||
setSelected(Selected + 1);
|
||||
break;
|
||||
case KEY_UP:
|
||||
setSelected(Selected - 1);
|
||||
break;
|
||||
case KEY_HOME:
|
||||
case KEY_PRIOR:
|
||||
setSelected(0);
|
||||
break;
|
||||
case KEY_END:
|
||||
case KEY_NEXT:
|
||||
setSelected((s32)Items.size() - 1);
|
||||
break;
|
||||
default:
|
||||
absorb = false;
|
||||
}
|
||||
|
||||
if (Selected <0)
|
||||
if (Selected < 0)
|
||||
setSelected(0);
|
||||
|
||||
if (Selected >= (s32)Items.size())
|
||||
setSelected((s32)Items.size() -1);
|
||||
setSelected((s32)Items.size() - 1);
|
||||
|
||||
if (Selected != oldSelected)
|
||||
{
|
||||
if (Selected != oldSelected) {
|
||||
sendSelectionChangedEvent();
|
||||
return true;
|
||||
}
|
||||
@ -265,31 +238,27 @@ bool CGUIComboBox::OnEvent(const SEvent& event)
|
||||
|
||||
case EET_GUI_EVENT:
|
||||
|
||||
switch(event.GUIEvent.EventType)
|
||||
{
|
||||
switch (event.GUIEvent.EventType) {
|
||||
case EGET_ELEMENT_FOCUS_LOST:
|
||||
if (ListBox &&
|
||||
(Environment->hasFocus(ListBox) || ListBox->isMyChild(event.GUIEvent.Caller) ) &&
|
||||
event.GUIEvent.Element != this &&
|
||||
!isMyChild(event.GUIEvent.Element) &&
|
||||
!ListBox->isMyChild(event.GUIEvent.Element))
|
||||
{
|
||||
(Environment->hasFocus(ListBox) || ListBox->isMyChild(event.GUIEvent.Caller)) &&
|
||||
event.GUIEvent.Element != this &&
|
||||
!isMyChild(event.GUIEvent.Element) &&
|
||||
!ListBox->isMyChild(event.GUIEvent.Element)) {
|
||||
openCloseMenu();
|
||||
}
|
||||
break;
|
||||
case EGET_BUTTON_CLICKED:
|
||||
if (event.GUIEvent.Caller == ListButton)
|
||||
{
|
||||
if (event.GUIEvent.Caller == ListButton) {
|
||||
openCloseMenu();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case EGET_LISTBOX_SELECTED_AGAIN:
|
||||
case EGET_LISTBOX_CHANGED:
|
||||
if (event.GUIEvent.Caller == ListBox)
|
||||
{
|
||||
if (event.GUIEvent.Caller == ListBox) {
|
||||
setSelected(ListBox->getSelected());
|
||||
if (Selected <0 || Selected >= (s32)Items.size())
|
||||
if (Selected < 0 || Selected >= (s32)Items.size())
|
||||
setSelected(-1);
|
||||
openCloseMenu();
|
||||
|
||||
@ -302,53 +271,48 @@ bool CGUIComboBox::OnEvent(const SEvent& event)
|
||||
break;
|
||||
case EET_MOUSE_INPUT_EVENT:
|
||||
|
||||
switch(event.MouseInput.Event)
|
||||
{
|
||||
case EMIE_LMOUSE_PRESSED_DOWN:
|
||||
{
|
||||
core::position2d<s32> p(event.MouseInput.X, event.MouseInput.Y);
|
||||
|
||||
// send to list box
|
||||
if (ListBox && ListBox->isPointInside(p) && ListBox->OnEvent(event))
|
||||
return true;
|
||||
switch (event.MouseInput.Event) {
|
||||
case EMIE_LMOUSE_PRESSED_DOWN: {
|
||||
core::position2d<s32> p(event.MouseInput.X, event.MouseInput.Y);
|
||||
|
||||
// send to list box
|
||||
if (ListBox && ListBox->isPointInside(p) && ListBox->OnEvent(event))
|
||||
return true;
|
||||
}
|
||||
case EMIE_LMOUSE_LEFT_UP:
|
||||
{
|
||||
core::position2d<s32> p(event.MouseInput.X, event.MouseInput.Y);
|
||||
|
||||
// send to list box
|
||||
if (!(ListBox &&
|
||||
return true;
|
||||
}
|
||||
case EMIE_LMOUSE_LEFT_UP: {
|
||||
core::position2d<s32> p(event.MouseInput.X, event.MouseInput.Y);
|
||||
|
||||
// send to list box
|
||||
if (!(ListBox &&
|
||||
ListBox->getAbsolutePosition().isPointInside(p) &&
|
||||
ListBox->OnEvent(event)))
|
||||
{
|
||||
openCloseMenu();
|
||||
}
|
||||
ListBox->OnEvent(event))) {
|
||||
openCloseMenu();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case EMIE_MOUSE_WHEEL: {
|
||||
// Try scrolling parent first
|
||||
if (IGUIElement::OnEvent(event))
|
||||
return true;
|
||||
|
||||
s32 oldSelected = Selected;
|
||||
setSelected(Selected + ((event.MouseInput.Wheel < 0) ? 1 : -1));
|
||||
|
||||
if (Selected < 0)
|
||||
setSelected(0);
|
||||
|
||||
if (Selected >= (s32)Items.size())
|
||||
setSelected((s32)Items.size() - 1);
|
||||
|
||||
if (Selected != oldSelected) {
|
||||
sendSelectionChangedEvent();
|
||||
return true;
|
||||
}
|
||||
case EMIE_MOUSE_WHEEL:
|
||||
{
|
||||
// Try scrolling parent first
|
||||
if (IGUIElement::OnEvent(event))
|
||||
return true;
|
||||
|
||||
s32 oldSelected = Selected;
|
||||
setSelected( Selected + ((event.MouseInput.Wheel < 0) ? 1 : -1));
|
||||
|
||||
if (Selected <0)
|
||||
setSelected(0);
|
||||
|
||||
if (Selected >= (s32)Items.size())
|
||||
setSelected((s32)Items.size() -1);
|
||||
|
||||
if (Selected != oldSelected) {
|
||||
sendSelectionChangedEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -361,11 +325,9 @@ bool CGUIComboBox::OnEvent(const SEvent& event)
|
||||
return IGUIElement::OnEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void CGUIComboBox::sendSelectionChangedEvent()
|
||||
{
|
||||
if (Parent)
|
||||
{
|
||||
if (Parent) {
|
||||
SEvent event;
|
||||
|
||||
event.EventType = EET_GUI_EVENT;
|
||||
@ -378,8 +340,7 @@ void CGUIComboBox::sendSelectionChangedEvent()
|
||||
|
||||
void CGUIComboBox::updateListButtonWidth(s32 width)
|
||||
{
|
||||
if (ListButton->getRelativePosition().getWidth() != width)
|
||||
{
|
||||
if (ListButton->getRelativePosition().getWidth() != width) {
|
||||
core::rect<s32> r;
|
||||
r.UpperLeftCorner.X = RelativeRect.getWidth() - width - 2;
|
||||
r.LowerRightCorner.X = RelativeRect.getWidth() - 2;
|
||||
@ -401,65 +362,54 @@ void CGUIComboBox::draw()
|
||||
if (!IsVisible)
|
||||
return;
|
||||
|
||||
IGUISkin* skin = Environment->getSkin();
|
||||
IGUISkin *skin = Environment->getSkin();
|
||||
|
||||
updateListButtonWidth(skin->getSize(EGDS_SCROLLBAR_SIZE));
|
||||
|
||||
// font changed while the listbox is open?
|
||||
if ( ActiveFont != skin->getFont() && ListBox )
|
||||
{
|
||||
if (ActiveFont != skin->getFont() && ListBox) {
|
||||
// close and re-open to use new font-size
|
||||
openCloseMenu();
|
||||
openCloseMenu();
|
||||
}
|
||||
|
||||
|
||||
IGUIElement *currentFocus = Environment->getFocus();
|
||||
if (currentFocus != LastFocus)
|
||||
{
|
||||
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())
|
||||
{
|
||||
if (isEnabled()) {
|
||||
SelectedText->setDrawBackground(HasFocus);
|
||||
SelectedText->setOverrideColor(skin->getColor(HasFocus ? EGDC_HIGH_LIGHT_TEXT : EGDC_BUTTON_TEXT));
|
||||
}
|
||||
else
|
||||
{
|
||||
} 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);
|
||||
true, true, frameRect, &AbsoluteClippingRect);
|
||||
|
||||
// draw children
|
||||
IGUIElement::draw();
|
||||
}
|
||||
|
||||
|
||||
void CGUIComboBox::openCloseMenu()
|
||||
{
|
||||
if (ListBox)
|
||||
{
|
||||
if (ListBox) {
|
||||
// close list box
|
||||
Environment->setFocus(this);
|
||||
ListBox->remove();
|
||||
ListBox = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (Parent) {
|
||||
SEvent event;
|
||||
event.EventType = EET_GUI_EVENT;
|
||||
@ -474,7 +424,7 @@ void CGUIComboBox::openCloseMenu()
|
||||
Parent->bringToFront(this);
|
||||
}
|
||||
|
||||
IGUISkin* skin = Environment->getSkin();
|
||||
IGUISkin *skin = Environment->getSkin();
|
||||
u32 h = Items.size();
|
||||
|
||||
if (h > getMaxSelectionRows())
|
||||
@ -488,7 +438,7 @@ void CGUIComboBox::openCloseMenu()
|
||||
|
||||
// open list box
|
||||
core::rect<s32> r(0, AbsoluteRect.getHeight(),
|
||||
AbsoluteRect.getWidth(), AbsoluteRect.getHeight() + h);
|
||||
AbsoluteRect.getWidth(), AbsoluteRect.getHeight() + h);
|
||||
|
||||
ListBox = new CGUIListBox(Environment, this, -1, r, false, true, true);
|
||||
ListBox->setSubElement(true);
|
||||
@ -497,9 +447,9 @@ void CGUIComboBox::openCloseMenu()
|
||||
|
||||
// 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) );
|
||||
ListBox->setRelativePosition(core::rect<s32>(0, -ListBox->getAbsolutePosition().getHeight(), AbsoluteRect.getWidth(), 0));
|
||||
|
||||
for (s32 i=0; i<(s32)Items.size(); ++i)
|
||||
for (s32 i = 0; i < (s32)Items.size(); ++i)
|
||||
ListBox->addItem(Items[i].Name.c_str());
|
||||
|
||||
ListBox->setSelected(Selected);
|
||||
@ -509,6 +459,5 @@ void CGUIComboBox::openCloseMenu()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // end namespace gui
|
||||
} // end namespace irr
|
||||
|
Reference in New Issue
Block a user