1 /* 2 * Copyright (c) 2001-2007, Haiku, Inc. 3 * Distributed under the terms of the MIT license. 4 * 5 * Author: DarkWyrm <bpmagic@columbus.rr.com> 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "PatternHandler.h" 10 11 #include <stdio.h> 12 13 #include <Point.h> 14 15 const Pattern kSolidHigh(0xFFFFFFFFFFFFFFFFLL); 16 const Pattern kSolidLow((uint64)0); 17 const Pattern kMixedColors(0xAAAAAAAAAAAAAAAALL); 18 19 const rgb_color kBlack = (rgb_color){ 0, 0, 0, 255 }; 20 const rgb_color kWhite = (rgb_color){ 255, 255, 255, 255 }; 21 22 /*! 23 \brief Void constructor 24 25 The pattern is set to B_SOLID_HIGH, high color is set to black, and 26 low color is set to white. 27 */ 28 PatternHandler::PatternHandler(void) 29 : fPattern(kSolidHigh), 30 fHighColor(kBlack), 31 fLowColor(kWhite), 32 fXOffset(0), 33 fYOffset(0) 34 { 35 } 36 37 /*! 38 \brief Constructor initializes to given pattern 39 \param pat Pattern to use. 40 41 This initializes to the given pattern or B_SOLID_HIGH if the pattern 42 is NULL. High color is set to black, and low color is set to white. 43 */ 44 PatternHandler::PatternHandler(const int8* pat) 45 : fPattern(pat ? Pattern(pat) : Pattern(kSolidHigh)), 46 fHighColor(kBlack), 47 fLowColor(kWhite), 48 fXOffset(0), 49 fYOffset(0) 50 { 51 } 52 53 /*! 54 \brief Constructor initializes to given pattern 55 \param pat Pattern to use. 56 57 This initializes to the given pattern or B_SOLID_HIGH if the pattern 58 is NULL. High color is set to black, and low color is set to white. 59 */ 60 PatternHandler::PatternHandler(const uint64& pat) 61 : fPattern(pat), 62 fHighColor(kBlack), 63 fLowColor(kWhite), 64 fXOffset(0), 65 fYOffset(0) 66 { 67 } 68 69 /*! 70 \brief Constructor initializes to given pattern 71 \param pat Pattern to use. 72 73 This initializes to the given Pattern. 74 High color is set to black, and low color is set to white. 75 */ 76 PatternHandler::PatternHandler(const Pattern& pat) 77 : fPattern(pat), 78 fHighColor(kBlack), 79 fLowColor(kWhite), 80 fXOffset(0), 81 fYOffset(0) 82 { 83 } 84 85 /*! 86 \brief Constructor initializes to given PatternHandler 87 \param other PatternHandler to copy. 88 89 Copy constructor. 90 */ 91 PatternHandler::PatternHandler(const PatternHandler& other) 92 : fPattern(other.fPattern), 93 fHighColor(other.fHighColor), 94 fLowColor(other.fLowColor), 95 fXOffset(other.fXOffset), 96 fYOffset(other.fYOffset) 97 { 98 } 99 100 //! Destructor does nothing 101 PatternHandler::~PatternHandler(void) 102 { 103 } 104 105 /*! 106 \brief Sets the pattern for the handler to the one given 107 \param pat Pattern to use. 108 109 This initializes to the given pattern or B_SOLID_HIGH if the pattern 110 is NULL. 111 */ 112 void 113 PatternHandler::SetPattern(const int8* pat) 114 { 115 if (pat) 116 fPattern.Set(pat); 117 else 118 fPattern = kSolidHigh; 119 } 120 121 /*! 122 \brief Sets the pattern for the handler to the one given 123 \param pat Pattern to use. 124 */ 125 void 126 PatternHandler::SetPattern(const uint64& pat) 127 { 128 fPattern = pat; 129 } 130 131 /*! 132 \brief Sets the pattern for the handler to the one given 133 \param pat Pattern to use. 134 */ 135 void 136 PatternHandler::SetPattern(const Pattern& pat) 137 { 138 fPattern = pat; 139 } 140 141 /*! 142 \brief Sets the pattern for the handler to the one given 143 \param pat R5 style pattern to use. 144 */ 145 void 146 PatternHandler::SetPattern(const pattern& pat) 147 { 148 fPattern = pat; 149 } 150 151 /*! 152 \brief Set the colors for the pattern to use 153 \param high High color for the handler 154 \param low Low color for the handler 155 */ 156 void 157 PatternHandler::SetColors(const RGBColor& high, const RGBColor& low) 158 { 159 fHighColor = high; 160 fLowColor = low; 161 } 162 163 /*! 164 \brief Set the high color for the pattern to use 165 \param color High color for the handler 166 */ 167 void 168 PatternHandler::SetHighColor(const RGBColor& color) 169 { 170 fHighColor = color; 171 } 172 173 /*! 174 \brief Set the low color for the pattern to use 175 \param color Low color for the handler 176 */ 177 void 178 PatternHandler::SetLowColor(const RGBColor& color) 179 { 180 fLowColor = color; 181 } 182 183 /*! 184 \brief Set the colors for the pattern to use 185 \param high High color for the handler 186 \param low Low color for the handler 187 */ 188 void 189 PatternHandler::SetColors(const rgb_color& high, const rgb_color& low) 190 { 191 fHighColor = high; 192 fLowColor = low; 193 } 194 195 /*! 196 \brief Set the high color for the pattern to use 197 \param color High color for the handler 198 */ 199 void 200 PatternHandler::SetHighColor(const rgb_color& color) 201 { 202 fHighColor = color; 203 } 204 205 /*! 206 \brief Set the low color for the pattern to use 207 \param color Low color for the handler 208 */ 209 void 210 PatternHandler::SetLowColor(const rgb_color& color) 211 { 212 fLowColor = color; 213 } 214 215 /*! 216 \brief Obtains the color in the pattern at the specified coordinates 217 \param pt Coordinates to get the color for 218 \return Color for the coordinates 219 */ 220 RGBColor 221 PatternHandler::ColorAt(const BPoint &pt) const 222 { 223 return ColorAt(pt.x, pt.y); 224 } 225 226 /*! 227 \brief Obtains the color in the pattern at the specified coordinates 228 \param x X coordinate to get the color for 229 \param y Y coordinate to get the color for 230 \return Color for the coordinates 231 */ 232 RGBColor 233 PatternHandler::ColorAt(float x, float y) const 234 { 235 return ColorAt(int(x), int(y)); 236 } 237 238 /*! 239 \brief Obtains the value of the pattern at the specified coordinates 240 \param pt Coordinates to get the value for 241 \return Value for the coordinates - true if high, false if low. 242 */ 243 bool 244 PatternHandler::IsHighColor(const BPoint &pt) const 245 { 246 return IsHighColor((int)pt.x, (int)pt.y); 247 } 248 249 /*! 250 \brief Transfers the scrolling offset of a BView to affect the pattern. 251 \param x Positive or negative horizontal offset 252 \param y Positive or negative vertical offset 253 */ 254 void 255 PatternHandler::SetOffsets(int32 x, int32 y) 256 { 257 fXOffset = x & 7; 258 fYOffset = y & 7; 259 } 260 261