Skip to content

Commit

Permalink
Merge pull request CleverRaven#14969 from kevingranade/astyle-6
Browse files Browse the repository at this point in the history
Astyle campaign 6.
  • Loading branch information
Rivet-the-Zombie committed Jan 23, 2016
2 parents 39449a0 + 6680072 commit 57efa62
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 170 deletions.
4 changes: 4 additions & 0 deletions astyled_whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ src/drawing_primitives.cpp
src/gamemode.cpp
src/itype.cpp
src/iuse_software.cpp
src/live_view.cpp
src/lua_console.cpp
src/mapsharing.cpp
src/mattack_actors.cpp
Expand Down Expand Up @@ -48,6 +49,7 @@ src/bionics.h
src/bodypart.h
src/calendar.h
src/cata_utility.h
src/catacharset.h
src/catalua.h
src/char_validity_check.h
src/color.h
Expand Down Expand Up @@ -116,7 +118,9 @@ src/text_snippets.h
src/tile_id_data.h
src/tileray.h
src/translations.h
src/trap.h
src/tutorial.h
src/ui.h
src/veh_interact.h
src/version.h
src/weather.h
Expand Down
88 changes: 39 additions & 49 deletions src/catacharset.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#define UNKNOWN_UNICODE 0xFFFD

// get a unicode character from a utf8 string
uint32_t UTF8_getch(const char **src, int *srclen);
uint32_t UTF8_getch( const char **src, int *srclen );
// from wcwidth.c, return "cell" width of a unicode char
int mk_wcwidth(uint32_t ucs);
int mk_wcwidth( uint32_t ucs );
// convert cursorx value to byte position
int cursorx_to_position(const char *line, int cursorx, int *prevppos = NULL, int maxlen = -1);
int cursorx_to_position( const char *line, int cursorx, int *prevppos = NULL, int maxlen = -1 );
//erease for characters insertion
int erease_utf8_by_cw( char *t, int cw, int len, int maxlen);
int utf8_width(const char *s, const bool ignore_tags = false);
int utf8_width(const std::string &str, const bool ignore_tags = false);
int erease_utf8_by_cw( char *t, int cw, int len, int maxlen );
int utf8_width( const char *s, const bool ignore_tags = false );
int utf8_width( const std::string &str, const bool ignore_tags = false );

/**
* Center text inside whole line.
Expand All @@ -24,13 +24,13 @@ int utf8_width(const std::string &str, const bool ignore_tags = false);
* @param Last printable position on line.
* @return First char position of centered text or start_pos if text is too big.
*/
int center_text_pos(const char *text, int start_pos, int end_pos);
std::string utf8_substr(std::string s, int start, int size = -1);
std::string utf32_to_utf8(uint32_t ch);
std::string utf8_truncate(std::string s, size_t length);
int center_text_pos( const char *text, int start_pos, int end_pos );
std::string utf8_substr( std::string s, int start, int size = -1 );
std::string utf32_to_utf8( uint32_t ch );
std::string utf8_truncate( std::string s, size_t length );

std::string base64_encode(std::string str);
std::string base64_decode(std::string str);
std::string base64_encode( std::string str );
std::string base64_decode( std::string str );

/**
* UTF8-Wrapper over std::string.
Expand Down Expand Up @@ -59,22 +59,20 @@ std::string base64_decode(std::string str);
class utf8_wrapper
{
public:
utf8_wrapper() : _data(), _length(0), _display_width(0) { }
utf8_wrapper(const std::string &d);
utf8_wrapper(const char *d);
utf8_wrapper() : _data(), _length( 0 ), _display_width( 0 ) { }
utf8_wrapper( const std::string &d );
utf8_wrapper( const char *d );

void insert(size_t start, const utf8_wrapper &other);
utf8_wrapper substr(size_t start, size_t length) const;
utf8_wrapper substr(size_t start) const
{
return substr(start, _length - start);
void insert( size_t start, const utf8_wrapper &other );
utf8_wrapper substr( size_t start, size_t length ) const;
utf8_wrapper substr( size_t start ) const {
return substr( start, _length - start );
}
void erase(size_t start, size_t length);
void erase(size_t start)
{
erase(start, _length - start);
void erase( size_t start, size_t length );
void erase( size_t start ) {
erase( start, _length - start );
}
void append(const utf8_wrapper &other);
void append( const utf8_wrapper &other );
/**
* Returns a substring based on the display width, not the number of
* code points (as the other substr function does).
Expand All @@ -89,45 +87,37 @@ class utf8_wrapper
* have a shorter display length (especially if the last character is a multi-cell
* character and including it would exceed the length parameter).
*/
utf8_wrapper substr_display(size_t start, size_t length) const;
utf8_wrapper substr_display(size_t start) const
{
return substr_display(start, _length - start);
utf8_wrapper substr_display( size_t start, size_t length ) const;
utf8_wrapper substr_display( size_t start ) const {
return substr_display( start, _length - start );
}

utf8_wrapper &operator=(const std::string &d)
{
return *this = utf8_wrapper(d);
utf8_wrapper &operator=( const std::string &d ) {
return *this = utf8_wrapper( d );
}
const std::string &str() const
{
const std::string &str() const {
return _data;
}

// Returns unicode character at position start
long at(size_t start) const;
long at( size_t start ) const;

// Returns number of unicode characters
size_t size() const
{
size_t size() const {
return _length;
}
size_t length() const
{
size_t length() const {
return size();
}
bool empty() const
{
bool empty() const {
return size() == 0;
}
// Display size might be different from length, as some characters
// are displayed as 2 chars in a terminal
size_t display_width() const
{
size_t display_width() const {
return _display_width;
}
const char *c_str() const
{
const char *c_str() const {
return _data.c_str();
}
/**
Expand All @@ -136,22 +126,22 @@ class utf8_wrapper
* string with the ellipsis will be exactly maxlength displayed
* characters.
*/
std::string shorten(size_t maxlength) const;
std::string shorten( size_t maxlength ) const;
protected:
std::string _data;
size_t _length;
size_t _display_width;
// Byte offset into @ref _data for codepoint at index start.
// bstart is a initial offset (in bytes!). The function operates on
// _data.substr(bstart), it ignores everything before bstart.
size_t byte_start(size_t bstart, size_t start) const;
size_t byte_start( size_t bstart, size_t start ) const;
// Byte offset into @ref _date for the codepoint starting at displayed cell start,
// if the first character occupies two cells, than byte_start_display(2)
// would return the byte offset of the second codepoint
// byte_start_display(1) and byte_start_display(0) would return 0
size_t byte_start_display(size_t bstart, size_t start) const;
size_t byte_start_display( size_t bstart, size_t start ) const;
// Same as @ref substr, but with a byte index as start
utf8_wrapper substr_byte(size_t bytestart, size_t length, bool use_display_width) const;
utf8_wrapper substr_byte( size_t bytestart, size_t length, bool use_display_width ) const;
void init_utf8_wrapper();
};

Expand Down
81 changes: 41 additions & 40 deletions src/live_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,33 @@

const efftype_id effect_blind( "blind" );

namespace {
namespace
{
constexpr int START_LINE = 1;
constexpr int START_COLUMN = 1;

void print_items(WINDOW *const w, const map_stack &items, int &line)
void print_items( WINDOW *const w, const map_stack &items, int &line )
{
std::map<std::string, int> item_names;
for (auto &item : items) {
for( auto &item : items ) {
++item_names[item.tname()];
}

int const last_line = getmaxy(w) - START_LINE - 1;
int const max_w = getmaxx(w) - START_COLUMN - 1; // border
int const last_line = getmaxy( w ) - START_LINE - 1;
int const max_w = getmaxx( w ) - START_COLUMN - 1; // border

for (auto const &it : item_names) {
if (line == last_line) {
mvwprintz(w, line++, START_COLUMN, c_yellow, _("More items here..."));
for( auto const &it : item_names ) {
if( line == last_line ) {
mvwprintz( w, line++, START_COLUMN, c_yellow, _( "More items here..." ) );
break;
}

if (it.second > 1) {
if( it.second > 1 ) {
//~ item name [quantity]
trim_and_print(w, line++, START_COLUMN, max_w, c_white, _("%s [%d]"),
it.first.c_str(), it.second);
trim_and_print( w, line++, START_COLUMN, max_w, c_white, _( "%s [%d]" ),
it.first.c_str(), it.second );
} else {
trim_and_print(w, line++, START_COLUMN, max_w, c_white, "%s", it.first.c_str());
trim_and_print( w, line++, START_COLUMN, max_w, c_white, "%s", it.first.c_str() );
}
}
}
Expand All @@ -48,54 +49,54 @@ bool live_view::is_compact() const
return compact_view;
}

void live_view::set_compact(bool const value)
void live_view::set_compact( bool const value )
{
compact_view = value;
}

void live_view::init(int const start_x, int const start_y, int const w, int const h)
void live_view::init( int const start_x, int const start_y, int const w, int const h )
{
enabled = true;
width = w;
height = h;

w_live_view.reset(newwin(height, width, start_y, start_x));
w_live_view.reset( newwin( height, width, start_y, start_x ) );

hide();
}

void live_view::show(const int x, const int y)
void live_view::show( const int x, const int y )
{
if (!enabled || !w_live_view) {
if( !enabled || !w_live_view ) {
return;
}

bool did_hide = hide(false); // Clear window if it's visible
bool did_hide = hide( false ); // Clear window if it's visible

if (!g->u.sees(x, y)) {
if (did_hide) {
wrefresh(*this);
if( !g->u.sees( x, y ) ) {
if( did_hide ) {
wrefresh( *this );
}
return;
}

map &m = g->m;
mvwprintz(*this, 0, START_COLUMN, c_white, "< ");
wprintz(*this, c_green, _("Mouse View"));
wprintz(*this, c_white, " >");
mvwprintz( *this, 0, START_COLUMN, c_white, "< " );
wprintz( *this, c_green, _( "Mouse View" ) );
wprintz( *this, c_white, " >" );
int line = START_LINE;

// TODO: Z
tripoint p( x, y, g->get_levz() );

g->print_all_tile_info( p, *this, START_COLUMN, line, true);
g->print_all_tile_info( p, *this, START_COLUMN, line, true );

if (m.can_put_items( p ) && m.sees_some_items( p, g->u)) {
if(g->u.has_effect( effect_blind) || g->u.worn_with_flag("BLIND")) {
mvwprintz(*this, line++, START_COLUMN, c_yellow,
_("There's something here, but you can't see what it is."));
if( m.can_put_items( p ) && m.sees_some_items( p, g->u ) ) {
if( g->u.has_effect( effect_blind ) || g->u.worn_with_flag( "BLIND" ) ) {
mvwprintz( *this, line++, START_COLUMN, c_yellow,
_( "There's something here, but you can't see what it is." ) );
} else {
print_items(*this, m.i_at(p), line);
print_items( *this, m.i_at( p ), line );
}
}

Expand All @@ -108,47 +109,47 @@ void live_view::show(const int x, const int y)
// currently support the mouse. If and when it does, there'll need to
// be a different code path here that works for ncurses.
int full_height = w_live_view->height;
if (line < w_live_view->height - 1) {
w_live_view->height = (line > 11) ? line : 11;
if( line < w_live_view->height - 1 ) {
w_live_view->height = ( line > 11 ) ? line : 11;
}
last_height = w_live_view->height;
#endif

draw_border(*this);
draw_border( *this );

#if (defined TILES || defined _WIN32 || defined WINDOWS)
w_live_view->height = full_height;
#endif

inuse = true;
wrefresh(*this);
wrefresh( *this );
}

bool live_view::hide(bool refresh /*= true*/, bool force /*= false*/)
bool live_view::hide( bool refresh /*= true*/, bool force /*= false*/ )
{
if (!enabled || (!inuse && !force)) {
if( !enabled || ( !inuse && !force ) ) {
return false;
}

#if (defined TILES || defined _WIN32 || defined WINDOWS)
int full_height = w_live_view->height;
if (use_narrow_sidebar() && last_height > 0) {
if( use_narrow_sidebar() && last_height > 0 ) {
// When using the narrow sidebar mode, the lower part of the screen
// is used for the message queue. Best not to obscure too much of it.
w_live_view->height = last_height;
}
#endif

werase(*this);
werase( *this );

#if (defined TILES || defined _WIN32 || defined WINDOWS)
w_live_view->height = full_height;
#endif

inuse = false;
last_height = -1;
if (refresh) {
wrefresh(*this);
if( refresh ) {
wrefresh( *this );
}

return true;
Expand Down

0 comments on commit 57efa62

Please sign in to comment.