Added Document and View classes
authorSam Moore <[email protected]>
Wed, 26 Mar 2014 09:17:14 +0000 (17:17 +0800)
committerSam Moore <[email protected]>
Wed, 26 Mar 2014 09:17:14 +0000 (17:17 +0800)
And member functions for doing stuff.

Document Format completed (not really).

src/Makefile
src/common.h
src/document.cpp [new file with mode: 0644]
src/document.h [new file with mode: 0644]
src/ipdf.h
src/main.cpp
src/view.cpp [new file with mode: 0644]
src/view.h [new file with mode: 0644]

index 8e44ac0..13e54d1 100644 (file)
@@ -1,6 +1,6 @@
 #Makefile
 CXX = g++ -std=gnu++0x -Wall -Werror -Wshadow -pedantic -g
-OBJ = log.o main.o
+OBJ = log.o main.o document.o view.o
 LIB = #-lSDL2
 OBJPATHS = $(OBJ:%=../obj/%)
 DEPS := $(OBJPATHS:%.o=%.d)
index 6af0792..47e0329 100644 (file)
@@ -1,4 +1,7 @@
 #include <cstdlib>
 #include <iostream>
+#include <vector>
+#include <string>
+#include <sstream>
 
 #include "log.h"
diff --git a/src/document.cpp b/src/document.cpp
new file mode 100644 (file)
index 0000000..99e429e
--- /dev/null
@@ -0,0 +1,18 @@
+#include "document.h"
+
+using namespace IPDF;
+using namespace std;
+
+void Document::Load(const string & filename)
+{
+       m_objects.bounds.clear();
+       m_count = 0;
+       if (filename == "")
+               return;
+}
+
+void Document::Add(Real x, Real y, Real w, Real h)
+{
+       m_objects.bounds.push_back(Rect(x, y, w, h));
+       m_count++;
+}
diff --git a/src/document.h b/src/document.h
new file mode 100644 (file)
index 0000000..71f6d38
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef _DOCUMENT_H
+#define _DOCUMENT_H
+
+#include "ipdf.h"
+
+namespace IPDF
+{
+       class Document
+       {
+               public:
+                       Document() : m_objects(), m_count(0) {Load();}
+                       virtual ~Document() {}
+
+                       void Load(const std::string & filename = "");
+                       void Add(Real x, Real y, Real w, Real h);
+
+                       unsigned ObjectCount() {return m_count;}
+
+               private:
+                       friend class View;
+                       Objects m_objects;
+                       unsigned m_count;
+       };
+}
+
+#endif //_DOCUMENT_H
index 33962d6..0264d96 100644 (file)
@@ -1,10 +1,34 @@
 #ifndef _IPDF_H
 #define _IPDF_H
 
+#include "common.h"
+
 namespace IPDF
 {
        typedef float Real;
+       
        inline float RealToFloat(Real r) {return r;}
+
+       typedef unsigned ObjectID;
+
+       struct Rect
+       {
+               Real x; Real y; Real w; Real h;
+               Rect(Real _x, Real _y, Real _w, Real _h) : x(_x), y(_y), w(_w), h(_h) {}
+               std::string Str() 
+               {
+                       std::stringstream s;
+                       s << "{" << x << ", " << y << ", " << w << ", " << h << "}";
+                       return s.str();
+               }
+       };
+
+       struct Objects
+       {
+               std::vector<Rect> bounds;
+       };
+
+       class View;
 }
 
 
index 5b8d4b8..701e163 100644 (file)
@@ -1,14 +1,18 @@
 #include "common.h"
 
-#include "ipdf.h"
+#include "document.h"
+#include "view.h"
 
 using namespace std;
 using namespace IPDF;
 
 int main(int argc, char ** argv)
 {
-       Real a = 10;
-       Real b = 20;
-       Debug("a*b = %f", RealToFloat(a*b));
+       Document doc;
+       doc.Add(0.5, 0.5, 0.5, 0.5);
+
+       View view(doc);
+       view.Render();
+
        return 0;
 }
diff --git a/src/view.cpp b/src/view.cpp
new file mode 100644 (file)
index 0000000..fcb841b
--- /dev/null
@@ -0,0 +1,14 @@
+#include "view.h"
+
+using namespace IPDF;
+using namespace std;
+
+void View::Render()
+{
+       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());
+       }
+}
diff --git a/src/view.h b/src/view.h
new file mode 100644 (file)
index 0000000..9a519b0
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef _VIEW_H
+#define _VIEW_H
+
+#include "ipdf.h"
+#include "document.h"
+
+namespace IPDF
+{
+       class View
+       {
+               public:
+                       View(Document & document) : m_document(document), m_bounds(0,0,1,1) {}
+                       virtual ~View() {}
+
+                       void Render();
+               
+               private:
+                       Document & m_document;
+                       Rect m_bounds;
+       };
+}
+
+#endif //_VIEW_H

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