mudgangster

Log | Files | Refs

commit c473ef11ec4b758f7ddaf0b64c8ebfac2d258abd
parent 1ee814ca8a45bf263399b8f8fcc5b96db506ba67
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Mon,  3 Sep 2018 18:09:10 +0300

Less C++, scroll fixes

Diffstat:
src/textbox.cc | 20++++++++++----------
src/textbox.h | 8++++----
src/ui.cc | 8++++----
3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/textbox.cc b/src/textbox.cc @@ -136,23 +136,23 @@ void textbox_draw( const TextBox * tb ) { XFreePixmap( UI.display, doublebuf ); } -void TextBox::scroll( int offset ) { +void textbox_scroll( TextBox * tb, int offset ) { if( offset < 0 ) { - scroll_offset -= min( size_t( -offset ), scroll_offset ); + tb->scroll_offset -= min( size_t( -offset ), tb->scroll_offset ); } else { - scroll_offset = min( scroll_offset + offset, text.num_lines - 1 ); + tb->scroll_offset = min( tb->scroll_offset + offset, tb->text.num_lines - 1 ); } - textbox_draw( this ); + textbox_draw( tb ); } -void TextBox::page_down() { - size_t rows = height / ( Style.font.height + SPACING ); - scroll( -int( rows ) + 2 ); +void textbox_page_down( TextBox * tb ) { + size_t rows = tb->height / ( Style.font.height + SPACING ); + textbox_scroll( tb, -int( rows ) + 1 ); } -void TextBox::page_up() { - size_t rows = height / ( Style.font.height + SPACING ); - scroll( rows - 2 ); // TODO +void textbox_page_up( TextBox * tb ) { + size_t rows = tb->height / ( Style.font.height + SPACING ); + textbox_scroll( tb, rows - 1 ); // TODO } diff --git a/src/textbox.h b/src/textbox.h @@ -46,10 +46,6 @@ struct TextBox { int height; size_t scroll_offset; - - void scroll( int offset ); - void page_up(); - void page_down(); }; void textbox_init( TextBox * tb, size_t scrollback ); @@ -60,3 +56,7 @@ void textbox_setsize( TextBox * tb, int width, int height ); void textbox_add( TextBox * tb, const char * str, unsigned int len, Colour fg, Colour bg, bool bold ); void textbox_newline( TextBox * tb ); void textbox_draw( const TextBox * tb ); + +void textbox_scroll( TextBox * tb, int offset ); +void textbox_page_up( TextBox * tb ); +void textbox_page_down( TextBox * tb ); diff --git a/src/ui.cc b/src/ui.cc @@ -147,16 +147,16 @@ void eventKeyPress( XEvent* event ) { case XK_Page_Up: if( shift ) - UI.textMain.scroll( 1 ); + textbox_scroll( &UI.textMain, 1 ); else - UI.textMain.page_up(); + textbox_page_up( &UI.textMain ); break; case XK_Page_Down: if( shift ) - UI.textMain.scroll( -1 ); + textbox_scroll( &UI.textMain, -1 ); else - UI.textMain.page_down(); + textbox_page_down( &UI.textMain ); break; case XK_Up: