Skip to content

Commit

Permalink
Merge pull request #65118 from sparr/change_colors_less
Browse files Browse the repository at this point in the history
Reduce repetitive output color changes
  • Loading branch information
Night-Pryanik authored Nov 13, 2024
2 parents f1fa949 + 56d0896 commit 1692e4a
Show file tree
Hide file tree
Showing 43 changed files with 711 additions and 723 deletions.
33 changes: 18 additions & 15 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,30 +144,32 @@ void draw_explosion_curses( game &g, const tripoint_bub_ms &center, const int r,
int frame = 0;
shared_ptr_fast<game::draw_callback_t> explosion_cb =
make_shared_fast<game::draw_callback_t>( [&]() {
wattron( g.w_terrain, col );
if( r == 0 ) {
mvwputch( g.w_terrain, point( p.y(), p.x() ), col, '*' );
mvwaddch( g.w_terrain, point( p.y(), p.x() ), '*' );
}

for( int i = 1; i <= frame; ++i ) {
// corner: top left
mvwputch( g.w_terrain, p.xy().raw() + point( -i, -i ), col, '/' );
mvwaddch( g.w_terrain, p.xy().raw() + point( -i, -i ), '/' );
// corner: top right
mvwputch( g.w_terrain, p.xy().raw() + point( i, -i ), col, '\\' );
mvwaddch( g.w_terrain, p.xy().raw() + point( i, -i ), '\\' );
// corner: bottom left
mvwputch( g.w_terrain, p.xy().raw() + point( -i, i ), col, '\\' );
mvwaddch( g.w_terrain, p.xy().raw() + point( -i, i ), '\\' );
// corner: bottom right
mvwputch( g.w_terrain, p.xy().raw() + point( i, i ), col, '/' );
mvwaddch( g.w_terrain, p.xy().raw() + point( i, i ), '/' );
for( int j = 1 - i; j < 0 + i; j++ ) {
// edge: top
mvwputch( g.w_terrain, p.xy().raw() + point( j, -i ), col, '-' );
mvwaddch( g.w_terrain, p.xy().raw() + point( j, -i ), '-' );
// edge: bottom
mvwputch( g.w_terrain, p.xy().raw() + point( j, i ), col, '-' );
mvwaddch( g.w_terrain, p.xy().raw() + point( j, i ), '-' );
// edge: left
mvwputch( g.w_terrain, p.xy().raw() + point( -i, j ), col, '|' );
mvwaddch( g.w_terrain, p.xy().raw() + point( -i, j ), '|' );
// edge: right
mvwputch( g.w_terrain, p.xy().raw() + point( i, j ), col, '|' );
mvwaddch( g.w_terrain, p.xy().raw() + point( i, j ), '|' );
}
}
wattroff( g.w_terrain, col );
} );
g.add_draw_callback( explosion_cb );

Expand Down Expand Up @@ -889,9 +891,12 @@ namespace
{
void draw_weather_curses( const catacurses::window &win, const weather_printable &w )
{
wattron( win, w.colGlyph );
const std::string symbol = w.get_symbol();
for( const auto &drop : w.vdrops ) {
mvwputch( win, point( drop.first, drop.second ), w.colGlyph, w.get_symbol() );
mvwprintw( win, point( drop.first, drop.second ), symbol );
}
wattroff( win, w.colGlyph );
}
} //namespace

Expand Down Expand Up @@ -965,12 +970,10 @@ void draw_zones_curses( const catacurses::window &w, const tripoint_bub_ms &star
}

nc_color const col = invert_color( c_light_green );
const std::string line( end.x() - start.x() + 1, '~' );
int const x = start.x() - offset.x;

for( int y = start.y(); y <= end.y(); ++y ) {
mvwprintz( w, point( x, y - offset.y ), col, line );
}
wattron( w, col );
mvwrectf( w, ( start.raw() - offset ).xy(), '~', end.x() - start.x() + 1, end.y() - start.y() + 1 );
wattroff( w, col );
}
} //namespace

Expand Down
20 changes: 11 additions & 9 deletions src/armor_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,21 +583,23 @@ static void draw_grid( const catacurses::window &w, int left_pane_w, int mid_pan
const int win_h = getmaxy( w );

draw_border( w );

wattron( w, BORDER_COLOR );
mvwhline( w, point( 1, 2 ), 0, win_w - 2 );
mvwhline( w, point( left_pane_w + 2, encumb_top - 1 ), 0, mid_pane_w );
mvwvline( w, point( left_pane_w + 1, 3 ), 0, win_h - 4 );
mvwvline( w, point( left_pane_w + mid_pane_w + 2, 3 ), 0, win_h - 4 );

// intersections
mvwputch( w, point( 0, 2 ), BORDER_COLOR, LINE_XXXO ); // '|-'
mvwputch( w, point( win_w - 1, 2 ), BORDER_COLOR, LINE_XOXX ); // '-|'
mvwputch( w, point( left_pane_w + 1, encumb_top - 1 ), BORDER_COLOR, LINE_XXXO ); // '|-'
mvwputch( w, point( left_pane_w + mid_pane_w + 2, encumb_top - 1 ), BORDER_COLOR,
LINE_XOXX ); // '-|'
mvwputch( w, point( left_pane_w + 1, 2 ), BORDER_COLOR, LINE_OXXX ); // '^|^'
mvwputch( w, point( left_pane_w + 1, win_h - 1 ), BORDER_COLOR, LINE_XXOX ); // '_|_'
mvwputch( w, point( left_pane_w + mid_pane_w + 2, 2 ), BORDER_COLOR, LINE_OXXX ); // '^|^'
mvwputch( w, point( left_pane_w + mid_pane_w + 2, win_h - 1 ), BORDER_COLOR, LINE_XXOX ); // '_|_'
mvwaddch( w, point( 0, 2 ), LINE_XXXO ); // '|-'
mvwaddch( w, point( win_w - 1, 2 ), LINE_XOXX ); // '-|'
mvwaddch( w, point( left_pane_w + 1, encumb_top - 1 ), LINE_XXXO ); // '|-'
mvwaddch( w, point( left_pane_w + mid_pane_w + 2, encumb_top - 1 ), LINE_XOXX ); // '-|'
mvwaddch( w, point( left_pane_w + 1, 2 ), LINE_OXXX ); // '^|^'
mvwaddch( w, point( left_pane_w + 1, win_h - 1 ), LINE_XXOX ); // '_|_'
mvwaddch( w, point( left_pane_w + mid_pane_w + 2, 2 ), LINE_OXXX ); // '^|^'
mvwaddch( w, point( left_pane_w + mid_pane_w + 2, win_h - 1 ), LINE_XXOX ); // '_|_'
wattroff( w, BORDER_COLOR );

wnoutrefresh( w );
}
Expand Down
42 changes: 18 additions & 24 deletions src/auto_note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,12 @@ void auto_note_manager_gui::show()
ui.on_redraw( [&]( const ui_adaptor & ) {
// == Draw border
draw_border( w_border, BORDER_COLOR, _( "Auto notes manager" ) );
mvwputch( w_border, point( 0, iHeaderHeight - 1 ), c_light_gray, LINE_XXXO );
mvwputch( w_border, point( 79, iHeaderHeight - 1 ), c_light_gray, LINE_XOXX );
mvwputch( w_border, point( 52, FULL_SCREEN_HEIGHT - 1 ), c_light_gray, LINE_XXOX );
mvwputch( w_border, point( 61, FULL_SCREEN_HEIGHT - 1 ), c_light_gray, LINE_XXOX );
wattron( w_border, c_light_gray );
mvwaddch( w_border, point( 0, iHeaderHeight - 1 ), LINE_XXXO );
mvwaddch( w_border, point( 79, iHeaderHeight - 1 ), LINE_XOXX );
mvwaddch( w_border, point( 52, FULL_SCREEN_HEIGHT - 1 ), LINE_XXOX );
mvwaddch( w_border, point( 61, FULL_SCREEN_HEIGHT - 1 ), LINE_XXOX );
wattroff( w_border, c_light_gray );
wnoutrefresh( w_border );

// == Draw header
Expand All @@ -367,14 +369,13 @@ void auto_note_manager_gui::show()
shortcut_print( w_header, point( tmpx, 0 ), c_white, c_light_green, _( "<Enter> - Toggle" ) );

// Draw horizontal line and corner pieces of the table
for( int x = 0; x < 78; x++ ) {
if( x == 51 || x == 60 ) {
mvwputch( w_header, point( x, iHeaderHeight - 2 ), c_light_gray, LINE_OXXX );
mvwputch( w_header, point( x, iHeaderHeight - 1 ), c_light_gray, LINE_XOXO );
} else {
mvwputch( w_header, point( x, iHeaderHeight - 2 ), c_light_gray, LINE_OXOX );
}
}
wattron( w_header, c_light_gray );
mvwhline( w_header, point( 0, iHeaderHeight - 2 ), LINE_OXOX, 78 );
mvwaddch( w_header, point( 51, iHeaderHeight - 2 ), LINE_OXXX );
mvwaddch( w_header, point( 51, iHeaderHeight - 1 ), LINE_XOXO );
mvwaddch( w_header, point( 60, iHeaderHeight - 2 ), LINE_OXXX );
mvwaddch( w_header, point( 60, iHeaderHeight - 1 ), LINE_XOXO );
wattroff( w_header, c_light_gray );
tmpx = 17;
tmpx += shortcut_print( w_header, point( tmpx, iHeaderHeight - 2 ),
bCharacter ? hilite( c_white ) : c_white, c_light_green, _( "Character" ) ) + 2;
Expand Down Expand Up @@ -414,23 +415,16 @@ void auto_note_manager_gui::show()
_( "<Tab> to change pages." ) );

// Clear table
for( int y = 0; y < iContentHeight; y++ ) {
for( int x = 0; x < 79; x++ ) {
// The middle beams needs special treatment
if( x == 51 || x == 60 ) {
mvwputch( w, point( x, y ), c_light_gray, LINE_XOXO );
} else {
mvwputch( w, point( x, y ), c_black, ' ' );
}
}
}
mvwrectf( w, point_zero, c_black, ' ', 79, iContentHeight );
mvwvline( w, point( 51, 0 ), c_light_gray, LINE_XOXO, iContentHeight );
mvwvline( w, point( 60, 0 ), c_light_gray, LINE_XOXO, iContentHeight );
int cacheSize = bCharacter ? char_cacheSize : global_cacheSize;
draw_scrollbar( w_border, currentLine, iContentHeight, cacheSize, point( 0, iHeaderHeight + 1 ) );

if( bCharacter ? char_emptyMode : global_emptyMode ) {
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwprintz( w, point( 1, 0 ), c_light_gray,
_( "Discover more special encounters to populate this list" ) );
fold_and_print( w, point( 1, 0 ), 49, c_light_gray,
_( "Discover more special encounters to populate this list" ) );
} else {
calcStartPos( startPosition, currentLine, iContentHeight,
( bCharacter ? char_displayCache : global_displayCache ).size() );
Expand Down
48 changes: 22 additions & 26 deletions src/auto_pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,17 @@ void user_interface::show()
ui.on_redraw( [&]( const ui_adaptor & ) {
// Redraw the border
draw_border( w_border, BORDER_COLOR, title );

wattron( w, c_light_gray );
// |-
mvwputch( w_border, point( 0, 3 ), c_light_gray, LINE_XXXO );
mvwaddch( w_border, point( 0, 3 ), LINE_XXXO );
// -|
mvwputch( w_border, point( 79, 3 ), c_light_gray, LINE_XOXX );
mvwaddch( w_border, point( 79, 3 ), LINE_XOXX );
// _|_
mvwputch( w_border, point( 5, FULL_SCREEN_HEIGHT - 1 ), c_light_gray, LINE_XXOX );
mvwputch( w_border, point( 51, FULL_SCREEN_HEIGHT - 1 ), c_light_gray, LINE_XXOX );
mvwputch( w_border, point( 61, FULL_SCREEN_HEIGHT - 1 ), c_light_gray, LINE_XXOX );
mvwaddch( w_border, point( 5, FULL_SCREEN_HEIGHT - 1 ), LINE_XXOX );
mvwaddch( w_border, point( 51, FULL_SCREEN_HEIGHT - 1 ), LINE_XXOX );
mvwaddch( w_border, point( 61, FULL_SCREEN_HEIGHT - 1 ), LINE_XXOX );
wattroff( w, c_light_gray );
wnoutrefresh( w_border );

// Redraw the header
Expand All @@ -358,15 +361,15 @@ void user_interface::show()
_( "<Enter>-Edit" ) ) + 2;
shortcut_print( w_header, point( tmpx, 1 ), c_white, c_light_green, _( "<Tab>-Switch Page" ) );

for( int i = 0; i < 78; i++ ) {
if( i == 4 || i == 50 || i == 60 ) {
mvwputch( w_header, point( i, 2 ), c_light_gray, LINE_OXXX );
mvwputch( w_header, point( i, 3 ), c_light_gray, LINE_XOXO );
} else {
// Draw line under header
mvwputch( w_header, point( i, 2 ), c_light_gray, LINE_OXOX );
}
wattron( w_header, c_light_gray );
mvwhline( w_header, point( 0, 2 ), LINE_OXOX, 78 );
for( int x : {
4, 50, 60
} ) {
mvwaddch( w_header, point( x, 2 ), LINE_OXXX );
mvwaddch( w_header, point( x, 3 ), LINE_XOXO );
}
wattroff( w_header, c_light_gray );
mvwprintz( w_header, point( 1, 3 ), c_white, "#" );
mvwprintz( w_header, point( 8, 3 ), c_white, _( "Rules" ) );
mvwprintz( w_header, point( 52, 3 ), c_white, _( "Inc/Exc" ) );
Expand All @@ -390,14 +393,11 @@ void user_interface::show()
wnoutrefresh( w_header );

// Clear the lines
for( int i = 0; i < iContentHeight; i++ ) {
for( int j = 0; j < 79; j++ ) {
if( j == 4 || j == 50 || j == 60 ) {
mvwputch( w, point( j, i ), c_light_gray, LINE_XOXO );
} else {
mvwputch( w, point( j, i ), c_black, ' ' );
}
}
mvwrectf( w, point_zero, c_black, ' ', 79, iContentHeight );
for( int x : {
4, 50, 60
} ) {
mvwvline( w, point( x, 0 ), c_light_gray, LINE_XOXO, iContentHeight );
}

draw_scrollbar( w_border, iLine, iContentHeight, cur_rules.size(), point( 0, 5 ) );
Expand Down Expand Up @@ -700,11 +700,7 @@ void rule::test_pattern() const
wnoutrefresh( w_test_rule_border );

// Clear the lines
for( int i = 0; i < iContentHeight; i++ ) {
for( int j = 0; j < 79; j++ ) {
mvwputch( w_test_rule_content, point( j, i ), c_black, ' ' );
}
}
mvwrectf( w_test_rule_content, point_zero, c_black, ' ', 79, iContentHeight );

calcStartPos( iStartPos, iLine, iContentHeight, vMatchingItems.size() );

Expand Down
49 changes: 25 additions & 24 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,13 @@ static void draw_bionics_titlebar( const catacurses::window &window, avatar *p,
string_format( _( "Bionic Power: <color_light_blue>%s</color>/<color_light_blue>%ikJ</color>" ),
power_string, units::to_kilojoule( p->get_max_power_level() ) ) );

mvwputch( window, point( pwr_str_pos - 1, 1 ), BORDER_COLOR, LINE_XOXO ); // |
mvwputch( window, point( pwr_str_pos - 1, 2 ), BORDER_COLOR, LINE_XXOO ); // |_
for( int i = pwr_str_pos; i < getmaxx( window ); i++ ) {
mvwputch( window, point( i, 2 ), BORDER_COLOR, LINE_OXOX ); // -
}
for( int i = 0; i < getmaxx( window ); i++ ) {
mvwputch( window, point( i, 0 ), BORDER_COLOR, LINE_OXOX ); // -
}
mvwputch( window, point( pwr_str_pos - 1, 0 ), BORDER_COLOR, LINE_OXXX ); // ^|^
wattron( window, BORDER_COLOR );
mvwaddch( window, point( pwr_str_pos - 1, 1 ), LINE_XOXO ); // |
mvwaddch( window, point( pwr_str_pos - 1, 2 ), LINE_XXOO ); // |_
mvwhline( window, point( pwr_str_pos, 2 ), LINE_OXOX, getmaxx( window ) - pwr_str_pos ); // -
mvwhline( window, point_zero, LINE_OXOX, getmaxx( window ) ); // -
mvwaddch( window, point( pwr_str_pos - 1, 0 ), LINE_OXXX ); // ^|^
wattroff( window, BORDER_COLOR );
center_print( window, 0, c_light_red, _( "Bionics" ) );

std::string desc_append = string_format(
Expand Down Expand Up @@ -387,16 +385,12 @@ static void draw_bionics_tabs( const catacurses::window &win, const size_t activ
// Draw symbols to connect additional lines to border
int width = getmaxx( win );
int height = getmaxy( win );
for( int i = 0; i < height - 1; ++i ) {
// |
mvwputch( win, point( 0, i ), BORDER_COLOR, LINE_XOXO );
// |
mvwputch( win, point( width - 1, i ), BORDER_COLOR, LINE_XOXO );
}
// |-
mvwputch( win, point( 0, height - 1 ), BORDER_COLOR, LINE_XXXO );
// -|
mvwputch( win, point( width - 1, height - 1 ), BORDER_COLOR, LINE_XOXX );
wattron( win, BORDER_COLOR );
mvwvline( win, point_zero, LINE_XOXO, height - 1 ); // |
mvwvline( win, point( width - 1, 0 ), LINE_XOXO, height - 1 ); // |
mvwaddch( win, point( 0, height - 1 ), LINE_XXXO ); // |-
mvwaddch( win, point( width - 1, height - 1 ), LINE_XOXX ); // -|
wattroff( win, BORDER_COLOR );

wnoutrefresh( win );
}
Expand Down Expand Up @@ -444,9 +438,11 @@ static void draw_connectors( const catacurses::window &win, const point &start,
return;
}

wattron( win, BORDER_COLOR );

// draw horizontal line from selected bionic
const int turn_x = start.x + ( last_x - start.x ) * 2 / 3;
mvwputch( win, start, BORDER_COLOR, '>' );
mvwaddch( win, start, '>' );
// NOLINTNEXTLINE(cata-use-named-point-constants)
mvwhline( win, start + point( 1, 0 ), LINE_OXOX, turn_x - start.x - 1 );

Expand Down Expand Up @@ -482,16 +478,18 @@ static void draw_connectors( const catacurses::window &win, const point &start,
bp_chr = LINE_XXXO;
}

mvwputch( win, point( turn_x, y ), BORDER_COLOR, bp_chr );
mvwaddch( win, point( turn_x, y ), bp_chr );

// draw horizontal line to bodypart title
mvwhline( win, point( turn_x + 1, y ), LINE_OXOX, last_x - turn_x - 1 );
mvwputch( win, point( last_x, y ), BORDER_COLOR, '<' );
mvwaddch( win, point( last_x, y ), '<' );

// draw amount of consumed slots by this CBM
wattroff( win, BORDER_COLOR );
const std::string fmt_num = string_format( "(%d)", elem.second );
mvwprintz( win, point( turn_x + std::max( 1, ( last_x - turn_x - utf8_width( fmt_num ) ) / 2 ), y ),
c_yellow, fmt_num );
wattron( win, BORDER_COLOR );
}

// define and draw a proper intersection character
Expand Down Expand Up @@ -523,7 +521,8 @@ static void draw_connectors( const catacurses::window &win, const point &start,
// '^|^'
bionic_chr = LINE_OXXX;
}
mvwputch( win, point( turn_x, start.y ), BORDER_COLOR, bionic_chr );
mvwaddch( win, point( turn_x, start.y ), bionic_chr );
wattroff( win, BORDER_COLOR );
}

//get a text color depending on the power/powering state of the bionic
Expand Down Expand Up @@ -691,9 +690,11 @@ void avatar::power_bionics()
}
const int pos_x = WIDTH - 2 - max_width;
if( get_option < bool >( "CBM_SLOTS_ENABLED" ) ) {
wattron( wBio, c_light_gray );
for( size_t i = 0; i < bps.size(); ++i ) {
mvwprintz( wBio, point( pos_x, i + list_start_y ), c_light_gray, bps[i] );
mvwprintw( wBio, point( pos_x, i + list_start_y ), bps[i] );
}
wattroff( wBio, c_light_gray );
}

if( current_bionic_list->empty() ) {
Expand Down
4 changes: 1 addition & 3 deletions src/bodygraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,7 @@ void bodygraph_display::draw_info()
int y = 0;
for( unsigned i = top_info; i < info_txt.size() && y < all_height - 2; i++, y++ ) {
if( info_txt[i] == "--" ) {
for( int x = 1; x < info_width - 2; x++ ) {
mvwputch( w_info, point( x, y ), c_dark_gray, LINE_OXOX );
}
mvwhline( w_info, point( 1, y ), c_dark_gray, LINE_OXOX, info_width - 3 );
} else {
trim_and_print( w_info, point( 1, y ), info_width - 2, c_white, info_txt[i] );
}
Expand Down
Loading

0 comments on commit 1692e4a

Please sign in to comment.