The Hildon::ColorSelector
is the Maemo equivalent for the Gtk::ColorSelector
but optimized for embedded devices. It consists of a control that displays the default palette of 16 colors and a control that can be opened to select a custom color from a 16M color palette. This way it fits better on a small screen as a Gtk::ColorSelection
There is also a Hildon::ColorButton
which can be used to launch a
Hildon::ColorSelector
and show the selected color on the button.
The interface is simple and self explanatory, but here is an example
File: examplewindow.h
#ifndef GTKMM_EXAMPLEWINDOW_H #define GTKMM_EXAMPLEWINDOW_H #include <hildonmm/window.h> #include <hildonmm/color-button.h> #include <gtkmm.h> class ExampleWindow : public Hildon::Window { public: ExampleWindow(); virtual ~ExampleWindow(); protected: void log_color(const Gdk::Color& color); //Signal handlers: void on_menu_quit(); //TODO: Port this: void on_button_clicked(); void on_color_button_color_changed(); //Child widgets: Gtk::Menu m_main; Gtk::MenuItem m_item_quit; Gtk::VBox m_vbox; Hildon::ColorButton m_color_button; }; #endif //GTKMM_EXAMPLEWINDOW_H
File: examplewindow.cc
#include "examplewindow.h" #include <gtkmm.h> #include <iostream> ExampleWindow::ExampleWindow() : m_item_quit("Quit"), m_vbox(false, 6) { // Add menu items to the main menu: m_main.append(m_item_quit); m_main.show_all(); set_menu(m_main); //Connect signal handlers: m_item_quit.signal_activate().connect( sigc::mem_fun(*this, &ExampleWindow::on_menu_quit) ); m_color_button.connect_property_changed("color", sigc::mem_fun(*this, &ExampleWindow::on_color_button_color_changed)); //Add the VBox and add the buttons to it: add(m_vbox); m_vbox.pack_start(m_color_button, Gtk::PACK_SHRINK); //Make all child widgets visible, //so they will be visible when this window is shown: show_all_children(); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_menu_quit() { hide(); } void ExampleWindow::on_color_button_color_changed() { //Show the chosen color details: Gdk::Color color; m_color_button.get_property("color", color); log_color(color); } void ExampleWindow::log_color(const Gdk::Color& color) { std::cout << "Color chosen: red: " << color.get_red() << ", green: " << color.get_green() << ", blue: " << color.get_blue() << std::endl; }
File: main.cc
#include <hildonmm.h> #include "examplewindow.h" #include <iostream> int main(int argc, char *argv[]) { // Initialize gtkmm: Gtk::Main kit(&argc, &argv); Hildon::init(); osso_context_t* osso_context = osso_initialize("example", "0.0.1", TRUE /* deprecated parameter */, 0 /* Use default Glib main loop context */); if(!osso_context) std::cerr << "osso_initialize() failed." << std::endl; Glib::set_application_name("Color example"); // Create Window and set it to Program ExampleWindow window; Hildon::Program::get_instance()->add_window(window); // Begin the main application kit.run(window); osso_deinitialize(osso_context); return 0; }
The documentation for the standard gtkmm ColorSelectionDialog
can be found in the
gtkmm tutorial.