2021-12-05 18:39:33 +08:00
|
|
|
#include "MyWin.hh"
|
|
|
|
|
2021-12-24 23:28:46 +08:00
|
|
|
MyWin::MyWin()
|
|
|
|
:main_box(Gtk::ORIENTATION_VERTICAL,5),
|
2021-12-26 00:05:54 +08:00
|
|
|
btnbox(Gtk::ORIENTATION_HORIZONTAL,5),
|
|
|
|
btnopen("Open Image")
|
2021-12-24 23:28:46 +08:00
|
|
|
{
|
|
|
|
//Add Widgets
|
|
|
|
set_default_size(800,450);
|
|
|
|
set_icon_name("org.gtk.daleclack");
|
2021-12-05 18:39:33 +08:00
|
|
|
|
2021-12-24 23:28:46 +08:00
|
|
|
//Scrolled Window
|
|
|
|
sw.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC);
|
|
|
|
sw.add(image_area);
|
|
|
|
main_box.pack_start(sw);
|
|
|
|
|
2021-12-26 00:05:54 +08:00
|
|
|
//Initalize Scale
|
|
|
|
m_adjustment = Gtk::Adjustment::create(1.0,0.1,10.0,0.1,0.1);
|
|
|
|
scale.set_default_direction(Gtk::TEXT_DIR_LTR);
|
|
|
|
scale.set_adjustment(m_adjustment);
|
|
|
|
|
|
|
|
//Add control widgets
|
|
|
|
btnbox.pack_start(scale);
|
|
|
|
btnbox.pack_start(btnopen,Gtk::PACK_SHRINK);
|
2021-12-24 23:28:46 +08:00
|
|
|
main_box.pack_start(btnbox,Gtk::PACK_SHRINK);
|
2021-12-26 00:05:54 +08:00
|
|
|
btnopen.signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btnopen_clicked));
|
2021-12-24 23:28:46 +08:00
|
|
|
|
|
|
|
add(main_box);
|
|
|
|
show_all_children();
|
2021-12-26 00:05:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyWin::btnopen_clicked(){
|
2021-12-26 13:31:00 +08:00
|
|
|
//Create a file open dialog
|
|
|
|
dialog = Gtk::FileChooserNative::create("Open a image File",*this,Gtk::FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
"OK","Cancel");
|
|
|
|
|
|
|
|
dialog->signal_response().connect(sigc::mem_fun(*this,&MyWin::dialog_response));
|
2021-12-26 00:05:54 +08:00
|
|
|
|
2021-12-26 13:31:00 +08:00
|
|
|
dialog->show();
|
2021-12-26 00:05:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyWin::dialog_response(int response_id){
|
2021-12-26 13:31:00 +08:00
|
|
|
if(response_id == Gtk::RESPONSE_ACCEPT){
|
|
|
|
//Show the image in a drawing area
|
|
|
|
auto filename = dialog->get_filename();
|
|
|
|
auto pixbuf = Gdk::Pixbuf::create_from_file(filename);
|
|
|
|
image_area.set_pixbuf(pixbuf);
|
|
|
|
pixbuf.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.reset();
|
2021-12-26 00:05:54 +08:00
|
|
|
}
|