mirror of
https://review.haiku-os.org/haiku
synced 2025-02-03 12:16:35 +01:00
3302521556
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
49 lines
991 B
C
49 lines
991 B
C
/*
|
|
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*
|
|
* Authors:
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
*/
|
|
#ifndef SERVER_READ_ONLY_MEMORY_H
|
|
#define SERVER_READ_ONLY_MEMORY_H
|
|
|
|
|
|
#include <GraphicsDefs.h>
|
|
#include <InterfaceDefs.h>
|
|
|
|
|
|
struct server_read_only_memory {
|
|
rgb_color colors[B_COLOR_WHICH_COUNT];
|
|
};
|
|
|
|
|
|
static inline int32
|
|
color_which_to_index(color_which which)
|
|
{
|
|
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_COLOR_WHICH_COUNT - 3;
|
|
|
|
return -1;
|
|
}
|
|
|
|
|
|
static inline color_which
|
|
index_to_color_which(int32 index)
|
|
{
|
|
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_COLOR_WHICH_COUNT - 3);
|
|
}
|
|
}
|
|
|
|
return (color_which)-1;
|
|
}
|
|
|
|
#endif /* SERVER_READ_ONLY_MEMORY_H */
|