1 #include <cppconsui/Button.h>
2 #include <cppconsui/CoreManager.h>
3 #include <cppconsui/KeyConfig.h>
4 #include <cppconsui/Label.h>
5 #include <cppconsui/ScrollPane.h>
6 #include <cppconsui/Window.h>
10 static const char *pic
[] =
12 " ______ __ __ __ __ ",
13 "| |.-----.-----.-----.----.---.-.| |_.--.--.| |.---.-.| |_|__|.-----.-----.-----. ",
14 "| ---|| _ | | _ | _| _ || _| | || || _ || _| || _ | |__ --|__ ",
15 "|______||_____|__|__|___ |__| |___._||____|_____||__||___._||____|__||_____|__|__|_____| |",
17 " __ __ __ __ _______ __ ",
18 ".--.--.-----.--.--. |__|.--.--.-----.| |_ | |.-----.-----.| |_ |_ _| |--.-----. ",
19 "| | | _ | | | | || | |__ --|| _| | || _ |__ --|| _| | | | | -__| ",
20 "|___ |_____|_____| | ||_____|_____||____| |__||_____|_____||____| |___| |__|__|_____| ",
23 "| __|.---.-.--------.-----. ",
24 "| | || _ | | -__|__ ",
25 "|_______||___._|__|__|__|_____|__| "
31 : public CppConsUI::ScrollPane
34 MyScrollPane(int w
, int h
, int scrollw
, int scrollh
);
35 virtual ~MyScrollPane() {}
43 MyScrollPane(const MyScrollPane
&);
44 MyScrollPane
& operator=(const MyScrollPane
&);
47 MyScrollPane::MyScrollPane(int w
, int h
, int scrollw
, int scrollh
)
48 : CppConsUI::ScrollPane(w
, h
, scrollw
, scrollh
)
52 void MyScrollPane::draw()
55 proceedUpdateVirtualArea();
58 // scrollpane will clear the scroll (real) area
63 area
->fill(getColorPair("container", "background"));
65 int real_height
= area
->getmaxy();
66 for (int i
= 0; i
< real_height
&& i
< (int) (sizeof(pic
) / sizeof(pic
[0]));
68 area
->mvaddstring(0, i
, pic
[i
]);
70 ScrollPane::drawEx(false);
75 : public CppConsUI::Window
79 virtual ~TestWindow() {}
85 TestWindow(const TestWindow
&);
86 TestWindow
& operator=(const TestWindow
&);
88 void actionScrollUp();
89 void actionScrollDown();
90 void actionScrollLeft();
91 void actionScrollRight();
94 TestWindow::TestWindow()
95 : CppConsUI::Window(0, 0, AUTOSIZE
, AUTOSIZE
)
99 addWidget(*(new CppConsUI::Label(25, 1, "Press F10 to quit.")), 1, 1);
100 addWidget(*(new CppConsUI::Label(25, 1, "WASD to move the picture.")),
103 pane
= new MyScrollPane(20, 10, 111, 23);
104 addWidget(*pane
, 1, 4);
106 declareBindable("scrollpanewindow", "scroll-up",
107 sigc::mem_fun(this, &TestWindow::actionScrollUp
),
108 InputProcessor::BINDABLE_NORMAL
);
109 declareBindable("scrollpanewindow", "scroll-down",
110 sigc::mem_fun(this, &TestWindow::actionScrollDown
),
111 InputProcessor::BINDABLE_NORMAL
);
112 declareBindable("scrollpanewindow", "scroll-left",
113 sigc::mem_fun(this, &TestWindow::actionScrollLeft
),
114 InputProcessor::BINDABLE_NORMAL
);
115 declareBindable("scrollpanewindow", "scroll-right",
116 sigc::mem_fun(this, &TestWindow::actionScrollRight
),
117 InputProcessor::BINDABLE_NORMAL
);
120 void TestWindow::actionScrollUp()
122 pane
->adjustScroll(pane
->getScrollPositionX(),
123 pane
->getScrollPositionY() - 1);
126 void TestWindow::actionScrollDown()
128 pane
->adjustScroll(pane
->getScrollPositionX(),
129 pane
->getScrollPositionY() + 1);
132 void TestWindow::actionScrollLeft()
134 pane
->adjustScroll(pane
->getScrollPositionX() - 1,
135 pane
->getScrollPositionY());
138 void TestWindow::actionScrollRight()
140 pane
->adjustScroll(pane
->getScrollPositionX() + 1,
141 pane
->getScrollPositionY());
146 : public CppConsUI::InputProcessor
150 virtual ~TestApp() {}
154 // ignore every message
155 static void g_log_func_(const gchar
* /*log_domain*/,
156 GLogLevelFlags
/*log_level*/, const gchar
* /*message*/,
157 gpointer
/*user_data*/)
163 TestApp(const TestApp
&);
164 TestApp
& operator=(const TestApp
&);
169 KEYCONFIG
->loadDefaultKeyConfig();
170 KEYCONFIG
->bindKey("testapp", "quit", "F10");
171 KEYCONFIG
->bindKey("scrollpanewindow", "scroll-up", "w");
172 KEYCONFIG
->bindKey("scrollpanewindow", "scroll-down", "s");
173 KEYCONFIG
->bindKey("scrollpanewindow", "scroll-left", "a");
174 KEYCONFIG
->bindKey("scrollpanewindow", "scroll-right", "d");
176 g_log_set_default_handler(g_log_func_
, this);
178 declareBindable("testapp", "quit", sigc::mem_fun(COREMANAGER
,
179 &CppConsUI::CoreManager::quitMainLoop
),
180 InputProcessor::BINDABLE_OVERRIDE
);
185 TestWindow
*win
= new TestWindow
;
188 COREMANAGER
->setTopInputProcessor(*this);
189 COREMANAGER
->enableResizing();
190 COREMANAGER
->startMainLoop();
196 setlocale(LC_ALL
, "");
198 // initialize CppConsUI
199 int consui_res
= CppConsUI::initializeConsUI();
201 fprintf(stderr
, "CppConsUI initialization failed.\n");
205 TestApp
*app
= new TestApp
;
209 // finalize CppConsUI
210 consui_res
= CppConsUI::finalizeConsUI();
212 fprintf(stderr
, "CppConsUI deinitialization failed.\n");
219 /* vim: set tabstop=2 shiftwidth=2 textwidth=78 expandtab : */