From 29639f5b6da42fc976c883351ef508020f821b59 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 26 Nov 2016 18:58:14 +0100 Subject: New MainWindow. --- plugingui/Makefile.am.plugingui | 1 + plugingui/Makefile.mingw32 | 4 ++ plugingui/mainwindow.cc | 103 ++++++++++++++++++++++++++++++++++++++++ plugingui/mainwindow.h | 75 +++++++++++++++++++++++++++++ plugingui/nativewindow_x11.cc | 3 -- plugingui/testmain.cc | 46 +++++------------- 6 files changed, 194 insertions(+), 38 deletions(-) create mode 100644 plugingui/mainwindow.cc create mode 100644 plugingui/mainwindow.h diff --git a/plugingui/Makefile.am.plugingui b/plugingui/Makefile.am.plugingui index 42824cc..d790f64 100644 --- a/plugingui/Makefile.am.plugingui +++ b/plugingui/Makefile.am.plugingui @@ -16,6 +16,7 @@ PLUGIN_GUI_SOURCES = \ $(top_srcdir)/plugingui/lineedit.cc \ $(top_srcdir)/plugingui/led.cc \ $(top_srcdir)/plugingui/checkbox.cc \ + $(top_srcdir)/plugingui/mainwindow.cc \ $(top_srcdir)/plugingui/slider.cc \ $(top_srcdir)/plugingui/scrollbar.cc \ $(top_srcdir)/plugingui/stackedwidget.cc \ diff --git a/plugingui/Makefile.mingw32 b/plugingui/Makefile.mingw32 index 68d70bc..33a8f54 100644 --- a/plugingui/Makefile.mingw32 +++ b/plugingui/Makefile.mingw32 @@ -24,12 +24,16 @@ GUI_SRC = \ lineedit.cc \ led.cc \ layout.cc \ + mainwindow.cc \ checkbox.cc \ slider.cc \ scrollbar.cc \ + stackedwidget.cc \ textedit.cc \ texture.cc \ texturedbox.cc \ + tabbutton.cc \ + tabwidget.cc \ listbox.cc \ listboxthin.cc \ listboxbasic.cc \ diff --git a/plugingui/mainwindow.cc b/plugingui/mainwindow.cc new file mode 100644 index 0000000..cff6b04 --- /dev/null +++ b/plugingui/mainwindow.cc @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * mainwindow.cc + * + * Sat Nov 26 14:27:29 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "mainwindow.h" + +#include + +#include "painter.h" + +namespace GUI +{ + +MainWindow::MainWindow(Settings& settings, void* native_window) + : Window(native_window) + , settings(settings) +{ + CONNECT(this, sizeChangeNotifier, this, &MainWindow::sizeChanged); + CONNECT(eventHandler(), closeNotifier, this, &MainWindow::closeEventHandler); + resize(370, 330); + tabs.move(16, 0); // x-offset to make room for the left side bar. + setCaption("DrumGizmo v" VERSION); +} + +bool MainWindow::processEvents() +{ +// if(!initialised) +// { +// return running; +// } + + eventHandler()->processEvents(); + + { + Painter p(*this); + settings_notifier.evaluate(); + } + + if(closing) + { + closeNotifier(); + closing = false; + return false; + } + + return true; +} + +void MainWindow::repaintEvent(RepaintEvent* repaintEvent) +{ + if(!visible()) + { + return; + } + + Painter painter(*this); + + // Grey background + painter.drawImageStretched(0, 0, back, width(), height()); + + // DrumGizmo logo + painter.drawImage(width() - logo.width() - 16, + height() - logo.height(), logo); + + // Sidebars + sidebar.setSize(16, height()); + painter.drawImage(0, 0, sidebar); + painter.drawImage(width() - 16, 0, sidebar); +} + +void MainWindow::sizeChanged(int width, int height) +{ + tabs.resize(width - 2 * 16, height); +} + +void MainWindow::closeEventHandler() +{ + closing = true; +} + +} // GUI:: diff --git a/plugingui/mainwindow.h b/plugingui/mainwindow.h new file mode 100644 index 0000000..bfef4a0 --- /dev/null +++ b/plugingui/mainwindow.h @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * mainwindow.h + * + * Sat Nov 26 14:27:28 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +#include + +#include "window.h" +#include "tabwidget.h" +#include "texturedbox.h" +#include "image.h" + +namespace GUI +{ + +class MainWindow + : public Window +{ +public: + MainWindow(Settings& settings, void* native_window); + + //! Process all events and messages in queue + //! \return true if not closing, returns false if closing. + bool processEvents(); + + //! Notify when window is closing. + Notifier<> closeNotifier; + +private: + void sizeChanged(int width, int height); + void closeEventHandler(); + + // From Widget + void repaintEvent(RepaintEvent* repaintEvent) override final; + + TabWidget tabs{this}; + + Image back{":bg.png"}; + Image logo{":logo.png"}; + + TexturedBox sidebar{getImageCache(), ":sidebar.png", + 0, 0, // offset + 16, 0, 0, // delta-x + 14, 1, 14}; // delta-y + + bool closing{false}; + + Settings& settings; + SettingsNotifier settings_notifier{settings}; +}; + +} // GUI:: diff --git a/plugingui/nativewindow_x11.cc b/plugingui/nativewindow_x11.cc index b579fb3..5d239ea 100644 --- a/plugingui/nativewindow_x11.cc +++ b/plugingui/nativewindow_x11.cc @@ -89,9 +89,6 @@ NativeWindowX11::NativeWindowX11(void* native_window, Window& window) int count = sizeof(protocols)/sizeof(Atom); XSetWMProtocols(display, xwindow, protocols, count); - // "Map" the window (that is, make it appear on the screen) - XMapWindow(display, xwindow); - // Create a "Graphics Context" gc = XCreateGC(display, xwindow, 0, nullptr); } diff --git a/plugingui/testmain.cc b/plugingui/testmain.cc index 84d813d..c4ca18d 100644 --- a/plugingui/testmain.cc +++ b/plugingui/testmain.cc @@ -24,56 +24,32 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include "plugingui.h" - #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include #endif #include - -#include #include -class TestMain : public Listener { -public: - TestMain() - { - CONNECT(&gui, closeNotifier, this, &TestMain::stop); - } +#include "mainwindow.h" - void stop() - { - DEBUG(stop, "Stopping...\n"); - running = false; - } +int main() +{ + INFO(example, "We are up and running"); - void run() + Settings settings; + GUI::MainWindow main_window(settings, nullptr); + main_window.show(); + + while(main_window.processEvents()) { - while(running) - { #ifdef WIN32 - SleepEx(50, FALSE); + SleepEx(50, FALSE); #else - usleep(50000); + usleep(50000); #endif - gui.processEvents(); - } } - bool running = true; - - Settings settings; - GUI::PluginGUI gui{settings}; -}; - -int main() -{ - INFO(example, "We are up and running"); - - TestMain testMain; - testMain.run(); - return 0; } -- cgit v1.2.3