Cleanups to core/color.[c|hpp]

A number of small cleanups to the color-table:

1) Make the profile_color map of static linkage - it is not
used outside of this file.

2) Remove the third color, which originally was planned for
printing. It was not accessed anywhere.

3) Replace QVector<QColor> by std::array<QColor, 2>. Using a
reference-counted, copy-on-write, dynamic container for static
data seems like overkill. std::array<QColor, 2> has exactly the
same run-time impact as QColor[2], but allows for assignment.

4) Use brace-initialization and remove the unneeded COLOR macro.

5) Remove the fill_profile_color function. Simply use static
initialization.

6) Move #includes from .h to .cpp file.

7) Remove text_render_options(_t), which were not used anywhere.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-07-17 20:12:29 +02:00 committed by Lubomir I. Ivanov
parent 2c6b1a99af
commit 6d72871942
4 changed files with 64 additions and 78 deletions

View file

@ -1,79 +1,78 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "color.h" #include "color.h"
#include <QMap>
#include <array>
QMap<color_index_t, QVector<QColor> > profile_color; // Note that std::array<QColor, 2> is in every respect equivalent to QColor[2],
// but allows assignment, comparison, can be returned from functions, etc.
static QMap<color_index_t, std::array<QColor, 2>> profile_color = {
{ SAC_1, { FUNGREEN1, BLACK1_LOW_TRANS } },
{ SAC_2, { APPLE1, BLACK1_LOW_TRANS } },
{ SAC_3, { ATLANTIS1, BLACK1_LOW_TRANS } },
{ SAC_4, { ATLANTIS2, BLACK1_LOW_TRANS } },
{ SAC_5, { EARLSGREEN1, BLACK1_LOW_TRANS } },
{ SAC_6, { HOKEYPOKEY1, BLACK1_LOW_TRANS } },
{ SAC_7, { TUSCANY1, BLACK1_LOW_TRANS } },
{ SAC_8, { CINNABAR1, BLACK1_LOW_TRANS } },
{ SAC_9, { REDORANGE1, BLACK1_LOW_TRANS } },
void fill_profile_color() { VELO_STABLE, { CAMARONE1, BLACK1_LOW_TRANS } },
{ { VELO_SLOW, { LIMENADE1, BLACK1_LOW_TRANS } },
#define COLOR(x, y, z) QVector<QColor>() << x << y << z; { VELO_MODERATE, { RIOGRANDE1, BLACK1_LOW_TRANS } },
profile_color[SAC_1] = COLOR(FUNGREEN1, BLACK1_LOW_TRANS, FUNGREEN1); { VELO_FAST, { PIRATEGOLD1, BLACK1_LOW_TRANS } },
profile_color[SAC_2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1); { VELO_CRAZY, { RED1, BLACK1_LOW_TRANS } },
profile_color[SAC_3] = COLOR(ATLANTIS1, BLACK1_LOW_TRANS, ATLANTIS1);
profile_color[SAC_4] = COLOR(ATLANTIS2, BLACK1_LOW_TRANS, ATLANTIS2);
profile_color[SAC_5] = COLOR(EARLSGREEN1, BLACK1_LOW_TRANS, EARLSGREEN1);
profile_color[SAC_6] = COLOR(HOKEYPOKEY1, BLACK1_LOW_TRANS, HOKEYPOKEY1);
profile_color[SAC_7] = COLOR(TUSCANY1, BLACK1_LOW_TRANS, TUSCANY1);
profile_color[SAC_8] = COLOR(CINNABAR1, BLACK1_LOW_TRANS, CINNABAR1);
profile_color[SAC_9] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1);
profile_color[VELO_STABLE] = COLOR(CAMARONE1, BLACK1_LOW_TRANS, CAMARONE1); { PO2, { APPLE1, BLACK1_LOW_TRANS } },
profile_color[VELO_SLOW] = COLOR(LIMENADE1, BLACK1_LOW_TRANS, LIMENADE1); { PO2_ALERT, { RED1, BLACK1_LOW_TRANS } },
profile_color[VELO_MODERATE] = COLOR(RIOGRANDE1, BLACK1_LOW_TRANS, RIOGRANDE1); { PN2, { BLACK1_LOW_TRANS, BLACK1_LOW_TRANS } },
profile_color[VELO_FAST] = COLOR(PIRATEGOLD1, BLACK1_LOW_TRANS, PIRATEGOLD1); { PN2_ALERT, { RED1, BLACK1_LOW_TRANS } },
profile_color[VELO_CRAZY] = COLOR(RED1, BLACK1_LOW_TRANS, RED1); { PHE, { PEANUT, BLACK1_LOW_TRANS } },
{ PHE_ALERT, { RED1, BLACK1_LOW_TRANS } },
{ O2SETPOINT, { PIRATEGOLD1_MED_TRANS, BLACK1_LOW_TRANS } },
{ CCRSENSOR1, { TUNDORA1_MED_TRANS, BLACK1_LOW_TRANS } },
{ CCRSENSOR2, { ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS } },
{ CCRSENSOR3, { PEANUT, BLACK1_LOW_TRANS } },
{ SCR_OCPO2, { PIRATEGOLD1_MED_TRANS, BLACK1_LOW_TRANS } },
profile_color[PO2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1); { PP_LINES, { BLACK1_HIGH_TRANS, BLACK1_LOW_TRANS } },
profile_color[PO2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PN2] = COLOR(BLACK1_LOW_TRANS, BLACK1_LOW_TRANS, BLACK1_LOW_TRANS);
profile_color[PN2_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[PHE] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT);
profile_color[PHE_ALERT] = COLOR(RED1, BLACK1_LOW_TRANS, RED1);
profile_color[O2SETPOINT] = COLOR(PIRATEGOLD1_MED_TRANS, BLACK1_LOW_TRANS, PIRATEGOLD1_MED_TRANS);
profile_color[CCRSENSOR1] = COLOR(TUNDORA1_MED_TRANS, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS);
profile_color[CCRSENSOR2] = COLOR(ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS);
profile_color[CCRSENSOR3] = COLOR(PEANUT, BLACK1_LOW_TRANS, PEANUT);
profile_color[SCR_OCPO2] = COLOR(PIRATEGOLD1_MED_TRANS, BLACK1_LOW_TRANS, PIRATEGOLD1_MED_TRANS);
profile_color[PP_LINES] = COLOR(BLACK1_HIGH_TRANS, BLACK1_LOW_TRANS, BLACK1_HIGH_TRANS); { TEXT_BACKGROUND, { CONCRETE1_LOWER_TRANS, WHITE1 } },
{ ALERT_BG, { BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS } },
profile_color[TEXT_BACKGROUND] = COLOR(CONCRETE1_LOWER_TRANS, WHITE1, CONCRETE1_LOWER_TRANS); { ALERT_FG, { BLACK1_LOW_TRANS, WHITE1 } },
profile_color[ALERT_BG] = COLOR(BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS, BROOM1_LOWER_TRANS); { EVENTS, { REDORANGE1, BLACK1_LOW_TRANS } },
profile_color[ALERT_FG] = COLOR(BLACK1_LOW_TRANS, WHITE1, BLACK1_LOW_TRANS); { SAMPLE_DEEP, { QColor(Qt::red).darker(), BLACK1 } },
profile_color[EVENTS] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1); { SAMPLE_SHALLOW, { QColor(Qt::red).lighter(), BLACK1_LOW_TRANS } },
profile_color[SAMPLE_DEEP] = COLOR(QColor(Qt::red).darker(), BLACK1, PERSIANRED1); { SMOOTHED, { REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS } },
profile_color[SAMPLE_SHALLOW] = COLOR(QColor(Qt::red).lighter(), BLACK1_LOW_TRANS, PERSIANRED1); { MINUTE, { MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS } },
profile_color[SMOOTHED] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS, REDORANGE1_HIGH_TRANS); { TIME_GRID, { WHITE1, BLACK1_HIGH_TRANS } },
profile_color[MINUTE] = COLOR(MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS, MEDIUMREDVIOLET1_HIGHER_TRANS); { TIME_TEXT, { FORESTGREEN1, BLACK1 } },
profile_color[TIME_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS); { DEPTH_GRID, { WHITE1, BLACK1_HIGH_TRANS } },
profile_color[TIME_TEXT] = COLOR(FORESTGREEN1, BLACK1, FORESTGREEN1); { MEAN_DEPTH, { REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS } },
profile_color[DEPTH_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS); { HR_PLOT, { REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS } },
profile_color[MEAN_DEPTH] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS); { HR_TEXT, { REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS } },
profile_color[HR_PLOT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS); { HR_AXIS, { MED_GRAY_HIGH_TRANS, MED_GRAY_HIGH_TRANS } },
profile_color[HR_TEXT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS); { DEPTH_BOTTOM, { GOVERNORBAY1_MED_TRANS, BLACK1_HIGH_TRANS } },
profile_color[HR_AXIS] = COLOR(MED_GRAY_HIGH_TRANS, MED_GRAY_HIGH_TRANS, MED_GRAY_HIGH_TRANS); { DEPTH_TOP, { MERCURY1_MED_TRANS, WHITE1_MED_TRANS } },
profile_color[DEPTH_BOTTOM] = COLOR(GOVERNORBAY1_MED_TRANS, BLACK1_HIGH_TRANS, GOVERNORBAY1_MED_TRANS); { TEMP_TEXT, { GOVERNORBAY2, BLACK1_LOW_TRANS } },
profile_color[DEPTH_TOP] = COLOR(MERCURY1_MED_TRANS, WHITE1_MED_TRANS, MERCURY1_MED_TRANS); { TEMP_PLOT, { ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS } },
profile_color[TEMP_TEXT] = COLOR(GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2); { SAC_DEFAULT, { WHITE1, BLACK1_LOW_TRANS } },
profile_color[TEMP_PLOT] = COLOR(ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS); { BOUNDING_BOX, { WHITE1, BLACK1_LOW_TRANS } },
profile_color[SAC_DEFAULT] = COLOR(WHITE1, BLACK1_LOW_TRANS, FORESTGREEN1); { PRESSURE_TEXT, { KILLARNEY1, BLACK1_LOW_TRANS } },
profile_color[BOUNDING_BOX] = COLOR(WHITE1, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS); { BACKGROUND, { SPRINGWOOD1, WHITE1 } },
profile_color[PRESSURE_TEXT] = COLOR(KILLARNEY1, BLACK1_LOW_TRANS, KILLARNEY1); { BACKGROUND_TRANS, { SPRINGWOOD1_MED_TRANS, WHITE1_MED_TRANS } },
profile_color[BACKGROUND] = COLOR(SPRINGWOOD1, WHITE1, SPRINGWOOD1); { CEILING_SHALLOW, { REDORANGE1_HIGH_TRANS, BLACK1_HIGH_TRANS } },
profile_color[BACKGROUND_TRANS] = COLOR(SPRINGWOOD1_MED_TRANS, WHITE1_MED_TRANS, SPRINGWOOD1_MED_TRANS); { CEILING_DEEP, { RED1_MED_TRANS, BLACK1_HIGH_TRANS } },
profile_color[CEILING_SHALLOW] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_HIGH_TRANS, REDORANGE1_HIGH_TRANS); { CALC_CEILING_SHALLOW, { FUNGREEN1_HIGH_TRANS, BLACK1_HIGH_TRANS } },
profile_color[CEILING_DEEP] = COLOR(RED1_MED_TRANS, BLACK1_HIGH_TRANS, RED1_MED_TRANS); { CALC_CEILING_DEEP, { APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS } },
profile_color[CALC_CEILING_SHALLOW] = COLOR(FUNGREEN1_HIGH_TRANS, BLACK1_HIGH_TRANS, FUNGREEN1_HIGH_TRANS); { TISSUE_PERCENTAGE, { GOVERNORBAY2, BLACK1_LOW_TRANS } },
profile_color[CALC_CEILING_DEEP] = COLOR(APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS, APPLE1_HIGH_TRANS); { GF_LINE, { BLACK1, BLACK1_LOW_TRANS } },
profile_color[TISSUE_PERCENTAGE] = COLOR(GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2); { AMB_PRESSURE_LINE, { TUNDORA1_MED_TRANS, BLACK1_LOW_TRANS } }
profile_color[GF_LINE] = COLOR(BLACK1, BLACK1_LOW_TRANS, BLACK1); };
profile_color[AMB_PRESSURE_LINE] = COLOR(TUNDORA1_MED_TRANS, BLACK1_LOW_TRANS, ATLANTIS1);
#undef COLOR
}
QColor getColor(const color_index_t i, bool isGrayscale) QColor getColor(const color_index_t i, bool isGrayscale)
{ {
if (profile_color.count() > i && i >= 0) if (profile_color.count() > i && i >= 0)
return profile_color[i].at((isGrayscale) ? 1 : 0); return profile_color[i][isGrayscale ? 1 : 0];
return QColor(Qt::black); return QColor(Qt::black);
} }

View file

@ -6,8 +6,6 @@
from http://chir.ag/projects/name-that-color */ from http://chir.ag/projects/name-that-color */
#include <QColor> #include <QColor>
#include <QMap>
#include <QVector>
// Greens // Greens
#define CAMARONE1 QColor::fromRgbF(0.0, 0.4, 0.0, 1) #define CAMARONE1 QColor::fromRgbF(0.0, 0.4, 0.0, 1)
@ -140,17 +138,8 @@ typedef enum {
AMB_PRESSURE_LINE AMB_PRESSURE_LINE
} color_index_t; } color_index_t;
extern QMap<color_index_t, QVector<QColor> > profile_color;
void fill_profile_color();
QColor getColor(const color_index_t i, bool isGrayscale = false); QColor getColor(const color_index_t i, bool isGrayscale = false);
QColor getSacColor(int sac, int diveSac); QColor getSacColor(int sac, int diveSac);
QColor getPressureColor(double density); QColor getPressureColor(double density);
struct text_render_options {
double size;
color_index_t color;
double hpos, vpos;
};
typedef text_render_options text_render_options_t;
#endif // COLOR_H #endif // COLOR_H

View file

@ -84,7 +84,6 @@ int main(int argc, char **argv)
qsrand(time(NULL)); qsrand(time(NULL));
setup_system_prefs(); setup_system_prefs();
copy_prefs(&default_prefs, &prefs); copy_prefs(&default_prefs, &prefs);
fill_profile_color();
fill_computer_list(); fill_computer_list();
parse_xml_init(); parse_xml_init();
taglist_init_global(); taglist_init_global();

View file

@ -83,7 +83,6 @@ int main(int argc, char **argv)
else else
default_prefs.units = IMPERIAL_units; default_prefs.units = IMPERIAL_units;
copy_prefs(&default_prefs, &prefs); copy_prefs(&default_prefs, &prefs);
fill_profile_color();
fill_computer_list(); fill_computer_list();
parse_xml_init(); parse_xml_init();