And member functions for doing stuff.
Document Format completed (not really).
#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)
#include <cstdlib>
#include <iostream>
+#include <vector>
+#include <string>
+#include <sstream>
#include "log.h"
--- /dev/null
+#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++;
+}
--- /dev/null
+#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
#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;
}
#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;
}
--- /dev/null
+#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());
+ }
+}
--- /dev/null
+#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