Add ObjectType for Object Type
authorSam Moore <[email protected]>
Wed, 26 Mar 2014 10:50:14 +0000 (18:50 +0800)
committerSam Moore <[email protected]>
Wed, 26 Mar 2014 10:50:14 +0000 (18:50 +0800)
src/Makefile
src/document.cpp
src/document.h
src/ipdf.h
src/tests/saveload.cpp
src/view.cpp

index 59e111b..3e8d8a0 100644 (file)
@@ -1,6 +1,6 @@
 #Makefile
 CXX = g++ -std=gnu++0x -Wall -Werror -Wshadow -pedantic -g
 #Makefile
 CXX = g++ -std=gnu++0x -Wall -Werror -Wshadow -pedantic -g
-OBJ = log.o main.o document.o view.o screen.o
+OBJ = log.o tests/saveload.o document.o view.o screen.o
 LIB = `sdl2-config --libs` -lGL
 OBJPATHS = $(OBJ:%=../obj/%)
 DEPS := $(OBJPATHS:%.o=%.d)
 LIB = `sdl2-config --libs` -lGL
 OBJPATHS = $(OBJ:%=../obj/%)
 DEPS := $(OBJPATHS:%.o=%.d)
index 3c1a4ab..e8556ee 100644 (file)
@@ -18,11 +18,18 @@ void Document::Save(const string & filename)
        if (written != 1)
                Fatal("Failed to write number of objects!");
 
        if (written != 1)
                Fatal("Failed to write number of objects!");
 
+       Debug("Object types...");
+       written = fwrite(m_objects.types.data(), sizeof(ObjectType), m_objects.types.size(), file);
+       if (written != ObjectCount())
+               Fatal("Only wrote %u objects!", written);
+
        Debug("Object bounds...");
        written = fwrite(m_objects.bounds.data(), sizeof(Rect), m_objects.bounds.size(), file);
        if (written != ObjectCount())
                Fatal("Only wrote %u objects!", written);
 
        Debug("Object bounds...");
        written = fwrite(m_objects.bounds.data(), sizeof(Rect), m_objects.bounds.size(), file);
        if (written != ObjectCount())
                Fatal("Only wrote %u objects!", written);
 
+
+
        int err = fclose(file);
        if (err != 0)
                Fatal("Failed to close file \"%s\" - %s", filename.c_str(), strerror(err));
        int err = fclose(file);
        if (err != 0)
                Fatal("Failed to close file \"%s\" - %s", filename.c_str(), strerror(err));
@@ -50,7 +57,13 @@ void Document::Load(const string & filename)
                Fatal("Failed to read number of objects!");
        Debug("Number of objects: %u", ObjectCount());
 
                Fatal("Failed to read number of objects!");
        Debug("Number of objects: %u", ObjectCount());
 
+       m_objects.types.resize(ObjectCount());
        m_objects.bounds.resize(ObjectCount());
        m_objects.bounds.resize(ObjectCount());
+
+       Debug("Object types...");
+       read = fread(m_objects.types.data(), sizeof(ObjectType), m_objects.types.size(), file);
+       if (read != ObjectCount())
+               Fatal("Only read %u objects!", read);
        
        Debug("Object bounds...");
        read = fread(m_objects.bounds.data(), sizeof(Rect), m_objects.bounds.size(), file);
        
        Debug("Object bounds...");
        read = fread(m_objects.bounds.data(), sizeof(Rect), m_objects.bounds.size(), file);
@@ -60,9 +73,10 @@ void Document::Load(const string & filename)
        Debug("Successfully loaded %u objects from \"%s\"", ObjectCount(), filename.c_str());
 }
 
        Debug("Successfully loaded %u objects from \"%s\"", ObjectCount(), filename.c_str());
 }
 
-void Document::Add(Real x, Real y, Real w, Real h)
+void Document::Add(ObjectType type, const Rect & bounds)
 {
 {
-       m_objects.bounds.push_back(Rect(x, y, w, h));
+       m_objects.types.push_back(type);
+       m_objects.bounds.push_back(bounds);
        m_count++;
 }
 
        m_count++;
 }
 
@@ -71,7 +85,7 @@ void Document::DebugDumpObjects()
        Debug("Objects for Document %p are:", this);
        for (unsigned id = 0; id < ObjectCount(); ++id)
        {
        Debug("Objects for Document %p are:", this);
        for (unsigned id = 0; id < ObjectCount(); ++id)
        {
-               Debug("%u.\t%s", id, m_objects.bounds[id].Str().c_str());
+               Debug("%u. \tType: %u\tBounds: %s", id, m_objects.types[id], m_objects.bounds[id].Str().c_str());
        }
 }
 
        }
 }
 
index ffb761d..89e854a 100644 (file)
@@ -13,7 +13,7 @@ namespace IPDF
 
                        void Load(const std::string & filename = "");
                        void Save(const std::string & filename);
 
                        void Load(const std::string & filename = "");
                        void Save(const std::string & filename);
-                       void Add(Real x, Real y, Real w, Real h);
+                       void Add(ObjectType type, const Rect & bounds);
                        void DebugDumpObjects();
 
                        unsigned ObjectCount() const {return m_count;}
                        void DebugDumpObjects();
 
                        unsigned ObjectCount() const {return m_count;}
index e150088..4041bca 100644 (file)
@@ -14,6 +14,7 @@ namespace IPDF
        }
 
        typedef unsigned ObjectID;
        }
 
        typedef unsigned ObjectID;
+       typedef enum {RECT_FILLED, RECT_OUTLINE} ObjectType;
 
        struct Rect
        {
 
        struct Rect
        {
@@ -30,6 +31,7 @@ namespace IPDF
 
        struct Objects
        {
 
        struct Objects
        {
+               std::vector<ObjectType> types;          
                std::vector<Rect> bounds;
        };
 
                std::vector<Rect> bounds;
        };
 
index a2d58cb..32dd1d7 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "../document.h"
 #include "../view.h"
 
 #include "../document.h"
 #include "../view.h"
+#include "../screen.h"
 
 using namespace std;
 using namespace IPDF;
 
 using namespace std;
 using namespace IPDF;
@@ -14,7 +15,7 @@ int main(int argc, char ** argv)
        Document doc;
        for (unsigned id = 0; id < test_objects; ++id)
        {
        Document doc;
        for (unsigned id = 0; id < test_objects; ++id)
        {
-               doc.Add(Random(), Random(), Random(), Random());
+               doc.Add((ObjectType)(rand() % 2), Rect(Random(), Random(), Random(), Random()));
        }
        doc.Save("test.ipdf");
 
        }
        doc.Save("test.ipdf");
 
@@ -28,5 +29,14 @@ int main(int argc, char ** argv)
        }
        
 
        }
        
 
+       View view(doc);
+       Screen scr;
+
+       while (scr.PumpEvents())
+       {
+               view.Render();
+               scr.Present();
+       }
+
        return 0;
 }
        return 0;
 }
index 40262ac..bd9b2fa 100644 (file)
@@ -10,12 +10,7 @@ void View::Render()
        static bool debug_output_done = false;
        if (!debug_output_done)
        {
        static bool debug_output_done = false;
        if (!debug_output_done)
        {
-               Debug("Bounds are %s", m_bounds.Str().c_str());
-               Debug("Objects are:");
-               for (unsigned id = 0; id < m_document.ObjectCount(); ++id)
-               {
-                       Debug("%u\t%s", id, m_document.m_objects.bounds[id].Str().c_str());
-               }
+               m_document.DebugDumpObjects();
                debug_output_done = true;
        }
 
                debug_output_done = true;
        }
 

UCC git Repository :: git.ucc.asn.au