Update gtk85
This commit is contained in:
parent
e00533f0e3
commit
42b49def5b
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.38.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.24"/>
|
||||
<object class="GtkStack" id="main_stack">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkOverlay" id="login_overlay">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">page0</property>
|
||||
<property name="title" translatable="yes">page0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkOverlay" id="main_overlay">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">page1</property>
|
||||
<property name="title" translatable="yes">page1</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkBox" id="user_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="user_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="user_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">dale</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="login_btn">
|
||||
<property name="label" translatable="yes">login</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="relief">none</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
|
@ -0,0 +1,21 @@
|
|||
#include "MyStack.hh"
|
||||
|
||||
MyStack::MyStack(){
|
||||
//Create a builder
|
||||
ref_builder=Gtk::Builder::create_from_file("../res/main_stack.ui");
|
||||
//Get widgets
|
||||
ref_builder->get_widget("main_stack",stack);
|
||||
ref_builder->get_widget("login_overlay",login_overlay);
|
||||
ref_builder->get_widget("user_box",user_box);
|
||||
ref_builder->get_widget("user_image",user_image);
|
||||
ref_builder->get_widget("login_btn",login_btn);
|
||||
ref_builder->get_widget("main_overlay",main_overlay);
|
||||
//Initalize Interface
|
||||
user_image->set_from_icon_name("org.gtk.daleclack",Gtk::ICON_SIZE_DIALOG);
|
||||
login_btn->signal_clicked().connect(sigc::mem_fun(*this,&MyStack::btnlogin_clicked));
|
||||
login_overlay->add_overlay(*user_box);
|
||||
}
|
||||
|
||||
void MyStack::btnlogin_clicked(){
|
||||
stack->set_visible_child(*main_overlay);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
class MyStack{
|
||||
public:
|
||||
MyStack();
|
||||
Gtk::Stack *stack;
|
||||
private:
|
||||
//Main builder
|
||||
Glib::RefPtr<Gtk::Builder> ref_builder;
|
||||
//Child widgets
|
||||
Gtk::Overlay *main_overlay,*login_overlay;
|
||||
Gtk::Box *user_box;
|
||||
Gtk::Image *user_image;
|
||||
Gtk::Button *login_btn;
|
||||
//Signal Handlers
|
||||
void btnlogin_clicked();
|
||||
};
|
|
@ -1,30 +1,122 @@
|
|||
#include "MyWin.hh"
|
||||
#include "winpe.xpm"
|
||||
|
||||
MyWin::MyWin(){
|
||||
//Initalize Window
|
||||
set_icon_name("org.gtk.daleclack");
|
||||
set_default_size(800,450);
|
||||
overlay.add_overlay(draw_area);
|
||||
default_background();
|
||||
overlay.add(background);
|
||||
|
||||
//Initalize menu
|
||||
menu_builder=Gtk::Builder::create_from_file("../res/appmenu.xml");
|
||||
auto object=menu_builder->get_object("app-menu");
|
||||
auto gmenu=Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
|
||||
|
||||
//Menu actions
|
||||
add_action("quit",sigc::mem_fun(*this,&MyWin::win_quit));
|
||||
add_action("default",sigc::mem_fun(*this,&MyWin::default_background));
|
||||
add_action("back",sigc::mem_fun(*this,&MyWin::back_dialog));
|
||||
add_action("about",sigc::mem_fun(*this,&MyWin::about_dialog));
|
||||
|
||||
//Set Popover Menu
|
||||
popover.bind_model(gmenu);
|
||||
popover.set_relative_to(draw_area);
|
||||
|
||||
//Set Gesture
|
||||
gesture=Gtk::GestureMultiPress::create(draw_area);
|
||||
gesture->set_button(3);
|
||||
gesture=Gtk::GestureMultiPress::create(overlay);
|
||||
gesture->set_button(GDK_BUTTON_SECONDARY);
|
||||
gesture->signal_pressed().connect(sigc::mem_fun(*this,&MyWin::btn_pressed));
|
||||
|
||||
//Add Stack
|
||||
overlay.add_overlay(*(main_stack.stack));
|
||||
add(overlay);
|
||||
show_all();
|
||||
}
|
||||
|
||||
void MyWin::btn_pressed(int n_press,double x,double y){
|
||||
//When mouse pressed,show a menu
|
||||
Gdk::Rectangle point{(int)x,(int)y,1,1};
|
||||
popover.set_pointing_to(point);
|
||||
popover.popup();
|
||||
}
|
||||
|
||||
void MyWin::default_background(){
|
||||
//Default background
|
||||
Glib::RefPtr<Gdk::Pixbuf> pixbuf=Gdk::Pixbuf::create_from_xpm_data(winpe);
|
||||
Glib::RefPtr<Gdk::Pixbuf> sized=pixbuf->scale_simple(800,450,Gdk::INTERP_BILINEAR);
|
||||
gtk_image_set_from_pixbuf(background.gobj(),sized->gobj());
|
||||
|
||||
//Free Memory of pixbufs
|
||||
pixbuf.reset();
|
||||
sized.reset();
|
||||
}
|
||||
|
||||
void MyWin::back_dialog(){
|
||||
//Initalize dialog
|
||||
auto dialog=new Gtk::FileChooserDialog("Open Image File",
|
||||
Gtk::FILE_CHOOSER_ACTION_OPEN);
|
||||
dialog->set_transient_for(*this);
|
||||
dialog->signal_response().connect(sigc::bind(
|
||||
sigc::mem_fun(*this,&MyWin::change_background),dialog));
|
||||
//Add button for dialog
|
||||
dialog->add_button("OK",Gtk::RESPONSE_OK);
|
||||
dialog->add_button("Cancel",Gtk::RESPONSE_CANCEL);
|
||||
//Add Filter
|
||||
auto filter=Gtk::FileFilter::create();
|
||||
filter->set_name("Image Files");
|
||||
filter->add_mime_type("image/*");
|
||||
dialog->add_filter(filter);
|
||||
|
||||
auto filter2=Gtk::FileFilter::create();
|
||||
filter2->set_name("All Files");
|
||||
filter2->add_pattern("*");
|
||||
dialog->add_filter(filter2);
|
||||
|
||||
dialog->show_all();
|
||||
filter.reset();
|
||||
filter2.reset();
|
||||
}
|
||||
|
||||
void MyWin::change_background(int response,Gtk::FileChooserDialog *dialog){
|
||||
Glib::ustring filename;
|
||||
if(response==Gtk::RESPONSE_OK){
|
||||
filename=dialog->get_filename();
|
||||
//Default background
|
||||
Glib::RefPtr<Gdk::Pixbuf> pixbuf=Gdk::Pixbuf::create_from_file(filename.c_str());
|
||||
Glib::RefPtr<Gdk::Pixbuf> sized=pixbuf->scale_simple(800,450,Gdk::INTERP_BILINEAR);
|
||||
gtk_image_set_from_pixbuf(background.gobj(),sized->gobj());
|
||||
|
||||
//Free Memory of pixbufs
|
||||
pixbuf.reset();
|
||||
sized.reset();
|
||||
}
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
void MyWin::about_dialog(){
|
||||
char *version;
|
||||
Gtk::AboutDialog about_dialog;
|
||||
about_dialog.set_transient_for(*this);
|
||||
//Create Comments
|
||||
version=g_strdup_printf("1.0\nRunning against Gtkmm %d.%d.%d",
|
||||
GTKMM_MAJOR_VERSION,
|
||||
GTKMM_MINOR_VERSION,
|
||||
GTKMM_MICRO_VERSION);
|
||||
about_dialog.set_program_name("Gtk(85)");
|
||||
about_dialog.set_version(version);
|
||||
about_dialog.set_logo_icon_name("org.gtk.daleclack");
|
||||
about_dialog.set_copyright("© 2019—2021 The Xe Project");
|
||||
about_dialog.set_comments("A test program for menu and background in gtkmm");
|
||||
about_dialog.set_title("About gtk(85)");
|
||||
about_dialog.run();
|
||||
g_free(version);
|
||||
}
|
||||
|
||||
void MyWin::win_quit(){
|
||||
hide();
|
||||
}
|
||||
|
||||
MyWin::~MyWin(){
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include "MyStack.hh"
|
||||
|
||||
class MyWin : public Gtk::Window{
|
||||
class MyWin : public Gtk::ApplicationWindow{
|
||||
public:
|
||||
MyWin();
|
||||
virtual ~MyWin();
|
||||
|
@ -12,7 +13,19 @@ private:
|
|||
Gtk::Overlay overlay;
|
||||
Gtk::DrawingArea draw_area;
|
||||
Gtk::PopoverMenu popover;
|
||||
Gtk::Image background;
|
||||
|
||||
//Main Pages
|
||||
MyStack main_stack;
|
||||
|
||||
//Gesture Widgets
|
||||
Glib::RefPtr<Gtk::GestureMultiPress> gesture;
|
||||
void btn_pressed(int n_press,double x,double y);
|
||||
|
||||
//Signal Handlers
|
||||
void default_background();
|
||||
void back_dialog();
|
||||
void change_background(int response,Gtk::FileChooserDialog *dialog);
|
||||
void about_dialog();
|
||||
void win_quit();
|
||||
};
|
Loading…
Reference in New Issue