Kstars

pointnode.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "pointnode.h"
7 
8 #include "Options.h"
9 #include "skymaplite.h"
10 #include "../../rootnode.h"
11 
12 #include <QQuickWindow>
13 #include <QSGSimpleTextureNode>
14 
15 PointNode::PointNode(RootNode *p, char sp, float size)
16  : spType(sp), texture(new QSGSimpleTextureNode), m_rootNode(p),
17  starColorMode(Options::starColorMode())
18 {
19  appendChildNode(texture);
20  setSize(size);
21 }
22 
23 void PointNode::setSize(float size)
24 {
25  int isize = qMin(static_cast<int>(size), 14);
26  uint newStarCM = Options::starColorMode();
27  if (size != m_size || newStarCM != starColorMode)
28  {
29  texture->setTexture(m_rootNode->getCachedTexture(isize, spType));
30 
31  //We divide size of texture by ratio. Otherwise texture will be very large
32  qreal ratio = SkyMapLite::Instance()->window()->effectiveDevicePixelRatio();
33 
34  QSize tSize = texture->texture()->textureSize();
35  QRectF oldRect = texture->rect();
36  texture->setRect(QRect(oldRect.x(), oldRect.y(), tSize.width() / ratio, tSize.height() / ratio));
37  m_size = size;
38  starColorMode = newStarCM;
39  }
40 }
41 
42 QSizeF PointNode::size() const
43 {
44  return texture->rect().size();
45 }
QSGTexture * getCachedTexture(int size, char spType)
returns cached texture from textureCache
Definition: rootnode.cpp:185
virtual QSize textureSize() const const=0
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
qreal x() const const
qreal y() const const
QQuickWindow * window() const const
void appendChildNode(QSGNode *node)
void setRect(const QRectF &r)
int width() const const
QRectF rect() const const
int height() const const
void setSize(float size)
setSize update size of PointNode with the given parameter
Definition: pointnode.cpp:23
QSGTexture * texture() const const
QSizeF size() const const
void setTexture(QSGTexture *texture)
qreal effectiveDevicePixelRatio() const const
PointNode(RootNode *p, char sp='A', float size=1)
Constructor.
Definition: pointnode.cpp:15
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 04:01:56 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.