Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • graphics
  • bitmap
tiledbuffer.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2012-2020 Matthew Chiawen Chang
5
6This program is free software; you can redistribute it and/or
7modify it under the terms of the GNU General Public License
8as published by the Free Software Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15*/
16#ifndef TILEDBUFFER_H
17#define TILEDBUFFER_H
18
19#include <QPainter>
20#include <QHash>
21
22#include "blitrect.h"
23
24class QImage;
25class QRect;
26class Tile;
27
28struct TileIndex {
29 int x;
30 int y;
31};
32
33#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
34inline uint qHash(const TileIndex &key, uint seed)
35#else
36inline size_t qHash(const TileIndex &key, size_t seed)
37#endif
38{
39 return qHash(key.x, seed) ^ key.y;
40}
41
42inline bool operator==(const TileIndex &e1, const TileIndex &e2)
43{
44 return e1.x == e2.x
45 && e1.y == e2.y;
46}
47
48class TiledBuffer: public QObject
49{
50 Q_OBJECT
51public:
52 TiledBuffer(QObject* parent = nullptr);
53 ~TiledBuffer();
54
56 void clear();
57
59 bool isValid() const { return !mTiles.isEmpty(); }
60
62 void drawBrush(QPointF point, qreal brushWidth, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing);
64 void drawPath(QPainterPath path, QPen pen, QBrush brush,
65 QPainter::CompositionMode cm, bool antialiasing);
67 void drawImage(const QImage& image, const QRect& imageBounds, QPainter::CompositionMode cm, bool antialiasing);
68
69 QHash<TileIndex, Tile*> tiles() const { return mTiles; }
70
71 const QRect& bounds() const { return mTileBounds; }
72
73signals:
74 void tileUpdated(TiledBuffer* tiledBuffer, Tile* tile);
75 void tileCreated(TiledBuffer* tiledBuffer, Tile* tile);
76
77private:
78
79 Tile* getTileFromIndex(const TileIndex& tileIndex);
80
81 inline QPoint getTilePos(const TileIndex& index) const;
82
83 const int UNIFORM_TILE_SIZE = 64;
84
85 BlitRect mTileBounds;
86
87 QHash<TileIndex, Tile*> mTiles;
88};
89
90#endif // TILEDBUFFER_H
BlitRect
Definition: blitrect.h:25
Tile
Definition: tile.h:24
TiledBuffer
Definition: tiledbuffer.h:49
TiledBuffer::drawPath
void drawPath(QPainterPath path, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing)
Draws a path with the specified parameters to the tiled buffer.
Definition: tiledbuffer.cpp:128
TiledBuffer::clear
void clear()
Clears the content of the tiled buffer.
Definition: tiledbuffer.cpp:161
TiledBuffer::isValid
bool isValid() const
Returns true if there are any tiles, otherwise false.
Definition: tiledbuffer.h:59
TiledBuffer::drawImage
void drawImage(const QImage &image, const QRect &imageBounds, QPainter::CompositionMode cm, bool antialiasing)
Draws a image with the specified parameters to the tiled buffer.
Definition: tiledbuffer.cpp:99
TiledBuffer::drawBrush
void drawBrush(QPointF point, qreal brushWidth, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing)
Draws a brush with the specified parameters to the tiled buffer.
Definition: tiledbuffer.cpp:51
QBrush
QHash
QHash::isEmpty
bool isEmpty() const const
QImage
QObject
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
QObject::parent
QObject * parent() const const
QPainter::CompositionMode
CompositionMode
QPainterPath
QPen
QPoint
QPointF
QRect
TileIndex
Definition: tiledbuffer.h:28
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39