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:
@@ -13,23 +13,18 @@
|
||||
#include <InterfaceDefs.h>
|
||||
|
||||
|
||||
static const int32 kNumColors = 35;
|
||||
|
||||
struct server_read_only_memory {
|
||||
rgb_color colors[kNumColors];
|
||||
rgb_color colors[B_COLOR_WHICH_COUNT];
|
||||
};
|
||||
|
||||
|
||||
// NOTE: these functions must be kept in sync with InterfaceDefs.h color_which!
|
||||
|
||||
static inline int32
|
||||
color_which_to_index(color_which which)
|
||||
{
|
||||
// NOTE: this must be kept in sync with InterfaceDefs.h color_which!
|
||||
if (which <= B_SCROLL_BAR_THUMB_COLOR)
|
||||
if (which <= B_COLOR_WHICH_COUNT - 3)
|
||||
return which - 1;
|
||||
if (which >= B_SUCCESS_COLOR && which <= B_FAILURE_COLOR)
|
||||
return which - B_SUCCESS_COLOR + B_SCROLL_BAR_THUMB_COLOR;
|
||||
return which - B_SUCCESS_COLOR + B_COLOR_WHICH_COUNT - 3;
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -38,12 +33,12 @@ color_which_to_index(color_which which)
|
||||
static inline color_which
|
||||
index_to_color_which(int32 index)
|
||||
{
|
||||
if (index >= 0 && index < kNumColors) {
|
||||
if ((color_which)index < B_SCROLL_BAR_THUMB_COLOR)
|
||||
if (index >= 0 && index < B_COLOR_WHICH_COUNT) {
|
||||
if ((color_which)index < B_COLOR_WHICH_COUNT - 3)
|
||||
return (color_which)(index + 1);
|
||||
else {
|
||||
return (color_which)(index + B_SUCCESS_COLOR
|
||||
- B_SCROLL_BAR_THUMB_COLOR);
|
||||
- B_COLOR_WHICH_COUNT - 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user