Added new qml module for drawing lines
This commit is contained in:
44
src/lineItem.cpp
Normal file
44
src/lineItem.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "rqt_demo_plugin/lineItem.hpp"
|
||||
#include <qquickitem.h>
|
||||
#include <qsgflatcolormaterial.h>
|
||||
#include <qsggeometry.h>
|
||||
#include <qsgnode.h>
|
||||
#include <qsize.h>
|
||||
|
||||
LineItem::LineItem(QQuickItem *parent)
|
||||
: QQuickItem(parent)
|
||||
, stupid_("")
|
||||
{
|
||||
setFlag(ItemHasContents, true);
|
||||
}
|
||||
|
||||
LineItem::~LineItem() = default;
|
||||
|
||||
|
||||
QSGNode *LineItem::updatePaintNode(QSGNode *old, UpdatePaintNodeData *)
|
||||
{
|
||||
QSGGeometryNode *node = nullptr;
|
||||
QSGGeometry *geometry = nullptr;
|
||||
|
||||
if(!old) {
|
||||
node = new QSGGeometryNode;
|
||||
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 4);
|
||||
geometry->setLineWidth(5);
|
||||
geometry->setDrawingMode(QSGGeometry::DrawLines);
|
||||
node->setGeometry(geometry);
|
||||
node->setFlag(QSGNode::OwnsGeometry);
|
||||
auto *material = new QSGFlatColorMaterial;
|
||||
material->setColor(QColor(255,0,0));
|
||||
node->setMaterial(material);
|
||||
node->setFlag(QSGNode::OwnsMaterial);
|
||||
|
||||
QSGGeometry::Point2D *verticies = geometry->vertexDataAsPoint2D();
|
||||
QSizeF s = size();
|
||||
verticies[0].set(0.1 * s.width(), 0.1 * s.height());
|
||||
verticies[1].set(0.75 * s.width(), 0.75 * s.height());
|
||||
verticies[2].set(0.1 * s.width(), 0.9 * s.height());
|
||||
verticies[3].set(0.9 * s.width(), 0.1 * s.height());
|
||||
node->markDirty(QSGNode::DirtyGeometry);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
#include "rqt_demo_plugin/rqt_demo_plugin.hpp"
|
||||
#include "rqt_demo_plugin/lineItem.hpp"
|
||||
|
||||
#include "pluginlib/class_list_macros.hpp"
|
||||
#include <qnamespace.h>
|
||||
@ -10,4 +11,9 @@ mg::DemoPluginMg::DemoPluginMg() : Plugin() {
|
||||
fmt.setSwapInterval(0);
|
||||
fmt.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
QSurfaceFormat::setDefaultFormat(fmt);
|
||||
static bool typesRegistered = 0;
|
||||
if(!typesRegistered) {
|
||||
qmlRegisterType<LineItem>("LineItem", 1, 0, "LineItem");
|
||||
typesRegistered = 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user