Skip to content

Commit

Permalink
Refactor 3 catacurses functions a bit (#37500)
Browse files Browse the repository at this point in the history
  • Loading branch information
AMurkin authored Jan 29, 2020
1 parent a3c1c37 commit fe85fe6
Showing 1 changed file with 29 additions and 78 deletions.
107 changes: 29 additions & 78 deletions src/cursesport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ inline void addedchar( cata_cursesport::WINDOW *win )

//Borders the window with fancy lines!
void catacurses::wborder( const window &win_, chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
chtype tr,
chtype bl, chtype br )
chtype tr, chtype bl, chtype br )
{
cata_cursesport::WINDOW *const win = win_.get<cata_cursesport::WINDOW>();
if( win == nullptr ) {
Expand All @@ -129,103 +128,55 @@ void catacurses::wborder( const window &win_, chtype ls, chtype rs, chtype ts, c
}
int i = 0;
int j = 0;
point old = win->cursor; //methods below move the cursor, save the value!
point old = win->cursor; // methods below move the cursor, save the value!

if( ls ) {
for( j = 1; j < win->height - 1; j++ ) {
mvwaddch( win_, point( 0, j ), ls );
}
} else {
for( j = 1; j < win->height - 1; j++ ) {
mvwaddch( win_, point( 0, j ), LINE_XOXO );
}
}

if( rs ) {
for( j = 1; j < win->height - 1; j++ ) {
mvwaddch( win_, point( win->width - 1, j ), rs );
}
} else {
for( j = 1; j < win->height - 1; j++ ) {
mvwaddch( win_, point( win->width - 1, j ), LINE_XOXO );
}
}

if( ts ) {
for( i = 1; i < win->width - 1; i++ ) {
mvwaddch( win_, point( i, 0 ), ts );
}
} else {
for( i = 1; i < win->width - 1; i++ ) {
mvwaddch( win_, point( i, 0 ), LINE_OXOX );
}
}
const chtype border_ls = ls ? ls : LINE_XOXO;
const chtype border_rs = rs ? rs : LINE_XOXO;
const chtype border_ts = ts ? ts : LINE_OXOX;
const chtype border_bs = bs ? bs : LINE_OXOX;
const chtype border_tl = tl ? tl : LINE_OXXO;
const chtype border_tr = tr ? tr : LINE_OOXX;
const chtype border_bl = bl ? bl : LINE_XXOO;
const chtype border_br = br ? br : LINE_XOOX;

if( bs ) {
for( i = 1; i < win->width - 1; i++ ) {
mvwaddch( win_, point( i, win->height - 1 ), bs );
}
} else {
for( i = 1; i < win->width - 1; i++ ) {
mvwaddch( win_, point( i, win->height - 1 ), LINE_OXOX );
}
for( j = 1; j < win->height - 1; j++ ) {
mvwaddch( win_, point( 0, j ), border_ls );
}

if( tl ) {
mvwaddch( win_, point_zero, tl );
} else {
mvwaddch( win_, point_zero, LINE_OXXO );
for( j = 1; j < win->height - 1; j++ ) {
mvwaddch( win_, point( win->width - 1, j ), border_rs );
}

if( tr ) {
mvwaddch( win_, point( win->width - 1, 0 ), tr );
} else {
mvwaddch( win_, point( win->width - 1, 0 ), LINE_OOXX );
for( i = 1; i < win->width - 1; i++ ) {
mvwaddch( win_, point( i, 0 ), border_ts );
}

if( bl ) {
mvwaddch( win_, point( 0, win->height - 1 ), bl );
} else {
mvwaddch( win_, point( 0, win->height - 1 ), LINE_XXOO );
for( i = 1; i < win->width - 1; i++ ) {
mvwaddch( win_, point( i, win->height - 1 ), border_bs );
}
mvwaddch( win_, point_zero, border_tl );
mvwaddch( win_, point( win->width - 1, 0 ), border_tr );
mvwaddch( win_, point( 0, win->height - 1 ), border_bl );
mvwaddch( win_, point( win->width - 1, win->height - 1 ), border_br );

if( br ) {
mvwaddch( win_, point( win->width - 1, win->height - 1 ), br );
} else {
mvwaddch( win_, point( win->width - 1, win->height - 1 ), LINE_XOOX );
}

//methods above move the cursor, put it back
// methods above move the cursor, put it back
wmove( win_, old );
wattroff( win_, c_white );
}

void catacurses::mvwhline( const window &win, const point &p, chtype ch, int n )
{
wattron( win, BORDER_COLOR );
if( ch ) {
for( int i = 0; i < n; i++ ) {
mvwaddch( win, p + point( i, 0 ), ch );
}
} else {
for( int i = 0; i < n; i++ ) {
mvwaddch( win, p + point( i, 0 ), LINE_OXOX );
}
const chtype hline_char = ch ? ch : LINE_OXOX;
for( int i = 0; i < n; i++ ) {
mvwaddch( win, p + point( i, 0 ), hline_char );
}
wattroff( win, BORDER_COLOR );
}

void catacurses::mvwvline( const window &win, const point &p, chtype ch, int n )
{
wattron( win, BORDER_COLOR );
if( ch ) {
for( int j = 0; j < n; j++ ) {
mvwaddch( win, p + point( 0, j ), ch );
}
} else {
for( int j = 0; j < n; j++ ) {
mvwaddch( win, p + point( 0, j ), LINE_XOXO );
}
const chtype vline_char = ch ? ch : LINE_XOXO;
for( int j = 0; j < n; j++ ) {
mvwaddch( win, p + point( 0, j ), vline_char );
}
wattroff( win, BORDER_COLOR );
}
Expand Down

0 comments on commit fe85fe6

Please sign in to comment.