Add background switch

This commit is contained in:
daleclack 2021-06-22 14:19:59 +08:00
parent a8b4e28c6f
commit 872d866516
3 changed files with 71 additions and 22 deletions

View File

@ -6,24 +6,35 @@
<attribute name='label'>Config</attribute> <attribute name='label'>Config</attribute>
<item> <item>
<attribute name='label'>Change Xe-lts config</attribute> <attribute name='label'>Change Xe-lts config</attribute>
<attribute name='action'>app.config1</attribute> <attribute name='action'>win.config1</attribute>
</item> </item>
<item> <item>
<attribute name='label'>Change Xe-stable config</attribute> <attribute name='label'>Change Xe-stable config</attribute>
<attribute name='action'>app.config2</attribute> <attribute name='action'>win.config2</attribute>
</item> </item>
<item> <item>
<attribute name='label'>Change Xe-devel config</attribute> <attribute name='label'>Change Xe-devel config</attribute>
<attribute name='action'>app.config3</attribute> <attribute name='action'>win.config3</attribute>
</item>
</submenu>
<submenu>
<attribute name='label'>Backgrounds</attribute>
<item>
<attribute name='label'>XeRelease8-9</attribute>
<attribute name='action'>win.back1</attribute>
</item>
<item>
<attribute name='label'>XeRelease10-12</attribute>
<attribute name='action'>win.back2</attribute>
</item> </item>
</submenu> </submenu>
<item> <item>
<attribute name='label'>About</attribute> <attribute name='label'>About</attribute>
<attribute name='action'>app.about</attribute> <attribute name='action'>win.about</attribute>
</item> </item>
<item> <item>
<attribute name='label'>Exit</attribute> <attribute name='label'>Exit</attribute>
<attribute name='action'>app.quit</attribute> <attribute name='action'>win.quit</attribute>
</item> </item>
</section> </section>
</menu> </menu>

View File

@ -1,5 +1,6 @@
#include "MyWin.hh" #include "MyWin.hh"
#include "img7.xpm" #include "img7.xpm"
#include "winpe.xpm"
MyWin::MyWin() MyWin::MyWin()
:btn_box(Gtk::ORIENTATION_VERTICAL,5), :btn_box(Gtk::ORIENTATION_VERTICAL,5),
@ -8,23 +9,7 @@ btn_ver("Xe-Ver")
//Initalize window //Initalize window
set_icon_name("Xe-Release"); set_icon_name("Xe-Release");
set_default_size(640,360); set_default_size(640,360);
titlebar_init();
//Add HeaderBar
header.set_title("Xe Release 12");
header.set_show_close_button();
header.set_decoration_layout("close,minimize:menu");
set_titlebar(header);
//Initalize Menu
menu_builder=Gtk::Builder::create_from_resource("/XeRelease/menubar.xml");
auto object=menu_builder->get_object("app-menu");
auto gmenu=Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
popover.bind_model(gmenu);
//Initalize MenuButton
menubtn.set_image_from_icon_name("open-menu");
menubtn.set_popover(popover);
header.pack_end(menubtn);
//Set Background Image //Set Background Image
auto pixbuf=Gdk::Pixbuf::create_from_xpm_data(img7); auto pixbuf=Gdk::Pixbuf::create_from_xpm_data(img7);
@ -53,3 +38,49 @@ btn_ver("Xe-Ver")
pixbuf.reset(); pixbuf.reset();
sized.reset(); sized.reset();
} }
void MyWin::titlebar_init(){
//Add HeaderBar
header.set_title("Xe Release 12");
header.set_show_close_button();
header.set_decoration_layout("close,minimize:menu");
set_titlebar(header);
//Initalize Menu
menu_builder=Gtk::Builder::create_from_resource("/XeRelease/menubar.xml");
auto object=menu_builder->get_object("app-menu");
auto gmenu=Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
popover.bind_model(gmenu);
//Add Menu Actions
add_action("back1",sigc::mem_fun(*this,&MyWin::background1));
add_action("back2",sigc::mem_fun(*this,&MyWin::background2));
add_action("quit",sigc::mem_fun(*this,&MyWin::hide));
//Initalize MenuButton
menubtn.set_image_from_icon_name("open-menu");
menubtn.set_popover(popover);
header.pack_end(menubtn);
}
void MyWin::background1(){
//Set Background Image
auto pixbuf=Gdk::Pixbuf::create_from_xpm_data(winpe);
auto sized=pixbuf->scale_simple(640,360,Gdk::INTERP_BILINEAR);
gtk_image_set_from_pixbuf(background.gobj(),sized->gobj());
//overlay.add(background);
//Free Memory
pixbuf.reset();
sized.reset();
}
void MyWin::background2(){
//Set Background Image
auto pixbuf=Gdk::Pixbuf::create_from_xpm_data(img7);
auto sized=pixbuf->scale_simple(640,360,Gdk::INTERP_BILINEAR);
gtk_image_set_from_pixbuf(background.gobj(),sized->gobj());
//overlay.add(background);
//Free Memory
pixbuf.reset();
sized.reset();
}

View File

@ -8,14 +8,21 @@ public:
private: private:
//Child Widgets //Child Widgets
Glib::RefPtr<Gtk::Builder> menu_builder; Glib::RefPtr<Gtk::Builder> menu_builder;
//Main window //Main window
Gtk::Image background; Gtk::Image background;
Gtk::Overlay overlay; Gtk::Overlay overlay;
Gtk::Box btn_box; Gtk::Box btn_box;
Gtk::ComboBoxText combo; Gtk::ComboBoxText combo;
Gtk::Button btn_ver; Gtk::Button btn_ver;
//TitleBar and menu //TitleBar and menu
Gtk::HeaderBar header; Gtk::HeaderBar header;
Gtk::MenuButton menubtn; Gtk::MenuButton menubtn;
Gtk::PopoverMenu popover; Gtk::PopoverMenu popover;
void titlebar_init();
//Backgrounds
void background1();
void background2();
}; };