File indexing completed on 2024-05-05 17:55:01
0001 /***************************************************************************** 0002 * Copyright 2007 Matthew Woehlke <mw_triad@users.sourceforge.net> * 0003 * Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com> * 0004 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU Lesser General Public License as * 0008 * published by the Free Software Foundation; either version 2.1 of the * 0009 * License, or (at your option) version 3, or any later version accepted * 0010 * by the membership of KDE e.V. (or its successor approved by the * 0011 * membership of KDE e.V.), which shall act as a proxy defined in * 0012 * Section 6 of version 3 of the license. * 0013 * * 0014 * This program is distributed in the hope that it will be useful, * 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0017 * Lesser General Public License for more details. * 0018 * * 0019 * You should have received a copy of the GNU Lesser General Public * 0020 * License along with this library. If not, * 0021 * see <http://www.gnu.org/licenses/>. * 0022 *****************************************************************************/ 0023 0024 #ifndef TILESET_H 0025 #define TILESET_H 0026 0027 #include <QPixmap> 0028 #include <QRect> 0029 #include <QVector> 0030 0031 //! handles proper scaling of pixmap to match widget rect. 0032 /*! 0033 tilesets are collections of stretchable pixmaps corresponding to a given widget corners, sides, and center. 0034 corner pixmaps are never stretched. center pixmaps are 0035 */ 0036 class TileSet { 0037 public: 0038 /** 0039 * Create a TileSet from a pixmap. The size of the bottom/right chunks is 0040 * whatever is left over from the other chunks, whose size is specified 0041 * in the required parameters. 0042 * 0043 * @param w1 width of the left chunks 0044 * @param h1 height of the top chunks 0045 * @param w2 width of the not-left-or-right chunks 0046 * @param h2 height of the not-top-or-bottom chunks 0047 */ 0048 TileSet(const QPixmap&, int w1, int h1, int w2, int h2); 0049 0050 /** 0051 * Create a TileSet from a pixmap. The size of the top/left and bottom/right 0052 * chunks is specified, with the middle chunks created from the specified 0053 * portion of the pixmap. This allows the middle chunks to overlap the outer 0054 * chunks (or to not use all pixels). The top/left and bottom/right chunks 0055 * are carved out of the corners of the pixmap. 0056 * 0057 * @param w1 width of the left chunks 0058 * @param h1 height of the top chunks 0059 * @param w3 width of the right chunks 0060 * @param h3 height of bottom chunks 0061 * @param x2 x-coordinate of the top of the not-left-or-right chunks 0062 * @param y2 y-coordinate of the left of the not-top-or-bottom chunks 0063 * @param w2 width of the not-left-or-right chunks 0064 * @param h2 height of the not-top-or-bottom chunks 0065 */ 0066 TileSet(const QPixmap &pix, int w1, int h1, int w3, int h3, int x2, int y2, int w2, int h2); 0067 0068 //! empty constructor 0069 TileSet(); 0070 0071 /** 0072 * Flags specifying what sides to draw in ::render. Corners are drawn when 0073 * the sides forming that corner are drawn, e.g. Top|Left draws the 0074 * top-center, center-left, and top-left chunks. The center-center chunk is 0075 * only drawn when Center is requested. 0076 */ 0077 enum Tile { 0078 Top = 0x1, 0079 Left = 0x2, 0080 Right = 0x8, 0081 Bottom = 0x4, 0082 Center = 0x10, 0083 Ring = 0x0f, 0084 Horizontal = 0x1a, 0085 Vertical = 0x15, 0086 Full = 0x1f 0087 }; 0088 Q_DECLARE_FLAGS(Tiles, Tile) 0089 0090 /** 0091 * Fills the specified rect with tiled chunks. Corners are never tiled, 0092 * edges are tiled in one direction, and the center chunk is tiled in both 0093 * directions. Partial tiles are used as needed so that the entire rect is 0094 * perfectly filled. Filling is performed as if all chunks are being drawn. 0095 */ 0096 void render(const QRect&, QPainter*, Tiles = Ring) const; 0097 0098 protected: 0099 // initialize pixmap 0100 void initPixmap( int, const QPixmap&, int w, int h, const QRect ®ion); 0101 0102 //! pixmap arry 0103 QVector<QPixmap> _pixmap; 0104 0105 // dimensions 0106 int _w1; 0107 int _h1; 0108 int _w3; 0109 int _h3; 0110 }; 0111 0112 Q_DECLARE_OPERATORS_FOR_FLAGS(TileSet::Tiles) 0113 0114 #endif //TILESET_H