Kstars

rectnode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "rectnode.h"
7
8#include <QSGFlatColorMaterial>
9#include <QSGGeometryNode>
10
11RectNode::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
25void 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
35void RectNode::setColor(const QColor &color)
36{
37 if (m_material->color() != color)
38 {
39 m_material->setColor(color);
41 }
42}
43
44void 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 setRect(int x, int y, int w, int h)
setRect sets rectangle to display
Definition rectnode.cpp:25
void setFilled(bool filled)
setFilled sets whether the rectangle should be filled or no
Definition rectnode.cpp:44
void setColor(const QColor &color)
setColor sets the color of rectangle
Definition rectnode.cpp:35
void setGeometry(QSGGeometry *geometry)
const QColor & color() const const
void setColor(const QColor &color)
void set(float x, float y)
void allocate(int vertexCount, int indexCount)
const AttributeSet & defaultAttributes_Point2D()
void setDrawingMode(unsigned int mode)
Point2D * vertexDataAsPoint2D()
void setMaterial(QSGMaterial *material)
void markDirty(DirtyState bits)
void setFlag(Flag f, bool enabled)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:51:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.