rtorrent/display: Initial ncurses canvas implementation.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@234 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-01-26 15:29:29 +00:00
parent 68788e904c
commit 1c10f620f8
5 changed files with 112 additions and 3 deletions
+4 -1
View File
@@ -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
])
+7 -2
View File
@@ -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 =
+23
View File
@@ -0,0 +1,23 @@
#include "config.h"
#include "canvas.h"
#include <stdarg.h>
namespace display {
void
Canvas::init() {
initscr();
cbreak();
noecho();
nodelay(stdscr, TRUE);
keypad(stdscr, TRUE);
curs_set(0);
}
void
Canvas::cleanup() {
endwin();
}
}
+55
View File
@@ -0,0 +1,55 @@
#ifndef RTORRENT_DISPLAY_CANVAS_H
#define RTORRENT_DISPLAY_CANVAS_H
#include <string>
#include <ncurses.h>
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 <typename A1>
void print(int x, int y, const char* str, A1 a1) { mvwprintw(m_window, y, x, str, a1); }
template <typename A1, typename A2>
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
+23
View File
@@ -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;
}