* Removed ColorUtils.cc from libbe.so - I can't think of a reason why

these should be public (they don't match any basic Be naming style
  anyway :-).
* Put the code that's used by the app_server where it's needed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16804 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-03-15 00:22:01 +00:00
parent e0f9a4e815
commit 49fe96777b
8 changed files with 275 additions and 439 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2005, Haiku, Inc.
* Copyright (c) 2001-2006, Haiku, Inc.
* Distributed under the terms of the MIT license.
*
* Authors:
@@ -72,7 +72,7 @@ AppServer::AppServer()
// Load the GUI colors here and set the global set to the values contained therein. If this
// is not possible, set colors to the defaults
if (LoadColorSet(SERVER_SETTINGS_DIR COLOR_SETTINGS_NAME, &gGUIColorSet) != B_OK)
if (ColorSet::LoadColorSet(SERVER_SETTINGS_DIR COLOR_SETTINGS_NAME, &gGUIColorSet) != B_OK)
gGUIColorSet.SetToDefaults();
gScreenManager = new ScreenManager();
+52 -46
View File
@@ -19,7 +19,20 @@
#include "ColorSet.h"
#include "ServerConfig.h"
//! Constructor which does nothing
static void
set_rgb_color(rgb_color& color, uint8 red, uint8 green, uint8 blue)
{
color.red = red;
color.green = green;
color.blue = blue;
color.alpha = 255;
}
// #pragma mark -
ColorSet::ColorSet()
{
}
@@ -136,32 +149,31 @@ ColorSet::SetToDefaults(void)
#ifdef DEBUG_COLORSET
printf("Initializing color settings to defaults\n");
#endif
SetRGBColor(&panel_background, 216, 216, 216);
SetRGBColor(&panel_text, 0, 0, 0);
SetRGBColor(&document_background, 255, 255, 255);
SetRGBColor(&document_text, 0, 0, 0);
SetRGBColor(&control_background, 245, 245, 245);
SetRGBColor(&control_text, 0, 0, 0);
SetRGBColor(&control_border, 0, 0, 0);
SetRGBColor(&control_highlight, 102, 152, 203);
SetRGBColor(&keyboard_navigation_base, 0, 0, 229);
SetRGBColor(&keyboard_navigation_pulse, 0, 0, 0);
SetRGBColor(&shine, 255, 255, 255);
SetRGBColor(&shadow, 0, 0, 0);
SetRGBColor(&menu_background, 216, 216, 216);
SetRGBColor(&menu_selected_background, 115, 120, 184);
SetRGBColor(&menu_text, 0, 0, 0);
SetRGBColor(&menu_selected_text, 255, 255, 255);
SetRGBColor(&menu_selected_border, 0, 0, 0);
SetRGBColor(&tooltip_background, 255, 255, 0);
SetRGBColor(&tooltip_text, 0, 0, 0);
SetRGBColor(&success, 0, 255, 0);
SetRGBColor(&failure, 255, 0, 0);
SetRGBColor(&window_tab, 255, 203, 0);
SetRGBColor(&window_tab_text, 0, 0, 0);
SetRGBColor(&inactive_window_tab, 232, 232, 232);
SetRGBColor(&inactive_window_tab_text, 80, 80, 80);
set_rgb_color(panel_background, 216, 216, 216);
set_rgb_color(panel_text, 0, 0, 0);
set_rgb_color(document_background, 255, 255, 255);
set_rgb_color(document_text, 0, 0, 0);
set_rgb_color(control_background, 245, 245, 245);
set_rgb_color(control_text, 0, 0, 0);
set_rgb_color(control_border, 0, 0, 0);
set_rgb_color(control_highlight, 102, 152, 203);
set_rgb_color(keyboard_navigation_base, 0, 0, 229);
set_rgb_color(keyboard_navigation_pulse, 0, 0, 0);
set_rgb_color(shine, 255, 255, 255);
set_rgb_color(shadow, 0, 0, 0);
set_rgb_color(menu_background, 216, 216, 216);
set_rgb_color(menu_selected_background, 115, 120, 184);
set_rgb_color(menu_text, 0, 0, 0);
set_rgb_color(menu_selected_text, 255, 255, 255);
set_rgb_color(menu_selected_border, 0, 0, 0);
set_rgb_color(tooltip_background, 255, 255, 0);
set_rgb_color(tooltip_text, 0, 0, 0);
set_rgb_color(success, 0, 255, 0);
set_rgb_color(failure, 255, 0, 0);
set_rgb_color(window_tab, 255, 203, 0);
set_rgb_color(window_tab_text, 0, 0, 0);
set_rgb_color(inactive_window_tab, 232, 232, 232);
set_rgb_color(inactive_window_tab_text, 80, 80, 80);
}
/*!
@@ -539,50 +551,44 @@ ColorSet::PrintMember(const rgb_color &color) const
printf("rgb_color(%d, %d, %d, %d)", color.red,color.green,color.blue,color.alpha);
}
/*!
\brief Loads the saved system colors into a ColorSet
\param set the set to receive the system colors
\return B_OK if successful. See BFile for other error codes
*/
status_t
LoadColorSet(const char *path, ColorSet *set)
ColorSet::LoadColorSet(const char *path, ColorSet *set)
{
BFile file(path,B_READ_ONLY);
if(file.InitCheck()!=B_OK)
if (file.InitCheck()!=B_OK)
return file.InitCheck();
BMessage msg;
status_t st=msg.Unflatten(&file);
if(st!=B_OK)
return st;
status_t status = msg.Unflatten(&file);
if (status != B_OK)
return status;
set->ConvertFromMessage(&msg);
return B_OK;
}
/*!
\brief Saves the saved system colors into a flattened BMessage
\param set ColorSet containing the colors to save
\return B_OK if successful. See BFile for other error codes
*/
status_t
SaveColorSet(const char *path, const ColorSet &set)
ColorSet::SaveColorSet(const char *path, const ColorSet &set)
{
// TODO: Move this check to the app_server
BEntry entry(SERVER_SETTINGS_DIR);
if(!entry.Exists())
create_directory(SERVER_SETTINGS_DIR,0777);
BFile file(path, B_READ_WRITE | B_ERASE_FILE | B_CREATE_FILE);
if(file.InitCheck()!=B_OK)
return file.InitCheck();
status_t status = file.InitCheck();
if (status != B_OK)
return status;
BMessage msg;
set.ConvertToMessage(&msg);
msg.Flatten(&file);
return B_OK;
return msg.Flatten(&file);
}
+59 -18
View File
@@ -12,7 +12,6 @@
#include "DefaultDecorator.h"
#include "ColorUtils.h"
#include "DesktopSettings.h"
#include "DrawingEngine.h"
#include "DrawState.h"
@@ -36,10 +35,52 @@
#endif
static inline uint8
blend_color_value(uint8 a, uint8 b, float position)
{
int16 delta = (int16)a - b;
int32 value = a + (int32)(position * delta);
if (value > 255)
return 255;
if (value < 0)
return 0;
return (uint8)value;
}
/*!
\brief Function mostly for calculating gradient colors
\param col Start color
\param col2 End color
\param position A floating point number such that 0.0 <= position <= 1.0. 0.0 results in the
start color and 1.0 results in the end color.
\return The blended color. If an invalid position was given, {0,0,0,0} is returned.
*/
static rgb_color
make_blend_color(rgb_color colorA, rgb_color colorB, float position)
{
if (position < 0)
return colorA;
if (position > 1)
return colorB;
rgb_color blendColor;
blendColor.red = blend_color_value(colorA.red, colorB.red, position);
blendColor.green = blend_color_value(colorA.green, colorB.green, position);
blendColor.blue = blend_color_value(colorA.blue, colorB.blue, position);
blendColor.alpha = blend_color_value(colorA.alpha, colorB.alpha, position);
return blendColor;
}
// #pragma mark -
// TODO: get rid of DesktopSettings here, and introduce private accessor
// methods to the Decorator base class
DefaultDecorator::DefaultDecorator(DesktopSettings& settings, BRect rect,
window_look look, uint32 flags)
: Decorator(settings, rect, look, flags),
@@ -924,38 +965,38 @@ DefaultDecorator::_DrawBlendedRect(BRect r, bool down)
// Actually just draws a blended square
int32 w = r.IntegerWidth();
int32 h = r.IntegerHeight();
RGBColor temprgbcol;
rgb_color halfcol, startcol, endcol;
rgb_color halfColor, startColor, endColor;
float rstep, gstep, bstep;
int steps = w < h ? w : h;
if (down) {
startcol = fButtonLowColor.GetColor32();
endcol = fButtonHighColor.GetColor32();
startColor = fButtonLowColor.GetColor32();
endColor = fButtonHighColor.GetColor32();
} else {
startcol = fButtonHighColor.GetColor32();
endcol = fButtonLowColor.GetColor32();
startColor = fButtonHighColor.GetColor32();
endColor = fButtonLowColor.GetColor32();
}
halfcol = MakeBlendColor(startcol,endcol,0.5);
halfColor = make_blend_color(startColor, endColor, 0.5);
rstep = float(startcol.red - halfcol.red) / steps;
gstep = float(startcol.green - halfcol.green) / steps;
bstep = float(startcol.blue - halfcol.blue) / steps;
rstep = float(startColor.red - halfColor.red) / steps;
gstep = float(startColor.green - halfColor.green) / steps;
bstep = float(startColor.blue - halfColor.blue) / steps;
for (int32 i = 0; i <= steps; i++) {
temprgbcol.SetColor(uint8(startcol.red - (i * rstep)),
uint8(startcol.green - (i * gstep)),
uint8(startcol.blue - (i * bstep)));
temprgbcol.SetColor(uint8(startColor.red - (i * rstep)),
uint8(startColor.green - (i * gstep)),
uint8(startColor.blue - (i * bstep)));
_driver->StrokeLine(BPoint(r.left, r.top + i),
BPoint(r.left + i, r.top), temprgbcol);
temprgbcol.SetColor(uint8(halfcol.red - (i * rstep)),
uint8(halfcol.green - (i * gstep)),
uint8(halfcol.blue - (i * bstep)));
temprgbcol.SetColor(uint8(halfColor.red - (i * rstep)),
uint8(halfColor.green - (i * gstep)),
uint8(halfColor.blue - (i * bstep)));
_driver->StrokeLine(BPoint(r.left + steps, r.top + i),
BPoint(r.left + i, r.top + steps), temprgbcol);
+144 -5
View File
@@ -10,11 +10,149 @@
#include "RGBColor.h"
#include "SystemPalette.h"
#include <ColorUtils.h>
#include <stdio.h>
/*!
\brief An approximation of 31/255, which is needed for converting from 32-bit
colors to 16-bit and 15-bit.
*/
#define RATIO_8_TO_5_BIT .121568627451
/*!
\brief An approximation of 63/255, which is needed for converting from 32-bit
colors to 16-bit.
*/
#define RATIO_8_TO_6_BIT .247058823529
/*!
\brief An approximation of 255/31, which is needed for converting from 16-bit
and 15-bit colors to 32-bit.
*/
#define RATIO_5_TO_8_BIT 8.22580645161
/*!
\brief An approximation of 255/63, which is needed for converting from 16-bit
colors to 32-bit.
*/
#define RATIO_6_TO_8_BIT 4.04761904762
#if 0
/*!
\brief Function for easy conversion of 16-bit colors to 32-bit
\param col Pointer to an rgb_color.
\param color RGB16 color
This function will do nothing if passed a NULL 32-bit color.
*/
void
SetRGBColor16(rgb_color *col,uint16 color)
{
if(!col)
return;
uint16 r16,g16,b16;
// alpha's the easy part
col->alpha=0;
r16= (color >> 11) & 31;
g16= (color >> 5) & 63;
b16= color & 31;
col->red=uint8(r16 * RATIO_5_TO_8_BIT);
col->green=uint8(g16 * RATIO_6_TO_8_BIT);
col->blue=uint8(b16 * RATIO_5_TO_8_BIT);
}
#endif
/*!
\brief Finds the index of the closest matching color in a rgb_color palette array
\param palette Array of 256 rgb_color objects
\param color Color to match
\return Index of the closest matching color
Note that passing a NULL palette will always return 0 and passing an array of less
than 256 rgb_colors will cause a crash.
*/
static uint8
FindClosestColor(const rgb_color *palette, rgb_color color)
{
if (!palette)
return 0;
uint16 cindex = 0, cdelta = 765, delta = 765;
for (uint16 i = 0; i < 256; i++) {
const rgb_color *c = &(palette[i]);
delta = abs(c->red-color.red) + abs(c->green-color.green)
+ abs(c->blue-color.blue);
if (delta == 0) {
cindex = i;
break;
}
if (delta < cdelta) {
cindex = i;
cdelta = delta;
}
}
return (uint8)cindex;
}
/*!
\brief Constructs a RGBA15 color which best matches a given 32-bit color
\param color Color to match
\return The closest matching color's value
Format is ARGB, 1:5:5:5
*/
static uint16
FindClosestColor15(rgb_color color)
{
uint16 r16 = uint16(color.red * RATIO_8_TO_5_BIT);
uint16 g16 = uint16(color.green * RATIO_8_TO_5_BIT);
uint16 b16 = uint16(color.blue * RATIO_8_TO_5_BIT);
// start with alpha value
uint16 color16 = color.alpha > 127 ? 0x8000 : 0;
color16 |= r16 << 10;
color16 |= g16 << 5;
color16 |= b16;
return color16;
}
/*!
\brief Constructs a RGB16 color which best matches a given 32-bit color
\param color Color to match
\return The closest matching color's value
Format is RGB, 5:6:5
*/
static uint16
FindClosestColor16(rgb_color color)
{
uint16 r16 = uint16(color.red * RATIO_8_TO_5_BIT);
uint16 g16 = uint16(color.green * RATIO_8_TO_6_BIT);
uint16 b16 = uint16(color.blue * RATIO_8_TO_5_BIT);
uint16 color16 = r16 << 11;
color16 |= g16 << 5;
color16 |= b16;
return color16;
}
// #pragma mark -
/*!
\brief Create an RGBColor from specified values
\param red red
@@ -50,7 +188,7 @@ RGBColor::RGBColor(const rgb_color &color)
SetColor(color);
}
#if 0
/*!
\brief Create an RGBColor from a 16-bit RGBA color
\param color color to initialize from
@@ -59,7 +197,7 @@ RGBColor::RGBColor(uint16 color)
{
SetColor(color);
}
#endif
/*!
\brief Create an RGBColor from an index color
@@ -190,7 +328,7 @@ RGBColor::SetColor(int r, int g, int b, int a)
fUpdate8 = fUpdate16 = true;
}
#if 0
/*!
\brief Set the object to specified value
\param col16 color to copy
@@ -204,6 +342,7 @@ RGBColor::SetColor(uint16 col16)
fUpdate8 = true;
fUpdate16 = false;
}
#endif
/*!