Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Fix file dialogs changing working directory on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Mar 8, 2015
1 parent 87da28d commit 5311ab9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/MediaManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Media
};

Media() { std::cerr << "Media Manager created!" << std::endl; }
Media(const Media &old) { std::cerr << "Media Manager copied! (This shouldn't happen)" << std::endl; }
~Media();
bool import(std::string filepath, std::string filename, IVideoDriver* driver);
bool add(std::string filepath, std::string filename, IImage *image, bool overwrite = false);
Expand Down
45 changes: 22 additions & 23 deletions src/NodeBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void NodeBox::moveNodeBox(EditorState* editor, CDRType type, vector3df position)
two = new_two;
}

ITexture* darken(IVideoDriver* driver, IImage* image, float amt)
ITexture* darken(IVideoDriver* driver, IImage* image, float amt, const char *name)
{
if(image == NULL)
return NULL;
Expand All @@ -171,22 +171,21 @@ ITexture* darken(IVideoDriver* driver, IImage* image, float amt)
}
}

ITexture *retval = driver->addTexture("media/texture_box.png", image2);
ITexture *retval = driver->addTexture(name, image2);
image2->drop();
return retval;
}

void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevice* device, Media::Image* images[6])
{
video::IVideoDriver* driver = device->getVideoDriver();
Media::Image *def = new Media::Image("default", driver->createImageFromFile("media/texture_box.png"));
static Media::Image *def = new Media::Image("default", driver->createImageFromFile("media/texture_box.png"));

Media::Image *copied[6];
for (int i = 0; i < 6; i++) {
copied[i] = images[i];
if (!copied[i]) {
if (!copied[i])
copied[i] = def;
def->grab();
}
}
ISceneManager* smgr = device->getSceneManager();
if (model) {
Expand Down Expand Up @@ -250,11 +249,11 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer->BoundingBox.reset(0,0,0);
ITexture *texture = NULL;
if (lighting == "2")
texture = darken(driver, copied[ECS_FRONT]->get(), 0.5);
texture = darken(driver, copied[ECS_FRONT]->get(), 0.5, copied[ECS_RIGHT]->name.c_str());
else if (lighting == "1")
texture = darken(driver, copied[ECS_FRONT]->get(), 0.5);
texture = darken(driver, copied[ECS_FRONT]->get(), 0.5, copied[ECS_RIGHT]->name.c_str());
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_FRONT]->get());
texture = driver->addTexture(copied[ECS_FRONT]->name.c_str(), copied[ECS_FRONT]->get());
SMaterial mat = SMaterial();
mat.setTexture(0, texture);
buffer->Material = mat;
Expand All @@ -273,11 +272,11 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer2->BoundingBox.reset(0,0,0);
texture = NULL;
if (lighting == "2")
texture = darken(driver, copied[ECS_BACK]->get(), 0.5);
texture = darken(driver, copied[ECS_BACK]->get(), 0.5, copied[ECS_BACK]->name.c_str());
else if (lighting == "1")
texture = darken(driver, copied[ECS_BACK]->get(), 0.5);
texture = darken(driver, copied[ECS_BACK]->get(), 0.5, copied[ECS_BACK]->name.c_str());
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_BACK]->get());
texture = driver->addTexture(copied[ECS_BACK]->name.c_str(), copied[ECS_BACK]->get());
mat = SMaterial();
mat.setTexture(0, texture);
buffer2->Material = mat;
Expand All @@ -296,11 +295,11 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer3->BoundingBox.reset(0,0,0);
texture = NULL;
if (lighting == "2")
texture = darken(driver, copied[ECS_LEFT]->get(), 0.7);
texture = darken(driver, copied[ECS_LEFT]->get(), 0.7, copied[ECS_LEFT]->name.c_str());
else if (lighting == "1")
texture = darken(driver, copied[ECS_LEFT]->get(), 0.7);
texture = darken(driver, copied[ECS_LEFT]->get(), 0.7, copied[ECS_LEFT]->name.c_str());
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_LEFT]->get());
texture = driver->addTexture(copied[ECS_LEFT]->name.c_str(), copied[ECS_LEFT]->get());
mat = SMaterial();
mat.setTexture(0, texture);
buffer3->Material = mat;
Expand All @@ -319,11 +318,11 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer4->BoundingBox.reset(0,0,0);
texture = NULL;
if (lighting == "2")
texture = darken(driver, copied[ECS_RIGHT]->get(), 0.7);
texture = darken(driver, copied[ECS_RIGHT]->get(), 0.7, copied[ECS_RIGHT]->name.c_str());
else if (lighting == "1")
texture = darken(driver, copied[ECS_RIGHT]->get(), 0.7);
texture = darken(driver, copied[ECS_RIGHT]->get(), 0.7, copied[ECS_RIGHT]->name.c_str());
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_RIGHT]->get());
texture = driver->addTexture(copied[ECS_RIGHT]->name.c_str(), copied[ECS_RIGHT]->get());
mat = SMaterial();
mat.setTexture(0, texture);
buffer4->Material = mat;
Expand All @@ -342,9 +341,9 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer5->BoundingBox.reset(0,0,0);
texture = NULL;
if (lighting == "1")
texture = darken(driver, copied[ECS_TOP]->get(), 0.7);
texture = darken(driver, copied[ECS_TOP]->get(), 0.7, copied[ECS_TOP]->name.c_str());
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_TOP]->get());
texture = driver->addTexture(copied[ECS_TOP]->name.c_str(), copied[ECS_TOP]->get());
mat = SMaterial();
mat.setTexture(0, texture);
buffer5->Material = mat;
Expand All @@ -362,11 +361,11 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer6->Vertices[3] = video::S3DVertex(x0,x0,x0, -1,-1,-1, cubeColour, topl.X, topl.Y);
buffer6->BoundingBox.reset(0,0,0);
if (lighting == "2")
texture = darken(driver, copied[ECS_BOTTOM]->get(), 0.4);
texture = darken(driver, copied[ECS_BOTTOM]->get(), 0.4, copied[ECS_BOTTOM]->name.c_str());
else if (lighting == "1")
texture = darken(driver, copied[ECS_BOTTOM]->get(), 0.4);
texture = darken(driver, copied[ECS_BOTTOM]->get(), 0.4, copied[ECS_BOTTOM]->name.c_str());
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_BOTTOM]->get());
texture = driver->addTexture(copied[ECS_BOTTOM]->name.c_str(), copied[ECS_BOTTOM]->get());
mat = SMaterial();
mat.setTexture(0, texture);
buffer6->Material = mat;
Expand Down
7 changes: 3 additions & 4 deletions src/dialogs/ImageDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,14 @@ bool ImageDialog::OnEvent(const SEvent &event)
return true;
} else if (!state->project->media.add(path.c_str(), shortname, image, cb->isChecked())) {
state->device->getGUIEnvironment()->addMessageBox(L"Unable to import",
L"Failed to add the image\n\t(Has an image with the same name already been added?)");
L"Failed to add the image\n\t(Unknown reason)");
return true;
}
state->project->remesh();
if (node) {
if (node)
TextureDialog::show(state, node, face);
} else {
else
close();
}
return true;
} else {
state->device->getGUIEnvironment()->addMessageBox(L"Unable to import",
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int main(int argc, char *argv[]) {
}

#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8
std::cerr << "Warning! Your irrlicht version is outdated, so some NBE features will not be available." << std::endl;
std::cerr << "Warning! Your Irrlicht version is outdated, so some NBE features will not be available." << std::endl;
#endif

// Editor
Expand Down
3 changes: 3 additions & 0 deletions src/util/tinyfiledialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ char const * tinyfd_saveFileDialog (
ofn.lCustData = 0L ;
ofn.lpfnHook = NULL ;
ofn.lpTemplateName = NULL ;
ofn.Flags |= OFN_NOCHANGEDIR;

if ( GetSaveFileName ( & ofn ) == 0 )
{
Expand Down Expand Up @@ -358,6 +359,8 @@ char const * tinyfd_openFileDialog (
ofn.Flags |= OFN_ALLOWMULTISELECT;
}

ofn.Flags |= OFN_NOCHANGEDIR;

if ( GetOpenFileName ( & ofn ) == 0 )
{
return NULL ;
Expand Down

0 comments on commit 5311ab9

Please sign in to comment.