# TODO: stb_truetype doesn't compile with some of these warnings.
CXX = g++ -std=gnu++0x -g -Wall -Werror -Wshadow -pedantic -rdynamic
MAIN = main.o
-OBJ = log.o real.o bezier.o document.o objectrenderer.o view.o screen.o vfpu.o quadtree.o graphicsbuffer.o framebuffer.o shaderprogram.o stb_truetype.o gl_core44.o add_digits_asm.o sub_digits_asm.o mul_digits_asm.o div_digits_asm.o arbint.o
-LIB_x86_64 = ../contrib/lib/libSDL2-2.0.so.0 -lGL -lgmp
+OBJ = log.o real.o bezier.o document.o objectrenderer.o view.o screen.o vfpu.o quadtree.o graphicsbuffer.o framebuffer.o shaderprogram.o stb_truetype.o gl_core44.o add_digits_asm.o sub_digits_asm.o mul_digits_asm.o div_digits_asm.o arbint.o controlpanel.o
+
+QT_INCLUDE := -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -Itests -I.
+
+QT_LIB := -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lpthread
+
+LIB_x86_64 = ../contrib/lib/libSDL2-2.0.so.0 -lGL -lgmp $(QT_LIB)
LIB_i386 = ../contrib/lib32/libSDL2-2.0.so.0 -lGL -lgmp
LIB_i686 = $(LIB_i386)
TESTRPATH_i686 = $(TESTRPATH_i386)
OBJPATHS = $(OBJ:%=../obj/%)
DEPS := $(OBJPATHS:%.o=%.d)
-CFLAGS_x86_64 := -I../contrib/include/SDL2 -I`pwd`
+CFLAGS_x86_64 := -I../contrib/include/SDL2 -I`pwd` $(QT_INCLUDE)
CFLAGS_i386 := -I../contrib/include32/SDL2 -I`pwd`
CFLAGS_i686 := $(CFLAGS_i386)
--- /dev/null
+/**
+ * Definitions for Qt4 based control panel
+ */
+
+#include "controlpanel.h"
+#include "view.h"
+#include "screen.h"
+#include "document.h"
+
+#ifndef CONTROLPANEL_DISABLED
+
+namespace IPDF
+{
+
+
+ControlPanel::ControlPanel(RunArgs & args, QWidget * p) : QMainWindow(p),
+ m_view(args.view), m_doc(args.doc), m_screen(args.screen)
+{
+ // Size
+ resize(300,300);
+ // Title
+ setWindowTitle("IPDF Control Panel");
+ // Tooltip
+ setToolTip("This is the IPDF Control Panel.\nDo you feel in control?");
+
+ // Main menues
+ CreateMainMenu();
+ CreateViewMenu();
+ CreateDocumentMenu();
+ CreateScreenMenu();
+
+ UpdateAll();
+
+}
+
+QMenu * ControlPanel::CreateMainMenu()
+{
+ QMenu * main = menuBar()->addMenu("&Main");
+
+ // Quit entry
+ QAction * quit = new QAction("&Quit", this);
+ main->addAction(quit);
+ connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
+ return main;
+}
+
+QMenu * ControlPanel::CreateDocumentMenu()
+{
+ QMenu * document = menuBar()->addMenu("&Document");
+ return document;
+}
+
+QMenu * ControlPanel::CreateViewMenu()
+{
+ QMenu * view = menuBar()->addMenu("&View");
+
+
+
+ return view;
+}
+
+
+
+QMenu * ControlPanel::CreateScreenMenu()
+{
+ QMenu * screen = menuBar()->addMenu("&Screen");
+
+ m_screen_gpu_rendering = new QAction("&GPU Rendering", this);
+ m_screen_gpu_rendering->setCheckable(true);
+
+ m_screen_cpu_rendering = new QAction("&CPU Rendering", this);
+ m_screen_cpu_rendering->setCheckable(true);
+
+ screen->addAction(m_screen_gpu_rendering);
+ screen->addAction(m_screen_cpu_rendering);
+
+ connect(m_screen_gpu_rendering, SIGNAL(triggered()), this, SLOT(SetGPURendering()));
+ connect(m_screen_cpu_rendering, SIGNAL(triggered()), this, SLOT(SetCPURendering()));
+
+ return screen;
+}
+
+void ControlPanel::UpdateAll()
+{
+ bool using_gpu_rendering = m_view.UsingGPURendering();
+ m_screen_gpu_rendering->setChecked(using_gpu_rendering);
+ m_screen_cpu_rendering->setChecked(!using_gpu_rendering);
+}
+
+void ControlPanel::SetGPURendering()
+{
+ m_view.SetGPURendering(true);
+ UpdateAll();
+}
+
+void ControlPanel::SetCPURendering()
+{
+ m_view.SetGPURendering(false);
+ UpdateAll();
+}
+
+ControlPanel * ControlPanel::g_panel = NULL;
+
+int ControlPanel::Run(void * args)
+{
+ ControlPanel::RunArgs * a = (ControlPanel::RunArgs*)args;
+ QApplication app(a->argc, a->argv);
+ g_panel = new ControlPanel(*a);
+ g_panel->show();
+ int result = app.exec();
+ a->screen.RequestQuit();
+ delete g_panel;
+ return result;
+}
+
+
+}
+
+#endif //CONTROLPANEL_ENABLED
+
--- /dev/null
+/**
+ * Declarations for Qt4 based control panel
+ */
+#ifndef _CONTROLPANEL_H
+#define _CONTROLPANEL_H
+
+//#define CONTROLPANEL_DISABLED // To turn off the control panel
+
+#ifndef CONTROLPANEL_DISABLED
+
+
+#include <QPushButton>
+#include <QMainWindow>
+#include <QWidget>
+#include <QAction>
+#include <QMenu>
+#include <QMenuBar>
+#include <QApplication>
+
+
+
+namespace IPDF
+{
+ class View;
+ class Document;
+ class Screen;
+
+ /**
+ * Class to manage Qt control panel
+ * Should be a singleton from the point of view of View, Document, Screen
+ * - Just call "Update"
+ */
+ class ControlPanel : public QMainWindow
+ {
+ //Q_OBJECT // Having this causes shit about undefined vtables
+ // Not having it means things break
+ // Apparently you need "qmake" to build qt applications
+ // Or some bullshit -_-
+ public:
+ struct RunArgs
+ {
+ int argc;
+ char ** argv;
+ View & view;
+ Document & doc;
+ Screen & screen;
+ };
+
+ static int Run(void * args);
+ static void Update() {if (g_panel != NULL) g_panel->UpdateAll();};
+
+ ControlPanel(RunArgs & a, QWidget * p = NULL);
+ virtual ~ControlPanel() {}
+
+ private slots:
+ void SetGPURendering();
+ void SetCPURendering();
+
+
+ private:
+ static ControlPanel * g_panel;
+
+
+ void UpdateAll();
+
+ View & m_view;
+ Document & m_doc;
+ Screen & m_screen;
+
+ QMenu * CreateMainMenu();
+ QMenu * CreateViewMenu();
+ QMenu * CreateDocumentMenu();
+ QMenu * CreateScreenMenu();
+
+ QAction * m_screen_gpu_rendering;
+ QAction * m_screen_cpu_rendering;
+
+
+ };
+
+}
+
+#endif //CONTROLPANEL_DISABLED
+
+#endif //_CONTROLPANEL_H
#include "main.h"
#include <unistd.h> // Because we can.
+#include "controlpanel.h"
+
+
+
int main(int argc, char ** argv)
{
#ifndef __STDC_IEC_559__
}
Debug("Start!");
Rect bounds(b[0],b[1],b[2],b[3]);
+
+ Screen scr;
+ View view(doc,scr, bounds);
+
+ #ifndef CONTROLPANEL_DISABLED
+ ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
+ SDL_Thread * cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
+ if (cp_thread == NULL)
+ {
+ Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
+ }
+ #endif //CONTROLPANEL_DISABLED
if (mode == LOOP)
- MainLoop(doc, bounds, c);
- else if (mode == OUTPUT_TO_BMP)
+ MainLoop(doc, scr, view);
+ else if (mode == OUTPUT_TO_BMP) //TODO: Remove this shit
OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
+
+ #ifndef CONTROLPANEL_DISABLED
+
+ if (cp_thread != NULL)
+ {
+ int cp_return;
+ qApp->quit(); // will close the control panel
+ // (seems to not explode if the qApp has already been quit)
+ SDL_WaitThread(cp_thread, &cp_return);
+ Debug("ControlPanel thread returned %d", cp_return);
+ }
+ #endif //CONTROLPANEL_DISABLED
return 0;
}
}
-inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f))
+inline void MainLoop(Document & doc, Screen & scr, View & view)
{
// order is important... segfaults occur when screen (which inits GL) is not constructed first -_-
- Screen scr;
- View view(doc,scr, bounds, c);
+
scr.DebugFontInit("DejaVuSansMono.ttf");
scr.SetMouseHandler(RatCatcher);
m_viewport_ubo.SetType(GraphicsBuffer::BufferTypeUniform);
m_debug_font_atlas = 0;
-
+ m_no_quit_requested = true;
m_view = NULL;
ResizeViewport(800, 600);
-
+
Clear();
Present();
bool Screen::PumpEvents()
{
SDL_Event evt;
- bool no_quit_requested = true;
+
while (SDL_PollEvent(&evt))
{
switch (evt.type)
{
case SDL_QUIT:
- no_quit_requested = false;
+ m_no_quit_requested = false;
break;
case SDL_WINDOWEVENT:
switch (evt.window.event)
break;
}
}
- return no_quit_requested;
+ return m_no_quit_requested;
}
void Screen::SetMouseCursor(Screen::MouseCursors cursor)
double GetLastFrameTimeCPU() const { return m_last_frame_time / SDL_GetPerformanceFrequency(); }
// Returns the GPU time (in seconds) it took to render the last completed frame.
double GetLastFrameTimeGPU() const;
+
+ void RequestQuit() {m_no_quit_requested = false;}
+ bool QuitRequested() const {return !m_no_quit_requested;}
private:
void ResizeViewport(int width, int height);
void DebugFontFlush();
int m_debug_font_vertex_head;
int m_debug_font_index_head;
View * m_view;
+ bool m_no_quit_requested;
};
}
--- /dev/null
+
+#include <QApplication>
+#include <QWidget>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QWidget window;
+
+ window.resize(250, 150);
+ window.setWindowTitle("Simple example");
+ window.show();
+
+ return app.exec();
+}
#include "screen.h"
#include "gl_core44.h"
+#ifndef CONTROLPANEL_DISABLED
+ #include "controlpanel.h"
+#endif //CONTROLPANEL_DISABLED
+
using namespace IPDF;
using namespace std;
m_cached_display.Blit(); // blit FrameBuffer to screen
m_buffer_dirty = false;
glPopDebugGroup();
+
+#ifndef CONTROLPANEL_DISABLED
+ ControlPanel::Update();
+#endif //CONTROLPANEL_DISABLED
+
}
#ifndef QUADTREE_DISABLED
const bool UsingGPURendering() const { return m_use_gpu_rendering; } // whether GPU shaders are used or CPU rendering
void ToggleGPUTransform() { m_use_gpu_transform = (!m_use_gpu_transform); m_bounds_dirty = true; m_buffer_dirty = true; }
void ToggleGPURendering() { m_use_gpu_rendering = (!m_use_gpu_rendering); m_bounds_dirty = true; m_buffer_dirty = true; }
+
+ void SetGPURendering(bool state) {m_use_gpu_rendering = state; m_bounds_dirty = true; m_buffer_dirty = true;}
void ForceBoundsDirty() {m_bounds_dirty = true;}
void ForceBufferDirty() {m_buffer_dirty = true;}
void ForceRenderDirty() {m_render_dirty = true;}
-
private:
struct GPUObjBounds
{