diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-04-09 16:03:28 -0400 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-04-09 16:03:28 -0400 |
commit | cb839e58e268c125fd3e6dd704370b4d0bde3cf8 (patch) | |
tree | 83bf15737450bf2c5a00ae392092d77c347321db /plugins/sigen_canvas_standard | |
parent | ce9e1a24c5ae67abbee16d02a43e42903ad644af (diff) | |
download | sigen-cb839e58e268c125fd3e6dd704370b4d0bde3cf8.tar.gz sigen-cb839e58e268c125fd3e6dd704370b4d0bde3cf8.tar.xz sigen-cb839e58e268c125fd3e6dd704370b4d0bde3cf8.zip |
Move the plugins out of sigencore
Diffstat (limited to 'plugins/sigen_canvas_standard')
-rw-r--r-- | plugins/sigen_canvas_standard/CMakeLists.txt | 38 | ||||
-rw-r--r-- | plugins/sigen_canvas_standard/SigenCanvases.cpp | 79 | ||||
-rw-r--r-- | plugins/sigen_canvas_standard/SigenCanvases.h | 41 | ||||
-rw-r--r-- | plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp | 112 | ||||
-rw-r--r-- | plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h | 62 | ||||
-rw-r--r-- | plugins/sigen_canvas_standard/sigen_canvases.desktop | 16 |
6 files changed, 348 insertions, 0 deletions
diff --git a/plugins/sigen_canvas_standard/CMakeLists.txt b/plugins/sigen_canvas_standard/CMakeLists.txt new file mode 100644 index 00000000..931659d4 --- /dev/null +++ b/plugins/sigen_canvas_standard/CMakeLists.txt @@ -0,0 +1,38 @@ +project(sigencanvases) + +set(sigencanvases_SRCS + SigenCanvases.cpp + qgraphicsscene/QGSCanvas.cpp +) +set(sigencanvases_SERVICES + sigen_canvases.desktop +) + +kde4_add_plugin(canvas_sigen + ${sigencanvases_SRCS} +) +target_link_libraries(canvas_sigen + ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} + ${KDE4_KDEUI_LIBRARY} + ${KDE4_KROSSCORE_LIBRARY} + sigencoreplugins +) + +install( + TARGETS + canvas_sigen + DESTINATION + ${PLUGIN_INSTALL_DIR} + COMPONENT + plugins +) + +install( + FILES + ${sigencanvases_SERVICES} + DESTINATION + ${SERVICES_INSTALL_DIR} + COMPONENT + plugins +) diff --git a/plugins/sigen_canvas_standard/SigenCanvases.cpp b/plugins/sigen_canvas_standard/SigenCanvases.cpp new file mode 100644 index 00000000..3969a56e --- /dev/null +++ b/plugins/sigen_canvas_standard/SigenCanvases.cpp @@ -0,0 +1,79 @@ +/* + * Copyright 2009 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "SigenCanvases.h" + +// Canvas includes +#include "qgraphicsscene/QGSCanvas.h" + +// Sigencore includes +#include <sigencore/Canvas.h> + +// KDE includes +#include <KIcon> + +SIGEN_CANVAS_PLUGIN_VERSION(SigenCanvases, "sigen_canvases", 000101) + +using namespace Sigscript; +using namespace Sigencore; +using namespace Sigencore::Plugins; + +SigenCanvases::SigenCanvases(QObject* parent, const QVariantList& args) : + CanvasPlugin(parent, args) +{ +} + +SigenCanvases::~SigenCanvases() +{ +} + +QStringList SigenCanvases::classList() const +{ + return QStringList() << QGSCanvas::name(); +} + +QString SigenCanvases::description(const QString& name) const +{ + if (name == QGSCanvas::name()) + return QGSCanvas::description(); + return "(Unknown canvas)"; +} + +QIcon SigenCanvases::icon(const QString& name) +{ + if (name == QGSCanvas::name()) + return QGSCanvas::icon(); + return KIcon(); +} + +Canvas* SigenCanvases::createCanvas(const QString& name, GameWrapper* game, Config* parent) +{ + if (name == QGSCanvas::name()) + return new QGSCanvas(game, parent); + return NULL; +} + +void SigenCanvases::cleanupCanvas(Canvas* canvas) +{ + QGSCanvas* qgsCanvas = qobject_cast<QGSCanvas*>(canvas); + if (qgsCanvas) + { + delete qgsCanvas; + return; + } +} diff --git a/plugins/sigen_canvas_standard/SigenCanvases.h b/plugins/sigen_canvas_standard/SigenCanvases.h new file mode 100644 index 00000000..6e0eaf22 --- /dev/null +++ b/plugins/sigen_canvas_standard/SigenCanvases.h @@ -0,0 +1,41 @@ +/* + * Copyright 2009 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGENCANVASES_SIGENCANVASES +#define SIGENCANVASES_SIGENCANVASES + +// Sigencore plugin includes +#include <sigencore/plugins/CanvasPlugin.h> + +class SigenCanvases : public Sigencore::Plugins::CanvasPlugin +{ + Q_OBJECT + + public: + SigenCanvases(QObject* parent, const QVariantList& args); + ~SigenCanvases(); + + QStringList classList() const; + QString description(const QString& name) const; + QIcon icon(const QString& name); + protected: + Sigencore::Canvas* createCanvas(const QString& name, Sigscript::GameWrapper* game, Sigscript::Config* parent); + protected slots: + void cleanupCanvas(Sigencore::Canvas* canvas); +}; + +#endif diff --git a/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp new file mode 100644 index 00000000..09f823b1 --- /dev/null +++ b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp @@ -0,0 +1,112 @@ +/* + * Copyright 2009 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "QGSCanvas.h" + +// Sigencore includes +#include <sigencore/RunScript.h> + +// Sigscript includes +#include <sigscript/GameWrapper.h> +#include <sigscript/SpriteWrapper.h> + +// KDE includes +#include <KIcon> +#include <kross/core/action.h> +#include <kross/core/actioncollection.h> +#include <kross/core/manager.h> + +// Qt includes +#include <QtCore/QUuid> +#include <QtGui/QGraphicsItem> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsView> + +using namespace Sigscript; +using namespace Sigencore; + +QGSCanvas::QGSCanvas(GameWrapper* game, Config* parent) : + Canvas(parent), + m_game(game), + m_scene(new QGraphicsScene), + m_collection(new Kross::ActionCollection(QString("canvas-%1").arg(QUuid::createUuid().toString()), Kross::Manager::self().actionCollection())) +{ +} + +QGSCanvas::~QGSCanvas() +{ + delete m_scene; + delete m_collection; +} + +QString QGSCanvas::name() +{ + return "QGraphicsScene canvas"; +} + +QString QGSCanvas::description() +{ + return "A canvas using QGraphicsScene"; +} + +QIcon QGSCanvas::icon() +{ + return KIcon(); +} + +void QGSCanvas::addSprite(const QString& name, const QString& sprite, const int x, const int y, const int zOrder) +{ + // TODO: NOOP or refresh? + if (m_items.contains(name)) + return; + SpriteWrapper* spr = m_game->sprite(sprite); + if (spr) + { + QGraphicsPixmapItem* item = new QGraphicsPixmapItem(spr->sprite()); + item->setPos(x, y); + item->setZValue(zOrder); + m_scene->addItem(item); + m_items[name] = item; + } +} + +void QGSCanvas::removeSprite(const QString& name) +{ + if (m_items.contains(name)) + { + delete m_items[name]; + m_items.remove(name); + } +} + +void QGSCanvas::transform(const QString& transform, const QString& object, const QVariantList& parameters) +{ +} + +int QGSCanvas::type() const +{ + return QGraphicsSceneCanvas; +} + +QWidget* QGSCanvas::viewport() +{ + // TODO: Only one view allowed? or as many as wanted? + QGraphicsView* view = new QGraphicsView; + view->setScene(m_scene); + return view; +} diff --git a/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h new file mode 100644 index 00000000..d779a3b3 --- /dev/null +++ b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h @@ -0,0 +1,62 @@ +/* + * Copyright 2009 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGENCANVASES_QGSCANVAS +#define SIGENCANVASES_QGSCANVAS + +// Sigencore includes +#include <sigencore/Canvas.h> + +// Forward declarations +namespace Kross +{ +class ActionCollection; +} +class QGraphicsItem; +class QGraphicsScene; +namespace Sigscript +{ +class GameWrapper; +} + +class QGSCanvas : public Sigencore::Canvas +{ + Q_OBJECT + + public: + QGSCanvas(Sigscript::GameWrapper* game, Sigscript::Config* parent); + ~QGSCanvas(); + + static QString name(); + static QString description(); + static QIcon icon(); + + Q_SCRIPTABLE void addSprite(const QString& name, const QString& sprite, const int x, const int y, const int zOrder); + Q_SCRIPTABLE void removeSprite(const QString& name); + Q_SCRIPTABLE void transform(const QString& transform, const QString& object, const QVariantList& parameters); + + int type() const; + + QWidget* viewport(); + private: + Sigscript::GameWrapper* m_game; + QGraphicsScene* m_scene; + QMap<QString, QGraphicsItem*> m_items; + Kross::ActionCollection* m_collection; +}; + +#endif diff --git a/plugins/sigen_canvas_standard/sigen_canvases.desktop b/plugins/sigen_canvas_standard/sigen_canvases.desktop new file mode 100644 index 00000000..7731030c --- /dev/null +++ b/plugins/sigen_canvas_standard/sigen_canvases.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Type=Service +X-KDE-ServiceTypes=Sigen/Canvas +Icon=sigen-canvasplugin +Name=Sigen Canvases +X-Sigen-MinVersion=0.1.1 +X-KDE-Library=canvas_sigen +X-KDE-PluginInfo-Author=Ben Boeckel +X-KDE-PluginInfo-Email=MathStuf@gmail.com +X-KDE-PluginInfo-Name=sigen_canvas +X-KDE-PluginInfo-Version=0.1.1 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category=canvas +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPLv3 +X-KDE-PluginInfo-EnabledByDefault=true |