From 6d72871942adf03e13436ff9342951543351cea6 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 17 Jul 2018 20:12:29 +0200 Subject: 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 by std::array. Using a reference-counted, copy-on-write, dynamic container for static data seems like overkill. std::array 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 --- core/color.cpp | 129 ++++++++++++++++++++++---------------------- core/color.h | 11 ---- subsurface-desktop-main.cpp | 1 - subsurface-mobile-main.cpp | 1 - 4 files changed, 64 insertions(+), 78 deletions(-) diff --git a/core/color.cpp b/core/color.cpp index c0b8a4643..e0a599aca 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -1,79 +1,78 @@ // SPDX-License-Identifier: GPL-2.0 #include "color.h" +#include +#include -QMap > profile_color; +// Note that std::array is in every respect equivalent to QColor[2], +// but allows assignment, comparison, can be returned from functions, etc. +static QMap> 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() -{ -#define COLOR(x, y, z) QVector() << x << y << z; - profile_color[SAC_1] = COLOR(FUNGREEN1, BLACK1_LOW_TRANS, FUNGREEN1); - profile_color[SAC_2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1); - 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); - profile_color[VELO_SLOW] = COLOR(LIMENADE1, BLACK1_LOW_TRANS, LIMENADE1); - profile_color[VELO_MODERATE] = COLOR(RIOGRANDE1, BLACK1_LOW_TRANS, RIOGRANDE1); - profile_color[VELO_FAST] = COLOR(PIRATEGOLD1, BLACK1_LOW_TRANS, PIRATEGOLD1); - profile_color[VELO_CRAZY] = COLOR(RED1, BLACK1_LOW_TRANS, RED1); + { VELO_STABLE, { CAMARONE1, BLACK1_LOW_TRANS } }, + { VELO_SLOW, { LIMENADE1, BLACK1_LOW_TRANS } }, + { VELO_MODERATE, { RIOGRANDE1, BLACK1_LOW_TRANS } }, + { VELO_FAST, { PIRATEGOLD1, BLACK1_LOW_TRANS } }, + { VELO_CRAZY, { RED1, BLACK1_LOW_TRANS } }, - profile_color[PO2] = COLOR(APPLE1, BLACK1_LOW_TRANS, APPLE1); - 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); + { PO2, { APPLE1, BLACK1_LOW_TRANS } }, + { PO2_ALERT, { RED1, BLACK1_LOW_TRANS } }, + { PN2, { BLACK1_LOW_TRANS, BLACK1_LOW_TRANS } }, + { PN2_ALERT, { RED1, BLACK1_LOW_TRANS } }, + { 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[PP_LINES] = COLOR(BLACK1_HIGH_TRANS, BLACK1_LOW_TRANS, BLACK1_HIGH_TRANS); + { PP_LINES, { BLACK1_HIGH_TRANS, BLACK1_LOW_TRANS } }, - profile_color[TEXT_BACKGROUND] = COLOR(CONCRETE1_LOWER_TRANS, WHITE1, CONCRETE1_LOWER_TRANS); - profile_color[ALERT_BG] = COLOR(BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS, BROOM1_LOWER_TRANS); - profile_color[ALERT_FG] = COLOR(BLACK1_LOW_TRANS, WHITE1, BLACK1_LOW_TRANS); - profile_color[EVENTS] = COLOR(REDORANGE1, BLACK1_LOW_TRANS, REDORANGE1); - profile_color[SAMPLE_DEEP] = COLOR(QColor(Qt::red).darker(), BLACK1, PERSIANRED1); - profile_color[SAMPLE_SHALLOW] = COLOR(QColor(Qt::red).lighter(), BLACK1_LOW_TRANS, PERSIANRED1); - profile_color[SMOOTHED] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS, REDORANGE1_HIGH_TRANS); - profile_color[MINUTE] = COLOR(MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS, MEDIUMREDVIOLET1_HIGHER_TRANS); - profile_color[TIME_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS); - profile_color[TIME_TEXT] = COLOR(FORESTGREEN1, BLACK1, FORESTGREEN1); - profile_color[DEPTH_GRID] = COLOR(WHITE1, BLACK1_HIGH_TRANS, TUNDORA1_MED_TRANS); - profile_color[MEAN_DEPTH] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS); - profile_color[HR_PLOT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS); - profile_color[HR_TEXT] = COLOR(REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS, REDORANGE1_MED_TRANS); - profile_color[HR_AXIS] = COLOR(MED_GRAY_HIGH_TRANS, MED_GRAY_HIGH_TRANS, MED_GRAY_HIGH_TRANS); - profile_color[DEPTH_BOTTOM] = COLOR(GOVERNORBAY1_MED_TRANS, BLACK1_HIGH_TRANS, GOVERNORBAY1_MED_TRANS); - profile_color[DEPTH_TOP] = COLOR(MERCURY1_MED_TRANS, WHITE1_MED_TRANS, MERCURY1_MED_TRANS); - profile_color[TEMP_TEXT] = COLOR(GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2); - profile_color[TEMP_PLOT] = COLOR(ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS, ROYALBLUE2_LOW_TRANS); - profile_color[SAC_DEFAULT] = COLOR(WHITE1, BLACK1_LOW_TRANS, FORESTGREEN1); - profile_color[BOUNDING_BOX] = COLOR(WHITE1, BLACK1_LOW_TRANS, TUNDORA1_MED_TRANS); - profile_color[PRESSURE_TEXT] = COLOR(KILLARNEY1, BLACK1_LOW_TRANS, KILLARNEY1); - profile_color[BACKGROUND] = COLOR(SPRINGWOOD1, WHITE1, SPRINGWOOD1); - profile_color[BACKGROUND_TRANS] = COLOR(SPRINGWOOD1_MED_TRANS, WHITE1_MED_TRANS, SPRINGWOOD1_MED_TRANS); - profile_color[CEILING_SHALLOW] = COLOR(REDORANGE1_HIGH_TRANS, BLACK1_HIGH_TRANS, REDORANGE1_HIGH_TRANS); - profile_color[CEILING_DEEP] = COLOR(RED1_MED_TRANS, BLACK1_HIGH_TRANS, RED1_MED_TRANS); - profile_color[CALC_CEILING_SHALLOW] = COLOR(FUNGREEN1_HIGH_TRANS, BLACK1_HIGH_TRANS, FUNGREEN1_HIGH_TRANS); - profile_color[CALC_CEILING_DEEP] = COLOR(APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS, APPLE1_HIGH_TRANS); - profile_color[TISSUE_PERCENTAGE] = COLOR(GOVERNORBAY2, BLACK1_LOW_TRANS, GOVERNORBAY2); - 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 -} + { TEXT_BACKGROUND, { CONCRETE1_LOWER_TRANS, WHITE1 } }, + { ALERT_BG, { BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS } }, + { ALERT_FG, { BLACK1_LOW_TRANS, WHITE1 } }, + { EVENTS, { REDORANGE1, BLACK1_LOW_TRANS } }, + { SAMPLE_DEEP, { QColor(Qt::red).darker(), BLACK1 } }, + { SAMPLE_SHALLOW, { QColor(Qt::red).lighter(), BLACK1_LOW_TRANS } }, + { SMOOTHED, { REDORANGE1_HIGH_TRANS, BLACK1_LOW_TRANS } }, + { MINUTE, { MEDIUMREDVIOLET1_HIGHER_TRANS, BLACK1_LOW_TRANS } }, + { TIME_GRID, { WHITE1, BLACK1_HIGH_TRANS } }, + { TIME_TEXT, { FORESTGREEN1, BLACK1 } }, + { DEPTH_GRID, { WHITE1, BLACK1_HIGH_TRANS } }, + { MEAN_DEPTH, { REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS } }, + { HR_PLOT, { REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS } }, + { HR_TEXT, { REDORANGE1_MED_TRANS, BLACK1_LOW_TRANS } }, + { HR_AXIS, { MED_GRAY_HIGH_TRANS, MED_GRAY_HIGH_TRANS } }, + { DEPTH_BOTTOM, { GOVERNORBAY1_MED_TRANS, BLACK1_HIGH_TRANS } }, + { DEPTH_TOP, { MERCURY1_MED_TRANS, WHITE1_MED_TRANS } }, + { TEMP_TEXT, { GOVERNORBAY2, BLACK1_LOW_TRANS } }, + { TEMP_PLOT, { ROYALBLUE2_LOW_TRANS, BLACK1_LOW_TRANS } }, + { SAC_DEFAULT, { WHITE1, BLACK1_LOW_TRANS } }, + { BOUNDING_BOX, { WHITE1, BLACK1_LOW_TRANS } }, + { PRESSURE_TEXT, { KILLARNEY1, BLACK1_LOW_TRANS } }, + { BACKGROUND, { SPRINGWOOD1, WHITE1 } }, + { BACKGROUND_TRANS, { SPRINGWOOD1_MED_TRANS, WHITE1_MED_TRANS } }, + { CEILING_SHALLOW, { REDORANGE1_HIGH_TRANS, BLACK1_HIGH_TRANS } }, + { CEILING_DEEP, { RED1_MED_TRANS, BLACK1_HIGH_TRANS } }, + { CALC_CEILING_SHALLOW, { FUNGREEN1_HIGH_TRANS, BLACK1_HIGH_TRANS } }, + { CALC_CEILING_DEEP, { APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS } }, + { TISSUE_PERCENTAGE, { GOVERNORBAY2, BLACK1_LOW_TRANS } }, + { GF_LINE, { BLACK1, BLACK1_LOW_TRANS } }, + { AMB_PRESSURE_LINE, { TUNDORA1_MED_TRANS, BLACK1_LOW_TRANS } } +}; QColor getColor(const color_index_t i, bool isGrayscale) { 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); } diff --git a/core/color.h b/core/color.h index bf2f1ddcb..246808d19 100644 --- a/core/color.h +++ b/core/color.h @@ -6,8 +6,6 @@ from http://chir.ag/projects/name-that-color */ #include -#include -#include // Greens #define CAMARONE1 QColor::fromRgbF(0.0, 0.4, 0.0, 1) @@ -140,17 +138,8 @@ typedef enum { AMB_PRESSURE_LINE } color_index_t; -extern QMap > profile_color; -void fill_profile_color(); QColor getColor(const color_index_t i, bool isGrayscale = false); QColor getSacColor(int sac, int diveSac); 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 diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp index 8d1532c08..8cb6ffa50 100644 --- a/subsurface-desktop-main.cpp +++ b/subsurface-desktop-main.cpp @@ -84,7 +84,6 @@ int main(int argc, char **argv) qsrand(time(NULL)); setup_system_prefs(); copy_prefs(&default_prefs, &prefs); - fill_profile_color(); fill_computer_list(); parse_xml_init(); taglist_init_global(); diff --git a/subsurface-mobile-main.cpp b/subsurface-mobile-main.cpp index cd9c9dfa4..91bfd65d9 100644 --- a/subsurface-mobile-main.cpp +++ b/subsurface-mobile-main.cpp @@ -83,7 +83,6 @@ int main(int argc, char **argv) else default_prefs.units = IMPERIAL_units; copy_prefs(&default_prefs, &prefs); - fill_profile_color(); fill_computer_list(); parse_xml_init(); -- cgit v1.2.3-70-g09d2