1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/* Gobby - GTK-based collaborative text editor
* Copyright (C) 2008-2014 Armin Burgmeier <armin@arbur.net>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "core/huebutton.hpp"
#include "util/color.hpp"
#include <gtkmm/stock.h>
#include <libinftextgtk/inf-text-gtk-hue-chooser.h>
Gobby::HueButton::HueButton(const Glib::ustring& title, Gtk::Window& parent):
m_title(title), m_parent(parent), m_saturation(1.0), m_value(1.0)
{
parent.signal_hide().connect(
sigc::mem_fun(*this, &HueButton::on_parent_hide));
set_hue(1.0);
}
double Gobby::HueButton::get_hue() const
{
return hue_from_gdk_color(get_color());
}
double Gobby::HueButton::get_saturation() const
{
return m_saturation;
}
double Gobby::HueButton::get_value() const
{
return m_value;
}
void Gobby::HueButton::set_hue(double hue)
{
Gdk::Color color;
color.set_hsv(hue * 360.0, m_saturation, m_value);
set_color(color);
}
void Gobby::HueButton::set_saturation(double saturation)
{
m_saturation = saturation;
set_hue(get_hue()); // Update view
}
void Gobby::HueButton::set_value(double value)
{
m_value = value;
set_hue(get_hue()); // Update view
}
void Gobby::HueButton::on_clicked()
{
if(!m_dialog.get())
{
m_dialog.reset(new Gtk::Dialog(m_title, m_parent));
m_hue_chooser =
inf_text_gtk_hue_chooser_new_with_hue(get_hue());
gtk_box_pack_start(GTK_BOX(m_dialog->get_vbox()->gobj()),
m_hue_chooser, FALSE, FALSE, 0);
gtk_widget_show(m_hue_chooser);
m_dialog->add_button(Gtk::Stock::CANCEL,
Gtk::RESPONSE_CANCEL);
m_dialog->add_button(Gtk::Stock::OK,
Gtk::RESPONSE_OK);
m_dialog->set_default_response(Gtk::RESPONSE_OK);
m_dialog->set_resizable(false);
m_dialog->signal_response().connect(
sigc::mem_fun(*this,
&HueButton::on_dialog_response));
}
else
{
inf_text_gtk_hue_chooser_set_hue(
INF_TEXT_GTK_HUE_CHOOSER(m_hue_chooser), get_hue());
}
m_dialog->present();
}
void Gobby::HueButton::on_parent_hide()
{
// Hide child dialog when the window containing the color button
// goes away
m_dialog.reset(NULL);
}
void Gobby::HueButton::on_dialog_response(int response_id)
{
if(response_id == Gtk::RESPONSE_OK)
{
set_hue(
inf_text_gtk_hue_chooser_get_hue(
INF_TEXT_GTK_HUE_CHOOSER(m_hue_chooser)));
}
m_dialog->hide();
}
|