Add QtahRasterWindow and QtahOpenGLWindow to be able to handle paint events.

Listening for QPaintEvent on QRasterWindow seems not to work, so let's
create subclasses on which we can set callbacks instead.

We need support for default-constructed callback functors on Hoppy for
this to work, hence the Hoppy dependency bump.
parent d1dec8b1
#ifndef QTAH_WRAP_QOPENGLWINDOW_HPP
#define QTAH_WRAP_QOPENGLWINDOW_HPP
// This file is part of Qtah.
//
// Copyright 2017 Bryan Gardiner <bog@khumba.net>
//
// This program 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.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#if QT_VERSION >= 0x050400
#include <QOpenGLWindow>
#include <QtGlobal>
#include "b_callback.hpp"
namespace qtah {
namespace qtahopenglwindow {
class QtahOpenGLWindow : public QOpenGLWindow {
public:
QtahOpenGLWindow(UpdateBehavior updateBehavior = NoPartialUpdate, QWindow* parent = Q_NULLPTR)
: QOpenGLWindow(updateBehavior, parent) {}
QtahOpenGLWindow(
QOpenGLContext* shareContext,
UpdateBehavior updateBehavior = NoPartialUpdate,
QWindow *parent = Q_NULLPTR)
: QOpenGLWindow(shareContext, updateBehavior, parent) {}
virtual ~QtahOpenGLWindow() {}
virtual void onInitializeGL() {
if (onInitializeGL_) {
onInitializeGL_();
}
}
virtual void onPaintGL() {
if (onPaintGL_) {
onPaintGL_();
}
}
virtual void onPaintOverGL() {
if (onPaintOverGL_) {
onPaintOverGL_();
}
}
virtual void onPaintUnderGL() {
if (onPaintUnderGL_) {
onPaintUnderGL_();
}
}
virtual void onResizeGL(int width, int height) {
if (onResizeGL_) {
onResizeGL_(width, height);
}
}
void onInitializeGL(CallbackVoid handler) {
onInitializeGL_ = handler;
}
void onPaintGL(CallbackVoid handler) {
onPaintGL_ = handler;
}
void onPaintOverGL(CallbackVoid handler) {
onPaintOverGL_ = handler;
}
void onPaintUnderGL(CallbackVoid handler) {
onPaintUnderGL_ = handler;
}
void onResizeGL(CallbackIntIntVoid handler) {
onResizeGL_ = handler;
}
private:
CallbackVoid onInitializeGL_;
CallbackVoid onPaintGL_;
CallbackVoid onPaintOverGL_;
CallbackVoid onPaintUnderGL_;
CallbackIntIntVoid onResizeGL_;
};
} // namespace qtahopenglwindow
} // namespace qtah
#endif
#endif // QTAH_WRAP_QOPENGLWINDOW_HPP
#ifndef QTAH_WRAP_QRASTERWINDOW_HPP
#define QTAH_WRAP_QRASTERWINDOW_HPP
// This file is part of Qtah.
//
// Copyright 2017 Bryan Gardiner <bog@khumba.net>
//
// This program 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.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#if QT_VERSION >= 0x050400
#include <QRasterWindow>
#include <QtGlobal>
#include "b_callback.hpp"
namespace qtah {
namespace qtahrasterwindow {
class QtahRasterWindow : public QRasterWindow {
public:
QtahRasterWindow(QWindow* parent = Q_NULLPTR) : QRasterWindow(parent) {}
virtual ~QtahRasterWindow() {}
virtual void paintEvent(QPaintEvent* paintEvent) {
if (onPaintEvent_) {
onPaintEvent_(paintEvent);
}
}
void onPaintEvent(CallbackPtrQPaintEventVoid handler) {
onPaintEvent_ = handler;
}
private:
CallbackPtrQPaintEventVoid onPaintEvent_;
};
} // namespace qtahrasterwindow
} // namespace qtah
#endif
#endif // QTAH_WRAP_QRASTERWINDOW_HPP
......@@ -41,7 +41,7 @@ executable qtah-generator
, containers >=0.5 && <0.6
, directory >=1.2 && <1.4
, filepath >=1.3 && <1.5
, hoppy-generator >=0.3 && <0.4
, hoppy-generator >=0.3.3 && <0.4
, hoppy-std >=0.3 && <0.4
, haskell-src >=1.0 && <1.1
, mtl >=2.1 && <2.3
......@@ -118,6 +118,8 @@ executable qtah-generator
, Graphics.UI.Qtah.Generator.Interface.Gui.QValidator
, Graphics.UI.Qtah.Generator.Interface.Gui.QWheelEvent
, Graphics.UI.Qtah.Generator.Interface.Gui.QWindow
, Graphics.UI.Qtah.Generator.Interface.Gui.QtahOpenGLWindow
, Graphics.UI.Qtah.Generator.Interface.Gui.QtahRasterWindow
, Graphics.UI.Qtah.Generator.Interface.Imports
, Graphics.UI.Qtah.Generator.Interface.Internal
, Graphics.UI.Qtah.Generator.Interface.Internal.Callback
......
......@@ -50,6 +50,8 @@ import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QTransform as QTransfo
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QValidator as QValidator
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QWheelEvent as QWheelEvent
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QWindow as QWindow
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QtahOpenGLWindow as QtahOpenGLWindow
import qualified Graphics.UI.Qtah.Generator.Interface.Gui.QtahRasterWindow as QtahRasterWindow
import Graphics.UI.Qtah.Generator.Module (AModule)
{-# ANN module "HLint: ignore Use camelCase" #-}
......@@ -89,4 +91,6 @@ modules =
, QValidator.aModule
, QWheelEvent.aModule
, QWindow.aModule
, QtahOpenGLWindow.aModule
, QtahRasterWindow.aModule
]
......@@ -16,8 +16,10 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
module Graphics.UI.Qtah.Generator.Interface.Gui.QOpenGLWindow (
minVersion,
aModule,
c_QOpenGLWindow,
e_UpdateBehavior,
) where
import Foreign.Hoppy.Generator.Spec (
......
......@@ -16,6 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
module Graphics.UI.Qtah.Generator.Interface.Gui.QRasterWindow (
minVersion,
aModule,
c_QRasterWindow,
) where
......
-- This file is part of Qtah.
--
-- Copyright 2017 Bryan Gardiner <bog@khumba.net>
--
-- This program 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.
--
-- This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
module Graphics.UI.Qtah.Generator.Interface.Gui.QtahOpenGLWindow (
aModule,
c_QtahOpenGLWindow,
) where
import Foreign.Hoppy.Generator.Spec (
Export (ExportClass),
addReqIncludes,
classSetEntityPrefix,
ident2,
includeLocal,
makeClass,
mkCtor,
mkMethod,
)
import Foreign.Hoppy.Generator.Types (callbackT, enumT, objT, ptrT, voidT)
import Graphics.UI.Qtah.Generator.Interface.Gui.QOpenGLWindow (
c_QOpenGLWindow,
e_UpdateBehavior,
minVersion,
)
import Graphics.UI.Qtah.Generator.Interface.Gui.QWindow (c_QWindow)
import Graphics.UI.Qtah.Generator.Interface.Internal.Callback (cb_Void, cb_IntIntVoid)
import Graphics.UI.Qtah.Generator.Module (AModule (AQtModule), makeQtModuleWithMinVersion)
import Graphics.UI.Qtah.Generator.Types
{-# ANN module "HLint: ignore Use camelCase" #-}
aModule =
AQtModule $
makeQtModuleWithMinVersion ["Gui", "QtahOpenGLWindow"] minVersion $
[ QtExport $ ExportClass c_QtahOpenGLWindow ]
c_QtahOpenGLWindow =
addReqIncludes [includeLocal "qtahopenglwindow.hpp"] $
classSetEntityPrefix "" $
makeClass (ident2 "qtah" "qtahopenglwindow" "QtahOpenGLWindow") Nothing [c_QOpenGLWindow]
[ mkCtor "new" []
, mkCtor "newWithUpdateBehavior" [enumT e_UpdateBehavior]
, mkCtor "newWithUpdateBehaviorAndParent" [enumT e_UpdateBehavior, ptrT $ objT c_QWindow]
-- TODO QtahOpenGLWindow(QOpenGLContext*, ...)
-- TODO QOpenGLContext* context() const
, mkMethod "onInitializeGL" [callbackT cb_Void] voidT
, mkMethod "onPaintGL" [callbackT cb_Void] voidT
, mkMethod "onPaintOverGL" [callbackT cb_Void] voidT
, mkMethod "onPaintUnderGL" [callbackT cb_Void] voidT
, mkMethod "onResizeGL" [callbackT cb_IntIntVoid] voidT
]
-- This file is part of Qtah.
--
-- Copyright 2017 Bryan Gardiner <bog@khumba.net>
--
-- This program 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.
--
-- This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
module Graphics.UI.Qtah.Generator.Interface.Gui.QtahRasterWindow (
aModule,
c_QtahRasterWindow,
) where
import Foreign.Hoppy.Generator.Spec (
Export (ExportClass),
addReqIncludes,
classSetEntityPrefix,
ident2,
includeLocal,
makeClass,
mkCtor,
mkMethod,
)
import Foreign.Hoppy.Generator.Types (callbackT, objT, ptrT, voidT)
import Graphics.UI.Qtah.Generator.Interface.Gui.QRasterWindow (c_QRasterWindow, minVersion)
import Graphics.UI.Qtah.Generator.Interface.Gui.QWindow (c_QWindow)
import Graphics.UI.Qtah.Generator.Interface.Internal.Callback (cb_PtrQPaintEventVoid)
import Graphics.UI.Qtah.Generator.Module (AModule (AQtModule), makeQtModuleWithMinVersion)
import Graphics.UI.Qtah.Generator.Types
{-# ANN module "HLint: ignore Use camelCase" #-}
aModule =
AQtModule $
makeQtModuleWithMinVersion ["Gui", "QtahRasterWindow"] minVersion $
[ QtExport $ ExportClass c_QtahRasterWindow ]
c_QtahRasterWindow =
addReqIncludes [includeLocal "qtahrasterwindow.hpp"] $
classSetEntityPrefix "" $
makeClass (ident2 "qtah" "qtahrasterwindow" "QtahRasterWindow") Nothing [c_QRasterWindow]
[ mkCtor "new" []
, mkCtor "newWithParent" [ptrT $ objT c_QWindow]
, mkMethod "onPaintEvent" [callbackT cb_PtrQPaintEventVoid] voidT
]
......@@ -57,6 +57,7 @@ import Graphics.UI.Qtah.Generator.Interface.Core.Types (
qreal,
)
import {-# SOURCE #-} qualified Graphics.UI.Qtah.Generator.Interface.Gui.QClipboard as QClipboard
import Graphics.UI.Qtah.Generator.Interface.Gui.QPaintEvent (c_QPaintEvent)
import {-# SOURCE #-} qualified Graphics.UI.Qtah.Generator.Interface.Gui.QWindow as QWindow
import {-# SOURCE #-} Graphics.UI.Qtah.Generator.Interface.Widgets.QAbstractButton
(c_QAbstractButton)
......@@ -85,6 +86,7 @@ aModule =
, just $ ExportCallback cb_PtrQGraphicsItemPtrQEventBool
, just $ ExportCallback cb_PtrQObjectPtrQEventBool
, just $ ExportCallback cb_PtrQObjectVoid
, just $ ExportCallback cb_PtrQPaintEventVoid
, just $ ExportCallback cb_PtrQWidgetPtrQWidgetVoid
, just $ ExportCallback cb_QAbstractSliderActionVoid
, just $ ExportCallback cb_QClipboardModeVoid
......@@ -153,6 +155,10 @@ cb_PtrQObjectVoid =
makeCallback (toExtName "CallbackPtrQObjectVoid")
[ptrT $ objT c_QObject] voidT
cb_PtrQPaintEventVoid =
makeCallback (toExtName "CallbackPtrQPaintEventVoid")
[ptrT $ objT c_QPaintEvent] voidT
cb_PtrQWidgetPtrQWidgetVoid =
makeCallback (toExtName "CallbackPtrQWidgetPtrQWidgetVoid")
[ptrT $ objT c_QWidget, ptrT $ objT c_QWidget] voidT
......
......@@ -105,6 +105,8 @@ library
, Graphics.UI.Qtah.Gui.QValidator
, Graphics.UI.Qtah.Gui.QWheelEvent
, Graphics.UI.Qtah.Gui.QWindow
, Graphics.UI.Qtah.Gui.QtahOpenGLWindow
, Graphics.UI.Qtah.Gui.QtahRasterWindow
, Graphics.UI.Qtah.SceneEvent
, Graphics.UI.Qtah.Signal
-- TODO This should not be exposed directly, but there is no nice interface
......@@ -244,6 +246,8 @@ library
, Graphics.UI.Qtah.Generated.Gui.QValidator
, Graphics.UI.Qtah.Generated.Gui.QWheelEvent
, Graphics.UI.Qtah.Generated.Gui.QWindow
, Graphics.UI.Qtah.Generated.Gui.QtahOpenGLWindow
, Graphics.UI.Qtah.Generated.Gui.QtahRasterWindow
, Graphics.UI.Qtah.Generated.Internal.EventListener
, Graphics.UI.Qtah.Generated.Internal.SceneEventListener
, Graphics.UI.Qtah.Generated.Widgets.QAbstractButton
......
......@@ -45,7 +45,7 @@ packages:
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps:
- hoppy-generator-0.3.2
- hoppy-generator-0.3.3
- hoppy-runtime-0.3.0
- hoppy-std-0.3.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment