summaryrefslogtreecommitdiff
path: root/cairomm/pattern.h
blob: dd2bb159e78838ef9ae6df8aed40790f36bf5632 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* Copyright (C) 2005 The cairomm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef __CAIROMM_PATTERN_H
#define __CAIROMM_PATTERN_H

#include <cairomm/surface.h>
#include <cairomm/enums.h>
#include <cairo/cairo.h>


namespace Cairo
{

typedef cairo_extend_t Extend;
typedef cairo_filter_t Filter;

/**
 * This is a reference-counted object. The copy constructor creates a second reference to the object, instead 
 * of creating an independent copy of the object.
 */
class Pattern
{
public:
  //Use derived constructors.

  /** Create a C++ wrapper for the C instance.
   * @param cobject The C instance.
   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
   */
  explicit Pattern(cairo_pattern_t* cobject, bool has_reference = false);

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  Pattern(const Pattern& src);

  //TODO?: Pattern(cairo_pattern_t *target);
  virtual ~Pattern();

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  Pattern& operator=(const Pattern& src);

  void set_matrix(const cairo_matrix_t &matrix);
  void get_matrix(cairo_matrix_t &matrix) const;

  typedef cairo_pattern_t cobject;
  inline cobject* cobj() { return m_cobject; }
  inline const cobject* cobj() const { return m_cobject; }

  #ifndef DOXYGEN_IGNORE_THIS
  ///For use only by the cairomm implementation.
  inline Status get_status() const
  { return cairo_pattern_status(const_cast<cairo_pattern_t*>(cobj())); }
  #endif //DOXYGEN_IGNORE_THIS

protected:
  //Used by derived types only.
  Pattern();

  cobject* m_cobject;
};

class SolidPattern : public Pattern
{
public:

  static SolidPattern create_rgb(double red, double green, double blue);
  static SolidPattern create_rgba(double red, double green, double blue, double alpha);

  /** Create a C++ wrapper for the C instance.
   * @param cobject The C instance.
   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
   */
  explicit SolidPattern(cairo_pattern_t* cobject, bool has_reference = false);

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  SolidPattern(const SolidPattern& src);

  //TODO?: SolidPattern(cairo_pattern_t *target);
  virtual ~SolidPattern();

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  SolidPattern& operator=(const SolidPattern& src);
};

class SurfacePattern : public Pattern
{
public:

  explicit SurfacePattern(Surface& surface);

  /** Create a C++ wrapper for the C instance.
   * @param cobject The C instance.
   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
   */
  explicit SurfacePattern(cairo_pattern_t* cobject, bool has_reference = false);

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  SurfacePattern(const SurfacePattern& src);

  //TODO?: SurfacePattern(cairo_pattern_t *target);
  virtual ~SurfacePattern();

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  SurfacePattern& operator=(const SurfacePattern& src);

  void set_extend(Extend extend);
  Extend get_extend() const;
  void set_filter(Filter filter);
  Filter get_filter() const;
};

class Gradient : public Pattern
{
public:
  //Use derived constructors.

  /** Create a C++ wrapper for the C instance.
   * @param cobject The C instance.
   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
   */
  explicit Gradient(cairo_pattern_t* cobject, bool has_reference = false);

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  Gradient(const Gradient& src);

  //TODO?: Gradient(cairo_pattern_t *target);
  virtual ~Gradient();

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  Gradient& operator=(const Gradient& src);

  void add_color_stop_rgb(double offset, double red, double green, double blue);
  void add_color_stop_rgba(double offset, double red, double green, double blue, double alpha);

protected:
  Gradient();
};

class LinearGradient : public Gradient
{
public:

  LinearGradient(double x0, double y0, double x1, double y1);

  /** Create a C++ wrapper for the C instance.
   * @param cobject The C instance.
   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
   */
  explicit LinearGradient(cairo_pattern_t* cobject, bool has_reference = false);

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  LinearGradient(const LinearGradient& src);

  //TODO?: LinearGradient(cairo_pattern_t *target);
  virtual ~LinearGradient();

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  LinearGradient& operator=(const LinearGradient& src);
};

class RadialGradient : public Gradient
{
public:

  RadialGradient(double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);

  /** Create a C++ wrapper for the C instance.
   * @param cobject The C instance.
   * @param has_reference Whether we already have a reference. Otherwise, the constructor will take an extra reference.
   */
  explicit RadialGradient(cairo_pattern_t* cobject, bool has_reference = false);

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  RadialGradient(const RadialGradient& src);

  //TODO?: RadialGradient(cairo_pattern_t *target);
  virtual ~RadialGradient();

  /** Create a second reference to the Pattern.
  * Changing this instance will change the original instance.
  */
  RadialGradient& operator=(const RadialGradient& src);
};

} // namespace Cairo

#endif //__CAIROMM_PATTERN_H