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)
44 CppConsUI::Button
*button
;
46 addWidget(*(new CppConsUI::Label("Press F10 to quit.")), 1, 1);
48 button
= new CppConsUI::Button("Open Colorpicker...");
49 addWidget(*button
, 1, 3);
50 button
->signal_activate
.connect(sigc::bind(sigc::mem_fun(this,
51 &TestWindow::onButtonActivate
), 0));
53 button
= new CppConsUI::Button("Open Colorpicker: ansi only...");
54 addWidget(*button
, 1, 4);
55 button
->signal_activate
.connect(sigc::bind(sigc::mem_fun(this,
56 &TestWindow::onButtonActivate
),
57 CppConsUI::ColorPickerPalette::FLAG_HIDE_GRAYSCALE
58 | CppConsUI::ColorPickerPalette::FLAG_HIDE_COLORCUBE
));
60 button
= new CppConsUI::Button("Open Colorpicker: ansi + Grayscale...");
61 addWidget(*button
, 1, 5);
62 button
->signal_activate
.connect(sigc::bind(sigc::mem_fun(this,
63 &TestWindow::onButtonActivate
),
64 CppConsUI::ColorPickerPalette::FLAG_HIDE_COLORCUBE
));
66 button
= new CppConsUI::Button("Open Colorpicker: color cube only...");
67 addWidget(*button
, 1, 6);
68 button
->signal_activate
.connect(sigc::bind(sigc::mem_fun(this,
69 &TestWindow::onButtonActivate
),
70 CppConsUI::ColorPickerPalette::FLAG_HIDE_ANSI
71 | CppConsUI::ColorPickerPalette::FLAG_HIDE_GRAYSCALE
));
73 char *text
= g_strdup_printf("Supported nr of colors: %d",
74 CppConsUI::Curses::nrcolors());
75 label1
= new CppConsUI::Label(text
);
77 addWidget(*label1
, 1, 8);
78 label2
= new CppConsUI::Label("...");
79 addWidget(*label2
, 1, 10);
81 CppConsUI::Label
*l
= new CppConsUI::Label("ColorPickerComboBox:");
84 l
= new CppConsUI::Label
;
85 text
= g_strdup_printf("Supported nr of color pairs: %d",
86 CppConsUI::Curses::nrcolorpairs());
91 combo
= new CppConsUI::ColorPickerComboBox (10, defaultcolor
);
92 combo
->signal_color_changed
.connect(sigc::mem_fun(this,
93 &TestWindow::onComboColorChange
));
94 addWidget(*combo
, 1, 13);
96 CppConsUI::ColorPicker
*picker
;
98 addWidget(*(new CppConsUI::Label("ColorPicker:")), 1, 15);
99 picker
= new CppConsUI::ColorPicker(7, 1, "Label:", false);
100 picker
->signal_colorpair_selected
.connect(sigc::mem_fun(this,
101 &TestWindow::onColerPickerChanged
));
102 addWidget(*picker
, 1, 16);
104 addWidget(*(new CppConsUI::Label("ColorPicker:")), 1, 18);
105 picker
= new CppConsUI::ColorPicker(15, 8, "(with sample)", true);
106 picker
->signal_colorpair_selected
.connect(sigc::mem_fun(this,
107 &TestWindow::onColerPickerChanged
));
108 addWidget(*picker
, 1, 19);
111 void TestWindow::onButtonActivate(CppConsUI::Button
& /*activator*/, int flags
)
113 CppConsUI::ColorPickerDialog
*dialog
= new CppConsUI::ColorPickerDialog(
114 "Test Colorpicker", 0, flags
);
115 dialog
->signal_response
.connect(sigc::mem_fun(this,
116 &TestWindow::onChangeColorResponseHandler
));
120 void TestWindow::onColerPickerChanged(CppConsUI::ColorPicker
& /*activator*/,
121 int new_fg
, int new_bg
)
123 char *text
= g_strdup_printf("Chosen color (%d,%d)", new_fg
, new_bg
);
124 label2
->setText(text
);
127 combo
->setColor(new_fg
);
130 void TestWindow::onChangeColorResponseHandler(
131 CppConsUI::ColorPickerDialog
& /*activator*/,
132 CppConsUI::AbstractDialog::ResponseType response
,
135 if (response
!= CppConsUI::AbstractDialog::RESPONSE_OK
)
138 combo
->setColor(color
);
140 char *text
= g_strdup_printf("Chosen color nr: %d", color
);
141 label2
->setText(text
);
145 void TestWindow::onComboColorChange(CppConsUI::ComboBox
& /*activator*/,
148 char *text
= g_strdup_printf("Chosen color nr: %d",
149 static_cast<int>(color
));
150 label2
->setText(text
);
156 : public CppConsUI::InputProcessor
160 virtual ~TestApp() {}
164 // ignore every message
165 static void g_log_func_(const gchar
* /*log_domain*/,
166 GLogLevelFlags
/*log_level*/, const gchar
* /*message*/,
167 gpointer
/*user_data*/)
173 TestApp(const TestApp
&);
174 TestApp
& operator=(const TestApp
&);
179 KEYCONFIG
->loadDefaultKeyConfig();
180 KEYCONFIG
->bindKey("testapp", "quit", "F10");
182 g_log_set_default_handler(g_log_func_
, this);
184 declareBindable("testapp", "quit", sigc::mem_fun(COREMANAGER
,
185 &CppConsUI::CoreManager::quitMainLoop
),
186 InputProcessor::BINDABLE_OVERRIDE
);
191 TestWindow
*win
= new TestWindow
;
194 COREMANAGER
->setTopInputProcessor(*this);
195 COREMANAGER
->enableResizing();
196 COREMANAGER
->startMainLoop();
202 setlocale(LC_ALL
, "");
204 // initialize CppConsUI
205 int consui_res
= CppConsUI::initializeConsUI();
207 fprintf(stderr
, "CppConsUI initialization failed.\n");
211 TestApp
*app
= new TestApp
;
215 // finalize CppConsUI
216 consui_res
= CppConsUI::finalizeConsUI();
218 fprintf(stderr
, "CppConsUI deinitialization failed.\n");
225 /* vim: set tabstop=2 shiftwidth=2 textwidth=78 expandtab : */