diff --git a/configure.ac b/configure.ac index 1475f056..08348e9b 100644 --- a/configure.ac +++ b/configure.ac @@ -8,7 +8,7 @@ sinclude(scripts/checks.m4) CXXFLAGS="-O3" AC_PROG_CXX - +AC_PROG_RANLIB AC_SYS_LARGEFILE AC_ARG_ENABLE(debug, @@ -37,6 +37,8 @@ PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.4.8, CXXFLAGS="$CXXFLAGS $STUFF_CFLAGS"; LIBS="$LIBS $STUFF_liBS") +AC_SEARCH_LIBS(wbkgdset, ncurses curses,,echo "*** The ncurses library is required!";exit 1) + TORRENT_CHECK_CURL() TORRENT_OTFD() @@ -45,4 +47,5 @@ AC_DEFINE(HAVE_CONFIG_H, 1, true if config.h was included) AC_OUTPUT([ Makefile src/Makefile + src/display/Makefile ]) diff --git a/src/Makefile.am b/src/Makefile.am index e81ed370..d714e295 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,11 @@ +SUBDIRS = \ + display + bin_PROGRAMS = rtorrent +rtorrent_LDFLAGS = -version-info $(RTORRENT_INTERFACE_VERSION_INFO) +rtorrent_LDADD = \ + $(top_srcdir)/src/display/libsub_display.a + rtorrent_SOURCES = \ rtorrent.cc - -rtorrent_LDADD = \ No newline at end of file diff --git a/src/display/canvas.cc b/src/display/canvas.cc new file mode 100644 index 00000000..333ea4be --- /dev/null +++ b/src/display/canvas.cc @@ -0,0 +1,23 @@ +#include "config.h" + +#include "canvas.h" +#include + +namespace display { + +void +Canvas::init() { + initscr(); + cbreak(); + noecho(); + nodelay(stdscr, TRUE); + keypad(stdscr, TRUE); + curs_set(0); +} + +void +Canvas::cleanup() { + endwin(); +} + +} diff --git a/src/display/canvas.h b/src/display/canvas.h new file mode 100644 index 00000000..d965f7fa --- /dev/null +++ b/src/display/canvas.h @@ -0,0 +1,55 @@ +#ifndef RTORRENT_DISPLAY_CANVAS_H +#define RTORRENT_DISPLAY_CANVAS_H + +#include +#include + +namespace display { + +class Canvas { +public: + Canvas(int x, int y, int width = 0, int height = 0) : + m_window(newwin(height, width, y, x)) {} + ~Canvas() { delwin(m_window); } + + void refresh() { wnoutrefresh(m_window); } + void redraw() { redrawwin(m_window); } + + void update_size(int w, int h) { wresize(m_window, h, w); } + + int get_x() { int x, y; getyx(m_window, y, x); return x; } + int get_y() { int x, y; getyx(m_window, y, x); return y; } + int get_width() { int x, y; getmaxyx(m_window, y, x); return x; } + int get_height() { int x, y; getmaxyx(m_window, y, x); return y; } + + chtype get_background() { return getbkgd(m_window); } + void set_background(chtype c) { return wbkgdset(m_window, c); } + + void erase() { werase(m_window); } + + void print(int x, int y, const char* str) { mvwprintw(m_window, y, x, str); } + + template + void print(int x, int y, const char* str, A1 a1) { mvwprintw(m_window, y, x, str, a1); } + + template + void print(int x, int y, const char* str, A1 a1, A2 a2) { mvwprintw(m_window, y, x, str, a1, a2); } + + void print_border(chtype ls, chtype rs, + chtype ts, chtype bs, + chtype tl, chtype tr, + chtype bl, chtype br) { wborder(m_window, ls, rs, ts, bs, tl, tr, bl, br); } + + // Initialize stdscr. + static void init(); + static void cleanup(); + + static void do_update() { doupdate(); } + +private: + WINDOW* m_window; +}; + +} + +#endif diff --git a/src/rtorrent.cc b/src/rtorrent.cc index d4951f5e..b5965c79 100644 --- a/src/rtorrent.cc +++ b/src/rtorrent.cc @@ -1,4 +1,27 @@ +#include "display/canvas.h" int main(int argc, char** argv) { + display::Canvas::init(); + + display::Canvas canvas1(0, 0, 20, 0); + display::Canvas canvas2(15, 5, 20, 10); + + canvas1.erase(); + canvas2.erase(); + canvas1.set_background(A_REVERSE); + + canvas1.print_border('|', '|', '-', '-', '+', '+', '+', '+'); + canvas2.print_border('|', '|', '-', '-', '+', '+', '+', '+'); + + canvas1.print(2, 5, "test %i %s", 42, "bar"); + + canvas1.refresh(); + canvas2.refresh(); + display::Canvas::do_update(); + + while (true); + + display::Canvas::cleanup(); + return 0; }