Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor 3 catacurses functions a bit #37500

Merged
merged 2 commits into from
Jan 29, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 28 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,54 @@ 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_tr = tr ? tr : LINE_OOXX;
AMurkin marked this conversation as resolved.
Show resolved Hide resolved
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, tl ? tl : LINE_OXXO );
AMurkin marked this conversation as resolved.
Show resolved Hide resolved
AMurkin marked this conversation as resolved.
Show resolved Hide resolved
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