Update gtk116
This commit is contained in:
parent
b4fdde68b7
commit
3df5ab7c2b
|
@ -1,8 +1,11 @@
|
||||||
#include "MyWin.hh"
|
#include "MyWin.hh"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "image_types.hh"
|
||||||
#include "winpe.xpm"
|
#include "winpe.xpm"
|
||||||
|
|
||||||
MyWin::MyWin(){
|
MyWin::MyWin()
|
||||||
|
:btn_back("Background")
|
||||||
|
{
|
||||||
set_icon_name("org.gtk.daleclack");
|
set_icon_name("org.gtk.daleclack");
|
||||||
background.set_size_request(640,360);
|
background.set_size_request(640,360);
|
||||||
|
|
||||||
|
@ -10,10 +13,17 @@ MyWin::MyWin(){
|
||||||
pixbuf = Gdk::Pixbuf::create_from_xpm_data(winpe);
|
pixbuf = Gdk::Pixbuf::create_from_xpm_data(winpe);
|
||||||
sized = pixbuf->scale_simple(640,360,Gdk::INTERP_BILINEAR);
|
sized = pixbuf->scale_simple(640,360,Gdk::INTERP_BILINEAR);
|
||||||
|
|
||||||
|
//Add Button
|
||||||
|
btn_back.set_halign(Gtk::ALIGN_CENTER);
|
||||||
|
btn_back.set_valign(Gtk::ALIGN_CENTER);
|
||||||
|
m_overlay.add_overlay(btn_back);
|
||||||
|
btn_back.signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btnback_clicked));
|
||||||
|
|
||||||
//Set image
|
//Set image
|
||||||
gtk_image_set_from_pixbuf(background.gobj(),sized->gobj());
|
gtk_image_set_from_pixbuf(background.gobj(),sized->gobj());
|
||||||
get_pixel_color(320,180);
|
get_pixel_color(320,180);
|
||||||
add(background);
|
m_overlay.add(background);
|
||||||
|
add(m_overlay);
|
||||||
show_all_children();
|
show_all_children();
|
||||||
pixbuf.reset();
|
pixbuf.reset();
|
||||||
}
|
}
|
||||||
|
@ -50,3 +60,47 @@ void MyWin::get_pixel_color(int x,int y){
|
||||||
std::cout<<red<<" "<<green<<" "<<blue<<" "<<alpha<<std::endl;
|
std::cout<<red<<" "<<green<<" "<<blue<<" "<<alpha<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyWin::btnback_clicked(){
|
||||||
|
//Initalize Dialog
|
||||||
|
dialog = Gtk::FileChooserNative::create("Open a image file",*this,Gtk::FILE_CHOOSER_ACTION_OPEN,
|
||||||
|
"OK","Cancel");
|
||||||
|
|
||||||
|
//Add filter for Image files
|
||||||
|
auto filter_image = Gtk::FileFilter::create();
|
||||||
|
filter_image->set_name("Image Files");
|
||||||
|
if(mime_type_supported()){
|
||||||
|
//For systems that supports mime type, add a mime type
|
||||||
|
filter_image->add_mime_type("image/*");
|
||||||
|
}else{
|
||||||
|
//For Systems that not support mime type, use a supported globs
|
||||||
|
for(int i=0; supported_globs!=NULL && supported_globs[i]!=NULL; i++){
|
||||||
|
const char * glob = supported_globs[i];
|
||||||
|
filter_image->add_pattern(glob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dialog->add_filter(filter_image);
|
||||||
|
|
||||||
|
//Filter for any files
|
||||||
|
auto filter_any = Gtk::FileFilter::create();
|
||||||
|
filter_any->set_name("Any Files");
|
||||||
|
filter_any->add_pattern("*");
|
||||||
|
dialog->add_filter(filter_any);
|
||||||
|
|
||||||
|
//Link the "reponse" signal of dialog and show dialog
|
||||||
|
dialog->signal_response().connect(sigc::mem_fun(*this,&MyWin::set_background));
|
||||||
|
dialog->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyWin::set_background(int response_id){
|
||||||
|
if(response_id == Gtk::RESPONSE_ACCEPT){
|
||||||
|
Glib::ustring filename = dialog->get_filename();
|
||||||
|
pixbuf = Gdk::Pixbuf::create_from_file(filename);
|
||||||
|
//Release memory of pixbuf "sized"
|
||||||
|
sized.reset();
|
||||||
|
sized = pixbuf->scale_simple(640,360,Gdk::INTERP_BILINEAR);
|
||||||
|
gtk_image_set_from_pixbuf(background.gobj(),sized->gobj());
|
||||||
|
get_pixel_color(320,180);
|
||||||
|
}
|
||||||
|
dialog.reset();
|
||||||
|
}
|
||||||
|
|
|
@ -7,9 +7,16 @@ class MyWin : public Gtk::Window{
|
||||||
MyWin();
|
MyWin();
|
||||||
private:
|
private:
|
||||||
//Child Widgets
|
//Child Widgets
|
||||||
|
Gtk::Overlay m_overlay;
|
||||||
|
Gtk::Button btn_back;
|
||||||
Gtk::Image background;
|
Gtk::Image background;
|
||||||
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
|
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
|
||||||
Glib::RefPtr<Gdk::Pixbuf> sized;
|
Glib::RefPtr<Gdk::Pixbuf> sized;
|
||||||
|
//Get Mouse Position
|
||||||
|
Glib::RefPtr<Gtk::Gesture> gesture;
|
||||||
//Signal Handlers
|
//Signal Handlers
|
||||||
|
Glib::RefPtr<Gtk::FileChooserNative> dialog;
|
||||||
void get_pixel_color(int x,int y);
|
void get_pixel_color(int x,int y);
|
||||||
|
void btnback_clicked();
|
||||||
|
void set_background(int reponse_id);
|
||||||
};
|
};
|
Loading…
Reference in New Issue