1 #include <cppconsui/Button.h>
2 #include <cppconsui/ConsUICurses.h>
3 #include <cppconsui/ColorPicker.h>
4 #include <cppconsui/ColorPickerComboBox.h>
5 #include <cppconsui/ColorPickerDialog.h>
6 #include <cppconsui/Window.h>
12 class TestWindow
: public CppConsUI::Window
{
15 virtual ~TestWindow() override
{}
18 CppConsUI::Label
*label1
;
19 CppConsUI::Label
*label2
;
21 CppConsUI::ColorPickerComboBox
*combo
;
23 void onButtonActivate(CppConsUI::Button
&activator
, int flags
);
24 void onChangeColorResponseHandler(CppConsUI::ColorPickerDialog
&activator
,
25 CppConsUI::AbstractDialog::ResponseType response
, int color
);
26 void onColerPickerChanged(
27 CppConsUI::ColorPicker
&activator
, int new_fg
, int new_bg
);
28 void onComboColorChange(CppConsUI::ComboBox
&activator
, intptr_t color
);
30 CONSUI_DISABLE_COPY(TestWindow
);
33 TestWindow::TestWindow()
34 : CppConsUI::Window(0, 0, AUTOSIZE
, AUTOSIZE
), defaultcolor(0)
38 CppConsUI::Button
*button
;
40 addWidget(*(new CppConsUI::Label("Press F10 to quit.")), 1, 1);
42 button
= new CppConsUI::Button("Open Colorpicker...");
43 addWidget(*button
, 1, 3);
44 button
->signal_activate
.connect(
45 sigc::bind(sigc::mem_fun(this, &TestWindow::onButtonActivate
), 0));
47 button
= new CppConsUI::Button("Open Colorpicker: ansi only...");
48 addWidget(*button
, 1, 4);
49 button
->signal_activate
.connect(
50 sigc::bind(sigc::mem_fun(this, &TestWindow::onButtonActivate
),
51 CppConsUI::ColorPickerPalette::FLAG_HIDE_GRAYSCALE
|
52 CppConsUI::ColorPickerPalette::FLAG_HIDE_COLORCUBE
));
54 button
= new CppConsUI::Button("Open Colorpicker: ansi + Grayscale...");
55 addWidget(*button
, 1, 5);
56 button
->signal_activate
.connect(
57 sigc::bind(sigc::mem_fun(this, &TestWindow::onButtonActivate
),
58 CppConsUI::ColorPickerPalette::FLAG_HIDE_COLORCUBE
));
60 button
= new CppConsUI::Button("Open Colorpicker: color cube only...");
61 addWidget(*button
, 1, 6);
62 button
->signal_activate
.connect(
63 sigc::bind(sigc::mem_fun(this, &TestWindow::onButtonActivate
),
64 CppConsUI::ColorPickerPalette::FLAG_HIDE_ANSI
|
65 CppConsUI::ColorPickerPalette::FLAG_HIDE_GRAYSCALE
));
67 std::string text
= std::string("Supported nr of colors: ") +
68 dynamic_cast<std::ostringstream
*>(
69 &(std::ostringstream() << CppConsUI::Curses::getColorCount()))
71 label1
= new CppConsUI::Label(text
.c_str());
72 addWidget(*label1
, 1, 8);
73 label2
= new CppConsUI::Label("...");
74 addWidget(*label2
, 1, 10);
76 addWidget(*(new CppConsUI::Label("ColorPickerComboBox:")), 1, 12);
78 auto l
= new CppConsUI::Label
;
79 text
= std::string("Supported nr of color pairs: ") +
80 dynamic_cast<std::ostringstream
*>(
81 &(std::ostringstream() << CppConsUI::Curses::getColorPairCount()))
83 l
->setText(text
.c_str());
86 combo
= new CppConsUI::ColorPickerComboBox(10, defaultcolor
);
87 combo
->signal_color_changed
.connect(
88 sigc::mem_fun(this, &TestWindow::onComboColorChange
));
89 addWidget(*combo
, 1, 13);
91 CppConsUI::ColorPicker
*picker
;
93 addWidget(*(new CppConsUI::Label("ColorPicker:")), 1, 15);
94 picker
= new CppConsUI::ColorPicker(7, 1, "Label:", false);
95 picker
->signal_colorpair_selected
.connect(
96 sigc::mem_fun(this, &TestWindow::onColerPickerChanged
));
97 addWidget(*picker
, 1, 16);
99 addWidget(*(new CppConsUI::Label("ColorPicker:")), 1, 18);
100 picker
= new CppConsUI::ColorPicker(1, 7, "(with sample)", true);
101 picker
->signal_colorpair_selected
.connect(
102 sigc::mem_fun(this, &TestWindow::onColerPickerChanged
));
103 addWidget(*picker
, 1, 19);
106 void TestWindow::onButtonActivate(CppConsUI::Button
& /*activator*/, int flags
)
108 CppConsUI::ColorPickerDialog
*dialog
=
109 new CppConsUI::ColorPickerDialog("Test Colorpicker", 0, flags
);
110 dialog
->signal_response
.connect(
111 sigc::mem_fun(this, &TestWindow::onChangeColorResponseHandler
));
115 void TestWindow::onColerPickerChanged(
116 CppConsUI::ColorPicker
& /*activator*/, int new_fg
, int new_bg
)
118 std::string text
= std::string("Chosen color (") +
119 dynamic_cast<std::ostringstream
*>(&(std::ostringstream() << new_fg
))
122 dynamic_cast<std::ostringstream
*>(&(std::ostringstream() << new_bg
))
125 label2
->setText(text
.c_str());
127 combo
->setColor(new_fg
);
130 void TestWindow::onChangeColorResponseHandler(
131 CppConsUI::ColorPickerDialog
& /*activator*/,
132 CppConsUI::AbstractDialog::ResponseType response
, int color
)
134 if (response
!= CppConsUI::AbstractDialog::RESPONSE_OK
)
137 combo
->setColor(color
);
139 std::string text
= std::string("Chosen color nr: ") +
140 dynamic_cast<std::ostringstream
*>(&(std::ostringstream() << color
))->str();
141 label2
->setText(text
.c_str());
144 void TestWindow::onComboColorChange(
145 CppConsUI::ComboBox
& /*activator*/, intptr_t color
)
147 std::string text
= std::string("Chosen color nr: ") +
148 dynamic_cast<std::ostringstream
*>(
149 &(std::ostringstream() << static_cast<int>(color
)))
151 label2
->setText(text
.c_str());
156 // Create the main window.
157 auto win
= new TestWindow
;
161 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab