| 1 |
/** |
|---|
| 2 |
XXX |
|---|
| 3 |
|
|---|
| 4 |
Authors: Daniel Keep |
|---|
| 5 |
Copyright: 2006, Daniel Keep |
|---|
| 6 |
License: BSD v2 (http://opensource.org/licenses/bsd-license.php). |
|---|
| 7 |
**/ |
|---|
| 8 |
/** |
|---|
| 9 |
Copyright © 2006 Daniel Keep |
|---|
| 10 |
All rights reserved. |
|---|
| 11 |
|
|---|
| 12 |
Redistribution and use in source and binary forms, with or without |
|---|
| 13 |
modification, are permitted provided that the following conditions are |
|---|
| 14 |
met: |
|---|
| 15 |
|
|---|
| 16 |
* Redistributions of source code must retain the above copyright |
|---|
| 17 |
notice, this list of conditions and the following disclaimer. |
|---|
| 18 |
|
|---|
| 19 |
* Redistributions in binary form must reproduce the above copyright |
|---|
| 20 |
notice, this list of conditions and the following disclaimer in the |
|---|
| 21 |
documentation and/or other materials provided with the distribution. |
|---|
| 22 |
|
|---|
| 23 |
* Neither the name of this software, nor the names of its contributors |
|---|
| 24 |
may be used to endorse or promote products derived from this software |
|---|
| 25 |
without specific prior written permission. |
|---|
| 26 |
|
|---|
| 27 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 28 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|---|
| 29 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 30 |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|---|
| 31 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|---|
| 32 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|---|
| 33 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|---|
| 34 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|---|
| 35 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|---|
| 36 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 37 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 38 |
**/ |
|---|
| 39 |
module cairooo.pattern; |
|---|
| 40 |
|
|---|
| 41 |
private |
|---|
| 42 |
{ |
|---|
| 43 |
import cairo.cairo; |
|---|
| 44 |
import cairooo.enums; |
|---|
| 45 |
import cairooo.exceptions; |
|---|
| 46 |
import cairooo.matrix; |
|---|
| 47 |
import cairooo.surface; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
/** |
|---|
| 51 |
* A cairo pattern. |
|---|
| 52 |
*/ |
|---|
| 53 |
class Pattern |
|---|
| 54 |
{ |
|---|
| 55 |
private: |
|---|
| 56 |
cairo_pattern_t* _handle; |
|---|
| 57 |
|
|---|
| 58 |
public: |
|---|
| 59 |
// NOTE: We are following the way cairomm does things, and allowing the |
|---|
| 60 |
// user to create the various kinds of patterns via subclasses. So you |
|---|
| 61 |
// can't actually make anything interesting from this base class (although |
|---|
| 62 |
// it hangs around to wrap low-level handles). |
|---|
| 63 |
|
|---|
| 64 |
/** |
|---|
| 65 |
* Wraps the low-level cairo pattern in a new object. This method is most |
|---|
| 66 |
* useful for wrapping pointers returned from cairo api functions that are |
|---|
| 67 |
* not yet supported by the OO api. Please note that this function is |
|---|
| 68 |
* slightly dangerous and can lead to memory leaks if misused (see below). |
|---|
| 69 |
* |
|---|
| 70 |
* Please note that it is $(I vitally) important that you use the takeref |
|---|
| 71 |
* parameter correctly. If takeref is set to true, then the |
|---|
| 72 |
* object will $(I not) add to the handle's reference count. This means |
|---|
| 73 |
* that if you do not pass the correct value for takeref, then you could |
|---|
| 74 |
* end up with handles either not being destroyed, or being destroyed too |
|---|
| 75 |
* early! |
|---|
| 76 |
* |
|---|
| 77 |
* Params: |
|---|
| 78 |
* handle = Pointer to a cairo_pattern_t |
|---|
| 79 |
* takeref = Should the object take a reference to the handle? |
|---|
| 80 |
*/ |
|---|
| 81 |
this(cairo_pattern_t* handle, bool takeref) |
|---|
| 82 |
{ |
|---|
| 83 |
checkStatus(handle); |
|---|
| 84 |
this._handle = handle; |
|---|
| 85 |
if( takeref ) |
|---|
| 86 |
{ |
|---|
| 87 |
cairo_pattern_reference(this.handle); |
|---|
| 88 |
checkStatus(this.handle); |
|---|
| 89 |
} |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
/** |
|---|
| 93 |
* Duplicates a pattern, providing a new, independant reference to it. |
|---|
| 94 |
*/ |
|---|
| 95 |
this(Pattern pattern) |
|---|
| 96 |
{ |
|---|
| 97 |
this(pattern.handle, true); |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
~this() |
|---|
| 101 |
{ |
|---|
| 102 |
cairo_pattern_destroy(this.handle); |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
// |
|---|
| 106 |
// cairo api members |
|---|
| 107 |
// |
|---|
| 108 |
Matrix |
|---|
| 109 |
matrix() |
|---|
| 110 |
{ |
|---|
| 111 |
scope(success) checkStatus(); |
|---|
| 112 |
Matrix temp; |
|---|
| 113 |
cairo_pattern_get_matrix(this.handle, temp.toPtr); |
|---|
| 114 |
return temp; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
Matrix |
|---|
| 118 |
matrix(Matrix value) |
|---|
| 119 |
{ |
|---|
| 120 |
scope(success) checkStatus(); |
|---|
| 121 |
cairo_pattern_set_matrix(this.handle, value.toPtr); |
|---|
| 122 |
return value; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
// |
|---|
| 126 |
// miscellaneous members |
|---|
| 127 |
// |
|---|
| 128 |
|
|---|
| 129 |
Pattern |
|---|
| 130 |
dup() |
|---|
| 131 |
{ |
|---|
| 132 |
return new Pattern(this); |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
cairo_pattern_t* |
|---|
| 136 |
handle() |
|---|
| 137 |
{ |
|---|
| 138 |
return this._handle; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
int |
|---|
| 142 |
opEquals(Pattern other) |
|---|
| 143 |
{ |
|---|
| 144 |
return this.handle == other.handle; |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
// |
|---|
| 148 |
// internal stuff |
|---|
| 149 |
// |
|---|
| 150 |
protected: |
|---|
| 151 |
void |
|---|
| 152 |
checkStatus() |
|---|
| 153 |
{ |
|---|
| 154 |
.checkStatus(cairo_pattern_status(this.handle)); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
void |
|---|
| 158 |
checkStatus(cairo_pattern_t* handle) |
|---|
| 159 |
{ |
|---|
| 160 |
.checkStatus(cairo_pattern_status(handle)); |
|---|
| 161 |
} |
|---|
| 162 |
} |
|---|