/* * clockwin.cc * * Created: 2009, 2010 * Author: fischer * for use in Yale course CPSC 427a, Fall 2010 * * Derived from: * http://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/drawingarea/clock * subject to the following license: * * gtkmm example Copyright (C) 2002 gtkmm development team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "clockwin.hpp" ClockWin::ClockWin() : m_canvas(&m_clock), m_RedCheckBox("Red"), m_OrangeCheckBox("Orange"), m_YellowCheckBox("Yellow"), m_GreenCheckBox("Green"), m_BlueCheckBox("Blue"), m_BlinkBox("Blink"), m_ONButton(m_group, "ON"), m_OFFButton(m_group, "OFF") { set_title("Cairomm Clock"); add(m_mainVBox); m_canvas.set_size_request(300,300); m_mainVBox.pack_start(m_HBox); m_mainVBox.pack_start(m_Frame_Button); m_Frame_Button.add(m_ButtonBox); m_HBox.pack_start(m_canvas); m_HBox.pack_start(m_ColorBox); m_ColorBox.pack_start(m_RedCheckBox); m_ColorBox.pack_start(m_OrangeCheckBox); m_ColorBox.pack_start(m_YellowCheckBox); m_ColorBox.pack_start(m_GreenCheckBox); m_ColorBox.pack_start(m_BlueCheckBox); m_ButtonBox.pack_start(m_OFFButton); m_ButtonBox.pack_start(m_ONButton); m_ButtonBox.pack_start(m_BlinkBox); // Signal handlers m_RedCheckBox.signal_clicked().connect(sigc::bind( sigc::mem_fun(*this, &ClockWin::on_color_button_clicked), Clock::red_box)); m_OrangeCheckBox.signal_clicked().connect(sigc::bind( sigc::mem_fun(*this, &ClockWin::on_color_button_clicked), Clock::orange_box)); m_YellowCheckBox.signal_clicked().connect(sigc::bind( sigc::mem_fun(*this, &ClockWin::on_color_button_clicked), Clock::yellow_box)); m_GreenCheckBox.signal_clicked().connect(sigc::bind( sigc::mem_fun(*this, &ClockWin::on_color_button_clicked), Clock::green_box)); m_BlueCheckBox.signal_clicked().connect(sigc::bind( sigc::mem_fun(*this, &ClockWin::on_color_button_clicked), Clock::blue_box)); m_BlinkBox.signal_clicked().connect(sigc::bind( sigc::mem_fun(*this, &ClockWin::on_power_button_clicked), Blink)); m_OFFButton.signal_clicked().connect(sigc::bind( sigc::mem_fun(*this, &ClockWin::on_power_button_clicked), OFF)); m_ONButton.signal_clicked().connect(sigc::bind( sigc::mem_fun(*this, &ClockWin::on_power_button_clicked), ON)); Glib::signal_timeout().connect(sigc::mem_fun(*this, &ClockWin::on_timeout), 500); #ifndef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED //Connect the signal handler if it isn't already a virtual method override: signal_expose_event().connect( sigc::mem_fun(*this, &on_expose_event), false); #endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED show_all_children(); } void ClockWin::on_color_button_clicked(Clock::ColorBoxName data) { m_clock.toggleCheck(data); m_canvas.forceRedraw(); } void ClockWin::on_power_button_clicked(Power data) { switch (data) { case Blink: m_clock.toggleBlink(); break; case OFF: if (getOFFButtonState()) m_clock.setPowerSwitch(false); break; case ON: if (getONButtonState()) m_clock.setPowerSwitch(true); break; } } bool ClockWin::on_timeout() { // force our program to redraw the entire clock. if (m_clock.getPowerSwitch()) { m_clock.updateTime(); m_canvas.forceRedraw(); } return true; }