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:
@ -22,46 +22,41 @@ namespace gui
|
||||
const s32 FOD_WIDTH = 350;
|
||||
const s32 FOD_HEIGHT = 250;
|
||||
|
||||
|
||||
//! constructor
|
||||
CGUIFileOpenDialog::CGUIFileOpenDialog(const wchar_t* title,
|
||||
IGUIEnvironment* environment, IGUIElement* parent, s32 id,
|
||||
bool restoreCWD, io::path::char_type* startDir)
|
||||
: IGUIFileOpenDialog(environment, parent, id,
|
||||
core::rect<s32>((parent->getAbsolutePosition().getWidth()-FOD_WIDTH)/2,
|
||||
(parent->getAbsolutePosition().getHeight()-FOD_HEIGHT)/2,
|
||||
(parent->getAbsolutePosition().getWidth()-FOD_WIDTH)/2+FOD_WIDTH,
|
||||
(parent->getAbsolutePosition().getHeight()-FOD_HEIGHT)/2+FOD_HEIGHT)),
|
||||
FileNameText(0), FileList(0), Dragging(false)
|
||||
CGUIFileOpenDialog::CGUIFileOpenDialog(const wchar_t *title,
|
||||
IGUIEnvironment *environment, IGUIElement *parent, s32 id,
|
||||
bool restoreCWD, io::path::char_type *startDir) :
|
||||
IGUIFileOpenDialog(environment, parent, id,
|
||||
core::rect<s32>((parent->getAbsolutePosition().getWidth() - FOD_WIDTH) / 2,
|
||||
(parent->getAbsolutePosition().getHeight() - FOD_HEIGHT) / 2,
|
||||
(parent->getAbsolutePosition().getWidth() - FOD_WIDTH) / 2 + FOD_WIDTH,
|
||||
(parent->getAbsolutePosition().getHeight() - FOD_HEIGHT) / 2 + FOD_HEIGHT)),
|
||||
FileNameText(0), FileList(0), Dragging(false)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
#ifdef _DEBUG
|
||||
IGUIElement::setDebugName("CGUIFileOpenDialog");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Text = title;
|
||||
|
||||
FileSystem = Environment?Environment->getFileSystem():0;
|
||||
FileSystem = Environment ? Environment->getFileSystem() : 0;
|
||||
|
||||
if (FileSystem)
|
||||
{
|
||||
if (FileSystem) {
|
||||
FileSystem->grab();
|
||||
|
||||
if (restoreCWD)
|
||||
RestoreDirectory = FileSystem->getWorkingDirectory();
|
||||
if (startDir)
|
||||
{
|
||||
if (startDir) {
|
||||
StartDirectory = startDir;
|
||||
FileSystem->changeWorkingDirectoryTo(startDir);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
return;
|
||||
|
||||
IGUISpriteBank* sprites = 0;
|
||||
video::SColor color(255,255,255,255);
|
||||
IGUISkin* skin = Environment->getSkin();
|
||||
if (skin)
|
||||
{
|
||||
IGUISpriteBank *sprites = 0;
|
||||
video::SColor color(255, 255, 255, 255);
|
||||
IGUISkin *skin = Environment->getSkin();
|
||||
if (skin) {
|
||||
sprites = skin->getSpriteBank();
|
||||
color = skin->getColor(EGDC_WINDOW_SYMBOL);
|
||||
}
|
||||
@ -70,11 +65,10 @@ CGUIFileOpenDialog::CGUIFileOpenDialog(const wchar_t* title,
|
||||
const s32 posx = RelativeRect.getWidth() - buttonw - 4;
|
||||
|
||||
CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
|
||||
L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close");
|
||||
L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close");
|
||||
CloseButton->setSubElement(true);
|
||||
CloseButton->setTabStop(false);
|
||||
if (sprites && skin)
|
||||
{
|
||||
if (sprites && skin) {
|
||||
CloseButton->setSpriteBank(sprites);
|
||||
CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), color);
|
||||
CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), color);
|
||||
@ -83,25 +77,25 @@ CGUIFileOpenDialog::CGUIFileOpenDialog(const wchar_t* title,
|
||||
CloseButton->grab();
|
||||
|
||||
OKButton = Environment->addButton(
|
||||
core::rect<s32>(RelativeRect.getWidth()-80, 30, RelativeRect.getWidth()-10, 50),
|
||||
this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"OK");
|
||||
core::rect<s32>(RelativeRect.getWidth() - 80, 30, RelativeRect.getWidth() - 10, 50),
|
||||
this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"OK");
|
||||
OKButton->setSubElement(true);
|
||||
OKButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
|
||||
OKButton->grab();
|
||||
|
||||
CancelButton = Environment->addButton(
|
||||
core::rect<s32>(RelativeRect.getWidth()-80, 55, RelativeRect.getWidth()-10, 75),
|
||||
this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_CANCEL) : L"Cancel");
|
||||
core::rect<s32>(RelativeRect.getWidth() - 80, 55, RelativeRect.getWidth() - 10, 75),
|
||||
this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_CANCEL) : L"Cancel");
|
||||
CancelButton->setSubElement(true);
|
||||
CancelButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
|
||||
CancelButton->grab();
|
||||
|
||||
FileBox = Environment->addListBox(core::rect<s32>(10, 55, RelativeRect.getWidth()-90, 230), this, -1, true);
|
||||
FileBox = Environment->addListBox(core::rect<s32>(10, 55, RelativeRect.getWidth() - 90, 230), this, -1, true);
|
||||
FileBox->setSubElement(true);
|
||||
FileBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
|
||||
FileBox->grab();
|
||||
|
||||
FileNameText = Environment->addEditBox(0, core::rect<s32>(10, 30, RelativeRect.getWidth()-90, 50), true, this);
|
||||
FileNameText = Environment->addEditBox(0, core::rect<s32>(10, 30, RelativeRect.getWidth() - 90, 50), true, this);
|
||||
FileNameText->setSubElement(true);
|
||||
FileNameText->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
|
||||
FileNameText->grab();
|
||||
@ -111,7 +105,6 @@ CGUIFileOpenDialog::CGUIFileOpenDialog(const wchar_t* title,
|
||||
fillListBox();
|
||||
}
|
||||
|
||||
|
||||
//! destructor
|
||||
CGUIFileOpenDialog::~CGUIFileOpenDialog()
|
||||
{
|
||||
@ -130,8 +123,7 @@ CGUIFileOpenDialog::~CGUIFileOpenDialog()
|
||||
if (FileNameText)
|
||||
FileNameText->drop();
|
||||
|
||||
if (FileSystem)
|
||||
{
|
||||
if (FileSystem) {
|
||||
// revert to original CWD if path was set in constructor
|
||||
if (RestoreDirectory.size())
|
||||
FileSystem->changeWorkingDirectoryTo(RestoreDirectory);
|
||||
@ -142,139 +134,114 @@ CGUIFileOpenDialog::~CGUIFileOpenDialog()
|
||||
FileList->drop();
|
||||
}
|
||||
|
||||
|
||||
//! returns the filename of the selected file. Returns NULL, if no file was selected.
|
||||
const wchar_t* CGUIFileOpenDialog::getFileName() const
|
||||
const wchar_t *CGUIFileOpenDialog::getFileName() const
|
||||
{
|
||||
return FileNameW.c_str();
|
||||
}
|
||||
|
||||
const io::path& CGUIFileOpenDialog::getFileNameP() const
|
||||
const io::path &CGUIFileOpenDialog::getFileNameP() const
|
||||
{
|
||||
return FileName;
|
||||
}
|
||||
|
||||
//! Returns the directory of the selected file. Returns NULL, if no directory was selected.
|
||||
const io::path& CGUIFileOpenDialog::getDirectoryName() const
|
||||
const io::path &CGUIFileOpenDialog::getDirectoryName() const
|
||||
{
|
||||
return FileDirectoryFlat;
|
||||
}
|
||||
|
||||
const wchar_t* CGUIFileOpenDialog::getDirectoryNameW() const
|
||||
const wchar_t *CGUIFileOpenDialog::getDirectoryNameW() const
|
||||
{
|
||||
return FileDirectoryFlatW.c_str();
|
||||
}
|
||||
|
||||
void CGUIFileOpenDialog::setFileName(const irr::io::path& name)
|
||||
void CGUIFileOpenDialog::setFileName(const irr::io::path &name)
|
||||
{
|
||||
FileName = name;
|
||||
pathToStringW(FileNameW, FileName);
|
||||
}
|
||||
|
||||
void CGUIFileOpenDialog::setDirectoryName(const irr::io::path& name)
|
||||
void CGUIFileOpenDialog::setDirectoryName(const irr::io::path &name)
|
||||
{
|
||||
FileDirectory = name;
|
||||
FileDirectoryFlat = name;
|
||||
FileSystem->flattenFilename (FileDirectoryFlat );
|
||||
FileSystem->flattenFilename(FileDirectoryFlat);
|
||||
pathToStringW(FileDirectoryFlatW, FileDirectoryFlat);
|
||||
}
|
||||
|
||||
//! called if an event happened.
|
||||
bool CGUIFileOpenDialog::OnEvent(const SEvent& event)
|
||||
bool CGUIFileOpenDialog::OnEvent(const SEvent &event)
|
||||
{
|
||||
if (isEnabled())
|
||||
{
|
||||
switch(event.EventType)
|
||||
{
|
||||
if (isEnabled()) {
|
||||
switch (event.EventType) {
|
||||
case EET_GUI_EVENT:
|
||||
switch(event.GUIEvent.EventType)
|
||||
{
|
||||
switch (event.GUIEvent.EventType) {
|
||||
case EGET_ELEMENT_FOCUS_LOST:
|
||||
Dragging = false;
|
||||
break;
|
||||
case EGET_BUTTON_CLICKED:
|
||||
if (event.GUIEvent.Caller == CloseButton ||
|
||||
event.GUIEvent.Caller == CancelButton)
|
||||
{
|
||||
event.GUIEvent.Caller == CancelButton) {
|
||||
sendCancelEvent();
|
||||
remove();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (event.GUIEvent.Caller == OKButton )
|
||||
{
|
||||
if ( FileDirectory != L"" )
|
||||
{
|
||||
sendSelectedEvent( EGET_DIRECTORY_SELECTED );
|
||||
} else if (event.GUIEvent.Caller == OKButton) {
|
||||
if (FileDirectory != L"") {
|
||||
sendSelectedEvent(EGET_DIRECTORY_SELECTED);
|
||||
}
|
||||
if ( FileName != L"" )
|
||||
{
|
||||
sendSelectedEvent( EGET_FILE_SELECTED );
|
||||
if (FileName != L"") {
|
||||
sendSelectedEvent(EGET_FILE_SELECTED);
|
||||
remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EGET_LISTBOX_CHANGED:
|
||||
{
|
||||
s32 selected = FileBox->getSelected();
|
||||
if (FileList && FileSystem)
|
||||
{
|
||||
if (FileList->isDirectory(selected))
|
||||
{
|
||||
setFileName("");
|
||||
setDirectoryName(FileList->getFullFileName(selected));
|
||||
}
|
||||
else
|
||||
{
|
||||
setDirectoryName("");
|
||||
setFileName(FileList->getFullFileName(selected));
|
||||
}
|
||||
return true;
|
||||
case EGET_LISTBOX_CHANGED: {
|
||||
s32 selected = FileBox->getSelected();
|
||||
if (FileList && FileSystem) {
|
||||
if (FileList->isDirectory(selected)) {
|
||||
setFileName("");
|
||||
setDirectoryName(FileList->getFullFileName(selected));
|
||||
} else {
|
||||
setDirectoryName("");
|
||||
setFileName(FileList->getFullFileName(selected));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case EGET_LISTBOX_SELECTED_AGAIN:
|
||||
{
|
||||
const s32 selected = FileBox->getSelected();
|
||||
if (FileList && FileSystem)
|
||||
{
|
||||
if (FileList->isDirectory(selected))
|
||||
{
|
||||
setDirectoryName(FileList->getFullFileName(selected));
|
||||
FileSystem->changeWorkingDirectoryTo(FileDirectory );
|
||||
fillListBox();
|
||||
setFileName("");
|
||||
}
|
||||
else
|
||||
{
|
||||
setFileName(FileList->getFullFileName(selected));
|
||||
}
|
||||
return true;
|
||||
case EGET_LISTBOX_SELECTED_AGAIN: {
|
||||
const s32 selected = FileBox->getSelected();
|
||||
if (FileList && FileSystem) {
|
||||
if (FileList->isDirectory(selected)) {
|
||||
setDirectoryName(FileList->getFullFileName(selected));
|
||||
FileSystem->changeWorkingDirectoryTo(FileDirectory);
|
||||
fillListBox();
|
||||
setFileName("");
|
||||
} else {
|
||||
setFileName(FileList->getFullFileName(selected));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case EGET_EDITBOX_ENTER:
|
||||
if (event.GUIEvent.Caller == FileNameText)
|
||||
{
|
||||
io::path dir( FileNameText->getText () );
|
||||
if ( FileSystem->changeWorkingDirectoryTo( dir ) )
|
||||
{
|
||||
if (event.GUIEvent.Caller == FileNameText) {
|
||||
io::path dir(FileNameText->getText());
|
||||
if (FileSystem->changeWorkingDirectoryTo(dir)) {
|
||||
fillListBox();
|
||||
setFileName("");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case EET_MOUSE_INPUT_EVENT:
|
||||
switch(event.MouseInput.Event)
|
||||
{
|
||||
switch (event.MouseInput.Event) {
|
||||
case EMIE_MOUSE_WHEEL:
|
||||
return FileBox->OnEvent(event);
|
||||
case EMIE_LMOUSE_PRESSED_DOWN:
|
||||
@ -287,17 +254,16 @@ bool CGUIFileOpenDialog::OnEvent(const SEvent& event)
|
||||
return true;
|
||||
case EMIE_MOUSE_MOVED:
|
||||
|
||||
if ( !event.MouseInput.isLeftPressed () )
|
||||
if (!event.MouseInput.isLeftPressed())
|
||||
Dragging = false;
|
||||
|
||||
if (Dragging)
|
||||
{
|
||||
if (Dragging) {
|
||||
// gui window should not be dragged outside its parent
|
||||
if (Parent)
|
||||
if (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 ||
|
||||
event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 ||
|
||||
event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 ||
|
||||
event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1)
|
||||
if (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X + 1 ||
|
||||
event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y + 1 ||
|
||||
event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X - 1 ||
|
||||
event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y - 1)
|
||||
|
||||
return true;
|
||||
|
||||
@ -318,26 +284,24 @@ bool CGUIFileOpenDialog::OnEvent(const SEvent& event)
|
||||
return IGUIElement::OnEvent(event);
|
||||
}
|
||||
|
||||
|
||||
//! draws the element and its children
|
||||
void CGUIFileOpenDialog::draw()
|
||||
{
|
||||
if (!IsVisible)
|
||||
return;
|
||||
|
||||
IGUISkin* skin = Environment->getSkin();
|
||||
IGUISkin *skin = Environment->getSkin();
|
||||
|
||||
core::rect<s32> rect = AbsoluteRect;
|
||||
|
||||
rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER),
|
||||
rect, &AbsoluteClippingRect);
|
||||
rect, &AbsoluteClippingRect);
|
||||
|
||||
if (Text.size())
|
||||
{
|
||||
if (Text.size()) {
|
||||
rect.UpperLeftCorner.X += 2;
|
||||
rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;
|
||||
|
||||
IGUIFont* font = skin->getFont(EGDF_WINDOW);
|
||||
IGUIFont *font = skin->getFont(EGDF_WINDOW);
|
||||
if (font)
|
||||
font->draw(Text.c_str(), rect,
|
||||
skin->getColor(EGDC_ACTIVE_CAPTION),
|
||||
@ -347,7 +311,7 @@ void CGUIFileOpenDialog::draw()
|
||||
IGUIElement::draw();
|
||||
}
|
||||
|
||||
void CGUIFileOpenDialog::pathToStringW(irr::core::stringw& result, const irr::io::path& p)
|
||||
void CGUIFileOpenDialog::pathToStringW(irr::core::stringw &result, const irr::io::path &p)
|
||||
{
|
||||
core::multibyteToWString(result, p);
|
||||
}
|
||||
@ -368,17 +332,14 @@ void CGUIFileOpenDialog::fillListBox()
|
||||
FileList = FileSystem->createFileList();
|
||||
core::stringw s;
|
||||
|
||||
if (FileList)
|
||||
{
|
||||
for (u32 i=0; i < FileList->getFileCount(); ++i)
|
||||
{
|
||||
if (FileList) {
|
||||
for (u32 i = 0; i < FileList->getFileCount(); ++i) {
|
||||
pathToStringW(s, FileList->getFileName(i));
|
||||
FileBox->addItem(s.c_str(), skin->getIcon(FileList->isDirectory(i) ? EGDI_DIRECTORY : EGDI_FILE));
|
||||
}
|
||||
}
|
||||
|
||||
if (FileNameText)
|
||||
{
|
||||
if (FileNameText) {
|
||||
setDirectoryName(FileSystem->getWorkingDirectory());
|
||||
pathToStringW(s, FileDirectory);
|
||||
FileNameText->setText(s.c_str());
|
||||
@ -386,7 +347,7 @@ void CGUIFileOpenDialog::fillListBox()
|
||||
}
|
||||
|
||||
//! sends the event that the file has been selected.
|
||||
void CGUIFileOpenDialog::sendSelectedEvent( EGUI_EVENT_TYPE type)
|
||||
void CGUIFileOpenDialog::sendSelectedEvent(EGUI_EVENT_TYPE type)
|
||||
{
|
||||
SEvent event;
|
||||
event.EventType = EET_GUI_EVENT;
|
||||
@ -396,7 +357,6 @@ void CGUIFileOpenDialog::sendSelectedEvent( EGUI_EVENT_TYPE type)
|
||||
Parent->OnEvent(event);
|
||||
}
|
||||
|
||||
|
||||
//! sends the event that the file choose process has been cancelled
|
||||
void CGUIFileOpenDialog::sendCancelEvent()
|
||||
{
|
||||
|
Reference in New Issue
Block a user