From: Sam Moore Date: Wed, 26 Mar 2014 09:17:14 +0000 (+0800) Subject: Added Document and View classes X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b006386ab52e8a2c47c20bc21591d01c314d4d8e;p=ipdf%2Fcode.git Added Document and View classes And member functions for doing stuff. Document Format completed (not really). --- diff --git a/src/Makefile b/src/Makefile index 8e44ac0..13e54d1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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) diff --git a/src/common.h b/src/common.h index 6af0792..47e0329 100644 --- a/src/common.h +++ b/src/common.h @@ -1,4 +1,7 @@ #include #include +#include +#include +#include #include "log.h" diff --git a/src/document.cpp b/src/document.cpp new file mode 100644 index 0000000..99e429e --- /dev/null +++ b/src/document.cpp @@ -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 index 0000000..71f6d38 --- /dev/null +++ b/src/document.h @@ -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 diff --git a/src/ipdf.h b/src/ipdf.h index 33962d6..0264d96 100644 --- a/src/ipdf.h +++ b/src/ipdf.h @@ -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 bounds; + }; + + class View; } diff --git a/src/main.cpp b/src/main.cpp index 5b8d4b8..701e163 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 index 0000000..fcb841b --- /dev/null +++ b/src/view.cpp @@ -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 index 0000000..9a519b0 --- /dev/null +++ b/src/view.h @@ -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