summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/globals.cpp1
-rw-r--r--common/globals.h3
-rw-r--r--common/lc_application.cpp407
-rw-r--r--common/lc_application.h51
-rwxr-xr-xcommon/library.cpp3
-rw-r--r--common/minifig.cpp13
-rwxr-xr-xcommon/object.cpp3
-rw-r--r--common/piece.cpp25
-rw-r--r--common/pieceinf.cpp5
-rw-r--r--common/preview.cpp7
-rw-r--r--common/project.cpp358
-rw-r--r--common/project.h10
-rw-r--r--common/str.h2
-rw-r--r--common/texfont.cpp3
-rw-r--r--common/texture.cpp3
-rw-r--r--common/typedefs.h2
-rw-r--r--win/Cadview.cpp46
-rw-r--r--win/EdGrpDlg.cpp3
-rw-r--r--win/Leocad.cpp54
-rw-r--r--win/Libdlg.cpp30
-rw-r--r--win/Mainfrm.cpp30
-rw-r--r--win/Moddlg.cpp23
-rw-r--r--win/Piecebar.cpp13
-rw-r--r--win/Piececmb.cpp9
-rw-r--r--win/Print.cpp10
-rw-r--r--win/Steppop.cpp5
-rw-r--r--win/System.cpp53
-rw-r--r--win/Tools.cpp3
-rw-r--r--win/texdlg.cpp13
29 files changed, 735 insertions, 453 deletions
diff --git a/common/globals.cpp b/common/globals.cpp
index f0e885c..8a186ef 100644
--- a/common/globals.cpp
+++ b/common/globals.cpp
@@ -5,7 +5,6 @@
#include <stdlib.h>
#include "globals.h"
-Project* project;
Messenger* messenger;
MainWnd* main_window;
diff --git a/common/globals.h b/common/globals.h
index 312251c..6f6daa1 100644
--- a/common/globals.h
+++ b/common/globals.h
@@ -5,9 +5,6 @@
#include "typedefs.h"
#include "console.h"
-class Project;
-extern Project* project;
-
class Messenger;
extern Messenger* messenger;
diff --git a/common/lc_application.cpp b/common/lc_application.cpp
new file mode 100644
index 0000000..13ef637
--- /dev/null
+++ b/common/lc_application.cpp
@@ -0,0 +1,407 @@
+#include <stdio.h>
+#include "lc_application.h"
+#include "library.h"
+#include "system.h"
+#include "console.h"
+#include "config.h"
+#include "opengl.h"
+#include "project.h"
+#include "image.h"
+
+// ----------------------------------------------------------------------------
+// Global functions.
+
+lcApplication* g_App;
+
+PiecesLibrary* lcGetPiecesLibrary()
+{
+ LC_ASSERT(g_App, "g_App not initialized.");
+ return g_App->GetPiecesLibrary();
+}
+
+Project* lcGetActiveProject()
+{
+ LC_ASSERT(g_App, "g_App not initialized.");
+ return g_App->GetActiveProject();
+}
+
+// ----------------------------------------------------------------------------
+// lcApplication class.
+
+lcApplication::lcApplication()
+{
+ m_ActiveProject = NULL;
+ m_Library = NULL;
+}
+
+lcApplication::~lcApplication()
+{
+}
+
+void lcApplication::AddProject(Project* project)
+{
+ m_Projects.Add(project);
+
+ if (m_ActiveProject == NULL)
+ m_ActiveProject = project;
+}
+
+bool lcApplication::LoadPiecesLibrary(const char* LibPath, const char* SysLibPath)
+{
+ // Create an empty library.
+ if (m_Library == NULL)
+ m_Library = new PiecesLibrary();
+ else
+ m_Library->Unload();
+
+ // Check if the user specified a library path in the command line.
+ if (LibPath != NULL)
+ if (m_Library->Load(LibPath))
+ return true;
+
+ // Check for the LEOCAD_LIB environment variable.
+ char* EnvPath = getenv("LEOCAD_LIB");
+
+ if (EnvPath != NULL)
+ if (m_Library->Load(EnvPath))
+ return true;
+
+ // Try the executable install path last.
+ if (SysLibPath != NULL)
+ if (m_Library->Load(SysLibPath))
+ return true;
+
+#ifdef LC_WINDOWS
+ SystemDoMessageBox("Cannot load pieces library.\n"
+ "Make sure that you have the PIECES.IDX file in the same "
+ "folder where you installed the program.", LC_MB_OK|LC_MB_ICONERROR);
+#else
+ printf("Error: Cannot load pieces library.\n");
+#endif
+
+ return false;
+}
+
+void lcApplication::ParseIntegerArgument(int* CurArg, int argc, char* argv[], int* Value)
+{
+ if (argc > (*CurArg + 1))
+ {
+ (*CurArg)++;
+ int val;
+
+ if ((sscanf(argv[(*CurArg)], "%d", &val) == 1) && (val > 0))
+ *Value = val;
+ else
+ console.PrintWarning("Invalid value specified for the %s argument.", argv[(*CurArg) - 1]);
+ }
+ else
+ {
+ console.PrintWarning("Not enough parameters for the %s argument.", argv[(*CurArg) - 1]);
+ }
+}
+
+void lcApplication::ParseStringArgument(int* CurArg, int argc, char* argv[], char** Value)
+{
+ if (argc > (*CurArg + 1))
+ {
+ (*CurArg)++;
+ *Value = argv[(*CurArg)];
+ }
+ else
+ {
+ console.PrintWarning("No path specified after the %s argument.", argv[(*CurArg) - 1]);
+ }
+}
+
+bool lcApplication::Initialize(int argc, char* argv[], const char* SysLibPath)
+{
+ // System setup parameters.
+ char* LibPath = NULL;
+ char* GLPath = NULL;
+
+ // Image output options.
+ bool SaveImage = false;
+ bool ImageAnimation = false;
+ bool ImageInstructions = false;
+ bool ImageHighlight = false;
+ int ImageWidth = Sys_ProfileLoadInt("Default", "Image Width", 640);
+ int ImageHeight = Sys_ProfileLoadInt("Default", "Image Height", 480);
+ int ImageStart = 0;
+ int ImageEnd = 0;
+ char* ImageName = NULL;
+
+ // File to open.
+ char* ProjectName = NULL;
+
+ // Parse the command line arguments.
+ for (int i = 1; i < argc; i++)
+ {
+ char* Param = argv[i];
+
+ if (Param[0] == '-')
+ {
+ if (strcmp(Param, "--libgl") == 0)
+ {
+ ParseStringArgument(&i, argc, argv, &GLPath);
+ }
+ else if ((strcmp(Param, "-l") == 0) || (strcmp(Param, "--libpath") == 0))
+ {
+ ParseStringArgument(&i, argc, argv, &LibPath);
+ }
+ else if ((strcmp(Param, "-i") == 0) || (strcmp(Param, "--image") == 0))
+ {
+ SaveImage = true;
+
+ if ((argc > (i+1)) && (argv[i+1][0] != '-'))
+ {
+ i++;
+ ImageName = argv[i];
+ }
+ }
+ else if ((strcmp(Param, "-w") == 0) || (strcmp(Param, "--width") == 0))
+ {
+ ParseIntegerArgument(&i, argc, argv, &ImageWidth);
+ }
+ else if ((strcmp(Param, "-h") == 0) || (strcmp(Param, "--height") == 0))
+ {
+ ParseIntegerArgument(&i, argc, argv, &ImageHeight);
+ }
+ else if ((strcmp(Param, "-f") == 0) || (strcmp(Param, "--from") == 0))
+ {
+ ParseIntegerArgument(&i, argc, argv, &ImageStart);
+ }
+ else if ((strcmp(Param, "-t") == 0) || (strcmp(Param, "--to") == 0))
+ {
+ ParseIntegerArgument(&i, argc, argv, &ImageEnd);
+ }
+ else if (strcmp(Param, "--animation") == 0)
+ ImageAnimation = true;
+ else if (strcmp(Param, "--instructions") == 0)
+ ImageInstructions = true;
+ else if (strcmp(Param, "--highlight") == 0)
+ ImageHighlight = true;
+ else if ((strcmp(Param, "-v") == 0) || (strcmp(Param, "--version") == 0))
+ {
+ printf("LeoCAD version " LC_VERSION_TEXT LC_VERSION_TAG " for "LC_VERSION_OSNAME"\n");
+ printf("Copyright (c) 1996-2006, BT Software\n");
+ printf("Compiled "__DATE__"\n");
+
+#ifdef LC_HAVE_JPEGLIB
+ printf("With JPEG support\n");
+#else
+ printf("Without JPEG support\n");
+#endif
+
+#ifdef LC_HAVE_PNGLIB
+ printf("With PNG support\n");
+#else
+ printf("Without PNG support\n");
+#endif
+
+ return false;
+ }
+ else if ((strcmp(Param, "-?") == 0) || (strcmp(Param, "--help") == 0))
+ {
+ printf("Usage: leocad [options] [file]\n");
+ printf(" [options] can be:\n");
+ printf(" --libgl <path>: Searches for OpenGL libraries in path.\n");
+ printf(" --libpath <path>: Loads the Pieces library from path.\n");
+ printf(" -i, --image <outfile.ext>: Saves a picture in the format specified by ext.\n");
+ printf(" -w, --width <width>: Sets the picture width.\n");
+ printf(" -h, --height <height>: Sets the picture height.\n");
+ printf(" -f, --from <time>: Sets the first frame or step to save pictures.\n");
+ printf(" -t, --to <time>: Sets the last frame or step to save pictures.\n");
+ printf(" --animation: Saves animations frames.\n");
+ printf(" --instructions: Saves instructions steps.\n");
+ printf(" --highlight: Highlight pieces in the steps they appear.\n");
+ printf(" \n");
+ }
+ else
+ console.PrintWarning("Unknown parameter: %s\n", Param);
+ }
+ else
+ {
+ ProjectName = Param;
+ }
+ }
+
+ // Initialize other systems.
+ if (!GL_Initialize(GLPath))
+ return false;
+
+ if (!LoadPiecesLibrary(LibPath, SysLibPath))
+ return false;
+
+ SystemInit();
+
+ // Create a new project.
+ Project* project = new Project();
+ AddProject(project);
+
+ // Load project.
+ if (ProjectName && project->OpenProject(ProjectName))
+ {
+ if (!SaveImage)
+ return true;
+
+ // Check if there's a file name and it has an extension.
+ bool NeedExt = true;
+ String FileName;
+
+ if (!ImageName)
+ {
+ FileName = ProjectName;
+
+ int i = FileName.ReverseFind('.');
+ if (i != -1)
+ FileName[i] = 0;
+ }
+ else
+ {
+ FileName = ImageName;
+
+ int i = FileName.ReverseFind('.');
+ String Ext;
+
+ if (i != -1)
+ {
+ Ext = FileName.Right(FileName.GetLength() - i);
+ Ext.MakeLower();
+ }
+
+ if ((Ext == "bmp") || (Ext == "gif"))
+ NeedExt = false;
+#ifdef LC_HAVE_JPEGLIB
+ else if ((Ext == "jpg") || (Ext == "jpeg"))
+ NeedExt = false;
+#endif
+#ifdef LC_HAVE_PNGLIB
+ else if (Ext == "png")
+ NeedExt = false;
+#endif
+ }
+
+ // Setup default options.
+ LC_IMAGE_OPTS ImageOptions;
+ unsigned long image = Sys_ProfileLoadInt ("Default", "Image Options", 1|LC_IMAGE_TRANSPARENT);
+ ImageOptions.quality = Sys_ProfileLoadInt ("Default", "JPEG Quality", 70);
+ ImageOptions.interlaced = (image & LC_IMAGE_PROGRESSIVE) != 0;
+ ImageOptions.transparent = (image & LC_IMAGE_TRANSPARENT) != 0;
+ ImageOptions.truecolor = (image & LC_IMAGE_HIGHCOLOR) != 0;
+ ImageOptions.format = image & ~(LC_IMAGE_MASK);
+ ImageOptions.background[0] = (unsigned char)(project->GetBackgroundColor()[0]*255);
+ ImageOptions.background[1] = (unsigned char)(project->GetBackgroundColor()[1]*255);
+ ImageOptions.background[2] = (unsigned char)(project->GetBackgroundColor()[2]*255);
+
+ // Append file extension if needed.
+ if (NeedExt)
+ {
+ switch (ImageOptions.format)
+ {
+ default:
+ case LC_IMAGE_BMP:
+ FileName += ".bmp";
+ break;
+ case LC_IMAGE_GIF:
+ FileName += ".gif";
+ break;
+ case LC_IMAGE_JPG:
+ FileName += ".jpg";
+ break;
+ case LC_IMAGE_PNG:
+ FileName += ".png";
+ break;
+ }
+ }
+
+ if (ImageInstructions)
+ project->SetAnimation(false);
+ else if (ImageAnimation)
+ project->SetAnimation(true);
+
+ if (ImageEnd < ImageStart)
+ ImageEnd = ImageStart;
+ else if (ImageStart > ImageEnd)
+ ImageStart = ImageEnd;
+
+ if ((ImageStart == 0) && (ImageEnd == 0))
+ {
+ ImageStart = ImageEnd = project->GetCurrentTime();
+ }
+ else if ((ImageStart == 0) && (ImageEnd != 0))
+ {
+ ImageStart = ImageEnd;
+ }
+ else if ((ImageStart != 0) && (ImageEnd == 0))
+ {
+ ImageEnd = ImageStart;
+ }
+
+ if (project->IsAnimation())
+ {
+ if (ImageStart > project->GetTotalFrames())
+ ImageStart = project->GetTotalFrames();
+
+ if (ImageEnd > project->GetTotalFrames())
+ ImageEnd = project->GetTotalFrames();
+ }
+ else
+ {
+ if (ImageStart > 255)
+ ImageStart = 255;
+
+ if (ImageEnd > 255)
+ ImageEnd = 255;
+ }
+
+ Image* images = new Image[ImageEnd - ImageStart + 1];
+ project->CreateImages(images, ImageWidth, ImageHeight, ImageStart, ImageEnd, ImageHighlight);
+
+ for (i = 0; i <= ImageEnd - ImageStart; i++)
+ {
+ char idx[256];
+ String Frame;
+
+ if (ImageStart != ImageEnd)
+ {
+ sprintf(idx, "%02d", i+1);
+ int Ext = FileName.ReverseFind('.');
+
+ Frame = FileName.Left(Ext) + idx + FileName.Right(FileName.GetLength() - Ext);
+ }
+ else
+ Frame = FileName;
+
+ images[i].FileSave(Frame, &ImageOptions);
+ }
+
+ delete []images;
+
+ return false;
+ }
+ else
+ {
+ if (SaveImage)
+ return false;
+ else
+ project->OnNewDocument();
+ }
+
+ return true;
+}
+
+void lcApplication::Shutdown()
+{
+ for (int i = 0; i < m_Projects.GetSize(); i++)
+ {
+ Project* project = m_Projects[i];
+
+ project->HandleNotify(LC_ACTIVATE, 0);
+ delete project;
+ }
+
+ delete m_Library;
+ m_Library = NULL;
+
+ GL_Shutdown();
+}
diff --git a/common/lc_application.h b/common/lc_application.h
new file mode 100644
index 0000000..0336f10
--- /dev/null
+++ b/common/lc_application.h
@@ -0,0 +1,51 @@
+#ifndef _LC_APPLICATION_H_
+#define _LC_APPLICATION_H_
+
+#include "array.h"
+
+class Project;
+class PiecesLibrary;
+
+class lcApplication
+{
+public:
+ lcApplication();
+ ~lcApplication();
+
+ bool Initialize(int argc, char *argv[], const char* SysLibPath);
+ void Shutdown();
+
+ // Pieces library.
+ bool LoadPiecesLibrary(const char* LibPath, const char* SysLibPath);
+ PiecesLibrary* GetPiecesLibrary() const
+ {
+ return m_Library;
+ }
+
+ // Projects.
+ void AddProject(Project* project);
+
+ Project* GetActiveProject() const
+ {
+ return m_ActiveProject;
+ }
+
+ void SetActiveProject(Project* project)
+ {
+ m_ActiveProject = project;
+ }
+
+protected:
+ void ParseIntegerArgument(int* CurArg, int argc, char* argv[], int* Value);
+ void ParseStringArgument(int* CurArg, int argc, char* argv[], char** Value);
+
+ Project* m_ActiveProject;
+ PtrArray<Project> m_Projects;
+ PiecesLibrary* m_Library;
+};
+
+extern lcApplication* g_App;
+PiecesLibrary* lcGetPiecesLibrary();
+Project* lcGetActiveProject();
+
+#endif // _LC_APPLICATION_H_
diff --git a/common/library.cpp b/common/library.cpp
index c1e495c..04939dd 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -11,6 +11,7 @@
#include "image.h"
#include "system.h"
#include "console.h"
+#include "lc_application.h"
// =============================================================================
// PiecesLibrary class
@@ -2266,7 +2267,7 @@ bool SaveLDrawPiece(LC_LDRAW_PIECE* piece)
unsigned long i, j, cs, binoff = 0, delta;
void* membuf;
short scale, sb[6];
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
+ PiecesLibrary *pLib = lcGetPiecesLibrary();
strcpy(file1, pLib->GetLibraryPath());
strcat(file1, "pieces-b.old");
diff --git a/common/minifig.cpp b/common/minifig.cpp
index a8e7d33..9098e49 100644
--- a/common/minifig.cpp
+++ b/common/minifig.cpp
@@ -13,6 +13,7 @@
#include "system.h"
#include "matrix.h"
#include "library.h"
+#include "lc_application.h"
// =============================================================================
// Static variables
@@ -442,7 +443,7 @@ MinifigWizard::MinifigWizard (GLWindow *share)
m_Colors[i] = colors[i];
m_Angles[i] = 0;
- m_Info[i] = project->GetPiecesLibrary ()->FindPieceInfo (pieces[i]);
+ m_Info[i] = lcGetPiecesLibrary()->FindPieceInfo(pieces[i]);
if (m_Info[i] != NULL)
m_Info[i]->AddRef();
}
@@ -451,7 +452,7 @@ MinifigWizard::MinifigWizard (GLWindow *share)
m_MinifigNames = NULL;
m_MinifigTemplates = NULL;
- i = Sys_ProfileLoadInt ("MinifigWizard", "Version", 1);
+ i = Sys_ProfileLoadInt("MinifigWizard", "Version", 1);
if (i == 1)
{
char *ptr, buf[32];
@@ -552,7 +553,7 @@ void MinifigWizard::OnDraw ()
glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_LEQUAL);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- float *bg = project->GetBackgroundColor();
+ float *bg = lcGetActiveProject()->GetBackgroundColor();
glClearColor (bg[0], bg[1], bg[2], bg[3]);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable (GL_DITHER);
@@ -888,7 +889,7 @@ void MinifigWizard::GetDescriptions (int type, char ***names, int *count)
{
PieceInfo* piece_info;
- piece_info = project->GetPiecesLibrary ()->FindPieceInfo (mfw_pieceinfo[i].name);
+ piece_info = lcGetPiecesLibrary()->FindPieceInfo(mfw_pieceinfo[i].name);
if (piece_info == NULL)
continue;
@@ -971,7 +972,7 @@ void MinifigWizard::ChangePiece (int type, const char *desc)
{
if (strcmp(desc, mfw_pieceinfo[j].description) == 0)
{
- piece_info = project->GetPiecesLibrary()->FindPieceInfo(mfw_pieceinfo[j].name);
+ piece_info = lcGetPiecesLibrary()->FindPieceInfo(mfw_pieceinfo[j].name);
if (piece_info == NULL)
continue;
@@ -1083,7 +1084,7 @@ bool MinifigWizard::LoadMinifig (const char* name)
endptr = strchr (ptr, ' ');
*endptr = '\0';
- m_Info[j] = project->GetPiecesLibrary ()->FindPieceInfo (ptr);
+ m_Info[j] = lcGetPiecesLibrary()->FindPieceInfo (ptr);
*endptr = ' ';
ptr = endptr;
diff --git a/common/object.cpp b/common/object.cpp
index cdcb107..489ad12 100755
--- a/common/object.cpp
+++ b/common/object.cpp
@@ -10,6 +10,7 @@
#include "matrix.h"
#include "vector.h"
#include "file.h"
+#include "lc_application.h"
#define LC_KEY_SAVE_VERSION 1 // LeoCAD 0.73
@@ -347,7 +348,7 @@ void Object::InsertTime (unsigned short start, bool animation, unsigned short ti
if (animation)
{
node = m_pAnimationKeys;
- last = project->GetTotalFrames ();
+ last = lcGetActiveProject()->GetTotalFrames ();
}
else
{
diff --git a/common/piece.cpp b/common/piece.cpp
index 2a11bd5..684bcd5 100644
--- a/common/piece.cpp
+++ b/common/piece.cpp
@@ -13,6 +13,7 @@
#include "group.h"
#include "project.h"
#include "algebra.h"
+#include "lc_application.h"
#define LC_PIECE_SAVE_VERSION 9 // LeoCAD 0.73
@@ -420,23 +421,23 @@ void Piece::InsertTime (unsigned short start, bool animation, unsigned short tim
if (animation)
{
if (m_nFrameShow >= start)
- m_nFrameShow = min (m_nFrameShow + time, project->GetTotalFrames ());
+ m_nFrameShow = min(m_nFrameShow + time, lcGetActiveProject()->GetTotalFrames());
if (m_nFrameHide >= start)
- m_nFrameHide = min (m_nFrameHide + time, project->GetTotalFrames ());
+ m_nFrameHide = min(m_nFrameHide + time, lcGetActiveProject()->GetTotalFrames());
- if (m_nFrameShow > project->GetCurrentTime ())
+ if (m_nFrameShow > lcGetActiveProject()->GetCurrentTime())
Select (false, false, false);
}
else
{
if (m_nStepShow >= start)
- m_nStepShow = min (m_nStepShow + time, 255);
+ m_nStepShow = min(m_nStepShow + time, 255);
if (m_nStepHide >= start)
- m_nStepHide = min (m_nStepHide + time, 255);
+ m_nStepHide = min(m_nStepHide + time, 255);
- if (m_nStepShow > project->GetCurrentTime ())
+ if (m_nStepShow > lcGetActiveProject()->GetCurrentTime ())
Select (false, false, false);
}
@@ -448,14 +449,14 @@ void Piece::RemoveTime (unsigned short start, bool animation, unsigned short tim
if (animation)
{
if (m_nFrameShow >= start)
- m_nFrameShow = max (m_nFrameShow - time, 1);
+ m_nFrameShow = max(m_nFrameShow - time, 1);
- if (m_nFrameHide == project->GetTotalFrames ())
- m_nFrameHide = project->GetTotalFrames ();
+ if (m_nFrameHide == lcGetActiveProject()->GetTotalFrames())
+ m_nFrameHide = lcGetActiveProject()->GetTotalFrames();
else
- m_nFrameHide = max (m_nFrameHide - time, 1);
+ m_nFrameHide = max(m_nFrameHide - time, 1);
- if (m_nFrameHide < project->GetCurrentTime ())
+ if (m_nFrameHide < lcGetActiveProject()->GetCurrentTime())
Select (false, false, false);
}
else
@@ -466,7 +467,7 @@ void Piece::RemoveTime (unsigned short start, bool animation, unsigned short tim
if (m_nStepHide != 255)
m_nStepHide = max (m_nStepHide - time, 1);
- if (m_nStepHide < project->GetCurrentTime ())
+ if (m_nStepHide < lcGetActiveProject()->GetCurrentTime())
Select (false, false, false);
}
diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp
index ffb1a76..9a9d30a 100644
--- a/common/pieceinf.cpp
+++ b/common/pieceinf.cpp
@@ -15,6 +15,7 @@
#include "defines.h"
#include "config.h"
#include "library.h"
+#include "lc_application.h"
#define SIDES 16
static float sintbl[SIDES];
@@ -320,7 +321,7 @@ void PieceInfo::LoadInformation()
glEndList ();
// Open pieces.bin and buffer the information we need.
- strcpy (filename, project->GetPiecesLibrary ()->GetLibraryPath());
+ strcpy (filename, lcGetPiecesLibrary()->GetLibraryPath());
strcat (filename, "pieces.bin");
if (!bin.Open (filename, "rb"))
return;
@@ -381,7 +382,7 @@ void PieceInfo::LoadInformation()
bytes++;
strcpy(name, (char*)bytes);
- tex->texture = project->GetPiecesLibrary()->FindTexture(name);
+ tex->texture = lcGetPiecesLibrary()->FindTexture(name);
shorts = (lcint16*)(bytes + 8);
for (i = 0; i < 4; i++)
diff --git a/common/preview.cpp b/common/preview.cpp
index d792849..82d16f6 100644
--- a/common/preview.cpp
+++ b/common/preview.cpp
@@ -7,6 +7,7 @@
#include "project.h"
#include "pieceinf.h"
#include "system.h"
+#include "lc_application.h"
PiecePreview::PiecePreview(GLWindow *share)
: GLWindow(share)
@@ -76,11 +77,11 @@ void PiecePreview::OnDraw()
glLoadMatrixf(WorldToView);
}
- float pos[4] = { 0, 0, 10, 0 }, *bg = project->GetBackgroundColor ();
+ float pos[4] = { 0, 0, 10, 0 }, *bg = lcGetActiveProject()->GetBackgroundColor ();
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glClearColor(bg[0], bg[1], bg[2], bg[3]);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- m_PieceInfo->RenderPiece(project->GetCurrentColor ());
+ m_PieceInfo->RenderPiece(lcGetActiveProject()->GetCurrentColor());
glFinish();
SwapBuffers();
@@ -98,7 +99,7 @@ void PiecePreview::SetCurrentPiece(PieceInfo *pInfo)
if (m_PieceInfo != NULL)
{
m_PieceInfo->AddRef();
- project->SetCurrentPiece(m_PieceInfo);
+ lcGetActiveProject()->SetCurrentPiece(m_PieceInfo);
Redraw();
}
}
diff --git a/common/project.cpp b/common/project.cpp
index 23c487e..1ddf706 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -31,6 +31,7 @@
#include "texfont.h"
#include "algebra.h"
#include "debug.h"
+#include "lc_application.h"
// FIXME: temporary function, replace the code !!!
void SystemUpdateFocus (void* p)
@@ -119,7 +120,6 @@ Project::Project()
for (i = 0; i < 10; i++)
m_pClipboard[i] = NULL;
- m_pLibrary = new PiecesLibrary ();
m_pScreenFont = new TexFont();
}
@@ -143,291 +143,53 @@ Project::~Project()
delete m_pTerrain;
delete m_pBackground;
delete m_pScreenFont;
- delete m_pLibrary;
}
/////////////////////////////////////////////////////////////////////////////
// Project attributes, general services
-// The main window should be created before calling this
-bool Project::Initialize(int argc, char *argv[], char* binpath, char* libpath)
+void Project::UpdateInterface()
{
- char *env_path;
- bool loaded = false;
-
- // check if there's an environment variable for the piece library
- env_path = getenv ("LEOCAD_LIB");
- if (env_path != NULL)
- libpath = env_path;
-
- m_strPathName[0] = 0;
-
- LC_IMAGE_OPTS imopts;
- char picture[LC_MAXPATH];
- bool save_image = false;
- picture[0] = 0;
-
- unsigned long image = Sys_ProfileLoadInt ("Default", "Image Options", 1|LC_IMAGE_TRANSPARENT);
- int width = Sys_ProfileLoadInt ("Default", "Image Width", 640);
- int height = Sys_ProfileLoadInt ("Default", "Image Height", 480);
-// int width = Sys_ProfileLoadInt ("Default", "Image Width", GetSystemMetrics(SM_CXSCREEN));
-// int height = Sys_ProfileLoadInt ("Default", "Image Height", GetSystemMetrics(SM_CYSCREEN));
- unsigned short from = 0, to = 0;
- int i, animation = -1;
- bool highlight = false;
- imopts.quality = Sys_ProfileLoadInt ("Default", "JPEG Quality", 70);
- imopts.interlaced = (image & LC_IMAGE_PROGRESSIVE) != 0;
- imopts.transparent = (image & LC_IMAGE_TRANSPARENT) != 0;
- imopts.truecolor = (image & LC_IMAGE_HIGHCOLOR) != 0;
- imopts.format = (unsigned char)(image & ~(LC_IMAGE_MASK));
-
- for (i = 1; i < argc; i++)
- {
- char* param = argv[i];
-
- if (param[0] == '-')
- {
- if (((strcmp (param, "-l") == 0) || (strcmp (param, "--libpath") == 0)) && ((i+1) < argc))
- {
- i++;
- libpath = argv[i];
- }
- else if ((strcmp (param, "-i") == 0) || (strcmp (param, "--image") == 0))
- {
- save_image = true;
-
- if (((i+1) != argc) && (argv[i+1][0] != '-'))
- {
- i++;
- strcpy (picture, argv[i]);
- }
- }
- else if (((strcmp (param, "-w") == 0) || (strcmp (param, "--width") == 0)) && ((i+1) < argc))
- {
- int w;
- i++;
- if (sscanf(argv[i], "%d", &w) == 1)
- width = w;
- }
- else if (((strcmp (param, "-h") == 0) || (strcmp (param, "--height") == 0)) && ((i+1) < argc))
- {
- int h;
- i++;
- if (sscanf(argv[i], "%d", &h) == 1)
- height = h;
- }
- else if (((strcmp (param, "-f") == 0) || (strcmp (param, "--from") == 0)) && ((i+1) < argc))
- {
- int f;
- i++;
- if (sscanf(argv[i], "%d", &f) == 1)
- from = f;
- }
- else if (((strcmp (param, "-t") == 0) || (strcmp (param, "--to") == 0)) && ((i+1) < argc))
- {
- int t;
- i++;
- if (sscanf(argv[i], "%d", &t) == 1)
- to = t;
- }
- else if (strcmp (param, "--animation") == 0)
- animation = 1;
- else if (strcmp (param, "--instructions") == 0)
- animation = 0;
- else if (strcmp (param, "--highlight") == 0)
- highlight = true;
- else if ((strcmp (param, "-v") == 0) || (strcmp (param, "--version") == 0))
- {
- printf ("LeoCAD version " LC_VERSION_TEXT LC_VERSION_TAG " for "LC_VERSION_OSNAME"\n");
- printf ("Copyright (c) 1996-2003, BT Software\n");
- printf ("Compiled "__DATE__"\n");
-
-#ifdef LC_HAVE_JPEGLIB
- printf ("With JPEG support\n");
-#else
- printf ("Without JPEG support\n");
-#endif
-
-#ifdef LC_HAVE_PNGLIB
- printf ("With PNG support\n");
-#else
- printf ("Without PNG support\n");
-#endif
-
- return false;
- }
- else if ((strcmp (param, "-h") == 0) || (strcmp (param, "--help") == 0))
- {
- }
- else
- printf ("Unknown parameter: %s\n", param);
- }
- else
- {
- strcpy (m_strPathName, param);
-/*
- if (m_strFileName.IsEmpty())
- m_strFileName = pszParam;
- else if (m_nShellCommand == FilePrintTo && m_strPrinterName.IsEmpty())
- m_strPrinterName = pszParam;
- else if (m_nShellCommand == FilePrintTo && m_strDriverName.IsEmpty())
- m_strDriverName = pszParam;
- else if (m_nShellCommand == FilePrintTo && m_strPortName.IsEmpty())
- m_strPortName = pszParam;
-*/
- }
- }
-
- // if the user specified a library, try to load it first
- if (libpath != NULL)
- loaded = m_pLibrary->Load (libpath);
-
- // if we couldn't find a library, try the executable path
- if (!loaded)
- loaded = m_pLibrary->Load (binpath);
-
- if (!loaded)
- {
-#ifdef LC_WINDOWS
- // let's hope this message helps the users
- SystemDoMessageBox("Cannot load piece library.\n"
- "Make sure that you have the PIECES.IDX file in the same "
- "folder where you installed the program.", LC_MB_OK|LC_MB_ICONERROR);
-#else
- printf("Cannot load piece library !\n");
-#endif
- return false;
- }
-
- SystemInit();
-
- if (strlen(m_strPathName) && OnOpenDocument(m_strPathName))
- {
- SetPathName(m_strPathName, true);
-
- if (save_image == true)
- {
- bool need_ext = false;
-
- if (picture[0] == 0)
- {
- strcpy (picture, m_strPathName);
- char *p = strrchr (picture, '.');
- if (p != NULL)
- *p = 0;
- need_ext = true;
- }
- else
- {
- char ext[5];
- char *p = strrchr(picture, '.');
- if (p != NULL)
- strcpy(ext, p+1);
- strlwr(ext);
-
- if ((strcmp(ext, "bmp") != 0) && (strcmp(ext, "gif") != 0) &&
- (strcmp(ext, "jpg") != 0) && (strcmp(ext, "jpeg") != 0) &&
- (strcmp(ext, "png") != 0))
- need_ext = true;
- }
-
- if (need_ext)
- switch (imopts.format)
- {
- case LC_IMAGE_BMP: strcat(picture, ".bmp"); break;
- case LC_IMAGE_GIF: strcat(picture, ".gif"); break;
- case LC_IMAGE_JPG: strcat(picture, ".jpg"); break;
- case LC_IMAGE_PNG: strcat(picture, ".png"); break;
- }
-
- imopts.background[0] = (unsigned char)(m_fBackground[0]*255);
- imopts.background[1] = (unsigned char)(m_fBackground[1]*255);
- imopts.background[2] = (unsigned char)(m_fBackground[2]*255);
-
- if (animation == 0)
- m_bAnimation = false;
- else if (animation == 1)
- m_bAnimation = true;
-
- if (to < from)
- {
- unsigned short tmp;
- tmp = from;
- from = to;
- to = tmp;
- }
-
- if ((from == 0) && (to == 0))
- {
+ // Update all user interface elements.
+ SystemUpdateUndoRedo(m_pUndoList->pNext ? m_pUndoList->strText : NULL, m_pRedoList ? m_pRedoList->strText : NULL);
+ SystemUpdatePaste(m_pClipboard[m_nCurClipboard] != NULL);
+ SystemUpdatePlay(true, false);
+ SystemUpdateCategories(false);
+ SetTitle(m_strTitle);
+
+ SystemUpdateFocus(NULL);
+ SetAction(m_nCurAction);
+ SystemUpdateViewport(m_nViewportMode, 0);
+ SystemUpdateColorList(m_nCurColor);
+ SystemUpdateAnimation(m_bAnimation, m_bAddKeys);
+ SystemUpdateRenderingMode((m_nDetail & LC_DET_BACKGROUND) != 0, (m_nDetail & LC_DET_FAST) != 0);
+ SystemUpdateSnap(m_nSnap);
+ SystemUpdateSnap(m_nMoveSnap, m_nAngleSnap);
+ SystemUpdateCameraMenu(m_pCameras);
+ SystemUpdateCurrentCamera(NULL, m_pViewCameras[m_nActiveViewport], m_pCameras);
+ UpdateSelection();
if (m_bAnimation)
- from = to = m_nCurFrame;
+ SystemUpdateTime(m_bAnimation, m_nCurFrame, m_nTotalFrames);
else
- from = to = m_nCurStep;
- }
- else if ((from == 0) && (to != 0))
- {
- from = to;
- }
- else if ((from != 0) && (to == 0))
- {
- to = from;
- }
-
- if (m_bAnimation)
- {
- if (from > m_nTotalFrames)
- from = m_nTotalFrames;
-
- if (to > m_nTotalFrames)
- to = m_nTotalFrames;
- }
- else
- {
- if (from > 255)
- from = 255;
-
- if (to > 255)
- to = 255;
- }
-
- Image* images = new Image[to - from + 1];
- CreateImages (images, width, height, from, to, highlight);
-
- for (i = 0; i <= to - from; i++)
- {
- char filename[LC_MAXPATH];
-
- if (from != to)
- {
- char* ext = strrchr (picture, '.');
- *ext = 0;
- sprintf (filename, "%s%02d.%s", picture, i+1, ext+1);
- *ext = '.';
- }
- else
- strcpy (filename, picture);
-
- images[i].FileSave (filename, &imopts);
- }
- delete []images;
+ SystemUpdateTime(m_bAnimation, m_nCurStep, 255);
- return false;
- }
- }
- else
- OnNewDocument();
+ for (int i = 0; i < m_ViewList.GetSize(); i++)
+ {
+ m_ViewList[i]->MakeCurrent();
+ RenderInitialize();
+ }
- return true;
+ UpdateSelection();
}
void Project::SetTitle(const char* lpszTitle)
{
- strcpy(m_strTitle, lpszTitle);
+ if (lpszTitle != m_strTitle)
+ strcpy(m_strTitle, lpszTitle);
char title[LC_MAXPATH], *ptr, ext[4];
- strcpy(title, "LeoCAD - ");
- strcat(title, m_strTitle);
+ strcpy(title, m_strTitle);
ptr = strrchr(title, '.');
if (ptr != NULL)
@@ -444,6 +206,8 @@ void Project::SetTitle(const char* lpszTitle)
*ptr = 0;
}
+ strcat(title, " - LeoCAD");
+
SystemSetWindowCaption(title);
}
@@ -733,7 +497,7 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
char name[9];
Piece* pPiece = new Piece(NULL);
pPiece->FileLoad(*file, name);
- PieceInfo* pInfo = m_pLibrary->FindPieceInfo(name);
+ PieceInfo* pInfo = lcGetPiecesLibrary()->FindPieceInfo(name);
if (pInfo)
{
pPiece->SetPieceInfo(pInfo);
@@ -772,7 +536,7 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
const unsigned char conv[20] = { 0,2,4,9,7,6,22,8,10,11,14,16,18,9,21,20,22,8,10,11 };
color = conv[color];
- PieceInfo* pInfo = m_pLibrary->FindPieceInfo(name);
+ PieceInfo* pInfo = lcGetPiecesLibrary()->FindPieceInfo(name);
if (pInfo != NULL)
{
Piece* pPiece = new Piece(pInfo);
@@ -1318,7 +1082,7 @@ void Project::FileReadLDraw(File* file, Matrix* prevmat, int* nOk, int DefColor,
char name[9];
strcpy(name, tmp);
- PieceInfo* pInfo = m_pLibrary->FindPieceInfo(name);
+ PieceInfo* pInfo = lcGetPiecesLibrary()->FindPieceInfo(name);
if (pInfo != NULL)
{
float x, y, z, rot[4];
@@ -1744,7 +1508,7 @@ void Project::SetPathName(const char* lpszPathName, bool bAddToMRU)
// add it to the file MRU list
if (bAddToMRU)
- main_window->AddToMRU (lpszPathName);
+ main_window->AddToMRU (lpszPathName);
}
/////////////////////////////////////////////////////////////////////////////
@@ -1823,7 +1587,7 @@ void Project::Render(bool bToMemory)
#ifdef _DEBUG
#ifdef LC_WINDOWS
-#define BENCHMARK
+//#define BENCHMARK
#endif
#endif
@@ -3182,7 +2946,7 @@ void Project::RenderInitialize()
char filename[LC_MAXPATH];
FileDisk file;
- strcpy (filename, m_pLibrary->GetLibraryPath ());
+ strcpy (filename, lcGetPiecesLibrary()->GetLibraryPath ());
strcat (filename, "sysfont.txf");
if (file.Open (filename, "rb"))
@@ -3621,12 +3385,12 @@ void Project::CreateHTMLPieceList(FILE* f, int nStep, bool bImages, char* ext)
fputs("</tr>\n",f);
PieceInfo* pInfo;
- for (int j = 0; j < m_pLibrary->GetPieceCount (); j++)
+ for (int j = 0; j < lcGetPiecesLibrary()->GetPieceCount (); j++)
{
bool Add = false;
int count[LC_MAXCOLORS];
memset (&count, 0, sizeof (count));
- pInfo = m_pLibrary->GetPieceInfo (j);
+ pInfo = lcGetPiecesLibrary()->GetPieceInfo (j);
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
{
@@ -4226,10 +3990,10 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
PieceInfo* pInfo;
Piece* pPiece;
FILE* f;
- char *conv = (char*)malloc (9*m_pLibrary->GetPieceCount ());
- char *flags = (char*)malloc (m_pLibrary->GetPieceCount ());
- memset (conv, 0, 9*m_pLibrary->GetPieceCount());
- memset (flags, 0, m_pLibrary->GetPieceCount());
+ char *conv = (char*)malloc (9*lcGetPiecesLibrary()->GetPieceCount ());
+ char *flags = (char*)malloc (lcGetPiecesLibrary()->GetPieceCount ());
+ memset (conv, 0, 9*lcGetPiecesLibrary()->GetPieceCount());
+ memset (flags, 0, lcGetPiecesLibrary()->GetPieceCount());
// read LGEO conversion table
if (strlen (opts.libpath))
@@ -4252,7 +4016,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
u = (((unsigned char)(bt[3])|((unsigned short)(bt[2]) << 8))|
(((unsigned long)(bt[1])) << 16)) + bt[0] * 16581375;
sprintf(tmp, "%d", (int)u);
- pInfo = m_pLibrary->FindPieceInfo(tmp);
+ pInfo = lcGetPiecesLibrary()->FindPieceInfo(tmp);
fread(&tmp, 9, 1, f);
if (tmp[8] != 0)
@@ -4260,7 +4024,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if (pInfo != NULL)
{
- int idx = m_pLibrary->GetPieceIndex (pInfo);
+ int idx = lcGetPiecesLibrary()->GetPieceIndex (pInfo);
memcpy (&conv[idx*9], &tmp[1], 9);
flags[idx] = tmp[0];
}
@@ -4285,12 +4049,12 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if ((tmp[u] == 0) && (u != 0))
{
u = 0;
- pInfo = m_pLibrary->FindPieceInfo(tmp);
+ pInfo = lcGetPiecesLibrary()->FindPieceInfo(tmp);
fread(&tmp, 8, 1, f);
if (pInfo != NULL)
{
- int idx = m_pLibrary->GetPieceIndex (pInfo);
+ int idx = lcGetPiecesLibrary()->GetPieceIndex (pInfo);
memcpy(&conv[idx*9], tmp, 9);
}
}
@@ -4322,7 +4086,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if (pNext == pPiece)
{
- int idx = m_pLibrary->GetPieceIndex (pInfo);
+ int idx = lcGetPiecesLibrary()->GetPieceIndex (pInfo);
char pat[] = "patterns/";
if (conv[idx*9+1] != 'p')
strcpy(pat, "");
@@ -4365,7 +4129,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
{
pInfo = pPiece->GetPieceInfo();
- int idx = m_pLibrary->GetPieceIndex (pInfo);
+ int idx = lcGetPiecesLibrary()->GetPieceIndex (pInfo);
if (conv[idx*9] != 0)
continue;
@@ -4520,7 +4284,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
{
float fl[12], pos[3], rot[4];
char name[20];
- int idx = m_pLibrary->GetPieceIndex (pPiece->GetPieceInfo ());
+ int idx = lcGetPiecesLibrary()->GetPieceIndex (pPiece->GetPieceInfo ());
if (conv[idx*9] == 0)
{
@@ -4671,16 +4435,16 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
strcpy(opts.strComments, m_strComments);
opts.strFilename = m_strPathName;
- opts.lines = m_pLibrary->GetPieceCount();
- opts.count = (unsigned short*)malloc(m_pLibrary->GetPieceCount()*LC_MAXCOLORS*sizeof(unsigned short));
- memset (opts.count, 0, m_pLibrary->GetPieceCount()*LC_MAXCOLORS*sizeof(unsigned short));
- opts.names = (char**)malloc(m_pLibrary->GetPieceCount()*sizeof(char*));
- for (int i = 0; i < m_pLibrary->GetPieceCount(); i++)
- opts.names[i] = m_pLibrary->GetPieceInfo (i)->m_strDescription;
+ opts.lines = lcGetPiecesLibrary()->GetPieceCount();
+ opts.count = (unsigned short*)malloc(lcGetPiecesLibrary()->GetPieceCount()*LC_MAXCOLORS*sizeof(unsigned short));
+ memset (opts.count, 0, lcGetPiecesLibrary()->GetPieceCount()*LC_MAXCOLORS*sizeof(unsigned short));
+ opts.names = (char**)malloc(lcGetPiecesLibrary()->GetPieceCount()*sizeof(char*));
+ for (int i = 0; i < lcGetPiecesLibrary()->GetPieceCount(); i++)
+ opts.names[i] = lcGetPiecesLibrary()->GetPieceInfo (i)->m_strDescription;
for (Piece* pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
{
- int idx = m_pLibrary->GetPieceIndex (pPiece->GetPieceInfo ());
+ int idx = lcGetPiecesLibrary()->GetPieceIndex (pPiece->GetPieceInfo ());
opts.count[idx*LC_MAXCOLORS+pPiece->GetColor()]++;
}
@@ -4721,7 +4485,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if (SystemDoDialog(LC_DLG_LIBRARY, NULL))
{
- if (m_pLibrary->m_Modified)
+ if (lcGetPiecesLibrary()->m_Modified)
{
DeleteContents(true);
FileLoad(&file, true, false);
@@ -4878,7 +4642,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
char name[9];
Piece* pPiece = new Piece(NULL);
pPiece->FileLoad(*file, name);
- PieceInfo* pInfo = m_pLibrary->FindPieceInfo(name);
+ PieceInfo* pInfo = lcGetPiecesLibrary()->FindPieceInfo(name);
if (pInfo)
{
pPiece->SetPieceInfo(pInfo);
diff --git a/common/project.h b/common/project.h
index ade05d0..1330303 100644
--- a/common/project.h
+++ b/common/project.h
@@ -57,7 +57,6 @@ public:
// Constructors
Project();
~Project();
- bool Initialize(int argc, char *argv[], char* binpath, char* libpath);
// Attributes
public:
@@ -70,6 +69,8 @@ public:
unsigned char GetLastStep();
bool IsAnimation()
{ return m_bAnimation; }
+ void SetAnimation(bool Anim)
+ { m_bAnimation = Anim; } // only to be called from lcApplication::Initialize()
unsigned short GetCurrentTime ()
{ return m_bAnimation ? m_nCurFrame : m_nCurStep; }
unsigned long GetSnapFlags() const
@@ -102,9 +103,7 @@ public:
*ppLight = m_pLights;
}
- PiecesLibrary* GetPiecesLibrary () const
- { return m_pLibrary; }
-
+ void UpdateInterface();
void SetPathName (const char* lpszPathName, bool bAddToMRU);
void SetTitle (const char* lpszTitle);
@@ -113,6 +112,7 @@ public:
void DeleteContents(bool bUndo); // delete doc items etc
void LoadDefaults(bool cameras);
+ void CreateImages(Image* images, int width, int height, unsigned short from, unsigned short to, bool hilite);
void Render(bool bToMemory);
void SetViewSize(int cx, int cy);
void CheckAutoSave();
@@ -139,7 +139,6 @@ protected:
// Piece library
TexFont* m_pScreenFont;
- PiecesLibrary* m_pLibrary;
// Undo support
LC_UNDOINFO* m_pUndoList;
@@ -194,7 +193,6 @@ protected:
void RenderOverlays(int Viewport);
void RenderBoxes(bool bHilite);
void RenderInitialize();
- void CreateImages(Image* images, int width, int height, unsigned short from, unsigned short to, bool hilite);
void CreateHTMLPieceList(FILE* f, int nStep, bool bImages, char* ext);
inline bool IsDrawing()
diff --git a/common/str.h b/common/str.h
index 658a16e..78192bc 100644
--- a/common/str.h
+++ b/common/str.h
@@ -22,7 +22,7 @@ public:
char GetAt(int index) const
{ return m_pData[index]; }
- char operator[](int index) const
+ char& operator[](int index) const
{ return m_pData[index]; }
void SetAt(int index, char ch)
{ m_pData[index] = ch; }
diff --git a/common/texfont.cpp b/common/texfont.cpp
index b3b7213..a5c3b5d 100644
--- a/common/texfont.cpp
+++ b/common/texfont.cpp
@@ -8,6 +8,7 @@
#include "texture.h"
#include "library.h"
#include "file.h"
+#include "lc_application.h"
#define LC_TEXFONT_FILE_VERSION 1 // LeoCAD 0.74
#define LC_TEXFONT_FILE_HEADER "LeoCAD Texture Font\0\0\0\0\0\0\0\0\0\0\0\0"
@@ -56,7 +57,7 @@ bool TexFont::FileLoad (File& file)
memset (buf, 0, 32);
file.Read (buf, 8);
- m_pTexture = project->GetPiecesLibrary()->FindTexture (buf);
+ m_pTexture = lcGetPiecesLibrary()->FindTexture (buf);
if (m_pTexture == NULL)
{
console.PrintError ("Cannot find texture for font %s.\n", buf);
diff --git a/common/texture.cpp b/common/texture.cpp
index 4957a0e..8c92e67 100644
--- a/common/texture.cpp
+++ b/common/texture.cpp
@@ -10,6 +10,7 @@
#include "globals.h"
#include "image.h"
#include "library.h"
+#include "lc_application.h"
// =============================================================================
// Static functions
@@ -131,7 +132,7 @@ void Texture::Load(bool bFilter)
FileDisk bin;
void* bits;
- strcpy(filename, project->GetPiecesLibrary ()->GetLibraryPath());
+ strcpy(filename, lcGetPiecesLibrary()->GetLibraryPath());
strcat(filename, "textures.bin");
if (!bin.Open(filename, "rb"))
return;
diff --git a/common/typedefs.h b/common/typedefs.h
index 9346fe8..a12882c 100644
--- a/common/typedefs.h
+++ b/common/typedefs.h
@@ -267,7 +267,7 @@ typedef struct
bool truecolor;
unsigned char background[3];
float pause;
- unsigned char format;
+ unsigned int format;
} LC_IMAGE_OPTS;
typedef struct
diff --git a/win/Cadview.cpp b/win/Cadview.cpp
index 9e26db1..f38c80b 100644
--- a/win/Cadview.cpp
+++ b/win/Cadview.cpp
@@ -16,6 +16,7 @@
#include "view.h"
#include "MainFrm.h"
#include "PiecePrv.h"
+#include "lc_application.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -160,8 +161,8 @@ BOOL CCADView::OnPreparePrinting(CPrintInfo* pInfo)
int cols = theApp.GetProfileInt("Default", "Print Columns", 1);
int rows = theApp.GetProfileInt("Default", "Print Rows", 1);
- int Max = (project->GetLastStep()/(rows*cols));
- if (project->GetLastStep()%(rows*cols) != 0)
+ int Max = (lcGetActiveProject()->GetLastStep()/(rows*cols));
+ if (lcGetActiveProject()->GetLastStep()%(rows*cols) != 0)
Max++;
pInfo->SetMaxPage(Max);
@@ -190,8 +191,8 @@ void CCADView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* pInfo)
{
int cols = theApp.GetProfileInt("Default", "Print Columns", 1);
int rows = theApp.GetProfileInt("Default", "Print Rows", 1);
- int Max = (project->GetLastStep()/(rows*cols));
- if (project->GetLastStep()%(rows*cols) != 0)
+ int Max = (lcGetActiveProject()->GetLastStep()/(rows*cols));
+ if (lcGetActiveProject()->GetLastStep()%(rows*cols) != 0)
Max++;
pInfo->SetMaxPage(Max);
}
@@ -200,6 +201,8 @@ void CCADView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
int cols = theApp.GetProfileInt("Default","Print Columns", 1);
int rows = theApp.GetProfileInt("Default","Print Rows", 1);
+ Project* project = lcGetActiveProject();
+
if (rows < 1) rows = 1;
if (cols < 1) cols = 1;
CRect rc(0, 0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
@@ -426,6 +429,7 @@ void CCADView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
void CCADView::PrintHeader(BOOL bFooter, HDC hDC, CRect rc, UINT nCurPage, UINT nMaxPage, BOOL bCatalog)
{
+ Project* project = lcGetActiveProject();
CString str,tmp;
UINT nFormat = DT_CENTER;
int r;
@@ -734,25 +738,25 @@ CCADDoc* CCADView::GetDocument() // non-debug version is inline
int CCADView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
- if (CView::OnCreate(lpCreateStruct) == -1)
+ if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
- m_pView = new View (project, NULL);
- m_pView->Create (m_hWnd);
- m_pView->OnInitialUpdate ();
+ m_pView = new View (lcGetActiveProject(), NULL);
+ m_pView->Create (m_hWnd);
+ m_pView->OnInitialUpdate ();
- SetTimer (IDT_LC_SAVETIMER, 5000, NULL);
+ SetTimer (IDT_LC_SAVETIMER, 5000, NULL);
- return 0;
+ return 0;
}
void CCADView::OnDestroy()
{
- delete m_pView;
- m_pView = NULL;
+ delete m_pView;
+ m_pView = NULL;
+
+ KillTimer (IDT_LC_SAVETIMER);
- KillTimer (IDT_LC_SAVETIMER);
-
CView::OnDestroy();
}
@@ -845,9 +849,9 @@ BOOL CCADView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
BOOL CCADView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
if (zDelta > 0)
- project->HandleCommand(LC_VIEW_ZOOMOUT, 0);
+ lcGetActiveProject()->HandleCommand(LC_VIEW_ZOOMOUT, 0);
else
- project->HandleCommand(LC_VIEW_ZOOMIN, 0);
+ lcGetActiveProject()->HandleCommand(LC_VIEW_ZOOMIN, 0);
return CView::OnMouseWheel(nFlags, zDelta, pt);
}
@@ -873,7 +877,7 @@ LONG CCADView::OnAutoPan(UINT lParam, LONG wParam)
pt2.y = -pt2.y;
unsigned long pt = ((short)pt2.x) | ((unsigned long)(((short)pt2.y) << 16));
- project->HandleCommand(LC_VIEW_AUTOPAN, pt);
+ lcGetActiveProject()->HandleCommand(LC_VIEW_AUTOPAN, pt);
return TRUE;
}
@@ -881,7 +885,7 @@ LONG CCADView::OnAutoPan(UINT lParam, LONG wParam)
void CCADView::OnTimer(UINT nIDEvent)
{
if (nIDEvent == IDT_LC_SAVETIMER)
- project->CheckAutoSave();
+ lcGetActiveProject()->CheckAutoSave();
CView::OnTimer(nIDEvent);
}
@@ -890,7 +894,7 @@ void CCADView::OnTimer(UINT nIDEvent)
LONG CCADView::OnSetStep(UINT lParam, LONG /*wParam*/)
{
if (lParam > 0)
- project->HandleCommand(LC_VIEW_STEP_SET, lParam);
+ lcGetActiveProject()->HandleCommand(LC_VIEW_STEP_SET, lParam);
return TRUE;
}
@@ -898,7 +902,7 @@ LONG CCADView::OnSetStep(UINT lParam, LONG /*wParam*/)
void CCADView::OnCaptureChanged(CWnd *pWnd)
{
if (pWnd != this)
- project->HandleNotify(LC_CAPTURE_LOST, 0);
+ lcGetActiveProject()->HandleNotify(LC_CAPTURE_LOST, 0);
CView::OnCaptureChanged(pWnd);
}
@@ -951,7 +955,7 @@ void CCADView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
} break;
}
- project->OnKeyDown(nKey, GetKeyState (VK_CONTROL) < 0, GetKeyState (VK_SHIFT) < 0);
+ lcGetActiveProject()->OnKeyDown(nKey, GetKeyState (VK_CONTROL) < 0, GetKeyState (VK_SHIFT) < 0);
/*
switch (nChar)
{
diff --git a/win/EdGrpDlg.cpp b/win/EdGrpDlg.cpp
index 48c894d..8ab3b8f 100644
--- a/win/EdGrpDlg.cpp
+++ b/win/EdGrpDlg.cpp
@@ -6,6 +6,7 @@
#include "EdGrpDlg.h"
#include "globals.h"
#include "project.h"
+#include "lc_application.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -90,7 +91,7 @@ void CEditGroupsDlg::OnEditgrpNewgroup()
pParent = m_Tree.opts->groups[item.lParam - 0xFFFF];
}
- pGroup = project->AddGroup (NULL, pParent, 0, 0, 0);
+ pGroup = lcGetActiveProject()->AddGroup (NULL, pParent, 0, 0, 0);
m_Tree.opts->groupcount++;
m_Tree.opts->groups = (Group**)realloc(m_Tree.opts->groups, m_Tree.opts->groupcount*sizeof(Group*));
diff --git a/win/Leocad.cpp b/win/Leocad.cpp
index fb409bd..9f921b5 100644
--- a/win/Leocad.cpp
+++ b/win/Leocad.cpp
@@ -17,6 +17,7 @@
#include "mainwnd.h"
#include "library.h"
#include "keyboard.h"
+#include "lc_application.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -88,7 +89,7 @@ static void CheckForUpdates(void* Data)
else
str = "You are using the latest version of LeoCAD.\n";
- if (lib > project->GetPiecesLibrary ()->GetPieceCount ())
+ if (lib > lcGetPiecesLibrary()->GetPieceCount ())
{
str += "There are new pieces available.\n\n";
Update = true;
@@ -175,8 +176,17 @@ BOOL CCADApp::InitInstance()
InitKeyboardShortcuts();
- if (!GL_Initialize (NULL))
- return FALSE;
+ char app[LC_MAXPATH], *ptr;
+ GetModuleFileName (NULL, app, LC_MAXPATH);
+ ptr = strrchr(app,'\\');
+ if (ptr)
+ *(++ptr) = 0;
+
+ g_App = new lcApplication();
+ main_window = new MainWnd();
+
+ if (!g_App->Initialize(__argc, __targv, app))
+ return false;
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
@@ -191,29 +201,18 @@ BOOL CCADApp::InitInstance()
EnableShellOpen();
RegisterShellFileTypes(TRUE);
- main_window = new MainWnd ();
- project = new Project;
-
UINT cmdshow = m_nCmdShow;
m_nCmdShow = SW_HIDE;
pDocTemplate->OpenDocumentFile(NULL);
- char app[LC_MAXPATH], *ptr;
- GetModuleFileName (NULL, app, LC_MAXPATH);
- ptr = strrchr(app,'\\');
- if (ptr)
- *(++ptr) = 0;
-
- if (!project->Initialize(__argc, __targv, app, NULL))
- return false;
-
// Show something in the piece preview window.
- PieceInfo* Info = project->GetPiecesLibrary()->FindPieceInfo("3005");
+ PieceInfo* Info = lcGetPiecesLibrary()->FindPieceInfo("3005");
if (!Info)
- Info = project->GetPiecesLibrary()->GetPieceInfo(0);
+ Info = lcGetPiecesLibrary()->GetPieceInfo(0);
+
if (Info)
{
- project->SetCurrentPiece(Info);
+ lcGetActiveProject()->SetCurrentPiece(Info);
((CMainFrame*)(AfxGetMainWnd()))->m_wndPiecesBar.m_wndPiecePreview.SetPieceInfo(Info);
((CMainFrame*)(AfxGetMainWnd()))->m_wndPiecesBar.m_wndPiecePreview.PostMessage(WM_PAINT);
}
@@ -260,14 +259,15 @@ BOOL CCADApp::InitInstance()
else
m_pMainWnd->ShowWindow(cmdshow);
m_pMainWnd->UpdateWindow();
- project->HandleNotify(LC_ACTIVATE, 1);
+ lcGetActiveProject()->HandleNotify(LC_ACTIVATE, 1);
+ lcGetActiveProject()->UpdateInterface();
main_window->UpdateMRU ();
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
- project->UpdateAllViews (NULL);
+ lcGetActiveProject()->UpdateAllViews (NULL);
if (AfxGetApp()->GetProfileInt("Settings", "CheckUpdates", 1))
_beginthread(CheckForUpdates, 0, NULL);
@@ -280,17 +280,13 @@ int CCADApp::ExitInstance()
if (m_hMutex != NULL)
ReleaseMutex(m_hMutex);
- if (project)
- {
- project->HandleNotify(LC_ACTIVATE, 0);
- delete project;
- project = NULL;
- }
+ delete main_window;
+ main_window = NULL;
- delete main_window;
- main_window = NULL;
+ g_App->Shutdown();
- GL_Shutdown ();
+ delete g_App;
+ g_App = NULL;
#ifdef _DEBUG
if (__hStdOut != NULL)
diff --git a/win/Libdlg.cpp b/win/Libdlg.cpp
index 8b59319..7fb05b3 100644
--- a/win/Libdlg.cpp
+++ b/win/Libdlg.cpp
@@ -14,6 +14,7 @@
#include "globals.h"
#include "system.h"
#include "library.h"
+#include "lc_application.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -142,20 +143,20 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
case ID_LIBDLG_FILE_OPEN:
{
- project->GetPiecesLibrary()->LoadCategories(NULL);
+ lcGetPiecesLibrary()->LoadCategories(NULL);
UpdateTree();
return TRUE;
}
case ID_LIBDLG_FILE_SAVE:
{
- project->GetPiecesLibrary()->DoSaveCategories(false);
+ lcGetPiecesLibrary()->DoSaveCategories(false);
return TRUE;
}
case ID_LIBDLG_FILE_SAVEAS:
{
- project->GetPiecesLibrary()->DoSaveCategories(true);
+ lcGetPiecesLibrary()->DoSaveCategories(true);
return TRUE;
}
@@ -178,7 +179,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (SystemDoDialog(LC_DLG_FILE_OPEN, &opts))
{
- project->GetPiecesLibrary()->LoadUpdate((char*)opts.filenames);
+ lcGetPiecesLibrary()->LoadUpdate((char*)opts.filenames);
free(opts.filenames);
@@ -199,7 +200,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
for (int i = 0; i < opts.numfiles; i++)
{
- project->GetPiecesLibrary ()->ImportLDrawPiece (opts.filenames[i]);
+ lcGetPiecesLibrary ()->ImportLDrawPiece (opts.filenames[i]);
free (opts.filenames[i]);
}
@@ -222,7 +223,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
if (SystemDoMessageBox("Are you sure you want to reset the categories?", LC_MB_YESNO | LC_MB_ICONQUESTION) == LC_YES)
{
- project->GetPiecesLibrary()->ResetCategories();
+ lcGetPiecesLibrary()->ResetCategories();
UpdateList();
UpdateTree();
@@ -239,8 +240,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts))
{
- PiecesLibrary* Lib = project->GetPiecesLibrary();
- Lib->AddCategory(Opts.Name, Opts.Keywords);
+ lcGetPiecesLibrary()->AddCategory(Opts.Name, Opts.Keywords);
}
UpdateTree();
@@ -255,7 +255,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (Item == NULL)
break;
- PiecesLibrary* Lib = project->GetPiecesLibrary();
+ PiecesLibrary* Lib = lcGetPiecesLibrary();
CString CategoryName = m_Tree.GetItemText(Item);
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
@@ -283,7 +283,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (Item == NULL)
break;
- PiecesLibrary* Lib = project->GetPiecesLibrary();
+ PiecesLibrary* Lib = lcGetPiecesLibrary();
CString CategoryName = m_Tree.GetItemText(Item);
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
@@ -331,7 +331,7 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam)
if (SystemDoMessageBox ("Are you sure you want to permanently delete the selected pieces?", LC_MB_YESNO|LC_MB_ICONQUESTION) != LC_YES)
return TRUE;
- project->GetPiecesLibrary()->DeletePieces(Pieces);
+ lcGetPiecesLibrary()->DeletePieces(Pieces);
UpdateList();
@@ -347,7 +347,7 @@ void CLibraryDlg::UpdateList()
m_List.DeleteAllItems();
m_List.SetRedraw(FALSE);
- PiecesLibrary *Lib = project->GetPiecesLibrary();
+ PiecesLibrary *Lib = lcGetPiecesLibrary();
HTREEITEM CategoryItem = m_Tree.GetSelectedItem();
CString CategoryName = m_Tree.GetItemText(CategoryItem);
@@ -433,7 +433,7 @@ void CLibraryDlg::UpdateTree()
HTREEITEM Root = m_Tree.InsertItem(TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_TEXT, "Pieces", 0, 1, 0, 0, 0, TVI_ROOT, TVI_SORT);
- PiecesLibrary *Lib = project->GetPiecesLibrary();
+ PiecesLibrary *Lib = lcGetPiecesLibrary();
for (int i = 0; i < Lib->GetNumCategories(); i++)
m_Tree.InsertItem(TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM|TVIF_TEXT, Lib->GetCategoryName(i), 0, 1, 0, 0, 0, Root, TVI_SORT);
@@ -454,7 +454,7 @@ void CLibraryDlg::OnSelChangedTree(NMHDR* pNMHDR, LRESULT* pResult)
void CLibraryDlg::OnCancel()
{
// Check if it's ok to close the dialog
- if (!project->GetPiecesLibrary()->SaveCategories())
+ if (!lcGetPiecesLibrary()->SaveCategories())
return;
CDialog::OnCancel();
@@ -463,7 +463,7 @@ void CLibraryDlg::OnCancel()
void CLibraryDlg::OnOK()
{
// Check if it's ok to close the dialog
- if (!project->GetPiecesLibrary()->SaveCategories())
+ if (!lcGetPiecesLibrary()->SaveCategories())
return;
CDialog::OnOK();
diff --git a/win/Mainfrm.cpp b/win/Mainfrm.cpp
index ca4d5e4..0761390 100644
--- a/win/Mainfrm.cpp
+++ b/win/Mainfrm.cpp
@@ -16,7 +16,7 @@
#include "keyboard.h"
#include "system.h"
#include "library.h"
-
+#include "lc_application.h"
#include "Print.h"
#ifdef _DEBUG
@@ -418,7 +418,7 @@ LONG CMainFrame::OnUpdateInfo(UINT lParam, LONG wParam)
char str[128];
float pos[3];
- project->GetFocusPosition(pos);
+ lcGetActiveProject()->GetFocusPosition(pos);
sprintf (str, "X: %.2f Y: %.2f Z: %.2f", pos[0], pos[1], pos[2]);
SetStatusBarPane(ID_INDICATOR_POSITION, str);
@@ -475,7 +475,7 @@ void CMainFrame::OnClose()
if (m_lpfnCloseProc != NULL && !(*m_lpfnCloseProc)(this))
return;
- if (!project->SaveModified())
+ if (!lcGetActiveProject()->SaveModified())
return;
if (GetStyle() & WS_VISIBLE)
@@ -629,7 +629,7 @@ void CMainFrame::GetMessageString(UINT nID, CString& rMessage) const
{
if (nID >= ID_CAMERA_FIRST && nID <= ID_CAMERA_LAST)
{
- Camera* pCamera = project->GetCamera(nID-ID_CAMERA_FIRST);
+ Camera* pCamera = lcGetActiveProject()->GetCamera(nID-ID_CAMERA_FIRST);
rMessage = "Use the camera \"";
rMessage += pCamera->GetName();
rMessage += "\"";
@@ -646,6 +646,7 @@ void CMainFrame::OnFilePrintPieceList()
// Pass all commands to the project.
BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
{
+ Project* project = lcGetActiveProject();
int nID = LOWORD(wParam);
if (nID >= ID_SNAP_0 && nID <= ID_SNAP_9)
@@ -966,7 +967,7 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
if (Item == NULL)
break;
- PiecesLibrary* Lib = project->GetPiecesLibrary();
+ PiecesLibrary* Lib = lcGetPiecesLibrary();
CString CategoryName = m_wndPiecesBar.m_PiecesTree.GetItemText(Item);
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
@@ -994,7 +995,7 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts))
{
- PiecesLibrary* Lib = project->GetPiecesLibrary();
+ PiecesLibrary* Lib = lcGetPiecesLibrary();
Lib->AddCategory(Opts.Name, Opts.Keywords);
m_wndPiecesBar.UpdatePiecesTree(NULL, Opts.Name);
}
@@ -1008,7 +1009,7 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
if (Item == NULL)
break;
- PiecesLibrary* Lib = project->GetPiecesLibrary();
+ PiecesLibrary* Lib = lcGetPiecesLibrary();
CString CategoryName = m_wndPiecesBar.m_PiecesTree.GetItemText(Item);
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
@@ -1040,7 +1041,12 @@ void CMainFrame::OnActivateApp(BOOL bActive, ACTIVATEAPPPARAM hTask)
// Don't notify if we loose focus while on print preview
if (m_lpfnCloseProc == NULL)
- project->HandleNotify(LC_ACTIVATE, bActive ? 1 : 0);
+ {
+ Project* project = lcGetActiveProject();
+
+ if (project)
+ project->HandleNotify(LC_ACTIVATE, bActive ? 1 : 0);
+ }
}
LRESULT CMainFrame::OnSetMessageString(WPARAM wParam, LPARAM lParam)
@@ -1115,7 +1121,7 @@ void CMainFrame::OnViewNewView()
AfxThrowResourceException();
}
- View *view = new View (project, NULL);
+ View *view = new View (lcGetActiveProject(), NULL);
CreateWindowEx (0, FLOATING_CLASSNAME, "LeoCAD",
WS_VISIBLE | WS_POPUPWINDOW | WS_OVERLAPPEDWINDOW,
@@ -1205,7 +1211,7 @@ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
}
}
- project->HandleCommand(Cmd.ID, 0);
+ lcGetActiveProject()->HandleCommand(Cmd.ID, 0);
return true;
}
}
@@ -1223,7 +1229,7 @@ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
}
}
- project->HandleCommand(Cmd.ID, 0);
+ lcGetActiveProject()->HandleCommand(Cmd.ID, 0);
return true;
}
}
@@ -1394,7 +1400,7 @@ void CMainFrame::OnDropFiles(HDROP hDropInfo)
TCHAR szFileName[_MAX_PATH];
::DragQueryFile(hDropInfo, 0, szFileName, _MAX_PATH);
- project->OpenProject(szFileName);
+ lcGetActiveProject()->OpenProject(szFileName);
}
::DragFinish(hDropInfo);
}
diff --git a/win/Moddlg.cpp b/win/Moddlg.cpp
index c9035f8..b81ec37 100644
--- a/win/Moddlg.cpp
+++ b/win/Moddlg.cpp
@@ -13,6 +13,7 @@
#include "camera.h"
#include "light.h"
#include "matrix.h"
+#include "lc_application.h"
#ifdef _DEBUG
#undef THIS_FILE
@@ -143,7 +144,7 @@ void CModifyDialog::UpdateInfo(Object* pObject)
return;
if (pObject == NULL)
- pObject = project->GetFocusObject();
+ pObject = lcGetActiveProject()->GetFocusObject();
m_pObject = pObject;
@@ -171,7 +172,7 @@ void CModifyDialog::UpdateInfo(Object* pObject)
Matrix mat(rot, pos);
mat.ToEulerAngles(rot);
- if ((project->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
+ if ((lcGetActiveProject()->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
{
pos[0] /= 0.08f;
pos[1] /= 0.08f;
@@ -185,7 +186,7 @@ void CModifyDialog::UpdateInfo(Object* pObject)
m_fRotY = rot[1];
m_fRotZ = rot[2];
- if (project->IsAnimation())
+ if (lcGetActiveProject()->IsAnimation())
{
m_nFrom = pPiece->GetFrameShow();
m_nTo = pPiece->GetFrameHide();
@@ -213,7 +214,7 @@ void CModifyDialog::UpdateInfo(Object* pObject)
pCamera = ((CameraTarget*)m_pObject)->GetParent();
pCamera->GetEyePos(tmp);
- if ((project->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
+ if ((lcGetActiveProject()->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
{
tmp[0] /= 0.08f;
tmp[1] /= 0.08f;
@@ -224,7 +225,7 @@ void CModifyDialog::UpdateInfo(Object* pObject)
m_fPosZ = tmp[2];
pCamera->GetTargetPos(tmp);
- if ((project->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
+ if ((lcGetActiveProject()->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
{
tmp[0] /= 0.08f;
tmp[1] /= 0.08f;
@@ -235,7 +236,7 @@ void CModifyDialog::UpdateInfo(Object* pObject)
m_fRotZ = tmp[2];
pCamera->GetUpVec(tmp);
- if ((project->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
+ if ((lcGetActiveProject()->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
{
tmp[0] /= 0.08f;
tmp[1] /= 0.08f;
@@ -372,7 +373,7 @@ void CModifyDialog::OnModdlgApply()
mod.pos[0] = m_fPosX;
mod.pos[1] = m_fPosY;
mod.pos[2] = m_fPosZ;
- if ((project->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
+ if ((lcGetActiveProject()->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
{
mod.pos[0] *= 0.08f;
mod.pos[1] *= 0.08f;
@@ -387,7 +388,7 @@ void CModifyDialog::OnModdlgApply()
mod.color = m_ctlColor.GetColorIndex();
strcpy(mod.name, m_strName);
- project->HandleNotify(LC_PIECE_MODIFIED, (unsigned long)&mod);
+ lcGetActiveProject()->HandleNotify(LC_PIECE_MODIFIED, (unsigned long)&mod);
} break;
case LC_OBJECT_CAMERA: case LC_OBJECT_CAMERA_TARGET:
@@ -405,7 +406,7 @@ void CModifyDialog::OnModdlgApply()
mod.up[0] = m_fUpX;
mod.up[1] = m_fUpY;
mod.up[2] = m_fUpZ;
- if ((project->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
+ if ((lcGetActiveProject()->GetSnapFlags() & LC_DRAW_CM_UNITS) == 0)
{
mod.eye[0] *= 0.08f;
mod.eye[1] *= 0.08f;
@@ -421,7 +422,7 @@ void CModifyDialog::OnModdlgApply()
mod.znear = m_fNear;
mod.zfar = m_fFar;
- project->HandleNotify(LC_CAMERA_MODIFIED, (unsigned long)&mod);
+ lcGetActiveProject()->HandleNotify(LC_CAMERA_MODIFIED, (unsigned long)&mod);
} break;
case LC_OBJECT_LIGHT: case LC_OBJECT_LIGHT_TARGET:
@@ -446,7 +447,7 @@ void CModifyDialog::OnDropdownModdlgList()
Light* pLight;
int i;
- project->GetArrays(&pPiece, &pCamera, &pLight);
+ lcGetActiveProject()->GetArrays(&pPiece, &pCamera, &pLight);
m_ctlCombo.ResetContent();
diff --git a/win/Piecebar.cpp b/win/Piecebar.cpp
index 3ec1cdb..f66cd2d 100644
--- a/win/Piecebar.cpp
+++ b/win/Piecebar.cpp
@@ -9,6 +9,7 @@
#include "pieceinf.h"
#include "project.h"
#include "globals.h"
+#include "lc_application.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -737,7 +738,7 @@ void CPiecesBar::OnSelChangeColor()
if (i == LB_ERR)
return;
- project->HandleNotify(LC_COLOR_CHANGED, (i % 2 == 0) ? (i/2) : (((i-1)/2)+14));
+ lcGetActiveProject()->HandleNotify(LC_COLOR_CHANGED, (i % 2 == 0) ? (i/2) : (((i-1)/2)+14));
m_wndPiecePreview.PostMessage (WM_PAINT);
}
@@ -778,7 +779,7 @@ void CPiecesBar::OnContextMenu(CWnd* pWnd, CPoint point)
if (Item != NULL)
{
- PiecesLibrary *Lib = project->GetPiecesLibrary();
+ PiecesLibrary *Lib = lcGetPiecesLibrary();
CString CategoryName = m_PiecesTree.GetItemText(Item);
int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName);
@@ -833,7 +834,7 @@ void CPiecesBar::SelectPiece(const char* Category, PieceInfo* Info)
strcpy(ParentName, Info->m_strName);
*strchr(ParentName, 'P') = '\0';
- Parent = project->GetPiecesLibrary()->FindPieceInfo(ParentName);
+ Parent = lcGetPiecesLibrary()->FindPieceInfo(ParentName);
if (Parent)
{
@@ -933,7 +934,7 @@ void CPiecesBar::UpdatePiecesTree(const char* OldCategory, const char* NewCatego
void CPiecesBar::UpdatePiecesTree(bool SearchOnly)
{
- PiecesLibrary *Lib = project->GetPiecesLibrary();
+ PiecesLibrary *Lib = lcGetPiecesLibrary();
if (SearchOnly)
{
@@ -1006,7 +1007,7 @@ BOOL CPiecesBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
if (Info != NULL)
{
- project->SetCurrentPiece(Info);
+ lcGetActiveProject()->SetCurrentPiece(Info);
m_wndPiecePreview.SetPieceInfo(Info);
m_wndPiecePreview.PostMessage(WM_PAINT);
}
@@ -1015,7 +1016,7 @@ BOOL CPiecesBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
if (Notify->action == TVE_EXPAND)
{
- PiecesLibrary *Lib = project->GetPiecesLibrary();
+ PiecesLibrary *Lib = lcGetPiecesLibrary();
// Check if we're expanding a category item.
if (Notify->itemNew.lParam == NULL)
diff --git a/win/Piececmb.cpp b/win/Piececmb.cpp
index ecefb8d..f1f3e29 100644
--- a/win/Piececmb.cpp
+++ b/win/Piececmb.cpp
@@ -9,6 +9,7 @@
#include "project.h"
#include "globals.h"
#include "library.h"
+#include "lc_application.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -45,7 +46,7 @@ void CPiecesCombo::OnEditupdate()
return;
char str[66];
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
+ PiecesLibrary *pLib = lcGetPiecesLibrary();
CPiecesBar* pBar = (CPiecesBar*)GetParent();
PieceInfo* pInfo;
@@ -105,7 +106,7 @@ BOOL CPiecesCombo::PreTranslateMessage(MSG* pMsg)
}
else if (nVirtKey == VK_RETURN)
{
- PiecesLibrary* Lib = project->GetPiecesLibrary();
+ PiecesLibrary* Lib = lcGetPiecesLibrary();
CString str;
GetWindowText(str);
@@ -126,7 +127,7 @@ void CPiecesCombo::OnSelchange()
{
char str[66];
CPiecesBar* pBar = (CPiecesBar*)GetParent();
- PiecesLibrary *pLib = project->GetPiecesLibrary();
+ PiecesLibrary *pLib = lcGetPiecesLibrary();
if (!GetLBText (GetCurSel(), str))
return;
@@ -142,7 +143,7 @@ void CPiecesCombo::OnSelchange()
void CPiecesCombo::SelectPiece(PieceInfo* Info)
{
- PiecesLibrary *Lib = project->GetPiecesLibrary();
+ PiecesLibrary *Lib = lcGetPiecesLibrary();
CPiecesBar* Bar = (CPiecesBar*)GetParent();
int Index = Lib->GetFirstCategory(Info);
diff --git a/win/Print.cpp b/win/Print.cpp
index 80c96b2..6f693f8 100644
--- a/win/Print.cpp
+++ b/win/Print.cpp
@@ -13,12 +13,13 @@
#include "Tools.h"
#include "Piece.h"
#include "library.h"
+#include "lc_application.h"
static void PrintCatalogThread (CWnd* pParent, CFrameWnd* pMainFrame)
{
CCADView* pView = (CCADView*)pMainFrame->GetActiveView();
CPrintDialog* PD = new CPrintDialog(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOSELECTION|PD_ENABLEPRINTHOOK, pParent);
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
+ PiecesLibrary *pLib = lcGetPiecesLibrary();
int bricks = 0;
for (int j = 0; j < pLib->GetPieceCount (); j++)
@@ -288,7 +289,7 @@ static void PrintCatalogThread (CWnd* pParent, CFrameWnd* pMainFrame)
glDisable (GL_DITHER);
glShadeModel (GL_FLAT);
- glColor3ubv(FlatColorArray[project->GetCurrentColor()]);
+ glColor3ubv(FlatColorArray[lcGetActiveProject()->GetCurrentColor()]);
// dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, node->name);
node = node->next;
@@ -305,7 +306,7 @@ static void PrintCatalogThread (CWnd* pParent, CFrameWnd* pMainFrame)
FillRect(pMemDC->m_hDC, CRect(0,h,w,0), (HBRUSH)GetStockObject(WHITE_BRUSH));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- pInfo->RenderPiece(project->GetCurrentColor());
+ pInfo->RenderPiece(lcGetActiveProject()->GetCurrentColor());
glFlush();
TextOut (pMemDC->m_hDC, 5, 5, pInfo->m_strDescription, strlen(pInfo->m_strDescription));
@@ -411,7 +412,8 @@ static void PrintPiecesThread(void* pv)
CFrameWnd* pFrame = (CFrameWnd*)pv;
CView* pView = pFrame->GetActiveView();
CPrintDialog* PD = new CPrintDialog(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOPAGENUMS|PD_NOSELECTION, pFrame);
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
+ PiecesLibrary *pLib = lcGetPiecesLibrary();
+ Project* project = lcGetActiveProject();
UINT *pieces = (UINT*)malloc(pLib->GetPieceCount ()*28*sizeof(UINT));
int col[28];
diff --git a/win/Steppop.cpp b/win/Steppop.cpp
index eff6447..3314763 100644
--- a/win/Steppop.cpp
+++ b/win/Steppop.cpp
@@ -6,6 +6,7 @@
#include "StepPop.h"
#include "project.h"
#include "globals.h"
+#include "lc_application.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -32,7 +33,7 @@ CStepPopup::CStepPopup(CPoint pt, CWnd* pParentWnd)
m_Slider.Create (WS_CHILD|WS_VISIBLE|TBS_BOTH|TBS_HORZ|TBS_NOTICKS, CRect(5,10,90,30), this, 1000);
int from, to;
- project->GetTimeRange(&from, &to);
+ lcGetActiveProject()->GetTimeRange(&from, &to);
m_Slider.SetRange(1, to);
m_Slider.SetPos(from);
}
@@ -82,7 +83,7 @@ void CStepPopup::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
int pos = m_Slider.GetPos();
if (pos > 0)
- project->HandleCommand(LC_VIEW_STEP_SET, pos);
+ lcGetActiveProject()->HandleCommand(LC_VIEW_STEP_SET, pos);
CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
}
diff --git a/win/System.cpp b/win/System.cpp
index b8000e9..0e2cb92 100644
--- a/win/System.cpp
+++ b/win/System.cpp
@@ -32,6 +32,7 @@
#include "mainfrm.h"
#include "project.h"
#include "globals.h"
+#include "lc_application.h"
bool lcAssert(const char* FileName, int Line, const char* Expression, const char* Description)
{
@@ -447,7 +448,10 @@ void SystemInit()
// Viewport menu.
void SystemUpdateViewport(int nNew, int nOld)
{
- CMenu* pMenu = GetMainMenu(2)->GetSubMenu(12);
+ CMenu* pMenu = GetMainMenu(2);
+ if (!pMenu)
+ return;
+ pMenu = pMenu->GetSubMenu(12);
pMenu->CheckMenuItem(nOld + ID_VIEWPORT01, MF_BYCOMMAND | MF_UNCHECKED);
pMenu->CheckMenuItem(nNew + ID_VIEWPORT01, MF_BYCOMMAND | MF_CHECKED);
}
@@ -456,6 +460,8 @@ void SystemUpdateViewport(int nNew, int nOld)
void SystemUpdateAction(int nNew, int nOld)
{
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CToolBar* pBar = (CToolBar*)pFrame->GetControlBar(ID_VIEW_TOOLS_BAR);
CToolBarCtrl* pCtrl = &pBar->GetToolBarCtrl();
CView* pView = pFrame->GetActiveView();
@@ -474,12 +480,15 @@ void SystemUpdateAction(int nNew, int nOld)
// Current color in the listbox;
void SystemUpdateColorList(int nNew)
{
- AfxGetMainWnd()->PostMessage (WM_LC_UPDATE_LIST, 0, nNew+1);
+ if (AfxGetMainWnd())
+ AfxGetMainWnd()->PostMessage (WM_LC_UPDATE_LIST, 0, nNew+1);
}
void SystemUpdateRenderingMode(bool bBackground, bool bFast)
{
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CToolBar* pBar = (CToolBar*)pFrame->GetControlBar(AFX_IDW_TOOLBAR);
CToolBarCtrl* pCtrl = &pBar->GetToolBarCtrl();
@@ -500,6 +509,8 @@ void SystemUpdateRenderingMode(bool bBackground, bool bFast)
void SystemUpdateUndoRedo(char* undo, char* redo)
{
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CToolBar* pBar = (CToolBar*)pFrame->GetControlBar(AFX_IDW_TOOLBAR);
CToolBarCtrl* pCtrl = &pBar->GetToolBarCtrl();
CMenu* pMenu = GetMainMenu(1);
@@ -542,6 +553,8 @@ void SystemUpdateUndoRedo(char* undo, char* redo)
void SystemUpdateSnap(const unsigned long nSnap)
{
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CToolBar* pBar = (CToolBar*)pFrame->GetControlBar(AFX_IDW_TOOLBAR);
CToolBarCtrl* pCtrl = &pBar->GetToolBarCtrl();
pCtrl->CheckButton(ID_SNAP_ANGLE, (nSnap & LC_DRAW_SNAP_A) != 0);
@@ -577,6 +590,8 @@ void SystemUpdateSelected(unsigned long flags)
{
CMenu* pMenu;
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CToolBar* pBar = (CToolBar*)pFrame->GetControlBar(AFX_IDW_TOOLBAR);
CToolBarCtrl* pCtrl = &pBar->GetToolBarCtrl();
@@ -647,6 +662,8 @@ void SystemUpdateTime(bool bAnimation, int nTime, int nTotal)
{
// Toolbar
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CToolBar* pBar = (CToolBar*)pFrame->GetControlBar(ID_VIEW_ANIMATION_BAR);
CToolBarCtrl* pCtrl = &pBar->GetToolBarCtrl();
@@ -687,11 +704,12 @@ void SystemUpdateSnap(unsigned short MoveSnap, unsigned short RotateSnap)
{
char Text[256], xy[32], z[32];
- project->GetSnapDistanceText(xy, z);
+ lcGetActiveProject()->GetSnapDistanceText(xy, z);
sprintf(Text, " M: %s %s R: %d ", xy, z, RotateSnap);
- ((CMainFrame*)AfxGetMainWnd())->SetStatusBarPane(ID_INDICATOR_SNAP, Text);
+ if (AfxGetMainWnd())
+ ((CMainFrame*)AfxGetMainWnd())->SetStatusBarPane(ID_INDICATOR_SNAP, Text);
}
void SystemUpdatePaste(bool enable)
@@ -722,6 +740,8 @@ void SystemUpdateAnimation(bool bAnimation, bool bAddKeys)
{
// Toolbar
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CToolBar* pBar = (CToolBar*)pFrame->GetControlBar(ID_VIEW_ANIMATION_BAR);
CToolBarCtrl* pCtrl = &pBar->GetToolBarCtrl();
@@ -747,7 +767,10 @@ void SystemUpdateAnimation(bool bAnimation, bool bAddKeys)
void SystemUpdateCurrentCamera(Camera* pOld, Camera* pNew, Camera* pCamera)
{
- CBMPMenu* pMainMenu = (CBMPMenu*)GetMainMenu(2)->GetSubMenu(13);
+ CMenu* Menu = GetMainMenu(2);
+ if (!Menu)
+ return;
+ CBMPMenu* pMainMenu = (CBMPMenu*)Menu->GetSubMenu(13);
CMenu* pPopupMenu = menuPopups.GetSubMenu(1)->GetSubMenu(3);
int i;
@@ -772,7 +795,10 @@ void SystemUpdateCurrentCamera(Camera* pOld, Camera* pNew, Camera* pCamera)
// Update the list of cameras
void SystemUpdateCameraMenu(Camera* pCamera)
{
- CBMPMenu* pMainMenu = (CBMPMenu*)GetMainMenu(2)->GetSubMenu(13);
+ CMenu* Menu = GetMainMenu(2);
+ if (!Menu)
+ return;
+ CBMPMenu* pMainMenu = (CBMPMenu*)Menu->GetSubMenu(13);
CMenu* pPopupMenu = menuPopups.GetSubMenu(1)->GetSubMenu(3);
Camera* pFirst = pCamera;
int i;
@@ -817,6 +843,10 @@ void SystemUpdateCameraMenu(Camera* pCamera)
void SystemUpdateCategories(bool SearchOnly)
{
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+
+ if (!pFrame)
+ return;
+
CPiecesBar* pBar = (CPiecesBar*)pFrame->GetControlBar(ID_VIEW_PIECES_BAR);
pBar->UpdatePiecesTree(SearchOnly);
}
@@ -970,6 +1000,8 @@ static BOOL GetDisplayName(char* filename, CString& strName, LPCTSTR lpszCurDir,
void SystemUpdateRecentMenu(char names[4][LC_MAXPATH])
{
CBMPMenu* pMenu = (CBMPMenu*)GetMainMenu(0);
+ if (!pMenu)
+ return;
UINT nState;
pMenu->DeleteMenu(ID_FILE_MRU_FILE2, MF_BYCOMMAND);
@@ -1061,6 +1093,9 @@ extern void AFXAPI AfxSetWindowText(HWND, LPCTSTR);
void SystemSetWindowCaption(char* caption)
{
+ if (!AfxGetMainWnd())
+ return;
+
AfxSetWindowText(AfxGetMainWnd()->m_hWnd, caption);
}
@@ -1724,6 +1759,8 @@ long SystemGetTicks()
void SystemStartProgressBar(int nLower, int nUpper, int nStep, const char* Text)
{
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CCADStatusBar* pStatusBar = (CCADStatusBar*)pFrame->GetControlBar(AFX_IDW_STATUS_BAR);
pStatusBar->ShowProgressBar(TRUE);
@@ -1738,6 +1775,8 @@ void SystemStartProgressBar(int nLower, int nUpper, int nStep, const char* Text)
void SytemEndProgressBar()
{
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CCADStatusBar* pStatusBar = (CCADStatusBar*)pFrame->GetControlBar(AFX_IDW_STATUS_BAR);
pStatusBar->ShowProgressBar(FALSE);
@@ -1749,6 +1788,8 @@ void SytemEndProgressBar()
void SytemStepProgressBar()
{
CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ if (!pFrame)
+ return;
CCADStatusBar* pStatusBar = (CCADStatusBar*)pFrame->GetControlBar(AFX_IDW_STATUS_BAR);
pStatusBar->StepProgressBar();
diff --git a/win/Tools.cpp b/win/Tools.cpp
index b39c0e4..cdf49a4 100644
--- a/win/Tools.cpp
+++ b/win/Tools.cpp
@@ -5,6 +5,7 @@
#include "Tools.h"
#include "resource.h"
#include "PrefSht.h"
+#include "lc_application.h"
#include <math.h>
#include <shlobj.h>
@@ -255,6 +256,8 @@ void Export3DStudio()
if (dlg.DoModal() != IDOK)
return;
+ Project* project = lcGetActiveProject();
+
ClearErrList3ds();
file3ds *file = OpenFile3ds(dlg.GetPathName(), "w");
database3ds *db = NULL;
diff --git a/win/texdlg.cpp b/win/texdlg.cpp
index 3b09d21..1bafd02 100644
--- a/win/texdlg.cpp
+++ b/win/texdlg.cpp
@@ -8,6 +8,7 @@
#include "project.h"
#include "globals.h"
#include "texture.h"
+#include "lc_application.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -68,7 +69,7 @@ void CTexturesDlg::OnLibtexAdd()
if (dlg.DoModal() == IDOK)
{
- project->GetPiecesLibrary ()->ImportTexture (dlg.GetPathName());
+ lcGetPiecesLibrary()->ImportTexture(dlg.GetPathName());
UpdateList();
}
}
@@ -96,7 +97,7 @@ void CTexturesDlg::OnLibtexRemove()
}
}
- project->GetPiecesLibrary ()->DeleteTextures (names, selected);
+ lcGetPiecesLibrary()->DeleteTextures(names, selected);
free (names);
@@ -105,13 +106,13 @@ void CTexturesDlg::OnLibtexRemove()
void CTexturesDlg::UpdateList()
{
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
+ PiecesLibrary *pLib = lcGetPiecesLibrary();
- m_List.ResetContent ();
+ m_List.ResetContent();
- for (int i = 0; i < pLib->GetTextureCount (); i++)
+ for (int i = 0; i < pLib->GetTextureCount(); i++)
{
int index = m_List.AddString (pLib->GetTexture(i)->m_strName);
- m_List.SetItemDataPtr (index, pLib->GetTexture(i)->m_strName);
+ m_List.SetItemDataPtr(index, pLib->GetTexture(i)->m_strName);
}
}