Update gtk96

This commit is contained in:
daleclack 2021-07-21 18:35:56 +08:00
parent 5f4987c3a6
commit f29303f46f
1 changed files with 20 additions and 5 deletions

View File

@ -4,17 +4,24 @@ class MyWin : public Gtk::Window{
//Child Widgets
Gtk::Box main_box;
Gtk::DrawingArea draw_area;
Gtk::Button color_btn;
Gtk::ColorButton color_btn;
Gtk::Label color_label;
//Color Defination
Gdk::RGBA color;
//Signal Handlers
bool my_draw(const Cairo::RefPtr<Cairo::Context> &cr){
cr->set_source_rgba(0,0,1,1);
Gdk::Cairo::set_source_rgba(cr,color);
cr->paint();
return false;
return true;
}
void color_changed(){
//Get Color
color=color_btn.get_rgba();
}
public:
MyWin()
:main_box(Gtk::ORIENTATION_VERTICAL,5),
color_btn("Change Color")
color_label("Press Here to Change Color")
{
//Initalize Window
set_default_size(260,300);
@ -23,13 +30,21 @@ public:
//Add widgets
draw_area.set_size_request(200,200);
main_box.pack_start(draw_area,Gtk::PACK_SHRINK);
main_box.pack_start(color_label,Gtk::PACK_SHRINK);
main_box.pack_start(color_btn,Gtk::PACK_SHRINK);
main_box.set_halign(Gtk::ALIGN_CENTER);
main_box.set_valign(Gtk::ALIGN_CENTER);
//Draw Event
//Signals
color_btn.signal_color_set().connect(sigc::mem_fun(*this,&MyWin::color_changed));
draw_area.signal_draw().connect(sigc::mem_fun(*this,&MyWin::my_draw));
//Color Setting
color.set_alpha(1);
color.set_blue(1);
color.set_red(0);
color.set_green(0);
//Show Everything
add(main_box);
show_all_children();