* use the GtkBuilder for the ui
[hkl3d.git] / gui / ghkl3d / hkl3d-gui-application.cpp
blob6121495df603934771dd3c6b1a35807b2340c5e1
1 /*
2 * This file is part of the hkl3d library.
3 * inspired from logo-model.c of the GtkGLExt logo models.
4 * written by Naofumi Yasufuku <naofumi@users.sourceforge.net>
6 * The hkl library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * The hkl library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
19 * Copyright (C) 2010 Synchrotron SOLEIL
20 * L'Orme des Merisiers Saint-Aubin
21 * BP 48 91192 GIF-sur-YVETTE CEDEX
23 * Authors: Oussama Sboui <oussama.sboui@synchrotron-soleil.fr>
24 * Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
27 #include "hkl3d-gui-application.h"
29 namespace Logo
31 const Glib::ustring Application::APP_NAME = "ghkl3d";
33 Application::Application(unsigned int rot_count,
34 bool enable_anim)
35 : m_Scene(rot_count, enable_anim)
37 this->get_widgets_and_objects_from_ui();
40 // Top-level window.
42 _window1->set_title(APP_NAME);
44 // Get automatically redrawn if any of their children changed allocation.
45 _window1->set_reallocate_redraws(true);
48 // Application scene.
50 m_Scene.set_size_request(1200, 800);
52 _vbox1->pack_start(m_Scene);
54 this->connect_all_signals();
56 // Show window.
58 _window1->show_all();
61 Application::~Application(void)
65 void Application::get_widgets_and_objects_from_ui(void)
67 //Get Glade UI:
68 _refGlade = Gtk::Builder::create();
69 if(!_refGlade->add_from_file("ghkl3d.ui")){
70 std::string filename = Glib::build_filename(PKGDATA, "ghkl3d.ui");
71 if(!_refGlade->add_from_file(filename))
72 exit(1);
75 // window1
76 _refGlade->get_widget("window1", _window1);
77 _refGlade->get_widget("vbox1", _vbox1);
78 _refGlade->get_widget("button1", _button1);
79 _refGlade->get_widget("spinbutton1", _spinbutton1);
80 _refGlade->get_widget("spinbutton2", _spinbutton2);
81 _refGlade->get_widget("spinbutton3", _spinbutton3);
82 _refGlade->get_widget("spinbutton4", _spinbutton4);
83 _refGlade->get_widget("spinbutton5", _spinbutton5);
84 _refGlade->get_widget("spinbutton6", _spinbutton6);
87 void Application::connect_all_signals(void)
89 _spinbutton1->signal_value_changed().connect(
90 sigc::mem_fun(*this, &Application::on_spinbutton1_value_changed));
91 _spinbutton2->signal_value_changed().connect(
92 sigc::mem_fun(*this, &Application::on_spinbutton2_value_changed));
93 _spinbutton3->signal_value_changed().connect(
94 sigc::mem_fun(*this, &Application::on_spinbutton3_value_changed));
95 _spinbutton4->signal_value_changed().connect(
96 sigc::mem_fun(*this, &Application::on_spinbutton4_value_changed));
97 _spinbutton5->signal_value_changed().connect(
98 sigc::mem_fun(*this, &Application::on_spinbutton5_value_changed));
99 _spinbutton6->signal_value_changed().connect(
100 sigc::mem_fun(*this, &Application::on_spinbutton6_value_changed));
103 _button1->signal_clicked().connect(
104 sigc::mem_fun(*this, &Application::on_button1_quit_clicked));
107 void Application::on_spinbutton1_value_changed(void)
110 void Application::on_spinbutton2_value_changed(void)
113 void Application::on_spinbutton3_value_changed(void)
116 void Application::on_spinbutton4_value_changed(void)
119 void Application::on_spinbutton5_value_changed(void)
122 void Application::on_spinbutton6_value_changed(void)
126 void Application::on_button1_quit_clicked(void)
128 Gtk::Main::quit();
131 bool Application::on_key_press_event(GdkEventKey* event)
133 switch (event->keyval) {
134 case GDK_a:
135 m_Scene.toggle_anim();
136 break;
137 case GDK_i:
138 m_Scene.init_anim();
139 break;
140 case GDK_Escape:
141 Gtk::Main::quit();
142 break;
143 default:
144 return true;
147 m_Scene.invalidate();
149 return true;
152 } // namespace Logo