mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-06 22:29:23 +00:00
rtorrent: Initial key handler implemented.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@239 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+4
-3
@@ -33,11 +33,11 @@ AC_ARG_ENABLE(werror,
|
||||
]
|
||||
)
|
||||
|
||||
AC_SEARCH_LIBS(wbkgdset, ncurses curses,,echo "*** The ncurses library is required!";exit 1)
|
||||
|
||||
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)
|
||||
LIBS="$LIBS $STUFF_LIBS")
|
||||
|
||||
TORRENT_CHECK_CURL()
|
||||
TORRENT_OTFD()
|
||||
@@ -48,4 +48,5 @@ AC_OUTPUT([
|
||||
Makefile
|
||||
src/Makefile
|
||||
src/display/Makefile
|
||||
src/input/Makefile
|
||||
])
|
||||
|
||||
+4
-2
@@ -1,10 +1,12 @@
|
||||
SUBDIRS = \
|
||||
display
|
||||
display \
|
||||
input
|
||||
|
||||
bin_PROGRAMS = rtorrent
|
||||
|
||||
rtorrent_LDADD = \
|
||||
$(top_srcdir)/src/display/libsub_display.a
|
||||
$(top_srcdir)/src/display/libsub_display.a \
|
||||
$(top_srcdir)/src/input/libsub_input.a
|
||||
|
||||
rtorrent_SOURCES = \
|
||||
rtorrent.cc
|
||||
|
||||
@@ -41,6 +41,7 @@ Manager::adjust_row(iterator bItr, iterator eItr, int x, int y, int w, int h) {
|
||||
void
|
||||
Manager::do_update() {
|
||||
std::for_each(begin(), end(), std::mem_fun_ref(&ManagerElement::redraw));
|
||||
std::for_each(begin(), end(), std::mem_fun_ref(&ManagerElement::refresh));
|
||||
|
||||
Canvas::do_update();
|
||||
}
|
||||
|
||||
@@ -7,11 +7,10 @@ class Canvas;
|
||||
|
||||
class Window {
|
||||
public:
|
||||
Window() : m_canvas(NULL) {}
|
||||
Window(Canvas* c = NULL) : m_canvas(c) {}
|
||||
virtual ~Window() {}
|
||||
|
||||
Canvas* get_canvas() { return m_canvas; }
|
||||
void set_canvas(Canvas* c) { m_canvas = c; }
|
||||
|
||||
void refresh();
|
||||
void resize(int x, int y, int w, int h);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
noinst_LIBRARIES = libsub_input.a
|
||||
|
||||
libsub_input_a_SOURCES = \
|
||||
bindings.cc \
|
||||
bindings.h \
|
||||
manager.cc \
|
||||
manager.h
|
||||
|
||||
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "bindings.h"
|
||||
|
||||
namespace input {
|
||||
|
||||
bool
|
||||
Bindings::pressed(int key) {
|
||||
const_iterator itr = find(key);
|
||||
|
||||
if (itr != end())
|
||||
itr->second();
|
||||
|
||||
return itr != end();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef RTORRENT_INPUT_BINDINGS_H
|
||||
#define RTORRENT_INPUT_BINDINGS_H
|
||||
|
||||
#include <map>
|
||||
#include <sigc++/slot.h>
|
||||
|
||||
namespace input {
|
||||
|
||||
class Bindings : private std::map<int, sigc::slot0<void> > {
|
||||
public:
|
||||
typedef std::map<int, sigc::slot0<void> > Base;
|
||||
|
||||
using Base::iterator;
|
||||
using Base::const_iterator;
|
||||
using Base::reverse_iterator;
|
||||
using Base::const_reverse_iterator;
|
||||
|
||||
using Base::begin;
|
||||
using Base::end;
|
||||
using Base::rbegin;
|
||||
using Base::rend;
|
||||
using Base::find;
|
||||
|
||||
using Base::operator[];
|
||||
|
||||
bool pressed(int key);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include "manager.h"
|
||||
#include "bindings.h"
|
||||
|
||||
namespace input {
|
||||
|
||||
bool
|
||||
Manager::pressed(int key) {
|
||||
return std::find_if(begin(), end(), std::bind2nd(std::mem_fun(&Bindings::pressed), key)) != end();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef RTORRENT_INPUT_MANAGER_H
|
||||
#define RTORRENT_INPUT_MANAGER_H
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace input {
|
||||
|
||||
class Bindings;
|
||||
|
||||
class Manager : private std::list<Bindings*> {
|
||||
public:
|
||||
typedef std::list<Bindings*> Base;
|
||||
|
||||
using Base::iterator;
|
||||
using Base::const_iterator;
|
||||
using Base::reverse_iterator;
|
||||
using Base::const_reverse_iterator;
|
||||
|
||||
using Base::begin;
|
||||
using Base::end;
|
||||
using Base::rbegin;
|
||||
using Base::rend;
|
||||
|
||||
using Base::push_back;
|
||||
using Base::push_front;
|
||||
|
||||
bool pressed(int key);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+34
-13
@@ -3,48 +3,69 @@
|
||||
#include "display/window.h"
|
||||
#include "display/canvas.h"
|
||||
#include "display/manager.h"
|
||||
#include "input/bindings.h"
|
||||
#include "input/manager.h"
|
||||
|
||||
class WindowTest : public display::Window {
|
||||
public:
|
||||
WindowTest(const std::string& str) : m_str(str) {}
|
||||
WindowTest(const std::string& str, bool reverse = false) : Window(new display::Canvas), m_str(str), m_reverse(reverse) {}
|
||||
|
||||
virtual void redraw() {
|
||||
if (m_canvas == NULL)
|
||||
return;
|
||||
|
||||
if (m_reverse)
|
||||
m_canvas->set_background(A_REVERSE);
|
||||
else
|
||||
m_canvas->set_background(0);
|
||||
|
||||
m_canvas->erase();
|
||||
m_canvas->print_border('|', '|', '-', '-', '+', '+', '+', '+');
|
||||
m_canvas->print(1, 1, "%s", m_str.c_str());
|
||||
}
|
||||
|
||||
void reverse() {
|
||||
m_reverse = !m_reverse;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_str;
|
||||
|
||||
bool m_reverse;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
display::Canvas::init();
|
||||
display::Manager manager;
|
||||
display::Manager display;
|
||||
input::Manager inputManager;
|
||||
|
||||
WindowTest window1("This is window 1");
|
||||
WindowTest window2("This is window 2");
|
||||
|
||||
window1.set_canvas(new display::Canvas());
|
||||
window2.set_canvas(new display::Canvas());
|
||||
input::Bindings bindings1;
|
||||
input::Bindings bindings2;
|
||||
|
||||
manager.add(&window1);
|
||||
manager.add(&window2);
|
||||
inputManager.push_back(&bindings1);
|
||||
inputManager.push_back(&bindings2);
|
||||
|
||||
window1.get_canvas()->set_background(A_REVERSE);
|
||||
bindings1[KEY_LEFT] = sigc::mem_fun(window1, &WindowTest::reverse);
|
||||
bindings2[KEY_LEFT] = sigc::mem_fun(window2, &WindowTest::reverse);
|
||||
bindings2[KEY_RIGHT] = sigc::mem_fun(window2, &WindowTest::reverse);
|
||||
|
||||
manager.adjust_layout();
|
||||
manager.do_update();
|
||||
display.add(&window1);
|
||||
display.add(&window2);
|
||||
|
||||
while (true);
|
||||
display.adjust_layout();
|
||||
|
||||
while (true) {
|
||||
display.do_update();
|
||||
|
||||
inputManager.pressed(getch());
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
display::Canvas::cleanup();
|
||||
|
||||
delete window1.get_canvas();
|
||||
delete window2.get_canvas();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user