Added class for easily adding pattern support to DisplayDriver subclasses.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2637 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2003-02-06 01:04:14 +00:00
parent 3c79f2fe4f
commit 1568958e09
3 changed files with 203 additions and 0 deletions

View File

@ -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

View File

@ -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 <bpmagic@columbus.rr.com>
// Description: Class for easy calculation and use of patterns
//
//------------------------------------------------------------------------------
#include <Point.h>
#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);
}

View File

@ -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 <bpmagic@columbus.rr.com>
// Description: Class for easy calculation and use of patterns
//
//------------------------------------------------------------------------------
#ifndef PATTERNHADLER_H
#include <SupportDefs.h>
#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