Remove dependence on color constants in ServerReadOnlyMemory.
This fixes a maintainance problem where you have to update this otherwise unrelated file to keep it in sync whenever you add a color constant. I've added a B_COLOR_WHICH_COUNT constant to the color_which enum which should be updated to point to the newest color constants as new ones are added. I reworked ServerReadOnlyMemory to use this constant instead of using to the current largest color constant directly. If you use B_COLOR_WHICH_COUNT to refer to a color in your code expect to get unpredictable and nonsensical results. Most likely you'll get an undefined result which will return black but don't depend on it. The net effect of this is that ServerReadOnlyMemory doesn't need to be updated anymore when new color constants are introduced but will continue to produce correct results. Eliminate kNumColors constant, replace it with B_COLOR_WHICH_COUNT
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include <Path.h>
|
||||
|
||||
#include <DefaultColors.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <ServerReadOnlyMemory.h>
|
||||
|
||||
#include "Desktop.h"
|
||||
@@ -77,7 +78,7 @@ DesktopSettingsPrivate::_SetDefaults()
|
||||
fWorkspacesRows = 2;
|
||||
|
||||
memcpy(fShared.colors, BPrivate::kDefaultColors,
|
||||
sizeof(rgb_color) * kNumColors);
|
||||
sizeof(rgb_color) * B_COLOR_WHICH_COUNT);
|
||||
|
||||
gSubpixelAntialiasing = false;
|
||||
gDefaultHintingMode = HINTING_MODE_ON;
|
||||
@@ -291,7 +292,7 @@ DesktopSettingsPrivate::_Load()
|
||||
}
|
||||
|
||||
// colors
|
||||
for (int32 i = 0; i < kNumColors; i++) {
|
||||
for (int32 i = 0; i < B_COLOR_WHICH_COUNT; i++) {
|
||||
char colorName[12];
|
||||
snprintf(colorName, sizeof(colorName), "color%" B_PRId32,
|
||||
(int32)index_to_color_which(i));
|
||||
@@ -436,7 +437,7 @@ DesktopSettingsPrivate::Save(uint32 mask)
|
||||
settings.AddInt8("subpixel average weight", gSubpixelAverageWeight);
|
||||
settings.AddBool("subpixel ordering", gSubpixelOrderingRGB);
|
||||
|
||||
for (int32 i = 0; i < kNumColors; i++) {
|
||||
for (int32 i = 0; i < B_COLOR_WHICH_COUNT; i++) {
|
||||
char colorName[12];
|
||||
snprintf(colorName, sizeof(colorName), "color%" B_PRId32,
|
||||
(int32)index_to_color_which(i));
|
||||
@@ -648,10 +649,10 @@ DesktopSettingsPrivate::WorkspacesMessage(int32 index) const
|
||||
void
|
||||
DesktopSettingsPrivate::SetUIColor(color_which which, const rgb_color color)
|
||||
{
|
||||
//
|
||||
int32 index = color_which_to_index(which);
|
||||
if (index < 0 || index >= kNumColors)
|
||||
if (index < 0 || index >= B_COLOR_WHICH_COUNT)
|
||||
return;
|
||||
|
||||
fShared.colors[index] = color;
|
||||
// TODO: deprecate the background_color member of the menu_info struct,
|
||||
// otherwise we have to keep this duplication...
|
||||
@@ -666,7 +667,7 @@ DesktopSettingsPrivate::UIColor(color_which which) const
|
||||
{
|
||||
static const rgb_color invalidColor = {0, 0, 0, 0};
|
||||
int32 index = color_which_to_index(which);
|
||||
if (index < 0 || index >= kNumColors)
|
||||
if (index < 0 || index >= B_COLOR_WHICH_COUNT)
|
||||
return invalidColor;
|
||||
return fShared.colors[index];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user