diff --git a/src/servers/app/server/Jamfile b/src/servers/app/server/Jamfile index f4e24537a7..c7cd45e97d 100644 --- a/src/servers/app/server/Jamfile +++ b/src/servers/app/server/Jamfile @@ -9,6 +9,7 @@ Server app_server : # Misc. Sources Angle.cpp TokenHandler.cpp + PatternHandler.cpp # PortLink will disappear as soon as I can figure out how to link the server # against libopenbeos diff --git a/src/servers/app/server/PatternHandler.cpp b/src/servers/app/server/PatternHandler.cpp new file mode 100644 index 0000000000..33746cde40 --- /dev/null +++ b/src/servers/app/server/PatternHandler.cpp @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, OpenBeOS +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// File Name: PatternHandler.cpp +// Author: DarkWyrm +// Description: Class for easy calculation and use of patterns +// +//------------------------------------------------------------------------------ +#include +#include "PatternHandler.h" + +/*! + \brief Void constructor + + The pattern is set to B_SOLID_HIGH, high color is set to black, and + low color is set to white. +*/ +PatternHandler::PatternHandler(void) +{ + _pat.type64=0xFFFFFFFFLL; + _high=new RGBColor(0,0,0,255); + _low=new RGBColor(255,255,255,255); +} + +/*! + \brief Constructor initializes to given pattern + \param pat Pattern to use. + + This initializes to the given pattern or B_SOLID_HIGH if the pattern + is NULL. High color is set to black, and low color is set to white. +*/ +PatternHandler::PatternHandler(int8 *pat) +{ + if(pat) + _pat.type64=*((uint64*)pat); + else + _pat.type64=0xFFFFFFFFLL; + + _high=new RGBColor(0,0,0,255); + _low=new RGBColor(255,255,255,255); +} + +//! Destructor frees internal color variables +PatternHandler::~PatternHandler(void) +{ + delete _high; + delete _low; +} + +/*! + \brief Sets the pattern for the handler to the one given + \param pat Pattern to use. + + This initializes to the given pattern or B_SOLID_HIGH if the pattern + is NULL. +*/ +void PatternHandler::SetTarget(int8 *pat) +{ + if(pat) + _pat.type64=*((uint64*)pat); + else + _pat.type64=0xFFFFFFFFLL; +} + +/*! + \brief Set the colors for the pattern to use + \param high High color for the handler + \param low Low color for the handler +*/ +void PatternHandler::SetColors(const RGBColor &high, const RGBColor &low) +{ + *_high=high; + *_low=low; +} + +/*! + \brief Obtains the color in the pattern at the specified coordinates + \param pt Coordinates to get the color for + \return Color for the coordinates +*/ +RGBColor PatternHandler::GetColor(const BPoint &pt) +{ + return GetColor(pt.x,pt.y); +} + +/*! + \brief Obtains the color in the pattern at the specified coordinates + \param x X coordinate to get the color for + \param y Y coordinate to get the color for + \return Color for the coordinates +*/ +RGBColor PatternHandler::GetColor(const float &x, const float &y) +{ + int32 value=_pat.type8[(uint32)y%8] & (1 << (7-((uint32)x%8)) ); + + return (value==0)?*_low:*_high; +} + +/*! + \brief Obtains the value of the pattern at the specified coordinates + \param x X coordinate to get the value for + \param y Y coordinate to get the value for + \return Value for the coordinates - true if high, false if low. +*/ +bool PatternHandler::GetValue(const float &x, const float &y) +{ + int32 value=_pat.type8[(uint32)y%8] & (1 << (7-((uint32)x%8)) ); + + return (value==0)?false:true; +} + +/*! + \brief Obtains the value of the pattern at the specified coordinates + \param pt Coordinates to get the value for + \return Value for the coordinates - true if high, false if low. +*/ +bool PatternHandler::GetValue(const BPoint &pt) +{ + return GetValue(pt.x,pt.y); +} + diff --git a/src/servers/app/server/PatternHandler.h b/src/servers/app/server/PatternHandler.h new file mode 100644 index 0000000000..0834d352ad --- /dev/null +++ b/src/servers/app/server/PatternHandler.h @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, OpenBeOS +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// File Name: PatternHandler.h +// Author: DarkWyrm +// Description: Class for easy calculation and use of patterns +// +//------------------------------------------------------------------------------ +#ifndef PATTERNHADLER_H + +#include +#include "RGBColor.h" + +typedef union +{ + uint64 type64; + uint8 type8[8]; +} pattern_union; + +/*! + \brief Class for easy calculation and use of patterns + + PatternHandlers are designed specifically for DisplayDriver subclasses. + Pattern support can be easily added by setting the pattern to use via + SetTarget, and then merely retrieving the value for the coordinates + specified. +*/ +class PatternHandler +{ +public: + PatternHandler(void); + PatternHandler(int8 *pat); + ~PatternHandler(void); + void SetTarget(int8 *pat); + void SetColors(const RGBColor &high, const RGBColor &low); + RGBColor GetColor(const BPoint &pt); + RGBColor GetColor(const float &x, const float &y); + bool GetValue(const float &x, const float &y); + bool GetValue(const BPoint &pt); +private: + pattern_union _pat; + RGBColor *_high,*_low; +}; + +#endif