diff --git a/src/servers/app/server/AccelerantDriver.cpp b/src/servers/app/server/AccelerantDriver.cpp index 8defe6c8cd..b925753319 100644 --- a/src/servers/app/server/AccelerantDriver.cpp +++ b/src/servers/app/server/AccelerantDriver.cpp @@ -228,7 +228,7 @@ void AccelerantDriver::StrokeLineArray(const int32 &numlines, const LineArrayDat Lock(); fLineThickness = (int)d->pensize; - fDrawPattern.SetTarget((int8*)&B_SOLID_HIGH); + fDrawPattern.SetPattern((int8*)&B_SOLID_HIGH); for (i=0; iGetColor(x,y).GetColor8(); + fb[x] = pat->ColorAt(x,y).GetColor8(); } break; case B_RGB15_BIG: case B_RGBA15_BIG: @@ -589,14 +589,14 @@ void AccelerantDriver::HLine(int32 x1, int32 x2, int32 y, PatternHandler *pat) { uint16 *fb = (uint16 *)((uint8 *)mFrameBufferConfig.frame_buffer + y*mFrameBufferConfig.bytes_per_row); for (x=x1; x<=x2; x++) - fb[x] = pat->GetColor(x,y).GetColor15(); + fb[x] = pat->ColorAt(x,y).GetColor15(); } break; case B_RGB16_BIG: case B_RGB16_LITTLE: { uint16 *fb = (uint16 *)((uint8 *)mFrameBufferConfig.frame_buffer + y*mFrameBufferConfig.bytes_per_row); for (x=x1; x<=x2; x++) - fb[x] = pat->GetColor(x,y).GetColor16(); + fb[x] = pat->ColorAt(x,y).GetColor16(); } break; case B_RGB32_BIG: case B_RGBA32_BIG: @@ -607,7 +607,7 @@ void AccelerantDriver::HLine(int32 x1, int32 x2, int32 y, PatternHandler *pat) rgb_color color; for (x=x1; x<=x2; x++) { - color = pat->GetColor(x,y).GetColor32(); + color = pat->ColorAt(x,y).GetColor32(); fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); } } break; @@ -644,7 +644,7 @@ void AccelerantDriver::HLinePatternThick(int32 x1, int32 x2, int32 y) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor8(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); fb += mFrameBufferConfig.bytes_per_row; } } break; @@ -657,7 +657,7 @@ void AccelerantDriver::HLinePatternThick(int32 x1, int32 x2, int32 y) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor15(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); } } break; @@ -668,7 +668,7 @@ void AccelerantDriver::HLinePatternThick(int32 x1, int32 x2, int32 y) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor16(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); } } break; @@ -683,7 +683,7 @@ void AccelerantDriver::HLinePatternThick(int32 x1, int32 x2, int32 y) { for (x=x1; x<=x2; x++) { - color = fDrawPattern.GetColor(x,y).GetColor32(); + color = fDrawPattern.ColorAt(x,y).GetColor32(); fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); } fb = (uint32 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); @@ -721,7 +721,7 @@ void AccelerantDriver::VLinePatternThick(int32 x, int32 y1, int32 y2) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor8(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); fb += mFrameBufferConfig.bytes_per_row; } } break; @@ -734,7 +734,7 @@ void AccelerantDriver::VLinePatternThick(int32 x, int32 y1, int32 y2) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor15(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); } } break; @@ -745,7 +745,7 @@ void AccelerantDriver::VLinePatternThick(int32 x, int32 y1, int32 y2) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor16(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); } } break; @@ -760,7 +760,7 @@ void AccelerantDriver::VLinePatternThick(int32 x, int32 y1, int32 y2) { for (x=x1; x<=x2; x++) { - color = fDrawPattern.GetColor(x,y).GetColor32(); + color = fDrawPattern.ColorAt(x,y).GetColor32(); fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); } fb = (uint32 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); @@ -895,7 +895,7 @@ void AccelerantDriver::FillPatternRect(int32 left, int32 top, int32 right, int32 for (y=top; y<=bottom; y++) { for (x=left; x<=right; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor8(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); fb += mFrameBufferConfig.bytes_per_row; } } break; @@ -909,7 +909,7 @@ void AccelerantDriver::FillPatternRect(int32 left, int32 top, int32 right, int32 for (y=top; y<=bottom; y++) { for (x=left; x<=right; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor15(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); } } break; @@ -921,7 +921,7 @@ void AccelerantDriver::FillPatternRect(int32 left, int32 top, int32 right, int32 for (y=top; y<=bottom; y++) { for (x=left; x<=right; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor16(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); } } break; @@ -937,7 +937,7 @@ void AccelerantDriver::FillPatternRect(int32 left, int32 top, int32 right, int32 { for (x=left; x<=right; x++) { - color = fDrawPattern.GetColor(x,y).GetColor32(); + color = fDrawPattern.ColorAt(x,y).GetColor32(); fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); } fb = (uint32 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); diff --git a/src/servers/app/server/BitmapDriver.cpp b/src/servers/app/server/BitmapDriver.cpp index 0fe00d24b3..25c1cae496 100644 --- a/src/servers/app/server/BitmapDriver.cpp +++ b/src/servers/app/server/BitmapDriver.cpp @@ -340,7 +340,7 @@ void BitmapDriver::SetThickPatternPixel(int x, int y) for (y=top; y<=bottom; y++) { for (x=left; x<=right; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor8(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); fb += bytes_per_row; } } break; @@ -351,7 +351,7 @@ void BitmapDriver::SetThickPatternPixel(int x, int y) for (y=top; y<=bottom; y++) { for (x=left; x<=right; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor15(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); fb = (uint16 *)((uint8 *)fb + bytes_per_row); } } break; @@ -362,7 +362,7 @@ void BitmapDriver::SetThickPatternPixel(int x, int y) for (y=top; y<=bottom; y++) { for (x=left; x<=right; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor16(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); fb = (uint16 *)((uint8 *)fb + bytes_per_row); } } break; @@ -376,7 +376,7 @@ void BitmapDriver::SetThickPatternPixel(int x, int y) { for (x=left; x<=right; x++) { - color = fDrawPattern.GetColor(x,y).GetColor32(); + color = fDrawPattern.ColorAt(x,y).GetColor32(); fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); } fb = (uint32 *)((uint8 *)fb + bytes_per_row); @@ -414,7 +414,7 @@ void BitmapDriver::HLinePatternThick(int32 x1, int32 x2, int32 y) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor8(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); fb += bytes_per_row; } } break; @@ -424,7 +424,7 @@ void BitmapDriver::HLinePatternThick(int32 x1, int32 x2, int32 y) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor15(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); fb = (uint16 *)((uint8 *)fb + bytes_per_row); } } break; @@ -434,7 +434,7 @@ void BitmapDriver::HLinePatternThick(int32 x1, int32 x2, int32 y) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor16(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); fb = (uint16 *)((uint8 *)fb + bytes_per_row); } } break; @@ -447,7 +447,7 @@ void BitmapDriver::HLinePatternThick(int32 x1, int32 x2, int32 y) { for (x=x1; x<=x2; x++) { - color = fDrawPattern.GetColor(x,y).GetColor32(); + color = fDrawPattern.ColorAt(x,y).GetColor32(); fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); } fb = (uint32 *)((uint8 *)fb + bytes_per_row); @@ -485,7 +485,7 @@ void BitmapDriver::VLinePatternThick(int32 x, int32 y1, int32 y2) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor8(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); fb += bytes_per_row; } } break; @@ -495,7 +495,7 @@ void BitmapDriver::VLinePatternThick(int32 x, int32 y1, int32 y2) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor15(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); fb = (uint16 *)((uint8 *)fb + bytes_per_row); } } break; @@ -505,7 +505,7 @@ void BitmapDriver::VLinePatternThick(int32 x, int32 y1, int32 y2) for (y=y1; y<=y2; y++) { for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor16(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); fb = (uint16 *)((uint8 *)fb + bytes_per_row); } } break; @@ -518,7 +518,7 @@ void BitmapDriver::VLinePatternThick(int32 x, int32 y1, int32 y2) { for (x=x1; x<=x2; x++) { - color = fDrawPattern.GetColor(x,y).GetColor32(); + color = fDrawPattern.ColorAt(x,y).GetColor32(); fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); } fb = (uint32 *)((uint8 *)fb + bytes_per_row); @@ -760,7 +760,7 @@ void BitmapDriver::FillPatternRect(const BRect &rect, const DrawData *d) for (y=top; y<=bottom; y++) { for (x=left; x<=right; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor8(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); fb += bytes_per_row; } } break; @@ -771,7 +771,7 @@ void BitmapDriver::FillPatternRect(const BRect &rect, const DrawData *d) for (y=top; y<=bottom; y++) { for (x=left; x<=right; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor15(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); fb = (uint16 *)((uint8 *)fb + bytes_per_row); } } break; @@ -782,7 +782,7 @@ void BitmapDriver::FillPatternRect(const BRect &rect, const DrawData *d) for (y=top; y<=bottom; y++) { for (x=left; x<=right; x++) - fb[x] = fDrawPattern.GetColor(x,y).GetColor16(); + fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); fb = (uint16 *)((uint8 *)fb + bytes_per_row); } } break; @@ -796,7 +796,7 @@ void BitmapDriver::FillPatternRect(const BRect &rect, const DrawData *d) { for (x=left; x<=right; x++) { - color = fDrawPattern.GetColor(x,y).GetColor32(); + color = fDrawPattern.ColorAt(x,y).GetColor32(); fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); } fb = (uint32 *)((uint8 *)fb + bytes_per_row); diff --git a/src/servers/app/server/LayerData.cpp b/src/servers/app/server/LayerData.cpp index 4a3b4d7fb8..d5aaf55c7b 100644 --- a/src/servers/app/server/LayerData.cpp +++ b/src/servers/app/server/LayerData.cpp @@ -36,7 +36,7 @@ DrawData::DrawData(void) highcolor.SetColor(0, 0, 0, 255); lowcolor.SetColor(255, 255, 255, 255); - patt=pat_solidhigh; + patt=kSolidHigh; draw_mode=B_OP_COPY; lineCap =B_BUTT_CAP; diff --git a/src/servers/app/server/PatternHandler.cpp b/src/servers/app/server/PatternHandler.cpp index a99015c5c9..ceaa1f590e 100644 --- a/src/servers/app/server/PatternHandler.cpp +++ b/src/servers/app/server/PatternHandler.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. +// Copyright (c) 2001-2005, Haiku, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -21,15 +21,19 @@ // // File Name: PatternHandler.cpp // Author: DarkWyrm +// Stephan Aßmus // Description: Class for easy calculation and use of patterns // //------------------------------------------------------------------------------ #include #include "PatternHandler.h" -const Pattern pat_solidhigh(0xFFFFFFFFFFFFFFFFLL); -const Pattern pat_solidlow((uint64)0); -const Pattern pat_mixedcolors(0xAAAAAAAAAAAAAAAALL); +const Pattern kSolidHigh(0xFFFFFFFFFFFFFFFFLL); +const Pattern kSolidLow((uint64)0); +const Pattern kMixedColors(0xAAAAAAAAAAAAAAAALL); + +const rgb_color kBlack = (rgb_color){ 0, 0, 0, 255 }; +const rgb_color kWhite = (rgb_color){ 255, 255, 255, 255 }; /*! \brief Void constructor @@ -38,10 +42,10 @@ const Pattern pat_mixedcolors(0xAAAAAAAAAAAAAAAALL); low color is set to white. */ PatternHandler::PatternHandler(void) + : fPattern(kSolidHigh), + fHighColor(kBlack), + fLowColor(kWhite) { - _pat=0xFFFFFFFFFFFFFFFFLL; - _high=new RGBColor(0,0,0,255); - _low=new RGBColor(255,255,255,255); } /*! @@ -51,15 +55,11 @@ PatternHandler::PatternHandler(void) 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) +PatternHandler::PatternHandler(const int8* pat) + : fPattern(pat ? Pattern(pat) : Pattern(kSolidHigh)), + fHighColor(kBlack), + fLowColor(kWhite) { - if(pat) - _pat.Set(pat); - else - _pat=0xFFFFFFFFFFFFFFFFLL; - - _high=new RGBColor(0,0,0,255); - _low=new RGBColor(255,255,255,255); } /*! @@ -69,25 +69,43 @@ PatternHandler::PatternHandler(int8 *pat) 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(const uint64 &pat) +PatternHandler::PatternHandler(const uint64& pat) + : fPattern(pat), + fHighColor(kBlack), + fLowColor(kWhite) { - _pat=pat; - _high=new RGBColor(0,0,0,255); - _low=new RGBColor(255,255,255,255); } -PatternHandler::PatternHandler(const Pattern &pat) +/*! + \brief Constructor initializes to given pattern + \param pat Pattern to use. + + This initializes to the given Pattern. + High color is set to black, and low color is set to white. +*/ +PatternHandler::PatternHandler(const Pattern& pat) + : fPattern(pat), + fHighColor(kBlack), + fLowColor(kWhite) { - _pat=pat; - _high=new RGBColor(0,0,0,255); - _low=new RGBColor(255,255,255,255); } -//! Destructor frees internal color variables +/*! + \brief Constructor initializes to given PatternHandler + \param other PatternHandler to copy. + + Copy constructor. +*/ +PatternHandler::PatternHandler(const PatternHandler& other) + : fPattern(other.fPattern), + fHighColor(other.fHighColor), + fLowColor(other.fLowColor) +{ +} + +//! Destructor does nothing PatternHandler::~PatternHandler(void) { - delete _high; - delete _low; } /*! @@ -97,30 +115,39 @@ PatternHandler::~PatternHandler(void) This initializes to the given pattern or B_SOLID_HIGH if the pattern is NULL. */ -void PatternHandler::SetTarget(int8 *pat) +void PatternHandler::SetPattern(const int8* pat) { - if(pat) - _pat.Set(pat); + if (pat) + fPattern.Set(pat); else - _pat=0xFFFFFFFFFFFFFFFFLL; + fPattern = kSolidHigh; } /*! \brief Sets the pattern for the handler to the one given \param pat Pattern to use. */ -void PatternHandler::SetTarget(const uint64 &pat) +void PatternHandler::SetPattern(const uint64& pat) { - _pat=pat; + fPattern = pat; } /*! \brief Sets the pattern for the handler to the one given \param pat Pattern to use. */ -void PatternHandler::SetTarget(const Pattern &pat) +void PatternHandler::SetPattern(const Pattern& pat) { - _pat=pat; + fPattern = pat; +} + +/*! + \brief Sets the pattern for the handler to the one given + \param pat R5 style pattern to use. +*/ +void PatternHandler::SetPattern(const pattern& pat) +{ + fPattern = pat; } /*! @@ -128,10 +155,28 @@ void PatternHandler::SetTarget(const Pattern &pat) \param high High color for the handler \param low Low color for the handler */ -void PatternHandler::SetColors(const RGBColor &high, const RGBColor &low) +void PatternHandler::SetColors(const RGBColor& high, const RGBColor& low) { - *_high=high; - *_low=low; + fHighColor = high; + fLowColor = low; +} + +/*! + \brief Set the high color for the pattern to use + \param color High color for the handler +*/ +void PatternHandler::SetHighColor(const RGBColor& color) +{ + fHighColor = color; +} + +/*! + \brief Set the low color for the pattern to use + \param color Low color for the handler +*/ +void PatternHandler::SetLowColor(const RGBColor& color) +{ + fLowColor = color; } /*! @@ -139,9 +184,10 @@ void PatternHandler::SetColors(const RGBColor &high, const RGBColor &low) \param pt Coordinates to get the color for \return Color for the coordinates */ -RGBColor PatternHandler::GetColor(const BPoint &pt) +RGBColor +PatternHandler::ColorAt(const BPoint &pt) const { - return GetColor(pt.x,pt.y); + return ColorAt(pt.x, pt.y); } /*! @@ -150,26 +196,10 @@ RGBColor PatternHandler::GetColor(const BPoint &pt) \param y Y coordinate to get the color for \return Color for the coordinates */ -RGBColor PatternHandler::GetColor(const float &x, const float &y) +RGBColor +PatternHandler::ColorAt(float x, float y) const { - const int8 *ptr=_pat.GetInt8(); - int32 value=ptr[(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) -{ - const int8 *ptr=_pat.GetInt8(); - int32 value=ptr[(uint32)y%8] & (1 << (7-((uint32)x%8)) ); - - return (value==0)?false:true; + return ColorAt(int(x), int(y)); } /*! @@ -177,8 +207,8 @@ bool PatternHandler::GetValue(const float &x, const float &y) \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) +bool PatternHandler::IsHighColor(const BPoint &pt) const { - return GetValue(pt.x,pt.y); + return IsHighColor((int)pt.x, (int)pt.y); }