Skip to content

Commit

Permalink
FIXED rendering of shapes with non-zero offset
Browse files Browse the repository at this point in the history
FIXED setting path & filename when loading existing models
  • Loading branch information
ksterker committed Sep 1, 2009
1 parent 052c58f commit a236da2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
46 changes: 40 additions & 6 deletions src/modeller/gui_modeller.cc
Expand Up @@ -644,19 +644,43 @@ static void on_file_save_as_activate (GtkMenuItem * menuitem, gpointer user_data
{
GuiModeller *modeller = (GuiModeller *) user_data;
GtkWindow *parent = GTK_WINDOW(modeller->getWindow());

std::string saveDir;
std::string filename = modeller->filename ();

std::string spriteDir = modeller->spriteDirectory ();
size_t index = spriteDir.find ("/gfx/");
if (index != std::string::npos)
/*
// filename might end in .png if we loaded a 'default' sprite
* Actually, for now the filename will always be 'untitled.xml' if
* we are working on a new model or end in '.xml' if we loaded an
* existing model.
if (filename.find (".png", filename.size() - 4) != std::string::npos)
{
spriteDir.replace (index, 4, "/models");
filename = filename.replace (filename.size() - 3, 3, "xml");
}

*/

// generate save directory from sprite directory for new models
if (filename.find ("untitled") != filename.npos)
{
saveDir = modeller->spriteDirectory ();
size_t index = saveDir.find ("/gfx/");
if (index != std::string::npos)
{
saveDir.replace (index, 4, "/models");
}
}
// otherwise save to directory the model came from
else
{
saveDir = modeller->modelDirectory ();
}

// try to create directory, if it doesn't exist
// TODO: make a program setting for that instead of doing it by default
// g_mkdir_with_parents (spriteDir.c_str(), 0755);

GuiFile fs (parent, GTK_FILE_CHOOSER_ACTION_SAVE, "Save Model", spriteDir + "/" + modeller->filename ());
GuiFile fs (parent, GTK_FILE_CHOOSER_ACTION_SAVE, "Save Model", saveDir + "/" + modeller->filename ());
fs.add_filter ("*.xml", "Adonthell Model");

// File selection closed with OK
Expand Down Expand Up @@ -919,6 +943,16 @@ void GuiModeller::loadModel (const std::string & name)
return;
}

// remember path to model for convenience
gchar* model_path = g_path_get_dirname (name.c_str());
ModelDir = model_path;
g_free (model_path);

// remember model file for convenience
gchar* model_file = g_path_get_basename (name.c_str());
Filename = model_file;
g_free (model_file);

base::flat entity = placeable.get_flat ("entity");

char *id;
Expand Down
6 changes: 3 additions & 3 deletions src/modeller/mdl_renderer.cc
Expand Up @@ -75,15 +75,15 @@ void ModelRenderer::draw (GdkPoint *handles, const s_int16 & x, const s_int16 &
// render shapes, if any
for (std::vector<world::cube3*>::const_iterator i = ri.Shape->begin(); i != ri.Shape->end(); i++)
{
s_int16 ox = sx + (*i)->min_x();
s_int16 oy = sy + (*i)->min_y() + (*i)->max_z();
s_int16 ox = sx;
s_int16 oy = sy + (*i)->max_z() - (*i)->min_z();

(*i)->draw (ox, oy, &da, target);

if (ActiveShape == *i)
{
ox += (*i)->min_x();
oy += (*i)->min_y() - (*i)->min_z(); // ???
oy += (*i)->min_y() - (*i)->min_z();

updateHandles (handles, ox, oy);
}
Expand Down

0 comments on commit a236da2

Please sign in to comment.