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:
Desour
2024-03-20 19:35:52 +01:00
parent eb4dec46c2
commit 2bf1d12353
292 changed files with 37376 additions and 42421 deletions

View File

@ -17,20 +17,20 @@ namespace irr
namespace gui
{
//! constructor
CGUIScrollBar::CGUIScrollBar(bool horizontal, IGUIEnvironment* environment,
IGUIElement* parent, s32 id,
core::rect<s32> rectangle, bool noclip)
: IGUIScrollBar(environment, parent, id, rectangle), UpButton(0),
DownButton(0), Dragging(false), Horizontal(horizontal),
DraggedBySlider(false), TrayClick(false), Pos(0), DrawPos(0),
DrawHeight(0), Min(0), Max(100), SmallStep(10), LargeStep(50), DesiredPos(0),
LastChange(0)
CGUIScrollBar::CGUIScrollBar(bool horizontal, IGUIEnvironment *environment,
IGUIElement *parent, s32 id,
core::rect<s32> rectangle, bool noclip) :
IGUIScrollBar(environment, parent, id, rectangle),
UpButton(0),
DownButton(0), Dragging(false), Horizontal(horizontal),
DraggedBySlider(false), TrayClick(false), Pos(0), DrawPos(0),
DrawHeight(0), Min(0), Max(100), SmallStep(10), LargeStep(50), DesiredPos(0),
LastChange(0)
{
#ifdef _DEBUG
#ifdef _DEBUG
setDebugName("CGUIScrollBar");
#endif
#endif
refreshControls();
@ -43,7 +43,6 @@ CGUIScrollBar::CGUIScrollBar(bool horizontal, IGUIEnvironment* environment,
setPos(0);
}
//! destructor
CGUIScrollBar::~CGUIScrollBar()
{
@ -54,48 +53,42 @@ CGUIScrollBar::~CGUIScrollBar()
DownButton->drop();
}
//! called if an event happened.
bool CGUIScrollBar::OnEvent(const SEvent& event)
bool CGUIScrollBar::OnEvent(const SEvent &event)
{
if (isEnabled())
{
if (isEnabled()) {
switch(event.EventType)
{
switch (event.EventType) {
case EET_KEY_INPUT_EVENT:
if (event.KeyInput.PressedDown)
{
if (event.KeyInput.PressedDown) {
const s32 oldPos = Pos;
bool absorb = true;
switch (event.KeyInput.Key)
{
switch (event.KeyInput.Key) {
case KEY_LEFT:
case KEY_UP:
setPos(Pos-SmallStep);
setPos(Pos - SmallStep);
break;
case KEY_RIGHT:
case KEY_DOWN:
setPos(Pos+SmallStep);
setPos(Pos + SmallStep);
break;
case KEY_HOME:
setPos(Min);
break;
case KEY_PRIOR:
setPos(Pos-LargeStep);
setPos(Pos - LargeStep);
break;
case KEY_END:
setPos(Max);
break;
case KEY_NEXT:
setPos(Pos+LargeStep);
setPos(Pos + LargeStep);
break;
default:
absorb = false;
}
if (Pos != oldPos)
{
if (Pos != oldPos) {
SEvent newEvent;
newEvent.EventType = EET_GUI_EVENT;
newEvent.GUIEvent.Caller = this;
@ -108,13 +101,11 @@ bool CGUIScrollBar::OnEvent(const SEvent& event)
}
break;
case EET_GUI_EVENT:
if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
{
if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) {
if (event.GUIEvent.Caller == UpButton)
setPos(Pos-SmallStep);
else
if (event.GUIEvent.Caller == DownButton)
setPos(Pos+SmallStep);
setPos(Pos - SmallStep);
else if (event.GUIEvent.Caller == DownButton)
setPos(Pos + SmallStep);
SEvent newEvent;
newEvent.EventType = EET_GUI_EVENT;
@ -124,29 +115,22 @@ bool CGUIScrollBar::OnEvent(const SEvent& event)
Parent->OnEvent(newEvent);
return true;
}
else
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
{
} else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) {
if (event.GUIEvent.Caller == this)
Dragging = false;
}
break;
case EET_MOUSE_INPUT_EVENT:
{
case EET_MOUSE_INPUT_EVENT: {
const core::position2di p(event.MouseInput.X, event.MouseInput.Y);
bool isInside = isPointInside ( p );
switch(event.MouseInput.Event)
{
bool isInside = isPointInside(p);
switch (event.MouseInput.Event) {
case EMIE_MOUSE_WHEEL:
if (Environment->hasFocus(this))
{
if (Environment->hasFocus(this)) {
// thanks to a bug report by REAPER
// thanks to tommi by tommi for another bugfix
// everybody needs a little thanking. hallo niko!;-)
setPos( getPos() +
( (event.MouseInput.Wheel < 0 ? -1 : 1) * SmallStep * (Horizontal ? 1 : -1 ) )
);
setPos(getPos() +
((event.MouseInput.Wheel < 0 ? -1 : 1) * SmallStep * (Horizontal ? 1 : -1)));
SEvent newEvent;
newEvent.EventType = EET_GUI_EVENT;
@ -157,10 +141,8 @@ bool CGUIScrollBar::OnEvent(const SEvent& event)
return true;
}
break;
case EMIE_LMOUSE_PRESSED_DOWN:
{
if (isInside)
{
case EMIE_LMOUSE_PRESSED_DOWN: {
if (isInside) {
Dragging = true;
DraggedBySlider = SliderRect.isPointInside(p);
TrayClick = !DraggedBySlider;
@ -170,55 +152,44 @@ bool CGUIScrollBar::OnEvent(const SEvent& event)
break;
}
case EMIE_LMOUSE_LEFT_UP:
case EMIE_MOUSE_MOVED:
{
if ( !event.MouseInput.isLeftPressed () )
case EMIE_MOUSE_MOVED: {
if (!event.MouseInput.isLeftPressed())
Dragging = false;
if ( !Dragging )
{
if ( event.MouseInput.Event == EMIE_MOUSE_MOVED )
if (!Dragging) {
if (event.MouseInput.Event == EMIE_MOUSE_MOVED)
break;
return isInside;
}
if ( event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP )
if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
Dragging = false;
const s32 newPos = getPosFromMousePos(p);
const s32 oldPos = Pos;
if (!DraggedBySlider)
{
if ( isInside )
{
if (!DraggedBySlider) {
if (isInside) {
DraggedBySlider = SliderRect.isPointInside(p);
TrayClick = !DraggedBySlider;
}
if (DraggedBySlider)
{
if (DraggedBySlider) {
setPos(newPos);
}
else
{
} else {
TrayClick = false;
if (event.MouseInput.Event == EMIE_MOUSE_MOVED)
return isInside;
}
}
if (DraggedBySlider)
{
if (DraggedBySlider) {
setPos(newPos);
}
else
{
} else {
DesiredPos = newPos;
}
if (Pos != oldPos && Parent)
{
if (Pos != oldPos && Parent) {
SEvent newEvent;
newEvent.EventType = EET_GUI_EVENT;
newEvent.GUIEvent.Caller = this;
@ -243,23 +214,19 @@ bool CGUIScrollBar::OnEvent(const SEvent& event)
void CGUIScrollBar::OnPostRender(u32 timeMs)
{
if (Dragging && !DraggedBySlider && TrayClick && timeMs > LastChange + 200)
{
if (Dragging && !DraggedBySlider && TrayClick && timeMs > LastChange + 200) {
LastChange = timeMs;
const s32 oldPos = Pos;
if (DesiredPos >= Pos + LargeStep)
setPos(Pos + LargeStep);
else
if (DesiredPos <= Pos - LargeStep)
else if (DesiredPos <= Pos - LargeStep)
setPos(Pos - LargeStep);
else
if (DesiredPos >= Pos - LargeStep && DesiredPos <= Pos + LargeStep)
else if (DesiredPos >= Pos - LargeStep && DesiredPos <= Pos + LargeStep)
setPos(DesiredPos);
if (Pos != oldPos && Parent)
{
if (Pos != oldPos && Parent) {
SEvent newEvent;
newEvent.EventType = EET_GUI_EVENT;
newEvent.GUIEvent.Caller = this;
@ -268,7 +235,6 @@ void CGUIScrollBar::OnPostRender(u32 timeMs)
Parent->OnEvent(newEvent);
}
}
}
//! draws the element and its children
@ -277,34 +243,27 @@ void CGUIScrollBar::draw()
if (!IsVisible)
return;
IGUISkin* skin = Environment->getSkin();
IGUISkin *skin = Environment->getSkin();
if (!skin)
return;
video::SColor iconColor = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL);
if ( iconColor != CurrentIconColor )
{
if (iconColor != CurrentIconColor) {
refreshControls();
}
SliderRect = AbsoluteRect;
// draws the background
skin->draw2DRectangle(this, skin->getColor(EGDC_SCROLLBAR), SliderRect, &AbsoluteClippingRect);
if ( core::isnotzero ( range() ) )
{
if (core::isnotzero(range())) {
// recalculate slider rectangle
if (Horizontal)
{
SliderRect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + DrawPos + RelativeRect.getHeight() - DrawHeight/2;
if (Horizontal) {
SliderRect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + DrawPos + RelativeRect.getHeight() - DrawHeight / 2;
SliderRect.LowerRightCorner.X = SliderRect.UpperLeftCorner.X + DrawHeight;
}
else
{
SliderRect.UpperLeftCorner.Y = AbsoluteRect.UpperLeftCorner.Y + DrawPos + RelativeRect.getWidth() - DrawHeight/2;
} else {
SliderRect.UpperLeftCorner.Y = AbsoluteRect.UpperLeftCorner.Y + DrawPos + RelativeRect.getWidth() - DrawHeight / 2;
SliderRect.LowerRightCorner.Y = SliderRect.UpperLeftCorner.Y + DrawHeight;
}
@ -315,64 +274,53 @@ void CGUIScrollBar::draw()
IGUIElement::draw();
}
void CGUIScrollBar::updateAbsolutePosition()
{
IGUIElement::updateAbsolutePosition();
// todo: properly resize
refreshControls();
setPos ( Pos );
setPos(Pos);
}
//!
s32 CGUIScrollBar::getPosFromMousePos(const core::position2di &pos) const
{
f32 w, p;
if (Horizontal)
{
w = RelativeRect.getWidth() - f32(RelativeRect.getHeight())*3.0f;
p = pos.X - AbsoluteRect.UpperLeftCorner.X - RelativeRect.getHeight()*1.5f;
if (Horizontal) {
w = RelativeRect.getWidth() - f32(RelativeRect.getHeight()) * 3.0f;
p = pos.X - AbsoluteRect.UpperLeftCorner.X - RelativeRect.getHeight() * 1.5f;
} else {
w = RelativeRect.getHeight() - f32(RelativeRect.getWidth()) * 3.0f;
p = pos.Y - AbsoluteRect.UpperLeftCorner.Y - RelativeRect.getWidth() * 1.5f;
}
else
{
w = RelativeRect.getHeight() - f32(RelativeRect.getWidth())*3.0f;
p = pos.Y - AbsoluteRect.UpperLeftCorner.Y - RelativeRect.getWidth()*1.5f;
}
return (s32) ( p/w * range() ) + Min;
return (s32)(p / w * range()) + Min;
}
//! sets the position of the scrollbar
void CGUIScrollBar::setPos(s32 pos)
{
Pos = core::s32_clamp ( pos, Min, Max );
Pos = core::s32_clamp(pos, Min, Max);
if ( core::isnotzero ( range() ) )
{
if (Horizontal)
{
f32 f = (RelativeRect.getWidth() - ((f32)RelativeRect.getHeight()*3.0f)) / range();
DrawPos = (s32)( ( ( Pos - Min ) * f) + ((f32)RelativeRect.getHeight() * 0.5f));
if (core::isnotzero(range())) {
if (Horizontal) {
f32 f = (RelativeRect.getWidth() - ((f32)RelativeRect.getHeight() * 3.0f)) / range();
DrawPos = (s32)(((Pos - Min) * f) + ((f32)RelativeRect.getHeight() * 0.5f));
DrawHeight = RelativeRect.getHeight();
}
else
{
f32 f = (RelativeRect.getHeight() - ((f32)RelativeRect.getWidth()*3.0f)) / range();
} else {
f32 f = (RelativeRect.getHeight() - ((f32)RelativeRect.getWidth() * 3.0f)) / range();
DrawPos = (s32)( ( ( Pos - Min ) * f) + ((f32)RelativeRect.getWidth() * 0.5f));
DrawPos = (s32)(((Pos - Min) * f) + ((f32)RelativeRect.getWidth() * 0.5f));
DrawHeight = RelativeRect.getWidth();
}
}
}
//! gets the small step value
s32 CGUIScrollBar::getSmallStep() const
{
return SmallStep;
}
//! sets the small step value
void CGUIScrollBar::setSmallStep(s32 step)
{
@ -382,14 +330,12 @@ void CGUIScrollBar::setSmallStep(s32 step)
SmallStep = 10;
}
//! gets the small step value
s32 CGUIScrollBar::getLargeStep() const
{
return LargeStep;
}
//! sets the small step value
void CGUIScrollBar::setLargeStep(s32 step)
{
@ -399,22 +345,20 @@ void CGUIScrollBar::setLargeStep(s32 step)
LargeStep = 50;
}
//! gets the maximum value of the scrollbar.
s32 CGUIScrollBar::getMax() const
{
return Max;
}
//! sets the maximum value of the scrollbar.
void CGUIScrollBar::setMax(s32 max)
{
Max = max;
if ( Min > Max )
if (Min > Max)
Min = Max;
bool enable = core::isnotzero ( range() );
bool enable = core::isnotzero(range());
UpButton->setEnabled(enable);
DownButton->setEnabled(enable);
setPos(Pos);
@ -426,107 +370,91 @@ s32 CGUIScrollBar::getMin() const
return Min;
}
//! sets the minimum value of the scrollbar.
void CGUIScrollBar::setMin(s32 min)
{
Min = min;
if ( Max < Min )
if (Max < Min)
Max = Min;
bool enable = core::isnotzero ( range() );
bool enable = core::isnotzero(range());
UpButton->setEnabled(enable);
DownButton->setEnabled(enable);
setPos(Pos);
}
//! gets the current position of the scrollbar
s32 CGUIScrollBar::getPos() const
{
return Pos;
}
//! refreshes the position and text on child buttons
void CGUIScrollBar::refreshControls()
{
CurrentIconColor = video::SColor(255,255,255,255);
CurrentIconColor = video::SColor(255, 255, 255, 255);
IGUISkin* skin = Environment->getSkin();
IGUISpriteBank* sprites = 0;
IGUISkin *skin = Environment->getSkin();
IGUISpriteBank *sprites = 0;
if (skin)
{
if (skin) {
sprites = skin->getSpriteBank();
CurrentIconColor = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL);
}
if (Horizontal)
{
if (Horizontal) {
const s32 h = RelativeRect.getHeight();
const s32 w = (h < RelativeRect.getWidth() / 2) ? h : RelativeRect.getWidth() / 2;
if (!UpButton)
{
UpButton = new CGUIButton(Environment, this, -1, core::rect<s32>(0,0, w, h), NoClip);
if (!UpButton) {
UpButton = new CGUIButton(Environment, this, -1, core::rect<s32>(0, 0, w, h), NoClip);
UpButton->setSubElement(true);
UpButton->setTabStop(false);
}
if (sprites)
{
if (sprites) {
UpButton->setSpriteBank(sprites);
UpButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_LEFT), CurrentIconColor);
UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_LEFT), CurrentIconColor);
}
UpButton->setRelativePosition(core::rect<s32>(0,0, w, h));
UpButton->setRelativePosition(core::rect<s32>(0, 0, w, h));
UpButton->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
if (!DownButton)
{
DownButton = new CGUIButton(Environment, this, -1, core::rect<s32>(RelativeRect.getWidth()-w, 0, RelativeRect.getWidth(), h), NoClip);
if (!DownButton) {
DownButton = new CGUIButton(Environment, this, -1, core::rect<s32>(RelativeRect.getWidth() - w, 0, RelativeRect.getWidth(), h), NoClip);
DownButton->setSubElement(true);
DownButton->setTabStop(false);
}
if (sprites)
{
if (sprites) {
DownButton->setSpriteBank(sprites);
DownButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_RIGHT), CurrentIconColor);
DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_RIGHT), CurrentIconColor);
}
DownButton->setRelativePosition(core::rect<s32>(RelativeRect.getWidth()-w, 0, RelativeRect.getWidth(), h));
DownButton->setRelativePosition(core::rect<s32>(RelativeRect.getWidth() - w, 0, RelativeRect.getWidth(), h));
DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
}
else
{
} else {
const s32 w = RelativeRect.getWidth();
const s32 h = (w < RelativeRect.getHeight() / 2) ? w : RelativeRect.getHeight() / 2;
if (!UpButton)
{
UpButton = new CGUIButton(Environment, this, -1, core::rect<s32>(0,0, w, h), NoClip);
if (!UpButton) {
UpButton = new CGUIButton(Environment, this, -1, core::rect<s32>(0, 0, w, h), NoClip);
UpButton->setSubElement(true);
UpButton->setTabStop(false);
}
if (sprites)
{
if (sprites) {
UpButton->setSpriteBank(sprites);
UpButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_UP), CurrentIconColor);
UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_UP), CurrentIconColor);
}
UpButton->setRelativePosition(core::rect<s32>(0,0, w, h));
UpButton->setRelativePosition(core::rect<s32>(0, 0, w, h));
UpButton->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (!DownButton)
{
DownButton = new CGUIButton(Environment, this, -1, core::rect<s32>(0,RelativeRect.getHeight()-h, w, RelativeRect.getHeight()), NoClip);
if (!DownButton) {
DownButton = new CGUIButton(Environment, this, -1, core::rect<s32>(0, RelativeRect.getHeight() - h, w, RelativeRect.getHeight()), NoClip);
DownButton->setSubElement(true);
DownButton->setTabStop(false);
}
if (sprites)
{
if (sprites) {
DownButton->setSpriteBank(sprites);
DownButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), CurrentIconColor);
DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), CurrentIconColor);
}
DownButton->setRelativePosition(core::rect<s32>(0,RelativeRect.getHeight()-h, w, RelativeRect.getHeight()));
DownButton->setRelativePosition(core::rect<s32>(0, RelativeRect.getHeight() - h, w, RelativeRect.getHeight()));
DownButton->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
}
}