From: Sam Moore Date: Sun, 17 Aug 2014 09:28:51 +0000 (+0800) Subject: Inflict Qt4 upon the codebase X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=6dd539966821debd18e0b86ed126742cd81d7fc9;p=ipdf%2Fcode.git Inflict Qt4 upon the codebase I'm getting issues compiling it though Qt seems to expect some magical auto-generated Makefile Remove the not-very-functional control panel with a "CONTROLPANEL_DISABLED" define. --- diff --git a/src/Makefile b/src/Makefile index 75781a9..067cc61 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,8 +3,13 @@ ARCH := $(shell uname -m) # 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) @@ -16,7 +21,7 @@ TESTRPATH_i386 = -Wl,-rpath,'$$ORIGIN/../../contrib/lib32' 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) diff --git a/src/controlpanel.cpp b/src/controlpanel.cpp new file mode 100644 index 0000000..984a459 --- /dev/null +++ b/src/controlpanel.cpp @@ -0,0 +1,120 @@ +/** + * 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 + diff --git a/src/controlpanel.h b/src/controlpanel.h new file mode 100644 index 0000000..3e8eb9a --- /dev/null +++ b/src/controlpanel.h @@ -0,0 +1,85 @@ +/** + * 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 +#include +#include +#include +#include +#include +#include + + + +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 diff --git a/src/main.cpp b/src/main.cpp index 46946f9..2612afc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,10 @@ #include "main.h" #include // Because we can. +#include "controlpanel.h" + + + int main(int argc, char ** argv) { #ifndef __STDC_IEC_559__ @@ -88,10 +92,34 @@ int main(int argc, char ** argv) } 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; } diff --git a/src/main.h b/src/main.h index cfc6909..9e48967 100644 --- a/src/main.h +++ b/src/main.h @@ -78,11 +78,10 @@ void RatCatcher(int x, int y, int buttons, int wheel, Screen * scr, View * view) } -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); diff --git a/src/screen.cpp b/src/screen.cpp index f075684..223f4a3 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -92,10 +92,10 @@ Screen::Screen() m_viewport_ubo.SetType(GraphicsBuffer::BufferTypeUniform); m_debug_font_atlas = 0; - + m_no_quit_requested = true; m_view = NULL; ResizeViewport(800, 600); - + Clear(); Present(); @@ -128,13 +128,13 @@ void Screen::ResizeViewport(int width, int height) 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) @@ -183,7 +183,7 @@ bool Screen::PumpEvents() break; } } - return no_quit_requested; + return m_no_quit_requested; } void Screen::SetMouseCursor(Screen::MouseCursors cursor) diff --git a/src/screen.h b/src/screen.h index 85b3c27..6b52a09 100644 --- a/src/screen.h +++ b/src/screen.h @@ -69,6 +69,9 @@ namespace IPDF 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(); @@ -100,6 +103,7 @@ namespace IPDF int m_debug_font_vertex_head; int m_debug_font_index_head; View * m_view; + bool m_no_quit_requested; }; } diff --git a/src/tests/qtapp.cpp b/src/tests/qtapp.cpp new file mode 100644 index 0000000..126c1f3 --- /dev/null +++ b/src/tests/qtapp.cpp @@ -0,0 +1,16 @@ + +#include +#include + +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(); +} diff --git a/src/view.cpp b/src/view.cpp index e0efce9..a953579 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -3,6 +3,10 @@ #include "screen.h" #include "gl_core44.h" +#ifndef CONTROLPANEL_DISABLED + #include "controlpanel.h" +#endif //CONTROLPANEL_DISABLED + using namespace IPDF; using namespace std; @@ -239,6 +243,11 @@ void View::Render(int width, int height) m_cached_display.Blit(); // blit FrameBuffer to screen m_buffer_dirty = false; glPopDebugGroup(); + +#ifndef CONTROLPANEL_DISABLED + ControlPanel::Update(); +#endif //CONTROLPANEL_DISABLED + } #ifndef QUADTREE_DISABLED diff --git a/src/view.h b/src/view.h index e4254de..ff34415 100644 --- a/src/view.h +++ b/src/view.h @@ -36,13 +36,14 @@ namespace IPDF 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 {