1 #include <cppconsui/Button.h>
2 #include <cppconsui/ConsUICurses.h>
3 #include <cppconsui/CoreManager.h>
4 #include <cppconsui/ColorPicker.h>
5 #include <cppconsui/ColorPickerComboBox.h>
6 #include <cppconsui/ColorPickerDialog.h>
7 #include <cppconsui/KeyConfig.h>
8 #include <cppconsui/Window.h>
14 : public CppConsUI::Window
18 virtual ~TestWindow() {}
23 CppConsUI::Label
*label1
;
24 CppConsUI::Label
*label2
;
26 CppConsUI::ColorPickerComboBox
*combo
;
28 TestWindow(const TestWindow
&);
29 TestWindow
& operator=(const TestWindow
&);
31 void onButtonActivate(CppConsUI::Button
& activator
, int flags
);
32 void onChangeColorResponseHandler(CppConsUI::ColorPickerDialog
& activator
,
33 CppConsUI::AbstractDialog::ResponseType response
, int color
);
34 void onColerPickerChanged(CppConsUI::ColorPicker
& activator
, int new_fg
,
36 void onComboColorChange(CppConsUI::ComboBox
& activator
, intptr_t color
);
39 TestWindow::TestWindow()
40 : CppConsUI::Window(0, 0, AUTOSIZE
, AUTOSIZE
), defaultcolor(0)
42 CppConsUI::Button
*button
;
44 addWidget(*(new CppConsUI::Label("Press F10 to quit.")), 1, 1);
46 button
= new CppConsUI::Button("Open Colorpicker...");
47 addWidget(*button
, 1, 3);
48 button
->signal_activate
.connect(sigc::bind(sigc::mem_fun(this,
49 &TestWindow::onButtonActivate
), 0));
51 button
= new CppConsUI::Button("Open Colorpicker: ansi only...");
52 addWidget(*button
, 1, 4);
53 button
->signal_activate
.connect(sigc::bind(sigc::mem_fun(this,
54 &TestWindow::onButtonActivate
),
55 CppConsUI::ColorPickerPalette::FLAG_HIDE_GRAYSCALE
56 | CppConsUI::ColorPickerPalette::FLAG_HIDE_COLORCUBE
));
58 button
= new CppConsUI::Button("Open Colorpicker: ansi + Grayscale...");
59 addWidget(*button
, 1, 5);
60 button
->signal_activate
.connect(sigc::bind(sigc::mem_fun(this,
61 &TestWindow::onButtonActivate
),
62 CppConsUI::ColorPickerPalette::FLAG_HIDE_COLORCUBE
));
64 button
= new CppConsUI::Button("Open Colorpicker: color cube only...");
65 addWidget(*button
, 1, 6);
66 button
->signal_activate
.connect(sigc::bind(sigc::mem_fun(this,
67 &TestWindow::onButtonActivate
),
68 CppConsUI::ColorPickerPalette::FLAG_HIDE_ANSI
69 | CppConsUI::ColorPickerPalette::FLAG_HIDE_GRAYSCALE
));
71 char *text
= g_strdup_printf("Supported nr of colors: %d",
72 CppConsUI::Curses::nrcolors());
73 label1
= new CppConsUI::Label(text
);
75 addWidget(*label1
, 1, 8);
76 label2
= new CppConsUI::Label("...");
77 addWidget(*label2
, 1, 10);
79 CppConsUI::Label
*l
= new CppConsUI::Label("ColorPickerComboBox:");
82 l
= new CppConsUI::Label
;
83 text
= g_strdup_printf("Supported nr of color pairs: %d",
84 CppConsUI::Curses::nrcolorpairs());
89 combo
= new CppConsUI::ColorPickerComboBox (10, defaultcolor
);
90 combo
->signal_color_changed
.connect(sigc::mem_fun(this,
91 &TestWindow::onComboColorChange
));
92 addWidget(*combo
, 1, 13);
94 CppConsUI::ColorPicker
*picker
;
96 addWidget(*(new CppConsUI::Label("ColorPicker:")), 1, 15);
97 picker
= new CppConsUI::ColorPicker(7, 1, "Label:", false);
98 picker
->signal_colorpair_selected
.connect(sigc::mem_fun(this,
99 &TestWindow::onColerPickerChanged
));
100 addWidget(*picker
, 1, 16);
102 addWidget(*(new CppConsUI::Label("ColorPicker:")), 1, 18);
103 picker
= new CppConsUI::ColorPicker(15, 8, "(with sample)", true);
104 picker
->signal_colorpair_selected
.connect(sigc::mem_fun(this,
105 &TestWindow::onColerPickerChanged
));
106 addWidget(*picker
, 1, 19);
109 void TestWindow::onButtonActivate(CppConsUI::Button
& /*activator*/, int flags
)
111 CppConsUI::ColorPickerDialog
*dialog
= new CppConsUI::ColorPickerDialog(
112 "Test Colorpicker", 0, flags
);
113 dialog
->signal_response
.connect(sigc::mem_fun(this,
114 &TestWindow::onChangeColorResponseHandler
));
118 void TestWindow::onColerPickerChanged(CppConsUI::ColorPicker
& /*activator*/,
119 int new_fg
, int new_bg
)
121 char *text
= g_strdup_printf("Chosen color (%d,%d)", new_fg
, new_bg
);
122 label2
->setText(text
);
125 combo
->setColor(new_fg
);
128 void TestWindow::onChangeColorResponseHandler(
129 CppConsUI::ColorPickerDialog
& /*activator*/,
130 CppConsUI::AbstractDialog::ResponseType response
,
133 if (response
!= CppConsUI::AbstractDialog::RESPONSE_OK
)
136 combo
->setColor(color
);
138 char *text
= g_strdup_printf("Chosen color nr: %d", color
);
139 label2
->setText(text
);
143 void TestWindow::onComboColorChange(CppConsUI::ComboBox
& /*activator*/,
146 char *text
= g_strdup_printf("Chosen color nr: %d",
147 static_cast<int>(color
));
148 label2
->setText(text
);
154 : public CppConsUI::InputProcessor
158 virtual ~TestApp() {}
162 // ignore every message
163 static void g_log_func_(const gchar
* /*log_domain*/,
164 GLogLevelFlags
/*log_level*/, const gchar
* /*message*/,
165 gpointer
/*user_data*/)
171 TestApp(const TestApp
&);
172 TestApp
& operator=(const TestApp
&);
177 KEYCONFIG
->loadDefaultKeyConfig();
178 KEYCONFIG
->bindKey("testapp", "quit", "F10");
180 g_log_set_default_handler(g_log_func_
, this);
182 declareBindable("testapp", "quit", sigc::mem_fun(COREMANAGER
,
183 &CppConsUI::CoreManager::quitMainLoop
),
184 InputProcessor::BINDABLE_OVERRIDE
);
189 TestWindow
*win
= new TestWindow
;
192 COREMANAGER
->setTopInputProcessor(*this);
193 COREMANAGER
->enableResizing();
194 COREMANAGER
->startMainLoop();
200 setlocale(LC_ALL
, "");
202 // initialize CppConsUI
203 int consui_res
= CppConsUI::initializeConsUI();
205 fprintf(stderr
, "CppConsUI initialization failed.\n");
209 TestApp
*app
= new TestApp
;
213 // finalize CppConsUI
214 consui_res
= CppConsUI::finalizeConsUI();
216 fprintf(stderr
, "CppConsUI deinitialization failed.\n");
223 /* vim: set tabstop=2 shiftwidth=2 textwidth=78 expandtab : */