Kstars

rectnode.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "rectnode.h"
7 
8 #include <QSGFlatColorMaterial>
9 #include <QSGGeometryNode>
10 
11 RectNode::RectNode(bool filled)
12 {
14  m_geometry->allocate(4);
15  setGeometry(m_geometry);
17 
18  m_material = new QSGFlatColorMaterial;
19  setMaterial(m_material);
21 
22  setFilled(filled);
23 }
24 
25 void RectNode::setRect(int x, int y, int w, int h)
26 {
27  QSGGeometry::Point2D *vertex = m_geometry->vertexDataAsPoint2D();
28  vertex[0].set(x, y);
29  vertex[1].set(x + w, y);
30  vertex[2].set(x + w, y + h);
31  vertex[3].set(x, y + h);
33 }
34 
35 void RectNode::setColor(const QColor &color)
36 {
37  if (m_material->color() != color)
38  {
39  m_material->setColor(color);
41  }
42 }
43 
44 void RectNode::setFilled(bool filled)
45 {
46  m_filled = filled;
47  if (filled)
48  {
49  m_geometry->setDrawingMode(GL_TRIANGLE_FAN);
50  }
51  else
52  {
53  m_geometry->setDrawingMode(GL_LINE_LOOP);
54  }
55 }
void setDrawingMode(unsigned int mode)
void setRect(int x, int y, int w, int h)
setRect sets rectangle to display
Definition: rectnode.cpp:25
void set(float x, float y)
void setColor(const QColor &color)
setColor sets the color of rectangle
Definition: rectnode.cpp:35
void setGeometry(QSGGeometry *geometry)
void setFilled(bool filled)
setFilled sets whether the rectangle should be filled or no
Definition: rectnode.cpp:44
const QColor & color() const const
const QSGGeometry::AttributeSet & defaultAttributes_Point2D()
void setMaterial(QSGMaterial *material)
void markDirty(QSGNode::DirtyState bits)
void setColor(const QColor &color)
void allocate(int vertexCount, int indexCount)
QSGGeometry::Point2D * vertexDataAsPoint2D()
void setFlag(QSGNode::Flag f, bool enabled)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:00:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.