1
#ifndef oxygentileset_h
2
#define oxygentileset_h
5
* Copyright 2009-2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
6
* Copyright 2008 Long Huynh Huu <long.upcase@googlemail.com>
7
* Copyright 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Library General Public
11
* License version 2 as published by the Free Software Foundation.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Library General Public License for more details.
18
* You should have received a copy of the GNU Library General Public License
19
* along with this library; see the file COPYING.LIB. If not, write to
20
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
* Boston, MA 02110-1301, USA.
24
#include "oxygen_export.h"
26
#include <QtGui/QPixmap>
27
#include <QtCore/QRect>
28
#include <QtCore/QVector>
32
//! handles proper scaling of pixmap to match widget rect.
34
tilesets are collections of stretchable pixmaps corresponding to a given widget corners, sides, and center.
35
corner pixmaps are never stretched. center pixmaps are
39
class OXYGEN_EXPORT TileSet
43
Create a TileSet from a pixmap. The size of the bottom/right chunks is
44
whatever is left over from the other chunks, whose size is specified
45
in the required parameters.
47
@param w1 width of the left chunks
48
@param h1 height of the top chunks
49
@param w2 width of the not-left-or-right chunks
50
@param h2 height of the not-top-or-bottom chunks
52
TileSet(const QPixmap&, int w1, int h1, int w2, int h2);
55
Create a TileSet from a pixmap. The size of the top/left and bottom/right
56
chunks is specified, with the middle chunks created from the specified
57
portion of the pixmap. This allows the middle chunks to overlap the outer
58
chunks (or to not use all pixels). The top/left and bottom/right chunks
59
are carved out of the corners of the pixmap.
61
@param w1 width of the left chunks
62
@param h1 height of the top chunks
63
@param w3 width of the right chunks
64
@param h3 height of bottom chunks
65
@param x2 x-coordinate of the top of the not-left-or-right chunks
66
@param y2 y-coordinate of the left of the not-top-or-bottom chunks
67
@param w2 width of the not-left-or-right chunks
68
@param h2 height of the not-top-or-bottom chunks
70
TileSet(const QPixmap &pix, int w1, int h1, int w3, int h3, int x2, int y2, int w2, int h2);
80
Flags specifying what sides to draw in ::render. Corners are drawn when
81
the sides forming that corner are drawn, e.g. Top|Left draws the
82
top-center, center-left, and top-left chunks. The center-center chunk is
83
only drawn when Center is requested.
93
BottomLeft = Bottom|Left,
94
BottomRight = Bottom|Right,
95
Ring = Top|Left|Bottom|Right,
96
Horizontal = Left|Right|Center,
97
Vertical = Top|Bottom|Center,
100
Q_DECLARE_FLAGS(Tiles, Tile)
103
Fills the specified rect with tiled chunks. Corners are never tiled,
104
edges are tiled in one direction, and the center chunk is tiled in both
105
directions. Partial tiles are used as needed so that the entire rect is
106
perfectly filled. Filling is performed as if all chunks are being drawn.
108
void render(const QRect&, QPainter*, Tiles = Ring) const;
110
//! return size associated to this tileset
111
QSize size( void ) const
112
{ return QSize( _w1 + _w3, _h1 + _h3 ); }
115
bool isValid( void ) const
116
{ return size().isValid() && _pixmaps.size() == 9; }
119
/*! pixmap names will be \p basename-position.suffix. Other arguments are the same as for QPixmap::save */
120
void save( const QString& basename, const QString& suffix = "png", const char* format = 0, int quality = -1 ) const;
124
it is used to (pre) tile the side pixmaps, in order to make further tiling faster when rendering, at the cost of
125
using more memory for the cache. Changes to this member only affects tilesets that are created afterwards.
127
void setSideExtent( int value )
128
{ _sideExtent = value; }
130
//! returns pixmap for given index
131
QPixmap pixmap( int index ) const
133
assert( index >= 0 && index < _pixmaps.size() );
134
return _pixmaps[index];
139
//! shortcut to pixmap list
140
typedef QVector<QPixmap> PixmapList;
142
//! initialize pixmap
143
void initPixmap( PixmapList&, const QPixmap&, int w, int h, const QRect& );
149
it is used to (pre) tile the side pixmaps, in order to make further tiling faster when rendering, at the cost of
150
using more memory for the cache.
152
static int _sideExtent;
167
Q_DECLARE_OPERATORS_FOR_FLAGS(Oxygen::TileSet::Tiles)